@smplkit/sdk 3.0.15 → 3.0.18

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.js CHANGED
@@ -16742,6 +16742,7 @@ function _attributesFromInput(input) {
16742
16742
  }
16743
16743
  if (input.snapshot !== void 0) attrs.snapshot = input.snapshot;
16744
16744
  if (input.data !== void 0) attrs.data = input.data;
16745
+ if (input.doNotForward) attrs.do_not_forward = true;
16745
16746
  return attrs;
16746
16747
  }
16747
16748
  function _eventFromResource(resource) {
@@ -16758,9 +16759,84 @@ function _eventFromResource(resource) {
16758
16759
  actorLabel: String(attrs.actor_label ?? ""),
16759
16760
  snapshot: attrs.snapshot ?? null,
16760
16761
  data: attrs.data ?? {},
16761
- idempotencyKey: String(attrs.idempotency_key ?? "")
16762
+ idempotencyKey: String(attrs.idempotency_key ?? ""),
16763
+ doNotForward: Boolean(attrs.do_not_forward ?? false)
16762
16764
  };
16763
16765
  }
16766
+ function _httpToWire(http) {
16767
+ return {
16768
+ method: http.method,
16769
+ url: http.url,
16770
+ headers: http.headers.map((h) => ({ name: h.name, value: h.value })),
16771
+ body: http.body,
16772
+ success_status: http.successStatus
16773
+ };
16774
+ }
16775
+ function _httpFromWire(raw) {
16776
+ const r = raw ?? {};
16777
+ const headers = (r.headers ?? []).map((h) => ({
16778
+ name: String(h.name ?? ""),
16779
+ value: String(h.value ?? "")
16780
+ }));
16781
+ return {
16782
+ method: String(r.method ?? "POST"),
16783
+ url: String(r.url ?? ""),
16784
+ headers,
16785
+ body: r.body ?? null,
16786
+ successStatus: String(r.success_status ?? "2xx")
16787
+ };
16788
+ }
16789
+ function _forwarderAttributes(input) {
16790
+ const attrs = {
16791
+ name: input.name,
16792
+ forwarder_type: input.forwarderType,
16793
+ enabled: input.enabled ?? true,
16794
+ http: _httpToWire(input.http)
16795
+ };
16796
+ if (input.filter !== void 0) attrs.filter = input.filter;
16797
+ if (input.transform !== void 0) attrs.transform = input.transform;
16798
+ if (input.data !== void 0) attrs.data = input.data;
16799
+ return attrs;
16800
+ }
16801
+ function _forwarderFromResource(resource) {
16802
+ const a = resource.attributes;
16803
+ return {
16804
+ id: resource.id,
16805
+ name: String(a.name ?? ""),
16806
+ slug: String(a.slug ?? ""),
16807
+ forwarderType: String(a.forwarder_type ?? ""),
16808
+ enabled: Boolean(a.enabled ?? true),
16809
+ filter: a.filter ?? null,
16810
+ transform: a.transform ?? null,
16811
+ http: _httpFromWire(a.http),
16812
+ data: a.data ?? {},
16813
+ createdAt: a.created_at ?? null,
16814
+ updatedAt: a.updated_at ?? null,
16815
+ deletedAt: a.deleted_at ?? null,
16816
+ version: a.version ?? null
16817
+ };
16818
+ }
16819
+ function _deliveryFromResource(resource) {
16820
+ const a = resource.attributes;
16821
+ return {
16822
+ id: resource.id,
16823
+ forwarderId: String(a.forwarder_id ?? ""),
16824
+ eventId: String(a.event_id ?? ""),
16825
+ attemptNumber: Number(a.attempt_number ?? 1),
16826
+ status: a.status ?? "failed",
16827
+ request: a.request ?? null,
16828
+ responseStatus: a.response_status ?? null,
16829
+ responseBody: a.response_body ?? null,
16830
+ latencyMs: a.latency_ms ?? null,
16831
+ error: a.error ?? null,
16832
+ createdAt: a.created_at ?? null
16833
+ };
16834
+ }
16835
+ function _nextCursorFromLinks(body) {
16836
+ const next = body.links?.next;
16837
+ if (typeof next !== "string" || !next.includes("page[after]=")) return null;
16838
+ return next.split("page[after]=")[1];
16839
+ }
16764
16840
  var EventsClient = class {
16765
16841
  /** @internal */
16766
16842
  _http;
@@ -16771,6 +16847,7 @@ var EventsClient = class {
16771
16847
  baseUrl,
16772
16848
  fetch: opts.fetch,
16773
16849
  headers: {
16850
+ ...opts.extraHeaders ?? {},
16774
16851
  Authorization: `Bearer ${opts.apiKey}`,
16775
16852
  Accept: JSONAPI_CONTENT_TYPE,
16776
16853
  "Content-Type": JSONAPI_CONTENT_TYPE
@@ -16856,10 +16933,215 @@ var EventsClient = class {
16856
16933
  await this._buffer.close();
16857
16934
  }
16858
16935
  };
16936
+ var DeliveryActionsClient = class {
16937
+ constructor(_http) {
16938
+ this._http = _http;
16939
+ }
16940
+ /** Retry a single failed delivery. Records a new attempt row with
16941
+ * attempt_number = prior + 1; the prior row is unchanged. */
16942
+ async retry(forwarderId, deliveryId) {
16943
+ const result = await this._http.POST(
16944
+ "/api/v1/forwarders/{forwarder_id}/deliveries/{delivery_id}/actions/retry",
16945
+ { params: { path: { forwarder_id: forwarderId, delivery_id: deliveryId } } }
16946
+ );
16947
+ if (!result.response.ok || result.data === void 0) {
16948
+ throw new Error(
16949
+ `audit retry delivery failed: ${result.response.status} ${result.response.statusText}`
16950
+ );
16951
+ }
16952
+ return _deliveryFromResource(result.data.data);
16953
+ }
16954
+ };
16955
+ var DeliveriesClient = class {
16956
+ constructor(_http) {
16957
+ this._http = _http;
16958
+ this.actions = new DeliveryActionsClient(_http);
16959
+ }
16960
+ actions;
16961
+ async list(forwarderId, params = {}) {
16962
+ const query = {};
16963
+ if (params.status !== void 0) query["filter[status]"] = params.status;
16964
+ if (params.createdAtRange !== void 0) query["filter[created_at]"] = params.createdAtRange;
16965
+ if (params.pageSize !== void 0) query["page[size]"] = params.pageSize;
16966
+ if (params.pageAfter !== void 0) query["page[after]"] = params.pageAfter;
16967
+ const result = await this._http.GET("/api/v1/forwarders/{forwarder_id}/deliveries", {
16968
+ params: {
16969
+ path: { forwarder_id: forwarderId },
16970
+ query
16971
+ }
16972
+ });
16973
+ if (!result.response.ok || result.data === void 0) {
16974
+ throw new Error(
16975
+ `audit list deliveries failed: ${result.response.status} ${result.response.statusText}`
16976
+ );
16977
+ }
16978
+ const body = result.data;
16979
+ return {
16980
+ deliveries: (body.data ?? []).map(_deliveryFromResource),
16981
+ nextCursor: _nextCursorFromLinks(body)
16982
+ };
16983
+ }
16984
+ };
16985
+ var ForwarderActionsClient = class {
16986
+ constructor(_http) {
16987
+ this._http = _http;
16988
+ }
16989
+ /** Retry every failed delivery for a forwarder. Returns a count summary. */
16990
+ async retryFailedDeliveries(forwarderId) {
16991
+ const result = await this._http.POST(
16992
+ "/api/v1/forwarders/{forwarder_id}/actions/retry_failed_deliveries",
16993
+ { params: { path: { forwarder_id: forwarderId } } }
16994
+ );
16995
+ if (!result.response.ok || result.data === void 0) {
16996
+ throw new Error(
16997
+ `audit bulk retry failed: ${result.response.status} ${result.response.statusText}`
16998
+ );
16999
+ }
17000
+ const d = result.data;
17001
+ return {
17002
+ attempted: Number(d.attempted ?? 0),
17003
+ succeeded: Number(d.succeeded ?? 0),
17004
+ failed: Number(d.failed ?? 0)
17005
+ };
17006
+ }
17007
+ };
17008
+ var ForwardersClient = class {
17009
+ constructor(_http) {
17010
+ this._http = _http;
17011
+ this.deliveries = new DeliveriesClient(_http);
17012
+ this.actions = new ForwarderActionsClient(_http);
17013
+ }
17014
+ deliveries;
17015
+ actions;
17016
+ async create(input) {
17017
+ const body = { data: { id: "", type: "forwarder", attributes: _forwarderAttributes(input) } };
17018
+ const result = await this._http.POST("/api/v1/forwarders", {
17019
+ body
17020
+ });
17021
+ if (!result.response.ok || result.data === void 0) {
17022
+ throw new Error(
17023
+ `audit create forwarder failed: ${result.response.status} ${result.response.statusText}`
17024
+ );
17025
+ }
17026
+ return _forwarderFromResource(result.data.data);
17027
+ }
17028
+ async list(params = {}) {
17029
+ const query = {};
17030
+ if (params.forwarderType !== void 0) query["filter[forwarder_type]"] = params.forwarderType;
17031
+ if (params.enabled !== void 0) query["filter[enabled]"] = params.enabled;
17032
+ if (params.pageSize !== void 0) query["page[size]"] = params.pageSize;
17033
+ if (params.pageAfter !== void 0) query["page[after]"] = params.pageAfter;
17034
+ const result = await this._http.GET("/api/v1/forwarders", {
17035
+ params: { query }
17036
+ });
17037
+ if (!result.response.ok || result.data === void 0) {
17038
+ throw new Error(
17039
+ `audit list forwarders failed: ${result.response.status} ${result.response.statusText}`
17040
+ );
17041
+ }
17042
+ const body = result.data;
17043
+ return {
17044
+ forwarders: (body.data ?? []).map(_forwarderFromResource),
17045
+ nextCursor: _nextCursorFromLinks(body)
17046
+ };
17047
+ }
17048
+ async get(forwarderId) {
17049
+ const result = await this._http.GET("/api/v1/forwarders/{forwarder_id}", {
17050
+ params: { path: { forwarder_id: forwarderId } }
17051
+ });
17052
+ if (!result.response.ok || result.data === void 0) {
17053
+ throw new Error(
17054
+ `audit get forwarder failed: ${result.response.status} ${result.response.statusText}`
17055
+ );
17056
+ }
17057
+ return _forwarderFromResource(result.data.data);
17058
+ }
17059
+ async update(forwarderId, input) {
17060
+ const body = {
17061
+ data: { id: forwarderId, type: "forwarder", attributes: _forwarderAttributes(input) }
17062
+ };
17063
+ const result = await this._http.PUT("/api/v1/forwarders/{forwarder_id}", {
17064
+ params: { path: { forwarder_id: forwarderId } },
17065
+ body
17066
+ });
17067
+ if (!result.response.ok || result.data === void 0) {
17068
+ throw new Error(
17069
+ `audit update forwarder failed: ${result.response.status} ${result.response.statusText}`
17070
+ );
17071
+ }
17072
+ return _forwarderFromResource(result.data.data);
17073
+ }
17074
+ async delete(forwarderId) {
17075
+ const result = await this._http.DELETE("/api/v1/forwarders/{forwarder_id}", {
17076
+ params: { path: { forwarder_id: forwarderId } }
17077
+ });
17078
+ if (result.response.status !== 204) {
17079
+ throw new Error(
17080
+ `audit delete forwarder failed: ${result.response.status} ${result.response.statusText}`
17081
+ );
17082
+ }
17083
+ }
17084
+ };
17085
+ var TestForwarderActionsClient = class {
17086
+ constructor(_http) {
17087
+ this._http = _http;
17088
+ }
17089
+ /** Server-side proxy to a customer-supplied URL. SSRF-guarded; the
17090
+ * audit service rejects private/loopback/link-local addresses (incl.
17091
+ * the EC2 IMDS at 169.254.169.254) and ports outside the allowlist. */
17092
+ async execute(input) {
17093
+ const body = {
17094
+ method: input.method ?? "POST",
17095
+ url: input.url,
17096
+ headers: (input.headers ?? []).map((h) => ({ name: h.name, value: h.value })),
17097
+ body: input.body ?? null,
17098
+ success_status: input.successStatus ?? "2xx"
17099
+ };
17100
+ if (input.timeoutMs !== void 0) body.timeout_ms = input.timeoutMs;
17101
+ const result = await this._http.POST("/api/v1/functions/test_forwarder/actions/execute", {
17102
+ // This endpoint serves and accepts plain JSON, NOT JSON:API. The
17103
+ // openapi-fetch client adds its default JSON:API content-type
17104
+ // header; we override here so the server's strict validator
17105
+ // doesn't reject the request.
17106
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
17107
+ body
17108
+ });
17109
+ if (!result.response.ok || result.data === void 0) {
17110
+ throw new Error(
17111
+ `audit test_forwarder failed: ${result.response.status} ${result.response.statusText}`
17112
+ );
17113
+ }
17114
+ const d = result.data;
17115
+ return {
17116
+ succeeded: Boolean(d.succeeded),
17117
+ responseStatus: d.response_status ?? null,
17118
+ responseHeaders: d.response_headers ?? {},
17119
+ responseBody: String(d.response_body ?? ""),
17120
+ latencyMs: d.latency_ms ?? null,
17121
+ error: d.error ?? null
17122
+ };
17123
+ }
17124
+ };
17125
+ var TestForwarderClient = class {
17126
+ actions;
17127
+ constructor(http) {
17128
+ this.actions = new TestForwarderActionsClient(http);
17129
+ }
17130
+ };
17131
+ var FunctionsClient = class {
17132
+ test_forwarder;
17133
+ constructor(http) {
17134
+ this.test_forwarder = new TestForwarderClient(http);
17135
+ }
17136
+ };
16859
17137
  var AuditClient = class {
16860
17138
  events;
17139
+ forwarders;
17140
+ functions;
16861
17141
  constructor(opts) {
16862
17142
  this.events = new EventsClient(opts);
17143
+ this.forwarders = new ForwardersClient(this.events._http);
17144
+ this.functions = new FunctionsClient(this.events._http);
16863
17145
  }
16864
17146
  /** @internal */
16865
17147
  async _close() {
@@ -17530,7 +17812,7 @@ var ConfigClient = class {
17530
17812
  _initialized = false;
17531
17813
  _listeners = [];
17532
17814
  /** @internal */
17533
- constructor(apiKey, timeout, baseUrl) {
17815
+ constructor(apiKey, timeout, baseUrl, extraHeaders) {
17534
17816
  this._apiKey = apiKey;
17535
17817
  const resolvedBaseUrl = baseUrl ?? BASE_URL;
17536
17818
  this._baseUrl = resolvedBaseUrl;
@@ -17538,6 +17820,7 @@ var ConfigClient = class {
17538
17820
  this._http = createClient2({
17539
17821
  baseUrl: resolvedBaseUrl,
17540
17822
  headers: {
17823
+ ...extraHeaders ?? {},
17541
17824
  Authorization: `Bearer ${apiKey}`,
17542
17825
  Accept: "application/json"
17543
17826
  },
@@ -20582,7 +20865,7 @@ var FlagsClient = class {
20582
20865
  /** @internal — set by SmplClient after construction. */
20583
20866
  _parent = null;
20584
20867
  /** @internal */
20585
- constructor(apiKey, ensureWs, timeout, flagsBaseUrl, appBaseUrl, contextBuffer) {
20868
+ constructor(apiKey, ensureWs, timeout, flagsBaseUrl, appBaseUrl, contextBuffer, extraHeaders) {
20586
20869
  this._apiKey = apiKey;
20587
20870
  this._ensureWs = ensureWs;
20588
20871
  const resolvedBaseUrl = flagsBaseUrl ?? FLAGS_BASE_URL;
@@ -20603,9 +20886,11 @@ var FlagsClient = class {
20603
20886
  clearTimeout(timer);
20604
20887
  }
20605
20888
  };
20889
+ const extra = extraHeaders ?? {};
20606
20890
  this._http = createClient4({
20607
20891
  baseUrl: resolvedBaseUrl,
20608
20892
  headers: {
20893
+ ...extra,
20609
20894
  Authorization: `Bearer ${apiKey}`,
20610
20895
  Accept: "application/json"
20611
20896
  },
@@ -20614,6 +20899,7 @@ var FlagsClient = class {
20614
20899
  this._appHttp = createClient4({
20615
20900
  baseUrl: resolvedAppBaseUrl,
20616
20901
  headers: {
20902
+ ...extra,
20617
20903
  Authorization: `Bearer ${apiKey}`,
20618
20904
  Accept: "application/json"
20619
20905
  },
@@ -21213,7 +21499,7 @@ var LoggingClient = class {
21213
21499
  _groupStore = {};
21214
21500
  // key -> level
21215
21501
  /** @internal */
21216
- constructor(apiKey, ensureWs, timeout, baseUrl) {
21502
+ constructor(apiKey, ensureWs, timeout, baseUrl, extraHeaders) {
21217
21503
  this._apiKey = apiKey;
21218
21504
  this._ensureWs = ensureWs;
21219
21505
  const resolvedBaseUrl = baseUrl ?? LOGGING_BASE_URL;
@@ -21222,6 +21508,7 @@ var LoggingClient = class {
21222
21508
  this._http = createClient5({
21223
21509
  baseUrl: resolvedBaseUrl,
21224
21510
  headers: {
21511
+ ...extraHeaders ?? {},
21225
21512
  Authorization: `Bearer ${apiKey}`,
21226
21513
  Accept: "application/json"
21227
21514
  },
@@ -22182,9 +22469,11 @@ var SmplClient = class {
22182
22469
  "lifecycle",
22183
22470
  `SmplClient created (api_key=${maskedKey}, environment=${cfg.environment}, service=${cfg.service})`
22184
22471
  );
22472
+ const extraHeaders = options.extraHeaders ?? {};
22185
22473
  this._appHttp = createClient6({
22186
22474
  baseUrl: appBaseUrl,
22187
22475
  headers: {
22476
+ ...extraHeaders,
22188
22477
  Authorization: `Bearer ${cfg.apiKey}`,
22189
22478
  Accept: "application/json"
22190
22479
  }
@@ -22203,25 +22492,28 @@ var SmplClient = class {
22203
22492
  scheme: cfg.scheme,
22204
22493
  debug: cfg.debug
22205
22494
  });
22206
- this.config = new ConfigClient(cfg.apiKey, this._timeout, configBaseUrl);
22495
+ this.config = new ConfigClient(cfg.apiKey, this._timeout, configBaseUrl, extraHeaders);
22207
22496
  this.flags = new FlagsClient(
22208
22497
  cfg.apiKey,
22209
22498
  () => this._ensureWs(),
22210
22499
  this._timeout,
22211
22500
  flagsBaseUrl,
22212
22501
  appBaseUrl,
22213
- this.manage._contextBuffer
22502
+ this.manage._contextBuffer,
22503
+ extraHeaders
22214
22504
  );
22215
22505
  this.logging = new LoggingClient(
22216
22506
  cfg.apiKey,
22217
22507
  () => this._ensureWs(),
22218
22508
  this._timeout,
22219
- loggingBaseUrl
22509
+ loggingBaseUrl,
22510
+ extraHeaders
22220
22511
  );
22221
22512
  this.audit = new AuditClient({
22222
22513
  apiKey: cfg.apiKey,
22223
22514
  baseUrl: auditBaseUrl,
22224
- timeoutMs: this._timeout
22515
+ timeoutMs: this._timeout,
22516
+ extraHeaders
22225
22517
  });
22226
22518
  this.config._getSharedWs = () => this._ensureWs();
22227
22519
  this.flags._parent = this;