ids.ts70 lines · main
1import { ulid } from 'ulid';
2
3/**
4 * Prefixed ULID identifiers. Per CLAUDE.md §8.1 every meta-DB row uses a
5 * ULID primary key; human-facing IDs additionally carry a two-or-three letter
6 * prefix so they are self-describing in logs, URLs, and dashboards.
7 *
8 * @example
9 * const projectId = newId('p'); // "p_01HZ5E4..."
10 */
11export type IdPrefix =
12 | 'u' // user
13 | 'a' // account
14 | 'org' // organisation
15 | 'p' // project
16 | 'd' // deployment
17 | 'k' // api key
18 | 'mck' // mcp project key (agent door — mcp.briven.tech)
19 | 'm' // member
20 | 'au' // audit log
21 | 'ar' // abuse report
22 | 'fn' // function record
23 | 'ev' // event
24 | 'inv' // invocation — per-call id attached to function logs
25 | 'iso' // isolate — per-process id used by the runtime pool
26 | 'sup' // email suppression entry
27 | 'dh' // deploy history entry
28 | 'au' // usage event (aggregator row)
29 | 'br' // project branch (preview environment)
30 | 'wf' // workflow definition
31 | 'wfr' // workflow run
32 | 'sch' // schedule (cron-triggered function invocation)
33 | 'sr' // schedule run (per-fire audit record)
34 | 'f' // file (project storage object)
35 | 'whe' // webhook endpoint (customer-defined inbound webhook)
36 | 'whd' // webhook delivery (per-incoming-request log row)
37 | 'whs' // webhook subscriber (customer-defined outbound webhook target)
38 | 'whod' // webhook outbound delivery (per-fanout attempt log row)
39 | 'wev' // webhook event (an emitted platform event, fans out to N deliveries)
40 | 'al' // allowlist entry (invite-only beta signup gate)
41 | 'mig' // migration request (customer-initiated import from convex/supabase/etc.)
42 | 'me' // marketing event (funnel tracking for /migrate views + leads)
43 | 'auk' // briven auth SDK key (issued from the Auth → API Keys panel)
44 | 'as' // auto-snapshot settings row (per-project automatic save-points)
45 | 'agt' // platform agent (admin-registered AI agent, encrypted provider key)
46 | 'ctc' // contact message (public /contact submission; ticketed or plain)
47 | 'crp' // contact message reply (operator/user reply on a message thread)
48 | 'ao' // allowed app origin (per-project login domain for CORS + auth trust)
49 | 'sk' // storage key (per-project scoped MinIO service-account key)
50 | 'sg' // storage grant (cross-project sharing grant — granter→grantee resource)
51 | 'sl' // storage share-link (tokenized public download link — time-limited, revocable)
52 | 'kans' // known-answer (briven_ask self-growing knowledge-base row)
53 | 'tsec' // tenant secret (per-project encrypted credential, e.g. provider keys)
54 | 'beu' // briven-engine end-user (Auth product, Doltgres vault)
55 | 'btp' // briven-engine third-party link
56 | 'btd' // briven-engine TOTP device
57 | 'bwc' // briven-engine webauthn credential
58 | 'bsc' // briven-engine SSO connection (SAML/OIDC)
59
60export function newId(prefix: IdPrefix): string {
61 return `${prefix}_${ulid()}`;
62}
63
64export function isId(value: unknown, prefix: IdPrefix): value is `${IdPrefix}_${string}` {
65 return (
66 typeof value === 'string' &&
67 value.startsWith(`${prefix}_`) &&
68 value.length === prefix.length + 27
69 );
70}