@identomic/server 0.0.0-stage → 0.1.1

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.
Files changed (4) hide show
  1. package/README.md +72 -2
  2. package/index.cjs +131 -0
  3. package/index.d.cts +50 -0
  4. package/package.json +25 -4
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # Identomic Server SDK
2
+
3
+ Authorize identity capture sessions and report their outcomes from your Node.js backend. Use the results with the Identomic iOS, Android, or Expo SDK.
4
+
5
+ [SDK documentation](https://identomic.com/docs/server/) · [HTTP API reference](https://identomic.com/docs/api/) · [Contact sales](https://identomic.com/contact/)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm i @identomic/server
11
+ ```
12
+
13
+ Requires Node.js 22 or later. Supports ES modules, CommonJS, and TypeScript.
14
+
15
+ ## Initialize
16
+
17
+ ```ts
18
+ import { IdentomicServer } from "@identomic/server";
19
+
20
+ const secretKey = process.env.IDENTOMIC_SECRET_KEY;
21
+ if (!secretKey) throw new Error("Missing IDENTOMIC_SECRET_KEY");
22
+
23
+ const identomic = new IdentomicServer({
24
+ baseUrl: "https://api.identomic.com",
25
+ secretKey: secretKey,
26
+ });
27
+ ```
28
+
29
+ `baseUrl` accepts the Identomic HTTPS origin or the full URL ending in `/api/v1/sdk`. The SDK refuses redirects and defaults to a 15-second timeout. Set `timeoutMs` to override it.
30
+
31
+ Store `IDENTOMIC_SECRET_KEY` in your server environment. Use a key with the required **Authorize sessions** or **Report outcomes** scope. Initialize a separate client for each environment or organization your backend serves.
32
+
33
+ ## Create a capture session
34
+
35
+ After authenticating your app user and confirming that they may start the operation, call the SDK from your own backend route.
36
+
37
+ ```ts
38
+ const session = await identomic.sessions.create({
39
+ module: "fingerprints",
40
+ idempotencyKey: captureAttemptId,
41
+ });
42
+
43
+ // Return the session token (plus expiry if useful) to the authorized caller.
44
+ return { sessionToken: session.sessionToken, expiresAt: session.expiresAt };
45
+ ```
46
+
47
+ `captureAttemptId` identifies one intentional capture. Use a distinct ID for each new capture and keep the same value for any retry, including after a timeout. This keeps usage to one transaction per successful authorization. For a multi-user backend, derive or store the ID under your authenticated user's capture request so they can only retry their own operation.
48
+
49
+ | Operation | Module |
50
+ | --- | --- |
51
+ | Four-finger capture | `fingerprints` |
52
+ | Face photo | `face_capture` |
53
+ | Live selfie | `face_liveness` |
54
+ | Face comparison | `face_comparison` |
55
+ | Passport page | `passport_photo` |
56
+ | Passport NFC | `passport_nfc` |
57
+ | TD1 ID card capture | `id_card_capture` |
58
+
59
+ The mobile app initializes with the matching publishable key, calls your authenticated endpoint to get a token, and passes it to the native capture function. For example, Expo can call `captureFingerprints(sessionToken)` after requesting the session. The token normally expires after five minutes and can be claimed once. The backend keeps the `sessionId` for reporting and does not log tokens, secrets, or biometric data.
60
+
61
+ ## Report an outcome
62
+
63
+ ```ts
64
+ await identomic.sessions.reportOutcome({
65
+ sessionId,
66
+ outcome: "completed",
67
+ });
68
+ ```
69
+
70
+ Supported outcomes are `completed`, `cancelled`, and `failed`. Store the session ID with your own request and verify ownership before accepting outcome reports from the mobile app. Reporting the same outcome twice is safe. A conflicting outcome returns an error.
71
+
72
+ Catch `IdentomicAPIError` to inspect `error.code` and `error.status`. Examples include `QUOTA_EXHAUSTED`, `MODULE_DISABLED`, and `IDEMPOTENCY_CONFLICT`. Local validation errors are `TypeError`. The client does not automatically retry. Retry uncertain authorizations using the original idempotency key.
2
73
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
package/index.cjs ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ const secretPattern = /^id_sk_(sandbox|production)_[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}_[A-Za-z0-9_-]{43}$/;
4
+ const idempotencyPattern = /^[A-Za-z0-9._:-]{1,128}$/;
5
+ const uuidPattern = /^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i;
6
+ const modules = new Set(["fingerprints", "face_capture", "face_liveness", "face_comparison", "passport_photo", "passport_nfc", "id_card_capture"]);
7
+ const outcomes = new Set(["completed", "cancelled", "failed"]);
8
+ const loopback = new Set(["localhost", "127.0.0.1", "[::1]"]);
9
+ const apiPath = "/api/v1/sdk";
10
+
11
+ // Keep upstream response bodies and connection errors out of messages that may be logged.
12
+ class IdentomicAPIError extends Error {
13
+ constructor(code, status) {
14
+ super("Identomic request failed: " + code);
15
+ this.name = "IdentomicAPIError";
16
+ this.code = code;
17
+ this.status = status;
18
+ }
19
+ }
20
+
21
+ function normalizeBaseUrl(baseUrl) {
22
+ let url;
23
+ try { url = new URL(baseUrl); } catch { throw new TypeError("baseUrl must be an absolute Identomic API URL"); }
24
+ if (url.username || url.password || url.href.includes("?") || url.href.includes("#") ||
25
+ (url.protocol !== "https:" && !(url.protocol === "http:" && loopback.has(url.hostname)))) {
26
+ throw new TypeError("baseUrl must use HTTPS, or HTTP on loopback for local development");
27
+ }
28
+ const pathname = url.pathname.replace(/\/$/, "");
29
+ if (pathname !== "" && pathname !== apiPath) {
30
+ throw new TypeError("baseUrl must be the Identomic origin or its /api/v1/sdk URL");
31
+ }
32
+ return url.origin + apiPath;
33
+ }
34
+
35
+ class IdentomicServer {
36
+ #baseUrl;
37
+ #secretKey;
38
+ #timeoutMs;
39
+
40
+ constructor({ baseUrl, secretKey, timeoutMs = 15_000 }) {
41
+ this.#baseUrl = normalizeBaseUrl(baseUrl);
42
+ if (typeof secretKey !== "string" || !secretPattern.test(secretKey)) {
43
+ throw new TypeError("secretKey must be an Identomic server-side secret key");
44
+ }
45
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 120_000) {
46
+ throw new TypeError("timeoutMs must be an integer between 1 and 120000");
47
+ }
48
+ this.#secretKey = secretKey;
49
+ this.#timeoutMs = timeoutMs;
50
+ this.sessions = Object.freeze({
51
+ create: (input) => this.#createSession(input),
52
+ reportOutcome: (input) => this.#reportOutcome(input),
53
+ });
54
+ }
55
+
56
+ async getSandboxKeyPair() {
57
+ const { data, status } = await this.#request("/sandbox/key-pair", {});
58
+ if (data?.environment !== "sandbox" || typeof data.project !== "string" || !uuidPattern.test(data.project) ||
59
+ typeof data.publishableKey !== "string" || !/^id_pk_sandbox_[A-Za-z0-9_-]{43}$/.test(data.publishableKey)) {
60
+ throw new IdentomicAPIError("INVALID_RESPONSE", status);
61
+ }
62
+ return { publishableKey: data.publishableKey, project: data.project, environment: "sandbox" };
63
+ }
64
+
65
+ async #request(path, body) {
66
+ const signal = AbortSignal.timeout(this.#timeoutMs);
67
+ let response;
68
+ try {
69
+ response = await fetch(this.#baseUrl + path, {
70
+ method: "POST",
71
+ headers: {
72
+ "Authorization": "Bearer " + this.#secretKey,
73
+ "Content-Type": "application/json",
74
+ "Accept": "application/json",
75
+ },
76
+ body: JSON.stringify(body),
77
+ redirect: "manual",
78
+ signal,
79
+ });
80
+ } catch {
81
+ throw new IdentomicAPIError(signal.aborted ? "REQUEST_TIMEOUT" : "NETWORK_ERROR");
82
+ }
83
+
84
+ if (response.status >= 300 && response.status < 400) {
85
+ await response.body?.cancel().catch(() => {});
86
+ throw new IdentomicAPIError("UNEXPECTED_REDIRECT", response.status);
87
+ }
88
+ let data;
89
+ try {
90
+ data = await response.json();
91
+ } catch {
92
+ if (signal.aborted) throw new IdentomicAPIError("REQUEST_TIMEOUT", response.status);
93
+ if (response.ok) throw new IdentomicAPIError("INVALID_RESPONSE", response.status);
94
+ }
95
+ if (!response.ok) {
96
+ const code = typeof data?.error === "string" && /^[A-Z0-9_]{1,64}$/.test(data.error)
97
+ ? data.error : "HTTP_ERROR";
98
+ throw new IdentomicAPIError(code, response.status);
99
+ }
100
+ return { data, status: response.status };
101
+ }
102
+
103
+ async #createSession({ module, idempotencyKey }) {
104
+ if (!modules.has(module)) throw new TypeError("Unsupported Identomic module");
105
+ if (typeof idempotencyKey !== "string" || !idempotencyPattern.test(idempotencyKey)) {
106
+ throw new TypeError("Provide a valid idempotency key and reuse it when retrying the same capture");
107
+ }
108
+ const { data, status } = await this.#request("/sessions", { module, idempotencyKey });
109
+ if (typeof data?.sessionId !== "string" || !uuidPattern.test(data.sessionId) ||
110
+ typeof data.sessionToken !== "string" || !data.sessionToken ||
111
+ typeof data.expiresAt !== "string" || !Number.isFinite(Date.parse(data.expiresAt))) {
112
+ throw new IdentomicAPIError("INVALID_RESPONSE", status);
113
+ }
114
+ return { sessionId: data.sessionId, sessionToken: data.sessionToken, expiresAt: data.expiresAt };
115
+ }
116
+
117
+ async #reportOutcome({ sessionId, outcome }) {
118
+ if (typeof sessionId !== "string" || !uuidPattern.test(sessionId)) {
119
+ throw new TypeError("sessionId must be the UUID returned by sessions.create");
120
+ }
121
+ if (!outcomes.has(outcome)) throw new TypeError("Unsupported Identomic outcome");
122
+ const { data, status } = await this.#request("/outcomes", { sessionId, outcome });
123
+ if (data?.sessionId !== sessionId || data?.outcome !== outcome) {
124
+ throw new IdentomicAPIError("INVALID_RESPONSE", status);
125
+ }
126
+ return { sessionId, outcome };
127
+ }
128
+ }
129
+
130
+ exports.IdentomicServer = IdentomicServer;
131
+ exports.IdentomicAPIError = IdentomicAPIError;
package/index.d.cts ADDED
@@ -0,0 +1,50 @@
1
+ export type CaptureModule =
2
+ | "fingerprints"
3
+ | "face_capture"
4
+ | "face_liveness"
5
+ | "face_comparison"
6
+ | "passport_photo"
7
+ | "passport_nfc"
8
+ | "id_card_capture";
9
+
10
+ export type CaptureOutcome = "completed" | "cancelled" | "failed";
11
+
12
+ export interface IdentomicServerOptions {
13
+ /** HTTPS origin or /api/v1/sdk URL. HTTP is allowed on loopback for development. */
14
+ baseUrl: string;
15
+ /** Identomic secret key. Keep it in your backend environment. */
16
+ secretKey: string;
17
+ /** Request timeout in milliseconds. Defaults to 15000. */
18
+ timeoutMs?: number;
19
+ }
20
+
21
+ export interface CreateSessionInput {
22
+ module: CaptureModule;
23
+ idempotencyKey: string;
24
+ }
25
+
26
+ export interface CaptureSession {
27
+ sessionId: string;
28
+ sessionToken: string;
29
+ expiresAt: string;
30
+ }
31
+
32
+ export interface SessionOutcome {
33
+ sessionId: string;
34
+ outcome: CaptureOutcome;
35
+ }
36
+
37
+ export declare class IdentomicAPIError extends Error {
38
+ constructor(code: string, status?: number);
39
+ readonly code: string;
40
+ readonly status: number | undefined;
41
+ }
42
+
43
+ export declare class IdentomicServer {
44
+ constructor(options: IdentomicServerOptions);
45
+ getSandboxKeyPair(): Promise<{ publishableKey: string; project: string; environment: "sandbox" }>;
46
+ readonly sessions: Readonly<{
47
+ create(input: CreateSessionInput): Promise<CaptureSession>;
48
+ reportOutcome(input: SessionOutcome): Promise<SessionOutcome>;
49
+ }>;
50
+ }
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@identomic/server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Node.js server SDK for Identomic capture sessions",
5
+ "license": "UNLICENSED",
6
+ "type": "commonjs",
7
+ "main": "./index.cjs",
8
+ "types": "./index.d.cts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.cts",
12
+ "default": "./index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "index.cjs",
17
+ "index.d.cts",
18
+ "README.md"
19
+ ],
20
+ "engines": {
21
+ "node": ">=22"
22
+ },
23
+ "scripts": {
24
+ "test": "node --test"
25
+ },
26
+ "homepage": "https://identomic.com/docs/server/"
27
+ }