firebase-functions 3.24.0 → 4.0.0-rc.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.
- package/README.md +7 -9
- package/lib/bin/firebase-functions.js +13 -15
- package/lib/common/app.d.ts +14 -0
- package/lib/common/app.js +62 -0
- package/lib/common/change.d.ts +0 -5
- package/lib/common/change.js +5 -7
- package/lib/common/config.d.ts +6 -0
- package/lib/common/config.js +49 -0
- package/lib/common/debug.js +2 -2
- package/lib/common/encoding.d.ts +0 -8
- package/lib/common/encoding.js +6 -29
- package/lib/common/options.d.ts +14 -0
- package/lib/common/options.js +44 -0
- package/lib/common/params.d.ts +32 -0
- package/lib/common/params.js +23 -0
- package/lib/common/providers/database.d.ts +17 -19
- package/lib/common/providers/database.js +68 -39
- package/lib/common/providers/https.d.ts +11 -52
- package/lib/common/providers/https.js +115 -110
- package/lib/common/providers/identity.d.ts +8 -8
- package/lib/common/providers/identity.js +71 -79
- package/lib/common/providers/tasks.d.ts +11 -10
- package/lib/common/providers/tasks.js +10 -9
- package/lib/common/timezone.js +538 -538
- package/lib/common/trace.d.ts +14 -0
- package/lib/common/trace.js +69 -0
- package/lib/{encoder.d.ts → common/utilities/encoder.d.ts} +0 -0
- package/lib/{encoder.js → common/utilities/encoder.js} +1 -1
- package/lib/{utilities → common/utilities}/path-pattern.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path-pattern.js +17 -16
- package/lib/{utilities → common/utilities}/path.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path.js +5 -7
- package/lib/{utils.d.ts → common/utilities/utils.d.ts} +1 -1
- package/lib/{utils.js → common/utilities/utils.js} +18 -12
- package/lib/logger/common.d.ts +1 -3
- package/lib/logger/common.js +9 -14
- package/lib/logger/compat.js +9 -9
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +24 -30
- package/lib/{v2/params → params}/index.d.ts +22 -9
- package/lib/{v2/params → params}/index.js +22 -14
- package/lib/params/types.d.ts +180 -0
- package/lib/params/types.js +289 -0
- package/lib/runtime/loader.js +12 -14
- package/lib/runtime/manifest.d.ts +56 -24
- package/lib/runtime/manifest.js +114 -4
- package/lib/v1/cloud-functions.d.ts +232 -0
- package/lib/v1/cloud-functions.js +205 -0
- package/lib/v1/config.d.ts +8 -0
- package/lib/v1/config.js +75 -0
- package/lib/{function-builder.d.ts → v1/function-builder.d.ts} +16 -16
- package/lib/{function-builder.js → v1/function-builder.js} +56 -46
- package/lib/v1/function-configuration.d.ts +197 -0
- package/lib/v1/function-configuration.js +70 -0
- package/lib/v1/index.d.ts +20 -0
- package/lib/{index.js → v1/index.js} +5 -10
- package/lib/{providers → v1/providers}/analytics.d.ts +5 -11
- package/lib/{providers → v1/providers}/analytics.js +49 -43
- package/lib/{providers → v1/providers}/auth.d.ts +28 -18
- package/lib/{providers → v1/providers}/auth.js +45 -34
- package/lib/{providers → v1/providers}/database.d.ts +25 -42
- package/lib/{providers → v1/providers}/database.js +46 -46
- package/lib/{providers → v1/providers}/firestore.d.ts +15 -33
- package/lib/{providers → v1/providers}/firestore.js +40 -44
- package/lib/{providers → v1/providers}/https.d.ts +3 -8
- package/lib/{providers → v1/providers}/https.js +14 -22
- package/lib/{providers → v1/providers}/pubsub.d.ts +8 -16
- package/lib/{providers → v1/providers}/pubsub.js +22 -26
- package/lib/{providers → v1/providers}/remoteConfig.d.ts +2 -11
- package/lib/{providers → v1/providers}/remoteConfig.js +9 -9
- package/lib/{providers → v1/providers}/storage.d.ts +11 -26
- package/lib/{providers → v1/providers}/storage.js +24 -29
- package/lib/{providers → v1/providers}/tasks.d.ts +6 -8
- package/lib/{providers → v1/providers}/tasks.js +12 -17
- package/lib/{providers → v1/providers}/testLab.d.ts +86 -46
- package/lib/{providers → v1/providers}/testLab.js +14 -14
- package/lib/v2/core.d.ts +4 -5
- package/lib/v2/index.d.ts +16 -14
- package/lib/v2/index.js +5 -1
- package/lib/v2/options.d.ts +52 -32
- package/lib/v2/options.js +32 -47
- package/lib/v2/providers/alerts/alerts.d.ts +20 -18
- package/lib/v2/providers/alerts/alerts.js +9 -6
- package/lib/v2/providers/alerts/appDistribution.d.ts +36 -26
- package/lib/v2/providers/alerts/appDistribution.js +10 -7
- package/lib/v2/providers/alerts/billing.d.ts +5 -5
- package/lib/v2/providers/alerts/billing.js +5 -4
- package/lib/v2/providers/alerts/crashlytics.d.ts +32 -30
- package/lib/v2/providers/alerts/crashlytics.js +10 -9
- package/lib/v2/providers/alerts/index.d.ts +5 -5
- package/lib/v2/providers/alerts/performance.d.ts +15 -3
- package/lib/v2/providers/alerts/performance.js +5 -7
- package/lib/v2/providers/database.d.ts +41 -38
- package/lib/v2/providers/database.js +22 -17
- package/lib/v2/providers/eventarc.d.ts +25 -23
- package/lib/v2/providers/eventarc.js +10 -7
- package/lib/v2/providers/https.d.ts +43 -33
- package/lib/v2/providers/https.js +18 -56
- package/lib/v2/providers/identity.d.ts +25 -23
- package/lib/v2/providers/identity.js +10 -7
- package/lib/v2/providers/pubsub.d.ts +25 -23
- package/lib/v2/providers/pubsub.js +11 -27
- package/lib/v2/providers/remoteConfig.d.ts +63 -0
- package/lib/v2/providers/remoteConfig.js +65 -0
- package/lib/v2/providers/scheduler.d.ts +14 -12
- package/lib/v2/providers/scheduler.js +16 -14
- package/lib/v2/providers/storage.d.ts +32 -30
- package/lib/v2/providers/storage.js +16 -32
- package/lib/v2/providers/tasks.d.ts +30 -26
- package/lib/v2/providers/tasks.js +14 -31
- package/lib/v2/providers/testLab.d.ts +110 -0
- package/lib/v2/providers/testLab.js +65 -0
- package/lib/v2/trace.d.ts +4 -0
- package/lib/v2/trace.js +21 -0
- package/package.json +62 -67
- package/lib/apps.d.ts +0 -35
- package/lib/apps.js +0 -112
- package/lib/cloud-functions.d.ts +0 -231
- package/lib/cloud-functions.js +0 -251
- package/lib/config.d.ts +0 -24
- package/lib/config.js +0 -117
- package/lib/function-configuration.d.ts +0 -108
- package/lib/function-configuration.js +0 -71
- package/lib/handler-builder.d.ts +0 -256
- package/lib/handler-builder.js +0 -349
- package/lib/index.d.ts +0 -19
- package/lib/setup.d.ts +0 -1
- package/lib/setup.js +0 -60
- package/lib/v2/params/types.d.ts +0 -118
- package/lib/v2/params/types.js +0 -196
package/lib/runtime/manifest.js
CHANGED
|
@@ -21,13 +21,15 @@
|
|
|
21
21
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.stackToWire = void 0;
|
|
25
|
-
const
|
|
24
|
+
exports.initV2ScheduleTrigger = exports.initV1ScheduleTrigger = exports.initTaskQueueTrigger = exports.initV2Endpoint = exports.initV1Endpoint = exports.stackToWire = void 0;
|
|
25
|
+
const options_1 = require("../common/options");
|
|
26
|
+
const params_1 = require("../params");
|
|
26
27
|
/**
|
|
27
28
|
* Returns the JSON representation of a ManifestStack, which has CEL
|
|
28
29
|
* expressions in its options as object types, with its expressions
|
|
29
30
|
* transformed into the actual CEL strings.
|
|
30
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* @alpha
|
|
31
33
|
*/
|
|
32
34
|
function stackToWire(stack) {
|
|
33
35
|
const wireStack = stack;
|
|
@@ -36,7 +38,11 @@ function stackToWire(stack) {
|
|
|
36
38
|
if (val instanceof params_1.Expression) {
|
|
37
39
|
obj[key] = val.toCEL();
|
|
38
40
|
}
|
|
39
|
-
else if (
|
|
41
|
+
else if (val instanceof options_1.ResetValue) {
|
|
42
|
+
obj[key] = val.toJSON();
|
|
43
|
+
}
|
|
44
|
+
else if (typeof val === "object" && val !== null) {
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
40
46
|
traverse(val);
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -45,3 +51,107 @@ function stackToWire(stack) {
|
|
|
45
51
|
return wireStack;
|
|
46
52
|
}
|
|
47
53
|
exports.stackToWire = stackToWire;
|
|
54
|
+
const RESETTABLE_OPTIONS = {
|
|
55
|
+
availableMemoryMb: null,
|
|
56
|
+
timeoutSeconds: null,
|
|
57
|
+
minInstances: null,
|
|
58
|
+
maxInstances: null,
|
|
59
|
+
ingressSettings: null,
|
|
60
|
+
concurrency: null,
|
|
61
|
+
serviceAccountEmail: null,
|
|
62
|
+
vpc: null,
|
|
63
|
+
};
|
|
64
|
+
function initEndpoint(resetOptions, ...opts) {
|
|
65
|
+
const endpoint = {};
|
|
66
|
+
if (opts.every((opt) => !(opt === null || opt === void 0 ? void 0 : opt.preserveExternalChanges))) {
|
|
67
|
+
for (const key of Object.keys(resetOptions)) {
|
|
68
|
+
endpoint[key] = options_1.RESET_VALUE;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return endpoint;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
function initV1Endpoint(...opts) {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
78
|
+
const { concurrency, ...resetOpts } = RESETTABLE_OPTIONS;
|
|
79
|
+
return initEndpoint({ ...resetOpts }, ...opts);
|
|
80
|
+
}
|
|
81
|
+
exports.initV1Endpoint = initV1Endpoint;
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
function initV2Endpoint(...opts) {
|
|
86
|
+
return initEndpoint(RESETTABLE_OPTIONS, ...opts);
|
|
87
|
+
}
|
|
88
|
+
exports.initV2Endpoint = initV2Endpoint;
|
|
89
|
+
const RESETTABLE_RETRY_CONFIG_OPTIONS = {
|
|
90
|
+
maxAttempts: null,
|
|
91
|
+
maxDoublings: null,
|
|
92
|
+
maxBackoffSeconds: null,
|
|
93
|
+
maxRetrySeconds: null,
|
|
94
|
+
minBackoffSeconds: null,
|
|
95
|
+
};
|
|
96
|
+
const RESETTABLE_RATE_LIMITS_OPTIONS = {
|
|
97
|
+
maxConcurrentDispatches: null,
|
|
98
|
+
maxDispatchesPerSecond: null,
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
function initTaskQueueTrigger(...opts) {
|
|
104
|
+
let taskQueueTrigger = {};
|
|
105
|
+
if (opts.every((opt) => !(opt === null || opt === void 0 ? void 0 : opt.preserveExternalChanges))) {
|
|
106
|
+
const retryConfig = {};
|
|
107
|
+
for (const key of Object.keys(RESETTABLE_RETRY_CONFIG_OPTIONS)) {
|
|
108
|
+
retryConfig[key] = options_1.RESET_VALUE;
|
|
109
|
+
}
|
|
110
|
+
const rateLimits = {};
|
|
111
|
+
for (const key of Object.keys(RESETTABLE_RATE_LIMITS_OPTIONS)) {
|
|
112
|
+
rateLimits[key] = options_1.RESET_VALUE;
|
|
113
|
+
}
|
|
114
|
+
taskQueueTrigger = { retryConfig, rateLimits };
|
|
115
|
+
}
|
|
116
|
+
return taskQueueTrigger;
|
|
117
|
+
}
|
|
118
|
+
exports.initTaskQueueTrigger = initTaskQueueTrigger;
|
|
119
|
+
const RESETTABLE_V1_SCHEDULE_OPTIONS = {
|
|
120
|
+
retryCount: null,
|
|
121
|
+
maxDoublings: null,
|
|
122
|
+
maxRetryDuration: null,
|
|
123
|
+
maxBackoffDuration: null,
|
|
124
|
+
minBackoffDuration: null,
|
|
125
|
+
};
|
|
126
|
+
const RESETTABLE_V2_SCHEDULE_OPTIONS = {
|
|
127
|
+
retryCount: null,
|
|
128
|
+
maxDoublings: null,
|
|
129
|
+
maxRetrySeconds: null,
|
|
130
|
+
minBackoffSeconds: null,
|
|
131
|
+
maxBackoffSeconds: null,
|
|
132
|
+
};
|
|
133
|
+
function initScheduleTrigger(resetOptions, schedule, ...opts) {
|
|
134
|
+
let scheduleTrigger = { schedule };
|
|
135
|
+
if (opts.every((opt) => !(opt === null || opt === void 0 ? void 0 : opt.preserveExternalChanges))) {
|
|
136
|
+
const retryConfig = {};
|
|
137
|
+
for (const key of Object.keys(resetOptions)) {
|
|
138
|
+
retryConfig[key] = options_1.RESET_VALUE;
|
|
139
|
+
}
|
|
140
|
+
scheduleTrigger = { ...scheduleTrigger, timeZone: options_1.RESET_VALUE, retryConfig };
|
|
141
|
+
}
|
|
142
|
+
return scheduleTrigger;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
function initV1ScheduleTrigger(schedule, ...opts) {
|
|
148
|
+
return initScheduleTrigger(RESETTABLE_V1_SCHEDULE_OPTIONS, schedule, ...opts);
|
|
149
|
+
}
|
|
150
|
+
exports.initV1ScheduleTrigger = initV1ScheduleTrigger;
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
function initV2ScheduleTrigger(schedule, ...opts) {
|
|
155
|
+
return initScheduleTrigger(RESETTABLE_V2_SCHEDULE_OPTIONS, schedule, ...opts);
|
|
156
|
+
}
|
|
157
|
+
exports.initV2ScheduleTrigger = initV2ScheduleTrigger;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
export { Request, Response };
|
|
3
|
+
import { ManifestEndpoint, ManifestRequiredAPI } from "../runtime/manifest";
|
|
4
|
+
export { Change } from "../common/change";
|
|
5
|
+
/**
|
|
6
|
+
* Wire format for an event.
|
|
7
|
+
*/
|
|
8
|
+
export interface Event {
|
|
9
|
+
/**
|
|
10
|
+
* Wire format for an event context.
|
|
11
|
+
*/
|
|
12
|
+
context: {
|
|
13
|
+
eventId: string;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
eventType: string;
|
|
16
|
+
resource: Resource;
|
|
17
|
+
domain?: string;
|
|
18
|
+
auth?: {
|
|
19
|
+
variable?: {
|
|
20
|
+
uid?: string;
|
|
21
|
+
token?: string;
|
|
22
|
+
};
|
|
23
|
+
admin: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Event data over wire.
|
|
28
|
+
*/
|
|
29
|
+
data: any;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The context in which an event occurred.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* An EventContext describes:
|
|
36
|
+
* - The time an event occurred.
|
|
37
|
+
* - A unique identifier of the event.
|
|
38
|
+
* - The resource on which the event occurred, if applicable.
|
|
39
|
+
* - Authorization of the request that triggered the event, if applicable and
|
|
40
|
+
* available.
|
|
41
|
+
*/
|
|
42
|
+
export interface EventContext<Params = Record<string, string>> {
|
|
43
|
+
/**
|
|
44
|
+
* Authentication information for the user that triggered the function.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* This object contains `uid` and `token` properties for authenticated users.
|
|
48
|
+
* For more detail including token keys, see the
|
|
49
|
+
* {@link https://firebase.google.com/docs/reference/rules/rules#properties | security rules reference}.
|
|
50
|
+
*
|
|
51
|
+
* This field is only populated for Realtime Database triggers and Callable
|
|
52
|
+
* functions. For an unauthenticated user, this field is null. For Firebase
|
|
53
|
+
* admin users and event types that do not provide user information, this field
|
|
54
|
+
* does not exist.
|
|
55
|
+
*/
|
|
56
|
+
auth?: {
|
|
57
|
+
token: object;
|
|
58
|
+
uid: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The level of permissions for a user.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Valid values are:
|
|
65
|
+
*
|
|
66
|
+
* - `ADMIN`: Developer user or user authenticated via a service account.
|
|
67
|
+
*
|
|
68
|
+
* - `USER`: Known user.
|
|
69
|
+
*
|
|
70
|
+
* - `UNAUTHENTICATED`: Unauthenticated action
|
|
71
|
+
*
|
|
72
|
+
* - `null`: For event types that do not provide user information (all except
|
|
73
|
+
* Realtime Database).
|
|
74
|
+
*/
|
|
75
|
+
authType?: "ADMIN" | "USER" | "UNAUTHENTICATED";
|
|
76
|
+
/**
|
|
77
|
+
* The event’s unique identifier.
|
|
78
|
+
*/
|
|
79
|
+
eventId: string;
|
|
80
|
+
/**
|
|
81
|
+
* Type of event.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* Possible values are:
|
|
85
|
+
*
|
|
86
|
+
* - `google.analytics.event.log`
|
|
87
|
+
*
|
|
88
|
+
* - `google.firebase.auth.user.create`
|
|
89
|
+
*
|
|
90
|
+
* - `google.firebase.auth.user.delete`
|
|
91
|
+
*
|
|
92
|
+
* - `google.firebase.database.ref.write`
|
|
93
|
+
*
|
|
94
|
+
* - `google.firebase.database.ref.create`
|
|
95
|
+
*
|
|
96
|
+
* - `google.firebase.database.ref.update`
|
|
97
|
+
*
|
|
98
|
+
* - `google.firebase.database.ref.delete`
|
|
99
|
+
*
|
|
100
|
+
* - `google.firestore.document.write`
|
|
101
|
+
*
|
|
102
|
+
* - `google.firestore.document.create`
|
|
103
|
+
*
|
|
104
|
+
* - `google.firestore.document.update`
|
|
105
|
+
*
|
|
106
|
+
* - `google.firestore.document.delete`
|
|
107
|
+
*
|
|
108
|
+
* - `google.pubsub.topic.publish`
|
|
109
|
+
*
|
|
110
|
+
* - `google.firebase.remoteconfig.update`
|
|
111
|
+
*
|
|
112
|
+
* - `google.storage.object.finalize`
|
|
113
|
+
*
|
|
114
|
+
* - `google.storage.object.archive`
|
|
115
|
+
*
|
|
116
|
+
* - `google.storage.object.delete`
|
|
117
|
+
*
|
|
118
|
+
* - `google.storage.object.metadataUpdate`
|
|
119
|
+
*
|
|
120
|
+
* - `google.testing.testMatrix.complete`
|
|
121
|
+
*/
|
|
122
|
+
eventType: string;
|
|
123
|
+
/**
|
|
124
|
+
* An object containing the values of the wildcards in the `path` parameter
|
|
125
|
+
* provided to the {@link fireabase-functions.v1.database#ref | `ref()`} method for a Realtime Database trigger.
|
|
126
|
+
*/
|
|
127
|
+
params: Params;
|
|
128
|
+
/**
|
|
129
|
+
* The resource that emitted the event.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* Valid values are:
|
|
133
|
+
*
|
|
134
|
+
* Analytics: `projects/<projectId>/events/<analyticsEventType>`
|
|
135
|
+
*
|
|
136
|
+
* Realtime Database: `projects/_/instances/<databaseInstance>/refs/<databasePath>`
|
|
137
|
+
*
|
|
138
|
+
* Storage: `projects/_/buckets/<bucketName>/objects/<fileName>#<generation>`
|
|
139
|
+
*
|
|
140
|
+
* Authentication: `projects/<projectId>`
|
|
141
|
+
*
|
|
142
|
+
* Pub/Sub: `projects/<projectId>/topics/<topicName>`
|
|
143
|
+
*
|
|
144
|
+
* Because Realtime Database instances and Cloud Storage buckets are globally
|
|
145
|
+
* unique and not tied to the project, their resources start with `projects/_`.
|
|
146
|
+
* Underscore is not a valid project name.
|
|
147
|
+
*/
|
|
148
|
+
resource: Resource;
|
|
149
|
+
/**
|
|
150
|
+
* Timestamp for the event as an {@link https://www.ietf.org/rfc/rfc3339.txt | RFC 3339} string.
|
|
151
|
+
*/
|
|
152
|
+
timestamp: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Resource is a standard format for defining a resource
|
|
156
|
+
* (google.rpc.context.AttributeContext.Resource). In Cloud Functions, it is the
|
|
157
|
+
* resource that triggered the function - such as a storage bucket.
|
|
158
|
+
*/
|
|
159
|
+
export interface Resource {
|
|
160
|
+
/** The name of the service that this resource belongs to. */
|
|
161
|
+
service: string;
|
|
162
|
+
/**
|
|
163
|
+
* The stable identifier (name) of a resource on the service.
|
|
164
|
+
* A resource can be logically identified as "//{resource.service}/{resource.name}"
|
|
165
|
+
*/
|
|
166
|
+
name: string;
|
|
167
|
+
/**
|
|
168
|
+
* The type of the resource. The syntax is platform-specific because different platforms define their resources differently.
|
|
169
|
+
* For Google APIs, the type format must be "{service}/{kind}"
|
|
170
|
+
*/
|
|
171
|
+
type?: string;
|
|
172
|
+
/** Map of Resource's labels. */
|
|
173
|
+
labels?: {
|
|
174
|
+
[tag: string]: string;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* A Runnable has a `run` method which directly invokes the user-defined
|
|
179
|
+
* function - useful for unit testing.
|
|
180
|
+
*/
|
|
181
|
+
export interface Runnable<T> {
|
|
182
|
+
/** Directly invoke the user defined function. */
|
|
183
|
+
run: (data: T, context: any) => PromiseLike<any> | any;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The function type for HTTPS triggers. This should be exported from your
|
|
187
|
+
* JavaScript file to define a Cloud Function.
|
|
188
|
+
*
|
|
189
|
+
* @remarks
|
|
190
|
+
* This type is a special JavaScript function which takes Express
|
|
191
|
+
* {@link https://expressjs.com/en/api.html#req | `Request` } and
|
|
192
|
+
* {@link https://expressjs.com/en/api.html#res | `Response` } objects as its only
|
|
193
|
+
* arguments.
|
|
194
|
+
*/
|
|
195
|
+
export interface HttpsFunction {
|
|
196
|
+
(req: Request, resp: Response): void | Promise<void>;
|
|
197
|
+
/** @alpha */
|
|
198
|
+
__endpoint: ManifestEndpoint;
|
|
199
|
+
/** @alpha */
|
|
200
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The function type for Auth Blocking triggers.
|
|
204
|
+
*
|
|
205
|
+
* @remarks
|
|
206
|
+
* This type is a special JavaScript function for Auth Blocking triggers which takes Express
|
|
207
|
+
* {@link https://expressjs.com/en/api.html#req | `Request` } and
|
|
208
|
+
* {@link https://expressjs.com/en/api.html#res | `Response` } objects as its only
|
|
209
|
+
* arguments.
|
|
210
|
+
*/
|
|
211
|
+
export interface BlockingFunction {
|
|
212
|
+
/** @public */
|
|
213
|
+
(req: Request, resp: Response): void | Promise<void>;
|
|
214
|
+
/** @alpha */
|
|
215
|
+
__endpoint: ManifestEndpoint;
|
|
216
|
+
/** @alpha */
|
|
217
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The function type for all non-HTTPS triggers. This should be exported
|
|
221
|
+
* from your JavaScript file to define a Cloud Function.
|
|
222
|
+
*
|
|
223
|
+
* This type is a special JavaScript function which takes a templated
|
|
224
|
+
* `Event` object as its only argument.
|
|
225
|
+
*/
|
|
226
|
+
export interface CloudFunction<T> extends Runnable<T> {
|
|
227
|
+
(input: any, context?: any): PromiseLike<any> | any;
|
|
228
|
+
/** @alpha */
|
|
229
|
+
__endpoint: ManifestEndpoint;
|
|
230
|
+
/** @alpha */
|
|
231
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
232
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2017 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.optionsToEndpoint = exports.makeCloudFunction = exports.Change = void 0;
|
|
25
|
+
const logger_1 = require("../logger");
|
|
26
|
+
const function_configuration_1 = require("./function-configuration");
|
|
27
|
+
const encoding_1 = require("../common/encoding");
|
|
28
|
+
const manifest_1 = require("../runtime/manifest");
|
|
29
|
+
const options_1 = require("../common/options");
|
|
30
|
+
const types_1 = require("../params/types");
|
|
31
|
+
var change_1 = require("../common/change");
|
|
32
|
+
Object.defineProperty(exports, "Change", { enumerable: true, get: function () { return change_1.Change; } });
|
|
33
|
+
/** @internal */
|
|
34
|
+
const WILDCARD_REGEX = new RegExp("{[^/{}]*}", "g");
|
|
35
|
+
/** @internal */
|
|
36
|
+
function makeCloudFunction({ contextOnlyHandler, dataConstructor = (raw) => raw.data, eventType, handler, labels = {}, legacyEventType, options = {}, provider, service, triggerResource, }) {
|
|
37
|
+
const cloudFunction = (data, context) => {
|
|
38
|
+
if (legacyEventType && context.eventType === legacyEventType) {
|
|
39
|
+
/*
|
|
40
|
+
* v1beta1 event flow has different format for context, transform them to
|
|
41
|
+
* new format.
|
|
42
|
+
*/
|
|
43
|
+
context.eventType = provider + "." + eventType;
|
|
44
|
+
context.resource = {
|
|
45
|
+
service,
|
|
46
|
+
name: context.resource,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const event = {
|
|
50
|
+
data,
|
|
51
|
+
context,
|
|
52
|
+
};
|
|
53
|
+
if (provider === "google.firebase.database") {
|
|
54
|
+
context.authType = _detectAuthType(event);
|
|
55
|
+
if (context.authType !== "ADMIN") {
|
|
56
|
+
context.auth = _makeAuth(event, context.authType);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
delete context.auth;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (triggerResource() == null) {
|
|
63
|
+
Object.defineProperty(context, "params", {
|
|
64
|
+
get: () => {
|
|
65
|
+
throw new Error("context.params is not available when using the handler namespace.");
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
context.params = context.params || _makeParams(context, triggerResource);
|
|
71
|
+
}
|
|
72
|
+
let promise;
|
|
73
|
+
if (labels && labels["deployment-scheduled"]) {
|
|
74
|
+
// Scheduled function do not have meaningful data, so exclude it
|
|
75
|
+
promise = contextOnlyHandler(context);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const dataOrChange = dataConstructor(event);
|
|
79
|
+
promise = handler(dataOrChange, context);
|
|
80
|
+
}
|
|
81
|
+
if (typeof promise === "undefined") {
|
|
82
|
+
(0, logger_1.warn)("Function returned undefined, expected Promise or value");
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve(promise);
|
|
85
|
+
};
|
|
86
|
+
Object.defineProperty(cloudFunction, "__endpoint", {
|
|
87
|
+
get: () => {
|
|
88
|
+
if (triggerResource() == null) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const endpoint = {
|
|
92
|
+
platform: "gcfv1",
|
|
93
|
+
...(0, manifest_1.initV1Endpoint)(options),
|
|
94
|
+
...optionsToEndpoint(options),
|
|
95
|
+
};
|
|
96
|
+
if (options.schedule) {
|
|
97
|
+
endpoint.scheduleTrigger = (0, manifest_1.initV1ScheduleTrigger)(options.schedule.schedule, options);
|
|
98
|
+
(0, encoding_1.copyIfPresent)(endpoint.scheduleTrigger, options.schedule, "timeZone");
|
|
99
|
+
(0, encoding_1.copyIfPresent)(endpoint.scheduleTrigger.retryConfig, options.schedule.retryConfig, "retryCount", "maxDoublings", "maxBackoffDuration", "maxRetryDuration", "minBackoffDuration");
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
endpoint.eventTrigger = {
|
|
103
|
+
eventType: legacyEventType || provider + "." + eventType,
|
|
104
|
+
eventFilters: {
|
|
105
|
+
resource: triggerResource(),
|
|
106
|
+
},
|
|
107
|
+
retry: !!options.failurePolicy,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// Note: We intentionally don't make use of labels args here.
|
|
111
|
+
// labels is used to pass SDK-defined labels to the trigger, which isn't
|
|
112
|
+
// something we will do in the container contract world.
|
|
113
|
+
endpoint.labels = { ...endpoint.labels };
|
|
114
|
+
return endpoint;
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
if (options.schedule) {
|
|
118
|
+
cloudFunction.__requiredAPIs = [
|
|
119
|
+
{
|
|
120
|
+
api: "cloudscheduler.googleapis.com",
|
|
121
|
+
reason: "Needed for scheduled functions.",
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
cloudFunction.run = handler || contextOnlyHandler;
|
|
126
|
+
return cloudFunction;
|
|
127
|
+
}
|
|
128
|
+
exports.makeCloudFunction = makeCloudFunction;
|
|
129
|
+
function _makeParams(context, triggerResourceGetter) {
|
|
130
|
+
var _a, _b, _c;
|
|
131
|
+
if (context.params) {
|
|
132
|
+
// In unit testing, user may directly provide `context.params`.
|
|
133
|
+
return context.params;
|
|
134
|
+
}
|
|
135
|
+
if (!context.resource) {
|
|
136
|
+
// In unit testing, `resource` may be unpopulated for a test event.
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
const triggerResource = triggerResourceGetter();
|
|
140
|
+
const wildcards = triggerResource.match(WILDCARD_REGEX);
|
|
141
|
+
const params = {};
|
|
142
|
+
// Note: some tests don't set context.resource.name
|
|
143
|
+
const eventResourceParts = (_c = (_b = (_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.split) === null || _c === void 0 ? void 0 : _c.call(_b, "/");
|
|
144
|
+
if (wildcards && eventResourceParts) {
|
|
145
|
+
const triggerResourceParts = triggerResource.split("/");
|
|
146
|
+
for (const wildcard of wildcards) {
|
|
147
|
+
const wildcardNoBraces = wildcard.slice(1, -1);
|
|
148
|
+
const position = triggerResourceParts.indexOf(wildcard);
|
|
149
|
+
params[wildcardNoBraces] = eventResourceParts[position];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return params;
|
|
153
|
+
}
|
|
154
|
+
function _makeAuth(event, authType) {
|
|
155
|
+
var _a, _b, _c, _d, _e, _f;
|
|
156
|
+
if (authType === "UNAUTHENTICATED") {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
uid: (_c = (_b = (_a = event.context) === null || _a === void 0 ? void 0 : _a.auth) === null || _b === void 0 ? void 0 : _b.variable) === null || _c === void 0 ? void 0 : _c.uid,
|
|
161
|
+
token: (_f = (_e = (_d = event.context) === null || _d === void 0 ? void 0 : _d.auth) === null || _e === void 0 ? void 0 : _e.variable) === null || _f === void 0 ? void 0 : _f.token,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function _detectAuthType(event) {
|
|
165
|
+
var _a, _b, _c, _d;
|
|
166
|
+
if ((_b = (_a = event.context) === null || _a === void 0 ? void 0 : _a.auth) === null || _b === void 0 ? void 0 : _b.admin) {
|
|
167
|
+
return "ADMIN";
|
|
168
|
+
}
|
|
169
|
+
if ((_d = (_c = event.context) === null || _c === void 0 ? void 0 : _c.auth) === null || _d === void 0 ? void 0 : _d.variable) {
|
|
170
|
+
return "USER";
|
|
171
|
+
}
|
|
172
|
+
return "UNAUTHENTICATED";
|
|
173
|
+
}
|
|
174
|
+
/** @internal */
|
|
175
|
+
function optionsToEndpoint(options) {
|
|
176
|
+
const endpoint = {};
|
|
177
|
+
(0, encoding_1.copyIfPresent)(endpoint, options, "minInstances", "maxInstances", "ingressSettings", "labels", "timeoutSeconds");
|
|
178
|
+
(0, encoding_1.convertIfPresent)(endpoint, options, "region", "regions");
|
|
179
|
+
(0, encoding_1.convertIfPresent)(endpoint, options, "serviceAccountEmail", "serviceAccount", (sa) => sa);
|
|
180
|
+
(0, encoding_1.convertIfPresent)(endpoint, options, "secretEnvironmentVariables", "secrets", (secrets) => secrets.map((secret) => ({ key: secret instanceof types_1.SecretParam ? secret.name : secret })));
|
|
181
|
+
if ((options === null || options === void 0 ? void 0 : options.vpcConnector) !== undefined) {
|
|
182
|
+
if (options.vpcConnector === null || options.vpcConnector instanceof options_1.ResetValue) {
|
|
183
|
+
endpoint.vpc = function_configuration_1.RESET_VALUE;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const vpc = { connector: options.vpcConnector };
|
|
187
|
+
(0, encoding_1.convertIfPresent)(vpc, options, "egressSettings", "vpcConnectorEgressSettings");
|
|
188
|
+
endpoint.vpc = vpc;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
(0, encoding_1.convertIfPresent)(endpoint, options, "availableMemoryMb", "memory", (mem) => {
|
|
192
|
+
const memoryLookup = {
|
|
193
|
+
"128MB": 128,
|
|
194
|
+
"256MB": 256,
|
|
195
|
+
"512MB": 512,
|
|
196
|
+
"1GB": 1024,
|
|
197
|
+
"2GB": 2048,
|
|
198
|
+
"4GB": 4096,
|
|
199
|
+
"8GB": 8192,
|
|
200
|
+
};
|
|
201
|
+
return typeof mem === "object" ? mem : memoryLookup[mem];
|
|
202
|
+
});
|
|
203
|
+
return endpoint;
|
|
204
|
+
}
|
|
205
|
+
exports.optionsToEndpoint = optionsToEndpoint;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { firebaseConfig } from "../common/config";
|
|
2
|
+
/**
|
|
3
|
+
* Store and retrieve project configuration data such as third-party API
|
|
4
|
+
* keys or other settings. You can set configuration values using the
|
|
5
|
+
* Firebase CLI as described in
|
|
6
|
+
* [Environment Configuration](/docs/functions/config-env).
|
|
7
|
+
*/
|
|
8
|
+
export declare function config(): Record<string, any>;
|
package/lib/v1/config.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2017 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.config = exports.resetCache = exports.singleton = exports.firebaseConfig = void 0;
|
|
25
|
+
const fs = require("fs");
|
|
26
|
+
const path = require("path");
|
|
27
|
+
var config_1 = require("../common/config");
|
|
28
|
+
Object.defineProperty(exports, "firebaseConfig", { enumerable: true, get: function () { return config_1.firebaseConfig; } });
|
|
29
|
+
/** @internal */
|
|
30
|
+
function resetCache() {
|
|
31
|
+
exports.singleton = undefined;
|
|
32
|
+
}
|
|
33
|
+
exports.resetCache = resetCache;
|
|
34
|
+
/**
|
|
35
|
+
* Store and retrieve project configuration data such as third-party API
|
|
36
|
+
* keys or other settings. You can set configuration values using the
|
|
37
|
+
* Firebase CLI as described in
|
|
38
|
+
* [Environment Configuration](/docs/functions/config-env).
|
|
39
|
+
*/
|
|
40
|
+
function config() {
|
|
41
|
+
// K_CONFIGURATION is only set in GCFv2
|
|
42
|
+
if (process.env.K_CONFIGURATION) {
|
|
43
|
+
throw new Error("functions.config() is no longer available in Cloud Functions for " +
|
|
44
|
+
"Firebase v2. Please see the latest documentation for information " +
|
|
45
|
+
"on how to transition to using environment variables");
|
|
46
|
+
}
|
|
47
|
+
if (typeof exports.singleton === "undefined") {
|
|
48
|
+
init();
|
|
49
|
+
}
|
|
50
|
+
return exports.singleton;
|
|
51
|
+
}
|
|
52
|
+
exports.config = config;
|
|
53
|
+
function init() {
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(process.env.CLOUD_RUNTIME_CONFIG);
|
|
56
|
+
delete parsed.firebase;
|
|
57
|
+
exports.singleton = parsed;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
// Do nothing
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const configPath = process.env.CLOUD_RUNTIME_CONFIG || path.join(process.cwd(), ".runtimeconfig.json");
|
|
65
|
+
const contents = fs.readFileSync(configPath);
|
|
66
|
+
const parsed = JSON.parse(contents.toString("utf8"));
|
|
67
|
+
delete parsed.firebase;
|
|
68
|
+
exports.singleton = parsed;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
// Do nothing
|
|
73
|
+
}
|
|
74
|
+
exports.singleton = {};
|
|
75
|
+
}
|