@dereekb/firebase-server 13.31.0 → 13.33.0
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.
- package/calcom/index.cjs.default.js +1 -0
- package/calcom/index.cjs.js +1451 -0
- package/calcom/index.cjs.mjs +2 -0
- package/calcom/index.d.ts +1 -0
- package/calcom/index.esm.js +1437 -0
- package/calcom/package.json +29 -0
- package/calcom/src/index.d.ts +1 -0
- package/calcom/src/lib/calcom.oauth.connection.cache.d.ts +49 -0
- package/calcom/src/lib/calcom.oauth.connection.config.d.ts +75 -0
- package/calcom/src/lib/calcom.oauth.connection.context.d.ts +84 -0
- package/calcom/src/lib/calcom.oauth.connection.controller.d.ts +18 -0
- package/calcom/src/lib/calcom.oauth.connection.module.d.ts +55 -0
- package/calcom/src/lib/calcom.oauth.connection.service.d.ts +33 -0
- package/calcom/src/lib/index.d.ts +6 -0
- package/discord/index.cjs.default.js +1 -0
- package/discord/index.cjs.js +761 -0
- package/discord/index.cjs.mjs +2 -0
- package/discord/index.d.ts +1 -0
- package/discord/index.esm.js +753 -0
- package/discord/package.json +29 -0
- package/discord/src/index.d.ts +1 -0
- package/discord/src/lib/discord.oauth.connection.config.d.ts +69 -0
- package/discord/src/lib/discord.oauth.connection.controller.d.ts +18 -0
- package/discord/src/lib/discord.oauth.connection.module.d.ts +39 -0
- package/discord/src/lib/discord.oauth.connection.service.d.ts +43 -0
- package/discord/src/lib/index.d.ts +4 -0
- package/index.cjs.js +14 -3
- package/index.esm.js +14 -3
- package/mailgun/package.json +9 -9
- package/mcp/package.json +11 -11
- package/model/index.cjs.js +11077 -6072
- package/model/index.esm.js +11020 -6081
- package/model/package.json +10 -9
- package/model/src/lib/index.d.ts +1 -0
- package/model/src/lib/mailgun/index.d.ts +1 -0
- package/model/src/lib/mailgun/notification.healthcheck.mailgun.d.ts +115 -0
- package/model/src/lib/notification/index.d.ts +2 -0
- package/model/src/lib/notification/notification.action.server.d.ts +42 -3
- package/model/src/lib/notification/notification.error.d.ts +31 -0
- package/model/src/lib/notification/notification.healthcheck.d.ts +39 -0
- package/model/src/lib/notification/notification.healthcheck.service.d.ts +118 -0
- package/model/src/lib/notification/notification.send.service.d.ts +22 -0
- package/model/src/lib/userexternalconnection/index.d.ts +8 -0
- package/model/src/lib/userexternalconnection/oauth/index.d.ts +7 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.config.d.ts +110 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.controller.d.ts +68 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.error.d.ts +29 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.refresh.d.ts +24 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.registry.d.ts +54 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.service.d.ts +216 -0
- package/model/src/lib/userexternalconnection/oauth/userexternalconnection.oauth.state.d.ts +114 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.accessor.service.d.ts +111 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.action.server.d.ts +172 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.error.d.ts +44 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.module.d.ts +129 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.private.d.ts +192 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.reader.service.d.ts +157 -0
- package/model/src/lib/userexternalconnection/userexternalconnection.refresh.service.d.ts +46 -0
- package/oidc/index.cjs.js +104 -78
- package/oidc/index.esm.js +104 -78
- package/oidc/package.json +10 -10
- package/package.json +24 -10
- package/src/lib/env/env.config.d.ts +15 -0
- package/src/lib/env/env.service.d.ts +7 -0
- package/src/lib/nest/env/env.service.d.ts +1 -0
- package/test/index.cjs.js +14 -2
- package/test/index.esm.js +15 -3
- package/test/package.json +11 -11
- package/test/src/lib/firebase/firebase.admin.auth.d.ts +1 -1
- package/twilio/package.json +8 -8
- package/zoho/README.md +8 -0
- package/zoho/index.cjs.js +1223 -33
- package/zoho/index.esm.js +1212 -36
- package/zoho/package.json +12 -9
- package/zoho/src/lib/index.d.ts +5 -0
- package/zoho/src/lib/zoho.oauth.connection.cache.d.ts +45 -0
- package/zoho/src/lib/zoho.oauth.connection.config.d.ts +80 -0
- package/zoho/src/lib/zoho.oauth.connection.controller.d.ts +18 -0
- package/zoho/src/lib/zoho.oauth.connection.module.d.ts +43 -0
- package/zoho/src/lib/zoho.oauth.connection.service.d.ts +107 -0
|
@@ -0,0 +1,1451 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var calcom = require('@dereekb/calcom');
|
|
4
|
+
var firebase = require('@dereekb/firebase');
|
|
5
|
+
var model = require('@dereekb/firebase-server/model');
|
|
6
|
+
var util = require('@dereekb/util');
|
|
7
|
+
var date = require('@dereekb/date');
|
|
8
|
+
var common = require('@nestjs/common');
|
|
9
|
+
var nestjs = require('@dereekb/calcom/nestjs');
|
|
10
|
+
var fetch = require('@dereekb/util/fetch');
|
|
11
|
+
var config = require('@nestjs/config');
|
|
12
|
+
var firebaseServer = require('@dereekb/firebase-server');
|
|
13
|
+
|
|
14
|
+
function _type_of$3(obj) {
|
|
15
|
+
"@swc/helpers - typeof";
|
|
16
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
17
|
+
}
|
|
18
|
+
function __decorate(decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if ((typeof Reflect === "undefined" ? "undefined" : _type_of$3(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
}
|
|
24
|
+
function __param(paramIndex, decorator) {
|
|
25
|
+
return function(target, key) {
|
|
26
|
+
decorator(target, key, paramIndex);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
30
|
+
var e = new Error(message);
|
|
31
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function _assert_this_initialized$2(self) {
|
|
35
|
+
if (self === void 0) {
|
|
36
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
37
|
+
}
|
|
38
|
+
return self;
|
|
39
|
+
}
|
|
40
|
+
function _call_super$2(_this, derived, args) {
|
|
41
|
+
derived = _get_prototype_of$2(derived);
|
|
42
|
+
return _possible_constructor_return$2(_this, _is_native_reflect_construct$2() ? Reflect.construct(derived, args || [], _get_prototype_of$2(_this).constructor) : derived.apply(_this, args));
|
|
43
|
+
}
|
|
44
|
+
function _class_call_check$3(instance, Constructor) {
|
|
45
|
+
if (!(instance instanceof Constructor)) {
|
|
46
|
+
throw new TypeError("Cannot call a class as a function");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function _define_property$3(obj, key, value) {
|
|
50
|
+
if (key in obj) {
|
|
51
|
+
Object.defineProperty(obj, key, {
|
|
52
|
+
value: value,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
obj[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
function _get_prototype_of$2(o) {
|
|
63
|
+
_get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
64
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
65
|
+
};
|
|
66
|
+
return _get_prototype_of$2(o);
|
|
67
|
+
}
|
|
68
|
+
function _inherits$2(subClass, superClass) {
|
|
69
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
70
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
71
|
+
}
|
|
72
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
73
|
+
constructor: {
|
|
74
|
+
value: subClass,
|
|
75
|
+
writable: true,
|
|
76
|
+
configurable: true
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (superClass) _set_prototype_of$2(subClass, superClass);
|
|
80
|
+
}
|
|
81
|
+
function _object_spread$1(target) {
|
|
82
|
+
for(var i = 1; i < arguments.length; i++){
|
|
83
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
84
|
+
var ownKeys = Object.keys(source);
|
|
85
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
86
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
87
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
ownKeys.forEach(function(key) {
|
|
91
|
+
_define_property$3(target, key, source[key]);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return target;
|
|
95
|
+
}
|
|
96
|
+
function ownKeys$1(object, enumerableOnly) {
|
|
97
|
+
var keys = Object.keys(object);
|
|
98
|
+
if (Object.getOwnPropertySymbols) {
|
|
99
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
100
|
+
keys.push.apply(keys, symbols);
|
|
101
|
+
}
|
|
102
|
+
return keys;
|
|
103
|
+
}
|
|
104
|
+
function _object_spread_props$1(target, source) {
|
|
105
|
+
source = source != null ? source : {};
|
|
106
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
107
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
108
|
+
} else {
|
|
109
|
+
ownKeys$1(Object(source)).forEach(function(key) {
|
|
110
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return target;
|
|
114
|
+
}
|
|
115
|
+
function _possible_constructor_return$2(self, call) {
|
|
116
|
+
if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
|
|
117
|
+
return call;
|
|
118
|
+
}
|
|
119
|
+
return _assert_this_initialized$2(self);
|
|
120
|
+
}
|
|
121
|
+
function _set_prototype_of$2(o, p) {
|
|
122
|
+
_set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
123
|
+
o.__proto__ = p;
|
|
124
|
+
return o;
|
|
125
|
+
};
|
|
126
|
+
return _set_prototype_of$2(o, p);
|
|
127
|
+
}
|
|
128
|
+
function _type_of$2(obj) {
|
|
129
|
+
"@swc/helpers - typeof";
|
|
130
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
131
|
+
}
|
|
132
|
+
function _is_native_reflect_construct$2() {
|
|
133
|
+
try {
|
|
134
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
135
|
+
} catch (_) {}
|
|
136
|
+
return (_is_native_reflect_construct$2 = function() {
|
|
137
|
+
return !!result;
|
|
138
|
+
})();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Controller path the Cal.com external-connection OAuth endpoints are mounted at.
|
|
142
|
+
*
|
|
143
|
+
* Derived from the framework's path factory, the same expression the redirect URI and the
|
|
144
|
+
* global-prefix exclusion are built from, so the three cannot drift apart.
|
|
145
|
+
*/ var CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH = model.userExternalConnectionOAuthControllerPath(firebase.CALCOM_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
|
|
146
|
+
/**
|
|
147
|
+
* Routes to exclude from an app's global API route prefix so the Cal.com callback controller stays
|
|
148
|
+
* mounted at `/oauth/calcom/*`.
|
|
149
|
+
*
|
|
150
|
+
* Spread this into the `exclude` list of the app's `globalApiRoutePrefix` config, alongside
|
|
151
|
+
* `FIREBASE_SERVER_OIDC_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE`.
|
|
152
|
+
*/ var CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = model.userExternalConnectionOAuthRoutesForGlobalRouteExclude(firebase.CALCOM_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE);
|
|
153
|
+
/**
|
|
154
|
+
* The scopes requested when an app does not declare its own.
|
|
155
|
+
*
|
|
156
|
+
* Declared in code, deliberately NOT read from the environment: the set to request follows from what
|
|
157
|
+
* the integration actually does, so it is a property of the code rather than of a deployment.
|
|
158
|
+
* Requesting less than the code uses does not make it work — it moves the failure from the consent
|
|
159
|
+
* screen to the first API call.
|
|
160
|
+
*
|
|
161
|
+
* Least privilege for a per-user calendar connect: read which meeting types exist, read the user's
|
|
162
|
+
* availability, and read/write bookings. Excludes `EVENT_TYPE_WRITE` and `SCHEDULE_WRITE` —
|
|
163
|
+
* connecting a calendar does not involve editing the user's meeting types or availability — and
|
|
164
|
+
* `PROFILE_READ`, which is only needed to label the connection with the Cal.com account it belongs
|
|
165
|
+
* to.
|
|
166
|
+
*
|
|
167
|
+
* Cal.com refuses the authorize request outright when the requested set exceeds what the OAuth
|
|
168
|
+
* client is registered for ("Requested scope exceeds the client's registered scopes"). That is a
|
|
169
|
+
* registration problem: register the scopes the code needs, rather than narrowing the request to fit.
|
|
170
|
+
* An app whose integration genuinely does less can declare its own set on the module metadata, in
|
|
171
|
+
* code where it is reviewable.
|
|
172
|
+
*/ var DEFAULT_CALCOM_OAUTH_SCOPES = [
|
|
173
|
+
'EVENT_TYPE_READ',
|
|
174
|
+
'SCHEDULE_READ',
|
|
175
|
+
'BOOKING_READ',
|
|
176
|
+
'BOOKING_WRITE'
|
|
177
|
+
];
|
|
178
|
+
/**
|
|
179
|
+
* Configuration for the {@link CalcomUserExternalConnectionOAuthService}.
|
|
180
|
+
*
|
|
181
|
+
* Extends the framework config with the one thing that is Cal.com's own — which scopes to request.
|
|
182
|
+
*/ var CalcomUserExternalConnectionOAuthServiceConfig = /*#__PURE__*/ function(UserExternalConnectionOAuthServiceConfig) {
|
|
183
|
+
_inherits$2(CalcomUserExternalConnectionOAuthServiceConfig, UserExternalConnectionOAuthServiceConfig);
|
|
184
|
+
function CalcomUserExternalConnectionOAuthServiceConfig() {
|
|
185
|
+
_class_call_check$3(this, CalcomUserExternalConnectionOAuthServiceConfig);
|
|
186
|
+
var _this;
|
|
187
|
+
_this = _call_super$2(this, CalcomUserExternalConnectionOAuthServiceConfig, arguments), _define_property$3(_this, "scopes", void 0);
|
|
188
|
+
return _this;
|
|
189
|
+
}
|
|
190
|
+
return CalcomUserExternalConnectionOAuthServiceConfig;
|
|
191
|
+
}(model.UserExternalConnectionOAuthServiceConfig);
|
|
192
|
+
/**
|
|
193
|
+
* Builds the Cal.com connect flow's configuration from the app's configured origins.
|
|
194
|
+
*
|
|
195
|
+
* Nothing here is read from the environment as a value: the redirect URI is derived from the app's
|
|
196
|
+
* OAuth origin plus the mounted controller path, and the return URLs from the app URL plus
|
|
197
|
+
* code-declared paths. Registering Cal.com therefore adds no deployment configuration beyond the
|
|
198
|
+
* client credentials themselves.
|
|
199
|
+
*
|
|
200
|
+
* @param config - The env service, the return paths, and the optional scope override.
|
|
201
|
+
* @returns The validated service configuration.
|
|
202
|
+
*/ function calcomUserExternalConnectionOAuthServiceConfigFactory(config) {
|
|
203
|
+
var envService = config.envService, successPath = config.successPath, failurePath = config.failurePath, scopes = config.scopes;
|
|
204
|
+
var baseConfig = model.userExternalConnectionOAuthServiceConfigFactory({
|
|
205
|
+
envService: envService,
|
|
206
|
+
providerType: firebase.CALCOM_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE,
|
|
207
|
+
successPath: successPath,
|
|
208
|
+
failurePath: failurePath
|
|
209
|
+
});
|
|
210
|
+
return _object_spread_props$1(_object_spread$1({}, baseConfig), {
|
|
211
|
+
scopes: scopes !== null && scopes !== void 0 ? scopes : DEFAULT_CALCOM_OAUTH_SCOPES
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function _assert_this_initialized$1(self) {
|
|
216
|
+
if (self === void 0) {
|
|
217
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
218
|
+
}
|
|
219
|
+
return self;
|
|
220
|
+
}
|
|
221
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
222
|
+
try {
|
|
223
|
+
var info = gen[key](arg);
|
|
224
|
+
var value = info.value;
|
|
225
|
+
} catch (error) {
|
|
226
|
+
reject(error);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (info.done) {
|
|
230
|
+
resolve(value);
|
|
231
|
+
} else {
|
|
232
|
+
Promise.resolve(value).then(_next, _throw);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function _async_to_generator$2(fn) {
|
|
236
|
+
return function() {
|
|
237
|
+
var self = this, args = arguments;
|
|
238
|
+
return new Promise(function(resolve, reject) {
|
|
239
|
+
var gen = fn.apply(self, args);
|
|
240
|
+
function _next(value) {
|
|
241
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
242
|
+
}
|
|
243
|
+
function _throw(err) {
|
|
244
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
245
|
+
}
|
|
246
|
+
_next(undefined);
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function _call_super$1(_this, derived, args) {
|
|
251
|
+
derived = _get_prototype_of$1(derived);
|
|
252
|
+
return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
|
|
253
|
+
}
|
|
254
|
+
function _class_call_check$2(instance, Constructor) {
|
|
255
|
+
if (!(instance instanceof Constructor)) {
|
|
256
|
+
throw new TypeError("Cannot call a class as a function");
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function _defineProperties(target, props) {
|
|
260
|
+
for(var i = 0; i < props.length; i++){
|
|
261
|
+
var descriptor = props[i];
|
|
262
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
263
|
+
descriptor.configurable = true;
|
|
264
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
265
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
269
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
270
|
+
return Constructor;
|
|
271
|
+
}
|
|
272
|
+
function _define_property$2(obj, key, value) {
|
|
273
|
+
if (key in obj) {
|
|
274
|
+
Object.defineProperty(obj, key, {
|
|
275
|
+
value: value,
|
|
276
|
+
enumerable: true,
|
|
277
|
+
configurable: true,
|
|
278
|
+
writable: true
|
|
279
|
+
});
|
|
280
|
+
} else {
|
|
281
|
+
obj[key] = value;
|
|
282
|
+
}
|
|
283
|
+
return obj;
|
|
284
|
+
}
|
|
285
|
+
function _get_prototype_of$1(o) {
|
|
286
|
+
_get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
287
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
288
|
+
};
|
|
289
|
+
return _get_prototype_of$1(o);
|
|
290
|
+
}
|
|
291
|
+
function _inherits$1(subClass, superClass) {
|
|
292
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
293
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
294
|
+
}
|
|
295
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
296
|
+
constructor: {
|
|
297
|
+
value: subClass,
|
|
298
|
+
writable: true,
|
|
299
|
+
configurable: true
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
if (superClass) _set_prototype_of$1(subClass, superClass);
|
|
303
|
+
}
|
|
304
|
+
function _possible_constructor_return$1(self, call) {
|
|
305
|
+
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
306
|
+
return call;
|
|
307
|
+
}
|
|
308
|
+
return _assert_this_initialized$1(self);
|
|
309
|
+
}
|
|
310
|
+
function _set_prototype_of$1(o, p) {
|
|
311
|
+
_set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
312
|
+
o.__proto__ = p;
|
|
313
|
+
return o;
|
|
314
|
+
};
|
|
315
|
+
return _set_prototype_of$1(o, p);
|
|
316
|
+
}
|
|
317
|
+
function _type_of$1(obj) {
|
|
318
|
+
"@swc/helpers - typeof";
|
|
319
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
320
|
+
}
|
|
321
|
+
function _is_native_reflect_construct$1() {
|
|
322
|
+
try {
|
|
323
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
324
|
+
} catch (_) {}
|
|
325
|
+
return (_is_native_reflect_construct$1 = function() {
|
|
326
|
+
return !!result;
|
|
327
|
+
})();
|
|
328
|
+
}
|
|
329
|
+
function _ts_generator$2(thisArg, body) {
|
|
330
|
+
var f, y, t, _ = {
|
|
331
|
+
label: 0,
|
|
332
|
+
sent: function() {
|
|
333
|
+
if (t[0] & 1) throw t[1];
|
|
334
|
+
return t[1];
|
|
335
|
+
},
|
|
336
|
+
trys: [],
|
|
337
|
+
ops: []
|
|
338
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
339
|
+
return d(g, "next", {
|
|
340
|
+
value: verb(0)
|
|
341
|
+
}), d(g, "throw", {
|
|
342
|
+
value: verb(1)
|
|
343
|
+
}), d(g, "return", {
|
|
344
|
+
value: verb(2)
|
|
345
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
346
|
+
value: function() {
|
|
347
|
+
return this;
|
|
348
|
+
}
|
|
349
|
+
}), g;
|
|
350
|
+
function verb(n) {
|
|
351
|
+
return function(v) {
|
|
352
|
+
return step([
|
|
353
|
+
n,
|
|
354
|
+
v
|
|
355
|
+
]);
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function step(op) {
|
|
359
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
360
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
361
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
362
|
+
if (y = 0, t) op = [
|
|
363
|
+
op[0] & 2,
|
|
364
|
+
t.value
|
|
365
|
+
];
|
|
366
|
+
switch(op[0]){
|
|
367
|
+
case 0:
|
|
368
|
+
case 1:
|
|
369
|
+
t = op;
|
|
370
|
+
break;
|
|
371
|
+
case 4:
|
|
372
|
+
_.label++;
|
|
373
|
+
return {
|
|
374
|
+
value: op[1],
|
|
375
|
+
done: false
|
|
376
|
+
};
|
|
377
|
+
case 5:
|
|
378
|
+
_.label++;
|
|
379
|
+
y = op[1];
|
|
380
|
+
op = [
|
|
381
|
+
0
|
|
382
|
+
];
|
|
383
|
+
continue;
|
|
384
|
+
case 7:
|
|
385
|
+
op = _.ops.pop();
|
|
386
|
+
_.trys.pop();
|
|
387
|
+
continue;
|
|
388
|
+
default:
|
|
389
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
390
|
+
_ = 0;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
394
|
+
_.label = op[1];
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
398
|
+
_.label = t[1];
|
|
399
|
+
t = op;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
if (t && _.label < t[2]) {
|
|
403
|
+
_.label = t[2];
|
|
404
|
+
_.ops.push(op);
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
if (t[2]) _.ops.pop();
|
|
408
|
+
_.trys.pop();
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
op = body.call(thisArg, _);
|
|
412
|
+
} catch (e) {
|
|
413
|
+
op = [
|
|
414
|
+
6,
|
|
415
|
+
e
|
|
416
|
+
];
|
|
417
|
+
y = 0;
|
|
418
|
+
} finally{
|
|
419
|
+
f = t = 0;
|
|
420
|
+
}
|
|
421
|
+
if (op[0] & 5) throw op[1];
|
|
422
|
+
return {
|
|
423
|
+
value: op[0] ? op[1] : void 0,
|
|
424
|
+
done: true
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Maps an exchanged Cal.com token to the credentials stored on the private connection document.
|
|
430
|
+
*
|
|
431
|
+
* The `refreshToken` written here is the rotated one from the exchange — Cal.com invalidates the
|
|
432
|
+
* token each use, so persisting the one we sent would break the next refresh.
|
|
433
|
+
*
|
|
434
|
+
* @param accessToken - The exchanged Cal.com access token.
|
|
435
|
+
* @returns The credentials to store.
|
|
436
|
+
*/ function calcomUserExternalConnectionCredentials(accessToken) {
|
|
437
|
+
var token = accessToken.accessToken, refreshToken = accessToken.refreshToken, expiresAt = accessToken.expiresAt, scope = accessToken.scope;
|
|
438
|
+
// split on the same delimiter the authorize request joins with, so the round trip stays symmetric
|
|
439
|
+
var scopes = scope ? scope.split(calcom.CALCOM_OAUTH_SCOPE_DELIMITER).filter(function(x) {
|
|
440
|
+
return x.length > 0;
|
|
441
|
+
}) : undefined;
|
|
442
|
+
return {
|
|
443
|
+
accessToken: token,
|
|
444
|
+
refreshToken: refreshToken,
|
|
445
|
+
tokenType: 'Bearer',
|
|
446
|
+
issuedAt: new Date().toISOString(),
|
|
447
|
+
expiresAt: expiresAt.toISOString(),
|
|
448
|
+
scopes: scopes
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Cal.com's half of the external-connection authorization-code handoff.
|
|
453
|
+
*
|
|
454
|
+
* Everything else — resolving who is connecting, surfacing a refusal, persisting the credentials,
|
|
455
|
+
* choosing the redirect — is the framework's.
|
|
456
|
+
*/ exports.CalcomUserExternalConnectionOAuthService = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthService) {
|
|
457
|
+
_inherits$1(CalcomUserExternalConnectionOAuthService, AbstractUserExternalConnectionOAuthService);
|
|
458
|
+
function CalcomUserExternalConnectionOAuthService(config, stateCoder, userExternalConnectionActions, userExternalConnectionAccessor, oauthApi) {
|
|
459
|
+
_class_call_check$2(this, CalcomUserExternalConnectionOAuthService);
|
|
460
|
+
var _this;
|
|
461
|
+
_this = _call_super$1(this, CalcomUserExternalConnectionOAuthService), _define_property$2(_this, "config", void 0), _define_property$2(_this, "stateCoder", void 0), _define_property$2(_this, "userExternalConnectionActions", void 0), _define_property$2(_this, "userExternalConnectionAccessor", void 0), _define_property$2(_this, "oauthApi", void 0), _define_property$2(_this, "authorizeUrlFactory", void 0);
|
|
462
|
+
_this.config = config;
|
|
463
|
+
_this.stateCoder = stateCoder;
|
|
464
|
+
_this.userExternalConnectionActions = userExternalConnectionActions;
|
|
465
|
+
_this.userExternalConnectionAccessor = userExternalConnectionAccessor;
|
|
466
|
+
_this.oauthApi = oauthApi;
|
|
467
|
+
var scopes = config.scopes, userExternalConnectionOAuth = config.userExternalConnectionOAuth;
|
|
468
|
+
// read through the api rather than injecting CalcomOAuthServiceConfig directly, which the OAuth
|
|
469
|
+
// module does not export to its dependents
|
|
470
|
+
var clientId = oauthApi.config.calcomOAuth.clientId;
|
|
471
|
+
// CalcomOAuthServiceConfig accepts an api-key-only configuration, which has no client id — that
|
|
472
|
+
// would otherwise compose an authorize URL carrying `client_id=undefined` and fail at the
|
|
473
|
+
// consent screen rather than at startup
|
|
474
|
+
if (!clientId) {
|
|
475
|
+
throw new Error('CalcomUserExternalConnectionOAuthService requires a Cal.com OAuth clientId (CALCOM_CLIENT_ID). An api-key-only Cal.com configuration cannot run the per-user connect flow.');
|
|
476
|
+
}
|
|
477
|
+
_this.authorizeUrlFactory = calcom.calcomOAuthAuthorizeUrlFactory({
|
|
478
|
+
clientId: clientId,
|
|
479
|
+
redirectUri: userExternalConnectionOAuth.redirectUri,
|
|
480
|
+
scopes: scopes
|
|
481
|
+
});
|
|
482
|
+
return _this;
|
|
483
|
+
}
|
|
484
|
+
_create_class(CalcomUserExternalConnectionOAuthService, [
|
|
485
|
+
{
|
|
486
|
+
key: "authorizeUrlForState",
|
|
487
|
+
value: function authorizeUrlForState(state) {
|
|
488
|
+
return this.authorizeUrlFactory({
|
|
489
|
+
state: state
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
key: "credentialsForAuthorizationCode",
|
|
495
|
+
value: function credentialsForAuthorizationCode(input) {
|
|
496
|
+
return _async_to_generator$2(function() {
|
|
497
|
+
var accessToken;
|
|
498
|
+
return _ts_generator$2(this, function(_state) {
|
|
499
|
+
switch(_state.label){
|
|
500
|
+
case 0:
|
|
501
|
+
return [
|
|
502
|
+
4,
|
|
503
|
+
this.oauthApi.exchangeAuthorizationCodeToAccessToken({
|
|
504
|
+
code: input.code,
|
|
505
|
+
redirectUri: input.redirectUri
|
|
506
|
+
})
|
|
507
|
+
];
|
|
508
|
+
case 1:
|
|
509
|
+
accessToken = _state.sent();
|
|
510
|
+
return [
|
|
511
|
+
2,
|
|
512
|
+
calcomUserExternalConnectionCredentials(accessToken)
|
|
513
|
+
];
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}).call(this);
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
key: "refreshCredentials",
|
|
521
|
+
value: function refreshCredentials(input) {
|
|
522
|
+
return _async_to_generator$2(function() {
|
|
523
|
+
var refreshToken, response;
|
|
524
|
+
return _ts_generator$2(this, function(_state) {
|
|
525
|
+
switch(_state.label){
|
|
526
|
+
case 0:
|
|
527
|
+
refreshToken = input.credentials.refreshToken;
|
|
528
|
+
if (!refreshToken) {
|
|
529
|
+
throw new Error('CalcomUserExternalConnectionOAuthService.refreshCredentials: the stored credentials carry no refresh token.');
|
|
530
|
+
}
|
|
531
|
+
return [
|
|
532
|
+
4,
|
|
533
|
+
calcom.refreshAccessToken(this.oauthApi.oauthContext)({
|
|
534
|
+
refreshToken: refreshToken
|
|
535
|
+
})
|
|
536
|
+
];
|
|
537
|
+
case 1:
|
|
538
|
+
response = _state.sent();
|
|
539
|
+
return [
|
|
540
|
+
2,
|
|
541
|
+
calcomUserExternalConnectionCredentials(calcom.calcomAccessTokenFromTokenResponse(response))
|
|
542
|
+
];
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}).call(this);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
]);
|
|
549
|
+
return CalcomUserExternalConnectionOAuthService;
|
|
550
|
+
}(model.AbstractUserExternalConnectionOAuthService);
|
|
551
|
+
exports.CalcomUserExternalConnectionOAuthService = __decorate([
|
|
552
|
+
common.Injectable(),
|
|
553
|
+
__param(0, common.Inject(CalcomUserExternalConnectionOAuthServiceConfig)),
|
|
554
|
+
__param(1, common.Inject(model.UserExternalConnectionStateCoder)),
|
|
555
|
+
__param(2, common.Inject(model.UserExternalConnectionServerActions)),
|
|
556
|
+
__param(3, common.Inject(model.UserExternalConnectionAccessor)),
|
|
557
|
+
__param(4, common.Inject(nestjs.CalcomOAuthApi))
|
|
558
|
+
], exports.CalcomUserExternalConnectionOAuthService);
|
|
559
|
+
|
|
560
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
561
|
+
try {
|
|
562
|
+
var info = gen[key](arg);
|
|
563
|
+
var value = info.value;
|
|
564
|
+
} catch (error) {
|
|
565
|
+
reject(error);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
if (info.done) {
|
|
569
|
+
resolve(value);
|
|
570
|
+
} else {
|
|
571
|
+
Promise.resolve(value).then(_next, _throw);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function _async_to_generator$1(fn) {
|
|
575
|
+
return function() {
|
|
576
|
+
var self = this, args = arguments;
|
|
577
|
+
return new Promise(function(resolve, reject) {
|
|
578
|
+
var gen = fn.apply(self, args);
|
|
579
|
+
function _next(value) {
|
|
580
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
581
|
+
}
|
|
582
|
+
function _throw(err) {
|
|
583
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
584
|
+
}
|
|
585
|
+
_next(undefined);
|
|
586
|
+
});
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function _ts_generator$1(thisArg, body) {
|
|
590
|
+
var f, y, t, _ = {
|
|
591
|
+
label: 0,
|
|
592
|
+
sent: function() {
|
|
593
|
+
if (t[0] & 1) throw t[1];
|
|
594
|
+
return t[1];
|
|
595
|
+
},
|
|
596
|
+
trys: [],
|
|
597
|
+
ops: []
|
|
598
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
599
|
+
return d(g, "next", {
|
|
600
|
+
value: verb(0)
|
|
601
|
+
}), d(g, "throw", {
|
|
602
|
+
value: verb(1)
|
|
603
|
+
}), d(g, "return", {
|
|
604
|
+
value: verb(2)
|
|
605
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
606
|
+
value: function() {
|
|
607
|
+
return this;
|
|
608
|
+
}
|
|
609
|
+
}), g;
|
|
610
|
+
function verb(n) {
|
|
611
|
+
return function(v) {
|
|
612
|
+
return step([
|
|
613
|
+
n,
|
|
614
|
+
v
|
|
615
|
+
]);
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function step(op) {
|
|
619
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
620
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
621
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
622
|
+
if (y = 0, t) op = [
|
|
623
|
+
op[0] & 2,
|
|
624
|
+
t.value
|
|
625
|
+
];
|
|
626
|
+
switch(op[0]){
|
|
627
|
+
case 0:
|
|
628
|
+
case 1:
|
|
629
|
+
t = op;
|
|
630
|
+
break;
|
|
631
|
+
case 4:
|
|
632
|
+
_.label++;
|
|
633
|
+
return {
|
|
634
|
+
value: op[1],
|
|
635
|
+
done: false
|
|
636
|
+
};
|
|
637
|
+
case 5:
|
|
638
|
+
_.label++;
|
|
639
|
+
y = op[1];
|
|
640
|
+
op = [
|
|
641
|
+
0
|
|
642
|
+
];
|
|
643
|
+
continue;
|
|
644
|
+
case 7:
|
|
645
|
+
op = _.ops.pop();
|
|
646
|
+
_.trys.pop();
|
|
647
|
+
continue;
|
|
648
|
+
default:
|
|
649
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
650
|
+
_ = 0;
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
654
|
+
_.label = op[1];
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
658
|
+
_.label = t[1];
|
|
659
|
+
t = op;
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
if (t && _.label < t[2]) {
|
|
663
|
+
_.label = t[2];
|
|
664
|
+
_.ops.push(op);
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
if (t[2]) _.ops.pop();
|
|
668
|
+
_.trys.pop();
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
op = body.call(thisArg, _);
|
|
672
|
+
} catch (e) {
|
|
673
|
+
op = [
|
|
674
|
+
6,
|
|
675
|
+
e
|
|
676
|
+
];
|
|
677
|
+
y = 0;
|
|
678
|
+
} finally{
|
|
679
|
+
f = t = 0;
|
|
680
|
+
}
|
|
681
|
+
if (op[0] & 5) throw op[1];
|
|
682
|
+
return {
|
|
683
|
+
value: op[0] ? op[1] : void 0,
|
|
684
|
+
done: true
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Maps stored connection credentials to a {@link CalcomAccessToken}.
|
|
690
|
+
*
|
|
691
|
+
* @param credentials - The credentials stored for the `calcom` provider.
|
|
692
|
+
* @returns The equivalent Cal.com access token, or null when the credentials cannot form one.
|
|
693
|
+
*/ function calcomAccessTokenFromUserExternalConnectionCredentials(credentials) {
|
|
694
|
+
var expiresAt = date.safeToJsDate(credentials === null || credentials === void 0 ? void 0 : credentials.expiresAt);
|
|
695
|
+
var result;
|
|
696
|
+
// Cal.com's token type requires all four, and its factory reads `expiresAt` to decide whether to
|
|
697
|
+
// refresh — a token synthesized without one would be treated as valid forever
|
|
698
|
+
if ((credentials === null || credentials === void 0 ? void 0 : credentials.refreshToken) && expiresAt != null) {
|
|
699
|
+
var _ref, _credentials_scopes;
|
|
700
|
+
var issuedAt = date.safeToJsDate(credentials.issuedAt);
|
|
701
|
+
var expiresIn = Math.round((expiresAt.getTime() - ((_ref = issuedAt === null || issuedAt === void 0 ? void 0 : issuedAt.getTime()) !== null && _ref !== void 0 ? _ref : Date.now())) / util.MS_IN_SECOND);
|
|
702
|
+
result = {
|
|
703
|
+
accessToken: credentials.accessToken,
|
|
704
|
+
refreshToken: credentials.refreshToken,
|
|
705
|
+
// re-joined on the delimiter the authorize request splits on, so the round trip stays symmetric
|
|
706
|
+
scope: ((_credentials_scopes = credentials.scopes) !== null && _credentials_scopes !== void 0 ? _credentials_scopes : []).join(calcom.CALCOM_OAUTH_SCOPE_DELIMITER),
|
|
707
|
+
expiresIn: expiresIn,
|
|
708
|
+
expiresAt: expiresAt
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
return result;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Creates a {@link CalcomAccessTokenCache} backed by a user's UserExternalConnection pair.
|
|
715
|
+
*
|
|
716
|
+
* This is what keeps a Cal.com connection working past its first refresh. Cal.com invalidates a
|
|
717
|
+
* refresh token on every use and returns a rotated one, but it hands that rotated token to its
|
|
718
|
+
* `CalcomAccessTokenCache` — not back to us. With the default in-memory or file cache, the token
|
|
719
|
+
* stored on `uecp` is spent the first time it is used: nothing looks wrong, the entry stays
|
|
720
|
+
* `connected`, and the next process that starts with a cold cache replays a dead token.
|
|
721
|
+
*
|
|
722
|
+
* Pointing the cache at the connection pair makes the pair the single store of record, so a rotation
|
|
723
|
+
* is durable the moment it happens.
|
|
724
|
+
*
|
|
725
|
+
* Deliberately NOT registered as a `CalcomOAuthAccessTokenCacheService`: that service's `cacheForKey`
|
|
726
|
+
* is keyed by an opaque string, whereas this cache is per-user and needs a uid. Build one per user at
|
|
727
|
+
* the call site and pass it in explicitly.
|
|
728
|
+
*
|
|
729
|
+
* @param config - The accessor, the actions, and the user the cache is for.
|
|
730
|
+
* @returns A CalcomAccessTokenCache reading and writing the user's connection pair.
|
|
731
|
+
*/ function userExternalConnectionCalcomAccessTokenCache(config) {
|
|
732
|
+
var accessor = config.accessor, actions = config.actions, uid = config.uid;
|
|
733
|
+
var providerType = firebase.CALCOM_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE;
|
|
734
|
+
var connection = accessor.accessorForUser({
|
|
735
|
+
uid: uid
|
|
736
|
+
})(providerType);
|
|
737
|
+
function loadCachedToken() {
|
|
738
|
+
return _async_to_generator$1(function() {
|
|
739
|
+
var credentials;
|
|
740
|
+
return _ts_generator$1(this, function(_state) {
|
|
741
|
+
switch(_state.label){
|
|
742
|
+
case 0:
|
|
743
|
+
return [
|
|
744
|
+
4,
|
|
745
|
+
connection.readUserExternalConnectionCredentials()
|
|
746
|
+
];
|
|
747
|
+
case 1:
|
|
748
|
+
credentials = _state.sent();
|
|
749
|
+
return [
|
|
750
|
+
2,
|
|
751
|
+
calcomAccessTokenFromUserExternalConnectionCredentials(credentials)
|
|
752
|
+
];
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
})();
|
|
756
|
+
}
|
|
757
|
+
function updateCachedToken(accessToken) {
|
|
758
|
+
return _async_to_generator$1(function() {
|
|
759
|
+
var previous, refreshed, credentials;
|
|
760
|
+
return _ts_generator$1(this, function(_state) {
|
|
761
|
+
switch(_state.label){
|
|
762
|
+
case 0:
|
|
763
|
+
return [
|
|
764
|
+
4,
|
|
765
|
+
connection.readUserExternalConnectionCredentials()
|
|
766
|
+
];
|
|
767
|
+
case 1:
|
|
768
|
+
previous = _state.sent();
|
|
769
|
+
refreshed = calcomUserExternalConnectionCredentials(accessToken);
|
|
770
|
+
// merged rather than written verbatim, because the paired write replaces the provider's credentials
|
|
771
|
+
// wholesale and Cal.com's token carries no account id or label
|
|
772
|
+
credentials = previous == null ? refreshed : model.mergeRefreshedUserExternalConnectionCredentials({
|
|
773
|
+
previous: previous,
|
|
774
|
+
refreshed: refreshed
|
|
775
|
+
});
|
|
776
|
+
return [
|
|
777
|
+
4,
|
|
778
|
+
actions.refreshUserExternalConnectionCredentials({
|
|
779
|
+
uid: uid,
|
|
780
|
+
providerType: providerType,
|
|
781
|
+
credentials: credentials
|
|
782
|
+
})
|
|
783
|
+
];
|
|
784
|
+
case 2:
|
|
785
|
+
_state.sent();
|
|
786
|
+
return [
|
|
787
|
+
2
|
|
788
|
+
];
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
})();
|
|
792
|
+
}
|
|
793
|
+
return {
|
|
794
|
+
loadCachedToken: loadCachedToken,
|
|
795
|
+
updateCachedToken: updateCachedToken
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
800
|
+
try {
|
|
801
|
+
var info = gen[key](arg);
|
|
802
|
+
var value = info.value;
|
|
803
|
+
} catch (error) {
|
|
804
|
+
reject(error);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
if (info.done) {
|
|
808
|
+
resolve(value);
|
|
809
|
+
} else {
|
|
810
|
+
Promise.resolve(value).then(_next, _throw);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
function _async_to_generator(fn) {
|
|
814
|
+
return function() {
|
|
815
|
+
var self = this, args = arguments;
|
|
816
|
+
return new Promise(function(resolve, reject) {
|
|
817
|
+
var gen = fn.apply(self, args);
|
|
818
|
+
function _next(value) {
|
|
819
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
820
|
+
}
|
|
821
|
+
function _throw(err) {
|
|
822
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
823
|
+
}
|
|
824
|
+
_next(undefined);
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function _class_call_check$1(instance, Constructor) {
|
|
829
|
+
if (!(instance instanceof Constructor)) {
|
|
830
|
+
throw new TypeError("Cannot call a class as a function");
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
function _define_property$1(obj, key, value) {
|
|
834
|
+
if (key in obj) {
|
|
835
|
+
Object.defineProperty(obj, key, {
|
|
836
|
+
value: value,
|
|
837
|
+
enumerable: true,
|
|
838
|
+
configurable: true,
|
|
839
|
+
writable: true
|
|
840
|
+
});
|
|
841
|
+
} else {
|
|
842
|
+
obj[key] = value;
|
|
843
|
+
}
|
|
844
|
+
return obj;
|
|
845
|
+
}
|
|
846
|
+
function _instanceof(left, right) {
|
|
847
|
+
"@swc/helpers - instanceof";
|
|
848
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
849
|
+
return !!right[Symbol.hasInstance](left);
|
|
850
|
+
} else {
|
|
851
|
+
return left instanceof right;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function _object_spread(target) {
|
|
855
|
+
for(var i = 1; i < arguments.length; i++){
|
|
856
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
857
|
+
var ownKeys = Object.keys(source);
|
|
858
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
859
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
860
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
861
|
+
}));
|
|
862
|
+
}
|
|
863
|
+
ownKeys.forEach(function(key) {
|
|
864
|
+
_define_property$1(target, key, source[key]);
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
return target;
|
|
868
|
+
}
|
|
869
|
+
function ownKeys(object, enumerableOnly) {
|
|
870
|
+
var keys = Object.keys(object);
|
|
871
|
+
if (Object.getOwnPropertySymbols) {
|
|
872
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
873
|
+
keys.push.apply(keys, symbols);
|
|
874
|
+
}
|
|
875
|
+
return keys;
|
|
876
|
+
}
|
|
877
|
+
function _object_spread_props(target, source) {
|
|
878
|
+
source = source != null ? source : {};
|
|
879
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
880
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
881
|
+
} else {
|
|
882
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
883
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
return target;
|
|
887
|
+
}
|
|
888
|
+
function _ts_generator(thisArg, body) {
|
|
889
|
+
var f, y, t, _ = {
|
|
890
|
+
label: 0,
|
|
891
|
+
sent: function() {
|
|
892
|
+
if (t[0] & 1) throw t[1];
|
|
893
|
+
return t[1];
|
|
894
|
+
},
|
|
895
|
+
trys: [],
|
|
896
|
+
ops: []
|
|
897
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
898
|
+
return d(g, "next", {
|
|
899
|
+
value: verb(0)
|
|
900
|
+
}), d(g, "throw", {
|
|
901
|
+
value: verb(1)
|
|
902
|
+
}), d(g, "return", {
|
|
903
|
+
value: verb(2)
|
|
904
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
905
|
+
value: function() {
|
|
906
|
+
return this;
|
|
907
|
+
}
|
|
908
|
+
}), g;
|
|
909
|
+
function verb(n) {
|
|
910
|
+
return function(v) {
|
|
911
|
+
return step([
|
|
912
|
+
n,
|
|
913
|
+
v
|
|
914
|
+
]);
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
function step(op) {
|
|
918
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
919
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
920
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
921
|
+
if (y = 0, t) op = [
|
|
922
|
+
op[0] & 2,
|
|
923
|
+
t.value
|
|
924
|
+
];
|
|
925
|
+
switch(op[0]){
|
|
926
|
+
case 0:
|
|
927
|
+
case 1:
|
|
928
|
+
t = op;
|
|
929
|
+
break;
|
|
930
|
+
case 4:
|
|
931
|
+
_.label++;
|
|
932
|
+
return {
|
|
933
|
+
value: op[1],
|
|
934
|
+
done: false
|
|
935
|
+
};
|
|
936
|
+
case 5:
|
|
937
|
+
_.label++;
|
|
938
|
+
y = op[1];
|
|
939
|
+
op = [
|
|
940
|
+
0
|
|
941
|
+
];
|
|
942
|
+
continue;
|
|
943
|
+
case 7:
|
|
944
|
+
op = _.ops.pop();
|
|
945
|
+
_.trys.pop();
|
|
946
|
+
continue;
|
|
947
|
+
default:
|
|
948
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
949
|
+
_ = 0;
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
953
|
+
_.label = op[1];
|
|
954
|
+
break;
|
|
955
|
+
}
|
|
956
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
957
|
+
_.label = t[1];
|
|
958
|
+
t = op;
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
if (t && _.label < t[2]) {
|
|
962
|
+
_.label = t[2];
|
|
963
|
+
_.ops.push(op);
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
966
|
+
if (t[2]) _.ops.pop();
|
|
967
|
+
_.trys.pop();
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
op = body.call(thisArg, _);
|
|
971
|
+
} catch (e) {
|
|
972
|
+
op = [
|
|
973
|
+
6,
|
|
974
|
+
e
|
|
975
|
+
];
|
|
976
|
+
y = 0;
|
|
977
|
+
} finally{
|
|
978
|
+
f = t = 0;
|
|
979
|
+
}
|
|
980
|
+
if (op[0] & 5) throw op[1];
|
|
981
|
+
return {
|
|
982
|
+
value: op[0] ? op[1] : void 0,
|
|
983
|
+
done: true
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Maps an error thrown while calling Cal.com as a user to the code to record on their connection.
|
|
989
|
+
*
|
|
990
|
+
* Returns null for anything that is not the grant being refused — a rate limit, a validation error, a
|
|
991
|
+
* network failure, or a 403 all leave the connection itself intact, and marking it `error` for those
|
|
992
|
+
* would send the user to a reconnect that fixes nothing.
|
|
993
|
+
*
|
|
994
|
+
* @param error - The error thrown by a Cal.com call.
|
|
995
|
+
* @returns The error code to record, or null when the connection is not at fault.
|
|
996
|
+
*
|
|
997
|
+
* @__NO_SIDE_EFFECTS__
|
|
998
|
+
*/ function userExternalConnectionErrorCodeFromCalcomError(error) {
|
|
999
|
+
var result;
|
|
1000
|
+
if (_instanceof(error, calcom.CalcomOAuthAccessTokenError)) {
|
|
1001
|
+
// `invalid_grant`, the only code this error carries. Recorded as `expired` rather than `revoked`
|
|
1002
|
+
// for the same reason the reader does: the code cannot distinguish a revoked grant from a refresh
|
|
1003
|
+
// token that was already spent, and telling the user they revoked access when they did not would
|
|
1004
|
+
// send the UI down the wrong path
|
|
1005
|
+
result = model.DEFAULT_USER_EXTERNAL_CONNECTION_REFRESH_FAILURE_ERROR_CODE;
|
|
1006
|
+
} else if (_instanceof(error, calcom.CalcomOAuthAuthFailureError)) {
|
|
1007
|
+
// no usable access token could be produced from the stored refresh token
|
|
1008
|
+
result = 'unauthorized';
|
|
1009
|
+
} else if (_instanceof(error, calcom.CalcomServerFetchResponseError)) {
|
|
1010
|
+
result = error.responseError.response.status === util.HTTP_UNAUTHORIZED_STATUS_CODE ? 'unauthorized' : undefined;
|
|
1011
|
+
} else if (_instanceof(error, fetch.FetchResponseError)) {
|
|
1012
|
+
// the same rejection, for a response whose body Cal.com's error parser could not read
|
|
1013
|
+
result = error.response.status === util.HTTP_UNAUTHORIZED_STATUS_CODE ? 'unauthorized' : undefined;
|
|
1014
|
+
}
|
|
1015
|
+
return result;
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Turns a uid into a Cal.com API instance that acts as that user.
|
|
1019
|
+
*
|
|
1020
|
+
* The provider-specific sibling of `UserExternalConnectionReader.readerForUser`, and the only correct
|
|
1021
|
+
* way to make per-user Cal.com calls in an app that stores connections on the pair:
|
|
1022
|
+
*
|
|
1023
|
+
* ```ts
|
|
1024
|
+
* const calcom = await calcomUserContextService.calcomUserContextForUser({ uid });
|
|
1025
|
+
* const me = await calcom.getMe();
|
|
1026
|
+
* ```
|
|
1027
|
+
*
|
|
1028
|
+
* Do NOT assemble this by hand from `readUsableUserExternalConnectionCredentials()`. Cal.com runs its
|
|
1029
|
+
* own refresh loop through the access token cache, so a reader refresh followed by a library refresh
|
|
1030
|
+
* spends a rotated refresh token twice and destroys one of two valid grants.
|
|
1031
|
+
*/ var UserExternalConnectionCalcomUserContextService = function UserExternalConnectionCalcomUserContextService() {
|
|
1032
|
+
_class_call_check$1(this, UserExternalConnectionCalcomUserContextService);
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* Creates a {@link UserExternalConnectionCalcomUserContextService}.
|
|
1036
|
+
*
|
|
1037
|
+
* Instances are NOT cached per user. Each call builds a fresh token factory, so the in-memory token
|
|
1038
|
+
* tier lives only as long as the returned instance and one request's tokens are never visible to the
|
|
1039
|
+
* next. The pair-backed cache means the cost of that is a document read, not a token refresh.
|
|
1040
|
+
*
|
|
1041
|
+
* @param config - The Cal.com API, the accessor, and the write surface.
|
|
1042
|
+
* @returns A concrete UserExternalConnectionCalcomUserContextService implementation.
|
|
1043
|
+
*/ function userExternalConnectionCalcomUserContextService(config) {
|
|
1044
|
+
var calcomApi = config.calcomApi, accessor = config.accessor, actions = config.actions;
|
|
1045
|
+
var providerType = firebase.CALCOM_USER_EXTERNAL_CONNECTION_PROVIDER_TYPE;
|
|
1046
|
+
var logger = new common.Logger('UserExternalConnectionCalcomUserContextService');
|
|
1047
|
+
/**
|
|
1048
|
+
* Records that Cal.com refused the user's grant.
|
|
1049
|
+
*
|
|
1050
|
+
* Never throws: the caller is already handling the provider's error, and losing that error to a
|
|
1051
|
+
* failed write would be worse than not recording it.
|
|
1052
|
+
*
|
|
1053
|
+
* @param uid - The user whose grant was refused.
|
|
1054
|
+
* @param error - The code to record.
|
|
1055
|
+
*/ function reportRefusedGrant(uid, error) {
|
|
1056
|
+
return _async_to_generator(function() {
|
|
1057
|
+
var entry, e;
|
|
1058
|
+
return _ts_generator(this, function(_state) {
|
|
1059
|
+
switch(_state.label){
|
|
1060
|
+
case 0:
|
|
1061
|
+
_state.trys.push([
|
|
1062
|
+
0,
|
|
1063
|
+
4,
|
|
1064
|
+
,
|
|
1065
|
+
5
|
|
1066
|
+
]);
|
|
1067
|
+
return [
|
|
1068
|
+
4,
|
|
1069
|
+
accessor.accessorForUser({
|
|
1070
|
+
uid: uid
|
|
1071
|
+
})(providerType).readUserExternalConnectionForProvider()
|
|
1072
|
+
];
|
|
1073
|
+
case 1:
|
|
1074
|
+
entry = _state.sent().entry;
|
|
1075
|
+
if (!((entry === null || entry === void 0 ? void 0 : entry.st) !== 'error' || entry.er !== error)) return [
|
|
1076
|
+
3,
|
|
1077
|
+
3
|
|
1078
|
+
];
|
|
1079
|
+
return [
|
|
1080
|
+
4,
|
|
1081
|
+
actions.markUserExternalConnectionError({
|
|
1082
|
+
uid: uid,
|
|
1083
|
+
providerType: providerType,
|
|
1084
|
+
error: error
|
|
1085
|
+
})
|
|
1086
|
+
];
|
|
1087
|
+
case 2:
|
|
1088
|
+
_state.sent();
|
|
1089
|
+
_state.label = 3;
|
|
1090
|
+
case 3:
|
|
1091
|
+
return [
|
|
1092
|
+
3,
|
|
1093
|
+
5
|
|
1094
|
+
];
|
|
1095
|
+
case 4:
|
|
1096
|
+
e = _state.sent();
|
|
1097
|
+
logger.error('Failed marking the "'.concat(providerType, '" connection error for uid "').concat(uid, '": '), e);
|
|
1098
|
+
return [
|
|
1099
|
+
3,
|
|
1100
|
+
5
|
|
1101
|
+
];
|
|
1102
|
+
case 5:
|
|
1103
|
+
return [
|
|
1104
|
+
2
|
|
1105
|
+
];
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
})();
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Wraps a Cal.com fetch so a refused grant is always recorded on the connection.
|
|
1112
|
+
*
|
|
1113
|
+
* Wrapping the fetch rather than asking callers to report is what makes this impossible to forget,
|
|
1114
|
+
* and it is the only layer that sees both failures: Cal.com resolves the access token inside the
|
|
1115
|
+
* request's header factory, so a dead refresh token surfaces here exactly like a 401 response does.
|
|
1116
|
+
*
|
|
1117
|
+
* @param uid - The user the fetch acts as.
|
|
1118
|
+
* @param fetch - The user context's fetch.
|
|
1119
|
+
* @returns An equivalent fetch that records a refused grant before rethrowing.
|
|
1120
|
+
*/ function reportingFetch(uid, fetch) {
|
|
1121
|
+
return function(input, init) {
|
|
1122
|
+
return _async_to_generator(function() {
|
|
1123
|
+
var result, e, error;
|
|
1124
|
+
return _ts_generator(this, function(_state) {
|
|
1125
|
+
switch(_state.label){
|
|
1126
|
+
case 0:
|
|
1127
|
+
_state.trys.push([
|
|
1128
|
+
0,
|
|
1129
|
+
2,
|
|
1130
|
+
,
|
|
1131
|
+
5
|
|
1132
|
+
]);
|
|
1133
|
+
return [
|
|
1134
|
+
4,
|
|
1135
|
+
fetch(input, init)
|
|
1136
|
+
];
|
|
1137
|
+
case 1:
|
|
1138
|
+
result = _state.sent(); // awaited so a thrown error is caught here
|
|
1139
|
+
return [
|
|
1140
|
+
3,
|
|
1141
|
+
5
|
|
1142
|
+
];
|
|
1143
|
+
case 2:
|
|
1144
|
+
e = _state.sent();
|
|
1145
|
+
error = userExternalConnectionErrorCodeFromCalcomError(e);
|
|
1146
|
+
if (!(error != null)) return [
|
|
1147
|
+
3,
|
|
1148
|
+
4
|
|
1149
|
+
];
|
|
1150
|
+
return [
|
|
1151
|
+
4,
|
|
1152
|
+
reportRefusedGrant(uid, error)
|
|
1153
|
+
];
|
|
1154
|
+
case 3:
|
|
1155
|
+
_state.sent();
|
|
1156
|
+
_state.label = 4;
|
|
1157
|
+
case 4:
|
|
1158
|
+
throw e;
|
|
1159
|
+
case 5:
|
|
1160
|
+
return [
|
|
1161
|
+
2,
|
|
1162
|
+
result
|
|
1163
|
+
];
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
})();
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
function calcomUserContextForUser(input) {
|
|
1170
|
+
return _async_to_generator(function() {
|
|
1171
|
+
var uid, _ref, entry, credentials, refreshToken, accessTokenCache, userContext, fetch$1, fetchJson, reportingContext;
|
|
1172
|
+
return _ts_generator(this, function(_state) {
|
|
1173
|
+
switch(_state.label){
|
|
1174
|
+
case 0:
|
|
1175
|
+
uid = input.uid;
|
|
1176
|
+
return [
|
|
1177
|
+
4,
|
|
1178
|
+
accessor.accessorForUser({
|
|
1179
|
+
uid: uid
|
|
1180
|
+
})(providerType).readUserExternalConnectionForProvider()
|
|
1181
|
+
];
|
|
1182
|
+
case 1:
|
|
1183
|
+
_ref = _state.sent(), entry = _ref.entry, credentials = _ref.credentials;
|
|
1184
|
+
// an absent entry, absent credentials, or an explicit disconnect all mean the same thing: there is
|
|
1185
|
+
// nothing here to act as, and the remedy is for the user to connect. An `error` entry is NOT
|
|
1186
|
+
// refused — it keeps its credentials precisely so a refresh can repair it, and the refresh Cal.com
|
|
1187
|
+
// runs through the cache writes back as `connected`, so a working grant heals the entry on first use
|
|
1188
|
+
if (entry == null || credentials == null || entry.st === 'disconnected') {
|
|
1189
|
+
throw model.userExternalConnectionProviderNotConnectedError(providerType);
|
|
1190
|
+
}
|
|
1191
|
+
refreshToken = credentials.refreshToken;
|
|
1192
|
+
// Cal.com issues an access token only in exchange for a refresh token, so without one there is
|
|
1193
|
+
// nothing to act with and no way to renew — a reconnect is the only remedy
|
|
1194
|
+
if (!refreshToken) {
|
|
1195
|
+
throw model.userExternalConnectionCredentialsExpiredError(providerType);
|
|
1196
|
+
}
|
|
1197
|
+
// the pair-backed cache, never the default: Cal.com invalidates a refresh token on every use and
|
|
1198
|
+
// hands the replacement to its cache, so any other cache leaves the stored token spent after one
|
|
1199
|
+
// use while the entry still reads `connected`
|
|
1200
|
+
accessTokenCache = userExternalConnectionCalcomAccessTokenCache({
|
|
1201
|
+
accessor: accessor,
|
|
1202
|
+
actions: actions,
|
|
1203
|
+
uid: uid
|
|
1204
|
+
});
|
|
1205
|
+
userContext = calcomApi.makeUserContext({
|
|
1206
|
+
refreshToken: refreshToken,
|
|
1207
|
+
accessTokenCache: accessTokenCache
|
|
1208
|
+
});
|
|
1209
|
+
fetch$1 = reportingFetch(uid, userContext.userFetch);
|
|
1210
|
+
// rebuilt over the wrapped fetch rather than wrapped itself, so the reporting cannot be bypassed
|
|
1211
|
+
// by whichever of the two an API function reaches for. The parse handling matches the Cal.com
|
|
1212
|
+
// factory's, which is what the unwrapped `userFetchJson` was built with
|
|
1213
|
+
fetchJson = fetch.fetchJsonFunction(fetch$1, {
|
|
1214
|
+
handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
|
|
1215
|
+
});
|
|
1216
|
+
reportingContext = _object_spread_props(_object_spread({}, userContext), {
|
|
1217
|
+
fetch: fetch$1,
|
|
1218
|
+
fetchJson: fetchJson,
|
|
1219
|
+
userFetch: fetch$1,
|
|
1220
|
+
userFetchJson: fetchJson
|
|
1221
|
+
});
|
|
1222
|
+
return [
|
|
1223
|
+
2,
|
|
1224
|
+
calcomApi.makeContextInstance(reportingContext)
|
|
1225
|
+
];
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
})();
|
|
1229
|
+
}
|
|
1230
|
+
return {
|
|
1231
|
+
calcomUserContextForUser: calcomUserContextForUser
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
function _assert_this_initialized(self) {
|
|
1236
|
+
if (self === void 0) {
|
|
1237
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
1238
|
+
}
|
|
1239
|
+
return self;
|
|
1240
|
+
}
|
|
1241
|
+
function _call_super(_this, derived, args) {
|
|
1242
|
+
derived = _get_prototype_of(derived);
|
|
1243
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
1244
|
+
}
|
|
1245
|
+
function _class_call_check(instance, Constructor) {
|
|
1246
|
+
if (!(instance instanceof Constructor)) {
|
|
1247
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
function _define_property(obj, key, value) {
|
|
1251
|
+
if (key in obj) {
|
|
1252
|
+
Object.defineProperty(obj, key, {
|
|
1253
|
+
value: value,
|
|
1254
|
+
enumerable: true,
|
|
1255
|
+
configurable: true,
|
|
1256
|
+
writable: true
|
|
1257
|
+
});
|
|
1258
|
+
} else {
|
|
1259
|
+
obj[key] = value;
|
|
1260
|
+
}
|
|
1261
|
+
return obj;
|
|
1262
|
+
}
|
|
1263
|
+
function _get_prototype_of(o) {
|
|
1264
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
1265
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
1266
|
+
};
|
|
1267
|
+
return _get_prototype_of(o);
|
|
1268
|
+
}
|
|
1269
|
+
function _inherits(subClass, superClass) {
|
|
1270
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
1271
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
1272
|
+
}
|
|
1273
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
1274
|
+
constructor: {
|
|
1275
|
+
value: subClass,
|
|
1276
|
+
writable: true,
|
|
1277
|
+
configurable: true
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
1281
|
+
}
|
|
1282
|
+
function _possible_constructor_return(self, call) {
|
|
1283
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
1284
|
+
return call;
|
|
1285
|
+
}
|
|
1286
|
+
return _assert_this_initialized(self);
|
|
1287
|
+
}
|
|
1288
|
+
function _set_prototype_of(o, p) {
|
|
1289
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
1290
|
+
o.__proto__ = p;
|
|
1291
|
+
return o;
|
|
1292
|
+
};
|
|
1293
|
+
return _set_prototype_of(o, p);
|
|
1294
|
+
}
|
|
1295
|
+
function _type_of(obj) {
|
|
1296
|
+
"@swc/helpers - typeof";
|
|
1297
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1298
|
+
}
|
|
1299
|
+
function _is_native_reflect_construct() {
|
|
1300
|
+
try {
|
|
1301
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
1302
|
+
} catch (_) {}
|
|
1303
|
+
return (_is_native_reflect_construct = function() {
|
|
1304
|
+
return !!result;
|
|
1305
|
+
})();
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Endpoints for the Cal.com external-connection authorization-code handoff.
|
|
1309
|
+
*
|
|
1310
|
+
* Mounted at `/oauth/calcom`, matching the Angular registry's default authorize path of
|
|
1311
|
+
* `/oauth/<providerType>/authorize`. Hosting rewrites do not strip the path, so this prefix is the
|
|
1312
|
+
* public path — but an app with a global API route prefix must ALSO exclude these routes from it via
|
|
1313
|
+
* {@link CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE}, or they land under
|
|
1314
|
+
* that prefix instead and no longer match the redirect URI registered with Cal.com.
|
|
1315
|
+
*
|
|
1316
|
+
* The `authorize` and `callback` routes come from the base class, so this declares only where they
|
|
1317
|
+
* mount and which service serves them.
|
|
1318
|
+
*/ exports.CalcomUserExternalConnectionOAuthController = /*#__PURE__*/ function(AbstractUserExternalConnectionOAuthController) {
|
|
1319
|
+
_inherits(CalcomUserExternalConnectionOAuthController, AbstractUserExternalConnectionOAuthController);
|
|
1320
|
+
function CalcomUserExternalConnectionOAuthController(oauthService) {
|
|
1321
|
+
_class_call_check(this, CalcomUserExternalConnectionOAuthController);
|
|
1322
|
+
var _this;
|
|
1323
|
+
_this = _call_super(this, CalcomUserExternalConnectionOAuthController), _define_property(_this, "oauthService", void 0);
|
|
1324
|
+
_this.oauthService = oauthService;
|
|
1325
|
+
return _this;
|
|
1326
|
+
}
|
|
1327
|
+
return CalcomUserExternalConnectionOAuthController;
|
|
1328
|
+
}(model.AbstractUserExternalConnectionOAuthController);
|
|
1329
|
+
exports.CalcomUserExternalConnectionOAuthController = __decorate([
|
|
1330
|
+
common.Controller(CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH),
|
|
1331
|
+
__param(0, common.Inject(exports.CalcomUserExternalConnectionOAuthService))
|
|
1332
|
+
], exports.CalcomUserExternalConnectionOAuthController);
|
|
1333
|
+
|
|
1334
|
+
function _array_like_to_array(arr, len) {
|
|
1335
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1336
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1337
|
+
return arr2;
|
|
1338
|
+
}
|
|
1339
|
+
function _array_without_holes(arr) {
|
|
1340
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
1341
|
+
}
|
|
1342
|
+
function _iterable_to_array(iter) {
|
|
1343
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1344
|
+
}
|
|
1345
|
+
function _non_iterable_spread() {
|
|
1346
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1347
|
+
}
|
|
1348
|
+
function _to_consumable_array(arr) {
|
|
1349
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
1350
|
+
}
|
|
1351
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
1352
|
+
if (!o) return;
|
|
1353
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1354
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1355
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1356
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1357
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Convenience function used to generate ModuleMetadata for an app's Cal.com external-connection
|
|
1361
|
+
* OAuth module.
|
|
1362
|
+
*
|
|
1363
|
+
* Opt-in, like the webhook module: importing the Cal.com OAuth module alone never mounts HTTP
|
|
1364
|
+
* routes, so an app that only makes outbound Cal.com calls exposes no endpoints.
|
|
1365
|
+
*
|
|
1366
|
+
* The importing module must also supply `UserExternalConnectionServerActions` and
|
|
1367
|
+
* `UserExternalConnectionStateCoder` — both exported by `appUserExternalConnectionModuleMetadata`,
|
|
1368
|
+
* so pass that module in `imports`.
|
|
1369
|
+
*
|
|
1370
|
+
* @param config - The module metadata configuration.
|
|
1371
|
+
* @returns NestJS ModuleMetadata mounting the Cal.com connect endpoints.
|
|
1372
|
+
*/ function appCalcomUserExternalConnectionOAuthModuleMetadata(config$1) {
|
|
1373
|
+
var dependencyModule = config$1.dependencyModule, successPath = config$1.successPath, failurePath = config$1.failurePath, scopes = config$1.scopes, imports = config$1.imports, exports$1 = config$1.exports, providers = config$1.providers;
|
|
1374
|
+
var dependencyModuleImport = dependencyModule ? [
|
|
1375
|
+
dependencyModule
|
|
1376
|
+
] : [];
|
|
1377
|
+
return {
|
|
1378
|
+
imports: [
|
|
1379
|
+
config.ConfigModule
|
|
1380
|
+
].concat(_to_consumable_array(dependencyModuleImport), _to_consumable_array(imports !== null && imports !== void 0 ? imports : [])),
|
|
1381
|
+
controllers: [
|
|
1382
|
+
exports.CalcomUserExternalConnectionOAuthController
|
|
1383
|
+
],
|
|
1384
|
+
exports: [
|
|
1385
|
+
exports.CalcomUserExternalConnectionOAuthService
|
|
1386
|
+
].concat(_to_consumable_array(exports$1 !== null && exports$1 !== void 0 ? exports$1 : [])),
|
|
1387
|
+
providers: [
|
|
1388
|
+
{
|
|
1389
|
+
provide: CalcomUserExternalConnectionOAuthServiceConfig,
|
|
1390
|
+
inject: [
|
|
1391
|
+
firebaseServer.FirebaseServerEnvService
|
|
1392
|
+
],
|
|
1393
|
+
useFactory: function useFactory(envService) {
|
|
1394
|
+
return calcomUserExternalConnectionOAuthServiceConfigFactory({
|
|
1395
|
+
envService: envService,
|
|
1396
|
+
successPath: successPath,
|
|
1397
|
+
failurePath: failurePath,
|
|
1398
|
+
scopes: scopes
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
},
|
|
1402
|
+
exports.CalcomUserExternalConnectionOAuthService
|
|
1403
|
+
].concat(_to_consumable_array(providers !== null && providers !== void 0 ? providers : []))
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
// MARK: Calcom User Context Service
|
|
1407
|
+
/**
|
|
1408
|
+
* Creates the NestJS provider for the {@link UserExternalConnectionCalcomUserContextService}.
|
|
1409
|
+
*
|
|
1410
|
+
* A provider rather than a module, because the three tokens it needs are never declared together:
|
|
1411
|
+
* `CalcomApi` comes from the app's Cal.com module and the accessor and actions from its
|
|
1412
|
+
* UserExternalConnection module. Declare this in a module that imports both.
|
|
1413
|
+
*
|
|
1414
|
+
* Separate from {@link appCalcomUserExternalConnectionOAuthModuleMetadata} on purpose — that module
|
|
1415
|
+
* needs only `CalcomOAuthApi`, and folding this in would force every app running the connect flow to
|
|
1416
|
+
* also provide `CalcomApi` whether it makes outbound Cal.com calls or not.
|
|
1417
|
+
*
|
|
1418
|
+
* @returns The NestJS provider.
|
|
1419
|
+
*
|
|
1420
|
+
* @__NO_SIDE_EFFECTS__
|
|
1421
|
+
*/ function userExternalConnectionCalcomUserContextServiceProvider() {
|
|
1422
|
+
return {
|
|
1423
|
+
provide: UserExternalConnectionCalcomUserContextService,
|
|
1424
|
+
useFactory: function useFactory(calcomApi, accessor, actions) {
|
|
1425
|
+
return userExternalConnectionCalcomUserContextService({
|
|
1426
|
+
calcomApi: calcomApi,
|
|
1427
|
+
accessor: accessor,
|
|
1428
|
+
actions: actions
|
|
1429
|
+
});
|
|
1430
|
+
},
|
|
1431
|
+
inject: [
|
|
1432
|
+
nestjs.CalcomApi,
|
|
1433
|
+
model.UserExternalConnectionAccessor,
|
|
1434
|
+
model.UserExternalConnectionServerActions
|
|
1435
|
+
]
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
exports.CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH = CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_CONTROLLER_PATH;
|
|
1440
|
+
exports.CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE = CALCOM_USER_EXTERNAL_CONNECTION_OAUTH_ROUTES_FOR_GLOBAL_ROUTE_EXCLUDE;
|
|
1441
|
+
exports.CalcomUserExternalConnectionOAuthServiceConfig = CalcomUserExternalConnectionOAuthServiceConfig;
|
|
1442
|
+
exports.DEFAULT_CALCOM_OAUTH_SCOPES = DEFAULT_CALCOM_OAUTH_SCOPES;
|
|
1443
|
+
exports.UserExternalConnectionCalcomUserContextService = UserExternalConnectionCalcomUserContextService;
|
|
1444
|
+
exports.appCalcomUserExternalConnectionOAuthModuleMetadata = appCalcomUserExternalConnectionOAuthModuleMetadata;
|
|
1445
|
+
exports.calcomAccessTokenFromUserExternalConnectionCredentials = calcomAccessTokenFromUserExternalConnectionCredentials;
|
|
1446
|
+
exports.calcomUserExternalConnectionCredentials = calcomUserExternalConnectionCredentials;
|
|
1447
|
+
exports.calcomUserExternalConnectionOAuthServiceConfigFactory = calcomUserExternalConnectionOAuthServiceConfigFactory;
|
|
1448
|
+
exports.userExternalConnectionCalcomAccessTokenCache = userExternalConnectionCalcomAccessTokenCache;
|
|
1449
|
+
exports.userExternalConnectionCalcomUserContextService = userExternalConnectionCalcomUserContextService;
|
|
1450
|
+
exports.userExternalConnectionCalcomUserContextServiceProvider = userExternalConnectionCalcomUserContextServiceProvider;
|
|
1451
|
+
exports.userExternalConnectionErrorCodeFromCalcomError = userExternalConnectionErrorCodeFromCalcomError;
|