UNPKG

2.99 kBJavaScriptView Raw
1"use strict";
2// The MIT License (MIT)
3//
4// Copyright (c) 2022 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.
23Object.defineProperty(exports, "__esModule", { value: true });
24exports.onConfigUpdated = exports.eventType = void 0;
25const onInit_1 = require("../../common/onInit");
26const manifest_1 = require("../../runtime/manifest");
27const options_1 = require("../options");
28const trace_1 = require("../trace");
29/** @internal */
30exports.eventType = "google.firebase.remoteconfig.remoteConfig.v1.updated";
31/**
32 * Event handler which triggers when data is updated in a Remote Config.
33 *
34 * @param optsOrHandler - Options or an event handler.
35 * @param handler - Event handler which is run every time a Remote Config update occurs.
36 * @returns A function that you can export and deploy.
37 */
38function onConfigUpdated(optsOrHandler, handler) {
39 var _a;
40 if (typeof optsOrHandler === "function") {
41 handler = optsOrHandler;
42 optsOrHandler = {};
43 }
44 const baseOpts = (0, options_1.optionsToEndpoint)((0, options_1.getGlobalOptions)());
45 const specificOpts = (0, options_1.optionsToEndpoint)(optsOrHandler);
46 const func = (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)((raw) => {
47 return handler(raw);
48 }));
49 func.run = handler;
50 const ep = {
51 ...(0, manifest_1.initV2Endpoint)((0, options_1.getGlobalOptions)(), optsOrHandler),
52 platform: "gcfv2",
53 ...baseOpts,
54 ...specificOpts,
55 labels: {
56 ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
57 ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
58 },
59 eventTrigger: {
60 eventType: exports.eventType,
61 eventFilters: {},
62 retry: (_a = optsOrHandler.retry) !== null && _a !== void 0 ? _a : false,
63 },
64 };
65 func.__endpoint = ep;
66 return func;
67}
68exports.onConfigUpdated = onConfigUpdated;