@siglume/api-sdk 1.0.0 → 1.2.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.
@@ -177,6 +177,61 @@ var init_utils = __esm({
177
177
  }
178
178
  });
179
179
 
180
+ // src/types.ts
181
+ var PermissionClass, ApprovalMode, Environment, PriceModel, AppCategory, MINIMUM_JPY_OPERATION_PRICE_MINOR, ToolManualPermissionClass, SettlementMode;
182
+ var init_types = __esm({
183
+ "src/types.ts"() {
184
+ "use strict";
185
+ PermissionClass = {
186
+ READ_ONLY: "read-only",
187
+ ACTION: "action",
188
+ PAYMENT: "payment",
189
+ /** @deprecated Use READ_ONLY. Behaves identically. */
190
+ RECOMMENDATION: "recommendation"
191
+ };
192
+ ApprovalMode = {
193
+ AUTO: "auto",
194
+ BUDGET_BOUNDED: "budget-bounded",
195
+ ALWAYS_ASK: "always-ask",
196
+ DENY: "deny"
197
+ };
198
+ Environment = {
199
+ SANDBOX: "sandbox",
200
+ LIVE: "live"
201
+ };
202
+ PriceModel = {
203
+ FREE: "free",
204
+ SUBSCRIPTION: "subscription",
205
+ ONE_TIME: "one_time",
206
+ BUNDLE: "bundle",
207
+ USAGE_BASED: "usage_based",
208
+ PER_ACTION: "per_action"
209
+ };
210
+ AppCategory = {
211
+ COMMERCE: "commerce",
212
+ BOOKING: "booking",
213
+ CRM: "crm",
214
+ FINANCE: "finance",
215
+ DOCUMENT: "document",
216
+ COMMUNICATION: "communication",
217
+ MONITORING: "monitoring",
218
+ OTHER: "other"
219
+ };
220
+ MINIMUM_JPY_OPERATION_PRICE_MINOR = 15;
221
+ ToolManualPermissionClass = {
222
+ READ_ONLY: "read_only",
223
+ ACTION: "action",
224
+ PAYMENT: "payment"
225
+ };
226
+ SettlementMode = {
227
+ STRIPE_CHECKOUT: "stripe_checkout",
228
+ STRIPE_PAYMENT_INTENT: "stripe_payment_intent",
229
+ POLYGON_MANDATE: "polygon_mandate",
230
+ EMBEDDED_WALLET_CHARGE: "embedded_wallet_charge"
231
+ };
232
+ }
233
+ });
234
+
180
235
  // src/webhooks.ts
181
236
  function isRecord2(value) {
182
237
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1298,6 +1353,58 @@ function validateSaveDataSchema(schema, fieldName) {
1298
1353
  }
1299
1354
  }
1300
1355
  }
1356
+ function validatePricingPlanFloor(plan, defaultCurrency) {
1357
+ if (plan === void 0 || plan === null) {
1358
+ return;
1359
+ }
1360
+ if (!isRecord(plan)) {
1361
+ throw new SiglumeClientError("AppManifest.pricing_plan must be an object when provided.");
1362
+ }
1363
+ const items = plan.items;
1364
+ if (items === void 0 || items === null) {
1365
+ return;
1366
+ }
1367
+ if (!Array.isArray(items)) {
1368
+ throw new SiglumeClientError("AppManifest.pricing_plan.items must be an array when provided.");
1369
+ }
1370
+ const planCurrency = String(plan.currency ?? defaultCurrency ?? "").trim().toUpperCase();
1371
+ const seenKeys = /* @__PURE__ */ new Set();
1372
+ items.forEach((item, index) => {
1373
+ if (!isRecord(item)) {
1374
+ throw new SiglumeClientError(`AppManifest.pricing_plan.items[${index}] must be an object.`);
1375
+ }
1376
+ const itemKey = String(
1377
+ item.key ?? item.operation ?? item.operation_key ?? item.request_type ?? item.receipt_code ?? item.action ?? ""
1378
+ ).trim();
1379
+ if (!itemKey) {
1380
+ throw new SiglumeClientError(`AppManifest.pricing_plan.items[${index}].key is required.`);
1381
+ }
1382
+ if (seenKeys.has(itemKey)) {
1383
+ throw new SiglumeClientError(`AppManifest.pricing_plan.items[${index}].key duplicates ${itemKey}.`);
1384
+ }
1385
+ seenKeys.add(itemKey);
1386
+ const amountRaw = item.price_minor ?? item.amount_minor ?? item.cost_minor ?? item.value_minor;
1387
+ if (amountRaw === void 0 || amountRaw === null) {
1388
+ throw new SiglumeClientError(`AppManifest.pricing_plan.items[${index}].price_minor is required.`);
1389
+ }
1390
+ const amountMinor = typeof amountRaw === "number" ? amountRaw : typeof amountRaw === "string" && amountRaw.trim() ? Number(amountRaw) : NaN;
1391
+ if (!Number.isInteger(amountMinor)) {
1392
+ throw new SiglumeClientError(`AppManifest.pricing_plan.items[${index}].price_minor must be an integer.`);
1393
+ }
1394
+ if (amountMinor < 0) {
1395
+ throw new SiglumeClientError(`AppManifest.pricing_plan.items[${index}].price_minor must be zero or positive.`);
1396
+ }
1397
+ const currency = String(item.currency ?? planCurrency ?? defaultCurrency ?? "").trim().toUpperCase();
1398
+ if (MINIMUM_JPY_OPERATION_PRICE_CURRENCIES.has(currency) && amountMinor > 0 && amountMinor < MINIMUM_JPY_OPERATION_PRICE_MINOR) {
1399
+ throw new SiglumeClientError(
1400
+ `AppManifest.pricing_plan.items[${index}].price_minor must be 0 or at least ${MINIMUM_JPY_OPERATION_PRICE_MINOR} for JPY/JPYC operation billing.`
1401
+ );
1402
+ }
1403
+ });
1404
+ }
1405
+ function pricingPlanHasItems(plan) {
1406
+ return isRecord(plan) && Array.isArray(plan.items) && plan.items.length > 0;
1407
+ }
1301
1408
  function buildToolManualQualityReport(payload) {
1302
1409
  const qualityBlock = isRecord(payload.quality) ? payload.quality : payload;
1303
1410
  const issues = [];
@@ -1373,6 +1480,7 @@ function buildUrl(baseUrl, path, params) {
1373
1480
  }
1374
1481
  function parseListing(data) {
1375
1482
  const metadata = isRecord(data.metadata) ? data.metadata : {};
1483
+ const pricing_plan = isRecord(data.pricing_plan) ? data.pricing_plan : isRecord(metadata.pricing_plan) ? metadata.pricing_plan : null;
1376
1484
  const persistence = isRecord(data.persistence) ? data.persistence : isRecord(metadata.persistence) ? metadata.persistence : {};
1377
1485
  return {
1378
1486
  listing_id: String(data.listing_id ?? data.id ?? ""),
@@ -1386,6 +1494,8 @@ function parseListing(data) {
1386
1494
  dry_run_supported: Boolean(data.dry_run_supported ?? false),
1387
1495
  price_model: stringOrNull(data.price_model),
1388
1496
  price_value_minor: Number(data.price_value_minor ?? 0),
1497
+ pricing_plan,
1498
+ billing_timing: String(data.billing_timing ?? metadata.billing_timing ?? "post"),
1389
1499
  currency: String(data.currency ?? "USD"),
1390
1500
  allow_free_trial: Boolean(data.allow_free_trial ?? false),
1391
1501
  free_trial_duration_days: Number(data.free_trial_duration_days ?? 30),
@@ -2483,10 +2593,11 @@ function cloneJsonLike(value) {
2483
2593
  }
2484
2594
  return value;
2485
2595
  }
2486
- var DEFAULT_SIGLUME_API_BASE, RETRYABLE_STATUS_CODES, CursorPageResult, SiglumeClient;
2596
+ var DEFAULT_SIGLUME_API_BASE, RETRYABLE_STATUS_CODES, MINIMUM_JPY_OPERATION_PRICE_CURRENCIES, CursorPageResult, SiglumeClient;
2487
2597
  var init_client = __esm({
2488
2598
  "src/client.ts"() {
2489
2599
  "use strict";
2600
+ init_types();
2490
2601
  init_errors();
2491
2602
  init_webhooks();
2492
2603
  init_web3();
@@ -2494,6 +2605,7 @@ var init_client = __esm({
2494
2605
  init_utils();
2495
2606
  DEFAULT_SIGLUME_API_BASE = "https://siglume.com/v1";
2496
2607
  RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
2608
+ MINIMUM_JPY_OPERATION_PRICE_CURRENCIES = /* @__PURE__ */ new Set(["JPY", "JPYC"]);
2497
2609
  CursorPageResult = class {
2498
2610
  items;
2499
2611
  next_cursor;
@@ -2601,6 +2713,8 @@ var init_client = __esm({
2601
2713
  "jurisdiction",
2602
2714
  "price_model",
2603
2715
  "price_value_minor",
2716
+ "pricing_plan",
2717
+ "billing_timing",
2604
2718
  "currency",
2605
2719
  "allow_free_trial",
2606
2720
  "free_trial_duration_days",
@@ -2617,6 +2731,16 @@ var init_client = __esm({
2617
2731
  payload[fieldName] = value;
2618
2732
  }
2619
2733
  }
2734
+ if (payload.pricing_plan !== void 0 && (typeof payload.pricing_plan !== "object" || Array.isArray(payload.pricing_plan))) {
2735
+ throw new SiglumeClientError("AppManifest.pricing_plan must be an object when provided.");
2736
+ }
2737
+ if (payload.billing_timing !== void 0 && payload.billing_timing !== null) {
2738
+ const billingTiming = String(payload.billing_timing || "post").trim().toLowerCase();
2739
+ if (billingTiming !== "post" && billingTiming !== "prepay") {
2740
+ throw new SiglumeClientError("AppManifest.billing_timing must be 'post' or 'prepay'.");
2741
+ }
2742
+ payload.billing_timing = billingTiming;
2743
+ }
2620
2744
  if (payload.store_vertical === void 0 || payload.store_vertical === null) {
2621
2745
  throw new SiglumeClientError(
2622
2746
  "AppManifest.store_vertical is required. Choose 'api' for normal API Store listings or 'game' for API games."
@@ -2632,6 +2756,13 @@ var init_client = __esm({
2632
2756
  throw new SiglumeClientError(`AppManifest.currency must be 'USD' or 'JPY'. Got ${String(payload.currency)}.`);
2633
2757
  }
2634
2758
  payload.currency = currency;
2759
+ if (payload.pricing_plan !== void 0) {
2760
+ validatePricingPlanFloor(payload.pricing_plan, currency);
2761
+ }
2762
+ const priceModel = String(payload.price_model ?? "free").trim().toLowerCase();
2763
+ if ((priceModel === "usage_based" || priceModel === "per_action") && !pricingPlanHasItems(payload.pricing_plan)) {
2764
+ throw new SiglumeClientError("AppManifest.pricing_plan.items is required for usage_based/per_action pricing.");
2765
+ }
2635
2766
  if (payload.allow_free_trial === void 0 || payload.allow_free_trial === null) {
2636
2767
  throw new SiglumeClientError(
2637
2768
  "AppManifest.allow_free_trial is required. Pass true to offer a Plus/Pro buyer free trial or false to disable trials."
@@ -5311,53 +5442,8 @@ function stableValue(value) {
5311
5442
  return value;
5312
5443
  }
5313
5444
 
5314
- // src/types.ts
5315
- var PermissionClass = {
5316
- READ_ONLY: "read-only",
5317
- ACTION: "action",
5318
- PAYMENT: "payment",
5319
- /** @deprecated Use READ_ONLY. Behaves identically. */
5320
- RECOMMENDATION: "recommendation"
5321
- };
5322
- var ApprovalMode = {
5323
- AUTO: "auto",
5324
- BUDGET_BOUNDED: "budget-bounded",
5325
- ALWAYS_ASK: "always-ask",
5326
- DENY: "deny"
5327
- };
5328
- var Environment = {
5329
- SANDBOX: "sandbox",
5330
- LIVE: "live"
5331
- };
5332
- var PriceModel = {
5333
- FREE: "free",
5334
- SUBSCRIPTION: "subscription",
5335
- ONE_TIME: "one_time",
5336
- BUNDLE: "bundle",
5337
- USAGE_BASED: "usage_based",
5338
- PER_ACTION: "per_action"
5339
- };
5340
- var AppCategory = {
5341
- COMMERCE: "commerce",
5342
- BOOKING: "booking",
5343
- CRM: "crm",
5344
- FINANCE: "finance",
5345
- DOCUMENT: "document",
5346
- COMMUNICATION: "communication",
5347
- MONITORING: "monitoring",
5348
- OTHER: "other"
5349
- };
5350
- var ToolManualPermissionClass = {
5351
- READ_ONLY: "read_only",
5352
- ACTION: "action",
5353
- PAYMENT: "payment"
5354
- };
5355
- var SettlementMode = {
5356
- STRIPE_CHECKOUT: "stripe_checkout",
5357
- STRIPE_PAYMENT_INTENT: "stripe_payment_intent",
5358
- POLYGON_MANDATE: "polygon_mandate",
5359
- EMBEDDED_WALLET_CHARGE: "embedded_wallet_charge"
5360
- };
5445
+ // src/runtime.ts
5446
+ init_types();
5361
5447
 
5362
5448
  // src/testing/recorder.ts
5363
5449
  var CASSETTE_VERSION = 1;
@@ -5749,6 +5835,7 @@ Actual: ${requestSignature(requestRecord, ignoreBodyFields)}`
5749
5835
  };
5750
5836
 
5751
5837
  // src/tool-manual-validator.ts
5838
+ init_types();
5752
5839
  init_utils();
5753
5840
  var JURISDICTION_PATTERN = /^[A-Z]{2}(-[A-Z0-9]{1,3})?$/;
5754
5841
  var TOOL_NAME_RE = /^[A-Za-z0-9_]{3,64}$/;
@@ -6020,6 +6107,64 @@ function validate_tool_manual(manualInput) {
6020
6107
  // src/runtime.ts
6021
6108
  init_web3();
6022
6109
  var CAPABILITY_KEY_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
6110
+ var MINIMUM_JPY_OPERATION_PRICE_CURRENCIES2 = /* @__PURE__ */ new Set(["JPY", "JPYC"]);
6111
+ function pricingPlanFloorIssues(plan, defaultCurrency) {
6112
+ const issues = [];
6113
+ if (plan === void 0 || plan === null) {
6114
+ return issues;
6115
+ }
6116
+ if (typeof plan !== "object" || Array.isArray(plan)) {
6117
+ return ["pricing_plan must be an object when provided"];
6118
+ }
6119
+ const record = plan;
6120
+ const items = record.items;
6121
+ if (items === void 0 || items === null) {
6122
+ return issues;
6123
+ }
6124
+ if (!Array.isArray(items)) {
6125
+ return ["pricing_plan.items must be an array when provided"];
6126
+ }
6127
+ const planCurrency = String(record.currency ?? defaultCurrency ?? "").trim().toUpperCase();
6128
+ const seenKeys = /* @__PURE__ */ new Set();
6129
+ items.forEach((item, index) => {
6130
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
6131
+ issues.push(`pricing_plan.items[${index}] must be an object`);
6132
+ return;
6133
+ }
6134
+ const itemRecord = item;
6135
+ const itemKey = String(
6136
+ itemRecord.key ?? itemRecord.operation ?? itemRecord.operation_key ?? itemRecord.request_type ?? itemRecord.receipt_code ?? itemRecord.action ?? ""
6137
+ ).trim();
6138
+ if (!itemKey) {
6139
+ issues.push(`pricing_plan.items[${index}].key is required`);
6140
+ } else if (seenKeys.has(itemKey)) {
6141
+ issues.push(`pricing_plan.items[${index}].key duplicates ${itemKey}`);
6142
+ } else {
6143
+ seenKeys.add(itemKey);
6144
+ }
6145
+ const amountRaw = itemRecord.price_minor ?? itemRecord.amount_minor ?? itemRecord.cost_minor ?? itemRecord.value_minor;
6146
+ if (amountRaw === void 0 || amountRaw === null) {
6147
+ issues.push(`pricing_plan.items[${index}].price_minor is required`);
6148
+ return;
6149
+ }
6150
+ const amountMinor = typeof amountRaw === "number" ? amountRaw : typeof amountRaw === "string" && amountRaw.trim() ? Number(amountRaw) : NaN;
6151
+ if (!Number.isInteger(amountMinor)) {
6152
+ issues.push(`pricing_plan.items[${index}].price_minor must be an integer`);
6153
+ return;
6154
+ }
6155
+ if (amountMinor < 0) {
6156
+ issues.push(`pricing_plan.items[${index}].price_minor must be zero or positive`);
6157
+ return;
6158
+ }
6159
+ const currency = String(itemRecord.currency ?? planCurrency ?? defaultCurrency ?? "").trim().toUpperCase();
6160
+ if (MINIMUM_JPY_OPERATION_PRICE_CURRENCIES2.has(currency) && amountMinor > 0 && amountMinor < MINIMUM_JPY_OPERATION_PRICE_MINOR) {
6161
+ issues.push(
6162
+ `pricing_plan.items[${index}].price_minor must be 0 or at least ${MINIMUM_JPY_OPERATION_PRICE_MINOR} for JPY/JPYC operation billing`
6163
+ );
6164
+ }
6165
+ });
6166
+ return issues;
6167
+ }
6023
6168
  function normalizeExecutionResult(result, executionKind) {
6024
6169
  return {
6025
6170
  success: Boolean(result.success),
@@ -6107,6 +6252,13 @@ var AppTestHarness = class {
6107
6252
  if (!manifest.example_prompts || manifest.example_prompts.length === 0) {
6108
6253
  issues.push("at least one example_prompt is recommended");
6109
6254
  }
6255
+ issues.push(...pricingPlanFloorIssues(manifest.pricing_plan, String(manifest.currency ?? "USD")));
6256
+ if (manifest.billing_timing !== void 0 && manifest.billing_timing !== "post" && manifest.billing_timing !== "prepay") {
6257
+ issues.push("billing_timing must be 'post' or 'prepay'");
6258
+ }
6259
+ if ((manifest.price_model === PriceModel.USAGE_BASED || manifest.price_model === PriceModel.PER_ACTION) && (!manifest.pricing_plan || !Array.isArray(manifest.pricing_plan.items) || manifest.pricing_plan.items.length === 0)) {
6260
+ issues.push("pricing_plan.items is required for usage_based/per_action pricing");
6261
+ }
6110
6262
  if (manifest.permission_class === PermissionClass.ACTION || manifest.permission_class === PermissionClass.PAYMENT) {
6111
6263
  if (!manifest.dry_run_supported) {
6112
6264
  issues.push("action/payment apps should support dry_run");
@@ -6182,7 +6334,7 @@ var AppTestHarness = class {
6182
6334
  };
6183
6335
  }
6184
6336
  return {
6185
- experimental: manifest.price_model === PriceModel.USAGE_BASED || manifest.price_model === PriceModel.PER_ACTION,
6337
+ experimental: false,
6186
6338
  usage_record,
6187
6339
  invoice_line_preview
6188
6340
  };