echoapi-converter 0.0.40 → 0.0.42

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/dist/index.d.ts CHANGED
@@ -204,6 +204,7 @@ declare class InsomniaToApipost {
204
204
  declare class PostmanToApipost {
205
205
  apis: any;
206
206
  project: any;
207
+ source: 'vscode' | 'workbench' | string;
207
208
  constructor();
208
209
  private clear;
209
210
  private completionApiRequestAuth;
@@ -216,7 +217,9 @@ declare class PostmanToApipost {
216
217
  private completionApis;
217
218
  private initApis;
218
219
  private initProject;
219
- convert(json: any, project_id: string): {
220
+ convert(json: any, project_id: string, option?: {
221
+ source: string;
222
+ }): {
220
223
  status: "error" | "success";
221
224
  message: string;
222
225
  data: any;
@@ -248,6 +251,7 @@ declare class ThunderToApipost {
248
251
  folders: any;
249
252
  project: any;
250
253
  global: any;
254
+ source: 'vscode' | 'workbench' | string;
251
255
  constructor();
252
256
  private clear;
253
257
  private initProject;
@@ -266,7 +270,9 @@ declare class ThunderToApipost {
266
270
  private initApis;
267
271
  private initGlobal;
268
272
  private buildFolderApiTree;
269
- convert(json: any, project_id: string): {
273
+ convert(json: any, project_id: string, option?: {
274
+ source: string;
275
+ }): {
270
276
  status: "error" | "success";
271
277
  message: string;
272
278
  data: any;
package/dist/index.js CHANGED
@@ -250,6 +250,12 @@ const API_METHODS = [
250
250
  'PROPFIND',
251
251
  'VIEW',
252
252
  ];
253
+ const APIPOST_GRANT_TYPES = ['authorization_code', 'password_credentials', 'authorization_code_with_pkce'];
254
+ const THUNDER_CLIENT_GRANT_TYPES = {
255
+ "password": 'password_credentials',
256
+ "authorization_code": "authorization_code",
257
+ "authorization_code_with_pkce": "authorization_code_with_pkce"
258
+ };
253
259
 
254
260
  // @ts-nocheck
255
261
  const splicedPath = (name, version) => {
@@ -5474,7 +5480,6 @@ class InsomniaToApipost {
5474
5480
 
5475
5481
  // @ts-nocheck
5476
5482
  const DEFAULT_FIELD_TYPE = ["string", "file"];
5477
- const APIPOST_GRANT_TYPES = ['authorization_code', 'password_credentials', 'authorization_code_with_pkce'];
5478
5483
  class PostmanToApipost {
5479
5484
  constructor() {
5480
5485
  Object.defineProperty(this, "apis", {
@@ -5489,12 +5494,20 @@ class PostmanToApipost {
5489
5494
  writable: true,
5490
5495
  value: void 0
5491
5496
  });
5497
+ // 转换的来源端
5498
+ Object.defineProperty(this, "source", {
5499
+ enumerable: true,
5500
+ configurable: true,
5501
+ writable: true,
5502
+ value: void 0
5503
+ });
5492
5504
  this.apis = [];
5493
5505
  this.project = {
5494
5506
  name: "",
5495
5507
  intro: "",
5496
5508
  project_id: "",
5497
5509
  };
5510
+ this.source = 'workbench';
5498
5511
  }
5499
5512
  clear() {
5500
5513
  this.apis = [];
@@ -5503,6 +5516,7 @@ class PostmanToApipost {
5503
5516
  intro: "",
5504
5517
  project_id: "",
5505
5518
  };
5519
+ this.source = 'workbench';
5506
5520
  }
5507
5521
  completionApiRequestAuth(auth) {
5508
5522
  var _a, _b, _c, _d, _e, _f, _g;
@@ -5568,11 +5582,22 @@ class PostmanToApipost {
5568
5582
  }
5569
5583
  else if ((auth === null || auth === void 0 ? void 0 : auth.type) === "oauth2") {
5570
5584
  customAuth["type"] = "oauth2";
5585
+ const getGrantType = (postman_grant_type) => {
5586
+ if (APIPOST_GRANT_TYPES.includes(postman_grant_type)) {
5587
+ return postman_grant_type;
5588
+ }
5589
+ else if (this.source === 'vscode') {
5590
+ return 'password_credentials';
5591
+ }
5592
+ else {
5593
+ return 'authorization_code';
5594
+ }
5595
+ };
5571
5596
  customAuth["oauth2"] = {
5572
5597
  addTokenTo: (authMap === null || authMap === void 0 ? void 0 : authMap.addTokenTo) || 'header',
5573
5598
  headerPrefix: (authMap === null || authMap === void 0 ? void 0 : authMap.headerPrefix) || 'Bearer',
5574
5599
  access_token: '',
5575
- grant_type: APIPOST_GRANT_TYPES.includes(authMap === null || authMap === void 0 ? void 0 : authMap.grant_type) ? authMap === null || authMap === void 0 ? void 0 : authMap.grant_type : 'authorization_code',
5600
+ grant_type: getGrantType(authMap === null || authMap === void 0 ? void 0 : authMap.grant_type),
5576
5601
  redirect_uri: (authMap === null || authMap === void 0 ? void 0 : authMap.redirect_uri) || '',
5577
5602
  authUrl: (authMap === null || authMap === void 0 ? void 0 : authMap.authUrl) || '',
5578
5603
  accessTokenUrl: (authMap === null || authMap === void 0 ? void 0 : authMap.accessTokenUrl) || '',
@@ -6005,9 +6030,10 @@ class PostmanToApipost {
6005
6030
  this.project.intro = ((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description) || "";
6006
6031
  this.project.project_id = project_id;
6007
6032
  }
6008
- convert(json, project_id) {
6033
+ convert(json, project_id, option) {
6009
6034
  this.clear();
6010
6035
  try {
6036
+ this.source = (option === null || option === void 0 ? void 0 : option.source) || 'workbench';
6011
6037
  this.initProject(json, project_id);
6012
6038
  this.initApis(json === null || json === void 0 ? void 0 : json.item);
6013
6039
  const data = Object.assign(Object.assign({}, this.project), { apis: this.apis });
@@ -6314,6 +6340,13 @@ class ThunderToApipost {
6314
6340
  writable: true,
6315
6341
  value: void 0
6316
6342
  });
6343
+ // 转换的来源端
6344
+ Object.defineProperty(this, "source", {
6345
+ enumerable: true,
6346
+ configurable: true,
6347
+ writable: true,
6348
+ value: void 0
6349
+ });
6317
6350
  Object.defineProperty(this, "diyScript", {
6318
6351
  enumerable: true,
6319
6352
  configurable: true,
@@ -6482,6 +6515,7 @@ class ThunderToApipost {
6482
6515
  intro: "",
6483
6516
  project_id: "",
6484
6517
  };
6518
+ this.source = 'vscode';
6485
6519
  }
6486
6520
  clear() {
6487
6521
  this.apis = [];
@@ -6493,6 +6527,7 @@ class ThunderToApipost {
6493
6527
  intro: "",
6494
6528
  project_id: "",
6495
6529
  };
6530
+ this.source = 'workbench';
6496
6531
  }
6497
6532
  initProject(json, project_id) {
6498
6533
  var _a;
@@ -6577,11 +6612,22 @@ class ThunderToApipost {
6577
6612
  }
6578
6613
  else if ((auth === null || auth === void 0 ? void 0 : auth.type) === "oauth2") {
6579
6614
  customAuth["type"] = "oauth2";
6615
+ const getGrantType = (thunder_grant_type) => {
6616
+ if (THUNDER_CLIENT_GRANT_TYPES[thunder_grant_type]) {
6617
+ return THUNDER_CLIENT_GRANT_TYPES[thunder_grant_type];
6618
+ }
6619
+ else if (this.source === 'vscode') {
6620
+ return 'password_credentials';
6621
+ }
6622
+ else {
6623
+ return 'authorization_code';
6624
+ }
6625
+ };
6580
6626
  customAuth["oauth2"] = {
6581
6627
  addTokenTo: "header",
6582
6628
  headerPrefix: "Bearer",
6583
6629
  access_token: "",
6584
- grant_type: ((_m = auth === null || auth === void 0 ? void 0 : auth.oauth2) === null || _m === void 0 ? void 0 : _m.grantType) || "authorization_code",
6630
+ grant_type: getGrantType((_m = auth === null || auth === void 0 ? void 0 : auth.oauth2) === null || _m === void 0 ? void 0 : _m.grantType),
6585
6631
  redirect_uri: ((_o = auth === null || auth === void 0 ? void 0 : auth.oauth2) === null || _o === void 0 ? void 0 : _o.callbackUrl) || "",
6586
6632
  authUrl: ((_p = auth === null || auth === void 0 ? void 0 : auth.oauth2) === null || _p === void 0 ? void 0 : _p.authUrl) || "",
6587
6633
  accessTokenUrl: ((_q = auth === null || auth === void 0 ? void 0 : auth.oauth2) === null || _q === void 0 ? void 0 : _q.tokenUrl) || "",
@@ -7018,9 +7064,10 @@ class ThunderToApipost {
7018
7064
  return throwResult$1("error", "Must contain a ThunderJson field", {});
7019
7065
  }
7020
7066
  }
7021
- convert(json, project_id) {
7067
+ convert(json, project_id, option) {
7022
7068
  this.clear();
7023
7069
  try {
7070
+ this.source = (option === null || option === void 0 ? void 0 : option.source) || 'vscode';
7024
7071
  this.initProject(json, project_id);
7025
7072
  this.initGlobal(json === null || json === void 0 ? void 0 : json.settings);
7026
7073
  const folders = lodash.map(json === null || json === void 0 ? void 0 : json.folders, (it) => (Object.assign(Object.assign({}, it), { type: "folder" })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [