@frak-labs/core-sdk 0.2.0 → 0.2.1-beta.06c52c98

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/README.md +1 -2
  2. package/cdn/bundle.js +55 -3
  3. package/dist/actions.cjs +1 -1
  4. package/dist/actions.d.cts +2 -2
  5. package/dist/actions.d.ts +2 -2
  6. package/dist/actions.js +1 -1
  7. package/dist/bundle.cjs +1 -1
  8. package/dist/bundle.d.cts +4 -4
  9. package/dist/bundle.d.ts +4 -4
  10. package/dist/bundle.js +1 -1
  11. package/dist/{computeLegacyProductId-Raks6FXg.d.cts → computeLegacyProductId-BP-ciVsp.d.cts} +73 -88
  12. package/dist/{computeLegacyProductId-BkyJ4rEY.d.ts → computeLegacyProductId-DiJd7RNo.d.ts} +73 -88
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +1 -1
  17. package/dist/{openSso-BCJGchIb.d.cts → openSso-B8v3Vtnh.d.ts} +157 -52
  18. package/dist/{openSso-DG-_9CED.d.ts → openSso-n_B4LSuW.d.cts} +157 -52
  19. package/dist/setupClient-Dr_UYfTD.cjs +13 -0
  20. package/dist/setupClient-TuhDjVJx.js +13 -0
  21. package/dist/siweAuthenticate-0UPcUqI1.js +1 -0
  22. package/dist/{siweAuthenticate-Btem4QHs.d.ts → siweAuthenticate-CDCsp8EJ.d.ts} +35 -36
  23. package/dist/siweAuthenticate-CfQibjZR.cjs +1 -0
  24. package/dist/{siweAuthenticate-BH7Dn7nZ.d.cts → siweAuthenticate-yITE-iKh.d.cts} +35 -36
  25. package/dist/trackEvent-5j5kkOCj.js +1 -0
  26. package/dist/trackEvent-B2uom25e.cjs +1 -0
  27. package/package.json +8 -8
  28. package/src/actions/displayEmbeddedWallet.ts +6 -2
  29. package/src/actions/displayModal.ts +6 -2
  30. package/src/actions/ensureIdentity.ts +2 -2
  31. package/src/actions/referral/processReferral.test.ts +109 -125
  32. package/src/actions/referral/processReferral.ts +134 -180
  33. package/src/actions/referral/referralInteraction.test.ts +3 -5
  34. package/src/actions/referral/referralInteraction.ts +2 -7
  35. package/src/actions/trackPurchaseStatus.test.ts +32 -20
  36. package/src/actions/trackPurchaseStatus.ts +3 -5
  37. package/src/actions/wrapper/modalBuilder.test.ts +4 -2
  38. package/src/actions/wrapper/modalBuilder.ts +6 -8
  39. package/src/clients/createIFrameFrakClient.ts +146 -25
  40. package/src/clients/transports/iframeLifecycleManager.test.ts +0 -80
  41. package/src/clients/transports/iframeLifecycleManager.ts +0 -44
  42. package/src/index.ts +8 -3
  43. package/src/types/config.ts +10 -3
  44. package/src/types/context.ts +48 -6
  45. package/src/types/index.ts +8 -2
  46. package/src/types/lifecycle/client.ts +22 -27
  47. package/src/types/lifecycle/iframe.ts +0 -8
  48. package/src/types/resolvedConfig.ts +104 -0
  49. package/src/types/rpc/interaction.ts +9 -0
  50. package/src/types/rpc.ts +7 -5
  51. package/src/types/tracking.ts +5 -34
  52. package/src/utils/FrakContext.test.ts +270 -186
  53. package/src/utils/FrakContext.ts +78 -56
  54. package/src/utils/backendUrl.test.ts +2 -2
  55. package/src/utils/backendUrl.ts +1 -1
  56. package/src/utils/index.ts +1 -5
  57. package/src/utils/sdkConfigStore.test.ts +405 -0
  58. package/src/utils/sdkConfigStore.ts +277 -0
  59. package/src/utils/sso.ts +3 -7
  60. package/dist/setupClient-CQrMDGyZ.js +0 -13
  61. package/dist/setupClient-Ccv3XxwL.cjs +0 -13
  62. package/dist/siweAuthenticate-BJHbtty4.js +0 -1
  63. package/dist/siweAuthenticate-Cwj3HP0m.cjs +0 -1
  64. package/dist/trackEvent-M2RLTQ2p.js +0 -1
  65. package/dist/trackEvent-T_R9ER2S.cjs +0 -1
  66. package/src/utils/merchantId.test.ts +0 -653
  67. package/src/utils/merchantId.ts +0 -143
@@ -8,7 +8,6 @@ export type IFrameLifecycleEvent =
8
8
  data?: never;
9
9
  }
10
10
  | DoBackupEvent
11
- | HandshakeRequestEvent
12
11
  | RedirectRequestEvent;
13
12
 
14
13
  type DoBackupEvent = {
@@ -16,13 +15,6 @@ type DoBackupEvent = {
16
15
  data: { backup?: string };
17
16
  };
18
17
 
19
- type HandshakeRequestEvent = {
20
- iframeLifecycle: "handshake";
21
- data: {
22
- token: string;
23
- };
24
- };
25
-
26
18
  type RedirectRequestEvent = {
27
19
  iframeLifecycle: "redirect";
28
20
  data: {
@@ -0,0 +1,104 @@
1
+ import type { Currency, Language } from "./config";
2
+
3
+ /**
4
+ * Response from the merchant resolve endpoint
5
+ * @category Config
6
+ */
7
+ export type MerchantConfigResponse = {
8
+ merchantId: string;
9
+ name: string;
10
+ domain: string;
11
+ allowedDomains: string[];
12
+ sdkConfig?: ResolvedSdkConfig;
13
+ };
14
+
15
+ /**
16
+ * Resolved placement config from backend
17
+ * Translations already flattened: default + lang-specific merged into one record
18
+ * @category Config
19
+ */
20
+ export type ResolvedPlacement = {
21
+ /** Per-component configuration within this placement */
22
+ components?: {
23
+ buttonShare?: {
24
+ text?: string;
25
+ noRewardText?: string;
26
+ clickAction?: "embedded-wallet" | "share-modal";
27
+ useReward?: boolean;
28
+ css?: string;
29
+ };
30
+ buttonWallet?: {
31
+ position?: "bottom-right" | "bottom-left";
32
+ css?: string;
33
+ };
34
+ openInApp?: {
35
+ text?: string;
36
+ css?: string;
37
+ };
38
+ };
39
+ targetInteraction?: string;
40
+ /** Already flattened: default + lang-specific merged into one record */
41
+ translations?: Record<string, string>;
42
+ /** Global placement CSS (applied to modals/listener) */
43
+ css?: string;
44
+ };
45
+
46
+ /**
47
+ * Resolved SDK config from backend `/resolve` endpoint
48
+ * Language resolution and translation merging already applied
49
+ * @category Config
50
+ */
51
+ export type ResolvedSdkConfig = {
52
+ name?: string;
53
+ logoUrl?: string;
54
+ homepageLink?: string;
55
+ currency?: Currency;
56
+ lang?: Language;
57
+ /** When true, all SDK components should be hidden */
58
+ hidden?: boolean;
59
+ css?: string;
60
+ translations?: Record<string, string>;
61
+ placements?: Record<string, ResolvedPlacement>;
62
+ };
63
+
64
+ /**
65
+ * Internal SDK config store state
66
+ * Merged config: backend > SDK static > defaults
67
+ * Components subscribe to this reactively
68
+ * @category Config
69
+ */
70
+ export type SdkResolvedConfig = {
71
+ /** Whether the backend config has been resolved */
72
+ isResolved: boolean;
73
+
74
+ /** Merchant ID from resolution */
75
+ merchantId: string;
76
+
77
+ /** Domain returned by the resolve endpoint */
78
+ domain?: string;
79
+
80
+ /** Domains allowed for this merchant (used by iframe trust check) */
81
+ allowedDomains?: string[];
82
+
83
+ /** Whether the resolve returned a backend sdkConfig object */
84
+ hasRawSdkConfig?: boolean;
85
+
86
+ /** Merged metadata fields */
87
+ name?: string;
88
+ logoUrl?: string;
89
+ homepageLink?: string;
90
+ lang?: Language;
91
+ currency?: Currency;
92
+
93
+ /** When true, all SDK components should be hidden */
94
+ hidden?: boolean;
95
+
96
+ /** Global CSS from backend config (passed to iframe) */
97
+ css?: string;
98
+
99
+ /** Global translations (for reference / component fallback) */
100
+ translations?: Record<string, string>;
101
+
102
+ /** Named placements (keyed by placement ID) */
103
+ placements?: Record<string, ResolvedPlacement>;
104
+ };
@@ -11,7 +11,12 @@ import type { Address } from "viem";
11
11
  export type SendInteractionParamsType =
12
12
  | {
13
13
  type: "arrival";
14
+ /** @deprecated V1 legacy — use referrerClientId for v2 */
14
15
  referrerWallet?: Address;
16
+ referrerClientId?: string;
17
+ referrerMerchantId?: string;
18
+ /** Epoch seconds timestamp from the referral link creation */
19
+ referralTimestamp?: number;
15
20
  landingUrl?: string;
16
21
  utmSource?: string;
17
22
  utmMedium?: string;
@@ -21,6 +26,10 @@ export type SendInteractionParamsType =
21
26
  }
22
27
  | {
23
28
  type: "sharing";
29
+ /** Epoch seconds timestamp matching the V2 context `t` field embedded in the referral link URL, used for backend correlation */
30
+ sharingTimestamp?: number;
31
+ /** Merchant order ID linking this sharing event to a purchase (stays server-side, never in URL) */
32
+ purchaseId?: string;
24
33
  }
25
34
  | {
26
35
  type: "custom";
package/src/types/rpc.ts CHANGED
@@ -38,7 +38,7 @@ import type { WalletStatusReturnType } from "./rpc/walletStatus";
38
38
  * - Response Type: stream (emits updates when wallet status changes)
39
39
  *
40
40
  * #### frak_displayModal
41
- * - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
41
+ * - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
42
42
  * - Returns: {@link ModalRpcStepsResultType}
43
43
  * - Response Type: promise (one-shot)
44
44
  *
@@ -53,7 +53,7 @@ import type { WalletStatusReturnType } from "./rpc/walletStatus";
53
53
  * - Response Type: promise (one-shot)
54
54
  *
55
55
  * #### frak_displayEmbeddedWallet
56
- * - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
56
+ * - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
57
57
  * - Returns: {@link DisplayEmbeddedWalletResultType}
58
58
  * - Response Type: promise (one-shot)
59
59
  */
@@ -77,6 +77,7 @@ export type IFrameRpcSchema = [
77
77
  requests: ModalRpcStepsInput,
78
78
  metadata: ModalRpcMetadata | undefined,
79
79
  configMetadata: FrakWalletSdkConfig["metadata"],
80
+ placement?: string,
80
81
  ];
81
82
  ReturnType: ModalRpcStepsResultType;
82
83
  },
@@ -89,7 +90,7 @@ export type IFrameRpcSchema = [
89
90
  Method: "frak_prepareSso";
90
91
  Parameters: [
91
92
  params: PrepareSsoParamsType,
92
- name: string,
93
+ name?: string,
93
94
  customCss?: string,
94
95
  ];
95
96
  ReturnType: PrepareSsoReturnType;
@@ -104,7 +105,7 @@ export type IFrameRpcSchema = [
104
105
  Method: "frak_openSso";
105
106
  Parameters: [
106
107
  params: OpenSsoParamsType,
107
- name: string,
108
+ name?: string,
108
109
  customCss?: string,
109
110
  ];
110
111
  ReturnType: OpenSsoReturnType;
@@ -130,6 +131,7 @@ export type IFrameRpcSchema = [
130
131
  Parameters: [
131
132
  request: DisplayEmbeddedWalletParamsType,
132
133
  metadata: FrakWalletSdkConfig["metadata"],
134
+ placement?: string,
133
135
  ];
134
136
  ReturnType: DisplayEmbeddedWalletResultType;
135
137
  },
@@ -137,7 +139,7 @@ export type IFrameRpcSchema = [
137
139
  * Method to send interactions (arrival, sharing, custom events)
138
140
  * Fire-and-forget method - no return value expected
139
141
  * merchantId is resolved from context
140
- * clientId is passed via metadata as safeguard against handshake race condition
142
+ * clientId is passed via metadata as safeguard against race conditions
141
143
  */
142
144
  {
143
145
  Method: "frak_sendInteraction";
@@ -1,14 +1,5 @@
1
- /**
2
- * Types for arrival tracking and referral attribution
3
- * @category Tracking
4
- */
5
-
6
1
  import type { Address } from "viem";
7
2
 
8
- /**
9
- * UTM parameters for marketing attribution
10
- * @category Tracking
11
- */
12
3
  export type UtmParams = {
13
4
  source?: string;
14
5
  medium?: string;
@@ -17,29 +8,17 @@ export type UtmParams = {
17
8
  content?: string;
18
9
  };
19
10
 
20
- /**
21
- * Parameters for tracking an arrival event
22
- * @category Tracking
23
- */
24
11
  export type TrackArrivalParams = {
25
- /**
26
- * The referrer wallet address (from fCtx URL param)
27
- */
12
+ /** @deprecated V1 legacy — use referrerClientId for v2 contexts */
28
13
  referrerWallet?: Address;
29
- /**
30
- * The landing page URL (defaults to current page)
31
- */
14
+ referrerClientId?: string;
15
+ referrerMerchantId?: string;
16
+ /** Epoch seconds timestamp from the referral link creation */
17
+ referralTimestamp?: number;
32
18
  landingUrl?: string;
33
- /**
34
- * UTM parameters for marketing attribution
35
- */
36
19
  utmParams?: UtmParams;
37
20
  };
38
21
 
39
- /**
40
- * Result from tracking an arrival event
41
- * @category Tracking
42
- */
43
22
  export type TrackArrivalResult = {
44
23
  success: boolean;
45
24
  identityGroupId?: string;
@@ -47,14 +26,6 @@ export type TrackArrivalResult = {
47
26
  error?: string;
48
27
  };
49
28
 
50
- /**
51
- * Internal params passed to the trackArrival action
52
- * Includes merchantId resolved from config or fetch
53
- * @internal
54
- */
55
29
  export type TrackArrivalInternalParams = TrackArrivalParams & {
56
- /**
57
- * The merchant ID (UUID from dashboard)
58
- */
59
30
  merchantId: string;
60
31
  };