@t2000/cli 10.12.0 → 10.13.1

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.
@@ -12233,6 +12233,57 @@ async function fetchService(base, agent, slug) {
12233
12233
  }
12234
12234
  return match;
12235
12235
  }
12236
+ function requirementFieldMap(listing) {
12237
+ const props = listing.properties;
12238
+ if (props && typeof props === "object" && !Array.isArray(props)) {
12239
+ return props;
12240
+ }
12241
+ return listing;
12242
+ }
12243
+ function requirementHint(value) {
12244
+ return typeof value === "string" ? value : JSON.stringify(value);
12245
+ }
12246
+ function isPlainObject(value) {
12247
+ return typeof value === "object" && value !== null && !Array.isArray(value);
12248
+ }
12249
+ function assertBuyerRequirements(listingRequirements, buyerPayload) {
12250
+ if (listingRequirements == null) {
12251
+ return;
12252
+ }
12253
+ if (isPlainObject(listingRequirements)) {
12254
+ const fields = requirementFieldMap(listingRequirements);
12255
+ const keys = Object.keys(fields);
12256
+ if (keys.length === 0) {
12257
+ return;
12258
+ }
12259
+ if (!isPlainObject(buyerPayload)) {
12260
+ throw new Error(
12261
+ `This service needs a JSON requirements object with: ${keys.join(", ")}. The seller asks for: ${JSON.stringify(fields)}`
12262
+ );
12263
+ }
12264
+ const missing = keys.filter(
12265
+ (key) => String(buyerPayload[key] ?? "").trim().length === 0
12266
+ );
12267
+ if (missing.length > 0) {
12268
+ const hints = missing.map((key) => `${key} \u2014 ${requirementHint(fields[key])}`).join("; ");
12269
+ throw new Error(
12270
+ `Missing required field(s): ${missing.join(", ")}. The seller asks for: ${hints}`
12271
+ );
12272
+ }
12273
+ return;
12274
+ }
12275
+ const hint = requirementHint(listingRequirements);
12276
+ if (typeof buyerPayload === "object" && buyerPayload !== null) {
12277
+ throw new Error(
12278
+ `This service expects free-text requirements, not JSON. The seller asks for: ${hint}`
12279
+ );
12280
+ }
12281
+ if (String(buyerPayload ?? "").trim().length === 0) {
12282
+ throw new Error(
12283
+ `This service needs requirements. The seller asks for: ${hint}`
12284
+ );
12285
+ }
12286
+ }
12236
12287
  async function sha256Hex(content) {
12237
12288
  const digest = await crypto.subtle.digest(
12238
12289
  "SHA-256",
@@ -13200,6 +13251,7 @@ export {
13200
13251
  DEFAULT_COMMERCE_API_BASE,
13201
13252
  listServices,
13202
13253
  fetchService,
13254
+ assertBuyerRequirements,
13203
13255
  putJobSpec,
13204
13256
  getJobSpec,
13205
13257
  SPONSORED_PYTH_DEPENDENT_PROVIDERS,
@@ -13262,4 +13314,4 @@ export {
13262
13314
  @scure/bip39/index.js:
13263
13315
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
13264
13316
  */
13265
- //# sourceMappingURL=chunk-322SPE2Y.js.map
13317
+ //# sourceMappingURL=chunk-I6UGZOTH.js.map