@identomic/server 0.1.0 → 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.
package/README.md CHANGED
@@ -1,29 +1,32 @@
1
- # Identomic Node.js server SDK
1
+ # Identomic Server SDK
2
2
 
3
- `@identomic/server` is the backend companion to the Identomic iOS, Android, and Expo SDKs. It uses Node.js 22 or later, with CommonJS, ESM, and TypeScript support. It has no runtime dependencies. Server SDKs for other languages are outside this release.
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
4
 
5
- ## Install locally
5
+ [SDK documentation](https://identomic.com/docs/server/) · [HTTP API reference](https://identomic.com/docs/api/) · [Contact sales](https://identomic.com/contact/)
6
6
 
7
- This package is available from the source tree as a local package. From your application's backend directory, install it by path.
7
+ ## Installation
8
8
 
9
- ```sh
10
- npm install "$HOME/Desktop/Identomic Control Center/packages/identomic-server"
9
+ ```bash
10
+ npm i @identomic/server
11
11
  ```
12
12
 
13
- For distribution inside your team, run `npm pack` in the SDK directory and install the resulting tarball in your backend.
13
+ Requires Node.js 22 or later. Supports ES modules, CommonJS, and TypeScript.
14
14
 
15
15
  ## Initialize
16
16
 
17
17
  ```ts
18
18
  import { IdentomicServer } from "@identomic/server";
19
19
 
20
+ const secretKey = process.env.IDENTOMIC_SECRET_KEY;
21
+ if (!secretKey) throw new Error("Missing IDENTOMIC_SECRET_KEY");
22
+
20
23
  const identomic = new IdentomicServer({
21
- baseUrl: process.env.IDENTOMIC_BASE_URL!,
22
- secretKey: process.env.IDENTOMIC_SECRET_KEY!,
24
+ baseUrl: "https://api.identomic.com",
25
+ secretKey: secretKey,
23
26
  });
24
27
  ```
25
28
 
26
- `baseUrl` is your Identomic API origin, for example `https://identomic-api.example.com`, or the full URL ending in `/api/v1/sdk`. For the local Control Center, use `http://localhost:3100`. HTTP is allowed on loopback for development. Use HTTPS for remote origins. The client rejects redirects and defaults to a 15-second timeout. To change it, pass `timeoutMs`.
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.
27
30
 
28
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.
29
32
 
@@ -51,6 +54,7 @@ return { sessionToken: session.sessionToken, expiresAt: session.expiresAt };
51
54
  | Face comparison | `face_comparison` |
52
55
  | Passport page | `passport_photo` |
53
56
  | Passport NFC | `passport_nfc` |
57
+ | TD1 ID card capture | `id_card_capture` |
54
58
 
55
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.
56
60
 
@@ -67,40 +71,3 @@ Supported outcomes are `completed`, `cancelled`, and `failed`. Store the session
67
71
 
68
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.
69
73
 
70
- ## Start the local example backend
71
-
72
- From this SDK directory:
73
-
74
- ```sh
75
- cp examples/backend/.env.example examples/backend/.env
76
- node -e 'console.log(require("node:crypto").randomBytes(32).toString("base64url"))'
77
- ```
78
-
79
- Put the generated value into `EXAMPLE_APP_TOKEN` in `examples/backend/.env`, then add your sandbox secret key as `IDENTOMIC_SECRET_KEY`. Keep the example file private. Start the Control Center API and dashboard first, then start the example:
80
-
81
- ```sh
82
- node --env-file=examples/backend/.env examples/backend/server.mjs
83
- ```
84
-
85
- The example listens only on `127.0.0.1:4200`. It accepts sandbox credentials and uses the temporary app bearer token for local testing. For a real app, replace that authentication with your existing app login and make your backend reachable over HTTPS.
86
-
87
- | Example endpoint | Request JSON | Response |
88
- | --- | --- | --- |
89
- | `POST /capture-sessions` | `{"module":"fingerprints","idempotencyKey":"test-attempt-1"}` | Session ID, token and expiry |
90
- | `POST /capture-outcomes` | `{"sessionId":"<session UUID>","outcome":"completed"}` | Session ID and outcome |
91
-
92
- Send `Content-Type: application/json` and `Authorization: Bearer <EXAMPLE_APP_TOKEN>` to the example. A successful session request uses one sandbox transaction. Requests contain only module and session metadata.
93
-
94
- Run `npm test` to verify the SDK and example against a local mock Identomic API.
95
-
96
- ## Test with the Expo example
97
-
98
- Start the example backend in Expo sandbox mode. Run this from the `examples/backend` directory after configuring its private `.env` with `IDENTOMIC_BASE_URL` and `IDENTOMIC_SECRET_KEY`.
99
-
100
- ```sh
101
- EXAMPLE_MODE=expo node --env-file=.env server.mjs
102
- ```
103
-
104
- The example backend verifies the sandbox secret and discovers its paired publishable key from Identomic at startup. Expo uses only that publishable key. `EXAMPLE_APP_TOKEN` is used by the default authenticated mode and is unnecessary in Expo mode.
105
-
106
- The Expo mode server still listens on loopback. For a phone build, configure a device-reachable HTTPS address that forwards to this server, and set `EXPO_PUBLIC_IDENTOMIC_DEMO_URL` to that origin in the Expo example before building. Expo mode serves only configuration, session authorization through the example backend, and session claiming. It allows up to 20 unique capture attempts per process as well as the normal sandbox quota. A publishable key is public. Use this mode for controlled sandbox tests and keep your own user authentication for production.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@identomic/server",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Node.js server SDK for Identomic capture sessions",
5
5
  "license": "UNLICENSED",
6
6
  "type": "commonjs",
@@ -15,14 +15,13 @@
15
15
  "files": [
16
16
  "index.cjs",
17
17
  "index.d.cts",
18
- "README.md",
19
- "examples/backend/server.mjs",
20
- "examples/backend/.env.example"
18
+ "README.md"
21
19
  ],
22
20
  "engines": {
23
21
  "node": ">=22"
24
22
  },
25
23
  "scripts": {
26
24
  "test": "node --test"
27
- }
25
+ },
26
+ "homepage": "https://identomic.com/docs/server/"
28
27
  }
@@ -1,6 +0,0 @@
1
- IDENTOMIC_BASE_URL=http://localhost:3100
2
- IDENTOMIC_SECRET_KEY=
3
- EXAMPLE_APP_TOKEN=
4
- EXAMPLE_PORT=4201
5
- # Set to expo only for controlled sandbox testing with a publishable key.
6
- EXAMPLE_MODE=authenticated
@@ -1,141 +0,0 @@
1
- import { createServer } from "node:http";
2
- import { timingSafeEqual } from "node:crypto";
3
- import { pathToFileURL } from "node:url";
4
- import { IdentomicAPIError, IdentomicServer } from "../../index.cjs";
5
-
6
- const maxBodySize = 4096;
7
- const sdkPrefix = "/api/v1/sdk";
8
- const maxExpoAttempts = 20;
9
- const modules = new Set(["fingerprints", "face_capture", "face_liveness", "face_comparison", "passport_photo", "passport_nfc", "id_card_capture"]);
10
-
11
- function send(response, status, data) {
12
- response.writeHead(status, {
13
- "Content-Type": "application/json",
14
- "Cache-Control": "no-store",
15
- });
16
- response.end(JSON.stringify(data));
17
- }
18
-
19
- async function parseObject(request) {
20
- const chunks = [];
21
- let length = 0;
22
- for await (const chunk of request) {
23
- length += chunk.length;
24
- if (length <= maxBodySize) chunks.push(chunk);
25
- }
26
- if (length > maxBodySize) throw new ExampleError(413, "REQUEST_TOO_LARGE");
27
- let body;
28
- try {
29
- body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
30
- } catch {
31
- throw new ExampleError(400, "INVALID_JSON");
32
- }
33
- if (body === null || typeof body !== "object" || Array.isArray(body))
34
- throw new ExampleError(400, "INVALID_REQUEST");
35
- return body;
36
- }
37
-
38
- class ExampleError extends Error {
39
- constructor(status, code) {
40
- super(code);
41
- this.status = status;
42
- this.code = code;
43
- }
44
- }
45
-
46
- export function createExampleBackend({ baseUrl, secretKey, appToken, expoPublishableKey }) {
47
- if (typeof secretKey !== "string" || !secretKey.startsWith("id_sk_sandbox_")) {
48
- throw new TypeError("The example backend requires an Identomic sandbox secret key");
49
- }
50
- const identomic = new IdentomicServer({ baseUrl, secretKey });
51
- const expoMode = expoPublishableKey !== undefined;
52
- if (!expoMode && (typeof appToken !== "string" || !/^[A-Za-z0-9_-]{43,128}$/.test(appToken))) {
53
- throw new TypeError("Set EXAMPLE_APP_TOKEN to a randomly generated bearer token of at least 32 bytes");
54
- }
55
- if (expoMode && !/^id_pk_sandbox_[A-Za-z0-9_-]{43}$/.test(expoPublishableKey)) {
56
- throw new TypeError("Expo mode requires a matched sandbox publishable key");
57
- }
58
- const expoAttempts = new Set();
59
- const expected = Buffer.from("Bearer " + (expoMode ? expoPublishableKey : appToken));
60
- const identomicOrigin = new URL(baseUrl).origin;
61
-
62
- return createServer({ requestTimeout: 15_000 }, async (request, response) => {
63
- const create = request.method === "POST" && request.url === "/capture-sessions";
64
- const report = !expoMode && request.method === "POST" && request.url === "/capture-outcomes";
65
- const configure = expoMode && request.method === "GET" && request.url === sdkPrefix + "/configuration";
66
- const claim = expoMode && request.method === "POST" && request.url === sdkPrefix + "/sessions/claim";
67
- if (!create && !report && !configure && !claim) return send(response, 404, { error: "NOT_FOUND" });
68
-
69
- // Expo mode is a sandbox demo. Production routes authenticate the app's own users.
70
- const supplied = Buffer.from(request.headers.authorization ?? "");
71
- if (supplied.length !== expected.length || !timingSafeEqual(supplied, expected)) {
72
- return send(response, 401, { error: expoMode ? "DEMO_PUBLISHABLE_KEY_MISMATCH" : "EXAMPLE_SIGN_IN_REQUIRED" });
73
- }
74
- if (!configure && request.headers["content-type"]?.split(";")[0].trim().toLowerCase() !== "application/json") {
75
- return send(response, 415, { error: "JSON_REQUIRED" });
76
- }
77
-
78
- try {
79
- if (configure || claim) {
80
- const body = claim ? JSON.stringify(await parseObject(request)) : undefined;
81
- const upstream = await fetch(identomicOrigin + request.url, {
82
- method: request.method,
83
- headers: { "Authorization": "Bearer " + expoPublishableKey, "Content-Type": "application/json" },
84
- body,
85
- redirect: "error",
86
- signal: AbortSignal.timeout(15_000),
87
- });
88
- return send(response, upstream.status, await upstream.json());
89
- }
90
- const body = await parseObject(request);
91
- const permitted = create ? ["module", "idempotencyKey"] : ["sessionId", "outcome"];
92
- if (Object.keys(body).length !== 2 || !permitted.every(key => Object.hasOwn(body, key))) {
93
- throw new ExampleError(400, "INVALID_REQUEST");
94
- }
95
- if (expoMode) {
96
- if (!modules.has(body.module) || typeof body.idempotencyKey !== "string" ||
97
- !/^[A-Za-z0-9._:-]{1,128}$/.test(body.idempotencyKey)) {
98
- throw new ExampleError(400, "INVALID_REQUEST");
99
- }
100
- if (!expoAttempts.has(body.idempotencyKey) && expoAttempts.size >= maxExpoAttempts) {
101
- throw new ExampleError(429, "EXPO_DEMO_LIMIT_REACHED");
102
- }
103
- expoAttempts.add(body.idempotencyKey);
104
- }
105
- const result = create
106
- ? await identomic.sessions.create(body)
107
- : await identomic.sessions.reportOutcome(body);
108
- return send(response, 200, result);
109
- } catch (error) {
110
- if (error instanceof ExampleError) return send(response, error.status, { error: error.code });
111
- if (configure || claim) return send(response, 502, { error: "IDENTOMIC_UNAVAILABLE" });
112
- if (error instanceof TypeError) return send(response, 400, { error: "INVALID_REQUEST" });
113
- if (error instanceof IdentomicAPIError) {
114
- const status = error.status;
115
- return send(response, status >= 400 && status <= 499 && status !== 401 ? status : 502, { error: error.code });
116
- }
117
- return send(response, 500, { error: "INTERNAL_ERROR" });
118
- }
119
- });
120
- }
121
-
122
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
123
- const baseUrl = process.env.IDENTOMIC_BASE_URL;
124
- const secretKey = process.env.IDENTOMIC_SECRET_KEY;
125
- const mode = process.env.EXAMPLE_MODE ?? "authenticated";
126
- if (mode !== "authenticated" && mode !== "expo") throw new TypeError("Invalid EXAMPLE_MODE");
127
- let expoPublishableKey;
128
- if (mode === "expo") {
129
- try {
130
- const pair = await new IdentomicServer({ baseUrl, secretKey }).getSandboxKeyPair();
131
- expoPublishableKey = pair.publishableKey;
132
- } catch (error) {
133
- console.error("Expo demo could not verify its sandbox key pair:", error.code ?? error.message);
134
- process.exit(1);
135
- }
136
- }
137
- const server = createExampleBackend({baseUrl,secretKey,appToken:process.env.EXAMPLE_APP_TOKEN,expoPublishableKey});
138
- const port = Number(process.env.EXAMPLE_PORT ?? 4200);
139
- if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new TypeError("Invalid EXAMPLE_PORT");
140
- server.listen(port, "127.0.0.1", () => console.log("Example backend (" + mode + ") listening at http://127.0.0.1:" + port));
141
- }