@mettlecast/domain-cli 0.2.60 → 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 (89) hide show
  1. package/dist/builder/build-registry.d.ts +1 -1
  2. package/dist/builder/build-registry.js +1 -36
  3. package/dist/builder/build-types.d.ts +1 -1
  4. package/dist/builder/load-module.d.ts +1 -1
  5. package/dist/cli.js +1 -1
  6. package/dist/commands/add-api.js +2 -2
  7. package/dist/commands/add-domain.js +4 -4
  8. package/dist/commands/add-fixture-factory.js +5 -6
  9. package/dist/commands/build-catalog.d.ts +6 -22
  10. package/dist/commands/build-catalog.js +7 -18
  11. package/dist/commands/build.js +2 -1
  12. package/dist/commands/dev.js +1 -1
  13. package/dist/commands/doctor.js +66 -37
  14. package/dist/commands/explain.js +13 -13
  15. package/dist/commands/generate-openapi.d.ts +10 -1
  16. package/dist/commands/generate-openapi.js +19 -33
  17. package/dist/commands/show.d.ts +2 -3
  18. package/dist/commands/show.js +0 -2
  19. package/dist/commands/test.js +0 -1
  20. package/dist/commands/upgrade-backend.js +3 -3
  21. package/dist/commands/validate.js +12 -90
  22. package/dist/server/api-server.d.ts +1 -1
  23. package/dist/server/mount-routes.d.ts +11 -2
  24. package/dist/server/mount-routes.js +20 -8
  25. package/dist/templates/api-skeleton.d.ts +5 -0
  26. package/dist/templates/api-skeleton.js +28 -27
  27. package/dist/templates/claude-md.js +1 -1
  28. package/dist/templates/patterns/api/create-with-event.d.ts +4 -0
  29. package/dist/templates/patterns/api/create-with-event.js +38 -32
  30. package/dist/templates/patterns/api/idempotent-mutation.d.ts +4 -0
  31. package/dist/templates/patterns/api/idempotent-mutation.js +47 -41
  32. package/dist/templates/patterns/api/paginated-list.d.ts +4 -0
  33. package/dist/templates/patterns/api/paginated-list.js +30 -24
  34. package/dist/templates/patterns/api/simple-crud.d.ts +4 -0
  35. package/dist/templates/patterns/api/simple-crud.js +46 -35
  36. package/dist/templates/patterns/api/streaming-list.d.ts +4 -0
  37. package/dist/templates/patterns/api/streaming-list.js +46 -41
  38. package/dist/templates/patterns/api/system-admin.d.ts +4 -0
  39. package/dist/templates/patterns/api/system-admin.js +59 -52
  40. package/dist/templates/patterns/api/webhook-receiver-style.d.ts +4 -0
  41. package/dist/templates/patterns/api/webhook-receiver-style.js +43 -35
  42. package/dist/types.d.ts +100 -0
  43. package/dist/types.js +1 -0
  44. package/dist/utils/file-helpers.d.ts +0 -2
  45. package/dist/utils/file-helpers.js +2 -3
  46. package/dist/utils/scaffold-config.d.ts +6 -0
  47. package/dist/utils/scaffold-config.js +2 -0
  48. package/package.json +1 -1
  49. package/src/__tests__/build-registry.test.ts +43 -20
  50. package/src/__tests__/build-types.test.ts +4 -7
  51. package/src/__tests__/builder/walkDomainDir.test.ts +19 -21
  52. package/src/__tests__/commands/add-api.test.ts +12 -10
  53. package/src/__tests__/commands/add-domain.test.ts +8 -5
  54. package/src/__tests__/commands/create-project.test.ts +5 -5
  55. package/src/__tests__/commands/dev.test.ts +0 -1
  56. package/src/__tests__/mount-routes.test.ts +64 -23
  57. package/src/__tests__/package-freshness.test.ts +1 -21
  58. package/src/__tests__/smoke/scaffold.test.ts +13 -15
  59. package/src/__tests__/validate.test.ts +21 -103
  60. package/src/builder/build-registry.ts +7 -44
  61. package/src/builder/build-types.ts +1 -1
  62. package/src/cli.ts +1 -1
  63. package/src/commands/add-api.ts +2 -2
  64. package/src/commands/add-domain.ts +4 -4
  65. package/src/commands/add-fixture-factory.ts +5 -6
  66. package/src/commands/build-catalog.ts +13 -35
  67. package/src/commands/build.ts +3 -2
  68. package/src/commands/dev.ts +1 -1
  69. package/src/commands/doctor.ts +68 -37
  70. package/src/commands/explain.ts +13 -13
  71. package/src/commands/generate-openapi.ts +30 -52
  72. package/src/commands/show.ts +2 -5
  73. package/src/commands/test.ts +0 -1
  74. package/src/commands/upgrade-backend.ts +3 -3
  75. package/src/commands/validate.ts +11 -96
  76. package/src/server/api-server.ts +1 -1
  77. package/src/server/mount-routes.ts +21 -10
  78. package/src/templates/api-skeleton.ts +29 -28
  79. package/src/templates/claude-md.ts +1 -1
  80. package/src/templates/patterns/api/create-with-event.ts +39 -33
  81. package/src/templates/patterns/api/idempotent-mutation.ts +48 -42
  82. package/src/templates/patterns/api/paginated-list.ts +31 -25
  83. package/src/templates/patterns/api/simple-crud.ts +47 -36
  84. package/src/templates/patterns/api/streaming-list.ts +47 -42
  85. package/src/templates/patterns/api/system-admin.ts +60 -53
  86. package/src/templates/patterns/api/webhook-receiver-style.ts +48 -40
  87. package/src/types.ts +128 -0
  88. package/src/utils/file-helpers.ts +2 -5
  89. package/src/utils/scaffold-config.ts +9 -0
package/src/types.ts ADDED
@@ -0,0 +1,128 @@
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 {
20
+ DomainRegistry as PackerDomainRegistry,
21
+ ActionRegistryEntry as PackerActionRegistryEntry,
22
+ SchemaSnapshot,
23
+ WebhookRegistryEntry,
24
+ SubscriberRegistryEntry,
25
+ ScheduleRegistryEntry,
26
+ JobRegistryEntry,
27
+ IntegrationRegistryEntry,
28
+ EventRegistryEntry,
29
+ DomainRegistryEntry,
30
+ SerialDeploymentConfig,
31
+ BaseRegistryEntry,
32
+ } from '@mettlecast/domain-cdk-packer';
33
+
34
+ // Re-export the unchanged registry entry types so callers can import
35
+ // everything from a single local module.
36
+ export type {
37
+ SchemaSnapshot,
38
+ WebhookRegistryEntry,
39
+ SubscriberRegistryEntry,
40
+ ScheduleRegistryEntry,
41
+ JobRegistryEntry,
42
+ IntegrationRegistryEntry,
43
+ EventRegistryEntry,
44
+ DomainRegistryEntry,
45
+ SerialDeploymentConfig,
46
+ BaseRegistryEntry,
47
+ };
48
+
49
+ /**
50
+ * Backend invocation permission for an action. Re-declared locally
51
+ * because the legacy published packer does not export this union yet
52
+ * (it was introduced as part of the action-first migration #4619).
53
+ */
54
+ export type ActionBackendAccess = 'private' | 'domain' | 'platform';
55
+
56
+ /**
57
+ * API-exposure metadata for an action whose `exposure.type === 'api'`.
58
+ * Carries the route, method, auth, tenancy, and any documented security
59
+ * exception that downstream CDK/contract generation needs to wire the
60
+ * route safely. Mirrors the canonical `ActionApiExposure` shape from
61
+ * `@mettlecast/domain-cdk-packer`.
62
+ */
63
+ export interface ActionApiExposure {
64
+ /** Discriminant. */
65
+ type: 'api';
66
+ /** HTTP route path, e.g. '/v1/tenants/{tenantId}/billing/invoices'. */
67
+ path: string;
68
+ /** HTTP method. One of: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS. */
69
+ method: string;
70
+ /** Authentication requirement for the route. */
71
+ auth: 'required' | 'none' | 'service';
72
+ /** Tenancy requirement for the route. */
73
+ tenancy: 'required' | 'none' | 'system';
74
+ /** Required role(s) for `auth: 'required'` routes (system tenancy requires this). */
75
+ roles?: string[];
76
+ /** Documented exception when auth or tenancy is intentionally not required. */
77
+ securityException?: { reason: string };
78
+ /**
79
+ * True if the source code explicitly declared `auth`. False if the
80
+ * builder fell back to the safe default (`'required'`). Validation-only.
81
+ */
82
+ authDeclared?: boolean;
83
+ /**
84
+ * True if the source code explicitly declared `tenancy`. False if the
85
+ * builder fell back to the safe default (`'required'`). Validation-only.
86
+ */
87
+ tenancyDeclared?: boolean;
88
+ }
89
+
90
+ /**
91
+ * Discriminated union for an action's external exposure shape.
92
+ * `internal` actions are reachable only through `ctx.actions`. `api`
93
+ * actions are exposed via API Gateway and carry the route + auth
94
+ * metadata needed for safe route generation.
95
+ */
96
+ export type ActionExposure = ActionApiExposure | { type: 'internal' };
97
+
98
+ /**
99
+ * Local `DomainRegistry` for the CLI. Drops the legacy `apis` slot
100
+ * that was removed in issue #4689's action-first migration, and pins
101
+ * the `actions` array to the local `ActionRegistryEntry` shape (which
102
+ * carries the action-first `exposure` field). The CLI builds an object
103
+ * literal that satisfies this type and then serialises it to
104
+ * `.mc/<domain>-registry.json`; downstream consumers (CDK packer,
105
+ * OpenAPI generator, dev server) only ever see the JSON.
106
+ */
107
+ export type DomainRegistry = Omit<PackerDomainRegistry, 'apis' | 'actions'> & {
108
+ /** All callable actions (local shape with action-first `exposure`). */
109
+ actions: ActionRegistryEntry[];
110
+ };
111
+
112
+ /**
113
+ * Local `ActionRegistryEntry` for the CLI. Augments the packer's shape
114
+ * with the `exposure` field and its `exposureDeclared` flag from the
115
+ * action-first migration (#4619) so the build/dev/mount-routes
116
+ * pipeline can read these properties regardless of which packer
117
+ * version is linked. The `backendAccess` field is also surfaced here
118
+ * (the CLI is the canonical writer of this field) even when the
119
+ * linked packer only exposes the legacy `visibility` alias.
120
+ */
121
+ export type ActionRegistryEntry = PackerActionRegistryEntry & {
122
+ /** External exposure shape for the action (see ActionExposure). */
123
+ exposure: ActionExposure;
124
+ /** True if the source code explicitly declared `exposure`. */
125
+ exposureDeclared?: boolean;
126
+ /** Backend invocation permission for the action. */
127
+ backendAccess?: ActionBackendAccess;
128
+ };
@@ -10,8 +10,6 @@ import { join } from 'node:path';
10
10
  export interface DomainFilePaths {
11
11
  /** Path to domain.config.ts if present. */
12
12
  domain: string | undefined;
13
- /** API handler file paths under api/. */
14
- apis: string[];
15
13
  /** Webhook handler file paths under webhooks/. */
16
14
  webhooks: string[];
17
15
  /** Subscriber handler file paths under subscribers/. */
@@ -74,10 +72,9 @@ export async function walkDomainDir(domainRoot: string): Promise<DomainFilePaths
74
72
  }
75
73
  }
76
74
 
77
- const [domain, apis, webhooks, subscribers, actions, schedules, jobs, integrations, publishes] =
75
+ const [domain, webhooks, subscribers, actions, schedules, jobs, integrations, publishes] =
78
76
  await Promise.all([
79
77
  singleTs(join(domainRoot, 'domain.config.ts')),
80
- tsFiles(join(domainRoot, 'api')),
81
78
  tsFiles(join(domainRoot, 'webhooks')),
82
79
  tsFiles(join(domainRoot, 'subscribers')),
83
80
  tsFiles(join(domainRoot, 'actions')),
@@ -87,5 +84,5 @@ export async function walkDomainDir(domainRoot: string): Promise<DomainFilePaths
87
84
  singleTs(join(domainRoot, 'publishes', 'events.ts')),
88
85
  ]);
89
86
 
90
- return { domain, apis, webhooks, subscribers, actions, schedules, jobs, integrations, publishes };
87
+ return { domain, webhooks, subscribers, actions, schedules, jobs, integrations, publishes };
91
88
  }
@@ -50,10 +50,15 @@ export interface CostOptions {
50
50
  reservedConcurrencyPerDomain?: Record<string, number>;
51
51
  }
52
52
 
53
+ /** NAT instance type options for cost control. */
54
+ export type NatInstanceType = 't4g.nano' | 't4g.micro' | 't4g.small';
55
+
53
56
  /** Monitoring / observability feature opt-ins. */
54
57
  export interface MonitoringOptions {
55
58
  /** Replace basic MonitoringStack with full ObservabilityStack (Grafana + Cost Explorer + CloudWatch). ~$9–18/month */
56
59
  enhanced: boolean;
60
+ /** Disable auto-generated per-domain CloudWatch dashboards. Removes existing dashboards on next deploy. */
61
+ disableCloudWatchDashboards?: boolean;
57
62
  }
58
63
 
59
64
  /** Lifecycle tunables — Phase B. Schema only in Phase A. */
@@ -114,6 +119,8 @@ export interface ScaffoldConfig {
114
119
  environments?: EnvironmentsConfig;
115
120
  /** When true, CORS responses include Allow-Credentials: true (requires non-wildcard origins). */
116
121
  allowCredentials?: boolean;
122
+ /** NAT instance type for the shared NAT instance. Defaults to the smallest: t4g.nano. */
123
+ natInstanceType?: NatInstanceType;
117
124
  }
118
125
 
119
126
  const DEFAULT_SCAFFOLD_CONFIG: Omit<ScaffoldConfig, 'domainIds' | 'flowIds'> = {
@@ -134,7 +141,9 @@ const DEFAULT_SCAFFOLD_CONFIG: Omit<ScaffoldConfig, 'domainIds' | 'flowIds'> = {
134
141
  logRetentionDays: 30,
135
142
  monitoringOptions: {
136
143
  enhanced: false,
144
+ disableCloudWatchDashboards: false,
137
145
  },
146
+ natInstanceType: 't4g.nano',
138
147
  };
139
148
 
140
149
  const CONFIG_PATH = '.mc/scaffold-config.json';