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._onCallWithOptions = exports._onRequestWithOptions = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
25 | const encoding_1 = require("../../common/encoding");
|
26 | const https_1 = require("../../common/providers/https");
|
27 | Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
|
28 | const cloud_functions_1 = require("../cloud-functions");
|
29 | const manifest_1 = require("../../runtime/manifest");
|
30 | const onInit_1 = require("../../common/onInit");
|
31 | const trace_1 = require("../../v2/trace");
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function onRequest(handler) {
|
38 | return _onRequestWithOptions(handler, {});
|
39 | }
|
40 | exports.onRequest = onRequest;
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | function onCall(handler) {
|
46 | return _onCallWithOptions(handler, {});
|
47 | }
|
48 | exports.onCall = onCall;
|
49 |
|
50 | function _onRequestWithOptions(handler, options) {
|
51 |
|
52 | const cloudFunction = (req, res) => {
|
53 | return (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)(handler))(req, res);
|
54 | };
|
55 | cloudFunction.__trigger = {
|
56 | ...(0, cloud_functions_1.optionsToTrigger)(options),
|
57 | httpsTrigger: {},
|
58 | };
|
59 | (0, encoding_1.convertIfPresent)(cloudFunction.__trigger.httpsTrigger, options, "invoker", "invoker", encoding_1.convertInvoker);
|
60 |
|
61 | cloudFunction.__endpoint = {
|
62 | platform: "gcfv1",
|
63 | ...(0, manifest_1.initV1Endpoint)(options),
|
64 | ...(0, cloud_functions_1.optionsToEndpoint)(options),
|
65 | httpsTrigger: {},
|
66 | };
|
67 | (0, encoding_1.convertIfPresent)(cloudFunction.__endpoint.httpsTrigger, options, "invoker", "invoker", encoding_1.convertInvoker);
|
68 | return cloudFunction;
|
69 | }
|
70 | exports._onRequestWithOptions = _onRequestWithOptions;
|
71 |
|
72 | function _onCallWithOptions(handler, options) {
|
73 |
|
74 |
|
75 |
|
76 | const fixedLen = (data, context) => {
|
77 | return (0, onInit_1.withInit)(handler)(data, context);
|
78 | };
|
79 | const func = (0, trace_1.wrapTraceContext)((0, https_1.onCallHandler)({
|
80 | enforceAppCheck: options.enforceAppCheck,
|
81 | consumeAppCheckToken: options.consumeAppCheckToken,
|
82 | cors: { origin: true, methods: "POST" },
|
83 | }, fixedLen));
|
84 | func.__trigger = {
|
85 | labels: {},
|
86 | ...(0, cloud_functions_1.optionsToTrigger)(options),
|
87 | httpsTrigger: {},
|
88 | };
|
89 | func.__trigger.labels["deployment-callable"] = "true";
|
90 | func.__endpoint = {
|
91 | platform: "gcfv1",
|
92 | labels: {},
|
93 | ...(0, manifest_1.initV1Endpoint)(options),
|
94 | ...(0, cloud_functions_1.optionsToEndpoint)(options),
|
95 | callableTrigger: {},
|
96 | };
|
97 | func.run = fixedLen;
|
98 | return func;
|
99 | }
|
100 | exports._onCallWithOptions = _onCallWithOptions;
|