@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.cjs
CHANGED
|
@@ -16680,7 +16680,10 @@ __export(index_exports, {
|
|
|
16680
16680
|
module.exports = __toCommonJS(index_exports);
|
|
16681
16681
|
|
|
16682
16682
|
// src/client.ts
|
|
16683
|
-
var
|
|
16683
|
+
var import_openapi_fetch6 = __toESM(require("openapi-fetch"), 1);
|
|
16684
|
+
|
|
16685
|
+
// src/audit/client.ts
|
|
16686
|
+
var import_openapi_fetch = __toESM(require("openapi-fetch"), 1);
|
|
16684
16687
|
|
|
16685
16688
|
// src/audit/buffer.ts
|
|
16686
16689
|
var MAX_BUFFER_SIZE = 1e3;
|
|
@@ -16725,10 +16728,10 @@ var AuditEventBuffer = class {
|
|
|
16725
16728
|
void this._drainOnce();
|
|
16726
16729
|
}
|
|
16727
16730
|
}
|
|
16728
|
-
/** Block (cooperatively) until the buffer is
|
|
16731
|
+
/** Block (cooperatively) until the buffer is idle or `timeoutMs` elapses. */
|
|
16729
16732
|
async flush(timeoutMs = 5e3) {
|
|
16730
16733
|
const deadline = Date.now() + timeoutMs;
|
|
16731
|
-
while (this._queue.length > 0) {
|
|
16734
|
+
while (this._queue.length > 0 || this._draining) {
|
|
16732
16735
|
if (Date.now() >= deadline) {
|
|
16733
16736
|
console.warn(`[smplkit.audit] flush timed out after ${timeoutMs}ms`);
|
|
16734
16737
|
return;
|
|
@@ -16792,10 +16795,7 @@ var AuditEventBuffer = class {
|
|
|
16792
16795
|
};
|
|
16793
16796
|
|
|
16794
16797
|
// src/audit/client.ts
|
|
16795
|
-
var
|
|
16796
|
-
"Content-Type": "application/vnd.api+json",
|
|
16797
|
-
Accept: "application/vnd.api+json"
|
|
16798
|
-
};
|
|
16798
|
+
var JSONAPI_CONTENT_TYPE = "application/vnd.api+json";
|
|
16799
16799
|
function _attributesFromInput(input) {
|
|
16800
16800
|
const attrs = {
|
|
16801
16801
|
action: input.action,
|
|
@@ -16828,37 +16828,33 @@ function _eventFromResource(resource) {
|
|
|
16828
16828
|
};
|
|
16829
16829
|
}
|
|
16830
16830
|
var EventsClient = class {
|
|
16831
|
-
_apiKey;
|
|
16832
|
-
_baseUrl;
|
|
16833
|
-
_timeoutMs;
|
|
16834
|
-
_buffer;
|
|
16835
16831
|
/** @internal */
|
|
16836
|
-
|
|
16832
|
+
_http;
|
|
16833
|
+
_buffer;
|
|
16837
16834
|
constructor(opts) {
|
|
16838
|
-
|
|
16839
|
-
this.
|
|
16840
|
-
|
|
16835
|
+
const baseUrl = opts.baseUrl.replace(/\/$/, "");
|
|
16836
|
+
this._http = (0, import_openapi_fetch.default)({
|
|
16837
|
+
baseUrl,
|
|
16838
|
+
fetch: opts.fetch,
|
|
16839
|
+
headers: {
|
|
16840
|
+
Authorization: `Bearer ${opts.apiKey}`,
|
|
16841
|
+
Accept: JSONAPI_CONTENT_TYPE,
|
|
16842
|
+
"Content-Type": JSONAPI_CONTENT_TYPE
|
|
16843
|
+
}
|
|
16844
|
+
});
|
|
16841
16845
|
this._buffer = new AuditEventBuffer({
|
|
16842
16846
|
post: async (item) => {
|
|
16843
16847
|
try {
|
|
16844
|
-
const
|
|
16845
|
-
|
|
16846
|
-
|
|
16847
|
-
|
|
16848
|
-
|
|
16849
|
-
|
|
16850
|
-
|
|
16851
|
-
|
|
16852
|
-
|
|
16853
|
-
|
|
16854
|
-
headers,
|
|
16855
|
-
body: JSON.stringify(item.body),
|
|
16856
|
-
signal: ctrl.signal
|
|
16857
|
-
});
|
|
16858
|
-
return { status: resp.status };
|
|
16859
|
-
} finally {
|
|
16860
|
-
clearTimeout(t);
|
|
16861
|
-
}
|
|
16848
|
+
const headerInit = {};
|
|
16849
|
+
if (item.idempotencyKey !== null) headerInit["Idempotency-Key"] = item.idempotencyKey;
|
|
16850
|
+
const result = await this._http.POST("/api/v1/events", {
|
|
16851
|
+
// Casting through unknown because the generated body type is
|
|
16852
|
+
// EventResponse with id required, while the wrapper builds an
|
|
16853
|
+
// unsaved-resource body without an id (server assigns).
|
|
16854
|
+
body: item.body,
|
|
16855
|
+
headers: headerInit
|
|
16856
|
+
});
|
|
16857
|
+
return { status: result.response.status };
|
|
16862
16858
|
} catch {
|
|
16863
16859
|
return { status: 0 };
|
|
16864
16860
|
}
|
|
@@ -16873,32 +16869,33 @@ var EventsClient = class {
|
|
|
16873
16869
|
* reject those with a 403 (the buffer logs and drops permanent
|
|
16874
16870
|
* failures, so a misuse will silently disappear from the queue).
|
|
16875
16871
|
*/
|
|
16876
|
-
|
|
16872
|
+
record(input) {
|
|
16877
16873
|
const body = {
|
|
16878
|
-
data: { type: "event", attributes: _attributesFromInput(input) }
|
|
16874
|
+
data: { id: "", type: "event", attributes: _attributesFromInput(input) }
|
|
16879
16875
|
};
|
|
16880
16876
|
this._buffer.enqueue(body, input.idempotencyKey ?? null);
|
|
16881
16877
|
}
|
|
16882
16878
|
async list(params = {}) {
|
|
16883
|
-
const
|
|
16884
|
-
if (params.action !== void 0)
|
|
16885
|
-
if (params.resourceType !== void 0)
|
|
16886
|
-
if (params.resourceId !== void 0)
|
|
16887
|
-
if (params.actorType !== void 0)
|
|
16888
|
-
if (params.actorId !== void 0)
|
|
16889
|
-
if (params.occurredAtRange !== void 0)
|
|
16890
|
-
if (params.pageSize !== void 0)
|
|
16891
|
-
if (params.pageAfter !== void 0)
|
|
16892
|
-
const
|
|
16893
|
-
|
|
16894
|
-
|
|
16895
|
-
|
|
16896
|
-
|
|
16879
|
+
const query = {};
|
|
16880
|
+
if (params.action !== void 0) query["filter[action]"] = params.action;
|
|
16881
|
+
if (params.resourceType !== void 0) query["filter[resource_type]"] = params.resourceType;
|
|
16882
|
+
if (params.resourceId !== void 0) query["filter[resource_id]"] = params.resourceId;
|
|
16883
|
+
if (params.actorType !== void 0) query["filter[actor_type]"] = params.actorType;
|
|
16884
|
+
if (params.actorId !== void 0) query["filter[actor_id]"] = params.actorId;
|
|
16885
|
+
if (params.occurredAtRange !== void 0) query["filter[occurred_at]"] = params.occurredAtRange;
|
|
16886
|
+
if (params.pageSize !== void 0) query["page[size]"] = params.pageSize;
|
|
16887
|
+
if (params.pageAfter !== void 0) query["page[after]"] = params.pageAfter;
|
|
16888
|
+
const result = await this._http.GET("/api/v1/events", {
|
|
16889
|
+
// openapi-fetch's typed query map is constrained by the spec's
|
|
16890
|
+
// exact param names (filteraction etc.); the JSON:API filter[*]
|
|
16891
|
+
// / page[*] format isn't expressible in that shape, so we cast
|
|
16892
|
+
// and let openapi-fetch URL-encode the literal keys.
|
|
16893
|
+
params: { query }
|
|
16897
16894
|
});
|
|
16898
|
-
if (!
|
|
16899
|
-
throw new Error(`audit list failed: ${
|
|
16895
|
+
if (!result.response.ok || result.data === void 0) {
|
|
16896
|
+
throw new Error(`audit list failed: ${result.response.status} ${result.response.statusText}`);
|
|
16900
16897
|
}
|
|
16901
|
-
const body =
|
|
16898
|
+
const body = result.data;
|
|
16902
16899
|
const events = (body.data ?? []).map(_eventFromResource);
|
|
16903
16900
|
let nextCursor = null;
|
|
16904
16901
|
const nextLink = body.links?.next;
|
|
@@ -16908,17 +16905,13 @@ var EventsClient = class {
|
|
|
16908
16905
|
return { events, nextCursor };
|
|
16909
16906
|
}
|
|
16910
16907
|
async get(eventId) {
|
|
16911
|
-
const
|
|
16912
|
-
|
|
16913
|
-
Authorization: `Bearer ${this._apiKey}`,
|
|
16914
|
-
Accept: "application/vnd.api+json"
|
|
16915
|
-
}
|
|
16908
|
+
const result = await this._http.GET("/api/v1/events/{event_id}", {
|
|
16909
|
+
params: { path: { event_id: eventId } }
|
|
16916
16910
|
});
|
|
16917
|
-
if (!
|
|
16918
|
-
throw new Error(`audit get failed: ${
|
|
16911
|
+
if (!result.response.ok || result.data === void 0) {
|
|
16912
|
+
throw new Error(`audit get failed: ${result.response.status} ${result.response.statusText}`);
|
|
16919
16913
|
}
|
|
16920
|
-
|
|
16921
|
-
return _eventFromResource(body.data);
|
|
16914
|
+
return _eventFromResource(result.data.data);
|
|
16922
16915
|
}
|
|
16923
16916
|
/** Block until the in-memory buffer is drained or `timeoutMs` elapses. */
|
|
16924
16917
|
async flush(timeoutMs = 5e3) {
|
|
@@ -16941,7 +16934,7 @@ var AuditClient = class {
|
|
|
16941
16934
|
};
|
|
16942
16935
|
|
|
16943
16936
|
// src/config/client.ts
|
|
16944
|
-
var
|
|
16937
|
+
var import_openapi_fetch2 = __toESM(require("openapi-fetch"), 1);
|
|
16945
16938
|
|
|
16946
16939
|
// src/errors.ts
|
|
16947
16940
|
var SmplError = class extends Error {
|
|
@@ -17608,7 +17601,7 @@ var ConfigClient = class {
|
|
|
17608
17601
|
const resolvedBaseUrl = baseUrl ?? BASE_URL;
|
|
17609
17602
|
this._baseUrl = resolvedBaseUrl;
|
|
17610
17603
|
const ms = timeout ?? 3e4;
|
|
17611
|
-
this._http = (0,
|
|
17604
|
+
this._http = (0, import_openapi_fetch2.default)({
|
|
17612
17605
|
baseUrl: resolvedBaseUrl,
|
|
17613
17606
|
headers: {
|
|
17614
17607
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -17899,7 +17892,7 @@ var ConfigClient = class {
|
|
|
17899
17892
|
};
|
|
17900
17893
|
|
|
17901
17894
|
// src/flags/client.ts
|
|
17902
|
-
var
|
|
17895
|
+
var import_openapi_fetch4 = __toESM(require("openapi-fetch"), 1);
|
|
17903
17896
|
|
|
17904
17897
|
// src/flags/models.ts
|
|
17905
17898
|
var FlagValue = class {
|
|
@@ -18229,7 +18222,7 @@ var JsonFlag = class extends Flag {
|
|
|
18229
18222
|
var import_json_logic_js = __toESM(require("json-logic-js"), 1);
|
|
18230
18223
|
|
|
18231
18224
|
// src/management/client.ts
|
|
18232
|
-
var
|
|
18225
|
+
var import_openapi_fetch3 = __toESM(require("openapi-fetch"), 1);
|
|
18233
18226
|
|
|
18234
18227
|
// src/management/types.ts
|
|
18235
18228
|
var EnvironmentClassification = /* @__PURE__ */ ((EnvironmentClassification3) => {
|
|
@@ -20435,19 +20428,19 @@ var SmplManagementClient = class {
|
|
|
20435
20428
|
Authorization: `Bearer ${cfg.apiKey}`,
|
|
20436
20429
|
Accept: "application/json"
|
|
20437
20430
|
};
|
|
20438
|
-
this._appHttpRef = (0,
|
|
20431
|
+
this._appHttpRef = (0, import_openapi_fetch3.default)({
|
|
20439
20432
|
baseUrl: appBaseUrl,
|
|
20440
20433
|
headers
|
|
20441
20434
|
});
|
|
20442
|
-
this._configHttpRef = (0,
|
|
20435
|
+
this._configHttpRef = (0, import_openapi_fetch3.default)({
|
|
20443
20436
|
baseUrl: configBaseUrl,
|
|
20444
20437
|
headers
|
|
20445
20438
|
});
|
|
20446
|
-
this._flagsHttpRef = (0,
|
|
20439
|
+
this._flagsHttpRef = (0, import_openapi_fetch3.default)({
|
|
20447
20440
|
baseUrl: flagsBaseUrl,
|
|
20448
20441
|
headers
|
|
20449
20442
|
});
|
|
20450
|
-
this._loggingHttpRef = (0,
|
|
20443
|
+
this._loggingHttpRef = (0, import_openapi_fetch3.default)({
|
|
20451
20444
|
baseUrl: loggingBaseUrl,
|
|
20452
20445
|
headers
|
|
20453
20446
|
});
|
|
@@ -20676,7 +20669,7 @@ var FlagsClient = class {
|
|
|
20676
20669
|
clearTimeout(timer);
|
|
20677
20670
|
}
|
|
20678
20671
|
};
|
|
20679
|
-
this._http = (0,
|
|
20672
|
+
this._http = (0, import_openapi_fetch4.default)({
|
|
20680
20673
|
baseUrl: resolvedBaseUrl,
|
|
20681
20674
|
headers: {
|
|
20682
20675
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -20684,7 +20677,7 @@ var FlagsClient = class {
|
|
|
20684
20677
|
},
|
|
20685
20678
|
fetch: fetchWithTimeout
|
|
20686
20679
|
});
|
|
20687
|
-
this._appHttp = (0,
|
|
20680
|
+
this._appHttp = (0, import_openapi_fetch4.default)({
|
|
20688
20681
|
baseUrl: resolvedAppBaseUrl,
|
|
20689
20682
|
headers: {
|
|
20690
20683
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -21238,7 +21231,7 @@ var FlagsClient = class {
|
|
|
21238
21231
|
};
|
|
21239
21232
|
|
|
21240
21233
|
// src/logging/client.ts
|
|
21241
|
-
var
|
|
21234
|
+
var import_openapi_fetch5 = __toESM(require("openapi-fetch"), 1);
|
|
21242
21235
|
var LOGGING_BASE_URL = "https://logging.smplkit.com";
|
|
21243
21236
|
var LoggerRegistrationBuffer2 = class {
|
|
21244
21237
|
_seen = /* @__PURE__ */ new Set();
|
|
@@ -21292,7 +21285,7 @@ var LoggingClient = class {
|
|
|
21292
21285
|
const resolvedBaseUrl = baseUrl ?? LOGGING_BASE_URL;
|
|
21293
21286
|
this._baseUrl = resolvedBaseUrl;
|
|
21294
21287
|
const ms = timeout ?? 3e4;
|
|
21295
|
-
this._http = (0,
|
|
21288
|
+
this._http = (0, import_openapi_fetch5.default)({
|
|
21296
21289
|
baseUrl: resolvedBaseUrl,
|
|
21297
21290
|
headers: {
|
|
21298
21291
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -22255,7 +22248,7 @@ var SmplClient = class {
|
|
|
22255
22248
|
"lifecycle",
|
|
22256
22249
|
`SmplClient created (api_key=${maskedKey}, environment=${cfg.environment}, service=${cfg.service})`
|
|
22257
22250
|
);
|
|
22258
|
-
this._appHttp = (0,
|
|
22251
|
+
this._appHttp = (0, import_openapi_fetch6.default)({
|
|
22259
22252
|
baseUrl: appBaseUrl,
|
|
22260
22253
|
headers: {
|
|
22261
22254
|
Authorization: `Bearer ${cfg.apiKey}`,
|