@emilgroup/discount-sdk 1.8.1-beta.3 → 1.14.1-beta.6

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.
@@ -4,7 +4,7 @@
4
4
  README.md
5
5
  api.ts
6
6
  api/campaigns-api.ts
7
- api/default-api.ts
7
+ api/health-api.ts
8
8
  api/policy-vouchers-api.ts
9
9
  api/vouchers-api.ts
10
10
  base.ts
package/README.md CHANGED
@@ -17,11 +17,11 @@ Although this package can be used in both TypeScript and JavaScript, it is inten
17
17
  Navigate to the folder of your consuming project and run one of the following commands:
18
18
 
19
19
  ```
20
- npm install @emilgroup/discount-sdk@1.8.1-beta.3 --save
20
+ npm install @emilgroup/discount-sdk@1.14.1-beta.6 --save
21
21
  ```
22
22
  or
23
23
  ```
24
- yarn add @emilgroup/discount-sdk@1.8.1-beta.3
24
+ yarn add @emilgroup/discount-sdk@1.14.1-beta.6
25
25
  ```
26
26
 
27
27
  And then you can import `CampaignApi`.
@@ -25,10 +25,10 @@ import { InlineResponse200 } from '../models';
25
25
  // @ts-ignore
26
26
  import { InlineResponse503 } from '../models';
27
27
  /**
28
- * DefaultApi - axios parameter creator
28
+ * HealthApi - axios parameter creator
29
29
  * @export
30
30
  */
31
- export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) {
31
+ export const HealthApiAxiosParamCreator = function (configuration?: Configuration) {
32
32
  return {
33
33
  /**
34
34
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
@@ -66,11 +66,11 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
66
66
  };
67
67
 
68
68
  /**
69
- * DefaultApi - functional programming interface
69
+ * HealthApi - functional programming interface
70
70
  * @export
71
71
  */
72
- export const DefaultApiFp = function(configuration?: Configuration) {
73
- const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration)
72
+ export const HealthApiFp = function(configuration?: Configuration) {
73
+ const localVarAxiosParamCreator = HealthApiAxiosParamCreator(configuration)
74
74
  return {
75
75
  /**
76
76
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
@@ -86,11 +86,11 @@ export const DefaultApiFp = function(configuration?: Configuration) {
86
86
  };
87
87
 
88
88
  /**
89
- * DefaultApi - factory interface
89
+ * HealthApi - factory interface
90
90
  * @export
91
91
  */
92
- export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
93
- const localVarFp = DefaultApiFp(configuration)
92
+ export const HealthApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
93
+ const localVarFp = HealthApiFp(configuration)
94
94
  return {
95
95
  /**
96
96
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
@@ -105,20 +105,20 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa
105
105
  };
106
106
 
107
107
  /**
108
- * DefaultApi - object-oriented interface
108
+ * HealthApi - object-oriented interface
109
109
  * @export
110
- * @class DefaultApi
110
+ * @class HealthApi
111
111
  * @extends {BaseAPI}
112
112
  */
113
- export class DefaultApi extends BaseAPI {
113
+ export class HealthApi extends BaseAPI {
114
114
  /**
115
115
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
116
116
  * @summary Health Check
117
117
  * @param {*} [options] Override http request option.
118
118
  * @throws {RequiredError}
119
- * @memberof DefaultApi
119
+ * @memberof HealthApi
120
120
  */
121
121
  public check(options?: AxiosRequestConfig) {
122
- return DefaultApiFp(this.configuration).check(options).then((request) => request(this.axios, this.basePath));
122
+ return HealthApiFp(this.configuration).check(options).then((request) => request(this.axios, this.basePath));
123
123
  }
124
124
  }
package/api.ts CHANGED
@@ -21,13 +21,13 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj
21
21
  // @ts-ignore
22
22
  import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
23
23
  import { CampaignsApi } from './api';
24
- import { DefaultApi } from './api';
24
+ import { HealthApi } from './api';
25
25
  import { PolicyVouchersApi } from './api';
26
26
  import { VouchersApi } from './api';
27
27
 
28
28
 
29
29
  export * from './api/campaigns-api';
30
- export * from './api/default-api';
30
+ export * from './api/health-api';
31
31
  export * from './api/policy-vouchers-api';
32
32
  export * from './api/vouchers-api';
33
33
 
package/base.ts CHANGED
@@ -53,6 +53,7 @@ export enum Environment {
53
53
  Staging = 'https://apiv2-staging.emil.de',
54
54
  Development = 'https://apiv2-dev.emil.de',
55
55
  ProductionZurich = 'https://eu-central-2.apiv2.emil.de',
56
+ StagingZurich = 'https://eu-central-2.apiv2-staging.emil.de',
56
57
  }
57
58
 
58
59
  let _retry_count = 0
@@ -101,10 +102,14 @@ export class BaseAPI {
101
102
  this.configuration = configuration;
102
103
  this.basePath = configuration.basePath || this.basePath;
103
104
 
104
- // Use config token if provided, otherwise use tokenData token
105
- const configToken = this.configuration.accessToken;
106
- const storedToken = accessToken ? `Bearer ${accessToken}` : '';
107
- this.configuration.accessToken = configToken || storedToken;
105
+ if (configuration.cookieAuth) {
106
+ this.useCookieAuth();
107
+ } else {
108
+ // Use config token if provided, otherwise use tokenData token
109
+ const configToken = this.configuration.accessToken;
110
+ const storedToken = accessToken ? `Bearer ${accessToken}` : '';
111
+ this.configuration.accessToken = configToken || storedToken;
112
+ }
108
113
  } else {
109
114
  const { accessToken, username } = this.tokenData;
110
115
 
@@ -118,6 +123,12 @@ export class BaseAPI {
118
123
  this.attachInterceptor(axios);
119
124
  }
120
125
 
126
+ // Cookie mode: the browser sends the HttpOnly access cookie, so no token is read from storage.
127
+ private useCookieAuth() {
128
+ this.configuration.username = this.configuration.username || this.tokenData.username;
129
+ this.configuration.baseOptions = { ...this.configuration.baseOptions, withCredentials: true };
130
+ }
131
+
121
132
  selectEnvironment(env: Environment) {
122
133
  this.selectBasePath(env);
123
134
  }
@@ -151,10 +162,12 @@ export class BaseAPI {
151
162
  const { data: { accessToken, permissions } } = response;
152
163
 
153
164
  this.configuration.username = username;
154
- this.configuration.accessToken = `Bearer ${accessToken}`;
155
165
  this.tokenData.username = username;
156
- this.tokenData.accessToken = accessToken;
157
166
  this.tokenData.permissions = permissions;
167
+ if (!this.configuration.cookieAuth) {
168
+ this.configuration.accessToken = `Bearer ${accessToken}`;
169
+ this.tokenData.accessToken = accessToken;
170
+ }
158
171
 
159
172
  // Switch workspace if provided
160
173
  if (targetWorkspace) {
@@ -177,7 +190,7 @@ export class BaseAPI {
177
190
  url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
178
191
  headers: {
179
192
  'Content-Type': 'application/json',
180
- 'Authorization': `Bearer ${this.configuration.accessToken}`,
193
+ ...(this.configuration.cookieAuth ? {} : { 'Authorization': `Bearer ${this.configuration.accessToken}` }),
181
194
  },
182
195
  data: {
183
196
  username: this.configuration.username,
@@ -189,10 +202,12 @@ export class BaseAPI {
189
202
  const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
190
203
 
191
204
  const { data: { accessToken, permissions } } = response;
192
-
193
- this.configuration.accessToken = `Bearer ${accessToken}`;
194
- this.tokenData.accessToken = accessToken;
205
+
195
206
  this.tokenData.permissions = permissions;
207
+ if (!this.configuration.cookieAuth) {
208
+ this.configuration.accessToken = `Bearer ${accessToken}`;
209
+ this.tokenData.accessToken = accessToken;
210
+ }
196
211
 
197
212
  this.storeTokenData({
198
213
  ...this.tokenData
@@ -232,6 +247,11 @@ export class BaseAPI {
232
247
 
233
248
  private storeTokenData(tokenData?: TokenData) {
234
249
  if (typeof window !== 'undefined') {
250
+ if (tokenData && this.configuration?.cookieAuth) {
251
+ // Cookie mode saves who is logged in, never the token; a token saved by apps not yet migrated stays.
252
+ const { username, permissions } = tokenData;
253
+ tokenData = { ...(defaultStorage().get<TokenData>(TOKEN_DATA) || {}), username, permissions };
254
+ }
235
255
  defaultStorage().set<TokenData>(TOKEN_DATA, tokenData);
236
256
  }
237
257
  }
@@ -262,15 +282,17 @@ export class BaseAPI {
262
282
  originalConfig._retry = true;
263
283
  try {
264
284
  const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
265
- const accessToken = `Bearer ${tokenString}`;
266
285
  this.tokenData.permissions = permissions;
267
286
 
268
287
  delete originalConfig.headers['Authorization']
269
288
 
270
- originalConfig.headers['Authorization'] = accessToken;
271
-
272
- this.configuration.accessToken = accessToken;
273
- this.tokenData.accessToken = tokenString;
289
+ // In cookie mode the refresh reply renewed the access cookie, so retry without a header.
290
+ if (!this.configuration.cookieAuth) {
291
+ const accessToken = `Bearer ${tokenString}`;
292
+ originalConfig.headers['Authorization'] = accessToken;
293
+ this.configuration.accessToken = accessToken;
294
+ this.tokenData.accessToken = tokenString;
295
+ }
274
296
 
275
297
  this.storeTokenData(this.tokenData);
276
298
 
package/configuration.ts CHANGED
@@ -21,6 +21,7 @@ export interface ConfigurationParameters {
21
21
  basePath?: string;
22
22
  baseOptions?: any;
23
23
  formDataCtor?: new () => any;
24
+ cookieAuth?: boolean;
24
25
  }
25
26
 
26
27
  export class Configuration {
@@ -74,6 +75,15 @@ export class Configuration {
74
75
  */
75
76
  formDataCtor?: new () => any;
76
77
 
78
+ /**
79
+ * Authenticate with the HttpOnly access cookie instead of a stored token: every call sends credentials.
80
+ * The browser holds one cookie, so use it with one logged-in account; log out through the auth service.
81
+ *
82
+ * @type {boolean}
83
+ * @memberof Configuration
84
+ */
85
+ cookieAuth?: boolean;
86
+
77
87
  constructor(param: ConfigurationParameters = {}) {
78
88
  this.apiKey = param.apiKey;
79
89
  this.username = param.username;
@@ -82,6 +92,7 @@ export class Configuration {
82
92
  this.basePath = param.basePath;
83
93
  this.baseOptions = param.baseOptions;
84
94
  this.formDataCtor = param.formDataCtor;
95
+ this.cookieAuth = param.cookieAuth;
85
96
  }
86
97
 
87
98
  /**
@@ -14,10 +14,10 @@ import { Configuration } from '../configuration';
14
14
  import { RequestArgs, BaseAPI } from '../base';
15
15
  import { InlineResponse200 } from '../models';
16
16
  /**
17
- * DefaultApi - axios parameter creator
17
+ * HealthApi - axios parameter creator
18
18
  * @export
19
19
  */
20
- export declare const DefaultApiAxiosParamCreator: (configuration?: Configuration) => {
20
+ export declare const HealthApiAxiosParamCreator: (configuration?: Configuration) => {
21
21
  /**
22
22
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
23
23
  * @summary Health Check
@@ -27,10 +27,10 @@ export declare const DefaultApiAxiosParamCreator: (configuration?: Configuration
27
27
  check: (options?: AxiosRequestConfig) => Promise<RequestArgs>;
28
28
  };
29
29
  /**
30
- * DefaultApi - functional programming interface
30
+ * HealthApi - functional programming interface
31
31
  * @export
32
32
  */
33
- export declare const DefaultApiFp: (configuration?: Configuration) => {
33
+ export declare const HealthApiFp: (configuration?: Configuration) => {
34
34
  /**
35
35
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
36
36
  * @summary Health Check
@@ -40,10 +40,10 @@ export declare const DefaultApiFp: (configuration?: Configuration) => {
40
40
  check(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse200>>;
41
41
  };
42
42
  /**
43
- * DefaultApi - factory interface
43
+ * HealthApi - factory interface
44
44
  * @export
45
45
  */
46
- export declare const DefaultApiFactory: (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) => {
46
+ export declare const HealthApiFactory: (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) => {
47
47
  /**
48
48
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
49
49
  * @summary Health Check
@@ -53,18 +53,18 @@ export declare const DefaultApiFactory: (configuration?: Configuration, basePath
53
53
  check(options?: any): AxiosPromise<InlineResponse200>;
54
54
  };
55
55
  /**
56
- * DefaultApi - object-oriented interface
56
+ * HealthApi - object-oriented interface
57
57
  * @export
58
- * @class DefaultApi
58
+ * @class HealthApi
59
59
  * @extends {BaseAPI}
60
60
  */
61
- export declare class DefaultApi extends BaseAPI {
61
+ export declare class HealthApi extends BaseAPI {
62
62
  /**
63
63
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
64
64
  * @summary Health Check
65
65
  * @param {*} [options] Override http request option.
66
66
  * @throws {RequiredError}
67
- * @memberof DefaultApi
67
+ * @memberof HealthApi
68
68
  */
69
69
  check(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<InlineResponse200, any, {}>>;
70
70
  }
@@ -78,7 +78,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
78
78
  return (mod && mod.__esModule) ? mod : { "default": mod };
79
79
  };
80
80
  Object.defineProperty(exports, "__esModule", { value: true });
81
- exports.DefaultApi = exports.DefaultApiFactory = exports.DefaultApiFp = exports.DefaultApiAxiosParamCreator = void 0;
81
+ exports.HealthApi = exports.HealthApiFactory = exports.HealthApiFp = exports.HealthApiAxiosParamCreator = void 0;
82
82
  var axios_1 = __importDefault(require("axios"));
83
83
  // Some imports not used depending on template conditions
84
84
  // @ts-ignore
@@ -86,10 +86,10 @@ var common_1 = require("../common");
86
86
  // @ts-ignore
87
87
  var base_1 = require("../base");
88
88
  /**
89
- * DefaultApi - axios parameter creator
89
+ * HealthApi - axios parameter creator
90
90
  * @export
91
91
  */
92
- var DefaultApiAxiosParamCreator = function (configuration) {
92
+ var HealthApiAxiosParamCreator = function (configuration) {
93
93
  var _this = this;
94
94
  return {
95
95
  /**
@@ -124,13 +124,13 @@ var DefaultApiAxiosParamCreator = function (configuration) {
124
124
  },
125
125
  };
126
126
  };
127
- exports.DefaultApiAxiosParamCreator = DefaultApiAxiosParamCreator;
127
+ exports.HealthApiAxiosParamCreator = HealthApiAxiosParamCreator;
128
128
  /**
129
- * DefaultApi - functional programming interface
129
+ * HealthApi - functional programming interface
130
130
  * @export
131
131
  */
132
- var DefaultApiFp = function (configuration) {
133
- var localVarAxiosParamCreator = (0, exports.DefaultApiAxiosParamCreator)(configuration);
132
+ var HealthApiFp = function (configuration) {
133
+ var localVarAxiosParamCreator = (0, exports.HealthApiAxiosParamCreator)(configuration);
134
134
  return {
135
135
  /**
136
136
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
@@ -153,13 +153,13 @@ var DefaultApiFp = function (configuration) {
153
153
  },
154
154
  };
155
155
  };
156
- exports.DefaultApiFp = DefaultApiFp;
156
+ exports.HealthApiFp = HealthApiFp;
157
157
  /**
158
- * DefaultApi - factory interface
158
+ * HealthApi - factory interface
159
159
  * @export
160
160
  */
161
- var DefaultApiFactory = function (configuration, basePath, axios) {
162
- var localVarFp = (0, exports.DefaultApiFp)(configuration);
161
+ var HealthApiFactory = function (configuration, basePath, axios) {
162
+ var localVarFp = (0, exports.HealthApiFp)(configuration);
163
163
  return {
164
164
  /**
165
165
  * Returns the health status of the DiscountService service. This endpoint is used to monitor the operational status of the DiscountService service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
@@ -172,16 +172,16 @@ var DefaultApiFactory = function (configuration, basePath, axios) {
172
172
  },
173
173
  };
174
174
  };
175
- exports.DefaultApiFactory = DefaultApiFactory;
175
+ exports.HealthApiFactory = HealthApiFactory;
176
176
  /**
177
- * DefaultApi - object-oriented interface
177
+ * HealthApi - object-oriented interface
178
178
  * @export
179
- * @class DefaultApi
179
+ * @class HealthApi
180
180
  * @extends {BaseAPI}
181
181
  */
182
- var DefaultApi = /** @class */ (function (_super) {
183
- __extends(DefaultApi, _super);
184
- function DefaultApi() {
182
+ var HealthApi = /** @class */ (function (_super) {
183
+ __extends(HealthApi, _super);
184
+ function HealthApi() {
185
185
  return _super !== null && _super.apply(this, arguments) || this;
186
186
  }
187
187
  /**
@@ -189,12 +189,12 @@ var DefaultApi = /** @class */ (function (_super) {
189
189
  * @summary Health Check
190
190
  * @param {*} [options] Override http request option.
191
191
  * @throws {RequiredError}
192
- * @memberof DefaultApi
192
+ * @memberof HealthApi
193
193
  */
194
- DefaultApi.prototype.check = function (options) {
194
+ HealthApi.prototype.check = function (options) {
195
195
  var _this = this;
196
- return (0, exports.DefaultApiFp)(this.configuration).check(options).then(function (request) { return request(_this.axios, _this.basePath); });
196
+ return (0, exports.HealthApiFp)(this.configuration).check(options).then(function (request) { return request(_this.axios, _this.basePath); });
197
197
  };
198
- return DefaultApi;
198
+ return HealthApi;
199
199
  }(base_1.BaseAPI));
200
- exports.DefaultApi = DefaultApi;
200
+ exports.HealthApi = HealthApi;
package/dist/api.d.ts CHANGED
@@ -10,6 +10,6 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  export * from './api/campaigns-api';
13
- export * from './api/default-api';
13
+ export * from './api/health-api';
14
14
  export * from './api/policy-vouchers-api';
15
15
  export * from './api/vouchers-api';
package/dist/api.js CHANGED
@@ -28,6 +28,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  __exportStar(require("./api/campaigns-api"), exports);
31
- __exportStar(require("./api/default-api"), exports);
31
+ __exportStar(require("./api/health-api"), exports);
32
32
  __exportStar(require("./api/policy-vouchers-api"), exports);
33
33
  __exportStar(require("./api/vouchers-api"), exports);
package/dist/base.d.ts CHANGED
@@ -39,7 +39,8 @@ export declare enum Environment {
39
39
  Test = "https://apiv2-test.emil.de",
40
40
  Staging = "https://apiv2-staging.emil.de",
41
41
  Development = "https://apiv2-dev.emil.de",
42
- ProductionZurich = "https://eu-central-2.apiv2.emil.de"
42
+ ProductionZurich = "https://eu-central-2.apiv2.emil.de",
43
+ StagingZurich = "https://eu-central-2.apiv2-staging.emil.de"
43
44
  }
44
45
  export declare function resetRetry(): void;
45
46
  /**
@@ -62,6 +63,7 @@ export declare class BaseAPI {
62
63
  protected configuration: Configuration | undefined;
63
64
  private tokenData?;
64
65
  constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
66
+ private useCookieAuth;
65
67
  selectEnvironment(env: Environment): void;
66
68
  selectBasePath(path: string): void;
67
69
  getPermissions(): Array<string>;
package/dist/base.js CHANGED
@@ -102,6 +102,7 @@ var Environment;
102
102
  Environment["Staging"] = "https://apiv2-staging.emil.de";
103
103
  Environment["Development"] = "https://apiv2-dev.emil.de";
104
104
  Environment["ProductionZurich"] = "https://eu-central-2.apiv2.emil.de";
105
+ Environment["StagingZurich"] = "https://eu-central-2.apiv2-staging.emil.de";
105
106
  })(Environment = exports.Environment || (exports.Environment = {}));
106
107
  var _retry_count = 0;
107
108
  var _retry = null;
@@ -127,10 +128,15 @@ var BaseAPI = /** @class */ (function () {
127
128
  var accessToken = this.tokenData.accessToken;
128
129
  this.configuration = configuration;
129
130
  this.basePath = configuration.basePath || this.basePath;
130
- // Use config token if provided, otherwise use tokenData token
131
- var configToken = this.configuration.accessToken;
132
- var storedToken = accessToken ? "Bearer ".concat(accessToken) : '';
133
- this.configuration.accessToken = configToken || storedToken;
131
+ if (configuration.cookieAuth) {
132
+ this.useCookieAuth();
133
+ }
134
+ else {
135
+ // Use config token if provided, otherwise use tokenData token
136
+ var configToken = this.configuration.accessToken;
137
+ var storedToken = accessToken ? "Bearer ".concat(accessToken) : '';
138
+ this.configuration.accessToken = configToken || storedToken;
139
+ }
134
140
  }
135
141
  else {
136
142
  var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
@@ -142,6 +148,11 @@ var BaseAPI = /** @class */ (function () {
142
148
  }
143
149
  this.attachInterceptor(axios);
144
150
  }
151
+ // Cookie mode: the browser sends the HttpOnly access cookie, so no token is read from storage.
152
+ BaseAPI.prototype.useCookieAuth = function () {
153
+ this.configuration.username = this.configuration.username || this.tokenData.username;
154
+ this.configuration.baseOptions = __assign(__assign({}, this.configuration.baseOptions), { withCredentials: true });
155
+ };
145
156
  BaseAPI.prototype.selectEnvironment = function (env) {
146
157
  this.selectBasePath(env);
147
158
  };
@@ -176,10 +187,12 @@ var BaseAPI = /** @class */ (function () {
176
187
  response = _b.sent();
177
188
  _a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
178
189
  this.configuration.username = username;
179
- this.configuration.accessToken = "Bearer ".concat(accessToken);
180
190
  this.tokenData.username = username;
181
- this.tokenData.accessToken = accessToken;
182
191
  this.tokenData.permissions = permissions;
192
+ if (!this.configuration.cookieAuth) {
193
+ this.configuration.accessToken = "Bearer ".concat(accessToken);
194
+ this.tokenData.accessToken = accessToken;
195
+ }
183
196
  if (!targetWorkspace) return [3 /*break*/, 3];
184
197
  return [4 /*yield*/, this.switchWorkspace(targetWorkspace)];
185
198
  case 2:
@@ -205,10 +218,7 @@ var BaseAPI = /** @class */ (function () {
205
218
  options = {
206
219
  method: 'POST',
207
220
  url: "".concat(this.configuration.basePath, "/authservice/v1/workspaces/switch"),
208
- headers: {
209
- 'Content-Type': 'application/json',
210
- 'Authorization': "Bearer ".concat(this.configuration.accessToken),
211
- },
221
+ headers: __assign({ 'Content-Type': 'application/json' }, (this.configuration.cookieAuth ? {} : { 'Authorization': "Bearer ".concat(this.configuration.accessToken) })),
212
222
  data: {
213
223
  username: this.configuration.username,
214
224
  targetWorkspace: targetWorkspace,
@@ -219,9 +229,11 @@ var BaseAPI = /** @class */ (function () {
219
229
  case 1:
220
230
  response = _b.sent();
221
231
  _a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
222
- this.configuration.accessToken = "Bearer ".concat(accessToken);
223
- this.tokenData.accessToken = accessToken;
224
232
  this.tokenData.permissions = permissions;
233
+ if (!this.configuration.cookieAuth) {
234
+ this.configuration.accessToken = "Bearer ".concat(accessToken);
235
+ this.tokenData.accessToken = accessToken;
236
+ }
225
237
  this.storeTokenData(__assign({}, this.tokenData));
226
238
  return [2 /*return*/];
227
239
  }
@@ -264,7 +276,13 @@ var BaseAPI = /** @class */ (function () {
264
276
  });
265
277
  };
266
278
  BaseAPI.prototype.storeTokenData = function (tokenData) {
279
+ var _a;
267
280
  if (typeof window !== 'undefined') {
281
+ if (tokenData && ((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.cookieAuth)) {
282
+ // Cookie mode saves who is logged in, never the token; a token saved by apps not yet migrated stays.
283
+ var username = tokenData.username, permissions = tokenData.permissions;
284
+ tokenData = __assign(__assign({}, ((0, common_1.defaultStorage)().get(TOKEN_DATA) || {})), { username: username, permissions: permissions });
285
+ }
268
286
  (0, common_1.defaultStorage)().set(TOKEN_DATA, tokenData);
269
287
  }
270
288
  };
@@ -299,12 +317,15 @@ var BaseAPI = /** @class */ (function () {
299
317
  return [4 /*yield*/, this.refreshTokenInternal()];
300
318
  case 2:
301
319
  _a = _c.sent(), tokenString = _a.accessToken, permissions = _a.permissions;
302
- accessToken = "Bearer ".concat(tokenString);
303
320
  this.tokenData.permissions = permissions;
304
321
  delete originalConfig.headers['Authorization'];
305
- originalConfig.headers['Authorization'] = accessToken;
306
- this.configuration.accessToken = accessToken;
307
- this.tokenData.accessToken = tokenString;
322
+ // In cookie mode the refresh reply renewed the access cookie, so retry without a header.
323
+ if (!this.configuration.cookieAuth) {
324
+ accessToken = "Bearer ".concat(tokenString);
325
+ originalConfig.headers['Authorization'] = accessToken;
326
+ this.configuration.accessToken = accessToken;
327
+ this.tokenData.accessToken = tokenString;
328
+ }
308
329
  this.storeTokenData(this.tokenData);
309
330
  return [2 /*return*/, axios(originalConfig)];
310
331
  case 3:
@@ -17,6 +17,7 @@ export interface ConfigurationParameters {
17
17
  basePath?: string;
18
18
  baseOptions?: any;
19
19
  formDataCtor?: new () => any;
20
+ cookieAuth?: boolean;
20
21
  }
21
22
  export declare class Configuration {
22
23
  /**
@@ -68,6 +69,14 @@ export declare class Configuration {
68
69
  * @type {new () => FormData}
69
70
  */
70
71
  formDataCtor?: new () => any;
72
+ /**
73
+ * Authenticate with the HttpOnly access cookie instead of a stored token: every call sends credentials.
74
+ * The browser holds one cookie, so use it with one logged-in account; log out through the auth service.
75
+ *
76
+ * @type {boolean}
77
+ * @memberof Configuration
78
+ */
79
+ cookieAuth?: boolean;
71
80
  constructor(param?: ConfigurationParameters);
72
81
  /**
73
82
  * Check if the given MIME is a JSON MIME.
@@ -24,6 +24,7 @@ var Configuration = /** @class */ (function () {
24
24
  this.basePath = param.basePath;
25
25
  this.baseOptions = param.baseOptions;
26
26
  this.formDataCtor = param.formDataCtor;
27
+ this.cookieAuth = param.cookieAuth;
27
28
  }
28
29
  /**
29
30
  * Check if the given MIME is a JSON MIME.
@@ -16,18 +16,18 @@ import { CampaignClass } from './campaign-class';
16
16
  * @interface ListCampaignsResponseClass
17
17
  */
18
18
  export interface ListCampaignsResponseClass {
19
- /**
20
- * campaigns
21
- * @type {Array<CampaignClass>}
22
- * @memberof ListCampaignsResponseClass
23
- */
24
- 'items': Array<CampaignClass>;
25
19
  /**
26
20
  * Next page token.
27
21
  * @type {string}
28
22
  * @memberof ListCampaignsResponseClass
29
23
  */
30
24
  'nextPageToken': string;
25
+ /**
26
+ * Total amount of items.
27
+ * @type {number}
28
+ * @memberof ListCampaignsResponseClass
29
+ */
30
+ 'totalItems': number;
31
31
  /**
32
32
  * Items per page.
33
33
  * @type {number}
@@ -35,9 +35,9 @@ export interface ListCampaignsResponseClass {
35
35
  */
36
36
  'itemsPerPage': number;
37
37
  /**
38
- * Total amount of items.
39
- * @type {number}
38
+ * campaigns
39
+ * @type {Array<CampaignClass>}
40
40
  * @memberof ListCampaignsResponseClass
41
41
  */
42
- 'totalItems': number;
42
+ 'items': Array<CampaignClass>;
43
43
  }
@@ -16,18 +16,18 @@ import { EligibleAccountClass } from './eligible-account-class';
16
16
  * @interface ListEligibleAccountsResponseClass
17
17
  */
18
18
  export interface ListEligibleAccountsResponseClass {
19
- /**
20
- * eligible accounts
21
- * @type {Array<EligibleAccountClass>}
22
- * @memberof ListEligibleAccountsResponseClass
23
- */
24
- 'items': Array<EligibleAccountClass>;
25
19
  /**
26
20
  * Next page token.
27
21
  * @type {string}
28
22
  * @memberof ListEligibleAccountsResponseClass
29
23
  */
30
24
  'nextPageToken': string;
25
+ /**
26
+ * Total amount of items.
27
+ * @type {number}
28
+ * @memberof ListEligibleAccountsResponseClass
29
+ */
30
+ 'totalItems': number;
31
31
  /**
32
32
  * Items per page.
33
33
  * @type {number}
@@ -35,9 +35,9 @@ export interface ListEligibleAccountsResponseClass {
35
35
  */
36
36
  'itemsPerPage': number;
37
37
  /**
38
- * Total amount of items.
39
- * @type {number}
38
+ * eligible accounts
39
+ * @type {Array<EligibleAccountClass>}
40
40
  * @memberof ListEligibleAccountsResponseClass
41
41
  */
42
- 'totalItems': number;
42
+ 'items': Array<EligibleAccountClass>;
43
43
  }
@@ -16,18 +16,18 @@ import { PolicyVoucherClass } from './policy-voucher-class';
16
16
  * @interface ListPolicyVouchersResponseClass
17
17
  */
18
18
  export interface ListPolicyVouchersResponseClass {
19
- /**
20
- * policy vouchers
21
- * @type {Array<PolicyVoucherClass>}
22
- * @memberof ListPolicyVouchersResponseClass
23
- */
24
- 'items': Array<PolicyVoucherClass>;
25
19
  /**
26
20
  * Next page token.
27
21
  * @type {string}
28
22
  * @memberof ListPolicyVouchersResponseClass
29
23
  */
30
24
  'nextPageToken': string;
25
+ /**
26
+ * Total amount of items.
27
+ * @type {number}
28
+ * @memberof ListPolicyVouchersResponseClass
29
+ */
30
+ 'totalItems': number;
31
31
  /**
32
32
  * Items per page.
33
33
  * @type {number}
@@ -35,9 +35,9 @@ export interface ListPolicyVouchersResponseClass {
35
35
  */
36
36
  'itemsPerPage': number;
37
37
  /**
38
- * Total amount of items.
39
- * @type {number}
38
+ * policy vouchers
39
+ * @type {Array<PolicyVoucherClass>}
40
40
  * @memberof ListPolicyVouchersResponseClass
41
41
  */
42
- 'totalItems': number;
42
+ 'items': Array<PolicyVoucherClass>;
43
43
  }
@@ -16,18 +16,18 @@ import { VoucherClass } from './voucher-class';
16
16
  * @interface ListVouchersResponseClass
17
17
  */
18
18
  export interface ListVouchersResponseClass {
19
- /**
20
- * vouchers
21
- * @type {Array<VoucherClass>}
22
- * @memberof ListVouchersResponseClass
23
- */
24
- 'items': Array<VoucherClass>;
25
19
  /**
26
20
  * Next page token.
27
21
  * @type {string}
28
22
  * @memberof ListVouchersResponseClass
29
23
  */
30
24
  'nextPageToken': string;
25
+ /**
26
+ * Total amount of items.
27
+ * @type {number}
28
+ * @memberof ListVouchersResponseClass
29
+ */
30
+ 'totalItems': number;
31
31
  /**
32
32
  * Items per page.
33
33
  * @type {number}
@@ -35,9 +35,9 @@ export interface ListVouchersResponseClass {
35
35
  */
36
36
  'itemsPerPage': number;
37
37
  /**
38
- * Total amount of items.
39
- * @type {number}
38
+ * vouchers
39
+ * @type {Array<VoucherClass>}
40
40
  * @memberof ListVouchersResponseClass
41
41
  */
42
- 'totalItems': number;
42
+ 'items': Array<VoucherClass>;
43
43
  }
@@ -21,18 +21,18 @@ import { CampaignClass } from './campaign-class';
21
21
  * @interface ListCampaignsResponseClass
22
22
  */
23
23
  export interface ListCampaignsResponseClass {
24
- /**
25
- * campaigns
26
- * @type {Array<CampaignClass>}
27
- * @memberof ListCampaignsResponseClass
28
- */
29
- 'items': Array<CampaignClass>;
30
24
  /**
31
25
  * Next page token.
32
26
  * @type {string}
33
27
  * @memberof ListCampaignsResponseClass
34
28
  */
35
29
  'nextPageToken': string;
30
+ /**
31
+ * Total amount of items.
32
+ * @type {number}
33
+ * @memberof ListCampaignsResponseClass
34
+ */
35
+ 'totalItems': number;
36
36
  /**
37
37
  * Items per page.
38
38
  * @type {number}
@@ -40,10 +40,10 @@ export interface ListCampaignsResponseClass {
40
40
  */
41
41
  'itemsPerPage': number;
42
42
  /**
43
- * Total amount of items.
44
- * @type {number}
43
+ * campaigns
44
+ * @type {Array<CampaignClass>}
45
45
  * @memberof ListCampaignsResponseClass
46
46
  */
47
- 'totalItems': number;
47
+ 'items': Array<CampaignClass>;
48
48
  }
49
49
 
@@ -21,18 +21,18 @@ import { EligibleAccountClass } from './eligible-account-class';
21
21
  * @interface ListEligibleAccountsResponseClass
22
22
  */
23
23
  export interface ListEligibleAccountsResponseClass {
24
- /**
25
- * eligible accounts
26
- * @type {Array<EligibleAccountClass>}
27
- * @memberof ListEligibleAccountsResponseClass
28
- */
29
- 'items': Array<EligibleAccountClass>;
30
24
  /**
31
25
  * Next page token.
32
26
  * @type {string}
33
27
  * @memberof ListEligibleAccountsResponseClass
34
28
  */
35
29
  'nextPageToken': string;
30
+ /**
31
+ * Total amount of items.
32
+ * @type {number}
33
+ * @memberof ListEligibleAccountsResponseClass
34
+ */
35
+ 'totalItems': number;
36
36
  /**
37
37
  * Items per page.
38
38
  * @type {number}
@@ -40,10 +40,10 @@ export interface ListEligibleAccountsResponseClass {
40
40
  */
41
41
  'itemsPerPage': number;
42
42
  /**
43
- * Total amount of items.
44
- * @type {number}
43
+ * eligible accounts
44
+ * @type {Array<EligibleAccountClass>}
45
45
  * @memberof ListEligibleAccountsResponseClass
46
46
  */
47
- 'totalItems': number;
47
+ 'items': Array<EligibleAccountClass>;
48
48
  }
49
49
 
@@ -21,18 +21,18 @@ import { PolicyVoucherClass } from './policy-voucher-class';
21
21
  * @interface ListPolicyVouchersResponseClass
22
22
  */
23
23
  export interface ListPolicyVouchersResponseClass {
24
- /**
25
- * policy vouchers
26
- * @type {Array<PolicyVoucherClass>}
27
- * @memberof ListPolicyVouchersResponseClass
28
- */
29
- 'items': Array<PolicyVoucherClass>;
30
24
  /**
31
25
  * Next page token.
32
26
  * @type {string}
33
27
  * @memberof ListPolicyVouchersResponseClass
34
28
  */
35
29
  'nextPageToken': string;
30
+ /**
31
+ * Total amount of items.
32
+ * @type {number}
33
+ * @memberof ListPolicyVouchersResponseClass
34
+ */
35
+ 'totalItems': number;
36
36
  /**
37
37
  * Items per page.
38
38
  * @type {number}
@@ -40,10 +40,10 @@ export interface ListPolicyVouchersResponseClass {
40
40
  */
41
41
  'itemsPerPage': number;
42
42
  /**
43
- * Total amount of items.
44
- * @type {number}
43
+ * policy vouchers
44
+ * @type {Array<PolicyVoucherClass>}
45
45
  * @memberof ListPolicyVouchersResponseClass
46
46
  */
47
- 'totalItems': number;
47
+ 'items': Array<PolicyVoucherClass>;
48
48
  }
49
49
 
@@ -21,18 +21,18 @@ import { VoucherClass } from './voucher-class';
21
21
  * @interface ListVouchersResponseClass
22
22
  */
23
23
  export interface ListVouchersResponseClass {
24
- /**
25
- * vouchers
26
- * @type {Array<VoucherClass>}
27
- * @memberof ListVouchersResponseClass
28
- */
29
- 'items': Array<VoucherClass>;
30
24
  /**
31
25
  * Next page token.
32
26
  * @type {string}
33
27
  * @memberof ListVouchersResponseClass
34
28
  */
35
29
  'nextPageToken': string;
30
+ /**
31
+ * Total amount of items.
32
+ * @type {number}
33
+ * @memberof ListVouchersResponseClass
34
+ */
35
+ 'totalItems': number;
36
36
  /**
37
37
  * Items per page.
38
38
  * @type {number}
@@ -40,10 +40,10 @@ export interface ListVouchersResponseClass {
40
40
  */
41
41
  'itemsPerPage': number;
42
42
  /**
43
- * Total amount of items.
44
- * @type {number}
43
+ * vouchers
44
+ * @type {Array<VoucherClass>}
45
45
  * @memberof ListVouchersResponseClass
46
46
  */
47
- 'totalItems': number;
47
+ 'items': Array<VoucherClass>;
48
48
  }
49
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emilgroup/discount-sdk",
3
- "version": "1.8.1-beta.3",
3
+ "version": "1.14.1-beta.6",
4
4
  "description": "OpenAPI client for @emilgroup/discount-sdk",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "keywords": [
@@ -18,7 +18,7 @@
18
18
  "prepare": "npm run build"
19
19
  },
20
20
  "dependencies": {
21
- "axios": "1.12.0"
21
+ "axios": "1.18.0"
22
22
  },
23
23
  "devDependencies": {
24
24