@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,361 +0,0 @@
1
- /**
2
- * Tests for SSO URL generation utility
3
- * Tests generateSsoUrl and compressed parameter formatting
4
- */
5
-
6
- import { vi } from "vitest";
7
-
8
- // Mock compression functions
9
- vi.mock("./compression/compress", () => ({
10
- compressJsonToB64: vi.fn((data: unknown) => {
11
- // Return base64url-like string for testing
12
- return `compressed_${JSON.stringify(data)}`;
13
- }),
14
- }));
15
-
16
- import type { Hex } from "viem";
17
- import { describe, expect, it } from "../../tests/vitest-fixtures";
18
- import type { PrepareSsoParamsType } from "../types";
19
- import { compressJsonToB64 } from "./compression/compress";
20
- import { generateSsoUrl } from "./sso";
21
-
22
- describe("generateSsoUrl", () => {
23
- const mockProductId =
24
- "0x1234567890123456789012345678901234567890123456789012345678901234" as Hex;
25
- const walletUrl = "https://wallet.frak.id";
26
-
27
- describe("basic URL generation", () => {
28
- it("should generate SSO URL with basic params", () => {
29
- const params: PrepareSsoParamsType = {};
30
- const name = "Test App";
31
-
32
- const result = generateSsoUrl(
33
- walletUrl,
34
- params,
35
- mockProductId,
36
- name
37
- );
38
-
39
- expect(result).toContain("https://wallet.frak.id/sso");
40
- expect(result).toContain("?p=");
41
- });
42
-
43
- it("should include compressed parameters in URL", () => {
44
- const params: PrepareSsoParamsType = {
45
- directExit: true,
46
- };
47
- const name = "My App";
48
-
49
- const result = generateSsoUrl(
50
- walletUrl,
51
- params,
52
- mockProductId,
53
- name
54
- );
55
-
56
- expect(result).toContain("?p=compressed_");
57
- expect(compressJsonToB64).toHaveBeenCalled();
58
- });
59
-
60
- it("should set /sso pathname", () => {
61
- const params: PrepareSsoParamsType = {};
62
- const name = "App";
63
-
64
- const result = generateSsoUrl(
65
- walletUrl,
66
- params,
67
- mockProductId,
68
- name
69
- );
70
-
71
- const url = new URL(result);
72
- expect(url.pathname).toBe("/sso");
73
- });
74
-
75
- it("should preserve wallet base URL", () => {
76
- const customWalletUrl = "https://custom-wallet.com";
77
- const params: PrepareSsoParamsType = {};
78
- const name = "App";
79
-
80
- const result = generateSsoUrl(
81
- customWalletUrl,
82
- params,
83
- mockProductId,
84
- name
85
- );
86
-
87
- expect(result).toContain("https://custom-wallet.com/sso");
88
- });
89
- });
90
-
91
- describe("parameter compression format", () => {
92
- it("should compress params with name and productId", () => {
93
- const params: PrepareSsoParamsType = {};
94
- const name = "Test App";
95
-
96
- generateSsoUrl(walletUrl, params, mockProductId, name);
97
-
98
- expect(compressJsonToB64).toHaveBeenCalledWith(
99
- expect.objectContaining({
100
- p: mockProductId,
101
- m: expect.objectContaining({
102
- n: name,
103
- }),
104
- })
105
- );
106
- });
107
-
108
- it("should include redirectUrl in compressed params", () => {
109
- const params: PrepareSsoParamsType = {
110
- redirectUrl: "https://example.com/callback",
111
- };
112
- const name = "App";
113
-
114
- generateSsoUrl(walletUrl, params, mockProductId, name);
115
-
116
- expect(compressJsonToB64).toHaveBeenCalledWith(
117
- expect.objectContaining({
118
- r: "https://example.com/callback",
119
- })
120
- );
121
- });
122
-
123
- it("should include directExit in compressed params", () => {
124
- const params: PrepareSsoParamsType = {
125
- directExit: true,
126
- };
127
- const name = "App";
128
-
129
- generateSsoUrl(walletUrl, params, mockProductId, name);
130
-
131
- expect(compressJsonToB64).toHaveBeenCalledWith(
132
- expect.objectContaining({
133
- d: true,
134
- })
135
- );
136
- });
137
-
138
- it("should include lang in compressed params", () => {
139
- const params: PrepareSsoParamsType = {
140
- lang: "fr",
141
- };
142
- const name = "App";
143
-
144
- generateSsoUrl(walletUrl, params, mockProductId, name);
145
-
146
- expect(compressJsonToB64).toHaveBeenCalledWith(
147
- expect.objectContaining({
148
- l: "fr",
149
- })
150
- );
151
- });
152
-
153
- it("should include custom CSS when provided", () => {
154
- const params: PrepareSsoParamsType = {};
155
- const name = "App";
156
- const css = "body { color: red; }";
157
-
158
- generateSsoUrl(walletUrl, params, mockProductId, name, css);
159
-
160
- expect(compressJsonToB64).toHaveBeenCalledWith(
161
- expect.objectContaining({
162
- m: expect.objectContaining({
163
- css: "body { color: red; }",
164
- }),
165
- })
166
- );
167
- });
168
-
169
- it("should include metadata logoUrl", () => {
170
- const params: PrepareSsoParamsType = {
171
- metadata: {
172
- logoUrl: "https://example.com/logo.png",
173
- },
174
- };
175
- const name = "App";
176
-
177
- generateSsoUrl(walletUrl, params, mockProductId, name);
178
-
179
- expect(compressJsonToB64).toHaveBeenCalledWith(
180
- expect.objectContaining({
181
- m: expect.objectContaining({
182
- l: "https://example.com/logo.png",
183
- }),
184
- })
185
- );
186
- });
187
-
188
- it("should include metadata homepageLink", () => {
189
- const params: PrepareSsoParamsType = {
190
- metadata: {
191
- homepageLink: "https://example.com",
192
- },
193
- };
194
- const name = "App";
195
-
196
- generateSsoUrl(walletUrl, params, mockProductId, name);
197
-
198
- expect(compressJsonToB64).toHaveBeenCalledWith(
199
- expect.objectContaining({
200
- m: expect.objectContaining({
201
- h: "https://example.com",
202
- }),
203
- })
204
- );
205
- });
206
-
207
- it("should include all metadata fields together", () => {
208
- const params: PrepareSsoParamsType = {
209
- metadata: {
210
- logoUrl: "https://example.com/logo.png",
211
- homepageLink: "https://example.com",
212
- },
213
- };
214
- const name = "Full App";
215
- const css = "body { background: blue; }";
216
-
217
- generateSsoUrl(walletUrl, params, mockProductId, name, css);
218
-
219
- expect(compressJsonToB64).toHaveBeenCalledWith(
220
- expect.objectContaining({
221
- m: {
222
- n: "Full App",
223
- css: "body { background: blue; }",
224
- l: "https://example.com/logo.png",
225
- h: "https://example.com",
226
- },
227
- })
228
- );
229
- });
230
- });
231
-
232
- describe("full parameter combinations", () => {
233
- it("should handle all parameters together", () => {
234
- const params: PrepareSsoParamsType = {
235
- redirectUrl: "https://example.com/callback",
236
- directExit: false,
237
- lang: "fr",
238
- metadata: {
239
- logoUrl: "https://example.com/logo.png",
240
- homepageLink: "https://example.com/home",
241
- },
242
- };
243
- const name = "Complete App";
244
- const css = "body { margin: 0; }";
245
-
246
- const result = generateSsoUrl(
247
- walletUrl,
248
- params,
249
- mockProductId,
250
- name,
251
- css
252
- );
253
-
254
- expect(result).toContain("https://wallet.frak.id/sso");
255
- expect(result).toContain("?p=");
256
- expect(compressJsonToB64).toHaveBeenCalledWith({
257
- r: "https://example.com/callback",
258
- d: false,
259
- l: "fr",
260
- p: mockProductId,
261
- m: {
262
- n: "Complete App",
263
- css: "body { margin: 0; }",
264
- l: "https://example.com/logo.png",
265
- h: "https://example.com/home",
266
- },
267
- });
268
- });
269
-
270
- it("should handle minimal parameters", () => {
271
- const params: PrepareSsoParamsType = {};
272
- const name = "Minimal App";
273
-
274
- const result = generateSsoUrl(
275
- walletUrl,
276
- params,
277
- mockProductId,
278
- name
279
- );
280
-
281
- expect(result).toBeDefined();
282
- expect(compressJsonToB64).toHaveBeenCalledWith(
283
- expect.objectContaining({
284
- p: mockProductId,
285
- m: expect.objectContaining({
286
- n: "Minimal App",
287
- }),
288
- })
289
- );
290
- });
291
- });
292
-
293
- describe("edge cases", () => {
294
- it("should handle empty name", () => {
295
- const params: PrepareSsoParamsType = {};
296
- const name = "";
297
-
298
- const result = generateSsoUrl(
299
- walletUrl,
300
- params,
301
- mockProductId,
302
- name
303
- );
304
-
305
- expect(result).toBeDefined();
306
- expect(compressJsonToB64).toHaveBeenCalledWith(
307
- expect.objectContaining({
308
- m: expect.objectContaining({
309
- n: "",
310
- }),
311
- })
312
- );
313
- });
314
-
315
- it("should handle undefined optional parameters", () => {
316
- const params: PrepareSsoParamsType = {};
317
- const name = "App";
318
-
319
- generateSsoUrl(walletUrl, params, mockProductId, name, undefined);
320
-
321
- expect(compressJsonToB64).toHaveBeenCalledWith(
322
- expect.objectContaining({
323
- m: expect.objectContaining({
324
- n: "App",
325
- css: undefined,
326
- }),
327
- })
328
- );
329
- });
330
-
331
- it("should handle wallet URL with trailing slash", () => {
332
- const walletUrlWithSlash = "https://wallet.frak.id/";
333
- const params: PrepareSsoParamsType = {};
334
- const name = "App";
335
-
336
- const result = generateSsoUrl(
337
- walletUrlWithSlash,
338
- params,
339
- mockProductId,
340
- name
341
- );
342
-
343
- expect(result).toContain("https://wallet.frak.id/sso");
344
- });
345
-
346
- it("should handle different product IDs", () => {
347
- const differentProductId =
348
- "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdabcdefabcdefabcdefabcd" as Hex;
349
- const params: PrepareSsoParamsType = {};
350
- const name = "App";
351
-
352
- generateSsoUrl(walletUrl, params, differentProductId, name);
353
-
354
- expect(compressJsonToB64).toHaveBeenCalledWith(
355
- expect.objectContaining({
356
- p: differentProductId,
357
- })
358
- );
359
- });
360
- });
361
- });