@tokenoftrust/cli 6.12.5 → 6.12.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "6.12.5",
3
+ "version": "6.12.7",
4
4
  "description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Token of Trust",
@@ -130,7 +130,7 @@ export const CAPABILITIES = [
130
130
  label: 'Private apps: inventory/WMS sync, shipping/label stations, and 3PL/dropship fulfillment',
131
131
  tier: 'app',
132
132
  summary:
133
- 'Merchant-scoped private apps (SkuVault WMS, ShipStation, Duoplane, affiliate attribution) '
133
+ 'Merchant-scoped private apps (multi-location WMS sync, shipping & label stations, 3PL/dropship routing, affiliate attribution) '
134
134
  + 'connected via OAuth2 client-credentials / private_key_jwt, scoped REST APIs, and signed '
135
135
  + 'CloudEvents webhooks. Developers self-serve test installs (`tot app install`, `tot catalog seed`) '
136
136
  + 'and stage production candidates (`pending_approval`) for 1-click store-owner approval.',
@@ -921,12 +921,18 @@ export function rendererCacheHealthy(runnerDir, opts = {}) {
921
921
  * follows links, so a `node_modules` entry whose target is gone (a junction left
922
922
  * pointing into a renamed staging directory) reads as absent. A tree with no
923
923
  * `apps/storefront/package.json` has nothing to check and passes.
924
+ *
925
+ * Resolution follows Node's walk from the app up to the runner root and no further:
926
+ * pnpm links astro into `apps/storefront/node_modules`, while npm workspaces hoist it
927
+ * to the runner root's `node_modules`. A copy outside the runner never counts.
924
928
  * @param {string} runnerDir
925
929
  */
926
930
  export function rendererDepsResolve(runnerDir) {
927
931
  const app = join(runnerDir, "apps", "storefront");
928
932
  if (!existsSync(join(app, "package.json"))) return true;
929
- return existsSync(join(app, "node_modules", "astro", "package.json"));
933
+ return [app, join(runnerDir, "apps"), runnerDir].some((dir) =>
934
+ existsSync(join(dir, "node_modules", "astro", "package.json")),
935
+ );
930
936
  }
931
937
 
932
938
  /**
@@ -4,6 +4,12 @@
4
4
  # Port the stub webhook receiver (server.js) listens on.
5
5
  PORT=8787
6
6
 
7
+ # Optional externally visible webhook origin (without trailing slash) when running
8
+ # behind a local preview tunnel (cloudflared, Microsoft devtunnel, ngrok) or
9
+ # reverse-proxied container host so RFC 9421 @target-uri verification matches
10
+ # the HTTPS URL Storefront signed.
11
+ # WEBHOOK_PUBLIC_URL=https://random-words.trycloudflare.com
12
+
7
13
  # Must match tot-app.json's webhooks.signatureKeyId. `tot app dev` writes the
8
14
  # matching public key alongside this app at .tot/dev-keys.json for local runs
9
15
  # — you don't need to set anything here to exercise the receiver locally.
@@ -1,12 +1,13 @@
1
- # Placeholder for the optional ToT-hosted runtime (installMode: "hosted",
2
- # see tot-app.json + docs/private-apps/contract/tot-app.schema.json#hosting).
3
- # The SAME manifest works for "external" (self-hosted, this Dockerfile is
4
- # informational only) and "hosted" (ToT runs this image; egress is deny-all
5
- # except tot-app.json's hosting.allowedHosts).
6
- FROM node:20-slim
1
+ # Portable Node.js container for self-hosted deployments (Google Cloud Run,
2
+ # Azure Container Apps, Fly.io, Render, Railway, AWS ECS — see
3
+ # https://github.com/tokenoftrust/storefront-devkit/tree/main/apps/private/hosting)
4
+ # and the optional ToT-hosted runtime (installMode: "hosted").
5
+ FROM node:22-alpine
7
6
  WORKDIR /app
8
7
  COPY package*.json ./
9
8
  RUN [ -f package.json ] && npm install --omit=dev || true
10
9
  COPY . .
10
+ ENV NODE_ENV=production
11
+ ENV PORT=8787
11
12
  EXPOSE 8787
12
13
  CMD ["node", "server.js"]
@@ -22,9 +22,12 @@ are the stable human and LLM entry points.
22
22
  - **`server.js`** — a minimal Node HTTP receiver for `webhooks.endpoint`. It
23
23
  verifies the RFC 9421 HTTP Message Signature + RFC 9530 Content-Digest on
24
24
  every inbound request before trusting the body — replace the handler logic,
25
- keep the verification.
26
- - **`Dockerfile`** — only relevant if you set `installMode: "hosted"`; ignored
27
- for `"external"` apps (the default here).
25
+ keep the verification. Supports `WEBHOOK_PUBLIC_URL` (or `X-Forwarded-Proto`
26
+ / `X-Forwarded-Host`) for local tunnels and reverse-proxied container hosts,
27
+ and logs `event.tenantid` + `event.appinstallid` for multi-tenant routing.
28
+ - **`Dockerfile`** — portable Node 22 Alpine container for self-hosted
29
+ container platforms (Google Cloud Run, Azure Container Apps, Fly.io, Render,
30
+ Railway, AWS ECS) or optional `installMode: "hosted"`.
28
31
  - **`.env.example`** — copy to `.env`; no real values are included.
29
32
 
30
33
  ## Local loop (no network, no real ToT account needed)
@@ -53,24 +56,52 @@ for runnable reference connectors against the v1.3 contract:
53
56
  - **`examples/hello-inventory`** — starter reference: locations (`GET`/`PUT /inventory/locations`),
54
57
  mirror stock reads/writes (`GET /inventory`, `POST /inventory/movements`), and synthetic test
55
58
  orders (`POST /api/apps/admin/test-orders`).
56
- - **`recipes/inventory-sync-skuvault`** — multi-location WMS sync (SkuVault, Finale Inventory):
59
+ - **`recipes/inventory-sync-wms`** — multi-location WMS sync:
57
60
  `GET`/`PUT /inventory/locations/{locationId}`, `PUT /inventory/levels` (`expectedVersion` CAS
58
61
  reconciliation), batch `POST /inventory/movements` (`receive`, `pick`, `cycle_count`, `damage`,
59
62
  `transfer_in`, `transfer_out`, `return_restock`), and `inventory.changed` webhooks (`low_stock`,
60
63
  `out_of_stock`, `back_in_stock`).
61
- - **`recipes/fulfillment-shipstation`** — shipping and label station (ShipStation, Shippo,
62
- PirateShip): `fulfillment.assignment.created`/`updated`, `GET /fulfillment/assignments`,
64
+ - **`recipes/fulfillment-label-station`** — shipping and label station:
65
+ `fulfillment.assignment.created`/`updated`, `GET /fulfillment/assignments`,
63
66
  `GET /fulfillment/orders/{orderId}/recipient`, `GET /fulfillment/carriers` (PACT Act &
64
67
  `adultSignature` carrier profiles), 1:N split cartons
65
68
  (`POST /fulfillment/assignments/{assignmentId}/shipments`), and whole-order `shipment-evidence`
66
69
  (`label-purchased`, `label-voided`, `handed-off`).
67
- - **`recipes/dropship-split-duoplane`** — 3PL and multi-vendor dropship routing (Duoplane, DSCO):
70
+ - **`recipes/dropship-multi-supplier`** — 3PL and multi-supplier dropship routing:
68
71
  location-keyed processor coexistence per `(tenant, stage, location_id)` (Stone 1), assignments
69
72
  with `locationId` and `lines[]` (`sku`, `quantity`, `fulfilledQuantity`, `cancelledQuantity`),
70
73
  partial line shipments (`order.partially_fulfilled` -> `order.fulfilled`), and line exceptions
71
74
  (`POST /fulfillment/assignments/{assignmentId}/exceptions`: `backordered`, `cannot_fulfill`,
72
75
  `address_undeliverable`).
73
76
 
77
+ ## Hosting & deployment fast-paths (single-tenant or multi-tenant)
78
+
79
+ A Storefront Private App runs **outside** the shared Storefront Worker as your
80
+ own service or scheduled worker. While **install records and credentials are
81
+ isolated per `(tenant, env)`**, your deployed service can be **single-tenant or
82
+ multi-tenant across any number of merchant stores**:
83
+ - Every inbound CloudEvent carries `event.tenantid`, `event.appinstallid`,
84
+ `event.source` (`/tenants/<tenant>/storefront`), and `event.id` in the top-level
85
+ envelope.
86
+ - Outbound `/api/apps/v1/*` calls use an OAuth2 Bearer token minted for that
87
+ merchant's `(tenant, appInstallId, env)` (using a single shared `private_key_jwt`
88
+ `jwksUri` across all your merchant installs, or per-install `test` secrets).
89
+
90
+ See [`https://github.com/tokenoftrust/storefront-devkit/tree/main/apps/private/hosting`](https://github.com/tokenoftrust/storefront-devkit/tree/main/apps/private/hosting)
91
+ and its machine-readable catalog [`apps/private/hosting/index.json`](https://github.com/tokenoftrust/storefront-devkit/blob/main/apps/private/hosting/index.json)
92
+ for copy-paste deployment guides across clouds and topologies:
93
+ - **Cloudflare Workers** (`apps/private/hosting/cloudflare-workers/`) — `fetch` + `scheduled` Cron + Workers KV deduplication
94
+ - **AWS Lambda** (`apps/private/hosting/aws-lambda/`) — Function URL / API Gateway HTTP API + EventBridge Scheduler + DynamoDB deduplication
95
+ - **Google Cloud** (`apps/private/hosting/google-cloud-run/`) — **Cloud Run** services (`gcloud run deploy`) & **Cloud Run functions** (`req.rawBody` verification) + Cloud Scheduler + Secret Manager
96
+ - **Microsoft Azure** (`apps/private/hosting/microsoft-azure-functions/`) — **Azure Functions** (v4 `request.arrayBuffer()` + `app.timer`) & **Azure Container Apps** (`az containerapp up`) + Key Vault
97
+ - **Containers, Pull-Only Scheduled Jobs & Local Tunnels** (`apps/private/hosting/containers-and-tunnels/`) — portable `Dockerfile` (Fly.io, Render, Railway, ECS, GKE, AKS), zero-inbound pull-only cron jobs, and local `env="test"` preview tunnels (`cloudflared tunnel --url http://localhost:8787`, Microsoft `devtunnel`, `ngrok`)
98
+
99
+ > **Agents & partner integrations:** Always read `apps/private/hosting/index.json`
100
+ > and list `apps/private/hosting/*` subdirectories for newly contributed runtime
101
+ > or platform guides. New provider guides can be contributed directly via a PR
102
+ > adding `apps/private/hosting/<provider-slug>/README.md` + an entry in
103
+ > `apps/private/hosting/index.json`.
104
+
74
105
  ## Self-serve `env="test"` preview loop (v1.3)
75
106
 
76
107
  Developers holding `preview-access` or `ship-on-behalf` on a store can verify an app end-to-end on
@@ -10,8 +10,8 @@
10
10
  * dev-only scaffolding: your real receiver checks against the platform's
11
11
  * published JWKS/signing-key metadata instead — see the Devkit's
12
12
  * https://github.com/tokenoftrust/storefront-devkit/tree/main/apps/private
13
- * (`examples/hello-inventory`, `recipes/inventory-sync-skuvault`,
14
- * `recipes/fulfillment-shipstation`, `recipes/dropship-split-duoplane`).
13
+ * (`examples/hello-inventory`, `recipes/inventory-sync-wms`,
14
+ * `recipes/fulfillment-label-station`, `recipes/dropship-multi-supplier`).
15
15
  *
16
16
  * Online preview & production flow (see README.md):
17
17
  * 1. `tot catalog seed --preset=general|regulated-vape|multi-warehouse` (then `tot preview`)
@@ -58,9 +58,15 @@ const server = createServer(async (req, res) => {
58
58
  return;
59
59
  }
60
60
 
61
+ const proto = req.headers["x-forwarded-proto"] || "http";
62
+ const host = req.headers["x-forwarded-host"] || req.headers.host || `localhost:${PORT}`;
63
+ const targetUrl = process.env.WEBHOOK_PUBLIC_URL
64
+ ? new URL(req.url, process.env.WEBHOOK_PUBLIC_URL).toString()
65
+ : `${proto}://${host}${req.url}`;
66
+
61
67
  const result = await verifyWebhookSignature({
62
68
  method: req.method,
63
- url: `http://${req.headers.host}${req.url}`,
69
+ url: targetUrl,
64
70
  body,
65
71
  headers: {
66
72
  "content-digest": req.headers["content-digest"],
@@ -77,9 +83,11 @@ const server = createServer(async (req, res) => {
77
83
  }
78
84
 
79
85
  console.log(`[${requestId}] verified delivery (keyid=${result.keyid}, created=${result.created})`);
80
- // ── Handle the event ────────────────────────────────────────────────────
86
+ // ── Handle the event (multi-tenant ready: route by tenantid + appinstallid) ─
81
87
  const event = JSON.parse(body);
82
- console.log(`[${requestId}] ${event.type} for tenant ${event.tenantid}`);
88
+ console.log(
89
+ `[${requestId}] ${event.type} for tenant ${event.tenantid} (install=${event.appinstallid}, eventId=${event.id})`,
90
+ );
83
91
  // ─────────────────────────────────────────────────────────────────────────
84
92
 
85
93
  res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({ ok: true }));