@zyphe-sdk/core 0.1.7 → 0.1.8

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
@@ -10,13 +10,13 @@
10
10
  CLI Target: es2023
11
11
  ESM Build start
12
12
  CJS Build start
13
- ESM dist/index.js 4.28 KB
14
- ESM dist/index.js.map 9.36 KB
13
+ CJS dist/index.cjs 6.12 KB
14
+ CJS dist/index.cjs.map 9.89 KB
15
+ CJS ⚡️ Build success in 12ms
16
+ ESM dist/index.js 4.31 KB
17
+ ESM dist/index.js.map 9.62 KB
15
18
  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
19
19
  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
20
+ DTS ⚡️ Build success in 898ms
21
+ DTS dist/index.d.ts 62.09 KB
22
+ DTS dist/index.d.cts 62.09 KB
package/README.md CHANGED
@@ -57,16 +57,28 @@ You can programmatically create verification sessions and construct user-facing
57
57
  import { createVerificationSession } from "@zyphe-sdk/core";
58
58
 
59
59
  const response = await createVerificationSession(
60
- "user@example.com", // email
61
- "<flowId>", // flowId
62
- "<flowStepId>", // flowStepId
63
- false, // isSandbox
60
+ {
61
+ email: "user@example.com", // required
62
+ flowId: "<flowId>", // required
63
+ flowStepId: "<flowStepId>",// required
64
+ isSandbox: false, // required
65
+ customData: { // optional
66
+ walletAddress: "0x123...",
67
+ // ...any extra data you want to pass
68
+ },
69
+ },
64
70
  {
65
71
  apiKey: "<your-api-key>",
66
72
  environment: "staging", // or "production", "local"
73
+ handoffBaseUrl: "https://your-app.com", // optional
74
+ primaryColor: "#000000", // optional
75
+ secondaryColor: "#ffffff", // optional
76
+ isFullscreen: true, // optional
67
77
  }
68
78
  );
69
79
  ```
80
+ - `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.
81
+ - The function returns a Promise resolving to the API response. Handle errors as needed (e.g., try/catch or checking for error fields).
70
82
 
71
83
  ### Construct a Verification Session URL
72
84
  ```ts
@@ -77,20 +89,46 @@ const url = constructVerificationSessionUrl({
77
89
  flowId: "...",
78
90
  flowStepId: "...",
79
91
  email: "user@example.com",
80
- product: "kyc",
92
+ product: "kyc", // or "kyb" if supported
81
93
  isSandbox: false,
94
+ customData: { walletAddress: "0x123..." }, // optional
82
95
  },
83
96
  verificationSession: response.data, // from createVerificationSession
84
97
  opts: {
85
98
  apiKey: "<your-api-key>",
86
99
  environment: "staging",
87
- handoffBaseUrl: "https://your-app.com",
88
- primaryColor: "#000000",
89
- secondaryColor: "#ffffff",
90
- isFullscreen: true,
100
+ handoffBaseUrl: "https://your-app.com", // optional
101
+ primaryColor: "#000000", // optional
102
+ secondaryColor: "#ffffff", // optional
103
+ isFullscreen: true, // optional
91
104
  },
92
105
  });
93
106
  ```
107
+ - The constructed URL includes all relevant parameters and can be used to embed or redirect users to the verification flow.
108
+ - Optional fields (like `handoffBaseUrl`, `primaryColor`, etc.) will be appended as query parameters if provided.
109
+
110
+ #### Types
111
+ - `InitializeZypheFlowParams`: Parameters for initializing a verification flow (see [types.ts](./src/types.ts)).
112
+ - `SDKOptions`: Configuration for the SDK (see [types.ts](./src/types.ts)).
113
+ - `SdkCreateVerificationRequestResponse`: API response type for session creation.
114
+
115
+ #### Error Handling
116
+ - 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.
117
+ - Example:
118
+ ```ts
119
+ try {
120
+ const response = await createVerificationSession(...);
121
+ if (response.error) {
122
+ // Handle error
123
+ console.error(response.error);
124
+ } else {
125
+ // Success
126
+ }
127
+ } catch (err) {
128
+ // Handle thrown errors (e.g., network issues)
129
+ console.error(err);
130
+ }
131
+ ```
94
132
 
95
133
  ---
96
134
 
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.rawBody\n * @default true\n */\n exposeRawBody?: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,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,2BAAyB;AA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AG,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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,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,2BAAyB;AAKlB,IAAM,iBAAiB,CAAC,SAAqB;AAClD,aAAO,qBAAAA,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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;;;ACDO,SAAS,0BACd,OACA,QACA,YACA,WACA,MACA;AACA,QAAM,SAAS,eAAe,IAAI;AAElC,SAAO,OAAO,KAAK,iCAAiC;AAAA,IAClD,MAAM,EAAE,OAAO,WAAW;AAAA,IAC1B,SAAS;AAAA,MACP,CAAC,cAAc,GAAG,KAAK;AAAA,IACzB;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,QACJ,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,SAAS,iBAAiB,aAAwC;AAChE,UAAQ,aAAa;AAAA,IACnB,KAAK,aAAa;AAChB,aAAO,mBAAmB,aAAa,KAAK,EAAE;AAAA,IAChD,KAAK,aAAa;AAChB,aAAO,mBAAmB,aAAa,OAAO,EAAE;AAAA,IAClD,KAAK,aAAa;AAChB,aAAO,mBAAmB,aAA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AM,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":[]}
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,aAA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G,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyphe-sdk/core",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
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",
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
  },