@frak-labs/core-sdk 0.1.1 → 0.2.0-beta.7898df5b

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 (130) hide show
  1. package/README.md +58 -0
  2. package/cdn/bundle.js +14 -0
  3. package/dist/actions.cjs +1 -1
  4. package/dist/actions.d.cts +3 -3
  5. package/dist/actions.d.ts +3 -3
  6. package/dist/actions.js +1 -1
  7. package/dist/bundle.cjs +1 -1
  8. package/dist/bundle.d.cts +4 -6
  9. package/dist/bundle.d.ts +4 -6
  10. package/dist/bundle.js +1 -1
  11. package/dist/computeLegacyProductId-CCAZvLa5.d.cts +537 -0
  12. package/dist/computeLegacyProductId-b5cUWdAm.d.ts +537 -0
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +3 -4
  15. package/dist/index.d.ts +3 -4
  16. package/dist/index.js +1 -1
  17. package/dist/{openSso-D--Airj6.d.cts → openSso-B0g7-807.d.cts} +173 -136
  18. package/dist/{openSso-DsKJ4y0j.d.ts → openSso-CMzwvaCa.d.ts} +173 -136
  19. package/dist/setupClient-BICl5fdX.js +13 -0
  20. package/dist/setupClient-nl8Dhh4V.cjs +13 -0
  21. package/dist/siweAuthenticate-BWmI2_TN.cjs +1 -0
  22. package/dist/{index-d8xS4ryI.d.ts → siweAuthenticate-CVigMOxz.d.cts} +113 -92
  23. package/dist/{index-C6FxkWPC.d.cts → siweAuthenticate-CnCZ7mok.d.ts} +113 -92
  24. package/dist/siweAuthenticate-zczqxm0a.js +1 -0
  25. package/dist/trackEvent-CeLFVzZn.js +1 -0
  26. package/dist/trackEvent-Ew5r5zfI.cjs +1 -0
  27. package/package.json +11 -22
  28. package/src/actions/displayEmbeddedWallet.ts +1 -0
  29. package/src/actions/displayModal.test.ts +12 -11
  30. package/src/actions/displayModal.ts +7 -18
  31. package/src/actions/ensureIdentity.ts +68 -0
  32. package/src/actions/{getProductInformation.test.ts → getMerchantInformation.test.ts} +33 -50
  33. package/src/actions/getMerchantInformation.ts +16 -0
  34. package/src/actions/index.ts +3 -2
  35. package/src/actions/openSso.ts +4 -2
  36. package/src/actions/referral/processReferral.test.ts +117 -242
  37. package/src/actions/referral/processReferral.ts +134 -204
  38. package/src/actions/referral/referralInteraction.test.ts +4 -12
  39. package/src/actions/referral/referralInteraction.ts +3 -13
  40. package/src/actions/sendInteraction.ts +46 -22
  41. package/src/actions/trackPurchaseStatus.test.ts +354 -141
  42. package/src/actions/trackPurchaseStatus.ts +48 -11
  43. package/src/actions/watchWalletStatus.ts +2 -3
  44. package/src/actions/wrapper/modalBuilder.test.ts +0 -14
  45. package/src/actions/wrapper/modalBuilder.ts +3 -12
  46. package/src/bundle.ts +0 -1
  47. package/src/clients/createIFrameFrakClient.ts +10 -5
  48. package/src/clients/transports/iframeLifecycleManager.test.ts +163 -4
  49. package/src/clients/transports/iframeLifecycleManager.ts +172 -33
  50. package/src/constants/interactionTypes.ts +12 -41
  51. package/src/index.ts +27 -16
  52. package/src/types/config.ts +6 -0
  53. package/src/types/context.ts +48 -6
  54. package/src/types/index.ts +15 -11
  55. package/src/types/lifecycle/client.ts +24 -1
  56. package/src/types/lifecycle/iframe.ts +6 -0
  57. package/src/types/rpc/displayModal.ts +2 -4
  58. package/src/types/rpc/embedded/index.ts +2 -2
  59. package/src/types/rpc/interaction.ts +31 -39
  60. package/src/types/rpc/merchantInformation.ts +77 -0
  61. package/src/types/rpc/modal/index.ts +0 -4
  62. package/src/types/rpc/modal/login.ts +5 -1
  63. package/src/types/rpc/walletStatus.ts +1 -7
  64. package/src/types/rpc.ts +22 -30
  65. package/src/types/tracking.ts +31 -0
  66. package/src/utils/FrakContext.test.ts +270 -186
  67. package/src/utils/FrakContext.ts +78 -56
  68. package/src/utils/backendUrl.test.ts +83 -0
  69. package/src/utils/backendUrl.ts +62 -0
  70. package/src/utils/clientId.test.ts +41 -0
  71. package/src/utils/clientId.ts +43 -0
  72. package/src/utils/compression/compress.test.ts +1 -1
  73. package/src/utils/compression/compress.ts +2 -2
  74. package/src/utils/compression/decompress.test.ts +8 -4
  75. package/src/utils/compression/decompress.ts +2 -2
  76. package/src/utils/{computeProductId.ts → computeLegacyProductId.ts} +2 -2
  77. package/src/utils/constants.ts +5 -0
  78. package/src/utils/deepLinkWithFallback.test.ts +243 -0
  79. package/src/utils/deepLinkWithFallback.ts +103 -0
  80. package/src/utils/formatAmount.ts +6 -0
  81. package/src/utils/iframeHelper.test.ts +18 -5
  82. package/src/utils/iframeHelper.ts +10 -3
  83. package/src/utils/index.ts +16 -1
  84. package/src/utils/merchantId.test.ts +653 -0
  85. package/src/utils/merchantId.ts +143 -0
  86. package/src/utils/sso.ts +18 -11
  87. package/src/utils/trackEvent.test.ts +23 -5
  88. package/src/utils/trackEvent.ts +13 -0
  89. package/cdn/bundle.iife.js +0 -14
  90. package/dist/actions-B5j-i1p0.cjs +0 -1
  91. package/dist/actions-q090Z0oR.js +0 -1
  92. package/dist/index-7OZ39x1U.d.ts +0 -195
  93. package/dist/index-CRsQWnTs.d.cts +0 -351
  94. package/dist/index-Ck1hudEi.d.ts +0 -351
  95. package/dist/index-zDq-VlKx.d.cts +0 -195
  96. package/dist/interaction-DMJ3ZfaF.d.cts +0 -45
  97. package/dist/interaction-KX1h9a7V.d.ts +0 -45
  98. package/dist/interactions-DnfM3oe0.js +0 -1
  99. package/dist/interactions-EIXhNLf6.cjs +0 -1
  100. package/dist/interactions.cjs +0 -1
  101. package/dist/interactions.d.cts +0 -2
  102. package/dist/interactions.d.ts +0 -2
  103. package/dist/interactions.js +0 -1
  104. package/dist/productTypes-BUkXJKZ7.cjs +0 -1
  105. package/dist/productTypes-CGb1MmBF.js +0 -1
  106. package/dist/src-1LQ4eLq5.js +0 -13
  107. package/dist/src-hW71KjPN.cjs +0 -13
  108. package/dist/trackEvent-CHnYa85W.js +0 -1
  109. package/dist/trackEvent-GuQm_1Nm.cjs +0 -1
  110. package/src/actions/getProductInformation.ts +0 -14
  111. package/src/actions/openSso.test.ts +0 -407
  112. package/src/actions/sendInteraction.test.ts +0 -219
  113. package/src/constants/interactionTypes.test.ts +0 -128
  114. package/src/constants/productTypes.test.ts +0 -130
  115. package/src/constants/productTypes.ts +0 -33
  116. package/src/interactions/index.ts +0 -5
  117. package/src/interactions/pressEncoder.test.ts +0 -215
  118. package/src/interactions/pressEncoder.ts +0 -53
  119. package/src/interactions/purchaseEncoder.test.ts +0 -291
  120. package/src/interactions/purchaseEncoder.ts +0 -99
  121. package/src/interactions/referralEncoder.test.ts +0 -170
  122. package/src/interactions/referralEncoder.ts +0 -47
  123. package/src/interactions/retailEncoder.test.ts +0 -107
  124. package/src/interactions/retailEncoder.ts +0 -37
  125. package/src/interactions/webshopEncoder.test.ts +0 -56
  126. package/src/interactions/webshopEncoder.ts +0 -30
  127. package/src/types/rpc/modal/openSession.ts +0 -25
  128. package/src/types/rpc/productInformation.ts +0 -59
  129. package/src/utils/computeProductId.test.ts +0 -80
  130. package/src/utils/sso.test.ts +0 -361
@@ -1,170 +0,0 @@
1
- /**
2
- * Tests for ReferralInteractionEncoder
3
- * Tests encoding of referral-related user interactions
4
- */
5
-
6
- import { pad, toHex } from "viem";
7
- import { describe, expect, it, test } from "../../tests/vitest-fixtures";
8
- import { interactionTypes } from "../constants/interactionTypes";
9
- import { productTypes } from "../constants/productTypes";
10
- import { ReferralInteractionEncoder } from "./referralEncoder";
11
-
12
- describe("ReferralInteractionEncoder", () => {
13
- describe("createLink", () => {
14
- it("should encode create link interaction with correct structure", () => {
15
- const interaction = ReferralInteractionEncoder.createLink();
16
-
17
- // Should return PreparedInteraction structure
18
- expect(interaction).toHaveProperty("handlerTypeDenominator");
19
- expect(interaction).toHaveProperty("interactionData");
20
- });
21
-
22
- it("should use referral product type in handlerTypeDenominator", () => {
23
- const interaction = ReferralInteractionEncoder.createLink();
24
-
25
- // Should use referral product type (30)
26
- const expectedDenominator = toHex(productTypes.referral);
27
- expect(interaction.handlerTypeDenominator).toBe(
28
- expectedDenominator
29
- );
30
- });
31
-
32
- it("should use createLink interaction type in data", () => {
33
- const interaction = ReferralInteractionEncoder.createLink();
34
-
35
- // Should use createLink interaction type
36
- expect(interaction.interactionData).toBe(
37
- interactionTypes.referral.createLink
38
- );
39
- });
40
-
41
- it("should produce consistent output (no parameters)", () => {
42
- const interaction1 = ReferralInteractionEncoder.createLink();
43
- const interaction2 = ReferralInteractionEncoder.createLink();
44
-
45
- // Should always produce the same output
46
- expect(interaction1).toEqual(interaction2);
47
- });
48
- });
49
-
50
- describe("referred", () => {
51
- test("should encode referred interaction with correct structure", ({
52
- mockReferrerAddress,
53
- }) => {
54
- const interaction = ReferralInteractionEncoder.referred({
55
- referrer: mockReferrerAddress,
56
- });
57
-
58
- // Should return PreparedInteraction structure
59
- expect(interaction).toHaveProperty("handlerTypeDenominator");
60
- expect(interaction).toHaveProperty("interactionData");
61
- });
62
-
63
- test("should use referral product type in handlerTypeDenominator", ({
64
- mockReferrerAddress,
65
- }) => {
66
- const interaction = ReferralInteractionEncoder.referred({
67
- referrer: mockReferrerAddress,
68
- });
69
-
70
- // Should use referral product type (30)
71
- const expectedDenominator = toHex(productTypes.referral);
72
- expect(interaction.handlerTypeDenominator).toBe(
73
- expectedDenominator
74
- );
75
- });
76
-
77
- test("should include referred interaction type in data", ({
78
- mockReferrerAddress,
79
- }) => {
80
- const interaction = ReferralInteractionEncoder.referred({
81
- referrer: mockReferrerAddress,
82
- });
83
-
84
- // Should start with referred interaction type
85
- expect(interaction.interactionData).toContain(
86
- interactionTypes.referral.referred
87
- );
88
- });
89
-
90
- test("should pad referrer address to 32 bytes", ({
91
- mockReferrerAddress,
92
- }) => {
93
- const interaction = ReferralInteractionEncoder.referred({
94
- referrer: mockReferrerAddress,
95
- });
96
-
97
- // Referrer address should be padded to 32 bytes
98
- const paddedAddress = pad(mockReferrerAddress, { size: 32 });
99
- expect(interaction.interactionData).toContain(
100
- paddedAddress.slice(2)
101
- );
102
- });
103
-
104
- test("should produce different output for different referrers", () => {
105
- const referrer1 =
106
- "0x1234567890123456789012345678901234567890" as const;
107
- const referrer2 =
108
- "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd" as const;
109
-
110
- const interaction1 = ReferralInteractionEncoder.referred({
111
- referrer: referrer1,
112
- });
113
- const interaction2 = ReferralInteractionEncoder.referred({
114
- referrer: referrer2,
115
- });
116
-
117
- // Different referrers should produce different interaction data
118
- expect(interaction1.interactionData).not.toBe(
119
- interaction2.interactionData
120
- );
121
- });
122
-
123
- test("should produce consistent output for same referrer", ({
124
- mockReferrerAddress,
125
- }) => {
126
- const interaction1 = ReferralInteractionEncoder.referred({
127
- referrer: mockReferrerAddress,
128
- });
129
- const interaction2 = ReferralInteractionEncoder.referred({
130
- referrer: mockReferrerAddress,
131
- });
132
-
133
- // Same referrer should produce same output
134
- expect(interaction1).toEqual(interaction2);
135
- });
136
- });
137
-
138
- describe("interaction data format", () => {
139
- test("should produce valid hex strings", ({ mockReferrerAddress }) => {
140
- const createLinkInteraction =
141
- ReferralInteractionEncoder.createLink();
142
- const referredInteraction = ReferralInteractionEncoder.referred({
143
- referrer: mockReferrerAddress,
144
- });
145
-
146
- // Both should be valid hex strings starting with 0x
147
- expect(createLinkInteraction.interactionData).toMatch(
148
- /^0x[0-9a-f]+$/
149
- );
150
- expect(referredInteraction.interactionData).toMatch(
151
- /^0x[0-9a-f]+$/
152
- );
153
- });
154
-
155
- test("should have different interaction types", ({
156
- mockReferrerAddress,
157
- }) => {
158
- const createLinkInteraction =
159
- ReferralInteractionEncoder.createLink();
160
- const referredInteraction = ReferralInteractionEncoder.referred({
161
- referrer: mockReferrerAddress,
162
- });
163
-
164
- // Different interaction types should produce different data
165
- expect(createLinkInteraction.interactionData).not.toBe(
166
- referredInteraction.interactionData
167
- );
168
- });
169
- });
170
- });
@@ -1,47 +0,0 @@
1
- import { type Address, concatHex, pad, toHex } from "viem";
2
- import { interactionTypes } from "../constants/interactionTypes";
3
- import { productTypes } from "../constants/productTypes";
4
- import type { PreparedInteraction } from "../types";
5
-
6
- /**
7
- * Referral interactions allow you to track user sharing activities.
8
- * These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
9
- *
10
- * :::info
11
- * To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
12
- * :::
13
- *
14
- * @description Encode referral related user interactions
15
- *
16
- * @group Interactions Encoder
17
- *
18
- * @see {@link PreparedInteraction} The prepared interaction object that can be sent
19
- * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
20
- */
21
- export const ReferralInteractionEncoder = {
22
- /**
23
- * 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.
24
- */
25
- createLink(): PreparedInteraction {
26
- return {
27
- handlerTypeDenominator: toHex(productTypes.referral),
28
- interactionData: interactionTypes.referral.createLink,
29
- };
30
- },
31
-
32
- /**
33
- * Encode a referred interaction
34
- * @param args
35
- * @param args.referrer - The Ethereum address of the user who made the referral
36
- */
37
- referred({ referrer }: { referrer: Address }): PreparedInteraction {
38
- const interactionData = concatHex([
39
- interactionTypes.referral.referred,
40
- pad(referrer, { size: 32 }),
41
- ]);
42
- return {
43
- handlerTypeDenominator: toHex(productTypes.referral),
44
- interactionData,
45
- };
46
- },
47
- };
@@ -1,107 +0,0 @@
1
- /**
2
- * Tests for RetailInteractionEncoder
3
- * Tests encoding of retail-related user interactions
4
- */
5
-
6
- import { pad, toHex } from "viem";
7
- import { describe, expect, test } from "../../tests/vitest-fixtures";
8
- import { interactionTypes } from "../constants/interactionTypes";
9
- import { productTypes } from "../constants/productTypes";
10
- import { RetailInteractionEncoder } from "./retailEncoder";
11
-
12
- describe("RetailInteractionEncoder", () => {
13
- describe("customerMeeting", () => {
14
- test("should encode customer meeting interaction with correct structure", ({
15
- mockAgencyId,
16
- }) => {
17
- const interaction = RetailInteractionEncoder.customerMeeting({
18
- agencyId: mockAgencyId,
19
- });
20
-
21
- // Should return PreparedInteraction structure
22
- expect(interaction).toHaveProperty("handlerTypeDenominator");
23
- expect(interaction).toHaveProperty("interactionData");
24
- });
25
-
26
- test("should use retail product type in handlerTypeDenominator", ({
27
- mockAgencyId,
28
- }) => {
29
- const interaction = RetailInteractionEncoder.customerMeeting({
30
- agencyId: mockAgencyId,
31
- });
32
-
33
- // Should use retail product type (4)
34
- const expectedDenominator = toHex(productTypes.retail);
35
- expect(interaction.handlerTypeDenominator).toBe(
36
- expectedDenominator
37
- );
38
- });
39
-
40
- test("should include customerMeeting interaction type in data", ({
41
- mockAgencyId,
42
- }) => {
43
- const interaction = RetailInteractionEncoder.customerMeeting({
44
- agencyId: mockAgencyId,
45
- });
46
-
47
- // Should start with customerMeeting interaction type
48
- expect(interaction.interactionData).toContain(
49
- interactionTypes.retail.customerMeeting
50
- );
51
- });
52
-
53
- test("should pad agency ID to 32 bytes", ({ mockAgencyId }) => {
54
- const interaction = RetailInteractionEncoder.customerMeeting({
55
- agencyId: mockAgencyId,
56
- });
57
-
58
- // Agency ID should be padded to 32 bytes
59
- const paddedAgencyId = pad(mockAgencyId, { size: 32 });
60
- expect(interaction.interactionData).toContain(
61
- paddedAgencyId.slice(2)
62
- );
63
- });
64
-
65
- test("should produce consistent output for same agency ID", ({
66
- mockAgencyId,
67
- }) => {
68
- const interaction1 = RetailInteractionEncoder.customerMeeting({
69
- agencyId: mockAgencyId,
70
- });
71
- const interaction2 = RetailInteractionEncoder.customerMeeting({
72
- agencyId: mockAgencyId,
73
- });
74
-
75
- // Same input should produce same output
76
- expect(interaction1).toEqual(interaction2);
77
- });
78
-
79
- test("should produce different output for different agency IDs", () => {
80
- const agencyId1 =
81
- "0x0000000000000000000000000000000000000000000000000000000000000001" as const;
82
- const agencyId2 =
83
- "0x0000000000000000000000000000000000000000000000000000000000000002" as const;
84
-
85
- const interaction1 = RetailInteractionEncoder.customerMeeting({
86
- agencyId: agencyId1,
87
- });
88
- const interaction2 = RetailInteractionEncoder.customerMeeting({
89
- agencyId: agencyId2,
90
- });
91
-
92
- // Different agency IDs should produce different interaction data
93
- expect(interaction1.interactionData).not.toBe(
94
- interaction2.interactionData
95
- );
96
- });
97
-
98
- test("should produce valid hex string", ({ mockAgencyId }) => {
99
- const interaction = RetailInteractionEncoder.customerMeeting({
100
- agencyId: mockAgencyId,
101
- });
102
-
103
- // Should be valid hex string starting with 0x
104
- expect(interaction.interactionData).toMatch(/^0x[0-9a-f]+$/);
105
- });
106
- });
107
- });
@@ -1,37 +0,0 @@
1
- import { concatHex, type Hex, pad, toHex } from "viem";
2
- import { interactionTypes } from "../constants/interactionTypes";
3
- import { productTypes } from "../constants/productTypes";
4
- import type { PreparedInteraction } from "../types";
5
-
6
- /**
7
- * Retail interactions allow you to track user activities on your retails products.
8
- *
9
- * :::info
10
- * To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
11
- * :::
12
- *
13
- * @description Encode retail related user interactions
14
- *
15
- * @group Interactions Encoder
16
- *
17
- * @see {@link PreparedInteraction} The prepared interaction object that can be sent
18
- * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
19
- */
20
- export const RetailInteractionEncoder = {
21
- /**
22
- * Encode a customer meeting retail interaction
23
- * @param args
24
- * @param args.agencyId - The id of the agency that the customer is meeting with
25
- *
26
- */
27
- customerMeeting({ agencyId }: { agencyId: Hex }): PreparedInteraction {
28
- const interactionData = concatHex([
29
- interactionTypes.retail.customerMeeting,
30
- pad(agencyId, { size: 32 }),
31
- ]);
32
- return {
33
- handlerTypeDenominator: toHex(productTypes.retail),
34
- interactionData,
35
- };
36
- },
37
- };
@@ -1,56 +0,0 @@
1
- /**
2
- * Tests for WebShopInteractionEncoder
3
- * Tests encoding of webshop-related user interactions
4
- */
5
-
6
- import { toHex } from "viem";
7
- import { describe, expect, it } from "../../tests/vitest-fixtures";
8
- import { interactionTypes } from "../constants/interactionTypes";
9
- import { productTypes } from "../constants/productTypes";
10
- import { WebShopInteractionEncoder } from "./webshopEncoder";
11
-
12
- describe("WebShopInteractionEncoder", () => {
13
- describe("open", () => {
14
- it("should encode open webshop interaction with correct structure", () => {
15
- const interaction = WebShopInteractionEncoder.open();
16
-
17
- // Should return PreparedInteraction structure
18
- expect(interaction).toHaveProperty("handlerTypeDenominator");
19
- expect(interaction).toHaveProperty("interactionData");
20
- });
21
-
22
- it("should use webshop product type in handlerTypeDenominator", () => {
23
- const interaction = WebShopInteractionEncoder.open();
24
-
25
- // Should use webshop product type (3)
26
- const expectedDenominator = toHex(productTypes.webshop);
27
- expect(interaction.handlerTypeDenominator).toBe(
28
- expectedDenominator
29
- );
30
- });
31
-
32
- it("should use open interaction type in data", () => {
33
- const interaction = WebShopInteractionEncoder.open();
34
-
35
- // Should use open interaction type
36
- expect(interaction.interactionData).toBe(
37
- interactionTypes.webshop.open
38
- );
39
- });
40
-
41
- it("should produce consistent output (no parameters)", () => {
42
- const interaction1 = WebShopInteractionEncoder.open();
43
- const interaction2 = WebShopInteractionEncoder.open();
44
-
45
- // Should always produce the same output
46
- expect(interaction1).toEqual(interaction2);
47
- });
48
-
49
- it("should produce valid hex string", () => {
50
- const interaction = WebShopInteractionEncoder.open();
51
-
52
- // Should be valid hex string starting with 0x
53
- expect(interaction.interactionData).toMatch(/^0x[0-9a-f]+$/);
54
- });
55
- });
56
- });
@@ -1,30 +0,0 @@
1
- import { toHex } from "viem";
2
- import { interactionTypes } from "../constants/interactionTypes";
3
- import { productTypes } from "../constants/productTypes";
4
- import type { PreparedInteraction } from "../types";
5
-
6
- /**
7
- * Webshop interactions allow you to track user activities on your webshop.
8
- *
9
- * :::info
10
- * To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
11
- * :::
12
- *
13
- * @description Encode webshop related user interactions
14
- *
15
- * @group Interactions Encoder
16
- *
17
- * @see {@link PreparedInteraction} The prepared interaction object that can be sent
18
- * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
19
- */
20
- export const WebShopInteractionEncoder = {
21
- /**
22
- * Encode an open webshop interaction
23
- */
24
- open(): PreparedInteraction {
25
- return {
26
- handlerTypeDenominator: toHex(productTypes.webshop),
27
- interactionData: interactionTypes.webshop.open,
28
- };
29
- },
30
- };
@@ -1,25 +0,0 @@
1
- import type { GenericModalStepType } from "./generic";
2
-
3
- /**
4
- * Return type of the open session modal step
5
- * @inline
6
- * @ignore
7
- */
8
- export type OpenInteractionSessionReturnType = {
9
- startTimestamp: number;
10
- endTimestamp: number;
11
- };
12
-
13
- /**
14
- * The open interaction session step for a Modal
15
- *
16
- * **Input**: None
17
- * **Output**: The interactions session period (start and end timestamp)
18
- *
19
- * @group Modal Display
20
- */
21
- export type OpenInteractionSessionModalStepType = GenericModalStepType<
22
- "openSession",
23
- object,
24
- OpenInteractionSessionReturnType
25
- >;
@@ -1,59 +0,0 @@
1
- import type { Address, Hex } from "viem";
2
- import type { FullInteractionTypesKey } from "../../constants/interactionTypes";
3
- import type { ProductTypesKey } from "../../constants/productTypes";
4
-
5
- /**
6
- * The type for the amount of tokens
7
- */
8
- export type TokenAmountType = {
9
- amount: number;
10
- eurAmount: number;
11
- usdAmount: number;
12
- gbpAmount: number;
13
- };
14
-
15
- /**
16
- * Response of the `frak_getProductInformation` RPC method
17
- * @group RPC Schema
18
- */
19
- export type GetProductInformationReturnType = {
20
- /**
21
- * Current product id
22
- */
23
- id: Hex;
24
- /**
25
- * Some metadata
26
- */
27
- onChainMetadata: {
28
- /**
29
- * Name of the product on-chain
30
- */
31
- name: string;
32
- /**
33
- * Domain of the product on-chain
34
- */
35
- domain: string;
36
- /**
37
- * The supported product types
38
- */
39
- productTypes: ProductTypesKey[];
40
- };
41
- /**
42
- * The max potential reward for the referrer
43
- */
44
- maxReferrer?: TokenAmountType;
45
- /**
46
- * The max potential reward for the referee
47
- */
48
- maxReferee?: TokenAmountType;
49
- /**
50
- * List of all the potentials reward arround this product
51
- */
52
- rewards: {
53
- token: Address;
54
- campaign: Address;
55
- interactionTypeKey: FullInteractionTypesKey;
56
- referrer: TokenAmountType;
57
- referee: TokenAmountType;
58
- }[];
59
- };
@@ -1,80 +0,0 @@
1
- /**
2
- * Tests for computeProductId utility function
3
- * Tests product ID computation from domain names with normalization
4
- */
5
-
6
- import { keccak256, toHex } from "viem";
7
- import { describe, expect, it } from "../../tests/vitest-fixtures";
8
- import { computeProductId } from "./computeProductId";
9
-
10
- describe("computeProductId", () => {
11
- it("should compute product ID from current domain (window.location.host)", () => {
12
- // In JSDOM test environment, window.location.host is "localhost:3000"
13
- const productId = computeProductId();
14
-
15
- // Should compute keccak256 hash of window.location.host
16
- const expectedId = keccak256(toHex(window.location.host));
17
- expect(productId).toBe(expectedId);
18
- });
19
-
20
- it("should compute product ID from custom domain", () => {
21
- const customDomain = "custom-domain.com";
22
- const productId = computeProductId({ domain: customDomain });
23
-
24
- // Should compute keccak256 hash of custom domain
25
- const expectedId = keccak256(toHex(customDomain));
26
- expect(productId).toBe(expectedId);
27
- });
28
-
29
- it("should remove www. prefix from domain before hashing", () => {
30
- const domainWithWww = "www.example.com";
31
- const productId = computeProductId({ domain: domainWithWww });
32
-
33
- // Should compute keccak256 hash of "example.com" (www. removed)
34
- const expectedId = keccak256(toHex("example.com"));
35
- expect(productId).toBe(expectedId);
36
- });
37
-
38
- it("should produce same product ID for domain with and without www", () => {
39
- const withWww = computeProductId({ domain: "www.example.com" });
40
- const withoutWww = computeProductId({ domain: "example.com" });
41
-
42
- // Both should produce the same hash
43
- expect(withWww).toBe(withoutWww);
44
- });
45
-
46
- it("should produce different product IDs for different domains", () => {
47
- const domain1ProductId = computeProductId({ domain: "domain1.com" });
48
- const domain2ProductId = computeProductId({ domain: "domain2.com" });
49
-
50
- // Different domains should produce different hashes
51
- expect(domain1ProductId).not.toBe(domain2ProductId);
52
- });
53
-
54
- it("should use window.location.host when domain is not provided", () => {
55
- // When no domain is provided, it should default to window.location.host
56
- const productId = computeProductId();
57
-
58
- // Should produce same result as using window.location.host explicitly
59
- const expectedId = keccak256(toHex(window.location.host));
60
- expect(productId).toBe(expectedId);
61
- });
62
-
63
- it("should handle subdomains correctly", () => {
64
- const subdomain = "blog.example.com";
65
- const productId = computeProductId({ domain: subdomain });
66
-
67
- // Should compute keccak256 hash of "blog.example.com" (subdomain preserved)
68
- const expectedId = keccak256(toHex(subdomain));
69
- expect(productId).toBe(expectedId);
70
- });
71
-
72
- it("should only remove www prefix, not other w-prefixed subdomains", () => {
73
- const domain = "web.example.com";
74
- const productId = computeProductId({ domain });
75
-
76
- // Should NOT remove "web." prefix, only "www."
77
- const expectedId = keccak256(toHex("web.example.com"));
78
- expect(productId).toBe(expectedId);
79
- });
80
- });