@frak-labs/core-sdk 0.1.0-beta.6e0d8026 → 0.1.0-beta.8d103039
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/package.json +3 -2
- package/src/actions/displayEmbeddedWallet.ts +20 -0
- package/src/actions/displayModal.ts +131 -0
- package/src/actions/getProductInformation.ts +14 -0
- package/src/actions/index.ts +29 -0
- package/src/actions/openSso.ts +116 -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.ts +32 -0
- package/src/actions/trackPurchaseStatus.ts +53 -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.ts +71 -0
- package/src/clients/transports/iframeLifecycleManager.ts +88 -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 +103 -0
- package/src/interactions/index.ts +5 -0
- package/src/interactions/pressEncoder.ts +53 -0
- package/src/interactions/purchaseEncoder.ts +94 -0
- package/src/interactions/referralEncoder.ts +47 -0
- package/src/interactions/retailEncoder.ts +37 -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 +70 -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.ts +152 -0
- package/src/utils/compression/b64.ts +29 -0
- package/src/utils/compression/compress.ts +11 -0
- package/src/utils/compression/decompress.ts +11 -0
- package/src/utils/compression/index.ts +3 -0
- package/src/utils/computeProductId.ts +11 -0
- package/src/utils/constants.ts +4 -0
- package/src/utils/formatAmount.ts +18 -0
- package/src/utils/getCurrencyAmountKey.ts +15 -0
- package/src/utils/getSupportedCurrency.ts +14 -0
- package/src/utils/getSupportedLocale.ts +16 -0
- package/src/utils/iframeHelper.ts +142 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/sso.ts +119 -0
- package/src/utils/ssoUrlListener.ts +60 -0
- package/src/utils/trackEvent.ts +26 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys for each product types
|
|
3
|
+
* @inline
|
|
4
|
+
*/
|
|
5
|
+
export type ProductTypesKey = keyof typeof productTypes;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* List of the product types per denominator
|
|
9
|
+
*/
|
|
10
|
+
export const productTypes = {
|
|
11
|
+
// content type
|
|
12
|
+
dapp: 1,
|
|
13
|
+
press: 2,
|
|
14
|
+
webshop: 3,
|
|
15
|
+
retail: 4,
|
|
16
|
+
|
|
17
|
+
// feature type
|
|
18
|
+
referral: 30,
|
|
19
|
+
purchase: 31,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Bitmask for each product types
|
|
24
|
+
*/
|
|
25
|
+
export const productTypesMask: Record<ProductTypesKey, bigint> = Object.entries(
|
|
26
|
+
productTypes
|
|
27
|
+
).reduce(
|
|
28
|
+
(acc, [key, value]) => {
|
|
29
|
+
acc[key as ProductTypesKey] = BigInt(1) << BigInt(value);
|
|
30
|
+
return acc;
|
|
31
|
+
},
|
|
32
|
+
{} as Record<ProductTypesKey, bigint>
|
|
33
|
+
);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Clients
|
|
2
|
+
export {
|
|
3
|
+
createIFrameFrakClient,
|
|
4
|
+
setupClient,
|
|
5
|
+
DebugInfoGatherer,
|
|
6
|
+
} from "./clients";
|
|
7
|
+
|
|
8
|
+
// Utils
|
|
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
|
+
|
|
29
|
+
// Constants
|
|
30
|
+
export {
|
|
31
|
+
type ProductTypesKey,
|
|
32
|
+
productTypes,
|
|
33
|
+
productTypesMask,
|
|
34
|
+
} 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
|
+
// Types
|
|
44
|
+
export type {
|
|
45
|
+
// Rpc
|
|
46
|
+
WalletStatusReturnType,
|
|
47
|
+
IFrameRpcSchema,
|
|
48
|
+
PreparedInteraction,
|
|
49
|
+
SendInteractionParamsType,
|
|
50
|
+
SendInteractionReturnType,
|
|
51
|
+
SsoMetadata,
|
|
52
|
+
PrepareSsoParamsType,
|
|
53
|
+
PrepareSsoReturnType,
|
|
54
|
+
OpenSsoParamsType,
|
|
55
|
+
OpenSsoReturnType,
|
|
56
|
+
Currency,
|
|
57
|
+
Language,
|
|
58
|
+
I18nConfig,
|
|
59
|
+
LocalizedI18nConfig,
|
|
60
|
+
TokenAmountType,
|
|
61
|
+
GetProductInformationReturnType,
|
|
62
|
+
// RPC Embedded wallet
|
|
63
|
+
DisplayEmbeddedWalletParamsType,
|
|
64
|
+
DisplayEmbeddedWalletResultType,
|
|
65
|
+
LoggedOutEmbeddedView,
|
|
66
|
+
LoggedInEmbeddedView,
|
|
67
|
+
EmbeddedViewActionReferred,
|
|
68
|
+
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
|
+
FinalActionType,
|
|
88
|
+
// Client
|
|
89
|
+
FrakClient,
|
|
90
|
+
// Transport
|
|
91
|
+
IFrameTransport,
|
|
92
|
+
IFrameLifecycleEvent,
|
|
93
|
+
ClientLifecycleEvent,
|
|
94
|
+
FrakLifecycleEvent,
|
|
95
|
+
// Config
|
|
96
|
+
FrakWalletSdkConfig,
|
|
97
|
+
// Compression
|
|
98
|
+
KeyProvider,
|
|
99
|
+
CompressedData,
|
|
100
|
+
HashProtectedData,
|
|
101
|
+
// Utils
|
|
102
|
+
FrakContext,
|
|
103
|
+
} from "./types";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PressInteractionEncoder } from "./pressEncoder";
|
|
2
|
+
export { ReferralInteractionEncoder } from "./referralEncoder";
|
|
3
|
+
export { PurchaseInteractionEncoder } from "./purchaseEncoder";
|
|
4
|
+
export { WebShopInteractionEncoder } from "./webshopEncoder";
|
|
5
|
+
export { RetailInteractionEncoder } from "./retailEncoder";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Hex, concatHex, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Press interactions allow you to track user engagement with articles or other press content on your platform.
|
|
8
|
+
* After setting up these interactions, you can create acquisition campaign based on the user engagement with your press content.
|
|
9
|
+
*
|
|
10
|
+
* :::info
|
|
11
|
+
* To properly handle press interactions, ensure that the "Press" product type is enabled in your Business dashboard.
|
|
12
|
+
* :::
|
|
13
|
+
*
|
|
14
|
+
* @description Encode press related user interactions
|
|
15
|
+
*
|
|
16
|
+
* @group Interactions Encoder
|
|
17
|
+
*
|
|
18
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
19
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
20
|
+
*/
|
|
21
|
+
export const PressInteractionEncoder = {
|
|
22
|
+
/**
|
|
23
|
+
* Encode an open article interaction
|
|
24
|
+
* @param args
|
|
25
|
+
* @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
|
|
26
|
+
*/
|
|
27
|
+
openArticle({ articleId }: { articleId: Hex }): PreparedInteraction {
|
|
28
|
+
const interactionData = concatHex([
|
|
29
|
+
interactionTypes.press.openArticle,
|
|
30
|
+
pad(articleId, { size: 32 }),
|
|
31
|
+
]);
|
|
32
|
+
return {
|
|
33
|
+
handlerTypeDenominator: toHex(productTypes.press),
|
|
34
|
+
interactionData,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Encode a read article interaction
|
|
40
|
+
* @param args
|
|
41
|
+
* @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
|
|
42
|
+
*/
|
|
43
|
+
readArticle({ articleId }: { articleId: Hex }): PreparedInteraction {
|
|
44
|
+
const interactionData = concatHex([
|
|
45
|
+
interactionTypes.press.readArticle,
|
|
46
|
+
pad(articleId, { size: 32 }),
|
|
47
|
+
]);
|
|
48
|
+
return {
|
|
49
|
+
handlerTypeDenominator: toHex(productTypes.press),
|
|
50
|
+
interactionData,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type Hex, concatHex, encodeAbiParameters, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Purchase interactions allow you to track user purchases on your platform.
|
|
8
|
+
* After setting up these interactions, you can create acquisition campaign based on the user purchase (starting a new one, completed, or even purchase dropped).
|
|
9
|
+
*
|
|
10
|
+
* :::info
|
|
11
|
+
* To properly handle purchase interactions, ensure that the "Purchase" product type is enabled in your Business dashboard, and that you have set up everything correctly in the `Purchasetracker` section.
|
|
12
|
+
* :::
|
|
13
|
+
*
|
|
14
|
+
* :::note
|
|
15
|
+
* The `purchaseId` is used on both interactions. It can be computed like this:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const purchaseId = keccak256(concatHex([productId, toHex(externalPurchaseId)]));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* With:
|
|
22
|
+
* - `productId`: The id of your product, you can find it in the product dashboard.
|
|
23
|
+
* - `externalPurchaseId`: The id of the purchase in your system (e.g. the shopify `order_id`).
|
|
24
|
+
* :::
|
|
25
|
+
*
|
|
26
|
+
* @description Encode purchase related user interactions
|
|
27
|
+
*
|
|
28
|
+
* @group Interactions Encoder
|
|
29
|
+
*
|
|
30
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
31
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
32
|
+
* @see {@link !actions.trackPurchaseStatus | `trackPurchaseStatus()`} Action that will automatically send the purchase upon completion
|
|
33
|
+
* @see [Purchase Webhooks](/wallet-sdk/references-api/webhook) Webhooks to be implemented on your side to confirm a purchase
|
|
34
|
+
* @see [Purchase Proof](/wallet-sdk/references-api/purchaseProof) Get a merklee proof for the purchase
|
|
35
|
+
*/
|
|
36
|
+
export const PurchaseInteractionEncoder = {
|
|
37
|
+
/**
|
|
38
|
+
* Encode a start purchase interaction
|
|
39
|
+
* @param args
|
|
40
|
+
* @param args.purchaseId - The id of the purchase that is being started.
|
|
41
|
+
*/
|
|
42
|
+
startPurchase({ purchaseId }: { purchaseId: Hex }): PreparedInteraction {
|
|
43
|
+
const interactionData = concatHex([
|
|
44
|
+
interactionTypes.purchase.started,
|
|
45
|
+
pad(purchaseId, { size: 32 }),
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
handlerTypeDenominator: toHex(productTypes.purchase),
|
|
49
|
+
interactionData,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Encode a complete purchase interaction
|
|
55
|
+
* @param args
|
|
56
|
+
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
57
|
+
* @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
|
|
58
|
+
*/
|
|
59
|
+
completedPurchase({
|
|
60
|
+
purchaseId,
|
|
61
|
+
proof,
|
|
62
|
+
}: { purchaseId: Hex; proof: Hex[] }): PreparedInteraction {
|
|
63
|
+
const innerData = encodeAbiParameters(
|
|
64
|
+
[{ type: "uint256" }, { type: "bytes32[]" }],
|
|
65
|
+
[BigInt(purchaseId), proof]
|
|
66
|
+
);
|
|
67
|
+
const interactionData = concatHex([
|
|
68
|
+
interactionTypes.purchase.completed,
|
|
69
|
+
innerData,
|
|
70
|
+
]);
|
|
71
|
+
return {
|
|
72
|
+
handlerTypeDenominator: toHex(productTypes.purchase),
|
|
73
|
+
interactionData,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Encode an unsafe complete purchase interaction (when we can't provide the proof)
|
|
79
|
+
* @param args
|
|
80
|
+
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
81
|
+
*/
|
|
82
|
+
unsafeCompletedPurchase({
|
|
83
|
+
purchaseId,
|
|
84
|
+
}: { purchaseId: Hex }): PreparedInteraction {
|
|
85
|
+
const interactionData = concatHex([
|
|
86
|
+
interactionTypes.purchase.unsafeCompleted,
|
|
87
|
+
pad(purchaseId, { size: 32 }),
|
|
88
|
+
]);
|
|
89
|
+
return {
|
|
90
|
+
handlerTypeDenominator: toHex(productTypes.purchase),
|
|
91
|
+
interactionData,
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Address, concatHex, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Referral interactions allow you to track user sharing activities.
|
|
8
|
+
* These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
|
|
9
|
+
*
|
|
10
|
+
* :::info
|
|
11
|
+
* To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
|
|
12
|
+
* :::
|
|
13
|
+
*
|
|
14
|
+
* @description Encode referral related user interactions
|
|
15
|
+
*
|
|
16
|
+
* @group Interactions Encoder
|
|
17
|
+
*
|
|
18
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
19
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
20
|
+
*/
|
|
21
|
+
export const ReferralInteractionEncoder = {
|
|
22
|
+
/**
|
|
23
|
+
* Records the event of a user creating a referral link. Note that this interaction doesn't actually create the link itself; it only sends an event to track that a link was created.
|
|
24
|
+
*/
|
|
25
|
+
createLink(): PreparedInteraction {
|
|
26
|
+
return {
|
|
27
|
+
handlerTypeDenominator: toHex(productTypes.referral),
|
|
28
|
+
interactionData: interactionTypes.referral.createLink,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Encode a referred interaction
|
|
34
|
+
* @param args
|
|
35
|
+
* @param args.referrer - The Ethereum address of the user who made the referral
|
|
36
|
+
*/
|
|
37
|
+
referred({ referrer }: { referrer: Address }): PreparedInteraction {
|
|
38
|
+
const interactionData = concatHex([
|
|
39
|
+
interactionTypes.referral.referred,
|
|
40
|
+
pad(referrer, { size: 32 }),
|
|
41
|
+
]);
|
|
42
|
+
return {
|
|
43
|
+
handlerTypeDenominator: toHex(productTypes.referral),
|
|
44
|
+
interactionData,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Hex, concatHex, pad, toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retail interactions allow you to track user activities on your retails products.
|
|
8
|
+
*
|
|
9
|
+
* :::info
|
|
10
|
+
* To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
|
|
11
|
+
* :::
|
|
12
|
+
*
|
|
13
|
+
* @description Encode retail related user interactions
|
|
14
|
+
*
|
|
15
|
+
* @group Interactions Encoder
|
|
16
|
+
*
|
|
17
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
18
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
19
|
+
*/
|
|
20
|
+
export const RetailInteractionEncoder = {
|
|
21
|
+
/**
|
|
22
|
+
* Encode a customer meeting retail interaction
|
|
23
|
+
* @param args
|
|
24
|
+
* @param args.agencyId - The id of the agency that the customer is meeting with
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
customerMeeting({ agencyId }: { agencyId: Hex }): PreparedInteraction {
|
|
28
|
+
const interactionData = concatHex([
|
|
29
|
+
interactionTypes.retail.customerMeeting,
|
|
30
|
+
pad(agencyId, { size: 32 }),
|
|
31
|
+
]);
|
|
32
|
+
return {
|
|
33
|
+
handlerTypeDenominator: toHex(productTypes.retail),
|
|
34
|
+
interactionData,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { toHex } from "viem";
|
|
2
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
3
|
+
import { productTypes } from "../constants/productTypes";
|
|
4
|
+
import type { PreparedInteraction } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Webshop interactions allow you to track user activities on your webshop.
|
|
8
|
+
*
|
|
9
|
+
* :::info
|
|
10
|
+
* To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
|
|
11
|
+
* :::
|
|
12
|
+
*
|
|
13
|
+
* @description Encode webshop related user interactions
|
|
14
|
+
*
|
|
15
|
+
* @group Interactions Encoder
|
|
16
|
+
*
|
|
17
|
+
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
18
|
+
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
19
|
+
*/
|
|
20
|
+
export const WebShopInteractionEncoder = {
|
|
21
|
+
/**
|
|
22
|
+
* Encode an open webshop interaction
|
|
23
|
+
*/
|
|
24
|
+
open(): PreparedInteraction {
|
|
25
|
+
return {
|
|
26
|
+
handlerTypeDenominator: toHex(productTypes.webshop),
|
|
27
|
+
interactionData: interactionTypes.webshop.open,
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OpenPanel } from "@openpanel/web";
|
|
2
|
+
import type { FrakWalletSdkConfig } from "./config";
|
|
3
|
+
import type { IFrameTransport } from "./transport";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Representing a Frak client, used to interact with the Frak Wallet
|
|
7
|
+
*/
|
|
8
|
+
export type FrakClient = {
|
|
9
|
+
config: FrakWalletSdkConfig;
|
|
10
|
+
debugInfo: {
|
|
11
|
+
formatDebugInfo: (error: Error | unknown | string) => string;
|
|
12
|
+
};
|
|
13
|
+
openPanel?: OpenPanel;
|
|
14
|
+
} & IFrameTransport;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The received encoded data from a client
|
|
3
|
+
* -> The encoded should contain a HashProtectedData once decoded
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export type CompressedData = Uint8Array;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The encoded data to send to a client / received by a client
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
12
|
+
export type HashProtectedData<DataType> = Readonly<
|
|
13
|
+
DataType & {
|
|
14
|
+
validationHash: string;
|
|
15
|
+
}
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Represent a key provider used for the hashed and secure compression
|
|
20
|
+
* @ignore
|
|
21
|
+
*/
|
|
22
|
+
export type KeyProvider<DataType> = (value: DataType) => string[];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All the currencies available
|
|
3
|
+
* @category Config
|
|
4
|
+
*/
|
|
5
|
+
export type Currency = "eur" | "usd" | "gbp";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* All the languages available
|
|
9
|
+
* @category Config
|
|
10
|
+
*/
|
|
11
|
+
export type Language = "fr" | "en";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for the Frak Wallet SDK
|
|
15
|
+
* @category Config
|
|
16
|
+
*/
|
|
17
|
+
export type FrakWalletSdkConfig = {
|
|
18
|
+
/**
|
|
19
|
+
* The Frak wallet url
|
|
20
|
+
* @defaultValue "https://wallet.frak.id"
|
|
21
|
+
*/
|
|
22
|
+
walletUrl?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Some metadata about your implementation of the Frak SDK
|
|
25
|
+
*/
|
|
26
|
+
metadata: {
|
|
27
|
+
/**
|
|
28
|
+
* Your application name (will be displayed in a few modals and in SSO)
|
|
29
|
+
*/
|
|
30
|
+
name: string;
|
|
31
|
+
/**
|
|
32
|
+
* Language to display in the modal
|
|
33
|
+
* If undefined, will default to the browser language
|
|
34
|
+
*/
|
|
35
|
+
lang?: Language;
|
|
36
|
+
/**
|
|
37
|
+
* The currency to display in the modal
|
|
38
|
+
* @defaultValue `"eur"`
|
|
39
|
+
*/
|
|
40
|
+
currency?: Currency;
|
|
41
|
+
/**
|
|
42
|
+
* The logo URL that will be displayed in a few components
|
|
43
|
+
*/
|
|
44
|
+
logoUrl?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The homepage link that could be displayed in a few components
|
|
47
|
+
*/
|
|
48
|
+
homepageLink?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Some customization for the modal
|
|
52
|
+
*/
|
|
53
|
+
customizations?: {
|
|
54
|
+
/**
|
|
55
|
+
* Custom CSS styles to apply to the modals and components
|
|
56
|
+
*/
|
|
57
|
+
css?: `${string}.css`;
|
|
58
|
+
/**
|
|
59
|
+
* Custom i18n configuration for the modal
|
|
60
|
+
*/
|
|
61
|
+
i18n?: I18nConfig;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The domain name of your application
|
|
65
|
+
* @defaultValue window.location.host
|
|
66
|
+
*/
|
|
67
|
+
domain?: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Custom i18n configuration for the modal
|
|
72
|
+
* See [i18next json format](https://www.i18next.com/misc/json-format#i18next-json-v4)
|
|
73
|
+
*
|
|
74
|
+
* Available variables
|
|
75
|
+
* - `{{ productName }}` : The name of your website (`metadata.name`)
|
|
76
|
+
* - `{{ productOrigin }}` : The origin url of your website
|
|
77
|
+
* - `{{ estimatedReward }}` : The estimated reward for the user (based on the specific `targetInteraction` you can specify, or the max referrer reward if no target interaction is specified)
|
|
78
|
+
*
|
|
79
|
+
* Context of the translation [see i18n context](https://www.i18next.com/translation-function/context)
|
|
80
|
+
* - For modal display, the key of the final action (`sharing`, `reward`, or undefined)
|
|
81
|
+
* - For embedded wallet display, the key of the logged in action (`sharing` or undefined)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Multi language config
|
|
86
|
+
* const multiI18n = {
|
|
87
|
+
* fr: {
|
|
88
|
+
* "sdk.modal.title": "Titre de modal",
|
|
89
|
+
* "sdk.modal.description": "Description de modal, avec {{ estimatedReward }} de gains possible",
|
|
90
|
+
* },
|
|
91
|
+
* en: "https://example.com/en.json"
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* // Single language config
|
|
95
|
+
* const singleI18n = {
|
|
96
|
+
* "sdk.modal.title": "Modal title",
|
|
97
|
+
* "sdk.modal.description": "Modal description, with {{ estimatedReward }} of gains possible",
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @category Config
|
|
102
|
+
*/
|
|
103
|
+
export type I18nConfig =
|
|
104
|
+
| Record<Language, LocalizedI18nConfig>
|
|
105
|
+
| LocalizedI18nConfig;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A localized i18n config
|
|
109
|
+
* @category Config
|
|
110
|
+
*/
|
|
111
|
+
export type LocalizedI18nConfig = `${string}.css` | { [key: string]: string };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Rpc related
|
|
2
|
+
export type { WalletStatusReturnType } from "./rpc/walletStatus";
|
|
3
|
+
export type {
|
|
4
|
+
DisplayEmbeddedWalletParamsType,
|
|
5
|
+
DisplayEmbeddedWalletResultType,
|
|
6
|
+
LoggedOutEmbeddedView,
|
|
7
|
+
LoggedInEmbeddedView,
|
|
8
|
+
EmbeddedViewActionReferred,
|
|
9
|
+
EmbeddedViewActionSharing,
|
|
10
|
+
} from "./rpc/embedded";
|
|
11
|
+
export type {
|
|
12
|
+
SsoMetadata,
|
|
13
|
+
OpenSsoParamsType,
|
|
14
|
+
OpenSsoReturnType,
|
|
15
|
+
PrepareSsoParamsType,
|
|
16
|
+
PrepareSsoReturnType,
|
|
17
|
+
} from "./rpc/sso";
|
|
18
|
+
export type {
|
|
19
|
+
TokenAmountType,
|
|
20
|
+
GetProductInformationReturnType,
|
|
21
|
+
} from "./rpc/productInformation";
|
|
22
|
+
export type {
|
|
23
|
+
PreparedInteraction,
|
|
24
|
+
SendInteractionParamsType,
|
|
25
|
+
SendInteractionReturnType,
|
|
26
|
+
} from "./rpc/interaction";
|
|
27
|
+
export type { IFrameRpcSchema } from "./rpc";
|
|
28
|
+
// Client related
|
|
29
|
+
export type { FrakClient } from "./client";
|
|
30
|
+
export type { IFrameTransport, FrakLifecycleEvent } from "./transport";
|
|
31
|
+
export type {
|
|
32
|
+
IFrameLifecycleEvent,
|
|
33
|
+
ClientLifecycleEvent,
|
|
34
|
+
} from "./lifecycle";
|
|
35
|
+
export type {
|
|
36
|
+
FrakWalletSdkConfig,
|
|
37
|
+
Currency,
|
|
38
|
+
Language,
|
|
39
|
+
I18nConfig,
|
|
40
|
+
LocalizedI18nConfig,
|
|
41
|
+
} from "./config";
|
|
42
|
+
export type {
|
|
43
|
+
CompressedData,
|
|
44
|
+
HashProtectedData,
|
|
45
|
+
KeyProvider,
|
|
46
|
+
} from "./compression";
|
|
47
|
+
// Modal related
|
|
48
|
+
export type {
|
|
49
|
+
ModalStepTypes,
|
|
50
|
+
ModalRpcStepsInput,
|
|
51
|
+
ModalRpcStepsResultType,
|
|
52
|
+
DisplayModalParamsType,
|
|
53
|
+
ModalRpcMetadata,
|
|
54
|
+
} from "./rpc/displayModal";
|
|
55
|
+
export type {
|
|
56
|
+
ModalStepMetadata,
|
|
57
|
+
LoginModalStepType,
|
|
58
|
+
SiweAuthenticateModalStepType,
|
|
59
|
+
SiweAuthenticationParams,
|
|
60
|
+
SiweAuthenticateReturnType,
|
|
61
|
+
SendTransactionTxType,
|
|
62
|
+
SendTransactionModalStepType,
|
|
63
|
+
SendTransactionReturnType,
|
|
64
|
+
OpenInteractionSessionReturnType,
|
|
65
|
+
OpenInteractionSessionModalStepType,
|
|
66
|
+
FinalModalStepType,
|
|
67
|
+
FinalActionType,
|
|
68
|
+
} from "./rpc/modal";
|
|
69
|
+
// Utils
|
|
70
|
+
export type { FrakContext } from "./context";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { I18nConfig } from "../config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Event related to the iframe lifecycle
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export type ClientLifecycleEvent =
|
|
8
|
+
| CustomCssEvent
|
|
9
|
+
| CustomI18nEvent
|
|
10
|
+
| RestoreBackupEvent
|
|
11
|
+
| HearbeatEvent
|
|
12
|
+
| HandshakeResponse
|
|
13
|
+
| SsoRedirectCompleteEvent;
|
|
14
|
+
|
|
15
|
+
type CustomCssEvent = {
|
|
16
|
+
clientLifecycle: "modal-css";
|
|
17
|
+
data: { cssLink: string };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type CustomI18nEvent = {
|
|
21
|
+
clientLifecycle: "modal-i18n";
|
|
22
|
+
data: { i18n: I18nConfig };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type RestoreBackupEvent = {
|
|
26
|
+
clientLifecycle: "restore-backup";
|
|
27
|
+
data: { backup: string };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type HearbeatEvent = {
|
|
31
|
+
clientLifecycle: "heartbeat";
|
|
32
|
+
data?: never;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type HandshakeResponse = {
|
|
36
|
+
clientLifecycle: "handshake-response";
|
|
37
|
+
data: {
|
|
38
|
+
token: string;
|
|
39
|
+
currentUrl: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type SsoRedirectCompleteEvent = {
|
|
44
|
+
clientLifecycle: "sso-redirect-complete";
|
|
45
|
+
data: { compressed: string };
|
|
46
|
+
};
|