@sinio/sdk 0.1.0 → 0.2.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 +21 -2
- package/dist/cjs/client.d.ts +9 -3
- package/dist/cjs/client.js +50 -30
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/errors.d.ts +4 -3
- package/dist/cjs/errors.js +1 -1
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/http.d.ts +2 -2
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/serialize.d.ts +43 -5
- package/dist/cjs/serialize.js +130 -50
- package/dist/cjs/serialize.js.map +1 -1
- package/dist/cjs/types.d.ts +38 -26
- package/dist/cjs/vocabularies.d.ts +23 -0
- package/dist/cjs/vocabularies.js +39 -0
- package/dist/cjs/vocabularies.js.map +1 -0
- package/dist/esm/client.d.ts +9 -3
- package/dist/esm/client.js +51 -31
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/errors.d.ts +4 -3
- package/dist/esm/errors.js +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/http.d.ts +2 -2
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/serialize.d.ts +43 -5
- package/dist/esm/serialize.js +127 -50
- package/dist/esm/serialize.js.map +1 -1
- package/dist/esm/types.d.ts +38 -26
- package/dist/esm/vocabularies.d.ts +23 -0
- package/dist/esm/vocabularies.js +35 -0
- package/dist/esm/vocabularies.js.map +1 -0
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -43,8 +43,10 @@ console.log(result.accepted, result.duplicates, result.rejections);
|
|
|
43
43
|
backoff and full jitter, honouring `Retry-After`. This is safe because
|
|
44
44
|
a resend with the same `source_event_id` and the same content is counted in
|
|
45
45
|
`duplicates`, never stored twice.
|
|
46
|
-
- **Local validation.**
|
|
47
|
-
|
|
46
|
+
- **Local validation.** What the API would refuse is refused before any call with a
|
|
47
|
+
`SinioValidationError` naming the field: a timestamp without a UTC offset (the API's own
|
|
48
|
+
rule), a kind or level outside its vocabulary, a missing required field, a `validTo` not after
|
|
49
|
+
`validFrom`, a role other than the four, a `payload` that is not an object.
|
|
48
50
|
- **Typed errors.** `SinioAuthError` (401/403, do not replay),
|
|
49
51
|
`SinioRequestError` (400/404/413, fix the request), `SinioRateLimitError`
|
|
50
52
|
(429, carries `retryAfterSeconds`), `SinioServerError` (5xx, replayable),
|
|
@@ -64,6 +66,23 @@ for (const rejection of result.rejections) {
|
|
|
64
66
|
|
|
65
67
|
`duplicates` and `revisions` are successes, not failures.
|
|
66
68
|
|
|
69
|
+
The vocabularies are exported, so a value from elsewhere can be checked or a code handled
|
|
70
|
+
without retyping the lists. A rejection code added by a later API version is kept as is:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { ENTITY_KINDS, isKnownRejectionCode, type EntityKind } from "@sinio/sdk";
|
|
74
|
+
|
|
75
|
+
const kind = row.type as EntityKind;
|
|
76
|
+
if (!ENTITY_KINDS.includes(kind)) throw new Error(`unexpected kind ${row.type}`);
|
|
77
|
+
|
|
78
|
+
for (const { code } of result.rejections) {
|
|
79
|
+
if (!isKnownRejectionCode(code)) console.warn("new rejection code", code);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Also exported: `INGESTION_MODES`, `LOCATION_LEVELS`, `ASSIGNMENT_RELATIONS`, `EVENT_ROLES`,
|
|
84
|
+
`REJECTION_CODES`.
|
|
85
|
+
|
|
67
86
|
## Reference data
|
|
68
87
|
|
|
69
88
|
```ts
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FetchLike } from "./http.ts";
|
|
2
2
|
import type { AssignmentInput, AssignmentsResult, EntityInput, LocationInput, SendEventsOptions, SendEventsResult, SinioEvent, ProjectOptions, UpsertResult } from "./types.ts";
|
|
3
|
-
export declare const SDK_VERSION = "0.
|
|
3
|
+
export declare const SDK_VERSION = "0.2.0";
|
|
4
4
|
export interface SinioClientOptions {
|
|
5
5
|
/** Machine credential, sent as `Authorization: Bearer`. Mutually exclusive with `webhookKey`. */
|
|
6
6
|
readonly apiKey?: string;
|
|
@@ -11,9 +11,15 @@ export interface SinioClientOptions {
|
|
|
11
11
|
readonly webhookKey?: string;
|
|
12
12
|
/** Defaults to `https://api.sinio.ai`. */
|
|
13
13
|
readonly baseUrl?: string;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Sent as `X-Source-Code`. Only for keys not bound to a single source (organization-wide keys,
|
|
16
|
+
* issued on request); a source key already carries its source.
|
|
17
|
+
*/
|
|
15
18
|
readonly sourceCode?: string;
|
|
16
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Default project `external_id`. Only for organization-wide keys (issued on request) covering
|
|
21
|
+
* several projects; a project key already carries its project.
|
|
22
|
+
*/
|
|
17
23
|
readonly project?: string;
|
|
18
24
|
/** Per-request timeout, default 30 s. */
|
|
19
25
|
readonly timeoutMs?: number;
|
package/dist/cjs/client.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.SinioClient = exports.SDK_VERSION = void 0;
|
|
|
4
4
|
const errors_ts_1 = require("./errors.js");
|
|
5
5
|
const http_ts_1 = require("./http.js");
|
|
6
6
|
const serialize_ts_1 = require("./serialize.js");
|
|
7
|
-
exports.SDK_VERSION = "0.
|
|
7
|
+
exports.SDK_VERSION = "0.2.0";
|
|
8
8
|
/**
|
|
9
9
|
* Client for the sinio.ai ingestion API.
|
|
10
10
|
*
|
|
@@ -44,7 +44,8 @@ class SinioClient {
|
|
|
44
44
|
}
|
|
45
45
|
/** `POST /v1/events` — live ingestion. Derivation is asynchronous: a 200 confirms receipt only. */
|
|
46
46
|
async sendEvents(events, options = {}) {
|
|
47
|
-
const
|
|
47
|
+
const mode = (0, serialize_ts_1.toWireMode)(options.mode ?? "webhook");
|
|
48
|
+
const wire = (0, serialize_ts_1.requireList)(events, "events").map((event, index) => (0, serialize_ts_1.toWireEvent)(withDefaultProject(event, this.project), index));
|
|
48
49
|
const sourceCode = options.sourceCode ?? this.sourceCode;
|
|
49
50
|
const headers = sourceCode === undefined ? {} : { "x-source-code": sourceCode };
|
|
50
51
|
const merged = {
|
|
@@ -58,25 +59,22 @@ class SinioClient {
|
|
|
58
59
|
testMode: false,
|
|
59
60
|
};
|
|
60
61
|
for (const part of (0, serialize_ts_1.chunk)(wire, serialize_ts_1.MAX_ITEMS_PER_CALL)) {
|
|
61
|
-
const
|
|
62
|
-
const response = asRecord(await this.transport.post(this.eventsPath, body, { ...this.authHeaders, ...headers }));
|
|
62
|
+
const response = asRecord(await this.transport.post(this.eventsPath, { events: part, mode }, { ...this.authHeaders, ...headers }));
|
|
63
63
|
const batchId = asString(response["batch_id"]);
|
|
64
64
|
if (batchId !== null) {
|
|
65
65
|
merged.batchIds.push(batchId);
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
testMode: merged.testMode || response["test_mode"] === true,
|
|
74
|
-
});
|
|
67
|
+
merged.accepted += asNumber(response["accepted"]);
|
|
68
|
+
merged.pendingClassification += asNumber(response["pending_classification"]);
|
|
69
|
+
merged.duplicates += asNumber(response["duplicates"]);
|
|
70
|
+
merged.revisions += asNumber(response["revisions"]);
|
|
71
|
+
merged.rejected += asNumber(response["rejected"]);
|
|
72
|
+
merged.testMode = merged.testMode || response["test_mode"] === true;
|
|
75
73
|
for (const rejection of asArray(response["rejections"])) {
|
|
76
74
|
const item = asRecord(rejection);
|
|
77
75
|
merged.rejections.push({
|
|
78
76
|
sourceEventId: asString(item["source_event_id"]) ?? "",
|
|
79
|
-
code:
|
|
77
|
+
code: asCode(item["code"]),
|
|
80
78
|
message: asString(item["message"]) ?? "",
|
|
81
79
|
});
|
|
82
80
|
}
|
|
@@ -96,11 +94,13 @@ class SinioClient {
|
|
|
96
94
|
* to qualify in the console.
|
|
97
95
|
*/
|
|
98
96
|
async upsertEntities(entities, options = {}) {
|
|
99
|
-
|
|
97
|
+
this.assertBearerMode("upsertEntities");
|
|
98
|
+
return this.upsertReference("/v1/entities", "entities", (0, serialize_ts_1.requireList)(entities, "entities").map((entity, index) => (0, serialize_ts_1.toWireEntity)(entity, index)), options);
|
|
100
99
|
}
|
|
101
100
|
/** `POST /v1/locations` — bulk upsert of the location tree, keyed on `external_id`. */
|
|
102
101
|
async upsertLocations(locations, options = {}) {
|
|
103
|
-
|
|
102
|
+
this.assertBearerMode("upsertLocations");
|
|
103
|
+
return this.upsertReference("/v1/locations", "locations", (0, serialize_ts_1.requireList)(locations, "locations").map((location, index) => (0, serialize_ts_1.toWireLocation)(location, index)), options);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* `POST /v1/assignments` — `credential -> subject` with a validity range. An
|
|
@@ -108,20 +108,22 @@ class SinioClient {
|
|
|
108
108
|
*/
|
|
109
109
|
async createAssignments(assignments, options = {}) {
|
|
110
110
|
this.assertBearerMode("createAssignments");
|
|
111
|
-
const wire = assignments.map(serialize_ts_1.toWireAssignment);
|
|
112
|
-
const merged = {
|
|
111
|
+
const wire = (0, serialize_ts_1.requireList)(assignments, "assignments").map((assignment, index) => (0, serialize_ts_1.toWireAssignment)(assignment, index));
|
|
112
|
+
const merged = {
|
|
113
|
+
accepted: 0,
|
|
114
|
+
rejected: 0,
|
|
115
|
+
rejections: [],
|
|
116
|
+
};
|
|
113
117
|
for (const part of (0, serialize_ts_1.chunk)(wire, serialize_ts_1.MAX_ITEMS_PER_CALL)) {
|
|
114
118
|
const response = asRecord(await this.transport.post("/v1/assignments", this.withProject({ assignments: part }, options), this.authHeaders));
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
rejected: merged.rejected + asNumber(response["rejected"]),
|
|
118
|
-
});
|
|
119
|
+
merged.accepted += asNumber(response["accepted"]);
|
|
120
|
+
merged.rejected += asNumber(response["rejected"]);
|
|
119
121
|
for (const rejection of asArray(response["rejections"])) {
|
|
120
122
|
const item = asRecord(rejection);
|
|
121
123
|
merged.rejections.push({
|
|
122
124
|
credential: asString(item["credential"]) ?? "",
|
|
123
125
|
subject: asString(item["subject"]) ?? "",
|
|
124
|
-
code:
|
|
126
|
+
code: asCode(item["code"]),
|
|
125
127
|
message: asString(item["message"]) ?? "",
|
|
126
128
|
});
|
|
127
129
|
}
|
|
@@ -129,19 +131,20 @@ class SinioClient {
|
|
|
129
131
|
return merged;
|
|
130
132
|
}
|
|
131
133
|
async upsertReference(path, key, wire, options) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
const merged = {
|
|
135
|
+
accepted: 0,
|
|
136
|
+
rejected: 0,
|
|
137
|
+
rejections: [],
|
|
138
|
+
};
|
|
134
139
|
for (const part of (0, serialize_ts_1.chunk)(wire, serialize_ts_1.MAX_ITEMS_PER_CALL)) {
|
|
135
140
|
const response = asRecord(await this.transport.post(path, this.withProject({ [key]: part }, options), this.authHeaders));
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
rejected: merged.rejected + asNumber(response["rejected"]),
|
|
139
|
-
});
|
|
141
|
+
merged.accepted += asNumber(response["accepted"]);
|
|
142
|
+
merged.rejected += asNumber(response["rejected"]);
|
|
140
143
|
for (const rejection of asArray(response["rejections"])) {
|
|
141
144
|
const item = asRecord(rejection);
|
|
142
145
|
merged.rejections.push({
|
|
143
146
|
externalId: asString(item["external_id"]) ?? "",
|
|
144
|
-
code:
|
|
147
|
+
code: asCode(item["code"]),
|
|
145
148
|
message: asString(item["message"]) ?? "",
|
|
146
149
|
});
|
|
147
150
|
}
|
|
@@ -149,7 +152,7 @@ class SinioClient {
|
|
|
149
152
|
return merged;
|
|
150
153
|
}
|
|
151
154
|
withProject(body, options) {
|
|
152
|
-
const project = options.project ?? this.project;
|
|
155
|
+
const project = optionalProject(options.project) ?? this.project;
|
|
153
156
|
return project === undefined ? body : { project, ...body };
|
|
154
157
|
}
|
|
155
158
|
assertBearerMode(operation) {
|
|
@@ -159,6 +162,23 @@ class SinioClient {
|
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
164
|
exports.SinioClient = SinioClient;
|
|
165
|
+
/** The client-level project applies only to an event that does not name its own. */
|
|
166
|
+
function withDefaultProject(event, project) {
|
|
167
|
+
if (project === undefined || typeof event !== "object" || event === null || event.project !== undefined) {
|
|
168
|
+
return event;
|
|
169
|
+
}
|
|
170
|
+
return { ...event, project };
|
|
171
|
+
}
|
|
172
|
+
function optionalProject(value) {
|
|
173
|
+
if (value !== undefined && typeof value !== "string") {
|
|
174
|
+
throw new errors_ts_1.SinioValidationError(`project must be a string (got ${JSON.stringify(value)})`);
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
/** A known code or any code the API adds later, kept as is; never a reason to fail. */
|
|
179
|
+
function asCode(value) {
|
|
180
|
+
return asString(value) ?? "unknown";
|
|
181
|
+
}
|
|
162
182
|
function asRecord(value) {
|
|
163
183
|
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
164
184
|
? value
|
package/dist/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,2CAAmD;AACnD,uCAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,2CAAmD;AACnD,uCAAsD;AACtD,iDASwB;AAiBX,QAAA,WAAW,GAAG,OAAO,CAAC;AAkCnC;;;;;;;;GAQG;AACH,MAAa,WAAW;IACL,SAAS,CAAY;IACrB,WAAW,CAAyB;IACpC,UAAU,CAAS;IACnB,WAAW,CAAU;IACrB,UAAU,CAAqB;IAC/B,OAAO,CAAqB;IAE7C,YAAY,OAA2B;QACrC,MAAM,SAAS,GAAG,OAAO,OAAO,CAAC,MAAM,KAAK,Q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CAAC,IAAI,CAAC;AAClD,CAAC"}
|
package/dist/cjs/errors.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RejectionCodeValue } from "./types.ts";
|
|
1
2
|
/** Base class for every error the SDK throws. */
|
|
2
3
|
export declare class SinioError extends Error {
|
|
3
4
|
constructor(message: string);
|
|
@@ -11,9 +12,9 @@ export declare class SinioConnectionError extends SinioError {
|
|
|
11
12
|
export declare class SinioApiError extends SinioError {
|
|
12
13
|
readonly status: number;
|
|
13
14
|
readonly body: unknown;
|
|
14
|
-
/** Rejection code returned by the API, when the body carries one. */
|
|
15
|
-
readonly code:
|
|
16
|
-
constructor(message: string, status: number, body: unknown, code?:
|
|
15
|
+
/** Rejection code returned by the API, when the body carries one (a known `RejectionCode` or a newer one). */
|
|
16
|
+
readonly code: RejectionCodeValue | null;
|
|
17
|
+
constructor(message: string, status: number, body: unknown, code?: RejectionCodeValue | null);
|
|
17
18
|
}
|
|
18
19
|
/** 401 / 403 — invalid, revoked, or insufficiently scoped key. Never replay. */
|
|
19
20
|
export declare class SinioAuthError extends SinioApiError {
|
package/dist/cjs/errors.js
CHANGED
|
@@ -22,7 +22,7 @@ exports.SinioConnectionError = SinioConnectionError;
|
|
|
22
22
|
class SinioApiError extends SinioError {
|
|
23
23
|
status;
|
|
24
24
|
body;
|
|
25
|
-
/** Rejection code returned by the API, when the body carries one. */
|
|
25
|
+
/** Rejection code returned by the API, when the body carries one (a known `RejectionCode` or a newer one). */
|
|
26
26
|
code;
|
|
27
27
|
constructor(message, status, body, code = null) {
|
|
28
28
|
super(message);
|
package/dist/cjs/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAEA,iDAAiD;AACjD,MAAa,UAAW,SAAQ,KAAK;I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qB,SAAQ,UAAU;CAAG;AAAvD,oDAAuD"}
|
package/dist/cjs/http.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export interface TransportOptions {
|
|
|
5
5
|
readonly maxRetries: number;
|
|
6
6
|
readonly retryBaseDelayMs: number;
|
|
7
7
|
readonly userAgent: string;
|
|
8
|
-
readonly fetch?: FetchLike;
|
|
8
|
+
readonly fetch?: FetchLike | undefined;
|
|
9
9
|
/** Injected in tests so retries do not actually wait. */
|
|
10
|
-
readonly sleep?: (ms: number) => Promise<void
|
|
10
|
+
readonly sleep?: ((ms: number) => Promise<void>) | undefined;
|
|
11
11
|
}
|
|
12
12
|
/** `Retry-After` is either a delay in seconds or an HTTP date. Both are accepted. */
|
|
13
13
|
export declare function parseRetryAfter(header: string | null, now?: number): number | null;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { SinioClient, SDK_VERSION, type SinioClientOptions } from "./client.ts";
|
|
2
2
|
export { SinioApiError, SinioAuthError, SinioConnectionError, SinioError, SinioRateLimitError, SinioRequestError, SinioServerError, SinioValidationError, } from "./errors.ts";
|
|
3
|
-
export { MAX_ITEMS_PER_CALL } from "./serialize.ts";
|
|
3
|
+
export { MAX_EVENT_COUNT, MAX_ITEMS_PER_CALL } from "./serialize.ts";
|
|
4
|
+
export { ASSIGNMENT_RELATIONS, ENTITY_KINDS, EVENT_ROLES, INGESTION_MODES, LOCATION_LEVELS, REJECTION_CODES, isKnownRejectionCode, } from "./vocabularies.ts";
|
|
4
5
|
export type * from "./types.ts";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_ITEMS_PER_CALL = exports.SinioValidationError = exports.SinioServerError = exports.SinioRequestError = exports.SinioRateLimitError = exports.SinioError = exports.SinioConnectionError = exports.SinioAuthError = exports.SinioApiError = exports.SDK_VERSION = exports.SinioClient = void 0;
|
|
3
|
+
exports.isKnownRejectionCode = exports.REJECTION_CODES = exports.LOCATION_LEVELS = exports.INGESTION_MODES = exports.EVENT_ROLES = exports.ENTITY_KINDS = exports.ASSIGNMENT_RELATIONS = exports.MAX_ITEMS_PER_CALL = exports.MAX_EVENT_COUNT = exports.SinioValidationError = exports.SinioServerError = exports.SinioRequestError = exports.SinioRateLimitError = exports.SinioError = exports.SinioConnectionError = exports.SinioAuthError = exports.SinioApiError = exports.SDK_VERSION = exports.SinioClient = void 0;
|
|
4
4
|
var client_ts_1 = require("./client.js");
|
|
5
5
|
Object.defineProperty(exports, "SinioClient", { enumerable: true, get: function () { return client_ts_1.SinioClient; } });
|
|
6
6
|
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return client_ts_1.SDK_VERSION; } });
|
|
@@ -14,5 +14,14 @@ Object.defineProperty(exports, "SinioRequestError", { enumerable: true, get: fun
|
|
|
14
14
|
Object.defineProperty(exports, "SinioServerError", { enumerable: true, get: function () { return errors_ts_1.SinioServerError; } });
|
|
15
15
|
Object.defineProperty(exports, "SinioValidationError", { enumerable: true, get: function () { return errors_ts_1.SinioValidationError; } });
|
|
16
16
|
var serialize_ts_1 = require("./serialize.js");
|
|
17
|
+
Object.defineProperty(exports, "MAX_EVENT_COUNT", { enumerable: true, get: function () { return serialize_ts_1.MAX_EVENT_COUNT; } });
|
|
17
18
|
Object.defineProperty(exports, "MAX_ITEMS_PER_CALL", { enumerable: true, get: function () { return serialize_ts_1.MAX_ITEMS_PER_CALL; } });
|
|
19
|
+
var vocabularies_ts_1 = require("./vocabularies.js");
|
|
20
|
+
Object.defineProperty(exports, "ASSIGNMENT_RELATIONS", { enumerable: true, get: function () { return vocabularies_ts_1.ASSIGNMENT_RELATIONS; } });
|
|
21
|
+
Object.defineProperty(exports, "ENTITY_KINDS", { enumerable: true, get: function () { return vocabularies_ts_1.ENTITY_KINDS; } });
|
|
22
|
+
Object.defineProperty(exports, "EVENT_ROLES", { enumerable: true, get: function () { return vocabularies_ts_1.EVENT_ROLES; } });
|
|
23
|
+
Object.defineProperty(exports, "INGESTION_MODES", { enumerable: true, get: function () { return vocabularies_ts_1.INGESTION_MODES; } });
|
|
24
|
+
Object.defineProperty(exports, "LOCATION_LEVELS", { enumerable: true, get: function () { return vocabularies_ts_1.LOCATION_LEVELS; } });
|
|
25
|
+
Object.defineProperty(exports, "REJECTION_CODES", { enumerable: true, get: function () { return vocabularies_ts_1.REJECTION_CODES; } });
|
|
26
|
+
Object.defineProperty(exports, "isKnownRejectionCode", { enumerable: true, get: function () { return vocabularies_ts_1.isKnownRejectionCode; } });
|
|
18
27
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAgF;AAAvE,wGAAA,WAAW,OAAA;AAAE,wGAAA,WAAW,OAAA;AACjC,yCASqB;AARnB,0GAAA,aAAa,OAAA;AACb,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AACpB,uGAAA,UAAU,OAAA;AACV,gHAAA,mBAAmB,OAAA;AACnB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA;AAEtB,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAgF;AAAvE,wGAAA,WAAW,OAAA;AAAE,wGAAA,WAAW,OAAA;AACjC,yCASqB;AARnB,0GAAA,aAAa,OAAA;AACb,2GAAA,cAAc,OAAA;AACd,iHAAA,oBAAoB,OAAA;AACpB,uGAAA,UAAU,OAAA;AACV,gHAAA,mBAAmB,OAAA;AACnB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA;AAEtB,+CAAqE;AAA5D,+GAAA,eAAe,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AAC5C,qDAQ2B;AAPzB,uHAAA,oBAAoB,OAAA;AACpB,+GAAA,YAAY,OAAA;AACZ,8GAAA,WAAW,OAAA;AACX,kHAAA,eAAe,OAAA;AACf,kHAAA,eAAe,OAAA;AACf,kHAAA,eAAe,OAAA;AACf,uHAAA,oBAAoB,OAAA"}
|
package/dist/cjs/serialize.d.ts
CHANGED
|
@@ -1,11 +1,49 @@
|
|
|
1
|
-
import type { AssignmentInput, EntityInput, LocationInput, SinioEvent, Timestamp } from "./types.ts";
|
|
1
|
+
import type { AssignmentInput, AssignmentRelation, EntityInput, EntityKind, EventRole, IngestionMode, JsonObject, LocationInput, LocationLevel, SinioEvent, Timestamp } from "./types.ts";
|
|
2
2
|
/** The API caps every collection at 500 items per call. */
|
|
3
3
|
export declare const MAX_ITEMS_PER_CALL = 500;
|
|
4
4
|
/** The most units one event may stand for. */
|
|
5
5
|
export declare const MAX_EVENT_COUNT = 1000000;
|
|
6
|
+
export type WireRoles = {
|
|
7
|
+
readonly [role in EventRole]?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
export interface WireEvent {
|
|
10
|
+
readonly source_event_id: string;
|
|
11
|
+
readonly source_version?: string | undefined;
|
|
12
|
+
readonly project?: string | undefined;
|
|
13
|
+
readonly type: string;
|
|
14
|
+
readonly label?: string | undefined;
|
|
15
|
+
readonly occurred_at: string;
|
|
16
|
+
readonly roles?: WireRoles | undefined;
|
|
17
|
+
readonly payload?: JsonObject | undefined;
|
|
18
|
+
readonly count?: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface WireEntity {
|
|
21
|
+
readonly external_id: string;
|
|
22
|
+
readonly kind: EntityKind;
|
|
23
|
+
readonly subkind?: string | undefined;
|
|
24
|
+
readonly label?: string | undefined;
|
|
25
|
+
readonly location?: string | undefined;
|
|
26
|
+
readonly attributes?: JsonObject | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface WireLocation {
|
|
29
|
+
readonly external_id: string;
|
|
30
|
+
readonly kind: LocationLevel;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly parent?: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface WireAssignment {
|
|
35
|
+
readonly credential: string;
|
|
36
|
+
readonly subject: string;
|
|
37
|
+
readonly relation?: AssignmentRelation | undefined;
|
|
38
|
+
readonly valid_from: string;
|
|
39
|
+
readonly valid_to?: string | undefined;
|
|
40
|
+
}
|
|
6
41
|
export declare function toIso(value: Timestamp, field: string): string;
|
|
7
42
|
export declare function chunk<T>(items: readonly T[], size: number): T[][];
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
43
|
+
export declare function requireOneOf<const T extends string>(value: unknown, values: readonly T[], field: string): T;
|
|
44
|
+
export declare function requireList(value: unknown, field: string): readonly unknown[];
|
|
45
|
+
export declare function toWireMode(mode: unknown): IngestionMode;
|
|
46
|
+
export declare function toWireEvent(event: SinioEvent, index: number): WireEvent;
|
|
47
|
+
export declare function toWireEntity(entity: EntityInput, index: number): WireEntity;
|
|
48
|
+
export declare function toWireLocation(location: LocationInput, index: number): WireLocation;
|
|
49
|
+
export declare function toWireAssignment(assignment: AssignmentInput, index: number): WireAssignment;
|
package/dist/cjs/serialize.js
CHANGED
|
@@ -3,11 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MAX_EVENT_COUNT = exports.MAX_ITEMS_PER_CALL = void 0;
|
|
4
4
|
exports.toIso = toIso;
|
|
5
5
|
exports.chunk = chunk;
|
|
6
|
+
exports.requireOneOf = requireOneOf;
|
|
7
|
+
exports.requireList = requireList;
|
|
8
|
+
exports.toWireMode = toWireMode;
|
|
6
9
|
exports.toWireEvent = toWireEvent;
|
|
7
10
|
exports.toWireEntity = toWireEntity;
|
|
8
11
|
exports.toWireLocation = toWireLocation;
|
|
9
12
|
exports.toWireAssignment = toWireAssignment;
|
|
10
13
|
const errors_ts_1 = require("./errors.js");
|
|
14
|
+
const vocabularies_ts_1 = require("./vocabularies.js");
|
|
11
15
|
/** The API caps every collection at 500 items per call. */
|
|
12
16
|
exports.MAX_ITEMS_PER_CALL = 500;
|
|
13
17
|
/** The most units one event may stand for. */
|
|
@@ -38,74 +42,150 @@ function chunk(items, size) {
|
|
|
38
42
|
}
|
|
39
43
|
return chunks;
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
// Local checks, each the API's own rule: the types already say it to TypeScript callers, these say it
|
|
46
|
+
// at runtime to plain JavaScript and to values typed loosely (`as`, `any`, parsed JSON).
|
|
47
|
+
function isPlainObject(value) {
|
|
48
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const prototype = Object.getPrototypeOf(value);
|
|
52
|
+
return prototype === Object.prototype || prototype === null;
|
|
53
|
+
}
|
|
54
|
+
function requireItem(value, field) {
|
|
55
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
56
|
+
throw new errors_ts_1.SinioValidationError(`${field} must be an object (got ${describe(value)})`);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function requireString(value, field) {
|
|
61
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
62
|
+
throw new errors_ts_1.SinioValidationError(`${field} is required and must be a non-empty string (got ${describe(value)})`);
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function optionalString(value, field) {
|
|
67
|
+
if (value !== undefined && typeof value !== "string") {
|
|
68
|
+
throw new errors_ts_1.SinioValidationError(`${field} must be a string (got ${describe(value)})`);
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
function optionalNonEmptyString(value, field) {
|
|
73
|
+
return value === undefined ? undefined : requireString(value, field);
|
|
74
|
+
}
|
|
75
|
+
function optionalObject(value, field) {
|
|
76
|
+
if (value !== undefined && !isPlainObject(value)) {
|
|
77
|
+
throw new errors_ts_1.SinioValidationError(`${field} must be a JSON object (got ${describe(value)})`);
|
|
44
78
|
}
|
|
45
|
-
|
|
46
|
-
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function requireOneOf(value, values, field) {
|
|
82
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
83
|
+
throw new errors_ts_1.SinioValidationError(`${field} must be one of ${values.join(", ")} (got ${describe(value)})`);
|
|
47
84
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
function requireList(value, field) {
|
|
88
|
+
if (!Array.isArray(value)) {
|
|
89
|
+
throw new errors_ts_1.SinioValidationError(`${field} must be an array (got ${describe(value)})`);
|
|
51
90
|
}
|
|
52
|
-
|
|
53
|
-
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
function toWireMode(mode) {
|
|
94
|
+
return requireOneOf(mode, vocabularies_ts_1.INGESTION_MODES, "mode");
|
|
95
|
+
}
|
|
96
|
+
function describe(value) {
|
|
97
|
+
if (value === undefined) {
|
|
98
|
+
return "undefined";
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(value)) {
|
|
101
|
+
return "an array";
|
|
102
|
+
}
|
|
103
|
+
if (value instanceof Date) {
|
|
104
|
+
return "a Date";
|
|
105
|
+
}
|
|
106
|
+
return JSON.stringify(value) ?? String(value);
|
|
107
|
+
}
|
|
108
|
+
function toWireRoles(value, field) {
|
|
109
|
+
if (value === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const roles = requireItem(value, field);
|
|
113
|
+
for (const key of Object.keys(roles)) {
|
|
114
|
+
if (!vocabularies_ts_1.EVENT_ROLES.includes(key)) {
|
|
115
|
+
throw new errors_ts_1.SinioValidationError(`${field}.${key} is not a role: roles are ${vocabularies_ts_1.EVENT_ROLES.join(", ")}`);
|
|
116
|
+
}
|
|
54
117
|
}
|
|
55
118
|
return compact({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
label: event.label,
|
|
61
|
-
occurred_at: toIso(event.occurredAt, `events[${index}].occurredAt`),
|
|
62
|
-
roles: event.roles === undefined ? undefined : compact({ ...event.roles }),
|
|
63
|
-
payload: event.payload,
|
|
64
|
-
count: event.count,
|
|
119
|
+
device: optionalNonEmptyString(roles["device"], `${field}.device`),
|
|
120
|
+
subject: optionalNonEmptyString(roles["subject"], `${field}.subject`),
|
|
121
|
+
location: optionalNonEmptyString(roles["location"], `${field}.location`),
|
|
122
|
+
actor: optionalNonEmptyString(roles["actor"], `${field}.actor`),
|
|
65
123
|
});
|
|
66
124
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!
|
|
72
|
-
throw new errors_ts_1.SinioValidationError(
|
|
125
|
+
function toWireEvent(event, index) {
|
|
126
|
+
const at = `events[${index}]`;
|
|
127
|
+
const item = requireItem(event, at);
|
|
128
|
+
const count = item["count"];
|
|
129
|
+
if (count !== undefined && (!Number.isInteger(count) || count < 1 || count > exports.MAX_EVENT_COUNT)) {
|
|
130
|
+
throw new errors_ts_1.SinioValidationError(`${at}.count must be an integer between 1 and ${exports.MAX_EVENT_COUNT} (got ${describe(count)})`);
|
|
73
131
|
}
|
|
74
132
|
return compact({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
133
|
+
source_event_id: requireString(item["sourceEventId"], `${at}.sourceEventId`),
|
|
134
|
+
source_version: optionalString(item["sourceVersion"], `${at}.sourceVersion`),
|
|
135
|
+
project: optionalString(item["project"], `${at}.project`),
|
|
136
|
+
type: requireString(item["type"], `${at}.type`),
|
|
137
|
+
label: optionalString(item["label"], `${at}.label`),
|
|
138
|
+
occurred_at: toIso(requireTimestamp(item["occurredAt"], `${at}.occurredAt`), `${at}.occurredAt`),
|
|
139
|
+
roles: toWireRoles(item["roles"], `${at}.roles`),
|
|
140
|
+
payload: optionalObject(item["payload"], `${at}.payload`),
|
|
141
|
+
count: count,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function toWireEntity(entity, index) {
|
|
145
|
+
const at = `entities[${index}]`;
|
|
146
|
+
const item = requireItem(entity, at);
|
|
147
|
+
return compact({
|
|
148
|
+
external_id: requireString(item["externalId"], `${at}.externalId`),
|
|
149
|
+
kind: requireOneOf(item["kind"], vocabularies_ts_1.ENTITY_KINDS, `${at}.kind`),
|
|
150
|
+
subkind: optionalNonEmptyString(item["subkind"], `${at}.subkind`),
|
|
151
|
+
label: optionalString(item["label"], `${at}.label`),
|
|
152
|
+
location: optionalString(item["location"], `${at}.location`),
|
|
153
|
+
attributes: optionalObject(item["attributes"], `${at}.attributes`),
|
|
81
154
|
});
|
|
82
155
|
}
|
|
83
156
|
function toWireLocation(location, index) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (!location.name) {
|
|
88
|
-
throw new errors_ts_1.SinioValidationError(`locations[${index}].name is required`);
|
|
89
|
-
}
|
|
157
|
+
const at = `locations[${index}]`;
|
|
158
|
+
const item = requireItem(location, at);
|
|
90
159
|
return compact({
|
|
91
|
-
external_id:
|
|
92
|
-
kind:
|
|
93
|
-
name:
|
|
94
|
-
parent:
|
|
160
|
+
external_id: requireString(item["externalId"], `${at}.externalId`),
|
|
161
|
+
kind: requireOneOf(item["kind"], vocabularies_ts_1.LOCATION_LEVELS, `${at}.kind`),
|
|
162
|
+
name: requireString(item["name"], `${at}.name`),
|
|
163
|
+
parent: optionalString(item["parent"], `${at}.parent`),
|
|
95
164
|
});
|
|
96
165
|
}
|
|
97
166
|
function toWireAssignment(assignment, index) {
|
|
98
|
-
|
|
99
|
-
|
|
167
|
+
const at = `assignments[${index}]`;
|
|
168
|
+
const item = requireItem(assignment, at);
|
|
169
|
+
const relation = item["relation"];
|
|
170
|
+
const validFrom = toIso(requireTimestamp(item["validFrom"], `${at}.validFrom`), `${at}.validFrom`);
|
|
171
|
+
const rawValidTo = item["validTo"];
|
|
172
|
+
const validTo = rawValidTo === undefined || rawValidTo === null ? undefined : toIso(rawValidTo, `${at}.validTo`);
|
|
173
|
+
// The API's `invalid_validity_period`: an assignment has to end after it starts.
|
|
174
|
+
if (validTo !== undefined && Date.parse(validTo) <= Date.parse(validFrom)) {
|
|
175
|
+
throw new errors_ts_1.SinioValidationError(`${at}.validTo must be after validFrom (got ${validFrom} -> ${validTo})`);
|
|
100
176
|
}
|
|
101
177
|
return compact({
|
|
102
|
-
credential:
|
|
103
|
-
subject:
|
|
104
|
-
relation:
|
|
105
|
-
valid_from:
|
|
106
|
-
valid_to:
|
|
107
|
-
? undefined
|
|
108
|
-
: toIso(assignment.validTo, `assignments[${index}].validTo`),
|
|
178
|
+
credential: requireString(item["credential"], `${at}.credential`),
|
|
179
|
+
subject: requireString(item["subject"], `${at}.subject`),
|
|
180
|
+
relation: relation === undefined ? undefined : requireOneOf(relation, vocabularies_ts_1.ASSIGNMENT_RELATIONS, `${at}.relation`),
|
|
181
|
+
valid_from: validFrom,
|
|
182
|
+
valid_to: validTo,
|
|
109
183
|
});
|
|
110
184
|
}
|
|
185
|
+
function requireTimestamp(value, field) {
|
|
186
|
+
if (value === undefined || value === null || value === "") {
|
|
187
|
+
throw new errors_ts_1.SinioValidationError(`${field} is required`);
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
111
191
|
//# sourceMappingURL=serialize.js.map
|