@sinio/sdk 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +117 -2
- package/dist/cjs/client.d.ts +69 -0
- package/dist/cjs/client.js +176 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors.d.ts +34 -0
- package/dist/cjs/errors.js +60 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/http.d.ts +22 -0
- package/dist/cjs/http.js +139 -0
- package/dist/cjs/http.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/serialize.d.ts +11 -0
- package/dist/cjs/serialize.js +111 -0
- package/dist/cjs/serialize.js.map +1 -0
- package/dist/cjs/types.d.ts +114 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/client.d.ts +69 -0
- package/dist/esm/client.js +172 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.d.ts +34 -0
- package/dist/esm/errors.js +49 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/http.d.ts +22 -0
- package/dist/esm/http.js +134 -0
- package/dist/esm/http.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/serialize.d.ts +11 -0
- package/dist/esm/serialize.js +102 -0
- package/dist/esm/serialize.js.map +1 -0
- package/dist/esm/types.d.ts +114 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +37 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAyBA,0CAaC;AAtCD,2CAOqB;AAerB,MAAM,YAAY,GAAG,CAAC,E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OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,EAAE,CAAC;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,EAAE,OAAO,EAAE,GAAG,IAA4B,CAAC;IACjD,6EAA6E;IAC7E,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { SinioClient, SDK_VERSION, type SinioClientOptions } from "./client.ts";
|
|
2
|
+
export { SinioApiError, SinioAuthError, SinioConnectionError, SinioError, SinioRateLimitError, SinioRequestError, SinioServerError, SinioValidationError, } from "./errors.ts";
|
|
3
|
+
export { MAX_ITEMS_PER_CALL } from "./serialize.ts";
|
|
4
|
+
export type * from "./types.ts";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
var client_ts_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "SinioClient", { enumerable: true, get: function () { return client_ts_1.SinioClient; } });
|
|
6
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return client_ts_1.SDK_VERSION; } });
|
|
7
|
+
var errors_ts_1 = require("./errors.js");
|
|
8
|
+
Object.defineProperty(exports, "SinioApiError", { enumerable: true, get: function () { return errors_ts_1.SinioApiError; } });
|
|
9
|
+
Object.defineProperty(exports, "SinioAuthError", { enumerable: true, get: function () { return errors_ts_1.SinioAuthError; } });
|
|
10
|
+
Object.defineProperty(exports, "SinioConnectionError", { enumerable: true, get: function () { return errors_ts_1.SinioConnectionError; } });
|
|
11
|
+
Object.defineProperty(exports, "SinioError", { enumerable: true, get: function () { return errors_ts_1.SinioError; } });
|
|
12
|
+
Object.defineProperty(exports, "SinioRateLimitError", { enumerable: true, get: function () { return errors_ts_1.SinioRateLimitError; } });
|
|
13
|
+
Object.defineProperty(exports, "SinioRequestError", { enumerable: true, get: function () { return errors_ts_1.SinioRequestError; } });
|
|
14
|
+
Object.defineProperty(exports, "SinioServerError", { enumerable: true, get: function () { return errors_ts_1.SinioServerError; } });
|
|
15
|
+
Object.defineProperty(exports, "SinioValidationError", { enumerable: true, get: function () { return errors_ts_1.SinioValidationError; } });
|
|
16
|
+
var serialize_ts_1 = require("./serialize.js");
|
|
17
|
+
Object.defineProperty(exports, "MAX_ITEMS_PER_CALL", { enumerable: true, get: function () { return serialize_ts_1.MAX_ITEMS_PER_CALL; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,+CAAoD;AAA3C,kHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AssignmentInput, EntityInput, LocationInput, SinioEvent, Timestamp } from "./types.ts";
|
|
2
|
+
/** The API caps every collection at 500 items per call. */
|
|
3
|
+
export declare const MAX_ITEMS_PER_CALL = 500;
|
|
4
|
+
/** The most units one event may stand for. */
|
|
5
|
+
export declare const MAX_EVENT_COUNT = 1000000;
|
|
6
|
+
export declare function toIso(value: Timestamp, field: string): string;
|
|
7
|
+
export declare function chunk<T>(items: readonly T[], size: number): T[][];
|
|
8
|
+
export declare function toWireEvent(event: SinioEvent, index: number): Record<string, unknown>;
|
|
9
|
+
export declare function toWireEntity(entity: EntityInput, index: number): Record<string, unknown>;
|
|
10
|
+
export declare function toWireLocation(location: LocationInput, index: number): Record<string, unknown>;
|
|
11
|
+
export declare function toWireAssignment(assignment: AssignmentInput, index: number): Record<string, unknown>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_EVENT_COUNT = exports.MAX_ITEMS_PER_CALL = void 0;
|
|
4
|
+
exports.toIso = toIso;
|
|
5
|
+
exports.chunk = chunk;
|
|
6
|
+
exports.toWireEvent = toWireEvent;
|
|
7
|
+
exports.toWireEntity = toWireEntity;
|
|
8
|
+
exports.toWireLocation = toWireLocation;
|
|
9
|
+
exports.toWireAssignment = toWireAssignment;
|
|
10
|
+
const errors_ts_1 = require("./errors.js");
|
|
11
|
+
/** The API caps every collection at 500 items per call. */
|
|
12
|
+
exports.MAX_ITEMS_PER_CALL = 500;
|
|
13
|
+
/** The most units one event may stand for. */
|
|
14
|
+
exports.MAX_EVENT_COUNT = 1_000_000;
|
|
15
|
+
// The API's own rule: a `T`, seconds, an optional fraction, then `Z` or an offset. It rejects the
|
|
16
|
+
// event otherwise (`invalid_occurred_at`); refused here, it is a fixable local error before any call.
|
|
17
|
+
const ISO_WITH_OFFSET = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:?\d{2})$/;
|
|
18
|
+
function toIso(value, field) {
|
|
19
|
+
if (value instanceof Date) {
|
|
20
|
+
if (Number.isNaN(value.getTime())) {
|
|
21
|
+
throw new errors_ts_1.SinioValidationError(`${field} is an invalid Date`);
|
|
22
|
+
}
|
|
23
|
+
return value.toISOString();
|
|
24
|
+
}
|
|
25
|
+
if (typeof value !== "string" || !ISO_WITH_OFFSET.test(value)) {
|
|
26
|
+
throw new errors_ts_1.SinioValidationError(`${field} must be an ISO 8601 timestamp with an offset (got ${JSON.stringify(value)})`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
/** Drops `undefined` keys so they never reach the wire as `null`. */
|
|
31
|
+
function compact(record) {
|
|
32
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
|
|
33
|
+
}
|
|
34
|
+
function chunk(items, size) {
|
|
35
|
+
const chunks = [];
|
|
36
|
+
for (let index = 0; index < items.length; index += size) {
|
|
37
|
+
chunks.push(items.slice(index, index + size));
|
|
38
|
+
}
|
|
39
|
+
return chunks;
|
|
40
|
+
}
|
|
41
|
+
function toWireEvent(event, index) {
|
|
42
|
+
if (!event.sourceEventId) {
|
|
43
|
+
throw new errors_ts_1.SinioValidationError(`events[${index}].sourceEventId is required`);
|
|
44
|
+
}
|
|
45
|
+
if (!event.type) {
|
|
46
|
+
throw new errors_ts_1.SinioValidationError(`events[${index}].type is required`);
|
|
47
|
+
}
|
|
48
|
+
if (event.payload !== undefined &&
|
|
49
|
+
(typeof event.payload !== "object" || event.payload === null || Array.isArray(event.payload))) {
|
|
50
|
+
throw new errors_ts_1.SinioValidationError(`events[${index}].payload must be an object`);
|
|
51
|
+
}
|
|
52
|
+
if (event.count !== undefined && (!Number.isInteger(event.count) || event.count < 1 || event.count > exports.MAX_EVENT_COUNT)) {
|
|
53
|
+
throw new errors_ts_1.SinioValidationError(`events[${index}].count must be an integer between 1 and ${exports.MAX_EVENT_COUNT}`);
|
|
54
|
+
}
|
|
55
|
+
return compact({
|
|
56
|
+
source_event_id: event.sourceEventId,
|
|
57
|
+
source_version: event.sourceVersion,
|
|
58
|
+
project: event.project,
|
|
59
|
+
type: event.type,
|
|
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,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function toWireEntity(entity, index) {
|
|
68
|
+
if (!entity.externalId) {
|
|
69
|
+
throw new errors_ts_1.SinioValidationError(`entities[${index}].externalId is required`);
|
|
70
|
+
}
|
|
71
|
+
if (!entity.kind) {
|
|
72
|
+
throw new errors_ts_1.SinioValidationError(`entities[${index}].kind is required`);
|
|
73
|
+
}
|
|
74
|
+
return compact({
|
|
75
|
+
external_id: entity.externalId,
|
|
76
|
+
kind: entity.kind,
|
|
77
|
+
subkind: entity.subkind,
|
|
78
|
+
label: entity.label,
|
|
79
|
+
location: entity.location,
|
|
80
|
+
attributes: entity.attributes,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function toWireLocation(location, index) {
|
|
84
|
+
if (!location.externalId) {
|
|
85
|
+
throw new errors_ts_1.SinioValidationError(`locations[${index}].externalId is required`);
|
|
86
|
+
}
|
|
87
|
+
if (!location.name) {
|
|
88
|
+
throw new errors_ts_1.SinioValidationError(`locations[${index}].name is required`);
|
|
89
|
+
}
|
|
90
|
+
return compact({
|
|
91
|
+
external_id: location.externalId,
|
|
92
|
+
kind: location.kind,
|
|
93
|
+
name: location.name,
|
|
94
|
+
parent: location.parent,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function toWireAssignment(assignment, index) {
|
|
98
|
+
if (!assignment.credential || !assignment.subject) {
|
|
99
|
+
throw new errors_ts_1.SinioValidationError(`assignments[${index}] requires both credential and subject`);
|
|
100
|
+
}
|
|
101
|
+
return compact({
|
|
102
|
+
credential: assignment.credential,
|
|
103
|
+
subject: assignment.subject,
|
|
104
|
+
relation: assignment.relation,
|
|
105
|
+
valid_from: toIso(assignment.validFrom, `assignments[${index}].validFrom`),
|
|
106
|
+
valid_to: assignment.validTo === undefined || assignment.validTo === null
|
|
107
|
+
? undefined
|
|
108
|
+
: toIso(assignment.validTo, `assignments[${index}].validTo`),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../src/serialize.ts"],"names":[],"mappings":";;;AAaA,sBAaC;AAOD,sBAMC;AAED,kCA2BC;AAED,oCAeC;AAED,wCAaC;AAED,4CAcC;AApHD,2CAAmD;AAGnD,2DAA2D;AAC9C,QAAA,kBAAkB,GAAG,GAAG,CAAC;AAEtC,8CAA8C;AACjC,QAAA,eAAe,GAAG,SAAS,CAAC;AAEzC,kGAAkG;AAClG,sGAAsG;AACtG,MAAM,eAAe,GAAG,mEAAmE,CAAC;AAE5F,SAAgB,KAAK,CAAC,KAAgB,EAAE,KAAa;IACnD,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,gCAAoB,CAAC,GAAG,KAAK,qBAAqB,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,gCAAoB,CAC5B,GAAG,KAAK,sDAAsD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CACvF,CAAC;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C"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Ingestion mode. `backfill` persists history without triggering alerts. */
|
|
2
|
+
export type IngestionMode = "webhook" | "backfill";
|
|
3
|
+
/** Kinds accepted by `POST /v1/entities`. */
|
|
4
|
+
export type EntityKind = "device" | "subject" | "asset" | "actor" | "credential";
|
|
5
|
+
/** Levels accepted by `POST /v1/locations`. */
|
|
6
|
+
export type LocationLevel = "site" | "zone" | "point";
|
|
7
|
+
/** An ISO 8601 timestamp *with* an offset, or a `Date`. */
|
|
8
|
+
export type Timestamp = string | Date;
|
|
9
|
+
/**
|
|
10
|
+
* The four structural roles the derivation engine resolves, each a raw
|
|
11
|
+
* identifier from the source. Anything else (ticket number, firmware, ...)
|
|
12
|
+
* belongs in `payload`. The API refuses any other key.
|
|
13
|
+
*/
|
|
14
|
+
export interface EventRoles {
|
|
15
|
+
readonly device?: string;
|
|
16
|
+
readonly subject?: string;
|
|
17
|
+
readonly location?: string;
|
|
18
|
+
readonly actor?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SinioEvent {
|
|
21
|
+
/** Identity at the source, stable over time. Part of the idempotency key. */
|
|
22
|
+
readonly sourceEventId: string;
|
|
23
|
+
/** Source-side version, kept for tracing: it plays no part in deduplication. */
|
|
24
|
+
readonly sourceVersion?: string;
|
|
25
|
+
/** Project `external_id`. Required for publisher-level keys, forbidden for project-level ones. */
|
|
26
|
+
readonly project?: string;
|
|
27
|
+
/** `code` of an event type in the catalog. */
|
|
28
|
+
readonly type: string;
|
|
29
|
+
readonly label?: string;
|
|
30
|
+
/** ISO 8601 with offset. Without an offset the API rejects the event. */
|
|
31
|
+
readonly occurredAt: Timestamp;
|
|
32
|
+
readonly roles?: EventRoles;
|
|
33
|
+
/** Free-form, optional (`{}` when omitted); the readings (battery, signal, ...) are read from it as its source declares them. */
|
|
34
|
+
readonly payload?: Record<string, unknown>;
|
|
35
|
+
/** How many units this one event stands for (a button pressed ten times). An integer from 1 to 1,000,000; omitted = 1. */
|
|
36
|
+
readonly count?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface EntityInput {
|
|
39
|
+
readonly externalId: string;
|
|
40
|
+
readonly kind: EntityKind;
|
|
41
|
+
readonly subkind?: string;
|
|
42
|
+
readonly label?: string;
|
|
43
|
+
/** External id of the location the entity sits in. */
|
|
44
|
+
readonly location?: string;
|
|
45
|
+
readonly attributes?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
export interface LocationInput {
|
|
48
|
+
readonly externalId: string;
|
|
49
|
+
readonly kind: LocationLevel;
|
|
50
|
+
readonly name: string;
|
|
51
|
+
/** External id of the parent location, if any. */
|
|
52
|
+
readonly parent?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface AssignmentInput {
|
|
55
|
+
/** External id of the credential (badge, card, ...). */
|
|
56
|
+
readonly credential: string;
|
|
57
|
+
/** External id of the subject the credential is assigned to. */
|
|
58
|
+
readonly subject: string;
|
|
59
|
+
readonly relation?: string;
|
|
60
|
+
readonly validFrom: Timestamp;
|
|
61
|
+
readonly validTo?: Timestamp | null;
|
|
62
|
+
}
|
|
63
|
+
export interface EventRejection {
|
|
64
|
+
readonly sourceEventId: string;
|
|
65
|
+
readonly code: string;
|
|
66
|
+
readonly message: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ReferenceRejection {
|
|
69
|
+
readonly externalId: string;
|
|
70
|
+
readonly code: string;
|
|
71
|
+
readonly message: string;
|
|
72
|
+
}
|
|
73
|
+
export interface AssignmentRejection {
|
|
74
|
+
readonly credential: string;
|
|
75
|
+
readonly subject: string;
|
|
76
|
+
readonly code: string;
|
|
77
|
+
readonly message: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Outcome of `sendEvents`. `duplicates` and `revisions` are successes, not
|
|
81
|
+
* errors: replaying a batch is expected and never creates anything twice.
|
|
82
|
+
*/
|
|
83
|
+
export interface SendEventsResult {
|
|
84
|
+
/** Server-side batch ids, one per HTTP call the SDK made (batches are chunked at 500). */
|
|
85
|
+
readonly batchIds: string[];
|
|
86
|
+
readonly accepted: number;
|
|
87
|
+
readonly pendingClassification: number;
|
|
88
|
+
readonly duplicates: number;
|
|
89
|
+
readonly revisions: number;
|
|
90
|
+
readonly rejected: number;
|
|
91
|
+
readonly rejections: EventRejection[];
|
|
92
|
+
/** The key is in test mode: its events are checked and kept apart, never used for detection. */
|
|
93
|
+
readonly testMode: boolean;
|
|
94
|
+
}
|
|
95
|
+
export interface UpsertResult {
|
|
96
|
+
readonly accepted: number;
|
|
97
|
+
readonly rejected: number;
|
|
98
|
+
readonly rejections: ReferenceRejection[];
|
|
99
|
+
}
|
|
100
|
+
export interface AssignmentsResult {
|
|
101
|
+
readonly accepted: number;
|
|
102
|
+
readonly rejected: number;
|
|
103
|
+
readonly rejections: AssignmentRejection[];
|
|
104
|
+
}
|
|
105
|
+
export interface SendEventsOptions {
|
|
106
|
+
/** Defaults to `webhook`. */
|
|
107
|
+
readonly mode?: IngestionMode;
|
|
108
|
+
/** Overrides the client-level source code for this call. */
|
|
109
|
+
readonly sourceCode?: string;
|
|
110
|
+
}
|
|
111
|
+
/** Project override, for publisher-level API keys covering several projects. */
|
|
112
|
+
export interface ProjectOptions {
|
|
113
|
+
readonly project?: string;
|
|
114
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type FetchLike } from "./http.ts";
|
|
2
|
+
import type { AssignmentInput, AssignmentsResult, EntityInput, LocationInput, SendEventsOptions, SendEventsResult, SinioEvent, ProjectOptions, UpsertResult } from "./types.ts";
|
|
3
|
+
export declare const SDK_VERSION = "0.1.0";
|
|
4
|
+
export interface SinioClientOptions {
|
|
5
|
+
/** Machine credential, sent as `Authorization: Bearer`. Mutually exclusive with `webhookKey`. */
|
|
6
|
+
readonly apiKey?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Key carried in the URL instead of a header, for systems that can only be
|
|
9
|
+
* pointed at a webhook URL. Only `sendEvents` is available in this mode.
|
|
10
|
+
*/
|
|
11
|
+
readonly webhookKey?: string;
|
|
12
|
+
/** Defaults to `https://api.sinio.ai`. */
|
|
13
|
+
readonly baseUrl?: string;
|
|
14
|
+
/** Sent as `X-Source-Code`; optional when the key is already bound to a source. */
|
|
15
|
+
readonly sourceCode?: string;
|
|
16
|
+
/** Default project `external_id`, for publisher-level keys covering several projects. */
|
|
17
|
+
readonly project?: string;
|
|
18
|
+
/** Per-request timeout, default 30 s. */
|
|
19
|
+
readonly timeoutMs?: number;
|
|
20
|
+
/** Retries on 429, 5xx and dropped connections. Default 3. */
|
|
21
|
+
readonly maxRetries?: number;
|
|
22
|
+
/** First backoff ceiling, doubled per attempt with full jitter. Default 500 ms. */
|
|
23
|
+
readonly retryBaseDelayMs?: number;
|
|
24
|
+
/** Injectable transport, for tests or for Node < 18. */
|
|
25
|
+
readonly fetch?: FetchLike;
|
|
26
|
+
/** Injectable sleep, so tests do not wait on retries. */
|
|
27
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Client for the sinio.ai ingestion API.
|
|
31
|
+
*
|
|
32
|
+
* Every method accepts an arbitrarily long list and splits it into calls of
|
|
33
|
+
* 500 items, the API limit, merging the counters and rejections back into a
|
|
34
|
+
* single result. Sending the same events twice is safe: idempotency is keyed
|
|
35
|
+
* on `(project, source, source_event_id, revision)`, so a replay is counted as
|
|
36
|
+
* a duplicate rather than stored again.
|
|
37
|
+
*/
|
|
38
|
+
export declare class SinioClient {
|
|
39
|
+
private readonly transport;
|
|
40
|
+
private readonly authHeaders;
|
|
41
|
+
private readonly eventsPath;
|
|
42
|
+
private readonly webhookMode;
|
|
43
|
+
private readonly sourceCode;
|
|
44
|
+
private readonly project;
|
|
45
|
+
constructor(options: SinioClientOptions);
|
|
46
|
+
/** `POST /v1/events` — live ingestion. Derivation is asynchronous: a 200 confirms receipt only. */
|
|
47
|
+
sendEvents(events: readonly SinioEvent[], options?: SendEventsOptions): Promise<SendEventsResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Same endpoint with `mode: "backfill"`: history is persisted but nothing is
|
|
50
|
+
* alerted, and derivation is replayed later in a canonical order.
|
|
51
|
+
*/
|
|
52
|
+
backfillEvents(events: readonly SinioEvent[], options?: Omit<SendEventsOptions, "mode">): Promise<SendEventsResult>;
|
|
53
|
+
/**
|
|
54
|
+
* `POST /v1/entities` — bulk upsert keyed on `(kind, external_id)`. An unknown
|
|
55
|
+
* `subkind` never fails the call: it is created undeclared, for someone
|
|
56
|
+
* to qualify in the console.
|
|
57
|
+
*/
|
|
58
|
+
upsertEntities(entities: readonly EntityInput[], options?: ProjectOptions): Promise<UpsertResult>;
|
|
59
|
+
/** `POST /v1/locations` — bulk upsert of the location tree, keyed on `external_id`. */
|
|
60
|
+
upsertLocations(locations: readonly LocationInput[], options?: ProjectOptions): Promise<UpsertResult>;
|
|
61
|
+
/**
|
|
62
|
+
* `POST /v1/assignments` — `credential -> subject` with a validity range. An
|
|
63
|
+
* overlap is rejected with `overlapping_assignment`, never merged silently.
|
|
64
|
+
*/
|
|
65
|
+
createAssignments(assignments: readonly AssignmentInput[], options?: ProjectOptions): Promise<AssignmentsResult>;
|
|
66
|
+
private upsertReference;
|
|
67
|
+
private withProject;
|
|
68
|
+
private assertBearerMode;
|
|
69
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { SinioValidationError } from "./errors.js";
|
|
2
|
+
import { Transport } from "./http.js";
|
|
3
|
+
import { MAX_ITEMS_PER_CALL, chunk, toWireAssignment, toWireEntity, toWireEvent, toWireLocation, } from "./serialize.js";
|
|
4
|
+
export const SDK_VERSION = "0.1.0";
|
|
5
|
+
/**
|
|
6
|
+
* Client for the sinio.ai ingestion API.
|
|
7
|
+
*
|
|
8
|
+
* Every method accepts an arbitrarily long list and splits it into calls of
|
|
9
|
+
* 500 items, the API limit, merging the counters and rejections back into a
|
|
10
|
+
* single result. Sending the same events twice is safe: idempotency is keyed
|
|
11
|
+
* on `(project, source, source_event_id, revision)`, so a replay is counted as
|
|
12
|
+
* a duplicate rather than stored again.
|
|
13
|
+
*/
|
|
14
|
+
export class SinioClient {
|
|
15
|
+
transport;
|
|
16
|
+
authHeaders;
|
|
17
|
+
eventsPath;
|
|
18
|
+
webhookMode;
|
|
19
|
+
sourceCode;
|
|
20
|
+
project;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
const hasApiKey = typeof options.apiKey === "string" && options.apiKey.length > 0;
|
|
23
|
+
const hasWebhookKey = typeof options.webhookKey === "string" && options.webhookKey.length > 0;
|
|
24
|
+
if (hasApiKey === hasWebhookKey) {
|
|
25
|
+
throw new SinioValidationError("Provide exactly one of `apiKey` or `webhookKey`.");
|
|
26
|
+
}
|
|
27
|
+
this.webhookMode = hasWebhookKey;
|
|
28
|
+
this.authHeaders = hasApiKey ? { authorization: `Bearer ${options.apiKey}` } : {};
|
|
29
|
+
this.eventsPath = hasWebhookKey ? `/v1/webhooks/${encodeURIComponent(options.webhookKey)}` : "/v1/events";
|
|
30
|
+
this.sourceCode = options.sourceCode;
|
|
31
|
+
this.project = options.project;
|
|
32
|
+
this.transport = new Transport({
|
|
33
|
+
baseUrl: options.baseUrl ?? "https://api.sinio.ai",
|
|
34
|
+
timeoutMs: options.timeoutMs ?? 30_000,
|
|
35
|
+
maxRetries: options.maxRetries ?? 3,
|
|
36
|
+
retryBaseDelayMs: options.retryBaseDelayMs ?? 500,
|
|
37
|
+
userAgent: `sinio-node/${SDK_VERSION}`,
|
|
38
|
+
fetch: options.fetch,
|
|
39
|
+
sleep: options.sleep,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** `POST /v1/events` — live ingestion. Derivation is asynchronous: a 200 confirms receipt only. */
|
|
43
|
+
async sendEvents(events, options = {}) {
|
|
44
|
+
const wire = events.map((event, index) => toWireEvent(this.project === undefined || event.project !== undefined ? event : { ...event, project: this.project }, index));
|
|
45
|
+
const sourceCode = options.sourceCode ?? this.sourceCode;
|
|
46
|
+
const headers = sourceCode === undefined ? {} : { "x-source-code": sourceCode };
|
|
47
|
+
const merged = {
|
|
48
|
+
batchIds: [],
|
|
49
|
+
accepted: 0,
|
|
50
|
+
pendingClassification: 0,
|
|
51
|
+
duplicates: 0,
|
|
52
|
+
revisions: 0,
|
|
53
|
+
rejected: 0,
|
|
54
|
+
rejections: [],
|
|
55
|
+
testMode: false,
|
|
56
|
+
};
|
|
57
|
+
for (const part of chunk(wire, MAX_ITEMS_PER_CALL)) {
|
|
58
|
+
const body = { events: part, mode: options.mode ?? "webhook" };
|
|
59
|
+
const response = asRecord(await this.transport.post(this.eventsPath, body, { ...this.authHeaders, ...headers }));
|
|
60
|
+
const batchId = asString(response["batch_id"]);
|
|
61
|
+
if (batchId !== null) {
|
|
62
|
+
merged.batchIds.push(batchId);
|
|
63
|
+
}
|
|
64
|
+
Object.assign(merged, {
|
|
65
|
+
accepted: merged.accepted + asNumber(response["accepted"]),
|
|
66
|
+
pendingClassification: merged.pendingClassification + asNumber(response["pending_classification"]),
|
|
67
|
+
duplicates: merged.duplicates + asNumber(response["duplicates"]),
|
|
68
|
+
revisions: merged.revisions + asNumber(response["revisions"]),
|
|
69
|
+
rejected: merged.rejected + asNumber(response["rejected"]),
|
|
70
|
+
testMode: merged.testMode || response["test_mode"] === true,
|
|
71
|
+
});
|
|
72
|
+
for (const rejection of asArray(response["rejections"])) {
|
|
73
|
+
const item = asRecord(rejection);
|
|
74
|
+
merged.rejections.push({
|
|
75
|
+
sourceEventId: asString(item["source_event_id"]) ?? "",
|
|
76
|
+
code: asString(item["code"]) ?? "unknown",
|
|
77
|
+
message: asString(item["message"]) ?? "",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return merged;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Same endpoint with `mode: "backfill"`: history is persisted but nothing is
|
|
85
|
+
* alerted, and derivation is replayed later in a canonical order.
|
|
86
|
+
*/
|
|
87
|
+
async backfillEvents(events, options = {}) {
|
|
88
|
+
return this.sendEvents(events, { ...options, mode: "backfill" });
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* `POST /v1/entities` — bulk upsert keyed on `(kind, external_id)`. An unknown
|
|
92
|
+
* `subkind` never fails the call: it is created undeclared, for someone
|
|
93
|
+
* to qualify in the console.
|
|
94
|
+
*/
|
|
95
|
+
async upsertEntities(entities, options = {}) {
|
|
96
|
+
return this.upsertReference("/v1/entities", "entities", entities.map(toWireEntity), options);
|
|
97
|
+
}
|
|
98
|
+
/** `POST /v1/locations` — bulk upsert of the location tree, keyed on `external_id`. */
|
|
99
|
+
async upsertLocations(locations, options = {}) {
|
|
100
|
+
return this.upsertReference("/v1/locations", "locations", locations.map(toWireLocation), options);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* `POST /v1/assignments` — `credential -> subject` with a validity range. An
|
|
104
|
+
* overlap is rejected with `overlapping_assignment`, never merged silently.
|
|
105
|
+
*/
|
|
106
|
+
async createAssignments(assignments, options = {}) {
|
|
107
|
+
this.assertBearerMode("createAssignments");
|
|
108
|
+
const wire = assignments.map(toWireAssignment);
|
|
109
|
+
const merged = { accepted: 0, rejected: 0, rejections: [] };
|
|
110
|
+
for (const part of chunk(wire, MAX_ITEMS_PER_CALL)) {
|
|
111
|
+
const response = asRecord(await this.transport.post("/v1/assignments", this.withProject({ assignments: part }, options), this.authHeaders));
|
|
112
|
+
Object.assign(merged, {
|
|
113
|
+
accepted: merged.accepted + asNumber(response["accepted"]),
|
|
114
|
+
rejected: merged.rejected + asNumber(response["rejected"]),
|
|
115
|
+
});
|
|
116
|
+
for (const rejection of asArray(response["rejections"])) {
|
|
117
|
+
const item = asRecord(rejection);
|
|
118
|
+
merged.rejections.push({
|
|
119
|
+
credential: asString(item["credential"]) ?? "",
|
|
120
|
+
subject: asString(item["subject"]) ?? "",
|
|
121
|
+
code: asString(item["code"]) ?? "unknown",
|
|
122
|
+
message: asString(item["message"]) ?? "",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return merged;
|
|
127
|
+
}
|
|
128
|
+
async upsertReference(path, key, wire, options) {
|
|
129
|
+
this.assertBearerMode(path);
|
|
130
|
+
const merged = { accepted: 0, rejected: 0, rejections: [] };
|
|
131
|
+
for (const part of chunk(wire, MAX_ITEMS_PER_CALL)) {
|
|
132
|
+
const response = asRecord(await this.transport.post(path, this.withProject({ [key]: part }, options), this.authHeaders));
|
|
133
|
+
Object.assign(merged, {
|
|
134
|
+
accepted: merged.accepted + asNumber(response["accepted"]),
|
|
135
|
+
rejected: merged.rejected + asNumber(response["rejected"]),
|
|
136
|
+
});
|
|
137
|
+
for (const rejection of asArray(response["rejections"])) {
|
|
138
|
+
const item = asRecord(rejection);
|
|
139
|
+
merged.rejections.push({
|
|
140
|
+
externalId: asString(item["external_id"]) ?? "",
|
|
141
|
+
code: asString(item["code"]) ?? "unknown",
|
|
142
|
+
message: asString(item["message"]) ?? "",
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return merged;
|
|
147
|
+
}
|
|
148
|
+
withProject(body, options) {
|
|
149
|
+
const project = options.project ?? this.project;
|
|
150
|
+
return project === undefined ? body : { project, ...body };
|
|
151
|
+
}
|
|
152
|
+
assertBearerMode(operation) {
|
|
153
|
+
if (this.webhookMode) {
|
|
154
|
+
throw new SinioValidationError(`${operation} requires an API key: a webhook key only authenticates event ingestion.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function asRecord(value) {
|
|
159
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
160
|
+
? value
|
|
161
|
+
: {};
|
|
162
|
+
}
|
|
163
|
+
function asArray(value) {
|
|
164
|
+
return Array.isArray(value) ? value : [];
|
|
165
|
+
}
|
|
166
|
+
function asNumber(value) {
|
|
167
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
168
|
+
}
|
|
169
|
+
function asString(value) {
|
|
170
|
+
return typeof value === "string" ? value : null;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AACtD,OAAO,EACL,kBAAkB,EAClB,KAAK,EACL,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,cAAc,GACf,MAAM,gBAAgB,CAAC;AAgBxB,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AA4BnC;;;;;;;;GAQG;AACH,MAAM,OAAO,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,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAClF,MAAM,aAAa,GAAG,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9F,IAAI,SAAS,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,IAAI,oBAAoB,CAAC,kDAAkD,CAAC,CAAC;QACrF,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClF,IAAI,CAAC,UAAU,G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ClD,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Base class for every error the SDK throws. */
|
|
2
|
+
export declare class SinioError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
/** The request never got a usable HTTP response (DNS, TCP, TLS, timeout). */
|
|
6
|
+
export declare class SinioConnectionError extends SinioError {
|
|
7
|
+
readonly reason: unknown;
|
|
8
|
+
constructor(message: string, reason?: unknown);
|
|
9
|
+
}
|
|
10
|
+
/** A 4xx or 5xx response. */
|
|
11
|
+
export declare class SinioApiError extends SinioError {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly body: unknown;
|
|
14
|
+
/** Rejection code returned by the API, when the body carries one. */
|
|
15
|
+
readonly code: string | null;
|
|
16
|
+
constructor(message: string, status: number, body: unknown, code?: string | null);
|
|
17
|
+
}
|
|
18
|
+
/** 401 / 403 — invalid, revoked, or insufficiently scoped key. Never replay. */
|
|
19
|
+
export declare class SinioAuthError extends SinioApiError {
|
|
20
|
+
}
|
|
21
|
+
/** 400 / 404 / 413 — the request itself is wrong. Fix it before replaying. */
|
|
22
|
+
export declare class SinioRequestError extends SinioApiError {
|
|
23
|
+
}
|
|
24
|
+
/** 429 — quota exceeded. `retryAfterSeconds` mirrors the `Retry-After` header. */
|
|
25
|
+
export declare class SinioRateLimitError extends SinioApiError {
|
|
26
|
+
readonly retryAfterSeconds: number | null;
|
|
27
|
+
constructor(message: string, status: number, body: unknown, retryAfterSeconds: number | null);
|
|
28
|
+
}
|
|
29
|
+
/** 5xx — temporary. Safe to replay verbatim: ingestion is idempotent. */
|
|
30
|
+
export declare class SinioServerError extends SinioApiError {
|
|
31
|
+
}
|
|
32
|
+
/** Raised before any network call, when the input cannot be a valid request. */
|
|
33
|
+
export declare class SinioValidationError extends SinioError {
|
|
34
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Base class for every error the SDK throws. */
|
|
2
|
+
export class SinioError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** The request never got a usable HTTP response (DNS, TCP, TLS, timeout). */
|
|
9
|
+
export class SinioConnectionError extends SinioError {
|
|
10
|
+
reason;
|
|
11
|
+
constructor(message, reason) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.reason = reason;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** A 4xx or 5xx response. */
|
|
17
|
+
export class SinioApiError extends SinioError {
|
|
18
|
+
status;
|
|
19
|
+
body;
|
|
20
|
+
/** Rejection code returned by the API, when the body carries one. */
|
|
21
|
+
code;
|
|
22
|
+
constructor(message, status, body, code = null) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.body = body;
|
|
26
|
+
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** 401 / 403 — invalid, revoked, or insufficiently scoped key. Never replay. */
|
|
30
|
+
export class SinioAuthError extends SinioApiError {
|
|
31
|
+
}
|
|
32
|
+
/** 400 / 404 / 413 — the request itself is wrong. Fix it before replaying. */
|
|
33
|
+
export class SinioRequestError extends SinioApiError {
|
|
34
|
+
}
|
|
35
|
+
/** 429 — quota exceeded. `retryAfterSeconds` mirrors the `Retry-After` header. */
|
|
36
|
+
export class SinioRateLimitError extends SinioApiError {
|
|
37
|
+
retryAfterSeconds;
|
|
38
|
+
constructor(message, status, body, retryAfterSeconds) {
|
|
39
|
+
super(message, status, body);
|
|
40
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** 5xx — temporary. Safe to replay verbatim: ingestion is idempotent. */
|
|
44
|
+
export class SinioServerError extends SinioApiError {
|
|
45
|
+
}
|
|
46
|
+
/** Raised before any network call, when the input cannot be a valid request. */
|
|
47
|
+
export class SinioValidationError extends SinioError {
|
|
48
|
+
}
|
|
49
|
+
//# source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