balena-cli 16.2.2 → 16.2.3

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 (45) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/commands/build.d.ts +43 -6
  3. package/build/commands/build.js.map +1 -1
  4. package/build/commands/config/generate.d.ts +6 -0
  5. package/build/commands/config/generate.js +9 -6
  6. package/build/commands/config/generate.js.map +1 -1
  7. package/build/commands/deploy.d.ts +5 -2
  8. package/build/commands/deploy.js +2 -3
  9. package/build/commands/deploy.js.map +1 -1
  10. package/build/commands/device/init.js +2 -2
  11. package/build/commands/device/init.js.map +1 -1
  12. package/build/commands/fleet/index.js +8 -5
  13. package/build/commands/fleet/index.js.map +1 -1
  14. package/build/commands/fleet/rename.js +1 -2
  15. package/build/commands/fleet/rename.js.map +1 -1
  16. package/build/commands/os/configure.js.map +1 -1
  17. package/build/commands/preload.d.ts +114 -16
  18. package/build/commands/preload.js +5 -4
  19. package/build/commands/preload.js.map +1 -1
  20. package/build/utils/config.d.ts +1 -1
  21. package/build/utils/config.js.map +1 -1
  22. package/build/utils/helpers.d.ts +38 -1
  23. package/build/utils/helpers.js +4 -6
  24. package/build/utils/helpers.js.map +1 -1
  25. package/build/utils/patterns.d.ts +1 -1
  26. package/build/utils/patterns.js +15 -15
  27. package/build/utils/patterns.js.map +1 -1
  28. package/build/utils/sdk.d.ts +3 -2
  29. package/build/utils/sdk.js +5 -4
  30. package/build/utils/sdk.js.map +1 -1
  31. package/lib/commands/build.ts +5 -3
  32. package/lib/commands/config/generate.ts +13 -10
  33. package/lib/commands/deploy.ts +7 -9
  34. package/lib/commands/device/init.ts +2 -2
  35. package/lib/commands/fleet/index.ts +8 -11
  36. package/lib/commands/fleet/rename.ts +1 -2
  37. package/lib/commands/os/configure.ts +3 -1
  38. package/lib/commands/preload.ts +18 -12
  39. package/lib/utils/config.ts +1 -1
  40. package/lib/utils/helpers.ts +5 -16
  41. package/lib/utils/patterns.ts +18 -16
  42. package/lib/utils/sdk.ts +17 -4
  43. package/npm-shrinkwrap.json +2 -2
  44. package/oclif.manifest.json +1 -1
  45. package/package.json +2 -2
@@ -31,7 +31,14 @@ import { parseAsInteger } from '../utils/validation';
31
31
 
32
32
  import { flags } from '@oclif/command';
33
33
  import * as _ from 'lodash';
34
- import type { Application, BalenaSDK, PineExpand, Release } from 'balena-sdk';
34
+ import type {
35
+ Application,
36
+ BalenaSDK,
37
+ PineExpand,
38
+ PineOptions,
39
+ PineTypedResult,
40
+ Release,
41
+ } from 'balena-sdk';
35
42
  import type { Preloader } from 'balena-preload';
36
43
 
37
44
  interface FlagsDef extends DockerConnectionCliFlags {
@@ -308,7 +315,7 @@ Can be repeated to add multiple certificates.\
308
315
  }
309
316
  }
310
317
 
311
- readonly applicationExpandOptions: PineExpand<Application> = {
318
+ readonly applicationExpandOptions = {
312
319
  owns__release: {
313
320
  $select: ['id', 'commit', 'end_timestamp', 'composition'],
314
321
  $expand: {
@@ -329,7 +336,7 @@ Can be repeated to add multiple certificates.\
329
336
  should_be_running__release: {
330
337
  $select: 'commit',
331
338
  },
332
- };
339
+ } satisfies PineExpand<Application>;
333
340
 
334
341
  isCurrentCommit(commit: string) {
335
342
  return commit === 'latest' || commit === 'current';
@@ -343,7 +350,7 @@ Can be repeated to add multiple certificates.\
343
350
  } catch {
344
351
  throw new Error(`Device type "${deviceTypeSlug}" not found in API query`);
345
352
  }
346
- return (await balena.models.application.getAllDirectlyAccessible({
353
+ const options = {
347
354
  $select: ['id', 'slug', 'should_track_latest_release'],
348
355
  $expand: this.applicationExpandOptions,
349
356
  $filter: {
@@ -388,11 +395,10 @@ Can be repeated to add multiple certificates.\
388
395
  },
389
396
  },
390
397
  $orderby: 'slug asc',
391
- })) as Array<
392
- ApplicationWithDeviceType & {
393
- should_be_running__release: [Release?];
394
- }
395
- >;
398
+ } satisfies PineOptions<Application>;
399
+ return (await balena.models.application.getAllDirectlyAccessible(
400
+ options,
401
+ )) as Array<PineTypedResult<Application, typeof options>>;
396
402
  }
397
403
 
398
404
  async selectApplication(deviceTypeSlug: string) {
@@ -442,7 +448,7 @@ Can be repeated to add multiple certificates.\
442
448
  }
443
449
 
444
450
  async offerToDisableAutomaticUpdates(
445
- application: Application,
451
+ application: Pick<Application, 'id' | 'should_track_latest_release'>,
446
452
  commit: string,
447
453
  pinDevice: boolean,
448
454
  ) {
@@ -494,9 +500,9 @@ Would you like to disable automatic updates for this fleet now?\
494
500
  async getAppWithReleases(balenaSdk: BalenaSDK, slug: string) {
495
501
  const { getApplication } = await import('../utils/sdk');
496
502
 
497
- return (await getApplication(balenaSdk, slug, {
503
+ return await getApplication(balenaSdk, slug, {
498
504
  $expand: this.applicationExpandOptions,
499
- })) as Application & { should_be_running__release: [Release?] };
505
+ });
500
506
  }
501
507
 
502
508
  async prepareAndPreload(
@@ -59,7 +59,7 @@ export interface ImgConfig {
59
59
  }
60
60
 
61
61
  export async function generateApplicationConfig(
62
- application: BalenaSdk.Application,
62
+ application: Pick<BalenaSdk.Application, 'slug'>,
63
63
  options: {
64
64
  version: string;
65
65
  appUpdatePollInterval?: number;
@@ -180,11 +180,10 @@ export async function osProgressHandler(step: InitializeEmitter) {
180
180
  });
181
181
  }
182
182
 
183
- export async function getAppWithArch(
184
- applicationName: string,
185
- ): Promise<ApplicationWithDeviceType & { arch: string }> {
183
+ export async function getAppWithArch(applicationName: string) {
186
184
  const { getApplication } = await import('./sdk');
187
- const options: BalenaSdk.PineOptions<BalenaSdk.Application> = {
185
+ const balena = getBalenaSdk();
186
+ const app = await getApplication(balena, applicationName, {
188
187
  $expand: {
189
188
  application_type: {
190
189
  $select: ['name', 'slug', 'supports_multicontainer'],
@@ -198,20 +197,10 @@ export async function getAppWithArch(
198
197
  },
199
198
  },
200
199
  },
201
- };
202
- const balena = getBalenaSdk();
203
- const app = (await getApplication(
204
- balena,
205
- applicationName,
206
- options,
207
- )) as ApplicationWithDeviceType;
208
- const { getExpanded } = await import('./pine');
209
-
200
+ });
210
201
  return {
211
202
  ...app,
212
- arch: getExpanded(
213
- getExpanded(app.is_for__device_type)!.is_of__cpu_architecture,
214
- )!.slug,
203
+ arch: app.is_for__device_type[0].is_of__cpu_architecture[0].slug,
215
204
  };
216
205
  }
217
206
 
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import type { Application, BalenaSDK, Device, Organization } from 'balena-sdk';
17
+ import type { BalenaSDK, Device, Organization } from 'balena-sdk';
18
18
  import _ = require('lodash');
19
19
 
20
20
  import { instanceOf, NotLoggedInError, ExpectedError } from '../errors';
@@ -193,10 +193,11 @@ export function selectApplication(
193
193
  });
194
194
  }
195
195
 
196
- export async function selectOrganization(organizations?: Organization[]) {
196
+ export async function selectOrganization(
197
+ organizations?: Array<Pick<Organization, 'handle' | 'name'>>,
198
+ ) {
197
199
  // Use either provided orgs (if e.g. already loaded) or load from cloud
198
- organizations =
199
- organizations || (await getBalenaSdk().models.organization.getAll());
200
+ organizations ??= await getBalenaSdk().models.organization.getAll();
200
201
  return getCliForm().ask({
201
202
  message: 'Select an organization',
202
203
  type: 'list',
@@ -295,19 +296,20 @@ export async function getOnlineTargetDeviceUuid(
295
296
  }
296
297
 
297
298
  // Not a device UUID, try application
298
- let application: Application;
299
- try {
300
- logger.logDebug(`Fetching fleet ${fleetOrDevice}`);
301
- const { getApplication } = await import('./sdk');
302
- application = await getApplication(sdk, fleetOrDevice);
303
- } catch (err) {
304
- const { BalenaApplicationNotFound } = await import('balena-errors');
305
- if (instanceOf(err, BalenaApplicationNotFound)) {
306
- throw new ExpectedError(`Fleet or Device not found: ${fleetOrDevice}`);
307
- } else {
308
- throw err;
299
+ const application = await (async () => {
300
+ try {
301
+ logger.logDebug(`Fetching fleet ${fleetOrDevice}`);
302
+ const { getApplication } = await import('./sdk');
303
+ return await getApplication(sdk, fleetOrDevice);
304
+ } catch (err) {
305
+ const { BalenaApplicationNotFound } = await import('balena-errors');
306
+ if (instanceOf(err, BalenaApplicationNotFound)) {
307
+ throw new ExpectedError(`Fleet or Device not found: ${fleetOrDevice}`);
308
+ } else {
309
+ throw err;
310
+ }
309
311
  }
310
- }
312
+ })();
311
313
 
312
314
  // App found, load its devices
313
315
  const devices = await sdk.models.device.getAllByApplication(application.id, {
package/lib/utils/sdk.ts CHANGED
@@ -20,8 +20,18 @@ import type {
20
20
  BalenaSDK,
21
21
  Organization,
22
22
  PineOptions,
23
+ PineTypedResult,
23
24
  } from 'balena-sdk';
24
25
 
26
+ export async function getApplication(
27
+ sdk: BalenaSDK,
28
+ nameOrSlugOrId: string | number,
29
+ ): Promise<Application>;
30
+ export async function getApplication<TP extends PineOptions<Application>>(
31
+ sdk: BalenaSDK,
32
+ nameOrSlugOrId: string | number,
33
+ options?: TP,
34
+ ): Promise<PineTypedResult<Application, TP>>;
25
35
  /**
26
36
  * Get a fleet object, disambiguating the fleet identifier which may be a
27
37
  * a fleet slug or name.
@@ -29,21 +39,24 @@ import type {
29
39
  */
30
40
  export async function getApplication(
31
41
  sdk: BalenaSDK,
32
- nameOrSlug: string,
42
+ nameOrSlugOrId: string | number,
33
43
  options?: PineOptions<Application>,
34
44
  ): Promise<Application> {
35
45
  const { looksLikeFleetSlug } = await import('./validation');
36
- if (!looksLikeFleetSlug(nameOrSlug)) {
46
+ if (
47
+ typeof nameOrSlugOrId === 'string' &&
48
+ !looksLikeFleetSlug(nameOrSlugOrId)
49
+ ) {
37
50
  // Not a slug: must be an app name.
38
51
  // TODO: revisit this logic when we add support for fleet UUIDs.
39
52
  return await sdk.models.application.getAppByName(
40
- nameOrSlug,
53
+ nameOrSlugOrId,
41
54
  options,
42
55
  'directly_accessible',
43
56
  );
44
57
  }
45
58
  return await sdk.models.application.getDirectlyAccessible(
46
- nameOrSlug,
59
+ nameOrSlugOrId,
47
60
  options,
48
61
  );
49
62
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "balena-cli",
3
- "version": "16.2.2",
3
+ "version": "16.2.3",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "balena-cli",
9
- "version": "16.2.2",
9
+ "version": "16.2.3",
10
10
  "hasInstallScript": true,
11
11
  "license": "Apache-2.0",
12
12
  "dependencies": {