firebase-admin 10.0.2 → 10.3.0

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 (194) hide show
  1. package/README.md +2 -1
  2. package/lib/app/core.d.ts +1 -1
  3. package/lib/app/core.js +1 -1
  4. package/lib/app/credential-factory.d.ts +1 -1
  5. package/lib/app/credential-factory.js +1 -1
  6. package/lib/app/credential-internal.d.ts +3 -1
  7. package/lib/app/credential-internal.js +18 -1
  8. package/lib/app/credential.d.ts +1 -1
  9. package/lib/app/credential.js +1 -1
  10. package/lib/app/firebase-app.d.ts +1 -1
  11. package/lib/app/firebase-app.js +1 -1
  12. package/lib/app/firebase-namespace.d.ts +1 -1
  13. package/lib/app/firebase-namespace.js +1 -1
  14. package/lib/app/index.d.ts +1 -1
  15. package/lib/app/index.js +1 -1
  16. package/lib/app/lifecycle.d.ts +1 -1
  17. package/lib/app/lifecycle.js +1 -1
  18. package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
  19. package/lib/app-check/app-check-api-client-internal.js +3 -3
  20. package/lib/app-check/app-check-api.d.ts +1 -1
  21. package/lib/app-check/app-check-api.js +1 -1
  22. package/lib/app-check/app-check-namespace.d.ts +1 -1
  23. package/lib/app-check/app-check-namespace.js +1 -1
  24. package/lib/app-check/app-check.d.ts +1 -1
  25. package/lib/app-check/app-check.js +1 -1
  26. package/lib/app-check/index.d.ts +1 -1
  27. package/lib/app-check/index.js +1 -1
  28. package/lib/app-check/token-generator.d.ts +1 -1
  29. package/lib/app-check/token-generator.js +2 -2
  30. package/lib/app-check/token-verifier.d.ts +1 -1
  31. package/lib/app-check/token-verifier.js +2 -2
  32. package/lib/auth/action-code-settings-builder.d.ts +1 -1
  33. package/lib/auth/action-code-settings-builder.js +1 -1
  34. package/lib/auth/auth-api-request.d.ts +1 -1
  35. package/lib/auth/auth-api-request.js +24 -4
  36. package/lib/auth/auth-config.d.ts +1 -1
  37. package/lib/auth/auth-config.js +1 -1
  38. package/lib/auth/auth-namespace.d.ts +4 -2
  39. package/lib/auth/auth-namespace.js +1 -1
  40. package/lib/auth/auth.d.ts +1 -1
  41. package/lib/auth/auth.js +1 -1
  42. package/lib/auth/base-auth.d.ts +29 -2
  43. package/lib/auth/base-auth.js +38 -1
  44. package/lib/auth/identifier.d.ts +1 -1
  45. package/lib/auth/identifier.js +1 -1
  46. package/lib/auth/index.d.ts +2 -2
  47. package/lib/auth/index.js +1 -1
  48. package/lib/auth/tenant-manager.d.ts +1 -1
  49. package/lib/auth/tenant-manager.js +1 -1
  50. package/lib/auth/tenant.d.ts +1 -1
  51. package/lib/auth/tenant.js +1 -1
  52. package/lib/auth/token-generator.d.ts +1 -1
  53. package/lib/auth/token-generator.js +1 -1
  54. package/lib/auth/token-verifier.d.ts +70 -1
  55. package/lib/auth/token-verifier.js +54 -7
  56. package/lib/auth/user-import-builder.d.ts +1 -1
  57. package/lib/auth/user-import-builder.js +1 -1
  58. package/lib/auth/user-record.d.ts +1 -1
  59. package/lib/auth/user-record.js +1 -1
  60. package/lib/credential/index.d.ts +1 -1
  61. package/lib/credential/index.js +1 -1
  62. package/lib/database/database-namespace.d.ts +1 -1
  63. package/lib/database/database-namespace.js +1 -1
  64. package/lib/database/database.d.ts +1 -1
  65. package/lib/database/database.js +1 -1
  66. package/lib/database/index.d.ts +1 -1
  67. package/lib/database/index.js +1 -1
  68. package/lib/default-namespace.d.ts +1 -1
  69. package/lib/default-namespace.js +1 -1
  70. package/lib/esm/eventarc/index.js +5 -0
  71. package/lib/esm/functions/index.js +5 -0
  72. package/lib/eventarc/cloudevent.d.ts +84 -0
  73. package/lib/eventarc/cloudevent.js +19 -0
  74. package/lib/eventarc/eventarc-client-internal.d.ts +18 -0
  75. package/lib/eventarc/eventarc-client-internal.js +205 -0
  76. package/lib/eventarc/eventarc-utils.d.ts +31 -0
  77. package/lib/eventarc/eventarc-utils.js +141 -0
  78. package/lib/eventarc/eventarc.d.ts +107 -0
  79. package/lib/eventarc/eventarc.js +139 -0
  80. package/lib/eventarc/index.d.ts +53 -0
  81. package/lib/eventarc/index.js +64 -0
  82. package/lib/firebase-namespace-api.d.ts +1 -1
  83. package/lib/firebase-namespace-api.js +1 -1
  84. package/lib/firestore/firestore-internal.d.ts +1 -1
  85. package/lib/firestore/firestore-internal.js +1 -1
  86. package/lib/firestore/firestore-namespace.d.ts +1 -1
  87. package/lib/firestore/firestore-namespace.js +1 -1
  88. package/lib/firestore/index.d.ts +1 -1
  89. package/lib/firestore/index.js +1 -1
  90. package/lib/functions/functions-api-client-internal.d.ts +32 -0
  91. package/lib/functions/functions-api-client-internal.js +279 -0
  92. package/lib/functions/functions-api.d.ts +67 -0
  93. package/lib/functions/functions-api.js +19 -0
  94. package/lib/functions/functions.d.ts +63 -0
  95. package/lib/functions/functions.js +99 -0
  96. package/lib/functions/index.d.ts +53 -0
  97. package/lib/functions/index.js +64 -0
  98. package/lib/index.d.ts +1 -1
  99. package/lib/index.js +1 -1
  100. package/lib/installations/index.d.ts +1 -1
  101. package/lib/installations/index.js +1 -1
  102. package/lib/installations/installations-namespace.d.ts +1 -1
  103. package/lib/installations/installations-namespace.js +1 -1
  104. package/lib/installations/installations-request-handler.d.ts +1 -1
  105. package/lib/installations/installations-request-handler.js +1 -1
  106. package/lib/installations/installations.d.ts +1 -1
  107. package/lib/installations/installations.js +1 -1
  108. package/lib/instance-id/index.d.ts +1 -1
  109. package/lib/instance-id/index.js +1 -1
  110. package/lib/instance-id/instance-id-namespace.d.ts +1 -1
  111. package/lib/instance-id/instance-id-namespace.js +1 -1
  112. package/lib/instance-id/instance-id.d.ts +1 -1
  113. package/lib/instance-id/instance-id.js +1 -1
  114. package/lib/machine-learning/index.d.ts +1 -1
  115. package/lib/machine-learning/index.js +1 -1
  116. package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
  117. package/lib/machine-learning/machine-learning-api-client.js +1 -1
  118. package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
  119. package/lib/machine-learning/machine-learning-namespace.js +1 -1
  120. package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
  121. package/lib/machine-learning/machine-learning-utils.js +1 -1
  122. package/lib/machine-learning/machine-learning.d.ts +1 -1
  123. package/lib/machine-learning/machine-learning.js +1 -1
  124. package/lib/messaging/batch-request-internal.d.ts +1 -1
  125. package/lib/messaging/batch-request-internal.js +1 -1
  126. package/lib/messaging/index.d.ts +1 -1
  127. package/lib/messaging/index.js +1 -1
  128. package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
  129. package/lib/messaging/messaging-api-request-internal.js +1 -1
  130. package/lib/messaging/messaging-api.d.ts +1 -1
  131. package/lib/messaging/messaging-api.js +1 -1
  132. package/lib/messaging/messaging-errors-internal.d.ts +1 -1
  133. package/lib/messaging/messaging-errors-internal.js +1 -1
  134. package/lib/messaging/messaging-internal.d.ts +1 -1
  135. package/lib/messaging/messaging-internal.js +1 -1
  136. package/lib/messaging/messaging-namespace.d.ts +1 -1
  137. package/lib/messaging/messaging-namespace.js +1 -1
  138. package/lib/messaging/messaging.d.ts +1 -1
  139. package/lib/messaging/messaging.js +1 -1
  140. package/lib/project-management/android-app.d.ts +1 -1
  141. package/lib/project-management/android-app.js +1 -1
  142. package/lib/project-management/app-metadata.d.ts +1 -1
  143. package/lib/project-management/app-metadata.js +1 -1
  144. package/lib/project-management/index.d.ts +1 -1
  145. package/lib/project-management/index.js +1 -1
  146. package/lib/project-management/ios-app.d.ts +1 -1
  147. package/lib/project-management/ios-app.js +1 -1
  148. package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
  149. package/lib/project-management/project-management-api-request-internal.js +1 -1
  150. package/lib/project-management/project-management-namespace.d.ts +1 -1
  151. package/lib/project-management/project-management-namespace.js +1 -1
  152. package/lib/project-management/project-management.d.ts +1 -1
  153. package/lib/project-management/project-management.js +1 -1
  154. package/lib/remote-config/index.d.ts +1 -1
  155. package/lib/remote-config/index.js +1 -1
  156. package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
  157. package/lib/remote-config/remote-config-api-client-internal.js +1 -1
  158. package/lib/remote-config/remote-config-api.d.ts +1 -1
  159. package/lib/remote-config/remote-config-api.js +1 -1
  160. package/lib/remote-config/remote-config-namespace.d.ts +1 -1
  161. package/lib/remote-config/remote-config-namespace.js +1 -1
  162. package/lib/remote-config/remote-config.d.ts +1 -1
  163. package/lib/remote-config/remote-config.js +1 -1
  164. package/lib/security-rules/index.d.ts +1 -1
  165. package/lib/security-rules/index.js +1 -1
  166. package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
  167. package/lib/security-rules/security-rules-api-client-internal.js +1 -1
  168. package/lib/security-rules/security-rules-internal.d.ts +1 -1
  169. package/lib/security-rules/security-rules-internal.js +1 -1
  170. package/lib/security-rules/security-rules-namespace.d.ts +1 -1
  171. package/lib/security-rules/security-rules-namespace.js +1 -1
  172. package/lib/security-rules/security-rules.d.ts +1 -1
  173. package/lib/security-rules/security-rules.js +1 -1
  174. package/lib/storage/index.d.ts +1 -1
  175. package/lib/storage/index.js +1 -1
  176. package/lib/storage/storage-namespace.d.ts +1 -1
  177. package/lib/storage/storage-namespace.js +1 -1
  178. package/lib/storage/storage.d.ts +1 -1
  179. package/lib/storage/storage.js +1 -1
  180. package/lib/utils/api-request.d.ts +1 -1
  181. package/lib/utils/api-request.js +3 -3
  182. package/lib/utils/crypto-signer.d.ts +1 -1
  183. package/lib/utils/crypto-signer.js +1 -1
  184. package/lib/utils/deep-copy.d.ts +1 -1
  185. package/lib/utils/deep-copy.js +1 -1
  186. package/lib/utils/error.d.ts +9 -1
  187. package/lib/utils/error.js +11 -1
  188. package/lib/utils/index.d.ts +43 -1
  189. package/lib/utils/index.js +72 -2
  190. package/lib/utils/jwt.d.ts +1 -1
  191. package/lib/utils/jwt.js +1 -1
  192. package/lib/utils/validator.d.ts +1 -1
  193. package/lib/utils/validator.js +1 -1
  194. package/package.json +44 -12
@@ -0,0 +1,279 @@
1
+ /*! firebase-admin v10.3.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ var __extends = (this && this.__extends) || (function () {
20
+ var extendStatics = function (d, b) {
21
+ extendStatics = Object.setPrototypeOf ||
22
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
24
+ return extendStatics(d, b);
25
+ };
26
+ return function (d, b) {
27
+ extendStatics(d, b);
28
+ function __() { this.constructor = d; }
29
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
30
+ };
31
+ })();
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.FirebaseFunctionsError = exports.FUNCTIONS_ERROR_CODE_MAPPING = exports.FunctionsApiClient = void 0;
34
+ var api_request_1 = require("../utils/api-request");
35
+ var error_1 = require("../utils/error");
36
+ var utils = require("../utils/index");
37
+ var validator = require("../utils/validator");
38
+ var CLOUD_TASKS_API_URL_FORMAT = 'https://cloudtasks.googleapis.com/v2/projects/{projectId}/locations/{locationId}/queues/{resourceId}/tasks';
39
+ var FIREBASE_FUNCTION_URL_FORMAT = 'https://{locationId}-{projectId}.cloudfunctions.net/{resourceId}';
40
+ var FIREBASE_FUNCTIONS_CONFIG_HEADERS = {
41
+ 'X-Firebase-Client': "fire-admin-node/" + utils.getSdkVersion()
42
+ };
43
+ // Default canonical location ID of the task queue.
44
+ var DEFAULT_LOCATION = 'us-central1';
45
+ /**
46
+ * Class that facilitates sending requests to the Firebase Functions backend API.
47
+ *
48
+ * @internal
49
+ */
50
+ var FunctionsApiClient = /** @class */ (function () {
51
+ function FunctionsApiClient(app) {
52
+ this.app = app;
53
+ if (!validator.isNonNullObject(app) || !('options' in app)) {
54
+ throw new FirebaseFunctionsError('invalid-argument', 'First argument passed to getFunctions() must be a valid Firebase app instance.');
55
+ }
56
+ this.httpClient = new api_request_1.AuthorizedHttpClient(app);
57
+ }
58
+ /**
59
+ * Creates a task and adds it to a queue.
60
+ *
61
+ * @param data - The data payload of the task.
62
+ * @param functionName - The functionName of the queue.
63
+ * @param extensionId - Optional canonical ID of the extension.
64
+ * @param opts - Optional options when enqueuing a new task.
65
+ */
66
+ FunctionsApiClient.prototype.enqueue = function (data, functionName, extensionId, opts) {
67
+ var _this = this;
68
+ if (!validator.isNonEmptyString(functionName)) {
69
+ throw new FirebaseFunctionsError('invalid-argument', 'Function name must be a non empty string');
70
+ }
71
+ var task = this.validateTaskOptions(data, opts);
72
+ var resources;
73
+ try {
74
+ resources = utils.parseResourceName(functionName, 'functions');
75
+ }
76
+ catch (err) {
77
+ throw new FirebaseFunctionsError('invalid-argument', 'Function name must be a single string or a qualified resource name');
78
+ }
79
+ if (typeof extensionId !== 'undefined' && validator.isNonEmptyString(extensionId)) {
80
+ resources.resourceId = "ext-" + extensionId + "-" + resources.resourceId;
81
+ }
82
+ return this.getUrl(resources, CLOUD_TASKS_API_URL_FORMAT)
83
+ .then(function (serviceUrl) {
84
+ return _this.updateTaskPayload(task, resources)
85
+ .then(function (task) {
86
+ var request = {
87
+ method: 'POST',
88
+ url: serviceUrl,
89
+ headers: FIREBASE_FUNCTIONS_CONFIG_HEADERS,
90
+ data: {
91
+ task: task,
92
+ }
93
+ };
94
+ return _this.httpClient.send(request);
95
+ });
96
+ })
97
+ .then(function () {
98
+ return;
99
+ })
100
+ .catch(function (err) {
101
+ throw _this.toFirebaseError(err);
102
+ });
103
+ };
104
+ FunctionsApiClient.prototype.getUrl = function (resourceName, urlFormat) {
105
+ var _this = this;
106
+ var locationId = resourceName.locationId;
107
+ var projectId = resourceName.projectId, resourceId = resourceName.resourceId;
108
+ if (typeof locationId === 'undefined' || !validator.isNonEmptyString(locationId)) {
109
+ locationId = DEFAULT_LOCATION;
110
+ }
111
+ return Promise.resolve()
112
+ .then(function () {
113
+ if (typeof projectId !== 'undefined' && validator.isNonEmptyString(projectId)) {
114
+ return projectId;
115
+ }
116
+ return _this.getProjectId();
117
+ })
118
+ .then(function (projectId) {
119
+ var urlParams = {
120
+ projectId: projectId,
121
+ locationId: locationId,
122
+ resourceId: resourceId,
123
+ };
124
+ // Formats a string of form 'project/{projectId}/{api}' and replaces
125
+ // with corresponding arguments {projectId: '1234', api: 'resource'}
126
+ // and returns output: 'project/1234/resource'.
127
+ return utils.formatString(urlFormat, urlParams);
128
+ });
129
+ };
130
+ FunctionsApiClient.prototype.getProjectId = function () {
131
+ var _this = this;
132
+ if (this.projectId) {
133
+ return Promise.resolve(this.projectId);
134
+ }
135
+ return utils.findProjectId(this.app)
136
+ .then(function (projectId) {
137
+ if (!validator.isNonEmptyString(projectId)) {
138
+ throw new FirebaseFunctionsError('unknown-error', 'Failed to determine project ID. Initialize the '
139
+ + 'SDK with service account credentials or set project ID as an app option. '
140
+ + 'Alternatively, set the GOOGLE_CLOUD_PROJECT environment variable.');
141
+ }
142
+ _this.projectId = projectId;
143
+ return projectId;
144
+ });
145
+ };
146
+ FunctionsApiClient.prototype.getServiceAccount = function () {
147
+ var _this = this;
148
+ if (this.accountId) {
149
+ return Promise.resolve(this.accountId);
150
+ }
151
+ return utils.findServiceAccountEmail(this.app)
152
+ .then(function (accountId) {
153
+ if (!validator.isNonEmptyString(accountId)) {
154
+ throw new FirebaseFunctionsError('unknown-error', 'Failed to determine service account. Initialize the '
155
+ + 'SDK with service account credentials or set service account ID as an app option.');
156
+ }
157
+ _this.accountId = accountId;
158
+ return accountId;
159
+ });
160
+ };
161
+ FunctionsApiClient.prototype.validateTaskOptions = function (data, opts) {
162
+ var task = {
163
+ httpRequest: {
164
+ url: '',
165
+ oidcToken: {
166
+ serviceAccountEmail: '',
167
+ },
168
+ body: Buffer.from(JSON.stringify({ data: data })).toString('base64'),
169
+ headers: { 'Content-Type': 'application/json' }
170
+ }
171
+ };
172
+ if (typeof opts !== 'undefined') {
173
+ if (!validator.isNonNullObject(opts)) {
174
+ throw new FirebaseFunctionsError('invalid-argument', 'TaskOptions must be a non-null object');
175
+ }
176
+ if ('scheduleTime' in opts && 'scheduleDelaySeconds' in opts) {
177
+ throw new FirebaseFunctionsError('invalid-argument', 'Both scheduleTime and scheduleDelaySeconds are provided. '
178
+ + 'Only one value should be set.');
179
+ }
180
+ if ('scheduleTime' in opts && typeof opts.scheduleTime !== 'undefined') {
181
+ if (!(opts.scheduleTime instanceof Date)) {
182
+ throw new FirebaseFunctionsError('invalid-argument', 'scheduleTime must be a valid Date object.');
183
+ }
184
+ task.scheduleTime = opts.scheduleTime.toISOString();
185
+ }
186
+ if ('scheduleDelaySeconds' in opts && typeof opts.scheduleDelaySeconds !== 'undefined') {
187
+ if (!validator.isNumber(opts.scheduleDelaySeconds) || opts.scheduleDelaySeconds < 0) {
188
+ throw new FirebaseFunctionsError('invalid-argument', 'scheduleDelaySeconds must be a non-negative duration in seconds.');
189
+ }
190
+ var date = new Date();
191
+ date.setSeconds(date.getSeconds() + opts.scheduleDelaySeconds);
192
+ task.scheduleTime = date.toISOString();
193
+ }
194
+ if (typeof opts.dispatchDeadlineSeconds !== 'undefined') {
195
+ if (!validator.isNumber(opts.dispatchDeadlineSeconds) || opts.dispatchDeadlineSeconds < 15
196
+ || opts.dispatchDeadlineSeconds > 1800) {
197
+ throw new FirebaseFunctionsError('invalid-argument', 'dispatchDeadlineSeconds must be a non-negative duration in seconds '
198
+ + 'and must be in the range of 15s to 30 mins.');
199
+ }
200
+ task.dispatchDeadline = opts.dispatchDeadlineSeconds + "s";
201
+ }
202
+ if (typeof opts.uri !== 'undefined') {
203
+ if (!validator.isURL(opts.uri)) {
204
+ throw new FirebaseFunctionsError('invalid-argument', 'uri must be a valid URL string.');
205
+ }
206
+ task.httpRequest.url = opts.uri;
207
+ }
208
+ }
209
+ return task;
210
+ };
211
+ FunctionsApiClient.prototype.updateTaskPayload = function (task, resources) {
212
+ var _this = this;
213
+ return Promise.resolve()
214
+ .then(function () {
215
+ if (validator.isNonEmptyString(task.httpRequest.url)) {
216
+ return task.httpRequest.url;
217
+ }
218
+ return _this.getUrl(resources, FIREBASE_FUNCTION_URL_FORMAT);
219
+ })
220
+ .then(function (functionUrl) {
221
+ return _this.getServiceAccount()
222
+ .then(function (account) {
223
+ task.httpRequest.oidcToken.serviceAccountEmail = account;
224
+ task.httpRequest.url = functionUrl;
225
+ return task;
226
+ });
227
+ });
228
+ };
229
+ FunctionsApiClient.prototype.toFirebaseError = function (err) {
230
+ if (err instanceof error_1.PrefixedFirebaseError) {
231
+ return err;
232
+ }
233
+ var response = err.response;
234
+ if (!response.isJson()) {
235
+ return new FirebaseFunctionsError('unknown-error', "Unexpected response with status: " + response.status + " and body: " + response.text);
236
+ }
237
+ var error = response.data.error || {};
238
+ var code = 'unknown-error';
239
+ if (error.status && error.status in exports.FUNCTIONS_ERROR_CODE_MAPPING) {
240
+ code = exports.FUNCTIONS_ERROR_CODE_MAPPING[error.status];
241
+ }
242
+ var message = error.message || "Unknown server error: " + response.text;
243
+ return new FirebaseFunctionsError(code, message);
244
+ };
245
+ return FunctionsApiClient;
246
+ }());
247
+ exports.FunctionsApiClient = FunctionsApiClient;
248
+ exports.FUNCTIONS_ERROR_CODE_MAPPING = {
249
+ ABORTED: 'aborted',
250
+ INVALID_ARGUMENT: 'invalid-argument',
251
+ INVALID_CREDENTIAL: 'invalid-credential',
252
+ INTERNAL: 'internal-error',
253
+ FAILED_PRECONDITION: 'failed-precondition',
254
+ PERMISSION_DENIED: 'permission-denied',
255
+ UNAUTHENTICATED: 'unauthenticated',
256
+ NOT_FOUND: 'not-found',
257
+ UNKNOWN: 'unknown-error',
258
+ };
259
+ /**
260
+ * Firebase Functions error code structure. This extends PrefixedFirebaseError.
261
+ *
262
+ * @param code - The error code.
263
+ * @param message - The error message.
264
+ * @constructor
265
+ */
266
+ var FirebaseFunctionsError = /** @class */ (function (_super) {
267
+ __extends(FirebaseFunctionsError, _super);
268
+ function FirebaseFunctionsError(code, message) {
269
+ var _this = _super.call(this, 'functions', code, message) || this;
270
+ /* tslint:disable:max-line-length */
271
+ // Set the prototype explicitly. See the following link for more details:
272
+ // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
273
+ /* tslint:enable:max-line-length */
274
+ _this.__proto__ = FirebaseFunctionsError.prototype;
275
+ return _this;
276
+ }
277
+ return FirebaseFunctionsError;
278
+ }(error_1.PrefixedFirebaseError));
279
+ exports.FirebaseFunctionsError = FirebaseFunctionsError;
@@ -0,0 +1,67 @@
1
+ /*! firebase-admin v10.3.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2021 Google Inc.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ /**
19
+ * Interface representing task options with delayed delivery.
20
+ */
21
+ export interface DelayDelivery {
22
+ /**
23
+ * The duration of delay of the time when the task is scheduled to be attempted or retried.
24
+ * This delay is added to the current time.
25
+ */
26
+ scheduleDelaySeconds?: number;
27
+ /** @alpha */
28
+ scheduleTime?: never;
29
+ }
30
+ /**
31
+ * Interface representing task options with absolute delivery.
32
+ */
33
+ export interface AbsoluteDelivery {
34
+ /**
35
+ * The time when the task is scheduled to be attempted or retried.
36
+ */
37
+ scheduleTime?: Date;
38
+ /** @alpha */
39
+ scheduleDelaySeconds?: never;
40
+ }
41
+ /**
42
+ * Type representing delivery schedule options.
43
+ * `DeliverySchedule` is a union type of {@link DelayDelivery} and {@link AbsoluteDelivery} types.
44
+ */
45
+ export declare type DeliverySchedule = DelayDelivery | AbsoluteDelivery;
46
+ /**
47
+ * Type representing task options.
48
+ */
49
+ export declare type TaskOptions = DeliverySchedule & TaskOptionsExperimental & {
50
+ /**
51
+ * The deadline for requests sent to the worker. If the worker does not respond by this deadline
52
+ * then the request is cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure.
53
+ * Cloud Tasks will retry the task according to the `RetryConfig`.
54
+ * The default is 10 minutes. The deadline must be in the range of 15 seconds and 30 minutes.
55
+ */
56
+ dispatchDeadlineSeconds?: number;
57
+ };
58
+ /**
59
+ * Type representing experimental (beta) task options.
60
+ */
61
+ export interface TaskOptionsExperimental {
62
+ /**
63
+ * The full URL path that the request will be sent to. Must be a valid URL.
64
+ * @beta
65
+ */
66
+ uri?: string;
67
+ }
@@ -0,0 +1,19 @@
1
+ /*! firebase-admin v10.3.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,63 @@
1
+ /*! firebase-admin v10.3.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2021 Google Inc.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ import { App } from '../app';
19
+ import { TaskOptions } from './functions-api';
20
+ /**
21
+ * The Firebase `Functions` service interface.
22
+ */
23
+ export declare class Functions {
24
+ readonly app: App;
25
+ private readonly client;
26
+ /**
27
+ * Creates a reference to a {@link TaskQueue} for a given function name.
28
+ * The function name can be either:
29
+ *
30
+ * 1) A fully qualified function resource name:
31
+ * `projects/{project}/locations/{location}/functions/{functionName}`
32
+ *
33
+ * 2) A partial resource name with location and function name, in which case
34
+ * the runtime project ID is used:
35
+ * `locations/{location}/functions/{functionName}`
36
+ *
37
+ * 3) A partial function name, in which case the runtime project ID and the default location,
38
+ * `us-central1`, is used:
39
+ * `{functionName}`
40
+ *
41
+ * @param functionName - The name of the function.
42
+ * @param extensionId - Optional Firebase extension ID.
43
+ * @returns A promise that fulfills with a `TaskQueue`.
44
+ */
45
+ taskQueue<Args = Record<string, any>>(functionName: string, extensionId?: string): TaskQueue<Args>;
46
+ }
47
+ /**
48
+ * The `TaskQueue` interface.
49
+ */
50
+ export declare class TaskQueue<Args = Record<string, any>> {
51
+ private readonly functionName;
52
+ private readonly client;
53
+ private readonly extensionId?;
54
+ /**
55
+ * Creates a task and adds it to the queue. Tasks cannot be updated after creation.
56
+ * This action requires `cloudtasks.tasks.create` IAM permission on the service account.
57
+ *
58
+ * @param data - The data payload of the task.
59
+ * @param opts - Optional options when enqueuing a new task.
60
+ * @returns A promise that resolves when the task has successfully been added to the queue.
61
+ */
62
+ enqueue(data: Args, opts?: TaskOptions): Promise<void>;
63
+ }
@@ -0,0 +1,99 @@
1
+ /*! firebase-admin v10.3.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.TaskQueue = exports.Functions = void 0;
21
+ var functions_api_client_internal_1 = require("./functions-api-client-internal");
22
+ var validator = require("../utils/validator");
23
+ /**
24
+ * The Firebase `Functions` service interface.
25
+ */
26
+ var Functions = /** @class */ (function () {
27
+ /**
28
+ * @param app - The app for this `Functions` service.
29
+ * @constructor
30
+ * @internal
31
+ */
32
+ function Functions(app) {
33
+ this.app = app;
34
+ this.client = new functions_api_client_internal_1.FunctionsApiClient(app);
35
+ }
36
+ /**
37
+ * Creates a reference to a {@link TaskQueue} for a given function name.
38
+ * The function name can be either:
39
+ *
40
+ * 1) A fully qualified function resource name:
41
+ * `projects/{project}/locations/{location}/functions/{functionName}`
42
+ *
43
+ * 2) A partial resource name with location and function name, in which case
44
+ * the runtime project ID is used:
45
+ * `locations/{location}/functions/{functionName}`
46
+ *
47
+ * 3) A partial function name, in which case the runtime project ID and the default location,
48
+ * `us-central1`, is used:
49
+ * `{functionName}`
50
+ *
51
+ * @param functionName - The name of the function.
52
+ * @param extensionId - Optional Firebase extension ID.
53
+ * @returns A promise that fulfills with a `TaskQueue`.
54
+ */
55
+ Functions.prototype.taskQueue = function (functionName, extensionId) {
56
+ return new TaskQueue(functionName, this.client, extensionId);
57
+ };
58
+ return Functions;
59
+ }());
60
+ exports.Functions = Functions;
61
+ /**
62
+ * The `TaskQueue` interface.
63
+ */
64
+ var TaskQueue = /** @class */ (function () {
65
+ /**
66
+ * @param functionName - The name of the function.
67
+ * @param client - The `FunctionsApiClient` instance.
68
+ * @param extensionId - Optional canonical ID of the extension.
69
+ * @constructor
70
+ * @internal
71
+ */
72
+ function TaskQueue(functionName, client, extensionId) {
73
+ this.functionName = functionName;
74
+ this.client = client;
75
+ this.extensionId = extensionId;
76
+ if (!validator.isNonEmptyString(functionName)) {
77
+ throw new functions_api_client_internal_1.FirebaseFunctionsError('invalid-argument', '`functionName` must be a non-empty string.');
78
+ }
79
+ if (!validator.isNonNullObject(client) || !('enqueue' in client)) {
80
+ throw new functions_api_client_internal_1.FirebaseFunctionsError('invalid-argument', 'Must provide a valid FunctionsApiClient instance to create a new TaskQueue.');
81
+ }
82
+ if (typeof extensionId !== 'undefined' && !validator.isString(extensionId)) {
83
+ throw new functions_api_client_internal_1.FirebaseFunctionsError('invalid-argument', '`extensionId` must be a string.');
84
+ }
85
+ }
86
+ /**
87
+ * Creates a task and adds it to the queue. Tasks cannot be updated after creation.
88
+ * This action requires `cloudtasks.tasks.create` IAM permission on the service account.
89
+ *
90
+ * @param data - The data payload of the task.
91
+ * @param opts - Optional options when enqueuing a new task.
92
+ * @returns A promise that resolves when the task has successfully been added to the queue.
93
+ */
94
+ TaskQueue.prototype.enqueue = function (data, opts) {
95
+ return this.client.enqueue(data, this.functionName, this.extensionId, opts);
96
+ };
97
+ return TaskQueue;
98
+ }());
99
+ exports.TaskQueue = TaskQueue;
@@ -0,0 +1,53 @@
1
+ /*! firebase-admin v10.3.0 */
2
+ /*!
3
+ * @license
4
+ * Copyright 2021 Google Inc.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ /**
19
+ * Firebase Functions service.
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ import { App } from '../app';
24
+ import { Functions } from './functions';
25
+ export { DelayDelivery, AbsoluteDelivery, DeliverySchedule, TaskOptions, TaskOptionsExperimental } from './functions-api';
26
+ export { Functions, TaskQueue } from './functions';
27
+ /**
28
+ * Gets the {@link Functions} service for the default app
29
+ * or a given app.
30
+ *
31
+ * `getFunctions()` can be called with no arguments to access the default
32
+ * app's `Functions` service or as `getFunctions(app)` to access the
33
+ * `Functions` service associated with a specific app.
34
+ *
35
+ * @example
36
+ * ```javascript
37
+ * // Get the `Functions` service for the default app
38
+ * const defaultFunctions = getFunctions();
39
+ * ```
40
+ *
41
+ * @example
42
+ * ```javascript
43
+ * // Get the `Functions` service for a given app
44
+ * const otherFunctions = getFunctions(otherApp);
45
+ * ```
46
+ *
47
+ * @param app - Optional app for which to return the `Functions` service.
48
+ * If not provided, the default `Functions` service is returned.
49
+ *
50
+ * @returns The default `Functions` service if no app is provided, or the `Functions`
51
+ * service associated with the provided app.
52
+ */
53
+ export declare function getFunctions(app?: App): Functions;
@@ -0,0 +1,64 @@
1
+ /*! firebase-admin v10.3.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2021 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.getFunctions = void 0;
21
+ /**
22
+ * Firebase Functions service.
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ var app_1 = require("../app");
27
+ var functions_1 = require("./functions");
28
+ var functions_2 = require("./functions");
29
+ Object.defineProperty(exports, "Functions", { enumerable: true, get: function () { return functions_2.Functions; } });
30
+ Object.defineProperty(exports, "TaskQueue", { enumerable: true, get: function () { return functions_2.TaskQueue; } });
31
+ /**
32
+ * Gets the {@link Functions} service for the default app
33
+ * or a given app.
34
+ *
35
+ * `getFunctions()` can be called with no arguments to access the default
36
+ * app's `Functions` service or as `getFunctions(app)` to access the
37
+ * `Functions` service associated with a specific app.
38
+ *
39
+ * @example
40
+ * ```javascript
41
+ * // Get the `Functions` service for the default app
42
+ * const defaultFunctions = getFunctions();
43
+ * ```
44
+ *
45
+ * @example
46
+ * ```javascript
47
+ * // Get the `Functions` service for a given app
48
+ * const otherFunctions = getFunctions(otherApp);
49
+ * ```
50
+ *
51
+ * @param app - Optional app for which to return the `Functions` service.
52
+ * If not provided, the default `Functions` service is returned.
53
+ *
54
+ * @returns The default `Functions` service if no app is provided, or the `Functions`
55
+ * service associated with the provided app.
56
+ */
57
+ function getFunctions(app) {
58
+ if (typeof app === 'undefined') {
59
+ app = app_1.getApp();
60
+ }
61
+ var firebaseApp = app;
62
+ return firebaseApp.getOrInitService('functions', function (app) { return new functions_1.Functions(app); });
63
+ }
64
+ exports.getFunctions = getFunctions;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.0.2 */
1
+ /*! firebase-admin v10.3.0 */
2
2
  /*!
3
3
  * @license
4
4
  * Copyright 2017 Google Inc.
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.0.2 */
1
+ /*! firebase-admin v10.3.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * @license
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.0.2 */
1
+ /*! firebase-admin v10.3.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.0.2 */
1
+ /*! firebase-admin v10.3.0 */
2
2
  "use strict";
3
3
  /*!
4
4
  * Copyright 2021 Google Inc.
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.0.2 */
1
+ /*! firebase-admin v10.3.0 */
2
2
  /*!
3
3
  * Copyright 2021 Google Inc.
4
4
  *