firebase-functions 6.6.0 → 7.0.0-rc.1

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 (156) hide show
  1. package/lib/_virtual/rolldown_runtime.js +34 -0
  2. package/lib/bin/firebase-functions.js +78 -103
  3. package/lib/common/app.js +35 -55
  4. package/lib/common/change.js +54 -75
  5. package/lib/common/config.js +41 -41
  6. package/lib/common/debug.js +23 -47
  7. package/lib/common/encoding.js +59 -82
  8. package/lib/common/onInit.js +26 -28
  9. package/lib/common/options.js +22 -42
  10. package/lib/common/params.d.ts +6 -6
  11. package/lib/common/params.js +0 -23
  12. package/lib/common/providers/database.js +270 -300
  13. package/lib/common/providers/firestore.js +66 -92
  14. package/lib/common/providers/https.d.ts +0 -1
  15. package/lib/common/providers/https.js +537 -539
  16. package/lib/common/providers/identity.js +393 -444
  17. package/lib/common/providers/tasks.js +64 -98
  18. package/lib/common/timezone.js +544 -542
  19. package/lib/common/trace.d.ts +0 -1
  20. package/lib/common/trace.js +63 -55
  21. package/lib/common/utilities/assertions.d.ts +11 -0
  22. package/lib/common/utilities/assertions.js +18 -0
  23. package/lib/common/utilities/encoder.js +20 -37
  24. package/lib/common/utilities/path-pattern.js +106 -132
  25. package/lib/common/utilities/path.js +28 -27
  26. package/lib/common/utilities/utils.js +23 -45
  27. package/lib/esm/_virtual/rolldown_runtime.mjs +16 -0
  28. package/lib/esm/bin/firebase-functions.mjs +91 -0
  29. package/lib/esm/common/app.mjs +39 -0
  30. package/lib/esm/common/change.mjs +57 -0
  31. package/lib/esm/common/config.mjs +45 -0
  32. package/lib/esm/common/debug.mjs +28 -0
  33. package/lib/esm/common/encoding.mjs +69 -0
  34. package/lib/esm/common/onInit.mjs +33 -0
  35. package/lib/esm/common/options.mjs +22 -0
  36. package/lib/esm/common/params.mjs +1 -0
  37. package/lib/esm/common/providers/database.mjs +269 -0
  38. package/lib/esm/common/providers/firestore.mjs +78 -0
  39. package/lib/esm/common/providers/https.mjs +573 -0
  40. package/lib/esm/common/providers/identity.mjs +428 -0
  41. package/lib/esm/common/providers/tasks.mjs +67 -0
  42. package/lib/esm/common/timezone.mjs +544 -0
  43. package/lib/esm/common/trace.mjs +73 -0
  44. package/lib/esm/common/utilities/assertions.mjs +17 -0
  45. package/lib/esm/common/utilities/encoder.mjs +21 -0
  46. package/lib/esm/common/utilities/path-pattern.mjs +116 -0
  47. package/lib/esm/common/utilities/path.mjs +35 -0
  48. package/lib/esm/common/utilities/utils.mjs +29 -0
  49. package/lib/esm/function-configuration.mjs +1 -0
  50. package/lib/esm/logger/common.mjs +23 -0
  51. package/lib/esm/logger/compat.mjs +25 -0
  52. package/lib/esm/logger/index.mjs +131 -0
  53. package/lib/esm/params/index.mjs +160 -0
  54. package/lib/esm/params/types.mjs +400 -0
  55. package/lib/esm/runtime/loader.mjs +132 -0
  56. package/lib/esm/runtime/manifest.mjs +134 -0
  57. package/lib/esm/types/global.d.mjs +1 -0
  58. package/lib/esm/v1/cloud-functions.mjs +206 -0
  59. package/lib/esm/v1/config.mjs +14 -0
  60. package/lib/esm/v1/function-builder.mjs +252 -0
  61. package/lib/esm/v1/function-configuration.mjs +72 -0
  62. package/lib/esm/v1/index.mjs +27 -0
  63. package/lib/esm/v1/providers/analytics.mjs +212 -0
  64. package/lib/esm/v1/providers/auth.mjs +156 -0
  65. package/lib/esm/v1/providers/database.mjs +243 -0
  66. package/lib/esm/v1/providers/firestore.mjs +131 -0
  67. package/lib/esm/v1/providers/https.mjs +82 -0
  68. package/lib/esm/v1/providers/pubsub.mjs +175 -0
  69. package/lib/esm/v1/providers/remoteConfig.mjs +64 -0
  70. package/lib/esm/v1/providers/storage.mjs +163 -0
  71. package/lib/esm/v1/providers/tasks.mjs +63 -0
  72. package/lib/esm/v1/providers/testLab.mjs +94 -0
  73. package/lib/esm/v2/core.mjs +4 -0
  74. package/lib/esm/v2/index.mjs +28 -0
  75. package/lib/esm/v2/options.mjs +102 -0
  76. package/lib/esm/v2/providers/alerts/alerts.mjs +85 -0
  77. package/lib/esm/v2/providers/alerts/appDistribution.mjs +75 -0
  78. package/lib/esm/v2/providers/alerts/billing.mjs +51 -0
  79. package/lib/esm/v2/providers/alerts/crashlytics.mjs +122 -0
  80. package/lib/esm/v2/providers/alerts/index.mjs +22 -0
  81. package/lib/esm/v2/providers/alerts/performance.mjs +66 -0
  82. package/lib/esm/v2/providers/database.mjs +197 -0
  83. package/lib/esm/v2/providers/dataconnect.mjs +130 -0
  84. package/lib/esm/v2/providers/eventarc.mjs +51 -0
  85. package/lib/esm/v2/providers/firestore.mjs +294 -0
  86. package/lib/esm/v2/providers/https.mjs +210 -0
  87. package/lib/esm/v2/providers/identity.mjs +103 -0
  88. package/lib/esm/v2/providers/pubsub.mjs +148 -0
  89. package/lib/esm/v2/providers/remoteConfig.mjs +52 -0
  90. package/lib/esm/v2/providers/scheduler.mjs +84 -0
  91. package/lib/esm/v2/providers/storage.mjs +155 -0
  92. package/lib/esm/v2/providers/tasks.mjs +65 -0
  93. package/lib/esm/v2/providers/testLab.mjs +53 -0
  94. package/lib/esm/v2/trace.mjs +20 -0
  95. package/lib/function-configuration.d.ts +0 -0
  96. package/lib/function-configuration.js +0 -0
  97. package/lib/logger/common.js +21 -41
  98. package/lib/logger/compat.js +18 -33
  99. package/lib/logger/index.js +119 -130
  100. package/lib/params/index.d.ts +4 -2
  101. package/lib/params/index.js +150 -144
  102. package/lib/params/types.js +389 -423
  103. package/lib/runtime/loader.js +114 -148
  104. package/lib/runtime/manifest.js +106 -126
  105. package/lib/types/global.d.js +0 -0
  106. package/lib/v1/cloud-functions.d.ts +2 -2
  107. package/lib/v1/cloud-functions.js +193 -241
  108. package/lib/v1/config.d.ts +4 -7
  109. package/lib/v1/config.js +13 -75
  110. package/lib/v1/function-builder.js +239 -368
  111. package/lib/v1/function-configuration.js +70 -63
  112. package/lib/v1/index.js +118 -73
  113. package/lib/v1/providers/analytics.js +188 -235
  114. package/lib/v1/providers/auth.d.ts +2 -1
  115. package/lib/v1/providers/auth.js +159 -164
  116. package/lib/v1/providers/database.js +237 -242
  117. package/lib/v1/providers/firestore.js +131 -130
  118. package/lib/v1/providers/https.d.ts +2 -1
  119. package/lib/v1/providers/https.js +79 -86
  120. package/lib/v1/providers/pubsub.js +175 -172
  121. package/lib/v1/providers/remoteConfig.js +64 -68
  122. package/lib/v1/providers/storage.js +161 -163
  123. package/lib/v1/providers/tasks.d.ts +1 -1
  124. package/lib/v1/providers/tasks.js +65 -80
  125. package/lib/v1/providers/testLab.js +94 -94
  126. package/lib/v2/core.d.ts +1 -1
  127. package/lib/v2/core.js +5 -32
  128. package/lib/v2/index.d.ts +6 -3
  129. package/lib/v2/index.js +123 -75
  130. package/lib/v2/options.js +88 -114
  131. package/lib/v2/providers/alerts/alerts.js +76 -95
  132. package/lib/v2/providers/alerts/appDistribution.js +73 -78
  133. package/lib/v2/providers/alerts/billing.js +49 -53
  134. package/lib/v2/providers/alerts/crashlytics.js +110 -102
  135. package/lib/v2/providers/alerts/index.js +56 -53
  136. package/lib/v2/providers/alerts/performance.js +64 -74
  137. package/lib/v2/providers/database.js +177 -180
  138. package/lib/v2/providers/dataconnect.d.ts +95 -0
  139. package/lib/v2/providers/dataconnect.js +137 -0
  140. package/lib/v2/providers/eventarc.js +55 -77
  141. package/lib/v2/providers/firestore.js +262 -260
  142. package/lib/v2/providers/https.d.ts +3 -2
  143. package/lib/v2/providers/https.js +210 -247
  144. package/lib/v2/providers/identity.d.ts +2 -1
  145. package/lib/v2/providers/identity.js +96 -105
  146. package/lib/v2/providers/pubsub.js +149 -167
  147. package/lib/v2/providers/remoteConfig.js +54 -63
  148. package/lib/v2/providers/scheduler.js +84 -96
  149. package/lib/v2/providers/storage.js +147 -162
  150. package/lib/v2/providers/tasks.d.ts +1 -1
  151. package/lib/v2/providers/tasks.js +68 -95
  152. package/lib/v2/providers/testLab.js +55 -64
  153. package/lib/v2/trace.js +18 -19
  154. package/package.json +321 -88
  155. package/protos/compiledFirestore.mjs +3512 -0
  156. package/protos/update.sh +28 -7
@@ -0,0 +1,206 @@
1
+ import { warn } from "../logger/index.mjs";
2
+ import { SecretParam } from "../params/types.mjs";
3
+ import { RESET_VALUE, ResetValue } from "../common/options.mjs";
4
+ import { initV1Endpoint, initV1ScheduleTrigger } from "../runtime/manifest.mjs";
5
+ import { Change } from "../common/change.mjs";
6
+ import { convertIfPresent, copyIfPresent, durationFromSeconds, serviceAccountFromShorthand } from "../common/encoding.mjs";
7
+ import { withInit } from "../common/onInit.mjs";
8
+ import { DEFAULT_FAILURE_POLICY } from "./function-configuration.mjs";
9
+
10
+ //#region src/v1/cloud-functions.ts
11
+ /** @internal */
12
+ const WILDCARD_REGEX = new RegExp("{[^/{}]*}", "g");
13
+ /** @internal */
14
+ function makeCloudFunction({ contextOnlyHandler, dataConstructor = (raw) => raw.data, eventType, handler, labels = {}, legacyEventType, options = {}, provider, service, triggerResource }) {
15
+ handler = withInit(handler ?? contextOnlyHandler);
16
+ const cloudFunction = (data, context) => {
17
+ if (legacyEventType && context.eventType === legacyEventType) {
18
+ context.eventType = provider + "." + eventType;
19
+ context.resource = {
20
+ service,
21
+ name: context.resource
22
+ };
23
+ }
24
+ const event = {
25
+ data,
26
+ context
27
+ };
28
+ if (provider === "google.firebase.database") {
29
+ context.authType = _detectAuthType(event);
30
+ if (context.authType !== "ADMIN") {
31
+ context.auth = _makeAuth(event, context.authType);
32
+ } else {
33
+ delete context.auth;
34
+ }
35
+ }
36
+ if (triggerResource() == null) {
37
+ Object.defineProperty(context, "params", { get: () => {
38
+ throw new Error("context.params is not available when using the handler namespace.");
39
+ } });
40
+ } else {
41
+ context.params = context.params || _makeParams(context, triggerResource);
42
+ }
43
+ let promise;
44
+ if (labels && labels["deployment-scheduled"]) {
45
+ promise = contextOnlyHandler(context);
46
+ } else {
47
+ const dataOrChange = dataConstructor(event);
48
+ promise = handler(dataOrChange, context);
49
+ }
50
+ if (typeof promise === "undefined") {
51
+ warn("Function returned undefined, expected Promise or value");
52
+ }
53
+ return Promise.resolve(promise);
54
+ };
55
+ Object.defineProperty(cloudFunction, "__trigger", { get: () => {
56
+ if (triggerResource() == null) {
57
+ return {};
58
+ }
59
+ const trigger = {
60
+ ...optionsToTrigger(options),
61
+ eventTrigger: {
62
+ resource: triggerResource(),
63
+ eventType: legacyEventType || provider + "." + eventType,
64
+ service
65
+ }
66
+ };
67
+ if (!!labels && Object.keys(labels).length) {
68
+ trigger.labels = {
69
+ ...trigger.labels,
70
+ ...labels
71
+ };
72
+ }
73
+ return trigger;
74
+ } });
75
+ Object.defineProperty(cloudFunction, "__endpoint", { get: () => {
76
+ if (triggerResource() == null) {
77
+ return undefined;
78
+ }
79
+ const endpoint = {
80
+ platform: "gcfv1",
81
+ ...initV1Endpoint(options),
82
+ ...optionsToEndpoint(options)
83
+ };
84
+ if (options.schedule) {
85
+ endpoint.scheduleTrigger = initV1ScheduleTrigger(options.schedule.schedule, options);
86
+ copyIfPresent(endpoint.scheduleTrigger, options.schedule, "timeZone");
87
+ copyIfPresent(endpoint.scheduleTrigger.retryConfig, options.schedule.retryConfig, "retryCount", "maxDoublings", "maxBackoffDuration", "maxRetryDuration", "minBackoffDuration");
88
+ } else {
89
+ endpoint.eventTrigger = {
90
+ eventType: legacyEventType || provider + "." + eventType,
91
+ eventFilters: { resource: triggerResource() },
92
+ retry: !!options.failurePolicy
93
+ };
94
+ }
95
+ endpoint.labels = { ...endpoint.labels };
96
+ return endpoint;
97
+ } });
98
+ if (options.schedule) {
99
+ cloudFunction.__requiredAPIs = [{
100
+ api: "cloudscheduler.googleapis.com",
101
+ reason: "Needed for scheduled functions."
102
+ }];
103
+ }
104
+ cloudFunction.run = handler || contextOnlyHandler;
105
+ return cloudFunction;
106
+ }
107
+ function _makeParams(context, triggerResourceGetter) {
108
+ if (context.params) {
109
+ return context.params;
110
+ }
111
+ if (!context.resource) {
112
+ return {};
113
+ }
114
+ const triggerResource = triggerResourceGetter();
115
+ const wildcards = triggerResource.match(WILDCARD_REGEX);
116
+ const params = {};
117
+ const eventResourceParts = context?.resource?.name?.split?.("/");
118
+ if (wildcards && eventResourceParts) {
119
+ const triggerResourceParts = triggerResource.split("/");
120
+ for (const wildcard of wildcards) {
121
+ const wildcardNoBraces = wildcard.slice(1, -1);
122
+ const position = triggerResourceParts.indexOf(wildcard);
123
+ params[wildcardNoBraces] = eventResourceParts[position];
124
+ }
125
+ }
126
+ return params;
127
+ }
128
+ function _makeAuth(event, authType) {
129
+ if (authType === "UNAUTHENTICATED") {
130
+ return null;
131
+ }
132
+ return {
133
+ uid: event.context?.auth?.variable?.uid,
134
+ token: event.context?.auth?.variable?.token
135
+ };
136
+ }
137
+ function _detectAuthType(event) {
138
+ if (event.context?.auth?.admin) {
139
+ return "ADMIN";
140
+ }
141
+ if (event.context?.auth?.variable) {
142
+ return "USER";
143
+ }
144
+ return "UNAUTHENTICATED";
145
+ }
146
+ /** @hidden */
147
+ function optionsToTrigger(options) {
148
+ const trigger = {};
149
+ copyIfPresent(trigger, options, "regions", "schedule", "minInstances", "maxInstances", "ingressSettings", "vpcConnectorEgressSettings", "vpcConnector", "labels", "secrets");
150
+ convertIfPresent(trigger, options, "failurePolicy", "failurePolicy", (policy) => {
151
+ if (policy === false) {
152
+ return undefined;
153
+ } else if (policy === true) {
154
+ return DEFAULT_FAILURE_POLICY;
155
+ } else {
156
+ return policy;
157
+ }
158
+ });
159
+ convertIfPresent(trigger, options, "timeout", "timeoutSeconds", durationFromSeconds);
160
+ convertIfPresent(trigger, options, "availableMemoryMb", "memory", (mem) => {
161
+ const memoryLookup = {
162
+ "128MB": 128,
163
+ "256MB": 256,
164
+ "512MB": 512,
165
+ "1GB": 1024,
166
+ "2GB": 2048,
167
+ "4GB": 4096,
168
+ "8GB": 8192
169
+ };
170
+ return memoryLookup[mem];
171
+ });
172
+ convertIfPresent(trigger, options, "serviceAccountEmail", "serviceAccount", serviceAccountFromShorthand);
173
+ return trigger;
174
+ }
175
+ function optionsToEndpoint(options) {
176
+ const endpoint = {};
177
+ copyIfPresent(endpoint, options, "omit", "minInstances", "maxInstances", "ingressSettings", "labels", "timeoutSeconds");
178
+ convertIfPresent(endpoint, options, "region", "regions");
179
+ convertIfPresent(endpoint, options, "serviceAccountEmail", "serviceAccount", (sa) => sa);
180
+ convertIfPresent(endpoint, options, "secretEnvironmentVariables", "secrets", (secrets) => secrets.map((secret) => ({ key: secret instanceof SecretParam ? secret.name : secret })));
181
+ if (options?.vpcConnector !== undefined) {
182
+ if (options.vpcConnector === null || options.vpcConnector instanceof ResetValue) {
183
+ endpoint.vpc = RESET_VALUE;
184
+ } else {
185
+ const vpc = { connector: options.vpcConnector };
186
+ convertIfPresent(vpc, options, "egressSettings", "vpcConnectorEgressSettings");
187
+ endpoint.vpc = vpc;
188
+ }
189
+ }
190
+ convertIfPresent(endpoint, options, "availableMemoryMb", "memory", (mem) => {
191
+ const memoryLookup = {
192
+ "128MB": 128,
193
+ "256MB": 256,
194
+ "512MB": 512,
195
+ "1GB": 1024,
196
+ "2GB": 2048,
197
+ "4GB": 4096,
198
+ "8GB": 8192
199
+ };
200
+ return typeof mem === "object" ? mem : memoryLookup[mem];
201
+ });
202
+ return endpoint;
203
+ }
204
+
205
+ //#endregion
206
+ export { Change, makeCloudFunction, optionsToEndpoint, optionsToTrigger };
@@ -0,0 +1,14 @@
1
+ import { firebaseConfig } from "../common/config.mjs";
2
+
3
+ //#region src/v1/config.ts
4
+ /**
5
+ * @deprecated `functions.config()` has been removed in firebase-functions v7.
6
+ * Migrate to environment parameters using the `params` module immediately.
7
+ * Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config
8
+ */
9
+ const config = (() => {
10
+ throw new Error("functions.config() has been removed in firebase-functions v7. " + "Migrate to environment parameters using the params module. " + "Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config");
11
+ });
12
+
13
+ //#endregion
14
+ export { config, firebaseConfig };
@@ -0,0 +1,252 @@
1
+ import { Expression, SecretParam } from "../params/types.mjs";
2
+ import { ResetValue } from "../common/options.mjs";
3
+ import { INGRESS_SETTINGS_OPTIONS, MAX_NUMBER_USER_LABELS, MAX_TIMEOUT_SECONDS, VALID_MEMORY_OPTIONS, VPC_EGRESS_SETTINGS_OPTIONS } from "./function-configuration.mjs";
4
+ import { _eventWithOptions } from "./providers/analytics.mjs";
5
+ import { _userWithOptions } from "./providers/auth.mjs";
6
+ import { _instanceWithOptions, _refWithOptions } from "./providers/database.mjs";
7
+ import { _databaseWithOptions, _documentWithOptions, _namespaceWithOptions } from "./providers/firestore.mjs";
8
+ import { _onCallWithOptions, _onRequestWithOptions } from "./providers/https.mjs";
9
+ import { _scheduleWithOptions, _topicWithOptions } from "./providers/pubsub.mjs";
10
+ import { _onUpdateWithOptions } from "./providers/remoteConfig.mjs";
11
+ import { _bucketWithOptions, _objectWithOptions } from "./providers/storage.mjs";
12
+ import { TaskQueueBuilder } from "./providers/tasks.mjs";
13
+ import { _testMatrixWithOpts } from "./providers/testLab.mjs";
14
+
15
+ //#region src/v1/function-builder.ts
16
+ /**
17
+ * Assert that the runtime options passed in are valid.
18
+ * @param runtimeOptions object containing memory and timeout information.
19
+ * @throws { Error } Memory and TimeoutSeconds values must be valid.
20
+ */
21
+ function assertRuntimeOptionsValid(runtimeOptions) {
22
+ const mem = runtimeOptions.memory;
23
+ if (mem && typeof mem !== "object" && !VALID_MEMORY_OPTIONS.includes(mem)) {
24
+ throw new Error(`The only valid memory allocation values are: ${VALID_MEMORY_OPTIONS.join(", ")}`);
25
+ }
26
+ if (typeof runtimeOptions.timeoutSeconds === "number" && (runtimeOptions.timeoutSeconds > MAX_TIMEOUT_SECONDS || runtimeOptions.timeoutSeconds < 0)) {
27
+ throw new Error(`TimeoutSeconds must be between 0 and ${MAX_TIMEOUT_SECONDS}`);
28
+ }
29
+ if (runtimeOptions.ingressSettings && !(runtimeOptions.ingressSettings instanceof ResetValue) && !INGRESS_SETTINGS_OPTIONS.includes(runtimeOptions.ingressSettings)) {
30
+ throw new Error(`The only valid ingressSettings values are: ${INGRESS_SETTINGS_OPTIONS.join(",")}`);
31
+ }
32
+ if (runtimeOptions.vpcConnectorEgressSettings && !(runtimeOptions.vpcConnectorEgressSettings instanceof ResetValue) && !VPC_EGRESS_SETTINGS_OPTIONS.includes(runtimeOptions.vpcConnectorEgressSettings)) {
33
+ throw new Error(`The only valid vpcConnectorEgressSettings values are: ${VPC_EGRESS_SETTINGS_OPTIONS.join(",")}`);
34
+ }
35
+ validateFailurePolicy(runtimeOptions.failurePolicy);
36
+ const serviceAccount = runtimeOptions.serviceAccount;
37
+ if (serviceAccount && !(serviceAccount === "default" || serviceAccount instanceof ResetValue || serviceAccount instanceof Expression || serviceAccount.includes("@"))) {
38
+ throw new Error(`serviceAccount must be set to 'default', a string expression, a service account email, or '{serviceAccountName}@'`);
39
+ }
40
+ if (runtimeOptions.labels) {
41
+ if (Object.keys(runtimeOptions.labels).length > MAX_NUMBER_USER_LABELS) {
42
+ throw new Error(`A function must not have more than ${MAX_NUMBER_USER_LABELS} user-defined labels.`);
43
+ }
44
+ const reservedKeys = Object.keys(runtimeOptions.labels).filter((key) => key.startsWith("deployment") || key.startsWith("firebase"));
45
+ if (reservedKeys.length) {
46
+ throw new Error(`Invalid labels: ${reservedKeys.join(", ")}. Labels may not start with reserved names 'deployment' or 'firebase'`);
47
+ }
48
+ const invalidLengthKeys = Object.keys(runtimeOptions.labels).filter((key) => key.length < 1 || key.length > 63);
49
+ if (invalidLengthKeys.length > 0) {
50
+ throw new Error(`Invalid labels: ${invalidLengthKeys.join(", ")}. Label keys must be between 1 and 63 characters in length.`);
51
+ }
52
+ const invalidLengthValues = Object.values(runtimeOptions.labels).filter((value) => value.length > 63);
53
+ if (invalidLengthValues.length > 0) {
54
+ throw new Error(`Invalid labels: ${invalidLengthValues.join(", ")}. Label values must be less than 64 charcters.`);
55
+ }
56
+ const validKeyPattern = /^[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}$/u;
57
+ const invalidKeys = Object.keys(runtimeOptions.labels).filter((key) => !validKeyPattern.test(key));
58
+ if (invalidKeys.length > 0) {
59
+ throw new Error(`Invalid labels: ${invalidKeys.join(", ")}. Label keys can only contain lowercase letters, international characters, numbers, _ or -, and must start with a letter.`);
60
+ }
61
+ const validValuePattern = /^[\p{Ll}\p{Lo}\p{N}_-]{0,63}$/u;
62
+ const invalidValues = Object.values(runtimeOptions.labels).filter((value) => !validValuePattern.test(value));
63
+ if (invalidValues.length > 0) {
64
+ throw new Error(`Invalid labels: ${invalidValues.join(", ")}. Label values can only contain lowercase letters, international characters, numbers, _ or -.`);
65
+ }
66
+ }
67
+ if (typeof runtimeOptions.invoker === "string" && runtimeOptions.invoker.length === 0) {
68
+ throw new Error("Invalid service account for function invoker, must be a non-empty string");
69
+ }
70
+ if (runtimeOptions.invoker !== undefined && Array.isArray(runtimeOptions.invoker)) {
71
+ if (runtimeOptions.invoker.length === 0) {
72
+ throw new Error("Invalid invoker array, must contain at least 1 service account entry");
73
+ }
74
+ for (const serviceAccount$1 of runtimeOptions.invoker) {
75
+ if (serviceAccount$1.length === 0) {
76
+ throw new Error("Invalid invoker array, a service account must be a non-empty string");
77
+ }
78
+ if (serviceAccount$1 === "public") {
79
+ throw new Error("Invalid invoker array, a service account cannot be set to the 'public' identifier");
80
+ }
81
+ if (serviceAccount$1 === "private") {
82
+ throw new Error("Invalid invoker array, a service account cannot be set to the 'private' identifier");
83
+ }
84
+ }
85
+ }
86
+ if (runtimeOptions.secrets !== undefined) {
87
+ const invalidSecrets = runtimeOptions.secrets.filter((s) => !/^[A-Za-z\d\-_]+$/.test(s instanceof SecretParam ? s.name : s));
88
+ if (invalidSecrets.length > 0) {
89
+ throw new Error(`Invalid secrets: ${invalidSecrets.join(",")}. ` + "Secret must be configured using the resource id (e.g. API_KEY)");
90
+ }
91
+ }
92
+ if ("allowInvalidAppCheckToken" in runtimeOptions) {
93
+ throw new Error("runWith option \"allowInvalidAppCheckToken\" has been inverted and " + "renamed \"enforceAppCheck\"");
94
+ }
95
+ return true;
96
+ }
97
+ function validateFailurePolicy(policy) {
98
+ if (typeof policy === "boolean" || typeof policy === "undefined") {
99
+ return;
100
+ }
101
+ if (typeof policy !== "object") {
102
+ throw new Error(`failurePolicy must be a boolean or an object.`);
103
+ }
104
+ const retry = policy.retry;
105
+ if (typeof retry !== "object" || Object.keys(retry).length) {
106
+ throw new Error("failurePolicy.retry must be an empty object.");
107
+ }
108
+ }
109
+ /**
110
+ * Assert regions specified are valid.
111
+ * @param regions list of regions.
112
+ * @throws { Error } Regions must be in list of supported regions.
113
+ */
114
+ function assertRegionsAreValid(regions) {
115
+ if (!regions.length) {
116
+ throw new Error("You must specify at least one region");
117
+ }
118
+ return true;
119
+ }
120
+ /**
121
+ * Configure the regions that the function is deployed to.
122
+ * @param regions One of more region strings.
123
+ * @example
124
+ * functions.region('us-east1')
125
+ * @example
126
+ * functions.region('us-east1', 'us-central1')
127
+ */
128
+ function region(...regions) {
129
+ if (assertRegionsAreValid(regions)) {
130
+ return new FunctionBuilder({ regions });
131
+ }
132
+ }
133
+ /**
134
+ * Configure runtime options for the function.
135
+ * @param runtimeOptions Object with optional fields:
136
+ * 1. `memory`: amount of memory to allocate to the function, possible values
137
+ * are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'.
138
+ * 2. `timeoutSeconds`: timeout for the function in seconds, possible values are
139
+ * 0 to 540.
140
+ * 3. `failurePolicy`: failure policy of the function, with boolean `true` being
141
+ * equivalent to providing an empty retry object.
142
+ * 4. `vpcConnector`: id of a VPC connector in same project and region.
143
+ * 5. `vpcConnectorEgressSettings`: when a vpcConnector is set, control which
144
+ * egress traffic is sent through the vpcConnector.
145
+ * 6. `serviceAccount`: Specific service account for the function.
146
+ * 7. `ingressSettings`: ingress settings for the function, which control where a HTTPS
147
+ * function can be called from.
148
+ *
149
+ * Value must not be null.
150
+ */
151
+ function runWith(runtimeOptions) {
152
+ if (assertRuntimeOptionsValid(runtimeOptions)) {
153
+ return new FunctionBuilder(runtimeOptions);
154
+ }
155
+ }
156
+ var FunctionBuilder = class {
157
+ constructor(options) {
158
+ this.options = options;
159
+ }
160
+ /**
161
+ * Configure the regions that the function is deployed to.
162
+ * @param regions One or more region strings.
163
+ * @example
164
+ * functions.region('us-east1')
165
+ * @example
166
+ * functions.region('us-east1', 'us-central1')
167
+ */
168
+ region(...regions) {
169
+ if (assertRegionsAreValid(regions)) {
170
+ this.options.regions = regions;
171
+ return this;
172
+ }
173
+ }
174
+ /**
175
+ * Configure runtime options for the function.
176
+ * @param runtimeOptions Object with optional fields:
177
+ * 1. `memory`: amount of memory to allocate to the function, possible values
178
+ * are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'.
179
+ * 2. `timeoutSeconds`: timeout for the function in seconds, possible values are
180
+ * 0 to 540.
181
+ * 3. `failurePolicy`: failure policy of the function, with boolean `true` being
182
+ * equivalent to providing an empty retry object.
183
+ * 4. `vpcConnector`: id of a VPC connector in the same project and region
184
+ * 5. `vpcConnectorEgressSettings`: when a `vpcConnector` is set, control which
185
+ * egress traffic is sent through the `vpcConnector`.
186
+ *
187
+ * Value must not be null.
188
+ */
189
+ runWith(runtimeOptions) {
190
+ if (assertRuntimeOptionsValid(runtimeOptions)) {
191
+ this.options = {
192
+ ...this.options,
193
+ ...runtimeOptions
194
+ };
195
+ return this;
196
+ }
197
+ }
198
+ get https() {
199
+ if (this.options.failurePolicy !== undefined) {
200
+ console.warn("RuntimeOptions.failurePolicy is not supported in https functions.");
201
+ }
202
+ return {
203
+ onRequest: (handler) => _onRequestWithOptions(handler, this.options),
204
+ onCall: (handler) => _onCallWithOptions(handler, this.options)
205
+ };
206
+ }
207
+ get tasks() {
208
+ return { taskQueue: (options) => {
209
+ return new TaskQueueBuilder(options, this.options);
210
+ } };
211
+ }
212
+ get database() {
213
+ return {
214
+ instance: (instance) => _instanceWithOptions(instance, this.options),
215
+ ref: (path) => _refWithOptions(path, this.options)
216
+ };
217
+ }
218
+ get firestore() {
219
+ return {
220
+ document: (path) => _documentWithOptions(path, this.options),
221
+ namespace: (namespace) => _namespaceWithOptions(namespace, this.options),
222
+ database: (database) => _databaseWithOptions(database, this.options)
223
+ };
224
+ }
225
+ get analytics() {
226
+ return { event: (analyticsEventType) => _eventWithOptions(analyticsEventType, this.options) };
227
+ }
228
+ get remoteConfig() {
229
+ return { onUpdate: (handler) => _onUpdateWithOptions(handler, this.options) };
230
+ }
231
+ get storage() {
232
+ return {
233
+ bucket: (bucket) => _bucketWithOptions(this.options, bucket),
234
+ object: () => _objectWithOptions(this.options)
235
+ };
236
+ }
237
+ get pubsub() {
238
+ return {
239
+ topic: (topic) => _topicWithOptions(topic, this.options),
240
+ schedule: (schedule) => _scheduleWithOptions(schedule, this.options)
241
+ };
242
+ }
243
+ get auth() {
244
+ return { user: (userOptions) => _userWithOptions(this.options, userOptions) };
245
+ }
246
+ get testLab() {
247
+ return { testMatrix: () => _testMatrixWithOpts(this.options) };
248
+ }
249
+ };
250
+
251
+ //#endregion
252
+ export { FunctionBuilder, region, runWith };
@@ -0,0 +1,72 @@
1
+ import { RESET_VALUE } from "../common/options.mjs";
2
+
3
+ //#region src/v1/function-configuration.ts
4
+ /**
5
+ * List of all regions supported by Cloud Functions.
6
+ */
7
+ const SUPPORTED_REGIONS = [
8
+ "us-central1",
9
+ "us-east1",
10
+ "us-east4",
11
+ "us-west2",
12
+ "us-west3",
13
+ "us-west4",
14
+ "europe-central2",
15
+ "europe-west1",
16
+ "europe-west2",
17
+ "europe-west3",
18
+ "europe-west6",
19
+ "asia-east1",
20
+ "asia-east2",
21
+ "asia-northeast1",
22
+ "asia-northeast2",
23
+ "asia-northeast3",
24
+ "asia-south1",
25
+ "asia-southeast1",
26
+ "asia-southeast2",
27
+ "northamerica-northeast1",
28
+ "southamerica-east1",
29
+ "australia-southeast1"
30
+ ];
31
+ /**
32
+ * Cloud Functions min timeout value.
33
+ */
34
+ const MIN_TIMEOUT_SECONDS = 0;
35
+ /**
36
+ * Cloud Functions max timeout value.
37
+ */
38
+ const MAX_TIMEOUT_SECONDS = 540;
39
+ /**
40
+ * List of available memory options supported by Cloud Functions.
41
+ */
42
+ const VALID_MEMORY_OPTIONS = [
43
+ "128MB",
44
+ "256MB",
45
+ "512MB",
46
+ "1GB",
47
+ "2GB",
48
+ "4GB",
49
+ "8GB"
50
+ ];
51
+ /**
52
+ * List of available options for VpcConnectorEgressSettings.
53
+ */
54
+ const VPC_EGRESS_SETTINGS_OPTIONS = [
55
+ "VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED",
56
+ "PRIVATE_RANGES_ONLY",
57
+ "ALL_TRAFFIC"
58
+ ];
59
+ /**
60
+ * List of available options for IngressSettings.
61
+ */
62
+ const INGRESS_SETTINGS_OPTIONS = [
63
+ "INGRESS_SETTINGS_UNSPECIFIED",
64
+ "ALLOW_ALL",
65
+ "ALLOW_INTERNAL_ONLY",
66
+ "ALLOW_INTERNAL_AND_GCLB"
67
+ ];
68
+ const DEFAULT_FAILURE_POLICY = { retry: {} };
69
+ const MAX_NUMBER_USER_LABELS = 58;
70
+
71
+ //#endregion
72
+ export { DEFAULT_FAILURE_POLICY, INGRESS_SETTINGS_OPTIONS, MAX_NUMBER_USER_LABELS, MAX_TIMEOUT_SECONDS, MIN_TIMEOUT_SECONDS, RESET_VALUE, SUPPORTED_REGIONS, VALID_MEMORY_OPTIONS, VPC_EGRESS_SETTINGS_OPTIONS };
@@ -0,0 +1,27 @@
1
+ import { logger_exports } from "../logger/index.mjs";
2
+ import { params_exports } from "../params/index.mjs";
3
+ import { RESET_VALUE } from "../common/options.mjs";
4
+ import { firebaseConfig } from "../common/config.mjs";
5
+ import { setApp } from "../common/app.mjs";
6
+ import { Change } from "../common/change.mjs";
7
+ import { onInit } from "../common/onInit.mjs";
8
+ import { DEFAULT_FAILURE_POLICY, INGRESS_SETTINGS_OPTIONS, MAX_NUMBER_USER_LABELS, MAX_TIMEOUT_SECONDS, MIN_TIMEOUT_SECONDS, SUPPORTED_REGIONS, VALID_MEMORY_OPTIONS, VPC_EGRESS_SETTINGS_OPTIONS } from "./function-configuration.mjs";
9
+ import { makeCloudFunction, optionsToEndpoint, optionsToTrigger } from "./cloud-functions.mjs";
10
+ import { config } from "./config.mjs";
11
+ import { analytics_exports } from "./providers/analytics.mjs";
12
+ import { auth_exports } from "./providers/auth.mjs";
13
+ import { database_exports } from "./providers/database.mjs";
14
+ import { firestore_exports } from "./providers/firestore.mjs";
15
+ import { https_exports } from "./providers/https.mjs";
16
+ import { pubsub_exports } from "./providers/pubsub.mjs";
17
+ import { remoteConfig_exports } from "./providers/remoteConfig.mjs";
18
+ import { storage_exports } from "./providers/storage.mjs";
19
+ import { tasks_exports } from "./providers/tasks.mjs";
20
+ import { testLab_exports } from "./providers/testLab.mjs";
21
+ import { FunctionBuilder, region, runWith } from "./function-builder.mjs";
22
+
23
+ //#region src/v1/index.ts
24
+ const app = { setEmulatedAdminApp: setApp };
25
+
26
+ //#endregion
27
+ export { Change, DEFAULT_FAILURE_POLICY, FunctionBuilder, INGRESS_SETTINGS_OPTIONS, MAX_NUMBER_USER_LABELS, MAX_TIMEOUT_SECONDS, MIN_TIMEOUT_SECONDS, RESET_VALUE, SUPPORTED_REGIONS, VALID_MEMORY_OPTIONS, VPC_EGRESS_SETTINGS_OPTIONS, analytics_exports as analytics, app, auth_exports as auth, config, database_exports as database, firebaseConfig, firestore_exports as firestore, https_exports as https, logger_exports as logger, makeCloudFunction, onInit, optionsToEndpoint, optionsToTrigger, params_exports as params, pubsub_exports as pubsub, region, remoteConfig_exports as remoteConfig, runWith, storage_exports as storage, tasks_exports as tasks, testLab_exports as testLab };