@docupace/pipeline 1.0.22 → 1.0.24-alpha-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.22",
3
+ "version": "1.0.24-alpha-2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,7 +17,6 @@
17
17
  "dependencies": {
18
18
  "@changesets/cli": "^2.27.10",
19
19
  "@docupace/core-client": "^0.1.59",
20
- "auth0-deploy-cli": "^7.24.3",
21
20
  "axios": "^1.7.9",
22
21
  "commander": "^12.1.0",
23
22
  "dotenv": "^16.4.7",
package/src/auth0/cli.js CHANGED
@@ -18,17 +18,18 @@ 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> <configureMFA>')
21
+ .command('configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain>')
22
22
  .description('Configure the Auth0 tenants in env for the given site')
23
- .action(async (fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA) => {
24
- await configureFromSite(fromSite, toSite, fromEnv, toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA);
23
+ .action(async (fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain) => {
24
+ await configureFromSite(fromSite, toSite, fromEnv, toEnv, deployUI, deployGraphQLServer, useNewDomain);
25
25
  });
26
26
 
27
27
  program
28
28
  .command('getVaultSecrets <vaultPath>')
29
29
  .description('Get Secrets for Vault PATH')
30
30
  .action(async (vaultPath) => {
31
- await getVaultSecrets(vaultPath);
31
+ const data = await getVaultSecrets(vaultPath);
32
+ console.log(data);
32
33
  });
33
34
 
34
35
  program
@@ -2,9 +2,7 @@ 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 { exec } from 'child_process';
7
- import { promisify } from 'node:util';
5
+ import fl from 'fs/promises';
8
6
 
9
7
  import {
10
8
  cloneEnvRepository,
@@ -23,6 +21,7 @@ import {
23
21
  environmentConfig
24
22
  } from '../next/config.js';
25
23
  import { connect } from 'http2';
24
+ import { promise } from 'zod';
26
25
 
27
26
  async function ensureDirectoryExists(dirPath) {
28
27
  try {
@@ -33,296 +32,23 @@ async function ensureDirectoryExists(dirPath) {
33
32
  }
34
33
  }
35
34
 
36
- async function addApplicationToApi ({application, auth0Domain, auth0AuthToken, coreApiIdentifier}){
37
- console.log("Adding application to API authorized applications...");
38
-
39
- try {
40
- const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
41
- headers: {authorization: `Bearer ${auth0AuthToken}`},
42
- });
43
-
44
- const appAuth0ClientIdData = auth0Response.data.find(client => client.name === `${application}`);
45
- const appAuth0ClientId = appAuth0ClientIdData.client_id;
46
-
47
- await axios.post(
48
- `https://${auth0Domain}/api/v2/client-grants`,
49
- {
50
- client_id: appAuth0ClientId,
51
- audience: `${coreApiIdentifier}`,
52
- scope: [],
53
- },
54
- {
55
- headers: {
56
- Authorization: `Bearer ${auth0AuthToken}`,
57
- "Content-Type": "application/json",
58
- },
59
- }
60
- );
61
- console.log(`Application (${appAuth0ClientId}) authorized for API: ${coreApiIdentifier}`);
62
- } catch (err) {
63
- console.error(`Failed to add application: ${application}: ${err.message}`);
64
- }
65
-
66
- }
67
-
68
- async function initializeAuth0Configuration({
69
- initConfiguration,
70
- auth0Domain,
71
- auth0AuthToken,
72
- coreApiIdentifier,
73
- }) {
74
- if (initConfiguration === "true") {
75
- try {
76
- // Create a new resource server in Auth0
77
- console.log("Creating resource server in Auth0...");
78
-
79
- const resourceServerResponse = await axios.post(
80
- `https://${auth0Domain}/api/v2/resource-servers`,
81
- {
82
- name: "docupace-core",
83
- identifier: `${coreApiIdentifier}`,
84
- token_lifetime: 86400,
85
- allow_offline_access: false,
86
- signing_alg: "RS256",
87
- skip_consent_for_verifiable_first_party_clients: true,
88
- scopes: [],
89
- },
90
- {
91
- headers: {
92
- Authorization: `Bearer ${auth0AuthToken}`,
93
- "Content-Type": "application/json",
94
- },
95
- }
96
- );
97
-
98
- const apiId = resourceServerResponse.data.id;
99
-
100
- // Update tenant settings with the default audience
101
- console.log("Updating tenant settings...");
102
- await axios.patch(
103
- `https://${auth0Domain}/api/v2/tenants/settings`,
104
- {
105
- default_audience: `${coreApiIdentifier}`,
106
- },
107
- {
108
- headers: {
109
- Authorization: `Bearer ${auth0AuthToken}`,
110
- "Content-Type": "application/json",
111
- },
112
- }
113
- );
114
- console.log("Tenant settings updated successfully.");
115
- } catch (error) {
116
- console.error("Error during Auth0 configuration:", error.response?.data || error.message);
117
- }
118
- }
119
- }
120
-
121
- async function importAuth0Templates(directoryPath, auth0Domain, auth0ClientID, auth0ClientSecret) {
122
- try {
123
- const config = {
124
- input_file: directoryPath,
125
- config: {
126
- AUTH0_DOMAIN: auth0Domain,
127
- AUTH0_CLIENT_ID: auth0ClientID,
128
- AUTH0_CLIENT_SECRET: auth0ClientSecret,
129
- },
130
- debug: true,
131
- };
132
-
133
- console.log('Starting Auth0 template import...');
134
- await deploy(config);
135
- console.log('Auth0 template import completed successfully!');
136
- } catch (error) {
137
- console.error('Error during Auth0 template import:', error.message);
138
- process.exit(1); // Exit with an error code
139
- }
140
- }
141
-
142
- async function updateJsonFile(filePath, updates) {
143
- const content = await fs.promises.readFile(filePath, 'utf8');
144
- const jsonContent = JSON.parse(content);
145
- const updatedContent = JSON.stringify({...jsonContent, ...updates}, null, 2);
146
- await fs.promises.writeFile(filePath, updatedContent);
147
- }
148
-
149
- async function replaceInFile(filePath, replacements) {
150
- let content = await fs.promises.readFile(filePath, 'utf8');
151
-
152
- for (const [search, replace] of replacements) {
153
- const escapedSearch = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); // Escape special chars
154
- content = content.replace(new RegExp(escapedSearch, 'g'), replace);
155
- }
156
- await fs.promises.writeFile(filePath, content, 'utf8');
157
- }
158
-
159
- async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA) {
35
+ async function copyDirectory(source, destination) {
160
36
  try {
161
- let uiAllowedCallbacksUrls,
162
- uiAllowedLogoutUrls;
163
- let graphqlAllowedCallbacksUrls,
164
- graphqlAllowedLogoutUrls;
165
- let connectAllowedCallbacksUrls,
166
- connectlAllowedLogoutUrls;
167
-
168
- let connectClientMetadata,
169
- connectCallbacks,
170
- connectAddons;
171
- // Configure URLs based on environment
172
- if (env === 'prd') {
173
- uiAllowedCallbacksUrls = [`${siteUrl}/api/auth/callback`];
174
- uiAllowedLogoutUrls = [`${siteUrl}`];
175
-
176
- graphqlAllowedCallbacksUrls = [`${siteUrl}/api/graphql/callback`];
177
- graphqlAllowedLogoutUrls = [`${siteUrl}/api/graphql/`];
178
-
179
- connectAllowedCallbacksUrls = [`${siteUrl}/connect/samlCallback?client_name=auth0`];
180
- connectlAllowedLogoutUrls = [ `${siteUrl}/connect`];
181
- } else {
182
- uiAllowedCallbacksUrls = [
183
- `${siteUrl}/api/auth/callback`,
184
- `http://localhost:3000/api/auth/callback`,
185
- ];
186
- uiAllowedLogoutUrls = [
187
- `${siteUrl}`,
188
- `http://localhost:3000`,
189
- ];
190
- graphqlAllowedCallbacksUrls = [
191
- `${siteUrl}/api/graphql/callback`,
192
- `http://localhost:4000/api/graphql/callback`,
193
- ];
194
- graphqlAllowedLogoutUrls = [
195
- `http://localhost:4000/api/graphql/`,
196
- `${siteUrl}/api/graphql/`,
197
- ];
198
- connectAllowedCallbacksUrls = [
199
- `${siteUrl}/connect/samlCallback?client_name=auth0`,
200
- `http://localhost:9000/connect/samlCallback?client_name=auth0`,
201
- ];
202
- connectlAllowedLogoutUrls = [
203
- `${siteUrl}/connect`
204
- ];
205
-
206
- const siteUrlNoPrefix=siteUrl.replace(/^https?:\/\//, '');
207
- connectClientMetadata ={
208
- "docupaceContext" : "core",
209
- "docupaceHost" : `${siteUrlNoPrefix}`,
210
- "docupace_context" : "core",
211
- "docupace_host" : `${siteUrlNoPrefix} `
212
- };
213
-
214
- connectCallbacks = [
215
- `${siteUrl}/connect/samlCallback?client_name=auth0`
216
- ];
217
-
218
- connectAddons = {
219
- "samlp": {
220
- "audience": `${siteUrl}/connect`,
221
- "recipient": `${siteUrl}/connect/samlCallback?client_name=auth0`,
222
- "destination": `${siteUrl}/connect/samlCallback?client_name=auth0`,
223
- "nameIdentifierFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
224
- "binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
225
- "nameIdentifierProbes": [
226
- "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/docupace-username"
227
- ],
228
- "mappings": {
229
- "proposalHandle": "ProposalHandle"
230
- }
231
- }
232
- };
233
-
234
- }
235
-
236
-
237
- const configureUI = deployUI === 'true';
238
- if (configureUI) {
239
- console.log('ui_allowed_callbacks_urls ->', uiAllowedCallbacksUrls);
240
- console.log('ui_allowed_logout_urls ->', uiAllowedLogoutUrls);
241
-
242
- await updateJsonFile(filePaths.uiJson, {
243
- callbacks: uiAllowedCallbacksUrls,
244
- allowed_logout_urls: uiAllowedLogoutUrls,
245
- });
246
-
37
+ await fl.mkdir(destination, { recursive: true });
38
+ const items = await fl.readdir(source, { withFileTypes: true });
247
39
 
248
- //TODO: move to separate function for connect
249
- console.log('connect_allowed_callbacks_urls ->', connectAllowedCallbacksUrls);
250
- console.log('connect_allowed_logout_urls ->', connectlAllowedLogoutUrls);
40
+ for (const item of items) {
41
+ const sourcePath = path.join(source, item.name);
42
+ const destinationPath = path.join(destination, item.name);
251
43
 
252
- // update allowed callback url
253
- await updateJsonFile(filePaths.connectJson, {
254
- callbacks: connectAllowedCallbacksUrls,
255
- allowed_logout_urls: connectlAllowedLogoutUrls,
256
- client_metadata: connectClientMetadata,
257
- addons: connectAddons
258
- });
259
-
260
-
261
-
262
- console.log('Updated URLs for main UI...');
263
- } else {
264
- await fs.promises.unlink(filePaths.uiJson);
265
- await updateJsonFile(filePaths.databaseJson, {
266
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-ui-main'),
267
- });
268
- console.log("Removed 'docupace-ui-main' from enabled_clients in database.json");
269
- }
270
-
271
- const configureGraphqlServer = deployGraphQLServer === 'true';
272
- if (configureGraphqlServer) {
273
- console.log('graphql_allowed_callbacks_urls ->', graphqlAllowedCallbacksUrls);
274
- console.log('graphql_allowed_logout_urls ->', graphqlAllowedLogoutUrls);
275
-
276
- await updateJsonFile(filePaths.graphqlJson, {
277
- callbacks: graphqlAllowedCallbacksUrls,
278
- allowed_logout_urls: graphqlAllowedLogoutUrls,
279
- });
280
- console.log('Updated URLs for GraphQL server...');
281
- } else {
282
- await fs.promises.unlink(filePaths.graphqlJson);
283
- await updateJsonFile(filePaths.databaseJson, {
284
- enabled_clients: (content) => content.enabled_clients.filter((client) => client !== 'docupace-graphql'),
285
- });
286
- console.log("Removed 'docupace-graphql' from enabled_clients in database.json");
287
- }
288
-
289
- // TWILIO configuration
290
- await replaceInFile(filePaths.twilioJson, [
291
- ['twilioauthtokenplaceholder', commonSecrets.TWILIO_AUTH_TOKEN],
292
- ['twiliosidplaceholder', commonSecrets.TWILIO_SID],
293
- ['twiliofromplaceholder', commonSecrets.TWILIO_FROM_NUMBER],
294
- ]);
295
-
296
- console.log('TWILIO configuration updated...');
297
-
298
- const tmpSiteUrl = siteUrl.replace(/^https?:\/\//, '');
299
- // Database configuration
300
- await replaceInFile(filePaths.databaseLoginJs, [
301
- ['${docupaceHost}', tmpSiteUrl],
302
- ['${docupaceContext}', coreApiContext],
303
- ]);
304
-
305
- // MFA configuration
306
- const execAsync = promisify(exec);
307
- try {
308
- console.log('Template configuration started...');
309
- if (configureMFA === 'ENABLED') {
310
- console.log('AUTH0 MFA is enabled');
311
- await execAsync('rsync -av auth0-site-setup/templateMFA/ auth0-site-setup/template/');
44
+ if (item.isDirectory()) {
45
+ await copyDirectory(sourcePath, destinationPath);
312
46
  } else {
313
- console.log('AUTH0 MFA is disabled');
314
- await execAsync('rsync -av auth0-site-setup/templateNoMFA/ auth0-site-setup/template/');
47
+ await fl.copyFile(sourcePath, destinationPath);
315
48
  }
316
-
317
- console.log('Template configuration completed.');
318
- } catch (err) {
319
- console.error('Error configuring Auth0 templates:', err);
320
- throw err;
321
49
  }
322
-
323
- console.log('Template configuration completed.');
324
50
  } catch (err) {
325
- // console.error('Error configuring Auth0 templates:', err);
51
+ console.error(`Error copying directory: ${err.message}`);
326
52
  throw err;
327
53
  }
328
54
  }
@@ -586,8 +312,7 @@ ingress:
586
312
  }
587
313
  }
588
314
 
589
-
590
- export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain, configureMFA) {
315
+ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployUI, deployGraphQLServer, useNewDomain) {
591
316
  console.log(`Configuring Auth0 tenants and ArgoCD apps for site: ${toSite} in env: ${toEnv} from site: ${fromSite}`);
592
317
  // Common Secrets
593
318
  const commonSecretsPath = getVaultSecretsConfigs(toSite).commonSecretsPath;
@@ -615,17 +340,17 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
615
340
  let repoPathFromEnv ="";
616
341
  let repoPathToEnv = "";
617
342
  // Clone repositories
618
- if ( fromEnv == toEnv ) {
343
+ if ( fromEnv === toEnv ) {
619
344
  repoPathFromEnv = await cloneEnvRepository(fromEnv);
620
345
  repoPathToEnv = repoPathFromEnv;
621
- }else {
346
+ } else {
622
347
  repoPathFromEnv = await cloneEnvRepository(fromEnv);
623
348
  repoPathToEnv = await cloneEnvRepository(toEnv);
624
349
  }
625
350
 
626
351
  //TODO: clone fromEnv and toEnv. replace above with this
627
352
 
628
- const auth0RepoPath = await cloneRepository('auth0-site-setup');
353
+ // const auth0RepoPath = await cloneRepository('auth0-site-setup');
629
354
 
630
355
  // Read deploy configs
631
356
  const { deployConfig: deployUIConfig } = await readDeployConfig('ui', fromEnv, fromSite, 'values');
@@ -671,9 +396,6 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
671
396
  CONNECT_URL = `${oldUrl}_ui`;
672
397
  }
673
398
 
674
- await templateAuth0(SITE_HOST, CORE_API_CONTEXT, toEnv, filePaths, deployUI, deployGraphQLServer, commonSecrets, configureMFA);
675
- await importAuth0Templates('./auth0-site-setup/template', auth0Domain, auth0ClientId, auth0ClientSecret);
676
-
677
399
  if (deployUI === 'true') {
678
400
  await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPathToEnv);
679
401
  }
@@ -681,17 +403,4 @@ export async function configureFromSite(fromSite, toSite, fromEnv,toEnv, deployU
681
403
  await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, toEnv, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, graphqlStandardConfigRemoteBranch, repoPathToEnv, commonSecrets);
682
404
  await pushDeployConfig(repoPathToEnv, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
683
405
 
684
- await initializeAuth0Configuration({
685
- initConfiguration: "true",
686
- auth0Domain: auth0Domain,
687
- auth0AuthToken: auth0Token,
688
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER,
689
- });
690
-
691
- await addApplicationToApi({
692
- application: 'docupace-graphql-client-credentials',
693
- auth0Domain: auth0Domain,
694
- auth0AuthToken: auth0Token,
695
- coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER
696
- })
697
406
  }