@frak-labs/core-sdk 0.1.0-beta.8d103039 → 0.1.0-beta.d9302e66

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 (67) hide show
  1. package/package.json +20 -16
  2. package/src/actions/displayEmbeddedWallet.test.ts +194 -0
  3. package/src/actions/displayModal.test.ts +387 -0
  4. package/src/actions/getProductInformation.test.ts +133 -0
  5. package/src/actions/index.ts +19 -19
  6. package/src/actions/openSso.test.ts +407 -0
  7. package/src/actions/prepareSso.test.ts +223 -0
  8. package/src/actions/referral/processReferral.ts +1 -1
  9. package/src/actions/referral/referralInteraction.ts +1 -1
  10. package/src/actions/sendInteraction.test.ts +219 -0
  11. package/src/actions/trackPurchaseStatus.test.ts +287 -0
  12. package/src/actions/watchWalletStatus.test.ts +372 -0
  13. package/src/bundle.ts +1 -1
  14. package/src/clients/createIFrameFrakClient.ts +2 -2
  15. package/src/clients/index.ts +1 -1
  16. package/src/clients/setupClient.ts +3 -1
  17. package/src/clients/transports/iframeLifecycleManager.ts +3 -1
  18. package/src/index.ts +72 -74
  19. package/src/interactions/index.ts +2 -2
  20. package/src/interactions/pressEncoder.test.ts +215 -0
  21. package/src/interactions/pressEncoder.ts +1 -1
  22. package/src/interactions/purchaseEncoder.test.ts +291 -0
  23. package/src/interactions/purchaseEncoder.ts +8 -3
  24. package/src/interactions/referralEncoder.test.ts +170 -0
  25. package/src/interactions/retailEncoder.test.ts +107 -0
  26. package/src/interactions/retailEncoder.ts +1 -1
  27. package/src/interactions/webshopEncoder.test.ts +56 -0
  28. package/src/types/index.ts +51 -50
  29. package/src/types/lifecycle/index.ts +1 -1
  30. package/src/types/rpc/embedded/loggedIn.ts +1 -1
  31. package/src/types/rpc/embedded/loggedOut.ts +1 -1
  32. package/src/types/rpc/modal/index.ts +11 -11
  33. package/src/utils/FrakContext.test.ts +338 -0
  34. package/src/utils/FrakContext.ts +8 -2
  35. package/src/utils/compression/b64.test.ts +181 -0
  36. package/src/utils/compression/compress.test.ts +123 -0
  37. package/src/utils/compression/decompress.test.ts +145 -0
  38. package/src/utils/compression/index.ts +1 -1
  39. package/src/utils/computeProductId.test.ts +80 -0
  40. package/src/utils/constants.test.ts +23 -0
  41. package/src/utils/formatAmount.test.ts +113 -0
  42. package/src/utils/getCurrencyAmountKey.test.ts +44 -0
  43. package/src/utils/getSupportedCurrency.test.ts +51 -0
  44. package/src/utils/getSupportedLocale.test.ts +64 -0
  45. package/src/utils/iframeHelper.test.ts +450 -0
  46. package/src/utils/iframeHelper.ts +4 -3
  47. package/src/utils/index.ts +12 -12
  48. package/src/utils/sso.test.ts +361 -0
  49. package/src/utils/trackEvent.test.ts +162 -0
  50. package/cdn/bundle.js +0 -19
  51. package/cdn/bundle.js.LICENSE.txt +0 -10
  52. package/dist/actions.cjs +0 -1
  53. package/dist/actions.d.cts +0 -1481
  54. package/dist/actions.d.ts +0 -1481
  55. package/dist/actions.js +0 -1
  56. package/dist/bundle.cjs +0 -13
  57. package/dist/bundle.d.cts +0 -2087
  58. package/dist/bundle.d.ts +0 -2087
  59. package/dist/bundle.js +0 -13
  60. package/dist/index.cjs +0 -13
  61. package/dist/index.d.cts +0 -1387
  62. package/dist/index.d.ts +0 -1387
  63. package/dist/index.js +0 -13
  64. package/dist/interactions.cjs +0 -1
  65. package/dist/interactions.d.cts +0 -182
  66. package/dist/interactions.d.ts +0 -182
  67. package/dist/interactions.js +0 -1
@@ -15,7 +15,9 @@ export type IframeLifecycleManager = {
15
15
  */
16
16
  export function createIFrameLifecycleManager({
17
17
  iframe,
18
- }: { iframe: HTMLIFrameElement }): IframeLifecycleManager {
18
+ }: {
19
+ iframe: HTMLIFrameElement;
20
+ }): IframeLifecycleManager {
19
21
  // Create the isConnected listener
20
22
  const isConnectedDeferred = new Deferred<boolean>();
21
23
 
package/src/index.ts CHANGED
@@ -1,103 +1,101 @@
1
1
  // Clients
2
+
3
+ export { ssoPopupFeatures, ssoPopupName } from "./actions/openSso";
2
4
  export {
3
5
  createIFrameFrakClient,
4
- setupClient,
5
6
  DebugInfoGatherer,
7
+ setupClient,
6
8
  } from "./clients";
7
-
8
- // Utils
9
9
  export {
10
- compressJsonToB64,
11
- decompressJsonFromB64,
12
- createIframe,
13
- FrakContextManager,
14
- baseIframeProps,
15
- findIframeInOpener,
16
- getSupportedCurrency,
17
- getSupportedLocale,
18
- getCurrencyAmountKey,
19
- formatAmount,
20
- base64urlDecode,
21
- base64urlEncode,
22
- trackEvent,
23
- generateSsoUrl,
24
- type CompressedSsoData,
25
- type FullSsoParams,
26
- type AppSpecificSsoMetadata,
27
- } from "./utils";
28
-
10
+ type FullInteractionTypesKey,
11
+ type InteractionTypesKey,
12
+ interactionTypes,
13
+ } from "./constants/interactionTypes";
14
+ export { type LocalesKey, locales } from "./constants/locales";
29
15
  // Constants
30
16
  export {
31
17
  type ProductTypesKey,
32
18
  productTypes,
33
19
  productTypesMask,
34
20
  } from "./constants/productTypes";
35
- export {
36
- interactionTypes,
37
- type InteractionTypesKey,
38
- type FullInteractionTypesKey,
39
- } from "./constants/interactionTypes";
40
- export { locales, type LocalesKey } from "./constants/locales";
41
- export { ssoPopupFeatures, ssoPopupName } from "./actions/openSso";
42
-
43
21
  // Types
44
22
  export type {
45
- // Rpc
46
- WalletStatusReturnType,
47
- IFrameRpcSchema,
48
- PreparedInteraction,
49
- SendInteractionParamsType,
50
- SendInteractionReturnType,
51
- SsoMetadata,
52
- PrepareSsoParamsType,
53
- PrepareSsoReturnType,
54
- OpenSsoParamsType,
55
- OpenSsoReturnType,
23
+ ClientLifecycleEvent,
24
+ CompressedData,
56
25
  Currency,
57
- Language,
58
- I18nConfig,
59
- LocalizedI18nConfig,
60
- TokenAmountType,
61
- GetProductInformationReturnType,
62
26
  // RPC Embedded wallet
63
27
  DisplayEmbeddedWalletParamsType,
64
28
  DisplayEmbeddedWalletResultType,
65
- LoggedOutEmbeddedView,
66
- LoggedInEmbeddedView,
29
+ DisplayModalParamsType,
67
30
  EmbeddedViewActionReferred,
68
31
  EmbeddedViewActionSharing,
69
- // RPC Modal generics
70
- ModalStepTypes,
71
- ModalRpcMetadata,
72
- DisplayModalParamsType,
73
- ModalRpcStepsInput,
74
- ModalRpcStepsResultType,
75
- // RPC Modal types
76
- ModalStepMetadata,
77
- LoginModalStepType,
78
- SiweAuthenticateModalStepType,
79
- SiweAuthenticationParams,
80
- SiweAuthenticateReturnType,
81
- SendTransactionTxType,
82
- SendTransactionModalStepType,
83
- SendTransactionReturnType,
84
- OpenInteractionSessionReturnType,
85
- OpenInteractionSessionModalStepType,
86
- FinalModalStepType,
87
32
  FinalActionType,
33
+ FinalModalStepType,
88
34
  // Client
89
35
  FrakClient,
90
- // Transport
91
- IFrameTransport,
92
- IFrameLifecycleEvent,
93
- ClientLifecycleEvent,
36
+ // Utils
37
+ FrakContext,
94
38
  FrakLifecycleEvent,
95
39
  // Config
96
40
  FrakWalletSdkConfig,
41
+ GetProductInformationReturnType,
42
+ HashProtectedData,
43
+ I18nConfig,
44
+ IFrameLifecycleEvent,
45
+ IFrameRpcSchema,
46
+ // Transport
47
+ IFrameTransport,
97
48
  // Compression
98
49
  KeyProvider,
99
- CompressedData,
100
- HashProtectedData,
101
- // Utils
102
- FrakContext,
50
+ Language,
51
+ LocalizedI18nConfig,
52
+ LoggedInEmbeddedView,
53
+ LoggedOutEmbeddedView,
54
+ LoginModalStepType,
55
+ ModalRpcMetadata,
56
+ ModalRpcStepsInput,
57
+ ModalRpcStepsResultType,
58
+ // RPC Modal types
59
+ ModalStepMetadata,
60
+ // RPC Modal generics
61
+ ModalStepTypes,
62
+ OpenInteractionSessionModalStepType,
63
+ OpenInteractionSessionReturnType,
64
+ OpenSsoParamsType,
65
+ OpenSsoReturnType,
66
+ PreparedInteraction,
67
+ PrepareSsoParamsType,
68
+ PrepareSsoReturnType,
69
+ SendInteractionParamsType,
70
+ SendInteractionReturnType,
71
+ SendTransactionModalStepType,
72
+ SendTransactionReturnType,
73
+ SendTransactionTxType,
74
+ SiweAuthenticateModalStepType,
75
+ SiweAuthenticateReturnType,
76
+ SiweAuthenticationParams,
77
+ SsoMetadata,
78
+ TokenAmountType,
79
+ // Rpc
80
+ WalletStatusReturnType,
103
81
  } from "./types";
82
+ // Utils
83
+ export {
84
+ type AppSpecificSsoMetadata,
85
+ base64urlDecode,
86
+ base64urlEncode,
87
+ baseIframeProps,
88
+ type CompressedSsoData,
89
+ compressJsonToB64,
90
+ createIframe,
91
+ decompressJsonFromB64,
92
+ FrakContextManager,
93
+ type FullSsoParams,
94
+ findIframeInOpener,
95
+ formatAmount,
96
+ generateSsoUrl,
97
+ getCurrencyAmountKey,
98
+ getSupportedCurrency,
99
+ getSupportedLocale,
100
+ trackEvent,
101
+ } from "./utils";
@@ -1,5 +1,5 @@
1
1
  export { PressInteractionEncoder } from "./pressEncoder";
2
- export { ReferralInteractionEncoder } from "./referralEncoder";
3
2
  export { PurchaseInteractionEncoder } from "./purchaseEncoder";
4
- export { WebShopInteractionEncoder } from "./webshopEncoder";
3
+ export { ReferralInteractionEncoder } from "./referralEncoder";
5
4
  export { RetailInteractionEncoder } from "./retailEncoder";
5
+ export { WebShopInteractionEncoder } from "./webshopEncoder";
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Tests for PressInteractionEncoder
3
+ * Tests encoding of press-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 { PressInteractionEncoder } from "./pressEncoder";
11
+
12
+ describe("PressInteractionEncoder", () => {
13
+ describe("openArticle", () => {
14
+ test("should encode open article interaction with correct structure", ({
15
+ mockArticleId,
16
+ }) => {
17
+ const interaction = PressInteractionEncoder.openArticle({
18
+ articleId: mockArticleId,
19
+ });
20
+
21
+ // Should return PreparedInteraction structure
22
+ expect(interaction).toHaveProperty("handlerTypeDenominator");
23
+ expect(interaction).toHaveProperty("interactionData");
24
+ });
25
+
26
+ test("should use press product type in handlerTypeDenominator", ({
27
+ mockArticleId,
28
+ }) => {
29
+ const interaction = PressInteractionEncoder.openArticle({
30
+ articleId: mockArticleId,
31
+ });
32
+
33
+ // Should use press product type (2)
34
+ const expectedDenominator = toHex(productTypes.press);
35
+ expect(interaction.handlerTypeDenominator).toBe(
36
+ expectedDenominator
37
+ );
38
+ });
39
+
40
+ test("should include openArticle interaction type in data", ({
41
+ mockArticleId,
42
+ }) => {
43
+ const interaction = PressInteractionEncoder.openArticle({
44
+ articleId: mockArticleId,
45
+ });
46
+
47
+ // Should start with openArticle interaction type
48
+ expect(interaction.interactionData).toContain(
49
+ interactionTypes.press.openArticle
50
+ );
51
+ });
52
+
53
+ test("should pad article ID to 32 bytes", ({ mockArticleId }) => {
54
+ const interaction = PressInteractionEncoder.openArticle({
55
+ articleId: mockArticleId,
56
+ });
57
+
58
+ // Article ID should be padded to 32 bytes (64 hex chars + 0x prefix = 66 chars)
59
+ const paddedArticleId = pad(mockArticleId, { size: 32 });
60
+ expect(interaction.interactionData).toContain(
61
+ paddedArticleId.slice(2)
62
+ );
63
+ });
64
+
65
+ it("should handle short article IDs by padding", () => {
66
+ const shortArticleId = "0x01" as const;
67
+ const interaction = PressInteractionEncoder.openArticle({
68
+ articleId: shortArticleId,
69
+ });
70
+
71
+ // Should pad short IDs to 32 bytes
72
+ expect(interaction.interactionData).toBeDefined();
73
+ // Total length: openArticle (10 chars) + padded ID (64 chars) + 0x (2 chars) = 76 chars
74
+ expect(interaction.interactionData.length).toBeGreaterThan(64);
75
+ });
76
+
77
+ test("should produce consistent output for same article ID", ({
78
+ mockArticleId,
79
+ }) => {
80
+ const interaction1 = PressInteractionEncoder.openArticle({
81
+ articleId: mockArticleId,
82
+ });
83
+ const interaction2 = PressInteractionEncoder.openArticle({
84
+ articleId: mockArticleId,
85
+ });
86
+
87
+ // Same input should produce same output
88
+ expect(interaction1).toEqual(interaction2);
89
+ });
90
+ });
91
+
92
+ describe("readArticle", () => {
93
+ test("should encode read article interaction with correct structure", ({
94
+ mockArticleId,
95
+ }) => {
96
+ const interaction = PressInteractionEncoder.readArticle({
97
+ articleId: mockArticleId,
98
+ });
99
+
100
+ // Should return PreparedInteraction structure
101
+ expect(interaction).toHaveProperty("handlerTypeDenominator");
102
+ expect(interaction).toHaveProperty("interactionData");
103
+ });
104
+
105
+ test("should use press product type in handlerTypeDenominator", ({
106
+ mockArticleId,
107
+ }) => {
108
+ const interaction = PressInteractionEncoder.readArticle({
109
+ articleId: mockArticleId,
110
+ });
111
+
112
+ // Should use press product type (2)
113
+ const expectedDenominator = toHex(productTypes.press);
114
+ expect(interaction.handlerTypeDenominator).toBe(
115
+ expectedDenominator
116
+ );
117
+ });
118
+
119
+ test("should include readArticle interaction type in data", ({
120
+ mockArticleId,
121
+ }) => {
122
+ const interaction = PressInteractionEncoder.readArticle({
123
+ articleId: mockArticleId,
124
+ });
125
+
126
+ // Should start with readArticle interaction type
127
+ expect(interaction.interactionData).toContain(
128
+ interactionTypes.press.readArticle
129
+ );
130
+ });
131
+
132
+ test("should pad article ID to 32 bytes", ({ mockArticleId }) => {
133
+ const interaction = PressInteractionEncoder.readArticle({
134
+ articleId: mockArticleId,
135
+ });
136
+
137
+ // Article ID should be padded to 32 bytes
138
+ const paddedArticleId = pad(mockArticleId, { size: 32 });
139
+ expect(interaction.interactionData).toContain(
140
+ paddedArticleId.slice(2)
141
+ );
142
+ });
143
+
144
+ test("should produce different output than openArticle for same ID", ({
145
+ mockArticleId,
146
+ }) => {
147
+ const openInteraction = PressInteractionEncoder.openArticle({
148
+ articleId: mockArticleId,
149
+ });
150
+ const readInteraction = PressInteractionEncoder.readArticle({
151
+ articleId: mockArticleId,
152
+ });
153
+
154
+ // Different interaction types should produce different data
155
+ expect(openInteraction.interactionData).not.toBe(
156
+ readInteraction.interactionData
157
+ );
158
+
159
+ // But should have same handlerTypeDenominator (both press)
160
+ expect(openInteraction.handlerTypeDenominator).toBe(
161
+ readInteraction.handlerTypeDenominator
162
+ );
163
+ });
164
+ });
165
+
166
+ describe("interaction data format", () => {
167
+ test("should concatenate interaction type and padded article ID", ({
168
+ mockArticleId,
169
+ }) => {
170
+ const interaction = PressInteractionEncoder.openArticle({
171
+ articleId: mockArticleId,
172
+ });
173
+
174
+ // Should start with interaction type (10 chars including 0x)
175
+ expect(interaction.interactionData.slice(0, 10)).toBe(
176
+ interactionTypes.press.openArticle
177
+ );
178
+
179
+ // Should be followed by padded article ID (64 hex chars)
180
+ expect(interaction.interactionData.length).toBe(74); // 0x + 8 (type) + 64 (padded ID)
181
+ });
182
+
183
+ test("should produce valid hex strings", ({ mockArticleId }) => {
184
+ const openInteraction = PressInteractionEncoder.openArticle({
185
+ articleId: mockArticleId,
186
+ });
187
+ const readInteraction = PressInteractionEncoder.readArticle({
188
+ articleId: mockArticleId,
189
+ });
190
+
191
+ // Both should be valid hex strings starting with 0x
192
+ expect(openInteraction.interactionData).toMatch(/^0x[0-9a-f]+$/);
193
+ expect(readInteraction.interactionData).toMatch(/^0x[0-9a-f]+$/);
194
+ });
195
+
196
+ it("should handle different article IDs correctly", () => {
197
+ const articleId1 =
198
+ "0x0000000000000000000000000000000000000000000000000000000000000001" as const;
199
+ const articleId2 =
200
+ "0x0000000000000000000000000000000000000000000000000000000000000002" as const;
201
+
202
+ const interaction1 = PressInteractionEncoder.openArticle({
203
+ articleId: articleId1,
204
+ });
205
+ const interaction2 = PressInteractionEncoder.openArticle({
206
+ articleId: articleId2,
207
+ });
208
+
209
+ // Different article IDs should produce different interaction data
210
+ expect(interaction1.interactionData).not.toBe(
211
+ interaction2.interactionData
212
+ );
213
+ });
214
+ });
215
+ });
@@ -1,4 +1,4 @@
1
- import { type Hex, concatHex, pad, toHex } from "viem";
1
+ import { concatHex, type Hex, pad, toHex } from "viem";
2
2
  import { interactionTypes } from "../constants/interactionTypes";
3
3
  import { productTypes } from "../constants/productTypes";
4
4
  import type { PreparedInteraction } from "../types";