1 | /**
|
2 | * Cloud functions to handle events from Google Cloud Identity Platform.
|
3 | * @packageDocumentation
|
4 | */
|
5 | import { ResetValue } from "../../common/options";
|
6 | import { AuthBlockingEvent, AuthBlockingEventType, AuthUserRecord, BeforeCreateResponse, BeforeSignInResponse, BeforeEmailResponse, BeforeSmsResponse, HandlerV2, HttpsError, MaybeAsync } from "../../common/providers/identity";
|
7 | import { BlockingFunction } from "../../v1/cloud-functions";
|
8 | import { Expression } from "../../params";
|
9 | import * as options from "../options";
|
10 | import { SecretParam } from "../../params/types";
|
11 | export { AuthUserRecord, AuthBlockingEvent, HttpsError };
|
12 | /** @hidden Internally used when parsing the options. */
|
13 | interface InternalOptions {
|
14 | opts: options.GlobalOptions;
|
15 | idToken: boolean;
|
16 | accessToken: boolean;
|
17 | refreshToken: boolean;
|
18 | }
|
19 | /**
|
20 | * All function options plus idToken, accessToken, and refreshToken.
|
21 | */
|
22 | export interface BlockingOptions {
|
23 | /** Pass the ID Token credential to the function. */
|
24 | idToken?: boolean;
|
25 | /** Pass the Access Token credential to the function. */
|
26 | accessToken?: boolean;
|
27 | /** Pass the Refresh Token credential to the function. */
|
28 | refreshToken?: boolean;
|
29 | /**
|
30 | * If true, do not deploy or emulate this function.
|
31 | */
|
32 | omit?: boolean | Expression<boolean>;
|
33 | /**
|
34 | * Region where functions should be deployed.
|
35 | */
|
36 | region?: options.SupportedRegion | string | Expression<string> | ResetValue;
|
37 | /**
|
38 | * Amount of memory to allocate to a function.
|
39 | */
|
40 | memory?: options.MemoryOption | Expression<number> | ResetValue;
|
41 | /**
|
42 | * Timeout for the function in seconds, possible values are 0 to 540.
|
43 | * HTTPS functions can specify a higher timeout.
|
44 | *
|
45 | * @remarks
|
46 | * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
47 | * function depends on the type of function: Event handling functions have a
|
48 | * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
49 | * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
50 | * timeout of 1,800s (30 minutes)
|
51 | */
|
52 | timeoutSeconds?: number | Expression<number> | ResetValue;
|
53 | /**
|
54 | * Min number of actual instances to be running at a given time.
|
55 | *
|
56 | * @remarks
|
57 | * Instances will be billed for memory allocation and 10% of CPU allocation
|
58 | * while idle.
|
59 | */
|
60 | minInstances?: number | Expression<number> | ResetValue;
|
61 | /**
|
62 | * Max number of instances to be running in parallel.
|
63 | */
|
64 | maxInstances?: number | Expression<number> | ResetValue;
|
65 | /**
|
66 | * Number of requests a function can serve at once.
|
67 | *
|
68 | * @remarks
|
69 | * Can only be applied to functions running on Cloud Functions v2.
|
70 | * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
71 | * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
72 | * The maximum value for concurrency is 1,000.
|
73 | */
|
74 | concurrency?: number | Expression<number> | ResetValue;
|
75 | /**
|
76 | * Fractional number of CPUs to allocate to a function.
|
77 | *
|
78 | * @remarks
|
79 | * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
80 | * This is different from the defaults when using the gcloud utility and is different from
|
81 | * the fixed amount assigned in Google Cloud Functions generation 1.
|
82 | * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
83 | * to the value "gcf_gen1"
|
84 | */
|
85 | cpu?: number | "gcf_gen1";
|
86 | /**
|
87 | * Connect cloud function to specified VPC connector.
|
88 | */
|
89 | vpcConnector?: string | Expression<string> | ResetValue;
|
90 | /**
|
91 | * Egress settings for VPC connector.
|
92 | */
|
93 | vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
|
94 | /**
|
95 | * Specific service account for the function to run as.
|
96 | */
|
97 | serviceAccount?: string | Expression<string> | ResetValue;
|
98 | /**
|
99 | * Ingress settings which control where this function can be called from.
|
100 | */
|
101 | ingressSettings?: options.IngressSetting | ResetValue;
|
102 | /**
|
103 | * User labels to set on the function.
|
104 | */
|
105 | labels?: Record<string, string>;
|
106 | secrets?: (string | SecretParam)[];
|
107 | }
|
108 | /**
|
109 | * Handles an event that is triggered before a user is created.
|
110 | * @param handler - Event handler which is run every time before a user is created.
|
111 | */
|
112 | export declare function beforeUserCreated(handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeCreateResponse | void>): BlockingFunction;
|
113 | /**
|
114 | * Handles an event that is triggered before a user is created.
|
115 | * @param opts - Object containing function options.
|
116 | * @param handler - Event handler which is run every time before a user is created.
|
117 | */
|
118 | export declare function beforeUserCreated(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeCreateResponse | void>): BlockingFunction;
|
119 | /**
|
120 | * Handles an event that is triggered before a user is signed in.
|
121 | * @param handler - Event handler which is run every time before a user is signed in.
|
122 | */
|
123 | export declare function beforeUserSignedIn(handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeSignInResponse | void>): BlockingFunction;
|
124 | /**
|
125 | * Handles an event that is triggered before a user is signed in.
|
126 | * @param opts - Object containing function options.
|
127 | * @param handler - Event handler which is run every time before a user is signed in.
|
128 | */
|
129 | export declare function beforeUserSignedIn(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeSignInResponse | void>): BlockingFunction;
|
130 | /**
|
131 | * Handles an event that is triggered before an email is sent to a user.
|
132 | * @param handler - Event handler that is run before an email is sent to a user.
|
133 | */
|
134 | export declare function beforeEmailSent(handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeEmailResponse | void>): BlockingFunction;
|
135 | /**
|
136 | * Handles an event that is triggered before an email is sent to a user.
|
137 | * @param opts - Object containing function options.
|
138 | * @param handler - Event handler that is run before an email is sent to a user.
|
139 | */
|
140 | export declare function beforeEmailSent(opts: Omit<BlockingOptions, "idToken" | "accessToken" | "refreshToken">, handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeEmailResponse | void>): BlockingFunction;
|
141 | /**
|
142 | * Handles an event that is triggered before an SMS is sent to a user.
|
143 | * @param handler - Event handler that is run before an SMS is sent to a user.
|
144 | */
|
145 | export declare function beforeSmsSent(handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeSmsResponse | void>): BlockingFunction;
|
146 | /**
|
147 | * Handles an event that is triggered before an SMS is sent to a user.
|
148 | * @param opts - Object containing function options.
|
149 | * @param handler - Event handler that is run before an SMS is sent to a user.
|
150 | */
|
151 | export declare function beforeSmsSent(opts: Omit<BlockingOptions, "idToken" | "accessToken" | "refreshToken">, handler: (event: AuthBlockingEvent) => MaybeAsync<BeforeSmsResponse | void>): BlockingFunction;
|
152 | /** @hidden */
|
153 | export declare function beforeOperation(eventType: AuthBlockingEventType, optsOrHandler: BlockingOptions | ((event: AuthBlockingEvent) => MaybeAsync<BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void>), handler: HandlerV2): BlockingFunction;
|
154 | /** @hidden */
|
155 | export declare function getOpts(blockingOptions: BlockingOptions): InternalOptions;
|