@smplkit/sdk 3.0.4 → 3.0.6

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
@@ -19102,13 +19102,23 @@ var LogGroup = class {
19102
19102
  if (this._client === null) {
19103
19103
  throw new Error("LogGroup was constructed without a client; cannot save");
19104
19104
  }
19105
- if (!this._client._saveGroup) {
19106
- throw new Error(
19107
- "LogGroup models obtained from the runtime LoggingClient cannot be saved. Use mgmt.logGroups.new(...) (or client.manage.logGroups.*) to author groups."
19108
- );
19105
+ if (this.createdAt === null) {
19106
+ if (!this._client._createGroup) {
19107
+ throw new Error(
19108
+ "LogGroup models obtained from the runtime LoggingClient cannot be saved. Use mgmt.logGroups.new(...) (or client.manage.logGroups.*) to author groups."
19109
+ );
19110
+ }
19111
+ const created = await this._client._createGroup(this);
19112
+ this._apply(created);
19113
+ } else {
19114
+ if (!this._client._updateGroup) {
19115
+ throw new Error(
19116
+ "LogGroup models obtained from the runtime LoggingClient cannot be saved. Use mgmt.logGroups.new(...) (or client.manage.logGroups.*) to author groups."
19117
+ );
19118
+ }
19119
+ const updated = await this._client._updateGroup(this);
19120
+ this._apply(updated);
19109
19121
  }
19110
- const saved = await this._client._saveGroup(this);
19111
- this._apply(saved);
19112
19122
  }
19113
19123
  async delete() {
19114
19124
  if (this._client === null || this.id === null) {
@@ -19424,9 +19434,28 @@ var LogGroupsClient = class {
19424
19434
  wrapFetchError3(err);
19425
19435
  }
19426
19436
  }
19427
- /** @internal — called by `LogGroup.save()`. PUT /log_groups/{id} is upsert. */
19428
- async _saveGroup(group) {
19429
- if (group.id === null) throw new Error("Cannot save a LogGroup with no id");
19437
+ /**
19438
+ * @internal — called by `LogGroup.save()` for new groups.
19439
+ * POST /api/v1/log_groups creates a new log group. The {id} PUT endpoint
19440
+ * is update-only on the server and returns 404 for non-existent ids,
19441
+ * so create and update have to dispatch to different endpoints.
19442
+ */
19443
+ async _createGroup(group) {
19444
+ const body = groupToBody(group);
19445
+ let data;
19446
+ try {
19447
+ const result = await this._http.POST("/api/v1/log_groups", { body });
19448
+ if (!result.response.ok) await checkError3(result.response);
19449
+ data = result.data;
19450
+ } catch (err) {
19451
+ wrapFetchError3(err);
19452
+ }
19453
+ if (!data || !data.data) throw new SmplValidationError("Failed to create log group");
19454
+ return resourceToLogGroup(data.data, this);
19455
+ }
19456
+ /** @internal — called by `LogGroup.save()` for existing groups. */
19457
+ async _updateGroup(group) {
19458
+ if (group.id === null) throw new Error("Cannot update a LogGroup with no id");
19430
19459
  const body = groupToBody(group);
19431
19460
  let data;
19432
19461
  try {
@@ -19439,7 +19468,9 @@ var LogGroupsClient = class {
19439
19468
  } catch (err) {
19440
19469
  wrapFetchError3(err);
19441
19470
  }
19442
- if (!data || !data.data) throw new SmplValidationError("Failed to save log group");
19471
+ if (!data || !data.data) {
19472
+ throw new SmplValidationError(`Failed to update log group ${group.id}`);
19473
+ }
19443
19474
  return resourceToLogGroup(data.data, this);
19444
19475
  }
19445
19476
  };