@frak-labs/core-sdk 0.0.19 → 0.1.0-beta.00226d62
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 -2022
- package/dist/bundle.d.ts +6 -2022
- 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 -1373
- package/dist/index.d.ts +4 -1373
- 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 +27 -18
- 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.test.ts +357 -0
- package/src/actions/referral/processReferral.ts +230 -0
- package/src/actions/referral/referralInteraction.test.ts +153 -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.test.ts +253 -0
- package/src/actions/wrapper/modalBuilder.ts +212 -0
- package/src/actions/wrapper/sendTransaction.test.ts +164 -0
- package/src/actions/wrapper/sendTransaction.ts +62 -0
- package/src/actions/wrapper/siweAuthenticate.test.ts +290 -0
- package/src/actions/wrapper/siweAuthenticate.ts +94 -0
- package/src/bundle.ts +3 -0
- package/src/clients/DebugInfo.test.ts +418 -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.test.ts +128 -0
- package/src/constants/interactionTypes.ts +44 -0
- package/src/constants/locales.ts +14 -0
- package/src/constants/productTypes.test.ts +130 -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.test.ts +252 -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,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for RetailInteractionEncoder
|
|
3
|
+
* Tests encoding of retail-related user interactions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { pad, toHex } from "viem";
|
|
7
|
+
import { describe, expect, test } from "../../tests/vitest-fixtures";
|
|
8
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
9
|
+
import { productTypes } from "../constants/productTypes";
|
|
10
|
+
import { RetailInteractionEncoder } from "./retailEncoder";
|
|
11
|
+
|
|
12
|
+
describe("RetailInteractionEncoder", () => {
|
|
13
|
+
describe("customerMeeting", () => {
|
|
14
|
+
test("should encode customer meeting interaction with correct structure", ({
|
|
15
|
+
mockAgencyId,
|
|
16
|
+
}) => {
|
|
17
|
+
const interaction = RetailInteractionEncoder.customerMeeting({
|
|
18
|
+
agencyId: mockAgencyId,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Should return PreparedInteraction structure
|
|
22
|
+
expect(interaction).toHaveProperty("handlerTypeDenominator");
|
|
23
|
+
expect(interaction).toHaveProperty("interactionData");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("should use retail product type in handlerTypeDenominator", ({
|
|
27
|
+
mockAgencyId,
|
|
28
|
+
}) => {
|
|
29
|
+
const interaction = RetailInteractionEncoder.customerMeeting({
|
|
30
|
+
agencyId: mockAgencyId,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Should use retail product type (4)
|
|
34
|
+
const expectedDenominator = toHex(productTypes.retail);
|
|
35
|
+
expect(interaction.handlerTypeDenominator).toBe(
|
|
36
|
+
expectedDenominator
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("should include customerMeeting interaction type in data", ({
|
|
41
|
+
mockAgencyId,
|
|
42
|
+
}) => {
|
|
43
|
+
const interaction = RetailInteractionEncoder.customerMeeting({
|
|
44
|
+
agencyId: mockAgencyId,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Should start with customerMeeting interaction type
|
|
48
|
+
expect(interaction.interactionData).toContain(
|
|
49
|
+
interactionTypes.retail.customerMeeting
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("should pad agency ID to 32 bytes", ({ mockAgencyId }) => {
|
|
54
|
+
const interaction = RetailInteractionEncoder.customerMeeting({
|
|
55
|
+
agencyId: mockAgencyId,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Agency ID should be padded to 32 bytes
|
|
59
|
+
const paddedAgencyId = pad(mockAgencyId, { size: 32 });
|
|
60
|
+
expect(interaction.interactionData).toContain(
|
|
61
|
+
paddedAgencyId.slice(2)
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("should produce consistent output for same agency ID", ({
|
|
66
|
+
mockAgencyId,
|
|
67
|
+
}) => {
|
|
68
|
+
const interaction1 = RetailInteractionEncoder.customerMeeting({
|
|
69
|
+
agencyId: mockAgencyId,
|
|
70
|
+
});
|
|
71
|
+
const interaction2 = RetailInteractionEncoder.customerMeeting({
|
|
72
|
+
agencyId: mockAgencyId,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Same input should produce same output
|
|
76
|
+
expect(interaction1).toEqual(interaction2);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("should produce different output for different agency IDs", () => {
|
|
80
|
+
const agencyId1 =
|
|
81
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001" as const;
|
|
82
|
+
const agencyId2 =
|
|
83
|
+
"0x0000000000000000000000000000000000000000000000000000000000000002" as const;
|
|
84
|
+
|
|
85
|
+
const interaction1 = RetailInteractionEncoder.customerMeeting({
|
|
86
|
+
agencyId: agencyId1,
|
|
87
|
+
});
|
|
88
|
+
const interaction2 = RetailInteractionEncoder.customerMeeting({
|
|
89
|
+
agencyId: agencyId2,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Different agency IDs should produce different interaction data
|
|
93
|
+
expect(interaction1.interactionData).not.toBe(
|
|
94
|
+
interaction2.interactionData
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("should produce valid hex string", ({ mockAgencyId }) => {
|
|
99
|
+
const interaction = RetailInteractionEncoder.customerMeeting({
|
|
100
|
+
agencyId: mockAgencyId,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Should be valid hex string starting with 0x
|
|
104
|
+
expect(interaction.interactionData).toMatch(/^0x[0-9a-f]+$/);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { concatHex, type Hex, 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,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for WebShopInteractionEncoder
|
|
3
|
+
* Tests encoding of webshop-related user interactions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { toHex } from "viem";
|
|
7
|
+
import { describe, expect, it } from "../../tests/vitest-fixtures";
|
|
8
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
9
|
+
import { productTypes } from "../constants/productTypes";
|
|
10
|
+
import { WebShopInteractionEncoder } from "./webshopEncoder";
|
|
11
|
+
|
|
12
|
+
describe("WebShopInteractionEncoder", () => {
|
|
13
|
+
describe("open", () => {
|
|
14
|
+
it("should encode open webshop interaction with correct structure", () => {
|
|
15
|
+
const interaction = WebShopInteractionEncoder.open();
|
|
16
|
+
|
|
17
|
+
// Should return PreparedInteraction structure
|
|
18
|
+
expect(interaction).toHaveProperty("handlerTypeDenominator");
|
|
19
|
+
expect(interaction).toHaveProperty("interactionData");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should use webshop product type in handlerTypeDenominator", () => {
|
|
23
|
+
const interaction = WebShopInteractionEncoder.open();
|
|
24
|
+
|
|
25
|
+
// Should use webshop product type (3)
|
|
26
|
+
const expectedDenominator = toHex(productTypes.webshop);
|
|
27
|
+
expect(interaction.handlerTypeDenominator).toBe(
|
|
28
|
+
expectedDenominator
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should use open interaction type in data", () => {
|
|
33
|
+
const interaction = WebShopInteractionEncoder.open();
|
|
34
|
+
|
|
35
|
+
// Should use open interaction type
|
|
36
|
+
expect(interaction.interactionData).toBe(
|
|
37
|
+
interactionTypes.webshop.open
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should produce consistent output (no parameters)", () => {
|
|
42
|
+
const interaction1 = WebShopInteractionEncoder.open();
|
|
43
|
+
const interaction2 = WebShopInteractionEncoder.open();
|
|
44
|
+
|
|
45
|
+
// Should always produce the same output
|
|
46
|
+
expect(interaction1).toEqual(interaction2);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should produce valid hex string", () => {
|
|
50
|
+
const interaction = WebShopInteractionEncoder.open();
|
|
51
|
+
|
|
52
|
+
// Should be valid hex string starting with 0x
|
|
53
|
+
expect(interaction.interactionData).toMatch(/^0x[0-9a-f]+$/);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -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,71 @@
|
|
|
1
|
+
// Rpc related
|
|
2
|
+
|
|
3
|
+
// Client related
|
|
4
|
+
export type { FrakClient } from "./client";
|
|
5
|
+
export type {
|
|
6
|
+
CompressedData,
|
|
7
|
+
HashProtectedData,
|
|
8
|
+
KeyProvider,
|
|
9
|
+
} from "./compression";
|
|
10
|
+
export type {
|
|
11
|
+
Currency,
|
|
12
|
+
FrakWalletSdkConfig,
|
|
13
|
+
I18nConfig,
|
|
14
|
+
Language,
|
|
15
|
+
LocalizedI18nConfig,
|
|
16
|
+
} from "./config";
|
|
17
|
+
// Utils
|
|
18
|
+
export type { FrakContext } from "./context";
|
|
19
|
+
export type {
|
|
20
|
+
ClientLifecycleEvent,
|
|
21
|
+
IFrameLifecycleEvent,
|
|
22
|
+
} from "./lifecycle";
|
|
23
|
+
export type { IFrameRpcSchema } from "./rpc";
|
|
24
|
+
// Modal related
|
|
25
|
+
export type {
|
|
26
|
+
DisplayModalParamsType,
|
|
27
|
+
ModalRpcMetadata,
|
|
28
|
+
ModalRpcStepsInput,
|
|
29
|
+
ModalRpcStepsResultType,
|
|
30
|
+
ModalStepTypes,
|
|
31
|
+
} from "./rpc/displayModal";
|
|
32
|
+
export type {
|
|
33
|
+
DisplayEmbeddedWalletParamsType,
|
|
34
|
+
DisplayEmbeddedWalletResultType,
|
|
35
|
+
EmbeddedViewActionReferred,
|
|
36
|
+
EmbeddedViewActionSharing,
|
|
37
|
+
LoggedInEmbeddedView,
|
|
38
|
+
LoggedOutEmbeddedView,
|
|
39
|
+
} from "./rpc/embedded";
|
|
40
|
+
export type {
|
|
41
|
+
PreparedInteraction,
|
|
42
|
+
SendInteractionParamsType,
|
|
43
|
+
SendInteractionReturnType,
|
|
44
|
+
} from "./rpc/interaction";
|
|
45
|
+
export type {
|
|
46
|
+
FinalActionType,
|
|
47
|
+
FinalModalStepType,
|
|
48
|
+
LoginModalStepType,
|
|
49
|
+
ModalStepMetadata,
|
|
50
|
+
OpenInteractionSessionModalStepType,
|
|
51
|
+
OpenInteractionSessionReturnType,
|
|
52
|
+
SendTransactionModalStepType,
|
|
53
|
+
SendTransactionReturnType,
|
|
54
|
+
SendTransactionTxType,
|
|
55
|
+
SiweAuthenticateModalStepType,
|
|
56
|
+
SiweAuthenticateReturnType,
|
|
57
|
+
SiweAuthenticationParams,
|
|
58
|
+
} from "./rpc/modal";
|
|
59
|
+
export type {
|
|
60
|
+
GetProductInformationReturnType,
|
|
61
|
+
TokenAmountType,
|
|
62
|
+
} from "./rpc/productInformation";
|
|
63
|
+
export type {
|
|
64
|
+
OpenSsoParamsType,
|
|
65
|
+
OpenSsoReturnType,
|
|
66
|
+
PrepareSsoParamsType,
|
|
67
|
+
PrepareSsoReturnType,
|
|
68
|
+
SsoMetadata,
|
|
69
|
+
} from "./rpc/sso";
|
|
70
|
+
export type { WalletStatusReturnType } from "./rpc/walletStatus";
|
|
71
|
+
export type { FrakLifecycleEvent, IFrameTransport } from "./transport";
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event related to the iframe lifecycle
|
|
3
|
+
* @ignore
|
|
4
|
+
*/
|
|
5
|
+
export type IFrameLifecycleEvent =
|
|
6
|
+
| {
|
|
7
|
+
iframeLifecycle: "connected" | "show" | "hide" | "remove-backup";
|
|
8
|
+
data?: never;
|
|
9
|
+
}
|
|
10
|
+
| DoBackupEvent
|
|
11
|
+
| HandshakeRequestEvent
|
|
12
|
+
| RedirectRequestEvent;
|
|
13
|
+
|
|
14
|
+
type DoBackupEvent = {
|
|
15
|
+
iframeLifecycle: "do-backup";
|
|
16
|
+
data: { backup?: string };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type HandshakeRequestEvent = {
|
|
20
|
+
iframeLifecycle: "handshake";
|
|
21
|
+
data: {
|
|
22
|
+
token: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type RedirectRequestEvent = {
|
|
27
|
+
iframeLifecycle: "redirect";
|
|
28
|
+
data: {
|
|
29
|
+
/**
|
|
30
|
+
* The base url to redirect to
|
|
31
|
+
* If it contain a query param `u`, the client need will suffix the current url to the base url
|
|
32
|
+
*/
|
|
33
|
+
baseRedirectUrl: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { FullInteractionTypesKey } from "../../constants/interactionTypes";
|
|
2
|
+
import type { I18nConfig } from "../config";
|
|
3
|
+
import type {
|
|
4
|
+
FinalModalStepType,
|
|
5
|
+
LoginModalStepType,
|
|
6
|
+
OpenInteractionSessionModalStepType,
|
|
7
|
+
SendTransactionModalStepType,
|
|
8
|
+
SiweAuthenticateModalStepType,
|
|
9
|
+
} from "./modal";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generic type of steps we will display in the modal to the end user
|
|
13
|
+
* @group Modal Display
|
|
14
|
+
*/
|
|
15
|
+
export type ModalStepTypes =
|
|
16
|
+
| LoginModalStepType
|
|
17
|
+
| SiweAuthenticateModalStepType
|
|
18
|
+
| SendTransactionModalStepType
|
|
19
|
+
| OpenInteractionSessionModalStepType
|
|
20
|
+
| FinalModalStepType;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Type for the result of a modal request
|
|
24
|
+
* Just the `returns` type of each `ModalStepTypes`
|
|
25
|
+
* @typeParam T - The list of modal steps we expect to have in the modal
|
|
26
|
+
* @group Modal Display
|
|
27
|
+
* @group RPC Schema
|
|
28
|
+
*/
|
|
29
|
+
export type ModalRpcStepsResultType<
|
|
30
|
+
T extends ModalStepTypes[] = ModalStepTypes[],
|
|
31
|
+
> = {
|
|
32
|
+
[K in T[number]["key"]]: Extract<T[number], { key: K }>["returns"];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Type for the RPC input of a modal
|
|
37
|
+
* Just the `params` type of each `ModalStepTypes`
|
|
38
|
+
* @typeParam T - The list of modal steps we expect to have in the modal
|
|
39
|
+
* @group Modal Display
|
|
40
|
+
* @group RPC Schema
|
|
41
|
+
*/
|
|
42
|
+
export type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> =
|
|
43
|
+
{
|
|
44
|
+
[K in T[number]["key"]]?: Extract<T[number], { key: K }>["params"];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* RPC metadata for the modal, used on top level modal configuration
|
|
49
|
+
* @group Modal Display
|
|
50
|
+
* @group RPC Schema
|
|
51
|
+
*/
|
|
52
|
+
export type ModalRpcMetadata = {
|
|
53
|
+
header?: {
|
|
54
|
+
title?: string;
|
|
55
|
+
icon?: string;
|
|
56
|
+
};
|
|
57
|
+
targetInteraction?: FullInteractionTypesKey;
|
|
58
|
+
/**
|
|
59
|
+
* Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
|
|
60
|
+
*/
|
|
61
|
+
i18n?: I18nConfig;
|
|
62
|
+
} & (
|
|
63
|
+
| {
|
|
64
|
+
isDismissible: true;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
|
|
67
|
+
*/
|
|
68
|
+
dismissActionTxt?: string;
|
|
69
|
+
}
|
|
70
|
+
| {
|
|
71
|
+
isDismissible?: false;
|
|
72
|
+
dismissActionTxt?: never;
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Params used to display a modal
|
|
78
|
+
* @typeParam T - The list of modal steps we expect to have in the modal
|
|
79
|
+
* @group Modal Display
|
|
80
|
+
*/
|
|
81
|
+
export type DisplayModalParamsType<T extends ModalStepTypes[]> = {
|
|
82
|
+
steps: ModalRpcStepsInput<T>;
|
|
83
|
+
metadata?: ModalRpcMetadata;
|
|
84
|
+
};
|