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