@firebase/functions 0.11.8 → 0.11.9
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.
- package/dist/{index.esm2017.js → esm/index.esm2017.js} +22 -14
- package/dist/esm/index.esm2017.js.map +1 -0
- package/dist/{esm-node → esm}/src/api.d.ts +1 -0
- package/dist/{esm-node → esm}/src/config.d.ts +1 -1
- package/dist/{esm-node → esm}/src/error.d.ts +10 -4
- package/dist/{esm-node → esm}/src/public-types.d.ts +0 -16
- package/dist/{esm-node → esm}/src/service.d.ts +1 -2
- package/dist/functions-public.d.ts +15 -4
- package/dist/functions.d.ts +15 -4
- package/dist/index.cjs.js +22 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/api.d.ts +1 -0
- package/dist/src/config.d.ts +1 -1
- package/dist/src/error.d.ts +10 -4
- package/dist/src/public-types.d.ts +0 -16
- package/dist/src/service.d.ts +1 -2
- package/package.json +15 -15
- package/dist/esm-node/index.node.esm.js +0 -731
- package/dist/esm-node/index.node.esm.js.map +0 -1
- package/dist/esm-node/src/index.node.d.ts +0 -1
- package/dist/index.esm.js +0 -804
- package/dist/index.esm.js.map +0 -1
- package/dist/index.esm2017.js.map +0 -1
- package/dist/index.node.cjs.js +0 -824
- package/dist/index.node.cjs.js.map +0 -1
- package/dist/src/index.node.d.ts +0 -1
- /package/dist/{esm-node → esm}/package.json +0 -0
- /package/dist/{esm-node → esm}/src/callable.test.d.ts +0 -0
- /package/dist/{esm-node → esm}/src/constants.d.ts +0 -0
- /package/dist/{esm-node → esm}/src/context.d.ts +0 -0
- /package/dist/{esm-node → esm}/src/index.d.ts +0 -0
- /package/dist/{esm-node → esm}/src/serializer.d.ts +0 -0
- /package/dist/{esm-node → esm}/src/serializer.test.d.ts +0 -0
- /package/dist/{esm-node → esm}/src/service.test.d.ts +0 -0
- /package/dist/{esm-node → esm}/test/utils.d.ts +0 -0
package/dist/index.esm.js
DELETED
|
@@ -1,804 +0,0 @@
|
|
|
1
|
-
import { _registerComponent, registerVersion, getApp, _getProvider } from '@firebase/app';
|
|
2
|
-
import { __extends, __awaiter, __generator, __spreadArray } from 'tslib';
|
|
3
|
-
import { FirebaseError, getModularInstance, getDefaultEmulatorHostnameAndPort } from '@firebase/util';
|
|
4
|
-
import { Component } from '@firebase/component';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @license
|
|
8
|
-
* Copyright 2017 Google LLC
|
|
9
|
-
*
|
|
10
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
-
* you may not use this file except in compliance with the License.
|
|
12
|
-
* You may obtain a copy of the License at
|
|
13
|
-
*
|
|
14
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
* See the License for the specific language governing permissions and
|
|
20
|
-
* limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
var LONG_TYPE = 'type.googleapis.com/google.protobuf.Int64Value';
|
|
23
|
-
var UNSIGNED_LONG_TYPE = 'type.googleapis.com/google.protobuf.UInt64Value';
|
|
24
|
-
function mapValues(
|
|
25
|
-
// { [k: string]: unknown } is no longer a wildcard assignment target after typescript 3.5
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
o, f) {
|
|
28
|
-
var result = {};
|
|
29
|
-
for (var key in o) {
|
|
30
|
-
if (o.hasOwnProperty(key)) {
|
|
31
|
-
result[key] = f(o[key]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Takes data and encodes it in a JSON-friendly way, such that types such as
|
|
38
|
-
* Date are preserved.
|
|
39
|
-
* @internal
|
|
40
|
-
* @param data - Data to encode.
|
|
41
|
-
*/
|
|
42
|
-
function encode(data) {
|
|
43
|
-
if (data == null) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
if (data instanceof Number) {
|
|
47
|
-
data = data.valueOf();
|
|
48
|
-
}
|
|
49
|
-
if (typeof data === 'number' && isFinite(data)) {
|
|
50
|
-
// Any number in JS is safe to put directly in JSON and parse as a double
|
|
51
|
-
// without any loss of precision.
|
|
52
|
-
return data;
|
|
53
|
-
}
|
|
54
|
-
if (data === true || data === false) {
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
if (Object.prototype.toString.call(data) === '[object String]') {
|
|
58
|
-
return data;
|
|
59
|
-
}
|
|
60
|
-
if (data instanceof Date) {
|
|
61
|
-
return data.toISOString();
|
|
62
|
-
}
|
|
63
|
-
if (Array.isArray(data)) {
|
|
64
|
-
return data.map(function (x) { return encode(x); });
|
|
65
|
-
}
|
|
66
|
-
if (typeof data === 'function' || typeof data === 'object') {
|
|
67
|
-
return mapValues(data, function (x) { return encode(x); });
|
|
68
|
-
}
|
|
69
|
-
// If we got this far, the data is not encodable.
|
|
70
|
-
throw new Error('Data cannot be encoded in JSON: ' + data);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Takes data that's been encoded in a JSON-friendly form and returns a form
|
|
74
|
-
* with richer datatypes, such as Dates, etc.
|
|
75
|
-
* @internal
|
|
76
|
-
* @param json - JSON to convert.
|
|
77
|
-
*/
|
|
78
|
-
function decode(json) {
|
|
79
|
-
if (json == null) {
|
|
80
|
-
return json;
|
|
81
|
-
}
|
|
82
|
-
if (json['@type']) {
|
|
83
|
-
switch (json['@type']) {
|
|
84
|
-
case LONG_TYPE:
|
|
85
|
-
// Fall through and handle this the same as unsigned.
|
|
86
|
-
case UNSIGNED_LONG_TYPE: {
|
|
87
|
-
// Technically, this could work return a valid number for malformed
|
|
88
|
-
// data if there was a number followed by garbage. But it's just not
|
|
89
|
-
// worth all the extra code to detect that case.
|
|
90
|
-
var value = Number(json['value']);
|
|
91
|
-
if (isNaN(value)) {
|
|
92
|
-
throw new Error('Data cannot be decoded from JSON: ' + json);
|
|
93
|
-
}
|
|
94
|
-
return value;
|
|
95
|
-
}
|
|
96
|
-
default: {
|
|
97
|
-
throw new Error('Data cannot be decoded from JSON: ' + json);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (Array.isArray(json)) {
|
|
102
|
-
return json.map(function (x) { return decode(x); });
|
|
103
|
-
}
|
|
104
|
-
if (typeof json === 'function' || typeof json === 'object') {
|
|
105
|
-
return mapValues(json, function (x) { return decode(x); });
|
|
106
|
-
}
|
|
107
|
-
// Anything else is safe to return.
|
|
108
|
-
return json;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @license
|
|
113
|
-
* Copyright 2020 Google LLC
|
|
114
|
-
*
|
|
115
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
116
|
-
* you may not use this file except in compliance with the License.
|
|
117
|
-
* You may obtain a copy of the License at
|
|
118
|
-
*
|
|
119
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
120
|
-
*
|
|
121
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
122
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
123
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
124
|
-
* See the License for the specific language governing permissions and
|
|
125
|
-
* limitations under the License.
|
|
126
|
-
*/
|
|
127
|
-
/**
|
|
128
|
-
* Type constant for Firebase Functions.
|
|
129
|
-
*/
|
|
130
|
-
var FUNCTIONS_TYPE = 'functions';
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @license
|
|
134
|
-
* Copyright 2017 Google LLC
|
|
135
|
-
*
|
|
136
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
137
|
-
* you may not use this file except in compliance with the License.
|
|
138
|
-
* You may obtain a copy of the License at
|
|
139
|
-
*
|
|
140
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
141
|
-
*
|
|
142
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
143
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
144
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
145
|
-
* See the License for the specific language governing permissions and
|
|
146
|
-
* limitations under the License.
|
|
147
|
-
*/
|
|
148
|
-
/**
|
|
149
|
-
* Standard error codes for different ways a request can fail, as defined by:
|
|
150
|
-
* https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
|
|
151
|
-
*
|
|
152
|
-
* This map is used primarily to convert from a backend error code string to
|
|
153
|
-
* a client SDK error code string, and make sure it's in the supported set.
|
|
154
|
-
*/
|
|
155
|
-
var errorCodeMap = {
|
|
156
|
-
OK: 'ok',
|
|
157
|
-
CANCELLED: 'cancelled',
|
|
158
|
-
UNKNOWN: 'unknown',
|
|
159
|
-
INVALID_ARGUMENT: 'invalid-argument',
|
|
160
|
-
DEADLINE_EXCEEDED: 'deadline-exceeded',
|
|
161
|
-
NOT_FOUND: 'not-found',
|
|
162
|
-
ALREADY_EXISTS: 'already-exists',
|
|
163
|
-
PERMISSION_DENIED: 'permission-denied',
|
|
164
|
-
UNAUTHENTICATED: 'unauthenticated',
|
|
165
|
-
RESOURCE_EXHAUSTED: 'resource-exhausted',
|
|
166
|
-
FAILED_PRECONDITION: 'failed-precondition',
|
|
167
|
-
ABORTED: 'aborted',
|
|
168
|
-
OUT_OF_RANGE: 'out-of-range',
|
|
169
|
-
UNIMPLEMENTED: 'unimplemented',
|
|
170
|
-
INTERNAL: 'internal',
|
|
171
|
-
UNAVAILABLE: 'unavailable',
|
|
172
|
-
DATA_LOSS: 'data-loss'
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* An explicit error that can be thrown from a handler to send an error to the
|
|
176
|
-
* client that called the function.
|
|
177
|
-
*/
|
|
178
|
-
var FunctionsError = /** @class */ (function (_super) {
|
|
179
|
-
__extends(FunctionsError, _super);
|
|
180
|
-
function FunctionsError(
|
|
181
|
-
/**
|
|
182
|
-
* A standard error code that will be returned to the client. This also
|
|
183
|
-
* determines the HTTP status code of the response, as defined in code.proto.
|
|
184
|
-
*/
|
|
185
|
-
code, message,
|
|
186
|
-
/**
|
|
187
|
-
* Extra data to be converted to JSON and included in the error response.
|
|
188
|
-
*/
|
|
189
|
-
details) {
|
|
190
|
-
var _this = _super.call(this, "".concat(FUNCTIONS_TYPE, "/").concat(code), message || '') || this;
|
|
191
|
-
_this.details = details;
|
|
192
|
-
return _this;
|
|
193
|
-
}
|
|
194
|
-
return FunctionsError;
|
|
195
|
-
}(FirebaseError));
|
|
196
|
-
/**
|
|
197
|
-
* Takes an HTTP status code and returns the corresponding ErrorCode.
|
|
198
|
-
* This is the standard HTTP status code -> error mapping defined in:
|
|
199
|
-
* https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
|
|
200
|
-
*
|
|
201
|
-
* @param status An HTTP status code.
|
|
202
|
-
* @return The corresponding ErrorCode, or ErrorCode.UNKNOWN if none.
|
|
203
|
-
*/
|
|
204
|
-
function codeForHTTPStatus(status) {
|
|
205
|
-
// Make sure any successful status is OK.
|
|
206
|
-
if (status >= 200 && status < 300) {
|
|
207
|
-
return 'ok';
|
|
208
|
-
}
|
|
209
|
-
switch (status) {
|
|
210
|
-
case 0:
|
|
211
|
-
// This can happen if the server returns 500.
|
|
212
|
-
return 'internal';
|
|
213
|
-
case 400:
|
|
214
|
-
return 'invalid-argument';
|
|
215
|
-
case 401:
|
|
216
|
-
return 'unauthenticated';
|
|
217
|
-
case 403:
|
|
218
|
-
return 'permission-denied';
|
|
219
|
-
case 404:
|
|
220
|
-
return 'not-found';
|
|
221
|
-
case 409:
|
|
222
|
-
return 'aborted';
|
|
223
|
-
case 429:
|
|
224
|
-
return 'resource-exhausted';
|
|
225
|
-
case 499:
|
|
226
|
-
return 'cancelled';
|
|
227
|
-
case 500:
|
|
228
|
-
return 'internal';
|
|
229
|
-
case 501:
|
|
230
|
-
return 'unimplemented';
|
|
231
|
-
case 503:
|
|
232
|
-
return 'unavailable';
|
|
233
|
-
case 504:
|
|
234
|
-
return 'deadline-exceeded';
|
|
235
|
-
}
|
|
236
|
-
return 'unknown';
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Takes an HTTP response and returns the corresponding Error, if any.
|
|
240
|
-
*/
|
|
241
|
-
function _errorForResponse(status, bodyJSON) {
|
|
242
|
-
var code = codeForHTTPStatus(status);
|
|
243
|
-
// Start with reasonable defaults from the status code.
|
|
244
|
-
var description = code;
|
|
245
|
-
var details = undefined;
|
|
246
|
-
// Then look through the body for explicit details.
|
|
247
|
-
try {
|
|
248
|
-
var errorJSON = bodyJSON && bodyJSON.error;
|
|
249
|
-
if (errorJSON) {
|
|
250
|
-
var status_1 = errorJSON.status;
|
|
251
|
-
if (typeof status_1 === 'string') {
|
|
252
|
-
if (!errorCodeMap[status_1]) {
|
|
253
|
-
// They must've included an unknown error code in the body.
|
|
254
|
-
return new FunctionsError('internal', 'internal');
|
|
255
|
-
}
|
|
256
|
-
code = errorCodeMap[status_1];
|
|
257
|
-
// TODO(klimt): Add better default descriptions for error enums.
|
|
258
|
-
// The default description needs to be updated for the new code.
|
|
259
|
-
description = status_1;
|
|
260
|
-
}
|
|
261
|
-
var message = errorJSON.message;
|
|
262
|
-
if (typeof message === 'string') {
|
|
263
|
-
description = message;
|
|
264
|
-
}
|
|
265
|
-
details = errorJSON.details;
|
|
266
|
-
if (details !== undefined) {
|
|
267
|
-
details = decode(details);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
catch (e) {
|
|
272
|
-
// If we couldn't parse explicit error data, that's fine.
|
|
273
|
-
}
|
|
274
|
-
if (code === 'ok') {
|
|
275
|
-
// Technically, there's an edge case where a developer could explicitly
|
|
276
|
-
// return an error code of OK, and we will treat it as success, but that
|
|
277
|
-
// seems reasonable.
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
return new FunctionsError(code, description, details);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* @license
|
|
285
|
-
* Copyright 2017 Google LLC
|
|
286
|
-
*
|
|
287
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
288
|
-
* you may not use this file except in compliance with the License.
|
|
289
|
-
* You may obtain a copy of the License at
|
|
290
|
-
*
|
|
291
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
292
|
-
*
|
|
293
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
294
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
295
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
296
|
-
* See the License for the specific language governing permissions and
|
|
297
|
-
* limitations under the License.
|
|
298
|
-
*/
|
|
299
|
-
/**
|
|
300
|
-
* Helper class to get metadata that should be included with a function call.
|
|
301
|
-
* @internal
|
|
302
|
-
*/
|
|
303
|
-
var ContextProvider = /** @class */ (function () {
|
|
304
|
-
function ContextProvider(authProvider, messagingProvider, appCheckProvider) {
|
|
305
|
-
var _this = this;
|
|
306
|
-
this.auth = null;
|
|
307
|
-
this.messaging = null;
|
|
308
|
-
this.appCheck = null;
|
|
309
|
-
this.auth = authProvider.getImmediate({ optional: true });
|
|
310
|
-
this.messaging = messagingProvider.getImmediate({
|
|
311
|
-
optional: true
|
|
312
|
-
});
|
|
313
|
-
if (!this.auth) {
|
|
314
|
-
authProvider.get().then(function (auth) { return (_this.auth = auth); }, function () {
|
|
315
|
-
/* get() never rejects */
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
if (!this.messaging) {
|
|
319
|
-
messagingProvider.get().then(function (messaging) { return (_this.messaging = messaging); }, function () {
|
|
320
|
-
/* get() never rejects */
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
if (!this.appCheck) {
|
|
324
|
-
appCheckProvider.get().then(function (appCheck) { return (_this.appCheck = appCheck); }, function () {
|
|
325
|
-
/* get() never rejects */
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
ContextProvider.prototype.getAuthToken = function () {
|
|
330
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
331
|
-
var token;
|
|
332
|
-
return __generator(this, function (_a) {
|
|
333
|
-
switch (_a.label) {
|
|
334
|
-
case 0:
|
|
335
|
-
if (!this.auth) {
|
|
336
|
-
return [2 /*return*/, undefined];
|
|
337
|
-
}
|
|
338
|
-
_a.label = 1;
|
|
339
|
-
case 1:
|
|
340
|
-
_a.trys.push([1, 3, , 4]);
|
|
341
|
-
return [4 /*yield*/, this.auth.getToken()];
|
|
342
|
-
case 2:
|
|
343
|
-
token = _a.sent();
|
|
344
|
-
return [2 /*return*/, token === null || token === void 0 ? void 0 : token.accessToken];
|
|
345
|
-
case 3:
|
|
346
|
-
_a.sent();
|
|
347
|
-
// If there's any error when trying to get the auth token, leave it off.
|
|
348
|
-
return [2 /*return*/, undefined];
|
|
349
|
-
case 4: return [2 /*return*/];
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
ContextProvider.prototype.getMessagingToken = function () {
|
|
355
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
356
|
-
return __generator(this, function (_a) {
|
|
357
|
-
switch (_a.label) {
|
|
358
|
-
case 0:
|
|
359
|
-
if (!this.messaging ||
|
|
360
|
-
!('Notification' in self) ||
|
|
361
|
-
Notification.permission !== 'granted') {
|
|
362
|
-
return [2 /*return*/, undefined];
|
|
363
|
-
}
|
|
364
|
-
_a.label = 1;
|
|
365
|
-
case 1:
|
|
366
|
-
_a.trys.push([1, 3, , 4]);
|
|
367
|
-
return [4 /*yield*/, this.messaging.getToken()];
|
|
368
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
369
|
-
case 3:
|
|
370
|
-
_a.sent();
|
|
371
|
-
// We don't warn on this, because it usually means messaging isn't set up.
|
|
372
|
-
// console.warn('Failed to retrieve instance id token.', e);
|
|
373
|
-
// If there's any error when trying to get the token, leave it off.
|
|
374
|
-
return [2 /*return*/, undefined];
|
|
375
|
-
case 4: return [2 /*return*/];
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
};
|
|
380
|
-
ContextProvider.prototype.getAppCheckToken = function (limitedUseAppCheckTokens) {
|
|
381
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
382
|
-
var result, _a;
|
|
383
|
-
return __generator(this, function (_b) {
|
|
384
|
-
switch (_b.label) {
|
|
385
|
-
case 0:
|
|
386
|
-
if (!this.appCheck) return [3 /*break*/, 5];
|
|
387
|
-
if (!limitedUseAppCheckTokens) return [3 /*break*/, 2];
|
|
388
|
-
return [4 /*yield*/, this.appCheck.getLimitedUseToken()];
|
|
389
|
-
case 1:
|
|
390
|
-
_a = _b.sent();
|
|
391
|
-
return [3 /*break*/, 4];
|
|
392
|
-
case 2: return [4 /*yield*/, this.appCheck.getToken()];
|
|
393
|
-
case 3:
|
|
394
|
-
_a = _b.sent();
|
|
395
|
-
_b.label = 4;
|
|
396
|
-
case 4:
|
|
397
|
-
result = _a;
|
|
398
|
-
if (result.error) {
|
|
399
|
-
// Do not send the App Check header to the functions endpoint if
|
|
400
|
-
// there was an error from the App Check exchange endpoint. The App
|
|
401
|
-
// Check SDK will already have logged the error to console.
|
|
402
|
-
return [2 /*return*/, null];
|
|
403
|
-
}
|
|
404
|
-
return [2 /*return*/, result.token];
|
|
405
|
-
case 5: return [2 /*return*/, null];
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
};
|
|
410
|
-
ContextProvider.prototype.getContext = function (limitedUseAppCheckTokens) {
|
|
411
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
412
|
-
var authToken, messagingToken, appCheckToken;
|
|
413
|
-
return __generator(this, function (_a) {
|
|
414
|
-
switch (_a.label) {
|
|
415
|
-
case 0: return [4 /*yield*/, this.getAuthToken()];
|
|
416
|
-
case 1:
|
|
417
|
-
authToken = _a.sent();
|
|
418
|
-
return [4 /*yield*/, this.getMessagingToken()];
|
|
419
|
-
case 2:
|
|
420
|
-
messagingToken = _a.sent();
|
|
421
|
-
return [4 /*yield*/, this.getAppCheckToken(limitedUseAppCheckTokens)];
|
|
422
|
-
case 3:
|
|
423
|
-
appCheckToken = _a.sent();
|
|
424
|
-
return [2 /*return*/, { authToken: authToken, messagingToken: messagingToken, appCheckToken: appCheckToken }];
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
});
|
|
428
|
-
};
|
|
429
|
-
return ContextProvider;
|
|
430
|
-
}());
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* @license
|
|
434
|
-
* Copyright 2017 Google LLC
|
|
435
|
-
*
|
|
436
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
437
|
-
* you may not use this file except in compliance with the License.
|
|
438
|
-
* You may obtain a copy of the License at
|
|
439
|
-
*
|
|
440
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
441
|
-
*
|
|
442
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
443
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
444
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
445
|
-
* See the License for the specific language governing permissions and
|
|
446
|
-
* limitations under the License.
|
|
447
|
-
*/
|
|
448
|
-
var DEFAULT_REGION = 'us-central1';
|
|
449
|
-
/**
|
|
450
|
-
* Returns a Promise that will be rejected after the given duration.
|
|
451
|
-
* The error will be of type FunctionsError.
|
|
452
|
-
*
|
|
453
|
-
* @param millis Number of milliseconds to wait before rejecting.
|
|
454
|
-
*/
|
|
455
|
-
function failAfter(millis) {
|
|
456
|
-
// Node timers and browser timers are fundamentally incompatible, but we
|
|
457
|
-
// don't care about the value here
|
|
458
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
459
|
-
var timer = null;
|
|
460
|
-
return {
|
|
461
|
-
promise: new Promise(function (_, reject) {
|
|
462
|
-
timer = setTimeout(function () {
|
|
463
|
-
reject(new FunctionsError('deadline-exceeded', 'deadline-exceeded'));
|
|
464
|
-
}, millis);
|
|
465
|
-
}),
|
|
466
|
-
cancel: function () {
|
|
467
|
-
if (timer) {
|
|
468
|
-
clearTimeout(timer);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* The main class for the Firebase Functions SDK.
|
|
475
|
-
* @internal
|
|
476
|
-
*/
|
|
477
|
-
var FunctionsService = /** @class */ (function () {
|
|
478
|
-
/**
|
|
479
|
-
* Creates a new Functions service for the given app.
|
|
480
|
-
* @param app - The FirebaseApp to use.
|
|
481
|
-
*/
|
|
482
|
-
function FunctionsService(app, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain, fetchImpl) {
|
|
483
|
-
if (regionOrCustomDomain === void 0) { regionOrCustomDomain = DEFAULT_REGION; }
|
|
484
|
-
var _this = this;
|
|
485
|
-
this.app = app;
|
|
486
|
-
this.fetchImpl = fetchImpl;
|
|
487
|
-
this.emulatorOrigin = null;
|
|
488
|
-
this.contextProvider = new ContextProvider(authProvider, messagingProvider, appCheckProvider);
|
|
489
|
-
// Cancels all ongoing requests when resolved.
|
|
490
|
-
this.cancelAllRequests = new Promise(function (resolve) {
|
|
491
|
-
_this.deleteService = function () {
|
|
492
|
-
return Promise.resolve(resolve());
|
|
493
|
-
};
|
|
494
|
-
});
|
|
495
|
-
// Resolve the region or custom domain overload by attempting to parse it.
|
|
496
|
-
try {
|
|
497
|
-
var url = new URL(regionOrCustomDomain);
|
|
498
|
-
this.customDomain =
|
|
499
|
-
url.origin + (url.pathname === '/' ? '' : url.pathname);
|
|
500
|
-
this.region = DEFAULT_REGION;
|
|
501
|
-
}
|
|
502
|
-
catch (e) {
|
|
503
|
-
this.customDomain = null;
|
|
504
|
-
this.region = regionOrCustomDomain;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
FunctionsService.prototype._delete = function () {
|
|
508
|
-
return this.deleteService();
|
|
509
|
-
};
|
|
510
|
-
/**
|
|
511
|
-
* Returns the URL for a callable with the given name.
|
|
512
|
-
* @param name - The name of the callable.
|
|
513
|
-
* @internal
|
|
514
|
-
*/
|
|
515
|
-
FunctionsService.prototype._url = function (name) {
|
|
516
|
-
var projectId = this.app.options.projectId;
|
|
517
|
-
if (this.emulatorOrigin !== null) {
|
|
518
|
-
var origin_1 = this.emulatorOrigin;
|
|
519
|
-
return "".concat(origin_1, "/").concat(projectId, "/").concat(this.region, "/").concat(name);
|
|
520
|
-
}
|
|
521
|
-
if (this.customDomain !== null) {
|
|
522
|
-
return "".concat(this.customDomain, "/").concat(name);
|
|
523
|
-
}
|
|
524
|
-
return "https://".concat(this.region, "-").concat(projectId, ".cloudfunctions.net/").concat(name);
|
|
525
|
-
};
|
|
526
|
-
return FunctionsService;
|
|
527
|
-
}());
|
|
528
|
-
/**
|
|
529
|
-
* Modify this instance to communicate with the Cloud Functions emulator.
|
|
530
|
-
*
|
|
531
|
-
* Note: this must be called before this instance has been used to do any operations.
|
|
532
|
-
*
|
|
533
|
-
* @param host The emulator host (ex: localhost)
|
|
534
|
-
* @param port The emulator port (ex: 5001)
|
|
535
|
-
* @public
|
|
536
|
-
*/
|
|
537
|
-
function connectFunctionsEmulator$1(functionsInstance, host, port) {
|
|
538
|
-
functionsInstance.emulatorOrigin = "http://".concat(host, ":").concat(port);
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Returns a reference to the callable https trigger with the given name.
|
|
542
|
-
* @param name - The name of the trigger.
|
|
543
|
-
* @public
|
|
544
|
-
*/
|
|
545
|
-
function httpsCallable$1(functionsInstance, name, options) {
|
|
546
|
-
return (function (data) {
|
|
547
|
-
return call(functionsInstance, name, data, options || {});
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Returns a reference to the callable https trigger with the given url.
|
|
552
|
-
* @param url - The url of the trigger.
|
|
553
|
-
* @public
|
|
554
|
-
*/
|
|
555
|
-
function httpsCallableFromURL$1(functionsInstance, url, options) {
|
|
556
|
-
return (function (data) {
|
|
557
|
-
return callAtURL(functionsInstance, url, data, options || {});
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Does an HTTP POST and returns the completed response.
|
|
562
|
-
* @param url The url to post to.
|
|
563
|
-
* @param body The JSON body of the post.
|
|
564
|
-
* @param headers The HTTP headers to include in the request.
|
|
565
|
-
* @return A Promise that will succeed when the request finishes.
|
|
566
|
-
*/
|
|
567
|
-
function postJSON(url, body, headers, fetchImpl) {
|
|
568
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
569
|
-
var response, json;
|
|
570
|
-
return __generator(this, function (_a) {
|
|
571
|
-
switch (_a.label) {
|
|
572
|
-
case 0:
|
|
573
|
-
headers['Content-Type'] = 'application/json';
|
|
574
|
-
_a.label = 1;
|
|
575
|
-
case 1:
|
|
576
|
-
_a.trys.push([1, 3, , 4]);
|
|
577
|
-
return [4 /*yield*/, fetchImpl(url, {
|
|
578
|
-
method: 'POST',
|
|
579
|
-
body: JSON.stringify(body),
|
|
580
|
-
headers: headers
|
|
581
|
-
})];
|
|
582
|
-
case 2:
|
|
583
|
-
response = _a.sent();
|
|
584
|
-
return [3 /*break*/, 4];
|
|
585
|
-
case 3:
|
|
586
|
-
_a.sent();
|
|
587
|
-
// This could be an unhandled error on the backend, or it could be a
|
|
588
|
-
// network error. There's no way to know, since an unhandled error on the
|
|
589
|
-
// backend will fail to set the proper CORS header, and thus will be
|
|
590
|
-
// treated as a network error by fetch.
|
|
591
|
-
return [2 /*return*/, {
|
|
592
|
-
status: 0,
|
|
593
|
-
json: null
|
|
594
|
-
}];
|
|
595
|
-
case 4:
|
|
596
|
-
json = null;
|
|
597
|
-
_a.label = 5;
|
|
598
|
-
case 5:
|
|
599
|
-
_a.trys.push([5, 7, , 8]);
|
|
600
|
-
return [4 /*yield*/, response.json()];
|
|
601
|
-
case 6:
|
|
602
|
-
json = _a.sent();
|
|
603
|
-
return [3 /*break*/, 8];
|
|
604
|
-
case 7:
|
|
605
|
-
_a.sent();
|
|
606
|
-
return [3 /*break*/, 8];
|
|
607
|
-
case 8: return [2 /*return*/, {
|
|
608
|
-
status: response.status,
|
|
609
|
-
json: json
|
|
610
|
-
}];
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Calls a callable function asynchronously and returns the result.
|
|
617
|
-
* @param name The name of the callable trigger.
|
|
618
|
-
* @param data The data to pass as params to the function.s
|
|
619
|
-
*/
|
|
620
|
-
function call(functionsInstance, name, data, options) {
|
|
621
|
-
var url = functionsInstance._url(name);
|
|
622
|
-
return callAtURL(functionsInstance, url, data, options);
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Calls a callable function asynchronously and returns the result.
|
|
626
|
-
* @param url The url of the callable trigger.
|
|
627
|
-
* @param data The data to pass as params to the function.s
|
|
628
|
-
*/
|
|
629
|
-
function callAtURL(functionsInstance, url, data, options) {
|
|
630
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
631
|
-
var body, headers, context, timeout, failAfterHandle, response, error, responseData, decodedData;
|
|
632
|
-
return __generator(this, function (_a) {
|
|
633
|
-
switch (_a.label) {
|
|
634
|
-
case 0:
|
|
635
|
-
// Encode any special types, such as dates, in the input data.
|
|
636
|
-
data = encode(data);
|
|
637
|
-
body = { data: data };
|
|
638
|
-
headers = {};
|
|
639
|
-
return [4 /*yield*/, functionsInstance.contextProvider.getContext(options.limitedUseAppCheckTokens)];
|
|
640
|
-
case 1:
|
|
641
|
-
context = _a.sent();
|
|
642
|
-
if (context.authToken) {
|
|
643
|
-
headers['Authorization'] = 'Bearer ' + context.authToken;
|
|
644
|
-
}
|
|
645
|
-
if (context.messagingToken) {
|
|
646
|
-
headers['Firebase-Instance-ID-Token'] = context.messagingToken;
|
|
647
|
-
}
|
|
648
|
-
if (context.appCheckToken !== null) {
|
|
649
|
-
headers['X-Firebase-AppCheck'] = context.appCheckToken;
|
|
650
|
-
}
|
|
651
|
-
timeout = options.timeout || 70000;
|
|
652
|
-
failAfterHandle = failAfter(timeout);
|
|
653
|
-
return [4 /*yield*/, Promise.race([
|
|
654
|
-
postJSON(url, body, headers, functionsInstance.fetchImpl),
|
|
655
|
-
failAfterHandle.promise,
|
|
656
|
-
functionsInstance.cancelAllRequests
|
|
657
|
-
])];
|
|
658
|
-
case 2:
|
|
659
|
-
response = _a.sent();
|
|
660
|
-
// Always clear the failAfter timeout
|
|
661
|
-
failAfterHandle.cancel();
|
|
662
|
-
// If service was deleted, interrupted response throws an error.
|
|
663
|
-
if (!response) {
|
|
664
|
-
throw new FunctionsError('cancelled', 'Firebase Functions instance was deleted.');
|
|
665
|
-
}
|
|
666
|
-
error = _errorForResponse(response.status, response.json);
|
|
667
|
-
if (error) {
|
|
668
|
-
throw error;
|
|
669
|
-
}
|
|
670
|
-
if (!response.json) {
|
|
671
|
-
throw new FunctionsError('internal', 'Response is not valid JSON object.');
|
|
672
|
-
}
|
|
673
|
-
responseData = response.json.data;
|
|
674
|
-
// TODO(klimt): For right now, allow "result" instead of "data", for
|
|
675
|
-
// backwards compatibility.
|
|
676
|
-
if (typeof responseData === 'undefined') {
|
|
677
|
-
responseData = response.json.result;
|
|
678
|
-
}
|
|
679
|
-
if (typeof responseData === 'undefined') {
|
|
680
|
-
// Consider the response malformed.
|
|
681
|
-
throw new FunctionsError('internal', 'Response is missing data field.');
|
|
682
|
-
}
|
|
683
|
-
decodedData = decode(responseData);
|
|
684
|
-
return [2 /*return*/, { data: decodedData }];
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
var name = "@firebase/functions";
|
|
691
|
-
var version = "0.11.8";
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* @license
|
|
695
|
-
* Copyright 2019 Google LLC
|
|
696
|
-
*
|
|
697
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
698
|
-
* you may not use this file except in compliance with the License.
|
|
699
|
-
* You may obtain a copy of the License at
|
|
700
|
-
*
|
|
701
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
702
|
-
*
|
|
703
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
704
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
705
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
706
|
-
* See the License for the specific language governing permissions and
|
|
707
|
-
* limitations under the License.
|
|
708
|
-
*/
|
|
709
|
-
var AUTH_INTERNAL_NAME = 'auth-internal';
|
|
710
|
-
var APP_CHECK_INTERNAL_NAME = 'app-check-internal';
|
|
711
|
-
var MESSAGING_INTERNAL_NAME = 'messaging-internal';
|
|
712
|
-
function registerFunctions(fetchImpl, variant) {
|
|
713
|
-
var factory = function (container, _a) {
|
|
714
|
-
var regionOrCustomDomain = _a.instanceIdentifier;
|
|
715
|
-
// Dependencies
|
|
716
|
-
var app = container.getProvider('app').getImmediate();
|
|
717
|
-
var authProvider = container.getProvider(AUTH_INTERNAL_NAME);
|
|
718
|
-
var messagingProvider = container.getProvider(MESSAGING_INTERNAL_NAME);
|
|
719
|
-
var appCheckProvider = container.getProvider(APP_CHECK_INTERNAL_NAME);
|
|
720
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
721
|
-
return new FunctionsService(app, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain, fetchImpl);
|
|
722
|
-
};
|
|
723
|
-
_registerComponent(new Component(FUNCTIONS_TYPE, factory, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
|
|
724
|
-
registerVersion(name, version, variant);
|
|
725
|
-
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
|
|
726
|
-
registerVersion(name, version, 'esm5');
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* @license
|
|
731
|
-
* Copyright 2020 Google LLC
|
|
732
|
-
*
|
|
733
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
734
|
-
* you may not use this file except in compliance with the License.
|
|
735
|
-
* You may obtain a copy of the License at
|
|
736
|
-
*
|
|
737
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
738
|
-
*
|
|
739
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
740
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
741
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
742
|
-
* See the License for the specific language governing permissions and
|
|
743
|
-
* limitations under the License.
|
|
744
|
-
*/
|
|
745
|
-
/**
|
|
746
|
-
* Returns a {@link Functions} instance for the given app.
|
|
747
|
-
* @param app - The {@link @firebase/app#FirebaseApp} to use.
|
|
748
|
-
* @param regionOrCustomDomain - one of:
|
|
749
|
-
* a) The region the callable functions are located in (ex: us-central1)
|
|
750
|
-
* b) A custom domain hosting the callable functions (ex: https://mydomain.com)
|
|
751
|
-
* @public
|
|
752
|
-
*/
|
|
753
|
-
function getFunctions(app, regionOrCustomDomain) {
|
|
754
|
-
if (app === void 0) { app = getApp(); }
|
|
755
|
-
if (regionOrCustomDomain === void 0) { regionOrCustomDomain = DEFAULT_REGION; }
|
|
756
|
-
// Dependencies
|
|
757
|
-
var functionsProvider = _getProvider(getModularInstance(app), FUNCTIONS_TYPE);
|
|
758
|
-
var functionsInstance = functionsProvider.getImmediate({
|
|
759
|
-
identifier: regionOrCustomDomain
|
|
760
|
-
});
|
|
761
|
-
var emulator = getDefaultEmulatorHostnameAndPort('functions');
|
|
762
|
-
if (emulator) {
|
|
763
|
-
connectFunctionsEmulator.apply(void 0, __spreadArray([functionsInstance], emulator, false));
|
|
764
|
-
}
|
|
765
|
-
return functionsInstance;
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Modify this instance to communicate with the Cloud Functions emulator.
|
|
769
|
-
*
|
|
770
|
-
* Note: this must be called before this instance has been used to do any operations.
|
|
771
|
-
*
|
|
772
|
-
* @param host - The emulator host (ex: localhost)
|
|
773
|
-
* @param port - The emulator port (ex: 5001)
|
|
774
|
-
* @public
|
|
775
|
-
*/
|
|
776
|
-
function connectFunctionsEmulator(functionsInstance, host, port) {
|
|
777
|
-
connectFunctionsEmulator$1(getModularInstance(functionsInstance), host, port);
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Returns a reference to the callable HTTPS trigger with the given name.
|
|
781
|
-
* @param name - The name of the trigger.
|
|
782
|
-
* @public
|
|
783
|
-
*/
|
|
784
|
-
function httpsCallable(functionsInstance, name, options) {
|
|
785
|
-
return httpsCallable$1(getModularInstance(functionsInstance), name, options);
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
* Returns a reference to the callable HTTPS trigger with the specified url.
|
|
789
|
-
* @param url - The url of the trigger.
|
|
790
|
-
* @public
|
|
791
|
-
*/
|
|
792
|
-
function httpsCallableFromURL(functionsInstance, url, options) {
|
|
793
|
-
return httpsCallableFromURL$1(getModularInstance(functionsInstance), url, options);
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Cloud Functions for Firebase
|
|
798
|
-
*
|
|
799
|
-
* @packageDocumentation
|
|
800
|
-
*/
|
|
801
|
-
registerFunctions(fetch.bind(self));
|
|
802
|
-
|
|
803
|
-
export { connectFunctionsEmulator, getFunctions, httpsCallable, httpsCallableFromURL };
|
|
804
|
-
//# sourceMappingURL=index.esm.js.map
|