@frak-labs/core-sdk 0.0.19-beta.f259d7fc → 0.1.0-beta.263acd1e
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/cdn/bundle.iife.js +14 -0
- package/dist/actions-CEEObPYc.js +1 -0
- package/dist/actions-DbQhWYx8.cjs +1 -0
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +3 -1400
- package/dist/actions.d.ts +3 -1400
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +1 -13
- package/dist/bundle.d.cts +6 -1927
- package/dist/bundle.d.ts +6 -1927
- package/dist/bundle.js +1 -13
- package/dist/index-7OZ39x1U.d.ts +195 -0
- package/dist/index-C6FxkWPC.d.cts +511 -0
- package/dist/index-UFX7xCg3.d.ts +351 -0
- package/dist/index-d8xS4ryI.d.ts +511 -0
- package/dist/index-p4FqSp8z.d.cts +351 -0
- package/dist/index-zDq-VlKx.d.cts +195 -0
- package/dist/index.cjs +1 -13
- package/dist/index.d.cts +4 -1269
- package/dist/index.d.ts +4 -1269
- package/dist/index.js +1 -13
- package/dist/interaction-DMJ3ZfaF.d.cts +45 -0
- package/dist/interaction-KX1h9a7V.d.ts +45 -0
- package/dist/interactions-DnfM3oe0.js +1 -0
- package/dist/interactions-EIXhNLf6.cjs +1 -0
- package/dist/interactions.cjs +1 -1
- package/dist/interactions.d.cts +2 -182
- package/dist/interactions.d.ts +2 -182
- package/dist/interactions.js +1 -1
- package/dist/openSso-D--Airj6.d.cts +1018 -0
- package/dist/openSso-DsKJ4y0j.d.ts +1018 -0
- package/dist/productTypes-BUkXJKZ7.cjs +1 -0
- package/dist/productTypes-CGb1MmBF.js +1 -0
- package/dist/src-B_xO0AR6.cjs +13 -0
- package/dist/src-D2d52OZa.js +13 -0
- package/dist/trackEvent-CHnYa85W.js +1 -0
- package/dist/trackEvent-GuQm_1Nm.cjs +1 -0
- package/package.json +24 -19
- package/src/actions/displayEmbeddedWallet.test.ts +194 -0
- package/src/actions/displayEmbeddedWallet.ts +20 -0
- package/src/actions/displayModal.test.ts +387 -0
- package/src/actions/displayModal.ts +131 -0
- package/src/actions/getProductInformation.test.ts +133 -0
- package/src/actions/getProductInformation.ts +14 -0
- package/src/actions/index.ts +29 -0
- package/src/actions/openSso.test.ts +407 -0
- package/src/actions/openSso.ts +116 -0
- package/src/actions/prepareSso.test.ts +223 -0
- package/src/actions/prepareSso.ts +48 -0
- package/src/actions/referral/processReferral.ts +230 -0
- package/src/actions/referral/referralInteraction.ts +57 -0
- package/src/actions/sendInteraction.test.ts +219 -0
- package/src/actions/sendInteraction.ts +32 -0
- package/src/actions/trackPurchaseStatus.test.ts +287 -0
- package/src/actions/trackPurchaseStatus.ts +53 -0
- package/src/actions/watchWalletStatus.test.ts +372 -0
- package/src/actions/watchWalletStatus.ts +94 -0
- package/src/actions/wrapper/modalBuilder.ts +212 -0
- package/src/actions/wrapper/sendTransaction.ts +62 -0
- package/src/actions/wrapper/siweAuthenticate.ts +94 -0
- package/src/bundle.ts +3 -0
- package/src/clients/DebugInfo.ts +182 -0
- package/src/clients/createIFrameFrakClient.ts +287 -0
- package/src/clients/index.ts +3 -0
- package/src/clients/setupClient.test.ts +343 -0
- package/src/clients/setupClient.ts +73 -0
- package/src/clients/transports/iframeLifecycleManager.test.ts +399 -0
- package/src/clients/transports/iframeLifecycleManager.ts +90 -0
- package/src/constants/interactionTypes.ts +44 -0
- package/src/constants/locales.ts +14 -0
- package/src/constants/productTypes.ts +33 -0
- package/src/index.ts +101 -0
- package/src/interactions/index.ts +5 -0
- package/src/interactions/pressEncoder.test.ts +215 -0
- package/src/interactions/pressEncoder.ts +53 -0
- package/src/interactions/purchaseEncoder.test.ts +291 -0
- package/src/interactions/purchaseEncoder.ts +99 -0
- package/src/interactions/referralEncoder.test.ts +170 -0
- package/src/interactions/referralEncoder.ts +47 -0
- package/src/interactions/retailEncoder.test.ts +107 -0
- package/src/interactions/retailEncoder.ts +37 -0
- package/src/interactions/webshopEncoder.test.ts +56 -0
- package/src/interactions/webshopEncoder.ts +30 -0
- package/src/types/client.ts +14 -0
- package/src/types/compression.ts +22 -0
- package/src/types/config.ts +111 -0
- package/src/types/context.ts +13 -0
- package/src/types/index.ts +71 -0
- package/src/types/lifecycle/client.ts +46 -0
- package/src/types/lifecycle/iframe.ts +35 -0
- package/src/types/lifecycle/index.ts +2 -0
- package/src/types/rpc/displayModal.ts +84 -0
- package/src/types/rpc/embedded/index.ts +68 -0
- package/src/types/rpc/embedded/loggedIn.ts +55 -0
- package/src/types/rpc/embedded/loggedOut.ts +28 -0
- package/src/types/rpc/interaction.ts +43 -0
- package/src/types/rpc/modal/final.ts +46 -0
- package/src/types/rpc/modal/generic.ts +46 -0
- package/src/types/rpc/modal/index.ts +20 -0
- package/src/types/rpc/modal/login.ts +32 -0
- package/src/types/rpc/modal/openSession.ts +25 -0
- package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
- package/src/types/rpc/modal/transaction.ts +33 -0
- package/src/types/rpc/productInformation.ts +59 -0
- package/src/types/rpc/sso.ts +80 -0
- package/src/types/rpc/walletStatus.ts +35 -0
- package/src/types/rpc.ts +158 -0
- package/src/types/transport.ts +34 -0
- package/src/utils/FrakContext.test.ts +407 -0
- package/src/utils/FrakContext.ts +158 -0
- package/src/utils/compression/b64.test.ts +181 -0
- package/src/utils/compression/b64.ts +29 -0
- package/src/utils/compression/compress.test.ts +123 -0
- package/src/utils/compression/compress.ts +11 -0
- package/src/utils/compression/decompress.test.ts +145 -0
- package/src/utils/compression/decompress.ts +11 -0
- package/src/utils/compression/index.ts +3 -0
- package/src/utils/computeProductId.test.ts +80 -0
- package/src/utils/computeProductId.ts +11 -0
- package/src/utils/constants.test.ts +23 -0
- package/src/utils/constants.ts +4 -0
- package/src/utils/formatAmount.test.ts +113 -0
- package/src/utils/formatAmount.ts +18 -0
- package/src/utils/getCurrencyAmountKey.test.ts +44 -0
- package/src/utils/getCurrencyAmountKey.ts +15 -0
- package/src/utils/getSupportedCurrency.test.ts +51 -0
- package/src/utils/getSupportedCurrency.ts +14 -0
- package/src/utils/getSupportedLocale.test.ts +64 -0
- package/src/utils/getSupportedLocale.ts +16 -0
- package/src/utils/iframeHelper.test.ts +450 -0
- package/src/utils/iframeHelper.ts +143 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/sso.test.ts +361 -0
- package/src/utils/sso.ts +119 -0
- package/src/utils/ssoUrlListener.ts +60 -0
- package/src/utils/trackEvent.test.ts +162 -0
- package/src/utils/trackEvent.ts +26 -0
- package/cdn/bundle.js +0 -19
- package/cdn/bundle.js.LICENSE.txt +0 -10
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Hex } from "viem";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SSO Metadata
|
|
5
|
+
*/
|
|
6
|
+
export type SsoMetadata = {
|
|
7
|
+
/**
|
|
8
|
+
* URL to your client, if provided will be displayed in the SSO header
|
|
9
|
+
*/
|
|
10
|
+
logoUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Link to your homepage, if referenced your app name will contain a link on the sso page
|
|
13
|
+
*/
|
|
14
|
+
homepageLink?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Params for preparing SSO (generating URL)
|
|
19
|
+
* Same as OpenSsoParamsType but without openInSameWindow (popup-only operation)
|
|
20
|
+
* @group RPC Schema
|
|
21
|
+
*/
|
|
22
|
+
export type PrepareSsoParamsType = {
|
|
23
|
+
/**
|
|
24
|
+
* Redirect URL after the SSO (optional)
|
|
25
|
+
*/
|
|
26
|
+
redirectUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* If the SSO should directly exit after completion
|
|
29
|
+
* @defaultValue true
|
|
30
|
+
*/
|
|
31
|
+
directExit?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Language of the SSO page (optional)
|
|
34
|
+
* It will default to the current user language (or "en" if unsupported language)
|
|
35
|
+
*/
|
|
36
|
+
lang?: "en" | "fr";
|
|
37
|
+
/**
|
|
38
|
+
* Custom SSO metadata
|
|
39
|
+
*/
|
|
40
|
+
metadata?: SsoMetadata;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Response after preparing SSO
|
|
45
|
+
* @group RPC Schema
|
|
46
|
+
*/
|
|
47
|
+
export type PrepareSsoReturnType = {
|
|
48
|
+
/**
|
|
49
|
+
* The SSO URL that should be opened in a popup
|
|
50
|
+
*/
|
|
51
|
+
ssoUrl: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Response after an SSO has been openned
|
|
56
|
+
*/
|
|
57
|
+
export type OpenSsoReturnType = {
|
|
58
|
+
/**
|
|
59
|
+
* Optional wallet address, returned when SSO completes via postMessage
|
|
60
|
+
* Note: Only present when SSO flow completes (not immediately on open)
|
|
61
|
+
*/
|
|
62
|
+
wallet?: Hex;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Params to start a SSO
|
|
67
|
+
* @group RPC Schema
|
|
68
|
+
*/
|
|
69
|
+
export type OpenSsoParamsType = PrepareSsoParamsType & {
|
|
70
|
+
/**
|
|
71
|
+
* Indicate whether we want todo the flow within the same window context, or if we want to do it with an external popup window openned
|
|
72
|
+
* Note: Default true if redirectUrl is present, otherwise, false
|
|
73
|
+
*/
|
|
74
|
+
openInSameWindow?: boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Custom SSO popup url if user want additionnal customisation
|
|
78
|
+
*/
|
|
79
|
+
ssoPopupUrl?: string;
|
|
80
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RPC Response for the method `frak_listenToWalletStatus`
|
|
5
|
+
* @group RPC Schema
|
|
6
|
+
*/
|
|
7
|
+
export type WalletStatusReturnType = WalletConnected | WalletNotConnected;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @ignore
|
|
11
|
+
* @inline
|
|
12
|
+
*/
|
|
13
|
+
export type WalletConnected = {
|
|
14
|
+
key: "connected";
|
|
15
|
+
// The user wallet address
|
|
16
|
+
wallet: Address;
|
|
17
|
+
// The interaction token, used to push interactions to the delegator if needed
|
|
18
|
+
interactionToken?: string;
|
|
19
|
+
// The current onchain interaction session of the user
|
|
20
|
+
interactionSession?: {
|
|
21
|
+
startTimestamp: number;
|
|
22
|
+
endTimestamp: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
* @inline
|
|
29
|
+
*/
|
|
30
|
+
export type WalletNotConnected = {
|
|
31
|
+
key: "not-connected";
|
|
32
|
+
wallet?: never;
|
|
33
|
+
interactionToken?: never;
|
|
34
|
+
interactionSession?: never;
|
|
35
|
+
};
|
package/src/types/rpc.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { Hex } from "viem";
|
|
2
|
+
import type { FrakWalletSdkConfig } from "./config";
|
|
3
|
+
import type {
|
|
4
|
+
ModalRpcMetadata,
|
|
5
|
+
ModalRpcStepsInput,
|
|
6
|
+
ModalRpcStepsResultType,
|
|
7
|
+
} from "./rpc/displayModal";
|
|
8
|
+
import type {
|
|
9
|
+
DisplayEmbeddedWalletParamsType,
|
|
10
|
+
DisplayEmbeddedWalletResultType,
|
|
11
|
+
} from "./rpc/embedded";
|
|
12
|
+
import type {
|
|
13
|
+
PreparedInteraction,
|
|
14
|
+
SendInteractionReturnType,
|
|
15
|
+
} from "./rpc/interaction";
|
|
16
|
+
import type { GetProductInformationReturnType } from "./rpc/productInformation";
|
|
17
|
+
import type {
|
|
18
|
+
OpenSsoParamsType,
|
|
19
|
+
OpenSsoReturnType,
|
|
20
|
+
PrepareSsoParamsType,
|
|
21
|
+
PrepareSsoReturnType,
|
|
22
|
+
} from "./rpc/sso";
|
|
23
|
+
import type { WalletStatusReturnType } from "./rpc/walletStatus";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* RPC interface that's used for the iframe communication
|
|
27
|
+
*
|
|
28
|
+
* Define all the methods available within the iFrame RPC client with response type annotations
|
|
29
|
+
*
|
|
30
|
+
* @group RPC Schema
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Each method in the schema now includes a ResponseType field that indicates:
|
|
34
|
+
* - "promise": One-shot request that resolves once
|
|
35
|
+
* - "stream": Streaming request that can emit multiple values
|
|
36
|
+
*
|
|
37
|
+
* ### Methods:
|
|
38
|
+
*
|
|
39
|
+
* #### frak_listenToWalletStatus
|
|
40
|
+
* - Params: None
|
|
41
|
+
* - Returns: {@link WalletStatusReturnType}
|
|
42
|
+
* - Response Type: stream (emits updates when wallet status changes)
|
|
43
|
+
*
|
|
44
|
+
* #### frak_displayModal
|
|
45
|
+
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
46
|
+
* - Returns: {@link ModalRpcStepsResultType}
|
|
47
|
+
* - Response Type: promise (one-shot)
|
|
48
|
+
*
|
|
49
|
+
* #### frak_sendInteraction
|
|
50
|
+
* - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
|
|
51
|
+
* - Returns: {@link SendInteractionReturnType}
|
|
52
|
+
* - Response Type: promise (one-shot)
|
|
53
|
+
*
|
|
54
|
+
* #### frak_sso
|
|
55
|
+
* - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
56
|
+
* - Returns: {@link OpenSsoReturnType}
|
|
57
|
+
* - Response Type: promise (one-shot)
|
|
58
|
+
*
|
|
59
|
+
* #### frak_getProductInformation
|
|
60
|
+
* - Params: None
|
|
61
|
+
* - Returns: {@link GetProductInformationReturnType}
|
|
62
|
+
* - Response Type: promise (one-shot)
|
|
63
|
+
*
|
|
64
|
+
* #### frak_displayEmbeddedWallet
|
|
65
|
+
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
66
|
+
* - Returns: {@link DisplayEmbeddedWalletResultType}
|
|
67
|
+
* - Response Type: promise (one-shot)
|
|
68
|
+
*/
|
|
69
|
+
export type IFrameRpcSchema = [
|
|
70
|
+
/**
|
|
71
|
+
* Method used to listen to the wallet status
|
|
72
|
+
* This is a streaming method that emits updates when wallet status changes
|
|
73
|
+
*/
|
|
74
|
+
{
|
|
75
|
+
Method: "frak_listenToWalletStatus";
|
|
76
|
+
Parameters?: undefined;
|
|
77
|
+
ReturnType: WalletStatusReturnType;
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Method to display a modal with the provided steps
|
|
81
|
+
* This is a one-shot request
|
|
82
|
+
*/
|
|
83
|
+
{
|
|
84
|
+
Method: "frak_displayModal";
|
|
85
|
+
Parameters: [
|
|
86
|
+
requests: ModalRpcStepsInput,
|
|
87
|
+
metadata: ModalRpcMetadata | undefined,
|
|
88
|
+
configMetadata: FrakWalletSdkConfig["metadata"],
|
|
89
|
+
];
|
|
90
|
+
ReturnType: ModalRpcStepsResultType;
|
|
91
|
+
},
|
|
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
|
+
/**
|
|
106
|
+
* Method to prepare SSO (generate URL for popup)
|
|
107
|
+
* Returns the SSO URL that should be opened in a popup
|
|
108
|
+
* Only used for popup flows (not redirect flows)
|
|
109
|
+
*/
|
|
110
|
+
{
|
|
111
|
+
Method: "frak_prepareSso";
|
|
112
|
+
Parameters: [
|
|
113
|
+
params: PrepareSsoParamsType,
|
|
114
|
+
name: string,
|
|
115
|
+
customCss?: string,
|
|
116
|
+
];
|
|
117
|
+
ReturnType: PrepareSsoReturnType;
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Method to open/trigger SSO
|
|
121
|
+
* Either triggers redirect (if openInSameWindow/redirectUrl)
|
|
122
|
+
* Or waits for popup completion (if popup mode)
|
|
123
|
+
* This method handles BOTH redirect and popup flows
|
|
124
|
+
*/
|
|
125
|
+
{
|
|
126
|
+
Method: "frak_openSso";
|
|
127
|
+
Parameters: [
|
|
128
|
+
params: OpenSsoParamsType,
|
|
129
|
+
name: string,
|
|
130
|
+
customCss?: string,
|
|
131
|
+
];
|
|
132
|
+
ReturnType: OpenSsoReturnType;
|
|
133
|
+
},
|
|
134
|
+
/**
|
|
135
|
+
* Method to get current product information's
|
|
136
|
+
* - Is product minted?
|
|
137
|
+
* - Does it have running campaign?
|
|
138
|
+
* - Estimated reward on actions
|
|
139
|
+
* This is a one-shot request
|
|
140
|
+
*/
|
|
141
|
+
{
|
|
142
|
+
Method: "frak_getProductInformation";
|
|
143
|
+
Parameters?: undefined;
|
|
144
|
+
ReturnType: GetProductInformationReturnType;
|
|
145
|
+
},
|
|
146
|
+
/**
|
|
147
|
+
* Method to show the embedded wallet, with potential customization
|
|
148
|
+
* This is a one-shot request
|
|
149
|
+
*/
|
|
150
|
+
{
|
|
151
|
+
Method: "frak_displayEmbeddedWallet";
|
|
152
|
+
Parameters: [
|
|
153
|
+
request: DisplayEmbeddedWalletParamsType,
|
|
154
|
+
metadata: FrakWalletSdkConfig["metadata"],
|
|
155
|
+
];
|
|
156
|
+
ReturnType: DisplayEmbeddedWalletResultType;
|
|
157
|
+
},
|
|
158
|
+
];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
|
|
2
|
+
import type { ClientLifecycleEvent, IFrameLifecycleEvent } from "./lifecycle";
|
|
3
|
+
import type { IFrameRpcSchema } from "./rpc";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* IFrame transport interface
|
|
7
|
+
*/
|
|
8
|
+
export type IFrameTransport = {
|
|
9
|
+
/**
|
|
10
|
+
* Wait for the connection to be established
|
|
11
|
+
*/
|
|
12
|
+
waitForConnection: Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Wait for the setup to be done
|
|
15
|
+
*/
|
|
16
|
+
waitForSetup: Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Function used to perform a single request via the iframe transport
|
|
19
|
+
*/
|
|
20
|
+
request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
|
|
21
|
+
/**
|
|
22
|
+
* Function used to listen to a request response via the iframe transport
|
|
23
|
+
*/
|
|
24
|
+
listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
|
|
25
|
+
/**
|
|
26
|
+
* Function used to destroy the iframe transport
|
|
27
|
+
*/
|
|
28
|
+
destroy: () => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Represent an iframe event
|
|
33
|
+
*/
|
|
34
|
+
export type FrakLifecycleEvent = IFrameLifecycleEvent | ClientLifecycleEvent;
|