@tokenoftrust/storefront-runner 7.9.7 → 7.9.8

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.
@@ -103,6 +103,17 @@ export interface TotAccessClient {
103
103
  * what the MCP binds the subject_token to. Fails closed.
104
104
  */
105
105
  mintSignInToken(email: string, ttlSeconds?: number): Promise<SignInTokenMintResult>;
106
+ /**
107
+ * Mint a short-lived ES256 catalog contribution assertion bound to one verified
108
+ * current owner/admin tenant and the configured Catalog contribution audience
109
+ * (fb-1795601895714-n58rdp). Distinct from the read bearer.
110
+ */
111
+ mintCatalogContributionAssertion?(input: {
112
+ email: string;
113
+ tenant: string;
114
+ audience: string;
115
+ ttlSeconds?: number;
116
+ }): Promise<CatalogContributionMintResult>;
106
117
  /**
107
118
  * STEP-UP COMPLETION (SMS), leg 1: ask tot CORE to send a one-time SMS code to
108
119
  * `identifier` (the identifier bound during a `step-up-required` challenge or a
@@ -139,6 +150,18 @@ export type FederatedVerifyResult =
139
150
 
140
151
  /** Result of {@link TotAccessClient.mintSignInToken}. The raw `token` is a single-use
141
152
  * secret — server-to-server only, NEVER logged. */
153
+ export type CatalogContributionMintResult =
154
+ | {
155
+ ok: true;
156
+ id_token: string;
157
+ audience: string;
158
+ tenant: string;
159
+ role: "owner" | "admin";
160
+ ttlSeconds?: number;
161
+ expiresAt?: string;
162
+ }
163
+ | { ok: false; reason: "not_tenant_admin" | "forbidden" | "unavailable" | "error" };
164
+
142
165
  export type SignInTokenMintResult =
143
166
  | { ok: true; token: string; expiresAt?: string; ttlSeconds?: number }
144
167
  | { ok: false; reason: VerifyFailureReason };
@@ -351,6 +374,38 @@ export class HttpTotAccessClient implements TotAccessClient {
351
374
  return result;
352
375
  }
353
376
 
377
+ async mintCatalogContributionAssertion(input: {
378
+ email: string;
379
+ tenant: string;
380
+ audience: string;
381
+ ttlSeconds?: number;
382
+ }): Promise<CatalogContributionMintResult> {
383
+ let res: HttpResponseLike;
384
+ try {
385
+ res = await this.transport.post(
386
+ `${this.baseUrl}/api/internal/access-code/catalog-contribution`,
387
+ {},
388
+ {
389
+ email: input.email.toLowerCase(),
390
+ tenant: input.tenant.toLowerCase(),
391
+ audience: input.audience,
392
+ ...(input.ttlSeconds != null ? { ttlSeconds: input.ttlSeconds } : {}),
393
+ ...this.credentialFields(),
394
+ },
395
+ );
396
+ } catch {
397
+ return { ok: false, reason: "error" };
398
+ }
399
+ if (res.status >= 300 && res.status < 400) return { ok: false, reason: "error" };
400
+ let body: unknown;
401
+ try {
402
+ body = await res.json();
403
+ } catch {
404
+ return { ok: false, reason: "error" };
405
+ }
406
+ return normalizeCatalogContributionMint(body, res.status, input.tenant, input.audience);
407
+ }
408
+
354
409
  async sendSmsChallenge(identifier: string): Promise<{ ok: true }> {
355
410
  // Neutral by contract, mirroring sendFederatedCode: a transport error still
356
411
  // resolves { ok: true } so the caller never learns eligibility. Best-effort
@@ -449,6 +504,44 @@ export function normalizeMint(body: unknown): SignInTokenMintResult {
449
504
  };
450
505
  }
451
506
 
507
+ /** Parse tot20's `/catalog-contribution` response into a typed result (fail closed). */
508
+ export function normalizeCatalogContributionMint(
509
+ body: unknown,
510
+ status: number,
511
+ expectedTenant: string,
512
+ expectedAudience: string,
513
+ ): CatalogContributionMintResult {
514
+ const raw = (body ?? {}) as Record<string, unknown>;
515
+ const b = (raw.content && typeof raw.content === "object" ? raw.content : raw) as Record<string, unknown>;
516
+ if (
517
+ status >= 200 &&
518
+ status < 300 &&
519
+ b.ok === true &&
520
+ typeof b.id_token === "string" &&
521
+ b.id_token &&
522
+ typeof b.audience === "string" &&
523
+ b.audience === expectedAudience &&
524
+ typeof b.tenant === "string" &&
525
+ b.tenant.toLowerCase() === expectedTenant.toLowerCase() &&
526
+ (b.role === "owner" || b.role === "admin")
527
+ ) {
528
+ const result: CatalogContributionMintResult = {
529
+ ok: true,
530
+ id_token: b.id_token,
531
+ audience: b.audience,
532
+ tenant: b.tenant.toLowerCase(),
533
+ role: b.role,
534
+ };
535
+ if (typeof b.ttlSeconds === "number") result.ttlSeconds = b.ttlSeconds;
536
+ if (typeof b.expiresAt === "string") result.expiresAt = b.expiresAt;
537
+ return result;
538
+ }
539
+ if (b.reason === "not_tenant_admin") return { ok: false, reason: "not_tenant_admin" };
540
+ if (status === 403) return { ok: false, reason: "forbidden" };
541
+ if (status === 503) return { ok: false, reason: "unavailable" };
542
+ return { ok: false, reason: "error" };
543
+ }
544
+
452
545
  /** Parse tot20's SMS step-up-completion verify response (fail closed). */
453
546
  export function normalizeSmsVerify(body: unknown): SmsVerifyResult {
454
547
  // Same envelope-unwrap convention as normalizeVerify/normalizeFederatedVerify.
@@ -639,6 +732,35 @@ export class MockTotAccessClient implements TotAccessClient {
639
732
  return { ok: true, token };
640
733
  }
641
734
 
735
+ async mintCatalogContributionAssertion(input: {
736
+ email: string;
737
+ tenant: string;
738
+ audience: string;
739
+ ttlSeconds?: number;
740
+ }): Promise<CatalogContributionMintResult> {
741
+ const entry = this.roster.get(this.key(input.tenant.toLowerCase(), input.email));
742
+ const cap = entry ? (entry.capability ?? effectiveCapability(entry.roles)) : "none";
743
+ if (cap !== "owner" && cap !== "admin") {
744
+ return { ok: false, reason: "not_tenant_admin" };
745
+ }
746
+ const id_token = this.signIdToken
747
+ ? await this.signIdToken({
748
+ email: input.email.toLowerCase(),
749
+ resource: input.tenant.toLowerCase(),
750
+ roles: entry?.roles ?? [],
751
+ capability: cap,
752
+ })
753
+ : `mock-contrib|${input.audience}|${input.tenant.toLowerCase()}|${cap}`;
754
+ return {
755
+ ok: true,
756
+ id_token,
757
+ audience: input.audience,
758
+ tenant: input.tenant.toLowerCase(),
759
+ role: cap,
760
+ ttlSeconds: input.ttlSeconds ?? 120,
761
+ };
762
+ }
763
+
642
764
  async sendSmsChallenge(identifier: string): Promise<{ ok: true }> {
643
765
  this.smsSent.push(identifier);
644
766
  return { ok: true }; // neutral regardless of eligibility
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.9.7",
3
+ "version": "7.9.8",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",