@docupace/pipeline 1.0.21 → 1.0.23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/auth0/cli.js CHANGED
@@ -18,10 +18,10 @@ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
18
18
  const program = new Command();
19
19
 
20
20
  program
21
- .command('configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain>')
21
+ .command('configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain> <configureMFA>')
22
22
  .description('Configure the Auth0 tenants in env for the given site')
23
- .action(async (fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain) => {
24
- await configureFromSite(fromSite, toSite, fromEnv, toEnv, deployUI, deployGraphQLServer, useNewDomain);
23
+ .action(async (fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA) => {
24
+ await configureFromSite(fromSite, toSite, fromEnv, toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA);
25
25
  });
26
26
 
27
27
  program
@@ -3,6 +3,7 @@ import path from 'path';
3
3
  import axios from 'axios';
4
4
  import crypto from 'crypto';
5
5
  import { deploy } from 'auth0-deploy-cli';
6
+ import fl from 'fs/promises';
6
7
 
7
8
  import {
8
9
  cloneEnvRepository,
@@ -21,6 +22,7 @@ import {
21
22
  environmentConfig
22
23
  } from '../next/config.js';
23
24
  import { connect } from 'http2';
25
+ import { promise } from 'zod';
24
26
 
25
27
  async function ensureDirectoryExists(dirPath) {
26
28
  try {
@@ -31,6 +33,27 @@ async function ensureDirectoryExists(dirPath) {
31
33
  }
32
34
  }
33
35
 
36
+ async function copyDirectory(source, destination) {
37
+ try {
38
+ await fl.mkdir(destination, { recursive: true });
39
+ const items = await fl.readdir(source, { withFileTypes: true });
40
+
41
+ for (const item of items) {
42
+ const sourcePath = path.join(source, item.name);
43
+ const destinationPath = path.join(destination, item.name);
44
+
45
+ if (item.isDirectory()) {
46
+ await copyDirectory(sourcePath, destinationPath);
47
+ } else {
48
+ await fl.copyFile(sourcePath, destinationPath);
49
+ }
50
+ }
51
+ } catch (err) {
52
+ console.error(`Error copying directory: ${err.message}`);
53
+ throw err;
54
+ }
55
+ }
56
+
34
57
  async function addApplicationToApi ({application, auth0Domain, auth0AuthToken, coreApiIdentifier}){
35
58
  console.log("Adding application to API authorized applications...");
36
59
 
@@ -154,7 +177,7 @@ async function replaceInFile(filePath, replacements) {
154
177
  await fs.promises.writeFile(filePath, content, 'utf8');
155
178
  }
156
179
 
157
- async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets) {
180
+ async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA) {
158
181
  try {
159
182
  let uiAllowedCallbacksUrls,
160
183
  uiAllowedLogoutUrls;
@@ -163,8 +186,8 @@ async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI,
163
186
  let connectAllowedCallbacksUrls,
164
187
  connectlAllowedLogoutUrls;
165
188
 
166
- let connectClientMetadata,
167
- connectCallbacks,
189
+ let connectClientMetadata,
190
+ connectCallbacks,
168
191
  connectAddons;
169
192
  // Configure URLs based on environment
170
193
  if (env === 'prd') {
@@ -212,7 +235,7 @@ async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI,
212
235
  connectCallbacks = [
213
236
  `${siteUrl}/connect/samlCallback?client_name=auth0`
214
237
  ];
215
-
238
+
216
239
  connectAddons = {
217
240
  "samlp": {
218
241
  "audience": `${siteUrl}/connect`,
@@ -242,7 +265,7 @@ async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI,
242
265
  allowed_logout_urls: uiAllowedLogoutUrls,
243
266
  });
244
267
 
245
-
268
+
246
269
  //TODO: move to separate function for connect
247
270
  console.log('connect_allowed_callbacks_urls ->', connectAllowedCallbacksUrls);
248
271
  console.log('connect_allowed_logout_urls ->', connectlAllowedLogoutUrls);
@@ -300,14 +323,20 @@ async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI,
300
323
  ['${docupaceContext}', coreApiContext],
301
324
  ]);
302
325
 
303
- // MFA configuration
304
- // if (process.env.AUTH0_MFA === 'ENABLE') {
305
- // console.log('AUTH0 MFA is enabled');
306
- // await execAsync('rsync -av ./auth0template/templateMFA/ ./auth0template/template/');
307
- // } else if (process.env.AUTH0_MFA === 'DISABLE') {
308
- // console.log('AUTH0 MFA is disabled');
309
- // await execAsync('rsync -av ./auth0template/templateNoMFA/ ./auth0template/template/');
310
- // }
326
+ console.log('MFA Template configuration started...');
327
+
328
+ try {
329
+ const sourceDir = configureMFA === 'DISABLED' ? 'auth0-site-setup/templateNoMFA/' : 'auth0-site-setup/templateMFA/';
330
+ const destinationDir = 'auth0-site-setup/template/';
331
+
332
+ console.log(`AUTH0 MFA is ${configureMFA === 'DISABLED' ? 'disabled' : 'enabled'}`);
333
+ await copyDirectory(sourceDir, destinationDir);
334
+
335
+ console.log('MFA configuration completed.');
336
+ } catch (err) {
337
+ console.error('Error configuring MFA:', err);
338
+ throw err;
339
+ }
311
340
 
312
341
  console.log('Template configuration completed.');
313
342
  } catch (err) {
@@ -576,7 +605,7 @@ ingress:
576
605
  }
577
606
 
578
607
 
579
- export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain) {
608
+ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA) {
580
609
  console.log(`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`);
581
610
  // Common Secrets
582
611
  const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
@@ -660,7 +689,7 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
660
689
  CONNECT_URL = `${oldUrl}_ui`;
661
690
  }
662
691
 
663
- await templateAuth0(SITE_HOST, CORE_API_CONTEXT, toEnv, filePaths, deployUI, deployGraphQLServer, commonSecrets);
692
+ await templateAuth0(SITE_HOST, CORE_API_CONTEXT, toEnv, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA);
664
693
  await importAuth0Templates('./auth0-site-setup/template', auth0Domain, auth0ClientId, auth0ClientSecret);
665
694
 
666
695
  if (deployUI === 'true') {