@mxpicture/gcp-functions-backend 2.1.34 → 2.1.35

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.
Files changed (58) hide show
  1. package/dist/api/BackendBaseApi.d.ts +35 -13
  2. package/dist/api/BackendBaseApi.d.ts.map +1 -1
  3. package/dist/api/BackendBaseApi.js +36 -13
  4. package/dist/api/BackendBaseApi.js.map +1 -1
  5. package/dist/api/BackendCrudApi.d.ts +5 -5
  6. package/dist/api/BackendCrudApi.d.ts.map +1 -1
  7. package/dist/api/BackendCrudApi.js +6 -2
  8. package/dist/api/BackendCrudApi.js.map +1 -1
  9. package/dist/api/BackendDefaultApi.d.ts +17 -8
  10. package/dist/api/BackendDefaultApi.d.ts.map +1 -1
  11. package/dist/api/BackendDefaultApi.js +19 -6
  12. package/dist/api/BackendDefaultApi.js.map +1 -1
  13. package/dist/api/BackendStoreApi.d.ts +1 -1
  14. package/dist/api/BackendStoreApi.d.ts.map +1 -1
  15. package/dist/api/BackendStoreApi.js.map +1 -1
  16. package/dist/api/IBackendApi.d.ts +22 -0
  17. package/dist/api/IBackendApi.d.ts.map +1 -1
  18. package/dist/factory/IBackendFactory.d.ts +39 -1
  19. package/dist/factory/IBackendFactory.d.ts.map +1 -1
  20. package/dist/factory/IBackendFactory.js +35 -0
  21. package/dist/factory/IBackendFactory.js.map +1 -1
  22. package/dist/factory/IBackendStoreFactory.d.ts +37 -1
  23. package/dist/factory/IBackendStoreFactory.d.ts.map +1 -1
  24. package/dist/factory/IBackendStoreFactory.js +34 -0
  25. package/dist/factory/IBackendStoreFactory.js.map +1 -1
  26. package/dist/firebase/FirebaseTaskHandler.d.ts +13 -6
  27. package/dist/firebase/FirebaseTaskHandler.d.ts.map +1 -1
  28. package/dist/firebase/FirebaseTaskHandler.js +13 -6
  29. package/dist/firebase/FirebaseTaskHandler.js.map +1 -1
  30. package/dist/firebase/FirebaseTaskQueueHandler.d.ts +23 -20
  31. package/dist/firebase/FirebaseTaskQueueHandler.d.ts.map +1 -1
  32. package/dist/firebase/FirebaseTaskQueueHandler.js +23 -20
  33. package/dist/firebase/FirebaseTaskQueueHandler.js.map +1 -1
  34. package/dist/firebase/firebase.express.d.ts +16 -8
  35. package/dist/firebase/firebase.express.d.ts.map +1 -1
  36. package/dist/firebase/firebase.express.js +16 -8
  37. package/dist/firebase/firebase.express.js.map +1 -1
  38. package/dist/firebase/firebase.tasks.d.ts +31 -0
  39. package/dist/firebase/firebase.tasks.d.ts.map +1 -1
  40. package/dist/firebase/firebase.tasks.js +31 -0
  41. package/dist/firebase/firebase.tasks.js.map +1 -1
  42. package/dist/function/CompositeBackendFunction.d.ts +33 -2
  43. package/dist/function/CompositeBackendFunction.d.ts.map +1 -1
  44. package/dist/function/CompositeBackendFunction.js +31 -1
  45. package/dist/function/CompositeBackendFunction.js.map +1 -1
  46. package/dist/function/IBackendFunction.d.ts +48 -23
  47. package/dist/function/IBackendFunction.d.ts.map +1 -1
  48. package/dist/function/IBackendFunction.js +39 -22
  49. package/dist/function/IBackendFunction.js.map +1 -1
  50. package/dist/store/Store.d.ts +21 -2
  51. package/dist/store/Store.d.ts.map +1 -1
  52. package/dist/store/Store.js +22 -3
  53. package/dist/store/Store.js.map +1 -1
  54. package/dist/types/types.env.d.ts +2 -1
  55. package/dist/types/types.env.d.ts.map +1 -1
  56. package/dist/types/types.tasks.d.ts +30 -1
  57. package/dist/types/types.tasks.d.ts.map +1 -1
  58. package/package.json +2 -2
@@ -1,6 +1,25 @@
1
1
  import { computeScheduleTimeUtc } from "@mxpicture/gcp-functions-common/helper";
2
+ /**
3
+ * Pattern matching a fully-qualified Cloud Tasks task resource path.
4
+ *
5
+ * @remarks
6
+ * Capture groups (in order): project ID, region, queue ID, task ID.
7
+ * Used by {@link fromTaskPath}.
8
+ */
2
9
  export const taskPathRegex = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/queues\/([a-zA-Z0-9-_]+)\/tasks\/([a-zA-Z0-9-_]+)$/;
10
+ /**
11
+ * Pattern matching a fully-qualified Cloud Tasks queue resource path.
12
+ *
13
+ * @remarks
14
+ * Capture groups (in order): project ID, region, queue ID. Used by {@link fromQueuePath}.
15
+ */
3
16
  export const queuePathRegex = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/queues\/([a-zA-Z0-9-_]+)$/;
17
+ /**
18
+ * Pattern matching the short `<queueId>-<taskId>` form used as a friendly task name.
19
+ *
20
+ * @remarks
21
+ * Used by {@link fromTaskName} and {@link toTaskName}.
22
+ */
4
23
  export const taskNameRegex = /^([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)$/;
5
24
  /**
6
25
  * Compute a Cloud Tasks schedule timestamp from a duration specification or an absolute `Date`.
@@ -66,6 +85,12 @@ export const fromQueuePath = (path) => {
66
85
  queueId: found[3],
67
86
  };
68
87
  };
88
+ /**
89
+ * Parses a short `<queueId>-<taskId>` task name into its parts.
90
+ *
91
+ * @param name - The short task name to parse.
92
+ * @returns The parsed parts, or `null` if `name` does not match {@link taskNameRegex}.
93
+ */
69
94
  export const fromTaskName = (name) => {
70
95
  const found = name.match(taskNameRegex);
71
96
  if (!found)
@@ -75,5 +100,11 @@ export const fromTaskName = (name) => {
75
100
  taskId: found[2],
76
101
  };
77
102
  };
103
+ /**
104
+ * Formats a {@link FirebaseTaskName} back into its short `<queueId>-<taskId>` string form.
105
+ *
106
+ * @param name - The task name parts.
107
+ * @returns The joined `<queueId>-<taskId>` string.
108
+ */
78
109
  export const toTaskName = (name) => `${name.queueId}-${name.taskId}`;
79
110
  //# sourceMappingURL=firebase.tasks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"firebase.tasks.js","sourceRoot":"","sources":["../../src/firebase/firebase.tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAShF,MAAM,CAAC,MAAM,aAAa,GACxB,8GAA8G,CAAC;AAEjH,M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I,IAAI,CAAC,MAAM,EAAE,CAAC"}
@@ -20,8 +20,17 @@ export declare class CompositeBackendFunction {
20
20
  readonly projectId: string;
21
21
  readonly region: string;
22
22
  readonly serviceAccount: string;
23
- protected readonly funcs: Map<string, IBackendFunction<any, any, any, any>>;
23
+ protected readonly funcs: Map<string, IBackendFunction<any, any, any, any, any>>;
24
+ /**
25
+ * Creates a new composite function.
26
+ *
27
+ * @param name - Deployed Cloud Function name.
28
+ * @param projectId - GCP project ID.
29
+ * @param region - Cloud Functions deployment region.
30
+ * @param serviceAccount - Service account email used by the deployed function.
31
+ */
24
32
  constructor(name: string, projectId: string, region: string, serviceAccount: string);
33
+ /** Deployed HTTPS URL for this composite function. */
25
34
  get url(): string;
26
35
  /**
27
36
  * Register a per-topic function under the given topic key.
@@ -30,10 +39,32 @@ export declare class CompositeBackendFunction {
30
39
  * Sets the per-topic API's `functionUrl` to `${this.url}/${topic}` so per-topic code
31
40
  * (e.g., Cloud Tasks integration) can derive correct callback URLs.
32
41
  */
33
- useTopic<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, SIDE_EFFECTS extends DocumentData, API extends BackendBaseApi<DTO, SIDE_EFFECTS>>(topic: string, func: IBackendFunction<STORE_DOC, DTO, SIDE_EFFECTS, API>): this;
42
+ useTopic<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, INPUT_DTO extends DocumentData, SIDE_EFFECTS extends DocumentData, API extends BackendBaseApi<DTO, INPUT_DTO, SIDE_EFFECTS>>(topic: string, func: IBackendFunction<STORE_DOC, DTO, INPUT_DTO, SIDE_EFFECTS, API>): this;
34
43
  /** Flattened `topic/route` strings used by `buildCheckServiceAuth` audience derivation. */
35
44
  get routes(): string[];
45
+ /**
46
+ * Builds a Firebase callable Cloud Function that dispatches by `{ topic, route, data }`.
47
+ *
48
+ * @remarks
49
+ * Wraps each registered per-topic {@link IBackendFunction} behind a single
50
+ * `onCall` handler. The composite verifies the topic exists and delegates
51
+ * to the per-topic function's `ingress`.
52
+ *
53
+ * @returns A Firebase callable function ready for deployment.
54
+ */
36
55
  buildCallableFunction(): ZCallableFunction<CompositeFunctionRequest<any>, Promise<FunctionResponse<any>>>;
56
+ /**
57
+ * Builds a Firebase HTTPS Cloud Function exposing each topic+route at `POST /<topic>/<route>`.
58
+ *
59
+ * @remarks
60
+ * Verifies the path has exactly two segments, looks up the topic, and
61
+ * delegates to the per-topic function's `ingress`. When `auth` is omitted, a
62
+ * default OIDC middleware (built via {@link buildCheckServiceAuth}) guards
63
+ * the function. Pass `null` explicitly to disable authentication.
64
+ *
65
+ * @param auth - Authentication middleware to install. Omit for the default OIDC check; pass `null` to disable.
66
+ * @returns A Firebase {@link HttpsFunction} ready for deployment.
67
+ */
37
68
  buildHttpsFunction(auth?: ExpressAuthHandler | null): HttpsFunction;
38
69
  }
39
70
  //# sourceMappingURL=CompositeBackendFunction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CompositeBackendFunction.d.ts","sourceRoot":"","sources":["../../src/function/CompositeBackendFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EACV,gBAAgB,IAAI,iBAAiB,EACrC,aAAa,EACd,MAAM,6BAA6B,CAAC;AAGrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;;;;;;GAWG;AACH,qBAAa,wBAAwB;aAKjB,IAAI,EAAE,MAAM;aACZ,SAAS,EAAE,MAAM;aACjB,MAAM,EAAE,MAAM;aACd,cAAc,EAAE,MAAM;IANxC,SAAS,CAAC,QAAQ,CAAC,KAAK,oDAA2D;gBAGjE,IAAI,EAAE,MAAM,E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,MAAM;IAlBxC,SAAS,CAAC,QAAQ,CAAC,KAAK,yDAIpB;IAEJ;;;;;;;OAOG;gBAEe,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM;IAGxC,sDAAsD;IACtD,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED;;;;;;OAMG;IACI,QAAQ,CACb,SAAS,SAAS,gBAAgB,EAClC,GAAG,SAAS,SAAS,EACrB,SAAS,SAAS,YAAY,EAC9B,YAAY,SAAS,YAAY,EACjC,GAAG,SAAS,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,YAAY,CAAC,EAExD,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,CAAC,GACnE,IAAI;IAMP,2FAA2F;IAC3F,IAAW,MAAM,IAAI,MAAM,EAAE,CAK5B;IAED;;;;;;;;;OASG;IACI,qBAAqB,IAAI,iBAAiB,CAE/C,wBAAwB,CAAC,GAAG,CAAC,EAE7B,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC/B;IAgBD;;;;;;;;;;;OAWG;IACI,kBAAkB,CAAC,IAAI,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,aAAa;CAwD3E"}
@@ -18,14 +18,22 @@ export class CompositeBackendFunction {
18
18
  projectId;
19
19
  region;
20
20
  serviceAccount;
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
21
  funcs = new Map();
22
+ /**
23
+ * Creates a new composite function.
24
+ *
25
+ * @param name - Deployed Cloud Function name.
26
+ * @param projectId - GCP project ID.
27
+ * @param region - Cloud Functions deployment region.
28
+ * @param serviceAccount - Service account email used by the deployed function.
29
+ */
23
30
  constructor(name, projectId, region, serviceAccount) {
24
31
  this.name = name;
25
32
  this.projectId = projectId;
26
33
  this.region = region;
27
34
  this.serviceAccount = serviceAccount;
28
35
  }
36
+ /** Deployed HTTPS URL for this composite function. */
29
37
  get url() {
30
38
  return `https://${this.region}-${this.projectId}.cloudfunctions.net/${this.name}`;
31
39
  }
@@ -49,6 +57,16 @@ export class CompositeBackendFunction {
49
57
  out.push(`${topic}/${route}`);
50
58
  return out;
51
59
  }
60
+ /**
61
+ * Builds a Firebase callable Cloud Function that dispatches by `{ topic, route, data }`.
62
+ *
63
+ * @remarks
64
+ * Wraps each registered per-topic {@link IBackendFunction} behind a single
65
+ * `onCall` handler. The composite verifies the topic exists and delegates
66
+ * to the per-topic function's `ingress`.
67
+ *
68
+ * @returns A Firebase callable function ready for deployment.
69
+ */
52
70
  buildCallableFunction() {
53
71
  return onCall({ region: this.region, serviceAccount: this.serviceAccount }, async (req) => {
54
72
  const { topic, route, data } = req.data;
@@ -58,6 +76,18 @@ export class CompositeBackendFunction {
58
76
  return func.ingress({ route, data }, !!req.auth);
59
77
  });
60
78
  }
79
+ /**
80
+ * Builds a Firebase HTTPS Cloud Function exposing each topic+route at `POST /<topic>/<route>`.
81
+ *
82
+ * @remarks
83
+ * Verifies the path has exactly two segments, looks up the topic, and
84
+ * delegates to the per-topic function's `ingress`. When `auth` is omitted, a
85
+ * default OIDC middleware (built via {@link buildCheckServiceAuth}) guards
86
+ * the function. Pass `null` explicitly to disable authentication.
87
+ *
88
+ * @param auth - Authentication middleware to install. Omit for the default OIDC check; pass `null` to disable.
89
+ * @returns A Firebase {@link HttpsFunction} ready for deployment.
90
+ */
61
91
  buildHttpsFunction(auth) {
62
92
  const app = express();
63
93
  app.use(express.json());
@@ -1 +1 @@
1
- {"version":3,"file":"CompositeBackendFunction.js","sourceRoot":"","sources":["../../src/function/CompositeBackendFunction.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAi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AAM,EAAE,EAAE,CAAC,CAAC;gBACrC,CAAC;qBAAM,CAAC;oBACN,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACzD,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;oBAChE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBACnB,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE;qBACjD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CACd,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,EAC5D,GAAG,CACJ,CAAC;IACJ,CAAC;CACF"}
@@ -2,75 +2,97 @@ import type { DocumentData, DocumentKeyAdmin, FunctionRequest, FunctionResponse
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 { BackendBaseApi } from "../api/BackendBaseApi.js";
5
+ /**
6
+ * Construction parameters for {@link IBackendFunction}.
7
+ */
5
8
  export interface BackendFunctionParams {
9
+ /** Deployed Cloud Function name. */
6
10
  name: string;
11
+ /** GCP project ID. */
7
12
  projectId: string;
13
+ /** Cloud Functions deployment region. */
8
14
  region: string;
15
+ /** Service account email used by the deployed function. */
9
16
  serviceAccount: string;
17
+ /** Paths within request/response payloads holding date values that need timestamp conversion. */
10
18
  datePaths: string[];
11
19
  }
12
20
  /**
13
- * Abstract base class for Firebase callable backend functions.
21
+ * Abstract base class for backend Cloud Functions.
14
22
  *
15
23
  * @remarks
16
- * Encapsulates the wiring between an incoming callable request and a {@link BackendDefaultApi}.
17
- * Subclasses configure the API, routes, region, and service account, then call
18
- * {@link IBackendFunction.buildFunction} to produce a deployable Cloud Function.
24
+ * Encapsulates the wiring between an incoming Firebase callable or HTTPS
25
+ * request and a {@link BackendBaseApi}. Subclasses inject the API via
26
+ * {@link useApi}; consumers call {@link buildCallableFunction} or
27
+ * {@link buildHttpsFunction} to produce a deployable Cloud Function.
19
28
  *
20
- * @typeParam DTO - The document data transfer object type.
29
+ * @typeParam STORE_DOC - The shape stored in the underlying {@link Store}.
30
+ * @typeParam DTO - The shape returned by the API (extends `STORE_DOC`).
31
+ * @typeParam INPUT_DTO - The shape accepted on write operations.
32
+ * @typeParam SIDE_EFFECTS - Type of side-effect payloads supported by the API.
21
33
  * @typeParam API - The backend API implementation that handles route logic.
22
34
  */
23
- export declare abstract class IBackendFunction<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, SIDE_EFFECTS extends DocumentData, API extends BackendBaseApi<DTO, SIDE_EFFECTS>> {
35
+ export declare abstract class IBackendFunction<STORE_DOC extends DocumentKeyAdmin, DTO extends STORE_DOC, INPUT_DTO extends DocumentData, SIDE_EFFECTS extends DocumentData, API extends BackendBaseApi<DTO, INPUT_DTO, SIDE_EFFECTS>> {
24
36
  protected readonly params: BackendFunctionParams;
25
37
  protected _api?: API;
26
38
  /**
27
- * Create a new backend function instance.
39
+ * Creates a new backend function instance.
28
40
  *
29
- * @param name - A descriptive name for this function, used in error messages.
30
- * @param region - The GCP region in which the function is deployed.
31
- * @param serviceAccount - The service account email used to run the function.
32
- * @param datePaths - JSON paths within the response payload that contain date values to convert to Firestore Timestamps.
41
+ * @param params - Deployment parameters; see {@link BackendFunctionParams}.
33
42
  */
34
43
  constructor(params: BackendFunctionParams);
44
+ /** Deployed HTTPS URL for this function. */
35
45
  get url(): string;
46
+ /** Deployed function name. */
36
47
  get name(): string;
48
+ /** GCP project ID. */
37
49
  get projectId(): string;
50
+ /** Cloud Functions deployment region. */
38
51
  get region(): string;
52
+ /** Service account email used by the deployed function. */
39
53
  get serviceAccount(): string;
54
+ /** Paths within payloads holding date values that need timestamp conversion. */
40
55
  protected get datePaths(): string[];
41
56
  /**
42
- * Inject the backend API instance that handles route logic.
57
+ * Injects the backend API instance that handles route logic.
58
+ *
59
+ * @remarks
60
+ * Also pushes this function's deployed URL into the API via
61
+ * {@link BackendBaseApi.useFunctionUrl} so the API can derive callback URLs.
43
62
  *
44
63
  * @param api - The API instance to delegate requests to.
64
+ * @returns This instance for chaining.
45
65
  */
46
66
  useApi(api: API): this;
47
67
  /**
48
- * Retrieve the injected API instance.
68
+ * Retrieves the injected API instance.
49
69
  *
50
70
  * @returns The API instance.
51
- * @throws {@link Error} if no API has been provided via {@link useApi}.
71
+ * @throws Error when no API has been provided via {@link useApi}.
52
72
  */
53
73
  get api(): API;
54
74
  /**
55
- * Retrieve the registered route names.
75
+ * Returns the route names registered on the underlying API.
56
76
  *
57
77
  * @returns The array of allowed route names.
58
- * @throws {@link Error} if no routes have been provided via {@link useRoutes}.
78
+ * @throws Error when the API has not been injected, or when its routes have not been configured.
59
79
  */
60
80
  get routes(): string[];
61
81
  /**
62
- * Route an incoming function request to the appropriate API method.
82
+ * Dispatches an incoming function request to the underlying API.
63
83
  *
64
84
  * @remarks
65
- * Validates that the requested route is registered, delegates to the API, and
66
- * converts date fields in the response payload to Firestore Timestamps.
85
+ * Rejects unauthenticated requests with `HttpsError("unauthenticated")` and
86
+ * wraps unexpected API errors in `HttpsError("internal")`. Existing
87
+ * {@link HttpsError} instances are re-thrown unchanged.
67
88
  *
68
89
  * @typeParam REQ - The request payload type.
69
90
  * @typeParam RES - The response document data type.
70
91
  * @param request - The incoming function request containing route and data.
92
+ * @param isAuthenticated - Whether the caller has been authenticated upstream.
71
93
  * @returns The function response wrapping the API result.
72
- * @throws {@link HttpsError} with `invalid-argument` if the route is not registered.
73
- * @throws {@link HttpsError} with `internal` if the API method throws an unexpected error.
94
+ * @throws {@link HttpsError} with `unauthenticated` when `isAuthenticated` is `false`.
95
+ * @throws {@link HttpsError} with `internal` when the API method throws an unexpected error.
74
96
  */
75
97
  ingress<REQ, RES extends DocumentData>(request: FunctionRequest<REQ>, isAuthenticated: boolean): Promise<FunctionResponse<RES>>;
76
98
  /**
@@ -84,12 +106,15 @@ export declare abstract class IBackendFunction<STORE_DOC extends DocumentKeyAdmi
84
106
  */
85
107
  buildCallableFunction(): CallableFunction<FunctionRequest<any>, Promise<FunctionResponse<any>>>;
86
108
  /**
87
- * Build and return a Firebase Https Cloud Function.
109
+ * Builds a Firebase HTTPS Cloud Function exposing each route at `POST /<route>`.
88
110
  *
89
111
  * @remarks
90
112
  * Wraps {@link ingress} in a Firebase `onRequest` handler configured with the
91
- * specified region and service account.
113
+ * function's region and service account. When `auth` is omitted, a default
114
+ * OIDC middleware built by {@link buildCheckServiceAuth} guards the function.
115
+ * Pass `null` explicitly to disable authentication.
92
116
  *
117
+ * @param auth - Authentication middleware to install. Omit for the default OIDC check; pass `null` to disable.
93
118
  * @returns A Firebase {@link HttpsFunction} ready for deployment.
94
119
  */
95
120
  buildHttpsFunction(auth?: ExpressAuthHandler | null): HttpsFunction;
@@ -1 +1 @@
1
- {"version":3,"file":"IBackendFunction.d.ts","sourceRoot":"","sources":["../../src/function/IBackendFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,6BAA6B,CAAC;AAGrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AA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AED;;;;;;;;;OASG;IACI,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI;IAK7B;;;;;OAKG;IACH,IAAW,GAAG,IAAI,GAAG,CAIpB;IAED;;;;;OAKG;IACH,IAAW,MAAM,IAAI,MAAM,EAAE,CAE5B;IAED;;;;;;;;;;;;;;;OAeG;IACU,OAAO,CAAC,GAAG,EAAE,GAAG,SAAS,YAAY,EAChD,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,EAC7B,eAAe,EAAE,OAAO,GACvB,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAejC;;;;;;;;OAQG;IACI,qBAAqB,IAAI,gBAAgB,CAE9C,eAAe,CAAC,GAAG,CAAC,EAEpB,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC/B;IAOD;;;;;;;;;;;OAWG;IACI,kBAAkB,CAAC,IAAI,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,aAAa;CAmD3E"}
@@ -2,62 +2,74 @@ import { onCall, HttpsError, onRequest } from "firebase-functions/v2/https";
2
2
  import express from "express";
3
3
  import { buildCheckServiceAuth } from "../firebase/firebase.express.js";
4
4
  /**
5
- * Abstract base class for Firebase callable backend functions.
5
+ * Abstract base class for backend Cloud Functions.
6
6
  *
7
7
  * @remarks
8
- * Encapsulates the wiring between an incoming callable request and a {@link BackendDefaultApi}.
9
- * Subclasses configure the API, routes, region, and service account, then call
10
- * {@link IBackendFunction.buildFunction} to produce a deployable Cloud Function.
8
+ * Encapsulates the wiring between an incoming Firebase callable or HTTPS
9
+ * request and a {@link BackendBaseApi}. Subclasses inject the API via
10
+ * {@link useApi}; consumers call {@link buildCallableFunction} or
11
+ * {@link buildHttpsFunction} to produce a deployable Cloud Function.
11
12
  *
12
- * @typeParam DTO - The document data transfer object type.
13
+ * @typeParam STORE_DOC - The shape stored in the underlying {@link Store}.
14
+ * @typeParam DTO - The shape returned by the API (extends `STORE_DOC`).
15
+ * @typeParam INPUT_DTO - The shape accepted on write operations.
16
+ * @typeParam SIDE_EFFECTS - Type of side-effect payloads supported by the API.
13
17
  * @typeParam API - The backend API implementation that handles route logic.
14
18
  */
15
19
  export class IBackendFunction {
16
20
  params;
17
21
  _api;
18
22
  /**
19
- * Create a new backend function instance.
23
+ * Creates a new backend function instance.
20
24
  *
21
- * @param name - A descriptive name for this function, used in error messages.
22
- * @param region - The GCP region in which the function is deployed.
23
- * @param serviceAccount - The service account email used to run the function.
24
- * @param datePaths - JSON paths within the response payload that contain date values to convert to Firestore Timestamps.
25
+ * @param params - Deployment parameters; see {@link BackendFunctionParams}.
25
26
  */
26
27
  constructor(params) {
27
28
  this.params = params;
28
29
  }
30
+ /** Deployed HTTPS URL for this function. */
29
31
  get url() {
30
32
  return `https://${this.region}-${this.projectId}.cloudfunctions.net/${this.name}`;
31
33
  }
34
+ /** Deployed function name. */
32
35
  get name() {
33
36
  return this.params.name;
34
37
  }
38
+ /** GCP project ID. */
35
39
  get projectId() {
36
40
  return this.params.projectId;
37
41
  }
42
+ /** Cloud Functions deployment region. */
38
43
  get region() {
39
44
  return this.params.region;
40
45
  }
46
+ /** Service account email used by the deployed function. */
41
47
  get serviceAccount() {
42
48
  return this.params.serviceAccount;
43
49
  }
50
+ /** Paths within payloads holding date values that need timestamp conversion. */
44
51
  get datePaths() {
45
52
  return this.params.datePaths;
46
53
  }
47
54
  /**
48
- * Inject the backend API instance that handles route logic.
55
+ * Injects the backend API instance that handles route logic.
56
+ *
57
+ * @remarks
58
+ * Also pushes this function's deployed URL into the API via
59
+ * {@link BackendBaseApi.useFunctionUrl} so the API can derive callback URLs.
49
60
  *
50
61
  * @param api - The API instance to delegate requests to.
62
+ * @returns This instance for chaining.
51
63
  */
52
64
  useApi(api) {
53
65
  this._api = api.useFunctionUrl(this.url);
54
66
  return this;
55
67
  }
56
68
  /**
57
- * Retrieve the injected API instance.
69
+ * Retrieves the injected API instance.
58
70
  *
59
71
  * @returns The API instance.
60
- * @throws {@link Error} if no API has been provided via {@link useApi}.
72
+ * @throws Error when no API has been provided via {@link useApi}.
61
73
  */
62
74
  get api() {
63
75
  if (!this._api)
@@ -65,27 +77,29 @@ export class IBackendFunction {
65
77
  return this._api;
66
78
  }
67
79
  /**
68
- * Retrieve the registered route names.
80
+ * Returns the route names registered on the underlying API.
69
81
  *
70
82
  * @returns The array of allowed route names.
71
- * @throws {@link Error} if no routes have been provided via {@link useRoutes}.
83
+ * @throws Error when the API has not been injected, or when its routes have not been configured.
72
84
  */
73
85
  get routes() {
74
86
  return this.api.routes;
75
87
  }
76
88
  /**
77
- * Route an incoming function request to the appropriate API method.
89
+ * Dispatches an incoming function request to the underlying API.
78
90
  *
79
91
  * @remarks
80
- * Validates that the requested route is registered, delegates to the API, and
81
- * converts date fields in the response payload to Firestore Timestamps.
92
+ * Rejects unauthenticated requests with `HttpsError("unauthenticated")` and
93
+ * wraps unexpected API errors in `HttpsError("internal")`. Existing
94
+ * {@link HttpsError} instances are re-thrown unchanged.
82
95
  *
83
96
  * @typeParam REQ - The request payload type.
84
97
  * @typeParam RES - The response document data type.
85
98
  * @param request - The incoming function request containing route and data.
99
+ * @param isAuthenticated - Whether the caller has been authenticated upstream.
86
100
  * @returns The function response wrapping the API result.
87
- * @throws {@link HttpsError} with `invalid-argument` if the route is not registered.
88
- * @throws {@link HttpsError} with `internal` if the API method throws an unexpected error.
101
+ * @throws {@link HttpsError} with `unauthenticated` when `isAuthenticated` is `false`.
102
+ * @throws {@link HttpsError} with `internal` when the API method throws an unexpected error.
89
103
  */
90
104
  async ingress(request, isAuthenticated) {
91
105
  if (!isAuthenticated)
@@ -115,12 +129,15 @@ export class IBackendFunction {
115
129
  return onCall({ region: this.region, serviceAccount: this.serviceAccount }, async (req) => this.ingress(req.data, !!req.auth));
116
130
  }
117
131
  /**
118
- * Build and return a Firebase Https Cloud Function.
132
+ * Builds a Firebase HTTPS Cloud Function exposing each route at `POST /<route>`.
119
133
  *
120
134
  * @remarks
121
135
  * Wraps {@link ingress} in a Firebase `onRequest` handler configured with the
122
- * specified region and service account.
136
+ * function's region and service account. When `auth` is omitted, a default
137
+ * OIDC middleware built by {@link buildCheckServiceAuth} guards the function.
138
+ * Pass `null` explicitly to disable authentication.
123
139
  *
140
+ * @param auth - Authentication middleware to install. Omit for the default OIDC check; pass `null` to disable.
124
141
  * @returns A Firebase {@link HttpsFunction} ready for deployment.
125
142
  */
126
143
  buildHttpsFunction(auth) {
@@ -1 +1 @@
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;AAG9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAUxE;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,gBAAgB;IAgBE;IAV5B,IAAI,CAAO;IAErB;;;;;;;OAOG;IACH,YAAsC,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;IAAG,CAAC;IAEvE,IAAW,GAAG;QACZ,OAAO,WAAW,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,uBAAuB,IAAI,CAAC,IAAI,EAAE,CAAC;IACpF,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IACD,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IACD,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IACD,IAAW,cAAc;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;IACpC,CAAC;IACD,IAAc,SAAS;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC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CAAC;gBACF,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;oBAChC,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;oBAEvD,GAAG;yBACA,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC;yBAClC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBACrC,CAAC;qBAAM,CAAC;oBACN,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAEzD,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;oBAExD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBACnB,KAAK,EAAE;4BACL,IAAI,EAAE,EAAE;4BACR,MAAM,EAAE,UAAU;4BAClB,OAAO;yBACR;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CACd;YACE,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,cAAc,EAAE,IAAI,CAAC,cAAc;SACpC,EACD,GAAG,CACJ,CAAC;IACJ,CAAC;CACF"}
@@ -83,18 +83,37 @@ export declare class Store<DTO extends DocumentKeyAdmin> {
83
83
  * @returns The persisted document including its generated key metadata.
84
84
  */
85
85
  create(doc: CreateInput<DTO>): Promise<DTO>;
86
+ /**
87
+ * Returns a document ID, generating a short UUID when none is supplied.
88
+ *
89
+ * @param id - Optional ID to use unchanged.
90
+ * @returns The provided `id`, or a freshly generated short UUID.
91
+ */
86
92
  createId(id?: string): string;
87
93
  /**
88
- * Update an existing document by merging partial data.
94
+ * Updates an existing document by merging partial data.
89
95
  *
90
96
  * @param id - The document ID to update.
91
97
  * @param doc - The partial document data to merge.
92
- * @returns The updated document including its key metadata.
98
+ * @param requestChanges - When `true`, the result includes the list of dot-delimited paths that changed.
99
+ * @returns The updated document plus the optionally-populated list of changed paths.
93
100
  */
94
101
  update(id: string, doc: Partial<DTO>, requestChanges?: boolean): Promise<{
95
102
  updated: DTO;
96
103
  changedPaths: string[];
97
104
  }>;
105
+ /**
106
+ * Compares a partial document against the persisted version and returns changed paths.
107
+ *
108
+ * @remarks
109
+ * Only the keys present on `doc` are considered; the persisted document is
110
+ * narrowed to the same key set before comparison so unmentioned fields don't
111
+ * appear as changes.
112
+ *
113
+ * @param id - The document ID.
114
+ * @param doc - Partial document data to diff against the persisted version.
115
+ * @returns Dot-delimited paths whose values differ between persisted and provided data.
116
+ */
98
117
  compare(id: string, doc: Partial<DTO>): Promise<string[]>;
99
118
  /**
100
119
  * Delete one or more documents by their IDs.
@@ -1 +1 @@
1
- {"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../../src/store/Store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,EACL,aAAa,EACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EACjB,MAAM,uCAAuC,CAAC;AAO/C;;;;;;;;GAQG;AACH,qBAAa,KAAK,CAAC,GAAG,SAAS,gBAAgB;aAW3B,cAAc,EAAE,MAAM;aACtB,SAAS,EAAE,MAAM;IACjC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,sBAAsB,CAAC,GAAG,CAAC;IAZ5D,SAAS,CAAC,GAAG,CAAC,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAEzC;;;;;;OAMG;gBAEe,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,sBAAsB,C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,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC;IAI9C;;;;;;OAMG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAW1C;;;;;OAKG;IACU,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjD;;;;;OAKG;IACU,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAOxD;;;;;OAKG;IACI,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAIpC;;;;;;;OAOG;IACU,MAAM,CACjB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EACjB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;QAAE,OAAO,EAAE,GAAG,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAmBpD;;;;;;;;;;;OAWG;IACU,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAWtE;;;;OAIG;IACU,MAAM,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD;;;;OAIG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5D;;;;;OAKG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM;CAGpC"}
@@ -145,15 +145,22 @@ export class Store {
145
145
  await ref.set({ ...doc, id });
146
146
  return this.get(id);
147
147
  }
148
+ /**
149
+ * Returns a document ID, generating a short UUID when none is supplied.
150
+ *
151
+ * @param id - Optional ID to use unchanged.
152
+ * @returns The provided `id`, or a freshly generated short UUID.
153
+ */
148
154
  createId(id) {
149
155
  return id ?? uuid.generate();
150
156
  }
151
157
  /**
152
- * Update an existing document by merging partial data.
158
+ * Updates an existing document by merging partial data.
153
159
  *
154
160
  * @param id - The document ID to update.
155
161
  * @param doc - The partial document data to merge.
156
- * @returns The updated document including its key metadata.
162
+ * @param requestChanges - When `true`, the result includes the list of dot-delimited paths that changed.
163
+ * @returns The updated document plus the optionally-populated list of changed paths.
157
164
  */
158
165
  async update(id, doc, requestChanges) {
159
166
  const entry = this.ref(id);
@@ -168,9 +175,21 @@ export class Store {
168
175
  : [],
169
176
  };
170
177
  }
178
+ /**
179
+ * Compares a partial document against the persisted version and returns changed paths.
180
+ *
181
+ * @remarks
182
+ * Only the keys present on `doc` are considered; the persisted document is
183
+ * narrowed to the same key set before comparison so unmentioned fields don't
184
+ * appear as changes.
185
+ *
186
+ * @param id - The document ID.
187
+ * @param doc - Partial document data to diff against the persisted version.
188
+ * @returns Dot-delimited paths whose values differ between persisted and provided data.
189
+ */
171
190
  async compare(id, doc) {
172
191
  const _current = await this.get(id);
173
- // onl compare provided props (doc)
192
+ // only compare provided props (doc)
174
193
  const current = stripObject(_current, Object.keys(doc));
175
194
  return compare(current, doc).filter((change) => change.split(".")[0]);
176
195
  }