@di-framework/cli-plugin-platform 6.1.2 → 6.3.0

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 (60) hide show
  1. package/README.md +154 -12
  2. package/dist/args.d.ts +8 -0
  3. package/dist/args.js +73 -28
  4. package/dist/assets/http-adapter.js +4 -1
  5. package/dist/assets/platform/README.md +68 -19
  6. package/dist/assets/platform/index.ts.tmpl +1 -1
  7. package/dist/assets/platform/tsconfig.json +2 -2
  8. package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
  9. package/dist/build.d.ts +27 -4
  10. package/dist/build.js +159 -18
  11. package/dist/bundle.d.ts +85 -0
  12. package/dist/bundle.js +608 -0
  13. package/dist/command.js +85 -3
  14. package/dist/console/catalog.js +2 -1
  15. package/dist/console/cluster.d.ts +4 -2
  16. package/dist/console/cluster.js +38 -40
  17. package/dist/control/auth.js +14 -2
  18. package/dist/controller/client.d.ts +47 -0
  19. package/dist/controller/client.js +157 -0
  20. package/dist/controller/commands.d.ts +48 -0
  21. package/dist/controller/commands.js +584 -0
  22. package/dist/controller/credentials.d.ts +63 -0
  23. package/dist/controller/credentials.js +156 -0
  24. package/dist/controller/index.d.ts +6 -0
  25. package/dist/controller/index.js +6 -0
  26. package/dist/controller/oidc.d.ts +54 -0
  27. package/dist/controller/oidc.js +121 -0
  28. package/dist/controller/registry.d.ts +15 -0
  29. package/dist/controller/registry.js +47 -0
  30. package/dist/controller/schema.d.ts +157 -0
  31. package/dist/controller/schema.js +1 -0
  32. package/dist/controller/sse.d.ts +12 -0
  33. package/dist/controller/sse.js +61 -0
  34. package/dist/controller/trust.d.ts +14 -0
  35. package/dist/controller/trust.js +39 -0
  36. package/dist/deploy.d.ts +14 -7
  37. package/dist/deploy.js +96 -5
  38. package/dist/deps.d.ts +4 -0
  39. package/dist/destroy.js +26 -2
  40. package/dist/environment-names.d.ts +6 -0
  41. package/dist/environment-names.js +10 -0
  42. package/dist/index.d.ts +5 -3
  43. package/dist/index.js +5 -3
  44. package/dist/manifest.d.ts +45 -1
  45. package/dist/manifest.js +197 -4
  46. package/dist/pglite-encryption.d.ts +79 -0
  47. package/dist/pglite-encryption.js +196 -0
  48. package/dist/pglite.d.ts +61 -4
  49. package/dist/pglite.js +124 -40
  50. package/dist/project.d.ts +7 -0
  51. package/dist/project.js +35 -0
  52. package/dist/publish.d.ts +7 -1
  53. package/dist/publish.js +33 -1
  54. package/dist/service.d.ts +34 -0
  55. package/dist/service.js +156 -145
  56. package/dist/target.d.ts +7 -1
  57. package/dist/target.js +19 -0
  58. package/dist/workload.d.ts +50 -12
  59. package/dist/workload.js +239 -44
  60. package/package.json +1 -1
package/dist/service.js CHANGED
@@ -2,12 +2,14 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { CommandFailure } from '@di-framework/cli-extension';
5
+ import { readEnvFlag, readStringFlag } from './args.js';
6
+ import { resolveControllerSession, wrapControllerError } from './controller/index.js';
5
7
  import { DEFAULT_DEPS } from './deps.js';
6
8
  import { captureKubectl } from './kubernetes.js';
7
- import { loadDeployManifest } from './manifest.js';
9
+ import { loadDeployManifest, tenantNamespace, } from './manifest.js';
8
10
  import { isNamespace } from './namespace.js';
9
11
  import { invalidUsage, matchOption } from './support.js';
10
- import { resolveConnection, resolveTarget } from './target.js';
12
+ import { isControllerBackedTarget, resolveConnection, resolveTarget, } from './target.js';
11
13
  export const BACKING_SERVICE_API_VERSION = 'platform.di-framework.dev/v1alpha1';
12
14
  export const BACKING_SERVICE_KIND = 'BackingService';
13
15
  export const BACKING_SERVICE_RESOURCE = 'backingservices.platform.di-framework.dev';
@@ -81,59 +83,50 @@ export function buildBackingServiceManifest(options) {
81
83
  spec,
82
84
  };
83
85
  }
86
+ const SERVICE_CREATE_STRING_FLAGS = {
87
+ '--name': 'name',
88
+ '--class': 'className',
89
+ '--target': 'target',
90
+ '--namespace': 'namespace',
91
+ '--context': 'context',
92
+ };
93
+ const SERVICE_SIZING_FLAGS = {
94
+ '--memory': 'memory',
95
+ '--storage': 'storage',
96
+ '--cpu': 'cpu',
97
+ };
98
+ const SERVICE_LIST_STRING_FLAGS = {
99
+ '--target': 'target',
100
+ '--namespace': 'namespace',
101
+ '--context': 'context',
102
+ };
84
103
  export function parseServiceCreateArgs(args) {
85
104
  let type;
86
- let name;
87
- let className;
105
+ const values = {};
88
106
  let deletionPolicy;
89
- let target;
90
- let namespace;
91
- let context;
107
+ let env;
92
108
  let wait = false;
93
109
  let timeoutMs = DEFAULT_WAIT_TIMEOUT_MS;
94
110
  let timeoutExplicit = false;
95
111
  const parameters = {};
96
112
  const destinations = [];
97
- for (let position = 0; position < args.length; position++) {
98
- const token = args[position] ?? '';
99
- const nameOpt = matchOption(args, position, token, '--name');
100
- if (nameOpt) {
101
- if (name !== undefined)
102
- invalidUsage('Option may be provided only once: --name', '--name');
103
- name = nameOpt.value;
104
- position = nameOpt.consumedThrough;
105
- continue;
106
- }
107
- const classOpt = matchOption(args, position, token, '--class');
108
- if (classOpt) {
109
- if (className !== undefined)
110
- invalidUsage('Option may be provided only once: --class', '--class');
111
- className = classOpt.value;
112
- position = classOpt.consumedThrough;
113
+ let position = 0;
114
+ while (position < args.length) {
115
+ const token = args[position];
116
+ const nextStringPos = readStringFlag(args, position, token, SERVICE_CREATE_STRING_FLAGS, values);
117
+ if (nextStringPos !== undefined) {
118
+ position = nextStringPos;
113
119
  continue;
114
120
  }
115
- const targetOpt = matchOption(args, position, token, '--target');
116
- if (targetOpt) {
117
- if (target !== undefined)
118
- invalidUsage('Option may be provided only once: --target', '--target');
119
- target = targetOpt.value;
120
- position = targetOpt.consumedThrough;
121
+ const nextSizingPos = readStringFlag(args, position, token, SERVICE_SIZING_FLAGS, parameters);
122
+ if (nextSizingPos !== undefined) {
123
+ position = nextSizingPos;
121
124
  continue;
122
125
  }
123
- const namespaceOpt = matchOption(args, position, token, '--namespace');
124
- if (namespaceOpt) {
125
- if (namespace !== undefined)
126
- invalidUsage('Option may be provided only once: --namespace', '--namespace');
127
- namespace = namespaceOpt.value;
128
- position = namespaceOpt.consumedThrough;
129
- continue;
130
- }
131
- const contextOpt = matchOption(args, position, token, '--context');
132
- if (contextOpt) {
133
- if (context !== undefined)
134
- invalidUsage('Option may be provided only once: --context', '--context');
135
- context = contextOpt.value;
136
- position = contextOpt.consumedThrough;
126
+ const envOpt = readEnvFlag(args, position, token, env, 'platform service create');
127
+ if (envOpt) {
128
+ env = envOpt.value;
129
+ position = envOpt.nextPosition;
137
130
  continue;
138
131
  }
139
132
  const deletionOpt = matchOption(args, position, token, '--deletion-policy');
@@ -146,31 +139,7 @@ export function parseServiceCreateArgs(args) {
146
139
  });
147
140
  }
148
141
  deletionPolicy = deletionOpt.value;
149
- position = deletionOpt.consumedThrough;
150
- continue;
151
- }
152
- const memoryOpt = matchOption(args, position, token, '--memory');
153
- if (memoryOpt) {
154
- if (parameters.memory !== undefined)
155
- invalidUsage('Option may be provided only once: --memory', '--memory');
156
- parameters.memory = memoryOpt.value;
157
- position = memoryOpt.consumedThrough;
158
- continue;
159
- }
160
- const storageOpt = matchOption(args, position, token, '--storage');
161
- if (storageOpt) {
162
- if (parameters.storage !== undefined)
163
- invalidUsage('Option may be provided only once: --storage', '--storage');
164
- parameters.storage = storageOpt.value;
165
- position = storageOpt.consumedThrough;
166
- continue;
167
- }
168
- const cpuOpt = matchOption(args, position, token, '--cpu');
169
- if (cpuOpt) {
170
- if (parameters.cpu !== undefined)
171
- invalidUsage('Option may be provided only once: --cpu', '--cpu');
172
- parameters.cpu = cpuOpt.value;
173
- position = cpuOpt.consumedThrough;
142
+ position = deletionOpt.consumedThrough + 1;
174
143
  continue;
175
144
  }
176
145
  const timeoutOpt = matchOption(args, position, token, '--timeout');
@@ -183,19 +152,20 @@ export function parseServiceCreateArgs(args) {
183
152
  invalidUsage('--timeout must be a positive number of seconds', timeoutOpt.value);
184
153
  }
185
154
  timeoutMs = Math.floor(parsed * 1000);
186
- position = timeoutOpt.consumedThrough;
155
+ position = timeoutOpt.consumedThrough + 1;
187
156
  continue;
188
157
  }
189
158
  const destinationOpt = matchOption(args, position, token, '--destination');
190
159
  if (destinationOpt) {
191
160
  destinations.push(destinationOpt.value);
192
- position = destinationOpt.consumedThrough;
161
+ position = destinationOpt.consumedThrough + 1;
193
162
  continue;
194
163
  }
195
164
  if (token === '--wait') {
196
165
  if (wait)
197
166
  invalidUsage('Option may be provided only once: --wait', '--wait');
198
167
  wait = true;
168
+ position += 1;
199
169
  continue;
200
170
  }
201
171
  if (token.startsWith('--')) {
@@ -203,26 +173,29 @@ export function parseServiceCreateArgs(args) {
203
173
  }
204
174
  if (type !== undefined) {
205
175
  // `service create egress <name>`: the name may follow the type instead of --name.
206
- if (name !== undefined)
176
+ if (values.name !== undefined)
207
177
  invalidUsage(`Unexpected argument: ${token}`, token, {
208
178
  command: 'platform service create',
209
179
  });
210
- name = token;
180
+ values.name = token;
181
+ position += 1;
211
182
  continue;
212
183
  }
213
184
  if (!isServiceType(token)) {
214
185
  invalidUsage(`Unknown service type "${token}". Supported types: ${SERVICE_TYPES.join(', ')}`, token, { command: 'platform service create', types: [...SERVICE_TYPES] });
215
186
  }
216
187
  type = token;
188
+ position += 1;
217
189
  }
218
190
  return {
219
191
  type,
220
- name,
221
- className,
192
+ name: values.name,
193
+ className: values.className,
222
194
  deletionPolicy,
223
- target,
224
- namespace,
225
- context,
195
+ target: values.target,
196
+ ...(env ? { env } : {}),
197
+ namespace: values.namespace,
198
+ context: values.context,
226
199
  wait,
227
200
  timeoutMs,
228
201
  parameters: Object.keys(parameters).length > 0 ? parameters : undefined,
@@ -231,33 +204,20 @@ export function parseServiceCreateArgs(args) {
231
204
  }
232
205
  export function parseServiceNameArgs(args, command) {
233
206
  let name;
234
- let target;
235
- let namespace;
236
- let context;
237
- for (let position = 0; position < args.length; position++) {
238
- const token = args[position] ?? '';
239
- const targetOpt = matchOption(args, position, token, '--target');
240
- if (targetOpt) {
241
- if (target !== undefined)
242
- invalidUsage('Option may be provided only once: --target', '--target');
243
- target = targetOpt.value;
244
- position = targetOpt.consumedThrough;
245
- continue;
246
- }
247
- const namespaceOpt = matchOption(args, position, token, '--namespace');
248
- if (namespaceOpt) {
249
- if (namespace !== undefined)
250
- invalidUsage('Option may be provided only once: --namespace', '--namespace');
251
- namespace = namespaceOpt.value;
252
- position = namespaceOpt.consumedThrough;
207
+ const values = {};
208
+ let env;
209
+ let position = 0;
210
+ while (position < args.length) {
211
+ const token = args[position];
212
+ const nextPos = readStringFlag(args, position, token, SERVICE_LIST_STRING_FLAGS, values);
213
+ if (nextPos !== undefined) {
214
+ position = nextPos;
253
215
  continue;
254
216
  }
255
- const contextOpt = matchOption(args, position, token, '--context');
256
- if (contextOpt) {
257
- if (context !== undefined)
258
- invalidUsage('Option may be provided only once: --context', '--context');
259
- context = contextOpt.value;
260
- position = contextOpt.consumedThrough;
217
+ const envOpt = readEnvFlag(args, position, token, env, command);
218
+ if (envOpt) {
219
+ env = envOpt.value;
220
+ position = envOpt.nextPosition;
261
221
  continue;
262
222
  }
263
223
  if (token.startsWith('--')) {
@@ -267,37 +227,24 @@ export function parseServiceNameArgs(args, command) {
267
227
  invalidUsage(`Unexpected argument: ${token}`, token, { command });
268
228
  }
269
229
  name = token;
230
+ position += 1;
270
231
  }
271
- return { name, target, namespace, context };
232
+ return {
233
+ name,
234
+ target: values.target,
235
+ ...(env ? { env } : {}),
236
+ namespace: values.namespace,
237
+ context: values.context,
238
+ };
272
239
  }
273
240
  export function parseServiceListArgs(args) {
274
- let target;
275
- let namespace;
276
- let context;
277
- for (let position = 0; position < args.length; position++) {
278
- const token = args[position] ?? '';
279
- const targetOpt = matchOption(args, position, token, '--target');
280
- if (targetOpt) {
281
- if (target !== undefined)
282
- invalidUsage('Option may be provided only once: --target', '--target');
283
- target = targetOpt.value;
284
- position = targetOpt.consumedThrough;
285
- continue;
286
- }
287
- const namespaceOpt = matchOption(args, position, token, '--namespace');
288
- if (namespaceOpt) {
289
- if (namespace !== undefined)
290
- invalidUsage('Option may be provided only once: --namespace', '--namespace');
291
- namespace = namespaceOpt.value;
292
- position = namespaceOpt.consumedThrough;
293
- continue;
294
- }
295
- const contextOpt = matchOption(args, position, token, '--context');
296
- if (contextOpt) {
297
- if (context !== undefined)
298
- invalidUsage('Option may be provided only once: --context', '--context');
299
- context = contextOpt.value;
300
- position = contextOpt.consumedThrough;
241
+ const values = {};
242
+ let position = 0;
243
+ while (position < args.length) {
244
+ const token = args[position];
245
+ const nextPos = readStringFlag(args, position, token, SERVICE_LIST_STRING_FLAGS, values);
246
+ if (nextPos !== undefined) {
247
+ position = nextPos;
301
248
  continue;
302
249
  }
303
250
  if (token.startsWith('--')) {
@@ -305,7 +252,11 @@ export function parseServiceListArgs(args) {
305
252
  }
306
253
  invalidUsage(`Unexpected argument: ${token}`, token, { command: 'platform service list' });
307
254
  }
308
- return { target, namespace, context };
255
+ return {
256
+ target: values.target,
257
+ namespace: values.namespace,
258
+ context: values.context,
259
+ };
309
260
  }
310
261
  function validateSizing(parameters) {
311
262
  if (!parameters)
@@ -373,12 +324,8 @@ async function resolveServiceConnection(options, deps) {
373
324
  return connection;
374
325
  }
375
326
  function kubectlFailure(verb, result, details = {}) {
376
- const detail = (result.stderr.trim() ||
377
- result.stdout.trim() ||
378
- `kubectl exited ${result.exitCode}`)
379
- .split('\n')
380
- .slice(0, 12)
381
- .join('\n');
327
+ const rawDetail = result.stderr.trim() || result.stdout.trim() || `kubectl exited ${result.exitCode}`;
328
+ const detail = rawDetail.split('\n').slice(0, 12).join('\n');
382
329
  const lower = detail.toLowerCase();
383
330
  if (lower.includes('alreadyexists') || lower.includes('already exists')) {
384
331
  return new CommandFailure('WASMCLOUD_SERVICE_ALREADY_EXISTS', `BackingService already exists: ${detail}`, 2, { ...details, stderr: detail });
@@ -405,11 +352,10 @@ function readyCondition(document) {
405
352
  export function summarizeService(document) {
406
353
  const ready = readyCondition(document);
407
354
  const endpoint = document.status?.endpoint;
408
- const className = document.spec?.className ||
409
- document.status?.classRef?.name ||
410
- (document.spec?.type && isServiceType(document.spec.type)
411
- ? DEFAULT_SERVICE_CLASSES[document.spec.type]
412
- : '');
355
+ const defaultClass = document.spec?.type && isServiceType(document.spec.type)
356
+ ? DEFAULT_SERVICE_CLASSES[document.spec.type]
357
+ : '';
358
+ const className = document.spec?.className || document.status?.classRef?.name || defaultClass;
413
359
  return {
414
360
  name: document.metadata?.name ?? '',
415
361
  namespace: document.metadata?.namespace ?? '',
@@ -524,9 +470,50 @@ async function getServiceDocument(connection, name, deps) {
524
470
  throw new CommandFailure('WASMCLOUD_TOOL_FAILED', `kubectl get returned unparseable JSON for BackingService ${name}`, 3, { name, namespace: connection.namespace });
525
471
  }
526
472
  }
473
+ async function runControllerServiceCreate(type, name, options, target, deployManifest, deps) {
474
+ try {
475
+ const { credential, client } = await resolveControllerSession({ target }, deps);
476
+ const env = options.env ?? target.env ?? deployManifest.env ?? 'prod';
477
+ const created = await client.createService({
478
+ env,
479
+ type,
480
+ name,
481
+ className: options.className,
482
+ parameters: options.parameters,
483
+ deletionPolicy: options.deletionPolicy,
484
+ destinations: options.destinations,
485
+ });
486
+ const data = {
487
+ name: created.name,
488
+ type: created.type,
489
+ className: created.className,
490
+ env: created.env,
491
+ account: credential.account,
492
+ namespace: tenantNamespace(credential.account),
493
+ target: target.name,
494
+ ...(created.parameters ? { parameters: created.parameters } : {}),
495
+ ...(created.deletionPolicy ? { deletionPolicy: created.deletionPolicy } : {}),
496
+ ...(created.destinations ? { destinations: created.destinations } : {}),
497
+ wait: options.wait,
498
+ ready: 'True',
499
+ createdAt: created.createdAt,
500
+ resource: { apiVersion: BACKING_SERVICE_API_VERSION, kind: BACKING_SERVICE_KIND },
501
+ };
502
+ const text = `Created ${created.type} service ${created.name} (${created.className}) in ${created.env} (${credential.account}).`;
503
+ return { data, text };
504
+ }
505
+ catch (error) {
506
+ wrapControllerError(error);
507
+ }
508
+ }
527
509
  export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
528
510
  const options = parseServiceCreateArgs(args);
529
511
  const { type, name } = validateCreateOptions(options);
512
+ const deployManifest = loadDeployManifest(deps.cwd(), deps.env);
513
+ const target = resolveTarget(deployManifest, options.target);
514
+ if (isControllerBackedTarget(target)) {
515
+ return runControllerServiceCreate(type, name, options, target, deployManifest, deps);
516
+ }
530
517
  const connection = await resolveServiceConnection(options, deps);
531
518
  const existing = await captureKubectl(deps, connection, ['get', BACKING_SERVICE_RESOURCE, name, '-o', 'name'], deps.cwd());
532
519
  if (existing.exitCode === 0) {
@@ -571,6 +558,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
571
558
  ready: 'Unknown',
572
559
  ...(options.deletionPolicy ? { deletionPolicy: options.deletionPolicy } : {}),
573
560
  };
561
+ const context = options.context ?? connection.context;
574
562
  return {
575
563
  data: {
576
564
  name,
@@ -578,9 +566,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
578
566
  className: summary.className,
579
567
  namespace: connection.namespace,
580
568
  target: connection.target,
581
- ...(options.context !== undefined || connection.context !== undefined
582
- ? { context: options.context ?? connection.context }
583
- : {}),
569
+ ...(context !== undefined ? { context } : {}),
584
570
  ...(options.parameters ? { parameters: options.parameters } : {}),
585
571
  ...(options.deletionPolicy ? { deletionPolicy: options.deletionPolicy } : {}),
586
572
  ...(options.destinations ? { destinations: options.destinations } : {}),
@@ -649,6 +635,26 @@ export async function runWasmcloudServiceGet(args, _io, deps = DEFAULT_DEPS) {
649
635
  text: formatServiceDetail(summary),
650
636
  };
651
637
  }
638
+ async function runControllerServiceDelete(name, options, target, deployManifest, deps) {
639
+ try {
640
+ const { credential, client } = await resolveControllerSession({ target }, deps);
641
+ const env = options.env ?? target.env ?? deployManifest.env ?? 'prod';
642
+ await client.deleteService(env, name);
643
+ const data = {
644
+ name,
645
+ env,
646
+ account: credential.account,
647
+ namespace: tenantNamespace(credential.account),
648
+ target: target.name,
649
+ deleted: true,
650
+ };
651
+ const text = `Deleted BackingService ${name} from ${env} (${credential.account}).`;
652
+ return { data, text };
653
+ }
654
+ catch (error) {
655
+ wrapControllerError(error);
656
+ }
657
+ }
652
658
  export async function runWasmcloudServiceDelete(args, io, deps = DEFAULT_DEPS) {
653
659
  const options = parseServiceNameArgs(args, 'platform service delete');
654
660
  if (options.name === undefined) {
@@ -659,6 +665,11 @@ export async function runWasmcloudServiceDelete(args, io, deps = DEFAULT_DEPS) {
659
665
  if (!isBackingServiceName(options.name)) {
660
666
  invalidUsage(`Invalid service name "${options.name}". Names must be DNS labels of at most 40 characters`, options.name, { command: 'platform service delete' });
661
667
  }
668
+ const deployManifest = loadDeployManifest(deps.cwd(), deps.env);
669
+ const target = resolveTarget(deployManifest, options.target);
670
+ if (isControllerBackedTarget(target)) {
671
+ return runControllerServiceDelete(options.name, options, target, deployManifest, deps);
672
+ }
662
673
  const connection = await resolveServiceConnection(options, deps);
663
674
  let deletionPolicy;
664
675
  try {
package/dist/target.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { WasmcloudDeps } from './deps.js';
2
- import type { DeployManifest, DeployTarget } from './manifest.js';
2
+ import type { AccountTarget, ControllerTarget, DeployManifest, DeployTarget } from './manifest.js';
3
3
  import { type PlatformOutputs } from './platform.js';
4
4
  import { type RegistryLocation } from './registry.js';
5
5
  export type ClusterConnection = {
@@ -14,5 +14,11 @@ export type ClusterConnection = {
14
14
  platformRoot?: string;
15
15
  stack?: string;
16
16
  };
17
+ export declare function isControllerBackedTarget(target: DeployTarget): target is AccountTarget | ControllerTarget;
18
+ /**
19
+ * Derives the platform gateway route for a tenant controller (`https://<account>.controller.<domain>`),
20
+ * matching the HTTPRoute created by the platform tenancy reconcile (platform#58).
21
+ */
22
+ export declare function discoverAccountControllerUrl(account: string, domain?: string, env?: Record<string, string | undefined>): string;
17
23
  export declare function resolveTarget(manifest: DeployManifest, requested?: string): DeployTarget;
18
24
  export declare function resolveConnection(target: DeployTarget, workspaceRoot: string, manifestPath: string, deps: WasmcloudDeps): Promise<ClusterConnection>;
package/dist/target.js CHANGED
@@ -2,6 +2,17 @@ import { resolve } from 'node:path';
2
2
  import { CommandFailure } from '@di-framework/cli-extension';
3
3
  import { loadPlatformOutputs, resolvePlatformDirectory } from './platform.js';
4
4
  import { materializeRegistry } from './registry.js';
5
+ export function isControllerBackedTarget(target) {
6
+ return target.kind === 'account' || target.kind === 'controller';
7
+ }
8
+ /**
9
+ * Derives the platform gateway route for a tenant controller (`https://<account>.controller.<domain>`),
10
+ * matching the HTTPRoute created by the platform tenancy reconcile (platform#58).
11
+ */
12
+ export function discoverAccountControllerUrl(account, domain, env) {
13
+ const effectiveDomain = domain ?? env?.DI_PLATFORM_DOMAIN ?? 'localhost';
14
+ return `https://${account}.controller.${effectiveDomain}`;
15
+ }
5
16
  export function resolveTarget(manifest, requested) {
6
17
  const name = requested ?? manifest.defaultTarget;
7
18
  if (name === undefined) {
@@ -14,6 +25,14 @@ export function resolveTarget(manifest, requested) {
14
25
  return target;
15
26
  }
16
27
  export async function resolveConnection(target, workspaceRoot, manifestPath, deps) {
28
+ if (isControllerBackedTarget(target)) {
29
+ const msg = `Target "${target.name}" is a ${target.kind} target and talks to the tenant controller /v1 API rather than a kubeconfig.`;
30
+ throw new CommandFailure('WASMCLOUD_TARGET_INVALID_KIND', msg, 2, {
31
+ target: target.name,
32
+ kind: target.kind,
33
+ manifestPath,
34
+ });
35
+ }
17
36
  if (target.kind === 'managed') {
18
37
  return resolveManagedConnection(target, workspaceRoot, manifestPath, deps);
19
38
  }
@@ -8,7 +8,11 @@ import type { ClusterConnection } from './target.js';
8
8
  import { type WitRequirement } from './wit.js';
9
9
  export declare const MANAGED_BY_LABEL = "di-framework";
10
10
  export declare const WAIT_ATTEMPTS = 30;
11
+ export declare const STORAGE_WAIT_ATTEMPTS = 90;
11
12
  export declare const WAIT_INTERVAL_MS = 2000;
13
+ export declare const DEFAULT_DEPLOY_TIMEOUT_SECONDS = 60;
14
+ export declare const STORAGE_DEPLOY_TIMEOUT_SECONDS = 180;
15
+ export declare const DEPLOY_TIMEOUT_ENV = "DI_FRAMEWORK_DEPLOY_TIMEOUT_SECONDS";
12
16
  export declare const WORKLOAD_DEPLOYMENT_RESOURCE = "workloaddeployment.runtime.wasmcloud.dev";
13
17
  export declare const WORKLOAD_REPLICA_SET_RESOURCE = "workloadreplicaset.runtime.wasmcloud.dev";
14
18
  /** Host directory where the storage hostgroup mounts the shared PVC. */
@@ -91,21 +95,43 @@ export interface WorkloadManifestOptions {
91
95
  export declare function renderWorkloadManifest(project: WasmcloudProject, connection: ClusterConnection, image: string, requirements?: readonly WitRequirement[], bindings?: readonly BindingRecord[], options?: WorkloadManifestOptions | boolean, cronJobs?: readonly DiscoveredCronJob[], queueHandlers?: readonly DiscoveredQueueHandler[]): string;
92
96
  /** Appended to a deploy failure that happened after the control Secret was rewritten. */
93
97
  export declare const CONTROL_TOKEN_ROTATED_NOTICE = "the control token was rotated; re-run deploy to roll the workload onto it";
94
- /** Control Secret written on deploy: its name and a digest that identifies the token. */
98
+ /**
99
+ * The control Secret after a deploy: its name and, when deploy wrote a new token, a digest that
100
+ * identifies it. `revision` is undefined when deploy kept the Secret as it was.
101
+ */
95
102
  export type ControlSecretWrite = {
96
103
  name: string;
97
- revision: string;
104
+ revision?: string;
98
105
  };
99
- /** The full control Secret the CLI owns; nothing in it is read back from the cluster. */
100
- export declare function controlSecretDocument(workloadName: string, namespace: string, token: string): Record<string, unknown>;
106
+ /** The keys the CLI owns in every control Secret. */
107
+ export declare const CONTROL_SECRET_CLI_KEYS: readonly ["DI_CONTROL_TOKEN", "DI_CONTROL_IDENTITY"];
108
+ /**
109
+ * The control Secret document. The CLI's keys hold `token` and the workload name; `appData`
110
+ * (already base64, as in a Secret's `data`) carries app-owned keys over, and `resourceVersion`
111
+ * makes the update conditional.
112
+ */
113
+ export declare function controlSecretDocument(workloadName: string, namespace: string, token: string, appData?: Readonly<Record<string, string>>, resourceVersion?: string): Record<string, unknown>;
101
114
  /**
102
- * Tenant developers may create, update and delete Secrets but never get, list, watch or
103
- * patch them (platform#112). The control Secret is therefore written blind: POST the full
104
- * document and, if it already exists, PUT the same document without a resourceVersion. A
105
- * Secret allows such an unconditional update, so no read is needed to learn the version,
106
- * and the Secret never disappears the way delete-then-create would make it. Both requests
107
- * go through `--raw` because `kubectl replace -f` GETs the object first to fill in its
108
- * resourceVersion. The token is regenerated on every deploy since the old one cannot be read.
115
+ * Writes the workload's control Secret on deploy and returns whether the token rotated.
116
+ *
117
+ * The Secret holds the CLI's `DI_CONTROL_TOKEN` and `DI_CONTROL_IDENTITY` plus the app-owned keys
118
+ * the project declares in `controlSecretKeys` (cli-extensions#69). Any other key is refused: the
119
+ * Secret is injected whole into the workload's environment, so an undeclared key is either a
120
+ * mistake or a value nobody vouched for.
121
+ *
122
+ * - A new Secret is created with the CLI's keys and a fresh token.
123
+ * - An existing Secret the caller may read (an admin) is read, checked for undeclared keys, and
124
+ * updated with a fresh token and its declared keys carried over, conditional on the
125
+ * `resourceVersion` that was read.
126
+ * - Tenant developers may create, update and delete Secrets but never get, list, watch or patch
127
+ * them (platform#112), and the platform's `tenant-secret-update` admission policy refuses an
128
+ * update that drops a key. So an existing Secret is replaced blind with the CLI's keys and a
129
+ * fresh token. When that is refused because the Secret holds more keys, a dry-run update that
130
+ * also names every declared key asks the same policy whether all of the extra keys are
131
+ * declared. If they are, the Secret is kept as it is, token included, since a blind writer
132
+ * cannot carry over values it cannot read; otherwise deploy stops.
133
+ *
134
+ * Every request goes through `--raw`: `kubectl replace -f` would GET the object first.
109
135
  */
110
136
  export declare function writeControlSecret(project: WasmcloudProject, connection: ClusterConnection, deps: WasmcloudDeps): Promise<ControlSecretWrite>;
111
137
  /**
@@ -115,5 +141,17 @@ export declare function writeControlSecret(project: WasmcloudProject, connection
115
141
  export declare function deleteControlSecret(project: WasmcloudProject, connection: ClusterConnection, deps: WasmcloudDeps): Promise<void>;
116
142
  export declare function applyWorkload(project: WasmcloudProject, connection: ClusterConnection, image: string, io: CliIo, deps: WasmcloudDeps): Promise<string>;
117
143
  export declare function deleteWorkload(project: WasmcloudProject, connection: ClusterConnection, io: CliIo, deps: WasmcloudDeps): Promise<void>;
118
- export declare function waitForReady(project: WasmcloudProject, connection: ClusterConnection, deps: WasmcloudDeps, io?: CliIo): Promise<void>;
144
+ export declare function projectHasStorageOrPglite(project: WasmcloudProject & {
145
+ storage?: unknown;
146
+ }): boolean;
147
+ export declare function resolveDeployTimeoutSeconds(project: WasmcloudProject & {
148
+ storage?: unknown;
149
+ }, deps: Pick<WasmcloudDeps, 'env'>, options?: {
150
+ timeoutSeconds?: number;
151
+ }): number;
152
+ export declare function waitForReady(project: WasmcloudProject & {
153
+ storage?: unknown;
154
+ }, connection: ClusterConnection, deps: WasmcloudDeps, io?: CliIo, options?: {
155
+ timeoutSeconds?: number;
156
+ }): Promise<void>;
119
157
  export declare function isReady(stdout: string): boolean;