@zyphe-sdk/core 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +432 -811
- package/dist/index.js +1072 -12
- package/dist/index.js.map +1 -1
- package/dist/openapi.d.ts +139 -2
- package/dist/openapi.json +209 -4
- package/package.json +22 -11
- package/.turbo/turbo-build.log +0 -17
- package/dist/index.cjs +0 -181
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1685
- package/docs/express.md +0 -45
- package/docs/fastify.md +0 -85
- package/docs/hono.md +0 -32
- package/public/openapi.d.ts +0 -959
- package/public/openapi.json +0 -3094
- package/scripts/generate-openapi.ts +0 -70
- package/src/client.ts +0 -10
- package/src/constants.ts +0 -29
- package/src/index.ts +0 -4
- package/src/types.ts +0 -82
- package/src/verification-session.ts +0 -94
- package/src/webhook.ts +0 -104
- package/tsconfig.json +0 -32
- package/tsup.config.ts +0 -11
package/dist/openapi.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"openapi": "3.0.3",
|
|
3
3
|
"info": {
|
|
4
|
-
"title": "zyphe-
|
|
4
|
+
"title": "zyphe-sdk",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": {
|
|
7
7
|
"name": ""
|
|
@@ -284,6 +284,180 @@
|
|
|
284
284
|
}
|
|
285
285
|
]
|
|
286
286
|
}
|
|
287
|
+
},
|
|
288
|
+
"/sdk/organizations/{organization_id}/flow-results/{flow_result_id}/details": {
|
|
289
|
+
"get": {
|
|
290
|
+
"tags": [
|
|
291
|
+
"SDK: Organizations"
|
|
292
|
+
],
|
|
293
|
+
"operationId": "get_sdk_flow_result_details",
|
|
294
|
+
"parameters": [
|
|
295
|
+
{
|
|
296
|
+
"name": "sandbox",
|
|
297
|
+
"in": "query",
|
|
298
|
+
"description": "Whether to use sandbox mode",
|
|
299
|
+
"required": false,
|
|
300
|
+
"schema": {
|
|
301
|
+
"type": "boolean",
|
|
302
|
+
"nullable": true
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
"name": "organization_id",
|
|
307
|
+
"in": "path",
|
|
308
|
+
"required": true,
|
|
309
|
+
"schema": {
|
|
310
|
+
"type": "string"
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
"name": "flow_result_id",
|
|
315
|
+
"in": "path",
|
|
316
|
+
"required": true,
|
|
317
|
+
"schema": {
|
|
318
|
+
"type": "string"
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
],
|
|
322
|
+
"responses": {
|
|
323
|
+
"200": {
|
|
324
|
+
"description": "",
|
|
325
|
+
"content": {
|
|
326
|
+
"application/json": {
|
|
327
|
+
"schema": {
|
|
328
|
+
"$ref": "#/components/schemas/FlowResult"
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
"400": {
|
|
334
|
+
"description": "",
|
|
335
|
+
"content": {
|
|
336
|
+
"application/json": {
|
|
337
|
+
"schema": {
|
|
338
|
+
"$ref": "#/components/schemas/BaxeError"
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
"401": {
|
|
344
|
+
"description": "",
|
|
345
|
+
"content": {
|
|
346
|
+
"application/json": {
|
|
347
|
+
"schema": {
|
|
348
|
+
"$ref": "#/components/schemas/BaxeError"
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
"403": {
|
|
354
|
+
"description": "",
|
|
355
|
+
"content": {
|
|
356
|
+
"application/json": {
|
|
357
|
+
"schema": {
|
|
358
|
+
"$ref": "#/components/schemas/BaxeError"
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
"500": {
|
|
364
|
+
"description": "",
|
|
365
|
+
"content": {
|
|
366
|
+
"application/json": {
|
|
367
|
+
"schema": {
|
|
368
|
+
"$ref": "#/components/schemas/BaxeError"
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
"security": [
|
|
375
|
+
{
|
|
376
|
+
"x-api-key": []
|
|
377
|
+
}
|
|
378
|
+
]
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
"/sdk/organizations/{organization_id}/flow-results/{flow_result_id}/dv/{dv_result_id}/details": {
|
|
382
|
+
"get": {
|
|
383
|
+
"tags": [
|
|
384
|
+
"SDK: Organizations"
|
|
385
|
+
],
|
|
386
|
+
"operationId": "get_sdk_dv_result_details",
|
|
387
|
+
"parameters": [
|
|
388
|
+
{
|
|
389
|
+
"name": "sandbox",
|
|
390
|
+
"in": "query",
|
|
391
|
+
"description": "Whether to use sandbox mode",
|
|
392
|
+
"required": false,
|
|
393
|
+
"schema": {
|
|
394
|
+
"type": "boolean",
|
|
395
|
+
"nullable": true
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
"name": "organization_id",
|
|
400
|
+
"in": "path",
|
|
401
|
+
"required": true,
|
|
402
|
+
"schema": {
|
|
403
|
+
"type": "string"
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
"name": "flow_result_id",
|
|
408
|
+
"in": "path",
|
|
409
|
+
"required": true,
|
|
410
|
+
"schema": {
|
|
411
|
+
"type": "string"
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"name": "dv_result_id",
|
|
416
|
+
"in": "path",
|
|
417
|
+
"required": true,
|
|
418
|
+
"schema": {
|
|
419
|
+
"type": "string"
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
],
|
|
423
|
+
"responses": {
|
|
424
|
+
"200": {
|
|
425
|
+
"description": "",
|
|
426
|
+
"content": {
|
|
427
|
+
"application/x-protobuf-stream": {
|
|
428
|
+
"schema": {
|
|
429
|
+
"type": "string"
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
"404": {
|
|
435
|
+
"description": "",
|
|
436
|
+
"content": {
|
|
437
|
+
"application/json": {
|
|
438
|
+
"schema": {
|
|
439
|
+
"$ref": "#/components/schemas/BaxeError"
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
"500": {
|
|
445
|
+
"description": "",
|
|
446
|
+
"content": {
|
|
447
|
+
"application/json": {
|
|
448
|
+
"schema": {
|
|
449
|
+
"$ref": "#/components/schemas/BaxeError"
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
"security": [
|
|
456
|
+
{
|
|
457
|
+
"x-api-key": []
|
|
458
|
+
}
|
|
459
|
+
]
|
|
460
|
+
}
|
|
287
461
|
}
|
|
288
462
|
},
|
|
289
463
|
"components": {
|
|
@@ -1052,6 +1226,7 @@
|
|
|
1052
1226
|
"WRONG_DOCUMENT_TYPE",
|
|
1053
1227
|
"COUNTRY_FILTER",
|
|
1054
1228
|
"FACE_MATCH_CHECK",
|
|
1229
|
+
"FACE_MATCH_CHECK_ONE_CLICK",
|
|
1055
1230
|
"OVERALL_STATUS",
|
|
1056
1231
|
"DOCUMENT_COUNTRY_MISMATCH",
|
|
1057
1232
|
"DOCUMENT_COUNTRY_MISSING",
|
|
@@ -1065,7 +1240,8 @@
|
|
|
1065
1240
|
"DOCUMENT_TYPE_NOT_DEFINED",
|
|
1066
1241
|
"LIVENESS_CHECK_FAILED",
|
|
1067
1242
|
"DOCUMENT_NOT_FOUND",
|
|
1068
|
-
"DATE_OF_BIRTH_BELOW_MINIMUM_AGE"
|
|
1243
|
+
"DATE_OF_BIRTH_BELOW_MINIMUM_AGE",
|
|
1244
|
+
"DOCUMENT_TYPE_CHECK"
|
|
1069
1245
|
]
|
|
1070
1246
|
},
|
|
1071
1247
|
"DvResult": {
|
|
@@ -1258,6 +1434,10 @@
|
|
|
1258
1434
|
"extendedWebhook": {
|
|
1259
1435
|
"type": "boolean"
|
|
1260
1436
|
},
|
|
1437
|
+
"failureUrl": {
|
|
1438
|
+
"type": "string",
|
|
1439
|
+
"nullable": true
|
|
1440
|
+
},
|
|
1261
1441
|
"id": {
|
|
1262
1442
|
"type": "string"
|
|
1263
1443
|
},
|
|
@@ -1408,6 +1588,10 @@
|
|
|
1408
1588
|
"format": "date-time",
|
|
1409
1589
|
"nullable": true
|
|
1410
1590
|
},
|
|
1591
|
+
"failureUrl": {
|
|
1592
|
+
"type": "string",
|
|
1593
|
+
"nullable": true
|
|
1594
|
+
},
|
|
1411
1595
|
"flowId": {
|
|
1412
1596
|
"type": "string"
|
|
1413
1597
|
},
|
|
@@ -1465,6 +1649,10 @@
|
|
|
1465
1649
|
"format": "date-time",
|
|
1466
1650
|
"nullable": true
|
|
1467
1651
|
},
|
|
1652
|
+
"failureUrl": {
|
|
1653
|
+
"type": "string",
|
|
1654
|
+
"nullable": true
|
|
1655
|
+
},
|
|
1468
1656
|
"flowId": {
|
|
1469
1657
|
"type": "string"
|
|
1470
1658
|
},
|
|
@@ -1522,6 +1710,10 @@
|
|
|
1522
1710
|
"format": "date-time",
|
|
1523
1711
|
"nullable": true
|
|
1524
1712
|
},
|
|
1713
|
+
"failureUrl": {
|
|
1714
|
+
"type": "string",
|
|
1715
|
+
"nullable": true
|
|
1716
|
+
},
|
|
1525
1717
|
"flowId": {
|
|
1526
1718
|
"type": "string"
|
|
1527
1719
|
},
|
|
@@ -1579,6 +1771,10 @@
|
|
|
1579
1771
|
"format": "date-time",
|
|
1580
1772
|
"nullable": true
|
|
1581
1773
|
},
|
|
1774
|
+
"failureUrl": {
|
|
1775
|
+
"type": "string",
|
|
1776
|
+
"nullable": true
|
|
1777
|
+
},
|
|
1582
1778
|
"flowId": {
|
|
1583
1779
|
"type": "string"
|
|
1584
1780
|
},
|
|
@@ -1636,6 +1832,10 @@
|
|
|
1636
1832
|
"format": "date-time",
|
|
1637
1833
|
"nullable": true
|
|
1638
1834
|
},
|
|
1835
|
+
"failureUrl": {
|
|
1836
|
+
"type": "string",
|
|
1837
|
+
"nullable": true
|
|
1838
|
+
},
|
|
1639
1839
|
"flowId": {
|
|
1640
1840
|
"type": "string"
|
|
1641
1841
|
},
|
|
@@ -2582,7 +2782,9 @@
|
|
|
2582
2782
|
"KYC",
|
|
2583
2783
|
"KYB",
|
|
2584
2784
|
"PRODUCTION_MODE",
|
|
2585
|
-
"SPID"
|
|
2785
|
+
"SPID",
|
|
2786
|
+
"EXPORT_API",
|
|
2787
|
+
"EXPORT_UI"
|
|
2586
2788
|
]
|
|
2587
2789
|
},
|
|
2588
2790
|
"ResultStatus": {
|
|
@@ -3085,7 +3287,10 @@
|
|
|
3085
3287
|
},
|
|
3086
3288
|
"tags": [
|
|
3087
3289
|
{
|
|
3088
|
-
"name": "SDK"
|
|
3290
|
+
"name": "SDK: Verification Requests"
|
|
3291
|
+
},
|
|
3292
|
+
{
|
|
3293
|
+
"name": "SDK: Organizations"
|
|
3089
3294
|
},
|
|
3090
3295
|
{
|
|
3091
3296
|
"name": "API Keys"
|
package/package.json
CHANGED
|
@@ -1,34 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyphe-sdk/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
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
|
-
"main": "dist/index.
|
|
10
|
-
"module": "dist/index.js",
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
12
17
|
"exports": {
|
|
13
18
|
".": {
|
|
14
19
|
"types": "./dist/index.d.ts",
|
|
15
|
-
"
|
|
20
|
+
"default": "./dist/index.js"
|
|
16
21
|
},
|
|
17
22
|
"./openapi": {
|
|
18
23
|
"types": "./dist/openapi.d.ts",
|
|
19
24
|
"default": "./dist/openapi.json"
|
|
20
25
|
}
|
|
21
26
|
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@bufbuild/protobuf": "^2.6.1",
|
|
29
|
+
"openapi-fetch": "^0.14.0"
|
|
30
|
+
},
|
|
22
31
|
"scripts": {
|
|
32
|
+
"\n============== Dev ===============": "",
|
|
23
33
|
"dev": "tsup --watch",
|
|
24
34
|
"build": "tsup",
|
|
25
35
|
"\n============== Gen ===============": "",
|
|
26
36
|
"gen": "pnpm run '/^gen:.*/'",
|
|
27
37
|
"gen:openapi": "tsx scripts/generate-openapi.ts",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
38
|
+
"gen:proto": "bash scripts/generate-proto.sh",
|
|
39
|
+
"\n============== Lint ==============": "",
|
|
40
|
+
"lint": "pnpm run '/^lint:.*/'",
|
|
41
|
+
"lint:tsc": "tsc --noEmit",
|
|
42
|
+
"\n============== Test ==============": "",
|
|
43
|
+
"check-exports": "attw --profile esm-only --pack ."
|
|
33
44
|
}
|
|
34
|
-
}
|
|
45
|
+
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @zyphe-sdk/core@0.1.13 build /Users/mtumiati/dev/zyphe/zyphe-sdk/packages/core
|
|
4
|
-
> tsup
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
7
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
-
[34mCLI[39m tsup v8.5.0
|
|
9
|
-
[34mCLI[39m Using tsup config: /Users/mtumiati/dev/zyphe/zyphe-sdk/packages/core/tsup.config.ts
|
|
10
|
-
[34mCLI[39m Target: es2023
|
|
11
|
-
[34mESM[39m Build start
|
|
12
|
-
[32mESM[39m [1mdist/index.js [22m[32m4.31 KB[39m
|
|
13
|
-
[32mESM[39m [1mdist/index.js.map [22m[32m9.62 KB[39m
|
|
14
|
-
[32mESM[39m ⚡️ Build success in 9ms
|
|
15
|
-
DTS Build start
|
|
16
|
-
DTS ⚡️ Build success in 872ms
|
|
17
|
-
DTS dist/index.d.ts 62.09 KB
|
package/dist/index.cjs
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
API_KEY_HEADER: () => API_KEY_HEADER,
|
|
34
|
-
EnvironmentConfigs: () => EnvironmentConfigs,
|
|
35
|
-
Environments: () => Environments,
|
|
36
|
-
WebhookSignatureErrorCodes: () => WebhookSignatureErrorCodes,
|
|
37
|
-
WebhookSignatureErrorMessages: () => WebhookSignatureErrorMessages,
|
|
38
|
-
bufferToHex: () => bufferToHex,
|
|
39
|
-
constructVerificationSessionUrl: () => constructVerificationSessionUrl,
|
|
40
|
-
createVerificationSession: () => createVerificationSession,
|
|
41
|
-
hexToBytes: () => hexToBytes,
|
|
42
|
-
parseSignatureHeader: () => parseSignatureHeader,
|
|
43
|
-
timingSafeEqual: () => timingSafeEqual
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(index_exports);
|
|
46
|
-
|
|
47
|
-
// src/constants.ts
|
|
48
|
-
var Environments = {
|
|
49
|
-
LOCAL: "local",
|
|
50
|
-
STAGING: "staging",
|
|
51
|
-
PRODUCTION: "production"
|
|
52
|
-
};
|
|
53
|
-
var EnvironmentConfigs = {
|
|
54
|
-
[Environments.LOCAL]: {
|
|
55
|
-
appUrl: "http://localhost:5173",
|
|
56
|
-
apiUrl: "http://localhost:3000"
|
|
57
|
-
},
|
|
58
|
-
[Environments.STAGING]: {
|
|
59
|
-
appUrl: "https://app-dev.zyphe.com",
|
|
60
|
-
apiUrl: "https://api-dev.zyphe.com"
|
|
61
|
-
},
|
|
62
|
-
[Environments.PRODUCTION]: {
|
|
63
|
-
appUrl: "https://verify.zyphe.com",
|
|
64
|
-
apiUrl: "https://api.zyphe.com"
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var API_KEY_HEADER = "x-api-key";
|
|
68
|
-
|
|
69
|
-
// src/client.ts
|
|
70
|
-
var import_openapi_fetch = __toESM(require("openapi-fetch"), 1);
|
|
71
|
-
var zypheApiClient = (opts) => {
|
|
72
|
-
return (0, import_openapi_fetch.default)({
|
|
73
|
-
baseUrl: EnvironmentConfigs[opts.environment].apiUrl
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/verification-session.ts
|
|
78
|
-
function createVerificationSession({
|
|
79
|
-
email,
|
|
80
|
-
flowId,
|
|
81
|
-
flowStepId,
|
|
82
|
-
isSandbox,
|
|
83
|
-
customData
|
|
84
|
-
}, opts) {
|
|
85
|
-
const client = zypheApiClient(opts);
|
|
86
|
-
return client.POST("/sdk/flow/{flow_id}/vr/create", {
|
|
87
|
-
body: { email, flowStepId, customData },
|
|
88
|
-
headers: {
|
|
89
|
-
[API_KEY_HEADER]: opts.apiKey
|
|
90
|
-
},
|
|
91
|
-
params: {
|
|
92
|
-
path: {
|
|
93
|
-
flow_id: flowId
|
|
94
|
-
},
|
|
95
|
-
query: {
|
|
96
|
-
sandbox: isSandbox
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
function getFlowUrlOrigin(environment) {
|
|
102
|
-
switch (environment) {
|
|
103
|
-
case Environments.LOCAL:
|
|
104
|
-
return EnvironmentConfigs[Environments.LOCAL].appUrl;
|
|
105
|
-
case Environments.STAGING:
|
|
106
|
-
return EnvironmentConfigs[Environments.STAGING].appUrl;
|
|
107
|
-
case Environments.PRODUCTION:
|
|
108
|
-
return EnvironmentConfigs[Environments.PRODUCTION].appUrl;
|
|
109
|
-
default:
|
|
110
|
-
throw new Error(`Invalid environment: ${environment}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function constructVerificationSessionUrl({
|
|
114
|
-
flowParams,
|
|
115
|
-
verificationSession,
|
|
116
|
-
opts
|
|
117
|
-
}) {
|
|
118
|
-
const origin = getFlowUrlOrigin(opts.environment);
|
|
119
|
-
const { isSandbox, product } = flowParams;
|
|
120
|
-
const { handoffBaseUrl, primaryColor, secondaryColor, isFullscreen } = opts;
|
|
121
|
-
if (!verificationSession) {
|
|
122
|
-
throw new Error("Failed to create verification session");
|
|
123
|
-
}
|
|
124
|
-
let baseUrl = `${origin}${isSandbox ? "/sandbox" : ""}/flow/${verificationSession.flowSlug}/${product}/${verificationSession.flowStepSlug}?zypheVr=${encodeURIComponent(verificationSession.verificationRequest.id)}&zypheEmail=${encodeURIComponent(verificationSession.email)}&zypheToken=${encodeURIComponent(verificationSession.zypheToken)}`;
|
|
125
|
-
if (handoffBaseUrl) {
|
|
126
|
-
baseUrl += `&zypheHandoffBaseUrl=${encodeURIComponent(handoffBaseUrl)}`;
|
|
127
|
-
}
|
|
128
|
-
if (primaryColor) {
|
|
129
|
-
baseUrl += `&zyphePrimaryColor=${encodeURIComponent(primaryColor)}`;
|
|
130
|
-
}
|
|
131
|
-
if (secondaryColor) {
|
|
132
|
-
baseUrl += `&zypheSecondaryColor=${encodeURIComponent(secondaryColor)}`;
|
|
133
|
-
}
|
|
134
|
-
if (isFullscreen) {
|
|
135
|
-
baseUrl += `&zypheFullscreen=${encodeURIComponent(isFullscreen)}`;
|
|
136
|
-
}
|
|
137
|
-
return baseUrl;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// src/webhook.ts
|
|
141
|
-
function parseSignatureHeader(signatureHeader) {
|
|
142
|
-
const match = signatureHeader.match(/^t=(\d+),v0=([a-fA-F0-9]+)$/);
|
|
143
|
-
if (!match) {
|
|
144
|
-
throw new Error("Invalid signature header format");
|
|
145
|
-
}
|
|
146
|
-
const [, timestamp, signatureHex] = match;
|
|
147
|
-
if (!timestamp || !signatureHex) {
|
|
148
|
-
throw new Error("Invalid signature header format");
|
|
149
|
-
}
|
|
150
|
-
return { timestamp, signatureHex };
|
|
151
|
-
}
|
|
152
|
-
function hexToBytes(hex) {
|
|
153
|
-
if (hex.length % 2 !== 0) throw new Error("Invalid hex string");
|
|
154
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
155
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
156
|
-
bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
157
|
-
}
|
|
158
|
-
return bytes;
|
|
159
|
-
}
|
|
160
|
-
function bufferToHex(buffer) {
|
|
161
|
-
return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
162
|
-
}
|
|
163
|
-
function timingSafeEqual(a, b) {
|
|
164
|
-
if (a.length !== b.length) return false;
|
|
165
|
-
let result = 0;
|
|
166
|
-
for (let i = 0; i < a.length; i++) {
|
|
167
|
-
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
168
|
-
}
|
|
169
|
-
return result === 0;
|
|
170
|
-
}
|
|
171
|
-
var WebhookSignatureErrorCodes = {
|
|
172
|
-
MISSING_SIGNATURE_HEADER: 1,
|
|
173
|
-
INVALID_SIGNATURE_HEADER: 2,
|
|
174
|
-
SIGNATURE_MISMATCH: 3
|
|
175
|
-
};
|
|
176
|
-
var WebhookSignatureErrorMessages = {
|
|
177
|
-
[WebhookSignatureErrorCodes.MISSING_SIGNATURE_HEADER]: "Missing signature header",
|
|
178
|
-
[WebhookSignatureErrorCodes.INVALID_SIGNATURE_HEADER]: "Invalid signature header",
|
|
179
|
-
[WebhookSignatureErrorCodes.SIGNATURE_MISMATCH]: "Signature mismatch"
|
|
180
|
-
};
|
|
181
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,SAAoB;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,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,QACJ,SAAS;AAAA,MACX;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF,CAAC;AACH;A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