@absolutejs/billing 0.2.2 → 0.3.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.
@@ -3,5 +3,13 @@ type BillingRuntime = {
3
3
  plan: Plan;
4
4
  balances?: ProviderBalanceConfig;
5
5
  };
6
- export declare const manifest: import("@absolutejs/manifest").PackageManifest<Record<never, never>, BillingRuntime>;
6
+ export declare const manifest: Omit<import("@absolutejs/manifest").PackageManifest<Record<never, never>, BillingRuntime>, "contract" | "settings" | "tools"> & (({
7
+ contract: 1;
8
+ tools?: Record<string, import("@absolutejs/manifest").LegacyManifestTool<BillingRuntime>> | undefined;
9
+ } | {
10
+ contract: 2;
11
+ tools?: Record<string, import("@absolutejs/manifest").AuthorizedManifestTool<BillingRuntime>> | undefined;
12
+ }) & {
13
+ settings: import("@sinclair/typebox").TObject<{}>;
14
+ });
7
15
  export {};
package/dist/manifest.js CHANGED
@@ -516,14 +516,19 @@ var __export2 = (target, all) => {
516
516
  set: __exportSetter2.bind(all, name)
517
517
  });
518
518
  };
519
- var defineManifest = () => (manifest) => {
520
- const defined = manifest;
521
- return defined;
519
+ var defineManifest = () => (manifest) => manifest;
520
+ var literal = (value) => value;
521
+ var RUNTIME_KIND = literal("runtime");
522
+ var WORKSPACE_KIND = literal("workspace");
523
+ var toolFactory = () => {
524
+ function runtime(definition) {
525
+ return { kind: RUNTIME_KIND, ...definition };
526
+ }
527
+ function workspace(definition) {
528
+ return { kind: WORKSPACE_KIND, ...definition };
529
+ }
530
+ return { runtime, workspace };
522
531
  };
523
- var toolFactory = () => ({
524
- runtime: (definition) => ({ kind: "runtime", ...definition }),
525
- workspace: (definition) => ({ kind: "workspace", ...definition })
526
- });
527
532
  function IsAsyncIterator(value) {
528
533
  return IsObject(value) && globalThis.Symbol.asyncIterator in value;
529
534
  }
@@ -1261,7 +1266,7 @@ function String2(options) {
1261
1266
  function* FromUnion(syntax) {
1262
1267
  const trim = syntax.trim().replace(/"|'/g, "");
1263
1268
  return trim === "boolean" ? yield Boolean() : trim === "number" ? yield Number2() : trim === "bigint" ? yield BigInt2() : trim === "string" ? yield String2() : yield (() => {
1264
- const literals = trim.split("|").map((literal) => Literal(literal.trim()));
1269
+ const literals = trim.split("|").map((literal2) => Literal(literal2.trim()));
1265
1270
  return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals);
1266
1271
  })();
1267
1272
  }
@@ -3969,10 +3974,10 @@ function ScoreUnion(schema, references, value) {
3969
3974
  const keys = Object.getOwnPropertyNames(value);
3970
3975
  const entries = Object.entries(object.properties);
3971
3976
  return entries.reduce((acc, [key, schema2]) => {
3972
- const literal = schema2[Kind] === "Literal" && schema2.const === value[key] ? 100 : 0;
3977
+ const literal2 = schema2[Kind] === "Literal" && schema2.const === value[key] ? 100 : 0;
3973
3978
  const checks = Check(schema2, references, value[key]) ? 10 : 0;
3974
3979
  const exists = keys.includes(key) ? 1 : 0;
3975
- return acc + (literal + checks + exists);
3980
+ return acc + (literal2 + checks + exists);
3976
3981
  }, 0);
3977
3982
  } else if (schema[Kind] === "Union") {
3978
3983
  const schemas = schema.anyOf.map((schema2) => Deref(schema2, references));
@@ -6309,7 +6314,13 @@ var wiringSnippet = Type.Object({
6309
6314
  Type.Literal("server-plugin")
6310
6315
  ]))
6311
6316
  });
6312
- var clientFrameworks = ["angular", "client", "react", "svelte", "vue"];
6317
+ var clientFrameworks = [
6318
+ "angular",
6319
+ "client",
6320
+ "react",
6321
+ "svelte",
6322
+ "vue"
6323
+ ];
6313
6324
  var wiringRecipe = Type.Object({
6314
6325
  client: Type.Optional(Type.Partial(Type.Object(Object.fromEntries(clientFrameworks.map((framework) => [framework, wiringSnippet]))))),
6315
6326
  description: Type.Optional(Type.String()),
@@ -6374,8 +6385,47 @@ var toolAnnotations = Type.Object({
6374
6385
  readOnlyHint: Type.Optional(Type.Boolean()),
6375
6386
  title: Type.Optional(Type.String())
6376
6387
  });
6388
+ var toolAuthorization = Type.Object({
6389
+ approval: Type.Union([
6390
+ Type.Literal("always"),
6391
+ Type.Literal("never"),
6392
+ Type.Literal("policy")
6393
+ ]),
6394
+ audience: Type.Union([
6395
+ Type.Literal("admin"),
6396
+ Type.Literal("authenticated"),
6397
+ Type.Literal("owner"),
6398
+ Type.Literal("public")
6399
+ ]),
6400
+ compensatingTool: Type.Optional(Type.String({ pattern: TOOL_NAME_PATTERN.source })),
6401
+ destinationFields: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1 })),
6402
+ destinations: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1 })),
6403
+ effects: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
6404
+ idempotency: Type.Optional(Type.Union([
6405
+ Type.Object({
6406
+ field: Type.String({ minLength: 1 }),
6407
+ mode: Type.Literal("field")
6408
+ }),
6409
+ Type.Object({ mode: Type.Literal("host") }),
6410
+ Type.Object({ mode: Type.Literal("resource") })
6411
+ ])),
6412
+ requiredScopes: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1 })),
6413
+ resource: Type.Optional(Type.Object({
6414
+ idField: Type.Optional(Type.String({ minLength: 1 })),
6415
+ ownerIdField: Type.Optional(Type.String({ minLength: 1 })),
6416
+ tenantIdField: Type.Optional(Type.String({ minLength: 1 })),
6417
+ type: Type.String({ minLength: 1 })
6418
+ })),
6419
+ reversible: Type.Optional(Type.Boolean()),
6420
+ spend: Type.Optional(Type.Object({
6421
+ amountMinorField: Type.String({ minLength: 1 }),
6422
+ currencyField: Type.String({ minLength: 1 }),
6423
+ maximumAmountMinor: Type.Optional(Type.Integer({ minimum: 0 }))
6424
+ }))
6425
+ });
6377
6426
  var serializedTool = Type.Object({
6378
6427
  annotations: Type.Optional(toolAnnotations),
6428
+ authorization: Type.Optional(toolAuthorization),
6379
6429
  capabilities: Type.Optional(Type.Array(Type.Union([
6380
6430
  Type.Literal("exec"),
6381
6431
  Type.Literal("glob"),
@@ -6387,7 +6437,15 @@ var serializedTool = Type.Object({
6387
6437
  kind: Type.Union([Type.Literal("runtime"), Type.Literal("workspace")])
6388
6438
  });
6389
6439
  var manifestSchema = Type.Object({
6390
- contract: Type.Literal(1),
6440
+ contract: Type.Union([Type.Literal(1), Type.Literal(2)]),
6441
+ discovery: Type.Optional(Type.Object({
6442
+ audiences: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
6443
+ certificationUrl: Type.Optional(Type.String()),
6444
+ intents: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
6445
+ keywords: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
6446
+ protocols: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
6447
+ url: Type.Optional(Type.String())
6448
+ })),
6391
6449
  identity: Type.Object({
6392
6450
  accent: Type.Optional(Type.String({ pattern: "^#[0-9a-fA-F]{3,8}$" })),
6393
6451
  category: Type.String({ minLength: 1 }),
@@ -6397,7 +6455,9 @@ var manifestSchema = Type.Object({
6397
6455
  svg: Type.Optional(Type.String()),
6398
6456
  url: Type.Optional(Type.String())
6399
6457
  })),
6400
- name: Type.String({ pattern: "^(@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$" }),
6458
+ name: Type.String({
6459
+ pattern: "^(@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$"
6460
+ }),
6401
6461
  tagline: Type.String({ minLength: 1 })
6402
6462
  }),
6403
6463
  implements: Type.Optional(Type.Array(adapterImplementation)),
@@ -7370,7 +7430,7 @@ function String3(options) {
7370
7430
  function* FromUnion21(syntax) {
7371
7431
  const trim = syntax.trim().replace(/"|'/g, "");
7372
7432
  return trim === "boolean" ? yield Boolean2() : trim === "number" ? yield Number3() : trim === "bigint" ? yield BigInt3() : trim === "string" ? yield String3() : yield (() => {
7373
- const literals = trim.split("|").map((literal) => Literal2(literal.trim()));
7433
+ const literals = trim.split("|").map((literal2) => Literal2(literal2.trim()));
7374
7434
  return literals.length === 0 ? Never2() : literals.length === 1 ? literals[0] : UnionEvaluated2(literals);
7375
7435
  })();
7376
7436
  }
@@ -8972,7 +9032,7 @@ var DEFAULT_PREVIEW_DAYS = 30;
8972
9032
  var MAX_PREVIEW_DAYS = 366;
8973
9033
  var tool = toolFactory();
8974
9034
  var manifest = defineManifest()({
8975
- contract: 1,
9035
+ contract: 2,
8976
9036
  identity: {
8977
9037
  accent: "#f59e0b",
8978
9038
  category: "commerce",
@@ -9005,6 +9065,12 @@ var manifest = defineManifest()({
9005
9065
  tools: {
9006
9066
  explain_plan: tool.runtime({
9007
9067
  annotations: { readOnlyHint: true },
9068
+ authorization: {
9069
+ approval: "never",
9070
+ audience: "authenticated",
9071
+ effects: ["read"],
9072
+ requiredScopes: ["billing:read"]
9073
+ },
9008
9074
  description: "Describe the app's pricing plan: base fee, per-dimension unit prices or tier tables, free-tier allowances, rounding, and minimum charge. Amounts are integer micros (1,000,000 micros = 1 currency unit). Custom function-priced dimensions are reported as 'custom'.",
9009
9075
  handler: (_input, { plan }) => {
9010
9076
  const dimensions = Object.entries(plan.pricedDimensions).map(([key, dim]) => ({
@@ -9027,6 +9093,13 @@ var manifest = defineManifest()({
9027
9093
  }),
9028
9094
  preview_invoice: tool.runtime({
9029
9095
  annotations: { idempotentHint: true, readOnlyHint: true },
9096
+ authorization: {
9097
+ approval: "never",
9098
+ audience: "owner",
9099
+ effects: ["read"],
9100
+ requiredScopes: ["billing:preview"],
9101
+ resource: { idField: "tenant", tenantIdField: "tenant", type: "billing-preview" }
9102
+ },
9030
9103
  description: "Dry-run an invoice: price a usage snapshot through the app's plan and return the line items and total in integer micros. Pure math \u2014 nothing is charged or stored. Usage keys must match the plan's priced dimensions.",
9031
9104
  handler: ({ periodDays, tenant, usage }, { plan }) => {
9032
9105
  const end = Date.now();
@@ -9056,7 +9129,16 @@ var manifest = defineManifest()({
9056
9129
  })
9057
9130
  }),
9058
9131
  provider_balances: tool.runtime({
9059
- annotations: { openWorldHint: true, readOnlyHint: true },
9132
+ annotations: { idempotentHint: true, openWorldHint: true },
9133
+ authorization: {
9134
+ approval: "policy",
9135
+ audience: "admin",
9136
+ destinations: ["configured-billing-provider"],
9137
+ effects: ["read", "external-network"],
9138
+ idempotency: { mode: "host" },
9139
+ requiredScopes: ["billing:providers:read"],
9140
+ reversible: false
9141
+ },
9060
9142
  description: "Read each configured upstream vendor's OWN reported balance, quota, or spend (Anthropic/OpenAI report spend; Twilio/Deepgram report balance; ElevenLabs/Apollo report quota). Free reporting endpoints \u2014 no per-call charge. Reports only the providers the host wired credentials for.",
9061
9143
  handler: async (_input, { balances }) => balances === undefined ? "no provider credentials are wired \u2014 wire a ProviderBalanceConfig (see the provider-balances recipe)" : JSON.stringify(await readProviderBalances(balances)),
9062
9144
  input: Type2.Object({})
@@ -9104,5 +9186,5 @@ export {
9104
9186
  manifest
9105
9187
  };
9106
9188
 
9107
- //# debugId=B0E122DF0D110CFA64756E2164756E21
9189
+ //# debugId=22773D62A08DEEC264756E2164756E21
9108
9190
  //# sourceMappingURL=manifest.js.map