@docupace/pipeline 1.0.24 → 1.0.26-alpha-1

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.
@@ -2,27 +2,15 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import axios from 'axios';
4
4
  import crypto from 'crypto';
5
- import { deploy } from 'auth0-deploy-cli';
6
- import fl from 'fs/promises';
7
5
 
8
6
  import {
9
7
  cloneEnvRepository,
10
- cloneRepository,
11
8
  readDeployConfig,
12
- pushDeployConfig
9
+ pushDeployConfig,
13
10
  } from '../next/deploy.js';
14
11
 
15
- import {
16
- getVaultSecrets,
17
- updateVaultSecrets
18
- } from './vault.js';
19
-
20
- import {
21
- getVaultSecretsConfigs,
22
- environmentConfig
23
- } from '../next/config.js';
24
- import { connect } from 'http2';
25
- import { promise } from 'zod';
12
+ import { getVaultSecrets, updateVaultSecrets } from './vault.js';
13
+ import { getVaultSecretsConfigs, environmentConfig } from '../next/config.js';
26
14
 
27
15
  async function ensureDirectoryExists(dirPath) {
28
16
  try {
@@ -33,359 +21,77 @@ async function ensureDirectoryExists(dirPath) {
33
21
  }
34
22
  }
35
23
 
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
-
57
- async function addApplicationToApi ({application, auth0Domain, auth0AuthToken, coreApiIdentifier}){
58
- console.log("Adding application to API authorized applications...");
59
-
24
+ export async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
60
25
  try {
61
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
62
- headers: {authorization: `Bearer ${auth0AuthToken}`},
63
- });
64
-
65
- const appAuth0ClientIdData = auth0Response.data.find(client => client.name === `${application}`);
66
- const appAuth0ClientId = appAuth0ClientIdData.client_id;
67
-
68
- await axios.post(
69
- `https://${auth0Domain}/api/v2/client-grants`,
26
+ const response = await axios.post(
27
+ `https://${auth0Domain}/oauth/token`,
70
28
  {
71
- client_id: appAuth0ClientId,
72
- audience: `${coreApiIdentifier}`,
73
- scope: [],
29
+ client_id: clientId,
30
+ client_secret: clientSecret,
31
+ audience: `https://${auth0Domain}/api/v2/`,
32
+ grant_type: 'client_credentials',
74
33
  },
75
34
  {
76
35
  headers: {
77
- Authorization: `Bearer ${auth0AuthToken}`,
78
- "Content-Type": "application/json",
79
- },
80
- }
81
- );
82
- console.log(`Application (${appAuth0ClientId}) authorized for API: ${coreApiIdentifier}`);
83
- } catch (err) {
84
- console.error(`Failed to add application: ${application}: ${err.message}`);
85
- }
86
-
87
- }
88
-
89
- async function initializeAuth0Configuration({
90
- initConfiguration,
91
- auth0Domain,
92
- auth0AuthToken,
93
- coreApiIdentifier,
94
- }) {
95
- if (initConfiguration === "true") {
96
- try {
97
- // Create a new resource server in Auth0
98
- console.log("Creating resource server in Auth0...");
99
-
100
- const resourceServerResponse = await axios.post(
101
- `https://${auth0Domain}/api/v2/resource-servers`,
102
- {
103
- name: "docupace-core",
104
- identifier: `${coreApiIdentifier}`,
105
- token_lifetime: 86400,
106
- allow_offline_access: false,
107
- signing_alg: "RS256",
108
- skip_consent_for_verifiable_first_party_clients: true,
109
- scopes: [],
110
- },
111
- {
112
- headers: {
113
- Authorization: `Bearer ${auth0AuthToken}`,
114
- "Content-Type": "application/json",
115
- },
116
- }
117
- );
118
-
119
- const apiId = resourceServerResponse.data.id;
120
-
121
- // Update tenant settings with the default audience
122
- console.log("Updating tenant settings...");
123
- await axios.patch(
124
- `https://${auth0Domain}/api/v2/tenants/settings`,
125
- {
126
- default_audience: `${coreApiIdentifier}`,
36
+ 'Content-Type': 'application/json',
127
37
  },
128
- {
129
- headers: {
130
- Authorization: `Bearer ${auth0AuthToken}`,
131
- "Content-Type": "application/json",
132
- },
133
- }
134
- );
135
- console.log("Tenant settings updated successfully.");
136
- } catch (error) {
137
- console.error("Error during Auth0 configuration:", error.response?.data || error.message);
138
- }
139
- }
140
- }
141
-
142
- async function importAuth0Templates(directoryPath, auth0Domain, auth0ClientID, auth0ClientSecret) {
143
- try {
144
- const config = {
145
- input_file: directoryPath,
146
- config: {
147
- AUTH0_DOMAIN: auth0Domain,
148
- AUTH0_CLIENT_ID: auth0ClientID,
149
- AUTH0_CLIENT_SECRET: auth0ClientSecret,
150
38
  },
151
- debug: true,
152
- };
153
-
154
- console.log('Starting Auth0 template import...');
155
- await deploy(config);
156
- console.log('Auth0 template import completed successfully!');
157
- } catch (error) {
158
- console.error('Error during Auth0 template import:', error.message);
159
- process.exit(1); // Exit with an error code
160
- }
161
- }
162
-
163
- async function updateJsonFile(filePath, updates) {
164
- const content = await fs.promises.readFile(filePath, 'utf8');
165
- const jsonContent = JSON.parse(content);
166
- const updatedContent = JSON.stringify({...jsonContent, ...updates}, null, 2);
167
- await fs.promises.writeFile(filePath, updatedContent);
168
- }
169
-
170
- async function replaceInFile(filePath, replacements) {
171
- let content = await fs.promises.readFile(filePath, 'utf8');
172
-
173
- for (const [search, replace] of replacements) {
174
- const escapedSearch = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); // Escape special chars
175
- content = content.replace(new RegExp(escapedSearch, 'g'), replace);
176
- }
177
- await fs.promises.writeFile(filePath, content, 'utf8');
178
- }
179
-
180
- async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA) {
181
- try {
182
- let uiAllowedCallbacksUrls,
183
- uiAllowedLogoutUrls;
184
- let graphqlAllowedCallbacksUrls,
185
- graphqlAllowedLogoutUrls;
186
- let connectAllowedCallbacksUrls,
187
- connectlAllowedLogoutUrls;
188
-
189
- let connectClientMetadata,
190
- connectCallbacks,
191
- connectAddons;
192
- // Configure URLs based on environment
193
- if (env === 'prd') {
194
- uiAllowedCallbacksUrls = [`${siteUrl}/api/auth/callback`];
195
- uiAllowedLogoutUrls = [`${siteUrl}`];
196
-
197
- graphqlAllowedCallbacksUrls = [`${siteUrl}/api/graphql/callback`];
198
- graphqlAllowedLogoutUrls = [`${siteUrl}/api/graphql/`];
199
-
200
- connectAllowedCallbacksUrls = [`${siteUrl}/connect/samlCallback?client_name=auth0`];
201
- connectlAllowedLogoutUrls = [ `${siteUrl}/connect`];
202
- } else {
203
- uiAllowedCallbacksUrls = [
204
- `${siteUrl}/api/auth/callback`,
205
- `http://localhost:3000/api/auth/callback`,
206
- ];
207
- uiAllowedLogoutUrls = [
208
- `${siteUrl}`,
209
- `http://localhost:3000`,
210
- ];
211
- graphqlAllowedCallbacksUrls = [
212
- `${siteUrl}/api/graphql/callback`,
213
- `http://localhost:4000/api/graphql/callback`,
214
- ];
215
- graphqlAllowedLogoutUrls = [
216
- `http://localhost:4000/api/graphql/`,
217
- `${siteUrl}/api/graphql/`,
218
- ];
219
- connectAllowedCallbacksUrls = [
220
- `${siteUrl}/connect/samlCallback?client_name=auth0`,
221
- `http://localhost:9000/connect/samlCallback?client_name=auth0`,
222
- ];
223
- connectlAllowedLogoutUrls = [
224
- `${siteUrl}/connect`
225
- ];
226
-
227
- const siteUrlNoPrefix=siteUrl.replace(/^https?:\/\//, '');
228
- connectClientMetadata ={
229
- "docupaceContext" : "core",
230
- "docupaceHost" : `${siteUrlNoPrefix}`,
231
- "docupace_context" : "core",
232
- "docupace_host" : `${siteUrlNoPrefix} `
233
- };
234
-
235
- connectCallbacks = [
236
- `${siteUrl}/connect/samlCallback?client_name=auth0`
237
- ];
238
-
239
- connectAddons = {
240
- "samlp": {
241
- "audience": `${siteUrl}/connect`,
242
- "recipient": `${siteUrl}/connect/samlCallback?client_name=auth0`,
243
- "destination": `${siteUrl}/connect/samlCallback?client_name=auth0`,
244
- "nameIdentifierFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
245
- "binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
246
- "nameIdentifierProbes": [
247
- "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/docupace-username"
248
- ],
249
- "mappings": {
250
- "proposalHandle": "ProposalHandle"
251
- }
252
- }
253
- };
254
-
255
- }
256
-
257
-
258
- const configureUI = deployUI === 'true';
259
- if (configureUI) {
260
- console.log('ui_allowed_callbacks_urls ->', uiAllowedCallbacksUrls);
261
- console.log('ui_allowed_logout_urls ->', uiAllowedLogoutUrls);
262
-
263
- await updateJsonFile(filePaths.uiJson, {
264
- callbacks: uiAllowedCallbacksUrls,
265
- allowed_logout_urls: uiAllowedLogoutUrls,
266
- });
267
-
268
-
269
- //TODO: move to separate function for connect
270
- console.log('connect_allowed_callbacks_urls ->', connectAllowedCallbacksUrls);
271
- console.log('connect_allowed_logout_urls ->', connectlAllowedLogoutUrls);
272
-
273
- // update allowed callback url
274
- await updateJsonFile(filePaths.connectJson, {
275
- callbacks: connectAllowedCallbacksUrls,
276
- allowed_logout_urls: connectlAllowedLogoutUrls,
277
- client_metadata: connectClientMetadata,
278
- addons: connectAddons
279
- });
280
-
281
-
282
-
283
- console.log('Updated URLs for main UI...');
284
- } else {
285
- await fs.promises.unlink(filePaths.uiJson);
286
- await updateJsonFile(filePaths.databaseJson, {
287
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-ui-main'),
288
- });
289
- console.log("Removed 'docupace-ui-main' from enabled_clients in database.json");
290
- }
291
-
292
- const configureGraphqlServer = deployGraphQLServer === 'true';
293
- if (configureGraphqlServer) {
294
- console.log('graphql_allowed_callbacks_urls ->', graphqlAllowedCallbacksUrls);
295
- console.log('graphql_allowed_logout_urls ->', graphqlAllowedLogoutUrls);
296
-
297
- await updateJsonFile(filePaths.graphqlJson, {
298
- callbacks: graphqlAllowedCallbacksUrls,
299
- allowed_logout_urls: graphqlAllowedLogoutUrls,
300
- });
301
- console.log('Updated URLs for GraphQL server...');
302
- } else {
303
- await fs.promises.unlink(filePaths.graphqlJson);
304
- await updateJsonFile(filePaths.databaseJson, {
305
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-graphql'),
306
- });
307
- console.log("Removed 'docupace-graphql' from enabled_clients in database.json");
308
- }
309
-
310
- // TWILIO configuration
311
- await replaceInFile(filePaths.twilioJson, [
312
- ['twilioauthtokenplaceholder', commonSecrets.TWILIO_AUTH_TOKEN],
313
- ['twiliosidplaceholder', commonSecrets.TWILIO_SID],
314
- ['twiliofromplaceholder', commonSecrets.TWILIO_FROM_NUMBER],
315
- ]);
316
-
317
- console.log('TWILIO configuration updated...');
318
-
319
- const tmpSiteUrl = siteUrl.replace(/^https?:\/\//, '');
320
- // Database configuration
321
- await replaceInFile(filePaths.databaseLoginJs, [
322
- ['${docupaceHost}', tmpSiteUrl],
323
- ['${docupaceContext}', coreApiContext],
324
- ]);
325
-
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
- }
340
-
341
- console.log('Template configuration completed.');
342
- } catch (err) {
343
- // console.error('Error configuring Auth0 templates:', err);
344
- throw err;
345
- }
346
- }
347
-
348
- export async function getAuth0AuthToken(auth0Domain, clientId, clientSecret) {
349
- try {
350
- const response = await axios.post(`https://${auth0Domain}/oauth/token`, {
351
- client_id: clientId,
352
- client_secret: clientSecret,
353
- audience: `https://${auth0Domain}/api/v2/`,
354
- grant_type: 'client_credentials',
355
- }, {
356
- headers: {
357
- 'Content-Type': 'application/json',
358
- },
359
- });
39
+ );
360
40
 
361
41
  const authToken = response.data.access_token;
362
42
  // console.log("Auth0 Auth Token:", authToken);
363
43
  return authToken;
364
44
  } catch (error) {
365
- console.error("Error fetching Auth0 token:", error.response ? error.response.data : error.message);
45
+ console.error(
46
+ 'Error fetching Auth0 token:',
47
+ error.response ? error.response.data : error.message,
48
+ );
366
49
  }
367
50
  }
368
51
 
369
- async function configureUI(siteHost, coreURL, docupaceHost, site, env, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, repoPath) {
370
- console.log(`Configuring UI for site: ${site} Host: ${siteHost} in env: ${env}`);
52
+ async function configureUI(
53
+ siteHost,
54
+ coreURL,
55
+ docupaceHost,
56
+ site,
57
+ env,
58
+ useNewDomain,
59
+ auth0Domain,
60
+ auth0ClientId,
61
+ auth0ClientSecret,
62
+ auth0Token,
63
+ vaultSiteSecretsPath,
64
+ imageTag,
65
+ repoPath,
66
+ ) {
67
+ console.log(
68
+ `Configuring UI for site: ${site} Host: ${siteHost} in env: ${env}`,
69
+ );
371
70
  siteHost = siteHost.replace('https://', '');
372
71
  coreURL = coreURL.replace('https://', '');
373
72
 
374
-
375
73
  try {
376
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
377
- headers: {authorization: `Bearer ${auth0Token}`},
378
- });
74
+ const auth0Response = await axios.get(
75
+ `https://${auth0Domain}/api/v2/clients`,
76
+ {
77
+ headers: { authorization: `Bearer ${auth0Token}` },
78
+ },
79
+ );
379
80
 
380
- const uiClient = auth0Response.data.find(client => client.name === "docupace-ui-main");
81
+ const uiClient = auth0Response.data.find(
82
+ (client) => client.name === 'docupace-ui-main',
83
+ );
381
84
  const uiAuth0ClientId = uiClient.client_id;
382
85
  const uiAuth0ClientSecret = uiClient.client_secret;
383
86
 
384
87
  // Generate Auth0 Secret
385
- const uiAuth0Secret = crypto.randomBytes(48).toString('base64').replace(/[^a-zA-Z0-9]/g, '');
88
+ const uiAuth0Secret = crypto
89
+ .randomBytes(48)
90
+ .toString('base64')
91
+ .replace(/[^a-zA-Z0-9]/g, '');
386
92
 
387
93
  // Prepare data payload
388
- console.log("Preparing Vault UI data payload...");
94
+ console.log('Preparing Vault UI data payload...');
389
95
  const uiSecretData = JSON.stringify({
390
96
  data: {
391
97
  AUTH0_CLIENT_ID: uiAuth0ClientId,
@@ -473,51 +179,85 @@ externalConnectService:
473
179
  `.trim();
474
180
 
475
181
  // Write configuration files
476
- console.log("Writing configuration files...");
182
+ console.log('Writing configuration files...');
477
183
  await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
478
184
 
479
- await fs.writeFile(`${repoPath}/dp/${site}/ui.app.yaml`, uiAppYaml, (err) => {
480
- if (err) {
481
- console.error("Failed to write the file:", err);
482
- } else {
483
- console.log("File written successfully.");
484
- }
485
- });
185
+ await fs.writeFile(
186
+ `${repoPath}/dp/${site}/ui.app.yaml`,
187
+ uiAppYaml,
188
+ (err) => {
189
+ if (err) {
190
+ console.error('Failed to write the file:', err);
191
+ } else {
192
+ console.log('File written successfully.');
193
+ }
194
+ },
195
+ );
486
196
 
487
- await fs.writeFile(`${repoPath}/dp/${site}/ui.values.yaml`, uiValuesYaml, (err) => {
488
- if (err) {
489
- console.error("Failed to write the file:", err);
490
- } else {
491
- console.log("File written successfully.");
492
- }
493
- });
494
- console.log("Done!");
197
+ await fs.writeFile(
198
+ `${repoPath}/dp/${site}/ui.values.yaml`,
199
+ uiValuesYaml,
200
+ (err) => {
201
+ if (err) {
202
+ console.error('Failed to write the file:', err);
203
+ } else {
204
+ console.log('File written successfully.');
205
+ }
206
+ },
207
+ );
208
+ console.log('Done!');
495
209
  } catch (error) {
496
- console.error("Error configuring UI:", error);
210
+ console.error('Error configuring UI:', error);
497
211
  }
498
212
  }
499
213
 
500
- async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, standardConfigRemoteBranch, repoPath, commonSecrets) {
214
+ async function configureGraphQLServer(
215
+ siteHost,
216
+ coreURL,
217
+ docupaceHost,
218
+ site,
219
+ env,
220
+ auth0Domain,
221
+ auth0ClientId,
222
+ auth0ClientSecret,
223
+ auth0Token,
224
+ vaultSiteSecretsPath,
225
+ imageTag,
226
+ standardConfigRemoteBranch,
227
+ repoPath,
228
+ commonSecrets,
229
+ ) {
501
230
  siteHost = siteHost.replace('https://', '');
502
231
  coreURL = coreURL.replace('https://', '');
503
- console.log(`Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`);
232
+ console.log(
233
+ `Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`,
234
+ );
504
235
 
505
236
  try {
506
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
507
- headers: {authorization: `Bearer ${auth0Token}`},
508
- });
237
+ const auth0Response = await axios.get(
238
+ `https://${auth0Domain}/api/v2/clients`,
239
+ {
240
+ headers: { authorization: `Bearer ${auth0Token}` },
241
+ },
242
+ );
509
243
 
510
- const graphQLServerClient = auth0Response.data.find(client => client.name === "docupace-graphql");
511
- const graphQLServerClientCredentials = auth0Response.data.find(client => client.name === "docupace-graphql-client-credentials");
244
+ const graphQLServerClient = auth0Response.data.find(
245
+ (client) => client.name === 'docupace-graphql',
246
+ );
247
+ const graphQLServerClientCredentials = auth0Response.data.find(
248
+ (client) => client.name === 'docupace-graphql-client-credentials',
249
+ );
512
250
 
513
251
  const graphQLServerAuth0ClientId = graphQLServerClient.client_id;
514
252
  const graphQLServerAuth0ClientSecret = graphQLServerClient.client_secret;
515
253
 
516
- const graphQLServerCCAuth0ClientId = graphQLServerClientCredentials.client_id;
517
- const graphQLServerCCAuth0ClientSecret = graphQLServerClientCredentials.client_secret;
254
+ const graphQLServerCCAuth0ClientId =
255
+ graphQLServerClientCredentials.client_id;
256
+ const graphQLServerCCAuth0ClientSecret =
257
+ graphQLServerClientCredentials.client_secret;
518
258
 
519
259
  // Prepare data payload
520
- console.log("Preparing Vault GraphQL Server data payload...");
260
+ console.log('Preparing Vault GraphQL Server data payload...');
521
261
  const graphQLServerSecretData = JSON.stringify({
522
262
  data: {
523
263
  AUTH0_CLIENT_ID: graphQLServerAuth0ClientId,
@@ -580,105 +320,128 @@ ingress:
580
320
  `.trim();
581
321
 
582
322
  // Write configuration files
583
- console.log("Writing ArgoCD GraphQL Server configuration files...");
323
+ console.log('Writing ArgoCD GraphQL Server configuration files...');
584
324
  await ensureDirectoryExists(path.resolve(`${repoPath}/dp/${site}`));
585
325
 
586
- await fs.writeFile(`${repoPath}/dp/${site}/graphql-server.app.yaml`, graphQLServerAppYaml, (err) => {
587
- if (err) {
588
- console.error("Failed to write the file:", err);
589
- } else {
590
- console.log("File written successfully.");
591
- }
592
- });
326
+ await fs.writeFile(
327
+ `${repoPath}/dp/${site}/graphql-server.app.yaml`,
328
+ graphQLServerAppYaml,
329
+ (err) => {
330
+ if (err) {
331
+ console.error('Failed to write the file:', err);
332
+ } else {
333
+ console.log('File written successfully.');
334
+ }
335
+ },
336
+ );
593
337
 
594
- await fs.writeFile(`${repoPath}/dp/${site}/graphql-server.values.yaml`, graphQLServerValuesYaml, (err) => {
595
- if (err) {
596
- console.error("Failed to write the file:", err);
597
- } else {
598
- console.log("File written successfully.");
599
- }
600
- });
601
- console.log("Done!");
338
+ await fs.writeFile(
339
+ `${repoPath}/dp/${site}/graphql-server.values.yaml`,
340
+ graphQLServerValuesYaml,
341
+ (err) => {
342
+ if (err) {
343
+ console.error('Failed to write the file:', err);
344
+ } else {
345
+ console.log('File written successfully.');
346
+ }
347
+ },
348
+ );
349
+ console.log('Done!');
602
350
  } catch (error) {
603
- console.error("Error configuring GraphQL Server:", error);
351
+ console.error('Error configuring GraphQL Server:', error);
604
352
  }
605
353
  }
606
354
 
607
-
608
- export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA) {
609
- console.log(`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`);
355
+ export async function configureFromSite(
356
+ fromSite,
357
+ toSite,
358
+ fromEnv,
359
+ toEnv,
360
+ deployUI,
361
+ deployGraphQLServer,
362
+ useNewDomain,
363
+ ) {
364
+ console.log(
365
+ `Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`,
366
+ );
610
367
  // Common Secrets
611
368
  const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
612
- console.log(`commonSecretsPath => ${commonSecretsPath}`)
369
+ console.log(`commonSecretsPath => ${commonSecretsPath}`);
613
370
  const commonSecrets = await getVaultSecrets(commonSecretsPath);
614
371
 
615
372
  // Site Common Secrets
616
- const siteCommonSecretsPath = getVaultSecretsConfigs(toSite).siteCommonSecretsPath;
617
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`)
373
+ const siteCommonSecretsPath =
374
+ getVaultSecretsConfigs(toSite).siteCommonSecretsPath;
375
+ console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
618
376
  const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
619
377
 
620
- const auth0Domain = `docupace-${toEnv}-${toSite}.us.auth0.com`
378
+ const auth0Domain = `docupace-${toEnv}-${toSite}.us.auth0.com`;
621
379
  const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
622
380
  const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
623
- const auth0Token = await getAuth0AuthToken(auth0Domain, auth0ClientId, auth0ClientSecret);
381
+ const auth0Token = await getAuth0AuthToken(
382
+ auth0Domain,
383
+ auth0ClientId,
384
+ auth0ClientSecret,
385
+ );
624
386
 
625
387
  // UI app
626
388
  const uiSecretsPath = getVaultSecretsConfigs(toSite).uiSecretsPath;
627
- console.log(`uiSecretsPath => ${uiSecretsPath}`)
389
+ console.log(`uiSecretsPath => ${uiSecretsPath}`);
628
390
 
629
391
  // GraphQL-Server app
630
- const graphqlSecretsPath = getVaultSecretsConfigs(toSite).graphqlServerSecretsPath;
392
+ const graphqlSecretsPath =
393
+ getVaultSecretsConfigs(toSite).graphqlServerSecretsPath;
631
394
  console.log(`graphqlSecretsPath => ${graphqlSecretsPath}`);
632
395
 
633
- let repoPathFromEnv ="";
634
- let repoPathToEnv = "";
396
+ let repoPathFromEnv = '';
397
+ let repoPathToEnv = '';
635
398
  // Clone repositories
636
- if ( fromEnv == toEnv ) {
637
- repoPathFromEnv = await cloneEnvRepository(fromEnv);
638
- repoPathToEnv = repoPathFromEnv;
639
- }else {
640
- repoPathFromEnv = await cloneEnvRepository(fromEnv);
641
- repoPathToEnv = await cloneEnvRepository(toEnv);
399
+ if (fromEnv === toEnv) {
400
+ repoPathFromEnv = await cloneEnvRepository(fromEnv);
401
+ repoPathToEnv = repoPathFromEnv;
402
+ } else {
403
+ repoPathFromEnv = await cloneEnvRepository(fromEnv);
404
+ repoPathToEnv = await cloneEnvRepository(toEnv);
642
405
  }
643
406
 
644
407
  //TODO: clone fromEnv and toEnv. replace above with this
645
408
 
646
- const auth0RepoPath = await cloneRepository('auth0-site-setup');
409
+ // const auth0RepoPath = await cloneRepository('auth0-site-setup');
647
410
 
648
411
  // Read deploy configs
649
- const { deployConfig: deployUIConfig } = await readDeployConfig('ui', fromEnv, fromSite, 'values');
412
+ const { deployConfig: deployUIConfig } = await readDeployConfig(
413
+ 'ui',
414
+ fromEnv,
415
+ fromSite,
416
+ 'values',
417
+ );
650
418
  const uiImageTag = deployUIConfig.image.tag;
651
419
 
652
- const { deployConfig: deployGraphQLServerConfig } = await readDeployConfig('graphql-server', fromEnv, fromSite, 'values');
420
+ const { deployConfig: deployGraphQLServerConfig } = await readDeployConfig(
421
+ 'graphql-server',
422
+ fromEnv,
423
+ fromSite,
424
+ 'values',
425
+ );
653
426
  const graphqlImageTag = deployGraphQLServerConfig.image.tag;
654
- const graphqlStandardConfigRemoteBranch = deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
655
-
656
- // File paths
657
- const filePaths = {
658
- databaseLoginJs: './auth0-site-setup/template/database-connections/docupace/login.js',
659
- loginHtml: './auth0-site-setup/template/pages/login.html',
660
- graphqlJson: './auth0-site-setup/template/clients/docupace-graphql.json',
661
- uiJson: './auth0-site-setup/template/clients/docupace-ui-main.json',
662
- connectJson: './auth0-site-setup/template/clients/docupace-connect.json',
663
- databaseJson: './auth0-site-setup/template/database-connections/docupace/database.json',
664
- twilioJson: './auth0-site-setup/template/guardian/providers/sms-twilio.json',
665
- };
666
-
667
- console.log(`Copying Latest UI Image Tag: ${deployUIConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
668
- console.log(`Copying Latest GraphQL Server Image Tag: ${deployGraphQLServerConfig.image.tag} from site: ${fromSite} to site: ${toSite}`);
427
+ const graphqlStandardConfigRemoteBranch =
428
+ deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
429
+
430
+ console.log(
431
+ `Copying Latest UI Image Tag: ${deployUIConfig.image.tag} from site: ${fromSite} to site: ${toSite}`,
432
+ );
433
+ console.log(
434
+ `Copying Latest GraphQL Server Image Tag: ${deployGraphQLServerConfig.image.tag} from site: ${fromSite} to site: ${toSite}`,
435
+ );
669
436
 
670
437
  const envConfig = environmentConfig[toEnv];
671
438
 
672
- let CORE_URL,
673
- SITE_HOST,
674
- CORE_API_CONTEXT,
675
- CONNECT_URL,
676
- DOCUPACE_HOST;
439
+ let CORE_URL, SITE_HOST, CORE_API_CONTEXT, CONNECT_URL, DOCUPACE_HOST;
677
440
  if (useNewDomain) {
678
441
  const newUrl = envConfig.newUrl(toSite);
679
442
  CORE_URL = `${newUrl}/core`;
680
443
  SITE_HOST = newUrl;
681
- CORE_API_CONTEXT = "core";
444
+ CORE_API_CONTEXT = 'core';
682
445
  CONNECT_URL = `${newUrl}/connect`;
683
446
  DOCUPACE_HOST = envConfig.docupaceHost();
684
447
  } else {
@@ -689,27 +452,42 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
689
452
  CONNECT_URL = `${oldUrl}_ui`;
690
453
  }
691
454
 
692
- await templateAuth0(SITE_HOST, CORE_API_CONTEXT, toEnv, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA);
693
- await importAuth0Templates('./auth0-site-setup/template', auth0Domain, auth0ClientId, auth0ClientSecret);
694
-
695
455
  if (deployUI === 'true') {
696
- await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPathToEnv);
456
+ await configureUI(
457
+ SITE_HOST,
458
+ CORE_URL,
459
+ DOCUPACE_HOST,
460
+ toSite,
461
+ toEnv,
462
+ useNewDomain,
463
+ auth0Domain,
464
+ auth0ClientId,
465
+ auth0ClientSecret,
466
+ auth0Token,
467
+ uiSecretsPath,
468
+ uiImageTag,
469
+ repoPathToEnv,
470
+ );
697
471
  }
698
472
 
699
- await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, graphqlStandardConfigRemoteBranch, repoPathToEnv, commonSecrets);
700
- await pushDeployConfig(repoPathToEnv, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
701
-
702
- await initializeAuth0Configuration({
703
- initConfiguration: "true",
704
- auth0Domain: auth0Domain,
705
- auth0AuthToken: auth0Token,
706
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER,
707
- });
708
-
709
- await addApplicationToApi({
710
- application: 'docupace-graphql-client-credentials',
711
- auth0Domain: auth0Domain,
712
- auth0AuthToken: auth0Token,
713
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER
714
- })
473
+ await configureGraphQLServer(
474
+ SITE_HOST,
475
+ CORE_URL,
476
+ DOCUPACE_HOST,
477
+ toSite,
478
+ toEnv,
479
+ auth0Domain,
480
+ auth0ClientId,
481
+ auth0ClientSecret,
482
+ auth0Token,
483
+ graphqlSecretsPath,
484
+ graphqlImageTag,
485
+ graphqlStandardConfigRemoteBranch,
486
+ repoPathToEnv,
487
+ commonSecrets,
488
+ );
489
+ await pushDeployConfig(
490
+ repoPathToEnv,
491
+ `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`,
492
+ );
715
493
  }