1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | exports.onCustomEventPublished = void 0;
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const encoding_1 = require("../../common/encoding");
|
30 | const manifest_1 = require("../../runtime/manifest");
|
31 | const trace_1 = require("../trace");
|
32 | const options = require("../options");
|
33 | const onInit_1 = require("../../common/onInit");
|
34 | function onCustomEventPublished(eventTypeOrOpts, handler) {
|
35 | var _a, _b;
|
36 | let opts;
|
37 | if (typeof eventTypeOrOpts === "string") {
|
38 | opts = {
|
39 | eventType: eventTypeOrOpts,
|
40 | };
|
41 | }
|
42 | else if (typeof eventTypeOrOpts === "object") {
|
43 | opts = eventTypeOrOpts;
|
44 | }
|
45 | const func = (raw) => {
|
46 | return (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)(handler))(raw);
|
47 | };
|
48 | func.run = handler;
|
49 | const channel = (_a = opts.channel) !== null && _a !== void 0 ? _a : "locations/us-central1/channels/firebase";
|
50 | const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
51 | const specificOpts = options.optionsToEndpoint(opts);
|
52 | const endpoint = {
|
53 | ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
|
54 | platform: "gcfv2",
|
55 | ...baseOpts,
|
56 | ...specificOpts,
|
57 | labels: {
|
58 | ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
59 | ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
60 | },
|
61 | eventTrigger: {
|
62 | eventType: opts.eventType,
|
63 | eventFilters: {},
|
64 | retry: (_b = opts.retry) !== null && _b !== void 0 ? _b : false,
|
65 | channel,
|
66 | },
|
67 | };
|
68 | (0, encoding_1.convertIfPresent)(endpoint.eventTrigger, opts, "eventFilters", "filters");
|
69 | (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, "retry");
|
70 | func.__endpoint = endpoint;
|
71 | func.__requiredAPIs = [
|
72 | {
|
73 | api: "eventarcpublishing.googleapis.com",
|
74 | reason: "Needed for custom event functions",
|
75 | },
|
76 | ];
|
77 | return func;
|
78 | }
|
79 | exports.onCustomEventPublished = onCustomEventPublished;
|