1 | ;
|
2 | // The MIT License (MIT)
|
3 | //
|
4 | // Copyright (c) 2018 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
|
14 | // all 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.UpdateBuilder = exports._onUpdateWithOptions = exports.onUpdate = exports.service = exports.provider = void 0;
|
25 | const cloud_functions_1 = require("../cloud-functions");
|
26 | /** @internal */
|
27 | exports.provider = "google.firebase.remoteconfig";
|
28 | /** @internal */
|
29 | exports.service = "firebaseremoteconfig.googleapis.com";
|
30 | /**
|
31 | * Registers a function that triggers on Firebase Remote Config template
|
32 | * update events.
|
33 | *
|
34 | * @param handler A function that takes the updated Remote Config
|
35 | * template version metadata as an argument.
|
36 | *
|
37 | * @returns A function that you can export and deploy.
|
38 | */
|
39 | function onUpdate(handler) {
|
40 | return _onUpdateWithOptions(handler, {});
|
41 | }
|
42 | exports.onUpdate = onUpdate;
|
43 | /** @internal */
|
44 | function _onUpdateWithOptions(handler, options) {
|
45 | const triggerResource = () => {
|
46 | if (!process.env.GCLOUD_PROJECT) {
|
47 | throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
48 | }
|
49 | return `projects/${process.env.GCLOUD_PROJECT}`;
|
50 | };
|
51 | return new UpdateBuilder(triggerResource, options).onUpdate(handler);
|
52 | }
|
53 | exports._onUpdateWithOptions = _onUpdateWithOptions;
|
54 | /** Builder used to create Cloud Functions for Remote Config. */
|
55 | class UpdateBuilder {
|
56 | /** @internal */
|
57 | constructor(triggerResource, options) {
|
58 | this.triggerResource = triggerResource;
|
59 | this.options = options;
|
60 | }
|
61 | /**
|
62 | * Handle all updates (including rollbacks) that affect a Remote Config
|
63 | * project.
|
64 | * @param handler A function that takes the updated Remote Config template
|
65 | * version metadata as an argument.
|
66 | */
|
67 | onUpdate(handler) {
|
68 | return (0, cloud_functions_1.makeCloudFunction)({
|
69 | handler,
|
70 | provider: exports.provider,
|
71 | service: exports.service,
|
72 | triggerResource: this.triggerResource,
|
73 | eventType: "update",
|
74 | options: this.options,
|
75 | });
|
76 | }
|
77 | }
|
78 | exports.UpdateBuilder = UpdateBuilder;
|