firebase-functions 6.5.0 → 7.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/lib/_virtual/rolldown_runtime.js +34 -0
- package/lib/bin/firebase-functions.js +78 -103
- package/lib/common/app.js +35 -55
- package/lib/common/change.js +54 -75
- package/lib/common/config.js +41 -41
- package/lib/common/debug.js +23 -47
- package/lib/common/encoding.js +59 -82
- package/lib/common/onInit.js +26 -28
- package/lib/common/options.js +22 -42
- package/lib/common/params.d.ts +6 -6
- package/lib/common/params.js +0 -23
- package/lib/common/providers/database.js +270 -300
- package/lib/common/providers/firestore.js +66 -92
- package/lib/common/providers/https.d.ts +0 -1
- package/lib/common/providers/https.js +537 -539
- package/lib/common/providers/identity.js +393 -444
- package/lib/common/providers/tasks.js +64 -98
- package/lib/common/timezone.js +544 -542
- package/lib/common/trace.d.ts +0 -1
- package/lib/common/trace.js +63 -55
- package/lib/common/utilities/assertions.d.ts +11 -0
- package/lib/common/utilities/assertions.js +18 -0
- package/lib/common/utilities/encoder.js +20 -37
- package/lib/common/utilities/path-pattern.js +106 -132
- package/lib/common/utilities/path.js +28 -27
- package/lib/common/utilities/utils.js +23 -45
- package/lib/esm/_virtual/rolldown_runtime.mjs +16 -0
- package/lib/esm/bin/firebase-functions.mjs +91 -0
- package/lib/esm/common/app.mjs +39 -0
- package/lib/esm/common/change.mjs +57 -0
- package/lib/esm/common/config.mjs +45 -0
- package/lib/esm/common/debug.mjs +28 -0
- package/lib/esm/common/encoding.mjs +69 -0
- package/lib/esm/common/onInit.mjs +33 -0
- package/lib/esm/common/options.mjs +22 -0
- package/lib/esm/common/params.mjs +1 -0
- package/lib/esm/common/providers/database.mjs +269 -0
- package/lib/esm/common/providers/firestore.mjs +78 -0
- package/lib/esm/common/providers/https.mjs +573 -0
- package/lib/esm/common/providers/identity.mjs +428 -0
- package/lib/esm/common/providers/tasks.mjs +67 -0
- package/lib/esm/common/timezone.mjs +544 -0
- package/lib/esm/common/trace.mjs +73 -0
- package/lib/esm/common/utilities/assertions.mjs +17 -0
- package/lib/esm/common/utilities/encoder.mjs +21 -0
- package/lib/esm/common/utilities/path-pattern.mjs +116 -0
- package/lib/esm/common/utilities/path.mjs +35 -0
- package/lib/esm/common/utilities/utils.mjs +29 -0
- package/lib/esm/function-configuration.mjs +1 -0
- package/lib/esm/logger/common.mjs +23 -0
- package/lib/esm/logger/compat.mjs +25 -0
- package/lib/esm/logger/index.mjs +131 -0
- package/lib/esm/params/index.mjs +160 -0
- package/lib/esm/params/types.mjs +400 -0
- package/lib/esm/runtime/loader.mjs +132 -0
- package/lib/esm/runtime/manifest.mjs +134 -0
- package/lib/esm/types/global.d.mjs +1 -0
- package/lib/esm/v1/cloud-functions.mjs +206 -0
- package/lib/esm/v1/config.mjs +14 -0
- package/lib/esm/v1/function-builder.mjs +252 -0
- package/lib/esm/v1/function-configuration.mjs +72 -0
- package/lib/esm/v1/index.mjs +27 -0
- package/lib/esm/v1/providers/analytics.mjs +212 -0
- package/lib/esm/v1/providers/auth.mjs +156 -0
- package/lib/esm/v1/providers/database.mjs +243 -0
- package/lib/esm/v1/providers/firestore.mjs +131 -0
- package/lib/esm/v1/providers/https.mjs +82 -0
- package/lib/esm/v1/providers/pubsub.mjs +175 -0
- package/lib/esm/v1/providers/remoteConfig.mjs +64 -0
- package/lib/esm/v1/providers/storage.mjs +163 -0
- package/lib/esm/v1/providers/tasks.mjs +63 -0
- package/lib/esm/v1/providers/testLab.mjs +94 -0
- package/lib/esm/v2/core.mjs +4 -0
- package/lib/esm/v2/index.mjs +28 -0
- package/lib/esm/v2/options.mjs +102 -0
- package/lib/esm/v2/providers/alerts/alerts.mjs +85 -0
- package/lib/esm/v2/providers/alerts/appDistribution.mjs +75 -0
- package/lib/esm/v2/providers/alerts/billing.mjs +51 -0
- package/lib/esm/v2/providers/alerts/crashlytics.mjs +122 -0
- package/lib/esm/v2/providers/alerts/index.mjs +22 -0
- package/lib/esm/v2/providers/alerts/performance.mjs +66 -0
- package/lib/esm/v2/providers/database.mjs +197 -0
- package/lib/esm/v2/providers/dataconnect.mjs +130 -0
- package/lib/esm/v2/providers/eventarc.mjs +51 -0
- package/lib/esm/v2/providers/firestore.mjs +294 -0
- package/lib/esm/v2/providers/https.mjs +210 -0
- package/lib/esm/v2/providers/identity.mjs +103 -0
- package/lib/esm/v2/providers/pubsub.mjs +148 -0
- package/lib/esm/v2/providers/remoteConfig.mjs +52 -0
- package/lib/esm/v2/providers/scheduler.mjs +84 -0
- package/lib/esm/v2/providers/storage.mjs +155 -0
- package/lib/esm/v2/providers/tasks.mjs +65 -0
- package/lib/esm/v2/providers/testLab.mjs +53 -0
- package/lib/esm/v2/trace.mjs +20 -0
- package/lib/function-configuration.d.ts +0 -0
- package/lib/function-configuration.js +0 -0
- package/lib/logger/common.js +21 -41
- package/lib/logger/compat.js +18 -33
- package/lib/logger/index.js +119 -130
- package/lib/params/index.d.ts +19 -4
- package/lib/params/index.js +153 -129
- package/lib/params/types.d.ts +17 -0
- package/lib/params/types.js +390 -382
- package/lib/runtime/loader.js +114 -148
- package/lib/runtime/manifest.js +106 -126
- package/lib/types/global.d.js +0 -0
- package/lib/v1/cloud-functions.d.ts +2 -2
- package/lib/v1/cloud-functions.js +193 -241
- package/lib/v1/config.d.ts +4 -7
- package/lib/v1/config.js +13 -75
- package/lib/v1/function-builder.js +239 -368
- package/lib/v1/function-configuration.js +70 -63
- package/lib/v1/index.js +118 -73
- package/lib/v1/providers/analytics.js +189 -210
- package/lib/v1/providers/auth.d.ts +2 -1
- package/lib/v1/providers/auth.js +159 -164
- package/lib/v1/providers/database.js +237 -242
- package/lib/v1/providers/firestore.js +131 -130
- package/lib/v1/providers/https.d.ts +2 -1
- package/lib/v1/providers/https.js +79 -86
- package/lib/v1/providers/pubsub.js +175 -172
- package/lib/v1/providers/remoteConfig.js +64 -68
- package/lib/v1/providers/storage.js +161 -163
- package/lib/v1/providers/tasks.d.ts +1 -1
- package/lib/v1/providers/tasks.js +65 -80
- package/lib/v1/providers/testLab.js +94 -94
- package/lib/v2/core.d.ts +1 -1
- package/lib/v2/core.js +5 -32
- package/lib/v2/index.d.ts +6 -3
- package/lib/v2/index.js +123 -75
- package/lib/v2/options.js +88 -114
- package/lib/v2/providers/alerts/alerts.js +76 -95
- package/lib/v2/providers/alerts/appDistribution.js +73 -78
- package/lib/v2/providers/alerts/billing.js +49 -53
- package/lib/v2/providers/alerts/crashlytics.js +110 -102
- package/lib/v2/providers/alerts/index.js +56 -53
- package/lib/v2/providers/alerts/performance.js +64 -74
- package/lib/v2/providers/database.js +177 -180
- package/lib/v2/providers/dataconnect.d.ts +95 -0
- package/lib/v2/providers/dataconnect.js +137 -0
- package/lib/v2/providers/eventarc.js +55 -77
- package/lib/v2/providers/firestore.js +262 -260
- package/lib/v2/providers/https.d.ts +3 -2
- package/lib/v2/providers/https.js +210 -247
- package/lib/v2/providers/identity.d.ts +2 -1
- package/lib/v2/providers/identity.js +96 -105
- package/lib/v2/providers/pubsub.js +149 -167
- package/lib/v2/providers/remoteConfig.js +54 -63
- package/lib/v2/providers/scheduler.js +84 -96
- package/lib/v2/providers/storage.js +147 -162
- package/lib/v2/providers/tasks.d.ts +1 -1
- package/lib/v2/providers/tasks.js +68 -95
- package/lib/v2/providers/testLab.js +55 -64
- package/lib/v2/trace.js +18 -19
- package/package.json +290 -226
- package/protos/compiledFirestore.mjs +3512 -0
- package/protos/update.sh +28 -7
|
@@ -1,124 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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.getOpts = exports.beforeOperation = exports.beforeSmsSent = exports.beforeEmailSent = exports.beforeUserSignedIn = exports.beforeUserCreated = exports.HttpsError = void 0;
|
|
25
|
-
const identity_1 = require("../../common/providers/identity");
|
|
26
|
-
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
|
|
27
|
-
const trace_1 = require("../trace");
|
|
28
|
-
const manifest_1 = require("../../runtime/manifest");
|
|
29
|
-
const options = require("../options");
|
|
30
|
-
const onInit_1 = require("../../common/onInit");
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_runtime_manifest = require('../../runtime/manifest.js');
|
|
3
|
+
const require_common_onInit = require('../../common/onInit.js');
|
|
4
|
+
const require_common_providers_https = require('../../common/providers/https.js');
|
|
5
|
+
const require_common_providers_identity = require('../../common/providers/identity.js');
|
|
6
|
+
const require_v2_trace = require('../trace.js');
|
|
7
|
+
const require_v2_options = require('../options.js');
|
|
8
|
+
|
|
9
|
+
//#region src/v2/providers/identity.ts
|
|
10
|
+
var identity_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
11
|
+
HttpsError: () => require_common_providers_https.HttpsError,
|
|
12
|
+
beforeEmailSent: () => beforeEmailSent,
|
|
13
|
+
beforeOperation: () => beforeOperation,
|
|
14
|
+
beforeSmsSent: () => beforeSmsSent,
|
|
15
|
+
beforeUserCreated: () => beforeUserCreated,
|
|
16
|
+
beforeUserSignedIn: () => beforeUserSignedIn,
|
|
17
|
+
getOpts: () => getOpts
|
|
18
|
+
});
|
|
31
19
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
* Handles an event that is triggered before a user is created.
|
|
21
|
+
* @param optsOrHandler - Either an object containing function options, or an event handler (run before user creation).
|
|
22
|
+
* @param handler? - If defined, an event handler which is run every time before a user is created.
|
|
23
|
+
*/
|
|
36
24
|
function beforeUserCreated(optsOrHandler, handler) {
|
|
37
|
-
|
|
25
|
+
return beforeOperation("beforeCreate", optsOrHandler, handler);
|
|
38
26
|
}
|
|
39
|
-
exports.beforeUserCreated = beforeUserCreated;
|
|
40
27
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
* Handles an event that is triggered before a user is signed in.
|
|
29
|
+
* @param optsOrHandler - Either an object containing function options, or an event handler (run before user signin).
|
|
30
|
+
* @param handler - Event handler which is run every time before a user is signed in.
|
|
31
|
+
*/
|
|
45
32
|
function beforeUserSignedIn(optsOrHandler, handler) {
|
|
46
|
-
|
|
33
|
+
return beforeOperation("beforeSignIn", optsOrHandler, handler);
|
|
47
34
|
}
|
|
48
|
-
exports.beforeUserSignedIn = beforeUserSignedIn;
|
|
49
35
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
* Handles an event that is triggered before an email is sent to a user.
|
|
37
|
+
* @param optsOrHandler- Either an object containing function options, or an event handler that is run before an email is sent to a user.
|
|
38
|
+
* @param handler - Event handler that is run before an email is sent to a user.
|
|
39
|
+
*/
|
|
54
40
|
function beforeEmailSent(optsOrHandler, handler) {
|
|
55
|
-
|
|
41
|
+
return beforeOperation("beforeSendEmail", optsOrHandler, handler);
|
|
56
42
|
}
|
|
57
|
-
exports.beforeEmailSent = beforeEmailSent;
|
|
58
43
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
44
|
+
* Handles an event that is triggered before an SMS is sent to a user.
|
|
45
|
+
* @param optsOrHandler - Either an object containing function options, or an event handler that is run before an SMS is sent to a user.
|
|
46
|
+
* @param handler - Event handler that is run before an SMS is sent to a user.
|
|
47
|
+
*/
|
|
63
48
|
function beforeSmsSent(optsOrHandler, handler) {
|
|
64
|
-
|
|
49
|
+
return beforeOperation("beforeSendSms", optsOrHandler, handler);
|
|
65
50
|
}
|
|
66
|
-
exports.beforeSmsSent = beforeSmsSent;
|
|
67
51
|
/** @hidden */
|
|
68
52
|
function beforeOperation(eventType, optsOrHandler, handler) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
api: "identitytoolkit.googleapis.com",
|
|
101
|
-
reason: "Needed for auth blocking functions",
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
func.run = handler;
|
|
105
|
-
return func;
|
|
53
|
+
if (!handler || typeof optsOrHandler === "function") {
|
|
54
|
+
handler = optsOrHandler;
|
|
55
|
+
optsOrHandler = {};
|
|
56
|
+
}
|
|
57
|
+
const { opts,...blockingOptions } = getOpts(optsOrHandler);
|
|
58
|
+
const annotatedHandler = Object.assign(handler, { platform: "gcfv2" });
|
|
59
|
+
const func = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(require_common_providers_identity.wrapHandler(eventType, annotatedHandler)));
|
|
60
|
+
const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
|
|
61
|
+
/** Endpoint */
|
|
62
|
+
const baseOptsEndpoint = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
|
|
63
|
+
const specificOptsEndpoint = require_v2_options.optionsToEndpoint(opts);
|
|
64
|
+
func.__endpoint = {
|
|
65
|
+
...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
|
|
66
|
+
platform: "gcfv2",
|
|
67
|
+
...baseOptsEndpoint,
|
|
68
|
+
...specificOptsEndpoint,
|
|
69
|
+
labels: {
|
|
70
|
+
...baseOptsEndpoint?.labels,
|
|
71
|
+
...specificOptsEndpoint?.labels
|
|
72
|
+
},
|
|
73
|
+
blockingTrigger: {
|
|
74
|
+
eventType: legacyEventType,
|
|
75
|
+
options: { ...(eventType === "beforeCreate" || eventType === "beforeSignIn") && blockingOptions }
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
func.__requiredAPIs = [{
|
|
79
|
+
api: "identitytoolkit.googleapis.com",
|
|
80
|
+
reason: "Needed for auth blocking functions"
|
|
81
|
+
}];
|
|
82
|
+
func.run = handler;
|
|
83
|
+
return func;
|
|
106
84
|
}
|
|
107
|
-
exports.beforeOperation = beforeOperation;
|
|
108
85
|
/** @hidden */
|
|
109
86
|
function getOpts(blockingOptions) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
87
|
+
const accessToken = blockingOptions.accessToken || false;
|
|
88
|
+
const idToken = blockingOptions.idToken || false;
|
|
89
|
+
const refreshToken = blockingOptions.refreshToken || false;
|
|
90
|
+
const opts = { ...blockingOptions };
|
|
91
|
+
delete opts.accessToken;
|
|
92
|
+
delete opts.idToken;
|
|
93
|
+
delete opts.refreshToken;
|
|
94
|
+
return {
|
|
95
|
+
opts,
|
|
96
|
+
accessToken,
|
|
97
|
+
idToken,
|
|
98
|
+
refreshToken
|
|
99
|
+
};
|
|
123
100
|
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
exports.HttpsError = require_common_providers_https.HttpsError;
|
|
104
|
+
exports.beforeEmailSent = beforeEmailSent;
|
|
105
|
+
exports.beforeOperation = beforeOperation;
|
|
106
|
+
exports.beforeSmsSent = beforeSmsSent;
|
|
107
|
+
exports.beforeUserCreated = beforeUserCreated;
|
|
108
|
+
exports.beforeUserSignedIn = beforeUserSignedIn;
|
|
124
109
|
exports.getOpts = getOpts;
|
|
110
|
+
Object.defineProperty(exports, 'identity_exports', {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function () {
|
|
113
|
+
return identity_exports;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
@@ -1,173 +1,155 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.onMessagePublished = exports.Message = void 0;
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_runtime_manifest = require('../../runtime/manifest.js');
|
|
3
|
+
const require_common_encoding = require('../../common/encoding.js');
|
|
4
|
+
const require_common_onInit = require('../../common/onInit.js');
|
|
5
|
+
const require_v2_trace = require('../trace.js');
|
|
6
|
+
const require_v2_options = require('../options.js');
|
|
7
|
+
|
|
8
|
+
//#region src/v2/providers/pubsub.ts
|
|
9
|
+
var pubsub_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
10
|
+
Message: () => Message,
|
|
11
|
+
onMessagePublished: () => onMessagePublished
|
|
12
|
+
});
|
|
25
13
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
* Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
|
|
15
|
+
* You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
|
|
16
|
+
*
|
|
17
|
+
* This function triggers whenever a new pub/sub message is sent to a specific topic.
|
|
18
|
+
* You must specify the Pub/Sub topic name that you want to trigger your function, and set the event within the
|
|
19
|
+
* onPublish() event handler.
|
|
20
|
+
*
|
|
21
|
+
* PubSub Topic:
|
|
22
|
+
* <ul>
|
|
23
|
+
* <li>A resource that you can publish messages to and then consume those messages via subscriptions.
|
|
24
|
+
* <li>An isolated data stream for pub/sub messages.
|
|
25
|
+
* <li>Messages are published to a topic.
|
|
26
|
+
* <li>Messages are listened to via a subscription.
|
|
27
|
+
* <li>Each subscription listens to the messages published to exactly one topic.
|
|
28
|
+
*
|
|
29
|
+
* Subscriptions - Resource that listens to the messages published by exactly one topic.
|
|
30
|
+
*
|
|
31
|
+
* [More info here](https://firebase.google.com/docs/functions/pubsub-events)
|
|
32
|
+
*/
|
|
34
33
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
* Interface representing a Google Cloud Pub/Sub message.
|
|
35
|
+
*
|
|
36
|
+
* @param data - Payload of a Pub/Sub message.
|
|
37
|
+
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
38
|
+
*/
|
|
39
|
+
var Message = class {
|
|
40
|
+
/**
|
|
41
|
+
* @hidden
|
|
42
|
+
* @alpha
|
|
43
|
+
*/
|
|
44
|
+
constructor(data) {
|
|
45
|
+
this.messageId = data.messageId;
|
|
46
|
+
this.data = data.data;
|
|
47
|
+
this.attributes = data.attributes || {};
|
|
48
|
+
this.orderingKey = data.orderingKey || "";
|
|
49
|
+
this.publishTime = data.publishTime || new Date().toISOString();
|
|
50
|
+
this._json = data.json;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The JSON data payload of this message object, if any.
|
|
54
|
+
*/
|
|
55
|
+
get json() {
|
|
56
|
+
if (typeof this._json === "undefined") {
|
|
57
|
+
try {
|
|
58
|
+
this._json = JSON.parse(Buffer.from(this.data, "base64").toString("utf8"));
|
|
59
|
+
} catch (err) {
|
|
60
|
+
throw new Error(`Unable to parse Pub/Sub message data as JSON: ${err.message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return this._json;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns a JSON-serializable representation of this object.
|
|
67
|
+
*
|
|
68
|
+
* @returns A JSON-serializable representation of this object.
|
|
69
|
+
*/
|
|
70
|
+
toJSON() {
|
|
71
|
+
const json = {
|
|
72
|
+
messageId: this.messageId,
|
|
73
|
+
data: this.data,
|
|
74
|
+
publishTime: this.publishTime
|
|
75
|
+
};
|
|
76
|
+
if (Object.keys(this.attributes).length) {
|
|
77
|
+
json.attributes = this.attributes;
|
|
78
|
+
}
|
|
79
|
+
if (this.orderingKey) {
|
|
80
|
+
json.orderingKey = this.orderingKey;
|
|
81
|
+
}
|
|
82
|
+
return json;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
54
85
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class Message {
|
|
61
|
-
/**
|
|
62
|
-
* @hidden
|
|
63
|
-
* @alpha
|
|
64
|
-
*/
|
|
65
|
-
constructor(data) {
|
|
66
|
-
this.messageId = data.messageId;
|
|
67
|
-
this.data = data.data;
|
|
68
|
-
this.attributes = data.attributes || {};
|
|
69
|
-
this.orderingKey = data.orderingKey || "";
|
|
70
|
-
this.publishTime = data.publishTime || new Date().toISOString();
|
|
71
|
-
this._json = data.json;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* The JSON data payload of this message object, if any.
|
|
75
|
-
*/
|
|
76
|
-
get json() {
|
|
77
|
-
if (typeof this._json === "undefined") {
|
|
78
|
-
try {
|
|
79
|
-
this._json = JSON.parse(Buffer.from(this.data, "base64").toString("utf8"));
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
throw new Error(`Unable to parse Pub/Sub message data as JSON: ${err.message}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return this._json;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Returns a JSON-serializable representation of this object.
|
|
89
|
-
*
|
|
90
|
-
* @returns A JSON-serializable representation of this object.
|
|
91
|
-
*/
|
|
92
|
-
toJSON() {
|
|
93
|
-
const json = {
|
|
94
|
-
messageId: this.messageId,
|
|
95
|
-
data: this.data,
|
|
96
|
-
publishTime: this.publishTime,
|
|
97
|
-
};
|
|
98
|
-
if (Object.keys(this.attributes).length) {
|
|
99
|
-
json.attributes = this.attributes;
|
|
100
|
-
}
|
|
101
|
-
if (this.orderingKey) {
|
|
102
|
-
json.orderingKey = this.orderingKey;
|
|
103
|
-
}
|
|
104
|
-
return json;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.Message = Message;
|
|
108
|
-
/**
|
|
109
|
-
* Handle a message being published to a Pub/Sub topic.
|
|
110
|
-
* @param topicOrOptions - A string representing the PubSub topic or an option (which contains the topic)
|
|
111
|
-
* @param handler - runs every time a Cloud Pub/Sub message is published
|
|
112
|
-
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
113
|
-
*/
|
|
86
|
+
* Handle a message being published to a Pub/Sub topic.
|
|
87
|
+
* @param topicOrOptions - A string representing the PubSub topic or an option (which contains the topic)
|
|
88
|
+
* @param handler - runs every time a Cloud Pub/Sub message is published
|
|
89
|
+
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
90
|
+
*/
|
|
114
91
|
function onMessagePublished(topicOrOptions, handler) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
};
|
|
169
|
-
(0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, "retry", "retry");
|
|
170
|
-
func.__endpoint = endpoint;
|
|
171
|
-
return func;
|
|
92
|
+
let topic;
|
|
93
|
+
let opts;
|
|
94
|
+
if (typeof topicOrOptions === "string") {
|
|
95
|
+
topic = topicOrOptions;
|
|
96
|
+
opts = {};
|
|
97
|
+
} else {
|
|
98
|
+
topic = topicOrOptions.topic;
|
|
99
|
+
opts = { ...topicOrOptions };
|
|
100
|
+
delete opts.topic;
|
|
101
|
+
}
|
|
102
|
+
const func = (raw) => {
|
|
103
|
+
const messagePublishedData = raw.data;
|
|
104
|
+
messagePublishedData.message = new Message(messagePublishedData.message);
|
|
105
|
+
return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(raw);
|
|
106
|
+
};
|
|
107
|
+
func.run = handler;
|
|
108
|
+
Object.defineProperty(func, "__trigger", { get: () => {
|
|
109
|
+
const baseOpts$1 = require_v2_options.optionsToTriggerAnnotations(require_v2_options.getGlobalOptions());
|
|
110
|
+
const specificOpts$1 = require_v2_options.optionsToTriggerAnnotations(opts);
|
|
111
|
+
return {
|
|
112
|
+
platform: "gcfv2",
|
|
113
|
+
...baseOpts$1,
|
|
114
|
+
...specificOpts$1,
|
|
115
|
+
labels: {
|
|
116
|
+
...baseOpts$1?.labels,
|
|
117
|
+
...specificOpts$1?.labels
|
|
118
|
+
},
|
|
119
|
+
eventTrigger: {
|
|
120
|
+
eventType: "google.cloud.pubsub.topic.v1.messagePublished",
|
|
121
|
+
resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
} });
|
|
125
|
+
const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
|
|
126
|
+
const specificOpts = require_v2_options.optionsToEndpoint(opts);
|
|
127
|
+
const endpoint = {
|
|
128
|
+
...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
|
|
129
|
+
platform: "gcfv2",
|
|
130
|
+
...baseOpts,
|
|
131
|
+
...specificOpts,
|
|
132
|
+
labels: {
|
|
133
|
+
...baseOpts?.labels,
|
|
134
|
+
...specificOpts?.labels
|
|
135
|
+
},
|
|
136
|
+
eventTrigger: {
|
|
137
|
+
eventType: "google.cloud.pubsub.topic.v1.messagePublished",
|
|
138
|
+
eventFilters: { topic },
|
|
139
|
+
retry: opts.retry ?? false
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
require_common_encoding.copyIfPresent(endpoint.eventTrigger, opts, "retry", "retry");
|
|
143
|
+
func.__endpoint = endpoint;
|
|
144
|
+
return func;
|
|
172
145
|
}
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
exports.Message = Message;
|
|
173
149
|
exports.onMessagePublished = onMessagePublished;
|
|
150
|
+
Object.defineProperty(exports, 'pubsub_exports', {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
get: function () {
|
|
153
|
+
return pubsub_exports;
|
|
154
|
+
}
|
|
155
|
+
});
|