piral-cli 1.5.0-beta.6740 → 1.5.0-beta.6744
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/lib/apps/publish-pilet.js +2 -9
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.js +2 -9
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/common/config.d.ts +1 -0
- package/lib/common/config.js +28 -2
- package/lib/common/config.js.map +1 -1
- package/lib/common/constants.d.ts +1 -0
- package/lib/common/constants.js +2 -1
- package/lib/common/constants.js.map +1 -1
- package/lib/common/http.d.ts +12 -1
- package/lib/common/http.js +113 -76
- package/lib/common/http.js.map +1 -1
- package/lib/common/interactive.js +2 -2
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/website.js +33 -10
- package/lib/common/website.js.map +1 -1
- package/package.json +2 -2
- package/src/apps/publish-pilet.ts +4 -12
- package/src/apps/publish-piral.ts +5 -14
- package/src/common/config.ts +36 -2
- package/src/common/constants.ts +1 -0
- package/src/common/http.ts +143 -97
- package/src/common/interactive.ts +2 -2
- package/src/common/website.ts +41 -10
|
@@ -73,21 +73,14 @@ async function getFiles(baseDir, sources, from, fresh, originalSchemaVersion, lo
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async function publishPilet(baseDir = process.cwd(), options = {}) {
|
|
76
|
-
const { fresh = exports.publishPiletDefaults.fresh, source = fresh ? './src/index' : '*.tgz', url = common_1.config.url ?? exports.publishPiletDefaults.url, apiKey = common_1.config.apiKeys?.[url] ?? common_1.config.apiKey ?? exports.publishPiletDefaults.apiKey, logLevel = exports.publishPiletDefaults.logLevel, from = exports.publishPiletDefaults.from, schemaVersion = exports.publishPiletDefaults.schemaVersion, cert =
|
|
76
|
+
const { fresh = exports.publishPiletDefaults.fresh, source = fresh ? './src/index' : '*.tgz', url = common_1.config.url ?? exports.publishPiletDefaults.url, apiKey = common_1.config.apiKeys?.[url] ?? common_1.config.apiKey ?? exports.publishPiletDefaults.apiKey, logLevel = exports.publishPiletDefaults.logLevel, from = exports.publishPiletDefaults.from, schemaVersion = exports.publishPiletDefaults.schemaVersion, cert = exports.publishPiletDefaults.cert, fields = exports.publishPiletDefaults.fields, headers = exports.publishPiletDefaults.headers, mode = exports.publishPiletDefaults.mode, interactive = exports.publishPiletDefaults.interactive, _ = {}, hooks = {}, bundlerName, } = options;
|
|
77
77
|
const fullBase = (0, path_1.resolve)(process.cwd(), baseDir);
|
|
78
78
|
(0, common_1.setLogLevel)(logLevel);
|
|
79
79
|
(0, common_1.progress)('Reading configuration ...');
|
|
80
80
|
if (!url) {
|
|
81
81
|
(0, common_1.fail)('missingPiletFeedUrl_0060');
|
|
82
82
|
}
|
|
83
|
-
(0, common_1.
|
|
84
|
-
let ca = undefined;
|
|
85
|
-
if (await (0, common_1.checkExists)(cert)) {
|
|
86
|
-
const dir = (0, path_1.dirname)(cert);
|
|
87
|
-
const file = (0, path_1.basename)(cert);
|
|
88
|
-
(0, common_1.log)('generalDebug_0003', `Reading certificate file "${file}" from "${dir}".`);
|
|
89
|
-
ca = await (0, common_1.readBinary)(dir, file);
|
|
90
|
-
}
|
|
83
|
+
const ca = await (0, common_1.getCertificate)(cert);
|
|
91
84
|
(0, common_1.log)('generalDebug_0003', 'Getting the tgz files ...');
|
|
92
85
|
const sources = Array.isArray(source) ? source : [source];
|
|
93
86
|
const files = await getFiles(fullBase, sources, from, fresh, schemaVersion, logLevel, bundlerName, _, ca, hooks);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-pilet.js","sourceRoot":"","sources":["../../src/apps/publish-pilet.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"publish-pilet.js","sourceRoot":"","sources":["../../src/apps/publish-pilet.ts"],"names":[],"mappings":";;;AAAA,+BAAyC;AACzC,oCAA4F;AAC5F,sCAgBmB;AAyFN,QAAA,oBAAoB,GAAwB;IACvD,GAAG,EAAE,SAAS;IACd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,CAAC,CAAC;aACjD;iBAAM;gBACL,IAAA,YAAG,EAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;aACtC;SACF;aAAM;YACL,IAAA,YAAG,EAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;SACpC;QAED,IAAA,YAAG,EAAC,mBAAmB,EAAE,8BAA8B,CAAC,CAAC;KAC1D;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,iBAAiB,CAAC,MAAM,EAAE;QAC7C,IAAA,gBAAO,EAAC,kCAAkC,CAAC,CAAC;KAC7C;SAAM;QACL,IAAA,aAAI,EAAC,sBAAsB,CAAC,CAAC;KAC9B;AACH,CAAC;AA9ED,oCA8EC"}
|
|
@@ -16,21 +16,14 @@ exports.publishPiralDefaults = {
|
|
|
16
16
|
headers: {},
|
|
17
17
|
};
|
|
18
18
|
async function publishPiral(baseDir = process.cwd(), options = {}) {
|
|
19
|
-
const { source = exports.publishPiralDefaults.source, logLevel = exports.publishPiralDefaults.logLevel, interactive = exports.publishPiralDefaults.interactive, fresh = exports.publishPiralDefaults.fresh, url = common_1.config.url ?? exports.publishPiralDefaults.url, apiKey = common_1.config.apiKeys?.[url] ?? common_1.config.apiKey ?? exports.publishPiralDefaults.apiKey, cert =
|
|
19
|
+
const { source = exports.publishPiralDefaults.source, logLevel = exports.publishPiralDefaults.logLevel, interactive = exports.publishPiralDefaults.interactive, fresh = exports.publishPiralDefaults.fresh, url = common_1.config.url ?? exports.publishPiralDefaults.url, apiKey = common_1.config.apiKeys?.[url] ?? common_1.config.apiKey ?? exports.publishPiralDefaults.apiKey, cert = exports.publishPiralDefaults.cert, headers = exports.publishPiralDefaults.headers, mode = exports.publishPiralDefaults.mode, _ = {}, hooks = {}, bundlerName, } = options;
|
|
20
20
|
const fullBase = (0, path_1.resolve)(process.cwd(), baseDir);
|
|
21
21
|
(0, common_1.setLogLevel)(logLevel);
|
|
22
22
|
(0, common_1.progress)('Reading configuration ...');
|
|
23
23
|
if (!url) {
|
|
24
24
|
(0, common_1.fail)('missingPiletFeedUrl_0060');
|
|
25
25
|
}
|
|
26
|
-
(0, common_1.
|
|
27
|
-
let ca = undefined;
|
|
28
|
-
if (await (0, common_1.checkExists)(cert)) {
|
|
29
|
-
const dir = (0, path_1.dirname)(cert);
|
|
30
|
-
const file = (0, path_1.basename)(cert);
|
|
31
|
-
(0, common_1.log)('generalDebug_0003', `Reading certificate file "${file}" from "${dir}".`);
|
|
32
|
-
ca = await (0, common_1.readBinary)(dir, file);
|
|
33
|
-
}
|
|
26
|
+
const ca = await (0, common_1.getCertificate)(cert);
|
|
34
27
|
(0, common_1.log)('generalDebug_0003', 'Getting the files ...');
|
|
35
28
|
const entryFiles = await (0, common_1.retrievePiralRoot)(fullBase, './');
|
|
36
29
|
const { name, root, ignored, externals, scripts, emulator = common_1.emulatorPackageName, } = await (0, common_1.retrievePiletsInfo)(entryFiles);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-piral.js","sourceRoot":"","sources":["../../src/apps/publish-piral.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"publish-piral.js","sourceRoot":"","sources":["../../src/apps/publish-piral.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,oCAAoD;AACpD,sCAoBmB;AAsEN,QAAA,oBAAoB,GAAwB;IACvD,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,iBAAS,CAAC,IAAI;IACxB,GAAG,EAAE,SAAS;IACd,WAAW,EAAE,KAAK;IAClB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,EAAE;CACZ,CAAC;AAEK,KAAK,UAAU,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,UAA+B,EAAE;IAC3F,MAAM,EACJ,MAAM,GAAG,4BAAoB,CAAC,MAAM,EACpC,QAAQ,GAAG,4BAAoB,CAA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,QAAQ,EAAE;QACnB,IAAA,YAAG,EAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;KACtC;IAED,IAAA,iBAAQ,EAAC,yBAAyB,CAAC,CAAC;IAEpC,IAAA,gBAAO,EAAC,kCAAkC,CAAC,CAAC;AAC9C,CAAC;AA9FD,oCA8FC"}
|
package/lib/common/config.d.ts
CHANGED
package/lib/common/config.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.config = void 0;
|
|
3
|
+
exports.updateConfig = exports.config = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
4
7
|
const constants_1 = require("./constants");
|
|
5
8
|
const external_1 = require("../external");
|
|
6
|
-
exports.config = (0, external_1.rc)(
|
|
9
|
+
exports.config = (0, external_1.rc)(constants_1.appName, {
|
|
7
10
|
apiKey: undefined,
|
|
8
11
|
apiKeys: {},
|
|
9
12
|
auth: {},
|
|
@@ -20,4 +23,27 @@ exports.config = (0, external_1.rc)('piral', {
|
|
|
20
23
|
host: 'localhost',
|
|
21
24
|
registry: constants_1.defaultRegistry,
|
|
22
25
|
}, {});
|
|
26
|
+
function mergeConfig(existing, area, value) {
|
|
27
|
+
const current = existing[area];
|
|
28
|
+
// update already existing config
|
|
29
|
+
Object.assign(existing, {
|
|
30
|
+
[area]: typeof current === 'object'
|
|
31
|
+
? {
|
|
32
|
+
...current,
|
|
33
|
+
...value,
|
|
34
|
+
}
|
|
35
|
+
: value,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function updateConfig(area, value) {
|
|
39
|
+
// update already existing config
|
|
40
|
+
mergeConfig(exports.config, area, value);
|
|
41
|
+
// update user-global config
|
|
42
|
+
const path = (0, path_1.resolve)((0, os_1.homedir)(), `.${constants_1.appName}rc`);
|
|
43
|
+
const content = await (0, promises_1.readFile)(path, 'utf8').catch(() => '{}');
|
|
44
|
+
const configFile = JSON.parse(content);
|
|
45
|
+
mergeConfig(configFile, area, value);
|
|
46
|
+
await (0, promises_1.writeFile)(path, JSON.stringify(configFile, undefined, 2), 'utf8');
|
|
47
|
+
}
|
|
48
|
+
exports.updateConfig = updateConfig;
|
|
23
49
|
//# sourceMappingURL=config.js.map
|
package/lib/common/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/common/config.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/common/config.ts"],"names":[],"mappings":";;;AAAA,2BAA6B;AAC7B,+BAA+B;AAC/B,0CAAkD;AAClD,2CAAuD;AACvD,0CAAiC;AAqEpB,QAAA,MAAM,GAAmB,IAAA,aAAE,EACtC,mBAAO,EACP;IACE,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,SAAS;IACf,SAAS,EAAE,KAAc;IACzB,OAAO,EAAE,UAAmB;IAC5B,QAAQ,EAAE,aAAa;IACvB,UAAU,EAAE,EAAE;IACd,aAAa,EAAE,IAAa;IAC5B,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,IAAa;IACvB,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,2BAAe;CAC1B,EACD,EAAE,CACH,CAAC;AAEF,SAAS,WAAW,CAClB,QAAwB,EACxB,IAAO,EACP,KAAiC;IAEjC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE/B,iCAAiC;IACjC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;QACtB,CAAC,IAAI,CAAC,EACJ,OAAO,OAAO,KAAK,QAAQ;YACzB,CAAC,CAAC;gBACE,GAAG,OAAO;gBACV,GAAG,KAAK;aACT;YACH,CAAC,CAAC,KAAK;KACZ,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,YAAY,CAAiC,IAAO,EAAE,KAAiC;IAC3G,iCAAiC;IACjC,WAAW,CAAC,cAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAEjC,4BAA4B;IAC5B,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,IAAA,YAAO,GAAE,EAAE,IAAI,mBAAO,IAAI,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvC,WAAW,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC1E,CAAC;AAVD,oCAUC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const defaultRegistry = "https://registry.npmjs.org/";
|
|
2
2
|
export declare const filesTar = "files";
|
|
3
|
+
export declare const appName = "piral";
|
|
3
4
|
export declare const packageJson = "package.json";
|
|
4
5
|
export declare const piralJson = "piral.json";
|
|
5
6
|
export declare const piletJson = "pilet.json";
|
package/lib/common/constants.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.legacyCoreExternals = exports.declarationEntryExtensions = exports.bundlerNames = exports.entryModuleExtensions = exports.piralJsonSchemaUrl = exports.piletJsonSchemaUrl = exports.frameworkLibs = exports.emulatorWebsiteName = exports.emulatorSourcesName = exports.emulatorPackageName = exports.emulatorName = exports.emulatorJson = exports.releaseName = exports.allName = exports.defaultSchemaVersion = exports.piralBaseRoot = exports.filesOnceTar = exports.piletJson = exports.piralJson = exports.packageJson = exports.filesTar = exports.defaultRegistry = void 0;
|
|
3
|
+
exports.legacyCoreExternals = exports.declarationEntryExtensions = exports.bundlerNames = exports.entryModuleExtensions = exports.piralJsonSchemaUrl = exports.piletJsonSchemaUrl = exports.frameworkLibs = exports.emulatorWebsiteName = exports.emulatorSourcesName = exports.emulatorPackageName = exports.emulatorName = exports.emulatorJson = exports.releaseName = exports.allName = exports.defaultSchemaVersion = exports.piralBaseRoot = exports.filesOnceTar = exports.piletJson = exports.piralJson = exports.packageJson = exports.appName = exports.filesTar = exports.defaultRegistry = void 0;
|
|
4
4
|
exports.defaultRegistry = 'https://registry.npmjs.org/';
|
|
5
5
|
exports.filesTar = 'files';
|
|
6
|
+
exports.appName = 'piral';
|
|
6
7
|
exports.packageJson = 'package.json';
|
|
7
8
|
exports.piralJson = 'piral.json';
|
|
8
9
|
exports.piletJson = 'pilet.json';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,6BAA6B,CAAC;AAChD,QAAA,QAAQ,GAAG,OAAO,CAAC;AACnB,QAAA,WAAW,GAAG,cAAc,CAAC;AAC7B,QAAA,SAAS,GAAG,YAAY,CAAC;AACzB,QAAA,SAAS,GAAG,YAAY,CAAC;AACzB,QAAA,YAAY,GAAG,YAAY,CAAC;AAC5B,QAAA,aAAa,GAAG,yBAAyB,CAAC;AAC1C,QAAA,oBAAoB,GAAG,IAAI,CAAC;AAC5B,QAAA,OAAO,GAAG,KAAK,CAAC;AAChB,QAAA,WAAW,GAAG,SAAS,CAAC;AACxB,QAAA,YAAY,GAAG,eAAe,CAAC;AAC/B,QAAA,YAAY,GAAG,UAAU,CAAC;AAC1B,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAChC,QAAA,mBAAm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AA,YAAY,GAAG,UAAU,CAAC;AAC1B,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAChC,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAChC,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAChC,QAAA,aAAa,GAAG,CAAC,OAAgB,EAAE,YAAqB,EAAE,YAAqB,CAAC,CAAC;AACjF,QAAA,kBAAkB,GAAG,6CAA6C,CAAC;AACnE,QAAA,kBAAkB,GAAG,6CAA6C,CAAC;AACnE,QAAA,qBAAqB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACvD,QAAA,YAAY,GAAG;IAC1B,KAAc;IACd,SAAkB;IAClB,QAAiB;IACjB,SAAkB;IAClB,QAAiB;IACjB,QAAiB;IACjB,SAAkB;IAClB,UAAmB;IACnB,MAAe;IACf,QAAiB;CAClB,CAAC;AACW,QAAA,0BAA0B,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,6BAAqB,CAAC,CAAC;AACzE,QAAA,mBAAmB,GAAG;IACjC,sBAAsB;IACtB,aAAa;IACb,SAAS;IACT,OAAO;IACP,WAAW;IACX,cAAc;IACd,kBAAkB;IAClB,OAAO;IACP,gBAAgB;CACjB,CAAC"}
|
package/lib/common/http.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Agent } from 'https';
|
|
4
|
+
import { FormData } from '../external';
|
|
2
5
|
import { PublishScheme } from '../types';
|
|
3
6
|
export declare function getAxiosOptions(url: string): {
|
|
4
7
|
headers: {
|
|
@@ -15,12 +18,20 @@ export declare function getAxiosOptions(url: string): {
|
|
|
15
18
|
headers?: undefined;
|
|
16
19
|
auth?: undefined;
|
|
17
20
|
};
|
|
21
|
+
export declare function getCertificate(cert?: string): Promise<Buffer>;
|
|
22
|
+
export declare function getAuthorizationHeaders(scheme: PublishScheme, key: string): {
|
|
23
|
+
authorization: string;
|
|
24
|
+
} | {
|
|
25
|
+
authorization?: undefined;
|
|
26
|
+
};
|
|
18
27
|
export declare function downloadFile(target: string, ca?: Buffer): Promise<Array<string>>;
|
|
28
|
+
export type FormDataObj = Record<string, string | number | boolean | [Buffer, string]>;
|
|
29
|
+
export declare function createAxiosForm(formData: FormDataObj): FormData;
|
|
30
|
+
export declare function handleAxiosError(error: any, interactive: boolean, httpsAgent: Agent, refetch: (mode: PublishScheme, key: string) => Promise<any>, onfail?: (status: number, statusText: string, response: string) => any): any;
|
|
19
31
|
export interface PostFormResult {
|
|
20
32
|
status: number;
|
|
21
33
|
success: boolean;
|
|
22
34
|
response?: object;
|
|
23
35
|
}
|
|
24
|
-
export type FormDataObj = Record<string, string | number | boolean | [Buffer, string]>;
|
|
25
36
|
export declare function postForm(target: string, scheme: PublishScheme, key: string, formData: FormDataObj, customHeaders?: Record<string, string>, ca?: Buffer, interactive?: boolean): Promise<PostFormResult>;
|
|
26
37
|
export declare function postFile(target: string, scheme: PublishScheme, key: string, file: Buffer, customFields?: Record<string, string>, customHeaders?: Record<string, string>, ca?: Buffer, interactive?: boolean): Promise<PostFormResult>;
|
package/lib/common/http.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postFile = exports.postForm = exports.downloadFile = exports.getAxiosOptions = void 0;
|
|
3
|
+
exports.postFile = exports.postForm = exports.handleAxiosError = exports.createAxiosForm = exports.downloadFile = exports.getAuthorizationHeaders = exports.getCertificate = exports.getAxiosOptions = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const https_1 = require("https");
|
|
6
6
|
const os_1 = require("os");
|
|
@@ -8,6 +8,7 @@ const fs_1 = require("fs");
|
|
|
8
8
|
const log_1 = require("./log");
|
|
9
9
|
const config_1 = require("./config");
|
|
10
10
|
const info_1 = require("./info");
|
|
11
|
+
const io_1 = require("./io");
|
|
11
12
|
const interactive_1 = require("./interactive");
|
|
12
13
|
const external_1 = require("../external");
|
|
13
14
|
function getMessage(body) {
|
|
@@ -59,6 +60,42 @@ function getAxiosOptions(url) {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
exports.getAxiosOptions = getAxiosOptions;
|
|
63
|
+
async function getCertificate(cert = config_1.config.cert) {
|
|
64
|
+
(0, log_1.log)('generalDebug_0003', 'Checking if certificate exists.');
|
|
65
|
+
if (await (0, io_1.checkExists)(cert)) {
|
|
66
|
+
const dir = (0, path_1.dirname)(cert);
|
|
67
|
+
const file = (0, path_1.basename)(cert);
|
|
68
|
+
(0, log_1.log)('generalDebug_0003', `Reading certificate file "${file}" from "${dir}".`);
|
|
69
|
+
return await (0, io_1.readBinary)(dir, file);
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
exports.getCertificate = getCertificate;
|
|
74
|
+
function getAuthorizationHeaders(scheme, key) {
|
|
75
|
+
if (key) {
|
|
76
|
+
switch (scheme) {
|
|
77
|
+
case 'basic':
|
|
78
|
+
return {
|
|
79
|
+
authorization: `Basic ${key}`,
|
|
80
|
+
};
|
|
81
|
+
case 'bearer':
|
|
82
|
+
return {
|
|
83
|
+
authorization: `Bearer ${key}`,
|
|
84
|
+
};
|
|
85
|
+
case 'digest':
|
|
86
|
+
return {
|
|
87
|
+
authorization: `Digest ${key}`,
|
|
88
|
+
};
|
|
89
|
+
case 'none':
|
|
90
|
+
default:
|
|
91
|
+
return {
|
|
92
|
+
authorization: key,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
exports.getAuthorizationHeaders = getAuthorizationHeaders;
|
|
62
99
|
function downloadFile(target, ca) {
|
|
63
100
|
const httpsAgent = ca ? new https_1.Agent({ ca }) : undefined;
|
|
64
101
|
return external_1.axios.default
|
|
@@ -79,8 +116,7 @@ function downloadFile(target, ca) {
|
|
|
79
116
|
});
|
|
80
117
|
}
|
|
81
118
|
exports.downloadFile = downloadFile;
|
|
82
|
-
function
|
|
83
|
-
const httpsAgent = ca ? new https_1.Agent({ ca }) : undefined;
|
|
119
|
+
function createAxiosForm(formData) {
|
|
84
120
|
const form = new external_1.FormData();
|
|
85
121
|
Object.keys(formData).forEach((key) => {
|
|
86
122
|
const value = formData[key];
|
|
@@ -94,91 +130,92 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
|
|
|
94
130
|
// unknown value - skip for now
|
|
95
131
|
}
|
|
96
132
|
});
|
|
133
|
+
return form;
|
|
134
|
+
}
|
|
135
|
+
exports.createAxiosForm = createAxiosForm;
|
|
136
|
+
function handleAxiosError(error, interactive, httpsAgent, refetch, onfail) {
|
|
137
|
+
if (!onfail) {
|
|
138
|
+
onfail = () => {
|
|
139
|
+
throw error;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (error.response) {
|
|
143
|
+
// The request was made and the server responded with a status code
|
|
144
|
+
// that falls out of the range of 2xx
|
|
145
|
+
const { data, statusText, status } = error.response;
|
|
146
|
+
if (interactive && 'interactiveAuth' in data) {
|
|
147
|
+
const { interactiveAuth } = data;
|
|
148
|
+
if (typeof interactiveAuth === 'string') {
|
|
149
|
+
(0, log_1.log)('generalDebug_0003', `Received status "${status}" from HTTP - trying interactive log in to "${interactiveAuth}".`);
|
|
150
|
+
return (0, interactive_1.getTokenInteractively)(interactiveAuth, httpsAgent).then(({ mode, token }) => refetch(mode, token));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const message = getMessage(data) || '';
|
|
154
|
+
return onfail(status, statusText, message);
|
|
155
|
+
}
|
|
156
|
+
else if (error.isAxiosError) {
|
|
157
|
+
// axios initiated error: try to parse message from error object
|
|
158
|
+
let errorMessage = error.errno || 'Unknown Axios Error';
|
|
159
|
+
if (typeof error.toJSON === 'function') {
|
|
160
|
+
const errorObj = error.toJSON();
|
|
161
|
+
errorMessage = errorObj?.message ?? errorMessage;
|
|
162
|
+
}
|
|
163
|
+
return onfail(500, undefined, errorMessage);
|
|
164
|
+
}
|
|
165
|
+
else if (error.request) {
|
|
166
|
+
// The request was made but no response was received
|
|
167
|
+
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
168
|
+
// http.ClientRequest in node.js
|
|
169
|
+
return onfail(500, undefined, error.request);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
// Something happened in setting up the request that triggered an Error
|
|
173
|
+
return onfail(500, undefined, error.message);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.handleAxiosError = handleAxiosError;
|
|
177
|
+
async function postForm(target, scheme, key, formData, customHeaders = {}, ca, interactive = false) {
|
|
178
|
+
const httpsAgent = ca ? new https_1.Agent({ ca }) : undefined;
|
|
179
|
+
const form = createAxiosForm(formData);
|
|
97
180
|
const headers = {
|
|
98
181
|
...form.getHeaders(),
|
|
99
182
|
...info_1.standardHeaders,
|
|
100
183
|
...customHeaders,
|
|
184
|
+
...getAuthorizationHeaders(scheme, key),
|
|
101
185
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
break;
|
|
110
|
-
case 'digest':
|
|
111
|
-
headers.authorization = `Digest ${key}`;
|
|
112
|
-
break;
|
|
113
|
-
case 'none':
|
|
114
|
-
default:
|
|
115
|
-
headers.authorization = key;
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return external_1.axios.default
|
|
120
|
-
.post(target, form, {
|
|
121
|
-
headers,
|
|
122
|
-
httpsAgent,
|
|
123
|
-
maxContentLength: Infinity,
|
|
124
|
-
maxBodyLength: Infinity,
|
|
125
|
-
})
|
|
126
|
-
.then((res) => {
|
|
186
|
+
try {
|
|
187
|
+
const res = await external_1.axios.default.post(target, form, {
|
|
188
|
+
headers,
|
|
189
|
+
httpsAgent,
|
|
190
|
+
maxContentLength: Infinity,
|
|
191
|
+
maxBodyLength: Infinity,
|
|
192
|
+
});
|
|
127
193
|
return {
|
|
128
194
|
status: res.status,
|
|
129
195
|
success: true,
|
|
130
196
|
response: res.data,
|
|
131
197
|
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
return await handleAxiosError(error, interactive, httpsAgent, (mode, token) => postForm(target, mode, token, formData, customHeaders, ca, false), (status, statusText, response) => {
|
|
201
|
+
if (status === 500) {
|
|
202
|
+
(0, log_1.log)('failedHttpPost_0065', response);
|
|
203
|
+
return {
|
|
204
|
+
status: 500,
|
|
205
|
+
success: false,
|
|
206
|
+
response: undefined,
|
|
207
|
+
};
|
|
143
208
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
else if (error.isAxiosError) {
|
|
153
|
-
// axios initiated error: try to parse message from error object
|
|
154
|
-
let errorMessage = error.errno || 'Unknown Axios Error';
|
|
155
|
-
if (typeof error.toJSON === 'function') {
|
|
156
|
-
const errorObj = error.toJSON();
|
|
157
|
-
errorMessage = errorObj?.message ?? errorMessage;
|
|
209
|
+
else {
|
|
210
|
+
(0, log_1.log)('unsuccessfulHttpPost_0066', statusText, status, response);
|
|
211
|
+
return {
|
|
212
|
+
status,
|
|
213
|
+
success: false,
|
|
214
|
+
response,
|
|
215
|
+
};
|
|
158
216
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
status: 500,
|
|
162
|
-
success: false,
|
|
163
|
-
response: errorMessage,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
else if (error.request) {
|
|
167
|
-
// The request was made but no response was received
|
|
168
|
-
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
169
|
-
// http.ClientRequest in node.js
|
|
170
|
-
(0, log_1.log)('failedHttpPost_0065', error.request);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// Something happened in setting up the request that triggered an Error
|
|
174
|
-
(0, log_1.log)('failedHttpPost_0065', error.message);
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
status: 500,
|
|
178
|
-
success: false,
|
|
179
|
-
response: undefined,
|
|
180
|
-
};
|
|
181
|
-
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
182
219
|
}
|
|
183
220
|
exports.postForm = postForm;
|
|
184
221
|
function postFile(target, scheme, key, file, customFields = {}, customHeaders = {}, ca, interactive = false) {
|
package/lib/common/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/common/http.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/common/http.ts"],"names":[],"mappings":";;;AAAA,+BAA+C;AAC/C,iCAA8B;AAE9B,2BAA4B;AAC5B,2BAAuC;AACvC,+BAA4B;AAC5B,qCAAkC;AAClC,iCAAyC;AACzC,6BAA+C;AAC/C,+CAAsD;AACtD,0CAA8C;AAG9C,SAAS,UAAU,CAAC,IAAmC;IACrD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI;YACF,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjC,OAAO,OAAO,CAAC,OAAO,CAAC;SACxB;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,IAAI,CAAC;SACb;KACF;SAAM,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC3C,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB,OAAO,IAAI,CAAC,OAAO,CAAC;SACrB;aAAM;YACL,OAAO,IAAI,CAAC,SAAS,CAAC,IA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UAAU,EAAE,QAAQ,EAAE,EAAE;YAC/B,IAAI,MAAM,KAAK,GAAG,EAAE;gBAClB,IAAA,SAAG,EAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;gBACrC,OAAO;oBACL,MAAM,EAAE,GAAG;oBACX,OAAO,EAAE,KAAK;oBACd,QAAQ,EAAE,SAAS;iBACpB,CAAC;aACH;iBAAM;gBACL,IAAA,SAAG,EAAC,2BAA2B,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAC/D,OAAO;oBACL,MAAM;oBACN,OAAO,EAAE,KAAK;oBACd,QAAQ;iBACT,CAAC;aACH;QACH,CAAC,CACF,CAAC;KACH;AACH,CAAC;AAzDD,4BAyDC;AAED,SAAgB,QAAQ,CACtB,MAAc,EACd,MAAqB,EACrB,GAAW,EACX,IAAY,EACZ,eAAuC,EAAE,EACzC,gBAAwC,EAAE,EAC1C,EAAW,EACX,WAAW,GAAG,KAAK;IAEnB,MAAM,IAAI,GAAgB,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;IACzE,OAAO,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;AAC7E,CAAC;AAZD,4BAYC"}
|
|
@@ -58,9 +58,9 @@ function getTokenInteractively(url, httpsAgent) {
|
|
|
58
58
|
(0, browser_1.openBrowserAt)(loginUrl);
|
|
59
59
|
try {
|
|
60
60
|
while (true) {
|
|
61
|
-
const { data, status } = await external_1.axios.default.get(callbackUrl);
|
|
61
|
+
const { data, status } = await external_1.axios.default.get(callbackUrl, { httpsAgent, headers: info_1.standardHeaders });
|
|
62
62
|
if (status === 202) {
|
|
63
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
63
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
64
64
|
continue;
|
|
65
65
|
}
|
|
66
66
|
if (status === 200) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/common/interactive.ts"],"names":[],"mappings":";;;AACA,uCAA0C;AAC1C,iCAAyC;AACzC,+BAA4C;AAC5C,0CAA8C;AAG9C,SAAgB,YAAY,CAAC,OAAe,EAAE,MAAqB,EAAE,YAAoB;IACvF,MAAM,SAAS,GAAG;QAChB;YACE,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,MAAe;YACrB,OAAO,EAAE,MAAM;YACf,OAAO;YACP,OAAO,EAAE,YAAY;SACtB;KACF,CAAC;IACF,OAAO,mBAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC;AAXD,oCAWC;AAED,SAAgB,aAAa,CAAC,OAAe,EAAE,YAAqB;IAClE,MAAM,SAAS,GAAG;QAChB;YACE,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,SAAkB;YACxB,OAAO;YACP,OAAO,EAAE,YAAY;SACtB;KACF,CAAC;IACF,OAAO,mBAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC;AAVD,sCAUC;AAID,MAAM,eAAe,GAAgC,EAAE,CAAC;AAExD,SAAgB,qBAAqB,CAAC,GAAW,EAAE,UAAiB;IAClE,IAAI,CAAC,CAAC,GAAG,IAAI,eAAe,CAAC,EAAE;QAC7B,MAAM,SAAS,GAAG,IAAA,gBAAU,GAAE,CAAC;QAE/B,eAAe,CAAC,GAAG,CAAC,GAAG,gBAAK,CAAC,OAAO;aACjC,IAAI,CACH,GAAG,EACH;YACE,QAAQ,EAAE,WAAW;YACrB,UAAU,EAAE,WAAW;YACvB,WAAW,EAAE,sEAAsE;SACpF,EACD;YACE,OAA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G,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;YAEhE,IAAA,aAAO,EAAC,gEAAgE,IAAI,aAAa,IAAI,IAAI,CAAC,CAAC;YACnG,IAAA,aAAO,EAAC,KAAK,CAAC,CAAC;YACf,IAAA,aAAO,EAAC,QAAQ,CAAC,CAAC;YAClB,IAAA,aAAO,EAAC,KAAK,CAAC,CAAC;YAEf,IAAA,uBAAa,EAAC,QAAQ,CAAC,CAAC;YAExB,IAAI;gBACF,OAAO,IAAI,EAAE;oBACX,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,gBAAK,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,sBAAe,EAAE,CAAC,CAAC;oBAExG,IAAI,MAAM,KAAK,GAAG,EAAE;wBAClB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;wBAC1D,SAAS;qBACV;oBAED,IAAI,MAAM,KAAK,GAAG,EAAE;wBAClB,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC;qBACpB;oBAED,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;iBAC1E;aACF;YAAC,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE,CAAC;aACV;oBAAS;gBACR,SAAS,EAAE,CAAC;aACb;QACH,CAAC,CAAC,CAAC;KACN;IAED,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AAzDD,sDAyDC"}
|
package/lib/common/website.js
CHANGED
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.scaffoldFromEmulatorWebsite = exports.updateFromEmulatorWebsite = void 0;
|
|
4
|
+
const https_1 = require("https");
|
|
4
5
|
const path_1 = require("path");
|
|
5
6
|
const template_1 = require("./template");
|
|
6
7
|
const http_1 = require("./http");
|
|
7
8
|
const constants_1 = require("./constants");
|
|
9
|
+
const config_1 = require("./config");
|
|
8
10
|
const enums_1 = require("./enums");
|
|
9
11
|
const io_1 = require("./io");
|
|
10
12
|
const io_2 = require("./io");
|
|
11
13
|
const log_1 = require("./log");
|
|
12
14
|
const external_1 = require("../external");
|
|
13
|
-
function requestManifest(url) {
|
|
15
|
+
async function requestManifest(url, httpsAgent) {
|
|
14
16
|
const opts = (0, http_1.getAxiosOptions)(url);
|
|
15
|
-
|
|
17
|
+
try {
|
|
18
|
+
return await external_1.axios.default.get(url, { ...opts, httpsAgent });
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return await (0, http_1.handleAxiosError)(error, true, httpsAgent, async (mode, key) => {
|
|
22
|
+
const headers = (0, http_1.getAuthorizationHeaders)(mode, key);
|
|
23
|
+
if (headers.authorization) {
|
|
24
|
+
await (0, config_1.updateConfig)('auth', {
|
|
25
|
+
[url]: {
|
|
26
|
+
mode: 'header',
|
|
27
|
+
key: 'authorization',
|
|
28
|
+
value: headers.authorization,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return await external_1.axios.default.get(url, { headers, httpsAgent });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
16
35
|
}
|
|
17
|
-
async function downloadEmulatorFiles(manifestUrl, target, files) {
|
|
36
|
+
async function downloadEmulatorFiles(manifestUrl, target, files, httpsAgent) {
|
|
18
37
|
const requiredFiles = [files.typings, files.main, files.app];
|
|
19
38
|
const opts = (0, http_1.getAxiosOptions)(manifestUrl);
|
|
20
39
|
await Promise.all(requiredFiles.map(async (file) => {
|
|
21
40
|
const url = new URL(file, manifestUrl);
|
|
22
|
-
const res = await external_1.axios.default.get(url.href, { ...opts, responseType: 'arraybuffer' });
|
|
41
|
+
const res = await external_1.axios.default.get(url.href, { ...opts, httpsAgent, responseType: 'arraybuffer' });
|
|
23
42
|
const data = res.data;
|
|
24
43
|
await (0, io_1.writeBinary)(target, file, data);
|
|
25
44
|
}));
|
|
26
45
|
}
|
|
27
|
-
async function createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson) {
|
|
46
|
+
async function createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson, httpsAgent) {
|
|
28
47
|
const mainFile = 'index.js';
|
|
29
48
|
const appDirName = (0, path_1.relative)(targetDir, appDir);
|
|
30
49
|
await (0, io_2.writeJson)(targetDir, constants_1.packageJson, {
|
|
@@ -52,12 +71,14 @@ async function createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson)
|
|
|
52
71
|
name: emulatorJson.name,
|
|
53
72
|
outFile: emulatorJson.files.main,
|
|
54
73
|
});
|
|
55
|
-
await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files);
|
|
74
|
+
await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files, httpsAgent);
|
|
56
75
|
}
|
|
57
76
|
async function updateFromEmulatorWebsite(targetDir, manifestUrl) {
|
|
58
77
|
(0, log_1.progress)(`Updating emulator from %s ...`, manifestUrl);
|
|
78
|
+
const ca = await (0, http_1.getCertificate)();
|
|
79
|
+
const httpsAgent = ca ? new https_1.Agent({ ca }) : undefined;
|
|
59
80
|
try {
|
|
60
|
-
const response = await requestManifest(manifestUrl);
|
|
81
|
+
const response = await requestManifest(manifestUrl, httpsAgent);
|
|
61
82
|
const nextEmulator = response.data;
|
|
62
83
|
const currentEmulator = await (0, io_1.readJson)(targetDir, constants_1.packageJson);
|
|
63
84
|
if (currentEmulator.name !== nextEmulator.name) {
|
|
@@ -66,7 +87,7 @@ async function updateFromEmulatorWebsite(targetDir, manifestUrl) {
|
|
|
66
87
|
else if (currentEmulator.piralCLI.timstamp !== nextEmulator.timestamp) {
|
|
67
88
|
(0, log_1.log)('generalDebug_0003', `The timestamp on "${currentEmulator.name}" is different (${nextEmulator.timestamp}).`);
|
|
68
89
|
const appDir = (0, path_1.resolve)(targetDir, 'app');
|
|
69
|
-
await createEmulatorFiles(targetDir, appDir, manifestUrl, nextEmulator);
|
|
90
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, nextEmulator, httpsAgent);
|
|
70
91
|
}
|
|
71
92
|
else {
|
|
72
93
|
(0, log_1.log)('generalDebug_0003', `Nothing to update for "${currentEmulator.name}".`);
|
|
@@ -80,12 +101,14 @@ async function updateFromEmulatorWebsite(targetDir, manifestUrl) {
|
|
|
80
101
|
exports.updateFromEmulatorWebsite = updateFromEmulatorWebsite;
|
|
81
102
|
async function scaffoldFromEmulatorWebsite(rootDir, manifestUrl) {
|
|
82
103
|
(0, log_1.progress)(`Downloading emulator from %s ...`, manifestUrl);
|
|
83
|
-
const
|
|
104
|
+
const ca = await (0, http_1.getCertificate)();
|
|
105
|
+
const httpsAgent = ca ? new https_1.Agent({ ca }) : undefined;
|
|
106
|
+
const response = await requestManifest(manifestUrl, httpsAgent);
|
|
84
107
|
const emulatorJson = response.data;
|
|
85
108
|
const targetDir = (0, path_1.resolve)(rootDir, 'node_modules', emulatorJson.name);
|
|
86
109
|
const appDir = (0, path_1.resolve)(targetDir, 'app');
|
|
87
110
|
await (0, io_1.createDirectory)(appDir);
|
|
88
|
-
await createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson);
|
|
111
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson, httpsAgent);
|
|
89
112
|
return { name: emulatorJson.name, path: targetDir };
|
|
90
113
|
}
|
|
91
114
|
exports.scaffoldFromEmulatorWebsite = scaffoldFromEmulatorWebsite;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"website.js","sourceRoot":"","sources":["../../src/common/website.ts"],"names":[],"mappings":";;;AAAA,+BAA+C;AAC/C,yCAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"website.js","sourceRoot":"","sources":["../../src/common/website.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,+BAA+C;AAC/C,yCA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BAAe,EAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IACpF,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AACtD,CAAC;AAXD,kEAWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-cli",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.6744",
|
|
4
4
|
"description": "The standard CLI for creating and building a Piral instance or a Pilet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"typescript": "^5.0.0",
|
|
82
82
|
"yargs": "^15.0.0"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "fd51003640999e348b3058df033bbbaf03fcd6ec"
|
|
85
85
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { relative,
|
|
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 =
|
|
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
|
-
|
|
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 {
|
|
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 =
|
|
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
|
-
|
|
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) {
|
package/src/common/config.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
+
}
|
package/src/common/constants.ts
CHANGED
package/src/common/http.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
122
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
204
|
-
|
|
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
|
|
package/src/common/website.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { Agent } from 'https';
|
|
1
2
|
import { join, relative, resolve } from 'path';
|
|
2
3
|
import { createPiralStubIndexIfNotExists } from './template';
|
|
3
|
-
import { getAxiosOptions } from './http';
|
|
4
|
+
import { getAuthorizationHeaders, getAxiosOptions, getCertificate, handleAxiosError } from './http';
|
|
4
5
|
import { packageJson } from './constants';
|
|
6
|
+
import { updateConfig } from './config';
|
|
5
7
|
import { ForceOverwrite } from './enums';
|
|
6
8
|
import { createDirectory, readJson, writeBinary } from './io';
|
|
7
9
|
import { writeJson } from './io';
|
|
@@ -9,19 +11,43 @@ import { progress, log } from './log';
|
|
|
9
11
|
import { axios } from '../external';
|
|
10
12
|
import { EmulatorWebsiteManifestFiles, EmulatorWebsiteManifest } from '../types';
|
|
11
13
|
|
|
12
|
-
function requestManifest(url: string) {
|
|
14
|
+
async function requestManifest(url: string, httpsAgent?: Agent) {
|
|
13
15
|
const opts = getAxiosOptions(url);
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
return await axios.default.get(url, { ...opts, httpsAgent });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return await handleAxiosError(error, true, httpsAgent, async (mode, key) => {
|
|
21
|
+
const headers = getAuthorizationHeaders(mode, key);
|
|
22
|
+
|
|
23
|
+
if (headers.authorization) {
|
|
24
|
+
await updateConfig('auth', {
|
|
25
|
+
[url]: {
|
|
26
|
+
mode: 'header',
|
|
27
|
+
key: 'authorization',
|
|
28
|
+
value: headers.authorization,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return await axios.default.get(url, { headers, httpsAgent });
|
|
34
|
+
});
|
|
35
|
+
}
|
|
15
36
|
}
|
|
16
37
|
|
|
17
|
-
async function downloadEmulatorFiles(
|
|
38
|
+
async function downloadEmulatorFiles(
|
|
39
|
+
manifestUrl: string,
|
|
40
|
+
target: string,
|
|
41
|
+
files: EmulatorWebsiteManifestFiles,
|
|
42
|
+
httpsAgent?: Agent,
|
|
43
|
+
) {
|
|
18
44
|
const requiredFiles = [files.typings, files.main, files.app];
|
|
19
45
|
const opts = getAxiosOptions(manifestUrl);
|
|
20
46
|
|
|
21
47
|
await Promise.all(
|
|
22
48
|
requiredFiles.map(async (file) => {
|
|
23
49
|
const url = new URL(file, manifestUrl);
|
|
24
|
-
const res = await axios.default.get(url.href, { ...opts, responseType: 'arraybuffer' });
|
|
50
|
+
const res = await axios.default.get(url.href, { ...opts, httpsAgent, responseType: 'arraybuffer' });
|
|
25
51
|
const data: Buffer = res.data;
|
|
26
52
|
await writeBinary(target, file, data);
|
|
27
53
|
}),
|
|
@@ -33,6 +59,7 @@ async function createEmulatorFiles(
|
|
|
33
59
|
appDir: string,
|
|
34
60
|
manifestUrl: string,
|
|
35
61
|
emulatorJson: EmulatorWebsiteManifest,
|
|
62
|
+
httpsAgent?: Agent,
|
|
36
63
|
) {
|
|
37
64
|
const mainFile = 'index.js';
|
|
38
65
|
const appDirName = relative(targetDir, appDir);
|
|
@@ -69,14 +96,16 @@ async function createEmulatorFiles(
|
|
|
69
96
|
outFile: emulatorJson.files.main,
|
|
70
97
|
});
|
|
71
98
|
|
|
72
|
-
await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files);
|
|
99
|
+
await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files, httpsAgent);
|
|
73
100
|
}
|
|
74
101
|
|
|
75
102
|
export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl: string) {
|
|
76
103
|
progress(`Updating emulator from %s ...`, manifestUrl);
|
|
104
|
+
const ca = await getCertificate();
|
|
105
|
+
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
77
106
|
|
|
78
107
|
try {
|
|
79
|
-
const response = await requestManifest(manifestUrl);
|
|
108
|
+
const response = await requestManifest(manifestUrl, httpsAgent);
|
|
80
109
|
const nextEmulator: EmulatorWebsiteManifest = response.data;
|
|
81
110
|
const currentEmulator = await readJson(targetDir, packageJson);
|
|
82
111
|
|
|
@@ -85,7 +114,7 @@ export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl:
|
|
|
85
114
|
} else if (currentEmulator.piralCLI.timstamp !== nextEmulator.timestamp) {
|
|
86
115
|
log('generalDebug_0003', `The timestamp on "${currentEmulator.name}" is different (${nextEmulator.timestamp}).`);
|
|
87
116
|
const appDir = resolve(targetDir, 'app');
|
|
88
|
-
await createEmulatorFiles(targetDir, appDir, manifestUrl, nextEmulator);
|
|
117
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, nextEmulator, httpsAgent);
|
|
89
118
|
} else {
|
|
90
119
|
log('generalDebug_0003', `Nothing to update for "${currentEmulator.name}".`);
|
|
91
120
|
}
|
|
@@ -97,11 +126,13 @@ export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl:
|
|
|
97
126
|
|
|
98
127
|
export async function scaffoldFromEmulatorWebsite(rootDir: string, manifestUrl: string) {
|
|
99
128
|
progress(`Downloading emulator from %s ...`, manifestUrl);
|
|
100
|
-
const
|
|
129
|
+
const ca = await getCertificate();
|
|
130
|
+
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
131
|
+
const response = await requestManifest(manifestUrl, httpsAgent);
|
|
101
132
|
const emulatorJson: EmulatorWebsiteManifest = response.data;
|
|
102
133
|
const targetDir = resolve(rootDir, 'node_modules', emulatorJson.name);
|
|
103
134
|
const appDir = resolve(targetDir, 'app');
|
|
104
135
|
await createDirectory(appDir);
|
|
105
|
-
await createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson);
|
|
136
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson, httpsAgent);
|
|
106
137
|
return { name: emulatorJson.name, path: targetDir };
|
|
107
138
|
}
|