@dereekb/calcom 13.4.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/LICENSE +21 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +2202 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +2141 -0
- package/nestjs/index.cjs.default.js +1 -0
- package/nestjs/index.cjs.js +1970 -0
- package/nestjs/index.cjs.mjs +2 -0
- package/nestjs/index.d.ts +1 -0
- package/nestjs/index.esm.js +1938 -0
- package/nestjs/package.json +28 -0
- package/nestjs/src/index.d.ts +1 -0
- package/nestjs/src/lib/calcom/calcom.api.d.ts +160 -0
- package/nestjs/src/lib/calcom/calcom.config.d.ts +10 -0
- package/nestjs/src/lib/calcom/calcom.module.d.ts +18 -0
- package/nestjs/src/lib/calcom/index.d.ts +3 -0
- package/nestjs/src/lib/index.d.ts +3 -0
- package/nestjs/src/lib/oauth/index.d.ts +4 -0
- package/nestjs/src/lib/oauth/oauth.api.d.ts +25 -0
- package/nestjs/src/lib/oauth/oauth.config.d.ts +22 -0
- package/nestjs/src/lib/oauth/oauth.module.d.ts +24 -0
- package/nestjs/src/lib/oauth/oauth.service.d.ts +66 -0
- package/nestjs/src/lib/webhook/index.d.ts +7 -0
- package/nestjs/src/lib/webhook/webhook.calcom.config.d.ts +11 -0
- package/nestjs/src/lib/webhook/webhook.calcom.controller.d.ts +8 -0
- package/nestjs/src/lib/webhook/webhook.calcom.d.ts +16 -0
- package/nestjs/src/lib/webhook/webhook.calcom.module.d.ts +20 -0
- package/nestjs/src/lib/webhook/webhook.calcom.service.d.ts +21 -0
- package/nestjs/src/lib/webhook/webhook.calcom.type.d.ts +33 -0
- package/nestjs/src/lib/webhook/webhook.calcom.verify.d.ts +16 -0
- package/package.json +34 -0
- package/src/index.d.ts +1 -0
- package/src/lib/calcom/calcom.api.booking.d.ts +86 -0
- package/src/lib/calcom/calcom.api.calendar.d.ts +82 -0
- package/src/lib/calcom/calcom.api.eventtype.d.ts +85 -0
- package/src/lib/calcom/calcom.api.schedule.d.ts +32 -0
- package/src/lib/calcom/calcom.api.slot.d.ts +46 -0
- package/src/lib/calcom/calcom.api.user.d.ts +29 -0
- package/src/lib/calcom/calcom.api.webhook.d.ts +97 -0
- package/src/lib/calcom/calcom.config.d.ts +66 -0
- package/src/lib/calcom/calcom.error.api.d.ts +6 -0
- package/src/lib/calcom/calcom.factory.d.ts +23 -0
- package/src/lib/calcom/index.d.ts +10 -0
- package/src/lib/calcom.config.d.ts +35 -0
- package/src/lib/calcom.error.api.d.ts +86 -0
- package/src/lib/calcom.limit.d.ts +35 -0
- package/src/lib/calcom.type.d.ts +70 -0
- package/src/lib/index.d.ts +7 -0
- package/src/lib/oauth/index.d.ts +5 -0
- package/src/lib/oauth/oauth.api.d.ts +54 -0
- package/src/lib/oauth/oauth.config.d.ts +53 -0
- package/src/lib/oauth/oauth.d.ts +64 -0
- package/src/lib/oauth/oauth.error.api.d.ts +26 -0
- package/src/lib/oauth/oauth.factory.d.ts +31 -0
- package/src/lib/shared/calcom.api-version.d.ts +17 -0
- package/src/lib/shared/index.d.ts +1 -0
package/index.esm.js
ADDED
|
@@ -0,0 +1,2141 @@
|
|
|
1
|
+
import { FetchResponseError, FetchRequestFactoryError, rateLimitedFetchHandler, fetchJsonFunction, returnNullHandleFetchJsonParseErrorFunction, fetchApiFetchService, makeUrlSearchParams } from '@dereekb/util/fetch';
|
|
2
|
+
import { MS_IN_SECOND, resetPeriodPromiseRateLimiter, MS_IN_MINUTE } from '@dereekb/util';
|
|
3
|
+
import { BaseError } from 'make-error';
|
|
4
|
+
|
|
5
|
+
function _assert_this_initialized$1(self) {
|
|
6
|
+
if (self === void 0) {
|
|
7
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
8
|
+
}
|
|
9
|
+
return self;
|
|
10
|
+
}
|
|
11
|
+
function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
|
|
12
|
+
try {
|
|
13
|
+
var info = gen[key](arg);
|
|
14
|
+
var value = info.value;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
reject(error);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (info.done) {
|
|
20
|
+
resolve(value);
|
|
21
|
+
} else {
|
|
22
|
+
Promise.resolve(value).then(_next, _throw);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _async_to_generator$5(fn) {
|
|
26
|
+
return function() {
|
|
27
|
+
var self = this, args = arguments;
|
|
28
|
+
return new Promise(function(resolve, reject) {
|
|
29
|
+
var gen = fn.apply(self, args);
|
|
30
|
+
function _next(value) {
|
|
31
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
|
|
32
|
+
}
|
|
33
|
+
function _throw(err) {
|
|
34
|
+
asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
|
|
35
|
+
}
|
|
36
|
+
_next(undefined);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function _call_super$1(_this, derived, args) {
|
|
41
|
+
derived = _get_prototype_of$1(derived);
|
|
42
|
+
return _possible_constructor_return$1(_this, _is_native_reflect_construct$1() ? Reflect.construct(derived, args || [], _get_prototype_of$1(_this).constructor) : derived.apply(_this, args));
|
|
43
|
+
}
|
|
44
|
+
function _class_call_check$1(instance, Constructor) {
|
|
45
|
+
if (!(instance instanceof Constructor)) {
|
|
46
|
+
throw new TypeError("Cannot call a class as a function");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function _defineProperties(target, props) {
|
|
50
|
+
for(var i = 0; i < props.length; i++){
|
|
51
|
+
var descriptor = props[i];
|
|
52
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
53
|
+
descriptor.configurable = true;
|
|
54
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
55
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
59
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
60
|
+
return Constructor;
|
|
61
|
+
}
|
|
62
|
+
function _define_property$2(obj, key, value) {
|
|
63
|
+
if (key in obj) {
|
|
64
|
+
Object.defineProperty(obj, key, {
|
|
65
|
+
value: value,
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
obj[key] = value;
|
|
72
|
+
}
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
function _get_prototype_of$1(o) {
|
|
76
|
+
_get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
77
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
78
|
+
};
|
|
79
|
+
return _get_prototype_of$1(o);
|
|
80
|
+
}
|
|
81
|
+
function _inherits$1(subClass, superClass) {
|
|
82
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
83
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
84
|
+
}
|
|
85
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
86
|
+
constructor: {
|
|
87
|
+
value: subClass,
|
|
88
|
+
writable: true,
|
|
89
|
+
configurable: true
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
if (superClass) _set_prototype_of$1(subClass, superClass);
|
|
93
|
+
}
|
|
94
|
+
function _instanceof(left, right) {
|
|
95
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
96
|
+
return !!right[Symbol.hasInstance](left);
|
|
97
|
+
} else {
|
|
98
|
+
return left instanceof right;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function _possible_constructor_return$1(self, call) {
|
|
102
|
+
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
103
|
+
return call;
|
|
104
|
+
}
|
|
105
|
+
return _assert_this_initialized$1(self);
|
|
106
|
+
}
|
|
107
|
+
function _set_prototype_of$1(o, p) {
|
|
108
|
+
_set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
109
|
+
o.__proto__ = p;
|
|
110
|
+
return o;
|
|
111
|
+
};
|
|
112
|
+
return _set_prototype_of$1(o, p);
|
|
113
|
+
}
|
|
114
|
+
function _type_of$1(obj) {
|
|
115
|
+
"@swc/helpers - typeof";
|
|
116
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
117
|
+
}
|
|
118
|
+
function _is_native_reflect_construct$1() {
|
|
119
|
+
try {
|
|
120
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
121
|
+
} catch (_) {}
|
|
122
|
+
return (_is_native_reflect_construct$1 = function() {
|
|
123
|
+
return !!result;
|
|
124
|
+
})();
|
|
125
|
+
}
|
|
126
|
+
function _ts_generator$5(thisArg, body) {
|
|
127
|
+
var f, y, t, _ = {
|
|
128
|
+
label: 0,
|
|
129
|
+
sent: function() {
|
|
130
|
+
if (t[0] & 1) throw t[1];
|
|
131
|
+
return t[1];
|
|
132
|
+
},
|
|
133
|
+
trys: [],
|
|
134
|
+
ops: []
|
|
135
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
136
|
+
return d(g, "next", {
|
|
137
|
+
value: verb(0)
|
|
138
|
+
}), d(g, "throw", {
|
|
139
|
+
value: verb(1)
|
|
140
|
+
}), d(g, "return", {
|
|
141
|
+
value: verb(2)
|
|
142
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
143
|
+
value: function() {
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
}), g;
|
|
147
|
+
function verb(n) {
|
|
148
|
+
return function(v) {
|
|
149
|
+
return step([
|
|
150
|
+
n,
|
|
151
|
+
v
|
|
152
|
+
]);
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function step(op) {
|
|
156
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
157
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
158
|
+
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;
|
|
159
|
+
if (y = 0, t) op = [
|
|
160
|
+
op[0] & 2,
|
|
161
|
+
t.value
|
|
162
|
+
];
|
|
163
|
+
switch(op[0]){
|
|
164
|
+
case 0:
|
|
165
|
+
case 1:
|
|
166
|
+
t = op;
|
|
167
|
+
break;
|
|
168
|
+
case 4:
|
|
169
|
+
_.label++;
|
|
170
|
+
return {
|
|
171
|
+
value: op[1],
|
|
172
|
+
done: false
|
|
173
|
+
};
|
|
174
|
+
case 5:
|
|
175
|
+
_.label++;
|
|
176
|
+
y = op[1];
|
|
177
|
+
op = [
|
|
178
|
+
0
|
|
179
|
+
];
|
|
180
|
+
continue;
|
|
181
|
+
case 7:
|
|
182
|
+
op = _.ops.pop();
|
|
183
|
+
_.trys.pop();
|
|
184
|
+
continue;
|
|
185
|
+
default:
|
|
186
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
187
|
+
_ = 0;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
191
|
+
_.label = op[1];
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
195
|
+
_.label = t[1];
|
|
196
|
+
t = op;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
if (t && _.label < t[2]) {
|
|
200
|
+
_.label = t[2];
|
|
201
|
+
_.ops.push(op);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
if (t[2]) _.ops.pop();
|
|
205
|
+
_.trys.pop();
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
op = body.call(thisArg, _);
|
|
209
|
+
} catch (e) {
|
|
210
|
+
op = [
|
|
211
|
+
6,
|
|
212
|
+
e
|
|
213
|
+
];
|
|
214
|
+
y = 0;
|
|
215
|
+
} finally{
|
|
216
|
+
f = t = 0;
|
|
217
|
+
}
|
|
218
|
+
if (op[0] & 5) throw op[1];
|
|
219
|
+
return {
|
|
220
|
+
value: op[0] ? op[1] : void 0,
|
|
221
|
+
done: true
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Cal.com Server Error
|
|
227
|
+
*/ var CalcomServerError = /*#__PURE__*/ function(BaseError) {
|
|
228
|
+
_inherits$1(CalcomServerError, BaseError);
|
|
229
|
+
function CalcomServerError(error) {
|
|
230
|
+
_class_call_check$1(this, CalcomServerError);
|
|
231
|
+
var _this;
|
|
232
|
+
_this = _call_super$1(this, CalcomServerError, [
|
|
233
|
+
error.message
|
|
234
|
+
]), _define_property$2(_this, "error", void 0);
|
|
235
|
+
_this.error = error;
|
|
236
|
+
return _this;
|
|
237
|
+
}
|
|
238
|
+
_create_class(CalcomServerError, [
|
|
239
|
+
{
|
|
240
|
+
key: "code",
|
|
241
|
+
get: function get() {
|
|
242
|
+
return this.error.code;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
]);
|
|
246
|
+
return CalcomServerError;
|
|
247
|
+
}(BaseError);
|
|
248
|
+
/**
|
|
249
|
+
* Cal.com Server Error that includes the FetchResponseError
|
|
250
|
+
*/ var CalcomServerFetchResponseError = /*#__PURE__*/ function(CalcomServerError) {
|
|
251
|
+
_inherits$1(CalcomServerFetchResponseError, CalcomServerError);
|
|
252
|
+
function CalcomServerFetchResponseError(data, responseError) {
|
|
253
|
+
_class_call_check$1(this, CalcomServerFetchResponseError);
|
|
254
|
+
var _this;
|
|
255
|
+
_this = _call_super$1(this, CalcomServerFetchResponseError, [
|
|
256
|
+
data
|
|
257
|
+
]), _define_property$2(_this, "data", void 0), _define_property$2(_this, "responseError", void 0);
|
|
258
|
+
_this.data = data;
|
|
259
|
+
_this.responseError = responseError;
|
|
260
|
+
return _this;
|
|
261
|
+
}
|
|
262
|
+
return CalcomServerFetchResponseError;
|
|
263
|
+
}(CalcomServerError);
|
|
264
|
+
/**
|
|
265
|
+
* Creates a logCalcomServerErrorFunction that logs the error to console.
|
|
266
|
+
*
|
|
267
|
+
* @param calcomApiNamePrefix Prefix to use when logging. I.E. CalcomError, etc.
|
|
268
|
+
* @returns
|
|
269
|
+
*/ function logCalcomServerErrorFunction(calcomApiNamePrefix) {
|
|
270
|
+
return function(error) {
|
|
271
|
+
if (_instanceof(error, CalcomServerFetchResponseError)) {
|
|
272
|
+
console.log("".concat(calcomApiNamePrefix, "Error(").concat(error.responseError.response.status, "): "), {
|
|
273
|
+
error: error,
|
|
274
|
+
errorData: error.data
|
|
275
|
+
});
|
|
276
|
+
} else if (_instanceof(error, CalcomServerError)) {
|
|
277
|
+
console.log("".concat(calcomApiNamePrefix, "Error(code:").concat(error.code, "): "), {
|
|
278
|
+
error: error
|
|
279
|
+
});
|
|
280
|
+
} else {
|
|
281
|
+
console.log("".concat(calcomApiNamePrefix, "Error(name:").concat(error.name, "): "), {
|
|
282
|
+
error: error
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Wraps a ConfiguredFetch to support handling errors returned by fetch.
|
|
289
|
+
*/ function handleCalcomErrorFetchFactory(parseCalcomError, defaultLogError) {
|
|
290
|
+
return function(fetch) {
|
|
291
|
+
var logError = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : defaultLogError;
|
|
292
|
+
return function(x, y) {
|
|
293
|
+
return _async_to_generator$5(function() {
|
|
294
|
+
var e, error;
|
|
295
|
+
return _ts_generator$5(this, function(_state) {
|
|
296
|
+
switch(_state.label){
|
|
297
|
+
case 0:
|
|
298
|
+
_state.trys.push([
|
|
299
|
+
0,
|
|
300
|
+
2,
|
|
301
|
+
,
|
|
302
|
+
5
|
|
303
|
+
]);
|
|
304
|
+
return [
|
|
305
|
+
4,
|
|
306
|
+
fetch(x, y)
|
|
307
|
+
];
|
|
308
|
+
case 1:
|
|
309
|
+
return [
|
|
310
|
+
2,
|
|
311
|
+
_state.sent()
|
|
312
|
+
]; // await to catch thrown errors
|
|
313
|
+
case 2:
|
|
314
|
+
e = _state.sent();
|
|
315
|
+
if (!_instanceof(e, FetchResponseError)) return [
|
|
316
|
+
3,
|
|
317
|
+
4
|
|
318
|
+
];
|
|
319
|
+
return [
|
|
320
|
+
4,
|
|
321
|
+
parseCalcomError(e)
|
|
322
|
+
];
|
|
323
|
+
case 3:
|
|
324
|
+
error = _state.sent();
|
|
325
|
+
if (error) {
|
|
326
|
+
logError(error); // log before throwing.
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
_state.label = 4;
|
|
330
|
+
case 4:
|
|
331
|
+
throw e;
|
|
332
|
+
case 5:
|
|
333
|
+
return [
|
|
334
|
+
2
|
|
335
|
+
];
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
})();
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
// MARK: Parsed Errors
|
|
343
|
+
/**
|
|
344
|
+
* The status code that indicates too many requests have been made.
|
|
345
|
+
*/ var CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE = 429;
|
|
346
|
+
var CALCOM_RATE_LIMIT_LIMIT_HEADER = 'X-RateLimit-Limit';
|
|
347
|
+
var CALCOM_RATE_LIMIT_REMAINING_HEADER = 'X-RateLimit-Remaining';
|
|
348
|
+
var CALCOM_RATE_LIMIT_RESET_HEADER = 'X-RateLimit-Reset';
|
|
349
|
+
var DEFAULT_CALCOM_API_RATE_LIMIT = 100;
|
|
350
|
+
var DEFAULT_CALCOM_API_RATE_LIMIT_RESET_PERIOD = 60 * MS_IN_SECOND;
|
|
351
|
+
function calcomRateLimitHeaderDetails(headers) {
|
|
352
|
+
var limitHeader = headers.get(CALCOM_RATE_LIMIT_LIMIT_HEADER);
|
|
353
|
+
var remainingHeader = headers.get(CALCOM_RATE_LIMIT_REMAINING_HEADER);
|
|
354
|
+
var resetHeader = headers.get(CALCOM_RATE_LIMIT_RESET_HEADER);
|
|
355
|
+
var result = null;
|
|
356
|
+
if (limitHeader != null || remainingHeader != null || resetHeader != null) {
|
|
357
|
+
var limit = limitHeader ? Number(limitHeader) : undefined;
|
|
358
|
+
var remaining = remainingHeader ? Number(remainingHeader) : undefined;
|
|
359
|
+
var resetAt = resetHeader ? new Date(Number(resetHeader) * MS_IN_SECOND) : undefined;
|
|
360
|
+
result = {
|
|
361
|
+
limit: limit,
|
|
362
|
+
remaining: remaining,
|
|
363
|
+
resetAt: resetAt
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
var CalcomTooManyRequestsError = /*#__PURE__*/ function(CalcomServerFetchResponseError) {
|
|
369
|
+
_inherits$1(CalcomTooManyRequestsError, CalcomServerFetchResponseError);
|
|
370
|
+
function CalcomTooManyRequestsError() {
|
|
371
|
+
_class_call_check$1(this, CalcomTooManyRequestsError);
|
|
372
|
+
return _call_super$1(this, CalcomTooManyRequestsError, arguments);
|
|
373
|
+
}
|
|
374
|
+
_create_class(CalcomTooManyRequestsError, [
|
|
375
|
+
{
|
|
376
|
+
key: "headerDetails",
|
|
377
|
+
get: function get() {
|
|
378
|
+
return calcomRateLimitHeaderDetails(this.responseError.response.headers);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
]);
|
|
382
|
+
return CalcomTooManyRequestsError;
|
|
383
|
+
}(CalcomServerFetchResponseError);
|
|
384
|
+
/**
|
|
385
|
+
* Function that parses/transforms a CalcomServerErrorData into a general CalcomServerError or other known error type.
|
|
386
|
+
*/ function parseCalcomServerErrorData(calcomServerError, responseError) {
|
|
387
|
+
var result;
|
|
388
|
+
if (responseError.response.status === CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
|
|
389
|
+
result = new CalcomTooManyRequestsError(calcomServerError, responseError);
|
|
390
|
+
console.warn('CalcomTooManyRequestsError', {
|
|
391
|
+
result: result,
|
|
392
|
+
responseError: responseError,
|
|
393
|
+
headerDetails: result.headerDetails
|
|
394
|
+
});
|
|
395
|
+
} else if (calcomServerError) {
|
|
396
|
+
switch(calcomServerError.code){
|
|
397
|
+
default:
|
|
398
|
+
result = new CalcomServerFetchResponseError(calcomServerError, responseError);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
406
|
+
try {
|
|
407
|
+
var info = gen[key](arg);
|
|
408
|
+
var value = info.value;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
reject(error);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (info.done) {
|
|
414
|
+
resolve(value);
|
|
415
|
+
} else {
|
|
416
|
+
Promise.resolve(value).then(_next, _throw);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function _async_to_generator$4(fn) {
|
|
420
|
+
return function() {
|
|
421
|
+
var self = this, args = arguments;
|
|
422
|
+
return new Promise(function(resolve, reject) {
|
|
423
|
+
var gen = fn.apply(self, args);
|
|
424
|
+
function _next(value) {
|
|
425
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
426
|
+
}
|
|
427
|
+
function _throw(err) {
|
|
428
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
429
|
+
}
|
|
430
|
+
_next(undefined);
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
function _ts_generator$4(thisArg, body) {
|
|
435
|
+
var f, y, t, _ = {
|
|
436
|
+
label: 0,
|
|
437
|
+
sent: function() {
|
|
438
|
+
if (t[0] & 1) throw t[1];
|
|
439
|
+
return t[1];
|
|
440
|
+
},
|
|
441
|
+
trys: [],
|
|
442
|
+
ops: []
|
|
443
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
444
|
+
return d(g, "next", {
|
|
445
|
+
value: verb(0)
|
|
446
|
+
}), d(g, "throw", {
|
|
447
|
+
value: verb(1)
|
|
448
|
+
}), d(g, "return", {
|
|
449
|
+
value: verb(2)
|
|
450
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
451
|
+
value: function() {
|
|
452
|
+
return this;
|
|
453
|
+
}
|
|
454
|
+
}), g;
|
|
455
|
+
function verb(n) {
|
|
456
|
+
return function(v) {
|
|
457
|
+
return step([
|
|
458
|
+
n,
|
|
459
|
+
v
|
|
460
|
+
]);
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function step(op) {
|
|
464
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
465
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
466
|
+
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;
|
|
467
|
+
if (y = 0, t) op = [
|
|
468
|
+
op[0] & 2,
|
|
469
|
+
t.value
|
|
470
|
+
];
|
|
471
|
+
switch(op[0]){
|
|
472
|
+
case 0:
|
|
473
|
+
case 1:
|
|
474
|
+
t = op;
|
|
475
|
+
break;
|
|
476
|
+
case 4:
|
|
477
|
+
_.label++;
|
|
478
|
+
return {
|
|
479
|
+
value: op[1],
|
|
480
|
+
done: false
|
|
481
|
+
};
|
|
482
|
+
case 5:
|
|
483
|
+
_.label++;
|
|
484
|
+
y = op[1];
|
|
485
|
+
op = [
|
|
486
|
+
0
|
|
487
|
+
];
|
|
488
|
+
continue;
|
|
489
|
+
case 7:
|
|
490
|
+
op = _.ops.pop();
|
|
491
|
+
_.trys.pop();
|
|
492
|
+
continue;
|
|
493
|
+
default:
|
|
494
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
495
|
+
_ = 0;
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
499
|
+
_.label = op[1];
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
503
|
+
_.label = t[1];
|
|
504
|
+
t = op;
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
if (t && _.label < t[2]) {
|
|
508
|
+
_.label = t[2];
|
|
509
|
+
_.ops.push(op);
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
if (t[2]) _.ops.pop();
|
|
513
|
+
_.trys.pop();
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
op = body.call(thisArg, _);
|
|
517
|
+
} catch (e) {
|
|
518
|
+
op = [
|
|
519
|
+
6,
|
|
520
|
+
e
|
|
521
|
+
];
|
|
522
|
+
y = 0;
|
|
523
|
+
} finally{
|
|
524
|
+
f = t = 0;
|
|
525
|
+
}
|
|
526
|
+
if (op[0] & 5) throw op[1];
|
|
527
|
+
return {
|
|
528
|
+
value: op[0] ? op[1] : void 0,
|
|
529
|
+
done: true
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
// MARK: Parser
|
|
534
|
+
var logCalcomErrorToConsole = logCalcomServerErrorFunction('Calcom');
|
|
535
|
+
function parseCalcomApiError(responseError) {
|
|
536
|
+
return _async_to_generator$4(function() {
|
|
537
|
+
var data, result;
|
|
538
|
+
return _ts_generator$4(this, function(_state) {
|
|
539
|
+
switch(_state.label){
|
|
540
|
+
case 0:
|
|
541
|
+
return [
|
|
542
|
+
4,
|
|
543
|
+
responseError.response.json().catch(function(_x) {
|
|
544
|
+
return undefined;
|
|
545
|
+
})
|
|
546
|
+
];
|
|
547
|
+
case 1:
|
|
548
|
+
data = _state.sent();
|
|
549
|
+
if (data) {
|
|
550
|
+
result = parseCalcomApiServerErrorResponseData(data, responseError);
|
|
551
|
+
}
|
|
552
|
+
return [
|
|
553
|
+
2,
|
|
554
|
+
result
|
|
555
|
+
];
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
})();
|
|
559
|
+
}
|
|
560
|
+
function parseCalcomApiServerErrorResponseData(calcomServerError, responseError) {
|
|
561
|
+
var result;
|
|
562
|
+
if (calcomServerError) {
|
|
563
|
+
switch(calcomServerError.code){
|
|
564
|
+
default:
|
|
565
|
+
result = parseCalcomServerErrorData(calcomServerError, responseError);
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return result;
|
|
570
|
+
}
|
|
571
|
+
var handleCalcomErrorFetch = handleCalcomErrorFetchFactory(parseCalcomApiError, logCalcomErrorToConsole);
|
|
572
|
+
|
|
573
|
+
function _assert_this_initialized(self) {
|
|
574
|
+
if (self === void 0) {
|
|
575
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
576
|
+
}
|
|
577
|
+
return self;
|
|
578
|
+
}
|
|
579
|
+
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
580
|
+
try {
|
|
581
|
+
var info = gen[key](arg);
|
|
582
|
+
var value = info.value;
|
|
583
|
+
} catch (error) {
|
|
584
|
+
reject(error);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (info.done) {
|
|
588
|
+
resolve(value);
|
|
589
|
+
} else {
|
|
590
|
+
Promise.resolve(value).then(_next, _throw);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function _async_to_generator$3(fn) {
|
|
594
|
+
return function() {
|
|
595
|
+
var self = this, args = arguments;
|
|
596
|
+
return new Promise(function(resolve, reject) {
|
|
597
|
+
var gen = fn.apply(self, args);
|
|
598
|
+
function _next(value) {
|
|
599
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
600
|
+
}
|
|
601
|
+
function _throw(err) {
|
|
602
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
603
|
+
}
|
|
604
|
+
_next(undefined);
|
|
605
|
+
});
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function _call_super(_this, derived, args) {
|
|
609
|
+
derived = _get_prototype_of(derived);
|
|
610
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
611
|
+
}
|
|
612
|
+
function _class_call_check(instance, Constructor) {
|
|
613
|
+
if (!(instance instanceof Constructor)) {
|
|
614
|
+
throw new TypeError("Cannot call a class as a function");
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function _define_property$1(obj, key, value) {
|
|
618
|
+
if (key in obj) {
|
|
619
|
+
Object.defineProperty(obj, key, {
|
|
620
|
+
value: value,
|
|
621
|
+
enumerable: true,
|
|
622
|
+
configurable: true,
|
|
623
|
+
writable: true
|
|
624
|
+
});
|
|
625
|
+
} else {
|
|
626
|
+
obj[key] = value;
|
|
627
|
+
}
|
|
628
|
+
return obj;
|
|
629
|
+
}
|
|
630
|
+
function _get_prototype_of(o) {
|
|
631
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
632
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
633
|
+
};
|
|
634
|
+
return _get_prototype_of(o);
|
|
635
|
+
}
|
|
636
|
+
function _inherits(subClass, superClass) {
|
|
637
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
638
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
639
|
+
}
|
|
640
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
641
|
+
constructor: {
|
|
642
|
+
value: subClass,
|
|
643
|
+
writable: true,
|
|
644
|
+
configurable: true
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
648
|
+
}
|
|
649
|
+
function _possible_constructor_return(self, call) {
|
|
650
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
651
|
+
return call;
|
|
652
|
+
}
|
|
653
|
+
return _assert_this_initialized(self);
|
|
654
|
+
}
|
|
655
|
+
function _set_prototype_of(o, p) {
|
|
656
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
657
|
+
o.__proto__ = p;
|
|
658
|
+
return o;
|
|
659
|
+
};
|
|
660
|
+
return _set_prototype_of(o, p);
|
|
661
|
+
}
|
|
662
|
+
function _type_of(obj) {
|
|
663
|
+
"@swc/helpers - typeof";
|
|
664
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
665
|
+
}
|
|
666
|
+
function _is_native_reflect_construct() {
|
|
667
|
+
try {
|
|
668
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
669
|
+
} catch (_) {}
|
|
670
|
+
return (_is_native_reflect_construct = function() {
|
|
671
|
+
return !!result;
|
|
672
|
+
})();
|
|
673
|
+
}
|
|
674
|
+
function _ts_generator$3(thisArg, body) {
|
|
675
|
+
var f, y, t, _ = {
|
|
676
|
+
label: 0,
|
|
677
|
+
sent: function() {
|
|
678
|
+
if (t[0] & 1) throw t[1];
|
|
679
|
+
return t[1];
|
|
680
|
+
},
|
|
681
|
+
trys: [],
|
|
682
|
+
ops: []
|
|
683
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
684
|
+
return d(g, "next", {
|
|
685
|
+
value: verb(0)
|
|
686
|
+
}), d(g, "throw", {
|
|
687
|
+
value: verb(1)
|
|
688
|
+
}), d(g, "return", {
|
|
689
|
+
value: verb(2)
|
|
690
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
691
|
+
value: function() {
|
|
692
|
+
return this;
|
|
693
|
+
}
|
|
694
|
+
}), g;
|
|
695
|
+
function verb(n) {
|
|
696
|
+
return function(v) {
|
|
697
|
+
return step([
|
|
698
|
+
n,
|
|
699
|
+
v
|
|
700
|
+
]);
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
function step(op) {
|
|
704
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
705
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
706
|
+
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;
|
|
707
|
+
if (y = 0, t) op = [
|
|
708
|
+
op[0] & 2,
|
|
709
|
+
t.value
|
|
710
|
+
];
|
|
711
|
+
switch(op[0]){
|
|
712
|
+
case 0:
|
|
713
|
+
case 1:
|
|
714
|
+
t = op;
|
|
715
|
+
break;
|
|
716
|
+
case 4:
|
|
717
|
+
_.label++;
|
|
718
|
+
return {
|
|
719
|
+
value: op[1],
|
|
720
|
+
done: false
|
|
721
|
+
};
|
|
722
|
+
case 5:
|
|
723
|
+
_.label++;
|
|
724
|
+
y = op[1];
|
|
725
|
+
op = [
|
|
726
|
+
0
|
|
727
|
+
];
|
|
728
|
+
continue;
|
|
729
|
+
case 7:
|
|
730
|
+
op = _.ops.pop();
|
|
731
|
+
_.trys.pop();
|
|
732
|
+
continue;
|
|
733
|
+
default:
|
|
734
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
735
|
+
_ = 0;
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
739
|
+
_.label = op[1];
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
743
|
+
_.label = t[1];
|
|
744
|
+
t = op;
|
|
745
|
+
break;
|
|
746
|
+
}
|
|
747
|
+
if (t && _.label < t[2]) {
|
|
748
|
+
_.label = t[2];
|
|
749
|
+
_.ops.push(op);
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
if (t[2]) _.ops.pop();
|
|
753
|
+
_.trys.pop();
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
op = body.call(thisArg, _);
|
|
757
|
+
} catch (e) {
|
|
758
|
+
op = [
|
|
759
|
+
6,
|
|
760
|
+
e
|
|
761
|
+
];
|
|
762
|
+
y = 0;
|
|
763
|
+
} finally{
|
|
764
|
+
f = t = 0;
|
|
765
|
+
}
|
|
766
|
+
if (op[0] & 5) throw op[1];
|
|
767
|
+
return {
|
|
768
|
+
value: op[0] ? op[1] : void 0,
|
|
769
|
+
done: true
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Error in the following cases:
|
|
775
|
+
* - the refresh token string is invalid
|
|
776
|
+
*/ var CALCOM_OAUTH_INVALID_GRANT_ERROR_CODE = 'invalid_grant';
|
|
777
|
+
/**
|
|
778
|
+
* Thrown if the call to the Cal.com API creating an access token using a refresh token fails.
|
|
779
|
+
*/ var CalcomOAuthAccessTokenError = /*#__PURE__*/ function(FetchRequestFactoryError) {
|
|
780
|
+
_inherits(CalcomOAuthAccessTokenError, FetchRequestFactoryError);
|
|
781
|
+
function CalcomOAuthAccessTokenError(errorCode) {
|
|
782
|
+
_class_call_check(this, CalcomOAuthAccessTokenError);
|
|
783
|
+
var _this;
|
|
784
|
+
_this = _call_super(this, CalcomOAuthAccessTokenError, [
|
|
785
|
+
"CalcomOAuthAccessTokenError: ".concat(errorCode)
|
|
786
|
+
]), _define_property$1(_this, "errorCode", void 0);
|
|
787
|
+
_this.errorCode = errorCode;
|
|
788
|
+
return _this;
|
|
789
|
+
}
|
|
790
|
+
return CalcomOAuthAccessTokenError;
|
|
791
|
+
}(FetchRequestFactoryError);
|
|
792
|
+
/**
|
|
793
|
+
* Thrown if a valid CalcomAccessToken cannot be retrieved successfully.
|
|
794
|
+
*/ var CalcomOAuthAuthFailureError = /*#__PURE__*/ function(FetchRequestFactoryError) {
|
|
795
|
+
_inherits(CalcomOAuthAuthFailureError, FetchRequestFactoryError);
|
|
796
|
+
function CalcomOAuthAuthFailureError(reason) {
|
|
797
|
+
_class_call_check(this, CalcomOAuthAuthFailureError);
|
|
798
|
+
var _this;
|
|
799
|
+
_this = _call_super(this, CalcomOAuthAuthFailureError, [
|
|
800
|
+
"Failed to retrieve proper authentication for the API call. Reason: ".concat(reason)
|
|
801
|
+
]), _define_property$1(_this, "reason", void 0);
|
|
802
|
+
_this.reason = reason;
|
|
803
|
+
return _this;
|
|
804
|
+
}
|
|
805
|
+
return CalcomOAuthAuthFailureError;
|
|
806
|
+
}(FetchRequestFactoryError);
|
|
807
|
+
var logCalcomOAuthErrorToConsole = logCalcomServerErrorFunction('CalcomOAuth');
|
|
808
|
+
function parseCalcomOAuthError(responseError) {
|
|
809
|
+
return _async_to_generator$3(function() {
|
|
810
|
+
var data, result;
|
|
811
|
+
return _ts_generator$3(this, function(_state) {
|
|
812
|
+
switch(_state.label){
|
|
813
|
+
case 0:
|
|
814
|
+
return [
|
|
815
|
+
4,
|
|
816
|
+
responseError.response.json().catch(function(_x) {
|
|
817
|
+
return undefined;
|
|
818
|
+
})
|
|
819
|
+
];
|
|
820
|
+
case 1:
|
|
821
|
+
data = _state.sent();
|
|
822
|
+
if (data) {
|
|
823
|
+
result = parseCalcomOAuthServerErrorResponseData(data, responseError);
|
|
824
|
+
}
|
|
825
|
+
return [
|
|
826
|
+
2,
|
|
827
|
+
result
|
|
828
|
+
];
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
})();
|
|
832
|
+
}
|
|
833
|
+
function parseCalcomOAuthServerErrorResponseData(calcomServerError, responseError) {
|
|
834
|
+
var result;
|
|
835
|
+
if (calcomServerError) {
|
|
836
|
+
var potentialErrorStringCode = calcomServerError.error;
|
|
837
|
+
var errorCode = potentialErrorStringCode !== null && potentialErrorStringCode !== void 0 ? potentialErrorStringCode : calcomServerError.code;
|
|
838
|
+
switch(errorCode){
|
|
839
|
+
case CALCOM_OAUTH_INVALID_GRANT_ERROR_CODE:
|
|
840
|
+
result = new CalcomOAuthAccessTokenError(errorCode);
|
|
841
|
+
break;
|
|
842
|
+
default:
|
|
843
|
+
result = parseCalcomServerErrorData(calcomServerError, responseError);
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return result;
|
|
848
|
+
}
|
|
849
|
+
var handleCalcomOAuthErrorFetch = handleCalcomErrorFetchFactory(parseCalcomOAuthError, logCalcomOAuthErrorToConsole);
|
|
850
|
+
|
|
851
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
852
|
+
try {
|
|
853
|
+
var info = gen[key](arg);
|
|
854
|
+
var value = info.value;
|
|
855
|
+
} catch (error) {
|
|
856
|
+
reject(error);
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
if (info.done) {
|
|
860
|
+
resolve(value);
|
|
861
|
+
} else {
|
|
862
|
+
Promise.resolve(value).then(_next, _throw);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function _async_to_generator$2(fn) {
|
|
866
|
+
return function() {
|
|
867
|
+
var self = this, args = arguments;
|
|
868
|
+
return new Promise(function(resolve, reject) {
|
|
869
|
+
var gen = fn.apply(self, args);
|
|
870
|
+
function _next(value) {
|
|
871
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
872
|
+
}
|
|
873
|
+
function _throw(err) {
|
|
874
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
875
|
+
}
|
|
876
|
+
_next(undefined);
|
|
877
|
+
});
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
function _ts_generator$2(thisArg, body) {
|
|
881
|
+
var f, y, t, _ = {
|
|
882
|
+
label: 0,
|
|
883
|
+
sent: function() {
|
|
884
|
+
if (t[0] & 1) throw t[1];
|
|
885
|
+
return t[1];
|
|
886
|
+
},
|
|
887
|
+
trys: [],
|
|
888
|
+
ops: []
|
|
889
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
890
|
+
return d(g, "next", {
|
|
891
|
+
value: verb(0)
|
|
892
|
+
}), d(g, "throw", {
|
|
893
|
+
value: verb(1)
|
|
894
|
+
}), d(g, "return", {
|
|
895
|
+
value: verb(2)
|
|
896
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
897
|
+
value: function() {
|
|
898
|
+
return this;
|
|
899
|
+
}
|
|
900
|
+
}), g;
|
|
901
|
+
function verb(n) {
|
|
902
|
+
return function(v) {
|
|
903
|
+
return step([
|
|
904
|
+
n,
|
|
905
|
+
v
|
|
906
|
+
]);
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
function step(op) {
|
|
910
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
911
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
912
|
+
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;
|
|
913
|
+
if (y = 0, t) op = [
|
|
914
|
+
op[0] & 2,
|
|
915
|
+
t.value
|
|
916
|
+
];
|
|
917
|
+
switch(op[0]){
|
|
918
|
+
case 0:
|
|
919
|
+
case 1:
|
|
920
|
+
t = op;
|
|
921
|
+
break;
|
|
922
|
+
case 4:
|
|
923
|
+
_.label++;
|
|
924
|
+
return {
|
|
925
|
+
value: op[1],
|
|
926
|
+
done: false
|
|
927
|
+
};
|
|
928
|
+
case 5:
|
|
929
|
+
_.label++;
|
|
930
|
+
y = op[1];
|
|
931
|
+
op = [
|
|
932
|
+
0
|
|
933
|
+
];
|
|
934
|
+
continue;
|
|
935
|
+
case 7:
|
|
936
|
+
op = _.ops.pop();
|
|
937
|
+
_.trys.pop();
|
|
938
|
+
continue;
|
|
939
|
+
default:
|
|
940
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
941
|
+
_ = 0;
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
945
|
+
_.label = op[1];
|
|
946
|
+
break;
|
|
947
|
+
}
|
|
948
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
949
|
+
_.label = t[1];
|
|
950
|
+
t = op;
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
if (t && _.label < t[2]) {
|
|
954
|
+
_.label = t[2];
|
|
955
|
+
_.ops.push(op);
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
if (t[2]) _.ops.pop();
|
|
959
|
+
_.trys.pop();
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
op = body.call(thisArg, _);
|
|
963
|
+
} catch (e) {
|
|
964
|
+
op = [
|
|
965
|
+
6,
|
|
966
|
+
e
|
|
967
|
+
];
|
|
968
|
+
y = 0;
|
|
969
|
+
} finally{
|
|
970
|
+
f = t = 0;
|
|
971
|
+
}
|
|
972
|
+
if (op[0] & 5) throw op[1];
|
|
973
|
+
return {
|
|
974
|
+
value: op[0] ? op[1] : void 0,
|
|
975
|
+
done: true
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Generates a new CalcomAccessTokenStringFactory.
|
|
981
|
+
*/ function calcomAccessTokenStringFactory(calcomAccessTokenFactory) {
|
|
982
|
+
return function() {
|
|
983
|
+
return _async_to_generator$2(function() {
|
|
984
|
+
var token;
|
|
985
|
+
return _ts_generator$2(this, function(_state) {
|
|
986
|
+
switch(_state.label){
|
|
987
|
+
case 0:
|
|
988
|
+
return [
|
|
989
|
+
4,
|
|
990
|
+
calcomAccessTokenFactory()
|
|
991
|
+
];
|
|
992
|
+
case 1:
|
|
993
|
+
token = _state.sent();
|
|
994
|
+
if (!(token === null || token === void 0 ? void 0 : token.accessToken)) {
|
|
995
|
+
throw new CalcomOAuthAuthFailureError();
|
|
996
|
+
}
|
|
997
|
+
return [
|
|
998
|
+
2,
|
|
999
|
+
token.accessToken
|
|
1000
|
+
];
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
})();
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
var DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION = function DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION(headers) {
|
|
1008
|
+
console.warn("calcomRateLimitedFetchHandler(): Too many requests made. The limit is ".concat(headers.limit, " requests per reset period. ResetAt is set for ").concat(headers.resetAt, "."));
|
|
1009
|
+
};
|
|
1010
|
+
function calcomRateLimitedFetchHandler(config) {
|
|
1011
|
+
var _ref, _ref1, _ref2;
|
|
1012
|
+
var onTooManyRequests = (config === null || config === void 0 ? void 0 : config.onTooManyRequests) !== false ? (_ref = config === null || config === void 0 ? void 0 : config.onTooManyRequests) !== null && _ref !== void 0 ? _ref : DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION : undefined;
|
|
1013
|
+
var defaultLimit = (_ref1 = config === null || config === void 0 ? void 0 : config.maxRateLimit) !== null && _ref1 !== void 0 ? _ref1 : DEFAULT_CALCOM_API_RATE_LIMIT;
|
|
1014
|
+
var defaultResetPeriod = (_ref2 = config === null || config === void 0 ? void 0 : config.resetPeriod) !== null && _ref2 !== void 0 ? _ref2 : DEFAULT_CALCOM_API_RATE_LIMIT_RESET_PERIOD;
|
|
1015
|
+
function configForLimit(limit, resetAt) {
|
|
1016
|
+
return {
|
|
1017
|
+
limit: defaultLimit,
|
|
1018
|
+
startLimitAt: 10,
|
|
1019
|
+
cooldownRate: 1.2,
|
|
1020
|
+
exponentRate: 1.08,
|
|
1021
|
+
maxWaitTime: MS_IN_SECOND * 10,
|
|
1022
|
+
resetPeriod: defaultResetPeriod,
|
|
1023
|
+
resetAt: resetAt
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
var defaultConfig = configForLimit();
|
|
1027
|
+
var rateLimiter = resetPeriodPromiseRateLimiter(defaultConfig);
|
|
1028
|
+
return rateLimitedFetchHandler({
|
|
1029
|
+
rateLimiter: rateLimiter,
|
|
1030
|
+
updateWithResponse: function updateWithResponse(response, fetchResponseError) {
|
|
1031
|
+
var hasRemainingHeader = response.headers.has(CALCOM_RATE_LIMIT_REMAINING_HEADER);
|
|
1032
|
+
var shouldRetry = false;
|
|
1033
|
+
if (hasRemainingHeader) {
|
|
1034
|
+
var headerDetails = calcomRateLimitHeaderDetails(response.headers);
|
|
1035
|
+
if (headerDetails) {
|
|
1036
|
+
var limit = headerDetails.limit, remaining = headerDetails.remaining, resetAt = headerDetails.resetAt;
|
|
1037
|
+
if (response.status === CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
|
|
1038
|
+
shouldRetry = true;
|
|
1039
|
+
try {
|
|
1040
|
+
onTooManyRequests === null || onTooManyRequests === void 0 ? void 0 : onTooManyRequests(headerDetails, response, fetchResponseError);
|
|
1041
|
+
} catch (_) {
|
|
1042
|
+
// ignore logging errors
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (limit != null && resetAt != null && remaining != null) {
|
|
1046
|
+
if (limit !== defaultLimit) {
|
|
1047
|
+
var newConfig = configForLimit(limit, resetAt);
|
|
1048
|
+
rateLimiter.setConfig(newConfig, false);
|
|
1049
|
+
}
|
|
1050
|
+
rateLimiter.setRemainingLimit(remaining);
|
|
1051
|
+
rateLimiter.setNextResetAt(resetAt);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
} else if (response.status === CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
|
|
1055
|
+
shouldRetry = true;
|
|
1056
|
+
try {
|
|
1057
|
+
var headerDetails1 = {};
|
|
1058
|
+
onTooManyRequests === null || onTooManyRequests === void 0 ? void 0 : onTooManyRequests(headerDetails1, response, fetchResponseError);
|
|
1059
|
+
} catch (_) {
|
|
1060
|
+
// ignore logging errors
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return shouldRetry;
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* The Cal.com API URL.
|
|
1070
|
+
*/ var CALCOM_API_URL = 'https://api.cal.com/v2';
|
|
1071
|
+
|
|
1072
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1073
|
+
try {
|
|
1074
|
+
var info = gen[key](arg);
|
|
1075
|
+
var value = info.value;
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
reject(error);
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
if (info.done) {
|
|
1081
|
+
resolve(value);
|
|
1082
|
+
} else {
|
|
1083
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
function _async_to_generator$1(fn) {
|
|
1087
|
+
return function() {
|
|
1088
|
+
var self = this, args = arguments;
|
|
1089
|
+
return new Promise(function(resolve, reject) {
|
|
1090
|
+
var gen = fn.apply(self, args);
|
|
1091
|
+
function _next(value) {
|
|
1092
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
1093
|
+
}
|
|
1094
|
+
function _throw(err) {
|
|
1095
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1096
|
+
}
|
|
1097
|
+
_next(undefined);
|
|
1098
|
+
});
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
function _ts_generator$1(thisArg, body) {
|
|
1102
|
+
var f, y, t, _ = {
|
|
1103
|
+
label: 0,
|
|
1104
|
+
sent: function() {
|
|
1105
|
+
if (t[0] & 1) throw t[1];
|
|
1106
|
+
return t[1];
|
|
1107
|
+
},
|
|
1108
|
+
trys: [],
|
|
1109
|
+
ops: []
|
|
1110
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1111
|
+
return d(g, "next", {
|
|
1112
|
+
value: verb(0)
|
|
1113
|
+
}), d(g, "throw", {
|
|
1114
|
+
value: verb(1)
|
|
1115
|
+
}), d(g, "return", {
|
|
1116
|
+
value: verb(2)
|
|
1117
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1118
|
+
value: function() {
|
|
1119
|
+
return this;
|
|
1120
|
+
}
|
|
1121
|
+
}), g;
|
|
1122
|
+
function verb(n) {
|
|
1123
|
+
return function(v) {
|
|
1124
|
+
return step([
|
|
1125
|
+
n,
|
|
1126
|
+
v
|
|
1127
|
+
]);
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
function step(op) {
|
|
1131
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1132
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1133
|
+
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;
|
|
1134
|
+
if (y = 0, t) op = [
|
|
1135
|
+
op[0] & 2,
|
|
1136
|
+
t.value
|
|
1137
|
+
];
|
|
1138
|
+
switch(op[0]){
|
|
1139
|
+
case 0:
|
|
1140
|
+
case 1:
|
|
1141
|
+
t = op;
|
|
1142
|
+
break;
|
|
1143
|
+
case 4:
|
|
1144
|
+
_.label++;
|
|
1145
|
+
return {
|
|
1146
|
+
value: op[1],
|
|
1147
|
+
done: false
|
|
1148
|
+
};
|
|
1149
|
+
case 5:
|
|
1150
|
+
_.label++;
|
|
1151
|
+
y = op[1];
|
|
1152
|
+
op = [
|
|
1153
|
+
0
|
|
1154
|
+
];
|
|
1155
|
+
continue;
|
|
1156
|
+
case 7:
|
|
1157
|
+
op = _.ops.pop();
|
|
1158
|
+
_.trys.pop();
|
|
1159
|
+
continue;
|
|
1160
|
+
default:
|
|
1161
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1162
|
+
_ = 0;
|
|
1163
|
+
continue;
|
|
1164
|
+
}
|
|
1165
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1166
|
+
_.label = op[1];
|
|
1167
|
+
break;
|
|
1168
|
+
}
|
|
1169
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1170
|
+
_.label = t[1];
|
|
1171
|
+
t = op;
|
|
1172
|
+
break;
|
|
1173
|
+
}
|
|
1174
|
+
if (t && _.label < t[2]) {
|
|
1175
|
+
_.label = t[2];
|
|
1176
|
+
_.ops.push(op);
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
if (t[2]) _.ops.pop();
|
|
1180
|
+
_.trys.pop();
|
|
1181
|
+
continue;
|
|
1182
|
+
}
|
|
1183
|
+
op = body.call(thisArg, _);
|
|
1184
|
+
} catch (e) {
|
|
1185
|
+
op = [
|
|
1186
|
+
6,
|
|
1187
|
+
e
|
|
1188
|
+
];
|
|
1189
|
+
y = 0;
|
|
1190
|
+
} finally{
|
|
1191
|
+
f = t = 0;
|
|
1192
|
+
}
|
|
1193
|
+
if (op[0] & 5) throw op[1];
|
|
1194
|
+
return {
|
|
1195
|
+
value: op[0] ? op[1] : void 0,
|
|
1196
|
+
done: true
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
function calcomFactory(factoryConfig) {
|
|
1201
|
+
var oauthContext = factoryConfig.oauthContext;
|
|
1202
|
+
var serverAccessTokenStringFactory = calcomAccessTokenStringFactory(oauthContext.loadAccessToken);
|
|
1203
|
+
var fetchHandler = calcomRateLimitedFetchHandler(factoryConfig.rateLimiterConfig);
|
|
1204
|
+
var logCalcomServerErrorFunction = factoryConfig.logCalcomServerErrorFunction, _factoryConfig_fetchFactory = factoryConfig.fetchFactory, fetchFactory = _factoryConfig_fetchFactory === void 0 ? function(input) {
|
|
1205
|
+
return fetchApiFetchService.makeFetch({
|
|
1206
|
+
baseUrl: CALCOM_API_URL,
|
|
1207
|
+
baseRequest: function baseRequest() {
|
|
1208
|
+
return _async_to_generator$1(function() {
|
|
1209
|
+
var _tmp, _tmp1, _, _1;
|
|
1210
|
+
return _ts_generator$1(this, function(_state) {
|
|
1211
|
+
switch(_state.label){
|
|
1212
|
+
case 0:
|
|
1213
|
+
_tmp = {};
|
|
1214
|
+
_tmp1 = {
|
|
1215
|
+
'Content-Type': 'application/json'
|
|
1216
|
+
};
|
|
1217
|
+
_1 = (_ = "Bearer ").concat;
|
|
1218
|
+
return [
|
|
1219
|
+
4,
|
|
1220
|
+
input.calcomAccessTokenStringFactory()
|
|
1221
|
+
];
|
|
1222
|
+
case 1:
|
|
1223
|
+
return [
|
|
1224
|
+
2,
|
|
1225
|
+
(_tmp.headers = (_tmp1.Authorization = _1.apply(_, [
|
|
1226
|
+
_state.sent()
|
|
1227
|
+
]), _tmp1), _tmp)
|
|
1228
|
+
];
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
})();
|
|
1232
|
+
},
|
|
1233
|
+
fetchHandler: fetchHandler,
|
|
1234
|
+
timeout: 20 * 1000,
|
|
1235
|
+
requireOkResponse: true,
|
|
1236
|
+
useTimeout: true // use timeout
|
|
1237
|
+
});
|
|
1238
|
+
} : _factoryConfig_fetchFactory;
|
|
1239
|
+
return function(config) {
|
|
1240
|
+
var baseFetch = fetchFactory({
|
|
1241
|
+
calcomAccessTokenStringFactory: serverAccessTokenStringFactory
|
|
1242
|
+
});
|
|
1243
|
+
var serverFetch = handleCalcomErrorFetch(baseFetch, logCalcomServerErrorFunction);
|
|
1244
|
+
var serverFetchJson = fetchJsonFunction(serverFetch, {
|
|
1245
|
+
handleFetchJsonParseErrorFunction: returnNullHandleFetchJsonParseErrorFunction
|
|
1246
|
+
});
|
|
1247
|
+
// MARK: Make Public Context
|
|
1248
|
+
var makePublicContext = function makePublicContext() {
|
|
1249
|
+
var publicFetch = fetchApiFetchService.makeFetch({
|
|
1250
|
+
baseUrl: CALCOM_API_URL,
|
|
1251
|
+
baseRequest: {
|
|
1252
|
+
headers: {
|
|
1253
|
+
'Content-Type': 'application/json'
|
|
1254
|
+
}
|
|
1255
|
+
},
|
|
1256
|
+
fetchHandler: fetchHandler,
|
|
1257
|
+
timeout: 20 * 1000,
|
|
1258
|
+
requireOkResponse: true,
|
|
1259
|
+
useTimeout: true
|
|
1260
|
+
});
|
|
1261
|
+
var publicHandledFetch = handleCalcomErrorFetch(publicFetch, logCalcomServerErrorFunction);
|
|
1262
|
+
var publicFetchJson = fetchJsonFunction(publicHandledFetch, {
|
|
1263
|
+
handleFetchJsonParseErrorFunction: returnNullHandleFetchJsonParseErrorFunction
|
|
1264
|
+
});
|
|
1265
|
+
return {
|
|
1266
|
+
fetch: publicHandledFetch,
|
|
1267
|
+
fetchJson: publicFetchJson
|
|
1268
|
+
};
|
|
1269
|
+
};
|
|
1270
|
+
// MARK: Make User Context
|
|
1271
|
+
var makeUserContext = function makeUserContext(input) {
|
|
1272
|
+
var userAccessTokenFactory = oauthContext.makeUserAccessTokenFactory({
|
|
1273
|
+
refreshToken: input.refreshToken,
|
|
1274
|
+
userAccessTokenCache: input.accessTokenCache
|
|
1275
|
+
});
|
|
1276
|
+
var userAccessTokenStringFactory = calcomAccessTokenStringFactory(userAccessTokenFactory);
|
|
1277
|
+
var userBaseFetch = fetchFactory({
|
|
1278
|
+
calcomAccessTokenStringFactory: userAccessTokenStringFactory
|
|
1279
|
+
});
|
|
1280
|
+
var userFetch = handleCalcomErrorFetch(userBaseFetch, logCalcomServerErrorFunction);
|
|
1281
|
+
var userFetchJson = fetchJsonFunction(userFetch, {
|
|
1282
|
+
handleFetchJsonParseErrorFunction: returnNullHandleFetchJsonParseErrorFunction
|
|
1283
|
+
});
|
|
1284
|
+
var result = {
|
|
1285
|
+
calcomServerContext: calcomContext,
|
|
1286
|
+
type: 'user',
|
|
1287
|
+
fetch: userFetch,
|
|
1288
|
+
fetchJson: userFetchJson,
|
|
1289
|
+
userFetch: userFetch,
|
|
1290
|
+
userFetchJson: userFetchJson,
|
|
1291
|
+
calcomRateLimiter: fetchHandler._rateLimiter
|
|
1292
|
+
};
|
|
1293
|
+
return result;
|
|
1294
|
+
};
|
|
1295
|
+
var calcomContext = {
|
|
1296
|
+
type: 'server',
|
|
1297
|
+
fetch: serverFetch,
|
|
1298
|
+
fetchJson: serverFetchJson,
|
|
1299
|
+
serverFetch: serverFetch,
|
|
1300
|
+
serverFetchJson: serverFetchJson,
|
|
1301
|
+
makeUserContext: makeUserContext,
|
|
1302
|
+
makePublicContext: makePublicContext,
|
|
1303
|
+
config: config,
|
|
1304
|
+
calcomRateLimiter: fetchHandler._rateLimiter
|
|
1305
|
+
};
|
|
1306
|
+
var calcom = {
|
|
1307
|
+
calcomServerContext: calcomContext
|
|
1308
|
+
};
|
|
1309
|
+
return calcom;
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
function _define_property(obj, key, value) {
|
|
1314
|
+
if (key in obj) {
|
|
1315
|
+
Object.defineProperty(obj, key, {
|
|
1316
|
+
value: value,
|
|
1317
|
+
enumerable: true,
|
|
1318
|
+
configurable: true,
|
|
1319
|
+
writable: true
|
|
1320
|
+
});
|
|
1321
|
+
} else {
|
|
1322
|
+
obj[key] = value;
|
|
1323
|
+
}
|
|
1324
|
+
return obj;
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Cal.com API version header constants.
|
|
1328
|
+
*
|
|
1329
|
+
* Each endpoint group requires a specific cal-api-version header value.
|
|
1330
|
+
*/ var CALCOM_API_VERSION_SCHEDULES = '2024-06-11';
|
|
1331
|
+
var CALCOM_API_VERSION_SLOTS = '2024-09-04';
|
|
1332
|
+
var CALCOM_API_VERSION_BOOKINGS = '2024-08-13';
|
|
1333
|
+
var CALCOM_API_VERSION_EVENT_TYPES = '2024-06-14';
|
|
1334
|
+
var CALCOM_API_VERSION_CALENDARS = '2024-06-11';
|
|
1335
|
+
var CALCOM_API_VERSION_ME = '2024-08-13';
|
|
1336
|
+
var CALCOM_API_VERSION_HEADER = 'cal-api-version';
|
|
1337
|
+
/**
|
|
1338
|
+
* Returns a headers object with the cal-api-version header set.
|
|
1339
|
+
*/ function calcomApiVersionHeaders(version) {
|
|
1340
|
+
return _define_property({}, CALCOM_API_VERSION_HEADER, version);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* Retrieves the profile of the currently authenticated Cal.com user.
|
|
1345
|
+
*
|
|
1346
|
+
* @see https://cal.com/docs/api-reference/v2/me
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1349
|
+
* ```ts
|
|
1350
|
+
* const response = await getMe(context)();
|
|
1351
|
+
* console.log(response.data.email);
|
|
1352
|
+
* ```
|
|
1353
|
+
*/ function getMe(context) {
|
|
1354
|
+
return function() {
|
|
1355
|
+
return context.fetchJson('/me', {
|
|
1356
|
+
method: 'GET',
|
|
1357
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_ME)
|
|
1358
|
+
});
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Retrieves all schedules for the authenticated user, including availability rules and overrides.
|
|
1364
|
+
*
|
|
1365
|
+
* @see https://cal.com/docs/api-reference/v2/schedules/get-all-schedules
|
|
1366
|
+
*
|
|
1367
|
+
* @example
|
|
1368
|
+
* ```ts
|
|
1369
|
+
* const response = await getSchedules(context)();
|
|
1370
|
+
* response.data.forEach(schedule => console.log(schedule.name, schedule.timeZone));
|
|
1371
|
+
* ```
|
|
1372
|
+
*/ function getSchedules(context) {
|
|
1373
|
+
return function() {
|
|
1374
|
+
return context.fetchJson('/schedules', {
|
|
1375
|
+
method: 'GET',
|
|
1376
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_SCHEDULES)
|
|
1377
|
+
});
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Queries available booking slots for a given event type within a date range.
|
|
1383
|
+
* This endpoint is public and does not require authentication.
|
|
1384
|
+
*
|
|
1385
|
+
* Identify the event type by `eventTypeId`, or by `eventTypeSlug` + `username`/`teamSlug`.
|
|
1386
|
+
*
|
|
1387
|
+
* @see https://cal.com/docs/api-reference/v2/slots/get-available-time-slots-for-an-event-type
|
|
1388
|
+
*
|
|
1389
|
+
* @example
|
|
1390
|
+
* ```ts
|
|
1391
|
+
* const response = await getAvailableSlots(context)({
|
|
1392
|
+
* start: '2026-03-17T00:00:00.000Z',
|
|
1393
|
+
* end: '2026-03-24T00:00:00.000Z',
|
|
1394
|
+
* eventTypeId: 12345
|
|
1395
|
+
* });
|
|
1396
|
+
*
|
|
1397
|
+
* for (const [date, slots] of Object.entries(response.data.slots)) {
|
|
1398
|
+
* console.log(date, slots.map(s => s.time));
|
|
1399
|
+
* }
|
|
1400
|
+
* ```
|
|
1401
|
+
*/ function getAvailableSlots(context) {
|
|
1402
|
+
return function(input) {
|
|
1403
|
+
var params = makeUrlSearchParams(input);
|
|
1404
|
+
return context.fetchJson("/slots?".concat(params), {
|
|
1405
|
+
method: 'GET',
|
|
1406
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_SLOTS)
|
|
1407
|
+
});
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
/**
|
|
1412
|
+
* Creates a new booking for the specified event type. The `attendee` represents the person
|
|
1413
|
+
* booking (the client), not the host. This endpoint can be called without authentication.
|
|
1414
|
+
*
|
|
1415
|
+
* @see https://cal.com/docs/api-reference/v2/bookings/create-a-booking
|
|
1416
|
+
*
|
|
1417
|
+
* @example
|
|
1418
|
+
* ```ts
|
|
1419
|
+
* const response = await createBooking(context)({
|
|
1420
|
+
* start: '2026-03-20T14:00:00.000Z',
|
|
1421
|
+
* eventTypeId: 12345,
|
|
1422
|
+
* attendee: { name: 'Jane Doe', email: 'jane@example.com', timeZone: 'America/New_York' }
|
|
1423
|
+
* });
|
|
1424
|
+
* console.log(response.data.uid);
|
|
1425
|
+
* ```
|
|
1426
|
+
*/ function createBooking(context) {
|
|
1427
|
+
return function(input) {
|
|
1428
|
+
return context.fetchJson('/bookings', {
|
|
1429
|
+
method: 'POST',
|
|
1430
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_BOOKINGS),
|
|
1431
|
+
body: JSON.stringify(input)
|
|
1432
|
+
});
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* Retrieves a booking by its unique UID.
|
|
1437
|
+
*
|
|
1438
|
+
* @see https://cal.com/docs/api-reference/v2/bookings/get-a-booking
|
|
1439
|
+
*
|
|
1440
|
+
* @example
|
|
1441
|
+
* ```ts
|
|
1442
|
+
* const response = await getBooking(context)('abc-123-uid');
|
|
1443
|
+
* console.log(response.data.title, response.data.status);
|
|
1444
|
+
* ```
|
|
1445
|
+
*/ function getBooking(context) {
|
|
1446
|
+
return function(uid) {
|
|
1447
|
+
return context.fetchJson("/bookings/".concat(uid), {
|
|
1448
|
+
method: 'GET',
|
|
1449
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_BOOKINGS)
|
|
1450
|
+
});
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Cancels a booking by its unique UID, with an optional cancellation reason.
|
|
1455
|
+
*
|
|
1456
|
+
* @see https://cal.com/docs/api-reference/v2/bookings/cancel-a-booking
|
|
1457
|
+
*
|
|
1458
|
+
* @example
|
|
1459
|
+
* ```ts
|
|
1460
|
+
* await cancelBooking(context)({ uid: 'abc-123-uid', cancellationReason: 'Schedule conflict' });
|
|
1461
|
+
* ```
|
|
1462
|
+
*/ function cancelBooking(context) {
|
|
1463
|
+
return function(input) {
|
|
1464
|
+
var body = {};
|
|
1465
|
+
if (input.cancellationReason) {
|
|
1466
|
+
body['cancellationReason'] = input.cancellationReason;
|
|
1467
|
+
}
|
|
1468
|
+
return context.fetchJson("/bookings/".concat(input.uid, "/cancel"), {
|
|
1469
|
+
method: 'POST',
|
|
1470
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_BOOKINGS),
|
|
1471
|
+
body: JSON.stringify(body)
|
|
1472
|
+
});
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
/**
|
|
1477
|
+
* Retrieves all event types for the authenticated user.
|
|
1478
|
+
*
|
|
1479
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/get-all-event-types
|
|
1480
|
+
*
|
|
1481
|
+
* @example
|
|
1482
|
+
* ```ts
|
|
1483
|
+
* const response = await getEventTypes(context)();
|
|
1484
|
+
* response.data.forEach(et => console.log(et.title, et.slug, et.lengthInMinutes));
|
|
1485
|
+
* ```
|
|
1486
|
+
*/ function getEventTypes(context) {
|
|
1487
|
+
return function() {
|
|
1488
|
+
return context.fetchJson('/event-types', {
|
|
1489
|
+
method: 'GET',
|
|
1490
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_EVENT_TYPES)
|
|
1491
|
+
});
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Creates a new event type for the authenticated user.
|
|
1496
|
+
*
|
|
1497
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/create-an-event-type
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```ts
|
|
1501
|
+
* const response = await createEventType(context)({
|
|
1502
|
+
* title: 'Mentoring Session',
|
|
1503
|
+
* slug: 'mentoring-session',
|
|
1504
|
+
* lengthInMinutes: 30
|
|
1505
|
+
* });
|
|
1506
|
+
* console.log(response.data.id);
|
|
1507
|
+
* ```
|
|
1508
|
+
*/ function createEventType(context) {
|
|
1509
|
+
return function(input) {
|
|
1510
|
+
return context.fetchJson('/event-types', {
|
|
1511
|
+
method: 'POST',
|
|
1512
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_EVENT_TYPES),
|
|
1513
|
+
body: JSON.stringify(input)
|
|
1514
|
+
});
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Updates an existing event type by ID.
|
|
1519
|
+
*
|
|
1520
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/update-an-event-type
|
|
1521
|
+
*
|
|
1522
|
+
* @example
|
|
1523
|
+
* ```ts
|
|
1524
|
+
* await updateEventType(context)(12345, { title: 'Updated Session Title' });
|
|
1525
|
+
* ```
|
|
1526
|
+
*/ function updateEventType(context) {
|
|
1527
|
+
return function(eventTypeId, input) {
|
|
1528
|
+
return context.fetchJson("/event-types/".concat(eventTypeId), {
|
|
1529
|
+
method: 'PATCH',
|
|
1530
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_EVENT_TYPES),
|
|
1531
|
+
body: JSON.stringify(input)
|
|
1532
|
+
});
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Deletes an event type by ID.
|
|
1537
|
+
*
|
|
1538
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/delete-an-event-type
|
|
1539
|
+
*
|
|
1540
|
+
* @example
|
|
1541
|
+
* ```ts
|
|
1542
|
+
* await deleteEventType(context)(12345);
|
|
1543
|
+
* ```
|
|
1544
|
+
*/ function deleteEventType(context) {
|
|
1545
|
+
return function(eventTypeId) {
|
|
1546
|
+
return context.fetchJson("/event-types/".concat(eventTypeId), {
|
|
1547
|
+
method: 'DELETE',
|
|
1548
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_EVENT_TYPES)
|
|
1549
|
+
});
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
/**
|
|
1554
|
+
* Retrieves all connected calendars and the destination calendar for the authenticated user.
|
|
1555
|
+
*
|
|
1556
|
+
* @see https://cal.com/docs/api-reference/v2/calendars/get-all-calendars
|
|
1557
|
+
*
|
|
1558
|
+
* @example
|
|
1559
|
+
* ```ts
|
|
1560
|
+
* const response = await getCalendars(context)();
|
|
1561
|
+
* response.data.connectedCalendars.forEach(cc => console.log(cc.integration));
|
|
1562
|
+
* ```
|
|
1563
|
+
*/ function getCalendars(context) {
|
|
1564
|
+
return function() {
|
|
1565
|
+
return context.fetchJson('/calendars', {
|
|
1566
|
+
method: 'GET',
|
|
1567
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_CALENDARS)
|
|
1568
|
+
});
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* Retrieves busy time ranges across the user's connected calendars for a given date range.
|
|
1573
|
+
*
|
|
1574
|
+
* @see https://cal.com/docs/api-reference/v2/calendars/get-busy-times
|
|
1575
|
+
*
|
|
1576
|
+
* @example
|
|
1577
|
+
* ```ts
|
|
1578
|
+
* const response = await getBusyTimes(context)({
|
|
1579
|
+
* dateFrom: '2026-03-17',
|
|
1580
|
+
* dateTo: '2026-03-24'
|
|
1581
|
+
* });
|
|
1582
|
+
* response.data.forEach(bt => console.log(bt.start, bt.end));
|
|
1583
|
+
* ```
|
|
1584
|
+
*/ function getBusyTimes(context) {
|
|
1585
|
+
return function(input) {
|
|
1586
|
+
var _input_calendarsToLoad;
|
|
1587
|
+
var params = makeUrlSearchParams({
|
|
1588
|
+
dateFrom: input.dateFrom,
|
|
1589
|
+
dateTo: input.dateTo,
|
|
1590
|
+
calendarsToLoad: (_input_calendarsToLoad = input.calendarsToLoad) === null || _input_calendarsToLoad === void 0 ? void 0 : _input_calendarsToLoad.join(',')
|
|
1591
|
+
});
|
|
1592
|
+
return context.fetchJson("/calendars/busy-times?".concat(params), {
|
|
1593
|
+
method: 'GET',
|
|
1594
|
+
headers: calcomApiVersionHeaders(CALCOM_API_VERSION_CALENDARS)
|
|
1595
|
+
});
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* Creates a webhook subscription for the authenticated user. Webhooks notify your app
|
|
1601
|
+
* when specified events occur (e.g., bookings created, cancelled, rescheduled).
|
|
1602
|
+
*
|
|
1603
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/create-a-webhook
|
|
1604
|
+
*
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```ts
|
|
1607
|
+
* const response = await createWebhook(context)({
|
|
1608
|
+
* subscriberUrl: 'https://example.com/webhook/calcom',
|
|
1609
|
+
* triggers: ['BOOKING_CREATED', 'BOOKING_CANCELLED'],
|
|
1610
|
+
* active: true
|
|
1611
|
+
* });
|
|
1612
|
+
* console.log(response.data.id);
|
|
1613
|
+
* ```
|
|
1614
|
+
*/ function createWebhook(context) {
|
|
1615
|
+
return function(input) {
|
|
1616
|
+
return context.fetchJson('/webhooks', {
|
|
1617
|
+
method: 'POST',
|
|
1618
|
+
body: JSON.stringify(input)
|
|
1619
|
+
});
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Retrieves all webhooks for the authenticated user.
|
|
1624
|
+
*
|
|
1625
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/get-all-webhooks
|
|
1626
|
+
*
|
|
1627
|
+
* @example
|
|
1628
|
+
* ```ts
|
|
1629
|
+
* const response = await getWebhooks(context)();
|
|
1630
|
+
* response.data.forEach(wh => console.log(wh.subscriberUrl, wh.triggers));
|
|
1631
|
+
* ```
|
|
1632
|
+
*/ function getWebhooks(context) {
|
|
1633
|
+
return function() {
|
|
1634
|
+
return context.fetchJson('/webhooks', {
|
|
1635
|
+
method: 'GET'
|
|
1636
|
+
});
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Retrieves a specific webhook by ID.
|
|
1641
|
+
*
|
|
1642
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/get-a-webhook
|
|
1643
|
+
*
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* const response = await getWebhook(context)(42);
|
|
1647
|
+
* console.log(response.data.subscriberUrl);
|
|
1648
|
+
* ```
|
|
1649
|
+
*/ function getWebhook(context) {
|
|
1650
|
+
return function(webhookId) {
|
|
1651
|
+
return context.fetchJson("/webhooks/".concat(webhookId), {
|
|
1652
|
+
method: 'GET'
|
|
1653
|
+
});
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Updates an existing webhook by ID.
|
|
1658
|
+
*
|
|
1659
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/update-a-webhook
|
|
1660
|
+
*
|
|
1661
|
+
* @example
|
|
1662
|
+
* ```ts
|
|
1663
|
+
* await updateWebhook(context)(42, { active: false });
|
|
1664
|
+
* ```
|
|
1665
|
+
*/ function updateWebhook(context) {
|
|
1666
|
+
return function(webhookId, input) {
|
|
1667
|
+
return context.fetchJson("/webhooks/".concat(webhookId), {
|
|
1668
|
+
method: 'PATCH',
|
|
1669
|
+
body: JSON.stringify(input)
|
|
1670
|
+
});
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Deletes a webhook by ID.
|
|
1675
|
+
*
|
|
1676
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/delete-a-webhook
|
|
1677
|
+
*
|
|
1678
|
+
* @example
|
|
1679
|
+
* ```ts
|
|
1680
|
+
* await deleteWebhook(context)(42);
|
|
1681
|
+
* ```
|
|
1682
|
+
*/ function deleteWebhook(context) {
|
|
1683
|
+
return function(webhookId) {
|
|
1684
|
+
return context.fetchJson("/webhooks/".concat(webhookId), {
|
|
1685
|
+
method: 'DELETE'
|
|
1686
|
+
});
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
/**
|
|
1691
|
+
* Refreshes an access token using a refresh token. Cal.com rotates refresh tokens
|
|
1692
|
+
* on every use, so the new `refresh_token` from the response must be persisted.
|
|
1693
|
+
*
|
|
1694
|
+
* Cal.com uses JSON body (not Basic Auth) for token requests.
|
|
1695
|
+
*
|
|
1696
|
+
* @see https://cal.com/docs/api-reference/v2/oauth/refresh-an-existing-access-token
|
|
1697
|
+
*
|
|
1698
|
+
* @example
|
|
1699
|
+
* ```ts
|
|
1700
|
+
* const response = await refreshAccessToken(context)({ refreshToken: 'existing-refresh-token' });
|
|
1701
|
+
* console.log(response.access_token, response.refresh_token);
|
|
1702
|
+
* ```
|
|
1703
|
+
*/ function refreshAccessToken(context) {
|
|
1704
|
+
return function(input) {
|
|
1705
|
+
var _ref;
|
|
1706
|
+
var refreshToken = (_ref = input === null || input === void 0 ? void 0 : input.refreshToken) !== null && _ref !== void 0 ? _ref : context.config.refreshToken;
|
|
1707
|
+
var fetchJsonInput = {
|
|
1708
|
+
method: 'POST',
|
|
1709
|
+
body: JSON.stringify({
|
|
1710
|
+
grant_type: 'refresh_token',
|
|
1711
|
+
client_id: context.config.clientId,
|
|
1712
|
+
client_secret: context.config.clientSecret,
|
|
1713
|
+
refresh_token: refreshToken
|
|
1714
|
+
})
|
|
1715
|
+
};
|
|
1716
|
+
return context.fetchJson('/oauth/token', fetchJsonInput);
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
/**
|
|
1720
|
+
* Exchanges an OAuth authorization code for access and refresh tokens.
|
|
1721
|
+
* Used during the initial OAuth flow when a user authorizes your app.
|
|
1722
|
+
*
|
|
1723
|
+
* Cal.com uses JSON body (not Basic Auth) for token requests.
|
|
1724
|
+
*
|
|
1725
|
+
* @see https://cal.com/docs/api-reference/v2/oauth/exchange-an-authorization-code-for-access-tokens
|
|
1726
|
+
*
|
|
1727
|
+
* @example
|
|
1728
|
+
* ```ts
|
|
1729
|
+
* const response = await exchangeAuthorizationCode(context)({
|
|
1730
|
+
* code: 'auth-code-from-redirect',
|
|
1731
|
+
* redirectUri: 'https://example.com/callback'
|
|
1732
|
+
* });
|
|
1733
|
+
* console.log(response.access_token, response.refresh_token);
|
|
1734
|
+
* ```
|
|
1735
|
+
*/ function exchangeAuthorizationCode(context) {
|
|
1736
|
+
return function(input) {
|
|
1737
|
+
var fetchJsonInput = {
|
|
1738
|
+
method: 'POST',
|
|
1739
|
+
body: JSON.stringify({
|
|
1740
|
+
grant_type: 'authorization_code',
|
|
1741
|
+
client_id: context.config.clientId,
|
|
1742
|
+
client_secret: context.config.clientSecret,
|
|
1743
|
+
code: input.code,
|
|
1744
|
+
redirect_uri: input.redirectUri
|
|
1745
|
+
})
|
|
1746
|
+
};
|
|
1747
|
+
return context.fetchJson('/oauth/token', fetchJsonInput);
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* The Cal.com OAuth token endpoint URL.
|
|
1753
|
+
*/ var CALCOM_OAUTH_TOKEN_URL = 'https://api.cal.com/v2/oauth/token';
|
|
1754
|
+
/**
|
|
1755
|
+
* The Cal.com OAuth authorize URL.
|
|
1756
|
+
*/ var CALCOM_OAUTH_AUTHORIZE_URL = 'https://app.cal.com/auth/oauth2/authorize';
|
|
1757
|
+
|
|
1758
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1759
|
+
try {
|
|
1760
|
+
var info = gen[key](arg);
|
|
1761
|
+
var value = info.value;
|
|
1762
|
+
} catch (error) {
|
|
1763
|
+
reject(error);
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
if (info.done) {
|
|
1767
|
+
resolve(value);
|
|
1768
|
+
} else {
|
|
1769
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
function _async_to_generator(fn) {
|
|
1773
|
+
return function() {
|
|
1774
|
+
var self = this, args = arguments;
|
|
1775
|
+
return new Promise(function(resolve, reject) {
|
|
1776
|
+
var gen = fn.apply(self, args);
|
|
1777
|
+
function _next(value) {
|
|
1778
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
1779
|
+
}
|
|
1780
|
+
function _throw(err) {
|
|
1781
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1782
|
+
}
|
|
1783
|
+
_next(undefined);
|
|
1784
|
+
});
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
function _ts_generator(thisArg, body) {
|
|
1788
|
+
var f, y, t, _ = {
|
|
1789
|
+
label: 0,
|
|
1790
|
+
sent: function() {
|
|
1791
|
+
if (t[0] & 1) throw t[1];
|
|
1792
|
+
return t[1];
|
|
1793
|
+
},
|
|
1794
|
+
trys: [],
|
|
1795
|
+
ops: []
|
|
1796
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1797
|
+
return d(g, "next", {
|
|
1798
|
+
value: verb(0)
|
|
1799
|
+
}), d(g, "throw", {
|
|
1800
|
+
value: verb(1)
|
|
1801
|
+
}), d(g, "return", {
|
|
1802
|
+
value: verb(2)
|
|
1803
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1804
|
+
value: function() {
|
|
1805
|
+
return this;
|
|
1806
|
+
}
|
|
1807
|
+
}), g;
|
|
1808
|
+
function verb(n) {
|
|
1809
|
+
return function(v) {
|
|
1810
|
+
return step([
|
|
1811
|
+
n,
|
|
1812
|
+
v
|
|
1813
|
+
]);
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
function step(op) {
|
|
1817
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1818
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1819
|
+
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;
|
|
1820
|
+
if (y = 0, t) op = [
|
|
1821
|
+
op[0] & 2,
|
|
1822
|
+
t.value
|
|
1823
|
+
];
|
|
1824
|
+
switch(op[0]){
|
|
1825
|
+
case 0:
|
|
1826
|
+
case 1:
|
|
1827
|
+
t = op;
|
|
1828
|
+
break;
|
|
1829
|
+
case 4:
|
|
1830
|
+
_.label++;
|
|
1831
|
+
return {
|
|
1832
|
+
value: op[1],
|
|
1833
|
+
done: false
|
|
1834
|
+
};
|
|
1835
|
+
case 5:
|
|
1836
|
+
_.label++;
|
|
1837
|
+
y = op[1];
|
|
1838
|
+
op = [
|
|
1839
|
+
0
|
|
1840
|
+
];
|
|
1841
|
+
continue;
|
|
1842
|
+
case 7:
|
|
1843
|
+
op = _.ops.pop();
|
|
1844
|
+
_.trys.pop();
|
|
1845
|
+
continue;
|
|
1846
|
+
default:
|
|
1847
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1848
|
+
_ = 0;
|
|
1849
|
+
continue;
|
|
1850
|
+
}
|
|
1851
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1852
|
+
_.label = op[1];
|
|
1853
|
+
break;
|
|
1854
|
+
}
|
|
1855
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1856
|
+
_.label = t[1];
|
|
1857
|
+
t = op;
|
|
1858
|
+
break;
|
|
1859
|
+
}
|
|
1860
|
+
if (t && _.label < t[2]) {
|
|
1861
|
+
_.label = t[2];
|
|
1862
|
+
_.ops.push(op);
|
|
1863
|
+
break;
|
|
1864
|
+
}
|
|
1865
|
+
if (t[2]) _.ops.pop();
|
|
1866
|
+
_.trys.pop();
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
op = body.call(thisArg, _);
|
|
1870
|
+
} catch (e) {
|
|
1871
|
+
op = [
|
|
1872
|
+
6,
|
|
1873
|
+
e
|
|
1874
|
+
];
|
|
1875
|
+
y = 0;
|
|
1876
|
+
} finally{
|
|
1877
|
+
f = t = 0;
|
|
1878
|
+
}
|
|
1879
|
+
if (op[0] & 5) throw op[1];
|
|
1880
|
+
return {
|
|
1881
|
+
value: op[0] ? op[1] : void 0,
|
|
1882
|
+
done: true
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
function calcomOAuthFactory(factoryConfig) {
|
|
1887
|
+
var fetchHandler = calcomRateLimitedFetchHandler();
|
|
1888
|
+
var logCalcomServerErrorFunction = factoryConfig.logCalcomServerErrorFunction, _factoryConfig_fetchFactory = factoryConfig.fetchFactory, fetchFactory = _factoryConfig_fetchFactory === void 0 ? function(_) {
|
|
1889
|
+
return fetchApiFetchService.makeFetch({
|
|
1890
|
+
baseUrl: CALCOM_OAUTH_TOKEN_URL,
|
|
1891
|
+
baseRequest: {
|
|
1892
|
+
headers: {
|
|
1893
|
+
'Content-Type': 'application/json'
|
|
1894
|
+
}
|
|
1895
|
+
},
|
|
1896
|
+
fetchHandler: fetchHandler,
|
|
1897
|
+
timeout: 20 * 1000,
|
|
1898
|
+
requireOkResponse: true,
|
|
1899
|
+
useTimeout: true // use timeout
|
|
1900
|
+
});
|
|
1901
|
+
} : _factoryConfig_fetchFactory;
|
|
1902
|
+
return function(config) {
|
|
1903
|
+
var accessTokenFromTokenResponse = function accessTokenFromTokenResponse(result) {
|
|
1904
|
+
var createdAt = new Date().getTime();
|
|
1905
|
+
var access_token = result.access_token, refresh_token = result.refresh_token, scope = result.scope, expires_in = result.expires_in;
|
|
1906
|
+
// Store the new refresh token for next use
|
|
1907
|
+
latestRefreshToken = refresh_token;
|
|
1908
|
+
var accessToken = {
|
|
1909
|
+
accessToken: access_token,
|
|
1910
|
+
refreshToken: refresh_token,
|
|
1911
|
+
expiresIn: expires_in,
|
|
1912
|
+
expiresAt: new Date(createdAt + expires_in * MS_IN_SECOND),
|
|
1913
|
+
scope: scope !== null && scope !== void 0 ? scope : ''
|
|
1914
|
+
};
|
|
1915
|
+
return accessToken;
|
|
1916
|
+
};
|
|
1917
|
+
var useApiKey = !!config.apiKey;
|
|
1918
|
+
if (!useApiKey) {
|
|
1919
|
+
if (!config.clientId) {
|
|
1920
|
+
throw new Error('CalcomOAuthConfig missing clientId. Provide clientId+clientSecret for OAuth or apiKey for API key auth.');
|
|
1921
|
+
} else if (!config.clientSecret) {
|
|
1922
|
+
throw new Error('CalcomOAuthConfig missing clientSecret.');
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
var baseFetch = fetchFactory();
|
|
1926
|
+
var fetch = handleCalcomOAuthErrorFetch(baseFetch, logCalcomServerErrorFunction);
|
|
1927
|
+
var fetchJson = fetchJsonFunction(fetch, {
|
|
1928
|
+
handleFetchJsonParseErrorFunction: returnNullHandleFetchJsonParseErrorFunction
|
|
1929
|
+
});
|
|
1930
|
+
// MARK: API Key Auth (static token, no refresh)
|
|
1931
|
+
if (useApiKey) {
|
|
1932
|
+
var apiKeyToken = {
|
|
1933
|
+
accessToken: config.apiKey,
|
|
1934
|
+
refreshToken: '',
|
|
1935
|
+
expiresIn: Number.MAX_SAFE_INTEGER,
|
|
1936
|
+
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 100),
|
|
1937
|
+
scope: ''
|
|
1938
|
+
};
|
|
1939
|
+
var loadAccessToken = function loadAccessToken() {
|
|
1940
|
+
return _async_to_generator(function() {
|
|
1941
|
+
return _ts_generator(this, function(_state) {
|
|
1942
|
+
return [
|
|
1943
|
+
2,
|
|
1944
|
+
apiKeyToken
|
|
1945
|
+
];
|
|
1946
|
+
});
|
|
1947
|
+
})();
|
|
1948
|
+
};
|
|
1949
|
+
var makeUserAccessTokenFactory = function makeUserAccessTokenFactory() {
|
|
1950
|
+
throw new Error('makeUserAccessTokenFactory is not available when using API key auth. Use OAuth for per-user contexts.');
|
|
1951
|
+
};
|
|
1952
|
+
var oauthContext = {
|
|
1953
|
+
fetch: fetch,
|
|
1954
|
+
fetchJson: fetchJson,
|
|
1955
|
+
loadAccessToken: loadAccessToken,
|
|
1956
|
+
makeUserAccessTokenFactory: makeUserAccessTokenFactory,
|
|
1957
|
+
config: config
|
|
1958
|
+
};
|
|
1959
|
+
return {
|
|
1960
|
+
oauthContext: oauthContext
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
// MARK: OAuth Auth (refresh token flow)
|
|
1964
|
+
/**
|
|
1965
|
+
* Tracks the latest refresh token since Cal.com rotates them.
|
|
1966
|
+
*/ var latestRefreshToken = config.refreshToken;
|
|
1967
|
+
var tokenRefresher = function tokenRefresher() {
|
|
1968
|
+
return _async_to_generator(function() {
|
|
1969
|
+
var accessToken;
|
|
1970
|
+
return _ts_generator(this, function(_state) {
|
|
1971
|
+
switch(_state.label){
|
|
1972
|
+
case 0:
|
|
1973
|
+
return [
|
|
1974
|
+
4,
|
|
1975
|
+
refreshAccessToken(oauthContext1)({
|
|
1976
|
+
refreshToken: latestRefreshToken !== null && latestRefreshToken !== void 0 ? latestRefreshToken : undefined
|
|
1977
|
+
})
|
|
1978
|
+
];
|
|
1979
|
+
case 1:
|
|
1980
|
+
accessToken = _state.sent();
|
|
1981
|
+
return [
|
|
1982
|
+
2,
|
|
1983
|
+
accessTokenFromTokenResponse(accessToken)
|
|
1984
|
+
];
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
})();
|
|
1988
|
+
};
|
|
1989
|
+
var loadAccessToken1 = calcomOAuthAccessTokenFactory({
|
|
1990
|
+
tokenRefresher: tokenRefresher,
|
|
1991
|
+
accessTokenCache: config.accessTokenCache
|
|
1992
|
+
});
|
|
1993
|
+
// User Access Token
|
|
1994
|
+
var makeUserAccessTokenFactory1 = function makeUserAccessTokenFactory(input) {
|
|
1995
|
+
var userLatestRefreshToken = input.refreshToken;
|
|
1996
|
+
var userTokenRefresher = function userTokenRefresher() {
|
|
1997
|
+
return _async_to_generator(function() {
|
|
1998
|
+
var tokenResponse, token;
|
|
1999
|
+
return _ts_generator(this, function(_state) {
|
|
2000
|
+
switch(_state.label){
|
|
2001
|
+
case 0:
|
|
2002
|
+
return [
|
|
2003
|
+
4,
|
|
2004
|
+
refreshAccessToken(oauthContext1)({
|
|
2005
|
+
refreshToken: userLatestRefreshToken
|
|
2006
|
+
})
|
|
2007
|
+
];
|
|
2008
|
+
case 1:
|
|
2009
|
+
tokenResponse = _state.sent();
|
|
2010
|
+
token = accessTokenFromTokenResponse(tokenResponse);
|
|
2011
|
+
// Track the rotated refresh token for this user
|
|
2012
|
+
userLatestRefreshToken = token.refreshToken;
|
|
2013
|
+
return [
|
|
2014
|
+
2,
|
|
2015
|
+
token
|
|
2016
|
+
];
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
})();
|
|
2020
|
+
};
|
|
2021
|
+
return calcomOAuthAccessTokenFactory({
|
|
2022
|
+
tokenRefresher: userTokenRefresher,
|
|
2023
|
+
accessTokenCache: input.userAccessTokenCache
|
|
2024
|
+
});
|
|
2025
|
+
};
|
|
2026
|
+
var oauthContext1 = {
|
|
2027
|
+
fetch: fetch,
|
|
2028
|
+
fetchJson: fetchJson,
|
|
2029
|
+
loadAccessToken: loadAccessToken1,
|
|
2030
|
+
makeUserAccessTokenFactory: makeUserAccessTokenFactory1,
|
|
2031
|
+
config: config
|
|
2032
|
+
};
|
|
2033
|
+
var calcomOAuth = {
|
|
2034
|
+
oauthContext: oauthContext1
|
|
2035
|
+
};
|
|
2036
|
+
return calcomOAuth;
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
/**
|
|
2040
|
+
* Creates a CalcomAccessTokenFactory with multi-tier caching.
|
|
2041
|
+
*/ function calcomOAuthAccessTokenFactory(config) {
|
|
2042
|
+
var tokenRefresher = config.tokenRefresher, accessTokenCache = config.accessTokenCache, inputTokenExpirationBuffer = config.tokenExpirationBuffer;
|
|
2043
|
+
var tokenExpirationBuffer = inputTokenExpirationBuffer !== null && inputTokenExpirationBuffer !== void 0 ? inputTokenExpirationBuffer : MS_IN_MINUTE;
|
|
2044
|
+
/**
|
|
2045
|
+
* Caches the token internally here until it expires.
|
|
2046
|
+
*/ var currentToken = null;
|
|
2047
|
+
return function() {
|
|
2048
|
+
return _async_to_generator(function() {
|
|
2049
|
+
var cachedToken, isExpired, e;
|
|
2050
|
+
return _ts_generator(this, function(_state) {
|
|
2051
|
+
switch(_state.label){
|
|
2052
|
+
case 0:
|
|
2053
|
+
if (!!currentToken) return [
|
|
2054
|
+
3,
|
|
2055
|
+
2
|
|
2056
|
+
];
|
|
2057
|
+
return [
|
|
2058
|
+
4,
|
|
2059
|
+
accessTokenCache === null || accessTokenCache === void 0 ? void 0 : accessTokenCache.loadCachedToken()
|
|
2060
|
+
];
|
|
2061
|
+
case 1:
|
|
2062
|
+
cachedToken = _state.sent();
|
|
2063
|
+
if (cachedToken) {
|
|
2064
|
+
currentToken = cachedToken;
|
|
2065
|
+
}
|
|
2066
|
+
_state.label = 2;
|
|
2067
|
+
case 2:
|
|
2068
|
+
// check expiration
|
|
2069
|
+
if (currentToken != null) {
|
|
2070
|
+
isExpired = new Date().getTime() + tokenExpirationBuffer >= currentToken.expiresAt.getTime();
|
|
2071
|
+
if (isExpired) {
|
|
2072
|
+
currentToken = null;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
if (!!currentToken) return [
|
|
2076
|
+
3,
|
|
2077
|
+
10
|
|
2078
|
+
];
|
|
2079
|
+
_state.label = 3;
|
|
2080
|
+
case 3:
|
|
2081
|
+
_state.trys.push([
|
|
2082
|
+
3,
|
|
2083
|
+
5,
|
|
2084
|
+
,
|
|
2085
|
+
6
|
|
2086
|
+
]);
|
|
2087
|
+
return [
|
|
2088
|
+
4,
|
|
2089
|
+
tokenRefresher()
|
|
2090
|
+
];
|
|
2091
|
+
case 4:
|
|
2092
|
+
currentToken = _state.sent();
|
|
2093
|
+
return [
|
|
2094
|
+
3,
|
|
2095
|
+
6
|
|
2096
|
+
];
|
|
2097
|
+
case 5:
|
|
2098
|
+
e = _state.sent();
|
|
2099
|
+
console.error("calcomOAuthAccessTokenFactory(): Failed retrieving new token from tokenRefresher: ", e);
|
|
2100
|
+
throw new CalcomOAuthAuthFailureError('Token Refresh Failed');
|
|
2101
|
+
case 6:
|
|
2102
|
+
if (!currentToken) return [
|
|
2103
|
+
3,
|
|
2104
|
+
10
|
|
2105
|
+
];
|
|
2106
|
+
_state.label = 7;
|
|
2107
|
+
case 7:
|
|
2108
|
+
_state.trys.push([
|
|
2109
|
+
7,
|
|
2110
|
+
9,
|
|
2111
|
+
,
|
|
2112
|
+
10
|
|
2113
|
+
]);
|
|
2114
|
+
return [
|
|
2115
|
+
4,
|
|
2116
|
+
accessTokenCache === null || accessTokenCache === void 0 ? void 0 : accessTokenCache.updateCachedToken(currentToken)
|
|
2117
|
+
];
|
|
2118
|
+
case 8:
|
|
2119
|
+
_state.sent();
|
|
2120
|
+
return [
|
|
2121
|
+
3,
|
|
2122
|
+
10
|
|
2123
|
+
];
|
|
2124
|
+
case 9:
|
|
2125
|
+
_state.sent();
|
|
2126
|
+
return [
|
|
2127
|
+
3,
|
|
2128
|
+
10
|
|
2129
|
+
];
|
|
2130
|
+
case 10:
|
|
2131
|
+
return [
|
|
2132
|
+
2,
|
|
2133
|
+
currentToken
|
|
2134
|
+
];
|
|
2135
|
+
}
|
|
2136
|
+
});
|
|
2137
|
+
})();
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
export { CALCOM_API_URL, CALCOM_API_VERSION_BOOKINGS, CALCOM_API_VERSION_CALENDARS, CALCOM_API_VERSION_EVENT_TYPES, CALCOM_API_VERSION_HEADER, CALCOM_API_VERSION_ME, CALCOM_API_VERSION_SCHEDULES, CALCOM_API_VERSION_SLOTS, CALCOM_OAUTH_AUTHORIZE_URL, CALCOM_OAUTH_INVALID_GRANT_ERROR_CODE, CALCOM_OAUTH_TOKEN_URL, CALCOM_RATE_LIMIT_LIMIT_HEADER, CALCOM_RATE_LIMIT_REMAINING_HEADER, CALCOM_RATE_LIMIT_RESET_HEADER, CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE, CalcomOAuthAccessTokenError, CalcomOAuthAuthFailureError, CalcomServerError, CalcomServerFetchResponseError, CalcomTooManyRequestsError, DEFAULT_CALCOM_API_RATE_LIMIT, DEFAULT_CALCOM_API_RATE_LIMIT_RESET_PERIOD, DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION, calcomAccessTokenStringFactory, calcomApiVersionHeaders, calcomFactory, calcomOAuthAccessTokenFactory, calcomOAuthFactory, calcomRateLimitHeaderDetails, calcomRateLimitedFetchHandler, cancelBooking, createBooking, createEventType, createWebhook, deleteEventType, deleteWebhook, exchangeAuthorizationCode, getAvailableSlots, getBooking, getBusyTimes, getCalendars, getEventTypes, getMe, getSchedules, getWebhook, getWebhooks, handleCalcomErrorFetch, handleCalcomErrorFetchFactory, handleCalcomOAuthErrorFetch, logCalcomErrorToConsole, logCalcomOAuthErrorToConsole, logCalcomServerErrorFunction, parseCalcomApiError, parseCalcomApiServerErrorResponseData, parseCalcomOAuthError, parseCalcomOAuthServerErrorResponseData, parseCalcomServerErrorData, refreshAccessToken, updateEventType, updateWebhook };
|