@warmhub/sdk-ts 0.62.0 → 0.63.0

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.
@@ -8311,6 +8311,14 @@ function resolveRetryPolicy(retry) {
8311
8311
  };
8312
8312
  }
8313
8313
  var DEFINITE_CLIENT_REJECT_CODES = /* @__PURE__ */ new Set([
8314
+ "BAD_REQUEST",
8315
+ "METHOD_NOT_SUPPORTED",
8316
+ "PARSE_ERROR",
8317
+ "PAYLOAD_TOO_LARGE",
8318
+ "PRECONDITION_FAILED",
8319
+ "UNAUTHORIZED",
8320
+ "UNPROCESSABLE_CONTENT",
8321
+ "UNSUPPORTED_MEDIA_TYPE",
8314
8322
  "UNAUTHENTICATED",
8315
8323
  "FORBIDDEN",
8316
8324
  "VALIDATION_ERROR",
@@ -8327,6 +8335,7 @@ var DEFINITE_CLIENT_REJECT_CODES = /* @__PURE__ */ new Set([
8327
8335
  // first-chunk wrapper would discard structured retry/validation detail
8328
8336
  // (retryAfter, the failing token, etc.).
8329
8337
  "RATE_LIMITED",
8338
+ "TOO_MANY_REQUESTS",
8330
8339
  "UNRESOLVED_TOKEN"
8331
8340
  ]);
8332
8341
  function extractErrorCode(cause) {
@@ -8340,9 +8349,21 @@ function extractErrorCode(cause) {
8340
8349
  if (typeof dc === "string") return dc;
8341
8350
  return void 0;
8342
8351
  }
8352
+ function extractHttpStatus(cause) {
8353
+ if (!cause || typeof cause !== "object") return void 0;
8354
+ const status = cause.data?.httpStatus;
8355
+ if (typeof status === "number") return status;
8356
+ const warmhubStatus = cause.data?.warmhub?.status;
8357
+ if (typeof warmhubStatus === "number") return warmhubStatus;
8358
+ const direct = cause.status;
8359
+ return typeof direct === "number" ? direct : void 0;
8360
+ }
8361
+ function isDefiniteClientRejectionStatus(status) {
8362
+ return status !== void 0 && status >= 400 && status < 500 && status !== 408;
8363
+ }
8343
8364
  function isDefiniteClientError(cause) {
8344
8365
  const code = extractErrorCode(cause);
8345
- return code !== void 0 && DEFINITE_CLIENT_REJECT_CODES.has(code);
8366
+ return code !== void 0 && DEFINITE_CLIENT_REJECT_CODES.has(code) || isDefiniteClientRejectionStatus(extractHttpStatus(cause));
8346
8367
  }
8347
8368
  function isTransientStreamFailure(cause) {
8348
8369
  if (isDefiniteClientError(cause)) return false;
@@ -8639,23 +8660,6 @@ async function verifyCliCall(request, secrets, opts) {
8639
8660
  args = { ...query };
8640
8661
  } else {
8641
8662
  query = {};
8642
- body = await request.text();
8643
- let parsed;
8644
- try {
8645
- parsed = JSON.parse(body);
8646
- } catch {
8647
- throw new CliCallVerificationError(
8648
- "invalid-body",
8649
- "POST body is not valid JSON"
8650
- );
8651
- }
8652
- if (!isArgsRecord(parsed)) {
8653
- throw new CliCallVerificationError(
8654
- "invalid-body",
8655
- "POST body must be a JSON object of primitive args (string / number / boolean)"
8656
- );
8657
- }
8658
- args = parsed;
8659
8663
  }
8660
8664
  if (hasSigning) {
8661
8665
  const signature = request.headers.get(CLI_SIGNATURE_HEADER);
@@ -8679,6 +8683,7 @@ async function verifyCliCall(request, secrets, opts) {
8679
8683
  `${CLI_TIMESTAMP_HEADER} must be an integer unix seconds value; got "${timestampHeader}"`
8680
8684
  );
8681
8685
  }
8686
+ body = await bodyTextForVerification(request, cliMethod, body);
8682
8687
  const verification = await verifyCliRequest({
8683
8688
  secret: secrets.CLI_SIGNING_SECRET,
8684
8689
  method: cliMethod,
@@ -8728,8 +8733,35 @@ async function verifyCliCall(request, secrets, opts) {
8728
8733
  );
8729
8734
  }
8730
8735
  }
8736
+ if (args === void 0) {
8737
+ body = await bodyTextForVerification(request, cliMethod, body);
8738
+ args = parseBodyArgs(body);
8739
+ }
8731
8740
  return { method: cliMethod, installRepo, args };
8732
8741
  }
8742
+ async function bodyTextForVerification(request, method, existing) {
8743
+ if (!cliMethodHasBody(method)) return "";
8744
+ if (existing !== void 0) return existing;
8745
+ return request.text();
8746
+ }
8747
+ function parseBodyArgs(body) {
8748
+ let parsed;
8749
+ try {
8750
+ parsed = JSON.parse(body);
8751
+ } catch {
8752
+ throw new CliCallVerificationError(
8753
+ "invalid-body",
8754
+ "POST body is not valid JSON"
8755
+ );
8756
+ }
8757
+ if (!isArgsRecord(parsed)) {
8758
+ throw new CliCallVerificationError(
8759
+ "invalid-body",
8760
+ "POST body must be a JSON object of primitive args (string / number / boolean)"
8761
+ );
8762
+ }
8763
+ return parsed;
8764
+ }
8733
8765
  function isNonEmpty(value) {
8734
8766
  return typeof value === "string" && value.length > 0;
8735
8767
  }
@@ -8979,7 +9011,7 @@ var OperationBuilder = class {
8979
9011
  * Set `kind: 'thing'` explicitly for hierarchical thing names that would otherwise look like assertion paths.
8980
9012
  */
8981
9013
  add(op) {
8982
- this.assertNotSubmitted();
9014
+ this.assertCanModify();
8983
9015
  const normalized = { ...op };
8984
9016
  delete normalized.operation;
8985
9017
  const shapeWref = inferShapeForAdd(normalized);
@@ -9025,7 +9057,7 @@ var OperationBuilder = class {
9025
9057
  * The target can be supplied as `name` or `wref`. When shape definitions were provided to the constructor, revise data is validated locally before the operation is queued.
9026
9058
  */
9027
9059
  revise(op) {
9028
- this.assertNotSubmitted();
9060
+ this.assertCanModify();
9029
9061
  const normalized = { ...op };
9030
9062
  delete normalized.operation;
9031
9063
  const target = normalized.name ?? normalized.wref;
@@ -9066,7 +9098,7 @@ var OperationBuilder = class {
9066
9098
  * Pass a wref string shorthand or an object with a target name, optional kind safety hint, and optional reason.
9067
9099
  */
9068
9100
  retract(target) {
9069
- this.assertNotSubmitted();
9101
+ this.assertCanModify();
9070
9102
  const op = typeof target === "string" ? Object.freeze({ operation: "retract", name: target }) : Object.freeze({
9071
9103
  operation: "retract",
9072
9104
  name: target.name,
@@ -9083,7 +9115,7 @@ var OperationBuilder = class {
9083
9115
  * The returned array is read-only; use `add`, `revise`, and `retract` to modify the builder.
9084
9116
  */
9085
9117
  get operations() {
9086
- return this.ops;
9118
+ return Object.freeze([...this.ops]);
9087
9119
  }
9088
9120
  /**
9089
9121
  * Return the number of queued operations.
@@ -9268,6 +9300,14 @@ var OperationBuilder = class {
9268
9300
  throw new Error("OperationBuilder: already submitted, cannot modify");
9269
9301
  }
9270
9302
  }
9303
+ assertCanModify() {
9304
+ this.assertNotSubmitted();
9305
+ if (this.inFlight) {
9306
+ throw new Error(
9307
+ "OperationBuilder: stream submission already in flight, cannot modify"
9308
+ );
9309
+ }
9310
+ }
9271
9311
  };
9272
9312
 
9273
9313
  // src/index.ts
@@ -9298,7 +9338,7 @@ function validateWarmHubClientOptions(options) {
9298
9338
  throw new TypeError(`Unknown WarmHubClient option "${key}"${hint}`);
9299
9339
  }
9300
9340
  }
9301
- var SDK_VERSION = "0.62.0" ;
9341
+ var SDK_VERSION = "0.63.0" ;
9302
9342
  var DEFAULT_API_URL = "https://api.warmhub.ai";
9303
9343
  var UNBATCHED_TRPC_PATHS = /* @__PURE__ */ new Set([
9304
9344
  "repo.shapeInstanceCounts",
@@ -9420,6 +9460,42 @@ function sanitizeSubscriptionUpdateInput(input) {
9420
9460
  function resolveFunctionLogMode(mode) {
9421
9461
  return mode ?? "off";
9422
9462
  }
9463
+ function trpcClientCodeToWarmHubCode(code) {
9464
+ switch (code) {
9465
+ case "BAD_REQUEST":
9466
+ case "PARSE_ERROR":
9467
+ case "PAYLOAD_TOO_LARGE":
9468
+ case "UNPROCESSABLE_CONTENT":
9469
+ case "UNSUPPORTED_MEDIA_TYPE":
9470
+ return "VALIDATION_ERROR";
9471
+ case "METHOD_NOT_SUPPORTED":
9472
+ return "NOT_FOUND";
9473
+ case "UNAUTHORIZED":
9474
+ return "UNAUTHENTICATED";
9475
+ case "FORBIDDEN":
9476
+ return "FORBIDDEN";
9477
+ case "NOT_FOUND":
9478
+ return "NOT_FOUND";
9479
+ case "CONFLICT":
9480
+ return "CONFLICT";
9481
+ case "PRECONDITION_FAILED":
9482
+ return "PRECONDITION_FAILED";
9483
+ case "TOO_MANY_REQUESTS":
9484
+ return "RATE_LIMITED";
9485
+ default:
9486
+ return void 0;
9487
+ }
9488
+ }
9489
+ function trpcHttpStatusToWarmHubCode(status) {
9490
+ if (status === void 0 || status === 408) return void 0;
9491
+ if (status === 405) return "NOT_FOUND";
9492
+ if (status === 412) return "PRECONDITION_FAILED";
9493
+ if (status === 422) return "VALIDATION_ERROR";
9494
+ const mapped = httpStatusToWarmHubCode(status);
9495
+ if (mapped !== "BACKEND") return mapped;
9496
+ if (status >= 400 && status < 500) return "VALIDATION_ERROR";
9497
+ return mapped;
9498
+ }
9423
9499
  var INTERNAL_PATTERNS = [
9424
9500
  /\bselect\b.+?\bfrom\b/i,
9425
9501
  /\binsert\b.+?\binto\b/i,
@@ -9511,13 +9587,15 @@ function toWarmHubError(error) {
9511
9587
  }
9512
9588
  const data = error.data;
9513
9589
  const wireCode = data?.warmhub?.code;
9590
+ const trpcCode = typeof data?.code === "string" ? trpcClientCodeToWarmHubCode(data.code) : void 0;
9591
+ const trpcStatus = trpcHttpStatusToWarmHubCode(data?.httpStatus);
9514
9592
  const message = data?.warmhub?.message ?? sanitizeErrorMessage(error.message);
9515
9593
  return new WarmHubError(
9516
- wireCode ?? "BACKEND",
9594
+ wireCode ?? trpcCode ?? trpcStatus ?? "BACKEND",
9517
9595
  message,
9518
- data?.warmhub?.status,
9596
+ data?.warmhub?.status ?? data?.httpStatus,
9519
9597
  data?.warmhub?.hint,
9520
- data?.warmhub?.retryAfter,
9598
+ data?.warmhub?.retryAfter ?? data?.retryAfter,
9521
9599
  wireCode,
9522
9600
  data?.warmhub?.details
9523
9601
  );
@@ -9693,6 +9771,21 @@ var WarmHubClient = class _WarmHubClient {
9693
9771
  }
9694
9772
  }
9695
9773
  };
9774
+ /**
9775
+ * Homepage surfaces.
9776
+ */
9777
+ homepage = {
9778
+ /**
9779
+ * Return manually curated featured homepage lists.
9780
+ */
9781
+ featuredLists: async () => {
9782
+ try {
9783
+ return await this.trpc.homepage.featuredLists.query();
9784
+ } catch (error) {
9785
+ throw toWarmHubError(error);
9786
+ }
9787
+ }
9788
+ };
9696
9789
  /**
9697
9790
  * Effective-access resolution for UI gating and service-side authorization.
9698
9791
  * First-party surface (web UI + whedge edge); the underlying `access.resolve`
@@ -11087,14 +11180,15 @@ var WarmHubClient = class _WarmHubClient {
11087
11180
  }
11088
11181
  },
11089
11182
  /**
11090
- * Claim one action delivery run for processing.
11183
+ * Claim one action delivery for processing.
11091
11184
  */
11092
- claimDelivery: async (orgName, repoName, runId, holderId) => {
11185
+ claimDelivery: async (orgName, repoName, target, holderId) => {
11186
+ const deliveryTarget = typeof target === "string" ? { runId: target } : target;
11093
11187
  try {
11094
11188
  return await this.trpc.action.claimDelivery.mutate({
11095
11189
  orgName,
11096
11190
  repoName,
11097
- runId,
11191
+ ...deliveryTarget,
11098
11192
  holderId
11099
11193
  });
11100
11194
  } catch (error) {
@@ -11102,14 +11196,15 @@ var WarmHubClient = class _WarmHubClient {
11102
11196
  }
11103
11197
  },
11104
11198
  /**
11105
- * Mark one claimed action delivery run as complete.
11199
+ * Mark one claimed action delivery as complete.
11106
11200
  */
11107
- completeDelivery: async (orgName, repoName, runId, holderId) => {
11201
+ completeDelivery: async (orgName, repoName, target, holderId) => {
11202
+ const deliveryTarget = typeof target === "string" ? { runId: target } : target;
11108
11203
  try {
11109
11204
  return await this.trpc.action.completeDelivery.mutate({
11110
11205
  orgName,
11111
11206
  repoName,
11112
- runId,
11207
+ ...deliveryTarget,
11113
11208
  holderId
11114
11209
  });
11115
11210
  } catch (error) {
@@ -12515,5 +12610,5 @@ re2js/build/index.js:
12515
12610
  */
12516
12611
 
12517
12612
  export { AllStreamOperationsFailedError, CLI_INSTALL_REPO_HEADER, CLI_SIGNATURE_HEADER, CLI_TIMESTAMP_HEADER, CONTENT_FIELD_LIMIT_ERROR, CliCallVerificationError, DEFAULT_API_URL, DEFAULT_STREAM_CHUNK_SIZE, MAX_CONTENT_FIELD_BYTES, MAX_STREAM_APPEND_OPERATION_COUNT2 as MAX_STREAM_APPEND_OPERATION_COUNT, OperationBuilder, PartialStreamSubmissionError, SDK_VERSION, WarmHubClient, WarmHubError, connectionErrorMessage, contentFieldLimitError, countStreamAppendResultStatuses, isConnectionError, isRetryable, isWarmHubError, normalizeWref, resolveFunctionLogMode, sanitizeErrorMessage, sdkVersionIsBelowMinimum, streamAppendResultStatus, submitOperationsViaStream, toWarmHubError, validateAgainstShape, verifyCliCall };
12518
- //# sourceMappingURL=chunk-CN4352BX.js.map
12519
- //# sourceMappingURL=chunk-CN4352BX.js.map
12613
+ //# sourceMappingURL=chunk-JPX7ZWWE.js.map
12614
+ //# sourceMappingURL=chunk-JPX7ZWWE.js.map