@topolo/sdk 0.7.0 → 0.8.1

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.
@@ -1,517 +0,0 @@
1
- import {
2
- APPLICATIONS,
3
- type ApplicationCatalogEntry,
4
- type ApplicationId,
5
- } from './applications.generated.js';
6
-
7
- export const APPLICATION_REQUIREMENTS_VERSION = '2026-06-07.1';
8
-
9
- export type ApplicationRequirementScope =
10
- | 'all'
11
- | 'browser'
12
- | 'api'
13
- | 'tooling'
14
- | 'agent_surface';
15
-
16
- export interface ApplicationRequirement {
17
- id: string;
18
- title: string;
19
- summary: string;
20
- appliesTo: readonly ApplicationRequirementScope[];
21
- evidence: readonly string[];
22
- implementation: readonly string[];
23
- }
24
-
25
- export type ApplicationRequirementStatus = 'met' | 'partial' | 'missing' | 'needs_review';
26
-
27
- export interface ApplicationRequirementFinding {
28
- requirementId: string;
29
- title: string;
30
- status: ApplicationRequirementStatus;
31
- reason: string;
32
- evidence: readonly string[];
33
- nextActions: readonly string[];
34
- }
35
-
36
- export interface ApplicationRequirementScore {
37
- met: number;
38
- partial: number;
39
- missing: number;
40
- needsReview: number;
41
- total: number;
42
- percent: number;
43
- }
44
-
45
- export interface ApplicationRequirementAudit {
46
- version: string;
47
- application: ApplicationCatalogEntry;
48
- scopes: ApplicationRequirementScope[];
49
- score: ApplicationRequirementScore;
50
- findings: ApplicationRequirementFinding[];
51
- }
52
-
53
- export interface ApplicationRequirementMigrationItem {
54
- applicationId: ApplicationId;
55
- applicationName: string;
56
- requirementId: string;
57
- title: string;
58
- status: Exclude<ApplicationRequirementStatus, 'met'>;
59
- reason: string;
60
- nextActions: readonly string[];
61
- }
62
-
63
- export interface ApplicationRequirementsAuditReport {
64
- version: string;
65
- applications: ApplicationRequirementAudit[];
66
- migrationQueue: ApplicationRequirementMigrationItem[];
67
- }
68
-
69
- export const APPLICATION_REQUIREMENTS = [
70
- {
71
- id: 'platform-metadata',
72
- title: 'Register the application in platform metadata',
73
- summary:
74
- 'Every app must have a stable application ID, CloudControl metadata for deployed surfaces, and package metadata where code is shipped.',
75
- appliesTo: ['all'],
76
- evidence: [
77
- 'topolo.cloudcontrol.json exists for every deployed app surface',
78
- 'package.json names the package or app when the repo ships code',
79
- 'The SDK application catalog exposes the app through topolo apps and MCP discovery',
80
- ],
81
- implementation: [
82
- 'Add the app to the SDK application catalog generator before exposing it to agents',
83
- 'Keep production URLs, Worker names, Pages projects, routes, domains, and bindings current in CloudControl metadata',
84
- 'Do not leave a new Topolo* app directory without an explicit application ID',
85
- ],
86
- },
87
- {
88
- id: 'canonical-docs',
89
- title: 'Update canonical docs with the code change',
90
- summary:
91
- 'TopoloDocs is the source of truth for application behavior, ownership, deployment shape, auth boundaries, and operations.',
92
- appliesTo: ['all'],
93
- evidence: [
94
- 'Matching system registry entry exists in TopoloDocs',
95
- 'Internal handbook coverage exists for the system',
96
- 'npm run validate passes in TopoloDocs when docs are touched',
97
- ],
98
- implementation: [
99
- 'Read the matching TopoloDocs system entry before coding',
100
- 'Update docs in the same change when behavior, API, auth, data ownership, deployment, or operations change',
101
- 'Update last_verified dates on touched canonical pages',
102
- ],
103
- },
104
- {
105
- id: 'shared-auth-boundary',
106
- title: 'Use the shared Topolo auth boundary',
107
- summary:
108
- 'Applications must derive identity, organization, scopes, and app entitlement from TopoloAuth rather than inventing parallel auth state.',
109
- appliesTo: ['browser', 'api', 'tooling', 'agent_surface'],
110
- evidence: [
111
- '@topolo/auth-client or @topolo-io/worker-runtime is used where applicable',
112
- 'No public command, tool, or SDK method accepts orgId',
113
- 'App slug and Auth app registration are documented for protected APIs',
114
- ],
115
- implementation: [
116
- 'Use shared auth/runtime packages instead of copying token parsing, gateway, or browser storage flows',
117
- 'Derive organization from the credential on every request',
118
- 'Route OAuth, refresh, logout, and SSO paths according to the shared Auth contract',
119
- ],
120
- },
121
- {
122
- id: 'shared-shell-and-launcher',
123
- title: 'Use the shared shell, launcher, and account menu',
124
- summary:
125
- 'Browser applications should feel like one platform and should not create isolated navigation or account surfaces.',
126
- appliesTo: ['browser'],
127
- evidence: [
128
- '@topolo-io/app-shell is used for the platform shell where the app has authenticated UI',
129
- '@topolo-io/app-launcher keeps the shared launcher/app switcher reachable from authenticated app chrome',
130
- 'Account menu and sign-out behavior use TopoloAppShell or the ui-kit TopoloAccountMenu primitive',
131
- 'Repeated app body surfaces use shared TopoloAppLayout primitives instead of local stat cards, empty states, or status badges',
132
- 'Local preview supports deterministic visual QA fixtures for overview, list, detail, settings, and empty/loading states',
133
- 'Authenticated app body content stays inside the viewport on mobile and desktop widths',
134
- ],
135
- implementation: [
136
- 'Use @topolo-io/app-shell TopoloAppShell for authenticated app layouts',
137
- 'Use the @topolo-io/ui-kit TopoloAccountMenu primitive when a partial-shell surface still needs account chrome',
138
- 'Pass app-specific account actions as additive menu items instead of forking dropdowns',
139
- 'Use shared design tokens and platform UI primitives before creating local equivalents',
140
- 'Use TopoloAppMetricCard, TopoloAppEmptyState, TopoloAppStatusBadge, TopoloAppGrid, and TopoloAppSection for repeated app body patterns',
141
- 'Keep visual QA fixtures available through visualQa=1 or __devpreview=1 so screenshot checks do not depend on live API state',
142
- 'Keep mobile and desktop shell behavior aligned with the platform UI kit',
143
- 'Constrain app-owned workspace wrappers with min-width: 0, width: auto, and viewport-aware max-width so shell padding cannot create page-level horizontal overflow',
144
- ],
145
- },
146
- {
147
- id: 'app-registration-and-scopes',
148
- title: 'Register protected APIs as platform apps',
149
- summary:
150
- 'Callable app APIs need a stable app ID, app slug, permissions, role bundles, and API-key scopes before agents or users rely on them.',
151
- appliesTo: ['api'],
152
- evidence: [
153
- 'Auth app catalog contains the app ID and slug',
154
- 'Permissions, role bundles, and API-key scopes exist for the app',
155
- 'SDK, CLI, and MCP app discovery include the callable production API',
156
- 'CloudControl production HTTP targets classify agent reachability with sdk_app_id or agent_callable:false',
157
- ],
158
- implementation: [
159
- 'Add production Worker api_url metadata and sdk_app_id for every agent-callable API target',
160
- 'Mark browser, documentation, and runtime-only Worker targets with agent_callable:false',
161
- 'Expose stable app IDs through generated DEFAULT_APP_URLS and live catalog discovery',
162
- 'Keep typed SDK/CLI/MCP surfaces in sync when an API contract stabilizes',
163
- ],
164
- },
165
- {
166
- id: 'organization-scoped-data',
167
- title: 'Keep application data organization-scoped',
168
- summary:
169
- 'Protected data access must be scoped by the authenticated organization at the backend boundary, not by client-provided hints.',
170
- appliesTo: ['api'],
171
- evidence: [
172
- 'Backend request handlers derive org membership from credential validation',
173
- 'Queries and Durable Object keys include the authenticated organization boundary where data is tenant-owned',
174
- 'MCP and CLI inputs do not include orgId overrides',
175
- ],
176
- implementation: [
177
- 'Reject or ignore organization hints supplied by clients',
178
- 'Bind SQL, KV, R2, queue, and Durable Object access to the authenticated organization',
179
- 'Document service-local exceptions explicitly in the system security assurance record',
180
- ],
181
- },
182
- {
183
- id: 'cloudflare-deployment-contract',
184
- title: 'Keep Cloudflare deployment metadata complete',
185
- summary:
186
- 'Workers, Pages, bindings, routes, env vars, queues, cron triggers, and deployment commands must be discoverable through CloudControl metadata.',
187
- appliesTo: ['browser', 'api'],
188
- evidence: [
189
- 'topolo.cloudcontrol.json lists production deploy targets and URLs',
190
- 'Wrangler/Pages configuration matches CloudControl metadata',
191
- 'Secrets and environment variables are not committed',
192
- ],
193
- implementation: [
194
- 'Update CloudControl metadata whenever deployment topology changes',
195
- 'Prefer Cloudflare-native runtime surfaces for new Topolo app infrastructure',
196
- 'Keep Worker bindings and Pages domains explicit enough for agents to inspect before deploying',
197
- ],
198
- },
199
- {
200
- id: 'agent-and-operator-surfaces',
201
- title: 'Expose agent-safe operations through SDK, CLI, and MCP',
202
- summary:
203
- 'Agent-accessible functionality should be discoverable, scope-gated, and write-confirmed instead of hidden behind ad hoc HTTP calls.',
204
- appliesTo: ['api', 'tooling', 'agent_surface'],
205
- evidence: [
206
- 'Read operations have typed SDK/CLI/MCP surfaces once their contract stabilizes',
207
- 'Mutating generic calls require --confirm or confirm:true',
208
- 'MCP tools never accept orgId and advertise only appropriate scope-gated tools',
209
- ],
210
- implementation: [
211
- 'Add SDK types first, then CLI commands and MCP tools for durable workflows',
212
- 'Use generic API passthrough only as a temporary escape hatch',
213
- 'Keep command output JSON-stable for agents and human-readable with --no-json',
214
- ],
215
- },
216
- {
217
- id: 'native-dashboard-widget',
218
- title: 'Expose a native dashboard widget contract',
219
- summary:
220
- 'Launchable first-party applications must populate TopoloOne live workspace through an app-owned /api/widget endpoint using the SDK widget response contract.',
221
- appliesTo: ['api'],
222
- evidence: [
223
- 'The app-owned API exposes GET /api/widget',
224
- 'The endpoint returns TopoloWidgetApiResponse from @topolo/sdk',
225
- 'Every returned widget includes snapshot.summary with app-owned operational prose',
226
- 'The endpoint derives organization/user context from the app auth boundary',
227
- ],
228
- implementation: [
229
- 'Import createTopoloWidgetResponse from @topolo/sdk in the app backend',
230
- 'Return native app metrics or action widgets instead of generic launch-card fallbacks',
231
- 'Populate snapshot.summary in the producing app for every widget instead of synthesizing summaries in TopoloOne',
232
- 'Add a route-level test that validates the response with validateTopoloWidgetResponse',
233
- ],
234
- },
235
- {
236
- id: 'observability-and-audit',
237
- title: 'Emit platform audit and debugging signals',
238
- summary:
239
- 'Requests, agent actions, and operational workflows need traceable IDs, client labels, and useful failure evidence.',
240
- appliesTo: ['api', 'tooling', 'agent_surface'],
241
- evidence: [
242
- 'Requests carry X-Topolo-Client and X-Topolo-Request-Id where the SDK is involved',
243
- 'Agent-originated calls can include X-Topolo-Agent',
244
- 'Failure modes are documented with request IDs or deployment/log lookup paths',
245
- ],
246
- implementation: [
247
- 'Use TopoloClient for platform API calls rather than raw fetch where practical',
248
- 'Keep logs free of secrets and tokens',
249
- 'Document live smoke commands and request-id correlation in canonical docs',
250
- ],
251
- },
252
- {
253
- id: 'verification-gates',
254
- title: 'Ship with build, test, docs, and smoke verification',
255
- summary:
256
- 'A Topolo app change is not complete until the relevant code checks and docs checks have been run or explicitly reported as blocked.',
257
- appliesTo: ['all'],
258
- evidence: [
259
- 'Relevant package build/typecheck/test commands pass',
260
- 'TopoloDocs validation passes when docs are touched',
261
- 'Live or local smoke evidence is captured for user-visible or API behavior',
262
- ],
263
- implementation: [
264
- 'Prefer existing package scripts before adding new tooling',
265
- 'Run app-specific checks and shared docs validation for behavior changes',
266
- 'Report any skipped verification with the blocker and residual risk',
267
- ],
268
- },
269
- ] as const satisfies readonly ApplicationRequirement[];
270
-
271
- export function applicationRequirementScopes(
272
- application: ApplicationCatalogEntry,
273
- ): ApplicationRequirementScope[] {
274
- const scopes = new Set<ApplicationRequirementScope>(['all']);
275
- // id is checked by value: tooling ids (cli/mcp) are intentionally not in
276
- // the deploy catalog union, so compare as string rather than assert overlap.
277
- const appId: string = application.id;
278
- const hasBrowserSurface =
279
- Boolean(application.productionUrl) ||
280
- // String() keeps this guard valid after the Pages->Worker migration narrowed
281
- // the generated kind union to "worker" (no "pages" literal remains).
282
- application.deployTargets.some((target) => String(target.kind) === 'pages');
283
- // An API surface means an agent-callable service — keyed on a resolved
284
- // appId, NOT a bare apiUrl. After the Pages->Worker migration every
285
- // frontend shell carries an apiUrl (its own serving domain), so apiUrl is no
286
- // longer a signal for "exposes a callable API"; appId is.
287
- const hasApiSurface =
288
- application.services.length > 0 ||
289
- application.deployTargets.some((target) => Boolean(target.appId));
290
-
291
- if (hasBrowserSurface) scopes.add('browser');
292
- if (hasApiSurface) scopes.add('api');
293
- if (appId === 'cli' || appId === 'mcp' || appId === 'cloudcontrol') {
294
- scopes.add('tooling');
295
- }
296
- if (appId === 'cli' || appId === 'mcp' || hasApiSurface) {
297
- scopes.add('agent_surface');
298
- }
299
-
300
- return Array.from(scopes);
301
- }
302
-
303
- export function requirementsForApplication(
304
- applicationOrId: ApplicationCatalogEntry | ApplicationId,
305
- ): ApplicationRequirement[] {
306
- const application =
307
- typeof applicationOrId === 'string' ? APPLICATIONS[applicationOrId] : applicationOrId;
308
- const scopes = new Set(applicationRequirementScopes(application));
309
- return APPLICATION_REQUIREMENTS.filter((requirement) =>
310
- requirement.appliesTo.some((scope) => scopes.has(scope)),
311
- );
312
- }
313
-
314
- export function auditApplicationRequirements(
315
- applicationOrId: ApplicationCatalogEntry | ApplicationId,
316
- ): ApplicationRequirementAudit {
317
- const application =
318
- typeof applicationOrId === 'string' ? APPLICATIONS[applicationOrId] : applicationOrId;
319
- const scopes = applicationRequirementScopes(application);
320
- const findings = requirementsForApplication(application).map((requirement) =>
321
- evaluateRequirement(application, requirement),
322
- );
323
-
324
- return {
325
- version: APPLICATION_REQUIREMENTS_VERSION,
326
- application,
327
- scopes,
328
- score: scoreFindings(findings),
329
- findings,
330
- };
331
- }
332
-
333
- export function auditAllApplicationRequirements(
334
- applicationIds: readonly ApplicationId[] = Object.keys(APPLICATIONS).sort() as ApplicationId[],
335
- ): ApplicationRequirementsAuditReport {
336
- const applications = applicationIds.map((applicationId) =>
337
- auditApplicationRequirements(applicationId),
338
- );
339
- const migrationQueue = applications
340
- .flatMap((audit) =>
341
- audit.findings
342
- .filter((finding): finding is ApplicationRequirementFinding & {
343
- status: Exclude<ApplicationRequirementStatus, 'met'>;
344
- } => finding.status !== 'met')
345
- .map((finding) => ({
346
- applicationId: audit.application.id as ApplicationId,
347
- applicationName: audit.application.name,
348
- requirementId: finding.requirementId,
349
- title: finding.title,
350
- status: finding.status,
351
- reason: finding.reason,
352
- nextActions: finding.nextActions,
353
- })),
354
- )
355
- .sort((a, b) => {
356
- const statusOrder = statusRank(a.status) - statusRank(b.status);
357
- if (statusOrder !== 0) return statusOrder;
358
- const appOrder = a.applicationId.localeCompare(b.applicationId);
359
- if (appOrder !== 0) return appOrder;
360
- return a.requirementId.localeCompare(b.requirementId);
361
- });
362
-
363
- return {
364
- version: APPLICATION_REQUIREMENTS_VERSION,
365
- applications,
366
- migrationQueue,
367
- };
368
- }
369
-
370
- function evaluateRequirement(
371
- application: ApplicationCatalogEntry,
372
- requirement: ApplicationRequirement,
373
- ): ApplicationRequirementFinding {
374
- const evidence: string[] = [];
375
-
376
- switch (requirement.id) {
377
- case 'platform-metadata': {
378
- if (application.packageName) evidence.push(`package=${application.packageName}`);
379
- if (application.productionUrl) evidence.push(`productionUrl=${application.productionUrl}`);
380
- if (application.deployTargets.length > 0) {
381
- evidence.push(`deployTargets=${application.deployTargets.length}`);
382
- }
383
- if (application.services.length > 0) {
384
- evidence.push(`services=${application.services.join(',')}`);
385
- }
386
-
387
- if (evidence.length === 0) {
388
- return finding(requirement, 'missing', 'No package, production URL, deploy target, or service metadata is available.', evidence);
389
- }
390
- return finding(requirement, 'met', 'Catalog metadata exists for this application.', evidence);
391
- }
392
- case 'canonical-docs':
393
- return finding(
394
- requirement,
395
- 'needs_review',
396
- 'Catalog metadata cannot verify matching TopoloDocs system and handbook coverage.',
397
- evidence,
398
- );
399
- case 'shared-auth-boundary':
400
- return finding(
401
- requirement,
402
- 'needs_review',
403
- 'Catalog metadata cannot verify that implementation uses shared Topolo auth packages and derives org from credentials.',
404
- evidence,
405
- );
406
- case 'shared-shell-and-launcher':
407
- return finding(
408
- requirement,
409
- 'needs_review',
410
- 'Catalog metadata cannot verify shared shell, launcher, and account menu adoption.',
411
- evidence,
412
- );
413
- case 'app-registration-and-scopes': {
414
- if (application.services.length > 0) {
415
- evidence.push(`services=${application.services.join(',')}`);
416
- return finding(
417
- requirement,
418
- 'partial',
419
- 'SDK service discovery exists, but Auth catalog permissions, role bundles, and API-key scopes still need confirmation.',
420
- evidence,
421
- );
422
- }
423
- return finding(requirement, 'missing', 'No SDK app API id is registered for this callable API surface.', evidence);
424
- }
425
- case 'organization-scoped-data':
426
- return finding(
427
- requirement,
428
- 'needs_review',
429
- 'Catalog metadata cannot verify backend tenant filters, storage keys, or Durable Object boundaries.',
430
- evidence,
431
- );
432
- case 'cloudflare-deployment-contract': {
433
- // `< 1` rather than `=== 0`: every catalogued app now has >=1 deploy target,
434
- // so the generated tuple-length union excludes 0 and `=== 0` fails typecheck.
435
- if (application.deployTargets.length < 1) {
436
- return finding(requirement, 'missing', 'No CloudControl deploy targets are registered.', evidence);
437
- }
438
- evidence.push(`deployTargets=${application.deployTargets.length}`);
439
- if (application.productionUrl) evidence.push(`productionUrl=${application.productionUrl}`);
440
- return finding(requirement, 'met', 'CloudControl deploy target metadata is present.', evidence);
441
- }
442
- case 'agent-and-operator-surfaces': {
443
- const appId: string = application.id;
444
- if (application.services.length > 0) {
445
- evidence.push(`services=${application.services.join(',')}`);
446
- return finding(requirement, 'partial', 'SDK service discovery exists; typed SDK/CLI/MCP workflow coverage should be checked as APIs stabilize.', evidence);
447
- }
448
- if (appId === 'cli' || appId === 'mcp' || appId === 'cloudcontrol') {
449
- evidence.push(`tooling=${appId}`);
450
- return finding(requirement, 'met', 'This application is itself an agent/operator surface.', evidence);
451
- }
452
- return finding(requirement, 'missing', 'No SDK service or tooling surface is registered.', evidence);
453
- }
454
- case 'native-dashboard-widget':
455
- return finding(
456
- requirement,
457
- 'needs_review',
458
- 'Catalog metadata cannot verify app-owned /api/widget implementation details.',
459
- evidence,
460
- );
461
- case 'observability-and-audit':
462
- return finding(
463
- requirement,
464
- 'needs_review',
465
- 'Catalog metadata cannot verify runtime request IDs, client labels, or log redaction.',
466
- evidence,
467
- );
468
- case 'verification-gates':
469
- return finding(
470
- requirement,
471
- 'needs_review',
472
- 'Catalog metadata cannot verify package checks, docs validation, or smoke evidence.',
473
- evidence,
474
- );
475
- default:
476
- return finding(requirement, 'needs_review', 'No automated evaluator exists for this requirement yet.', evidence);
477
- }
478
- }
479
-
480
- function finding(
481
- requirement: ApplicationRequirement,
482
- status: ApplicationRequirementStatus,
483
- reason: string,
484
- evidence: readonly string[],
485
- ): ApplicationRequirementFinding {
486
- return {
487
- requirementId: requirement.id,
488
- title: requirement.title,
489
- status,
490
- reason,
491
- evidence,
492
- nextActions: status === 'met' ? [] : requirement.implementation,
493
- };
494
- }
495
-
496
- function scoreFindings(findings: readonly ApplicationRequirementFinding[]): ApplicationRequirementScore {
497
- const met = findings.filter((finding) => finding.status === 'met').length;
498
- const partial = findings.filter((finding) => finding.status === 'partial').length;
499
- const missing = findings.filter((finding) => finding.status === 'missing').length;
500
- const needsReview = findings.filter((finding) => finding.status === 'needs_review').length;
501
- const total = findings.length;
502
- const weighted = met + partial * 0.5;
503
- return {
504
- met,
505
- partial,
506
- missing,
507
- needsReview,
508
- total,
509
- percent: total === 0 ? 100 : Math.round((weighted / total) * 100),
510
- };
511
- }
512
-
513
- function statusRank(status: Exclude<ApplicationRequirementStatus, 'met'>): number {
514
- if (status === 'missing') return 0;
515
- if (status === 'partial') return 1;
516
- return 2;
517
- }