Skip to content

Commit 29f08db

Browse files
Resul AvanResul Avan
authored andcommitted
common-types npm local module
1 parent cb7f281 commit 29f08db

File tree

81 files changed

+320
-552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+320
-552
lines changed

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ jobs:
66
- image: circleci/node:10.16.3
77
steps:
88
- checkout
9+
- run:
10+
name: Install commons-types dependencies
11+
command: npm --prefix functions commons-types
12+
- run:
13+
name: Build commons-types
14+
command: npm --prefix functions run build
915
- run:
1016
name: Add .env
1117
command: |

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ firebase-debug.log
101101
**/*.log
102102
node_modules
103103

104+
# modules
105+
*/lib
106+
104107
# firebase
105-
functions/lib
106108
functions/nuxt.config.ts
107109
public
108110
firebase-admin-credentials.json

common-types/tsconfig-cjs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "CommonJS",
5+
"outDir": "./lib/cjs"
6+
}
7+
}

common-types/tslint.json

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"rules": {
3+
// -- Strict errors --
4+
// These lint rules are likely always a good idea.
5+
6+
// Force function overloads to be declared together. This ensures readers understand APIs.
7+
"adjacent-overload-signatures": true,
8+
9+
// Do not allow the subtle/obscure comma operator.
10+
"ban-comma-operator": true,
11+
12+
// Do not allow internal modules or namespaces . These are deprecated in favor of ES6 modules.
13+
"no-namespace": true,
14+
15+
// Do not allow parameters to be reassigned. To avoid bugs, developers should instead assign new values to new vars.
16+
"no-parameter-reassignment": true,
17+
18+
// Force the use of ES6-style imports instead of /// <reference path=> imports.
19+
"no-reference": true,
20+
21+
// Do not allow type assertions that do nothing. This is a big warning that the developer may not understand the
22+
// code currently being edited (they may be incorrectly handling a different type case that does not exist).
23+
"no-unnecessary-type-assertion": true,
24+
25+
// Disallow nonsensical label usage.
26+
"label-position": true,
27+
28+
// Disallows the (often typo) syntax if (var1 = var2). Replace with if (var2) { var1 = var2 }.
29+
"no-conditional-assignment": true,
30+
31+
// Disallows constructors for primitive types (e.g. new Number('123'), though Number('123') is still allowed).
32+
"no-construct": true,
33+
34+
// Do not allow super() to be called twice in a constructor.
35+
"no-duplicate-super": true,
36+
37+
// Do not allow the same case to appear more than once in a switch block.
38+
"no-duplicate-switch-case": true,
39+
40+
// Do not allow a variable to be declared more than once in the same block. Consider function parameters in this
41+
// rule.
42+
"no-duplicate-variable": [true, "check-parameters"],
43+
44+
// Disallows a variable definition in an inner scope from shadowing a variable in an outer scope. Developers should
45+
// instead use a separate variable name.
46+
"no-shadowed-variable": true,
47+
48+
// Empty blocks are almost never needed. Allow the one general exception: empty catch blocks.
49+
"no-empty": [true, "allow-empty-catch"],
50+
51+
// Functions must either be handled directly (e.g. with a catch() handler) or returned to another function.
52+
// This is a major source of errors in Cloud Functions and the team strongly recommends leaving this rule on.
53+
"no-floating-promises": true,
54+
55+
// Do not allow any imports for modules that are not in package.json. These will almost certainly fail when
56+
// deployed.
57+
"no-implicit-dependencies": true,
58+
59+
// The 'this' keyword can only be used inside of classes.
60+
"no-invalid-this": true,
61+
62+
// Do not allow strings to be thrown because they will not include stack traces. Throw Errors instead.
63+
"no-string-throw": true,
64+
65+
// Disallow control flow statements, such as return, continue, break, and throw in finally blocks.
66+
"no-unsafe-finally": true,
67+
68+
// Expressions must always return a value. Avoids common errors like const myValue = functionReturningVoid();
69+
"no-void-expression": [true, "ignore-arrow-function-shorthand"],
70+
71+
// Disallow duplicate imports in the same file.
72+
"no-duplicate-imports": true,
73+
74+
75+
// -- Strong Warnings --
76+
// These rules should almost never be needed, but may be included due to legacy code.
77+
// They are left as a warning to avoid frustration with blocked deploys when the developer
78+
// understand the warning and wants to deploy anyway.
79+
80+
// Warn when an empty interface is defined. These are generally not useful.
81+
"no-empty-interface": {"severity": "warning"},
82+
83+
// Warn when an import will have side effects.
84+
"no-import-side-effect": {"severity": "warning"},
85+
86+
// Warn when variables are defined with var. Var has subtle meaning that can lead to bugs. Strongly prefer const for
87+
// most values and let for values that will change.
88+
"no-var-keyword": {"severity": "warning"},
89+
90+
// Prefer === and !== over == and !=. The latter operators support overloads that are often accidental.
91+
"triple-equals": {"severity": "warning"},
92+
93+
// Warn when using deprecated APIs.
94+
"deprecation": {"severity": "warning"},
95+
96+
// -- Light Warnings --
97+
// These rules are intended to help developers use better style. Simpler code has fewer bugs. These would be "info"
98+
// if TSLint supported such a level.
99+
100+
// prefer for( ... of ... ) to an index loop when the index is only used to fetch an object from an array.
101+
// (Even better: check out utils like .map if transforming an array!)
102+
"prefer-for-of": {"severity": "warning"},
103+
104+
// Warns if function overloads could be unified into a single function with optional or rest parameters.
105+
"unified-signatures": {"severity": "warning"},
106+
107+
// Prefer const for values that will not change. This better documents code.
108+
"prefer-const": {"severity": "warning"},
109+
110+
// Multi-line object literals and function calls should have a trailing comma. This helps avoid merge conflicts.
111+
"trailing-comma": {"severity": "warning"}
112+
},
113+
114+
"defaultSeverity": "error"
115+
}

functions/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"body-parser": "^1.19.0",
2626
"buefy": "^0.8.20",
2727
"bulma-helpers": "^0.3.12",
28+
"common-types": "file:../common-types",
2829
"cookie-parser": "^1.4.5",
2930
"cookie-universal-nuxt": "^2.1.4",
3031
"cors": "^2.8.5",

functions/src/api/api-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NextFunction, Request, RequestHandler, Response } from 'express'
22
import { OK } from 'http-status-codes'
33
import admin from 'firebase-admin'
4-
import { ApiErrorCode } from '../types'
54
import {
65
extractHeadersFromRequest,
76
getTokenFromRequest,
@@ -10,6 +9,7 @@ import {
109
} from '../service/request-handler-service';
1110
import { getDecodedIdToken } from '../service/firebase-admin-service'
1211
import DecodedIdToken = admin.auth.DecodedIdToken
12+
import { ApiErrorCode } from 'common-types'
1313

1414
export const extractHeaderHandler: RequestHandler = async (req: Request, res: Response, next: NextFunction) => {
1515
await extractHeadersFromRequest(req)

functions/src/api/auth-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RequestHandler } from 'express'
22
import { NO_CONTENT, OK } from 'http-status-codes'
33
import { setCustomClaims, toAuthUser, validateClaimsAndGet } from '../service/firebase-admin-service'
4-
import { ApiErrorCode, FirebaseClaimKey, FirebaseClaims } from '../types'
4+
import { ApiErrorCode, FirebaseClaimKey, FirebaseClaims } from 'common-types'
55
import {
66
getDecodedIdTokenFromRequest,
77
handleApiErrors,

functions/src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import cookieParser from 'cookie-parser'
33
import { json } from 'body-parser'
44
import cors from 'cors'
55
import { RuntimeOptions, runWith } from 'firebase-functions'
6-
import { ApiConfig } from '../types';
6+
import { ApiConfig } from 'common-types';
77
import { claimsHandler, verifyHandler } from './auth-handler'
88
import { extractHeaderHandler, healthyHandler, tokenHandler } from './api-handler'
99
import { notifyHandler } from './notification-handler'

functions/src/api/notification-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
handlerCalledLog,
88
handlerLog
99
} from '../service/request-handler-service'
10-
import { ApiErrorCode, UserDevice } from '../types'
10+
import { ApiErrorCode, UserDevice } from 'common-types'
1111
import { deleteUserDevice, getPushNotification, getUserDevices } from '../service/firebase-admin-service'
1212
import DecodedIdToken = admin.auth.DecodedIdToken
1313

functions/src/service/firebase-admin-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
User,
1212
UserDevice,
1313
WhereClause
14-
} from '../types'
14+
} from 'common-types'
1515
import { deleteModel, getModelById, getModelsByWhereClauses } from './firestore-admin-collection-service'
1616
import DecodedIdToken = admin.auth.DecodedIdToken
1717

0 commit comments

Comments
 (0)