@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.
- package/README.md +58 -0
- package/cdn/bundle.js +14 -0
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +3 -3
- package/dist/actions.d.ts +3 -3
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +1 -1
- package/dist/bundle.d.cts +4 -6
- package/dist/bundle.d.ts +4 -6
- package/dist/bundle.js +1 -1
- package/dist/computeLegacyProductId-CCAZvLa5.d.cts +537 -0
- package/dist/computeLegacyProductId-b5cUWdAm.d.ts +537 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/{openSso-D--Airj6.d.cts → openSso-B0g7-807.d.cts} +173 -136
- package/dist/{openSso-DsKJ4y0j.d.ts → openSso-CMzwvaCa.d.ts} +173 -136
- package/dist/setupClient-BICl5fdX.js +13 -0
- package/dist/setupClient-nl8Dhh4V.cjs +13 -0
- package/dist/siweAuthenticate-BWmI2_TN.cjs +1 -0
- package/dist/{index-d8xS4ryI.d.ts → siweAuthenticate-CVigMOxz.d.cts} +113 -92
- package/dist/{index-C6FxkWPC.d.cts → siweAuthenticate-CnCZ7mok.d.ts} +113 -92
- package/dist/siweAuthenticate-zczqxm0a.js +1 -0
- package/dist/trackEvent-CeLFVzZn.js +1 -0
- package/dist/trackEvent-Ew5r5zfI.cjs +1 -0
- package/package.json +11 -22
- package/src/actions/displayEmbeddedWallet.ts +1 -0
- package/src/actions/displayModal.test.ts +12 -11
- package/src/actions/displayModal.ts +7 -18
- package/src/actions/ensureIdentity.ts +68 -0
- package/src/actions/{getProductInformation.test.ts → getMerchantInformation.test.ts} +33 -50
- package/src/actions/getMerchantInformation.ts +16 -0
- package/src/actions/index.ts +3 -2
- package/src/actions/openSso.ts +4 -2
- package/src/actions/referral/processReferral.test.ts +117 -242
- package/src/actions/referral/processReferral.ts +134 -204
- package/src/actions/referral/referralInteraction.test.ts +4 -12
- package/src/actions/referral/referralInteraction.ts +3 -13
- package/src/actions/sendInteraction.ts +46 -22
- package/src/actions/trackPurchaseStatus.test.ts +354 -141
- package/src/actions/trackPurchaseStatus.ts +48 -11
- package/src/actions/watchWalletStatus.ts +2 -3
- package/src/actions/wrapper/modalBuilder.test.ts +0 -14
- package/src/actions/wrapper/modalBuilder.ts +3 -12
- package/src/bundle.ts +0 -1
- package/src/clients/createIFrameFrakClient.ts +10 -5
- package/src/clients/transports/iframeLifecycleManager.test.ts +163 -4
- package/src/clients/transports/iframeLifecycleManager.ts +172 -33
- package/src/constants/interactionTypes.ts +12 -41
- package/src/index.ts +27 -16
- package/src/types/config.ts +6 -0
- package/src/types/context.ts +48 -6
- package/src/types/index.ts +15 -11
- package/src/types/lifecycle/client.ts +24 -1
- package/src/types/lifecycle/iframe.ts +6 -0
- package/src/types/rpc/displayModal.ts +2 -4
- package/src/types/rpc/embedded/index.ts +2 -2
- package/src/types/rpc/interaction.ts +31 -39
- package/src/types/rpc/merchantInformation.ts +77 -0
- package/src/types/rpc/modal/index.ts +0 -4
- package/src/types/rpc/modal/login.ts +5 -1
- package/src/types/rpc/walletStatus.ts +1 -7
- package/src/types/rpc.ts +22 -30
- package/src/types/tracking.ts +31 -0
- package/src/utils/FrakContext.test.ts +270 -186
- package/src/utils/FrakContext.ts +78 -56
- package/src/utils/backendUrl.test.ts +83 -0
- package/src/utils/backendUrl.ts +62 -0
- package/src/utils/clientId.test.ts +41 -0
- package/src/utils/clientId.ts +43 -0
- package/src/utils/compression/compress.test.ts +1 -1
- package/src/utils/compression/compress.ts +2 -2
- package/src/utils/compression/decompress.test.ts +8 -4
- package/src/utils/compression/decompress.ts +2 -2
- package/src/utils/{computeProductId.ts → computeLegacyProductId.ts} +2 -2
- package/src/utils/constants.ts +5 -0
- package/src/utils/deepLinkWithFallback.test.ts +243 -0
- package/src/utils/deepLinkWithFallback.ts +103 -0
- package/src/utils/formatAmount.ts +6 -0
- package/src/utils/iframeHelper.test.ts +18 -5
- package/src/utils/iframeHelper.ts +10 -3
- package/src/utils/index.ts +16 -1
- package/src/utils/merchantId.test.ts +653 -0
- package/src/utils/merchantId.ts +143 -0
- package/src/utils/sso.ts +18 -11
- package/src/utils/trackEvent.test.ts +23 -5
- package/src/utils/trackEvent.ts +13 -0
- package/cdn/bundle.iife.js +0 -14
- package/dist/actions-B5j-i1p0.cjs +0 -1
- package/dist/actions-q090Z0oR.js +0 -1
- package/dist/index-7OZ39x1U.d.ts +0 -195
- package/dist/index-CRsQWnTs.d.cts +0 -351
- package/dist/index-Ck1hudEi.d.ts +0 -351
- package/dist/index-zDq-VlKx.d.cts +0 -195
- package/dist/interaction-DMJ3ZfaF.d.cts +0 -45
- package/dist/interaction-KX1h9a7V.d.ts +0 -45
- package/dist/interactions-DnfM3oe0.js +0 -1
- package/dist/interactions-EIXhNLf6.cjs +0 -1
- package/dist/interactions.cjs +0 -1
- package/dist/interactions.d.cts +0 -2
- package/dist/interactions.d.ts +0 -2
- package/dist/interactions.js +0 -1
- package/dist/productTypes-BUkXJKZ7.cjs +0 -1
- package/dist/productTypes-CGb1MmBF.js +0 -1
- package/dist/src-1LQ4eLq5.js +0 -13
- package/dist/src-hW71KjPN.cjs +0 -13
- package/dist/trackEvent-CHnYa85W.js +0 -1
- package/dist/trackEvent-GuQm_1Nm.cjs +0 -1
- package/src/actions/getProductInformation.ts +0 -14
- package/src/actions/openSso.test.ts +0 -407
- package/src/actions/sendInteraction.test.ts +0 -219
- package/src/constants/interactionTypes.test.ts +0 -128
- package/src/constants/productTypes.test.ts +0 -130
- package/src/constants/productTypes.ts +0 -33
- package/src/interactions/index.ts +0 -5
- package/src/interactions/pressEncoder.test.ts +0 -215
- package/src/interactions/pressEncoder.ts +0 -53
- package/src/interactions/purchaseEncoder.test.ts +0 -291
- package/src/interactions/purchaseEncoder.ts +0 -99
- package/src/interactions/referralEncoder.test.ts +0 -170
- package/src/interactions/referralEncoder.ts +0 -47
- package/src/interactions/retailEncoder.test.ts +0 -107
- package/src/interactions/retailEncoder.ts +0 -37
- package/src/interactions/webshopEncoder.test.ts +0 -56
- package/src/interactions/webshopEncoder.ts +0 -30
- package/src/types/rpc/modal/openSession.ts +0 -25
- package/src/types/rpc/productInformation.ts +0 -59
- package/src/utils/computeProductId.test.ts +0 -80
- package/src/utils/sso.test.ts +0 -361
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Address } from "viem";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
* ####
|
|
50
|
+
* #### frak_getMerchantInformation
|
|
60
51
|
* - Params: None
|
|
61
|
-
* - Returns: {@link
|
|
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
|
|
136
|
-
* - Is
|
|
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: "
|
|
120
|
+
Method: "frak_getMerchantInformation";
|
|
143
121
|
Parameters?: undefined;
|
|
144
|
-
ReturnType:
|
|
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
|
+
};
|