auth0-deploy-cli 7.4.0 → 7.5.2

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 (112) hide show
  1. package/.circleci/config.yml +15 -0
  2. package/.eslintrc +66 -17
  3. package/.github/CODEOWNERS +1 -0
  4. package/.husky/pre-commit +2 -0
  5. package/CHANGELOG.md +27 -2
  6. package/lib/args.js +94 -81
  7. package/lib/commands/export.js +54 -78
  8. package/lib/commands/import.js +46 -70
  9. package/lib/commands/index.js +11 -20
  10. package/lib/configFactory.js +19 -27
  11. package/lib/context/defaults.js +18 -41
  12. package/lib/context/directory/handlers/actions.js +77 -107
  13. package/lib/context/directory/handlers/attackProtection.js +59 -0
  14. package/lib/context/directory/handlers/clientGrants.js +45 -54
  15. package/lib/context/directory/handlers/clients.js +60 -79
  16. package/lib/context/directory/handlers/connections.js +65 -89
  17. package/lib/context/directory/handlers/databases.js +91 -123
  18. package/lib/context/directory/handlers/emailProvider.js +46 -57
  19. package/lib/context/directory/handlers/emailTemplates.js +67 -80
  20. package/lib/context/directory/handlers/guardianFactorProviders.js +41 -49
  21. package/lib/context/directory/handlers/guardianFactorTemplates.js +41 -49
  22. package/lib/context/directory/handlers/guardianFactors.js +41 -49
  23. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +40 -50
  24. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +40 -50
  25. package/lib/context/directory/handlers/guardianPolicies.js +40 -50
  26. package/lib/context/directory/handlers/hooks.js +55 -70
  27. package/lib/context/directory/handlers/index.js +53 -123
  28. package/lib/context/directory/handlers/migrations.js +36 -41
  29. package/lib/context/directory/handlers/organizations.js +54 -69
  30. package/lib/context/directory/handlers/pages.js +72 -86
  31. package/lib/context/directory/handlers/resourceServers.js +41 -49
  32. package/lib/context/directory/handlers/roles.js +49 -62
  33. package/lib/context/directory/handlers/rules.js +52 -68
  34. package/lib/context/directory/handlers/rulesConfigs.js +33 -32
  35. package/lib/context/directory/handlers/tenant.js +52 -47
  36. package/lib/context/directory/handlers/triggers.js +39 -54
  37. package/lib/context/directory/index.js +113 -101
  38. package/lib/context/index.js +96 -105
  39. package/lib/context/yaml/handlers/actions.js +71 -88
  40. package/lib/context/yaml/handlers/attackProtection.js +29 -0
  41. package/lib/context/yaml/handlers/clientGrants.js +36 -29
  42. package/lib/context/yaml/handlers/clients.js +61 -76
  43. package/lib/context/yaml/handlers/connections.js +76 -103
  44. package/lib/context/yaml/handlers/databases.js +64 -79
  45. package/lib/context/yaml/handlers/emailProvider.js +33 -30
  46. package/lib/context/yaml/handlers/emailTemplates.js +45 -54
  47. package/lib/context/yaml/handlers/guardianFactorProviders.js +27 -18
  48. package/lib/context/yaml/handlers/guardianFactorTemplates.js +27 -18
  49. package/lib/context/yaml/handlers/guardianFactors.js +27 -18
  50. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +27 -20
  51. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +27 -20
  52. package/lib/context/yaml/handlers/guardianPolicies.js +27 -20
  53. package/lib/context/yaml/handlers/hooks.js +57 -67
  54. package/lib/context/yaml/handlers/index.js +53 -123
  55. package/lib/context/yaml/handlers/migrations.js +23 -24
  56. package/lib/context/yaml/handlers/organizations.js +40 -38
  57. package/lib/context/yaml/handlers/pages.js +49 -58
  58. package/lib/context/yaml/handlers/resourceServers.js +27 -18
  59. package/lib/context/yaml/handlers/roles.js +34 -24
  60. package/lib/context/yaml/handlers/rules.js +48 -58
  61. package/lib/context/yaml/handlers/rulesConfigs.js +27 -18
  62. package/lib/context/yaml/handlers/tenant.js +44 -30
  63. package/lib/context/yaml/handlers/triggers.js +32 -23
  64. package/lib/context/yaml/index.js +127 -142
  65. package/lib/index.js +73 -79
  66. package/lib/logger.js +18 -22
  67. package/lib/readonly.js +74 -66
  68. package/lib/tools/ValidationError.js +8 -13
  69. package/lib/tools/auth0/client.js +143 -133
  70. package/lib/tools/auth0/handlers/actions.js +231 -243
  71. package/lib/tools/auth0/handlers/attackProtection.js +86 -0
  72. package/lib/tools/auth0/handlers/branding.js +47 -46
  73. package/lib/tools/auth0/handlers/clientGrants.js +118 -116
  74. package/lib/tools/auth0/handlers/clients.js +72 -90
  75. package/lib/tools/auth0/handlers/connections.js +150 -118
  76. package/lib/tools/auth0/handlers/databases.js +127 -124
  77. package/lib/tools/auth0/handlers/default.js +186 -189
  78. package/lib/tools/auth0/handlers/emailProvider.js +67 -78
  79. package/lib/tools/auth0/handlers/emailTemplates.js +116 -92
  80. package/lib/tools/auth0/handlers/guardianFactorProviders.js +66 -81
  81. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +60 -71
  82. package/lib/tools/auth0/handlers/guardianFactors.js +56 -63
  83. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +80 -79
  84. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +77 -76
  85. package/lib/tools/auth0/handlers/guardianPolicies.js +59 -62
  86. package/lib/tools/auth0/handlers/hooks.js +201 -227
  87. package/lib/tools/auth0/handlers/index.js +53 -111
  88. package/lib/tools/auth0/handlers/migrations.js +99 -79
  89. package/lib/tools/auth0/handlers/organizations.js +225 -247
  90. package/lib/tools/auth0/handlers/pages.js +116 -154
  91. package/lib/tools/auth0/handlers/prompts.js +47 -46
  92. package/lib/tools/auth0/handlers/resourceServers.js +88 -112
  93. package/lib/tools/auth0/handlers/roles.js +203 -220
  94. package/lib/tools/auth0/handlers/rules.js +168 -189
  95. package/lib/tools/auth0/handlers/rulesConfigs.js +54 -63
  96. package/lib/tools/auth0/handlers/tenant.js +88 -64
  97. package/lib/tools/auth0/handlers/triggers.js +126 -126
  98. package/lib/tools/auth0/index.js +92 -85
  99. package/lib/tools/auth0/schema.js +39 -31
  100. package/lib/tools/constants.js +111 -21
  101. package/lib/tools/deploy.js +35 -32
  102. package/lib/tools/index.js +19 -32
  103. package/lib/tools/logger.js +11 -12
  104. package/lib/tools/utils.js +255 -282
  105. package/lib/utils.js +167 -190
  106. package/package.json +10 -16
  107. package/tsconfig.json +17 -0
  108. package/typescript-migration-progress.sh +22 -0
  109. package/.babelrc +0 -17
  110. package/.nyc_output/597f412e-a239-4319-ad5b-ddb87fc39e67.json +0 -1
  111. package/.nyc_output/processinfo/597f412e-a239-4319-ad5b-ddb87fc39e67.json +0 -1
  112. package/.nyc_output/processinfo/index.json +0 -1
@@ -1,94 +1,70 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _fsExtra = require("fs-extra");
8
-
9
- var _fsExtra2 = _interopRequireDefault(_fsExtra);
10
-
11
- var _path = require("path");
12
-
13
- var _path2 = _interopRequireDefault(_path);
14
-
15
- var _tools = require("../../../tools");
16
-
17
- var _logger = require("../../../logger");
18
-
19
- var _logger2 = _interopRequireDefault(_logger);
20
-
21
- var _utils = require("../../../utils");
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const fs_extra_1 = __importDefault(require("fs-extra"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const tools_1 = require("../../../tools");
18
+ const logger_1 = __importDefault(require("../../../logger"));
19
+ const utils_1 = require("../../../utils");
25
20
  function parse(context) {
26
- const connectionDirectory = context.config.AUTH0_CONNECTIONS_DIRECTORY || _tools.constants.CONNECTIONS_DIRECTORY;
27
-
28
- const connectionsFolder = _path2.default.join(context.filePath, connectionDirectory);
29
-
30
- if (!(0, _utils.existsMustBeDir)(connectionsFolder)) return {
31
- connections: undefined
32
- };
33
- const foundFiles = (0, _utils.getFiles)(connectionsFolder, ['.json']);
34
- const connections = foundFiles.map(f => {
35
- const connection = (0, _utils.loadJSON)(f, context.mappings);
36
-
37
- if (connection.strategy === 'email') {
38
- (0, _utils.ensureProp)(connection, 'options.email.body');
39
-
40
- const htmlFileName = _path2.default.join(connectionsFolder, connection.options.email.body);
41
-
42
- if ((0, _utils.isFile)(htmlFileName)) {
43
- connection.options.email.body = (0, _tools.loadFileAndReplaceKeywords)(htmlFileName, context.mappings);
44
- }
45
- }
46
-
47
- return connection;
48
- }).filter(p => Object.keys(p).length > 0);
49
- return {
50
- connections
51
- };
52
- }
53
-
54
- async function dump(context) {
55
- const {
56
- connections
57
- } = context.assets;
58
- if (!connections) return;
59
-
60
- const connectionsFolder = _path2.default.join(context.filePath, _tools.constants.CONNECTIONS_DIRECTORY);
61
-
62
- _fsExtra2.default.ensureDirSync(connectionsFolder);
63
-
64
- connections.forEach(connection => {
65
- const dumpedConnection = { ...connection,
66
- ...(connection.enabled_clients && {
67
- enabled_clients: (0, _utils.mapClientID2NameSorted)(connection.enabled_clients, context.assets.clientsOrig)
68
- })
21
+ const connectionDirectory = context.config.AUTH0_CONNECTIONS_DIRECTORY || tools_1.constants.CONNECTIONS_DIRECTORY;
22
+ const connectionsFolder = path_1.default.join(context.filePath, connectionDirectory);
23
+ if (!(0, utils_1.existsMustBeDir)(connectionsFolder))
24
+ return { connections: undefined }; // Skip
25
+ const foundFiles = (0, utils_1.getFiles)(connectionsFolder, ['.json']);
26
+ const connections = foundFiles
27
+ .map((f) => {
28
+ const connection = (0, utils_1.loadJSON)(f, context.mappings);
29
+ if (connection.strategy === 'email') {
30
+ (0, utils_1.ensureProp)(connection, 'options.email.body');
31
+ const htmlFileName = path_1.default.join(connectionsFolder, connection.options.email.body);
32
+ if ((0, utils_1.isFile)(htmlFileName)) {
33
+ connection.options.email.body = (0, tools_1.loadFileAndReplaceKeywords)(htmlFileName, context.mappings);
34
+ }
35
+ }
36
+ return connection;
37
+ })
38
+ .filter((p) => Object.keys(p).length > 0); // Filter out empty connections
39
+ return {
40
+ connections
69
41
  };
70
- const connectionName = (0, _utils.sanitize)(dumpedConnection.name);
71
-
72
- if (dumpedConnection.strategy === 'email') {
73
- (0, _utils.ensureProp)(dumpedConnection, 'options.email.body');
74
- const html = dumpedConnection.options.email.body;
75
-
76
- const emailConnectionHtml = _path2.default.join(connectionsFolder, `${connectionName}.html`);
77
-
78
- _logger2.default.info(`Writing ${emailConnectionHtml}`);
79
-
80
- _fsExtra2.default.writeFileSync(emailConnectionHtml, html);
81
-
82
- dumpedConnection.options.email.body = `./${connectionName}.html`;
83
- }
84
-
85
- const connectionFile = _path2.default.join(connectionsFolder, `${connectionName}.json`);
86
-
87
- (0, _utils.dumpJSON)(connectionFile, dumpedConnection);
88
- });
89
42
  }
90
-
43
+ function dump(context) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const { connections } = context.assets;
46
+ if (!connections)
47
+ return; // Skip, nothing to dump
48
+ const connectionsFolder = path_1.default.join(context.filePath, tools_1.constants.CONNECTIONS_DIRECTORY);
49
+ fs_extra_1.default.ensureDirSync(connectionsFolder);
50
+ // Convert enabled_clients from id to name
51
+ connections.forEach((connection) => {
52
+ const dumpedConnection = Object.assign(Object.assign({}, connection), (connection.enabled_clients && { enabled_clients: (0, utils_1.mapClientID2NameSorted)(connection.enabled_clients, context.assets.clientsOrig) }));
53
+ const connectionName = (0, utils_1.sanitize)(dumpedConnection.name);
54
+ if (dumpedConnection.strategy === 'email') {
55
+ (0, utils_1.ensureProp)(dumpedConnection, 'options.email.body');
56
+ const html = dumpedConnection.options.email.body;
57
+ const emailConnectionHtml = path_1.default.join(connectionsFolder, `${connectionName}.html`);
58
+ logger_1.default.info(`Writing ${emailConnectionHtml}`);
59
+ fs_extra_1.default.writeFileSync(emailConnectionHtml, html);
60
+ dumpedConnection.options.email.body = `./${connectionName}.html`;
61
+ }
62
+ const connectionFile = path_1.default.join(connectionsFolder, `${connectionName}.json`);
63
+ (0, utils_1.dumpJSON)(connectionFile, dumpedConnection);
64
+ });
65
+ });
66
+ }
91
67
  exports.default = {
92
- parse,
93
- dump
94
- };
68
+ parse,
69
+ dump
70
+ };
@@ -1,131 +1,99 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _path = require("path");
8
-
9
- var _path2 = _interopRequireDefault(_path);
10
-
11
- var _fsExtra = require("fs-extra");
12
-
13
- var _fsExtra2 = _interopRequireDefault(_fsExtra);
14
-
15
- var _tools = require("../../../tools");
16
-
17
- var _logger = require("../../../logger");
18
-
19
- var _logger2 = _interopRequireDefault(_logger);
20
-
21
- var _utils = require("../../../utils");
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const path_1 = __importDefault(require("path"));
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const tools_1 = require("../../../tools");
18
+ const logger_1 = __importDefault(require("../../../logger"));
19
+ const utils_1 = require("../../../utils");
25
20
  function getDatabase(folder, mappings) {
26
- const metaFile = _path2.default.join(folder, 'database.json');
27
-
28
- let metaData = {};
29
-
30
- try {
31
- metaData = (0, _utils.loadJSON)(metaFile, mappings);
32
- } catch (err) {
33
- _logger2.default.warn(`Skipping database folder ${folder} as cannot find or read ${metaFile}`);
34
-
35
- return {};
36
- }
37
-
38
- if (!metaData) {
39
- _logger2.default.warn(`Skipping database folder ${folder} as ${metaFile} is empty`);
40
-
41
- return {};
42
- }
43
-
44
- const database = { ...metaData,
45
- options: { ...metaData.options,
46
- ...(metaData.customScripts && {
47
- customScripts: metaData.customScripts
48
- })
21
+ const metaFile = path_1.default.join(folder, 'database.json');
22
+ let metaData = {};
23
+ // First load database.json
24
+ try {
25
+ metaData = (0, utils_1.loadJSON)(metaFile, mappings);
49
26
  }
50
- };
51
-
52
- if (database.options.customScripts) {
53
- Object.entries(database.options.customScripts).forEach(([name, script]) => {
54
- if (!_tools.constants.DATABASE_SCRIPTS.includes(name)) {
55
- _logger2.default.warn('Skipping invalid database configuration: ' + name);
56
- } else {
57
- database.options.customScripts[name] = (0, _tools.loadFileAndReplaceKeywords)(_path2.default.join(folder, script), mappings);
58
- }
59
- });
60
- }
61
-
62
- return database;
27
+ catch (err) {
28
+ logger_1.default.warn(`Skipping database folder ${folder} as cannot find or read ${metaFile}`);
29
+ return {};
30
+ }
31
+ if (!metaData) {
32
+ logger_1.default.warn(`Skipping database folder ${folder} as ${metaFile} is empty`);
33
+ return {};
34
+ }
35
+ const database = Object.assign(Object.assign({}, metaData), { options: Object.assign(Object.assign({}, metaData.options), (metaData.customScripts && {
36
+ customScripts: metaData.customScripts
37
+ })) });
38
+ // If any customScripts configured then load content of files
39
+ if (database.options.customScripts) {
40
+ Object.entries(database.options.customScripts).forEach(([name, script]) => {
41
+ if (!tools_1.constants.DATABASE_SCRIPTS.includes(name)) {
42
+ // skip invalid keys in customScripts object
43
+ logger_1.default.warn('Skipping invalid database configuration: ' + name);
44
+ }
45
+ else {
46
+ database.options.customScripts[name] = (0, tools_1.loadFileAndReplaceKeywords)(path_1.default.join(folder, script), mappings);
47
+ }
48
+ });
49
+ }
50
+ return database;
63
51
  }
64
-
65
52
  function parse(context) {
66
- const databaseFolder = _path2.default.join(context.filePath, _tools.constants.DATABASE_CONNECTIONS_DIRECTORY);
67
-
68
- if (!(0, _utils.existsMustBeDir)(databaseFolder)) return {
69
- databases: undefined
70
- };
71
-
72
- const folders = _fsExtra2.default.readdirSync(databaseFolder).map(f => _path2.default.join(databaseFolder, f)).filter(f => (0, _utils.isDirectory)(f));
73
-
74
- const databases = folders.map(f => getDatabase(f, context.mappings)).filter(p => Object.keys(p).length > 1);
75
- return {
76
- databases
77
- };
78
- }
79
-
80
- async function dump(context) {
81
- const {
82
- databases
83
- } = context.assets;
84
- if (!databases) return;
85
-
86
- const databasesFolder = _path2.default.join(context.filePath, _tools.constants.DATABASE_CONNECTIONS_DIRECTORY);
87
-
88
- _fsExtra2.default.ensureDirSync(databasesFolder);
89
-
90
- databases.forEach(database => {
91
- const dbFolder = _path2.default.join(databasesFolder, (0, _utils.sanitize)(database.name));
92
-
93
- _fsExtra2.default.ensureDirSync(dbFolder);
94
-
95
- const sortCustomScripts = ([name1], [name2]) => {
96
- if (name1 === name2) return 0;
97
- return name1 > name2 ? 1 : -1;
98
- };
99
-
100
- const formatted = { ...database,
101
- ...(database.enabled_clients && {
102
- enabled_clients: (0, _utils.mapClientID2NameSorted)(database.enabled_clients, context.assets.clientsOrig)
103
- }),
104
- options: { ...database.options,
105
- ...(database.options.customScripts && {
106
- customScripts: Object.entries(database.options.customScripts).sort(sortCustomScripts).reduce((scripts, [name, script]) => {
107
- const scriptName = (0, _utils.sanitize)(`${name}.js`);
108
-
109
- const scriptFile = _path2.default.join(dbFolder, scriptName);
110
-
111
- _logger2.default.info(`Writing ${scriptFile}`);
112
-
113
- _fsExtra2.default.writeFileSync(scriptFile, script);
114
-
115
- scripts[name] = `./${scriptName}`;
116
- return scripts;
117
- }, {})
118
- })
119
- }
53
+ const databaseFolder = path_1.default.join(context.filePath, tools_1.constants.DATABASE_CONNECTIONS_DIRECTORY);
54
+ if (!(0, utils_1.existsMustBeDir)(databaseFolder))
55
+ return { databases: undefined }; // Skip
56
+ const folders = fs_extra_1.default.readdirSync(databaseFolder)
57
+ .map((f) => path_1.default.join(databaseFolder, f))
58
+ .filter((f) => (0, utils_1.isDirectory)(f));
59
+ const databases = folders.map((f) => getDatabase(f, context.mappings))
60
+ .filter((p) => Object.keys(p).length > 1);
61
+ return {
62
+ databases
120
63
  };
121
-
122
- const databaseFile = _path2.default.join(dbFolder, 'database.json');
123
-
124
- (0, _utils.dumpJSON)(databaseFile, formatted);
125
- });
126
64
  }
127
-
65
+ function dump(context) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const { databases } = context.assets;
68
+ if (!databases)
69
+ return; // Skip, nothing to dump
70
+ const databasesFolder = path_1.default.join(context.filePath, tools_1.constants.DATABASE_CONNECTIONS_DIRECTORY);
71
+ fs_extra_1.default.ensureDirSync(databasesFolder);
72
+ databases.forEach((database) => {
73
+ const dbFolder = path_1.default.join(databasesFolder, (0, utils_1.sanitize)(database.name));
74
+ fs_extra_1.default.ensureDirSync(dbFolder);
75
+ const sortCustomScripts = ([name1], [name2]) => {
76
+ if (name1 === name2)
77
+ return 0;
78
+ return name1 > name2 ? 1 : -1;
79
+ };
80
+ const formatted = Object.assign(Object.assign(Object.assign({}, database), (database.enabled_clients && { enabled_clients: (0, utils_1.mapClientID2NameSorted)(database.enabled_clients, context.assets.clientsOrig) })), { options: Object.assign(Object.assign({}, database.options), (database.options.customScripts && {
81
+ customScripts: Object.entries(database.options.customScripts).sort(sortCustomScripts).reduce((scripts, [name, script]) => {
82
+ // Dump custom script to file
83
+ const scriptName = (0, utils_1.sanitize)(`${name}.js`);
84
+ const scriptFile = path_1.default.join(dbFolder, scriptName);
85
+ logger_1.default.info(`Writing ${scriptFile}`);
86
+ fs_extra_1.default.writeFileSync(scriptFile, script);
87
+ scripts[name] = `./${scriptName}`;
88
+ return scripts;
89
+ }, {})
90
+ })) });
91
+ const databaseFile = path_1.default.join(dbFolder, 'database.json');
92
+ (0, utils_1.dumpJSON)(databaseFile, formatted);
93
+ });
94
+ });
95
+ }
128
96
  exports.default = {
129
- parse,
130
- dump
131
- };
97
+ parse,
98
+ dump
99
+ };
@@ -1,62 +1,51 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _fsExtra = require("fs-extra");
8
-
9
- var _fsExtra2 = _interopRequireDefault(_fsExtra);
10
-
11
- var _path = require("path");
12
-
13
- var _path2 = _interopRequireDefault(_path);
14
-
15
- var _tools = require("../../../tools");
16
-
17
- var _utils = require("../../../utils");
18
-
19
- var _defaults = require("../../defaults");
20
-
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const fs_extra_1 = __importDefault(require("fs-extra"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const tools_1 = require("../../../tools");
18
+ const utils_1 = require("../../../utils");
19
+ const defaults_1 = require("../../defaults");
23
20
  function parse(context) {
24
- const emailsFolder = _path2.default.join(context.filePath, _tools.constants.EMAIL_TEMPLATES_DIRECTORY);
25
-
26
- if (!(0, _utils.existsMustBeDir)(emailsFolder)) return {};
27
-
28
- const providerFile = _path2.default.join(emailsFolder, 'provider.json');
29
-
30
- if ((0, _utils.isFile)(providerFile)) {
31
- return {
32
- emailProvider: (0, _utils.loadJSON)(providerFile, context.mappings)
33
- };
34
- }
35
-
36
- return {};
21
+ const emailsFolder = path_1.default.join(context.filePath, tools_1.constants.EMAIL_TEMPLATES_DIRECTORY);
22
+ if (!(0, utils_1.existsMustBeDir)(emailsFolder))
23
+ return {}; // Skip
24
+ const providerFile = path_1.default.join(emailsFolder, 'provider.json');
25
+ if ((0, utils_1.isFile)(providerFile)) {
26
+ return {
27
+ emailProvider: (0, utils_1.loadJSON)(providerFile, context.mappings)
28
+ };
29
+ }
30
+ return {};
37
31
  }
38
-
39
- async function dump(context) {
40
- let {
41
- emailProvider
42
- } = context.assets;
43
- if (!emailProvider) return;
44
- const excludedDefaults = context.assets.exclude.defaults || [];
45
-
46
- if (!excludedDefaults.includes('emailProvider')) {
47
- emailProvider = (0, _defaults.emailProviderDefaults)(emailProvider);
48
- }
49
-
50
- const emailsFolder = _path2.default.join(context.filePath, _tools.constants.EMAIL_TEMPLATES_DIRECTORY);
51
-
52
- _fsExtra2.default.ensureDirSync(emailsFolder);
53
-
54
- const emailProviderFile = _path2.default.join(emailsFolder, 'provider.json');
55
-
56
- (0, _utils.dumpJSON)(emailProviderFile, emailProvider);
32
+ function dump(context) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ let { emailProvider } = context.assets;
35
+ if (!emailProvider)
36
+ return; // Skip, nothing to dump
37
+ const excludedDefaults = context.assets.exclude.defaults || [];
38
+ if (!excludedDefaults.includes('emailProvider')) {
39
+ // Add placeholder for credentials as they cannot be exported
40
+ emailProvider = (0, defaults_1.emailProviderDefaults)(emailProvider);
41
+ }
42
+ const emailsFolder = path_1.default.join(context.filePath, tools_1.constants.EMAIL_TEMPLATES_DIRECTORY);
43
+ fs_extra_1.default.ensureDirSync(emailsFolder);
44
+ const emailProviderFile = path_1.default.join(emailsFolder, 'provider.json');
45
+ (0, utils_1.dumpJSON)(emailProviderFile, emailProvider);
46
+ });
57
47
  }
58
-
59
48
  exports.default = {
60
- parse,
61
- dump
62
- };
49
+ parse,
50
+ dump
51
+ };
@@ -1,86 +1,73 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _fsExtra = require("fs-extra");
8
-
9
- var _fsExtra2 = _interopRequireDefault(_fsExtra);
10
-
11
- var _path = require("path");
12
-
13
- var _path2 = _interopRequireDefault(_path);
14
-
15
- var _tools = require("../../../tools");
16
-
17
- var _logger = require("../../../logger");
18
-
19
- var _logger2 = _interopRequireDefault(_logger);
20
-
21
- var _utils = require("../../../utils");
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const fs_extra_1 = __importDefault(require("fs-extra"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const tools_1 = require("../../../tools");
18
+ const logger_1 = __importDefault(require("../../../logger"));
19
+ const utils_1 = require("../../../utils");
25
20
  function parse(context) {
26
- const emailsFolder = _path2.default.join(context.filePath, _tools.constants.EMAIL_TEMPLATES_DIRECTORY);
27
-
28
- if (!(0, _utils.existsMustBeDir)(emailsFolder)) return {
29
- emailTemplates: undefined
30
- };
31
- const files = (0, _utils.getFiles)(emailsFolder, ['.json', '.html']).filter(f => _path2.default.basename(f) !== 'provider.json');
32
- const sorted = {};
33
- files.forEach(file => {
34
- const {
35
- ext,
36
- name
37
- } = _path2.default.parse(file);
38
-
39
- if (!sorted[name]) sorted[name] = {};
40
- if (ext === '.json') sorted[name].meta = file;
41
- if (ext === '.html') sorted[name].html = file;
42
- });
43
- const emailTemplates = [];
44
- Object.values(sorted).forEach(data => {
45
- if (!data.meta) {
46
- _logger2.default.warn(`Skipping email template file ${data.html} as missing the corresponding '.json' file`);
47
- } else if (!data.html) {
48
- _logger2.default.warn(`Skipping email template file ${data.meta} as missing corresponding '.html' file`);
49
- } else {
50
- emailTemplates.push({ ...(0, _utils.loadJSON)(data.meta, context.mappings),
51
- body: (0, _tools.loadFileAndReplaceKeywords)(data.html, context.mappings)
52
- });
53
- }
54
- });
55
- return {
56
- emailTemplates
57
- };
21
+ const emailsFolder = path_1.default.join(context.filePath, tools_1.constants.EMAIL_TEMPLATES_DIRECTORY);
22
+ if (!(0, utils_1.existsMustBeDir)(emailsFolder))
23
+ return { emailTemplates: undefined }; // Skip
24
+ const files = (0, utils_1.getFiles)(emailsFolder, ['.json', '.html']).filter((f) => path_1.default.basename(f) !== 'provider.json');
25
+ const sorted = {};
26
+ files.forEach((file) => {
27
+ const { ext, name } = path_1.default.parse(file);
28
+ if (!sorted[name])
29
+ sorted[name] = {};
30
+ if (ext === '.json')
31
+ sorted[name].meta = file;
32
+ if (ext === '.html')
33
+ sorted[name].html = file;
34
+ });
35
+ const emailTemplates = [];
36
+ Object.values(sorted).forEach((data) => {
37
+ if (!data.meta) {
38
+ logger_1.default.warn(`Skipping email template file ${data.html} as missing the corresponding '.json' file`);
39
+ }
40
+ else if (!data.html) {
41
+ logger_1.default.warn(`Skipping email template file ${data.meta} as missing corresponding '.html' file`);
42
+ }
43
+ else {
44
+ emailTemplates.push(Object.assign(Object.assign({}, (0, utils_1.loadJSON)(data.meta, context.mappings)), { body: (0, tools_1.loadFileAndReplaceKeywords)(data.html, context.mappings) }));
45
+ }
46
+ });
47
+ return {
48
+ emailTemplates
49
+ };
58
50
  }
59
-
60
- async function dump(context) {
61
- const emailTemplates = [...(context.assets.emailTemplates || [])];
62
- if (!emailTemplates) return;
63
-
64
- const templatesFolder = _path2.default.join(context.filePath, _tools.constants.EMAIL_TEMPLATES_DIRECTORY);
65
-
66
- _fsExtra2.default.ensureDirSync(templatesFolder);
67
-
68
- emailTemplates.forEach(template => {
69
- const templateHtml = _path2.default.join(templatesFolder, `${template.template}.html`);
70
-
71
- _logger2.default.info(`Writing ${templateHtml}`);
72
-
73
- _fsExtra2.default.writeFileSync(templateHtml, template.body);
74
-
75
- const templateFile = _path2.default.join(templatesFolder, `${template.template}.json`);
76
-
77
- (0, _utils.dumpJSON)(templateFile, { ...template,
78
- body: `./${template.template}.html`
51
+ function dump(context) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const emailTemplates = [...context.assets.emailTemplates || []];
54
+ if (!emailTemplates)
55
+ return; // Skip, nothing to dump
56
+ // Create Templates folder
57
+ const templatesFolder = path_1.default.join(context.filePath, tools_1.constants.EMAIL_TEMPLATES_DIRECTORY);
58
+ fs_extra_1.default.ensureDirSync(templatesFolder);
59
+ emailTemplates.forEach((template) => {
60
+ // Dump template html to file
61
+ const templateHtml = path_1.default.join(templatesFolder, `${template.template}.html`);
62
+ logger_1.default.info(`Writing ${templateHtml}`);
63
+ fs_extra_1.default.writeFileSync(templateHtml, template.body);
64
+ // Dump template metadata
65
+ const templateFile = path_1.default.join(templatesFolder, `${template.template}.json`);
66
+ (0, utils_1.dumpJSON)(templateFile, Object.assign(Object.assign({}, template), { body: `./${template.template}.html` }));
67
+ });
79
68
  });
80
- });
81
69
  }
82
-
83
70
  exports.default = {
84
- parse,
85
- dump
86
- };
71
+ parse,
72
+ dump
73
+ };