@frak-labs/core-sdk 0.0.2 → 0.0.5

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.
@@ -1,4 +1,4 @@
1
- import { a as FrakClient, W as WalletStatusReturnType, M as ModalStepTypes, D as DisplayModalParamsType, f as ModalRpcStepsResultType, O as OpenSsoParamsType, G as GetProductInformationReturnType, i as SiweAuthenticationParams, d as ModalRpcMetadata, j as SiweAuthenticateReturnType, l as SendTransactionModalStepType, m as SendTransactionReturnType, q as FinalModalStepType, r as FinalActionType, L as LoginModalStepType, o as OpenInteractionSessionModalStepType, b as FrakContext } from '../context-GkNATUkF.cjs';
1
+ import { a as FrakClient, W as WalletStatusReturnType, M as ModalStepTypes, j as DisplayModalParamsType, l as ModalRpcStepsResultType, D as DisplayEmbededWalletParamsType, O as OpenSsoParamsType, G as GetProductInformationReturnType, q as SiweAuthenticationParams, h as ModalRpcMetadata, r as SiweAuthenticateReturnType, t as SendTransactionModalStepType, u as SendTransactionReturnType, x as FinalModalStepType, y as FinalActionType, n as LoginModalStepType, w as OpenInteractionSessionModalStepType, b as FrakContext } from '../context-C7RkT8hA.cjs';
2
2
  import { S as SendInteractionParamsType, a as SendInteractionReturnType } from '../interaction-CTQ5-kqe.cjs';
3
3
  import { Hex } from 'viem';
4
4
  import 'viem/chains';
@@ -105,11 +105,6 @@ declare function sendInteraction(client: FrakClient, { productId, interaction, v
105
105
  * ssoMetadata: {
106
106
  * logoUrl: "https://my-app.com/logo.png",
107
107
  * homepageLink: "https://my-app.com",
108
- * links: {
109
- * confidentialityLink: "https://my-app.com/confidentiality",
110
- * helpLink: "https://my-app.com/help",
111
- * cguLink: "https://my-app.com/cgu",
112
- * },
113
108
  * },
114
109
  * metadata: {
115
110
  * // Modal title on desktop
@@ -181,6 +176,13 @@ declare function sendInteraction(client: FrakClient, { productId, interaction, v
181
176
  */
182
177
  declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, { steps, metadata }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
183
178
 
179
+ /**
180
+ * Function used to display the Frak embeded wallet popup
181
+ * @param client - The current Frak Client
182
+ * @param params - The parameter used to customise the embeded wallet
183
+ */
184
+ declare function displayEmbededWallet(client: FrakClient, params: DisplayEmbededWalletParamsType): Promise<void>;
185
+
184
186
  /**
185
187
  * Function used to open the SSO
186
188
  * @param client - The current Frak Client
@@ -195,11 +197,6 @@ declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(cli
195
197
  * const metadata: SsoMetadata = {
196
198
  * logoUrl: "https://my-app.com/logo.png",
197
199
  * homepageLink: "https://my-app.com",
198
- * links: {
199
- * confidentialityLink: "https://my-app.com/confidentiality",
200
- * helpLink: "https://my-app.com/help",
201
- * cguLink: "https://my-app.com/cgu",
202
- * },
203
200
  * };
204
201
  * ```
205
202
  *
@@ -377,8 +374,9 @@ type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
377
374
  }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
378
375
  /**
379
376
  * Display the modal
377
+ * @param metadataOverride - Function returning optional metadata to override the current modal metadata
380
378
  */
381
- display: () => Promise<ModalRpcStepsResultType<Steps>>;
379
+ display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
382
380
  };
383
381
  /**
384
382
  * Represent the output type of the modal builder
@@ -500,4 +498,4 @@ declare function referralInteraction(client: FrakClient, { productId, modalConfi
500
498
  options?: ProcessReferralOptions;
501
499
  }): Promise<("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral") | undefined>;
502
500
 
503
- export { type ModalBuilder, type ModalStepBuilder, type ProcessReferralOptions, type SendTransactionParams, type SiweAuthenticateModalParams, displayModal, getProductInformation, modalBuilder, openSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };
501
+ export { type ModalBuilder, type ModalStepBuilder, type ProcessReferralOptions, type SendTransactionParams, type SiweAuthenticateModalParams, displayEmbededWallet, displayModal, getProductInformation, modalBuilder, openSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };
@@ -1,4 +1,4 @@
1
- import { a as FrakClient, W as WalletStatusReturnType, M as ModalStepTypes, D as DisplayModalParamsType, f as ModalRpcStepsResultType, O as OpenSsoParamsType, G as GetProductInformationReturnType, i as SiweAuthenticationParams, d as ModalRpcMetadata, j as SiweAuthenticateReturnType, l as SendTransactionModalStepType, m as SendTransactionReturnType, q as FinalModalStepType, r as FinalActionType, L as LoginModalStepType, o as OpenInteractionSessionModalStepType, b as FrakContext } from '../context-B0trlYGx.js';
1
+ import { a as FrakClient, W as WalletStatusReturnType, M as ModalStepTypes, j as DisplayModalParamsType, l as ModalRpcStepsResultType, D as DisplayEmbededWalletParamsType, O as OpenSsoParamsType, G as GetProductInformationReturnType, q as SiweAuthenticationParams, h as ModalRpcMetadata, r as SiweAuthenticateReturnType, t as SendTransactionModalStepType, u as SendTransactionReturnType, x as FinalModalStepType, y as FinalActionType, n as LoginModalStepType, w as OpenInteractionSessionModalStepType, b as FrakContext } from '../context-CJ5ByAXa.js';
2
2
  import { S as SendInteractionParamsType, a as SendInteractionReturnType } from '../interaction-CTQ5-kqe.js';
3
3
  import { Hex } from 'viem';
4
4
  import 'viem/chains';
@@ -105,11 +105,6 @@ declare function sendInteraction(client: FrakClient, { productId, interaction, v
105
105
  * ssoMetadata: {
106
106
  * logoUrl: "https://my-app.com/logo.png",
107
107
  * homepageLink: "https://my-app.com",
108
- * links: {
109
- * confidentialityLink: "https://my-app.com/confidentiality",
110
- * helpLink: "https://my-app.com/help",
111
- * cguLink: "https://my-app.com/cgu",
112
- * },
113
108
  * },
114
109
  * metadata: {
115
110
  * // Modal title on desktop
@@ -181,6 +176,13 @@ declare function sendInteraction(client: FrakClient, { productId, interaction, v
181
176
  */
182
177
  declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, { steps, metadata }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
183
178
 
179
+ /**
180
+ * Function used to display the Frak embeded wallet popup
181
+ * @param client - The current Frak Client
182
+ * @param params - The parameter used to customise the embeded wallet
183
+ */
184
+ declare function displayEmbededWallet(client: FrakClient, params: DisplayEmbededWalletParamsType): Promise<void>;
185
+
184
186
  /**
185
187
  * Function used to open the SSO
186
188
  * @param client - The current Frak Client
@@ -195,11 +197,6 @@ declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(cli
195
197
  * const metadata: SsoMetadata = {
196
198
  * logoUrl: "https://my-app.com/logo.png",
197
199
  * homepageLink: "https://my-app.com",
198
- * links: {
199
- * confidentialityLink: "https://my-app.com/confidentiality",
200
- * helpLink: "https://my-app.com/help",
201
- * cguLink: "https://my-app.com/cgu",
202
- * },
203
200
  * };
204
201
  * ```
205
202
  *
@@ -377,8 +374,9 @@ type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
377
374
  }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
378
375
  /**
379
376
  * Display the modal
377
+ * @param metadataOverride - Function returning optional metadata to override the current modal metadata
380
378
  */
381
- display: () => Promise<ModalRpcStepsResultType<Steps>>;
379
+ display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
382
380
  };
383
381
  /**
384
382
  * Represent the output type of the modal builder
@@ -500,4 +498,4 @@ declare function referralInteraction(client: FrakClient, { productId, modalConfi
500
498
  options?: ProcessReferralOptions;
501
499
  }): Promise<("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral") | undefined>;
502
500
 
503
- export { type ModalBuilder, type ModalStepBuilder, type ProcessReferralOptions, type SendTransactionParams, type SiweAuthenticateModalParams, displayModal, getProductInformation, modalBuilder, openSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };
501
+ export { type ModalBuilder, type ModalStepBuilder, type ProcessReferralOptions, type SendTransactionParams, type SiweAuthenticateModalParams, displayEmbededWallet, displayModal, getProductInformation, modalBuilder, openSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };
@@ -1,13 +1,7 @@
1
- import {
2
- Deferred,
3
- FrakContextManager,
4
- FrakRpcError,
5
- RpcErrorCodes
6
- } from "../chunk-K5SAPMC2.js";
7
- import {
8
- ReferralInteractionEncoder
9
- } from "../chunk-VAINYZSV.js";
10
- import "../chunk-QZL2KCSB.js";
1
+ import { Deferred, FrakContextManager, FrakRpcError, RpcErrorCodes } from '../chunk-XDZMP74U.js';
2
+ import { ReferralInteractionEncoder } from '../chunk-RMOFMRZR.js';
3
+ import { isAddressEqual, keccak256, toHex } from 'viem';
4
+ import { generateSiweNonce } from 'viem/siwe';
11
5
 
12
6
  // src/actions/watchWalletStatus.ts
13
7
  function watchWalletStatus(client, callback) {
@@ -46,17 +40,14 @@ function savePotentialToken(interactionToken) {
46
40
  window.sessionStorage.removeItem("frak.interaction-token");
47
41
  }
48
42
  }
49
-
50
- // src/utils/computeProductId.ts
51
- import { keccak256, toHex } from "viem";
52
43
  function computeProductId({ domain }) {
53
- const effectiveDomain = domain ?? window.location.host;
44
+ const effectiveDomain = domain != null ? domain : window.location.host;
54
45
  return keccak256(toHex(effectiveDomain));
55
46
  }
56
47
 
57
48
  // src/actions/sendInteraction.ts
58
49
  async function sendInteraction(client, { productId, interaction, validation }) {
59
- const pId = productId ?? computeProductId(client.config);
50
+ const pId = productId != null ? productId : computeProductId(client.config);
60
51
  return await client.request({
61
52
  method: "frak_sendInteraction",
62
53
  params: [pId, interaction, validation]
@@ -71,6 +62,14 @@ async function displayModal(client, { steps, metadata }) {
71
62
  });
72
63
  }
73
64
 
65
+ // src/actions/displayEmbededWallet.ts
66
+ async function displayEmbededWallet(client, params) {
67
+ await client.request({
68
+ method: "frak_displayEmbededWallet",
69
+ params: [params, client.config.metadata.name]
70
+ });
71
+ }
72
+
74
73
  // src/actions/openSso.ts
75
74
  async function openSso(client, args) {
76
75
  const { metadata } = client.config;
@@ -110,18 +109,16 @@ async function trackPurchaseStatus(args) {
110
109
  body: JSON.stringify(args)
111
110
  });
112
111
  }
113
-
114
- // src/actions/wrapper/siweAuthenticate.ts
115
- import { generateSiweNonce } from "viem/siwe";
116
112
  async function siweAuthenticate(client, { siwe, metadata }) {
117
- const effectiveDomain = client.config?.domain ?? window.location.host;
118
- const realStatement = siwe?.statement ?? `I confirm that I want to use my Frak wallet on: ${client.config.metadata.name}`;
113
+ var _a, _b, _c, _d, _e, _f;
114
+ const effectiveDomain = (_b = (_a = client.config) == null ? undefined : _a.domain) != null ? _b : window.location.host;
115
+ const realStatement = (_c = siwe == null ? undefined : siwe.statement) != null ? _c : `I confirm that I want to use my Frak wallet on: ${client.config.metadata.name}`;
119
116
  const builtSiwe = {
120
117
  ...siwe,
121
118
  statement: realStatement,
122
- nonce: siwe?.nonce ?? generateSiweNonce(),
123
- uri: siwe?.uri ?? `https://${effectiveDomain}`,
124
- version: siwe?.version ?? "1",
119
+ nonce: (_d = siwe == null ? undefined : siwe.nonce) != null ? _d : generateSiweNonce(),
120
+ uri: (_e = siwe == null ? undefined : siwe.uri) != null ? _e : `https://${effectiveDomain}`,
121
+ version: (_f = siwe == null ? undefined : siwe.version) != null ? _f : "1",
125
122
  domain: effectiveDomain
126
123
  };
127
124
  const result = await displayModal(client, {
@@ -156,8 +153,8 @@ function modalBuilder(client, {
156
153
  }) {
157
154
  const baseParams = {
158
155
  steps: {
159
- login: login ?? {},
160
- openSession: openSession ?? {}
156
+ login: login != null ? login : {},
157
+ openSession: openSession != null ? openSession : {}
161
158
  },
162
159
  metadata
163
160
  };
@@ -203,7 +200,11 @@ function modalStepsBuilder(client, params) {
203
200
  }
204
201
  );
205
202
  }
206
- async function display() {
203
+ async function display(metadataOverride) {
204
+ var _a;
205
+ if (metadataOverride) {
206
+ params.metadata = metadataOverride((_a = params.metadata) != null ? _a : {});
207
+ }
207
208
  return await displayModal(client, params);
208
209
  }
209
210
  return {
@@ -217,9 +218,6 @@ function modalStepsBuilder(client, params) {
217
218
  display
218
219
  };
219
220
  }
220
-
221
- // src/actions/referral/processReferral.ts
222
- import { isAddressEqual } from "viem";
223
221
  async function processReferral(client, {
224
222
  walletStatus,
225
223
  frakContext,
@@ -227,6 +225,7 @@ async function processReferral(client, {
227
225
  productId,
228
226
  options
229
227
  }) {
228
+ var _a, _b;
230
229
  let walletRequest = false;
231
230
  async function getFreshWalletStatus() {
232
231
  if (walletRequest) {
@@ -252,15 +251,15 @@ async function processReferral(client, {
252
251
  frakContext
253
252
  });
254
253
  FrakContextManager.replaceUrl({
255
- url: window.location?.href,
256
- context: options?.alwaysAppendUrl ? { r: currentWallet } : null
254
+ url: (_a = window.location) == null ? undefined : _a.href,
255
+ context: (options == null ? undefined : options.alwaysAppendUrl) ? { r: currentWallet } : null
257
256
  });
258
257
  return status;
259
258
  } catch (error) {
260
259
  console.log("Error processing referral", { error });
261
260
  FrakContextManager.replaceUrl({
262
- url: window.location?.href,
263
- context: options?.alwaysAppendUrl ? { r: walletStatus?.wallet } : null
261
+ url: (_b = window.location) == null ? undefined : _b.href,
262
+ context: (options == null ? undefined : options.alwaysAppendUrl) ? { r: walletStatus == null ? undefined : walletStatus.wallet } : null
264
263
  });
265
264
  return mapErrorToState(error);
266
265
  }
@@ -271,8 +270,8 @@ async function processReferralLogic({
271
270
  pushReferralInteraction,
272
271
  frakContext
273
272
  }) {
274
- let currentWallet = initialWalletStatus?.wallet;
275
- if (!frakContext?.r) {
273
+ let currentWallet = initialWalletStatus == null ? undefined : initialWalletStatus.wallet;
274
+ if (!(frakContext == null ? undefined : frakContext.r)) {
276
275
  return { status: "no-referrer", currentWallet };
277
276
  }
278
277
  if (!currentWallet) {
@@ -281,7 +280,7 @@ async function processReferralLogic({
281
280
  if (currentWallet && isAddressEqual(frakContext.r, currentWallet)) {
282
281
  return { status: "self-referral", currentWallet };
283
282
  }
284
- if (!initialWalletStatus?.interactionSession) {
283
+ if (!(initialWalletStatus == null ? undefined : initialWalletStatus.interactionSession)) {
285
284
  currentWallet = await getFreshWalletStatus();
286
285
  }
287
286
  await pushReferralInteraction(frakContext.r);
@@ -291,14 +290,15 @@ async function ensureWalletConnected(client, {
291
290
  modalConfig,
292
291
  walletStatus
293
292
  }) {
294
- if (!walletStatus?.interactionSession) {
293
+ var _a, _b, _c;
294
+ if (!(walletStatus == null ? undefined : walletStatus.interactionSession)) {
295
295
  if (!modalConfig) {
296
- return void 0;
296
+ return undefined;
297
297
  }
298
298
  const result = await displayModal(client, modalConfig);
299
- return result?.login?.wallet ?? void 0;
299
+ return (_b = (_a = result == null ? undefined : result.login) == null ? undefined : _a.wallet) != null ? _b : undefined;
300
300
  }
301
- return walletStatus.wallet ?? void 0;
301
+ return (_c = walletStatus.wallet) != null ? _c : undefined;
302
302
  }
303
303
  function mapErrorToState(error) {
304
304
  if (error instanceof FrakRpcError) {
@@ -337,16 +337,5 @@ async function referralInteraction(client, {
337
337
  }
338
338
  return;
339
339
  }
340
- export {
341
- displayModal,
342
- getProductInformation,
343
- modalBuilder,
344
- openSso,
345
- processReferral,
346
- referralInteraction,
347
- sendInteraction,
348
- sendTransaction,
349
- siweAuthenticate,
350
- trackPurchaseStatus,
351
- watchWalletStatus
352
- };
340
+
341
+ export { displayEmbededWallet, displayModal, getProductInformation, modalBuilder, openSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };
@@ -32,6 +32,7 @@ var productTypes = {
32
32
  dapp: 1,
33
33
  press: 2,
34
34
  webshop: 3,
35
+ retail: 4,
35
36
  // feature type
36
37
  referral: 30,
37
38
  purchase: 31
@@ -65,15 +66,12 @@ var interactionTypes = {
65
66
  },
66
67
  purchase: {
67
68
  started: "0xd87e90c3",
68
- completed: "0x8403aeb4"
69
+ completed: "0x8403aeb4",
70
+ unsafeCompleted: "0x4d5b14e0"
71
+ },
72
+ retail: {
73
+ customerMeeting: "0x74489004"
69
74
  }
70
75
  };
71
76
 
72
- export {
73
- __commonJS,
74
- __toESM,
75
- __publicField,
76
- productTypes,
77
- productTypesMask,
78
- interactionTypes
79
- };
77
+ export { __commonJS, __publicField, __toESM, interactionTypes, productTypes, productTypesMask };