firebase-functions 3.20.1 → 3.21.2

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.
Files changed (65) hide show
  1. package/lib/apps.js +1 -1
  2. package/lib/bin/firebase-functions.js +22 -1
  3. package/lib/cloud-functions.d.ts +56 -35
  4. package/lib/cloud-functions.js +12 -12
  5. package/lib/common/encoding.js +21 -1
  6. package/lib/common/providers/https.d.ts +37 -17
  7. package/lib/common/providers/https.js +11 -6
  8. package/lib/common/providers/identity.d.ts +11 -1
  9. package/lib/common/providers/identity.js +59 -207
  10. package/lib/common/providers/tasks.d.ts +9 -0
  11. package/lib/function-builder.d.ts +2 -2
  12. package/lib/function-builder.js +1 -1
  13. package/lib/handler-builder.js +3 -3
  14. package/lib/index.js +6 -2
  15. package/lib/logger/common.js +21 -0
  16. package/lib/logger/compat.js +22 -1
  17. package/lib/logger/index.d.ts +14 -6
  18. package/lib/logger/index.js +33 -6
  19. package/lib/providers/analytics.js +1 -1
  20. package/lib/providers/auth.d.ts +44 -10
  21. package/lib/providers/auth.js +80 -14
  22. package/lib/providers/database.js +11 -11
  23. package/lib/providers/firestore.js +7 -7
  24. package/lib/providers/https.js +7 -7
  25. package/lib/providers/pubsub.d.ts +6 -6
  26. package/lib/providers/pubsub.js +8 -8
  27. package/lib/providers/remoteConfig.js +1 -1
  28. package/lib/providers/storage.js +2 -2
  29. package/lib/providers/tasks.d.ts +30 -15
  30. package/lib/providers/tasks.js +19 -12
  31. package/lib/providers/testLab.js +1 -1
  32. package/lib/runtime/loader.js +9 -7
  33. package/lib/runtime/manifest.d.ts +5 -0
  34. package/lib/setup.js +3 -3
  35. package/lib/v2/core.d.ts +24 -20
  36. package/lib/v2/index.d.ts +11 -4
  37. package/lib/v2/index.js +12 -5
  38. package/lib/v2/options.d.ts +25 -35
  39. package/lib/v2/options.js +28 -88
  40. package/lib/v2/params/index.d.ts +4 -1
  41. package/lib/v2/params/index.js +25 -1
  42. package/lib/v2/params/types.js +21 -0
  43. package/lib/v2/providers/alerts/alerts.d.ts +107 -8
  44. package/lib/v2/providers/alerts/alerts.js +23 -7
  45. package/lib/v2/providers/alerts/appDistribution.d.ts +112 -12
  46. package/lib/v2/providers/alerts/appDistribution.js +29 -2
  47. package/lib/v2/providers/alerts/billing.d.ts +39 -12
  48. package/lib/v2/providers/alerts/billing.js +38 -1
  49. package/lib/v2/providers/alerts/crashlytics.d.ts +255 -47
  50. package/lib/v2/providers/alerts/crashlytics.js +63 -2
  51. package/lib/v2/providers/alerts/index.d.ts +6 -0
  52. package/lib/v2/providers/alerts/index.js +32 -1
  53. package/lib/v2/providers/eventarc.d.ts +90 -6
  54. package/lib/v2/providers/eventarc.js +7 -3
  55. package/lib/v2/providers/https.d.ts +128 -4
  56. package/lib/v2/providers/https.js +18 -14
  57. package/lib/v2/providers/identity.d.ts +126 -0
  58. package/lib/v2/providers/identity.js +104 -0
  59. package/lib/v2/providers/pubsub.d.ts +125 -8
  60. package/lib/v2/providers/pubsub.js +60 -7
  61. package/lib/v2/providers/storage.d.ts +209 -17
  62. package/lib/v2/providers/storage.js +57 -13
  63. package/lib/v2/providers/tasks.d.ts +107 -7
  64. package/lib/v2/providers/tasks.js +11 -8
  65. package/package.json +18 -3
@@ -2,35 +2,134 @@ import { CloudEvent, CloudFunction } from '../../core';
2
2
  import * as options from '../../options';
3
3
  /**
4
4
  * The CloudEvent data emitted by Firebase Alerts.
5
+ * @typeParam T - the payload type that is expected for this alert.
5
6
  */
6
7
  export interface FirebaseAlertData<T = any> {
8
+ /** Time that the event has created. */
7
9
  createTime: string;
10
+ /** Time that the event has ended. Optional, only present for ongoing alerts. */
8
11
  endTime: string;
12
+ /** Payload of the event, which includes the details of the specific alert. */
9
13
  payload: T;
10
14
  }
11
- interface WithAlertTypeAndApp {
12
- alertType: string;
13
- appId?: string;
14
- }
15
15
  /**
16
16
  * A custom CloudEvent for Firebase Alerts (with custom extension attributes).
17
+ * @typeParam T - the data type for this alert that is wrapped in a `FirebaseAlertData` object.
17
18
  */
18
- export declare type AlertEvent<T> = CloudEvent<FirebaseAlertData<T>, WithAlertTypeAndApp>;
19
+ export interface AlertEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
20
+ /** The type of the alerts that got triggered. */
21
+ alertType: string;
22
+ /**
23
+ * The Firebase App ID that’s associated with the alert. This is optional,
24
+ * and only present when the alert is targeting at a specific Firebase App.
25
+ */
26
+ appId?: string;
27
+ /** Data for an `AlertEvent` is a `FirebaseAlertData` object with a given payload. */
28
+ data: FirebaseAlertData<T>;
29
+ }
19
30
  /** The underlying alert type of the Firebase Alerts provider. */
20
31
  export declare type AlertType = 'crashlytics.newFatalIssue' | 'crashlytics.newNonfatalIssue' | 'crashlytics.regression' | 'crashlytics.stabilityDigest' | 'crashlytics.velocity' | 'crashlytics.newAnrIssue' | 'billing.planUpdate' | 'billing.automatedPlanUpdate' | 'appDistribution.newTesterIosDevice' | string;
21
32
  /**
22
33
  * Configuration for Firebase Alert functions.
23
34
  */
24
35
  export interface FirebaseAlertOptions extends options.EventHandlerOptions {
36
+ /** Scope the handler to trigger on an alert type. */
25
37
  alertType: AlertType;
38
+ /** Scope the function to trigger on a specific application. */
26
39
  appId?: string;
40
+ /**
41
+ * Region where functions should be deployed.
42
+ */
43
+ region?: options.SupportedRegion | string;
44
+ /**
45
+ * Amount of memory to allocate to a function.
46
+ * A value of null restores the defaults of 256MB.
47
+ */
48
+ memory?: options.MemoryOption | null;
49
+ /**
50
+ * Timeout for the function in sections, possible values are 0 to 540.
51
+ * HTTPS functions can specify a higher timeout.
52
+ * A value of null restores the default of 60s
53
+ * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
54
+ * function depends on the type of function: Event handling functions have a
55
+ * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
56
+ * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
57
+ * timeout of 1,800s (30 minutes)
58
+ */
59
+ timeoutSeconds?: number | null;
60
+ /**
61
+ * Min number of actual instances to be running at a given time.
62
+ * Instances will be billed for memory allocation and 10% of CPU allocation
63
+ * while idle.
64
+ * A value of null restores the default min instances.
65
+ */
66
+ minInstances?: number | null;
67
+ /**
68
+ * Max number of instances to be running in parallel.
69
+ * A value of null restores the default max instances.
70
+ */
71
+ maxInstances?: number | null;
72
+ /**
73
+ * Number of requests a function can serve at once.
74
+ * Can only be applied to functions running on Cloud Functions v2.
75
+ * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
76
+ * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
77
+ * The maximum value for concurrency is 1,000.
78
+ */
79
+ concurrency?: number | null;
80
+ /**
81
+ * Fractional number of CPUs to allocate to a function.
82
+ * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
83
+ * This is different from the defaults when using the gcloud utility and is different from
84
+ * the fixed amount assigned in Google Cloud Functions generation 1.
85
+ * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
86
+ * to the value "gcf_gen1"
87
+ */
88
+ cpu?: number | 'gcf_gen1';
89
+ /**
90
+ * Connect cloud function to specified VPC connector.
91
+ * A value of null removes the VPC connector
92
+ */
93
+ vpcConnector?: string | null;
94
+ /**
95
+ * Egress settings for VPC connector.
96
+ * A value of null turns off VPC connector egress settings
97
+ */
98
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
99
+ /**
100
+ * Specific service account for the function to run as.
101
+ * A value of null restores the default service account.
102
+ */
103
+ serviceAccount?: string | null;
104
+ /**
105
+ * Ingress settings which control where this function can be called from.
106
+ * A value of null turns off ingress settings.
107
+ */
108
+ ingressSettings?: options.IngressSetting | null;
109
+ /**
110
+ * User labels to set on the function.
111
+ */
112
+ labels?: Record<string, string>;
113
+ secrets?: string[];
114
+ /** Whether failed executions should be delivered again. */
115
+ retry?: boolean;
27
116
  }
28
117
  /**
29
118
  * Declares a function that can handle Firebase Alerts from CloudEvents.
30
- * @param alertTypeOrOpts the alert type or Firebase Alert function configuration.
119
+ * @typeParam T - the type of event.data.payload.
120
+ * @param alertType - the alert type or Firebase Alert function configuration.
121
+ * @param handler a function that can handle the Firebase Alert inside a CloudEvent.
122
+ * @returns A function that you can export and deploy.
123
+ */
124
+ export declare function onAlertPublished<T extends {
125
+ ['@type']: string;
126
+ } = any>(alertType: AlertType, handler: (event: AlertEvent<T>) => any | Promise<any>): CloudFunction<AlertEvent<T>>;
127
+ /**
128
+ * Declares a function that can handle Firebase Alerts from CloudEvents.
129
+ * @typeParam T - the type of event.data.payload.
130
+ * @param options - the alert type and other options for this cloud function.
31
131
  * @param handler a function that can handle the Firebase Alert inside a CloudEvent.
32
132
  */
33
133
  export declare function onAlertPublished<T extends {
34
134
  ['@type']: string;
35
- } = any>(alertTypeOrOpts: AlertType | FirebaseAlertOptions, handler: (event: AlertEvent<T>) => any | Promise<any>): CloudFunction<FirebaseAlertData<T>>;
36
- export {};
135
+ } = any>(options: FirebaseAlertOptions, handler: (event: AlertEvent<T>) => any | Promise<any>): CloudFunction<AlertEvent<T>>;
@@ -1,14 +1,30 @@
1
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.
2
23
  Object.defineProperty(exports, "__esModule", { value: true });
3
24
  exports.getOptsAndAlertTypeAndApp = exports.getEndpointAnnotation = exports.onAlertPublished = exports.eventType = void 0;
4
25
  const options = require("../../options");
5
26
  /** @internal */
6
27
  exports.eventType = 'google.firebase.firebasealerts.alerts.v1.published';
7
- /**
8
- * Declares a function that can handle Firebase Alerts from CloudEvents.
9
- * @param alertTypeOrOpts the alert type or Firebase Alert function configuration.
10
- * @param handler a function that can handle the Firebase Alert inside a CloudEvent.
11
- */
12
28
  function onAlertPublished(alertTypeOrOpts, handler) {
13
29
  const [opts, alertType, appId] = getOptsAndAlertTypeAndApp(alertTypeOrOpts);
14
30
  const func = (raw) => {
@@ -20,8 +36,8 @@ function onAlertPublished(alertTypeOrOpts, handler) {
20
36
  }
21
37
  exports.onAlertPublished = onAlertPublished;
22
38
  /**
23
- * @internal
24
39
  * Helper function for getting the endpoint annotation used in alert handling functions.
40
+ * @internal
25
41
  */
26
42
  function getEndpointAnnotation(opts, alertType, appId) {
27
43
  const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
@@ -49,8 +65,8 @@ function getEndpointAnnotation(opts, alertType, appId) {
49
65
  }
50
66
  exports.getEndpointAnnotation = getEndpointAnnotation;
51
67
  /**
52
- * @internal
53
68
  * Helper function to parse the function opts, alert type, and appId.
69
+ * @internal
54
70
  */
55
71
  function getOptsAndAlertTypeAndApp(alertTypeOrOpts) {
56
72
  let opts;
@@ -1,35 +1,135 @@
1
- import { FirebaseAlertData } from './alerts';
1
+ /**
2
+ * Cloud functions to handle Firebase App Distribution events from Firebase Alerts.
3
+ * @packageDocumentation
4
+ */
2
5
  import { CloudEvent, CloudFunction } from '../../core';
3
6
  import * as options from '../../options';
7
+ import { FirebaseAlertData } from './alerts';
4
8
  /**
5
9
  * The internal payload object for adding a new tester device to app distribution.
6
- * Payload is wrapped inside a FirebaseAlertData object.
10
+ * Payload is wrapped inside a `FirebaseAlertData` object.
7
11
  */
8
12
  export interface NewTesterDevicePayload {
9
- ['@type']: 'com.google.firebase.firebasealerts.NewTesterDevicePayload';
13
+ ['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.AppDistroNewTesterIosDevicePayload';
14
+ /** Name of the tester */
10
15
  testerName: string;
16
+ /** Email of the tester */
11
17
  testerEmail: string;
18
+ /** The device model name */
12
19
  testerDeviceModelName: string;
20
+ /** The device ID */
13
21
  testerDeviceIdentifier: string;
14
22
  }
15
- interface WithAlertTypeAndApp {
16
- alertType: string;
17
- appId: string;
18
- }
19
23
  /**
20
24
  * A custom CloudEvent for Firebase Alerts (with custom extension attributes).
25
+ * @typeParam T - the data type for app distribution alerts that is wrapped in a `FirebaseAlertData` object.
21
26
  */
22
- export declare type AppDistributionEvent<T> = CloudEvent<FirebaseAlertData<T>, WithAlertTypeAndApp>;
27
+ export interface AppDistributionEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
28
+ /** The type of the alerts that got triggered. */
29
+ alertType: string;
30
+ /** The Firebase App ID that’s associated with the alert. */
31
+ appId: string;
32
+ }
23
33
  /**
24
34
  * Configuration for app distribution functions.
25
35
  */
26
36
  export interface AppDistributionOptions extends options.EventHandlerOptions {
37
+ /** Scope the function to trigger on a specific application. */
27
38
  appId?: string;
39
+ /**
40
+ * Region where functions should be deployed.
41
+ */
42
+ region?: options.SupportedRegion | string;
43
+ /**
44
+ * Amount of memory to allocate to a function.
45
+ * A value of null restores the defaults of 256MB.
46
+ */
47
+ memory?: options.MemoryOption | null;
48
+ /**
49
+ * Timeout for the function in sections, possible values are 0 to 540.
50
+ * HTTPS functions can specify a higher timeout.
51
+ * A value of null restores the default of 60s
52
+ * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
53
+ * function depends on the type of function: Event handling functions have a
54
+ * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
55
+ * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
56
+ * timeout of 1,800s (30 minutes)
57
+ */
58
+ timeoutSeconds?: number | null;
59
+ /**
60
+ * Min number of actual instances to be running at a given time.
61
+ * Instances will be billed for memory allocation and 10% of CPU allocation
62
+ * while idle.
63
+ * A value of null restores the default min instances.
64
+ */
65
+ minInstances?: number | null;
66
+ /**
67
+ * Max number of instances to be running in parallel.
68
+ * A value of null restores the default max instances.
69
+ */
70
+ maxInstances?: number | null;
71
+ /**
72
+ * Number of requests a function can serve at once.
73
+ * Can only be applied to functions running on Cloud Functions v2.
74
+ * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
75
+ * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
76
+ * The maximum value for concurrency is 1,000.
77
+ */
78
+ concurrency?: number | null;
79
+ /**
80
+ * Fractional number of CPUs to allocate to a function.
81
+ * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
82
+ * This is different from the defaults when using the gcloud utility and is different from
83
+ * the fixed amount assigned in Google Cloud Functions generation 1.
84
+ * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
85
+ * to the value "gcf_gen1"
86
+ */
87
+ cpu?: number | 'gcf_gen1';
88
+ /**
89
+ * Connect cloud function to specified VPC connector.
90
+ * A value of null removes the VPC connector
91
+ */
92
+ vpcConnector?: string | null;
93
+ /**
94
+ * Egress settings for VPC connector.
95
+ * A value of null turns off VPC connector egress settings
96
+ */
97
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
98
+ /**
99
+ * Specific service account for the function to run as.
100
+ * A value of null restores the default service account.
101
+ */
102
+ serviceAccount?: string | null;
103
+ /**
104
+ * Ingress settings which control where this function can be called from.
105
+ * A value of null turns off ingress settings.
106
+ */
107
+ ingressSettings?: options.IngressSetting | null;
108
+ /**
109
+ * User labels to set on the function.
110
+ */
111
+ labels?: Record<string, string>;
112
+ secrets?: string[];
113
+ /** Whether failed executions should be delivered again. */
114
+ retry?: boolean;
28
115
  }
29
116
  /**
30
117
  * Declares a function that can handle adding a new tester iOS device.
118
+ * @param handler - Event handler which is run every time a new tester iOS device is added.
119
+ * @returns A function that you can export and deploy.
120
+ */
121
+ export declare function onNewTesterIosDevicePublished(handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<NewTesterDevicePayload>>;
122
+ /**
123
+ * Declares a function that can handle adding a new tester iOS device.
124
+ * @param appId - A specific application the handler will trigger on.
125
+ * @param handler - Event handler which is run every time a new tester iOS device is added.
126
+ * @returns A function that you can export and deploy.
127
+ */
128
+ export declare function onNewTesterIosDevicePublished(appId: string, handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<NewTesterDevicePayload>>;
129
+ /**
130
+ * Declares a function that can handle adding a new tester iOS device.
131
+ * @param opts - Options that can be set on the function.
132
+ * @param handler - Event handler which is run every time a new tester iOS device is added.
133
+ * @returns A function that you can export and deploy.
31
134
  */
32
- export declare function onNewTesterIosDevicePublished(handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<NewTesterDevicePayload>>;
33
- export declare function onNewTesterIosDevicePublished(appId: string, handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<NewTesterDevicePayload>>;
34
- export declare function onNewTesterIosDevicePublished(opts: AppDistributionOptions, handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<NewTesterDevicePayload>>;
35
- export {};
135
+ export declare function onNewTesterIosDevicePublished(opts: AppDistributionOptions, handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<NewTesterDevicePayload>>;
@@ -1,9 +1,36 @@
1
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.
2
23
  Object.defineProperty(exports, "__esModule", { value: true });
3
24
  exports.getOptsAndApp = exports.onNewTesterIosDevicePublished = exports.newTesterIosDeviceAlert = void 0;
4
25
  const alerts_1 = require("./alerts");
5
26
  /** @internal */
6
27
  exports.newTesterIosDeviceAlert = 'appDistribution.newTesterIosDevice';
28
+ /**
29
+ * Declares a function that can handle adding a new tester iOS device.
30
+ * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
31
+ * @param handler - Event handler which is run every time a new tester iOS device is added.
32
+ * @returns A function that you can export and deploy.
33
+ */
7
34
  function onNewTesterIosDevicePublished(appIdOrOptsOrHandler, handler) {
8
35
  if (typeof appIdOrOptsOrHandler === 'function') {
9
36
  handler = appIdOrOptsOrHandler;
@@ -14,13 +41,13 @@ function onNewTesterIosDevicePublished(appIdOrOptsOrHandler, handler) {
14
41
  return handler(raw);
15
42
  };
16
43
  func.run = handler;
17
- func.__endpoint = alerts_1.getEndpointAnnotation(opts, exports.newTesterIosDeviceAlert, appId);
44
+ func.__endpoint = (0, alerts_1.getEndpointAnnotation)(opts, exports.newTesterIosDeviceAlert, appId);
18
45
  return func;
19
46
  }
20
47
  exports.onNewTesterIosDevicePublished = onNewTesterIosDevicePublished;
21
48
  /**
22
- * @internal
23
49
  * Helper function to parse the function opts and appId.
50
+ * @internal
24
51
  */
25
52
  function getOptsAndApp(appIdOrOpts) {
26
53
  let opts;
@@ -1,38 +1,65 @@
1
+ /**
2
+ * Cloud functions to handle billing events from Firebase Alerts.
3
+ * @packageDocumentation
4
+ */
1
5
  import { FirebaseAlertData } from '.';
2
6
  import { CloudEvent, CloudFunction } from '../../core';
3
7
  import * as options from '../../options';
4
8
  /**
5
9
  * The internal payload object for billing plan updates.
6
- * Payload is wrapped inside a FirebaseAlertData object.
10
+ * Payload is wrapped inside a `FirebaseAlertData` object.
7
11
  */
8
12
  export interface PlanUpdatePayload {
9
- ['@type']: 'com.google.firebase.firebasealerts.PlanUpdatePayload';
13
+ ['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.BillingPlanUpdatePayload';
14
+ /** A Firebase billing plan. */
10
15
  billingPlan: string;
16
+ /** The email address of the person that triggered billing plan change */
11
17
  principalEmail: string;
18
+ /** The type of the notification, e.g. upgrade, downgrade */
19
+ notificationType: string;
12
20
  }
13
21
  /**
14
22
  * The internal payload object for billing plan automated updates.
15
- * Payload is wrapped inside a FirebaseAlertData object.
23
+ * Payload is wrapped inside a `FirebaseAlertData` object.
16
24
  */
17
25
  export interface PlanAutomatedUpdatePayload {
18
- ['@type']: 'com.google.firebase.firebasealerts.PlanAutomatedUpdatePayload';
26
+ ['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.BillingPlanAutomatedUpdatePayload';
27
+ /** A Firebase billing plan. */
19
28
  billingPlan: string;
29
+ /** The type of the notification, e.g. upgrade, downgrade */
30
+ notificationType: string;
20
31
  }
21
- interface WithAlertType {
32
+ /**
33
+ * A custom CloudEvent for billing Firebase Alerts (with custom extension attributes).
34
+ * @typeParam T - the data type for billing alerts that is wrapped in a `FirebaseAlertData` object.
35
+ */
36
+ export interface BillingEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
37
+ /** The type of the alerts that got triggered. */
22
38
  alertType: string;
23
39
  }
24
40
  /**
25
- * A custom CloudEvent for billing Firebase Alerts (with custom extension attributes).
41
+ * Declares a function that can handle a billing plan update event.
42
+ * @param handler - Event handler which is run every time a billing plan is updated.
43
+ * @returns A function that you can export and deploy.
26
44
  */
27
- export declare type BillingEvent<T> = CloudEvent<FirebaseAlertData<T>, WithAlertType>;
45
+ export declare function onPlanUpdatePublished(handler: (event: BillingEvent<PlanUpdatePayload>) => any | Promise<any>): CloudFunction<BillingEvent<PlanUpdatePayload>>;
28
46
  /**
29
47
  * Declares a function that can handle a billing plan update event.
48
+ * @param opts - Options that can be set on the function.
49
+ * @param handler - Event handler which is run every time a billing plan is updated.
50
+ * @returns A function that you can export and deploy.
51
+ */
52
+ export declare function onPlanUpdatePublished(opts: options.EventHandlerOptions, handler: (event: BillingEvent<PlanUpdatePayload>) => any | Promise<any>): CloudFunction<BillingEvent<PlanUpdatePayload>>;
53
+ /**
54
+ * Declares a function that can handle an automated billing plan update event.
55
+ * @param handler - Event handler which is run every time an automated billing plan update occurs.
56
+ * @returns A function that you can export and deploy.
30
57
  */
31
- export declare function onPlanUpdatePublished(handler: (event: BillingEvent<PlanUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanUpdatePayload>>;
32
- export declare function onPlanUpdatePublished(opts: options.EventHandlerOptions, handler: (event: BillingEvent<PlanUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanUpdatePayload>>;
58
+ export declare function onPlanAutomatedUpdatePublished(handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<BillingEvent<PlanAutomatedUpdatePayload>>;
33
59
  /**
34
60
  * Declares a function that can handle an automated billing plan update event.
61
+ * @param opts - Options that can be set on the function.
62
+ * @param handler - Event handler which is run every time an automated billing plan update occurs.
63
+ * @returns A function that you can export and deploy.
35
64
  */
36
- export declare function onPlanAutomatedUpdatePublished(handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanAutomatedUpdatePayload>>;
37
- export declare function onPlanAutomatedUpdatePublished(opts: options.EventHandlerOptions, handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanAutomatedUpdatePayload>>;
38
- export {};
65
+ export declare function onPlanAutomatedUpdatePublished(opts: options.EventHandlerOptions, handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<BillingEvent<PlanAutomatedUpdatePayload>>;
@@ -1,15 +1,52 @@
1
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.
2
23
  Object.defineProperty(exports, "__esModule", { value: true });
3
24
  exports.onOperation = exports.onPlanAutomatedUpdatePublished = exports.onPlanUpdatePublished = exports.planAutomatedUpdateAlert = exports.planUpdateAlert = void 0;
25
+ /**
26
+ * Cloud functions to handle billing events from Firebase Alerts.
27
+ * @packageDocumentation
28
+ */
4
29
  const _1 = require(".");
5
30
  /** @internal */
6
31
  exports.planUpdateAlert = 'billing.planUpdate';
7
32
  /** @internal */
8
33
  exports.planAutomatedUpdateAlert = 'billing.planAutomatedUpdate';
34
+ /**
35
+ * Declares a function that can handle a billing plan update event.
36
+ * @param optsOrHandler - Options or an event-handling function.
37
+ * @param handler - Event handler which is run every time a billing plan is updated.
38
+ * @returns A function that you can export and deploy.
39
+ */
9
40
  function onPlanUpdatePublished(optsOrHandler, handler) {
10
41
  return onOperation(exports.planUpdateAlert, optsOrHandler, handler);
11
42
  }
12
43
  exports.onPlanUpdatePublished = onPlanUpdatePublished;
44
+ /**
45
+ * Declares a function that can handle an automated billing plan update event.
46
+ * @param optsOrHandler - Options or an event-handling function.
47
+ * @param handler - Event handler which is run every time an automated billing plan update occurs.
48
+ * @returns A function that you can export and deploy.
49
+ */
13
50
  function onPlanAutomatedUpdatePublished(optsOrHandler, handler) {
14
51
  return onOperation(exports.planAutomatedUpdateAlert, optsOrHandler, handler);
15
52
  }
@@ -24,7 +61,7 @@ function onOperation(alertType, optsOrHandler, handler) {
24
61
  return handler(raw);
25
62
  };
26
63
  func.run = handler;
27
- func.__endpoint = _1.getEndpointAnnotation(optsOrHandler, alertType);
64
+ func.__endpoint = (0, _1.getEndpointAnnotation)(optsOrHandler, alertType);
28
65
  return func;
29
66
  }
30
67
  exports.onOperation = onOperation;