@frak-labs/core-sdk 0.1.0-beta.afa252b0 → 0.1.0-beta.b0bd1f8a
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 -1481
- package/dist/actions.d.ts +3 -1481
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +1 -13
- package/dist/bundle.d.cts +6 -2087
- package/dist/bundle.d.ts +6 -2087
- 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 -1387
- package/dist/index.d.ts +4 -1387
- 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 +23 -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.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,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for ReferralInteractionEncoder
|
|
3
|
+
* Tests encoding of referral-related user interactions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { pad, toHex } from "viem";
|
|
7
|
+
import { describe, expect, it, test } from "../../tests/vitest-fixtures";
|
|
8
|
+
import { interactionTypes } from "../constants/interactionTypes";
|
|
9
|
+
import { productTypes } from "../constants/productTypes";
|
|
10
|
+
import { ReferralInteractionEncoder } from "./referralEncoder";
|
|
11
|
+
|
|
12
|
+
describe("ReferralInteractionEncoder", () => {
|
|
13
|
+
describe("createLink", () => {
|
|
14
|
+
it("should encode create link interaction with correct structure", () => {
|
|
15
|
+
const interaction = ReferralInteractionEncoder.createLink();
|
|
16
|
+
|
|
17
|
+
// Should return PreparedInteraction structure
|
|
18
|
+
expect(interaction).toHaveProperty("handlerTypeDenominator");
|
|
19
|
+
expect(interaction).toHaveProperty("interactionData");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should use referral product type in handlerTypeDenominator", () => {
|
|
23
|
+
const interaction = ReferralInteractionEncoder.createLink();
|
|
24
|
+
|
|
25
|
+
// Should use referral product type (30)
|
|
26
|
+
const expectedDenominator = toHex(productTypes.referral);
|
|
27
|
+
expect(interaction.handlerTypeDenominator).toBe(
|
|
28
|
+
expectedDenominator
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should use createLink interaction type in data", () => {
|
|
33
|
+
const interaction = ReferralInteractionEncoder.createLink();
|
|
34
|
+
|
|
35
|
+
// Should use createLink interaction type
|
|
36
|
+
expect(interaction.interactionData).toBe(
|
|
37
|
+
interactionTypes.referral.createLink
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should produce consistent output (no parameters)", () => {
|
|
42
|
+
const interaction1 = ReferralInteractionEncoder.createLink();
|
|
43
|
+
const interaction2 = ReferralInteractionEncoder.createLink();
|
|
44
|
+
|
|
45
|
+
// Should always produce the same output
|
|
46
|
+
expect(interaction1).toEqual(interaction2);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("referred", () => {
|
|
51
|
+
test("should encode referred interaction with correct structure", ({
|
|
52
|
+
mockReferrerAddress,
|
|
53
|
+
}) => {
|
|
54
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
55
|
+
referrer: mockReferrerAddress,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Should return PreparedInteraction structure
|
|
59
|
+
expect(interaction).toHaveProperty("handlerTypeDenominator");
|
|
60
|
+
expect(interaction).toHaveProperty("interactionData");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("should use referral product type in handlerTypeDenominator", ({
|
|
64
|
+
mockReferrerAddress,
|
|
65
|
+
}) => {
|
|
66
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
67
|
+
referrer: mockReferrerAddress,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Should use referral product type (30)
|
|
71
|
+
const expectedDenominator = toHex(productTypes.referral);
|
|
72
|
+
expect(interaction.handlerTypeDenominator).toBe(
|
|
73
|
+
expectedDenominator
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("should include referred interaction type in data", ({
|
|
78
|
+
mockReferrerAddress,
|
|
79
|
+
}) => {
|
|
80
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
81
|
+
referrer: mockReferrerAddress,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Should start with referred interaction type
|
|
85
|
+
expect(interaction.interactionData).toContain(
|
|
86
|
+
interactionTypes.referral.referred
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("should pad referrer address to 32 bytes", ({
|
|
91
|
+
mockReferrerAddress,
|
|
92
|
+
}) => {
|
|
93
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
94
|
+
referrer: mockReferrerAddress,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Referrer address should be padded to 32 bytes
|
|
98
|
+
const paddedAddress = pad(mockReferrerAddress, { size: 32 });
|
|
99
|
+
expect(interaction.interactionData).toContain(
|
|
100
|
+
paddedAddress.slice(2)
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("should produce different output for different referrers", () => {
|
|
105
|
+
const referrer1 =
|
|
106
|
+
"0x1234567890123456789012345678901234567890" as const;
|
|
107
|
+
const referrer2 =
|
|
108
|
+
"0xabcdefabcdefabcdefabcdefabcdefabcdefabcd" as const;
|
|
109
|
+
|
|
110
|
+
const interaction1 = ReferralInteractionEncoder.referred({
|
|
111
|
+
referrer: referrer1,
|
|
112
|
+
});
|
|
113
|
+
const interaction2 = ReferralInteractionEncoder.referred({
|
|
114
|
+
referrer: referrer2,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Different referrers should produce different interaction data
|
|
118
|
+
expect(interaction1.interactionData).not.toBe(
|
|
119
|
+
interaction2.interactionData
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("should produce consistent output for same referrer", ({
|
|
124
|
+
mockReferrerAddress,
|
|
125
|
+
}) => {
|
|
126
|
+
const interaction1 = ReferralInteractionEncoder.referred({
|
|
127
|
+
referrer: mockReferrerAddress,
|
|
128
|
+
});
|
|
129
|
+
const interaction2 = ReferralInteractionEncoder.referred({
|
|
130
|
+
referrer: mockReferrerAddress,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Same referrer should produce same output
|
|
134
|
+
expect(interaction1).toEqual(interaction2);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("interaction data format", () => {
|
|
139
|
+
test("should produce valid hex strings", ({ mockReferrerAddress }) => {
|
|
140
|
+
const createLinkInteraction =
|
|
141
|
+
ReferralInteractionEncoder.createLink();
|
|
142
|
+
const referredInteraction = ReferralInteractionEncoder.referred({
|
|
143
|
+
referrer: mockReferrerAddress,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Both should be valid hex strings starting with 0x
|
|
147
|
+
expect(createLinkInteraction.interactionData).toMatch(
|
|
148
|
+
/^0x[0-9a-f]+$/
|
|
149
|
+
);
|
|
150
|
+
expect(referredInteraction.interactionData).toMatch(
|
|
151
|
+
/^0x[0-9a-f]+$/
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("should have different interaction types", ({
|
|
156
|
+
mockReferrerAddress,
|
|
157
|
+
}) => {
|
|
158
|
+
const createLinkInteraction =
|
|
159
|
+
ReferralInteractionEncoder.createLink();
|
|
160
|
+
const referredInteraction = ReferralInteractionEncoder.referred({
|
|
161
|
+
referrer: mockReferrerAddress,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Different interaction types should produce different data
|
|
165
|
+
expect(createLinkInteraction.interactionData).not.toBe(
|
|
166
|
+
referredInteraction.interactionData
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -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,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";
|