sos-sdk-node-ts 0.1.0

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 ADDED
@@ -0,0 +1,28 @@
1
+ # sos-sdk-node-ts
2
+
3
+ SOSChain-specific Node adapters built above the shared runtime-neutral SDK.
4
+
5
+ ```text
6
+ gdc-* frozen
7
+ ↓
8
+ sos-data-utils-ts
9
+ ↓
10
+ sos-sdk-core-ts
11
+ ↓
12
+ sos-sdk-node-ts
13
+ ```
14
+
15
+ This package owns server-side SOSChain transport, credentials, persistence and
16
+ jobs. It does not own deterministic data contracts or common authorization.
17
+ Vet and UHC consume `sos-sdk-core-ts` independently; they do not consume this
18
+ SOSChain runtime package.
19
+
20
+ The first adapter, `SosEmergencyDispatchClient`, sends an already-authorized
21
+ emergency request over HTTPS with a stable idempotency key and validates the
22
+ provider acknowledgement. The bearer credential remains only in the trusted
23
+ Node runtime.
24
+
25
+ ```bash
26
+ npm ci
27
+ npm run check
28
+ ```
@@ -0,0 +1,29 @@
1
+ import type { EmergencyDeliveryTarget } from 'sos-sdk-core-ts/emergency-authorization';
2
+ export type SosEmergencyDispatchInput = Readonly<{
3
+ requestId: string;
4
+ callerId: string;
5
+ memberSubjectIds: readonly string[];
6
+ authorizationEvidenceIds: readonly string[];
7
+ deliveryTarget: EmergencyDeliveryTarget;
8
+ payload: unknown;
9
+ }>;
10
+ export type SosEmergencyDispatchAcknowledgement = Readonly<{
11
+ acknowledgedAt: string;
12
+ receiverId: string;
13
+ }>;
14
+ export type SosEmergencyDispatchClientOptions = Readonly<{
15
+ endpoint: string;
16
+ bearerToken: string;
17
+ fetch?: typeof globalThis.fetch;
18
+ }>;
19
+ /**
20
+ * Sends an already-authorized SOSChain request from a trusted Node runtime.
21
+ *
22
+ * Authorization remains in `sos-sdk-core-ts`; this adapter owns only HTTPS
23
+ * transport, service credentials, idempotency and acknowledgement validation.
24
+ */
25
+ export declare class SosEmergencyDispatchClient {
26
+ #private;
27
+ constructor(options: SosEmergencyDispatchClientOptions);
28
+ dispatch(input: SosEmergencyDispatchInput): Promise<SosEmergencyDispatchAcknowledgement>;
29
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Sends an already-authorized SOSChain request from a trusted Node runtime.
3
+ *
4
+ * Authorization remains in `sos-sdk-core-ts`; this adapter owns only HTTPS
5
+ * transport, service credentials, idempotency and acknowledgement validation.
6
+ */
7
+ export class SosEmergencyDispatchClient {
8
+ #endpoint;
9
+ #bearerToken;
10
+ #fetch;
11
+ constructor(options) {
12
+ this.#endpoint = secureEndpoint(options.endpoint);
13
+ this.#bearerToken = required(options.bearerToken, 'bearerToken');
14
+ this.#fetch = options.fetch ?? globalThis.fetch;
15
+ }
16
+ async dispatch(input) {
17
+ const requestId = required(input.requestId, 'requestId');
18
+ const callerId = required(input.callerId, 'callerId');
19
+ const memberSubjectIds = identifiers(input.memberSubjectIds, 'memberSubjectIds');
20
+ const authorizationEvidenceIds = identifiers(input.authorizationEvidenceIds, 'authorizationEvidenceIds');
21
+ const response = await this.#fetch(this.#endpoint, {
22
+ method: 'POST',
23
+ headers: {
24
+ 'content-type': 'application/json',
25
+ authorization: `Bearer ${this.#bearerToken}`,
26
+ 'idempotency-key': requestId,
27
+ },
28
+ body: JSON.stringify({
29
+ ...input,
30
+ requestId,
31
+ callerId,
32
+ memberSubjectIds,
33
+ authorizationEvidenceIds,
34
+ }),
35
+ });
36
+ if (!response.ok)
37
+ throw new Error(`emergency_dispatch_http_${response.status}`);
38
+ const body = await response.json().catch(() => undefined);
39
+ const acknowledgedAt = String(body?.acknowledgedAt ?? '').trim();
40
+ const receiverId = String(body?.receiverId ?? '').trim();
41
+ if (!receiverId || !Number.isFinite(Date.parse(acknowledgedAt))) {
42
+ throw new Error('emergency_dispatch_acknowledgement_invalid');
43
+ }
44
+ return Object.freeze({ acknowledgedAt, receiverId });
45
+ }
46
+ }
47
+ function secureEndpoint(value) {
48
+ const endpoint = new URL(required(value, 'endpoint'));
49
+ const local = endpoint.hostname === 'localhost' || endpoint.hostname === '127.0.0.1';
50
+ if (endpoint.protocol !== 'https:' && !(local && endpoint.protocol === 'http:')) {
51
+ throw new TypeError('Emergency dispatch endpoint must use HTTPS outside local development.');
52
+ }
53
+ return endpoint;
54
+ }
55
+ function identifiers(values, field) {
56
+ const normalized = [...new Set((values ?? []).map((value) => required(value, field)))];
57
+ if (normalized.length === 0)
58
+ throw new TypeError(`${field} must not be empty.`);
59
+ return normalized;
60
+ }
61
+ function required(value, field) {
62
+ const normalized = String(value ?? '').trim();
63
+ if (!normalized)
64
+ throw new TypeError(`${field} is required.`);
65
+ return normalized;
66
+ }
@@ -0,0 +1,2 @@
1
+ /** SOSChain-specific Node adapters over the shared runtime-neutral SDK. */
2
+ export * from './emergency-dispatch.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ /** SOSChain-specific Node adapters over the shared runtime-neutral SDK. */
2
+ export * from './emergency-dispatch.js';
@@ -0,0 +1,17 @@
1
+ # SOSChain Node SDK boundary
2
+
3
+ ```mermaid
4
+ flowchart TB
5
+ GDC["gdc-* frozen"] --> DATA["sos-data-utils-ts<br/>deterministic contracts"]
6
+ DATA --> CORE["sos-sdk-core-ts<br/>runtime-neutral authorization"]
7
+ CORE --> NODE["sos-sdk-node-ts<br/>SOSChain Node adapters"]
8
+ NODE --> RUNTIME["SOSChain BFF · jobs · portal server"]
9
+ CORE --> VET["vet-sdk-core-ts"]
10
+ CORE --> UHC["uhc-sdk-core-ts"]
11
+ DATA --> VET
12
+ DATA --> UHC
13
+ ```
14
+
15
+ `sos-sdk-node-ts` is a product runtime consumer, not another common layer. It
16
+ may integrate public Vet or UHC contracts for an SOSChain operation, but that
17
+ does not permit a dependency from either shared package back to a product SDK.
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "sos-sdk-node-ts",
3
+ "version": "0.1.0",
4
+ "description": "SOSChain-specific Node adapters over the shared runtime-neutral SOS SDK",
5
+ "license": "Apache-2.0",
6
+ "author": "Connecting Solution & Applications Ltd",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Fundacion-UNID/sos-sdk-node-ts.git"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./emergency-dispatch": {
20
+ "types": "./dist/emergency-dispatch.d.ts",
21
+ "default": "./dist/emergency-dispatch.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "docs"
28
+ ],
29
+ "scripts": {
30
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
31
+ "build": "npm run clean && tsc -p tsconfig.json",
32
+ "typecheck": "tsc -p tsconfig.json --noEmit",
33
+ "test": "npm run build && node --test tests/*.test.mjs",
34
+ "check": "npm run typecheck && npm test",
35
+ "prepack": "npm run check"
36
+ },
37
+ "dependencies": {
38
+ "sos-sdk-core-ts": "0.2.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^24.10.0",
42
+ "typescript": "^5.9.3"
43
+ },
44
+ "engines": {
45
+ "node": ">=24"
46
+ },
47
+ "private": false,
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }