@zyphe-sdk/core 0.1.7 → 0.1.9

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,6 +1,6 @@
1
1
 
2
2
  
3
- > @zyphe-sdk/core@0.1.7 build /Users/mtumiati/dev/zyphe/zyphe-sdk/packages/core
3
+ > @zyphe-sdk/core@0.1.8 build /Users/mtumiati/dev/zyphe/zyphe-sdk/packages/core
4
4
  > tsup
5
5
 
6
6
  CLI Building entry: src/index.ts
@@ -9,14 +9,9 @@
9
9
  CLI Using tsup config: /Users/mtumiati/dev/zyphe/zyphe-sdk/packages/core/tsup.config.ts
10
10
  CLI Target: es2023
11
11
  ESM Build start
12
- CJS Build start
13
- ESM dist/index.js 4.28 KB
14
- ESM dist/index.js.map 9.36 KB
15
- ESM ⚡️ Build success in 12ms
16
- CJS dist/index.cjs 6.08 KB
17
- CJS dist/index.cjs.map 9.63 KB
18
- CJS ⚡️ Build success in 13ms
12
+ ESM dist/index.js 4.31 KB
13
+ ESM dist/index.js.map 9.62 KB
14
+ ESM ⚡️ Build success in 27ms
19
15
  DTS Build start
20
- DTS ⚡️ Build success in 609ms
21
- DTS dist/index.d.ts 61.70 KB
22
- DTS dist/index.d.cts 61.70 KB
16
+ DTS ⚡️ Build success in 883ms
17
+ DTS dist/index.d.ts 62.09 KB
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Zyphe SDK – Core
2
2
 
3
+ > **⚠️ This package is now [ESM-only](https://nodejs.org/api/esm.html).**
4
+ >
5
+ > - You must use `import` syntax, not `require()`.
6
+ > - Node.js v16.17+ or v18+ is recommended.
7
+ > - CommonJS (`require()`) is **not supported**.
8
+
3
9
  This is the core SDK package for Zyphe. It contains utilities to interact with the Zyphe platform, including webhook signature verification and verification session management.
4
10
 
5
11
  ## Installing package
@@ -10,6 +16,16 @@ If you want to use the core SDK outside of this monorepo, you can install it dir
10
16
  pnpm install @zyphe-sdk/core
11
17
  ```
12
18
 
19
+ **ESM-only usage:**
20
+
21
+ ```ts
22
+ // Correct: ESM import
23
+ import { createVerificationSession, verifyWebhookSignature } from "@zyphe-sdk/core";
24
+
25
+ // ❌ Not supported:
26
+ // const sdk = require("@zyphe-sdk/core");
27
+ ```
28
+
13
29
  Then import and use the package in your project as described in the Usage section.
14
30
 
15
31
  ---
@@ -57,16 +73,28 @@ You can programmatically create verification sessions and construct user-facing
57
73
  import { createVerificationSession } from "@zyphe-sdk/core";
58
74
 
59
75
  const response = await createVerificationSession(
60
- "user@example.com", // email
61
- "<flowId>", // flowId
62
- "<flowStepId>", // flowStepId
63
- false, // isSandbox
76
+ {
77
+ email: "user@example.com", // required
78
+ flowId: "<flowId>", // required
79
+ flowStepId: "<flowStepId>",// required
80
+ isSandbox: false, // required
81
+ customData: { // optional
82
+ walletAddress: "0x123...",
83
+ // ...any extra data you want to pass
84
+ },
85
+ },
64
86
  {
65
87
  apiKey: "<your-api-key>",
66
88
  environment: "staging", // or "production", "local"
89
+ handoffBaseUrl: "https://your-app.com", // optional
90
+ primaryColor: "#000000", // optional
91
+ secondaryColor: "#ffffff", // optional
92
+ isFullscreen: true, // optional
67
93
  }
68
94
  );
69
95
  ```
96
+ - `customData` (optional): Pass any extra data you want to associate with the verification session. This will be available in the webhook payload and session data.
97
+ - The function returns a Promise resolving to the API response. Handle errors as needed (e.g., try/catch or checking for error fields).
70
98
 
71
99
  ### Construct a Verification Session URL
72
100
  ```ts
@@ -77,20 +105,46 @@ const url = constructVerificationSessionUrl({
77
105
  flowId: "...",
78
106
  flowStepId: "...",
79
107
  email: "user@example.com",
80
- product: "kyc",
108
+ product: "kyc", // or "kyb" if supported
81
109
  isSandbox: false,
110
+ customData: { walletAddress: "0x123..." }, // optional
82
111
  },
83
112
  verificationSession: response.data, // from createVerificationSession
84
113
  opts: {
85
114
  apiKey: "<your-api-key>",
86
115
  environment: "staging",
87
- handoffBaseUrl: "https://your-app.com",
88
- primaryColor: "#000000",
89
- secondaryColor: "#ffffff",
90
- isFullscreen: true,
116
+ handoffBaseUrl: "https://your-app.com", // optional
117
+ primaryColor: "#000000", // optional
118
+ secondaryColor: "#ffffff", // optional
119
+ isFullscreen: true, // optional
91
120
  },
92
121
  });
93
122
  ```
123
+ - The constructed URL includes all relevant parameters and can be used to embed or redirect users to the verification flow.
124
+ - Optional fields (like `handoffBaseUrl`, `primaryColor`, etc.) will be appended as query parameters if provided.
125
+
126
+ #### Types
127
+ - `InitializeZypheFlowParams`: Parameters for initializing a verification flow (see [types.ts](./src/types.ts)).
128
+ - `SDKOptions`: Configuration for the SDK (see [types.ts](./src/types.ts)).
129
+ - `SdkCreateVerificationRequestResponse`: API response type for session creation.
130
+
131
+ #### Error Handling
132
+ - If session creation fails, the function may throw or return an error object depending on usage context. Always check for errors and handle them appropriately.
133
+ - Example:
134
+ ```ts
135
+ try {
136
+ const response = await createVerificationSession(...);
137
+ if (response.error) {
138
+ // Handle error
139
+ console.error(response.error);
140
+ } else {
141
+ // Success
142
+ }
143
+ } catch (err) {
144
+ // Handle thrown errors (e.g., network issues)
145
+ console.error(err);
146
+ }
147
+ ```
94
148
 
95
149
  ---
96
150
 
package/dist/index.cjs CHANGED
@@ -75,10 +75,16 @@ var zypheApiClient = (opts) => {
75
75
  };
76
76
 
77
77
  // src/verification-session.ts
78
- function createVerificationSession(email, flowId, flowStepId, isSandbox, opts) {
78
+ function createVerificationSession({
79
+ email,
80
+ flowId,
81
+ flowStepId,
82
+ isSandbox,
83
+ customData
84
+ }, opts) {
79
85
  const client = zypheApiClient(opts);
80
86
  return client.POST("/sdk/flow/{flow_id}/vr/create", {
81
- body: { email, flowStepId },
87
+ body: { email, flowStepId, customData },
82
88
  headers: {
83
89
  [API_KEY_HEADER]: opts.apiKey
84
90
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/client.ts","../src/verification-session.ts","../src/webhook.ts"],"sourcesContent":["export * from \"./constants\";\nexport * from \"./types\";\nexport * from \"./verification-session\";\nexport * from \"./webhook\";\n","export const Environments = {\n LOCAL: \"local\",\n STAGING: \"staging\",\n PRODUCTION: \"production\",\n} as const;\n\nexport type Environment = (typeof Environments)[keyof typeof Environments];\n\ninterface EnvironmentConfig {\n appUrl: string;\n apiUrl: string;\n}\n\nexport const EnvironmentConfigs: Record<Environment, EnvironmentConfig> = {\n [Environments.LOCAL]: {\n appUrl: \"http://localhost:5173\",\n apiUrl: \"http://localhost:3000\",\n },\n [Environments.STAGING]: {\n appUrl: \"https://app-dev.zyphe.com\",\n apiUrl: \"https://api-dev.zyphe.com\",\n },\n [Environments.PRODUCTION]: {\n appUrl: \"https://verify.zyphe.com\",\n apiUrl: \"https://api.zyphe.com\",\n },\n};\n\nexport const API_KEY_HEADER = \"x-api-key\";\n","import createClient from \"openapi-fetch\";\nimport type { paths } from \"@zyphe-sdk/core/openapi\";\nimport { EnvironmentConfigs } from \"./constants\";\nimport type { SDKOptions } from \"./types\";\n\nexport const zypheApiClient = (opts: SDKOptions) => {\n return createClient<paths>({\n baseUrl: EnvironmentConfigs[opts.environment].apiUrl,\n });\n};\n","import { zypheApiClient } from \"./client\";\nimport { API_KEY_HEADER, EnvironmentConfigs, Environments } from \"./constants\";\nimport type {\n InitializeZypheFlowParams,\n SdkCreateVerificationRequestResponse,\n SDKOptions,\n} from \"./types\";\n\nexport function createVerificationSession(\n email: string,\n flowId: string,\n flowStepId: string,\n isSandbox: boolean,\n opts: SDKOptions\n) {\n const client = zypheApiClient(opts);\n\n return client.POST(\"/sdk/flow/{flow_id}/vr/create\", {\n body: { email, flowStepId },\n headers: {\n [API_KEY_HEADER]: opts.apiKey,\n },\n params: {\n path: {\n flow_id: flowId,\n },\n query: {\n sandbox: isSandbox,\n },\n },\n });\n}\n\nfunction getFlowUrlOrigin(environment: SDKOptions[\"environment\"]) {\n switch (environment) {\n case Environments.LOCAL:\n return EnvironmentConfigs[Environments.LOCAL].appUrl;\n case Environments.STAGING:\n return EnvironmentConfigs[Environments.STAGING].appUrl;\n case Environments.PRODUCTION:\n return EnvironmentConfigs[Environments.PRODUCTION].appUrl;\n default:\n throw new Error(`Invalid environment: ${environment}`);\n }\n}\n\nexport function constructVerificationSessionUrl({\n flowParams,\n verificationSession,\n opts,\n}: {\n flowParams: InitializeZypheFlowParams;\n verificationSession: SdkCreateVerificationRequestResponse;\n opts: SDKOptions;\n}) {\n const origin = getFlowUrlOrigin(opts.environment);\n const { isSandbox, product } = flowParams;\n const { handoffBaseUrl, primaryColor, secondaryColor, isFullscreen } = opts;\n\n if (!verificationSession) {\n throw new Error(\"Failed to create verification session\");\n }\n\n let baseUrl = `${origin}${isSandbox ? \"/sandbox\" : \"\"}/flow/${verificationSession.flowSlug}/${product}/${verificationSession.flowStepSlug}?zypheVr=${encodeURIComponent(verificationSession.verificationRequest.id)}&zypheEmail=${encodeURIComponent(verificationSession.email)}&zypheToken=${encodeURIComponent(verificationSession.zypheToken)}`;\n\n if (handoffBaseUrl) {\n baseUrl += `&zypheHandoffBaseUrl=${encodeURIComponent(handoffBaseUrl)}`;\n }\n\n if (primaryColor) {\n baseUrl += `&zyphePrimaryColor=${encodeURIComponent(primaryColor)}`;\n }\n\n if (secondaryColor) {\n baseUrl += `&zypheSecondaryColor=${encodeURIComponent(secondaryColor)}`;\n }\n\n if (isFullscreen) {\n baseUrl += `&zypheFullscreen=${encodeURIComponent(isFullscreen)}`;\n }\n\n return baseUrl;\n}\n","export interface SignatureComponents {\n timestamp: string;\n signatureHex: string;\n}\n\n/**\n * Parses a webhook signature header of the form \"t=<timestamp>,v0=<signature>\"\n * @param signatureHeader - The header string, e.g. \"t=1234567890,v0=abcdef...\"\n * @returns The parsed timestamp and signature hex\n */\nexport function parseSignatureHeader(\n signatureHeader: string\n): SignatureComponents {\n const match = signatureHeader.match(/^t=(\\d+),v0=([a-fA-F0-9]+)$/);\n if (!match) {\n throw new Error(\"Invalid signature header format\");\n }\n const [, timestamp, signatureHex] = match;\n\n if (!timestamp || !signatureHex) {\n throw new Error(\"Invalid signature header format\");\n }\n\n return { timestamp, signatureHex };\n}\n\n/**\n * Converts a hex string to a Uint8Array\n * @param hex - The hex string to convert\n * @returns The resulting Uint8Array\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) throw new Error(\"Invalid hex string\");\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Converts an ArrayBuffer to a hex string\n * @param buffer - The buffer to convert\n * @returns The hex string representation\n */\nexport function bufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Compares two strings in constant time to prevent timing attacks\n * @param a - First string\n * @param b - Second string\n * @returns True if strings are equal, false otherwise\n */\nexport function timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n\nexport const WebhookSignatureErrorCodes = {\n MISSING_SIGNATURE_HEADER: 1,\n INVALID_SIGNATURE_HEADER: 2,\n SIGNATURE_MISMATCH: 3,\n} as const;\n\nexport const WebhookSignatureErrorMessages = {\n [WebhookSignatureErrorCodes.MISSING_SIGNATURE_HEADER]:\n \"Missing signature header\",\n [WebhookSignatureErrorCodes.INVALID_SIGNATURE_HEADER]:\n \"Invalid signature header\",\n [WebhookSignatureErrorCodes.SIGNATURE_MISMATCH]: \"Signature mismatch\",\n} as const;\n\nexport interface WebhookVerifierOptions<T extends Function> {\n /**\n * The hex-encoded secret key used to verify the signature\n */\n secretHex: string;\n\n /**\n * The name of the header containing the signature\n * @default \"x-signature\"\n */\n signatureHeader?: string;\n\n /**\n * Optional function to handle unauthorized requests\n * @default Returns 401 Unauthorized with JSON error\n */\n onUnauthorized?: T;\n\n /**\n * Whether to make the raw body available on req.raw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AyB;AAClD,MAAI,IAAI,SAAS,MAAM,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC9D,QAAM,QAAQ,IAAI,WAAW,IAAI,SAAS,CAAC;AAC3C,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,GAAG;AACtC,UAAM,IAAI,CAAC,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE;AAAA,EACjD;AACA,SAAO;AACT;AAOO,SAAS,YAAY,QAA6B;AACvD,SAAO,MAAM,KAAK,IAAI,WAAW,MAAM,CAAC,EACrC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAC1C,KAAK,EAAE;AACZ;AAQO,SAAS,gBAAgB,GAAW,GAAoB;AAC7D,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,cAAU,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC5C;AACA,SAAO,WAAW;AACpB;AAEO,IAAM,6BAA6B;AAAA,EACxC,0BAA0B;AAAA,EAC1B,0BAA0B;AAAA,EAC1B,oBAAoB;AACtB;AAEO,IAAM,gCAAgC;AAAA,EAC3C,CAAC,2BAA2B,wBAAwB,GAClD;AAAA,EACF,CAAC,2BAA2B,wBAAwB,GAClD;AAAA,EACF,CAAC,2BAA2B,kBAAkB,GAAG;AACnD;","names":["createClient"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/client.ts","../src/verification-session.ts","../src/webhook.ts"],"sourcesContent":["export * from \"./constants\";\nexport * from \"./types\";\nexport * from \"./verification-session\";\nexport * from \"./webhook\";\n","export const Environments = {\n LOCAL: \"local\",\n STAGING: \"staging\",\n PRODUCTION: \"production\",\n} as const;\n\nexport type Environment = (typeof Environments)[keyof typeof Environments];\n\ninterface EnvironmentConfig {\n appUrl: string;\n apiUrl: string;\n}\n\nexport const EnvironmentConfigs: Record<Environment, EnvironmentConfig> = {\n [Environments.LOCAL]: {\n appUrl: \"http://localhost:5173\",\n apiUrl: \"http://localhost:3000\",\n },\n [Environments.STAGING]: {\n appUrl: \"https://app-dev.zyphe.com\",\n apiUrl: \"https://api-dev.zyphe.com\",\n },\n [Environments.PRODUCTION]: {\n appUrl: \"https://verify.zyphe.com\",\n apiUrl: \"https://api.zyphe.com\",\n },\n};\n\nexport const API_KEY_HEADER = \"x-api-key\";\n","import createClient from \"openapi-fetch\";\nimport type { paths } from \"@zyphe-sdk/core/openapi\";\nimport { EnvironmentConfigs } from \"./constants\";\nimport type { SDKOptions } from \"./types\";\n\nexport const zypheApiClient = (opts: SDKOptions) => {\n return createClient<paths>({\n baseUrl: EnvironmentConfigs[opts.environment].apiUrl,\n });\n};\n","import { zypheApiClient } from \"./client\";\nimport { API_KEY_HEADER, EnvironmentConfigs, Environments } from \"./constants\";\nimport type {\n InitializeZypheFlowParams,\n SdkCreateVerificationRequestResponse,\n SDKOptions,\n} from \"./types\";\n\ninterface CreateVerificationSessionParams {\n email: string;\n flowId: string;\n flowStepId: string;\n isSandbox: boolean;\n customData?: Record<string, string>;\n}\n\nexport function createVerificationSession(\n {\n email,\n flowId,\n flowStepId,\n isSandbox,\n customData,\n }: CreateVerificationSessionParams,\n opts: SDKOptions\n) {\n const client = zypheApiClient(opts);\n\n return client.POST(\"/sdk/flow/{flow_id}/vr/create\", {\n body: { email, flowStepId, customData },\n headers: {\n [API_KEY_HEADER]: opts.apiKey,\n },\n params: {\n path: {\n flow_id: flowId,\n },\n query: {\n sandbox: isSandbox,\n },\n },\n });\n}\n\nfunction getFlowUrlOrigin(environment: SDKOptions[\"environment\"]) {\n switch (environment) {\n case Environments.LOCAL:\n return EnvironmentConfigs[Environments.LOCAL].appUrl;\n case Environments.STAGING:\n return EnvironmentConfigs[Environments.STAGING].appUrl;\n case Environments.PRODUCTION:\n return EnvironmentConfigs[Environments.PRODUCTION].appUrl;\n default:\n throw new Error(`Invalid environment: ${environment}`);\n }\n}\n\nexport function constructVerificationSessionUrl({\n flowParams,\n verificationSession,\n opts,\n}: {\n flowParams: InitializeZypheFlowParams;\n verificationSession: SdkCreateVerificationRequestResponse;\n opts: SDKOptions;\n}) {\n const origin = getFlowUrlOrigin(opts.environment);\n const { isSandbox, product } = flowParams;\n const { handoffBaseUrl, primaryColor, secondaryColor, isFullscreen } = opts;\n\n if (!verificationSession) {\n throw new Error(\"Failed to create verification session\");\n }\n\n let baseUrl = `${origin}${isSandbox ? \"/sandbox\" : \"\"}/flow/${verificationSession.flowSlug}/${product}/${verificationSession.flowStepSlug}?zypheVr=${encodeURIComponent(verificationSession.verificationRequest.id)}&zypheEmail=${encodeURIComponent(verificationSession.email)}&zypheToken=${encodeURIComponent(verificationSession.zypheToken)}`;\n\n if (handoffBaseUrl) {\n baseUrl += `&zypheHandoffBaseUrl=${encodeURIComponent(handoffBaseUrl)}`;\n }\n\n if (primaryColor) {\n baseUrl += `&zyphePrimaryColor=${encodeURIComponent(primaryColor)}`;\n }\n\n if (secondaryColor) {\n baseUrl += `&zypheSecondaryColor=${encodeURIComponent(secondaryColor)}`;\n }\n\n if (isFullscreen) {\n baseUrl += `&zypheFullscreen=${encodeURIComponent(isFullscreen)}`;\n }\n\n return baseUrl;\n}\n","export interface SignatureComponents {\n timestamp: string;\n signatureHex: string;\n}\n\n/**\n * Parses a webhook signature header of the form \"t=<timestamp>,v0=<signature>\"\n * @param signatureHeader - The header string, e.g. \"t=1234567890,v0=abcdef...\"\n * @returns The parsed timestamp and signature hex\n */\nexport function parseSignatureHeader(\n signatureHeader: string\n): SignatureComponents {\n const match = signatureHeader.match(/^t=(\\d+),v0=([a-fA-F0-9]+)$/);\n if (!match) {\n throw new Error(\"Invalid signature header format\");\n }\n const [, timestamp, signatureHex] = match;\n\n if (!timestamp || !signatureHex) {\n throw new Error(\"Invalid signature header format\");\n }\n\n return { timestamp, signatureHex };\n}\n\n/**\n * Converts a hex string to a Uint8Array\n * @param hex - The hex string to convert\n * @returns The resulting Uint8Array\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) throw new Error(\"Invalid hex string\");\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Converts an ArrayBuffer to a hex string\n * @param buffer - The buffer to convert\n * @returns The hex string representation\n */\nexport function bufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Compares two strings in constant time to prevent timing attacks\n * @param a - First string\n * @param b - Second string\n * @returns True if strings are equal, false otherwise\n */\nexport function timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n\nexport const WebhookSignatureErrorCodes = {\n MISSING_SIGNATURE_HEADER: 1,\n INVALID_SIGNATURE_HEADER: 2,\n SIGNATURE_MISMATCH: 3,\n} as const;\n\nexport const WebhookSignatureErrorMessages = {\n [WebhookSignatureErrorCodes.MISSING_SIGNATURE_HEADER]:\n \"Missing signature header\",\n [WebhookSignatureErrorCodes.INVALID_SIGNATURE_HEADER]:\n \"Invalid signature header\",\n [WebhookSignatureErrorCodes.SIGNATURE_MISMATCH]: \"Signature mismatch\",\n} as const;\n\nexport interface WebhookVerifierOptions<T extends Function> {\n /**\n * The hex-encoded secret key used to verify the signature\n */\n secretHex: string;\n\n /**\n * The name of the header containing the signature\n * @default \"x-signature\"\n */\n signatureHeader?: string;\n\n /**\n * Optional function to handle unauthorized requests\n * @default Returns 401 Unauthorized with JSON error\n */\n onUnauthorized?: T;\n\n /**\n * Whether to make the raw body available on req.rawBody\n * @default true\n */\n exposeRawBody?: boolean;\n}\n"],"mappings":";;;;;;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;AAClD,MAAI,IAAI,SAAS,MAAM,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC9D,QAAM,QAAQ,IAAI,WAAW,IAAI,SAAS,CAAC;AAC3C,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,GAAG;AACtC,UAAM,IAAI,CAAC,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE;AAAA,EACjD;AACA,SAAO;AACT;AAOO,SAAS,YAAY,QAA6B;AACvD,SAAO,MAAM,KAAK,IAAI,WAAW,MAAM,CAAC,EACrC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAC1C,KAAK,EAAE;AACZ;AAQO,SAAS,gBAAgB,GAAW,GAAoB;AAC7D,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,cAAU,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC5C;AACA,SAAO,WAAW;AACpB;AAEO,IAAM,6BAA6B;AAAA,EACxC,0BAA0B;AAAA,EAC1B,0BAA0B;AAAA,EAC1B,oBAAoB;AACtB;AAEO,IAAM,gCAAgC;AAAA,EAC3C,CAAC,2BAA2B,wBAAwB,GAClD;AAAA,EACF,CAAC,2BAA2B,wBAAwB,GAClD;AAAA,EACF,CAAC,2BAA2B,kBAAkB,GAAG;AACnD;","names":["createClient"]}
package/dist/index.d.cts CHANGED
@@ -774,6 +774,11 @@ interface InitializeZypheFlowParams {
774
774
  * @example "http://localhost:5173/sandbox/flow/flowSlug/kyc/stepSlug"
775
775
  */
776
776
  isSandbox: boolean;
777
+ /**
778
+ * Custom data to be passed to the Flow.
779
+ * @example { "custom_data": "custom_value" }
780
+ */
781
+ customData?: Record<string, string>;
777
782
  }
778
783
  interface SDKOptions {
779
784
  apiKey: string;
@@ -1535,7 +1540,14 @@ interface components {
1535
1540
  pathItems: never;
1536
1541
  }
1537
1542
 
1538
- declare function createVerificationSession(email: string, flowId: string, flowStepId: string, isSandbox: boolean, opts: SDKOptions): Promise<openapi_fetch.FetchResponse<{
1543
+ interface CreateVerificationSessionParams {
1544
+ email: string;
1545
+ flowId: string;
1546
+ flowStepId: string;
1547
+ isSandbox: boolean;
1548
+ customData?: Record<string, string>;
1549
+ }
1550
+ declare function createVerificationSession({ email, flowId, flowStepId, isSandbox, customData, }: CreateVerificationSessionParams, opts: SDKOptions): Promise<openapi_fetch.FetchResponse<{
1539
1551
  parameters: {
1540
1552
  query?: {
1541
1553
  sandbox?: boolean | null;
@@ -1589,6 +1601,7 @@ declare function createVerificationSession(email: string, flowId: string, flowSt
1589
1601
  body: {
1590
1602
  email: string;
1591
1603
  flowStepId: string;
1604
+ customData: Record<string, string> | undefined;
1592
1605
  };
1593
1606
  headers: {
1594
1607
  "x-api-key": string;
package/dist/index.d.ts CHANGED
@@ -774,6 +774,11 @@ interface InitializeZypheFlowParams {
774
774
  * @example "http://localhost:5173/sandbox/flow/flowSlug/kyc/stepSlug"
775
775
  */
776
776
  isSandbox: boolean;
777
+ /**
778
+ * Custom data to be passed to the Flow.
779
+ * @example { "custom_data": "custom_value" }
780
+ */
781
+ customData?: Record<string, string>;
777
782
  }
778
783
  interface SDKOptions {
779
784
  apiKey: string;
@@ -1535,7 +1540,14 @@ interface components {
1535
1540
  pathItems: never;
1536
1541
  }
1537
1542
 
1538
- declare function createVerificationSession(email: string, flowId: string, flowStepId: string, isSandbox: boolean, opts: SDKOptions): Promise<openapi_fetch.FetchResponse<{
1543
+ interface CreateVerificationSessionParams {
1544
+ email: string;
1545
+ flowId: string;
1546
+ flowStepId: string;
1547
+ isSandbox: boolean;
1548
+ customData?: Record<string, string>;
1549
+ }
1550
+ declare function createVerificationSession({ email, flowId, flowStepId, isSandbox, customData, }: CreateVerificationSessionParams, opts: SDKOptions): Promise<openapi_fetch.FetchResponse<{
1539
1551
  parameters: {
1540
1552
  query?: {
1541
1553
  sandbox?: boolean | null;
@@ -1589,6 +1601,7 @@ declare function createVerificationSession(email: string, flowId: string, flowSt
1589
1601
  body: {
1590
1602
  email: string;
1591
1603
  flowStepId: string;
1604
+ customData: Record<string, string> | undefined;
1592
1605
  };
1593
1606
  headers: {
1594
1607
  "x-api-key": string;
package/dist/index.js CHANGED
@@ -29,10 +29,16 @@ var zypheApiClient = (opts) => {
29
29
  };
30
30
 
31
31
  // src/verification-session.ts
32
- function createVerificationSession(email, flowId, flowStepId, isSandbox, opts) {
32
+ function createVerificationSession({
33
+ email,
34
+ flowId,
35
+ flowStepId,
36
+ isSandbox,
37
+ customData
38
+ }, opts) {
33
39
  const client = zypheApiClient(opts);
34
40
  return client.POST("/sdk/flow/{flow_id}/vr/create", {
35
- body: { email, flowStepId },
41
+ body: { email, flowStepId, customData },
36
42
  headers: {
37
43
  [API_KEY_HEADER]: opts.apiKey
38
44
  },
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/client.ts","../src/verification-session.ts","../src/webhook.ts"],"sourcesContent":["export const Environments = {\n LOCAL: \"local\",\n STAGING: \"staging\",\n PRODUCTION: \"production\",\n} as const;\n\nexport type Environment = (typeof Environments)[keyof typeof Environments];\n\ninterface EnvironmentConfig {\n appUrl: string;\n apiUrl: string;\n}\n\nexport const EnvironmentConfigs: Record<Environment, EnvironmentConfig> = {\n [Environments.LOCAL]: {\n appUrl: \"http://localhost:5173\",\n apiUrl: \"http://localhost:3000\",\n },\n [Environments.STAGING]: {\n appUrl: \"https://app-dev.zyphe.com\",\n apiUrl: \"https://api-dev.zyphe.com\",\n },\n [Environments.PRODUCTION]: {\n appUrl: \"https://verify.zyphe.com\",\n apiUrl: \"https://api.zyphe.com\",\n },\n};\n\nexport const API_KEY_HEADER = \"x-api-key\";\n","import createClient from \"openapi-fetch\";\nimport type { paths } from \"@zyphe-sdk/core/openapi\";\nimport { EnvironmentConfigs } from \"./constants\";\nimport type { SDKOptions } from \"./types\";\n\nexport const zypheApiClient = (opts: SDKOptions) => {\n return createClient<paths>({\n baseUrl: EnvironmentConfigs[opts.environment].apiUrl,\n });\n};\n","import { zypheApiClient } from \"./client\";\nimport { API_KEY_HEADER, EnvironmentConfigs, Environments } from \"./constants\";\nimport type {\n InitializeZypheFlowParams,\n SdkCreateVerificationRequestResponse,\n SDKOptions,\n} from \"./types\";\n\nexport function createVerificationSession(\n email: string,\n flowId: string,\n flowStepId: string,\n isSandbox: boolean,\n opts: SDKOptions\n) {\n const client = zypheApiClient(opts);\n\n return client.POST(\"/sdk/flow/{flow_id}/vr/create\", {\n body: { email, flowStepId },\n headers: {\n [API_KEY_HEADER]: opts.apiKey,\n },\n params: {\n path: {\n flow_id: flowId,\n },\n query: {\n sandbox: isSandbox,\n },\n },\n });\n}\n\nfunction getFlowUrlOrigin(environment: SDKOptions[\"environment\"]) {\n switch (environment) {\n case Environments.LOCAL:\n return EnvironmentConfigs[Environments.LOCAL].appUrl;\n case Environments.STAGING:\n return EnvironmentConfigs[Environments.STAGING].appUrl;\n case Environments.PRODUCTION:\n return EnvironmentConfigs[Environments.PRODUCTION].appUrl;\n default:\n throw new Error(`Invalid environment: ${environment}`);\n }\n}\n\nexport function constructVerificationSessionUrl({\n flowParams,\n verificationSession,\n opts,\n}: {\n flowParams: InitializeZypheFlowParams;\n verificationSession: SdkCreateVerificationRequestResponse;\n opts: SDKOptions;\n}) {\n const origin = getFlowUrlOrigin(opts.environment);\n const { isSandbox, product } = flowParams;\n const { handoffBaseUrl, primaryColor, secondaryColor, isFullscreen } = opts;\n\n if (!verificationSession) {\n throw new Error(\"Failed to create verification session\");\n }\n\n let baseUrl = `${origin}${isSandbox ? \"/sandbox\" : \"\"}/flow/${verificationSession.flowSlug}/${product}/${verificationSession.flowStepSlug}?zypheVr=${encodeURIComponent(verificationSession.verificationRequest.id)}&zypheEmail=${encodeURIComponent(verificationSession.email)}&zypheToken=${encodeURIComponent(verificationSession.zypheToken)}`;\n\n if (handoffBaseUrl) {\n baseUrl += `&zypheHandoffBaseUrl=${encodeURIComponent(handoffBaseUrl)}`;\n }\n\n if (primaryColor) {\n baseUrl += `&zyphePrimaryColor=${encodeURIComponent(primaryColor)}`;\n }\n\n if (secondaryColor) {\n baseUrl += `&zypheSecondaryColor=${encodeURIComponent(secondaryColor)}`;\n }\n\n if (isFullscreen) {\n baseUrl += `&zypheFullscreen=${encodeURIComponent(isFullscreen)}`;\n }\n\n return baseUrl;\n}\n","export interface SignatureComponents {\n timestamp: string;\n signatureHex: string;\n}\n\n/**\n * Parses a webhook signature header of the form \"t=<timestamp>,v0=<signature>\"\n * @param signatureHeader - The header string, e.g. \"t=1234567890,v0=abcdef...\"\n * @returns The parsed timestamp and signature hex\n */\nexport function parseSignatureHeader(\n signatureHeader: string\n): SignatureComponents {\n const match = signatureHeader.match(/^t=(\\d+),v0=([a-fA-F0-9]+)$/);\n if (!match) {\n throw new Error(\"Invalid signature header format\");\n }\n const [, timestamp, signatureHex] = match;\n\n if (!timestamp || !signatureHex) {\n throw new Error(\"Invalid signature header format\");\n }\n\n return { timestamp, signatureHex };\n}\n\n/**\n * Converts a hex string to a Uint8Array\n * @param hex - The hex string to convert\n * @returns The resulting Uint8Array\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) throw new Error(\"Invalid hex string\");\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Converts an ArrayBuffer to a hex string\n * @param buffer - The buffer to convert\n * @returns The hex string representation\n */\nexport function bufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Compares two strings in constant time to prevent timing attacks\n * @param a - First string\n * @param b - Second string\n * @returns True if strings are equal, false otherwise\n */\nexport function timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n\nexport const WebhookSignatureErrorCodes = {\n MISSING_SIGNATURE_HEADER: 1,\n INVALID_SIGNATURE_HEADER: 2,\n SIGNATURE_MISMATCH: 3,\n} as const;\n\nexport const WebhookSignatureErrorMessages = {\n [WebhookSignatureErrorCodes.MISSING_SIGNATURE_HEADER]:\n \"Missing signature header\",\n [WebhookSignatureErrorCodes.INVALID_SIGNATURE_HEADER]:\n \"Invalid signature header\",\n [WebhookSignatureErrorCodes.SIGNATURE_MISMATCH]: \"Signature mismatch\",\n} as const;\n\nexport interface WebhookVerifierOptions<T extends Function> {\n /**\n * The hex-encoded secret key used to verify the signature\n */\n secretHex: string;\n\n /**\n * The name of the header containing the signature\n * @default \"x-signature\"\n */\n signatureHeader?: string;\n\n /**\n * Optional function to handle unauthorized requests\n * @default Returns 401 Unauthorized with JSON error\n */\n onUnauthorized?: T;\n\n /**\n * Whether to make the raw body available on req.rawBody\n * @default true\n */\n exposeRawBody?: boolean;\n}\n"],"mappings":";AAAO,IAAM,eAAe;AAAA,EAC1B,OAAO;AAAA,EACP,SAAS;AAAA,EACT,YAAY;AACd;AASO,IAAM,qBAA6D;AAAA,EACxE,CAAC,aAAa,KAAK,GAAG;AAAA,IACpB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,CAAC,aAAa,OAAO,GAAG;AAAA,IACtB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,CAAC,aAAa,UAAU,GAAG;AAAA,IACzB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AACF;AAEO,IAAM,iBAAiB;;;AC5B9B,OAAO,kBAAkB;AAKlB,IAAM,iBAAiB,CAAC,SAAqB;AAClD,SAAO,aAAoB;AAAA,IACzB,SAAS,mBAAmB,KAAK,WAAW,EAAE;AAAA,EAChD,CAAC;AACH;;;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,6BAA6B;AAAA,EACxC,0BAA0B;AAAA,EAC1B,0BAA0B;AAAA,EAC1B,oBAAoB;AACtB;AAEO,IAAM,gCAAgC;AAAA,EAC3C,CAAC,2BAA2B,wBAAwB,GAClD;AAAA,EACF,CAAC,2BAA2B,wBAAwB,GAClD;AAAA,EACF,CAAC,2BAA2B,kBAAkB,GAAG;AACnD;","names":[]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/client.ts","../src/verification-session.ts","../src/webhook.ts"],"sourcesContent":["export const Environments = {\n LOCAL: \"local\",\n STAGING: \"staging\",\n PRODUCTION: \"production\",\n} as const;\n\nexport type Environment = (typeof Environments)[keyof typeof Environments];\n\ninterface EnvironmentConfig {\n appUrl: string;\n apiUrl: string;\n}\n\nexport const EnvironmentConfigs: Record<Environment, EnvironmentConfig> = {\n [Environments.LOCAL]: {\n appUrl: \"http://localhost:5173\",\n apiUrl: \"http://localhost:3000\",\n },\n [Environments.STAGING]: {\n appUrl: \"https://app-dev.zyphe.com\",\n apiUrl: \"https://api-dev.zyphe.com\",\n },\n [Environments.PRODUCTION]: {\n appUrl: \"https://verify.zyphe.com\",\n apiUrl: \"https://api.zyphe.com\",\n },\n};\n\nexport const API_KEY_HEADER = \"x-api-key\";\n","import createClient from \"openapi-fetch\";\nimport type { paths } from \"@zyphe-sdk/core/openapi\";\nimport { EnvironmentConfigs } from \"./constants\";\nimport type { SDKOptions } from \"./types\";\n\nexport const zypheApiClient = (opts: SDKOptions) => {\n return createClient<paths>({\n baseUrl: EnvironmentConfigs[opts.environment].apiUrl,\n });\n};\n","import { zypheApiClient } from \"./client\";\nimport { API_KEY_HEADER, EnvironmentConfigs, Environments } from \"./constants\";\nimport type {\n InitializeZypheFlowParams,\n SdkCreateVerificationRequestResponse,\n SDKOptions,\n} from \"./types\";\n\ninterface CreateVerificationSessionParams {\n email: string;\n flowId: string;\n flowStepId: string;\n isSandbox: boolean;\n customData?: Record<string, string>;\n}\n\nexport function createVerificationSession(\n {\n email,\n flowId,\n flowStepId,\n isSandbox,\n customData,\n }: CreateVerificationSessionParams,\n opts: SDKOptions\n) {\n const client = zypheApiClient(opts);\n\n return client.POST(\"/sdk/flow/{flow_id}/vr/create\", {\n body: { email, flowStepId, customData },\n headers: {\n [API_KEY_HEADER]: opts.apiKey,\n },\n params: {\n path: {\n flow_id: flowId,\n },\n query: {\n sandbox: isSandbox,\n },\n },\n });\n}\n\nfunction getFlowUrlOrigin(environment: SDKOptions[\"environment\"]) {\n switch (environment) {\n case Environments.LOCAL:\n return EnvironmentConfigs[Environments.LOCAL].appUrl;\n case Environments.STAGING:\n return EnvironmentConfigs[Environments.STAGING].appUrl;\n case Environments.PRODUCTION:\n return EnvironmentConfigs[Environments.PRODUCTION].appUrl;\n default:\n throw new Error(`Invalid environment: ${environment}`);\n }\n}\n\nexport function constructVerificationSessionUrl({\n flowParams,\n verificationSession,\n opts,\n}: {\n flowParams: InitializeZypheFlowParams;\n verificationSession: SdkCreateVerificationRequestResponse;\n opts: SDKOptions;\n}) {\n const origin = getFlowUrlOrigin(opts.environment);\n const { isSandbox, product } = flowParams;\n const { handoffBaseUrl, primaryColor, secondaryColor, isFullscreen } = opts;\n\n if (!verificationSession) {\n throw new Error(\"Failed to create verification session\");\n }\n\n let baseUrl = `${origin}${isSandbox ? \"/sandbox\" : \"\"}/flow/${verificationSession.flowSlug}/${product}/${verificationSession.flowStepSlug}?zypheVr=${encodeURIComponent(verificationSession.verificationRequest.id)}&zypheEmail=${encodeURIComponent(verificationSession.email)}&zypheToken=${encodeURIComponent(verificationSession.zypheToken)}`;\n\n if (handoffBaseUrl) {\n baseUrl += `&zypheHandoffBaseUrl=${encodeURIComponent(handoffBaseUrl)}`;\n }\n\n if (primaryColor) {\n baseUrl += `&zyphePrimaryColor=${encodeURIComponent(primaryColor)}`;\n }\n\n if (secondaryColor) {\n baseUrl += `&zypheSecondaryColor=${encodeURIComponent(secondaryColor)}`;\n }\n\n if (isFullscreen) {\n baseUrl += `&zypheFullscreen=${encodeURIComponent(isFullscreen)}`;\n }\n\n return baseUrl;\n}\n","export interface SignatureComponents {\n timestamp: string;\n signatureHex: string;\n}\n\n/**\n * Parses a webhook signature header of the form \"t=<timestamp>,v0=<signature>\"\n * @param signatureHeader - The header string, e.g. \"t=1234567890,v0=abcdef...\"\n * @returns The parsed timestamp and signature hex\n */\nexport function parseSignatureHeader(\n signatureHeader: string\n): SignatureComponents {\n const match = signatureHeader.match(/^t=(\\d+),v0=([a-fA-F0-9]+)$/);\n if (!match) {\n throw new Error(\"Invalid signature header format\");\n }\n const [, timestamp, signatureHex] = match;\n\n if (!timestamp || !signatureHex) {\n throw new Error(\"Invalid signature header format\");\n }\n\n return { timestamp, signatureHex };\n}\n\n/**\n * Converts a hex string to a Uint8Array\n * @param hex - The hex string to convert\n * @returns The resulting Uint8Array\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) throw new Error(\"Invalid hex string\");\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Converts an ArrayBuffer to a hex string\n * @param buffer - The buffer to convert\n * @returns The hex string representation\n */\nexport function bufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Compares two strings in constant time to prevent timing attacks\n * @param a - First string\n * @param b - Second string\n * @returns True if strings are equal, false otherwise\n */\nexport function timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n\nexport const WebhookSignatureErrorCodes = {\n MISSING_SIGNATURE_HEADER: 1,\n INVALID_SIGNATURE_HEADER: 2,\n SIGNATURE_MISMATCH: 3,\n} as const;\n\nexport const WebhookSignatureErrorMessages = {\n [WebhookSignatureErrorCodes.MISSING_SIGNATURE_HEADER]:\n \"Missing signature header\",\n [WebhookSignatureErrorCodes.INVALID_SIGNATURE_HEADER]:\n \"Invalid signature header\",\n [WebhookSignatureErrorCodes.SIGNATURE_MISMATCH]: \"Signature mismatch\",\n} as const;\n\nexport interface WebhookVerifierOptions<T extends Function> {\n /**\n * The hex-encoded secret key used to verify the signature\n */\n secretHex: string;\n\n /**\n * The name of the header containing the signature\n * @default \"x-signature\"\n */\n signatureHeader?: string;\n\n /**\n * Optional function to handle unauthorized requests\n * @default Returns 401 Unauthorized with JSON error\n */\n onUnauthorized?: T;\n\n /**\n * Whether to make the raw body available on req.rawBody\n * @default true\n */\n exposeRawBody?: boolean;\n}\n"],"mappings":";AAAO,IAAM,eAAe;AAAA,EAC1B,OAAO;AAAA,EACP,SAAS;AAAA,EACT,YAAY;AACd;AASO,IAAM,qBAA6D;AAAA,EACxE,CAAC,aAAa,KAAK,GAAG;AAAA,IACpB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,CAAC,aAAa,OAAO,GAAG;AAAA,IACtB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,CAAC,aAAa,UAAU,GAAG;AAAA,IACzB,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AACF;AAEO,IAAM,iBAAiB;;;AC5B9B,OAAO,kBAAkB;AAKlB,IAAM,iBAAiB,CAAC,SAAqB;AAClD,SAAO,aAAoB;AAAA,IACzB,SAAS,mBAAmB,KAAK,WAAW,EAAE;AAAA,EAChD,CAAC;AACH;;;ACOO,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACA,MACA;AACA,QAAM,SAAS,eAAe,IAAI;AAElC,SAAO,OAAO,KAAK,iCAAiC;AAAA,IAClD,MAAM,EAAE,OAAO,YAAY,WAAW;AAAA,IACtC,SAAS;AAAA,MACP,CAAC,cAAc,GAAG,KAAK;AAAA,IACzB;AAAA,I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B,GAAG;AACnD;","names":[]}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@zyphe-sdk/core",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Simplifies interaction with the Zyphe platform for creating and managing digital identities and digital onboarding flows with ease",
5
5
  "author": "Zyphe",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "sideEffects": false,
9
9
  "main": "dist/index.js",
10
+ "module": "dist/index.js",
10
11
  "exports": {
11
12
  ".": {
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
13
+ "import": "./dist/index.js"
14
14
  },
15
15
  "./openapi": {
16
16
  "types": "./dist/openapi.d.ts",
package/src/types.ts CHANGED
@@ -39,6 +39,11 @@ export interface InitializeZypheFlowParams {
39
39
  * @example "http://localhost:5173/sandbox/flow/flowSlug/kyc/stepSlug"
40
40
  */
41
41
  isSandbox: boolean;
42
+ /**
43
+ * Custom data to be passed to the Flow.
44
+ * @example { "custom_data": "custom_value" }
45
+ */
46
+ customData?: Record<string, string>;
42
47
  }
43
48
 
44
49
  export interface SDKOptions {
@@ -6,17 +6,28 @@ import type {
6
6
  SDKOptions,
7
7
  } from "./types";
8
8
 
9
+ interface CreateVerificationSessionParams {
10
+ email: string;
11
+ flowId: string;
12
+ flowStepId: string;
13
+ isSandbox: boolean;
14
+ customData?: Record<string, string>;
15
+ }
16
+
9
17
  export function createVerificationSession(
10
- email: string,
11
- flowId: string,
12
- flowStepId: string,
13
- isSandbox: boolean,
18
+ {
19
+ email,
20
+ flowId,
21
+ flowStepId,
22
+ isSandbox,
23
+ customData,
24
+ }: CreateVerificationSessionParams,
14
25
  opts: SDKOptions
15
26
  ) {
16
27
  const client = zypheApiClient(opts);
17
28
 
18
29
  return client.POST("/sdk/flow/{flow_id}/vr/create", {
19
- body: { email, flowStepId },
30
+ body: { email, flowStepId, customData },
20
31
  headers: {
21
32
  [API_KEY_HEADER]: opts.apiKey,
22
33
  },
package/tsup.config.ts CHANGED
@@ -2,7 +2,7 @@ import { defineConfig } from "tsup";
2
2
 
3
3
  export default defineConfig({
4
4
  dts: true,
5
- format: ["esm", "cjs"],
5
+ format: ["esm"],
6
6
  sourcemap: true,
7
7
  outDir: "dist",
8
8
  entry: ["src/index.ts"],