@mettlecast/domain-cli 0.2.59 → 0.2.61

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.
Files changed (119) hide show
  1. package/dist/builder/build-registry.d.ts +1 -1
  2. package/dist/builder/build-registry.js +129 -49
  3. package/dist/builder/build-types.d.ts +1 -1
  4. package/dist/builder/load-module.d.ts +1 -1
  5. package/dist/builder/load-module.js +3 -3
  6. package/dist/cli.js +3 -3
  7. package/dist/commands/add-api.js +2 -2
  8. package/dist/commands/add-domain.js +4 -4
  9. package/dist/commands/add-fixture-factory.js +5 -6
  10. package/dist/commands/build-catalog.d.ts +8 -24
  11. package/dist/commands/build-catalog.js +12 -23
  12. package/dist/commands/build-flows.js +1 -1
  13. package/dist/commands/build.js +7 -6
  14. package/dist/commands/check-hashes.js +2 -2
  15. package/dist/commands/create-project.js +1 -1
  16. package/dist/commands/dev.js +1 -1
  17. package/dist/commands/doctor.d.ts +5 -7
  18. package/dist/commands/doctor.js +110 -202
  19. package/dist/commands/explain.js +13 -13
  20. package/dist/commands/generate-openapi.d.ts +10 -1
  21. package/dist/commands/generate-openapi.js +19 -33
  22. package/dist/commands/power-tune.js +2 -2
  23. package/dist/commands/show-dns.d.ts +1 -1
  24. package/dist/commands/show-dns.js +5 -5
  25. package/dist/commands/show.d.ts +2 -3
  26. package/dist/commands/show.js +0 -2
  27. package/dist/commands/test.js +0 -1
  28. package/dist/commands/upgrade-backend.js +3 -3
  29. package/dist/commands/upgrade.js +17 -11
  30. package/dist/commands/validate.js +144 -39
  31. package/dist/server/api-server.d.ts +1 -1
  32. package/dist/server/mount-routes.d.ts +11 -2
  33. package/dist/server/mount-routes.js +20 -8
  34. package/dist/templates/api-skeleton.d.ts +5 -0
  35. package/dist/templates/api-skeleton.js +28 -27
  36. package/dist/templates/claude-md.js +1 -1
  37. package/dist/templates/patterns/api/create-with-event.d.ts +4 -0
  38. package/dist/templates/patterns/api/create-with-event.js +38 -32
  39. package/dist/templates/patterns/api/idempotent-mutation.d.ts +4 -0
  40. package/dist/templates/patterns/api/idempotent-mutation.js +47 -41
  41. package/dist/templates/patterns/api/paginated-list.d.ts +4 -0
  42. package/dist/templates/patterns/api/paginated-list.js +30 -24
  43. package/dist/templates/patterns/api/simple-crud.d.ts +4 -0
  44. package/dist/templates/patterns/api/simple-crud.js +46 -35
  45. package/dist/templates/patterns/api/streaming-list.d.ts +4 -0
  46. package/dist/templates/patterns/api/streaming-list.js +46 -41
  47. package/dist/templates/patterns/api/system-admin.d.ts +4 -0
  48. package/dist/templates/patterns/api/system-admin.js +59 -52
  49. package/dist/templates/patterns/api/webhook-receiver-style.d.ts +4 -0
  50. package/dist/templates/patterns/api/webhook-receiver-style.js +43 -35
  51. package/dist/types.d.ts +100 -0
  52. package/dist/types.js +1 -0
  53. package/dist/utils/file-helpers.d.ts +0 -2
  54. package/dist/utils/file-helpers.js +2 -3
  55. package/dist/utils/header-inject.js +2 -2
  56. package/dist/utils/install-file.d.ts +1 -1
  57. package/dist/utils/install-file.js +1 -1
  58. package/dist/utils/manifest.js +1 -2
  59. package/dist/utils/scaffold-config.d.ts +8 -2
  60. package/dist/utils/scaffold-config.js +3 -1
  61. package/package.json +1 -1
  62. package/src/__tests__/build-registry.test.ts +43 -20
  63. package/src/__tests__/build-types.test.ts +4 -7
  64. package/src/__tests__/builder/walkDomainDir.test.ts +19 -21
  65. package/src/__tests__/commands/add-api.test.ts +12 -10
  66. package/src/__tests__/commands/add-domain.test.ts +8 -5
  67. package/src/__tests__/commands/check-hashes.test.ts +9 -9
  68. package/src/__tests__/commands/create-project.test.ts +5 -5
  69. package/src/__tests__/commands/dev.test.ts +0 -1
  70. package/src/__tests__/commands/upgrade.test.ts +7 -7
  71. package/src/__tests__/doctor.test.ts +60 -67
  72. package/src/__tests__/mount-routes.test.ts +64 -23
  73. package/src/__tests__/package-freshness.test.ts +94 -0
  74. package/src/__tests__/scaffold-src/part-a-layout.test.ts +10 -10
  75. package/src/__tests__/scripts/package-scaffold.test.ts +5 -5
  76. package/src/__tests__/smoke/scaffold.test.ts +13 -15
  77. package/src/__tests__/utils/install-file.test.ts +2 -2
  78. package/src/__tests__/utils/manifest.test.ts +2 -2
  79. package/src/__tests__/validate.test.ts +570 -1
  80. package/src/builder/build-registry.ts +154 -59
  81. package/src/builder/build-types.ts +1 -1
  82. package/src/builder/load-module.ts +3 -3
  83. package/src/cli.ts +4 -4
  84. package/src/commands/add-api.ts +2 -2
  85. package/src/commands/add-domain.ts +4 -4
  86. package/src/commands/add-fixture-factory.ts +5 -6
  87. package/src/commands/build-catalog.ts +18 -40
  88. package/src/commands/build-flows.ts +1 -1
  89. package/src/commands/build.ts +8 -7
  90. package/src/commands/check-hashes.ts +2 -2
  91. package/src/commands/create-project.ts +1 -1
  92. package/src/commands/dev.ts +1 -1
  93. package/src/commands/doctor.ts +120 -218
  94. package/src/commands/explain.ts +13 -13
  95. package/src/commands/generate-openapi.ts +30 -52
  96. package/src/commands/power-tune.ts +2 -2
  97. package/src/commands/show-dns.ts +5 -5
  98. package/src/commands/show.ts +2 -5
  99. package/src/commands/test.ts +0 -1
  100. package/src/commands/upgrade-backend.ts +3 -3
  101. package/src/commands/upgrade.ts +16 -10
  102. package/src/commands/validate.ts +180 -40
  103. package/src/server/api-server.ts +1 -1
  104. package/src/server/mount-routes.ts +21 -10
  105. package/src/templates/api-skeleton.ts +29 -28
  106. package/src/templates/claude-md.ts +1 -1
  107. package/src/templates/patterns/api/create-with-event.ts +39 -33
  108. package/src/templates/patterns/api/idempotent-mutation.ts +48 -42
  109. package/src/templates/patterns/api/paginated-list.ts +31 -25
  110. package/src/templates/patterns/api/simple-crud.ts +47 -36
  111. package/src/templates/patterns/api/streaming-list.ts +47 -42
  112. package/src/templates/patterns/api/system-admin.ts +60 -53
  113. package/src/templates/patterns/api/webhook-receiver-style.ts +48 -40
  114. package/src/types.ts +128 -0
  115. package/src/utils/file-helpers.ts +2 -5
  116. package/src/utils/header-inject.ts +2 -2
  117. package/src/utils/install-file.ts +1 -1
  118. package/src/utils/manifest.ts +1 -2
  119. package/src/utils/scaffold-config.ts +12 -3
@@ -19,6 +19,10 @@
19
19
  * - API Gateway HTTP API with 2.0 payload format (not REST API)
20
20
  * - Lambda runtime v20+
21
21
  *
22
+ * Action-first: HTTP endpoints are declared with `defineAction` +
23
+ * `exposure: { type: 'api', ... }`. The legacy `defineApi` factory was
24
+ * removed in #4689.
25
+ *
22
26
  * @param domain - Domain ID in kebab-case
23
27
  * @param apiId - API ID in kebab-case
24
28
  * @param itemName - Singular item name (e.g. 'ticket', 'member')
@@ -26,7 +30,7 @@
26
30
  */
27
31
  export function streamingListPattern(domain, apiId, itemName) {
28
32
  return `import { z } from 'zod';
29
- import { defineApi } from '@mettlecast/domain-runtime';
33
+ import { defineAction } from '@mettlecast/domain-runtime';
30
34
  import type { Result, AppError } from '@mettlecast/domain-runtime';
31
35
 
32
36
  const ${itemName}Schema = z.object({ id: z.string() });
@@ -39,53 +43,54 @@ const outputSchema = z.object({
39
43
  nextCursor: z.string().optional(),
40
44
  }).default({ items: [] });
41
45
 
42
- export const ${apiId.replace(/-/g, '_')} = defineApi({
46
+ export const ${apiId.replace(/-/g, '_')} = defineAction({
43
47
  id: '${apiId}',
44
- path: '/v1/${domain}/${apiId}',
45
- method: 'GET',
46
- tenancy: 'required',
48
+ backendAccess: 'domain',
49
+ exposure: {
50
+ type: 'api',
51
+ path: '/v1/tenants/{tenantId}/${domain}/${apiId}',
52
+ method: 'GET',
53
+ auth: 'required',
54
+ tenancy: 'required',
55
+ },
47
56
  outboundAccess: 'internal',
48
- versions: {
49
- v1: {
50
- status: 'stable',
51
- input: inputSchema,
52
- output: outputSchema,
53
- handler: async (input, ctx): Promise<Result<z.infer<typeof outputSchema>, AppError>> => {
54
- // Streaming response: each item is yielded as a JSON line
55
- // before the full query completes. The runtime handler
56
- // wrapper converts this generator into a chunked response.
57
- //
58
- // GET /v1/${domain}/${apiId}?limit=100
59
- // Transfer-Encoding: chunked
60
- // Content-Type: application/x-ndjson
61
- //
62
- // {"id":"1"}\\n
63
- // {"id":"2"}\\n
64
- // {"id":"3"}\\n
57
+ idempotent: true,
58
+ input: inputSchema,
59
+ output: outputSchema,
60
+ handler: async (input, ctx): Promise<Result<z.infer<typeof outputSchema>, AppError>> => {
61
+ // Streaming response: each item is yielded as a JSON line
62
+ // before the full query completes. The runtime handler
63
+ // wrapper converts this generator into a chunked response.
64
+ //
65
+ // GET /v1/${domain}/${apiId}?limit=100
66
+ // Transfer-Encoding: chunked
67
+ // Content-Type: application/x-ndjson
68
+ //
69
+ // {"id":"1"}\\n
70
+ // {"id":"2"}\\n
71
+ // {"id":"3"}\\n
65
72
 
66
- let nextCursor: string | undefined;
67
- const items: unknown[] = [];
73
+ let nextCursor: string | undefined;
74
+ const items: unknown[] = [];
68
75
 
69
- // Replace this query with your actual data source.
70
- const rows = await ctx.db.query(
71
- '${domain}',
72
- 'SELECT id FROM ${domain}s LIMIT $1 OFFSET $2',
73
- [input.limit + 1, input.cursor ? parseInt(input.cursor, 10) : 0],
74
- );
76
+ // Replace this query with your actual data source.
77
+ const rows = await ctx.db.query(
78
+ '${domain}',
79
+ 'SELECT id FROM ${domain}s LIMIT $1 OFFSET $2',
80
+ [input.limit + 1, input.cursor ? parseInt(input.cursor, 10) : 0],
81
+ );
75
82
 
76
- for (let i = 0; i < Math.min(rows.length, input.limit); i++) {
77
- items.push(rows[i]);
78
- }
83
+ for (let i = 0; i < Math.min(rows.length, input.limit); i++) {
84
+ items.push(rows[i]);
85
+ }
79
86
 
80
- if (rows.length > input.limit) {
81
- nextCursor = String(
82
- (input.cursor ? parseInt(input.cursor, 10) : 0) + input.limit,
83
- );
84
- }
87
+ if (rows.length > input.limit) {
88
+ nextCursor = String(
89
+ (input.cursor ? parseInt(input.cursor, 10) : 0) + input.limit,
90
+ );
91
+ }
85
92
 
86
- return { ok: true, value: { items, nextCursor } };
87
- },
88
- },
93
+ return { ok: true, value: { items, nextCursor } };
89
94
  },
90
95
  });
91
96
  `;
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * System-admin API pattern template.
3
3
  * Produces: GET/POST with tenancy: 'system', no tenant context.
4
+ *
5
+ * Action-first: HTTP endpoints are declared with `defineAction` +
6
+ * `exposure: { type: 'api', ... }`. The legacy `defineApi` factory was
7
+ * removed in #4689.
4
8
  */
5
9
  export declare function systemAdminTemplate(domain: string, id: string, tenancy: string): string;
6
10
  /**
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * System-admin API pattern template.
3
3
  * Produces: GET/POST with tenancy: 'system', no tenant context.
4
+ *
5
+ * Action-first: HTTP endpoints are declared with `defineAction` +
6
+ * `exposure: { type: 'api', ... }`. The legacy `defineApi` factory was
7
+ * removed in #4689.
4
8
  */
5
9
  function camelCase(s) {
6
10
  return s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
@@ -8,8 +12,7 @@ function camelCase(s) {
8
12
  export function systemAdminTemplate(domain, id, tenancy) {
9
13
  const varName = camelCase(id);
10
14
  return `import { z } from 'zod';
11
- import { defineApi } from '@mettlecast/domain-runtime';
12
- import { createKyClient, initOtel } from '@mettlecast/domain-runtime';
15
+ import { defineAction, initOtel } from '@mettlecast/domain-runtime';
13
16
  import type { Result, AppError } from '@mettlecast/domain-runtime';
14
17
  import { ok, err, notFound } from '@mettlecast/domain-runtime';
15
18
 
@@ -27,7 +30,7 @@ const ${varName}Output = z.object({
27
30
  data: z.record(z.unknown()).optional(),
28
31
  }).default({ ok: true });
29
32
 
30
- // ── System health input ──────────────────────────────────────
33
+ // ── System health output ─────────────────────────────────────
31
34
 
32
35
  const SystemHealthOutput = z.object({
33
36
  status: z.enum(['healthy', 'degraded', 'down']),
@@ -38,64 +41,68 @@ const SystemHealthOutput = z.object({
38
41
  })),
39
42
  }).default({ status: 'healthy', uptime: 0, domains: [] });
40
43
 
41
- // ── API definitions ──────────────────────────────────────────
44
+ // ── Action definitions (API exposure) ────────────────────────
42
45
 
43
- export const ${varName} = defineApi({
46
+ export const ${varName} = defineAction({
44
47
  id: '${id}',
45
- path: '/system/${domain}/${id}',
46
- tenancy: '${tenancy}',
48
+ backendAccess: 'platform',
49
+ exposure: {
50
+ type: 'api',
51
+ path: '/system/${domain}/${id}',
52
+ method: 'POST',
53
+ auth: 'service',
54
+ tenancy: '${tenancy}',
55
+ },
47
56
  outboundAccess: 'internal',
48
- versions: {
49
- v1: {
50
- status: 'stable',
51
- input: ${varName}Input,
52
- output: ${varName}Output,
53
- handler: async (input, ctx) => {
54
- await ctx.audit.log('${id}.system', 'system', { command: input.command });
57
+ idempotent: false,
58
+ input: ${varName}Input,
59
+ output: ${varName}Output,
60
+ handler: async (input, ctx) => {
61
+ await ctx.audit.log('${id}.system', 'system', { command: input.command });
55
62
 
56
- switch (input.command) {
57
- case 'status':
58
- return {
59
- ok: true,
60
- data: { status: 'healthy', domains: [] },
61
- };
62
- case 'metrics':
63
- return {
64
- ok: true,
65
- data: {
66
- requestCount: 0,
67
- errorCount: 0,
68
- p99LatencyMs: 0,
69
- },
70
- };
71
- case 'health':
72
- return { ok: true, data: { status: 'healthy' } };
73
- default:
74
- return { ok: false };
75
- }
76
- },
77
- },
63
+ switch (input.command) {
64
+ case 'status':
65
+ return {
66
+ ok: true,
67
+ data: { status: 'healthy', domains: [] },
68
+ };
69
+ case 'metrics':
70
+ return {
71
+ ok: true,
72
+ data: {
73
+ requestCount: 0,
74
+ errorCount: 0,
75
+ p99LatencyMs: 0,
76
+ },
77
+ };
78
+ case 'health':
79
+ return { ok: true, data: { status: 'healthy' } };
80
+ default:
81
+ return { ok: false };
82
+ }
78
83
  },
79
84
  });
80
85
 
81
- export const ${varName}Health = defineApi({
86
+ export const ${varName}Health = defineAction({
82
87
  id: '${id}-health',
83
- path: '/system/${domain}/${id}-health',
84
- tenancy: '${tenancy}',
88
+ backendAccess: 'platform',
89
+ exposure: {
90
+ type: 'api',
91
+ path: '/system/${domain}/${id}-health',
92
+ method: 'GET',
93
+ auth: 'service',
94
+ tenancy: '${tenancy}',
95
+ },
85
96
  outboundAccess: 'internal',
86
- versions: {
87
- v1: {
88
- status: 'stable',
89
- input: z.object({}).default({}),
90
- output: SystemHealthOutput,
91
- handler: async (_input, _ctx) => {
92
- return {
93
- status: 'healthy',
94
- uptime: process.uptime(),
95
- domains: [],
96
- };
97
- },
98
- },
97
+ idempotent: true,
98
+ input: z.object({}).default({}),
99
+ output: SystemHealthOutput,
100
+ handler: async (_input, _ctx) => {
101
+ return {
102
+ status: 'healthy',
103
+ uptime: process.uptime(),
104
+ domains: [],
105
+ };
99
106
  },
100
107
  });
101
108
  `;
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Webhook-receiver-style API pattern template.
3
3
  * Produces: POST with signature verification, provider enum.
4
+ *
5
+ * Action-first: HTTP endpoints are declared with `defineAction` +
6
+ * `exposure: { type: 'api', ... }`. The legacy `defineApi` factory was
7
+ * removed in #4689.
4
8
  */
5
9
  export declare function webhookReceiverStyleTemplate(domain: string, id: string, tenancy: string): string;
6
10
  /**
@@ -1,15 +1,21 @@
1
1
  /**
2
2
  * Webhook-receiver-style API pattern template.
3
3
  * Produces: POST with signature verification, provider enum.
4
+ *
5
+ * Action-first: HTTP endpoints are declared with `defineAction` +
6
+ * `exposure: { type: 'api', ... }`. The legacy `defineApi` factory was
7
+ * removed in #4689.
4
8
  */
5
9
  function camelCase(s) {
6
10
  return s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
7
11
  }
8
12
  export function webhookReceiverStyleTemplate(domain, id, tenancy) {
9
13
  const varName = camelCase(id);
14
+ // Webhook receivers are typically public; pair `auth: 'none'` with a
15
+ // securityException.reason so the validator does not flag the route.
16
+ const securityException = `\n securityException: { reason: 'webhook receiver; signature verification handled by authorizer' },`;
10
17
  return `import { z } from 'zod';
11
- import { defineApi } from '@mettlecast/domain-runtime';
12
- import { createKyClient, initOtel } from '@mettlecast/domain-runtime';
18
+ import { defineAction, initOtel } from '@mettlecast/domain-runtime';
13
19
  import type { Result, AppError } from '@mettlecast/domain-runtime';
14
20
  import { ok, err, notFound } from '@mettlecast/domain-runtime';
15
21
 
@@ -47,46 +53,48 @@ const ${varName}Output = z.object({
47
53
  provider: 'stripe',
48
54
  });
49
55
 
50
- // ── API definition ───────────────────────────────────────────
56
+ // ── Action definition (API exposure) ─────────────────────────
51
57
 
52
- export const ${varName} = defineApi({
58
+ export const ${varName} = defineAction({
53
59
  id: '${id}',
54
- path: '/webhooks/${domain}/${id}',
55
- tenancy: '${tenancy}',
60
+ backendAccess: 'domain',
61
+ exposure: {
62
+ type: 'api',
63
+ path: '/webhooks/${domain}/${id}',
64
+ method: 'POST',
65
+ auth: 'none',${securityException}
66
+ tenancy: '${tenancy}',
67
+ },
56
68
  outboundAccess: 'internal',
57
- versions: {
58
- v1: {
59
- status: 'stable',
60
- input: ${varName}Input,
61
- output: ${varName}Output,
62
- handler: async (input, ctx) => {
63
- // Signature verification belongs in a Lambda authorizer (x-webhook-signature header
64
- // is not accessible here). Wire an HttpLambdaAuthorizer in DomainStack for production.
69
+ idempotent: false,
70
+ input: ${varName}Input,
71
+ output: ${varName}Output,
72
+ handler: async (input, ctx) => {
73
+ // Signature verification belongs in a Lambda authorizer (x-webhook-signature header
74
+ // is not accessible here). Wire an HttpLambdaAuthorizer in DomainStack for production.
65
75
 
66
- const eventId = crypto.randomUUID();
76
+ const eventId = crypto.randomUUID();
67
77
 
68
- // ── Publish event for downstream processing ───────────
69
- await ctx.publish('${domain}.webhook.received', {
70
- eventId,
71
- provider: input.provider,
72
- eventType: input.eventType,
73
- payload: input.payload,
74
- tenantId: ctx.tenant.id,
75
- }, 1);
78
+ // ── Publish event for downstream processing ───────────
79
+ await ctx.publish('${domain}.webhook.received', {
80
+ eventId,
81
+ provider: input.provider,
82
+ eventType: input.eventType,
83
+ payload: input.payload,
84
+ tenantId: ctx.tenant.id,
85
+ }, 1);
76
86
 
77
- await ctx.audit.log('${id}.webhook.received', ctx.tenant.id, {
78
- provider: input.provider,
79
- eventType: input.eventType,
80
- eventId,
81
- });
87
+ await ctx.audit.log('${id}.webhook.received', ctx.tenant.id, {
88
+ provider: input.provider,
89
+ eventType: input.eventType,
90
+ eventId,
91
+ });
82
92
 
83
- return {
84
- received: true,
85
- eventId,
86
- provider: input.provider,
87
- };
88
- },
89
- },
93
+ return {
94
+ received: true,
95
+ eventId,
96
+ provider: input.provider,
97
+ };
90
98
  },
91
99
  });
92
100
  `;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * packages/domain-cli/src/types.ts
3
+ *
4
+ * Local re-declaration of registry types used by the CLI's
5
+ * build/dev/mount-routes pipeline.
6
+ *
7
+ * Issue #4689 removed the legacy `defineApi` primitive and the
8
+ * `registry.apis` field in favour of the action-first model (#4619).
9
+ * The CLI's own source defines the action-first shape here so the
10
+ * pipeline can compile even when the published
11
+ * `@mettlecast/domain-cdk-packer` on npm still carries the legacy
12
+ * shape (i.e. `DomainRegistry` still requires `apis`, and
13
+ * `ActionRegistryEntry` lacks the `exposure` field).
14
+ *
15
+ * Once the npm-published packer catches up, the two local types below
16
+ * can collapse back to a single re-export from
17
+ * `@mettlecast/domain-cdk-packer`.
18
+ */
19
+ import type { DomainRegistry as PackerDomainRegistry, ActionRegistryEntry as PackerActionRegistryEntry, SchemaSnapshot, WebhookRegistryEntry, SubscriberRegistryEntry, ScheduleRegistryEntry, JobRegistryEntry, IntegrationRegistryEntry, EventRegistryEntry, DomainRegistryEntry, SerialDeploymentConfig, BaseRegistryEntry } from '@mettlecast/domain-cdk-packer';
20
+ export type { SchemaSnapshot, WebhookRegistryEntry, SubscriberRegistryEntry, ScheduleRegistryEntry, JobRegistryEntry, IntegrationRegistryEntry, EventRegistryEntry, DomainRegistryEntry, SerialDeploymentConfig, BaseRegistryEntry, };
21
+ /**
22
+ * Backend invocation permission for an action. Re-declared locally
23
+ * because the legacy published packer does not export this union yet
24
+ * (it was introduced as part of the action-first migration #4619).
25
+ */
26
+ export type ActionBackendAccess = 'private' | 'domain' | 'platform';
27
+ /**
28
+ * API-exposure metadata for an action whose `exposure.type === 'api'`.
29
+ * Carries the route, method, auth, tenancy, and any documented security
30
+ * exception that downstream CDK/contract generation needs to wire the
31
+ * route safely. Mirrors the canonical `ActionApiExposure` shape from
32
+ * `@mettlecast/domain-cdk-packer`.
33
+ */
34
+ export interface ActionApiExposure {
35
+ /** Discriminant. */
36
+ type: 'api';
37
+ /** HTTP route path, e.g. '/v1/tenants/{tenantId}/billing/invoices'. */
38
+ path: string;
39
+ /** HTTP method. One of: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS. */
40
+ method: string;
41
+ /** Authentication requirement for the route. */
42
+ auth: 'required' | 'none' | 'service';
43
+ /** Tenancy requirement for the route. */
44
+ tenancy: 'required' | 'none' | 'system';
45
+ /** Required role(s) for `auth: 'required'` routes (system tenancy requires this). */
46
+ roles?: string[];
47
+ /** Documented exception when auth or tenancy is intentionally not required. */
48
+ securityException?: {
49
+ reason: string;
50
+ };
51
+ /**
52
+ * True if the source code explicitly declared `auth`. False if the
53
+ * builder fell back to the safe default (`'required'`). Validation-only.
54
+ */
55
+ authDeclared?: boolean;
56
+ /**
57
+ * True if the source code explicitly declared `tenancy`. False if the
58
+ * builder fell back to the safe default (`'required'`). Validation-only.
59
+ */
60
+ tenancyDeclared?: boolean;
61
+ }
62
+ /**
63
+ * Discriminated union for an action's external exposure shape.
64
+ * `internal` actions are reachable only through `ctx.actions`. `api`
65
+ * actions are exposed via API Gateway and carry the route + auth
66
+ * metadata needed for safe route generation.
67
+ */
68
+ export type ActionExposure = ActionApiExposure | {
69
+ type: 'internal';
70
+ };
71
+ /**
72
+ * Local `DomainRegistry` for the CLI. Drops the legacy `apis` slot
73
+ * that was removed in issue #4689's action-first migration, and pins
74
+ * the `actions` array to the local `ActionRegistryEntry` shape (which
75
+ * carries the action-first `exposure` field). The CLI builds an object
76
+ * literal that satisfies this type and then serialises it to
77
+ * `.mc/<domain>-registry.json`; downstream consumers (CDK packer,
78
+ * OpenAPI generator, dev server) only ever see the JSON.
79
+ */
80
+ export type DomainRegistry = Omit<PackerDomainRegistry, 'apis' | 'actions'> & {
81
+ /** All callable actions (local shape with action-first `exposure`). */
82
+ actions: ActionRegistryEntry[];
83
+ };
84
+ /**
85
+ * Local `ActionRegistryEntry` for the CLI. Augments the packer's shape
86
+ * with the `exposure` field and its `exposureDeclared` flag from the
87
+ * action-first migration (#4619) so the build/dev/mount-routes
88
+ * pipeline can read these properties regardless of which packer
89
+ * version is linked. The `backendAccess` field is also surfaced here
90
+ * (the CLI is the canonical writer of this field) even when the
91
+ * linked packer only exposes the legacy `visibility` alias.
92
+ */
93
+ export type ActionRegistryEntry = PackerActionRegistryEntry & {
94
+ /** External exposure shape for the action (see ActionExposure). */
95
+ exposure: ActionExposure;
96
+ /** True if the source code explicitly declared `exposure`. */
97
+ exposureDeclared?: boolean;
98
+ /** Backend invocation permission for the action. */
99
+ backendAccess?: ActionBackendAccess;
100
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -7,8 +7,6 @@
7
7
  export interface DomainFilePaths {
8
8
  /** Path to domain.config.ts if present. */
9
9
  domain: string | undefined;
10
- /** API handler file paths under api/. */
11
- apis: string[];
12
10
  /** Webhook handler file paths under webhooks/. */
13
11
  webhooks: string[];
14
12
  /** Subscriber handler file paths under subscribers/. */
@@ -44,9 +44,8 @@ export async function walkDomainDir(domainRoot) {
44
44
  return undefined;
45
45
  }
46
46
  }
47
- const [domain, apis, webhooks, subscribers, actions, schedules, jobs, integrations, publishes] = await Promise.all([
47
+ const [domain, webhooks, subscribers, actions, schedules, jobs, integrations, publishes] = await Promise.all([
48
48
  singleTs(join(domainRoot, 'domain.config.ts')),
49
- tsFiles(join(domainRoot, 'api')),
50
49
  tsFiles(join(domainRoot, 'webhooks')),
51
50
  tsFiles(join(domainRoot, 'subscribers')),
52
51
  tsFiles(join(domainRoot, 'actions')),
@@ -55,5 +54,5 @@ export async function walkDomainDir(domainRoot) {
55
54
  tsFiles(join(domainRoot, 'integrations')),
56
55
  singleTs(join(domainRoot, 'publishes', 'events.ts')),
57
56
  ]);
58
- return { domain, apis, webhooks, subscribers, actions, schedules, jobs, integrations, publishes };
57
+ return { domain, webhooks, subscribers, actions, schedules, jobs, integrations, publishes };
59
58
  }
@@ -47,7 +47,7 @@ export function injectHeader(content, filename, moduleId, version) {
47
47
  function injectLineCommentHeader(content, commentChar, moduleId, version) {
48
48
  const header = [
49
49
  `${commentChar} @mc-scaffold: ${moduleId}@${version}`,
50
- `${commentChar} This file is managed by TIB scaffold. Manual edits will be flagged during \`tib upgrade\`.`,
50
+ `${commentChar} This file is managed by TIB scaffold. Manual edits will be flagged during \`npx mc-domain-module upgrade\`.`,
51
51
  `${commentChar} To opt out of upgrade management for this file, remove these header lines.`,
52
52
  '',
53
53
  ].join('\n');
@@ -63,7 +63,7 @@ function injectLineCommentHeader(content, commentChar, moduleId, version) {
63
63
  function injectBlockCommentHeader(content, open, close, moduleId, version) {
64
64
  const header = [
65
65
  `${open} @mc-scaffold: ${moduleId}@${version} ${close}`,
66
- `${open} This file is managed by TIB scaffold. Manual edits will be flagged during \`tib upgrade\`. ${close}`,
66
+ `${open} This file is managed by TIB scaffold. Manual edits will be flagged during \`npx mc-domain-module upgrade\`. ${close}`,
67
67
  '',
68
68
  ].join('\n');
69
69
  return header + content;
@@ -8,7 +8,7 @@ export interface InstallResult {
8
8
  *
9
9
  * - managed: always overwrite. Return 'added' if new, 'updated' if existed.
10
10
  * - editable: check sha256. If same → 'unchanged'. If different → 'update-available'
11
- * (does not write .tib-upgrade or overwrite — user opts in via Updates tab).
11
+ * (does not write .mc-upgrade or overwrite — user opts in via Updates tab).
12
12
  * - seed: if file exists → 'skipped'. Else write → 'added'.
13
13
  */
14
14
  export declare function installScaffoldFile(absPath: string, content: string, policy: FilePolicy, currentEntry: ManifestFileEntry | undefined, opts?: {
@@ -6,7 +6,7 @@ import { computeChecksumString } from './checksum.js';
6
6
  *
7
7
  * - managed: always overwrite. Return 'added' if new, 'updated' if existed.
8
8
  * - editable: check sha256. If same → 'unchanged'. If different → 'update-available'
9
- * (does not write .tib-upgrade or overwrite — user opts in via Updates tab).
9
+ * (does not write .mc-upgrade or overwrite — user opts in via Updates tab).
10
10
  * - seed: if file exists → 'skipped'. Else write → 'added'.
11
11
  */
12
12
  export async function installScaffoldFile(absPath, content, policy, currentEntry, opts) {
@@ -4,9 +4,8 @@ import { cliLogger } from './logger.js';
4
4
  const MANIFEST_PATH = '.mc/manifest.json';
5
5
  const SCHEMA_URL = 'https://mc-scaffold.s3.amazonaws.com/schema/manifest.v3.json';
6
6
  export function inferPolicyFromPath(filePath) {
7
- // owned: infra/, .mc/infra/, mc-deploy.yml, .github/workflows/
7
+ // owned: infra/, mc-deploy.yml, .github/workflows/
8
8
  if (filePath.match(/^infra\//) ||
9
- filePath.match(/^\.tib\/infra\//) ||
10
9
  filePath === 'mc-deploy.yml' ||
11
10
  filePath.match(/^\.github\/workflows\//)) {
12
11
  return 'managed';
@@ -29,10 +29,14 @@ export interface CostOptions {
29
29
  xRaySamplingRate?: number;
30
30
  reservedConcurrencyPerDomain?: Record<string, number>;
31
31
  }
32
+ /** NAT instance type options for cost control. */
33
+ export type NatInstanceType = 't4g.nano' | 't4g.micro' | 't4g.small';
32
34
  /** Monitoring / observability feature opt-ins. */
33
35
  export interface MonitoringOptions {
34
36
  /** Replace basic MonitoringStack with full ObservabilityStack (Grafana + Cost Explorer + CloudWatch). ~$9–18/month */
35
37
  enhanced: boolean;
38
+ /** Disable auto-generated per-domain CloudWatch dashboards. Removes existing dashboards on next deploy. */
39
+ disableCloudWatchDashboards?: boolean;
36
40
  }
37
41
  /** Lifecycle tunables — Phase B. Schema only in Phase A. */
38
42
  export interface LifecycleOptions {
@@ -67,9 +71,9 @@ export interface ScaffoldConfig {
67
71
  awsAccountId: string;
68
72
  /** Admin email collected at scaffold time (Cognito seed user). Present only when auth module is enabled. */
69
73
  adminEmail?: string;
70
- /** Domain IDs added via `tib add-domain` — NOT scaffold-owned, user-managed */
74
+ /** Domain IDs added via `mc-domain-module add-domain` — NOT scaffold-owned, user-managed */
71
75
  domainIds: string[];
72
- /** Flow IDs added via `tib add-flow` — user-managed */
76
+ /** Flow IDs added via `mc-domain-module add-flow` — user-managed */
73
77
  flowIds: string[];
74
78
  /** S3 bucket used for scaffold fetches (defaults to public TIB bucket) */
75
79
  scaffoldBucket: string;
@@ -92,6 +96,8 @@ export interface ScaffoldConfig {
92
96
  environments?: EnvironmentsConfig;
93
97
  /** When true, CORS responses include Allow-Credentials: true (requires non-wildcard origins). */
94
98
  allowCredentials?: boolean;
99
+ /** NAT instance type for the shared NAT instance. Defaults to the smallest: t4g.nano. */
100
+ natInstanceType?: NatInstanceType;
95
101
  }
96
102
  export declare function readScaffoldConfig(projectRoot: string): Promise<ScaffoldConfig>;
97
103
  export declare function writeScaffoldConfig(projectRoot: string, config: ScaffoldConfig): Promise<void>;
@@ -18,7 +18,9 @@ const DEFAULT_SCAFFOLD_CONFIG = {
18
18
  logRetentionDays: 30,
19
19
  monitoringOptions: {
20
20
  enhanced: false,
21
+ disableCloudWatchDashboards: false,
21
22
  },
23
+ natInstanceType: 't4g.nano',
22
24
  };
23
25
  const CONFIG_PATH = '.mc/scaffold-config.json';
24
26
  export async function readScaffoldConfig(projectRoot) {
@@ -28,7 +30,7 @@ export async function readScaffoldConfig(projectRoot) {
28
30
  // Backward compatibility: old files may only have domainIds/flowIds
29
31
  if (!raw.scaffoldVersion) {
30
32
  // eslint-disable-next-line no-console
31
- console.warn('[tib] scaffold-config.json is missing scaffoldVersion — project was created before S3 scaffold migration. Run `tib upgrade` to backfill.');
33
+ console.warn('[mc-domain-module] scaffold-config.json is missing scaffoldVersion — project was created before S3 scaffold migration. Run `npx mc-domain-module upgrade` to backfill.');
32
34
  }
33
35
  return {
34
36
  ...DEFAULT_SCAFFOLD_CONFIG,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mettlecast/domain-cli",
3
- "version": "0.2.59",
3
+ "version": "0.2.61",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",