@compilot/react-sdk 2.0.48-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 (28) hide show
  1. package/dist/compilot-react-sdk.cjs.d.ts +2 -0
  2. package/dist/compilot-react-sdk.cjs.dev.js +1021 -0
  3. package/dist/compilot-react-sdk.cjs.js +7 -0
  4. package/dist/compilot-react-sdk.cjs.prod.js +1021 -0
  5. package/dist/compilot-react-sdk.esm.js +1006 -0
  6. package/dist/declarations/src/configuration/ComPilotProvider.d.ts +67 -0
  7. package/dist/declarations/src/configuration/ComPilotProvider.d.ts.map +1 -0
  8. package/dist/declarations/src/hooks/index.d.ts +6 -0
  9. package/dist/declarations/src/hooks/index.d.ts.map +1 -0
  10. package/dist/declarations/src/hooks/useCustomerStatus.d.ts +42 -0
  11. package/dist/declarations/src/hooks/useCustomerStatus.d.ts.map +1 -0
  12. package/dist/declarations/src/hooks/useDisconnect.d.ts +28 -0
  13. package/dist/declarations/src/hooks/useDisconnect.d.ts.map +1 -0
  14. package/dist/declarations/src/hooks/useGetTxAuthDataSignature.d.ts +168 -0
  15. package/dist/declarations/src/hooks/useGetTxAuthDataSignature.d.ts.map +1 -0
  16. package/dist/declarations/src/hooks/useIsAuthenticated.d.ts +10 -0
  17. package/dist/declarations/src/hooks/useIsAuthenticated.d.ts.map +1 -0
  18. package/dist/declarations/src/hooks/useOpenWidget.d.ts +51 -0
  19. package/dist/declarations/src/hooks/useOpenWidget.d.ts.map +1 -0
  20. package/dist/declarations/src/index.d.ts +4 -0
  21. package/dist/declarations/src/index.d.ts.map +1 -0
  22. package/dist/declarations/src/utils/useAsyncMutationState.d.ts +43 -0
  23. package/dist/declarations/src/utils/useAsyncMutationState.d.ts.map +1 -0
  24. package/dist/declarations/src/utils/useAsyncQueryState.d.ts +36 -0
  25. package/dist/declarations/src/utils/useAsyncQueryState.d.ts.map +1 -0
  26. package/dist/package.json +63 -0
  27. package/package.json +62 -0
  28. package/readme.md +15 -0
@@ -0,0 +1,1021 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var webSdk = require('@compilot/web-sdk');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+
9
+ var AutoLoader = function AutoLoader(_ref) {
10
+ var autoLoad = _ref.autoLoad,
11
+ children = _ref.children;
12
+ var config = useComPilotConfig();
13
+ react.useEffect(function () {
14
+ if (autoLoad) {
15
+ void webSdk.load(config);
16
+ }
17
+ }, [autoLoad]);
18
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
19
+ children: children
20
+ });
21
+ };
22
+
23
+ var ComPilotContext = /*#__PURE__*/react.createContext(null);
24
+
25
+ /**
26
+ * The props type of {@link ComPilotProvider}.
27
+ *
28
+ * @category PropTypes
29
+ */
30
+
31
+ /**
32
+ * ComPilotProvider is a React Context Provider that provides the ComPilot configuration to the rest of the application.
33
+ *
34
+ * @param props - The props of the ComPilotProvider component.
35
+ *
36
+ * @category Component
37
+ *
38
+ * @example
39
+ *
40
+ * Basic
41
+ * ```tsx
42
+ * import { ComPilotProvider } from "@compilot/react-sdk";
43
+ * import { config } from "./config";
44
+ *
45
+ * const App = () => {
46
+ * return (
47
+ * <ComPilotProvider config={config}>
48
+ * <MyApp />
49
+ * </ComPilotProvider>
50
+ * );
51
+ * };
52
+ * ```
53
+ *
54
+ * With AutoLoader disabled
55
+ * ```tsx
56
+ * import { ComPilotProvider } from "@compilot/react-sdk";
57
+ * import { config } from "./config";
58
+ *
59
+ * const App = () => {
60
+ * return (
61
+ * <ComPilotProvider config={config} autoLoad={false}>
62
+ * <MyApp />
63
+ * </ComPilotProvider>
64
+ * );
65
+ * };
66
+ * ```
67
+ */
68
+ var ComPilotProvider = function ComPilotProvider(_ref) {
69
+ var config = _ref.config,
70
+ _ref$autoLoad = _ref.autoLoad,
71
+ autoLoad = _ref$autoLoad === void 0 ? true : _ref$autoLoad,
72
+ children = _ref.children;
73
+ return /*#__PURE__*/jsxRuntime.jsx(ComPilotContext.Provider, {
74
+ value: config,
75
+ children: /*#__PURE__*/jsxRuntime.jsx(AutoLoader, {
76
+ autoLoad: autoLoad,
77
+ children: children
78
+ })
79
+ });
80
+ };
81
+
82
+ /**
83
+ * A hook to access the ComPilot configuration object.
84
+ * @private This hook is intended for internal use only.
85
+ */
86
+ var useComPilotConfig = function useComPilotConfig() {
87
+ var config = react.useContext(ComPilotContext);
88
+ if (!config) {
89
+ throw new Error("No ComPilot config found");
90
+ }
91
+ return config;
92
+ };
93
+
94
+ function _toPrimitive(t, r) {
95
+ if ("object" != typeof t || !t) return t;
96
+ var e = t[Symbol.toPrimitive];
97
+ if (void 0 !== e) {
98
+ var i = e.call(t, r || "default");
99
+ if ("object" != typeof i) return i;
100
+ throw new TypeError("@@toPrimitive must return a primitive value.");
101
+ }
102
+ return ("string" === r ? String : Number)(t);
103
+ }
104
+
105
+ function _toPropertyKey(t) {
106
+ var i = _toPrimitive(t, "string");
107
+ return "symbol" == typeof i ? i : i + "";
108
+ }
109
+
110
+ function _defineProperty(e, r, t) {
111
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
112
+ value: t,
113
+ enumerable: !0,
114
+ configurable: !0,
115
+ writable: !0
116
+ }) : e[r] = t, e;
117
+ }
118
+
119
+ function ownKeys(e, r) {
120
+ var t = Object.keys(e);
121
+ if (Object.getOwnPropertySymbols) {
122
+ var o = Object.getOwnPropertySymbols(e);
123
+ r && (o = o.filter(function (r) {
124
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
125
+ })), t.push.apply(t, o);
126
+ }
127
+ return t;
128
+ }
129
+ function _objectSpread2(e) {
130
+ for (var r = 1; r < arguments.length; r++) {
131
+ var t = null != arguments[r] ? arguments[r] : {};
132
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
133
+ _defineProperty(e, r, t[r]);
134
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
135
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
136
+ });
137
+ }
138
+ return e;
139
+ }
140
+
141
+ function _regeneratorRuntime() {
142
+ _regeneratorRuntime = function () {
143
+ return e;
144
+ };
145
+ var t,
146
+ e = {},
147
+ r = Object.prototype,
148
+ n = r.hasOwnProperty,
149
+ o = Object.defineProperty || function (t, e, r) {
150
+ t[e] = r.value;
151
+ },
152
+ i = "function" == typeof Symbol ? Symbol : {},
153
+ a = i.iterator || "@@iterator",
154
+ c = i.asyncIterator || "@@asyncIterator",
155
+ u = i.toStringTag || "@@toStringTag";
156
+ function define(t, e, r) {
157
+ return Object.defineProperty(t, e, {
158
+ value: r,
159
+ enumerable: !0,
160
+ configurable: !0,
161
+ writable: !0
162
+ }), t[e];
163
+ }
164
+ try {
165
+ define({}, "");
166
+ } catch (t) {
167
+ define = function (t, e, r) {
168
+ return t[e] = r;
169
+ };
170
+ }
171
+ function wrap(t, e, r, n) {
172
+ var i = e && e.prototype instanceof Generator ? e : Generator,
173
+ a = Object.create(i.prototype),
174
+ c = new Context(n || []);
175
+ return o(a, "_invoke", {
176
+ value: makeInvokeMethod(t, r, c)
177
+ }), a;
178
+ }
179
+ function tryCatch(t, e, r) {
180
+ try {
181
+ return {
182
+ type: "normal",
183
+ arg: t.call(e, r)
184
+ };
185
+ } catch (t) {
186
+ return {
187
+ type: "throw",
188
+ arg: t
189
+ };
190
+ }
191
+ }
192
+ e.wrap = wrap;
193
+ var h = "suspendedStart",
194
+ l = "suspendedYield",
195
+ f = "executing",
196
+ s = "completed",
197
+ y = {};
198
+ function Generator() {}
199
+ function GeneratorFunction() {}
200
+ function GeneratorFunctionPrototype() {}
201
+ var p = {};
202
+ define(p, a, function () {
203
+ return this;
204
+ });
205
+ var d = Object.getPrototypeOf,
206
+ v = d && d(d(values([])));
207
+ v && v !== r && n.call(v, a) && (p = v);
208
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
209
+ function defineIteratorMethods(t) {
210
+ ["next", "throw", "return"].forEach(function (e) {
211
+ define(t, e, function (t) {
212
+ return this._invoke(e, t);
213
+ });
214
+ });
215
+ }
216
+ function AsyncIterator(t, e) {
217
+ function invoke(r, o, i, a) {
218
+ var c = tryCatch(t[r], t, o);
219
+ if ("throw" !== c.type) {
220
+ var u = c.arg,
221
+ h = u.value;
222
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
223
+ invoke("next", t, i, a);
224
+ }, function (t) {
225
+ invoke("throw", t, i, a);
226
+ }) : e.resolve(h).then(function (t) {
227
+ u.value = t, i(u);
228
+ }, function (t) {
229
+ return invoke("throw", t, i, a);
230
+ });
231
+ }
232
+ a(c.arg);
233
+ }
234
+ var r;
235
+ o(this, "_invoke", {
236
+ value: function (t, n) {
237
+ function callInvokeWithMethodAndArg() {
238
+ return new e(function (e, r) {
239
+ invoke(t, n, e, r);
240
+ });
241
+ }
242
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
243
+ }
244
+ });
245
+ }
246
+ function makeInvokeMethod(e, r, n) {
247
+ var o = h;
248
+ return function (i, a) {
249
+ if (o === f) throw Error("Generator is already running");
250
+ if (o === s) {
251
+ if ("throw" === i) throw a;
252
+ return {
253
+ value: t,
254
+ done: !0
255
+ };
256
+ }
257
+ for (n.method = i, n.arg = a;;) {
258
+ var c = n.delegate;
259
+ if (c) {
260
+ var u = maybeInvokeDelegate(c, n);
261
+ if (u) {
262
+ if (u === y) continue;
263
+ return u;
264
+ }
265
+ }
266
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
267
+ if (o === h) throw o = s, n.arg;
268
+ n.dispatchException(n.arg);
269
+ } else "return" === n.method && n.abrupt("return", n.arg);
270
+ o = f;
271
+ var p = tryCatch(e, r, n);
272
+ if ("normal" === p.type) {
273
+ if (o = n.done ? s : l, p.arg === y) continue;
274
+ return {
275
+ value: p.arg,
276
+ done: n.done
277
+ };
278
+ }
279
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
280
+ }
281
+ };
282
+ }
283
+ function maybeInvokeDelegate(e, r) {
284
+ var n = r.method,
285
+ o = e.iterator[n];
286
+ 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;
287
+ var i = tryCatch(o, e.iterator, r.arg);
288
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
289
+ var a = i.arg;
290
+ 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);
291
+ }
292
+ function pushTryEntry(t) {
293
+ var e = {
294
+ tryLoc: t[0]
295
+ };
296
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
297
+ }
298
+ function resetTryEntry(t) {
299
+ var e = t.completion || {};
300
+ e.type = "normal", delete e.arg, t.completion = e;
301
+ }
302
+ function Context(t) {
303
+ this.tryEntries = [{
304
+ tryLoc: "root"
305
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
306
+ }
307
+ function values(e) {
308
+ if (e || "" === e) {
309
+ var r = e[a];
310
+ if (r) return r.call(e);
311
+ if ("function" == typeof e.next) return e;
312
+ if (!isNaN(e.length)) {
313
+ var o = -1,
314
+ i = function next() {
315
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
316
+ return next.value = t, next.done = !0, next;
317
+ };
318
+ return i.next = i;
319
+ }
320
+ }
321
+ throw new TypeError(typeof e + " is not iterable");
322
+ }
323
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
324
+ value: GeneratorFunctionPrototype,
325
+ configurable: !0
326
+ }), o(GeneratorFunctionPrototype, "constructor", {
327
+ value: GeneratorFunction,
328
+ configurable: !0
329
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
330
+ var e = "function" == typeof t && t.constructor;
331
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
332
+ }, e.mark = function (t) {
333
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
334
+ }, e.awrap = function (t) {
335
+ return {
336
+ __await: t
337
+ };
338
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
339
+ return this;
340
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
341
+ void 0 === i && (i = Promise);
342
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
343
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
344
+ return t.done ? t.value : a.next();
345
+ });
346
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
347
+ return this;
348
+ }), define(g, "toString", function () {
349
+ return "[object Generator]";
350
+ }), e.keys = function (t) {
351
+ var e = Object(t),
352
+ r = [];
353
+ for (var n in e) r.push(n);
354
+ return r.reverse(), function next() {
355
+ for (; r.length;) {
356
+ var t = r.pop();
357
+ if (t in e) return next.value = t, next.done = !1, next;
358
+ }
359
+ return next.done = !0, next;
360
+ };
361
+ }, e.values = values, Context.prototype = {
362
+ constructor: Context,
363
+ reset: function (e) {
364
+ 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);
365
+ },
366
+ stop: function () {
367
+ this.done = !0;
368
+ var t = this.tryEntries[0].completion;
369
+ if ("throw" === t.type) throw t.arg;
370
+ return this.rval;
371
+ },
372
+ dispatchException: function (e) {
373
+ if (this.done) throw e;
374
+ var r = this;
375
+ function handle(n, o) {
376
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
377
+ }
378
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
379
+ var i = this.tryEntries[o],
380
+ a = i.completion;
381
+ if ("root" === i.tryLoc) return handle("end");
382
+ if (i.tryLoc <= this.prev) {
383
+ var c = n.call(i, "catchLoc"),
384
+ u = n.call(i, "finallyLoc");
385
+ if (c && u) {
386
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
387
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
388
+ } else if (c) {
389
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
390
+ } else {
391
+ if (!u) throw Error("try statement without catch or finally");
392
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
393
+ }
394
+ }
395
+ }
396
+ },
397
+ abrupt: function (t, e) {
398
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
399
+ var o = this.tryEntries[r];
400
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
401
+ var i = o;
402
+ break;
403
+ }
404
+ }
405
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
406
+ var a = i ? i.completion : {};
407
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
408
+ },
409
+ complete: function (t, e) {
410
+ if ("throw" === t.type) throw t.arg;
411
+ 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;
412
+ },
413
+ finish: function (t) {
414
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
415
+ var r = this.tryEntries[e];
416
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
417
+ }
418
+ },
419
+ catch: function (t) {
420
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
421
+ var r = this.tryEntries[e];
422
+ if (r.tryLoc === t) {
423
+ var n = r.completion;
424
+ if ("throw" === n.type) {
425
+ var o = n.arg;
426
+ resetTryEntry(r);
427
+ }
428
+ return o;
429
+ }
430
+ }
431
+ throw Error("illegal catch attempt");
432
+ },
433
+ delegateYield: function (e, r, n) {
434
+ return this.delegate = {
435
+ iterator: values(e),
436
+ resultName: r,
437
+ nextLoc: n
438
+ }, "next" === this.method && (this.arg = t), y;
439
+ }
440
+ }, e;
441
+ }
442
+
443
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
444
+ try {
445
+ var i = n[a](c),
446
+ u = i.value;
447
+ } catch (n) {
448
+ return void e(n);
449
+ }
450
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
451
+ }
452
+ function _asyncToGenerator(n) {
453
+ return function () {
454
+ var t = this,
455
+ e = arguments;
456
+ return new Promise(function (r, o) {
457
+ var a = n.apply(t, e);
458
+ function _next(n) {
459
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
460
+ }
461
+ function _throw(n) {
462
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
463
+ }
464
+ _next(void 0);
465
+ });
466
+ };
467
+ }
468
+
469
+ function _arrayWithHoles(r) {
470
+ if (Array.isArray(r)) return r;
471
+ }
472
+
473
+ function _iterableToArrayLimit(r, l) {
474
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
475
+ if (null != t) {
476
+ var e,
477
+ n,
478
+ i,
479
+ u,
480
+ a = [],
481
+ f = !0,
482
+ o = !1;
483
+ try {
484
+ if (i = (t = t.call(r)).next, 0 === l) {
485
+ if (Object(t) !== t) return;
486
+ f = !1;
487
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
488
+ } catch (r) {
489
+ o = !0, n = r;
490
+ } finally {
491
+ try {
492
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
493
+ } finally {
494
+ if (o) throw n;
495
+ }
496
+ }
497
+ return a;
498
+ }
499
+ }
500
+
501
+ function _arrayLikeToArray(r, a) {
502
+ (null == a || a > r.length) && (a = r.length);
503
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
504
+ return n;
505
+ }
506
+
507
+ function _unsupportedIterableToArray(r, a) {
508
+ if (r) {
509
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
510
+ var t = {}.toString.call(r).slice(8, -1);
511
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
512
+ }
513
+ }
514
+
515
+ function _nonIterableRest() {
516
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
517
+ }
518
+
519
+ function _slicedToArray(r, e) {
520
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
521
+ }
522
+
523
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
524
+
525
+ var useAsyncMutationState = function useAsyncMutationState(_ref) {
526
+ var mutationFn = _ref.mutationFn;
527
+ var _useState = react.useState({
528
+ data: undefined,
529
+ isIdle: true,
530
+ isPending: false,
531
+ isError: false,
532
+ isSuccess: false,
533
+ error: null
534
+ }),
535
+ _useState2 = _slicedToArray(_useState, 2),
536
+ state = _useState2[0],
537
+ setState = _useState2[1];
538
+ var mutateAsync = react.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
539
+ var result,
540
+ _args = arguments;
541
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
542
+ while (1) switch (_context.prev = _context.next) {
543
+ case 0:
544
+ setState({
545
+ data: state.data,
546
+ isIdle: false,
547
+ isPending: true,
548
+ isError: false,
549
+ isSuccess: false,
550
+ error: null
551
+ });
552
+ _context.prev = 1;
553
+ _context.next = 4;
554
+ return mutationFn.apply(void 0, _args);
555
+ case 4:
556
+ result = _context.sent;
557
+ setState({
558
+ data: result,
559
+ isIdle: false,
560
+ isPending: false,
561
+ isError: false,
562
+ isSuccess: true,
563
+ error: null
564
+ });
565
+
566
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
567
+ return _context.abrupt("return", result);
568
+ case 9:
569
+ _context.prev = 9;
570
+ _context.t0 = _context["catch"](1);
571
+ setState({
572
+ data: state.data,
573
+ isIdle: false,
574
+ isPending: false,
575
+ isError: true,
576
+ isSuccess: false,
577
+ error: _context.t0 instanceof Error ? _context.t0 : new Error(String(_context.t0))
578
+ });
579
+ throw _context.t0;
580
+ case 13:
581
+ case "end":
582
+ return _context.stop();
583
+ }
584
+ }, _callee, null, [[1, 9]]);
585
+ })), [setState, mutationFn]);
586
+ return _objectSpread2(_objectSpread2({}, state), {}, {
587
+ mutateAsync: mutateAsync
588
+ });
589
+ };
590
+
591
+ var useAsyncQueryState = function useAsyncQueryState(defaultValue) {
592
+ var _useState = react.useState(defaultValue === undefined ? {
593
+ isLoading: false,
594
+ isError: false,
595
+ isSuccess: false,
596
+ error: null,
597
+ data: undefined
598
+ } : {
599
+ isLoading: false,
600
+ isError: false,
601
+ isSuccess: true,
602
+ error: null,
603
+ data: defaultValue
604
+ }),
605
+ _useState2 = _slicedToArray(_useState, 2),
606
+ state = _useState2[0],
607
+ setState = _useState2[1];
608
+ var setResult = react.useCallback(function (result) {
609
+ setState({
610
+ isLoading: false,
611
+ isError: false,
612
+ isSuccess: true,
613
+ error: null,
614
+ data: result
615
+ });
616
+ }, [setState]);
617
+ var setError = react.useCallback(function (error) {
618
+ setState({
619
+ isLoading: false,
620
+ isError: true,
621
+ isSuccess: false,
622
+ error: error,
623
+ data: undefined
624
+ });
625
+ }, [setState]);
626
+ var startLoading = react.useCallback(function () {
627
+ setState({
628
+ isLoading: true,
629
+ isError: false,
630
+ isSuccess: false,
631
+ error: null,
632
+ data: undefined
633
+ });
634
+ }, [setState]);
635
+ return {
636
+ state: state,
637
+ setResult: setResult,
638
+ setError: setError,
639
+ startLoading: startLoading
640
+ };
641
+ };
642
+
643
+ /**
644
+ * A hook that returns a function that opens the ComPilot ID widget.
645
+ *
646
+ * @param loginParams - The login parameters to use when opening the widget.
647
+ * @returns The async mutation state of the widget opening.
648
+ *
649
+ * @category Hook
650
+ */
651
+ var useOpenWidget = function useOpenWidget(loginParams) {
652
+ var config = useComPilotConfig();
653
+ var mutationFn = react.useCallback(function () {
654
+ return webSdk.openWidget(config, loginParams);
655
+ }, [config]);
656
+ var mutationState = useAsyncMutationState({
657
+ mutationFn: mutationFn
658
+ });
659
+
660
+ // but open state can change without us mutating it
661
+ // that's the only case for now so we don't need another kind of mutation state
662
+ var _useAsyncQueryState = useAsyncQueryState(webSdk.isOpen(config)),
663
+ setResult = _useAsyncQueryState.setResult,
664
+ startLoading = _useAsyncQueryState.startLoading,
665
+ queryState = _useAsyncQueryState.state;
666
+ react.useEffect(function () {
667
+ var unsubscribe = webSdk.watchWidgetVisibleState(config, {
668
+ onChange: function onChange(isVisible) {
669
+ setResult(isVisible);
670
+ },
671
+ onIsLoadingChange: function onIsLoadingChange(isLoading) {
672
+ if (isLoading) {
673
+ startLoading();
674
+ }
675
+ }
676
+ });
677
+ return unsubscribe;
678
+ }, [config, setResult, startLoading]);
679
+ return _objectSpread2(_objectSpread2({}, queryState.data === undefined ? mutationState : {
680
+ error: queryState.error,
681
+ isPending: queryState.isLoading,
682
+ isSuccess: queryState.isSuccess,
683
+ isError: queryState.isError,
684
+ isIdle: !queryState.isError && !queryState.isLoading && !queryState.isSuccess,
685
+ data: queryState.data
686
+ }), {}, {
687
+ mutateAsync: mutationState.mutateAsync
688
+ });
689
+ };
690
+
691
+ /**
692
+ * A callback that returns a transaction authorization data signature.
693
+ *
694
+ * @category Callback
695
+ */
696
+
697
+ /**
698
+ * A hook that returns a function that returns a transaction authorization data signature.
699
+ *
700
+ * @returns A function that returns a transaction authorization data signature.
701
+ *
702
+ * @category Hook
703
+ *
704
+ * @example
705
+ *
706
+ * ### EIP-155 Transaction Wagmi Example
707
+ * ```tsx
708
+ * import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
709
+ * import { waitForTransactionReceipt } from "viem/actions";
710
+ * import { encodeFunctionData } from "viem";
711
+ * import { usePublicClient, useWalletClient } from "wagmi";
712
+ *
713
+ * const MyComponent = () => {
714
+ *
715
+ * const { mutateAsync: getTxAuthDataSignature } = useGetTxAuthDataSignature();
716
+ * const walletClient = useWalletClient();
717
+ * const publicClient = usePublicClient();
718
+ *
719
+ * const gatedNftMint = async () => {
720
+ *
721
+ * // Get signature for the given parameters
722
+ * const signatureResponse = await getTxAuthDataSignature({
723
+ * namespace: "eip155",
724
+ * contractAbi,
725
+ * contractAddress,
726
+ * functionName: "mintNFTGated",
727
+ * args: [account.address],
728
+ * userAddress: account.address,
729
+ * chainId: EvmChainId.parse(chainId),
730
+ * });
731
+ *
732
+ * if (!signatureResponse.isAuthorized) {
733
+ * throw new Error("User is not authorized");
734
+ * }
735
+ *
736
+ * // Mint Gated Nft with signature
737
+ * const unsignedTx = encodeFunctionData({
738
+ * abi: contractAbi,
739
+ * functionName: "mintNFTGated",
740
+ * args: [account.address],
741
+ * });
742
+ *
743
+ * // Build the raw transaction data with the signature
744
+ * const txData = (unsignedTx + signatureResponse.payload) as `0x${string}`;
745
+ *
746
+ * // try to mint nft
747
+ * const tx = await walletClient.data.sendTransaction({
748
+ * to: contractAddress,
749
+ * data: txData,
750
+ * });
751
+ *
752
+ * const receipt = await waitForTransactionReceipt(publicClient, {
753
+ * hash: tx,
754
+ * });
755
+ *
756
+ * return receipt;
757
+ * };
758
+ *
759
+ * return <button onClick={gatedNftMint}>Mint Gated NFT</button>;
760
+ * };
761
+ * ```
762
+ *
763
+ * ### Tezos Transaction Example
764
+ *
765
+ * ```tsx
766
+ * import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
767
+ * import { packDataBytes, Parser } from "@taquito/michel-codec";
768
+ * import type { MichelsonData, MichelsonType } from "@taquito/michel-codec";
769
+ * import { RpcClient } from "@taquito/rpc";
770
+ *
771
+ * const MyComponent = () => {
772
+ * const { mutateAsync: getTxAuthDataSignature } = useGetTxAuthDataSignature();
773
+ * const wallet = useWallet();
774
+ *
775
+ * const signAndSend = async () => {
776
+ *
777
+ * // prepare the mint function call
778
+ * const storage: any = await claimerContract.storage();
779
+ * const lastAssetId = storage.siggated_extension.extension.lastMinted.toNumber() as number;
780
+ * const functionCallArgs = {
781
+ * owner: userAddress,
782
+ * token_id: (lastAssetId + 1).toString(), //"1",
783
+ * };
784
+ * const functionCallArgsBytes = convertMint(
785
+ * functionCallArgs.owner,
786
+ * functionCallArgs.token_id,
787
+ * );
788
+ *
789
+ * // Get signature for the given parameters
790
+ * const signatureResponse = await getTxAuthDataSignature({
791
+ * namespace: "tezos",
792
+ * contractAddress: "KT1JN7a2es4Ne8SuePZU7YrHKG49hfgCCyBK",
793
+ * functionName: "%mint_gated%",
794
+ * args: functionCallArgsBytes,
795
+ * chainID: TezosChainId.parse(currentChainId),
796
+ * userAddress: userAddress as TezosImplicitAddress,
797
+ * });
798
+ *
799
+ * // Check if the user is authorized
800
+ * if (!signatureResponse.isAuthorized) {
801
+ * return {
802
+ * signatureResponse: {
803
+ * isAuthorized: false,
804
+ * signature: "None",
805
+ * },
806
+ * };
807
+ * }
808
+ *
809
+ * // Mint Gated Nft with signature
810
+ * const op = await claimerContract.methodsObject
811
+ * .mint_gated({
812
+ * userAddress,
813
+ * expirationBlock: signatureResponse.blockExpiration,
814
+ * functionName,
815
+ * functionArgs: functionCallArgsBytes,
816
+ * signerPublicKey: COMPILOT_SIGNER_PK,
817
+ * signature: signatureResponse.signature,
818
+ * })
819
+ * .send();
820
+ * await op.confirmation(2);
821
+ * };
822
+ * return <button onClick={signAndSend}>Sign and Send</button>;
823
+ * };
824
+ *
825
+ *
826
+ * // Helper function to convert mint function to bytes
827
+ * function convertMint(owner_str: string, token_id: string) {
828
+ * const data = `(Pair "${owner_str}" ${token_id})`;
829
+ * const type = `(pair address nat)`;
830
+ * const p = new Parser();
831
+ * const dataJSON = p.parseMichelineExpression(data);
832
+ * const typeJSON = p.parseMichelineExpression(type);
833
+ * const packed = packDataBytes(
834
+ * dataJSON as MichelsonData,
835
+ * typeJSON as MichelsonType,
836
+ * );
837
+ * return packed.bytes;
838
+ * }
839
+ *
840
+ * // Tezos signer public key
841
+ * const COMPILOT_SIGNER_PK = "edpkurPsQ8eUApnLUJ9ZPDvu98E8VNj4KtJa1aZr16Cr5ow5VHKnz4";
842
+ * const client = new RpcClient("https://rpc.ghostnet.teztnets.com/");
843
+ * ```
844
+ *
845
+ */
846
+ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
847
+ var config = useComPilotConfig();
848
+ var mutationFn = react.useCallback(/*#__PURE__*/function () {
849
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
850
+ var res;
851
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
852
+ while (1) switch (_context.prev = _context.next) {
853
+ case 0:
854
+ _context.next = 2;
855
+ return webSdk.getTxAuthDataSignature(config, params);
856
+ case 2:
857
+ res = _context.sent;
858
+ return _context.abrupt("return", res);
859
+ case 4:
860
+ case "end":
861
+ return _context.stop();
862
+ }
863
+ }, _callee);
864
+ }));
865
+ return function (_x) {
866
+ return _ref.apply(this, arguments);
867
+ };
868
+ }(), [config._internal.widgetStateStore, config._internal.identifier]);
869
+ return useAsyncMutationState({
870
+ mutationFn: mutationFn
871
+ });
872
+ };
873
+
874
+ /**
875
+ * A hook that returns whether the user is authenticated.
876
+ *
877
+ * @returns Whether the user is authenticated or not.
878
+ *
879
+ * @category Hook
880
+ */
881
+ var useIsAuthenticated = function useIsAuthenticated() {
882
+ var config = useComPilotConfig();
883
+ var _useAsyncQueryState = useAsyncQueryState(webSdk.isAuthenticated(config)),
884
+ state = _useAsyncQueryState.state,
885
+ setResult = _useAsyncQueryState.setResult,
886
+ startLoading = _useAsyncQueryState.startLoading;
887
+ react.useEffect(function () {
888
+ var unsubscribe = webSdk.watchIsAuthenticated(config, {
889
+ onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
890
+ setResult(isAuthenticated);
891
+ },
892
+ onIsLoadingChange: function onIsLoadingChange(isLoading) {
893
+ if (isLoading) {
894
+ startLoading();
895
+ }
896
+ }
897
+ });
898
+ return function () {
899
+ unsubscribe();
900
+ };
901
+ }, [config._internal.widgetStateStore, config._internal.identifier]);
902
+ return state;
903
+ };
904
+
905
+ /**
906
+ * The parameters of the {@link useCustomerStatus} hook.
907
+ *
908
+ * @category Parameter Types
909
+ */
910
+
911
+ /**
912
+ * A hook that returns the current customer status.
913
+ *
914
+ * @param params {@link UseCustomerStatusParams}
915
+ *
916
+ * @returns The async query state of the customer status.
917
+ *
918
+ * @category Hook
919
+ *
920
+ * @example
921
+ * ```tsx
922
+ * import { useCustomerStatus } from "@compilot/react-sdk";
923
+ *
924
+ * const MyComponent = () => {
925
+ * const { data: status } = useCustomerStatus();
926
+ * const isVerified = status === "Active";
927
+ *
928
+ * return <div>User is verified: {isVerified}</div>;
929
+ * };
930
+ * ```
931
+ *
932
+ * Output:
933
+ * ```tsx
934
+ * <div>User is verified: true</div>
935
+ * ```
936
+ */
937
+ var useCustomerStatus = function useCustomerStatus() {
938
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
939
+ refreshInterval: 10000
940
+ },
941
+ refreshInterval = _ref.refreshInterval;
942
+ var config = useComPilotConfig();
943
+ var _useAsyncQueryState = useAsyncQueryState(),
944
+ state = _useAsyncQueryState.state,
945
+ setError = _useAsyncQueryState.setError,
946
+ setResult = _useAsyncQueryState.setResult,
947
+ startLoading = _useAsyncQueryState.startLoading;
948
+ react.useEffect(function () {
949
+ var unsubscribe = webSdk.watchCustomerStatus(config, {
950
+ onChange: function onChange(status) {
951
+ setResult(status);
952
+ }
953
+ });
954
+ return function () {
955
+ unsubscribe();
956
+ };
957
+ }, [config._internal.externalEventEmitter, config._internal.identifier]);
958
+ react.useEffect(function () {
959
+ startLoading();
960
+ var interval = setInterval(function () {
961
+ webSdk.getCustomerStatus(config).then(function (status) {
962
+ setResult(status);
963
+ })["catch"](function (error) {
964
+ setError(error instanceof Error ? error : new Error(String(error)));
965
+ });
966
+ }, refreshInterval);
967
+ return function () {
968
+ clearInterval(interval);
969
+ };
970
+ }, [config._internal.identifier, refreshInterval, config, setError, setResult, startLoading]);
971
+ return state;
972
+ };
973
+
974
+ /**
975
+ * A hook that returns a function that disconnects the ComPilot SDK.
976
+ *
977
+ * @returns The async mutation state of the disconnect function.
978
+ *
979
+ * @category Hook
980
+ *
981
+ * @example
982
+ * ```tsx
983
+ * import { useDisconnect } from "@compilot/react-sdk";
984
+ *
985
+ * const Logout = () => {
986
+ * const { mutateAsync: disconnect, isLoading } = useDisconnect();
987
+ *
988
+ * return (
989
+ * <button
990
+ * disabled={isLoading}
991
+ * onClick={disconnect}
992
+ * >
993
+ * Logout
994
+ * </button>;
995
+ * );
996
+ * };
997
+ * ```
998
+ */
999
+ var useDisconnect = function useDisconnect() {
1000
+ var config = useComPilotConfig();
1001
+ var mutationFn = react.useCallback(function () {
1002
+ return webSdk.disconnect(config);
1003
+ }, [config]);
1004
+ return useAsyncMutationState({
1005
+ mutationFn: mutationFn
1006
+ });
1007
+ };
1008
+
1009
+ exports.ComPilotProvider = ComPilotProvider;
1010
+ exports.useComPilotConfig = useComPilotConfig;
1011
+ exports.useCustomerStatus = useCustomerStatus;
1012
+ exports.useDisconnect = useDisconnect;
1013
+ exports.useGetTxAuthDataSignature = useGetTxAuthDataSignature;
1014
+ exports.useIsAuthenticated = useIsAuthenticated;
1015
+ exports.useOpenWidget = useOpenWidget;
1016
+ Object.keys(webSdk).forEach(function (k) {
1017
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
1018
+ enumerable: true,
1019
+ get: function () { return webSdk[k]; }
1020
+ });
1021
+ });