@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,43 +1,35 @@
1
- import type { Hex } from "viem";
1
+ import type { Address } from "viem";
2
2
 
3
3
  /**
4
- * Represent a prepared user interaction, ready to be sent on-chain via the wallet
5
- */
6
- export type PreparedInteraction = {
7
- handlerTypeDenominator: Hex;
8
- interactionData: Hex;
9
- };
10
-
11
- /**
12
- * Parameters that will be used to send an interaction to the blockchain
13
- * @inline
14
- */
15
- export type SendInteractionParamsType = {
16
- /**
17
- * The product id where this interaction has been made
18
- * @defaultValue keccak256(toHex(window.location.host))
19
- */
20
- productId?: Hex;
21
- /**
22
- * The prepared interaction, built from an Interaction Encoder
23
- */
24
- interaction: PreparedInteraction;
25
- /**
26
- * A pre-computed interaction signature
27
- * If none provided, the delegated interaction validator of your product will sign it (you can manage it in the business dashboard)
28
- *
29
- * @defaultValue undefined
30
- */
31
- validation?: Hex;
32
- };
33
-
34
- /**
35
- * Return type of the send interaction rpc request
4
+ * Parameters for sending interactions via RPC
5
+ *
6
+ * Note: merchantId and clientId come from WalletRpcContext
7
+ * and are NOT included in the params - they are resolved by the listener
8
+ *
36
9
  * @group RPC Schema
37
10
  */
38
- export type SendInteractionReturnType = {
39
- /**
40
- * The id of the interaction in the interaction pool
41
- */
42
- delegationId: string;
43
- };
11
+ export type SendInteractionParamsType =
12
+ | {
13
+ type: "arrival";
14
+ /** @deprecated V1 legacy — use referrerClientId for v2 */
15
+ referrerWallet?: Address;
16
+ referrerClientId?: string;
17
+ referrerMerchantId?: string;
18
+ /** Epoch seconds timestamp from the referral link creation */
19
+ referralTimestamp?: number;
20
+ landingUrl?: string;
21
+ utmSource?: string;
22
+ utmMedium?: string;
23
+ utmCampaign?: string;
24
+ utmTerm?: string;
25
+ utmContent?: string;
26
+ }
27
+ | {
28
+ type: "sharing";
29
+ }
30
+ | {
31
+ type: "custom";
32
+ customType: string;
33
+ data?: Record<string, unknown>;
34
+ idempotencyKey?: string;
35
+ };
@@ -0,0 +1,77 @@
1
+ import type { Address } from "viem";
2
+ import type { InteractionTypeKey } from "../../constants/interactionTypes";
3
+
4
+ /**
5
+ * The type for the amount of tokens
6
+ */
7
+ export type TokenAmountType = {
8
+ amount: number;
9
+ eurAmount: number;
10
+ usdAmount: number;
11
+ gbpAmount: number;
12
+ };
13
+
14
+ /**
15
+ * A tier definition for tiered rewards
16
+ */
17
+ export type RewardTier = {
18
+ minValue: number;
19
+ maxValue?: number;
20
+ amount: TokenAmountType;
21
+ };
22
+
23
+ /**
24
+ * Estimated reward amount — discriminated union by payout type
25
+ *
26
+ * - `fixed`: A known token amount (with fiat equivalents)
27
+ * - `percentage`: A percent of a purchase field (e.g. 5% of purchase_amount), with optional min/max caps
28
+ * - `tiered`: Amount depends on a field value matching tier brackets
29
+ */
30
+ export type EstimatedReward =
31
+ | {
32
+ payoutType: "fixed";
33
+ amount: TokenAmountType;
34
+ }
35
+ | {
36
+ payoutType: "percentage";
37
+ percent: number;
38
+ percentOf: string;
39
+ maxAmount?: TokenAmountType;
40
+ minAmount?: TokenAmountType;
41
+ }
42
+ | {
43
+ payoutType: "tiered";
44
+ tierField: string;
45
+ tiers: RewardTier[];
46
+ };
47
+
48
+ /**
49
+ * Response of the `frak_getMerchantInformation` RPC method
50
+ * @group RPC Schema
51
+ */
52
+ export type GetMerchantInformationReturnType = {
53
+ /**
54
+ * Current merchant id
55
+ */
56
+ id: string;
57
+ /**
58
+ * Some metadata
59
+ */
60
+ onChainMetadata: {
61
+ /**
62
+ * Name of the merchant on-chain
63
+ */
64
+ name: string;
65
+ /**
66
+ * Domain of the merchant on-chain
67
+ */
68
+ domain: string;
69
+ };
70
+ rewards: {
71
+ token?: Address;
72
+ campaignId: string;
73
+ interactionTypeKey: InteractionTypeKey;
74
+ referrer?: EstimatedReward;
75
+ referee?: EstimatedReward;
76
+ }[];
77
+ };
@@ -4,10 +4,6 @@ export type {
4
4
  } from "./final";
5
5
  export type { ModalStepMetadata } from "./generic";
6
6
  export type { LoginModalStepType } from "./login";
7
- export type {
8
- OpenInteractionSessionModalStepType,
9
- OpenInteractionSessionReturnType,
10
- } from "./openSession";
11
7
  export type {
12
8
  SiweAuthenticateModalStepType,
13
9
  SiweAuthenticateReturnType,
@@ -1,4 +1,4 @@
1
- import type { Address } from "viem";
1
+ import type { Address, Hex } from "viem";
2
2
  import type { SsoMetadata } from "../sso";
3
3
  import type { GenericModalStepType } from "./generic";
4
4
 
@@ -28,5 +28,9 @@ export type LoginModalStepType = GenericModalStepType<
28
28
  LoginWithSso | LoginWithoutSso,
29
29
  {
30
30
  wallet: Address;
31
+ webauthnProof?: {
32
+ challenge: Hex;
33
+ authenticatorResponse: string;
34
+ };
31
35
  }
32
36
  >;
@@ -14,13 +14,8 @@ export type WalletConnected = {
14
14
  key: "connected";
15
15
  // The user wallet address
16
16
  wallet: Address;
17
- // The interaction token, used to push interactions to the delegator if needed
17
+ // The interaction token, used to push interactions to the backend
18
18
  interactionToken?: string;
19
- // The current onchain interaction session of the user
20
- interactionSession?: {
21
- startTimestamp: number;
22
- endTimestamp: number;
23
- };
24
19
  };
25
20
 
26
21
  /**
@@ -31,5 +26,4 @@ export type WalletNotConnected = {
31
26
  key: "not-connected";
32
27
  wallet?: never;
33
28
  interactionToken?: never;
34
- interactionSession?: never;
35
29
  };
package/src/types/rpc.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { Hex } from "viem";
2
1
  import type { FrakWalletSdkConfig } from "./config";
3
2
  import type {
4
3
  ModalRpcMetadata,
@@ -9,11 +8,8 @@ import type {
9
8
  DisplayEmbeddedWalletParamsType,
10
9
  DisplayEmbeddedWalletResultType,
11
10
  } from "./rpc/embedded";
12
- import type {
13
- PreparedInteraction,
14
- SendInteractionReturnType,
15
- } from "./rpc/interaction";
16
- import type { GetProductInformationReturnType } from "./rpc/productInformation";
11
+ import type { SendInteractionParamsType } from "./rpc/interaction";
12
+ import type { GetMerchantInformationReturnType } from "./rpc/merchantInformation";
17
13
  import type {
18
14
  OpenSsoParamsType,
19
15
  OpenSsoReturnType,
@@ -46,19 +42,14 @@ import type { WalletStatusReturnType } from "./rpc/walletStatus";
46
42
  * - Returns: {@link ModalRpcStepsResultType}
47
43
  * - Response Type: promise (one-shot)
48
44
  *
49
- * #### frak_sendInteraction
50
- * - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
51
- * - Returns: {@link SendInteractionReturnType}
52
- * - Response Type: promise (one-shot)
53
- *
54
45
  * #### frak_sso
55
46
  * - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
56
47
  * - Returns: {@link OpenSsoReturnType}
57
48
  * - Response Type: promise (one-shot)
58
49
  *
59
- * #### frak_getProductInformation
50
+ * #### frak_getMerchantInformation
60
51
  * - Params: None
61
- * - Returns: {@link GetProductInformationReturnType}
52
+ * - Returns: {@link GetMerchantInformationReturnType}
62
53
  * - Response Type: promise (one-shot)
63
54
  *
64
55
  * #### frak_displayEmbeddedWallet
@@ -89,19 +80,6 @@ export type IFrameRpcSchema = [
89
80
  ];
90
81
  ReturnType: ModalRpcStepsResultType;
91
82
  },
92
- /**
93
- * Method to transmit a user interaction
94
- * This is a one-shot request
95
- */
96
- {
97
- Method: "frak_sendInteraction";
98
- Parameters: [
99
- productId: Hex,
100
- interaction: PreparedInteraction,
101
- signature?: Hex,
102
- ];
103
- ReturnType: SendInteractionReturnType;
104
- },
105
83
  /**
106
84
  * Method to prepare SSO (generate URL for popup)
107
85
  * Returns the SSO URL that should be opened in a popup
@@ -132,16 +110,16 @@ export type IFrameRpcSchema = [
132
110
  ReturnType: OpenSsoReturnType;
133
111
  },
134
112
  /**
135
- * Method to get current product information's
136
- * - Is product minted?
113
+ * Method to get current merchant information
114
+ * - Is merchant registered?
137
115
  * - Does it have running campaign?
138
116
  * - Estimated reward on actions
139
117
  * This is a one-shot request
140
118
  */
141
119
  {
142
- Method: "frak_getProductInformation";
120
+ Method: "frak_getMerchantInformation";
143
121
  Parameters?: undefined;
144
- ReturnType: GetProductInformationReturnType;
122
+ ReturnType: GetMerchantInformationReturnType;
145
123
  },
146
124
  /**
147
125
  * Method to show the embedded wallet, with potential customization
@@ -155,4 +133,18 @@ export type IFrameRpcSchema = [
155
133
  ];
156
134
  ReturnType: DisplayEmbeddedWalletResultType;
157
135
  },
136
+ /**
137
+ * Method to send interactions (arrival, sharing, custom events)
138
+ * Fire-and-forget method - no return value expected
139
+ * merchantId is resolved from context
140
+ * clientId is passed via metadata as safeguard against handshake race condition
141
+ */
142
+ {
143
+ Method: "frak_sendInteraction";
144
+ Parameters: [
145
+ interaction: SendInteractionParamsType,
146
+ metadata?: { clientId?: string },
147
+ ];
148
+ ReturnType: undefined;
149
+ },
158
150
  ];
@@ -0,0 +1,31 @@
1
+ import type { Address } from "viem";
2
+
3
+ export type UtmParams = {
4
+ source?: string;
5
+ medium?: string;
6
+ campaign?: string;
7
+ term?: string;
8
+ content?: string;
9
+ };
10
+
11
+ export type TrackArrivalParams = {
12
+ /** @deprecated V1 legacy — use referrerClientId for v2 contexts */
13
+ referrerWallet?: Address;
14
+ referrerClientId?: string;
15
+ referrerMerchantId?: string;
16
+ /** Epoch seconds timestamp from the referral link creation */
17
+ referralTimestamp?: number;
18
+ landingUrl?: string;
19
+ utmParams?: UtmParams;
20
+ };
21
+
22
+ export type TrackArrivalResult = {
23
+ success: boolean;
24
+ identityGroupId?: string;
25
+ touchpointId?: string;
26
+ error?: string;
27
+ };
28
+
29
+ export type TrackArrivalInternalParams = TrackArrivalParams & {
30
+ merchantId: string;
31
+ };