@smplkit/sdk 3.0.86 → 3.0.87

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
@@ -18969,17 +18969,32 @@ async function checkError(response, error) {
18969
18969
  }
18970
18970
  throwForStatus(response.status, body);
18971
18971
  }
18972
- function buildBody(config) {
18972
+ function buildAttrs(config) {
18973
18973
  const attrs = { name: config.name };
18974
18974
  if (config.description !== null) attrs.description = config.description;
18975
18975
  if (config.parent !== null) attrs.parent = config.parent;
18976
18976
  attrs.items = config._itemsRawDirect;
18977
18977
  attrs.environments = environmentsToWire(config._environmentsDirect);
18978
+ return attrs;
18979
+ }
18980
+ function buildCreateBody(config) {
18981
+ if (config.id === null) {
18982
+ throw new SmplValidationError("Cannot create a Config without an id");
18983
+ }
18984
+ return {
18985
+ data: {
18986
+ id: config.id,
18987
+ type: "config",
18988
+ attributes: buildAttrs(config)
18989
+ }
18990
+ };
18991
+ }
18992
+ function buildUpdateBody(config) {
18978
18993
  return {
18979
18994
  data: {
18980
18995
  id: config.id ?? null,
18981
18996
  type: "config",
18982
- attributes: attrs
18997
+ attributes: buildAttrs(config)
18983
18998
  }
18984
18999
  };
18985
19000
  }
@@ -19169,7 +19184,7 @@ var ManagementConfigClient = class {
19169
19184
  }
19170
19185
  /** @internal — called by `Config.save()` for new resources. */
19171
19186
  async _createConfig(config) {
19172
- const body = buildBody(config);
19187
+ const body = buildCreateBody(config);
19173
19188
  let data;
19174
19189
  try {
19175
19190
  const result = await this._http.POST("/api/v1/configs", { body });
@@ -19184,7 +19199,7 @@ var ManagementConfigClient = class {
19184
19199
  /** @internal — called by `Config.save()` for existing resources. */
19185
19200
  async _updateConfig(config) {
19186
19201
  if (config.id === null) throw new Error("Cannot update a Config with no id");
19187
- const body = buildBody(config);
19202
+ const body = buildUpdateBody(config);
19188
19203
  let data;
19189
19204
  try {
19190
19205
  const result = await this._http.PUT("/api/v1/configs/{id}", {
@@ -19263,19 +19278,34 @@ function environmentsToWire2(envs) {
19263
19278
  }
19264
19279
  return out;
19265
19280
  }
19266
- function flagToBody(flag) {
19281
+ function flagAttrs(flag) {
19282
+ return {
19283
+ name: flag.name,
19284
+ description: flag.description ?? "",
19285
+ type: flag.type,
19286
+ default: flag.default,
19287
+ values: flag.values?.map((v) => ({ name: v.name, value: v.value })),
19288
+ ...Object.keys(flag.environments).length > 0 ? { environments: environmentsToWire2(flag._envsRaw()) } : {}
19289
+ };
19290
+ }
19291
+ function flagToCreateBody(flag) {
19292
+ if (flag.id === null) {
19293
+ throw new SmplValidationError("Cannot create a Flag without an id");
19294
+ }
19267
19295
  return {
19268
19296
  data: {
19269
19297
  id: flag.id,
19270
19298
  type: "flag",
19271
- attributes: {
19272
- name: flag.name,
19273
- description: flag.description ?? "",
19274
- type: flag.type,
19275
- default: flag.default,
19276
- values: flag.values?.map((v) => ({ name: v.name, value: v.value })),
19277
- ...Object.keys(flag.environments).length > 0 ? { environments: environmentsToWire2(flag._envsRaw()) } : {}
19278
- }
19299
+ attributes: flagAttrs(flag)
19300
+ }
19301
+ };
19302
+ }
19303
+ function flagToUpdateBody(flag) {
19304
+ return {
19305
+ data: {
19306
+ id: flag.id ?? null,
19307
+ type: "flag",
19308
+ attributes: flagAttrs(flag)
19279
19309
  }
19280
19310
  };
19281
19311
  }
@@ -19500,7 +19530,7 @@ var ManagementFlagsClient = class {
19500
19530
  }
19501
19531
  /** @internal — called by `Flag.save()` for new resources. */
19502
19532
  async _createFlag(flag) {
19503
- const body = flagToBody(flag);
19533
+ const body = flagToCreateBody(flag);
19504
19534
  let data;
19505
19535
  try {
19506
19536
  const result = await this._http.POST("/api/v1/flags", { body });
@@ -19515,7 +19545,7 @@ var ManagementFlagsClient = class {
19515
19545
  /** @internal — called by `Flag.save()` for existing resources. */
19516
19546
  async _updateFlag(flag) {
19517
19547
  if (flag.id === null) throw new Error("Cannot update a Flag with no id");
19518
- const body = flagToBody(flag);
19548
+ const body = flagToUpdateBody(flag);
19519
19549
  let data;
19520
19550
  try {
19521
19551
  const result = await this._http.PUT("/api/v1/flags/{id}", {
@@ -19907,7 +19937,7 @@ function loggerToBody(logger) {
19907
19937
  data: { id: logger.id, type: "logger", attributes: attrs }
19908
19938
  };
19909
19939
  }
19910
- function groupToBody(group) {
19940
+ function groupAttrs(group) {
19911
19941
  const attrs = {
19912
19942
  name: group.name
19913
19943
  };
@@ -19917,8 +19947,19 @@ function groupToBody(group) {
19917
19947
  if (Object.keys(wire).length > 0) {
19918
19948
  attrs.environments = wire;
19919
19949
  }
19950
+ return attrs;
19951
+ }
19952
+ function groupToCreateBody(group) {
19953
+ if (group.id === null) {
19954
+ throw new SmplValidationError("Cannot create a LogGroup without an id");
19955
+ }
19956
+ return {
19957
+ data: { id: group.id, type: "log_group", attributes: groupAttrs(group) }
19958
+ };
19959
+ }
19960
+ function groupToUpdateBody(group) {
19920
19961
  return {
19921
- data: { id: group.id, type: "log_group", attributes: attrs }
19962
+ data: { id: group.id ?? null, type: "log_group", attributes: groupAttrs(group) }
19922
19963
  };
19923
19964
  }
19924
19965
  var LoggerRegistrationBuffer = class {
@@ -20152,7 +20193,7 @@ var LogGroupsClient = class {
20152
20193
  * so create and update have to dispatch to different endpoints.
20153
20194
  */
20154
20195
  async _createGroup(group) {
20155
- const body = groupToBody(group);
20196
+ const body = groupToCreateBody(group);
20156
20197
  let data;
20157
20198
  try {
20158
20199
  const result = await this._http.POST("/api/v1/log_groups", { body });
@@ -20167,7 +20208,7 @@ var LogGroupsClient = class {
20167
20208
  /** @internal — called by `LogGroup.save()` for existing groups. */
20168
20209
  async _updateGroup(group) {
20169
20210
  if (group.id === null) throw new Error("Cannot update a LogGroup with no id");
20170
- const body = groupToBody(group);
20211
+ const body = groupToUpdateBody(group);
20171
20212
  let data;
20172
20213
  try {
20173
20214
  const result = await this._http.PUT("/api/v1/log_groups/{id}", {
@@ -20434,6 +20475,11 @@ var ForwardersClient = class {
20434
20475
  * Construct an unsaved {@link Forwarder}. Call {@link Forwarder.save}
20435
20476
  * to persist.
20436
20477
  *
20478
+ * @param key Caller-supplied stable identifier for the
20479
+ * forwarder. Becomes the resource's `id`
20480
+ * and is the unique key used by the audit
20481
+ * service to address it on subsequent
20482
+ * GET / PUT / DELETE calls.
20437
20483
  * @param fields.name Display name. Free-form.
20438
20484
  * @param fields.forwarderType Destination type — see {@link ForwarderType}.
20439
20485
  * @param fields.configuration Destination HTTP request configuration.
@@ -20456,8 +20502,9 @@ var ForwardersClient = class {
20456
20502
  * expression. Must be supplied together
20457
20503
  * with `transformType` (both or neither).
20458
20504
  */
20459
- new(fields) {
20505
+ new(key, fields) {
20460
20506
  return new Forwarder(this, {
20507
+ id: key,
20461
20508
  name: fields.name,
20462
20509
  forwarderType: fields.forwarderType,
20463
20510
  configuration: fields.configuration,
@@ -20531,10 +20578,21 @@ var ForwardersClient = class {
20531
20578
  }
20532
20579
  /**
20533
20580
  * @internal Called by `Forwarder.save()` on unsaved instances.
20581
+ *
20582
+ * The audit service requires a caller-supplied `data.id` on create —
20583
+ * the forwarder's stable key, propagated from
20584
+ * `mgmt.audit.forwarders.new(key, ...)`.
20534
20585
  */
20535
20586
  async _createForwarder(forwarder) {
20587
+ if (forwarder.id === null) {
20588
+ throw new Error("cannot create a Forwarder without an id (pass key to forwarders.new)");
20589
+ }
20536
20590
  const body = {
20537
- data: { id: "", type: "forwarder", attributes: _forwarderAttrs(forwarder) }
20591
+ data: {
20592
+ id: forwarder.id,
20593
+ type: "forwarder",
20594
+ attributes: _forwarderAttrs(forwarder)
20595
+ }
20538
20596
  };
20539
20597
  let data;
20540
20598
  try {
@@ -20877,6 +20935,9 @@ var EnvironmentsClient = class {
20877
20935
  }
20878
20936
  /** @internal */
20879
20937
  async _create(env) {
20938
+ if (env.id === null) {
20939
+ throw new SmplValidationError("Cannot create an Environment without an id");
20940
+ }
20880
20941
  const body = {
20881
20942
  data: {
20882
20943
  id: env.id,