@kwik-id/sdk-node 0.1.0-alpha.7 → 0.1.0-alpha.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.
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("crypto"),w="https://api.kwik-id.com",y=3e4;class g{apiKey;baseUrl;timeout;constructor(e){if(!e.apiKey)throw new Error("KwikIDNode: apiKey is required");this.apiKey=e.apiKey,this.baseUrl=(e.baseUrl??w).replace(/\/$/,""),this.timeout=e.timeout??y}async createSession(e={}){return this.request("POST","/api/v1/sessions",e)}async getSession(e){const r=await this.request("GET",`/api/v1/sessions/${e}`);if(r.error)throw new Error(`KwikIDNode: getSession failed — ${r.error.message??r.error.code}`);return r}async listVerifications(e={}){const r=new URLSearchParams;e.status&&r.set("status",e.status),e.referenceId&&r.set("referenceId",e.referenceId),e.page!=null&&r.set("page",String(e.page)),e.limit!=null&&r.set("limit",String(e.limit)),e.sortBy&&r.set("sortBy",e.sortBy),e.sortOrder&&r.set("sortOrder",e.sortOrder);const s=r.toString();return this.request("GET",`/api/v1/verifications${s?`?${s}`:""}`)}async getVerification(e){const r=await this.request("GET",`/api/v1/verifications/${e}`);if(r.error)throw new Error(`KwikIDNode: getVerification failed — ${r.error.message}`);return r}async getVerificationByReference(e){const r=await this.request("GET",`/api/v1/verifications/reference/${encodeURIComponent(e)}`);if(r.error)throw new Error(`KwikIDNode: getVerificationByReference failed — ${r.error.message}`);return r}async getVerificationResult(e){const r=await this.request("GET",`/api/v1/verifications/${e}/result`);if(r.error)throw new Error(`KwikIDNode: getVerificationResult failed — ${r.error.message}`);return r}async request(e,r,s){const c=`${this.baseUrl}${r}`,a=new AbortController,n=setTimeout(()=>a.abort(),this.timeout);let i;try{i=await fetch(c,{method:e,headers:{"Content-Type":"application/json","X-API-Key":this.apiKey},body:s!==void 0?JSON.stringify(s):void 0,signal:a.signal})}catch(t){throw t.name==="AbortError"?new Error(`KwikIDNode: request timed out after ${this.timeout}ms`):t}finally{clearTimeout(n)}if(!i.ok){let t=`HTTP ${i.status}`;try{const f=await i.json();t=f.message??f.error??t}catch{}throw new Error(`KwikIDNode: ${e} ${r} failed — ${t}`)}return i.json()}}function p(u){const{payload:e,signature:r,secret:s,toleranceSeconds:c=300}=u,a={};for(const o of r.split(",")){const l=o.indexOf("=");l!==-1&&(a[o.slice(0,l)]=o.slice(l+1))}const n=a.t,i=a.v1;if(!n||!i)return{valid:!1,error:"Invalid signature format"};const t=parseInt(n,10);if(isNaN(t))return{valid:!1,error:"Invalid timestamp in signature"};if(c>0){const o=Math.floor(Date.now()/1e3);if(Math.abs(o-t)>c)return{valid:!1,error:"Timestamp too old"}}const f=`${n}.${e}`,h=m.createHmac("sha256",s).update(f).digest("hex");let d;try{d=m.timingSafeEqual(Buffer.from(h,"hex"),Buffer.from(i,"hex"))}catch{return{valid:!1,error:"Signature comparison failed"}}if(!d)return{valid:!1,error:"Signature mismatch"};try{return{valid:!0,event:JSON.parse(e)}}catch{return{valid:!1,error:"Failed to parse payload as JSON"}}}exports.KwikIDNode=g;exports.verifyWebhookSignature=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("crypto"),g="https://api.identity.staging.kwiknkap.com",w=3e4;class y{apiKey;baseUrl;timeout;constructor(e){if(!e.apiKey)throw new Error("KwikIDNode: apiKey is required");this.apiKey=e.apiKey,this.baseUrl=(e.baseUrl??g).replace(/\/$/,""),this.timeout=e.timeout??w}async createSession(e={}){return this.request("POST","/api/v1/sessions",e)}async getSession(e){const r=await this.request("GET",`/api/v1/sessions/${e}`);if(r.error)throw new Error(`KwikIDNode: getSession failed — ${r.error.message??r.error.code}`);return r}async listVerifications(e={}){const r=new URLSearchParams;e.status&&r.set("status",e.status),e.referenceId&&r.set("referenceId",e.referenceId),e.page!=null&&r.set("page",String(e.page)),e.limit!=null&&r.set("limit",String(e.limit)),e.sortBy&&r.set("sortBy",e.sortBy),e.sortOrder&&r.set("sortOrder",e.sortOrder);const s=r.toString();return this.request("GET",`/api/v1/verifications${s?`?${s}`:""}`)}async getVerification(e){const r=await this.request("GET",`/api/v1/verifications/${e}`);if(r.error)throw new Error(`KwikIDNode: getVerification failed — ${r.error.message}`);return r}async getVerificationByReference(e){const r=await this.request("GET",`/api/v1/verifications/reference/${encodeURIComponent(e)}`);if(r.error)throw new Error(`KwikIDNode: getVerificationByReference failed — ${r.error.message}`);return r}async getVerificationResult(e){const r=await this.request("GET",`/api/v1/verifications/${e}/result`);if(r.error)throw new Error(`KwikIDNode: getVerificationResult failed — ${r.error.message}`);return r}async request(e,r,s){const c=`${this.baseUrl}${r}`,a=new AbortController,n=setTimeout(()=>a.abort(),this.timeout);let i;try{i=await fetch(c,{method:e,headers:{"Content-Type":"application/json","X-API-Key":this.apiKey},body:s!==void 0?JSON.stringify(s):void 0,signal:a.signal})}catch(t){throw t.name==="AbortError"?new Error(`KwikIDNode: request timed out after ${this.timeout}ms`):t}finally{clearTimeout(n)}if(!i.ok){let t=`HTTP ${i.status}`;try{const f=await i.json();t=f.message??f.error??t}catch{}throw new Error(`KwikIDNode: ${e} ${r} failed — ${t}`)}return i.json()}}function p(u){const{payload:e,signature:r,secret:s,toleranceSeconds:c=300}=u,a={};for(const o of r.split(",")){const l=o.indexOf("=");l!==-1&&(a[o.slice(0,l)]=o.slice(l+1))}const n=a.t,i=a.v1;if(!n||!i)return{valid:!1,error:"Invalid signature format"};const t=parseInt(n,10);if(isNaN(t))return{valid:!1,error:"Invalid timestamp in signature"};if(c>0){const o=Math.floor(Date.now()/1e3);if(Math.abs(o-t)>c)return{valid:!1,error:"Timestamp too old"}}const f=`${n}.${e}`,h=m.createHmac("sha256",s).update(f).digest("hex");let d;try{d=m.timingSafeEqual(Buffer.from(h,"hex"),Buffer.from(i,"hex"))}catch{return{valid:!1,error:"Signature comparison failed"}}if(!d)return{valid:!1,error:"Signature mismatch"};try{return{valid:!0,event:JSON.parse(e)}}catch{return{valid:!1,error:"Failed to parse payload as JSON"}}}exports.KwikIDNode=y;exports.verifyWebhookSignature=p;
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createHmac as h, timingSafeEqual as w } from "crypto";
2
- const g = "https://api.kwik-id.com", y = 3e4;
2
+ const g = "https://api.identity.staging.kwiknkap.com", y = 3e4;
3
3
  class v {
4
4
  apiKey;
5
5
  baseUrl;
@@ -14,12 +14,11 @@ class v {
14
14
  return this.request("POST", "/api/v1/sessions", e);
15
15
  }
16
16
  async getSession(e) {
17
- const r = await this.request(
18
- "GET",
19
- `/api/v1/sessions/${e}`
20
- );
17
+ const r = await this.request("GET", `/api/v1/sessions/${e}`);
21
18
  if (r.error)
22
- throw new Error(`KwikIDNode: getSession failed — ${r.error.message ?? r.error.code}`);
19
+ throw new Error(
20
+ `KwikIDNode: getSession failed — ${r.error.message ?? r.error.code}`
21
+ );
23
22
  return r;
24
23
  }
25
24
  // ─── Verifications ───────────────────────────────────────────────────────
@@ -30,28 +29,21 @@ class v {
30
29
  return this.request("GET", `/api/v1/verifications${s ? `?${s}` : ""}`);
31
30
  }
32
31
  async getVerification(e) {
33
- const r = await this.request(
34
- "GET",
35
- `/api/v1/verifications/${e}`
36
- );
32
+ const r = await this.request("GET", `/api/v1/verifications/${e}`);
37
33
  if (r.error)
38
34
  throw new Error(`KwikIDNode: getVerification failed — ${r.error.message}`);
39
35
  return r;
40
36
  }
41
37
  async getVerificationByReference(e) {
42
- const r = await this.request(
43
- "GET",
44
- `/api/v1/verifications/reference/${encodeURIComponent(e)}`
45
- );
38
+ const r = await this.request("GET", `/api/v1/verifications/reference/${encodeURIComponent(e)}`);
46
39
  if (r.error)
47
- throw new Error(`KwikIDNode: getVerificationByReference failed — ${r.error.message}`);
40
+ throw new Error(
41
+ `KwikIDNode: getVerificationByReference failed — ${r.error.message}`
42
+ );
48
43
  return r;
49
44
  }
50
45
  async getVerificationResult(e) {
51
- const r = await this.request(
52
- "GET",
53
- `/api/v1/verifications/${e}/result`
54
- );
46
+ const r = await this.request("GET", `/api/v1/verifications/${e}/result`);
55
47
  if (r.error)
56
48
  throw new Error(`KwikIDNode: getVerificationResult failed — ${r.error.message}`);
57
49
  return r;
@@ -1,4 +1,4 @@
1
- import { KwikIDNodeConfig, CreateSessionOptions, SessionToken, SessionDetails, Verification, VerificationResult, ListVerificationsOptions, VerificationList } from '../types/index.js';
1
+ import { CreateSessionOptions, KwikIDNodeConfig, ListVerificationsOptions, SessionDetails, SessionToken, Verification, VerificationList, VerificationResult } from '../types/index.js';
2
2
  export declare class KwikIDNode {
3
3
  private readonly apiKey;
4
4
  private readonly baseUrl;
@@ -1 +1 @@
1
- {"version":3,"file":"kwik-node-sdk.d.ts","sourceRoot":"","sources":["../../src/lib/kwik-node-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAK3B,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,gBAAgB;IAW9B,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,YAAY,CAAC;IAIxE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAatD,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAapF,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAWlD,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAWtE,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;YAatD,OAAO;CAsCtB"}
1
+ {"version":3,"file":"kwik-node-sdk.d.ts","sourceRoot":"","sources":["../../src/lib/kwik-node-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACrB,MAAM,mBAAmB,CAAC;AAU3B,qBAAa,UAAU;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,gBAAgB;IAW9B,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,YAAY,CAAC;IAIxE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IActD,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAapF,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAUlD,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAYtE,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;YAYtD,OAAO;CAsCxB"}
package/package.json CHANGED
@@ -1,28 +1,34 @@
1
1
  {
2
- "name": "@kwik-id/sdk-node",
3
- "version": "0.1.0-alpha.7",
4
- "type": "module",
5
- "engines": {
6
- "node": ">=18"
7
- },
8
- "main": "./dist/index.cjs.js",
9
- "module": "./dist/index.es.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- "./package.json": "./package.json",
13
- ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.es.js",
16
- "require": "./dist/index.cjs.js",
17
- "default": "./dist/index.es.js"
18
- }
19
- },
20
- "files": [
21
- "dist",
22
- "!**/*.tsbuildinfo"
23
- ],
24
- "nx": {
25
- "name": "sdk-node"
26
- },
27
- "dependencies": {}
28
- }
2
+ "name": "@kwik-id/sdk-node",
3
+ "version": "0.1.0-alpha.8",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
8
+ "main": "./dist/index.cjs.js",
9
+ "module": "./dist/index.es.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ "./package.json": "./package.json",
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.es.js",
16
+ "require": "./dist/index.cjs.js",
17
+ "default": "./dist/index.es.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "!**/*.tsbuildinfo"
23
+ ],
24
+ "scripts": {
25
+ "build": "vite build",
26
+ "build:staging": "KWIK_API_URL=https://api.identity.staging.kwiknkap.com vite build",
27
+ "publish:latest": "npm run build && npm publish --access public",
28
+ "publish:alpha": "npm run build:staging && npm publish --tag alpha --access public"
29
+ },
30
+ "nx": {
31
+ "name": "sdk-node"
32
+ },
33
+ "dependencies": {}
34
+ }
package/dist/package.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "name": "@kwik-id/sdk-node",
3
- "version": "0.1.0-alpha.7",
4
- "type": "module",
5
- "engines": {
6
- "node": ">=18"
7
- },
8
- "main": "./dist/index.cjs.js",
9
- "module": "./dist/index.es.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- "./package.json": "./package.json",
13
- ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.es.js",
16
- "require": "./dist/index.cjs.js",
17
- "default": "./dist/index.es.js"
18
- }
19
- },
20
- "files": [
21
- "dist",
22
- "!**/*.tsbuildinfo"
23
- ],
24
- "nx": {
25
- "name": "sdk-node"
26
- },
27
- "dependencies": {}
28
- }