directus-template-cli 0.7.0-beta.3 → 0.7.0-beta.5

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 (93) hide show
  1. package/bin/dev +2 -3
  2. package/bin/dev.js +3 -0
  3. package/bin/run +0 -1
  4. package/bin/run.js +5 -0
  5. package/dist/commands/apply.d.ts +17 -17
  6. package/dist/commands/apply.js +160 -173
  7. package/dist/commands/extract.d.ts +13 -7
  8. package/dist/commands/extract.js +89 -73
  9. package/dist/commands/init.d.ts +7 -7
  10. package/dist/commands/init.js +78 -80
  11. package/dist/flags/common.d.ts +7 -7
  12. package/dist/flags/common.js +8 -11
  13. package/dist/index.js +1 -5
  14. package/dist/lib/constants.js +6 -9
  15. package/dist/lib/extract/extract-access.js +11 -15
  16. package/dist/lib/extract/extract-assets.js +20 -25
  17. package/dist/lib/extract/extract-collections.js +12 -16
  18. package/dist/lib/extract/extract-content.js +14 -19
  19. package/dist/lib/extract/extract-dashboards.js +22 -28
  20. package/dist/lib/extract/extract-extensions.js +12 -16
  21. package/dist/lib/extract/extract-fields.js +13 -17
  22. package/dist/lib/extract/extract-files.js +15 -19
  23. package/dist/lib/extract/extract-flows.js +22 -28
  24. package/dist/lib/extract/extract-folders.js +15 -19
  25. package/dist/lib/extract/extract-permissions.js +12 -16
  26. package/dist/lib/extract/extract-policies.js +12 -16
  27. package/dist/lib/extract/extract-presets.js +12 -16
  28. package/dist/lib/extract/extract-relations.js +14 -18
  29. package/dist/lib/extract/extract-roles.js +15 -19
  30. package/dist/lib/extract/extract-schema.js +17 -21
  31. package/dist/lib/extract/extract-settings.js +12 -16
  32. package/dist/lib/extract/extract-translations.js +12 -16
  33. package/dist/lib/extract/extract-users.js +15 -19
  34. package/dist/lib/extract/index.js +47 -51
  35. package/dist/lib/init/config.d.ts +1 -1
  36. package/dist/lib/init/config.js +2 -5
  37. package/dist/lib/init/index.js +54 -59
  38. package/dist/lib/init/types.js +1 -2
  39. package/dist/lib/init.d.ts +1 -0
  40. package/dist/lib/init.js +2 -0
  41. package/dist/lib/load/apply-flags.js +17 -23
  42. package/dist/lib/load/index.js +40 -44
  43. package/dist/lib/load/load-access.js +15 -20
  44. package/dist/lib/load/load-collections.js +27 -32
  45. package/dist/lib/load/load-dashboards.js +19 -25
  46. package/dist/lib/load/load-data.js +43 -49
  47. package/dist/lib/load/load-extensions.js +30 -38
  48. package/dist/lib/load/load-files.js +20 -24
  49. package/dist/lib/load/load-flows.js +23 -29
  50. package/dist/lib/load/load-folders.js +16 -20
  51. package/dist/lib/load/load-permissions.js +13 -17
  52. package/dist/lib/load/load-policies.js +14 -18
  53. package/dist/lib/load/load-presets.js +14 -18
  54. package/dist/lib/load/load-relations.d.ts +2 -0
  55. package/dist/lib/load/load-relations.js +16 -18
  56. package/dist/lib/load/load-roles.js +19 -23
  57. package/dist/lib/load/load-settings.js +18 -21
  58. package/dist/lib/load/load-translations.js +14 -18
  59. package/dist/lib/load/load-users.js +21 -25
  60. package/dist/lib/load/update-required-fields.js +13 -17
  61. package/dist/lib/sdk.d.ts +1 -2
  62. package/dist/lib/sdk.js +27 -27
  63. package/dist/lib/types/extension.js +1 -2
  64. package/dist/lib/utils/animated-bunny.js +9 -14
  65. package/dist/lib/utils/auth.d.ts +2 -2
  66. package/dist/lib/utils/auth.js +32 -33
  67. package/dist/lib/utils/catch-error.js +8 -11
  68. package/dist/lib/utils/check-template.js +4 -8
  69. package/dist/lib/utils/chunk-array.js +1 -5
  70. package/dist/lib/utils/ensure-dir.js +7 -12
  71. package/dist/lib/utils/filter-fields.js +1 -4
  72. package/dist/lib/utils/get-role-ids.d.ts +1 -1
  73. package/dist/lib/utils/get-role-ids.js +7 -12
  74. package/dist/lib/utils/get-template.js +33 -37
  75. package/dist/lib/utils/logger.js +11 -13
  76. package/dist/lib/utils/open-url.js +5 -8
  77. package/dist/lib/utils/parse-github-url.js +4 -9
  78. package/dist/lib/utils/path.js +6 -10
  79. package/dist/lib/utils/protected-domains.js +1 -4
  80. package/dist/lib/utils/read-file.js +8 -12
  81. package/dist/lib/utils/read-templates.js +9 -15
  82. package/dist/lib/utils/system-fields.js +19 -22
  83. package/dist/lib/utils/template-defaults.d.ts +1 -1
  84. package/dist/lib/utils/template-defaults.js +5 -14
  85. package/dist/lib/utils/transform-github-url.js +1 -5
  86. package/dist/lib/utils/validate-url.js +3 -6
  87. package/dist/lib/utils/wait.js +1 -5
  88. package/dist/lib/utils/write-to-file.js +8 -11
  89. package/dist/services/docker.js +19 -24
  90. package/dist/services/github.d.ts +1 -1
  91. package/dist/services/github.js +8 -12
  92. package/oclif.manifest.json +4 -4
  93. package/package.json +36 -32
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const sdk_1 = require("@directus/sdk");
5
- const core_1 = require("@oclif/core");
6
- const constants_1 = require("../constants");
7
- const sdk_2 = require("../sdk");
8
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
9
- const get_role_ids_1 = tslib_1.__importDefault(require("../utils/get-role-ids"));
10
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
11
- async function loadRoles(dir) {
12
- const roles = (0, read_file_1.default)('roles', dir);
13
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${roles.length} roles`));
1
+ import { createRole, readRoles, updateRole } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import { DIRECTUS_PINK } from '../constants.js';
4
+ import { api } from '../sdk.js';
5
+ import catchError from '../utils/catch-error.js';
6
+ import getRoleIds from '../utils/get-role-ids.js';
7
+ import readFile from '../utils/read-file.js';
8
+ export default async function loadRoles(dir) {
9
+ const roles = readFile('roles', dir);
10
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${roles.length} roles`));
14
11
  if (roles && roles.length > 0) {
15
- const { legacyAdminRoleId, newAdminRoleId } = await (0, get_role_ids_1.default)(dir);
12
+ const { legacyAdminRoleId, newAdminRoleId } = await getRoleIds(dir);
16
13
  // Fetch existing roles
17
- const existingRoles = await sdk_2.api.client.request((0, sdk_1.readRoles)({
14
+ const existingRoles = await api.client.request(readRoles({
18
15
  limit: -1,
19
16
  }));
20
17
  const existingRoleIds = new Set(existingRoles.map(role => role.id));
@@ -24,8 +21,8 @@ async function loadRoles(dir) {
24
21
  .filter(role => !existingRoleNames.has(role.name.toLowerCase())) // Filter out roles with existing names
25
22
  .map(role => {
26
23
  const r = { ...role };
27
- delete r.users; // Alias field. User roles will be applied when the users are loaded.
28
- delete r.parent; // We need to load all roles first
24
+ r.users = undefined; // Alias field. User roles will be applied when the users are loaded.
25
+ r.parent = undefined; // We need to load all roles first
29
26
  return r;
30
27
  });
31
28
  for await (const role of cleanedUpRoles) {
@@ -34,13 +31,13 @@ async function loadRoles(dir) {
34
31
  continue;
35
32
  }
36
33
  // Create new role
37
- await sdk_2.api.client.request((0, sdk_1.createRole)(role));
34
+ await api.client.request(createRole(role));
38
35
  // Add the new role ID and name to our sets of existing roles
39
36
  existingRoleIds.add(role.id);
40
37
  existingRoleNames.add(role.name.toLowerCase());
41
38
  }
42
39
  catch (error) {
43
- (0, catch_error_1.default)(error);
40
+ catchError(error);
44
41
  }
45
42
  }
46
43
  // Now add in any parent fields
@@ -52,13 +49,12 @@ async function loadRoles(dir) {
52
49
  role.parent = newAdminRoleId;
53
50
  }
54
51
  const simplifiedRole = { parent: role.parent };
55
- await sdk_2.api.client.request((0, sdk_1.updateRole)(role.id, simplifiedRole));
52
+ await api.client.request(updateRole(role.id, simplifiedRole));
56
53
  }
57
54
  catch (error) {
58
- (0, catch_error_1.default)(error);
55
+ catchError(error);
59
56
  }
60
57
  }
61
58
  }
62
- core_1.ux.action.stop();
59
+ ux.action.stop();
63
60
  }
64
- exports.default = loadRoles;
@@ -1,21 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const sdk_1 = require("@directus/sdk");
5
- const core_1 = require("@oclif/core");
6
- const defu_1 = require("defu");
7
- const constants_1 = require("../constants");
8
- const sdk_2 = require("../sdk");
9
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
10
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
11
- const customDefu = (0, defu_1.createDefu)((obj, key, value) => {
1
+ import { readSettings, updateSettings } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import { createDefu } from 'defu';
4
+ import { DIRECTUS_PINK } from '../constants.js';
5
+ import { api } from '../sdk.js';
6
+ import catchError from '../utils/catch-error.js';
7
+ import readFile from '../utils/read-file.js';
8
+ // Cast ux to any to bypass type errors
9
+ const customDefu = createDefu((obj, key, value) => {
12
10
  if (Array.isArray(obj[key]) && Array.isArray(value)) {
13
- // @ts-expect-error
11
+ // @ts-ignore - ignore
14
12
  obj[key] = mergeArrays(key, obj[key], value);
15
13
  return true;
16
14
  }
17
15
  if (typeof obj[key] === 'string' && typeof value === 'string') {
18
- // @ts-expect-error
16
+ // @ts-ignore - ignore
19
17
  obj[key] = mergeJsonStrings(obj[key], value);
20
18
  return true;
21
19
  }
@@ -42,17 +40,16 @@ function mergeJsonStrings(current, incoming) {
42
40
  return incoming; // If not valid JSON, return the incoming value
43
41
  }
44
42
  }
45
- async function loadSettings(dir) {
46
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, 'Loading settings'));
47
- const settings = (0, read_file_1.default)('settings', dir);
43
+ export default async function loadSettings(dir) {
44
+ ux.action.start(ux.colorize(DIRECTUS_PINK, 'Loading settings'));
45
+ const settings = readFile('settings', dir);
48
46
  try {
49
- const currentSettings = await sdk_2.api.client.request((0, sdk_1.readSettings)());
47
+ const currentSettings = await api.client.request(readSettings());
50
48
  const mergedSettings = customDefu(currentSettings, settings);
51
- await sdk_2.api.client.request((0, sdk_1.updateSettings)(mergedSettings));
49
+ await api.client.request(updateSettings(mergedSettings));
52
50
  }
53
51
  catch (error) {
54
- (0, catch_error_1.default)(error);
52
+ catchError(error);
55
53
  }
56
- core_1.ux.action.stop();
54
+ ux.action.stop();
57
55
  }
58
- exports.default = loadSettings;
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const sdk_1 = require("@directus/sdk");
5
- const core_1 = require("@oclif/core");
6
- const constants_1 = require("../constants");
7
- const sdk_2 = require("../sdk");
8
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
9
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
10
- async function loadTranslations(dir) {
11
- const translations = (0, read_file_1.default)('translations', dir);
12
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${translations.length} translations`));
1
+ import { createTranslations, readTranslations } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import { DIRECTUS_PINK } from '../constants.js';
4
+ import { api } from '../sdk.js';
5
+ import catchError from '../utils/catch-error.js';
6
+ import readFile from '../utils/read-file.js';
7
+ export default async function loadTranslations(dir) {
8
+ const translations = readFile('translations', dir);
9
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${translations.length} translations`));
13
10
  if (translations && translations.length > 0) {
14
11
  // Fetch existing translations
15
- const existingTranslations = await sdk_2.api.client.request((0, sdk_1.readTranslations)({
12
+ const existingTranslations = await api.client.request(readTranslations({
16
13
  limit: -1,
17
14
  }));
18
15
  const existingTranslationKeys = new Set(existingTranslations.map(t => `${t.language}_${t.key}`));
@@ -25,16 +22,15 @@ async function loadTranslations(dir) {
25
22
  });
26
23
  if (newTranslations.length > 0) {
27
24
  try {
28
- await sdk_2.api.client.request((0, sdk_1.createTranslations)(newTranslations));
25
+ await api.client.request(createTranslations(newTranslations));
29
26
  }
30
27
  catch (error) {
31
- (0, catch_error_1.default)(error);
28
+ catchError(error);
32
29
  }
33
30
  }
34
31
  else {
35
- // ux.info('-- No new translations to create')
32
+ // ux.stdout('-- No new translations to create')
36
33
  }
37
34
  }
38
- core_1.ux.action.stop();
35
+ ux.action.stop();
39
36
  }
40
- exports.default = loadTranslations;
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const sdk_1 = require("@directus/sdk");
5
- const core_1 = require("@oclif/core");
6
- const constants_1 = require("../constants");
7
- const sdk_2 = require("../sdk");
8
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
9
- const get_role_ids_1 = tslib_1.__importDefault(require("../utils/get-role-ids"));
10
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
11
- async function loadUsers(dir) {
12
- const users = (0, read_file_1.default)('users', dir);
13
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Loading ${users.length} users`));
1
+ import { createUser, readUsers } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import { DIRECTUS_PINK } from '../constants.js';
4
+ import { api } from '../sdk.js';
5
+ import catchError from '../utils/catch-error.js';
6
+ import getRoleIds from '../utils/get-role-ids.js';
7
+ import readFile from '../utils/read-file.js';
8
+ export default async function loadUsers(dir) {
9
+ const users = readFile('users', dir);
10
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Loading ${users.length} users`));
14
11
  if (users && users.length > 0) {
15
- const { legacyAdminRoleId, newAdminRoleId } = await (0, get_role_ids_1.default)(dir);
16
- const existingUsers = await sdk_2.api.client.request((0, sdk_1.readUsers)({
12
+ const { legacyAdminRoleId, newAdminRoleId } = await getRoleIds(dir);
13
+ const existingUsers = await api.client.request(readUsers({
17
14
  limit: -1,
18
15
  }));
19
16
  const filteredUsers = users.map(user => {
@@ -21,11 +18,11 @@ async function loadUsers(dir) {
21
18
  const isAdmin = user.role === legacyAdminRoleId;
22
19
  user.role = isAdmin ? newAdminRoleId : user.role;
23
20
  // Delete the unneeded fields
24
- delete user.last_page;
25
- delete user.token;
26
- delete user.policies;
21
+ user.last_page = undefined;
22
+ user.token = undefined;
23
+ user.policies = undefined;
27
24
  // Delete passwords to prevent setting to *******
28
- delete user.password;
25
+ user.password = undefined;
29
26
  return user;
30
27
  });
31
28
  for await (const user of filteredUsers) {
@@ -41,20 +38,19 @@ async function loadUsers(dir) {
41
38
  }
42
39
  if (existingUserWithSameEmail) {
43
40
  // Delete email if there's an existing user with the same email but different id
44
- delete user.email;
41
+ user.email = undefined;
45
42
  }
46
43
  if (user.email === null) {
47
44
  // Delete email if it's null
48
- delete user.email;
45
+ user.email = undefined;
49
46
  }
50
47
  try {
51
- await sdk_2.api.client.request((0, sdk_1.createUser)(user));
48
+ await api.client.request(createUser(user));
52
49
  }
53
50
  catch (error) {
54
- (0, catch_error_1.default)(error);
51
+ catchError(error);
55
52
  }
56
53
  }
57
54
  }
58
- core_1.ux.action.stop();
55
+ ux.action.stop();
59
56
  }
60
- exports.default = loadUsers;
@@ -1,24 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const sdk_1 = require("@directus/sdk");
5
- const core_1 = require("@oclif/core");
6
- const constants_1 = require("../constants");
7
- const sdk_2 = require("../sdk");
8
- const catch_error_1 = tslib_1.__importDefault(require("../utils/catch-error"));
9
- const read_file_1 = tslib_1.__importDefault(require("../utils/read-file"));
10
- async function updateRequiredFields(dir) {
11
- const fieldsToUpdate = (0, read_file_1.default)('fields', dir)
12
- .filter(field => { var _a, _b; return field.meta.required === true || ((_a = field.schema) === null || _a === void 0 ? void 0 : _a.is_nullable) === false || ((_b = field.schema) === null || _b === void 0 ? void 0 : _b.is_unique) === true; });
13
- core_1.ux.action.start(core_1.ux.colorize(constants_1.DIRECTUS_PINK, `Updating ${fieldsToUpdate.length} fields to required`));
1
+ import { updateField } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import { DIRECTUS_PINK } from '../constants.js';
4
+ import { api } from '../sdk.js';
5
+ import catchError from '../utils/catch-error.js';
6
+ import readFile from '../utils/read-file.js';
7
+ export default async function updateRequiredFields(dir) {
8
+ const fieldsToUpdate = readFile('fields', dir)
9
+ .filter(field => field.meta.required === true || field.schema?.is_nullable === false || field.schema?.is_unique === true);
10
+ ux.action.start(ux.colorize(DIRECTUS_PINK, `Updating ${fieldsToUpdate.length} fields to required`));
14
11
  for await (const field of fieldsToUpdate) {
15
12
  try {
16
- await sdk_2.api.client.request((0, sdk_1.updateField)(field.collection, field.field, { meta: { ...field.meta }, schema: { ...field.schema } }));
13
+ await api.client.request(updateField(field.collection, field.field, { meta: { ...field.meta }, schema: { ...field.schema } }));
17
14
  }
18
15
  catch (error) {
19
- (0, catch_error_1.default)(error);
16
+ catchError(error);
20
17
  }
21
18
  }
22
- core_1.ux.action.stop();
19
+ ux.action.stop();
23
20
  }
24
- exports.default = updateRequiredFields;
package/dist/lib/sdk.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { AuthenticationClient, RestClient } from '@directus/sdk';
2
- export interface Schema {
3
- }
2
+ type Schema = any;
4
3
  export declare class DirectusError extends Error {
5
4
  errors: Array<{
6
5
  extensions?: Record<string, unknown>;
package/dist/lib/sdk.js CHANGED
@@ -1,11 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.api = exports.DirectusError = void 0;
4
- const tslib_1 = require("tslib");
5
- const sdk_1 = require("@directus/sdk");
6
- const core_1 = require("@oclif/core");
7
- const bottleneck_1 = tslib_1.__importDefault(require("bottleneck"));
8
- class DirectusError extends Error {
1
+ import { authentication, createDirectus, rest } from '@directus/sdk';
2
+ import { ux } from '@oclif/core';
3
+ import Bottleneck from 'bottleneck';
4
+ export class DirectusError extends Error {
5
+ errors;
6
+ headers;
7
+ message;
8
+ response;
9
+ status;
9
10
  constructor(response) {
10
11
  super(response.statusText);
11
12
  this.name = 'DirectusError';
@@ -39,11 +40,12 @@ class DirectusError extends Error {
39
40
  }
40
41
  }
41
42
  }
42
- exports.DirectusError = DirectusError;
43
43
  class Api {
44
+ client;
45
+ authData = null;
46
+ limiter;
44
47
  constructor() {
45
- this.authData = null;
46
- this.limiter = new bottleneck_1.default({
48
+ this.limiter = new Bottleneck({
47
49
  maxConcurrent: 10,
48
50
  minTime: 100, // Ensure at least 100ms between requests
49
51
  reservoir: 50, // Reservoir to handle the default rate limiter of 50 requests per second
@@ -52,18 +54,17 @@ class Api {
52
54
  retryCount: 3, // Retry a maximum of 3 times
53
55
  });
54
56
  this.limiter.on('failed', async (error, jobInfo) => {
55
- var _a;
56
57
  if (error instanceof DirectusError) {
57
- const retryAfter = (_a = error.headers) === null || _a === void 0 ? void 0 : _a.get('Retry-After');
58
+ const retryAfter = error.headers?.get('Retry-After');
58
59
  const statusCode = error.status;
59
60
  if (statusCode === 429) {
60
- const delay = retryAfter ? Number.parseInt(retryAfter, 10) * 1000 : 60000;
61
- core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Rate limited. Retrying after ${delay}ms`);
61
+ const delay = retryAfter ? Number.parseInt(retryAfter, 10) * 1000 : 60_000;
62
+ ux.stdout(`${ux.colorize('dim', '--')} Rate limited. Retrying after ${delay}ms`);
62
63
  return delay;
63
64
  }
64
65
  if (statusCode === 503) {
65
66
  const delay = retryAfter ? Number.parseInt(retryAfter, 10) * 1000 : 5000;
66
- core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Server under pressure. Retrying after ${delay}ms`);
67
+ ux.stdout(`${ux.colorize('dim', '--')} Server under pressure. Retrying after ${delay}ms`);
67
68
  return delay;
68
69
  }
69
70
  // If the status code is 400 or 401, we don't want to retry
@@ -73,33 +74,32 @@ class Api {
73
74
  }
74
75
  // For other errors, use exponential backoff, but only if we haven't exceeded retryCount
75
76
  if (jobInfo.retryCount < 3) {
76
- const delay = Math.min(1000 * 2 ** jobInfo.retryCount, 30000);
77
- core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Request failed. Retrying after ${delay}ms`);
77
+ const delay = Math.min(1000 * 2 ** jobInfo.retryCount, 30_000);
78
+ ux.stdout(`${ux.colorize('dim', '--')} Request failed. Retrying after ${delay}ms`);
78
79
  return delay;
79
80
  }
80
- core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Max retries reached, not retrying further`);
81
+ ux.stdout(`${ux.colorize('dim', '--')} Max retries reached, not retrying further`);
81
82
  });
82
83
  this.limiter.on('retry', (error, jobInfo) => {
83
- core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Retrying job (attempt ${jobInfo.retryCount + 1})`);
84
+ ux.stdout(`${ux.colorize('dim', '--')} Retrying job (attempt ${jobInfo.retryCount + 1})`);
84
85
  });
85
86
  this.limiter.on('depleted', empty => {
86
87
  if (empty) {
87
- core_1.ux.log(`${core_1.ux.colorize('dim', '--')} Rate limit quota depleted. Requests will be queued.`);
88
+ ux.stdout(`${ux.colorize('dim', '--')} Rate limit quota depleted. Requests will be queued.`);
88
89
  }
89
90
  });
90
91
  }
91
92
  getToken() {
92
- var _a, _b;
93
- return (_b = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.access_token) !== null && _b !== void 0 ? _b : null;
93
+ return this.authData?.access_token ?? null;
94
94
  }
95
95
  initialize(url) {
96
- this.client = (0, sdk_1.createDirectus)(url, {
96
+ this.client = createDirectus(url, {
97
97
  globals: {
98
98
  fetch: this.limiter.wrap(this.enhancedFetch),
99
99
  },
100
100
  })
101
- .with((0, sdk_1.rest)())
102
- .with((0, sdk_1.authentication)('json', {
101
+ .with(rest())
102
+ .with(authentication('json', {
103
103
  autoRefresh: true,
104
104
  storage: {
105
105
  get: () => this.authData,
@@ -145,4 +145,4 @@ class Api {
145
145
  }
146
146
  }
147
147
  const api = new Api();
148
- exports.api = api;
148
+ export { api };
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,19 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.animatedBunny = exports.RANDOM_SAYINGS = void 0;
4
- const tslib_1 = require("tslib");
5
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const log_update_1 = tslib_1.__importDefault(require("log-update"));
7
- const constants_1 = require("../constants");
8
- exports.RANDOM_SAYINGS = [
1
+ import chalk from 'chalk';
2
+ import logUpdate from 'log-update';
3
+ import { DIRECTUS_PINK } from '../constants.js';
4
+ export const RANDOM_SAYINGS = [
9
5
  'One does not simply write backends...',
10
6
  'I don\'t always test my code, but when I do, I use production.',
11
7
  'A wild Directus appears!',
12
8
  'Error 418: I\'m a teapot. Just kidding, I\'m Directus and I\'ve got your backend covered.',
13
9
  'I\'ll fix it later. Narrator: They didn\'t fix it later.',
14
10
  ];
15
- async function animatedBunny(customMessage) {
16
- const saying = customMessage || exports.RANDOM_SAYINGS[Math.floor(Math.random() * exports.RANDOM_SAYINGS.length)];
11
+ export async function animatedBunny(customMessage) {
12
+ const saying = customMessage || RANDOM_SAYINGS[Math.floor(Math.random() * RANDOM_SAYINGS.length)];
17
13
  let typedSaying = '';
18
14
  let blinkState = true;
19
15
  let charIndex = 0;
@@ -24,7 +20,7 @@ async function animatedBunny(customMessage) {
24
20
  isCleanedUp = true;
25
21
  clearInterval(animation);
26
22
  clearInterval(typing);
27
- log_update_1.default.done();
23
+ logUpdate.done();
28
24
  };
29
25
  // Ensure cleanup on process exit
30
26
  process.on('exit', cleanup);
@@ -36,8 +32,8 @@ async function animatedBunny(customMessage) {
36
32
  if (isCleanedUp)
37
33
  return;
38
34
  const eyes = blinkState ? '- -' : 'Õ Õ';
39
- const frame = `(\\ /)\n \\\\_//\n ( ${eyes}) ${chalk_1.default.dim('')}${chalk_1.default.hex(constants_1.DIRECTUS_PINK).visible(`"${typedSaying}"`)}\nC(")(")`;
40
- (0, log_update_1.default)(frame);
35
+ const frame = `(\\ /)\n \\\\_//\n ( ${eyes}) ${chalk.dim('')}${chalk.hex(DIRECTUS_PINK).visible(`"${typedSaying}"`)}\nC(")(")`;
36
+ logUpdate(frame);
41
37
  };
42
38
  const animation = setInterval(() => {
43
39
  blinkState = !blinkState;
@@ -64,4 +60,3 @@ async function animatedBunny(customMessage) {
64
60
  process.removeListener('SIGINT', cleanup);
65
61
  }
66
62
  }
67
- exports.animatedBunny = animatedBunny;
@@ -8,13 +8,13 @@ interface AuthFlags {
8
8
  * Get the Directus URL from the user
9
9
  * @returns The Directus URL
10
10
  */
11
- export declare function getDirectusUrl(): Promise<string>;
11
+ export declare function getDirectusUrl(): Promise<string | symbol>;
12
12
  /**
13
13
  * Get the Directus token from the user
14
14
  * @param directusUrl - The Directus URL
15
15
  * @returns The Directus token
16
16
  */
17
- export declare function getDirectusToken(directusUrl: string): Promise<string>;
17
+ export declare function getDirectusToken(directusUrl: string): Promise<string | symbol>;
18
18
  /**
19
19
  * Initialize the Directus API with the provided flags
20
20
  * @param flags - The validated ApplyFlags
@@ -1,42 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateAuthFlags = exports.initializeDirectusApi = exports.getDirectusToken = exports.getDirectusUrl = void 0;
4
- const tslib_1 = require("tslib");
5
- const sdk_1 = require("@directus/sdk");
6
- const core_1 = require("@oclif/core");
7
- const sdk_2 = require("../sdk");
8
- const catch_error_1 = tslib_1.__importDefault(require("./catch-error"));
9
- const validate_url_1 = tslib_1.__importDefault(require("./validate-url"));
1
+ import { readMe } from '@directus/sdk';
2
+ import { text } from '@clack/prompts';
3
+ import { ux } from '@oclif/core';
4
+ import { api } from '../sdk.js';
5
+ import catchError from './catch-error.js';
6
+ import validateUrl from './validate-url.js';
10
7
  /**
11
8
  * Get the Directus URL from the user
12
9
  * @returns The Directus URL
13
10
  */
14
- async function getDirectusUrl() {
15
- const directusUrl = await core_1.ux.prompt('What is your Directus URL?', { default: 'http://localhost:8055' });
11
+ export async function getDirectusUrl() {
12
+ const directusUrl = await text({
13
+ placeholder: 'http://localhost:8055',
14
+ message: 'What is your Directus URL?',
15
+ });
16
16
  // Validate URL
17
- if (!(0, validate_url_1.default)(directusUrl)) {
18
- core_1.ux.warn('Invalid URL');
17
+ if (!validateUrl(directusUrl)) {
18
+ ux.warn('Invalid URL');
19
19
  return getDirectusUrl();
20
20
  }
21
- sdk_2.api.initialize(directusUrl);
21
+ api.initialize(directusUrl);
22
22
  return directusUrl;
23
23
  }
24
- exports.getDirectusUrl = getDirectusUrl;
25
24
  /**
26
25
  * Get the Directus token from the user
27
26
  * @param directusUrl - The Directus URL
28
27
  * @returns The Directus token
29
28
  */
30
- async function getDirectusToken(directusUrl) {
31
- const directusToken = await core_1.ux.prompt('What is your Directus Admin Token?');
29
+ export async function getDirectusToken(directusUrl) {
30
+ const directusToken = await text({
31
+ placeholder: 'admin-token-here',
32
+ message: 'What is your Directus Admin Token?',
33
+ });
32
34
  // Validate token by fetching the user
33
35
  try {
34
- await sdk_2.api.loginWithToken(directusToken);
35
- const response = await sdk_2.api.client.request((0, sdk_1.readMe)());
36
+ await api.loginWithToken(directusToken);
37
+ const response = await api.client.request(readMe());
36
38
  return directusToken;
37
39
  }
38
40
  catch (error) {
39
- (0, catch_error_1.default)(error, {
41
+ catchError(error, {
40
42
  context: {
41
43
  directusUrl,
42
44
  message: 'Invalid token. Please try again.',
@@ -46,40 +48,37 @@ async function getDirectusToken(directusUrl) {
46
48
  return getDirectusToken(directusUrl);
47
49
  }
48
50
  }
49
- exports.getDirectusToken = getDirectusToken;
50
51
  /**
51
52
  * Initialize the Directus API with the provided flags
52
53
  * @param flags - The validated ApplyFlags
53
54
  */
54
- async function initializeDirectusApi(flags) {
55
- sdk_2.api.initialize(flags.directusUrl);
55
+ export async function initializeDirectusApi(flags) {
56
+ api.initialize(flags.directusUrl);
56
57
  try {
57
58
  if (flags.directusToken) {
58
- await sdk_2.api.loginWithToken(flags.directusToken);
59
+ await api.loginWithToken(flags.directusToken);
59
60
  }
60
61
  else if (flags.userEmail && flags.userPassword) {
61
- await sdk_2.api.login(flags.userEmail, flags.userPassword);
62
+ await api.login(flags.userEmail, flags.userPassword);
62
63
  }
63
- const response = await sdk_2.api.client.request((0, sdk_1.readMe)());
64
- core_1.ux.log(`-- Logged in as ${response.first_name} ${response.last_name}`);
64
+ const response = await api.client.request(readMe());
65
+ ux.stdout(`-- Logged in as ${response.first_name} ${response.last_name}`);
65
66
  }
66
67
  catch {
67
- (0, catch_error_1.default)('-- Unable to authenticate with the provided credentials. Please check your credentials.', {
68
+ catchError('-- Unable to authenticate with the provided credentials. Please check your credentials.', {
68
69
  fatal: true,
69
70
  });
70
71
  }
71
72
  }
72
- exports.initializeDirectusApi = initializeDirectusApi;
73
73
  /**
74
74
  * Validate the authentication flags
75
75
  * @param flags - The AuthFlags
76
76
  */
77
- function validateAuthFlags(flags) {
77
+ export function validateAuthFlags(flags) {
78
78
  if (!flags.directusUrl) {
79
- core_1.ux.error('Directus URL is required.');
79
+ ux.error('Directus URL is required.');
80
80
  }
81
81
  if (!flags.directusToken && (!flags.userEmail || !flags.userPassword)) {
82
- core_1.ux.error('Either Directus token or email and password are required.');
82
+ ux.error('Either Directus token or email and password are required.');
83
83
  }
84
84
  }
85
- exports.validateAuthFlags = validateAuthFlags;