piral-cli 1.5.0-beta.6740 → 1.5.0-beta.6746

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 (45) hide show
  1. package/lib/apps/build-pilet.js.map +1 -1
  2. package/lib/apps/declaration-pilet.js +5 -2
  3. package/lib/apps/declaration-pilet.js.map +1 -1
  4. package/lib/apps/declaration-piral.js +3 -2
  5. package/lib/apps/declaration-piral.js.map +1 -1
  6. package/lib/apps/publish-pilet.js +2 -9
  7. package/lib/apps/publish-pilet.js.map +1 -1
  8. package/lib/apps/publish-piral.js +2 -9
  9. package/lib/apps/publish-piral.js.map +1 -1
  10. package/lib/apps/upgrade-pilet.js +4 -1
  11. package/lib/apps/upgrade-pilet.js.map +1 -1
  12. package/lib/common/config.d.ts +1 -0
  13. package/lib/common/config.js +28 -2
  14. package/lib/common/config.js.map +1 -1
  15. package/lib/common/constants.d.ts +1 -0
  16. package/lib/common/constants.js +2 -1
  17. package/lib/common/constants.js.map +1 -1
  18. package/lib/common/declaration.d.ts +2 -2
  19. package/lib/common/declaration.js +23 -12
  20. package/lib/common/declaration.js.map +1 -1
  21. package/lib/common/http.d.ts +12 -1
  22. package/lib/common/http.js +113 -76
  23. package/lib/common/http.js.map +1 -1
  24. package/lib/common/interactive.js +2 -2
  25. package/lib/common/interactive.js.map +1 -1
  26. package/lib/common/package.d.ts +3 -3
  27. package/lib/common/package.js +6 -6
  28. package/lib/common/package.js.map +1 -1
  29. package/lib/common/website.d.ts +1 -1
  30. package/lib/common/website.js +33 -11
  31. package/lib/common/website.js.map +1 -1
  32. package/package.json +2 -2
  33. package/src/apps/build-pilet.ts +2 -8
  34. package/src/apps/declaration-pilet.ts +15 -11
  35. package/src/apps/declaration-piral.ts +4 -2
  36. package/src/apps/publish-pilet.ts +4 -12
  37. package/src/apps/publish-piral.ts +5 -14
  38. package/src/apps/upgrade-pilet.ts +5 -1
  39. package/src/common/config.ts +36 -2
  40. package/src/common/constants.ts +1 -0
  41. package/src/common/declaration.ts +21 -12
  42. package/src/common/http.ts +143 -97
  43. package/src/common/interactive.ts +2 -2
  44. package/src/common/package.ts +11 -5
  45. package/src/common/website.ts +40 -12
@@ -1,18 +1,15 @@
1
- import { dirname, basename, resolve, relative } from 'path';
1
+ import { dirname, resolve } from 'path';
2
2
  import { LogLevels, PiletBuildType, PiletSchemaVersion } from '../types';
3
- import { callPiletBuild, callPiralBuild } from '../bundler';
3
+ import { callPiralBuild } from '../bundler';
4
4
  import {
5
5
  removeDirectory,
6
- retrievePiletData,
7
6
  setLogLevel,
8
7
  progress,
9
8
  logDone,
10
9
  logInfo,
11
- createPiletDeclaration,
12
10
  ForceOverwrite,
13
11
  matchAnyPilet,
14
12
  fail,
15
- config,
16
13
  log,
17
14
  writeJson,
18
15
  getPiletSpecMeta,
@@ -22,10 +19,7 @@ import {
22
19
  cpuCount,
23
20
  concurrentWorkers,
24
21
  normalizePublicUrl,
25
- combinePiletExternals,
26
22
  retrievePiletsInfo,
27
- validateSharedDependencies,
28
- defaultSchemaVersion,
29
23
  flattenExternals,
30
24
  triggerBuildPilet,
31
25
  } from '../common';
@@ -52,6 +52,7 @@ export async function declarationPilet(baseDir = process.cwd(), options: Declara
52
52
  setLogLevel(logLevel);
53
53
 
54
54
  const allEntries = await matchAnyPilet(fullBase, entryList);
55
+ const results: Array<boolean> = [];
55
56
 
56
57
  for (const item of allEntries) {
57
58
  const targetDir = dirname(item);
@@ -59,18 +60,21 @@ export async function declarationPilet(baseDir = process.cwd(), options: Declara
59
60
  const piralInstances = apps.map((m) => m.appPackage.name);
60
61
  const externals = combinePiletExternals(piralInstances, peerDependencies, peerModules, importmap);
61
62
  const dest = resolve(root, target);
62
-
63
- await createPiletDeclaration(
64
- piletPackage.name,
65
- piralInstances,
66
- root,
67
- item,
68
- externals,
69
- dest,
70
- forceOverwrite,
71
- logLevel,
63
+ results.push(
64
+ await createPiletDeclaration(
65
+ piletPackage.name,
66
+ piralInstances,
67
+ root,
68
+ item,
69
+ externals,
70
+ dest,
71
+ forceOverwrite,
72
+ logLevel,
73
+ ),
72
74
  );
73
75
  }
74
76
 
75
- logDone(`Declaration created successfully in "${target}"!`);
77
+ if (results.every(Boolean)) {
78
+ logDone(`Declaration created successfully in "${target}"!`);
79
+ }
76
80
  }
@@ -40,6 +40,8 @@ export async function declarationPiral(baseDir = process.cwd(), options: Declara
40
40
  } = options;
41
41
  const fullBase = resolve(process.cwd(), baseDir);
42
42
  setLogLevel(logLevel);
43
- await createPiralDeclaration(fullBase, entry, target, forceOverwrite, logLevel);
44
- logDone(`Declaration created successfully in "${target}"!`);
43
+
44
+ if (await createPiralDeclaration(fullBase, entry, target, forceOverwrite, logLevel)) {
45
+ logDone(`Declaration created successfully in "${target}"!`);
46
+ }
45
47
  }
@@ -1,4 +1,4 @@
1
- import { relative, dirname, basename, resolve } from 'path';
1
+ import { relative, resolve } from 'path';
2
2
  import { LogLevels, PiletSchemaVersion, PiletPublishSource, PublishScheme } from '../types';
3
3
  import {
4
4
  postFile,
@@ -11,11 +11,11 @@ import {
11
11
  progress,
12
12
  log,
13
13
  config,
14
- checkExists,
15
14
  findNpmTarball,
16
15
  downloadFile,
17
16
  matchAnyPilet,
18
17
  triggerBuildPilet,
18
+ getCertificate,
19
19
  } from '../common';
20
20
 
21
21
  export interface PublishPiletOptions {
@@ -203,7 +203,7 @@ export async function publishPilet(baseDir = process.cwd(), options: PublishPile
203
203
  logLevel = publishPiletDefaults.logLevel,
204
204
  from = publishPiletDefaults.from,
205
205
  schemaVersion = publishPiletDefaults.schemaVersion,
206
- cert = config.cert ?? publishPiletDefaults.cert,
206
+ cert = publishPiletDefaults.cert,
207
207
  fields = publishPiletDefaults.fields,
208
208
  headers = publishPiletDefaults.headers,
209
209
  mode = publishPiletDefaults.mode,
@@ -220,15 +220,7 @@ export async function publishPilet(baseDir = process.cwd(), options: PublishPile
220
220
  fail('missingPiletFeedUrl_0060');
221
221
  }
222
222
 
223
- log('generalDebug_0003', 'Checking if certificate exists.');
224
- let ca: Buffer = undefined;
225
-
226
- if (await checkExists(cert)) {
227
- const dir = dirname(cert);
228
- const file = basename(cert);
229
- log('generalDebug_0003', `Reading certificate file "${file}" from "${dir}".`);
230
- ca = await readBinary(dir, file);
231
- }
223
+ const ca = await getCertificate(cert);
232
224
 
233
225
  log('generalDebug_0003', 'Getting the tgz files ...');
234
226
  const sources = Array.isArray(source) ? source : [source];
@@ -1,14 +1,12 @@
1
- import { basename, dirname, resolve } from 'path';
1
+ import { resolve } from 'path';
2
2
  import { LogLevels, PublishScheme } from '../types';
3
3
  import {
4
4
  setLogLevel,
5
5
  progress,
6
- checkExists,
7
6
  fail,
8
7
  logDone,
9
8
  log,
10
9
  config,
11
- readBinary,
12
10
  emulatorName,
13
11
  emulatorJson,
14
12
  publishWebsiteEmulator,
@@ -21,6 +19,7 @@ import {
21
19
  emulatorPackageName,
22
20
  retrievePiletsInfo,
23
21
  validateSharedDependencies,
22
+ getCertificate,
24
23
  } from '../common';
25
24
 
26
25
  export interface PublishPiralOptions {
@@ -111,7 +110,7 @@ export async function publishPiral(baseDir = process.cwd(), options: PublishPira
111
110
  fresh = publishPiralDefaults.fresh,
112
111
  url = config.url ?? publishPiralDefaults.url,
113
112
  apiKey = config.apiKeys?.[url] ?? config.apiKey ?? publishPiralDefaults.apiKey,
114
- cert = config.cert ?? publishPiralDefaults.cert,
113
+ cert = publishPiralDefaults.cert,
115
114
  headers = publishPiralDefaults.headers,
116
115
  mode = publishPiralDefaults.mode,
117
116
  _ = {},
@@ -126,15 +125,7 @@ export async function publishPiral(baseDir = process.cwd(), options: PublishPira
126
125
  fail('missingPiletFeedUrl_0060');
127
126
  }
128
127
 
129
- log('generalDebug_0003', 'Checking if certificate exists.');
130
- let ca: Buffer = undefined;
131
-
132
- if (await checkExists(cert)) {
133
- const dir = dirname(cert);
134
- const file = basename(cert);
135
- log('generalDebug_0003', `Reading certificate file "${file}" from "${dir}".`);
136
- ca = await readBinary(dir, file);
137
- }
128
+ const ca = await getCertificate(cert);
138
129
 
139
130
  log('generalDebug_0003', 'Getting the files ...');
140
131
  const entryFiles = await retrievePiralRoot(fullBase, './');
@@ -150,7 +141,7 @@ export async function publishPiral(baseDir = process.cwd(), options: PublishPira
150
141
  if (emulator !== emulatorWebsiteName) {
151
142
  fail('generalError_0002', `Currently only the "${emulatorWebsiteName}" option is supported.`);
152
143
  }
153
-
144
+
154
145
  const emulatorDir = resolve(fullBase, source, emulatorName);
155
146
 
156
147
  if (fresh) {
@@ -1,5 +1,6 @@
1
1
  import { resolve } from 'path';
2
2
  import { LogLevels, NpmClientType } from '../types';
3
+ import { isInteractive } from '../external';
3
4
  import {
4
5
  installNpmPackage,
5
6
  checkExistingDirectory,
@@ -99,7 +100,10 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
99
100
  }
100
101
 
101
102
  const npmClient = await determineNpmClient(root, defaultNpmClient);
102
- const { apps, piletPackage } = await retrievePiletData(root);
103
+
104
+ // in case we run from a user's CLI we want to allow updating
105
+ const interactive = isInteractive();
106
+ const { apps, piletPackage } = await retrievePiletData(root, undefined, interactive);
103
107
  const { devDependencies = {}, dependencies = {}, source } = piletPackage;
104
108
 
105
109
  if (apps.length === 0) {
@@ -1,4 +1,7 @@
1
- import { defaultRegistry } from './constants';
1
+ import { homedir } from 'os';
2
+ import { resolve } from 'path';
3
+ import { readFile, writeFile } from 'fs/promises';
4
+ import { appName, defaultRegistry } from './constants';
2
5
  import { rc } from '../external';
3
6
  import { AuthConfig, SourceLanguage, NpmClientType, PiletSchemaVersion } from '../types';
4
7
 
@@ -69,7 +72,7 @@ export interface PiralCliConfig {
69
72
  }
70
73
 
71
74
  export const config: PiralCliConfig = rc(
72
- 'piral',
75
+ appName,
73
76
  {
74
77
  apiKey: undefined,
75
78
  apiKeys: {},
@@ -89,3 +92,34 @@ export const config: PiralCliConfig = rc(
89
92
  },
90
93
  {},
91
94
  );
95
+
96
+ function mergeConfig<T extends keyof PiralCliConfig>(
97
+ existing: PiralCliConfig,
98
+ area: T,
99
+ value: Partial<PiralCliConfig[T]>,
100
+ ) {
101
+ const current = existing[area];
102
+
103
+ // update already existing config
104
+ Object.assign(existing, {
105
+ [area]:
106
+ typeof current === 'object'
107
+ ? {
108
+ ...current,
109
+ ...value,
110
+ }
111
+ : value,
112
+ });
113
+ }
114
+
115
+ export async function updateConfig<T extends keyof PiralCliConfig>(area: T, value: Partial<PiralCliConfig[T]>) {
116
+ // update already existing config
117
+ mergeConfig(config, area, value);
118
+
119
+ // update user-global config
120
+ const path = resolve(homedir(), `.${appName}rc`);
121
+ const content = await readFile(path, 'utf8').catch(() => '{}');
122
+ const configFile = JSON.parse(content);
123
+ mergeConfig(configFile, area, value);
124
+ await writeFile(path, JSON.stringify(configFile, undefined, 2), 'utf8');
125
+ }
@@ -1,5 +1,6 @@
1
1
  export const defaultRegistry = 'https://registry.npmjs.org/';
2
2
  export const filesTar = 'files';
3
+ export const appName = 'piral';
3
4
  export const packageJson = 'package.json';
4
5
  export const piralJson = 'piral.json';
5
6
  export const piletJson = 'pilet.json';
@@ -130,20 +130,14 @@ function createLogger(): Logger {
130
130
 
131
131
  async function createDeclarationFile(
132
132
  options: DeclOptions,
133
- source: string,
134
133
  target: string,
135
134
  forceOverwrite: ForceOverwrite,
136
135
  ) {
137
136
  progress('Bundling declaration file ...');
137
+ const result = await generateDeclaration(options);
138
138
 
139
- try {
140
- const result = await generateDeclaration(options);
141
-
142
- progress('Writing declaration file ...');
143
- await createFileIfNotExists(target, 'index.d.ts', result, forceOverwrite);
144
- } catch (ex) {
145
- log('declarationCouldNotBeGenerated_0076', source, ex);
146
- }
139
+ progress('Writing declaration file ...');
140
+ await createFileIfNotExists(target, 'index.d.ts', result, forceOverwrite);
147
141
  }
148
142
 
149
143
  export async function createPiletDeclaration(
@@ -175,7 +169,15 @@ export async function createPiletDeclaration(
175
169
  logLevel,
176
170
  logger: createLogger(),
177
171
  };
178
- return await createDeclarationFile(options, root, target, forceOverwrite);
172
+
173
+ try {
174
+ await createDeclarationFile(options, target, forceOverwrite);
175
+ return true;
176
+ } catch (ex) {
177
+ log('declarationCouldNotBeGenerated_0076', root, ex);
178
+ }
179
+
180
+ return false;
179
181
  }
180
182
  }
181
183
 
@@ -206,8 +208,15 @@ export async function createPiralDeclaration(
206
208
  validateSharedDependencies(externals);
207
209
 
208
210
  if (options.apis.length) {
209
- return await createDeclarationFile(options, baseDir, target, forceOverwrite);
211
+ try {
212
+ await createDeclarationFile(options, target, forceOverwrite);
213
+ return true;
214
+ } catch (ex) {
215
+ log('declarationCouldNotBeGenerated_0076', baseDir, ex);
216
+ }
217
+ } else {
218
+ log('declarationCouldNotBeGenerated_0076', baseDir, 'The main Pilet API interface could not be found.');
210
219
  }
211
220
 
212
- log('declarationCouldNotBeGenerated_0076', baseDir, 'The main Pilet API interface could not be found.');
221
+ return false;
213
222
  }
@@ -1,4 +1,4 @@
1
- import { join } from 'path';
1
+ import { basename, dirname, join } from 'path';
2
2
  import { Agent } from 'https';
3
3
  import { Stream } from 'stream';
4
4
  import { tmpdir } from 'os';
@@ -6,6 +6,7 @@ import { createWriteStream } from 'fs';
6
6
  import { log } from './log';
7
7
  import { config } from './config';
8
8
  import { standardHeaders } from './info';
9
+ import { checkExists, readBinary } from './io';
9
10
  import { getTokenInteractively } from './interactive';
10
11
  import { axios, FormData } from '../external';
11
12
  import { PublishScheme } from '../types';
@@ -60,6 +61,45 @@ export function getAxiosOptions(url: string) {
60
61
  }
61
62
  }
62
63
 
64
+ export async function getCertificate(cert = config.cert): Promise<Buffer> {
65
+ log('generalDebug_0003', 'Checking if certificate exists.');
66
+
67
+ if (await checkExists(cert)) {
68
+ const dir = dirname(cert);
69
+ const file = basename(cert);
70
+ log('generalDebug_0003', `Reading certificate file "${file}" from "${dir}".`);
71
+ return await readBinary(dir, file);
72
+ }
73
+
74
+ return undefined;
75
+ }
76
+
77
+ export function getAuthorizationHeaders(scheme: PublishScheme, key: string) {
78
+ if (key) {
79
+ switch (scheme) {
80
+ case 'basic':
81
+ return {
82
+ authorization: `Basic ${key}`,
83
+ };
84
+ case 'bearer':
85
+ return {
86
+ authorization: `Bearer ${key}`,
87
+ };
88
+ case 'digest':
89
+ return {
90
+ authorization: `Digest ${key}`,
91
+ };
92
+ case 'none':
93
+ default:
94
+ return {
95
+ authorization: key,
96
+ };
97
+ }
98
+ }
99
+
100
+ return {};
101
+ }
102
+
63
103
  export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>> {
64
104
  const httpsAgent = ca ? new Agent({ ca }) : undefined;
65
105
  return axios.default
@@ -80,24 +120,9 @@ export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>
80
120
  });
81
121
  }
82
122
 
83
- export interface PostFormResult {
84
- status: number;
85
- success: boolean;
86
- response?: object;
87
- }
88
-
89
123
  export type FormDataObj = Record<string, string | number | boolean | [Buffer, string]>;
90
124
 
91
- export function postForm(
92
- target: string,
93
- scheme: PublishScheme,
94
- key: string,
95
- formData: FormDataObj,
96
- customHeaders: Record<string, string> = {},
97
- ca?: Buffer,
98
- interactive = false,
99
- ): Promise<PostFormResult> {
100
- const httpsAgent = ca ? new Agent({ ca }) : undefined;
125
+ export function createAxiosForm(formData: FormDataObj) {
101
126
  const form = new FormData();
102
127
 
103
128
  Object.keys(formData).forEach((key) => {
@@ -112,105 +137,126 @@ export function postForm(
112
137
  }
113
138
  });
114
139
 
140
+ return form;
141
+ }
142
+
143
+ export function handleAxiosError(
144
+ error: any,
145
+ interactive: boolean,
146
+ httpsAgent: Agent,
147
+ refetch: (mode: PublishScheme, key: string) => Promise<any>,
148
+ onfail?: (status: number, statusText: string, response: string) => any,
149
+ ) {
150
+ if (!onfail) {
151
+ onfail = () => {
152
+ throw error;
153
+ };
154
+ }
155
+
156
+ if (error.response) {
157
+ // The request was made and the server responded with a status code
158
+ // that falls out of the range of 2xx
159
+ const { data, statusText, status } = error.response;
160
+
161
+ if (interactive && 'interactiveAuth' in data) {
162
+ const { interactiveAuth } = data;
163
+
164
+ if (typeof interactiveAuth === 'string') {
165
+ log(
166
+ 'generalDebug_0003',
167
+ `Received status "${status}" from HTTP - trying interactive log in to "${interactiveAuth}".`,
168
+ );
169
+
170
+ return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) => refetch(mode, token));
171
+ }
172
+ }
173
+
174
+ const message = getMessage(data) || '';
175
+ return onfail(status, statusText, message);
176
+ } else if (error.isAxiosError) {
177
+ // axios initiated error: try to parse message from error object
178
+ let errorMessage: string = error.errno || 'Unknown Axios Error';
179
+
180
+ if (typeof error.toJSON === 'function') {
181
+ const errorObj: { message?: string } = error.toJSON();
182
+ errorMessage = errorObj?.message ?? errorMessage;
183
+ }
184
+
185
+ return onfail(500, undefined, errorMessage);
186
+ } else if (error.request) {
187
+ // The request was made but no response was received
188
+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
189
+ // http.ClientRequest in node.js
190
+ return onfail(500, undefined, error.request);
191
+ } else {
192
+ // Something happened in setting up the request that triggered an Error
193
+ return onfail(500, undefined, error.message);
194
+ }
195
+ }
196
+
197
+ export interface PostFormResult {
198
+ status: number;
199
+ success: boolean;
200
+ response?: object;
201
+ }
202
+
203
+ export async function postForm(
204
+ target: string,
205
+ scheme: PublishScheme,
206
+ key: string,
207
+ formData: FormDataObj,
208
+ customHeaders: Record<string, string> = {},
209
+ ca?: Buffer,
210
+ interactive = false,
211
+ ): Promise<PostFormResult> {
212
+ const httpsAgent = ca ? new Agent({ ca }) : undefined;
213
+ const form = createAxiosForm(formData);
214
+
115
215
  const headers: Record<string, string> = {
116
216
  ...form.getHeaders(),
117
217
  ...standardHeaders,
118
218
  ...customHeaders,
219
+ ...getAuthorizationHeaders(scheme, key),
119
220
  };
120
221
 
121
- if (key) {
122
- switch (scheme) {
123
- case 'basic':
124
- headers.authorization = `Basic ${key}`;
125
- break;
126
- case 'bearer':
127
- headers.authorization = `Bearer ${key}`;
128
- break;
129
- case 'digest':
130
- headers.authorization = `Digest ${key}`;
131
- break;
132
- case 'none':
133
- default:
134
- headers.authorization = key;
135
- break;
136
- }
137
- }
138
-
139
- return axios.default
140
- .post(target, form, {
222
+ try {
223
+ const res = await axios.default.post(target, form, {
141
224
  headers,
142
225
  httpsAgent,
143
226
  maxContentLength: Infinity,
144
227
  maxBodyLength: Infinity,
145
- })
146
- .then(
147
- (res) => {
148
- return {
149
- status: res.status,
150
- success: true,
151
- response: res.data,
152
- };
153
- },
154
- (error) => {
155
- if (error.response) {
156
- // The request was made and the server responded with a status code
157
- // that falls out of the range of 2xx
158
- const { data, statusText, status } = error.response;
159
-
160
- if (interactive && 'interactiveAuth' in data) {
161
- const { interactiveAuth } = data;
162
-
163
- if (typeof interactiveAuth === 'string') {
164
- log(
165
- 'generalDebug_0003',
166
- `Received status "${status}" from HTTP - trying interactive log in to "${interactiveAuth}".`,
167
- );
168
-
169
- return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
170
- postForm(target, mode, token, formData, customHeaders, ca, false),
171
- );
172
- }
173
- }
174
-
175
- const message = getMessage(data) || '';
176
- log('unsuccessfulHttpPost_0066', statusText, status, message);
177
- return {
178
- status,
179
- success: false,
180
- response: message,
181
- };
182
- } else if (error.isAxiosError) {
183
- // axios initiated error: try to parse message from error object
184
- let errorMessage: string = error.errno || 'Unknown Axios Error';
185
-
186
- if (typeof error.toJSON === 'function') {
187
- const errorObj: { message?: string } = error.toJSON();
188
- errorMessage = errorObj?.message ?? errorMessage;
189
- }
228
+ });
190
229
 
191
- log('failedHttpPost_0065', errorMessage);
230
+ return {
231
+ status: res.status,
232
+ success: true,
233
+ response: res.data,
234
+ };
235
+ } catch (error) {
236
+ return await handleAxiosError(
237
+ error,
238
+ interactive,
239
+ httpsAgent,
240
+ (mode, token) => postForm(target, mode, token, formData, customHeaders, ca, false),
241
+ (status, statusText, response) => {
242
+ if (status === 500) {
243
+ log('failedHttpPost_0065', response);
192
244
  return {
193
245
  status: 500,
194
246
  success: false,
195
- response: errorMessage,
247
+ response: undefined,
196
248
  };
197
- } else if (error.request) {
198
- // The request was made but no response was received
199
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
200
- // http.ClientRequest in node.js
201
- log('failedHttpPost_0065', error.request);
202
249
  } else {
203
- // Something happened in setting up the request that triggered an Error
204
- log('failedHttpPost_0065', error.message);
250
+ log('unsuccessfulHttpPost_0066', statusText, status, response);
251
+ return {
252
+ status,
253
+ success: false,
254
+ response,
255
+ };
205
256
  }
206
-
207
- return {
208
- status: 500,
209
- success: false,
210
- response: undefined,
211
- };
212
257
  },
213
258
  );
259
+ }
214
260
  }
215
261
 
216
262
  export function postFile(
@@ -69,10 +69,10 @@ export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResu
69
69
 
70
70
  try {
71
71
  while (true) {
72
- const { data, status } = await axios.default.get(callbackUrl);
72
+ const { data, status } = await axios.default.get(callbackUrl, { httpsAgent, headers: standardHeaders });
73
73
 
74
74
  if (status === 202) {
75
- await new Promise(resolve => setTimeout(resolve, 5000));
75
+ await new Promise((resolve) => setTimeout(resolve, 5000));
76
76
  continue;
77
77
  }
78
78
 
@@ -158,7 +158,12 @@ async function loadPiralInstance(root: string, details?: PiralInstanceDetails):
158
158
  return appPackage;
159
159
  }
160
160
 
161
- export async function findPiralInstance(proposedApp: string, rootDir: string, details?: PiralInstanceDetails) {
161
+ export async function findPiralInstance(
162
+ proposedApp: string,
163
+ rootDir: string,
164
+ details?: PiralInstanceDetails,
165
+ interactive = false,
166
+ ) {
162
167
  const path = findPackageRoot(proposedApp, rootDir);
163
168
  const url = details?.url;
164
169
 
@@ -167,7 +172,7 @@ export async function findPiralInstance(proposedApp: string, rootDir: string, de
167
172
 
168
173
  if (url) {
169
174
  log('generalDebug_0003', `Updating the emulator from remote "${url}" ...`);
170
- await updateFromEmulatorWebsite(root, url);
175
+ await updateFromEmulatorWebsite(root, url, interactive);
171
176
  }
172
177
 
173
178
  return await loadPiralInstance(root, details);
@@ -185,6 +190,7 @@ export async function findPiralInstances(
185
190
  piletPackage: PiletPackageData,
186
191
  piletDefinition: undefined | PiletDefinition,
187
192
  rootDir: string,
193
+ interactive?: boolean,
188
194
  ) {
189
195
  if (proposedApps) {
190
196
  // do nothing
@@ -202,7 +208,7 @@ export async function findPiralInstances(
202
208
  if (proposedApps.length > 0) {
203
209
  return Promise.all(
204
210
  proposedApps.map((proposedApp) =>
205
- findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp]),
211
+ findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp], interactive),
206
212
  ),
207
213
  );
208
214
  }
@@ -776,13 +782,13 @@ export async function findPiletRoot(proposedRoot: string) {
776
782
  return dirname(packageJsonPath);
777
783
  }
778
784
 
779
- export async function retrievePiletData(target: string, app?: string) {
785
+ export async function retrievePiletData(target: string, app?: string, interactive?: boolean) {
780
786
  const piletJsonPath = await findFile(target, piletJson);
781
787
  const proposedRoot = piletJsonPath ? dirname(piletJsonPath) : target;
782
788
  const root = await findPiletRoot(proposedRoot);
783
789
  const piletPackage = await readJson(root, packageJson);
784
790
  const piletDefinition: PiletDefinition = piletJsonPath && (await readJson(proposedRoot, piletJson));
785
- const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root);
791
+ const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root, interactive);
786
792
  const apps: Array<AppDefinition> = [];
787
793
 
788
794
  for (const appPackage of appPackages) {