@emilgroup/partner-sdk-node 1.4.0 → 1.5.0

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 (56) hide show
  1. package/README.md +38 -5
  2. package/api/default-api.ts +4 -0
  3. package/api/partner-relations-api.ts +12 -8
  4. package/api/partner-tags-api.ts +12 -8
  5. package/api/partner-types-api.ts +8 -4
  6. package/api/partner-version-api.ts +8 -4
  7. package/api/partners-api.ts +12 -8
  8. package/api.ts +4 -0
  9. package/base.ts +94 -65
  10. package/common.ts +1 -0
  11. package/configuration.ts +8 -0
  12. package/dist/api/default-api.js +5 -1
  13. package/dist/api/partner-relations-api.d.ts +8 -8
  14. package/dist/api/partner-relations-api.js +17 -13
  15. package/dist/api/partner-tags-api.d.ts +8 -8
  16. package/dist/api/partner-tags-api.js +16 -12
  17. package/dist/api/partner-types-api.d.ts +4 -4
  18. package/dist/api/partner-types-api.js +13 -9
  19. package/dist/api/partner-version-api.d.ts +4 -4
  20. package/dist/api/partner-version-api.js +9 -5
  21. package/dist/api/partners-api.d.ts +8 -8
  22. package/dist/api/partners-api.js +17 -13
  23. package/dist/base.d.ts +11 -8
  24. package/dist/base.js +138 -47
  25. package/dist/common.d.ts +1 -0
  26. package/dist/common.js +2 -1
  27. package/dist/configuration.d.ts +7 -0
  28. package/dist/models/create-partner-type-response-class.d.ts +1 -1
  29. package/dist/models/get-partner-type-response-class.d.ts +1 -1
  30. package/dist/models/get-partner-version-response-class.d.ts +3 -3
  31. package/dist/models/list-partner-relation-class.d.ts +1 -1
  32. package/dist/models/list-partner-relation-types-class.d.ts +1 -1
  33. package/dist/models/list-partner-types-response-class.d.ts +1 -1
  34. package/dist/models/list-partner-versions-response-class.d.ts +7 -1
  35. package/dist/models/list-partners-response-class.d.ts +1 -1
  36. package/dist/models/partner-class.d.ts +12 -6
  37. package/dist/models/partner-relation-class.d.ts +12 -0
  38. package/dist/models/partner-relation-type-class.d.ts +12 -0
  39. package/dist/models/partner-type-class.d.ts +12 -0
  40. package/dist/models/tag-class.d.ts +12 -0
  41. package/dist/models/update-partner-type-response-class.d.ts +1 -1
  42. package/models/create-partner-type-response-class.ts +1 -1
  43. package/models/get-partner-type-response-class.ts +1 -1
  44. package/models/get-partner-version-response-class.ts +3 -3
  45. package/models/list-partner-relation-class.ts +1 -1
  46. package/models/list-partner-relation-types-class.ts +1 -1
  47. package/models/list-partner-types-response-class.ts +1 -1
  48. package/models/list-partner-versions-response-class.ts +7 -1
  49. package/models/list-partners-response-class.ts +1 -1
  50. package/models/partner-class.ts +12 -6
  51. package/models/partner-relation-class.ts +12 -0
  52. package/models/partner-relation-type-class.ts +12 -0
  53. package/models/partner-type-class.ts +12 -0
  54. package/models/tag-class.ts +12 -0
  55. package/models/update-partner-type-response-class.ts +1 -1
  56. package/package.json +5 -2
@@ -85,6 +85,10 @@ var axios_1 = __importDefault(require("axios"));
85
85
  var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
+ // URLSearchParams not necessarily used
89
+ // @ts-ignore
90
+ var url_1 = require("url");
91
+ var FormData = require('form-data');
88
92
  /**
89
93
  * PartnersApi - axios parameter creator
90
94
  * @export
@@ -110,7 +114,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
110
114
  // verify required parameter 'createPartnerRequestDto' is not null or undefined
111
115
  (0, common_1.assertParamExists)('createPartner', 'createPartnerRequestDto', createPartnerRequestDto);
112
116
  localVarPath = "/partnerservice/v1/partners";
113
- localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
117
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
114
118
  if (configuration) {
115
119
  baseOptions = configuration.baseOptions;
116
120
  baseAccessToken = configuration.accessToken;
@@ -160,7 +164,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
160
164
  (0, common_1.assertParamExists)('deletePartner', 'code', code);
161
165
  localVarPath = "/partnerservice/v1/partners/{code}"
162
166
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
163
- localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
167
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
164
168
  if (configuration) {
165
169
  baseOptions = configuration.baseOptions;
166
170
  baseAccessToken = configuration.accessToken;
@@ -190,7 +194,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
190
194
  });
191
195
  },
192
196
  /**
193
- * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
197
+ * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
194
198
  * @summary Retrieve the partner
195
199
  * @param {string} code Unique identifier for the object.
196
200
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
@@ -209,7 +213,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
209
213
  (0, common_1.assertParamExists)('getPartner', 'code', code);
210
214
  localVarPath = "/partnerservice/v1/partners/{code}"
211
215
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
212
- localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
216
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
213
217
  if (configuration) {
214
218
  baseOptions = configuration.baseOptions;
215
219
  baseAccessToken = configuration.accessToken;
@@ -250,7 +254,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
250
254
  * @param {string} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, tags, tagSlugs, partnerTypeId</i>
251
255
  * @param {any} [search] To search the list by any field, pass search=xxx to fetch the result.
252
256
  * @param {string} [order] Order allows you to specify the desired order of entities retrieved from the server by ascending (ASC) or descending (DESC) order.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, version, tags, tagSlugs</i>
253
- * @param {string} [expand] Expand to fetch additional information about the list items. Expanding resources can reduce the number of API calls required to accomplish a task. Use with discretion as some expanded fields can drastically increase payload size.<br/> <br/> <i>Allowed values: partnerType, tags.<i>
257
+ * @param {string} [expand] Expand to fetch additional information about the list items. Expanding resources can reduce the number of API calls required to accomplish a task. Use with discretion as some expanded fields can drastically increase payload size.<br/> <br/> <i>Allowed values: partnerType, tags<i>
254
258
  * @param {string} [filters] Filters the response by one or multiple fields. Advanced filter functionality allows you to perform more complex filtering operations.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, tags, tagSlugs, partnerTypeId</i>
255
259
  * @param {*} [options] Override http request option.
256
260
  * @throws {RequiredError}
@@ -263,7 +267,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
263
267
  switch (_a.label) {
264
268
  case 0:
265
269
  localVarPath = "/partnerservice/v1/partners";
266
- localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
270
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
267
271
  if (configuration) {
268
272
  baseOptions = configuration.baseOptions;
269
273
  baseAccessToken = configuration.accessToken;
@@ -335,7 +339,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
335
339
  (0, common_1.assertParamExists)('tagPartner', 'tagPartnerRequestDtoRest', tagPartnerRequestDtoRest);
336
340
  localVarPath = "/partnerservice/v1/partners/{code}/tag"
337
341
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
338
- localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
342
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
339
343
  if (configuration) {
340
344
  baseOptions = configuration.baseOptions;
341
345
  baseAccessToken = configuration.accessToken;
@@ -388,7 +392,7 @@ var PartnersApiAxiosParamCreator = function (configuration) {
388
392
  (0, common_1.assertParamExists)('updatePartner', 'updatePartnerRequestDto', updatePartnerRequestDto);
389
393
  localVarPath = "/partnerservice/v1/partners/{code}"
390
394
  .replace("{".concat("code", "}"), encodeURIComponent(String(code)));
391
- localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
395
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
392
396
  if (configuration) {
393
397
  baseOptions = configuration.baseOptions;
394
398
  baseAccessToken = configuration.accessToken;
@@ -472,7 +476,7 @@ var PartnersApiFp = function (configuration) {
472
476
  });
473
477
  },
474
478
  /**
475
- * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
479
+ * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
476
480
  * @summary Retrieve the partner
477
481
  * @param {string} code Unique identifier for the object.
478
482
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
@@ -502,7 +506,7 @@ var PartnersApiFp = function (configuration) {
502
506
  * @param {string} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, tags, tagSlugs, partnerTypeId</i>
503
507
  * @param {any} [search] To search the list by any field, pass search=xxx to fetch the result.
504
508
  * @param {string} [order] Order allows you to specify the desired order of entities retrieved from the server by ascending (ASC) or descending (DESC) order.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, version, tags, tagSlugs</i>
505
- * @param {string} [expand] Expand to fetch additional information about the list items. Expanding resources can reduce the number of API calls required to accomplish a task. Use with discretion as some expanded fields can drastically increase payload size.<br/> <br/> <i>Allowed values: partnerType, tags.<i>
509
+ * @param {string} [expand] Expand to fetch additional information about the list items. Expanding resources can reduce the number of API calls required to accomplish a task. Use with discretion as some expanded fields can drastically increase payload size.<br/> <br/> <i>Allowed values: partnerType, tags<i>
506
510
  * @param {string} [filters] Filters the response by one or multiple fields. Advanced filter functionality allows you to perform more complex filtering operations.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, tags, tagSlugs, partnerTypeId</i>
507
511
  * @param {*} [options] Override http request option.
508
512
  * @throws {RequiredError}
@@ -597,7 +601,7 @@ var PartnersApiFactory = function (configuration, basePath, axios) {
597
601
  return localVarFp.deletePartner(code, authorization, options).then(function (request) { return request(axios, basePath); });
598
602
  },
599
603
  /**
600
- * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
604
+ * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
601
605
  * @summary Retrieve the partner
602
606
  * @param {string} code Unique identifier for the object.
603
607
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
@@ -617,7 +621,7 @@ var PartnersApiFactory = function (configuration, basePath, axios) {
617
621
  * @param {string} [filter] Filter the response by one or multiple fields. In general, fetching filtered responses will conserve bandwidth and reduce response time.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, tags, tagSlugs, partnerTypeId</i>
618
622
  * @param {any} [search] To search the list by any field, pass search=xxx to fetch the result.
619
623
  * @param {string} [order] Order allows you to specify the desired order of entities retrieved from the server by ascending (ASC) or descending (DESC) order.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, version, tags, tagSlugs</i>
620
- * @param {string} [expand] Expand to fetch additional information about the list items. Expanding resources can reduce the number of API calls required to accomplish a task. Use with discretion as some expanded fields can drastically increase payload size.<br/> <br/> <i>Allowed values: partnerType, tags.<i>
624
+ * @param {string} [expand] Expand to fetch additional information about the list items. Expanding resources can reduce the number of API calls required to accomplish a task. Use with discretion as some expanded fields can drastically increase payload size.<br/> <br/> <i>Allowed values: partnerType, tags<i>
621
625
  * @param {string} [filters] Filters the response by one or multiple fields. Advanced filter functionality allows you to perform more complex filtering operations.<br/> <br/> <i>Allowed values: id, code, displayName, createdAt, updatedAt, tags, tagSlugs, partnerTypeId</i>
622
626
  * @param {*} [options] Override http request option.
623
627
  * @throws {RequiredError}
@@ -688,7 +692,7 @@ var PartnersApi = /** @class */ (function (_super) {
688
692
  return (0, exports.PartnersApiFp)(this.configuration).deletePartner(requestParameters.code, requestParameters.authorization, options).then(function (request) { return request(_this.axios, _this.basePath); });
689
693
  };
690
694
  /**
691
- * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
695
+ * Retrieves the details of the partner that was previously created. Supply the unique partner code that was returned when you created it and Emil Api will return the corresponding partner information.
692
696
  * @summary Retrieve the partner
693
697
  * @param {PartnersApiGetPartnerRequest} requestParameters Request parameters.
694
698
  * @param {*} [options] Override http request option.
package/dist/base.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare const COLLECTION_FORMATS: {
24
24
  };
25
25
  export interface LoginClass {
26
26
  accessToken: string;
27
- permissions: Array<string>;
27
+ permissions: string;
28
28
  }
29
29
  export declare enum Environment {
30
30
  Production = "https://apiv2.emil.de",
@@ -50,18 +50,21 @@ export interface RequestArgs {
50
50
  export declare class BaseAPI {
51
51
  protected basePath: string;
52
52
  protected axios: AxiosInstance;
53
- protected configuration: Configuration | undefined;
54
- private tokenData?;
55
- private permissions;
53
+ protected configuration: Configuration;
54
+ private username?;
55
+ private password?;
56
+ private permissions?;
56
57
  constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
58
+ initialize(env?: Environment): Promise<void>;
59
+ private loadCredentials;
60
+ private readConfigFile;
61
+ private readEnvVariables;
57
62
  selectEnvironment(env: Environment): void;
58
- selectBasePath(path: string): void;
59
63
  getPermissions(): Array<string>;
60
64
  authorize(username: string, password: string): Promise<void>;
61
65
  refreshTokenInternal(): Promise<LoginClass>;
62
- private storeTokenData;
63
- loadTokenData(): void;
64
- cleanTokenData(): void;
66
+ private extractRefreshToken;
67
+ getConfiguration(): Configuration;
65
68
  private attachInterceptor;
66
69
  }
67
70
  /**
package/dist/base.js CHANGED
@@ -38,6 +38,29 @@ var __assign = (this && this.__assign) || function () {
38
38
  };
39
39
  return __assign.apply(this, arguments);
40
40
  };
41
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
42
+ if (k2 === undefined) k2 = k;
43
+ var desc = Object.getOwnPropertyDescriptor(m, k);
44
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
45
+ desc = { enumerable: true, get: function() { return m[k]; } };
46
+ }
47
+ Object.defineProperty(o, k2, desc);
48
+ }) : (function(o, m, k, k2) {
49
+ if (k2 === undefined) k2 = k;
50
+ o[k2] = m[k];
51
+ }));
52
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
53
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
54
+ }) : function(o, v) {
55
+ o["default"] = v;
56
+ });
57
+ var __importStar = (this && this.__importStar) || function (mod) {
58
+ if (mod && mod.__esModule) return mod;
59
+ var result = {};
60
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
61
+ __setModuleDefault(result, mod);
62
+ return result;
63
+ };
41
64
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
42
65
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
43
66
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -80,11 +103,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
80
103
  Object.defineProperty(exports, "__esModule", { value: true });
81
104
  exports.RequiredError = exports.BaseAPI = exports.resetRetry = exports.Environment = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0;
82
105
  var configuration_1 = require("./configuration");
83
- var common_1 = require("./common");
84
106
  // Some imports not used depending on template conditions
85
107
  // @ts-ignore
86
108
  var axios_1 = __importDefault(require("axios"));
109
+ var fs = __importStar(require("fs"));
110
+ var path = __importStar(require("path"));
111
+ var os = __importStar(require("os"));
87
112
  exports.BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
113
+ var CONFIG_DIRECTORY = '.emil';
114
+ var CONFIG_FILENAME = 'credentials';
115
+ var KEY_USERNAME = 'emil_username';
116
+ var KEY_PASSWORD = 'emil_password';
117
+ var filePath = os.homedir() + path.sep + CONFIG_DIRECTORY + path.sep + CONFIG_FILENAME;
88
118
  /**
89
119
  *
90
120
  * @export
@@ -109,7 +139,6 @@ function resetRetry() {
109
139
  }
110
140
  exports.resetRetry = resetRetry;
111
141
  var NETWORK_ERROR_MESSAGE = "Network Error";
112
- var TOKEN_DATA = 'APP_TOKEN';
113
142
  /**
114
143
  *
115
144
  * @export
@@ -121,35 +150,104 @@ var BaseAPI = /** @class */ (function () {
121
150
  if (axios === void 0) { axios = axios_1.default; }
122
151
  this.basePath = basePath;
123
152
  this.axios = axios;
124
- this.permissions = [];
125
- this.loadTokenData();
126
153
  if (configuration) {
127
154
  this.configuration = configuration;
128
155
  this.basePath = configuration.basePath || this.basePath;
129
- this.configuration.accessToken = this.tokenData.accessToken ? "Bearer ".concat(this.tokenData.accessToken) : '';
130
156
  }
131
157
  else {
132
- var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
133
158
  this.configuration = new configuration_1.Configuration({
134
159
  basePath: this.basePath,
135
- accessToken: accessToken ? "Bearer ".concat(accessToken) : '',
136
- username: username,
137
160
  });
138
161
  }
139
162
  this.attachInterceptor(axios);
140
163
  }
141
- BaseAPI.prototype.selectEnvironment = function (env) {
142
- this.selectBasePath(env);
164
+ BaseAPI.prototype.initialize = function (env) {
165
+ if (env === void 0) { env = Environment.Production; }
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0:
170
+ this.configuration.basePath = env;
171
+ return [4 /*yield*/, this.loadCredentials()];
172
+ case 1:
173
+ _a.sent();
174
+ if (!this.username) return [3 /*break*/, 3];
175
+ return [4 /*yield*/, this.authorize(this.username, this.password)];
176
+ case 2:
177
+ _a.sent();
178
+ this.password = null; // to avoid keeping password loaded in memory.
179
+ _a.label = 3;
180
+ case 3: return [2 /*return*/];
181
+ }
182
+ });
183
+ });
184
+ };
185
+ BaseAPI.prototype.loadCredentials = function () {
186
+ return __awaiter(this, void 0, void 0, function () {
187
+ var error_1;
188
+ return __generator(this, function (_a) {
189
+ switch (_a.label) {
190
+ case 0:
191
+ _a.trys.push([0, 2, , 3]);
192
+ return [4 /*yield*/, this.readConfigFile()];
193
+ case 1:
194
+ _a.sent();
195
+ return [3 /*break*/, 3];
196
+ case 2:
197
+ error_1 = _a.sent();
198
+ console.warn("No credentials file found. Check that ".concat(filePath, " exists."));
199
+ return [3 /*break*/, 3];
200
+ case 3:
201
+ this.readEnvVariables();
202
+ if (!this.username) {
203
+ console.info("No credentials found in credentials file or environment variables. Either provide some or use \n authorize() function.");
204
+ }
205
+ return [2 /*return*/];
206
+ }
207
+ });
208
+ });
209
+ };
210
+ BaseAPI.prototype.readConfigFile = function () {
211
+ return __awaiter(this, void 0, void 0, function () {
212
+ var file, lines;
213
+ var _this = this;
214
+ return __generator(this, function (_a) {
215
+ switch (_a.label) {
216
+ case 0: return [4 /*yield*/, fs.promises.readFile(filePath, 'utf-8')];
217
+ case 1:
218
+ file = _a.sent();
219
+ lines = file.split(os.EOL)
220
+ .filter(Boolean);
221
+ lines.forEach(function (line) {
222
+ if (line.startsWith(KEY_USERNAME)) {
223
+ _this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
224
+ }
225
+ else if (line.startsWith(KEY_PASSWORD)) {
226
+ _this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
227
+ }
228
+ });
229
+ return [2 /*return*/];
230
+ }
231
+ });
232
+ });
233
+ };
234
+ BaseAPI.prototype.readEnvVariables = function () {
235
+ if (process.env.EMIL_USERNAME) {
236
+ this.username = process.env.EMIL_USERNAME;
237
+ this.password = process.env.EMIL_PASSWORD || '';
238
+ return true;
239
+ }
240
+ return false;
143
241
  };
144
- BaseAPI.prototype.selectBasePath = function (path) {
145
- this.configuration.basePath = path;
242
+ BaseAPI.prototype.selectEnvironment = function (env) {
243
+ this.configuration.basePath = env;
146
244
  };
147
245
  BaseAPI.prototype.getPermissions = function () {
148
- return this.permissions;
246
+ return this.permissions.split(',');
149
247
  };
150
248
  BaseAPI.prototype.authorize = function (username, password) {
151
249
  return __awaiter(this, void 0, void 0, function () {
152
- var options, response, _a, accessToken, permissions;
250
+ var options, response, _a, accessToken, permissions, refreshToken;
153
251
  return __generator(this, function (_b) {
154
252
  switch (_b.label) {
155
253
  case 0:
@@ -169,10 +267,9 @@ var BaseAPI = /** @class */ (function () {
169
267
  _a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
170
268
  this.configuration.username = username;
171
269
  this.configuration.accessToken = "Bearer ".concat(accessToken);
172
- this.tokenData.username = username;
173
- this.tokenData.accessToken = accessToken;
174
270
  this.permissions = permissions;
175
- this.storeTokenData(__assign({}, this.tokenData));
271
+ refreshToken = this.extractRefreshToken(response);
272
+ this.configuration.refreshToken = refreshToken;
176
273
  return [2 /*return*/];
177
274
  }
178
275
  });
@@ -180,12 +277,12 @@ var BaseAPI = /** @class */ (function () {
180
277
  };
181
278
  BaseAPI.prototype.refreshTokenInternal = function () {
182
279
  return __awaiter(this, void 0, void 0, function () {
183
- var username, options, response;
184
- return __generator(this, function (_a) {
185
- switch (_a.label) {
280
+ var _a, username, refreshToken, options, response;
281
+ return __generator(this, function (_b) {
282
+ switch (_b.label) {
186
283
  case 0:
187
- username = this.configuration.username;
188
- if (!username) {
284
+ _a = this.configuration, username = _a.username, refreshToken = _a.refreshToken;
285
+ if (!username || !refreshToken) {
189
286
  throw new Error('Failed to refresh token.');
190
287
  }
191
288
  options = {
@@ -193,33 +290,28 @@ var BaseAPI = /** @class */ (function () {
193
290
  url: "".concat(this.configuration.basePath, "/authservice/v1/refresh-token"),
194
291
  headers: {
195
292
  'Content-Type': 'application/json',
293
+ Cookie: refreshToken,
196
294
  },
197
295
  data: { username: username },
198
296
  withCredentials: true,
199
297
  };
200
298
  return [4 /*yield*/, axios_1.default.request(options)];
201
299
  case 1:
202
- response = _a.sent();
300
+ response = _b.sent();
203
301
  return [2 /*return*/, response.data];
204
302
  }
205
303
  });
206
304
  });
207
305
  };
208
- BaseAPI.prototype.storeTokenData = function (tokenData) {
209
- if (typeof window !== 'undefined') {
210
- (0, common_1.defaultStorage)().set(TOKEN_DATA, tokenData);
306
+ BaseAPI.prototype.extractRefreshToken = function (response) {
307
+ if (response.headers && response.headers['set-cookie']
308
+ && response.headers['set-cookie'].length > 0) {
309
+ return "".concat(response.headers['set-cookie'][0].split(';')[0], ";");
211
310
  }
311
+ return '';
212
312
  };
213
- BaseAPI.prototype.loadTokenData = function () {
214
- if (typeof window !== 'undefined') {
215
- this.tokenData = (0, common_1.defaultStorage)().get(TOKEN_DATA) || {};
216
- }
217
- else {
218
- this.tokenData = {};
219
- }
220
- };
221
- BaseAPI.prototype.cleanTokenData = function () {
222
- this.storeTokenData(null);
313
+ BaseAPI.prototype.getConfiguration = function () {
314
+ return this.configuration;
223
315
  };
224
316
  BaseAPI.prototype.attachInterceptor = function (axios) {
225
317
  var _this = this;
@@ -231,9 +323,8 @@ var BaseAPI = /** @class */ (function () {
231
323
  switch (_c.label) {
232
324
  case 0:
233
325
  originalConfig = err.config;
234
- if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
235
- if (!((err.response.status === 401 || err.response.status === 403)
236
- && !originalConfig._retry)) return [3 /*break*/, 4];
326
+ if (!err.response) return [3 /*break*/, 5];
327
+ if (!(err.response.status === 401 && !originalConfig._retry)) return [3 /*break*/, 4];
237
328
  originalConfig._retry = true;
238
329
  _c.label = 1;
239
330
  case 1:
@@ -243,21 +334,23 @@ var BaseAPI = /** @class */ (function () {
243
334
  _a = _c.sent(), tokenString = _a.accessToken, permissions = _a.permissions;
244
335
  accessToken = "Bearer ".concat(tokenString);
245
336
  this.permissions = permissions;
246
- delete originalConfig.headers['Authorization'];
247
- originalConfig.headers['Authorization'] = accessToken;
337
+ originalConfig.headers['Authorization'] = "Bearer ".concat(accessToken);
248
338
  this.configuration.accessToken = accessToken;
249
- this.tokenData.accessToken = tokenString;
250
- this.storeTokenData(this.tokenData);
251
- return [2 /*return*/, axios(originalConfig)];
339
+ return [2 /*return*/, axios.request(originalConfig)];
252
340
  case 3:
253
341
  _error_1 = _c.sent();
254
342
  if (_error_1.response && _error_1.response.data) {
255
343
  return [2 /*return*/, Promise.reject(_error_1.response.data)];
256
344
  }
257
345
  return [2 /*return*/, Promise.reject(_error_1)];
258
- case 4: return [3 /*break*/, 9];
346
+ case 4:
347
+ if (err.response.status === 403 && err.response.data) {
348
+ return [2 /*return*/, Promise.reject(err.response.data)];
349
+ }
350
+ return [3 /*break*/, 9];
259
351
  case 5:
260
352
  if (!(err.message === NETWORK_ERROR_MESSAGE
353
+ && err.isAxiosError
261
354
  && originalConfig.headers.hasOwnProperty('Authorization')
262
355
  && _retry_count < 4)) return [3 /*break*/, 9];
263
356
  _retry_count++;
@@ -272,8 +365,6 @@ var BaseAPI = /** @class */ (function () {
272
365
  _retry = true;
273
366
  originalConfig.headers['Authorization'] = accessToken;
274
367
  this.configuration.accessToken = accessToken;
275
- this.tokenData.accessToken = tokenString;
276
- this.storeTokenData(this.tokenData);
277
368
  return [2 /*return*/, axios.request(__assign({}, originalConfig))];
278
369
  case 8:
279
370
  _error_2 = _c.sent();
package/dist/common.d.ts CHANGED
@@ -12,6 +12,7 @@
12
12
  import { Configuration } from "./configuration";
13
13
  import { RequestArgs } from "./base";
14
14
  import { AxiosInstance, AxiosResponse } from 'axios';
15
+ import { URL } from 'url';
15
16
  /**
16
17
  *
17
18
  * @export
package/dist/common.js CHANGED
@@ -62,6 +62,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
62
62
  Object.defineProperty(exports, "__esModule", { value: true });
63
63
  exports.defaultStorage = exports.LocalStorage = exports.createRequestFunction = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setOAuthToObject = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0;
64
64
  var base_1 = require("./base");
65
+ var url_1 = require("url");
65
66
  /**
66
67
  *
67
68
  * @export
@@ -187,7 +188,7 @@ var setSearchParams = function (url) {
187
188
  for (var _i = 1; _i < arguments.length; _i++) {
188
189
  objects[_i - 1] = arguments[_i];
189
190
  }
190
- var searchParams = new URLSearchParams(url.search);
191
+ var searchParams = new url_1.URLSearchParams(url.search);
191
192
  for (var _a = 0, objects_1 = objects; _a < objects_1.length; _a++) {
192
193
  var object = objects_1[_a];
193
194
  for (var key in object) {
@@ -68,6 +68,13 @@ export declare class Configuration {
68
68
  * @type {new () => FormData}
69
69
  */
70
70
  formDataCtor?: new () => any;
71
+ /**
72
+ * parameter for automatically refreshing access token for oauth2 security
73
+ *
74
+ * @type {string}
75
+ * @memberof Configuration
76
+ */
77
+ refreshToken?: string;
71
78
  constructor(param?: ConfigurationParameters);
72
79
  /**
73
80
  * Check if the given MIME is a JSON MIME.
@@ -17,7 +17,7 @@ import { PartnerTypeClass } from './partner-type-class';
17
17
  */
18
18
  export interface CreatePartnerTypeResponseClass {
19
19
  /**
20
- * The partnerType response.
20
+ * The partner type response.
21
21
  * @type {PartnerTypeClass}
22
22
  * @memberof CreatePartnerTypeResponseClass
23
23
  */
@@ -17,7 +17,7 @@ import { PartnerTypeClass } from './partner-type-class';
17
17
  */
18
18
  export interface GetPartnerTypeResponseClass {
19
19
  /**
20
- * The partnerType response.
20
+ * The partner type response.
21
21
  * @type {PartnerTypeClass}
22
22
  * @memberof GetPartnerTypeResponseClass
23
23
  */
@@ -17,9 +17,9 @@ import { PartnerClass } from './partner-class';
17
17
  */
18
18
  export interface GetPartnerVersionResponseClass {
19
19
  /**
20
- * The list of partners.
21
- * @type {Array<PartnerClass>}
20
+ * The partner response.
21
+ * @type {PartnerClass}
22
22
  * @memberof GetPartnerVersionResponseClass
23
23
  */
24
- 'partnerVersion': Array<PartnerClass>;
24
+ 'partnerVersion': PartnerClass;
25
25
  }
@@ -23,7 +23,7 @@ export interface ListPartnerRelationClass {
23
23
  */
24
24
  'items': Array<PartnerRelationClass>;
25
25
  /**
26
- * Next page token
26
+ * Next page token.
27
27
  * @type {string}
28
28
  * @memberof ListPartnerRelationClass
29
29
  */
@@ -23,7 +23,7 @@ export interface ListPartnerRelationTypesClass {
23
23
  */
24
24
  'items': Array<PartnerRelationTypeClass>;
25
25
  /**
26
- * Next page token
26
+ * Next page token.
27
27
  * @type {string}
28
28
  * @memberof ListPartnerRelationTypesClass
29
29
  */
@@ -17,7 +17,7 @@ import { PartnerTypeClass } from './partner-type-class';
17
17
  */
18
18
  export interface ListPartnerTypesResponseClass {
19
19
  /**
20
- * The list of partnerTypes.
20
+ * The list of partner typess.
21
21
  * @type {Array<PartnerTypeClass>}
22
22
  * @memberof ListPartnerTypesResponseClass
23
23
  */
@@ -17,9 +17,15 @@ import { PartnerClass } from './partner-class';
17
17
  */
18
18
  export interface ListPartnerVersionsResponseClass {
19
19
  /**
20
- * The list of Partnerss.
20
+ * The list of partnerss.
21
21
  * @type {Array<PartnerClass>}
22
22
  * @memberof ListPartnerVersionsResponseClass
23
23
  */
24
24
  'items': Array<PartnerClass>;
25
+ /**
26
+ * Next page token.
27
+ * @type {string}
28
+ * @memberof ListPartnerVersionsResponseClass
29
+ */
30
+ 'nextPageToken': string;
25
31
  }
@@ -17,7 +17,7 @@ import { PartnerClass } from './partner-class';
17
17
  */
18
18
  export interface ListPartnersResponseClass {
19
19
  /**
20
- * The list of Partnerss.
20
+ * The list of partnerss.
21
21
  * @type {Array<PartnerClass>}
22
22
  * @memberof ListPartnersResponseClass
23
23
  */
@@ -64,12 +64,6 @@ export interface PartnerClass {
64
64
  * @memberof PartnerClass
65
65
  */
66
66
  'updatedAt': string;
67
- /**
68
- * Last user who updated the entity
69
- * @type {string}
70
- * @memberof PartnerClass
71
- */
72
- 'updatedBy': string;
73
67
  /**
74
68
  * The version number of the partner
75
69
  * @type {number}
@@ -82,4 +76,16 @@ export interface PartnerClass {
82
76
  * @memberof PartnerClass
83
77
  */
84
78
  'tags': Array<string>;
79
+ /**
80
+ * Identifier of the user who created the record.
81
+ * @type {string}
82
+ * @memberof PartnerClass
83
+ */
84
+ 'createdBy': string;
85
+ /**
86
+ * Identifier of the user who last updated the record.
87
+ * @type {string}
88
+ * @memberof PartnerClass
89
+ */
90
+ 'updatedBy': string;
85
91
  }
@@ -69,4 +69,16 @@ export interface PartnerRelationClass {
69
69
  * @memberof PartnerRelationClass
70
70
  */
71
71
  'updatedAt': string;
72
+ /**
73
+ * Identifier of the user who created the record.
74
+ * @type {string}
75
+ * @memberof PartnerRelationClass
76
+ */
77
+ 'createdBy': string;
78
+ /**
79
+ * Identifier of the user who last updated the record.
80
+ * @type {string}
81
+ * @memberof PartnerRelationClass
82
+ */
83
+ 'updatedBy': string;
72
84
  }