@assembly-js/app-foundation 0.0.10-rc.1 → 0.0.11
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/CLAUDE.md +156 -594
- package/bin/check-token-usage.mjs +29 -3
- package/package.json +1 -1
- package/skills/assembly-app-bridge-header/SKILL.md +15 -1
- package/skills/assembly-automations/SKILL.md +1 -1
- package/skills/assembly-avatar-sub/SKILL.md +1 -1
- package/skills/assembly-clients-companies/SKILL.md +1 -1
- package/skills/assembly-custom-fields/SKILL.md +4 -0
- package/skills/assembly-integrations/SKILL.md +1 -1
- package/skills/assembly-internal-users/SKILL.md +1 -1
- package/skills/assembly-native-resources/SKILL.md +1 -1
- package/skills/assembly-notifications/SKILL.md +2 -2
- package/skills/assembly-platform-mcp/SKILL.md +1 -1
- package/skills/assembly-route-errors/SKILL.md +1 -1
- package/skills/assembly-session-token/SKILL.md +5 -4
- package/skills/assembly-storage/SKILL.md +1 -1
- package/skills/clearing-client-notifications/SKILL.md +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Fails the build if any page reads the session token from `searchParams
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// Fails the build if any page reads the session token from `searchParams` —
|
|
3
|
+
// except in a legacy (pre-bearer) app, where it's the only identity path and
|
|
4
|
+
// this is a warning instead. Dependency-free on purpose: it runs inside the
|
|
5
|
+
// generated app's sandbox before any deps beyond Node exist.
|
|
5
6
|
//
|
|
6
7
|
// Auth is cookie-borne in the bearer model: the foundation middleware exchanges
|
|
7
8
|
// the first-load `?token=` for an HttpOnly bearer cookie exactly once, and
|
|
@@ -10,12 +11,25 @@
|
|
|
10
11
|
// renders its auth-rejection state to everyone after any client-side navigation
|
|
11
12
|
// (`router.push`, `<Link>`), which drops query params. Fetch per-user data via
|
|
12
13
|
// server actions (useServerAction) or authFetch route handlers instead.
|
|
14
|
+
//
|
|
15
|
+
// A legacy app (cloned before the bearer model existed) has no bearer cookie to
|
|
16
|
+
// exchange into — URL-token auth is its only identity path, so the same pattern
|
|
17
|
+
// is expected there, not a bug. Severity is decided by probing two marker files
|
|
18
|
+
// from the checkout root, mirroring ProbeFoundationAuthVersionFromGithub in
|
|
19
|
+
// logic_build.go (mintBearerProbePath / packageWorldProbePath): mint-bearer.ts
|
|
20
|
+
// present -> bearer-capable, fatal; absent + assembly.ts present -> legacy, warn
|
|
21
|
+
// and exit 0; neither present -> package-world app (bearer-capable via
|
|
22
|
+
// @assembly-js/app-foundation in node_modules), fatal as today.
|
|
13
23
|
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
14
24
|
import { join, relative, sep } from 'node:path';
|
|
15
25
|
|
|
16
26
|
const ROOT = process.cwd();
|
|
17
27
|
const APP_DIR = join(ROOT, 'app');
|
|
18
28
|
|
|
29
|
+
// Mirrors mintBearerProbePath / packageWorldProbePath in logic_build.go.
|
|
30
|
+
const MINT_BEARER_PROBE_PATH = 'lib/mint-bearer.ts';
|
|
31
|
+
const PACKAGE_WORLD_PROBE_PATH = 'lib/assembly.ts';
|
|
32
|
+
|
|
19
33
|
function pageFiles(dir) {
|
|
20
34
|
const out = [];
|
|
21
35
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -114,11 +128,23 @@ for (const file of pageFiles(APP_DIR)) {
|
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
if (violations.length > 0) {
|
|
131
|
+
const isLegacy =
|
|
132
|
+
!existsSync(join(ROOT, MINT_BEARER_PROBE_PATH)) && existsSync(join(ROOT, PACKAGE_WORLD_PROBE_PATH));
|
|
133
|
+
|
|
117
134
|
console.error('');
|
|
118
135
|
console.error('A page reads the session token from searchParams:');
|
|
119
136
|
console.error('');
|
|
120
137
|
for (const v of violations) console.error(' - ' + v);
|
|
121
138
|
console.error('');
|
|
139
|
+
|
|
140
|
+
if (isLegacy) {
|
|
141
|
+
console.error('This is a pre-bearer app, so this is a warning, not a build failure:');
|
|
142
|
+
console.error('URL-token auth is its only identity path. Because client-side navigation');
|
|
143
|
+
console.error('(router.push, <Link>) drops query params, any page reading');
|
|
144
|
+
console.error('searchParams.token must thread the token through its outgoing hrefs.');
|
|
145
|
+
process.exit(0);
|
|
146
|
+
}
|
|
147
|
+
|
|
122
148
|
console.error('Auth is in the bearer cookie, not the URL — no page, not even a surface');
|
|
123
149
|
console.error('entry page, should read searchParams.token. getAssembly() and');
|
|
124
150
|
console.error('getSessionIdentity() read the bearer cookie; fetch per-user data via');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-app-bridge-header
|
|
3
|
-
description: Use any time the app sets breadcrumbs, primary
|
|
3
|
+
description: Use any time the app sets breadcrumbs, primary/secondary CTA, or actions menu in the header chrome. Always drive it via useAssemblyHeader — never call AssemblyBridge.header.set* from your own useEffect. The parent auto-prepends the app name as breadcrumb 0 — never include it yourself.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
The Assembly header (breadcrumbs, primary/secondary CTA buttons, overflow actions menu) is controlled from your app. **Drive it with the `useAssemblyHeader` hook** — it ships in the foundation at `app/components/use-assembly-header.ts`.
|
|
@@ -70,6 +70,20 @@ useAssemblyHeader({ onRootClick: goHome, breadcrumbs: [{ label: 'Reports' }] });
|
|
|
70
70
|
|
|
71
71
|
Use breadcrumbs only for hierarchical navigation, not branding. A flat one-page app omits `breadcrumbs` (or passes `[]`). A multi-level app uses one entry per level: `[{ label: 'Reports' }, { label: 'Q4 2026' }]`. A breadcrumb's `onClick` makes it clickable; omit it for the current/leaf level.
|
|
72
72
|
|
|
73
|
+
## Loading state on a `primaryCta` — no `disabled`/`loading` prop
|
|
74
|
+
|
|
75
|
+
Header CTAs have no `disabled` or `loading` prop. Indicate progress by changing the `primaryCta` value itself — swap the label and replace `onClick` with a no-op while the action runs, then restore both when it completes:
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
useAssemblyHeader({
|
|
79
|
+
primaryCta: isSaving
|
|
80
|
+
? { label: 'Saving…', icon: 'Check', onClick: () => {} }
|
|
81
|
+
: { label: 'Save', icon: 'Check', onClick: save },
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Because the hook re-applies whatever value you pass on every render, this is just a state change — no imperative set/clear needed. Don't let the user click a button and see nothing happen.
|
|
86
|
+
|
|
73
87
|
## Icon and color constraints
|
|
74
88
|
|
|
75
89
|
- **`icon` must be a `CtaIcon`** — the only valid values are `'Archive' | 'Plus' | 'Templates' | 'Trash' | 'Check'`. Any other string (e.g. `'Download'`, `'Settings'`, `'Edit'`) is a type error — omit the icon (it's optional) when none fit.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!-- feature:api-resources -->
|
|
2
2
|
---
|
|
3
3
|
name: assembly-automations
|
|
4
|
-
description:
|
|
4
|
+
description: REQUIRED when a request should react to an in-app event AND write to the Assembly platform (message a client, set a CRM field, send a contract/form, share a file) — not just the app's tables. Covers api-resources.json schema, event naming, triggers/actions, webhooks, automationActionRoute.
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
An app's API contract — the events it emits and the operations workspace automations can invoke — is declared in **`.assembly/api-resources.json`** at the repo root. The platform reads it at publish and registers the app's triggers and actions. Which file owns what: `.assembly/app.json` = how the platform runs the app (surfaces, secrets, integrations); `.assembly/api-resources.json` = the API contract the app exposes. Never mix their keys.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-avatar-sub
|
|
3
|
-
description: Use whenever a client's name or avatar
|
|
3
|
+
description: Use whenever a client's name or avatar renders in a list, table, card, or detail header — including tables of app records that reference a client. Clients belong to many companies, so an avatar without its company is ambiguous. Covers AvatarSub + expandClientsByCompany row-duplication.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
`AvatarSub` renders a single nested sub-avatar overlaid at the bottom-right of the parent avatar. It always contains exactly one `Avatar`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-clients-companies
|
|
3
|
-
description: Use when an app stores or scopes data by client or company — record keys, scope filters, company selectors, CRM-tab scoping. Clients belong to MANY companies (
|
|
3
|
+
description: Use when an app stores or scopes data by client or company — record keys, scope filters, company selectors, CRM-tab scoping. Clients belong to MANY companies (companyIds[]); a client viewer carries both clientId and active companyId. client.companyId is deprecated.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
Clients and companies are **many-to-many**: a client belongs to many companies via `client.companyIds: string[]`. In the portal, a client can switch between their companies — the viewer's `companyId` always reflects whichever company they currently have active. Apps that ignore this model show incomplete company pickers, or key and filter records on one dimension and then leak a company-A record into the same client's company-B view. This skill covers how to scope, key, and filter records correctly.
|
|
@@ -69,6 +69,10 @@ await assembly.updateClient({
|
|
|
69
69
|
|
|
70
70
|
Send the structured object — a bare string is accepted for backwards compatibility with older data, but it collapses to a single `fullAddress` string and loses city/region/postal code/country as separate values. Every property is optional except that the field is only considered set if `country` or `fullAddress` is non-empty; `fullAddress` is derived automatically from the other components if you omit it.
|
|
71
71
|
|
|
72
|
+
## Every other field type
|
|
73
|
+
|
|
74
|
+
Non-option, non-address fields take a direct string value — stringify numbers and booleans yourself: `{ mrr: '5000' }`, not `{ mrr: 5000 }`.
|
|
75
|
+
|
|
72
76
|
## Symptoms when it goes wrong
|
|
73
77
|
|
|
74
78
|
| Mistake | What you'll see |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-integrations
|
|
3
|
-
description: Use BEFORE declaring requiredIntegrations in .assembly/app.json
|
|
3
|
+
description: Use BEFORE declaring requiredIntegrations in .assembly/app.json or calling getIntegration() from @assembly-js/app-foundation/server (Slack + other providers). Covers manifest declaration, the broker client, per-provider gotchas (pagination, IDs vs names, membership), ConnectorError handling.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
## How it works
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-internal-users
|
|
3
|
-
description: Use when the app
|
|
3
|
+
description: Use when the app reads/lists internal users, or an internal viewer browses clients/companies in the Dashboard. Covers Client Access (isClientAccessLimited, companyAccessList) scoping. Internal users sign into the Dashboard only. Detect via tokenPayload.internalUserId.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
Internal users are the **business team** running the Assembly workspace. They sign into the Dashboard at the workspace's domain, never the branded Client Portal. They have full read/write power over clients, companies, files, etc. — **within their Client Access scope** (see below).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-native-resources
|
|
3
|
-
description: Use any time the app references a native Assembly message channel, form, or portal file/file
|
|
3
|
+
description: Use any time the app references a native Assembly message channel, form, or portal file/file-channel. Never hardcode the ID — discover it at runtime; IDs are workspace-scoped. Not assembly-forms (validation) or assembly-storage (app-private uploads).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
## The non-negotiable
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-notifications
|
|
3
3
|
# <!-- !feature:notification-settings -->
|
|
4
|
-
description: Use when the app
|
|
4
|
+
description: Use when the app must notify internal users or clients about something that happened — in-product, email, or both. Covers createNotification, the Notification Center /n surface, and clearing the client badge (see clearing-client-notifications).
|
|
5
5
|
# <!-- /feature:notification-settings -->
|
|
6
6
|
# <!-- feature:notification-settings -->
|
|
7
|
-
description: Use when the app
|
|
7
|
+
description: Use when the app must notify internal users or clients, or needs per-user notification preferences (Product/Email toggles). Covers createNotification, the /n surface, notificationSettings + notificationSettingId, and clearing the client badge (see clearing-client-notifications).
|
|
8
8
|
# <!-- /feature:notification-settings -->
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!-- feature:platform-mcp -->
|
|
2
2
|
---
|
|
3
3
|
name: assembly-platform-mcp
|
|
4
|
-
description: Use when the app
|
|
4
|
+
description: Use when the app depends on missing workspace config — e.g. no Phone-type client custom field exists yet. Provision it at build time via the scoped platform MCP server (mcp__platform__). Workspace config only — never client-facing data (no clients, messages, notifications, invoices).
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
## Provisioning custom fields at build time
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-route-errors
|
|
3
|
-
description:
|
|
3
|
+
description: REQUIRED in every app/api/**/route.ts handler. Return { error } JSON with the right status; never return err.message — Postgres/driver strings leak. Use handleRouteError/badRequest/notFound/internalError from @assembly-js/app-foundation/server. Validate before hitting DB columns (e.g. parseUuid).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
Route handlers must return safe, user-facing error messages. A `catch` that does `NextResponse.json({ error: err.message }, { status: 500 })` leaks raw Postgres errors (`invalid input syntax for type uuid: "…"`) and other driver internals to the client.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-session-token
|
|
3
|
-
description: Use any time
|
|
3
|
+
description: Use any time the app reads identity, fetches data, or touches auth/token handling. Covers the bearer lifecycle (session token, bearer cookie, getAssembly(), silent re-exchange), getSessionIdentity/useAssembly, useServerAction, authFetch. See assembly-route-auth for requireAuth/requireCompanyScope.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
Auth is **cookie-borne and automatic** — you never handle the session token and you never pass a token to anything. On the first load only, the parent opens your app at `…/?token=<session-token>`. The foundation middleware (`proxy.ts`) exchanges that session token exactly once (server-side, via `POST /v1/session`) for a short-lived **user-scoped bearer** and stores it in an HttpOnly, `SameSite=None` cookie. That mint is the only time the session token is ever used. Every server call your app makes reads the bearer from that cookie — `getAssembly()` returns an authenticated client with no token argument. The bearer lasts 60 minutes; when it expires, `authFetch` and `useServerAction` silently re-exchange (mint a fresh bearer from the parent's current session token via `/api/assembly-reexchange`) and retry — no reload, no code from you.
|
|
@@ -130,17 +130,18 @@ Everything above is **request-scoped**: a user is in the loop and `getAssembly()
|
|
|
130
130
|
|
|
131
131
|
```ts
|
|
132
132
|
// app/api/cron/sync/route.ts — no viewer, no cookie
|
|
133
|
-
import { getOfflineAssembly } from '@assembly-js/app-foundation/server';
|
|
133
|
+
import { getOfflineAssembly, listAll } from '@assembly-js/app-foundation/server';
|
|
134
134
|
|
|
135
135
|
export async function GET() {
|
|
136
136
|
const assembly = await getOfflineAssembly();
|
|
137
|
-
|
|
137
|
+
// Background work must cover everyone — walk every page, not just the first.
|
|
138
|
+
const clients = await listAll((nextToken) => assembly.listClients({ nextToken, limit: 100 }));
|
|
138
139
|
// …background work…
|
|
139
140
|
return Response.json({ ok: true });
|
|
140
141
|
}
|
|
141
142
|
```
|
|
142
143
|
|
|
143
|
-
It **throws** (not returns null) if `ASSEMBLY_API_KEY` is missing or the mint fails — there's no client to re-exchange in the background, so let it propagate. `getSessionIdentity()` returns `null` on this path (the bearer is the app, not a person). Only reach for this outside a request; ignore it for normal UI work.
|
|
144
|
+
It **throws** (not returns null) if `ASSEMBLY_API_KEY` is missing or the mint fails — there's no client to re-exchange in the background, so let it propagate. `getSessionIdentity()` returns `null` on this path (the bearer is the app, not a person). Only reach for this outside a request — using it inside a user request bypasses that viewer's own scope; ignore it for normal UI work.
|
|
144
145
|
|
|
145
146
|
## What NOT to do
|
|
146
147
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assembly-storage
|
|
3
|
-
description:
|
|
3
|
+
description: Use when an app uploads/downloads its own private files (attachments, exports) via pre-signed S3 URLs — the client PUTs bytes directly to S3, never proxied through an API route. NOT for files the user wants in the portal Files tab (use the Files module / createFile).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
## How it works
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clearing-client-notifications
|
|
3
|
-
description: REQUIRED whenever
|
|
3
|
+
description: REQUIRED whenever createNotification is called with recipientClientId. Use when building a client-facing view showing notified content, or a client action completing what a notification prompted — so the sidebar badge clears. Covers clear-on-view vs clear-on-action via clearClientNotifications.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
## Why this exists
|