@compilot/js-sdk 2.0.40-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/compilot-js-sdk.cjs.d.ts +2 -0
  2. package/dist/compilot-js-sdk.cjs.dev.js +1376 -0
  3. package/dist/compilot-js-sdk.cjs.js +7 -0
  4. package/dist/compilot-js-sdk.cjs.prod.js +1376 -0
  5. package/dist/compilot-js-sdk.esm.js +1360 -0
  6. package/dist/declarations/src/actions/attachCustomerInformation.d.ts +47 -0
  7. package/dist/declarations/src/actions/attachCustomerInformation.d.ts.map +1 -0
  8. package/dist/declarations/src/actions/createWeb2Session.d.ts +63 -0
  9. package/dist/declarations/src/actions/createWeb2Session.d.ts.map +1 -0
  10. package/dist/declarations/src/actions/createWeb3Challenge.d.ts +63 -0
  11. package/dist/declarations/src/actions/createWeb3Challenge.d.ts.map +1 -0
  12. package/dist/declarations/src/actions/getCustomerStatusByCustomerId.d.ts +29 -0
  13. package/dist/declarations/src/actions/getCustomerStatusByCustomerId.d.ts.map +1 -0
  14. package/dist/declarations/src/actions/getCustomerStatusByExternalCustomerId.d.ts +29 -0
  15. package/dist/declarations/src/actions/getCustomerStatusByExternalCustomerId.d.ts.map +1 -0
  16. package/dist/declarations/src/actions/getCustomerStatusByWallet.d.ts +29 -0
  17. package/dist/declarations/src/actions/getCustomerStatusByWallet.d.ts.map +1 -0
  18. package/dist/declarations/src/actions/getCustomerWallets.d.ts +31 -0
  19. package/dist/declarations/src/actions/getCustomerWallets.d.ts.map +1 -0
  20. package/dist/declarations/src/actions/getTxAuthDataSignature.d.ts +58 -0
  21. package/dist/declarations/src/actions/getTxAuthDataSignature.d.ts.map +1 -0
  22. package/dist/declarations/src/actions/validateWebhookEvent.d.ts +21 -0
  23. package/dist/declarations/src/actions/validateWebhookEvent.d.ts.map +1 -0
  24. package/dist/declarations/src/configuration/createSdk.d.ts +22 -0
  25. package/dist/declarations/src/configuration/createSdk.d.ts.map +1 -0
  26. package/dist/declarations/src/configuration/index.d.ts +2 -0
  27. package/dist/declarations/src/configuration/index.d.ts.map +1 -0
  28. package/dist/declarations/src/errors/ApiKeyNotProvidedError.d.ts +7 -0
  29. package/dist/declarations/src/errors/ApiKeyNotProvidedError.d.ts.map +1 -0
  30. package/dist/declarations/src/errors/WebhookEventDataNotSupportedByThisSdkVersion.d.ts +7 -0
  31. package/dist/declarations/src/errors/WebhookEventDataNotSupportedByThisSdkVersion.d.ts.map +1 -0
  32. package/dist/declarations/src/errors/WebhookSecretNotProvidedError.d.ts +7 -0
  33. package/dist/declarations/src/errors/WebhookSecretNotProvidedError.d.ts.map +1 -0
  34. package/dist/declarations/src/errors/WebhookSignatureInvalid.d.ts +7 -0
  35. package/dist/declarations/src/errors/WebhookSignatureInvalid.d.ts.map +1 -0
  36. package/dist/declarations/src/errors/index.d.ts +5 -0
  37. package/dist/declarations/src/errors/index.d.ts.map +1 -0
  38. package/dist/declarations/src/index.d.ts +5 -0
  39. package/dist/declarations/src/index.d.ts.map +1 -0
  40. package/dist/declarations/src/utils/index.d.ts +2 -0
  41. package/dist/declarations/src/utils/index.d.ts.map +1 -0
  42. package/dist/declarations/src/utils/internal.d.ts +17 -0
  43. package/dist/declarations/src/utils/internal.d.ts.map +1 -0
  44. package/dist/package.json +60 -0
  45. package/package.json +59 -0
  46. package/readme.md +69 -0
@@ -0,0 +1,1376 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var apiClient = require('@nexeraid/api-client');
6
+ var identityApiClient = require('@nexeraid/identity-api-client');
7
+ var logger = require('@nexeraid/logger');
8
+ var identitySchemas = require('@nexeraid/identity-schemas');
9
+ var zod = require('zod');
10
+ var webhooks = require('@nexeraid/identity-schemas/webhooks');
11
+ var svix = require('svix');
12
+
13
+ function _regeneratorRuntime() {
14
+ _regeneratorRuntime = function () {
15
+ return e;
16
+ };
17
+ var t,
18
+ e = {},
19
+ r = Object.prototype,
20
+ n = r.hasOwnProperty,
21
+ o = Object.defineProperty || function (t, e, r) {
22
+ t[e] = r.value;
23
+ },
24
+ i = "function" == typeof Symbol ? Symbol : {},
25
+ a = i.iterator || "@@iterator",
26
+ c = i.asyncIterator || "@@asyncIterator",
27
+ u = i.toStringTag || "@@toStringTag";
28
+ function define(t, e, r) {
29
+ return Object.defineProperty(t, e, {
30
+ value: r,
31
+ enumerable: !0,
32
+ configurable: !0,
33
+ writable: !0
34
+ }), t[e];
35
+ }
36
+ try {
37
+ define({}, "");
38
+ } catch (t) {
39
+ define = function (t, e, r) {
40
+ return t[e] = r;
41
+ };
42
+ }
43
+ function wrap(t, e, r, n) {
44
+ var i = e && e.prototype instanceof Generator ? e : Generator,
45
+ a = Object.create(i.prototype),
46
+ c = new Context(n || []);
47
+ return o(a, "_invoke", {
48
+ value: makeInvokeMethod(t, r, c)
49
+ }), a;
50
+ }
51
+ function tryCatch(t, e, r) {
52
+ try {
53
+ return {
54
+ type: "normal",
55
+ arg: t.call(e, r)
56
+ };
57
+ } catch (t) {
58
+ return {
59
+ type: "throw",
60
+ arg: t
61
+ };
62
+ }
63
+ }
64
+ e.wrap = wrap;
65
+ var h = "suspendedStart",
66
+ l = "suspendedYield",
67
+ f = "executing",
68
+ s = "completed",
69
+ y = {};
70
+ function Generator() {}
71
+ function GeneratorFunction() {}
72
+ function GeneratorFunctionPrototype() {}
73
+ var p = {};
74
+ define(p, a, function () {
75
+ return this;
76
+ });
77
+ var d = Object.getPrototypeOf,
78
+ v = d && d(d(values([])));
79
+ v && v !== r && n.call(v, a) && (p = v);
80
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
81
+ function defineIteratorMethods(t) {
82
+ ["next", "throw", "return"].forEach(function (e) {
83
+ define(t, e, function (t) {
84
+ return this._invoke(e, t);
85
+ });
86
+ });
87
+ }
88
+ function AsyncIterator(t, e) {
89
+ function invoke(r, o, i, a) {
90
+ var c = tryCatch(t[r], t, o);
91
+ if ("throw" !== c.type) {
92
+ var u = c.arg,
93
+ h = u.value;
94
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
95
+ invoke("next", t, i, a);
96
+ }, function (t) {
97
+ invoke("throw", t, i, a);
98
+ }) : e.resolve(h).then(function (t) {
99
+ u.value = t, i(u);
100
+ }, function (t) {
101
+ return invoke("throw", t, i, a);
102
+ });
103
+ }
104
+ a(c.arg);
105
+ }
106
+ var r;
107
+ o(this, "_invoke", {
108
+ value: function (t, n) {
109
+ function callInvokeWithMethodAndArg() {
110
+ return new e(function (e, r) {
111
+ invoke(t, n, e, r);
112
+ });
113
+ }
114
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
115
+ }
116
+ });
117
+ }
118
+ function makeInvokeMethod(e, r, n) {
119
+ var o = h;
120
+ return function (i, a) {
121
+ if (o === f) throw Error("Generator is already running");
122
+ if (o === s) {
123
+ if ("throw" === i) throw a;
124
+ return {
125
+ value: t,
126
+ done: !0
127
+ };
128
+ }
129
+ for (n.method = i, n.arg = a;;) {
130
+ var c = n.delegate;
131
+ if (c) {
132
+ var u = maybeInvokeDelegate(c, n);
133
+ if (u) {
134
+ if (u === y) continue;
135
+ return u;
136
+ }
137
+ }
138
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
139
+ if (o === h) throw o = s, n.arg;
140
+ n.dispatchException(n.arg);
141
+ } else "return" === n.method && n.abrupt("return", n.arg);
142
+ o = f;
143
+ var p = tryCatch(e, r, n);
144
+ if ("normal" === p.type) {
145
+ if (o = n.done ? s : l, p.arg === y) continue;
146
+ return {
147
+ value: p.arg,
148
+ done: n.done
149
+ };
150
+ }
151
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
152
+ }
153
+ };
154
+ }
155
+ function maybeInvokeDelegate(e, r) {
156
+ var n = r.method,
157
+ o = e.iterator[n];
158
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
159
+ var i = tryCatch(o, e.iterator, r.arg);
160
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
161
+ var a = i.arg;
162
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
163
+ }
164
+ function pushTryEntry(t) {
165
+ var e = {
166
+ tryLoc: t[0]
167
+ };
168
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
169
+ }
170
+ function resetTryEntry(t) {
171
+ var e = t.completion || {};
172
+ e.type = "normal", delete e.arg, t.completion = e;
173
+ }
174
+ function Context(t) {
175
+ this.tryEntries = [{
176
+ tryLoc: "root"
177
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
178
+ }
179
+ function values(e) {
180
+ if (e || "" === e) {
181
+ var r = e[a];
182
+ if (r) return r.call(e);
183
+ if ("function" == typeof e.next) return e;
184
+ if (!isNaN(e.length)) {
185
+ var o = -1,
186
+ i = function next() {
187
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
188
+ return next.value = t, next.done = !0, next;
189
+ };
190
+ return i.next = i;
191
+ }
192
+ }
193
+ throw new TypeError(typeof e + " is not iterable");
194
+ }
195
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
196
+ value: GeneratorFunctionPrototype,
197
+ configurable: !0
198
+ }), o(GeneratorFunctionPrototype, "constructor", {
199
+ value: GeneratorFunction,
200
+ configurable: !0
201
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
202
+ var e = "function" == typeof t && t.constructor;
203
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
204
+ }, e.mark = function (t) {
205
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
206
+ }, e.awrap = function (t) {
207
+ return {
208
+ __await: t
209
+ };
210
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
211
+ return this;
212
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
213
+ void 0 === i && (i = Promise);
214
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
215
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
216
+ return t.done ? t.value : a.next();
217
+ });
218
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
219
+ return this;
220
+ }), define(g, "toString", function () {
221
+ return "[object Generator]";
222
+ }), e.keys = function (t) {
223
+ var e = Object(t),
224
+ r = [];
225
+ for (var n in e) r.push(n);
226
+ return r.reverse(), function next() {
227
+ for (; r.length;) {
228
+ var t = r.pop();
229
+ if (t in e) return next.value = t, next.done = !1, next;
230
+ }
231
+ return next.done = !0, next;
232
+ };
233
+ }, e.values = values, Context.prototype = {
234
+ constructor: Context,
235
+ reset: function (e) {
236
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
237
+ },
238
+ stop: function () {
239
+ this.done = !0;
240
+ var t = this.tryEntries[0].completion;
241
+ if ("throw" === t.type) throw t.arg;
242
+ return this.rval;
243
+ },
244
+ dispatchException: function (e) {
245
+ if (this.done) throw e;
246
+ var r = this;
247
+ function handle(n, o) {
248
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
249
+ }
250
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
251
+ var i = this.tryEntries[o],
252
+ a = i.completion;
253
+ if ("root" === i.tryLoc) return handle("end");
254
+ if (i.tryLoc <= this.prev) {
255
+ var c = n.call(i, "catchLoc"),
256
+ u = n.call(i, "finallyLoc");
257
+ if (c && u) {
258
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
259
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
260
+ } else if (c) {
261
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
262
+ } else {
263
+ if (!u) throw Error("try statement without catch or finally");
264
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
265
+ }
266
+ }
267
+ }
268
+ },
269
+ abrupt: function (t, e) {
270
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
271
+ var o = this.tryEntries[r];
272
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
273
+ var i = o;
274
+ break;
275
+ }
276
+ }
277
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
278
+ var a = i ? i.completion : {};
279
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
280
+ },
281
+ complete: function (t, e) {
282
+ if ("throw" === t.type) throw t.arg;
283
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
284
+ },
285
+ finish: function (t) {
286
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
287
+ var r = this.tryEntries[e];
288
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
289
+ }
290
+ },
291
+ catch: function (t) {
292
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
293
+ var r = this.tryEntries[e];
294
+ if (r.tryLoc === t) {
295
+ var n = r.completion;
296
+ if ("throw" === n.type) {
297
+ var o = n.arg;
298
+ resetTryEntry(r);
299
+ }
300
+ return o;
301
+ }
302
+ }
303
+ throw Error("illegal catch attempt");
304
+ },
305
+ delegateYield: function (e, r, n) {
306
+ return this.delegate = {
307
+ iterator: values(e),
308
+ resultName: r,
309
+ nextLoc: n
310
+ }, "next" === this.method && (this.arg = t), y;
311
+ }
312
+ }, e;
313
+ }
314
+
315
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
316
+ try {
317
+ var i = n[a](c),
318
+ u = i.value;
319
+ } catch (n) {
320
+ return void e(n);
321
+ }
322
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
323
+ }
324
+ function _asyncToGenerator(n) {
325
+ return function () {
326
+ var t = this,
327
+ e = arguments;
328
+ return new Promise(function (r, o) {
329
+ var a = n.apply(t, e);
330
+ function _next(n) {
331
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
332
+ }
333
+ function _throw(n) {
334
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
335
+ }
336
+ _next(void 0);
337
+ });
338
+ };
339
+ }
340
+
341
+ /**
342
+ * Attach additional information to a customer
343
+ */
344
+
345
+ zod.z.object({
346
+ externalCustomerId: identitySchemas.ExternalCustomerId,
347
+ information: identitySchemas.AdditionalCustomerInformationParams
348
+ });
349
+
350
+ /**
351
+ * Attach additional information to a customer
352
+ *
353
+ * @param params - The parameters required to attach the information
354
+ *
355
+ * @category Actions
356
+ *
357
+ * @example
358
+ *
359
+ * ```typescript
360
+ * import { createApiClient } from "@compilot/js-sdk";
361
+ *
362
+ * const apiClient = createApiClient({ apiKey });
363
+ *
364
+ * await apiClient.attachCustomerInformation({
365
+ * externalCustomerId: "123",
366
+ * information: {
367
+ * email: "test@test.com",
368
+ * phone: "+1234567890",
369
+ * wallet: {
370
+ * address: "tz1abc",
371
+ * namespace: "tezos",
372
+ * },
373
+ * }
374
+ * });
375
+ * ```
376
+ */
377
+
378
+ var attachCustomerInformationFactory = function attachCustomerInformationFactory(_ref) {
379
+ var logger = _ref.logger,
380
+ compilotApiClient = _ref.compilotApiClient;
381
+ var externalIdToCustomerIdMap = new Map();
382
+ var getCustomerId = /*#__PURE__*/function () {
383
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(externalCustomerId) {
384
+ var customer;
385
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
386
+ while (1) switch (_context.prev = _context.next) {
387
+ case 0:
388
+ if (externalIdToCustomerIdMap.has(externalCustomerId)) {
389
+ _context.next = 5;
390
+ break;
391
+ }
392
+ _context.next = 3;
393
+ return compilotApiClient.customers.publicRouterCustomerRouterGetCustomerByExternalCustomerId({
394
+ externalCustomerId: externalCustomerId
395
+ });
396
+ case 3:
397
+ customer = _context.sent;
398
+ externalIdToCustomerIdMap.set(externalCustomerId, customer.id);
399
+ case 5:
400
+ return _context.abrupt("return", externalIdToCustomerIdMap.get(externalCustomerId));
401
+ case 6:
402
+ case "end":
403
+ return _context.stop();
404
+ }
405
+ }, _callee);
406
+ }));
407
+ return function getCustomerId(_x) {
408
+ return _ref2.apply(this, arguments);
409
+ };
410
+ }();
411
+ return /*#__PURE__*/function () {
412
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
413
+ var customerId, emails, emailExists, _customerId, phones, phoneExists, _customerId2, wallet, wallets, walletExists;
414
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
415
+ while (1) switch (_context2.prev = _context2.next) {
416
+ case 0:
417
+ if (!params.information.email) {
418
+ _context2.next = 13;
419
+ break;
420
+ }
421
+ _context2.next = 3;
422
+ return getCustomerId(params.externalCustomerId);
423
+ case 3:
424
+ customerId = _context2.sent;
425
+ logger.debug({
426
+ msg: "Fetching emails for customer",
427
+ customerId: customerId
428
+ });
429
+ _context2.next = 7;
430
+ return compilotApiClient.customers.publicRouterCustomerRouterEmailsGetCustomerEmails({
431
+ customerId: customerId
432
+ });
433
+ case 7:
434
+ emails = _context2.sent;
435
+ emailExists = emails.some(function (row) {
436
+ return row.email === params.information.email;
437
+ });
438
+ if (emailExists) {
439
+ _context2.next = 13;
440
+ break;
441
+ }
442
+ logger.info({
443
+ msg: "Creating email for customer",
444
+ customerId: customerId
445
+ });
446
+ _context2.next = 13;
447
+ return compilotApiClient.customers.publicRouterCustomerRouterEmailsCreateCustomerEmail({
448
+ customerId: customerId,
449
+ requestBody: {
450
+ email: params.information.email
451
+ }
452
+ });
453
+ case 13:
454
+ if (!params.information.phone) {
455
+ _context2.next = 26;
456
+ break;
457
+ }
458
+ _context2.next = 16;
459
+ return getCustomerId(params.externalCustomerId);
460
+ case 16:
461
+ _customerId = _context2.sent;
462
+ logger.debug({
463
+ msg: "Fetching phones for customer",
464
+ customerId: _customerId
465
+ });
466
+ _context2.next = 20;
467
+ return compilotApiClient.customers.publicRouterCustomerRouterPhoneNumbersGetCustomerPhoneNumbers({
468
+ customerId: _customerId
469
+ });
470
+ case 20:
471
+ phones = _context2.sent;
472
+ phoneExists = phones.some(function (row) {
473
+ return row.phoneNumber === params.information.phone;
474
+ });
475
+ if (phoneExists) {
476
+ _context2.next = 26;
477
+ break;
478
+ }
479
+ logger.info({
480
+ msg: "Creating phone for customer",
481
+ customerId: _customerId
482
+ });
483
+ _context2.next = 26;
484
+ return compilotApiClient.customers.publicRouterCustomerRouterPhoneNumbersCreateCustomerPhoneNumber({
485
+ customerId: _customerId,
486
+ requestBody: {
487
+ phoneNumber: params.information.phone
488
+ }
489
+ });
490
+ case 26:
491
+ if (!params.information.wallet) {
492
+ _context2.next = 40;
493
+ break;
494
+ }
495
+ _context2.next = 29;
496
+ return getCustomerId(params.externalCustomerId);
497
+ case 29:
498
+ _customerId2 = _context2.sent;
499
+ logger.debug({
500
+ msg: "Fetching wallets for customer",
501
+ customerId: _customerId2
502
+ });
503
+ wallet = params.information.wallet;
504
+ _context2.next = 34;
505
+ return compilotApiClient.customers.publicRouterCustomerRouterWalletsGetCustomerWallets({
506
+ customerId: _customerId2
507
+ });
508
+ case 34:
509
+ wallets = _context2.sent;
510
+ walletExists = wallets.some(function (row) {
511
+ return row.wallet === wallet.address && row.blockchainNamespace === wallet.namespace;
512
+ });
513
+ if (walletExists) {
514
+ _context2.next = 40;
515
+ break;
516
+ }
517
+ logger.info("Creating wallet for customer", {
518
+ customerId: _customerId2
519
+ });
520
+ _context2.next = 40;
521
+ return compilotApiClient.customers.publicRouterCustomerRouterWalletsCreateCustomerWallet({
522
+ customerId: _customerId2,
523
+ requestBody: {
524
+ wallet: wallet.address,
525
+ blockchainNamespace: wallet.namespace
526
+ }
527
+ });
528
+ case 40:
529
+ case "end":
530
+ return _context2.stop();
531
+ }
532
+ }, _callee2);
533
+ }));
534
+ return function (_x2) {
535
+ return _ref3.apply(this, arguments);
536
+ };
537
+ }();
538
+ };
539
+
540
+ /**
541
+ * Create a new web2 session
542
+ * @param params The parameters to create the session with
543
+ * @returns A promise that resolves when the session is created
544
+ *
545
+ * @category Actions
546
+ *
547
+ * @example
548
+ *
549
+ * Basic usage:
550
+ *
551
+ * ```typescript
552
+ * import { createApiClient } from "@compilot/js-sdk";
553
+ *
554
+ * const apiClient = createApiClient({ apiKey });
555
+ *
556
+ * const sessionContent = await apiClient.createSession({
557
+ * workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
558
+ * externalCustomerId: "123",
559
+ * additionalInformation: {
560
+ * email: "test@test.com",
561
+ * phone: "+1234567890",
562
+ * wallet: {
563
+ * address: "tz1abc",
564
+ * namespace: "tezos",
565
+ * },
566
+ * }
567
+ * });
568
+ * ```
569
+ *
570
+ * More often used as part of an api to protect the api key.
571
+ * Please find below an example of how to use the createSession function in Next.js:
572
+ *
573
+ * ```typescript
574
+ * import { createApiClient } from "@compilot/js-sdk";
575
+ *
576
+ * const apiClient = createApiClient({ apiKey });
577
+ *
578
+ *
579
+ * export default async function handler(req: NextApiRequest, res: NextApiResponse ) {
580
+ * if (req.method !== "POST") {
581
+ * res.setHeader("Allow", ["POST"]);
582
+ * res.status(405).end(`Method ${req.method} Not Allowed`);
583
+ * return;
584
+ * }
585
+ *
586
+ * const sessionRes = await apiClient.createSession({
587
+ * workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
588
+ * externalCustomerId: req.session.externalCustomerId,
589
+ * });
590
+ *
591
+ * // Return the session to the client
592
+ * res.status(200).json(sessionRes);
593
+ * }
594
+ * ```
595
+ */
596
+
597
+ var createWeb2SessionFactory = function createWeb2SessionFactory(deps) {
598
+ return /*#__PURE__*/function () {
599
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
600
+ var res;
601
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
602
+ while (1) switch (_context.prev = _context.next) {
603
+ case 0:
604
+ _context.next = 2;
605
+ return deps.identityApiClient.auth.createSession({
606
+ requestBody: params
607
+ });
608
+ case 2:
609
+ res = _context.sent;
610
+ return _context.abrupt("return", res);
611
+ case 4:
612
+ case "end":
613
+ return _context.stop();
614
+ }
615
+ }, _callee);
616
+ }));
617
+ return function (_x) {
618
+ return _ref.apply(this, arguments);
619
+ };
620
+ }();
621
+ };
622
+
623
+ /**
624
+ * Create a challenge for a wallet. The web-sdk will use this to sign a message and prove ownership of a wallet.
625
+ *
626
+ * @param params The parameters to create the challenge with
627
+ * @returns A promise that resolves to the challenge content
628
+ *
629
+ * @category Actions
630
+ *
631
+ * @example
632
+ *
633
+ * Basic usage:
634
+ *
635
+ * ```typescript
636
+ * import { createApiClient } from "@compilot/js-sdk";
637
+ *
638
+ * const apiClient = createApiClient({ apiKey });
639
+ *
640
+ * const challengeContent = await apiClient.createWeb3Challenge({
641
+ * address: "0xabc",
642
+ * namespace: "eip155",
643
+ * blockchainId: "1",
644
+ * origin: "https://example.com",
645
+ * workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
646
+ * externalCustomerId: "123",
647
+ * });
648
+ * ```
649
+ *
650
+ * More often used as part of an api to protect the api key.
651
+ * Please find below an example of how to use the createWeb3Challenge function in Next.js:
652
+ *
653
+ * ```typescript
654
+ * import { createApiClient } from "@compilot/js-sdk";
655
+ *
656
+ * const apiClient = createApiClient({ apiKey });
657
+ *
658
+ * export default async function handler(req: NextApiRequest, res: NextApiResponse ) {
659
+ * if (req.method !== "POST") {
660
+ * res.setHeader("Allow", ["POST"]);
661
+ * res.status(405).end(`Method ${req.method} Not Allowed`);
662
+ * return;
663
+ * }
664
+ *
665
+ * const challengeContent = await apiClient.createWeb3Challenge({
666
+ * address: "0xabc",
667
+ * namespace: "eip155",
668
+ * blockchainId: "1",
669
+ * origin: "https://example.com",
670
+ * workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
671
+ * externalCustomerId: "123",
672
+ * });
673
+ *
674
+ * // Return the challenge to the client
675
+ * res.status(200).json(challengeRes);
676
+ * }
677
+ * ```
678
+ */
679
+
680
+ var createWeb3ChallengeFactory = function createWeb3ChallengeFactory(deps) {
681
+ return /*#__PURE__*/function () {
682
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
683
+ var res;
684
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
685
+ while (1) switch (_context.prev = _context.next) {
686
+ case 0:
687
+ _context.next = 2;
688
+ return deps.identityApiClient.auth.createWalletChallenge({
689
+ requestBody: params
690
+ });
691
+ case 2:
692
+ res = _context.sent;
693
+ return _context.abrupt("return", res);
694
+ case 4:
695
+ case "end":
696
+ return _context.stop();
697
+ }
698
+ }, _callee);
699
+ }));
700
+ return function (_x) {
701
+ return _ref.apply(this, arguments);
702
+ };
703
+ }();
704
+ };
705
+
706
+ /**
707
+ * Get the status of a customer by their customer ID
708
+ *
709
+ * @param params - The parameters required to get the customer status
710
+ * @returns The status of the customer
711
+ *
712
+ * @category Actions
713
+ *
714
+ * @example
715
+ * ```typescript
716
+ *
717
+ * import { createApiClient } from "@compilot/js-sdk";
718
+ *
719
+ * const apiClient = createApiClient({ apiKey });
720
+ *
721
+ * const customerStatus = await apiClient.getCustomerStatusByCustomerId({
722
+ * customerId: "123",
723
+ * });
724
+ * ```
725
+ */
726
+
727
+ var getCustomerStatusByCustomerIdFactory = function getCustomerStatusByCustomerIdFactory(deps) {
728
+ return /*#__PURE__*/function () {
729
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
730
+ var customer;
731
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
732
+ while (1) switch (_context.prev = _context.next) {
733
+ case 0:
734
+ _context.next = 2;
735
+ return deps.compilotApiClient.customers.publicRouterCustomerRouterGetCustomerDetails({
736
+ id: params.customerId
737
+ });
738
+ case 2:
739
+ customer = _context.sent;
740
+ return _context.abrupt("return", customer.status);
741
+ case 4:
742
+ case "end":
743
+ return _context.stop();
744
+ }
745
+ }, _callee);
746
+ }));
747
+ return function (_x) {
748
+ return _ref.apply(this, arguments);
749
+ };
750
+ }();
751
+ };
752
+
753
+ /**
754
+ * Get the status of a customer by their external customer ID
755
+ *
756
+ * @param params - The parameters required to get the customer status
757
+ * @returns The status of the customer
758
+ *
759
+ * @category Actions
760
+ *
761
+ * @example
762
+ * ```typescript
763
+ *
764
+ * import { createApiClient } from "@compilot/js-sdk";
765
+ *
766
+ * const apiClient = createApiClient({ apiKey });
767
+ *
768
+ * const customerStatus = await apiClient.getCustomerStatusByExternalCustomerId({
769
+ * externalCustomerId: "123",
770
+ * });
771
+ * ```
772
+ */
773
+
774
+ var getCustomerStatusByExternalCustomerIdFactory = function getCustomerStatusByExternalCustomerIdFactory(deps) {
775
+ return /*#__PURE__*/function () {
776
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
777
+ var customer;
778
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
779
+ while (1) switch (_context.prev = _context.next) {
780
+ case 0:
781
+ _context.next = 2;
782
+ return deps.compilotApiClient.customers.publicRouterCustomerRouterGetCustomerByExternalCustomerId(params);
783
+ case 2:
784
+ customer = _context.sent;
785
+ return _context.abrupt("return", customer.status);
786
+ case 4:
787
+ case "end":
788
+ return _context.stop();
789
+ }
790
+ }, _callee);
791
+ }));
792
+ return function (_x) {
793
+ return _ref.apply(this, arguments);
794
+ };
795
+ }();
796
+ };
797
+
798
+ /**
799
+ * Get the status of a customer by their wallet address
800
+ *
801
+ * @param params - The parameters required to get the customer status
802
+ * @returns The status of the customer
803
+ *
804
+ * @category Actions
805
+ *
806
+ * @example
807
+ * ```typescript
808
+ * import { createApiClient } from "@compilot/js-sdk";
809
+ *
810
+ * const apiClient = createApiClient({ apiKey });
811
+ *
812
+ * const customerStatus = await apiClient.getCustomerStatusByWallet({
813
+ * walletAddress: "tz1abc",
814
+ * workspaceId: "123",
815
+ * });
816
+ */
817
+
818
+ var getCustomerStatusByWalletFactory = function getCustomerStatusByWalletFactory(deps) {
819
+ return /*#__PURE__*/function () {
820
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
821
+ var customer;
822
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
823
+ while (1) switch (_context.prev = _context.next) {
824
+ case 0:
825
+ _context.next = 2;
826
+ return deps.compilotApiClient.customers.publicRouterCustomerRouterGetCustomerByProjectAndWalletAddress({
827
+ address: params.walletAddress,
828
+ cmsProjectId: params.workspaceId
829
+ });
830
+ case 2:
831
+ customer = _context.sent;
832
+ return _context.abrupt("return", customer.status);
833
+ case 4:
834
+ case "end":
835
+ return _context.stop();
836
+ }
837
+ }, _callee);
838
+ }));
839
+ return function (_x) {
840
+ return _ref.apply(this, arguments);
841
+ };
842
+ }();
843
+ };
844
+
845
+ /**
846
+ * Get the wallets of a customer
847
+ *
848
+ * @param params - The parameters required to get the wallets
849
+ * @returns The wallets of the customer
850
+ *
851
+ * @category Actions
852
+ *
853
+ * @example
854
+ * ```typescript
855
+ * import { createApiClient } from "@compilot/js-sdk";
856
+ *
857
+ * const apiClient = createApiClient({ apiKey });
858
+ *
859
+ * const wallets = await apiClient.getCustomerWallets({
860
+ * customerId: "123",
861
+ * });
862
+ * ```
863
+ */
864
+
865
+ var getCustomerWalletsFactory = function getCustomerWalletsFactory(deps) {
866
+ return /*#__PURE__*/function () {
867
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
868
+ var customer;
869
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
870
+ while (1) switch (_context.prev = _context.next) {
871
+ case 0:
872
+ _context.next = 2;
873
+ return deps.compilotApiClient.customers.publicRouterCustomerRouterWalletsGetCustomerWallets({
874
+ customerId: params.customerId
875
+ });
876
+ case 2:
877
+ customer = _context.sent;
878
+ return _context.abrupt("return", customer.map(function (wallet) {
879
+ return {
880
+ address: wallet.wallet,
881
+ chain: wallet.blockchainNamespace,
882
+ verified: !!wallet.verified
883
+ };
884
+ }));
885
+ case 4:
886
+ case "end":
887
+ return _context.stop();
888
+ }
889
+ }, _callee);
890
+ }));
891
+ return function (_x) {
892
+ return _ref.apply(this, arguments);
893
+ };
894
+ }();
895
+ };
896
+
897
+ function _toPrimitive(t, r) {
898
+ if ("object" != typeof t || !t) return t;
899
+ var e = t[Symbol.toPrimitive];
900
+ if (void 0 !== e) {
901
+ var i = e.call(t, r || "default");
902
+ if ("object" != typeof i) return i;
903
+ throw new TypeError("@@toPrimitive must return a primitive value.");
904
+ }
905
+ return ("string" === r ? String : Number)(t);
906
+ }
907
+
908
+ function _toPropertyKey(t) {
909
+ var i = _toPrimitive(t, "string");
910
+ return "symbol" == typeof i ? i : i + "";
911
+ }
912
+
913
+ function _defineProperty(e, r, t) {
914
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
915
+ value: t,
916
+ enumerable: !0,
917
+ configurable: !0,
918
+ writable: !0
919
+ }) : e[r] = t, e;
920
+ }
921
+
922
+ function ownKeys(e, r) {
923
+ var t = Object.keys(e);
924
+ if (Object.getOwnPropertySymbols) {
925
+ var o = Object.getOwnPropertySymbols(e);
926
+ r && (o = o.filter(function (r) {
927
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
928
+ })), t.push.apply(t, o);
929
+ }
930
+ return t;
931
+ }
932
+ function _objectSpread2(e) {
933
+ for (var r = 1; r < arguments.length; r++) {
934
+ var t = null != arguments[r] ? arguments[r] : {};
935
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
936
+ _defineProperty(e, r, t[r]);
937
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
938
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
939
+ });
940
+ }
941
+ return e;
942
+ }
943
+
944
+ /**
945
+ * Get the signature of the transaction authorization data
946
+ *
947
+ * @param params - The parameters required to get the transaction authorization data signature
948
+ * @returns The signature of the transaction authorization data
949
+ *
950
+ * @category Actions
951
+ *
952
+ * @example
953
+ *
954
+ * Eip155:
955
+ * ```typescript
956
+ * import { createApiClient } from "@compilot/js-sdk";
957
+ *
958
+ * const apiClient = createApiClient({ apiKey });
959
+ *
960
+ * const txAuthDataSignature = await apiClient.getTxAuthDataSignature({
961
+ * namespace: "eip155",
962
+ * contractAbi: ExampleGatedNFTMinterABI,
963
+ * contractAddress: "0x123",
964
+ * functionName: "mintNFTGated",
965
+ * args: [account.address],
966
+ * userAddress: account.address,
967
+ * chainId: EvmChainId.parse(chainId),
968
+ * });
969
+ *
970
+ * if (!signatureResponse.isAuthorized) {
971
+ * throw new Error("User is not authorized");
972
+ * }
973
+ *
974
+ * // Mint Gated Nft with signature
975
+ * const unsignedTx = encodeFunctionData({
976
+ * abi: contractAbi,
977
+ * functionName: "mintNFTGated",
978
+ * args: [account.address],
979
+ * });
980
+ *
981
+ * // Build the raw transaction data with the signature
982
+ * const txData = (unsignedTx + signatureResponse.payload) as `0x${string}`;
983
+ *
984
+ * // try to mint nft
985
+ * const tx = await walletClient.data.sendTransaction({
986
+ * to: contractAddress,
987
+ * data: txData,
988
+ * });
989
+ * ```
990
+ */
991
+
992
+ var getTxAuthDataSignatureFactory = function getTxAuthDataSignatureFactory(deps) {
993
+ // use a mapping so we get a type error here when we add a new namespace
994
+ var mapping = {
995
+ eip155: function () {
996
+ var _eip = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
997
+ var res;
998
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
999
+ while (1) switch (_context.prev = _context.next) {
1000
+ case 0:
1001
+ if (!(params.namespace !== "eip155")) {
1002
+ _context.next = 2;
1003
+ break;
1004
+ }
1005
+ throw new Error("Unsupported namespace: ".concat(params.namespace));
1006
+ case 2:
1007
+ _context.next = 4;
1008
+ return deps.compilotApiClient.customers.publicRouterCustomerRouterGetTxAuthDataSignature({
1009
+ requestBody: params
1010
+ });
1011
+ case 4:
1012
+ res = _context.sent;
1013
+ return _context.abrupt("return", identitySchemas.ExtendedTxAuthDataSignatureResponse.parse(_objectSpread2({
1014
+ namespace: params.namespace,
1015
+ userAddress: params.userAddress
1016
+ }, res)));
1017
+ case 6:
1018
+ case "end":
1019
+ return _context.stop();
1020
+ }
1021
+ }, _callee);
1022
+ }));
1023
+ function eip155(_x) {
1024
+ return _eip.apply(this, arguments);
1025
+ }
1026
+ return eip155;
1027
+ }(),
1028
+ tezos: function () {
1029
+ var _tezos = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
1030
+ var res;
1031
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1032
+ while (1) switch (_context2.prev = _context2.next) {
1033
+ case 0:
1034
+ if (!(params.namespace !== "tezos")) {
1035
+ _context2.next = 2;
1036
+ break;
1037
+ }
1038
+ throw new Error("Unsupported namespace: ".concat(params.namespace));
1039
+ case 2:
1040
+ _context2.next = 4;
1041
+ return deps.compilotApiClient.customers.publicRouterCustomerRouterGetTezosTxAuthDataSignature({
1042
+ requestBody: params
1043
+ });
1044
+ case 4:
1045
+ res = _context2.sent;
1046
+ return _context2.abrupt("return", identitySchemas.ExtendedTezosTxAuthDataSignatureResponse.parse(_objectSpread2({
1047
+ namespace: params.namespace,
1048
+ userAddress: params.userAddress
1049
+ }, res)));
1050
+ case 6:
1051
+ case "end":
1052
+ return _context2.stop();
1053
+ }
1054
+ }, _callee2);
1055
+ }));
1056
+ function tezos(_x2) {
1057
+ return _tezos.apply(this, arguments);
1058
+ }
1059
+ return tezos;
1060
+ }()
1061
+ };
1062
+ return function (params) {
1063
+ var signer = mapping[params.namespace];
1064
+ if (!signer) {
1065
+ throw new Error("Unsupported namespace: ".concat(params.namespace));
1066
+ }
1067
+
1068
+ // It's ok to do this as this line is typed as the return type of the
1069
+ // factory and the mapping is typed to only accept the correct namespaces
1070
+ // eslint-disable-next-line
1071
+ return signer(params);
1072
+ };
1073
+ };
1074
+
1075
+ function _defineProperties(e, r) {
1076
+ for (var t = 0; t < r.length; t++) {
1077
+ var o = r[t];
1078
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
1079
+ }
1080
+ }
1081
+ function _createClass(e, r, t) {
1082
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
1083
+ writable: !1
1084
+ }), e;
1085
+ }
1086
+
1087
+ function _classCallCheck(a, n) {
1088
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
1089
+ }
1090
+
1091
+ function _getPrototypeOf(t) {
1092
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
1093
+ return t.__proto__ || Object.getPrototypeOf(t);
1094
+ }, _getPrototypeOf(t);
1095
+ }
1096
+
1097
+ function _isNativeReflectConstruct() {
1098
+ try {
1099
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
1100
+ } catch (t) {}
1101
+ return (_isNativeReflectConstruct = function () {
1102
+ return !!t;
1103
+ })();
1104
+ }
1105
+
1106
+ function _assertThisInitialized(e) {
1107
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1108
+ return e;
1109
+ }
1110
+
1111
+ function _possibleConstructorReturn(t, e) {
1112
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
1113
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
1114
+ return _assertThisInitialized(t);
1115
+ }
1116
+
1117
+ function _callSuper(t, o, e) {
1118
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
1119
+ }
1120
+
1121
+ function _setPrototypeOf(t, e) {
1122
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
1123
+ return t.__proto__ = e, t;
1124
+ }, _setPrototypeOf(t, e);
1125
+ }
1126
+
1127
+ function _inherits(t, e) {
1128
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
1129
+ t.prototype = Object.create(e && e.prototype, {
1130
+ constructor: {
1131
+ value: t,
1132
+ writable: !0,
1133
+ configurable: !0
1134
+ }
1135
+ }), Object.defineProperty(t, "prototype", {
1136
+ writable: !1
1137
+ }), e && _setPrototypeOf(t, e);
1138
+ }
1139
+
1140
+ function _isNativeFunction(t) {
1141
+ try {
1142
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
1143
+ } catch (n) {
1144
+ return "function" == typeof t;
1145
+ }
1146
+ }
1147
+
1148
+ function _construct(t, e, r) {
1149
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
1150
+ var o = [null];
1151
+ o.push.apply(o, e);
1152
+ var p = new (t.bind.apply(t, o))();
1153
+ return r && _setPrototypeOf(p, r.prototype), p;
1154
+ }
1155
+
1156
+ function _wrapNativeSuper(t) {
1157
+ var r = "function" == typeof Map ? new Map() : void 0;
1158
+ return _wrapNativeSuper = function (t) {
1159
+ if (null === t || !_isNativeFunction(t)) return t;
1160
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
1161
+ if (void 0 !== r) {
1162
+ if (r.has(t)) return r.get(t);
1163
+ r.set(t, Wrapper);
1164
+ }
1165
+ function Wrapper() {
1166
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
1167
+ }
1168
+ return Wrapper.prototype = Object.create(t.prototype, {
1169
+ constructor: {
1170
+ value: Wrapper,
1171
+ enumerable: !1,
1172
+ writable: !0,
1173
+ configurable: !0
1174
+ }
1175
+ }), _setPrototypeOf(Wrapper, t);
1176
+ }, _wrapNativeSuper(t);
1177
+ }
1178
+
1179
+ /**
1180
+ * Error thrown when the webhook event data is invalid.
1181
+ */
1182
+ var WebhookEventDataNotSupportedByThisSdkVersion = /*#__PURE__*/function (_Error) {
1183
+ function WebhookEventDataNotSupportedByThisSdkVersion() {
1184
+ _classCallCheck(this, WebhookEventDataNotSupportedByThisSdkVersion);
1185
+ return _callSuper(this, WebhookEventDataNotSupportedByThisSdkVersion, ["Webhook event data is not supported by this sdk version. You need to update the js-sdk to the latest version."]);
1186
+ }
1187
+ _inherits(WebhookEventDataNotSupportedByThisSdkVersion, _Error);
1188
+ return _createClass(WebhookEventDataNotSupportedByThisSdkVersion);
1189
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1190
+
1191
+ /**
1192
+ * Error thrown when webhook secret is not provided.
1193
+ */
1194
+ var WebhookSecretNotProvidedError = /*#__PURE__*/function (_Error) {
1195
+ function WebhookSecretNotProvidedError() {
1196
+ _classCallCheck(this, WebhookSecretNotProvidedError);
1197
+ return _callSuper(this, WebhookSecretNotProvidedError, ["Webhook secret is not provided. Please provide a webhook secret to use this SDK."]);
1198
+ }
1199
+ _inherits(WebhookSecretNotProvidedError, _Error);
1200
+ return _createClass(WebhookSecretNotProvidedError);
1201
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1202
+
1203
+ /**
1204
+ * Error thrown when the webhook signature is invalid.
1205
+ */
1206
+ var WebhookSignatureInvalid = /*#__PURE__*/function (_Error) {
1207
+ function WebhookSignatureInvalid() {
1208
+ _classCallCheck(this, WebhookSignatureInvalid);
1209
+ return _callSuper(this, WebhookSignatureInvalid, ["Webhook signature is invalid. Either the provided webhook secret is incorrect, or this event is not from ComPilot."]);
1210
+ }
1211
+ _inherits(WebhookSignatureInvalid, _Error);
1212
+ return _createClass(WebhookSignatureInvalid);
1213
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1214
+
1215
+ /**
1216
+ * Validate a webhook event and return the event type
1217
+ *
1218
+ * @param params.headers The headers of the webhook request. We are only interested in the `svix-*` header
1219
+ * @param params.body The body of the webhook request
1220
+ *
1221
+ * @throws {WebhookSignatureInvalid} If the webhook event is invalid
1222
+ *
1223
+ * @returns The parsed webhook event
1224
+ */
1225
+
1226
+ var validateWebhookEventFactory = function validateWebhookEventFactory(_ref) {
1227
+ var logger = _ref.logger,
1228
+ webhookSecret = _ref.webhookSecret;
1229
+ var wh = null;
1230
+ return function (_ref2) {
1231
+ var headers = _ref2.headers,
1232
+ body = _ref2.body;
1233
+ if (!webhookSecret || webhookSecret === "") {
1234
+ throw new WebhookSecretNotProvidedError();
1235
+ }
1236
+ if (!wh) {
1237
+ wh = new svix.Webhook(webhookSecret);
1238
+ }
1239
+ var verifiedPayload;
1240
+ try {
1241
+ var bodyStr = typeof body === "string" ? body : JSON.stringify(body);
1242
+ verifiedPayload = wh.verify(bodyStr, headers);
1243
+ } catch (e) {
1244
+ logger.trace(e);
1245
+ logger.error({
1246
+ msg: "Failed to verify webhook event",
1247
+ e: e
1248
+ });
1249
+ throw new WebhookSignatureInvalid();
1250
+ }
1251
+ var bodyObj = typeof verifiedPayload === "string" ? JSON.parse(verifiedPayload) : verifiedPayload;
1252
+ var parsedPayloadRes = webhooks.WebhookEventPayload.safeParse(bodyObj);
1253
+ if (!parsedPayloadRes.success) {
1254
+ logger.trace(parsedPayloadRes.error);
1255
+ logger.error({
1256
+ msg: "Failed to parse webhook event",
1257
+ error: parsedPayloadRes.error
1258
+ });
1259
+ throw new WebhookEventDataNotSupportedByThisSdkVersion();
1260
+ }
1261
+ return parsedPayloadRes.data;
1262
+ };
1263
+ };
1264
+
1265
+ /**
1266
+ * Error thrown when API key is not provided.
1267
+ */
1268
+ var ApiKeyNotProvidedError = /*#__PURE__*/function (_Error) {
1269
+ function ApiKeyNotProvidedError() {
1270
+ _classCallCheck(this, ApiKeyNotProvidedError);
1271
+ return _callSuper(this, ApiKeyNotProvidedError, ["API key is not provided. Please provide an API key to use this SDK."]);
1272
+ }
1273
+ _inherits(ApiKeyNotProvidedError, _Error);
1274
+ return _createClass(ApiKeyNotProvidedError);
1275
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1276
+
1277
+ /**
1278
+ * @private exclude from documentation
1279
+ */
1280
+
1281
+ /**
1282
+ * default internal config is prod
1283
+ * @private exclude from documentation
1284
+ */
1285
+ var internalConfig = {
1286
+ env: "prod"
1287
+ };
1288
+
1289
+ /**
1290
+ * @private exclude from documentation
1291
+ */
1292
+ var _setInternalConfig = function _setInternalConfig(config) {
1293
+ Object.assign(internalConfig, config);
1294
+ };
1295
+
1296
+ /**
1297
+ * @private exclude from documentation
1298
+ */
1299
+ var getEnv = function getEnv() {
1300
+ return internalConfig.env;
1301
+ };
1302
+
1303
+ /**
1304
+ * Create an API client for the ComPilot API
1305
+ *
1306
+ * @param config.apiKey The API key to use for the client
1307
+ * @returns The API client
1308
+ */
1309
+ var createSdk = function createSdk(_ref) {
1310
+ var apiKey = _ref.apiKey,
1311
+ webhookSecret = _ref.webhookSecret;
1312
+ if (!apiKey) {
1313
+ throw new ApiKeyNotProvidedError();
1314
+ }
1315
+ var logger$1 = logger.createLogger({
1316
+ name: "js-sdk"
1317
+ });
1318
+ var compilotApiClient = apiClient.createNexeraAPIClient({
1319
+ env: getEnv(),
1320
+ credentials: {
1321
+ apiKey: apiKey
1322
+ },
1323
+ type: "project"
1324
+ });
1325
+ var identityApiClient$1 = identityApiClient.createIdentityApiClient({
1326
+ env: getEnv(),
1327
+ apiKey: apiKey
1328
+ });
1329
+ return {
1330
+ createWeb3Challenge: createWeb3ChallengeFactory({
1331
+ identityApiClient: identityApiClient$1
1332
+ }),
1333
+ createSession: createWeb2SessionFactory({
1334
+ identityApiClient: identityApiClient$1
1335
+ }),
1336
+ getTxAuthDataSignature: getTxAuthDataSignatureFactory({
1337
+ compilotApiClient: compilotApiClient
1338
+ }),
1339
+ attachCustomerInformation: attachCustomerInformationFactory({
1340
+ logger: logger$1,
1341
+ compilotApiClient: compilotApiClient
1342
+ }),
1343
+ getCustomerStatusByExternalCustomerId: getCustomerStatusByExternalCustomerIdFactory({
1344
+ compilotApiClient: compilotApiClient
1345
+ }),
1346
+ getCustomerStatusByWallet: getCustomerStatusByWalletFactory({
1347
+ compilotApiClient: compilotApiClient
1348
+ }),
1349
+ getCustomerStatusByCustomerId: getCustomerStatusByCustomerIdFactory({
1350
+ compilotApiClient: compilotApiClient
1351
+ }),
1352
+ getCustomerWallets: getCustomerWalletsFactory({
1353
+ compilotApiClient: compilotApiClient
1354
+ }),
1355
+ validateWebhookEvent: validateWebhookEventFactory({
1356
+ webhookSecret: webhookSecret,
1357
+ logger: logger$1
1358
+ })
1359
+ };
1360
+ };
1361
+
1362
+ Object.defineProperty(exports, 'WalletChallengeRequest', {
1363
+ enumerable: true,
1364
+ get: function () { return identitySchemas.WalletChallengeRequest; }
1365
+ });
1366
+ Object.defineProperty(exports, 'AllNexeraEventTypes', {
1367
+ enumerable: true,
1368
+ get: function () { return webhooks.AllNexeraEventTypes; }
1369
+ });
1370
+ exports.ApiKeyNotProvidedError = ApiKeyNotProvidedError;
1371
+ exports.WebhookEventDataNotSupportedByThisSdkVersion = WebhookEventDataNotSupportedByThisSdkVersion;
1372
+ exports.WebhookSecretNotProvidedError = WebhookSecretNotProvidedError;
1373
+ exports.WebhookSignatureInvalid = WebhookSignatureInvalid;
1374
+ exports._setInternalConfig = _setInternalConfig;
1375
+ exports.createSdk = createSdk;
1376
+ exports.getEnv = getEnv;