@smplkit/sdk 3.0.11 → 3.0.13
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/dist/index.cjs +67 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +67 -74
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -48,26 +48,29 @@ interface ListEventsPage {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* Audit namespace — `client.audit.events.{
|
|
51
|
+
* Audit namespace — `client.audit.events.{record,list,get}`.
|
|
52
52
|
*
|
|
53
|
-
* ADR-047 §2.6. Writes are fire-and-forget by default: `
|
|
53
|
+
* ADR-047 §2.6. Writes are fire-and-forget by default: `record` enqueues the
|
|
54
54
|
* event onto an in-memory bounded buffer and returns immediately. The buffer
|
|
55
55
|
* worker flushes on a timer or when depth crosses a watermark, and retries
|
|
56
56
|
* transient failures with exponential backoff. Reads are async and return
|
|
57
57
|
* Promises that resolve to typed `AuditEvent` instances.
|
|
58
|
+
*
|
|
59
|
+
* All HTTP work is delegated to the auto-generated openapi-fetch client
|
|
60
|
+
* over `../generated/audit.d.ts` — the wrapper does not issue raw fetch
|
|
61
|
+
* calls.
|
|
58
62
|
*/
|
|
59
63
|
|
|
64
|
+
type AuditHttp = ReturnType<typeof createClient<paths>>;
|
|
60
65
|
declare class EventsClient {
|
|
61
|
-
private readonly _apiKey;
|
|
62
|
-
private readonly _baseUrl;
|
|
63
|
-
private readonly _timeoutMs;
|
|
64
|
-
private readonly _buffer;
|
|
65
66
|
/** @internal */
|
|
66
|
-
|
|
67
|
+
readonly _http: AuditHttp;
|
|
68
|
+
private readonly _buffer;
|
|
67
69
|
constructor(opts: {
|
|
68
70
|
apiKey: string;
|
|
69
71
|
baseUrl: string;
|
|
70
72
|
timeoutMs?: number;
|
|
73
|
+
fetch?: typeof fetch;
|
|
71
74
|
});
|
|
72
75
|
/**
|
|
73
76
|
* Enqueue an audit event for asynchronous delivery.
|
|
@@ -77,7 +80,7 @@ declare class EventsClient {
|
|
|
77
80
|
* reject those with a 403 (the buffer logs and drops permanent
|
|
78
81
|
* failures, so a misuse will silently disappear from the queue).
|
|
79
82
|
*/
|
|
80
|
-
|
|
83
|
+
record(input: CreateEventInput): void;
|
|
81
84
|
list(params?: ListEventsParams): Promise<ListEventsPage>;
|
|
82
85
|
get(eventId: string): Promise<AuditEvent>;
|
|
83
86
|
/** Block until the in-memory buffer is drained or `timeoutMs` elapses. */
|
|
@@ -91,6 +94,7 @@ declare class AuditClient {
|
|
|
91
94
|
apiKey: string;
|
|
92
95
|
baseUrl: string;
|
|
93
96
|
timeoutMs?: number;
|
|
97
|
+
fetch?: typeof fetch;
|
|
94
98
|
});
|
|
95
99
|
/** @internal */
|
|
96
100
|
_close(): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -48,26 +48,29 @@ interface ListEventsPage {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* Audit namespace — `client.audit.events.{
|
|
51
|
+
* Audit namespace — `client.audit.events.{record,list,get}`.
|
|
52
52
|
*
|
|
53
|
-
* ADR-047 §2.6. Writes are fire-and-forget by default: `
|
|
53
|
+
* ADR-047 §2.6. Writes are fire-and-forget by default: `record` enqueues the
|
|
54
54
|
* event onto an in-memory bounded buffer and returns immediately. The buffer
|
|
55
55
|
* worker flushes on a timer or when depth crosses a watermark, and retries
|
|
56
56
|
* transient failures with exponential backoff. Reads are async and return
|
|
57
57
|
* Promises that resolve to typed `AuditEvent` instances.
|
|
58
|
+
*
|
|
59
|
+
* All HTTP work is delegated to the auto-generated openapi-fetch client
|
|
60
|
+
* over `../generated/audit.d.ts` — the wrapper does not issue raw fetch
|
|
61
|
+
* calls.
|
|
58
62
|
*/
|
|
59
63
|
|
|
64
|
+
type AuditHttp = ReturnType<typeof createClient<paths>>;
|
|
60
65
|
declare class EventsClient {
|
|
61
|
-
private readonly _apiKey;
|
|
62
|
-
private readonly _baseUrl;
|
|
63
|
-
private readonly _timeoutMs;
|
|
64
|
-
private readonly _buffer;
|
|
65
66
|
/** @internal */
|
|
66
|
-
|
|
67
|
+
readonly _http: AuditHttp;
|
|
68
|
+
private readonly _buffer;
|
|
67
69
|
constructor(opts: {
|
|
68
70
|
apiKey: string;
|
|
69
71
|
baseUrl: string;
|
|
70
72
|
timeoutMs?: number;
|
|
73
|
+
fetch?: typeof fetch;
|
|
71
74
|
});
|
|
72
75
|
/**
|
|
73
76
|
* Enqueue an audit event for asynchronous delivery.
|
|
@@ -77,7 +80,7 @@ declare class EventsClient {
|
|
|
77
80
|
* reject those with a 403 (the buffer logs and drops permanent
|
|
78
81
|
* failures, so a misuse will silently disappear from the queue).
|
|
79
82
|
*/
|
|
80
|
-
|
|
83
|
+
record(input: CreateEventInput): void;
|
|
81
84
|
list(params?: ListEventsParams): Promise<ListEventsPage>;
|
|
82
85
|
get(eventId: string): Promise<AuditEvent>;
|
|
83
86
|
/** Block until the in-memory buffer is drained or `timeoutMs` elapses. */
|
|
@@ -91,6 +94,7 @@ declare class AuditClient {
|
|
|
91
94
|
apiKey: string;
|
|
92
95
|
baseUrl: string;
|
|
93
96
|
timeoutMs?: number;
|
|
97
|
+
fetch?: typeof fetch;
|
|
94
98
|
});
|
|
95
99
|
/** @internal */
|
|
96
100
|
_close(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -16614,7 +16614,10 @@ var require_pino = __commonJS({
|
|
|
16614
16614
|
});
|
|
16615
16615
|
|
|
16616
16616
|
// src/client.ts
|
|
16617
|
-
import
|
|
16617
|
+
import createClient6 from "openapi-fetch";
|
|
16618
|
+
|
|
16619
|
+
// src/audit/client.ts
|
|
16620
|
+
import createClient from "openapi-fetch";
|
|
16618
16621
|
|
|
16619
16622
|
// src/audit/buffer.ts
|
|
16620
16623
|
var MAX_BUFFER_SIZE = 1e3;
|
|
@@ -16659,10 +16662,10 @@ var AuditEventBuffer = class {
|
|
|
16659
16662
|
void this._drainOnce();
|
|
16660
16663
|
}
|
|
16661
16664
|
}
|
|
16662
|
-
/** Block (cooperatively) until the buffer is
|
|
16665
|
+
/** Block (cooperatively) until the buffer is idle or `timeoutMs` elapses. */
|
|
16663
16666
|
async flush(timeoutMs = 5e3) {
|
|
16664
16667
|
const deadline = Date.now() + timeoutMs;
|
|
16665
|
-
while (this._queue.length > 0) {
|
|
16668
|
+
while (this._queue.length > 0 || this._draining) {
|
|
16666
16669
|
if (Date.now() >= deadline) {
|
|
16667
16670
|
console.warn(`[smplkit.audit] flush timed out after ${timeoutMs}ms`);
|
|
16668
16671
|
return;
|
|
@@ -16726,10 +16729,7 @@ var AuditEventBuffer = class {
|
|
|
16726
16729
|
};
|
|
16727
16730
|
|
|
16728
16731
|
// src/audit/client.ts
|
|
16729
|
-
var
|
|
16730
|
-
"Content-Type": "application/vnd.api+json",
|
|
16731
|
-
Accept: "application/vnd.api+json"
|
|
16732
|
-
};
|
|
16732
|
+
var JSONAPI_CONTENT_TYPE = "application/vnd.api+json";
|
|
16733
16733
|
function _attributesFromInput(input) {
|
|
16734
16734
|
const attrs = {
|
|
16735
16735
|
action: input.action,
|
|
@@ -16762,37 +16762,33 @@ function _eventFromResource(resource) {
|
|
|
16762
16762
|
};
|
|
16763
16763
|
}
|
|
16764
16764
|
var EventsClient = class {
|
|
16765
|
-
_apiKey;
|
|
16766
|
-
_baseUrl;
|
|
16767
|
-
_timeoutMs;
|
|
16768
|
-
_buffer;
|
|
16769
16765
|
/** @internal */
|
|
16770
|
-
|
|
16766
|
+
_http;
|
|
16767
|
+
_buffer;
|
|
16771
16768
|
constructor(opts) {
|
|
16772
|
-
|
|
16773
|
-
this.
|
|
16774
|
-
|
|
16769
|
+
const baseUrl = opts.baseUrl.replace(/\/$/, "");
|
|
16770
|
+
this._http = createClient({
|
|
16771
|
+
baseUrl,
|
|
16772
|
+
fetch: opts.fetch,
|
|
16773
|
+
headers: {
|
|
16774
|
+
Authorization: `Bearer ${opts.apiKey}`,
|
|
16775
|
+
Accept: JSONAPI_CONTENT_TYPE,
|
|
16776
|
+
"Content-Type": JSONAPI_CONTENT_TYPE
|
|
16777
|
+
}
|
|
16778
|
+
});
|
|
16775
16779
|
this._buffer = new AuditEventBuffer({
|
|
16776
16780
|
post: async (item) => {
|
|
16777
16781
|
try {
|
|
16778
|
-
const
|
|
16779
|
-
|
|
16780
|
-
|
|
16781
|
-
|
|
16782
|
-
|
|
16783
|
-
|
|
16784
|
-
|
|
16785
|
-
|
|
16786
|
-
|
|
16787
|
-
|
|
16788
|
-
headers,
|
|
16789
|
-
body: JSON.stringify(item.body),
|
|
16790
|
-
signal: ctrl.signal
|
|
16791
|
-
});
|
|
16792
|
-
return { status: resp.status };
|
|
16793
|
-
} finally {
|
|
16794
|
-
clearTimeout(t);
|
|
16795
|
-
}
|
|
16782
|
+
const headerInit = {};
|
|
16783
|
+
if (item.idempotencyKey !== null) headerInit["Idempotency-Key"] = item.idempotencyKey;
|
|
16784
|
+
const result = await this._http.POST("/api/v1/events", {
|
|
16785
|
+
// Casting through unknown because the generated body type is
|
|
16786
|
+
// EventResponse with id required, while the wrapper builds an
|
|
16787
|
+
// unsaved-resource body without an id (server assigns).
|
|
16788
|
+
body: item.body,
|
|
16789
|
+
headers: headerInit
|
|
16790
|
+
});
|
|
16791
|
+
return { status: result.response.status };
|
|
16796
16792
|
} catch {
|
|
16797
16793
|
return { status: 0 };
|
|
16798
16794
|
}
|
|
@@ -16807,32 +16803,33 @@ var EventsClient = class {
|
|
|
16807
16803
|
* reject those with a 403 (the buffer logs and drops permanent
|
|
16808
16804
|
* failures, so a misuse will silently disappear from the queue).
|
|
16809
16805
|
*/
|
|
16810
|
-
|
|
16806
|
+
record(input) {
|
|
16811
16807
|
const body = {
|
|
16812
|
-
data: { type: "event", attributes: _attributesFromInput(input) }
|
|
16808
|
+
data: { id: "", type: "event", attributes: _attributesFromInput(input) }
|
|
16813
16809
|
};
|
|
16814
16810
|
this._buffer.enqueue(body, input.idempotencyKey ?? null);
|
|
16815
16811
|
}
|
|
16816
16812
|
async list(params = {}) {
|
|
16817
|
-
const
|
|
16818
|
-
if (params.action !== void 0)
|
|
16819
|
-
if (params.resourceType !== void 0)
|
|
16820
|
-
if (params.resourceId !== void 0)
|
|
16821
|
-
if (params.actorType !== void 0)
|
|
16822
|
-
if (params.actorId !== void 0)
|
|
16823
|
-
if (params.occurredAtRange !== void 0)
|
|
16824
|
-
if (params.pageSize !== void 0)
|
|
16825
|
-
if (params.pageAfter !== void 0)
|
|
16826
|
-
const
|
|
16827
|
-
|
|
16828
|
-
|
|
16829
|
-
|
|
16830
|
-
|
|
16813
|
+
const query = {};
|
|
16814
|
+
if (params.action !== void 0) query["filter[action]"] = params.action;
|
|
16815
|
+
if (params.resourceType !== void 0) query["filter[resource_type]"] = params.resourceType;
|
|
16816
|
+
if (params.resourceId !== void 0) query["filter[resource_id]"] = params.resourceId;
|
|
16817
|
+
if (params.actorType !== void 0) query["filter[actor_type]"] = params.actorType;
|
|
16818
|
+
if (params.actorId !== void 0) query["filter[actor_id]"] = params.actorId;
|
|
16819
|
+
if (params.occurredAtRange !== void 0) query["filter[occurred_at]"] = params.occurredAtRange;
|
|
16820
|
+
if (params.pageSize !== void 0) query["page[size]"] = params.pageSize;
|
|
16821
|
+
if (params.pageAfter !== void 0) query["page[after]"] = params.pageAfter;
|
|
16822
|
+
const result = await this._http.GET("/api/v1/events", {
|
|
16823
|
+
// openapi-fetch's typed query map is constrained by the spec's
|
|
16824
|
+
// exact param names (filteraction etc.); the JSON:API filter[*]
|
|
16825
|
+
// / page[*] format isn't expressible in that shape, so we cast
|
|
16826
|
+
// and let openapi-fetch URL-encode the literal keys.
|
|
16827
|
+
params: { query }
|
|
16831
16828
|
});
|
|
16832
|
-
if (!
|
|
16833
|
-
throw new Error(`audit list failed: ${
|
|
16829
|
+
if (!result.response.ok || result.data === void 0) {
|
|
16830
|
+
throw new Error(`audit list failed: ${result.response.status} ${result.response.statusText}`);
|
|
16834
16831
|
}
|
|
16835
|
-
const body =
|
|
16832
|
+
const body = result.data;
|
|
16836
16833
|
const events = (body.data ?? []).map(_eventFromResource);
|
|
16837
16834
|
let nextCursor = null;
|
|
16838
16835
|
const nextLink = body.links?.next;
|
|
@@ -16842,17 +16839,13 @@ var EventsClient = class {
|
|
|
16842
16839
|
return { events, nextCursor };
|
|
16843
16840
|
}
|
|
16844
16841
|
async get(eventId) {
|
|
16845
|
-
const
|
|
16846
|
-
|
|
16847
|
-
Authorization: `Bearer ${this._apiKey}`,
|
|
16848
|
-
Accept: "application/vnd.api+json"
|
|
16849
|
-
}
|
|
16842
|
+
const result = await this._http.GET("/api/v1/events/{event_id}", {
|
|
16843
|
+
params: { path: { event_id: eventId } }
|
|
16850
16844
|
});
|
|
16851
|
-
if (!
|
|
16852
|
-
throw new Error(`audit get failed: ${
|
|
16845
|
+
if (!result.response.ok || result.data === void 0) {
|
|
16846
|
+
throw new Error(`audit get failed: ${result.response.status} ${result.response.statusText}`);
|
|
16853
16847
|
}
|
|
16854
|
-
|
|
16855
|
-
return _eventFromResource(body.data);
|
|
16848
|
+
return _eventFromResource(result.data.data);
|
|
16856
16849
|
}
|
|
16857
16850
|
/** Block until the in-memory buffer is drained or `timeoutMs` elapses. */
|
|
16858
16851
|
async flush(timeoutMs = 5e3) {
|
|
@@ -16875,7 +16868,7 @@ var AuditClient = class {
|
|
|
16875
16868
|
};
|
|
16876
16869
|
|
|
16877
16870
|
// src/config/client.ts
|
|
16878
|
-
import
|
|
16871
|
+
import createClient2 from "openapi-fetch";
|
|
16879
16872
|
|
|
16880
16873
|
// src/errors.ts
|
|
16881
16874
|
var SmplError = class extends Error {
|
|
@@ -17542,7 +17535,7 @@ var ConfigClient = class {
|
|
|
17542
17535
|
const resolvedBaseUrl = baseUrl ?? BASE_URL;
|
|
17543
17536
|
this._baseUrl = resolvedBaseUrl;
|
|
17544
17537
|
const ms = timeout ?? 3e4;
|
|
17545
|
-
this._http =
|
|
17538
|
+
this._http = createClient2({
|
|
17546
17539
|
baseUrl: resolvedBaseUrl,
|
|
17547
17540
|
headers: {
|
|
17548
17541
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -17833,7 +17826,7 @@ var ConfigClient = class {
|
|
|
17833
17826
|
};
|
|
17834
17827
|
|
|
17835
17828
|
// src/flags/client.ts
|
|
17836
|
-
import
|
|
17829
|
+
import createClient4 from "openapi-fetch";
|
|
17837
17830
|
|
|
17838
17831
|
// src/flags/models.ts
|
|
17839
17832
|
var FlagValue = class {
|
|
@@ -18163,7 +18156,7 @@ var JsonFlag = class extends Flag {
|
|
|
18163
18156
|
import jsonLogic from "json-logic-js";
|
|
18164
18157
|
|
|
18165
18158
|
// src/management/client.ts
|
|
18166
|
-
import
|
|
18159
|
+
import createClient3 from "openapi-fetch";
|
|
18167
18160
|
|
|
18168
18161
|
// src/management/types.ts
|
|
18169
18162
|
var EnvironmentClassification = /* @__PURE__ */ ((EnvironmentClassification3) => {
|
|
@@ -20369,19 +20362,19 @@ var SmplManagementClient = class {
|
|
|
20369
20362
|
Authorization: `Bearer ${cfg.apiKey}`,
|
|
20370
20363
|
Accept: "application/json"
|
|
20371
20364
|
};
|
|
20372
|
-
this._appHttpRef =
|
|
20365
|
+
this._appHttpRef = createClient3({
|
|
20373
20366
|
baseUrl: appBaseUrl,
|
|
20374
20367
|
headers
|
|
20375
20368
|
});
|
|
20376
|
-
this._configHttpRef =
|
|
20369
|
+
this._configHttpRef = createClient3({
|
|
20377
20370
|
baseUrl: configBaseUrl,
|
|
20378
20371
|
headers
|
|
20379
20372
|
});
|
|
20380
|
-
this._flagsHttpRef =
|
|
20373
|
+
this._flagsHttpRef = createClient3({
|
|
20381
20374
|
baseUrl: flagsBaseUrl,
|
|
20382
20375
|
headers
|
|
20383
20376
|
});
|
|
20384
|
-
this._loggingHttpRef =
|
|
20377
|
+
this._loggingHttpRef = createClient3({
|
|
20385
20378
|
baseUrl: loggingBaseUrl,
|
|
20386
20379
|
headers
|
|
20387
20380
|
});
|
|
@@ -20610,7 +20603,7 @@ var FlagsClient = class {
|
|
|
20610
20603
|
clearTimeout(timer);
|
|
20611
20604
|
}
|
|
20612
20605
|
};
|
|
20613
|
-
this._http =
|
|
20606
|
+
this._http = createClient4({
|
|
20614
20607
|
baseUrl: resolvedBaseUrl,
|
|
20615
20608
|
headers: {
|
|
20616
20609
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -20618,7 +20611,7 @@ var FlagsClient = class {
|
|
|
20618
20611
|
},
|
|
20619
20612
|
fetch: fetchWithTimeout
|
|
20620
20613
|
});
|
|
20621
|
-
this._appHttp =
|
|
20614
|
+
this._appHttp = createClient4({
|
|
20622
20615
|
baseUrl: resolvedAppBaseUrl,
|
|
20623
20616
|
headers: {
|
|
20624
20617
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -21172,7 +21165,7 @@ var FlagsClient = class {
|
|
|
21172
21165
|
};
|
|
21173
21166
|
|
|
21174
21167
|
// src/logging/client.ts
|
|
21175
|
-
import
|
|
21168
|
+
import createClient5 from "openapi-fetch";
|
|
21176
21169
|
var LOGGING_BASE_URL = "https://logging.smplkit.com";
|
|
21177
21170
|
var LoggerRegistrationBuffer2 = class {
|
|
21178
21171
|
_seen = /* @__PURE__ */ new Set();
|
|
@@ -21226,7 +21219,7 @@ var LoggingClient = class {
|
|
|
21226
21219
|
const resolvedBaseUrl = baseUrl ?? LOGGING_BASE_URL;
|
|
21227
21220
|
this._baseUrl = resolvedBaseUrl;
|
|
21228
21221
|
const ms = timeout ?? 3e4;
|
|
21229
|
-
this._http =
|
|
21222
|
+
this._http = createClient5({
|
|
21230
21223
|
baseUrl: resolvedBaseUrl,
|
|
21231
21224
|
headers: {
|
|
21232
21225
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -22189,7 +22182,7 @@ var SmplClient = class {
|
|
|
22189
22182
|
"lifecycle",
|
|
22190
22183
|
`SmplClient created (api_key=${maskedKey}, environment=${cfg.environment}, service=${cfg.service})`
|
|
22191
22184
|
);
|
|
22192
|
-
this._appHttp =
|
|
22185
|
+
this._appHttp = createClient6({
|
|
22193
22186
|
baseUrl: appBaseUrl,
|
|
22194
22187
|
headers: {
|
|
22195
22188
|
Authorization: `Bearer ${cfg.apiKey}`,
|