@frak-labs/core-sdk 0.1.0 → 0.1.1-beta.1e44255d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/cdn/bundle.js +3 -8
- 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 +4 -1927
- package/dist/bundle.d.ts +4 -1927
- package/dist/bundle.js +1 -13
- package/dist/computeLegacyProductId-BkyJ4rEY.d.ts +538 -0
- package/dist/computeLegacyProductId-Raks6FXg.d.cts +538 -0
- package/dist/index.cjs +1 -13
- package/dist/index.d.cts +3 -1269
- package/dist/index.d.ts +3 -1269
- package/dist/index.js +1 -13
- package/dist/openSso-BCJGchIb.d.cts +1022 -0
- package/dist/openSso-DG-_9CED.d.ts +1022 -0
- package/dist/setupClient-Cfwpu08d.js +13 -0
- package/dist/setupClient-Dh8ljuhV.cjs +13 -0
- package/dist/siweAuthenticate-BH7Dn7nZ.d.cts +536 -0
- package/dist/siweAuthenticate-BJHbtty4.js +1 -0
- package/dist/siweAuthenticate-Btem4QHs.d.ts +536 -0
- package/dist/siweAuthenticate-Cwj3HP0m.cjs +1 -0
- package/dist/trackEvent-M2RLTQ2p.js +1 -0
- package/dist/trackEvent-T_R9ER2S.cjs +1 -0
- package/package.json +25 -31
- package/src/actions/displayEmbeddedWallet.test.ts +194 -0
- package/src/actions/displayEmbeddedWallet.ts +21 -0
- package/src/actions/displayModal.test.ts +388 -0
- package/src/actions/displayModal.ts +120 -0
- package/src/actions/ensureIdentity.ts +68 -0
- package/src/actions/getMerchantInformation.test.ts +116 -0
- package/src/actions/getMerchantInformation.ts +16 -0
- package/src/actions/index.ts +30 -0
- package/src/actions/openSso.ts +118 -0
- package/src/actions/prepareSso.test.ts +223 -0
- package/src/actions/prepareSso.ts +48 -0
- package/src/actions/referral/processReferral.test.ts +248 -0
- package/src/actions/referral/processReferral.ts +232 -0
- package/src/actions/referral/referralInteraction.test.ts +147 -0
- package/src/actions/referral/referralInteraction.ts +52 -0
- package/src/actions/sendInteraction.ts +56 -0
- package/src/actions/trackPurchaseStatus.test.ts +500 -0
- package/src/actions/trackPurchaseStatus.ts +90 -0
- package/src/actions/watchWalletStatus.test.ts +372 -0
- package/src/actions/watchWalletStatus.ts +93 -0
- package/src/actions/wrapper/modalBuilder.test.ts +239 -0
- package/src/actions/wrapper/modalBuilder.ts +203 -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 +2 -0
- package/src/clients/DebugInfo.test.ts +418 -0
- package/src/clients/DebugInfo.ts +182 -0
- package/src/clients/createIFrameFrakClient.ts +292 -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 +558 -0
- package/src/clients/transports/iframeLifecycleManager.ts +229 -0
- package/src/constants/interactionTypes.ts +15 -0
- package/src/constants/locales.ts +14 -0
- package/src/index.ts +109 -0
- package/src/types/client.ts +14 -0
- package/src/types/compression.ts +22 -0
- package/src/types/config.ts +117 -0
- package/src/types/context.ts +13 -0
- package/src/types/index.ts +74 -0
- package/src/types/lifecycle/client.ts +69 -0
- package/src/types/lifecycle/iframe.ts +41 -0
- package/src/types/lifecycle/index.ts +2 -0
- package/src/types/rpc/displayModal.ts +82 -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 +30 -0
- package/src/types/rpc/merchantInformation.ts +77 -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 +16 -0
- package/src/types/rpc/modal/login.ts +36 -0
- package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
- package/src/types/rpc/modal/transaction.ts +33 -0
- package/src/types/rpc/sso.ts +80 -0
- package/src/types/rpc/walletStatus.ts +29 -0
- package/src/types/rpc.ts +150 -0
- package/src/types/tracking.ts +60 -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/backendUrl.test.ts +83 -0
- package/src/utils/backendUrl.ts +62 -0
- package/src/utils/clientId.test.ts +41 -0
- package/src/utils/clientId.ts +43 -0
- package/src/utils/compression/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 +149 -0
- package/src/utils/compression/decompress.ts +11 -0
- package/src/utils/compression/index.ts +3 -0
- package/src/utils/computeLegacyProductId.ts +11 -0
- package/src/utils/constants.test.ts +23 -0
- package/src/utils/constants.ts +9 -0
- package/src/utils/deepLinkWithFallback.test.ts +243 -0
- package/src/utils/deepLinkWithFallback.ts +103 -0
- package/src/utils/formatAmount.test.ts +113 -0
- package/src/utils/formatAmount.ts +24 -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 +463 -0
- package/src/utils/iframeHelper.ts +150 -0
- package/src/utils/index.ts +36 -0
- package/src/utils/merchantId.test.ts +653 -0
- package/src/utils/merchantId.ts +143 -0
- package/src/utils/sso.ts +126 -0
- package/src/utils/ssoUrlListener.test.ts +252 -0
- package/src/utils/ssoUrlListener.ts +60 -0
- package/src/utils/trackEvent.test.ts +180 -0
- package/src/utils/trackEvent.ts +41 -0
- package/cdn/bundle.js.LICENSE.txt +0 -10
- package/dist/interactions.cjs +0 -1
- package/dist/interactions.d.cts +0 -182
- package/dist/interactions.d.ts +0 -182
- package/dist/interactions.js +0 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for trackEvent utility function
|
|
3
|
+
* Tests OpenPanel event tracking wrapper
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
afterEach,
|
|
8
|
+
beforeEach,
|
|
9
|
+
describe,
|
|
10
|
+
expect,
|
|
11
|
+
it,
|
|
12
|
+
vi,
|
|
13
|
+
} from "../../tests/vitest-fixtures";
|
|
14
|
+
import type { FrakClient } from "../types";
|
|
15
|
+
import { trackEvent } from "./trackEvent";
|
|
16
|
+
|
|
17
|
+
describe("trackEvent", () => {
|
|
18
|
+
let mockClient: FrakClient;
|
|
19
|
+
let consoleDebugSpy: any;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
// Create mock client
|
|
23
|
+
mockClient = {
|
|
24
|
+
openPanel: {
|
|
25
|
+
track: vi.fn(),
|
|
26
|
+
},
|
|
27
|
+
} as unknown as FrakClient;
|
|
28
|
+
|
|
29
|
+
// Spy on console.debug
|
|
30
|
+
consoleDebugSpy = vi
|
|
31
|
+
.spyOn(console, "debug")
|
|
32
|
+
.mockImplementation(() => {});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
consoleDebugSpy.mockRestore();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("success cases", () => {
|
|
40
|
+
it("should track event with client", () => {
|
|
41
|
+
trackEvent(mockClient, "share_button_clicked");
|
|
42
|
+
|
|
43
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
44
|
+
"share_button_clicked",
|
|
45
|
+
{}
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should track event with props", () => {
|
|
50
|
+
const props = { userId: "123", page: "home" };
|
|
51
|
+
trackEvent(mockClient, "wallet_button_clicked", props);
|
|
52
|
+
|
|
53
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
54
|
+
"wallet_button_clicked",
|
|
55
|
+
props
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should track share_modal_error event", () => {
|
|
60
|
+
const props = { error: "Network error" };
|
|
61
|
+
trackEvent(mockClient, "share_modal_error", props);
|
|
62
|
+
|
|
63
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
64
|
+
"share_modal_error",
|
|
65
|
+
props
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should track user_referred_started event", () => {
|
|
70
|
+
trackEvent(mockClient, "user_referred_started");
|
|
71
|
+
|
|
72
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
73
|
+
"user_referred_started",
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should track user_referred_completed event", () => {
|
|
79
|
+
trackEvent(mockClient, "user_referred_completed");
|
|
80
|
+
|
|
81
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
82
|
+
"user_referred_completed",
|
|
83
|
+
{}
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should track user_referred_error event", () => {
|
|
88
|
+
trackEvent(mockClient, "user_referred_error");
|
|
89
|
+
|
|
90
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
91
|
+
"user_referred_error",
|
|
92
|
+
{}
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("without client", () => {
|
|
98
|
+
it("should not throw when client is undefined", () => {
|
|
99
|
+
expect(() => {
|
|
100
|
+
trackEvent(undefined, "share_button_clicked");
|
|
101
|
+
}).not.toThrow();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should log debug message when client is undefined", () => {
|
|
105
|
+
trackEvent(undefined, "wallet_button_clicked");
|
|
106
|
+
|
|
107
|
+
expect(consoleDebugSpy).toHaveBeenCalledWith(
|
|
108
|
+
"[Frak] No client provided, skipping event tracking"
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should not call track when client is undefined", () => {
|
|
113
|
+
const trackMock = vi.fn();
|
|
114
|
+
const undefinedClient = undefined;
|
|
115
|
+
|
|
116
|
+
trackEvent(undefinedClient, "share_button_clicked");
|
|
117
|
+
|
|
118
|
+
expect(trackMock).not.toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("error handling", () => {
|
|
123
|
+
it("should catch and log errors from track()", () => {
|
|
124
|
+
const error = new Error("Track failed");
|
|
125
|
+
mockClient.openPanel = {
|
|
126
|
+
track: vi.fn().mockImplementation(() => {
|
|
127
|
+
throw error;
|
|
128
|
+
}),
|
|
129
|
+
} as any;
|
|
130
|
+
|
|
131
|
+
expect(() => {
|
|
132
|
+
trackEvent(mockClient, "share_button_clicked");
|
|
133
|
+
}).not.toThrow();
|
|
134
|
+
|
|
135
|
+
expect(consoleDebugSpy).toHaveBeenCalledWith(
|
|
136
|
+
"[Frak] Failed to track event:",
|
|
137
|
+
"share_button_clicked",
|
|
138
|
+
error
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should not throw when openPanel is undefined", () => {
|
|
143
|
+
const clientWithoutPanel = {} as FrakClient;
|
|
144
|
+
|
|
145
|
+
expect(() => {
|
|
146
|
+
trackEvent(clientWithoutPanel, "wallet_button_clicked");
|
|
147
|
+
}).not.toThrow();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("edge cases", () => {
|
|
152
|
+
it("should handle empty props object", () => {
|
|
153
|
+
trackEvent(mockClient, "share_button_clicked", {});
|
|
154
|
+
|
|
155
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
156
|
+
"share_button_clicked",
|
|
157
|
+
{}
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should handle complex props object", () => {
|
|
162
|
+
const complexProps = {
|
|
163
|
+
userId: "123",
|
|
164
|
+
metadata: {
|
|
165
|
+
page: "home",
|
|
166
|
+
section: "header",
|
|
167
|
+
},
|
|
168
|
+
tags: ["tag1", "tag2"],
|
|
169
|
+
timestamp: Date.now(),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
trackEvent(mockClient, "user_referred_completed", complexProps);
|
|
173
|
+
|
|
174
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
175
|
+
"user_referred_completed",
|
|
176
|
+
complexProps
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { FrakClient } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Analytics event names emitted by the SDK
|
|
5
|
+
*/
|
|
6
|
+
export type FrakEvent =
|
|
7
|
+
| "share_button_clicked"
|
|
8
|
+
| "wallet_button_clicked"
|
|
9
|
+
| "open_in_app_clicked"
|
|
10
|
+
| "open_in_app_login_clicked"
|
|
11
|
+
| "app_not_installed"
|
|
12
|
+
| "share_modal_error"
|
|
13
|
+
| "user_referred_started"
|
|
14
|
+
| "user_referred_completed"
|
|
15
|
+
| "user_referred_error";
|
|
16
|
+
|
|
17
|
+
type EventProps = Record<string, unknown>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Track an analytics event via OpenPanel.
|
|
21
|
+
* Fire-and-forget: silently catches errors.
|
|
22
|
+
* @param client - The Frak client instance (no-op if undefined)
|
|
23
|
+
* @param event - The event name to track
|
|
24
|
+
* @param props - Optional event properties
|
|
25
|
+
*/
|
|
26
|
+
export function trackEvent(
|
|
27
|
+
client: FrakClient | undefined,
|
|
28
|
+
event: FrakEvent,
|
|
29
|
+
props: EventProps = {}
|
|
30
|
+
): void {
|
|
31
|
+
if (!client) {
|
|
32
|
+
console.debug("[Frak] No client provided, skipping event tracking");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
client.openPanel?.track(event, props);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.debug("[Frak] Failed to track event:", event, e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* The buffer module from node.js, for the browser.
|
|
3
|
-
*
|
|
4
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
9
|
-
|
|
10
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
package/dist/interactions.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{PressInteractionEncoder:()=>PressInteractionEncoder,ReferralInteractionEncoder:()=>ReferralInteractionEncoder,RetailInteractionEncoder:()=>RetailInteractionEncoder,PurchaseInteractionEncoder:()=>PurchaseInteractionEncoder,WebShopInteractionEncoder:()=>WebShopInteractionEncoder});let external_viem_namespaceObject=require("viem"),interactionTypes={press:{openArticle:"0xc0a24ffb",readArticle:"0xd5bd0fbe"},dapp:{proofVerifiableStorageUpdate:"0x2ab2aeef",callableVerifiableStorageUpdate:"0xa07da986"},webshop:{open:"0xb311798f"},referral:{referred:"0x010cc3b9",createLink:"0xb2c0f17c"},purchase:{started:"0xd87e90c3",completed:"0x8403aeb4",unsafeCompleted:"0x4d5b14e0"},retail:{customerMeeting:"0x74489004"}},productTypes={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},productTypesMask=Object.entries(productTypes).reduce((e,[r,t])=>(e[r]=BigInt(1)<<BigInt(t),e),{}),PressInteractionEncoder={openArticle({articleId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.press.openArticle,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.press),interactionData:r}},readArticle({articleId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.press.readArticle,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.press),interactionData:r}}},ReferralInteractionEncoder={createLink:()=>({handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.referral),interactionData:interactionTypes.referral.createLink}),referred({referrer:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.referral.referred,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.referral),interactionData:r}}},PurchaseInteractionEncoder={startPurchase({purchaseId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.started,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:r}},completedPurchase({purchaseId:e,proof:r}){let t=(0,external_viem_namespaceObject.encodeAbiParameters)([{type:"uint256"},{type:"bytes32[]"}],[BigInt(e),r]),a=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.completed,t]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:a}},unsafeCompletedPurchase({purchaseId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.unsafeCompleted,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:r}}},WebShopInteractionEncoder={open:()=>({handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.webshop),interactionData:interactionTypes.webshop.open})},RetailInteractionEncoder={customerMeeting({agencyId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.retail.customerMeeting,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.retail),interactionData:r}}};for(var __webpack_i__ in exports.PressInteractionEncoder=__webpack_exports__.PressInteractionEncoder,exports.PurchaseInteractionEncoder=__webpack_exports__.PurchaseInteractionEncoder,exports.ReferralInteractionEncoder=__webpack_exports__.ReferralInteractionEncoder,exports.RetailInteractionEncoder=__webpack_exports__.RetailInteractionEncoder,exports.WebShopInteractionEncoder=__webpack_exports__.WebShopInteractionEncoder,__webpack_exports__)-1===["PressInteractionEncoder","PurchaseInteractionEncoder","ReferralInteractionEncoder","RetailInteractionEncoder","WebShopInteractionEncoder"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/interactions.d.cts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { Address } from 'viem';
|
|
2
|
-
import { Hex } from 'viem';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
6
|
-
*/
|
|
7
|
-
declare type PreparedInteraction = {
|
|
8
|
-
handlerTypeDenominator: Hex;
|
|
9
|
-
interactionData: Hex;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Press interactions allow you to track user engagement with articles or other press content on your platform.
|
|
14
|
-
* After setting up these interactions, you can create acquisition campaign based on the user engagement with your press content.
|
|
15
|
-
*
|
|
16
|
-
* :::info
|
|
17
|
-
* To properly handle press interactions, ensure that the "Press" product type is enabled in your Business dashboard.
|
|
18
|
-
* :::
|
|
19
|
-
*
|
|
20
|
-
* @description Encode press related user interactions
|
|
21
|
-
*
|
|
22
|
-
* @group Interactions Encoder
|
|
23
|
-
*
|
|
24
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
25
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
26
|
-
*/
|
|
27
|
-
export declare const PressInteractionEncoder: {
|
|
28
|
-
/**
|
|
29
|
-
* Encode an open article interaction
|
|
30
|
-
* @param args
|
|
31
|
-
* @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
|
|
32
|
-
*/
|
|
33
|
-
openArticle({ articleId }: {
|
|
34
|
-
articleId: Hex;
|
|
35
|
-
}): PreparedInteraction;
|
|
36
|
-
/**
|
|
37
|
-
* Encode a read article interaction
|
|
38
|
-
* @param args
|
|
39
|
-
* @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
|
|
40
|
-
*/
|
|
41
|
-
readArticle({ articleId }: {
|
|
42
|
-
articleId: Hex;
|
|
43
|
-
}): PreparedInteraction;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Purchase interactions allow you to track user purchases on your platform.
|
|
48
|
-
* After setting up these interactions, you can create acquisition campaign based on the user purchase (starting a new one, completed, or even purchase dropped).
|
|
49
|
-
*
|
|
50
|
-
* :::info
|
|
51
|
-
* 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.
|
|
52
|
-
* :::
|
|
53
|
-
*
|
|
54
|
-
* :::note
|
|
55
|
-
* The `purchaseId` is used on both interactions. It can be computed like this:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const purchaseId = keccak256(concatHex([productId, toHex(externalPurchaseId)]));
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* With:
|
|
62
|
-
* - `productId`: The id of your product, you can find it in the product dashboard.
|
|
63
|
-
* - `externalPurchaseId`: The id of the purchase in your system (e.g. the shopify `order_id`).
|
|
64
|
-
* :::
|
|
65
|
-
*
|
|
66
|
-
* @description Encode purchase related user interactions
|
|
67
|
-
*
|
|
68
|
-
* @group Interactions Encoder
|
|
69
|
-
*
|
|
70
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
71
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
72
|
-
* @see {@link !actions.trackPurchaseStatus | `trackPurchaseStatus()`} Action that will automatically send the purchase upon completion
|
|
73
|
-
* @see [Purchase Webhooks](/wallet-sdk/references-api/webhook) Webhooks to be implemented on your side to confirm a purchase
|
|
74
|
-
* @see [Purchase Proof](/wallet-sdk/references-api/purchaseProof) Get a merklee proof for the purchase
|
|
75
|
-
*/
|
|
76
|
-
export declare const PurchaseInteractionEncoder: {
|
|
77
|
-
/**
|
|
78
|
-
* Encode a start purchase interaction
|
|
79
|
-
* @param args
|
|
80
|
-
* @param args.purchaseId - The id of the purchase that is being started.
|
|
81
|
-
*/
|
|
82
|
-
startPurchase({ purchaseId }: {
|
|
83
|
-
purchaseId: Hex;
|
|
84
|
-
}): PreparedInteraction;
|
|
85
|
-
/**
|
|
86
|
-
* Encode a complete purchase interaction
|
|
87
|
-
* @param args
|
|
88
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
89
|
-
* @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
|
|
90
|
-
*/
|
|
91
|
-
completedPurchase({ purchaseId, proof, }: {
|
|
92
|
-
purchaseId: Hex;
|
|
93
|
-
proof: Hex[];
|
|
94
|
-
}): PreparedInteraction;
|
|
95
|
-
/**
|
|
96
|
-
* Encode an unsafe complete purchase interaction (when we can't provide the proof)
|
|
97
|
-
* @param args
|
|
98
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
99
|
-
*/
|
|
100
|
-
unsafeCompletedPurchase({ purchaseId, }: {
|
|
101
|
-
purchaseId: Hex;
|
|
102
|
-
}): PreparedInteraction;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Referral interactions allow you to track user sharing activities.
|
|
107
|
-
* These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
|
|
108
|
-
*
|
|
109
|
-
* :::info
|
|
110
|
-
* To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
|
|
111
|
-
* :::
|
|
112
|
-
*
|
|
113
|
-
* @description Encode referral related user interactions
|
|
114
|
-
*
|
|
115
|
-
* @group Interactions Encoder
|
|
116
|
-
*
|
|
117
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
118
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
119
|
-
*/
|
|
120
|
-
export declare const ReferralInteractionEncoder: {
|
|
121
|
-
/**
|
|
122
|
-
* 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.
|
|
123
|
-
*/
|
|
124
|
-
createLink(): PreparedInteraction;
|
|
125
|
-
/**
|
|
126
|
-
* Encode a referred interaction
|
|
127
|
-
* @param args
|
|
128
|
-
* @param args.referrer - The Ethereum address of the user who made the referral
|
|
129
|
-
*/
|
|
130
|
-
referred({ referrer }: {
|
|
131
|
-
referrer: Address;
|
|
132
|
-
}): PreparedInteraction;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Retail interactions allow you to track user activities on your retails products.
|
|
137
|
-
*
|
|
138
|
-
* :::info
|
|
139
|
-
* To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
|
|
140
|
-
* :::
|
|
141
|
-
*
|
|
142
|
-
* @description Encode retail related user interactions
|
|
143
|
-
*
|
|
144
|
-
* @group Interactions Encoder
|
|
145
|
-
*
|
|
146
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
147
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
148
|
-
*/
|
|
149
|
-
export declare const RetailInteractionEncoder: {
|
|
150
|
-
/**
|
|
151
|
-
* Encode a customer meeting retail interaction
|
|
152
|
-
* @param args
|
|
153
|
-
* @param args.agencyId - The id of the agency that the customer is meeting with
|
|
154
|
-
*
|
|
155
|
-
*/
|
|
156
|
-
customerMeeting({ agencyId }: {
|
|
157
|
-
agencyId: Hex;
|
|
158
|
-
}): PreparedInteraction;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Webshop interactions allow you to track user activities on your webshop.
|
|
163
|
-
*
|
|
164
|
-
* :::info
|
|
165
|
-
* To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
|
|
166
|
-
* :::
|
|
167
|
-
*
|
|
168
|
-
* @description Encode webshop related user interactions
|
|
169
|
-
*
|
|
170
|
-
* @group Interactions Encoder
|
|
171
|
-
*
|
|
172
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
173
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
174
|
-
*/
|
|
175
|
-
export declare const WebShopInteractionEncoder: {
|
|
176
|
-
/**
|
|
177
|
-
* Encode an open webshop interaction
|
|
178
|
-
*/
|
|
179
|
-
open(): PreparedInteraction;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export { }
|
package/dist/interactions.d.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { Address } from 'viem';
|
|
2
|
-
import { Hex } from 'viem';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
6
|
-
*/
|
|
7
|
-
declare type PreparedInteraction = {
|
|
8
|
-
handlerTypeDenominator: Hex;
|
|
9
|
-
interactionData: Hex;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Press interactions allow you to track user engagement with articles or other press content on your platform.
|
|
14
|
-
* After setting up these interactions, you can create acquisition campaign based on the user engagement with your press content.
|
|
15
|
-
*
|
|
16
|
-
* :::info
|
|
17
|
-
* To properly handle press interactions, ensure that the "Press" product type is enabled in your Business dashboard.
|
|
18
|
-
* :::
|
|
19
|
-
*
|
|
20
|
-
* @description Encode press related user interactions
|
|
21
|
-
*
|
|
22
|
-
* @group Interactions Encoder
|
|
23
|
-
*
|
|
24
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
25
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
26
|
-
*/
|
|
27
|
-
export declare const PressInteractionEncoder: {
|
|
28
|
-
/**
|
|
29
|
-
* Encode an open article interaction
|
|
30
|
-
* @param args
|
|
31
|
-
* @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
|
|
32
|
-
*/
|
|
33
|
-
openArticle({ articleId }: {
|
|
34
|
-
articleId: Hex;
|
|
35
|
-
}): PreparedInteraction;
|
|
36
|
-
/**
|
|
37
|
-
* Encode a read article interaction
|
|
38
|
-
* @param args
|
|
39
|
-
* @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
|
|
40
|
-
*/
|
|
41
|
-
readArticle({ articleId }: {
|
|
42
|
-
articleId: Hex;
|
|
43
|
-
}): PreparedInteraction;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Purchase interactions allow you to track user purchases on your platform.
|
|
48
|
-
* After setting up these interactions, you can create acquisition campaign based on the user purchase (starting a new one, completed, or even purchase dropped).
|
|
49
|
-
*
|
|
50
|
-
* :::info
|
|
51
|
-
* 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.
|
|
52
|
-
* :::
|
|
53
|
-
*
|
|
54
|
-
* :::note
|
|
55
|
-
* The `purchaseId` is used on both interactions. It can be computed like this:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const purchaseId = keccak256(concatHex([productId, toHex(externalPurchaseId)]));
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* With:
|
|
62
|
-
* - `productId`: The id of your product, you can find it in the product dashboard.
|
|
63
|
-
* - `externalPurchaseId`: The id of the purchase in your system (e.g. the shopify `order_id`).
|
|
64
|
-
* :::
|
|
65
|
-
*
|
|
66
|
-
* @description Encode purchase related user interactions
|
|
67
|
-
*
|
|
68
|
-
* @group Interactions Encoder
|
|
69
|
-
*
|
|
70
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
71
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
72
|
-
* @see {@link !actions.trackPurchaseStatus | `trackPurchaseStatus()`} Action that will automatically send the purchase upon completion
|
|
73
|
-
* @see [Purchase Webhooks](/wallet-sdk/references-api/webhook) Webhooks to be implemented on your side to confirm a purchase
|
|
74
|
-
* @see [Purchase Proof](/wallet-sdk/references-api/purchaseProof) Get a merklee proof for the purchase
|
|
75
|
-
*/
|
|
76
|
-
export declare const PurchaseInteractionEncoder: {
|
|
77
|
-
/**
|
|
78
|
-
* Encode a start purchase interaction
|
|
79
|
-
* @param args
|
|
80
|
-
* @param args.purchaseId - The id of the purchase that is being started.
|
|
81
|
-
*/
|
|
82
|
-
startPurchase({ purchaseId }: {
|
|
83
|
-
purchaseId: Hex;
|
|
84
|
-
}): PreparedInteraction;
|
|
85
|
-
/**
|
|
86
|
-
* Encode a complete purchase interaction
|
|
87
|
-
* @param args
|
|
88
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
89
|
-
* @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
|
|
90
|
-
*/
|
|
91
|
-
completedPurchase({ purchaseId, proof, }: {
|
|
92
|
-
purchaseId: Hex;
|
|
93
|
-
proof: Hex[];
|
|
94
|
-
}): PreparedInteraction;
|
|
95
|
-
/**
|
|
96
|
-
* Encode an unsafe complete purchase interaction (when we can't provide the proof)
|
|
97
|
-
* @param args
|
|
98
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
99
|
-
*/
|
|
100
|
-
unsafeCompletedPurchase({ purchaseId, }: {
|
|
101
|
-
purchaseId: Hex;
|
|
102
|
-
}): PreparedInteraction;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Referral interactions allow you to track user sharing activities.
|
|
107
|
-
* These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
|
|
108
|
-
*
|
|
109
|
-
* :::info
|
|
110
|
-
* To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
|
|
111
|
-
* :::
|
|
112
|
-
*
|
|
113
|
-
* @description Encode referral related user interactions
|
|
114
|
-
*
|
|
115
|
-
* @group Interactions Encoder
|
|
116
|
-
*
|
|
117
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
118
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
119
|
-
*/
|
|
120
|
-
export declare const ReferralInteractionEncoder: {
|
|
121
|
-
/**
|
|
122
|
-
* 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.
|
|
123
|
-
*/
|
|
124
|
-
createLink(): PreparedInteraction;
|
|
125
|
-
/**
|
|
126
|
-
* Encode a referred interaction
|
|
127
|
-
* @param args
|
|
128
|
-
* @param args.referrer - The Ethereum address of the user who made the referral
|
|
129
|
-
*/
|
|
130
|
-
referred({ referrer }: {
|
|
131
|
-
referrer: Address;
|
|
132
|
-
}): PreparedInteraction;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Retail interactions allow you to track user activities on your retails products.
|
|
137
|
-
*
|
|
138
|
-
* :::info
|
|
139
|
-
* To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
|
|
140
|
-
* :::
|
|
141
|
-
*
|
|
142
|
-
* @description Encode retail related user interactions
|
|
143
|
-
*
|
|
144
|
-
* @group Interactions Encoder
|
|
145
|
-
*
|
|
146
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
147
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
148
|
-
*/
|
|
149
|
-
export declare const RetailInteractionEncoder: {
|
|
150
|
-
/**
|
|
151
|
-
* Encode a customer meeting retail interaction
|
|
152
|
-
* @param args
|
|
153
|
-
* @param args.agencyId - The id of the agency that the customer is meeting with
|
|
154
|
-
*
|
|
155
|
-
*/
|
|
156
|
-
customerMeeting({ agencyId }: {
|
|
157
|
-
agencyId: Hex;
|
|
158
|
-
}): PreparedInteraction;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Webshop interactions allow you to track user activities on your webshop.
|
|
163
|
-
*
|
|
164
|
-
* :::info
|
|
165
|
-
* To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
|
|
166
|
-
* :::
|
|
167
|
-
*
|
|
168
|
-
* @description Encode webshop related user interactions
|
|
169
|
-
*
|
|
170
|
-
* @group Interactions Encoder
|
|
171
|
-
*
|
|
172
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
173
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
174
|
-
*/
|
|
175
|
-
export declare const WebShopInteractionEncoder: {
|
|
176
|
-
/**
|
|
177
|
-
* Encode an open webshop interaction
|
|
178
|
-
*/
|
|
179
|
-
open(): PreparedInteraction;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export { }
|
package/dist/interactions.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{concatHex as e,encodeAbiParameters as r,pad as t,toHex as n}from"viem";let a="0xc0a24ffb",o="0xd5bd0fbe",i="0xb311798f",c="0x010cc3b9",l="0xb2c0f17c",p="0xd87e90c3",s="0x8403aeb4",d="0x4d5b14e0",h="0x74489004",u={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31};Object.entries(u).reduce((e,[r,t])=>(e[r]=BigInt(1)<<BigInt(t),e),{});let m={openArticle({articleId:r}){let o=e([a,t(r,{size:32})]);return{handlerTypeDenominator:n(u.press),interactionData:o}},readArticle({articleId:r}){let a=e([o,t(r,{size:32})]);return{handlerTypeDenominator:n(u.press),interactionData:a}}},b={createLink:()=>({handlerTypeDenominator:n(u.referral),interactionData:l}),referred({referrer:r}){let a=e([c,t(r,{size:32})]);return{handlerTypeDenominator:n(u.referral),interactionData:a}}},f={startPurchase({purchaseId:r}){let a=e([p,t(r,{size:32})]);return{handlerTypeDenominator:n(u.purchase),interactionData:a}},completedPurchase({purchaseId:t,proof:a}){let o=r([{type:"uint256"},{type:"bytes32[]"}],[BigInt(t),a]),i=e([s,o]);return{handlerTypeDenominator:n(u.purchase),interactionData:i}},unsafeCompletedPurchase({purchaseId:r}){let a=e([d,t(r,{size:32})]);return{handlerTypeDenominator:n(u.purchase),interactionData:a}}},y={open:()=>({handlerTypeDenominator:n(u.webshop),interactionData:i})},D={customerMeeting({agencyId:r}){let a=e([h,t(r,{size:32})]);return{handlerTypeDenominator:n(u.retail),interactionData:a}}};export{m as PressInteractionEncoder,f as PurchaseInteractionEncoder,b as ReferralInteractionEncoder,D as RetailInteractionEncoder,y as WebShopInteractionEncoder};
|