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.UserBuilder = exports._userWithOptions = exports.user = exports.service = exports.provider = exports.HttpsError = exports.userRecordConstructor = exports.UserRecordMetadata = void 0;
|
25 | const identity_1 = require("../../common/providers/identity");
|
26 | Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
|
27 | Object.defineProperty(exports, "userRecordConstructor", { enumerable: true, get: function () { return identity_1.userRecordConstructor; } });
|
28 | Object.defineProperty(exports, "UserRecordMetadata", { enumerable: true, get: function () { return identity_1.UserRecordMetadata; } });
|
29 | const cloud_functions_1 = require("../cloud-functions");
|
30 | const manifest_1 = require("../../runtime/manifest");
|
31 |
|
32 | exports.provider = "google.firebase.auth";
|
33 |
|
34 | exports.service = "firebaseauth.googleapis.com";
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function user(userOptions) {
|
44 | return _userWithOptions({}, userOptions || {});
|
45 | }
|
46 | exports.user = user;
|
47 |
|
48 | function _userWithOptions(options, userOptions) {
|
49 | return new UserBuilder(() => {
|
50 | if (!process.env.GCLOUD_PROJECT) {
|
51 | throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
52 | }
|
53 | return "projects/" + process.env.GCLOUD_PROJECT;
|
54 | }, options, userOptions);
|
55 | }
|
56 | exports._userWithOptions = _userWithOptions;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | class UserBuilder {
|
62 | static dataConstructor(raw) {
|
63 | return (0, identity_1.userRecordConstructor)(raw.data);
|
64 | }
|
65 |
|
66 | constructor(triggerResource, options, userOptions) {
|
67 | this.triggerResource = triggerResource;
|
68 | this.options = options;
|
69 | this.userOptions = userOptions;
|
70 | }
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | onCreate(handler) {
|
79 | return this.onOperation(handler, "user.create");
|
80 | }
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | onDelete(handler) {
|
89 | return this.onOperation(handler, "user.delete");
|
90 | }
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | beforeCreate(handler) {
|
99 | return this.beforeOperation(handler, "beforeCreate");
|
100 | }
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | beforeSignIn(handler) {
|
109 | return this.beforeOperation(handler, "beforeSignIn");
|
110 | }
|
111 | onOperation(handler, eventType) {
|
112 | return (0, cloud_functions_1.makeCloudFunction)({
|
113 | handler,
|
114 | provider: exports.provider,
|
115 | eventType,
|
116 | service: exports.service,
|
117 | triggerResource: this.triggerResource,
|
118 |
|
119 | dataConstructor: UserBuilder.dataConstructor,
|
120 | legacyEventType: `providers/firebase.auth/eventTypes/${eventType}`,
|
121 | options: this.options,
|
122 | });
|
123 | }
|
124 | beforeOperation(handler, eventType) {
|
125 | var _a, _b, _c, _d, _e, _f;
|
126 | const accessToken = ((_b = (_a = this.userOptions) === null || _a === void 0 ? void 0 : _a.blockingOptions) === null || _b === void 0 ? void 0 : _b.accessToken) || false;
|
127 | const idToken = ((_d = (_c = this.userOptions) === null || _c === void 0 ? void 0 : _c.blockingOptions) === null || _d === void 0 ? void 0 : _d.idToken) || false;
|
128 | const refreshToken = ((_f = (_e = this.userOptions) === null || _e === void 0 ? void 0 : _e.blockingOptions) === null || _f === void 0 ? void 0 : _f.refreshToken) || false;
|
129 |
|
130 |
|
131 | const wrappedHandler = (user, context) => handler(user, context);
|
132 | const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
|
133 | const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
|
134 | func.__trigger = {
|
135 | labels: {},
|
136 | ...(0, cloud_functions_1.optionsToTrigger)(this.options),
|
137 | blockingTrigger: {
|
138 | eventType: legacyEventType,
|
139 | options: {
|
140 | accessToken,
|
141 | idToken,
|
142 | refreshToken,
|
143 | },
|
144 | },
|
145 | };
|
146 | func.__endpoint = {
|
147 | platform: "gcfv1",
|
148 | labels: {},
|
149 | ...(0, manifest_1.initV1Endpoint)(this.options),
|
150 | ...(0, cloud_functions_1.optionsToEndpoint)(this.options),
|
151 | blockingTrigger: {
|
152 | eventType: legacyEventType,
|
153 | options: {
|
154 | accessToken,
|
155 | idToken,
|
156 | refreshToken,
|
157 | },
|
158 | },
|
159 | };
|
160 | func.__requiredAPIs = [
|
161 | {
|
162 | api: "identitytoolkit.googleapis.com",
|
163 | reason: "Needed for auth blocking functions",
|
164 | },
|
165 | ];
|
166 | func.run = handler;
|
167 | return func;
|
168 | }
|
169 | }
|
170 | exports.UserBuilder = UserBuilder;
|