@frak-labs/core-sdk 0.0.2 → 0.0.5

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.
@@ -1,13 +1,10 @@
1
- import {
2
- __commonJS,
3
- __publicField,
4
- __toESM
5
- } from "./chunk-QZL2KCSB.js";
1
+ import { __commonJS, __toESM, __publicField } from './chunk-GDH3M5ZC.js';
2
+ import { sha256 } from 'js-sha256';
3
+ import { hexToBytes, bytesToHex } from 'viem';
6
4
 
7
5
  // ../../node_modules/async-lz-string/libs/async-lz-string.js
8
6
  var require_async_lz_string = __commonJS({
9
7
  "../../node_modules/async-lz-string/libs/async-lz-string.js"(exports, module) {
10
- "use strict";
11
8
  !function(t, e) {
12
9
  if ("object" == typeof exports && "object" == typeof module) module.exports = e();
13
10
  else if ("function" == typeof define && define.amd) define([], e);
@@ -16,7 +13,6 @@ var require_async_lz_string = __commonJS({
16
13
  for (var r in n) ("object" == typeof exports ? exports : t)[r] = n[r];
17
14
  }
18
15
  }(exports, () => (() => {
19
- "use strict";
20
16
  var t = { 48: function(t2, e2, n) {
21
17
  var r = this && this.__awaiter || function(t3, e3, n2, r2) {
22
18
  return new (n2 || (n2 = Promise))(function(a2, o2) {
@@ -96,15 +92,15 @@ var require_async_lz_string = __commonJS({
96
92
  n2 = a2 = 0;
97
93
  }
98
94
  if (5 & s4[0]) throw s4[1];
99
- return { value: s4[0] ? s4[1] : void 0, done: true };
95
+ return { value: s4[0] ? s4[1] : undefined, done: true };
100
96
  }([s3, u2]);
101
97
  };
102
98
  }
103
99
  };
104
- Object.defineProperty(e2, "__esModule", { value: true }), e2.decompressFromUTF16 = e2.compressToUTF16 = e2.decompressFromBase64 = e2.compressToBase64 = void 0;
100
+ Object.defineProperty(e2, "__esModule", { value: true }), e2.decompressFromUTF16 = e2.compressToUTF16 = e2.decompressFromBase64 = e2.compressToBase64 = undefined;
105
101
  var o = n(304), i = n(134), s = new o.CompressorImpl(), u = new i.DecompressorImpl(), c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", l = {};
106
102
  e2.compressToBase64 = function(t3) {
107
- return r(this, void 0, void 0, function() {
103
+ return r(this, undefined, undefined, function() {
108
104
  var e3;
109
105
  return a(this, function(n2) {
110
106
  switch (n2.label) {
@@ -129,7 +125,7 @@ var require_async_lz_string = __commonJS({
129
125
  });
130
126
  });
131
127
  }, e2.decompressFromBase64 = function(t3) {
132
- return r(this, void 0, void 0, function() {
128
+ return r(this, undefined, undefined, function() {
133
129
  return a(this, function(e3) {
134
130
  switch (e3.label) {
135
131
  case 0:
@@ -148,7 +144,7 @@ var require_async_lz_string = __commonJS({
148
144
  });
149
145
  });
150
146
  }, e2.compressToUTF16 = function(t3) {
151
- return r(this, void 0, void 0, function() {
147
+ return r(this, undefined, undefined, function() {
152
148
  return a(this, function(e3) {
153
149
  switch (e3.label) {
154
150
  case 0:
@@ -161,7 +157,7 @@ var require_async_lz_string = __commonJS({
161
157
  });
162
158
  });
163
159
  }, e2.decompressFromUTF16 = function(t3) {
164
- return r(this, void 0, void 0, function() {
160
+ return r(this, undefined, undefined, function() {
165
161
  return a(this, function(e3) {
166
162
  switch (e3.label) {
167
163
  case 0:
@@ -253,12 +249,12 @@ var require_async_lz_string = __commonJS({
253
249
  n2 = a2 = 0;
254
250
  }
255
251
  if (5 & s4[0]) throw s4[1];
256
- return { value: s4[0] ? s4[1] : void 0, done: true };
252
+ return { value: s4[0] ? s4[1] : undefined, done: true };
257
253
  }([s3, u]);
258
254
  };
259
255
  }
260
256
  };
261
- Object.defineProperty(e2, "__esModule", { value: true }), e2.CompressorImpl = void 0;
257
+ Object.defineProperty(e2, "__esModule", { value: true }), e2.CompressorImpl = undefined;
262
258
  var o = n(658), i = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], s = function() {
263
259
  function t3() {
264
260
  }
@@ -278,7 +274,7 @@ var require_async_lz_string = __commonJS({
278
274
  }, t3.prototype.compress = function(e3, n2, i2) {
279
275
  var s2 = this;
280
276
  return new Promise(function(u) {
281
- return r(s2, void 0, void 0, function() {
277
+ return r(s2, undefined, undefined, function() {
282
278
  var r2, s3;
283
279
  return a(this, function(a2) {
284
280
  switch (a2.label) {
@@ -379,19 +375,19 @@ var require_async_lz_string = __commonJS({
379
375
  n2 = a2 = 0;
380
376
  }
381
377
  if (5 & s3[0]) throw s3[1];
382
- return { value: s3[0] ? s3[1] : void 0, done: true };
378
+ return { value: s3[0] ? s3[1] : undefined, done: true };
383
379
  }([s2, u]);
384
380
  };
385
381
  }
386
382
  };
387
- Object.defineProperty(e2, "__esModule", { value: true }), e2.DecompressorImpl = void 0;
383
+ Object.defineProperty(e2, "__esModule", { value: true }), e2.DecompressorImpl = undefined;
388
384
  var o = n(658), i = function() {
389
385
  function t3() {
390
386
  }
391
387
  return t3.prototype.decompress = function(t4, e3, n2) {
392
388
  var i2 = this;
393
389
  return new Promise(function(s) {
394
- return r(i2, void 0, void 0, function() {
390
+ return r(i2, undefined, undefined, function() {
395
391
  var r2, i3, u;
396
392
  return a(this, function(a2) {
397
393
  switch (a2.label) {
@@ -524,13 +520,13 @@ var require_async_lz_string = __commonJS({
524
520
  n2 = a = 0;
525
521
  }
526
522
  if (5 & s3[0]) throw s3[1];
527
- return { value: s3[0] ? s3[1] : void 0, done: true };
523
+ return { value: s3[0] ? s3[1] : undefined, done: true };
528
524
  }([s2, u]);
529
525
  };
530
526
  }
531
527
  };
532
- Object.defineProperty(e2, "__esModule", { value: true }), e2.wait = void 0, e2.wait = function() {
533
- return n(this, void 0, void 0, function() {
528
+ Object.defineProperty(e2, "__esModule", { value: true }), e2.wait = undefined, e2.wait = function() {
529
+ return n(this, undefined, undefined, function() {
534
530
  return r(this, function(t3) {
535
531
  return [2, new Promise(function(t4) {
536
532
  setTimeout(t4, 0);
@@ -541,7 +537,7 @@ var require_async_lz_string = __commonJS({
541
537
  } }, e = {};
542
538
  return function n(r) {
543
539
  var a = e[r];
544
- if (void 0 !== a) return a.exports;
540
+ if (undefined !== a) return a.exports;
545
541
  var o = e[r] = { exports: {} };
546
542
  return t[r].call(o.exports, o, o.exports, n), o.exports;
547
543
  }(48);
@@ -591,10 +587,12 @@ var Deferred = class {
591
587
  __publicField(this, "_resolve");
592
588
  __publicField(this, "_reject");
593
589
  __publicField(this, "resolve", (value) => {
594
- this._resolve?.(value);
590
+ var _a;
591
+ (_a = this._resolve) == null ? undefined : _a.call(this, value);
595
592
  });
596
593
  __publicField(this, "reject", (reason) => {
597
- this._reject?.(reason);
594
+ var _a;
595
+ (_a = this._reject) == null ? undefined : _a.call(this, reason);
598
596
  });
599
597
  this._promise = new Promise((resolve, reject) => {
600
598
  this._resolve = resolve;
@@ -608,7 +606,6 @@ var Deferred = class {
608
606
 
609
607
  // src/utils/compression/compress.ts
610
608
  var import_async_lz_string = __toESM(require_async_lz_string(), 1);
611
- import { sha256 } from "js-sha256";
612
609
  async function hashAndCompressData(data) {
613
610
  const validationHash = sha256(JSON.stringify(data));
614
611
  const hashProtectedData = {
@@ -628,9 +625,8 @@ async function compressJson(data) {
628
625
 
629
626
  // src/utils/compression/decompress.ts
630
627
  var import_async_lz_string2 = __toESM(require_async_lz_string(), 1);
631
- import { sha256 as sha2562 } from "js-sha256";
632
628
  async function decompressDataAndCheckHash(compressedData) {
633
- if (!(compressedData?.compressed && compressedData?.compressedHash)) {
629
+ if (!((compressedData == null ? undefined : compressedData.compressed) && (compressedData == null ? undefined : compressedData.compressedHash))) {
634
630
  throw new FrakRpcError(
635
631
  RpcErrorCodes.corruptedResponse,
636
632
  "Missing compressed data"
@@ -645,13 +641,13 @@ async function decompressDataAndCheckHash(compressedData) {
645
641
  "Invalid compressed data"
646
642
  );
647
643
  }
648
- if (!parsedData?.validationHash) {
644
+ if (!(parsedData == null ? undefined : parsedData.validationHash)) {
649
645
  throw new FrakRpcError(
650
646
  RpcErrorCodes.corruptedResponse,
651
647
  "Missing validation hash"
652
648
  );
653
649
  }
654
- const expectedCompressedHash = sha2562(compressedData.compressed);
650
+ const expectedCompressedHash = sha256(compressedData.compressed);
655
651
  if (expectedCompressedHash !== compressedData.compressedHash) {
656
652
  throw new FrakRpcError(
657
653
  RpcErrorCodes.corruptedResponse,
@@ -659,7 +655,7 @@ async function decompressDataAndCheckHash(compressedData) {
659
655
  );
660
656
  }
661
657
  const { validationHash: _, ...rawResultData } = parsedData;
662
- const expectedValidationHash = sha2562(JSON.stringify(rawResultData));
658
+ const expectedValidationHash = sha256(JSON.stringify(rawResultData));
663
659
  if (expectedValidationHash !== parsedData.validationHash) {
664
660
  throw new FrakRpcError(
665
661
  RpcErrorCodes.corruptedResponse,
@@ -709,8 +705,9 @@ function createIframe({
709
705
  changeIframeVisibility({ iframe, isVisible: false });
710
706
  document.body.appendChild(iframe);
711
707
  return new Promise((resolve) => {
712
- iframe?.addEventListener("load", () => resolve(iframe));
713
- iframe.src = `${config?.walletUrl ?? walletBaseUrl ?? "https://wallet.frak.id"}/listener`;
708
+ var _a, _b;
709
+ iframe == null ? undefined : iframe.addEventListener("load", () => resolve(iframe));
710
+ iframe.src = `${(_b = (_a = config == null ? undefined : config.walletUrl) != null ? _a : walletBaseUrl) != null ? _b : "https://wallet.frak.id"}/listener`;
714
711
  });
715
712
  }
716
713
  function changeIframeVisibility({
@@ -733,9 +730,6 @@ function changeIframeVisibility({
733
730
  iframe.style.height = "100%";
734
731
  iframe.style.pointerEvents = "auto";
735
732
  }
736
-
737
- // src/utils/FrakContext.ts
738
- import { bytesToHex, hexToBytes } from "viem";
739
733
  var contextKey = "fCtx";
740
734
  function base64url_encode(buffer) {
741
735
  return btoa(Array.from(buffer, (b) => String.fromCharCode(b)).join("")).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
@@ -750,14 +744,14 @@ function base64url_decode(value) {
750
744
  );
751
745
  }
752
746
  function compress(context) {
753
- if (!context?.r) return;
747
+ if (!(context == null ? undefined : context.r)) return;
754
748
  try {
755
749
  const bytes = hexToBytes(context.r);
756
750
  return base64url_encode(bytes);
757
751
  } catch (e) {
758
752
  console.error("Error compressing Frak context", { e, context });
759
753
  }
760
- return void 0;
754
+ return undefined;
761
755
  }
762
756
  function decompress(context) {
763
757
  if (!context || context.length === 0) return;
@@ -767,7 +761,7 @@ function decompress(context) {
767
761
  } catch (e) {
768
762
  console.error("Error decompressing Frak context", { e, context });
769
763
  }
770
- return void 0;
764
+ return undefined;
771
765
  }
772
766
  function parse({ url }) {
773
767
  if (!url) return null;
@@ -799,11 +793,12 @@ function replaceUrl({
799
793
  url: baseUrl,
800
794
  context
801
795
  }) {
802
- if (!window.location?.href || typeof window === "undefined") {
796
+ var _a;
797
+ if (!((_a = window.location) == null ? undefined : _a.href) || typeof window === "undefined") {
803
798
  console.error("No window found, can't update context");
804
799
  return;
805
800
  }
806
- const url = baseUrl ?? window.location.href;
801
+ const url = baseUrl != null ? baseUrl : window.location.href;
807
802
  let newUrl;
808
803
  if (context !== null) {
809
804
  newUrl = update({
@@ -825,18 +820,4 @@ var FrakContextManager = {
825
820
  replaceUrl
826
821
  };
827
822
 
828
- export {
829
- FrakRpcError,
830
- InternalError,
831
- ClientNotFound,
832
- RpcErrorCodes,
833
- Deferred,
834
- hashAndCompressData,
835
- compressJson,
836
- decompressDataAndCheckHash,
837
- decompressJson,
838
- baseIframeProps,
839
- createIframe,
840
- changeIframeVisibility,
841
- FrakContextManager
842
- };
823
+ export { ClientNotFound, Deferred, FrakContextManager, FrakRpcError, InternalError, RpcErrorCodes, baseIframeProps, changeIframeVisibility, compressJson, createIframe, decompressDataAndCheckHash, decompressJson, hashAndCompressData };
@@ -0,0 +1,155 @@
1
+ 'use strict';
2
+
3
+ var chunkPO6YSB4Q_cjs = require('./chunk-PO6YSB4Q.cjs');
4
+ var viem = require('viem');
5
+
6
+ var PressInteractionEncoder = {
7
+ /**
8
+ * Encode an open article interaction
9
+ * @param args
10
+ * @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
11
+ */
12
+ openArticle({ articleId }) {
13
+ const interactionData = viem.concatHex([
14
+ chunkPO6YSB4Q_cjs.interactionTypes.press.openArticle,
15
+ viem.pad(articleId, { size: 32 })
16
+ ]);
17
+ return {
18
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.press),
19
+ interactionData
20
+ };
21
+ },
22
+ /**
23
+ * Encode a read article interaction
24
+ * @param args
25
+ * @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
26
+ */
27
+ readArticle({ articleId }) {
28
+ const interactionData = viem.concatHex([
29
+ chunkPO6YSB4Q_cjs.interactionTypes.press.readArticle,
30
+ viem.pad(articleId, { size: 32 })
31
+ ]);
32
+ return {
33
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.press),
34
+ interactionData
35
+ };
36
+ }
37
+ };
38
+ var ReferralInteractionEncoder = {
39
+ /**
40
+ * Records the event of a user creating a referral link. Note that this interaction doesn't actually create the link itself; it only sends an event to track that a link was created.
41
+ */
42
+ createLink() {
43
+ return {
44
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.referral),
45
+ interactionData: chunkPO6YSB4Q_cjs.interactionTypes.referral.createLink
46
+ };
47
+ },
48
+ /**
49
+ * Encode a referred interaction
50
+ * @param args
51
+ * @param args.referrer - The Ethereum address of the user who made the referral
52
+ */
53
+ referred({ referrer }) {
54
+ const interactionData = viem.concatHex([
55
+ chunkPO6YSB4Q_cjs.interactionTypes.referral.referred,
56
+ viem.pad(referrer, { size: 32 })
57
+ ]);
58
+ return {
59
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.referral),
60
+ interactionData
61
+ };
62
+ }
63
+ };
64
+ var PurchaseInteractionEncoder = {
65
+ /**
66
+ * Encode a start purchase interaction
67
+ * @param args
68
+ * @param args.purchaseId - The id of the purchase that is being started.
69
+ */
70
+ startPurchase({ purchaseId }) {
71
+ const interactionData = viem.concatHex([
72
+ chunkPO6YSB4Q_cjs.interactionTypes.purchase.started,
73
+ viem.pad(purchaseId, { size: 32 })
74
+ ]);
75
+ return {
76
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.purchase),
77
+ interactionData
78
+ };
79
+ },
80
+ /**
81
+ * Encode a complete purchase interaction
82
+ * @param args
83
+ * @param args.purchaseId - The id of the purchase that is being completed.
84
+ * @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
85
+ */
86
+ completedPurchase({
87
+ purchaseId,
88
+ proof
89
+ }) {
90
+ const innerData = viem.encodeAbiParameters(
91
+ [{ type: "uint256" }, { type: "bytes32[]" }],
92
+ [BigInt(purchaseId), proof]
93
+ );
94
+ const interactionData = viem.concatHex([
95
+ chunkPO6YSB4Q_cjs.interactionTypes.purchase.completed,
96
+ innerData
97
+ ]);
98
+ return {
99
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.purchase),
100
+ interactionData
101
+ };
102
+ },
103
+ /**
104
+ * Encode an unsafe complete purchase interaction (when we can't provide the proof)
105
+ * @param args
106
+ * @param args.purchaseId - The id of the purchase that is being completed.
107
+ */
108
+ unsafeCompletedPurchase({
109
+ purchaseId
110
+ }) {
111
+ const interactionData = viem.concatHex([
112
+ chunkPO6YSB4Q_cjs.interactionTypes.purchase.unsafeCompleted,
113
+ viem.pad(purchaseId, { size: 32 })
114
+ ]);
115
+ return {
116
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.purchase),
117
+ interactionData
118
+ };
119
+ }
120
+ };
121
+ var WebShopInteractionEncoder = {
122
+ /**
123
+ * Encode an open webshop interaction
124
+ */
125
+ open() {
126
+ return {
127
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.webshop),
128
+ interactionData: chunkPO6YSB4Q_cjs.interactionTypes.webshop.open
129
+ };
130
+ }
131
+ };
132
+ var RetailInteractionEncoder = {
133
+ /**
134
+ * Encode a customer meeting retail interaction
135
+ * @param args
136
+ * @param args.agencyId - The id of the agency that the customer is meeting with
137
+ *
138
+ */
139
+ customerMeeting({ agencyId }) {
140
+ const interactionData = viem.concatHex([
141
+ chunkPO6YSB4Q_cjs.interactionTypes.retail.customerMeeting,
142
+ viem.pad(agencyId, { size: 32 })
143
+ ]);
144
+ return {
145
+ handlerTypeDenominator: viem.toHex(chunkPO6YSB4Q_cjs.productTypes.retail),
146
+ interactionData
147
+ };
148
+ }
149
+ };
150
+
151
+ exports.PressInteractionEncoder = PressInteractionEncoder;
152
+ exports.PurchaseInteractionEncoder = PurchaseInteractionEncoder;
153
+ exports.ReferralInteractionEncoder = ReferralInteractionEncoder;
154
+ exports.RetailInteractionEncoder = RetailInteractionEncoder;
155
+ exports.WebShopInteractionEncoder = WebShopInteractionEncoder;