@mxpicture/gcp-functions-backend 1.3.17 → 1.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocumentData, DocumentKeyAdmin,
|
|
1
|
+
import type { DocumentData, DocumentKeyAdmin, FunctionRequest, FunctionResponse } from "@mxpicture/gcp-functions-common/types";
|
|
2
2
|
import type { CallableFunction, HttpsFunction } from "firebase-functions/v2/https";
|
|
3
3
|
import type { ExpressAuthHandler } from "../types/types.express.js";
|
|
4
4
|
import type { IBackendApi } from "../api/IBackendApi.js";
|
|
@@ -20,7 +20,6 @@ export declare abstract class IBackendFunction<STORE_DOC extends DocumentKeyAdmi
|
|
|
20
20
|
protected readonly datePaths: string[];
|
|
21
21
|
protected _api?: API;
|
|
22
22
|
protected _routes?: string[];
|
|
23
|
-
ingressFollowup: FunctionIngressFollowup | null;
|
|
24
23
|
/**
|
|
25
24
|
* Create a new backend function instance.
|
|
26
25
|
*
|
|
@@ -50,14 +49,14 @@ export declare abstract class IBackendFunction<STORE_DOC extends DocumentKeyAdmi
|
|
|
50
49
|
* @returns The API instance.
|
|
51
50
|
* @throws {@link Error} if no API has been provided via {@link useApi}.
|
|
52
51
|
*/
|
|
53
|
-
|
|
52
|
+
get api(): API;
|
|
54
53
|
/**
|
|
55
54
|
* Retrieve the registered route names.
|
|
56
55
|
*
|
|
57
56
|
* @returns The array of allowed route names.
|
|
58
57
|
* @throws {@link Error} if no routes have been provided via {@link useRoutes}.
|
|
59
58
|
*/
|
|
60
|
-
|
|
59
|
+
get routes(): string[];
|
|
61
60
|
/**
|
|
62
61
|
* Route an incoming function request to the appropriate API method.
|
|
63
62
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IBackendFunction.d.ts","sourceRoot":"","sources":["../../src/function/IBackendFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,gBA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ED;;;;;;;;;;;;;OAaG;IACU,OAAO,CAAC,GAAG,EAAE,GAAG,SAAS,YAAY,EAChD,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,GAC5B,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAuBjC;;;;;;;;OAQG;IACI,qBAAqB,IAAI,gBAAgB,CAE9C,eAAe,CAAC,GAAG,CAAC,EAEpB,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC/B;IAOD;;;;;;;;OAQG;IACI,kBAAkB,CACvB,IAAI,GAAE,kBAAkB,GAAG,IAAuB,GACjD,aAAa;CAsBjB"}
|
|
@@ -2,7 +2,6 @@ import { onCall, HttpsError, onRequest } from "firebase-functions/v2/https";
|
|
|
2
2
|
import express from "express";
|
|
3
3
|
import { toDatesDeep, toTimestampsDeep, } from "@mxpicture/gcp-functions-common/helper";
|
|
4
4
|
import { checkServiceAuth } from "../firebase/firebase.express.js";
|
|
5
|
-
import { mapHttpToFunctionHeaders } from "@mxpicture/gcp-functions-common/config";
|
|
6
5
|
/**
|
|
7
6
|
* Abstract base class for Firebase callable backend functions.
|
|
8
7
|
*
|
|
@@ -21,7 +20,6 @@ export class IBackendFunction {
|
|
|
21
20
|
datePaths;
|
|
22
21
|
_api;
|
|
23
22
|
_routes;
|
|
24
|
-
ingressFollowup = null;
|
|
25
23
|
/**
|
|
26
24
|
* Create a new backend function instance.
|
|
27
25
|
*
|
|
@@ -58,7 +56,7 @@ export class IBackendFunction {
|
|
|
58
56
|
* @returns The API instance.
|
|
59
57
|
* @throws {@link Error} if no API has been provided via {@link useApi}.
|
|
60
58
|
*/
|
|
61
|
-
api() {
|
|
59
|
+
get api() {
|
|
62
60
|
if (!this._api)
|
|
63
61
|
throw new Error(`${this.name}: api not provided. Use "useApi" method`);
|
|
64
62
|
return this._api;
|
|
@@ -69,7 +67,7 @@ export class IBackendFunction {
|
|
|
69
67
|
* @returns The array of allowed route names.
|
|
70
68
|
* @throws {@link Error} if no routes have been provided via {@link useRoutes}.
|
|
71
69
|
*/
|
|
72
|
-
routes() {
|
|
70
|
+
get routes() {
|
|
73
71
|
if (!this._routes)
|
|
74
72
|
throw new Error(`${this.name}: routes not provided. Use "useRoutes" method`);
|
|
75
73
|
return this._routes;
|
|
@@ -89,26 +87,22 @@ export class IBackendFunction {
|
|
|
89
87
|
* @throws {@link HttpsError} with `internal` if the API method throws an unexpected error.
|
|
90
88
|
*/
|
|
91
89
|
async ingress(request) {
|
|
92
|
-
const routes = this.routes
|
|
90
|
+
const routes = this.routes;
|
|
93
91
|
if (!routes.find((m) => m === request.route))
|
|
94
92
|
throw new HttpsError("invalid-argument", `Route ${request.route} not available`);
|
|
95
93
|
try {
|
|
96
94
|
const requestData = toDatesDeep(request.data, this.datePaths);
|
|
97
95
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
-
const payload = await this.api
|
|
99
|
-
|
|
96
|
+
const payload = await this.api[request.route](requestData);
|
|
97
|
+
return {
|
|
100
98
|
data: toTimestampsDeep(payload, this.datePaths),
|
|
101
99
|
};
|
|
102
|
-
await this.ingressFollowup?.(this, "success", request, response);
|
|
103
|
-
return response;
|
|
104
100
|
}
|
|
105
101
|
catch (error) {
|
|
106
|
-
await this.ingressFollowup?.(this, "error", request, null);
|
|
107
102
|
if (error instanceof HttpsError)
|
|
108
103
|
throw error;
|
|
109
104
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
105
|
throw new HttpsError("internal", error?.message ?? "unknown");
|
|
111
|
-
// }
|
|
112
106
|
}
|
|
113
107
|
}
|
|
114
108
|
/**
|
|
@@ -141,11 +135,14 @@ export class IBackendFunction {
|
|
|
141
135
|
if (req.method !== "POST")
|
|
142
136
|
return next();
|
|
143
137
|
const route = req.path.slice(1);
|
|
144
|
-
const
|
|
145
|
-
const result = await this.ingress({ data: req.body, route, headers });
|
|
138
|
+
const result = await this.ingress({ data: req.body, route });
|
|
146
139
|
res.json(result.data);
|
|
147
140
|
});
|
|
148
|
-
|
|
141
|
+
// no-invoker-iam-check
|
|
142
|
+
return onRequest({
|
|
143
|
+
region: this.region,
|
|
144
|
+
serviceAccount: this.serviceAccount,
|
|
145
|
+
}, app);
|
|
149
146
|
}
|
|
150
147
|
}
|
|
151
148
|
//# sourceMappingURL=IBackendFunction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IBackendFunction.js","sourceRoot":"","sources":["../../src/function/IBackendFunction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IBackendFunction.js","sourceRoot":"","sources":["../../src/function/IBackendFunction.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EACL,WAAW,EACX,gBAAgB,GACjB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAInE;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,gBAAgB;IAkBlB;IACA;IACA;IACG;IAfX,IAAI,CAAO;IACX,OAAO,CAAY;IAE7B;;;;;;;OAOG;IACH,YACkB,IAAY,EACZ,MAAc,EACd,cAAsB,EACnB,SAAmB;QAHtB,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,mBAAc,GAAd,cAAc,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAU;IACrC,CAAC;IAEJ;;;;OAIG;IACI,MAAM,CAAC,GAAQ;QACpB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAA4C;QAC3D,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;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|
|
4
4
|
"description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@google-cloud/tasks": "^6.2.1",
|
|
57
|
-
"@mxpicture/gcp-functions-common": "^1.3.
|
|
57
|
+
"@mxpicture/gcp-functions-common": "^1.3.19",
|
|
58
58
|
"express": "^5.2.1",
|
|
59
59
|
"firebase-admin": "^13.7.0",
|
|
60
60
|
"firebase-functions": "^7.0.6",
|