publish-microfrontend 1.7.2 → 1.7.3-beta.7564

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/index.js CHANGED
@@ -29772,8 +29772,16 @@ function getMessage(body) {
29772
29772
  }
29773
29773
  return "";
29774
29774
  }
29775
- async function downloadFile(url2, ca) {
29776
- const httpsAgent = ca ? new import_https2.Agent({ ca }) : void 0;
29775
+ function getAgent({ allowSelfSigned, ca }) {
29776
+ if (ca) {
29777
+ return new import_https2.Agent({ ca });
29778
+ } else if (allowSelfSigned) {
29779
+ return new import_https2.Agent({ rejectUnauthorized: false });
29780
+ } else {
29781
+ return void 0;
29782
+ }
29783
+ }
29784
+ async function downloadFile(url2, httpsAgent) {
29777
29785
  try {
29778
29786
  const res = await axios_default.get(url2, {
29779
29787
  responseType: "stream",
@@ -29787,8 +29795,7 @@ async function downloadFile(url2, ca) {
29787
29795
  return [];
29788
29796
  }
29789
29797
  }
29790
- function postForm(target, scheme, key, formData, customHeaders = {}, ca, interactive = false) {
29791
- const httpsAgent = ca ? new import_https2.Agent({ ca }) : void 0;
29798
+ function postForm(target, scheme, key, formData, customHeaders = {}, httpsAgent, interactive = false) {
29792
29799
  const form = new import_form_data2.default();
29793
29800
  Object.keys(formData).forEach((key2) => {
29794
29801
  const value = formData[key2];
@@ -29837,7 +29844,7 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29837
29844
  if (interactive && "interactiveAuth" in data) {
29838
29845
  const { interactiveAuth } = data;
29839
29846
  if (typeof interactiveAuth === "string") {
29840
- return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) => postForm(target, mode, token, formData, customHeaders, ca, false));
29847
+ return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) => postForm(target, mode, token, formData, customHeaders, httpsAgent, false));
29841
29848
  }
29842
29849
  }
29843
29850
  const message = getMessage(data) || "";
@@ -29871,9 +29878,9 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29871
29878
  };
29872
29879
  });
29873
29880
  }
29874
- function postFile(target, scheme, key, file, customFields = {}, customHeaders = {}, ca, interactive = false) {
29881
+ function postFile(target, scheme, key, file, customFields = {}, customHeaders = {}, agent, interactive = false) {
29875
29882
  const data = { ...customFields, file: [file, "microfrontend.tgz"] };
29876
- return postForm(target, scheme, key, data, customHeaders, ca, interactive);
29883
+ return postForm(target, scheme, key, data, customHeaders, agent, interactive);
29877
29884
  }
29878
29885
 
29879
29886
  // src/scripts.ts
@@ -29991,7 +29998,7 @@ async function getCa(cert) {
29991
29998
  }
29992
29999
  return void 0;
29993
30000
  }
29994
- async function getFiles(baseDir, sources, from, ca) {
30001
+ async function getFiles(baseDir, sources, from, agent) {
29995
30002
  switch (from) {
29996
30003
  case "local": {
29997
30004
  const allFiles = await Promise.all(sources.map((s) => matchFiles(baseDir, s)));
@@ -30025,12 +30032,12 @@ async function getFiles(baseDir, sources, from, ca) {
30025
30032
  return allMatches.filter(isFile2);
30026
30033
  }
30027
30034
  case "remote": {
30028
- const allFiles = await Promise.all(sources.map((s) => downloadFile(s, ca)));
30035
+ const allFiles = await Promise.all(sources.map((s) => downloadFile(s, agent)));
30029
30036
  return allFiles.reduce((result, files) => [...result, ...files], []);
30030
30037
  }
30031
30038
  case "npm": {
30032
30039
  const allUrls = await Promise.all(sources.map((s) => findTarball(s)));
30033
- const allFiles = await Promise.all(allUrls.map((url2) => downloadFile(url2, ca)));
30040
+ const allFiles = await Promise.all(allUrls.map((url2) => downloadFile(url2, agent)));
30034
30041
  return allFiles.reduce((result, files) => [...result, ...files], []);
30035
30042
  }
30036
30043
  }
@@ -30042,18 +30049,20 @@ var defaultArgs = (0, import_rc.default)("microfrontend", {
30042
30049
  url: void 0,
30043
30050
  apiKey: void 0,
30044
30051
  cert: void 0,
30052
+ allowSelfSigned: false,
30045
30053
  mode: "basic",
30046
30054
  from: "local",
30047
30055
  fields: {},
30048
30056
  headers: {},
30049
30057
  interactive: false
30050
30058
  });
30051
- var args = yargs.string("source").describe("source", "Sets the source of either the previously packed *.tgz bundle or the directory to publish.").default("source", current).string("url").describe("url", "Sets the explicit URL where to publish the micro frontend to.").default("url", defaultArgs.url).string("api-key").describe("api-key", "Sets the potential API key to send to the service.").default("api-key", defaultArgs.apiKey).string("cert").describe("cert", "Sets a custom certificate authority to use, if any.").default("cert", defaultArgs.cert).choices("mode", publishModeKeys).describe("mode", "Sets the authorization mode to use.").default("mode", defaultArgs.mode).alias("mode", "auth-mode").choices("from", fromKeys).describe("from", "Sets the type of the source to use for publishing.").default("from", defaultArgs.from).option("fields", void 0).describe("fields", "Sets additional fields to be included in the feed service request.").default("fields", defaultArgs.fields).option("headers", void 0).describe("headers", "Sets additional headers to be included in the feed service request.").default("headers", defaultArgs.headers).boolean("interactive").describe("interactive", "Defines if authorization tokens can be retrieved interactively.").default("interactive", defaultArgs.interactive).argv;
30059
+ var args = yargs.string("source").describe("source", "Sets the source of either the previously packed *.tgz bundle or the directory to publish.").default("source", current).string("url").describe("url", "Sets the explicit URL where to publish the micro frontend to.").default("url", defaultArgs.url).string("api-key").describe("api-key", "Sets the potential API key to send to the service.").default("api-key", defaultArgs.apiKey).string("cert").describe("cert", "Sets a custom certificate authority to use, if any.").default("cert", defaultArgs.cert).boolean("allow-self-signed").describe("allow-self-signed", "Indicates that self-signed certificates should be allowed.").default("allow-self-signed", defaultArgs.allowSelfSigned).choices("mode", publishModeKeys).describe("mode", "Sets the authorization mode to use.").default("mode", defaultArgs.mode).alias("mode", "auth-mode").choices("from", fromKeys).describe("from", "Sets the type of the source to use for publishing.").default("from", defaultArgs.from).option("fields", void 0).describe("fields", "Sets additional fields to be included in the feed service request.").default("fields", defaultArgs.fields).option("headers", void 0).describe("headers", "Sets additional headers to be included in the feed service request.").default("headers", defaultArgs.headers).boolean("interactive").describe("interactive", "Defines if authorization tokens can be retrieved interactively.").default("interactive", defaultArgs.interactive).argv;
30052
30060
  async function run() {
30053
- const { cert, source, from, url: url2, "api-key": apiKey, headers, fields, interactive, mode } = args;
30061
+ const { cert, source, from, url: url2, "api-key": apiKey, "allow-self-signed": allowSelfSigned, headers, fields, interactive, mode } = args;
30054
30062
  const sources = Array.isArray(source) ? source : [source];
30055
30063
  const ca = await getCa(cert);
30056
- const files = await getFiles(current, sources, from, ca);
30064
+ const agent = getAgent({ ca, allowSelfSigned });
30065
+ const files = await getFiles(current, sources, from, agent);
30057
30066
  const successfulUploads = [];
30058
30067
  if (files.length === 0) {
30059
30068
  fail("No micro frontends for publishing found: %s.", sources.join(", "));
@@ -30063,7 +30072,7 @@ async function run() {
30063
30072
  const content = await (0, import_promises2.readFile)(file);
30064
30073
  if (content) {
30065
30074
  progress(`Publishing "%s" ...`, file, url2);
30066
- const { success, status, response } = await postFile(url2, mode, apiKey, content, fields, headers, ca, interactive);
30075
+ const { success, status, response } = await postFile(url2, mode, apiKey, content, fields, headers, agent, interactive);
30067
30076
  const result = typeof response !== "string" ? JSON.stringify(response, void 0, 2) : response;
30068
30077
  if (success) {
30069
30078
  successfulUploads.push(file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publish-microfrontend",
3
- "version": "1.7.2",
3
+ "version": "1.7.3-beta.7564",
4
4
  "description": "A CLI for publishing micro frontends to a feed service.",
5
5
  "keywords": [
6
6
  "modules",
@@ -69,5 +69,5 @@
69
69
  "typescript": "^5.0.0",
70
70
  "yargs": "^15.0.0"
71
71
  },
72
- "gitHead": "79c505aaf4c6be1d279c1f554ab60321f9f5ef68"
72
+ "gitHead": "936744c565691e81a9e3ce914803c42ba369879c"
73
73
  }
package/src/http.ts CHANGED
@@ -34,10 +34,22 @@ export interface PostFormResult {
34
34
 
35
35
  export type FormDataObj = Record<string, string | [Buffer, string]>;
36
36
 
37
+ export interface AgentOptions {
38
+ ca?: Buffer;
39
+ allowSelfSigned?: boolean;
40
+ }
37
41
 
38
- export async function downloadFile(url: string, ca?: Buffer): Promise<Array<string>> {
39
- const httpsAgent = ca ? new Agent({ ca }) : undefined;
42
+ export function getAgent({ allowSelfSigned, ca }: AgentOptions) {
43
+ if (ca) {
44
+ return new Agent({ ca });
45
+ } else if (allowSelfSigned) {
46
+ return new Agent({ rejectUnauthorized: false });
47
+ } else {
48
+ return undefined;
49
+ }
50
+ }
40
51
 
52
+ export async function downloadFile(url: string, httpsAgent?: Agent): Promise<Array<string>> {
41
53
  try {
42
54
  const res = await axios.get<Stream>(url, {
43
55
  responseType: 'stream',
@@ -58,10 +70,9 @@ export function postForm(
58
70
  key: string,
59
71
  formData: FormDataObj,
60
72
  customHeaders: Record<string, string> = {},
61
- ca?: Buffer,
73
+ httpsAgent?: Agent,
62
74
  interactive = false,
63
75
  ): Promise<PostFormResult> {
64
- const httpsAgent = ca ? new Agent({ ca }) : undefined;
65
76
  const form = new FormData();
66
77
 
67
78
  Object.keys(formData).forEach((key) => {
@@ -124,7 +135,7 @@ export function postForm(
124
135
 
125
136
  if (typeof interactiveAuth === 'string') {
126
137
  return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
127
- postForm(target, mode, token, formData, customHeaders, ca, false),
138
+ postForm(target, mode, token, formData, customHeaders, httpsAgent, false),
128
139
  );
129
140
  }
130
141
  }
@@ -173,9 +184,9 @@ export function postFile(
173
184
  file: Buffer,
174
185
  customFields: Record<string, string> = {},
175
186
  customHeaders: Record<string, string> = {},
176
- ca?: Buffer,
187
+ agent?: Agent,
177
188
  interactive = false,
178
189
  ): Promise<PostFormResult> {
179
190
  const data: FormDataObj = { ...customFields, file: [file, 'microfrontend.tgz'] };
180
- return postForm(target, scheme, key, data, customHeaders, ca, interactive);
191
+ return postForm(target, scheme, key, data, customHeaders, agent, interactive);
181
192
  }
package/src/index.ts CHANGED
@@ -7,13 +7,14 @@ import { basename } from 'path';
7
7
  import { readFile } from 'fs/promises';
8
8
  import { progress, fail, logDone, logFail, logInfo } from './log';
9
9
  import { getCa, getFiles } from './utils';
10
- import { postFile } from './http';
10
+ import { getAgent, postFile } from './http';
11
11
 
12
12
  const current = process.cwd();
13
13
  const defaultArgs = rc('microfrontend', {
14
14
  url: undefined,
15
15
  apiKey: undefined,
16
16
  cert: undefined,
17
+ allowSelfSigned: false,
17
18
  mode: 'basic',
18
19
  from: 'local',
19
20
  fields: {},
@@ -34,6 +35,9 @@ const args = yargs
34
35
  .string('cert')
35
36
  .describe('cert', 'Sets a custom certificate authority to use, if any.')
36
37
  .default('cert', defaultArgs.cert)
38
+ .boolean('allow-self-signed')
39
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
40
+ .default('allow-self-signed', defaultArgs.allowSelfSigned)
37
41
  .choices('mode', publishModeKeys)
38
42
  .describe('mode', 'Sets the authorization mode to use.')
39
43
  .default('mode', defaultArgs.mode)
@@ -52,10 +56,11 @@ const args = yargs
52
56
  .default('interactive', defaultArgs.interactive).argv;
53
57
 
54
58
  async function run() {
55
- const { cert, source, from, url, 'api-key': apiKey, headers, fields, interactive, mode } = args;
59
+ const { cert, source, from, url, 'api-key': apiKey, 'allow-self-signed': allowSelfSigned, headers, fields, interactive, mode } = args;
56
60
  const sources = Array.isArray(source) ? source : [source];
57
61
  const ca = await getCa(cert);
58
- const files = await getFiles(current, sources, from, ca);
62
+ const agent = getAgent({ ca, allowSelfSigned });
63
+ const files = await getFiles(current, sources, from, agent);
59
64
  const successfulUploads: Array<string> = [];
60
65
 
61
66
  if (files.length === 0) {
@@ -76,7 +81,7 @@ async function run() {
76
81
  content,
77
82
  fields,
78
83
  headers,
79
- ca,
84
+ agent,
80
85
  interactive,
81
86
  );
82
87
 
package/src/utils.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import glob from 'glob';
2
+ import { Agent } from 'https';
2
3
  import { existsSync, statSync } from 'fs';
3
4
  import { stat, readFile, readdir, copyFile, rm } from 'fs/promises';
4
5
  import { dirname, basename, resolve } from 'path';
@@ -83,7 +84,7 @@ export async function getFiles(
83
84
  baseDir: string,
84
85
  sources: Array<string>,
85
86
  from: string,
86
- ca: Buffer,
87
+ agent: Agent,
87
88
  ): Promise<Array<string>> {
88
89
  switch (from) {
89
90
  case 'local': {
@@ -127,12 +128,12 @@ export async function getFiles(
127
128
  return allMatches.filter(isFile);
128
129
  }
129
130
  case 'remote': {
130
- const allFiles = await Promise.all(sources.map((s) => downloadFile(s, ca)));
131
+ const allFiles = await Promise.all(sources.map((s) => downloadFile(s, agent)));
131
132
  return allFiles.reduce((result, files) => [...result, ...files], []);
132
133
  }
133
134
  case 'npm': {
134
135
  const allUrls = await Promise.all(sources.map((s) => findTarball(s)));
135
- const allFiles = await Promise.all(allUrls.map((url) => downloadFile(url, ca)));
136
+ const allFiles = await Promise.all(allUrls.map((url) => downloadFile(url, agent)));
136
137
  return allFiles.reduce((result, files) => [...result, ...files], []);
137
138
  }
138
139
  }