@emilgroup/settlement-sdk 0.3.1-beta.13 → 0.3.1-beta.14

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/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/settlement-sdk@0.3.1-beta.13 --save
20
+ npm install @emilgroup/settlement-sdk@0.3.1-beta.14 --save
21
21
  ```
22
22
  or
23
23
  ```
24
- yarn add @emilgroup/settlement-sdk@0.3.1-beta.13
24
+ yarn add @emilgroup/settlement-sdk@0.3.1-beta.14
25
25
  ```
26
26
 
27
27
  And then you can import ``.
package/base.ts CHANGED
@@ -93,10 +93,14 @@ export class BaseAPI {
93
93
  this.configuration = configuration;
94
94
  this.basePath = configuration.basePath || this.basePath;
95
95
 
96
- // Use config token if provided, otherwise use tokenData token
97
- const configToken = this.configuration.accessToken;
98
- const storedToken = accessToken ? `Bearer ${accessToken}` : '';
99
- this.configuration.accessToken = configToken || storedToken;
96
+ if (configuration.cookieAuth) {
97
+ this.useCookieAuth();
98
+ } else {
99
+ // Use config token if provided, otherwise use tokenData token
100
+ const configToken = this.configuration.accessToken;
101
+ const storedToken = accessToken ? `Bearer ${accessToken}` : '';
102
+ this.configuration.accessToken = configToken || storedToken;
103
+ }
100
104
  } else {
101
105
  const { accessToken, username } = this.tokenData;
102
106
 
@@ -110,6 +114,12 @@ export class BaseAPI {
110
114
  this.attachInterceptor(axios);
111
115
  }
112
116
 
117
+ // Cookie mode: the browser sends the HttpOnly access cookie, so no token is read from storage.
118
+ private useCookieAuth() {
119
+ this.configuration.username = this.configuration.username || this.tokenData.username;
120
+ this.configuration.baseOptions = { ...this.configuration.baseOptions, withCredentials: true };
121
+ }
122
+
113
123
  selectEnvironment(env: Environment) {
114
124
  this.selectBasePath(env);
115
125
  }
@@ -143,10 +153,12 @@ export class BaseAPI {
143
153
  const { data: { accessToken, permissions } } = response;
144
154
 
145
155
  this.configuration.username = username;
146
- this.configuration.accessToken = `Bearer ${accessToken}`;
147
156
  this.tokenData.username = username;
148
- this.tokenData.accessToken = accessToken;
149
157
  this.tokenData.permissions = permissions;
158
+ if (!this.configuration.cookieAuth) {
159
+ this.configuration.accessToken = `Bearer ${accessToken}`;
160
+ this.tokenData.accessToken = accessToken;
161
+ }
150
162
 
151
163
  }
152
164
 
@@ -184,6 +196,11 @@ export class BaseAPI {
184
196
 
185
197
  private storeTokenData(tokenData?: TokenData) {
186
198
  if (typeof window !== 'undefined') {
199
+ if (tokenData && this.configuration?.cookieAuth) {
200
+ // Cookie mode saves who is logged in, never the token; a token saved by apps not yet migrated stays.
201
+ const { username, permissions } = tokenData;
202
+ tokenData = { ...(defaultStorage().get<TokenData>(TOKEN_DATA) || {}), username, permissions };
203
+ }
187
204
  defaultStorage().set<TokenData>(TOKEN_DATA, tokenData);
188
205
  }
189
206
  }
@@ -214,15 +231,17 @@ export class BaseAPI {
214
231
  originalConfig._retry = true;
215
232
  try {
216
233
  const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
217
- const accessToken = `Bearer ${tokenString}`;
218
234
  this.tokenData.permissions = permissions;
219
235
 
220
236
  delete originalConfig.headers['Authorization']
221
237
 
222
- originalConfig.headers['Authorization'] = accessToken;
223
-
224
- this.configuration.accessToken = accessToken;
225
- this.tokenData.accessToken = tokenString;
238
+ // In cookie mode the refresh reply renewed the access cookie, so retry without a header.
239
+ if (!this.configuration.cookieAuth) {
240
+ const accessToken = `Bearer ${tokenString}`;
241
+ originalConfig.headers['Authorization'] = accessToken;
242
+ this.configuration.accessToken = accessToken;
243
+ this.tokenData.accessToken = tokenString;
244
+ }
226
245
 
227
246
  this.storeTokenData(this.tokenData);
228
247
 
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
  /**
package/dist/base.d.ts CHANGED
@@ -55,6 +55,7 @@ export declare class BaseAPI {
55
55
  protected configuration: Configuration | undefined;
56
56
  private tokenData?;
57
57
  constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
58
+ private useCookieAuth;
58
59
  selectEnvironment(env: Environment): void;
59
60
  selectBasePath(path: string): void;
60
61
  getPermissions(): Array<string>;
package/dist/base.js CHANGED
@@ -128,10 +128,15 @@ var BaseAPI = /** @class */ (function () {
128
128
  var accessToken = this.tokenData.accessToken;
129
129
  this.configuration = configuration;
130
130
  this.basePath = configuration.basePath || this.basePath;
131
- // Use config token if provided, otherwise use tokenData token
132
- var configToken = this.configuration.accessToken;
133
- var storedToken = accessToken ? "Bearer ".concat(accessToken) : '';
134
- 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
+ }
135
140
  }
136
141
  else {
137
142
  var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
@@ -143,6 +148,11 @@ var BaseAPI = /** @class */ (function () {
143
148
  }
144
149
  this.attachInterceptor(axios);
145
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
+ };
146
156
  BaseAPI.prototype.selectEnvironment = function (env) {
147
157
  this.selectBasePath(env);
148
158
  };
@@ -177,10 +187,12 @@ var BaseAPI = /** @class */ (function () {
177
187
  response = _b.sent();
178
188
  _a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
179
189
  this.configuration.username = username;
180
- this.configuration.accessToken = "Bearer ".concat(accessToken);
181
190
  this.tokenData.username = username;
182
- this.tokenData.accessToken = accessToken;
183
191
  this.tokenData.permissions = permissions;
192
+ if (!this.configuration.cookieAuth) {
193
+ this.configuration.accessToken = "Bearer ".concat(accessToken);
194
+ this.tokenData.accessToken = accessToken;
195
+ }
184
196
  return [2 /*return*/];
185
197
  }
186
198
  });
@@ -222,7 +234,13 @@ var BaseAPI = /** @class */ (function () {
222
234
  });
223
235
  };
224
236
  BaseAPI.prototype.storeTokenData = function (tokenData) {
237
+ var _a;
225
238
  if (typeof window !== 'undefined') {
239
+ if (tokenData && ((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.cookieAuth)) {
240
+ // Cookie mode saves who is logged in, never the token; a token saved by apps not yet migrated stays.
241
+ var username = tokenData.username, permissions = tokenData.permissions;
242
+ tokenData = __assign(__assign({}, ((0, common_1.defaultStorage)().get(TOKEN_DATA) || {})), { username: username, permissions: permissions });
243
+ }
226
244
  (0, common_1.defaultStorage)().set(TOKEN_DATA, tokenData);
227
245
  }
228
246
  };
@@ -257,12 +275,15 @@ var BaseAPI = /** @class */ (function () {
257
275
  return [4 /*yield*/, this.refreshTokenInternal()];
258
276
  case 2:
259
277
  _a = _c.sent(), tokenString = _a.accessToken, permissions = _a.permissions;
260
- accessToken = "Bearer ".concat(tokenString);
261
278
  this.tokenData.permissions = permissions;
262
279
  delete originalConfig.headers['Authorization'];
263
- originalConfig.headers['Authorization'] = accessToken;
264
- this.configuration.accessToken = accessToken;
265
- this.tokenData.accessToken = tokenString;
280
+ // In cookie mode the refresh reply renewed the access cookie, so retry without a header.
281
+ if (!this.configuration.cookieAuth) {
282
+ accessToken = "Bearer ".concat(tokenString);
283
+ originalConfig.headers['Authorization'] = accessToken;
284
+ this.configuration.accessToken = accessToken;
285
+ this.tokenData.accessToken = tokenString;
286
+ }
266
287
  this.storeTokenData(this.tokenData);
267
288
  return [2 /*return*/, axios(originalConfig)];
268
289
  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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emilgroup/settlement-sdk",
3
- "version": "0.3.1-beta.13",
3
+ "version": "0.3.1-beta.14",
4
4
  "description": "OpenAPI client for @emilgroup/settlement-sdk",
5
5
  "author": "OpenAPI-Generator Contributors",
6
6
  "keywords": [