@smplkit/sdk 3.0.14 → 3.0.17

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 CHANGED
@@ -16808,6 +16808,7 @@ function _attributesFromInput(input) {
16808
16808
  }
16809
16809
  if (input.snapshot !== void 0) attrs.snapshot = input.snapshot;
16810
16810
  if (input.data !== void 0) attrs.data = input.data;
16811
+ if (input.doNotForward) attrs.do_not_forward = true;
16811
16812
  return attrs;
16812
16813
  }
16813
16814
  function _eventFromResource(resource) {
@@ -16824,9 +16825,84 @@ function _eventFromResource(resource) {
16824
16825
  actorLabel: String(attrs.actor_label ?? ""),
16825
16826
  snapshot: attrs.snapshot ?? null,
16826
16827
  data: attrs.data ?? {},
16827
- idempotencyKey: String(attrs.idempotency_key ?? "")
16828
+ idempotencyKey: String(attrs.idempotency_key ?? ""),
16829
+ doNotForward: Boolean(attrs.do_not_forward ?? false)
16828
16830
  };
16829
16831
  }
16832
+ function _httpToWire(http) {
16833
+ return {
16834
+ method: http.method,
16835
+ url: http.url,
16836
+ headers: http.headers.map((h) => ({ name: h.name, value: h.value })),
16837
+ body: http.body,
16838
+ success_status: http.successStatus
16839
+ };
16840
+ }
16841
+ function _httpFromWire(raw) {
16842
+ const r = raw ?? {};
16843
+ const headers = (r.headers ?? []).map((h) => ({
16844
+ name: String(h.name ?? ""),
16845
+ value: String(h.value ?? "")
16846
+ }));
16847
+ return {
16848
+ method: String(r.method ?? "POST"),
16849
+ url: String(r.url ?? ""),
16850
+ headers,
16851
+ body: r.body ?? null,
16852
+ successStatus: String(r.success_status ?? "2xx")
16853
+ };
16854
+ }
16855
+ function _forwarderAttributes(input) {
16856
+ const attrs = {
16857
+ name: input.name,
16858
+ forwarder_type: input.forwarderType,
16859
+ enabled: input.enabled ?? true,
16860
+ http: _httpToWire(input.http)
16861
+ };
16862
+ if (input.filter !== void 0) attrs.filter = input.filter;
16863
+ if (input.transform !== void 0) attrs.transform = input.transform;
16864
+ if (input.data !== void 0) attrs.data = input.data;
16865
+ return attrs;
16866
+ }
16867
+ function _forwarderFromResource(resource) {
16868
+ const a = resource.attributes;
16869
+ return {
16870
+ id: resource.id,
16871
+ name: String(a.name ?? ""),
16872
+ slug: String(a.slug ?? ""),
16873
+ forwarderType: String(a.forwarder_type ?? ""),
16874
+ enabled: Boolean(a.enabled ?? true),
16875
+ filter: a.filter ?? null,
16876
+ transform: a.transform ?? null,
16877
+ http: _httpFromWire(a.http),
16878
+ data: a.data ?? {},
16879
+ createdAt: a.created_at ?? null,
16880
+ updatedAt: a.updated_at ?? null,
16881
+ deletedAt: a.deleted_at ?? null,
16882
+ version: a.version ?? null
16883
+ };
16884
+ }
16885
+ function _deliveryFromResource(resource) {
16886
+ const a = resource.attributes;
16887
+ return {
16888
+ id: resource.id,
16889
+ forwarderId: String(a.forwarder_id ?? ""),
16890
+ eventId: String(a.event_id ?? ""),
16891
+ attemptNumber: Number(a.attempt_number ?? 1),
16892
+ status: a.status ?? "failed",
16893
+ request: a.request ?? null,
16894
+ responseStatus: a.response_status ?? null,
16895
+ responseBody: a.response_body ?? null,
16896
+ latencyMs: a.latency_ms ?? null,
16897
+ error: a.error ?? null,
16898
+ createdAt: a.created_at ?? null
16899
+ };
16900
+ }
16901
+ function _nextCursorFromLinks(body) {
16902
+ const next = body.links?.next;
16903
+ if (typeof next !== "string" || !next.includes("page[after]=")) return null;
16904
+ return next.split("page[after]=")[1];
16905
+ }
16830
16906
  var EventsClient = class {
16831
16907
  /** @internal */
16832
16908
  _http;
@@ -16837,6 +16913,7 @@ var EventsClient = class {
16837
16913
  baseUrl,
16838
16914
  fetch: opts.fetch,
16839
16915
  headers: {
16916
+ ...opts.extraHeaders ?? {},
16840
16917
  Authorization: `Bearer ${opts.apiKey}`,
16841
16918
  Accept: JSONAPI_CONTENT_TYPE,
16842
16919
  "Content-Type": JSONAPI_CONTENT_TYPE
@@ -16922,10 +16999,215 @@ var EventsClient = class {
16922
16999
  await this._buffer.close();
16923
17000
  }
16924
17001
  };
17002
+ var DeliveryActionsClient = class {
17003
+ constructor(_http) {
17004
+ this._http = _http;
17005
+ }
17006
+ /** Retry a single failed delivery. Records a new attempt row with
17007
+ * attempt_number = prior + 1; the prior row is unchanged. */
17008
+ async retry(forwarderId, deliveryId) {
17009
+ const result = await this._http.POST(
17010
+ "/api/v1/forwarders/{forwarder_id}/deliveries/{delivery_id}/actions/retry",
17011
+ { params: { path: { forwarder_id: forwarderId, delivery_id: deliveryId } } }
17012
+ );
17013
+ if (!result.response.ok || result.data === void 0) {
17014
+ throw new Error(
17015
+ `audit retry delivery failed: ${result.response.status} ${result.response.statusText}`
17016
+ );
17017
+ }
17018
+ return _deliveryFromResource(result.data.data);
17019
+ }
17020
+ };
17021
+ var DeliveriesClient = class {
17022
+ constructor(_http) {
17023
+ this._http = _http;
17024
+ this.actions = new DeliveryActionsClient(_http);
17025
+ }
17026
+ actions;
17027
+ async list(forwarderId, params = {}) {
17028
+ const query = {};
17029
+ if (params.status !== void 0) query["filter[status]"] = params.status;
17030
+ if (params.createdAtRange !== void 0) query["filter[created_at]"] = params.createdAtRange;
17031
+ if (params.pageSize !== void 0) query["page[size]"] = params.pageSize;
17032
+ if (params.pageAfter !== void 0) query["page[after]"] = params.pageAfter;
17033
+ const result = await this._http.GET("/api/v1/forwarders/{forwarder_id}/deliveries", {
17034
+ params: {
17035
+ path: { forwarder_id: forwarderId },
17036
+ query
17037
+ }
17038
+ });
17039
+ if (!result.response.ok || result.data === void 0) {
17040
+ throw new Error(
17041
+ `audit list deliveries failed: ${result.response.status} ${result.response.statusText}`
17042
+ );
17043
+ }
17044
+ const body = result.data;
17045
+ return {
17046
+ deliveries: (body.data ?? []).map(_deliveryFromResource),
17047
+ nextCursor: _nextCursorFromLinks(body)
17048
+ };
17049
+ }
17050
+ };
17051
+ var ForwarderActionsClient = class {
17052
+ constructor(_http) {
17053
+ this._http = _http;
17054
+ }
17055
+ /** Retry every failed delivery for a forwarder. Returns a count summary. */
17056
+ async retryFailedDeliveries(forwarderId) {
17057
+ const result = await this._http.POST(
17058
+ "/api/v1/forwarders/{forwarder_id}/actions/retry_failed_deliveries",
17059
+ { params: { path: { forwarder_id: forwarderId } } }
17060
+ );
17061
+ if (!result.response.ok || result.data === void 0) {
17062
+ throw new Error(
17063
+ `audit bulk retry failed: ${result.response.status} ${result.response.statusText}`
17064
+ );
17065
+ }
17066
+ const d = result.data;
17067
+ return {
17068
+ attempted: Number(d.attempted ?? 0),
17069
+ succeeded: Number(d.succeeded ?? 0),
17070
+ failed: Number(d.failed ?? 0)
17071
+ };
17072
+ }
17073
+ };
17074
+ var ForwardersClient = class {
17075
+ constructor(_http) {
17076
+ this._http = _http;
17077
+ this.deliveries = new DeliveriesClient(_http);
17078
+ this.actions = new ForwarderActionsClient(_http);
17079
+ }
17080
+ deliveries;
17081
+ actions;
17082
+ async create(input) {
17083
+ const body = { data: { id: "", type: "forwarder", attributes: _forwarderAttributes(input) } };
17084
+ const result = await this._http.POST("/api/v1/forwarders", {
17085
+ body
17086
+ });
17087
+ if (!result.response.ok || result.data === void 0) {
17088
+ throw new Error(
17089
+ `audit create forwarder failed: ${result.response.status} ${result.response.statusText}`
17090
+ );
17091
+ }
17092
+ return _forwarderFromResource(result.data.data);
17093
+ }
17094
+ async list(params = {}) {
17095
+ const query = {};
17096
+ if (params.forwarderType !== void 0) query["filter[forwarder_type]"] = params.forwarderType;
17097
+ if (params.enabled !== void 0) query["filter[enabled]"] = params.enabled;
17098
+ if (params.pageSize !== void 0) query["page[size]"] = params.pageSize;
17099
+ if (params.pageAfter !== void 0) query["page[after]"] = params.pageAfter;
17100
+ const result = await this._http.GET("/api/v1/forwarders", {
17101
+ params: { query }
17102
+ });
17103
+ if (!result.response.ok || result.data === void 0) {
17104
+ throw new Error(
17105
+ `audit list forwarders failed: ${result.response.status} ${result.response.statusText}`
17106
+ );
17107
+ }
17108
+ const body = result.data;
17109
+ return {
17110
+ forwarders: (body.data ?? []).map(_forwarderFromResource),
17111
+ nextCursor: _nextCursorFromLinks(body)
17112
+ };
17113
+ }
17114
+ async get(forwarderId) {
17115
+ const result = await this._http.GET("/api/v1/forwarders/{forwarder_id}", {
17116
+ params: { path: { forwarder_id: forwarderId } }
17117
+ });
17118
+ if (!result.response.ok || result.data === void 0) {
17119
+ throw new Error(
17120
+ `audit get forwarder failed: ${result.response.status} ${result.response.statusText}`
17121
+ );
17122
+ }
17123
+ return _forwarderFromResource(result.data.data);
17124
+ }
17125
+ async update(forwarderId, input) {
17126
+ const body = {
17127
+ data: { id: forwarderId, type: "forwarder", attributes: _forwarderAttributes(input) }
17128
+ };
17129
+ const result = await this._http.PUT("/api/v1/forwarders/{forwarder_id}", {
17130
+ params: { path: { forwarder_id: forwarderId } },
17131
+ body
17132
+ });
17133
+ if (!result.response.ok || result.data === void 0) {
17134
+ throw new Error(
17135
+ `audit update forwarder failed: ${result.response.status} ${result.response.statusText}`
17136
+ );
17137
+ }
17138
+ return _forwarderFromResource(result.data.data);
17139
+ }
17140
+ async delete(forwarderId) {
17141
+ const result = await this._http.DELETE("/api/v1/forwarders/{forwarder_id}", {
17142
+ params: { path: { forwarder_id: forwarderId } }
17143
+ });
17144
+ if (result.response.status !== 204) {
17145
+ throw new Error(
17146
+ `audit delete forwarder failed: ${result.response.status} ${result.response.statusText}`
17147
+ );
17148
+ }
17149
+ }
17150
+ };
17151
+ var TestForwarderActionsClient = class {
17152
+ constructor(_http) {
17153
+ this._http = _http;
17154
+ }
17155
+ /** Server-side proxy to a customer-supplied URL. SSRF-guarded; the
17156
+ * audit service rejects private/loopback/link-local addresses (incl.
17157
+ * the EC2 IMDS at 169.254.169.254) and ports outside the allowlist. */
17158
+ async execute(input) {
17159
+ const body = {
17160
+ method: input.method ?? "POST",
17161
+ url: input.url,
17162
+ headers: (input.headers ?? []).map((h) => ({ name: h.name, value: h.value })),
17163
+ body: input.body ?? null,
17164
+ success_status: input.successStatus ?? "2xx"
17165
+ };
17166
+ if (input.timeoutMs !== void 0) body.timeout_ms = input.timeoutMs;
17167
+ const result = await this._http.POST("/api/v1/functions/test_forwarder/actions/execute", {
17168
+ // This endpoint serves and accepts plain JSON, NOT JSON:API. The
17169
+ // openapi-fetch client adds its default JSON:API content-type
17170
+ // header; we override here so the server's strict validator
17171
+ // doesn't reject the request.
17172
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
17173
+ body
17174
+ });
17175
+ if (!result.response.ok || result.data === void 0) {
17176
+ throw new Error(
17177
+ `audit test_forwarder failed: ${result.response.status} ${result.response.statusText}`
17178
+ );
17179
+ }
17180
+ const d = result.data;
17181
+ return {
17182
+ succeeded: Boolean(d.succeeded),
17183
+ responseStatus: d.response_status ?? null,
17184
+ responseHeaders: d.response_headers ?? {},
17185
+ responseBody: String(d.response_body ?? ""),
17186
+ latencyMs: d.latency_ms ?? null,
17187
+ error: d.error ?? null
17188
+ };
17189
+ }
17190
+ };
17191
+ var TestForwarderClient = class {
17192
+ actions;
17193
+ constructor(http) {
17194
+ this.actions = new TestForwarderActionsClient(http);
17195
+ }
17196
+ };
17197
+ var FunctionsClient = class {
17198
+ test_forwarder;
17199
+ constructor(http) {
17200
+ this.test_forwarder = new TestForwarderClient(http);
17201
+ }
17202
+ };
16925
17203
  var AuditClient = class {
16926
17204
  events;
17205
+ forwarders;
17206
+ functions;
16927
17207
  constructor(opts) {
16928
17208
  this.events = new EventsClient(opts);
17209
+ this.forwarders = new ForwardersClient(this.events._http);
17210
+ this.functions = new FunctionsClient(this.events._http);
16929
17211
  }
16930
17212
  /** @internal */
16931
17213
  async _close() {
@@ -17596,7 +17878,7 @@ var ConfigClient = class {
17596
17878
  _initialized = false;
17597
17879
  _listeners = [];
17598
17880
  /** @internal */
17599
- constructor(apiKey, timeout, baseUrl) {
17881
+ constructor(apiKey, timeout, baseUrl, extraHeaders) {
17600
17882
  this._apiKey = apiKey;
17601
17883
  const resolvedBaseUrl = baseUrl ?? BASE_URL;
17602
17884
  this._baseUrl = resolvedBaseUrl;
@@ -17604,6 +17886,7 @@ var ConfigClient = class {
17604
17886
  this._http = (0, import_openapi_fetch2.default)({
17605
17887
  baseUrl: resolvedBaseUrl,
17606
17888
  headers: {
17889
+ ...extraHeaders ?? {},
17607
17890
  Authorization: `Bearer ${apiKey}`,
17608
17891
  Accept: "application/json"
17609
17892
  },
@@ -20648,7 +20931,7 @@ var FlagsClient = class {
20648
20931
  /** @internal — set by SmplClient after construction. */
20649
20932
  _parent = null;
20650
20933
  /** @internal */
20651
- constructor(apiKey, ensureWs, timeout, flagsBaseUrl, appBaseUrl, contextBuffer) {
20934
+ constructor(apiKey, ensureWs, timeout, flagsBaseUrl, appBaseUrl, contextBuffer, extraHeaders) {
20652
20935
  this._apiKey = apiKey;
20653
20936
  this._ensureWs = ensureWs;
20654
20937
  const resolvedBaseUrl = flagsBaseUrl ?? FLAGS_BASE_URL;
@@ -20669,9 +20952,11 @@ var FlagsClient = class {
20669
20952
  clearTimeout(timer);
20670
20953
  }
20671
20954
  };
20955
+ const extra = extraHeaders ?? {};
20672
20956
  this._http = (0, import_openapi_fetch4.default)({
20673
20957
  baseUrl: resolvedBaseUrl,
20674
20958
  headers: {
20959
+ ...extra,
20675
20960
  Authorization: `Bearer ${apiKey}`,
20676
20961
  Accept: "application/json"
20677
20962
  },
@@ -20680,6 +20965,7 @@ var FlagsClient = class {
20680
20965
  this._appHttp = (0, import_openapi_fetch4.default)({
20681
20966
  baseUrl: resolvedAppBaseUrl,
20682
20967
  headers: {
20968
+ ...extra,
20683
20969
  Authorization: `Bearer ${apiKey}`,
20684
20970
  Accept: "application/json"
20685
20971
  },
@@ -21279,7 +21565,7 @@ var LoggingClient = class {
21279
21565
  _groupStore = {};
21280
21566
  // key -> level
21281
21567
  /** @internal */
21282
- constructor(apiKey, ensureWs, timeout, baseUrl) {
21568
+ constructor(apiKey, ensureWs, timeout, baseUrl, extraHeaders) {
21283
21569
  this._apiKey = apiKey;
21284
21570
  this._ensureWs = ensureWs;
21285
21571
  const resolvedBaseUrl = baseUrl ?? LOGGING_BASE_URL;
@@ -21288,6 +21574,7 @@ var LoggingClient = class {
21288
21574
  this._http = (0, import_openapi_fetch5.default)({
21289
21575
  baseUrl: resolvedBaseUrl,
21290
21576
  headers: {
21577
+ ...extraHeaders ?? {},
21291
21578
  Authorization: `Bearer ${apiKey}`,
21292
21579
  Accept: "application/json"
21293
21580
  },
@@ -22248,9 +22535,11 @@ var SmplClient = class {
22248
22535
  "lifecycle",
22249
22536
  `SmplClient created (api_key=${maskedKey}, environment=${cfg.environment}, service=${cfg.service})`
22250
22537
  );
22538
+ const extraHeaders = options.extraHeaders ?? {};
22251
22539
  this._appHttp = (0, import_openapi_fetch6.default)({
22252
22540
  baseUrl: appBaseUrl,
22253
22541
  headers: {
22542
+ ...extraHeaders,
22254
22543
  Authorization: `Bearer ${cfg.apiKey}`,
22255
22544
  Accept: "application/json"
22256
22545
  }
@@ -22269,25 +22558,28 @@ var SmplClient = class {
22269
22558
  scheme: cfg.scheme,
22270
22559
  debug: cfg.debug
22271
22560
  });
22272
- this.config = new ConfigClient(cfg.apiKey, this._timeout, configBaseUrl);
22561
+ this.config = new ConfigClient(cfg.apiKey, this._timeout, configBaseUrl, extraHeaders);
22273
22562
  this.flags = new FlagsClient(
22274
22563
  cfg.apiKey,
22275
22564
  () => this._ensureWs(),
22276
22565
  this._timeout,
22277
22566
  flagsBaseUrl,
22278
22567
  appBaseUrl,
22279
- this.manage._contextBuffer
22568
+ this.manage._contextBuffer,
22569
+ extraHeaders
22280
22570
  );
22281
22571
  this.logging = new LoggingClient(
22282
22572
  cfg.apiKey,
22283
22573
  () => this._ensureWs(),
22284
22574
  this._timeout,
22285
- loggingBaseUrl
22575
+ loggingBaseUrl,
22576
+ extraHeaders
22286
22577
  );
22287
22578
  this.audit = new AuditClient({
22288
22579
  apiKey: cfg.apiKey,
22289
22580
  baseUrl: auditBaseUrl,
22290
- timeoutMs: this._timeout
22581
+ timeoutMs: this._timeout,
22582
+ extraHeaders
22291
22583
  });
22292
22584
  this.config._getSharedWs = () => this._ensureWs();
22293
22585
  this.flags._parent = this;