@emilgroup/accounting-sdk 1.34.1-beta.8 → 1.34.1-beta.81

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 (172) hide show
  1. package/.openapi-generator/FILES +35 -1
  2. package/README.md +2 -2
  3. package/api/accounting-configs-api.ts +54 -38
  4. package/api/booking-entries-api.ts +234 -10
  5. package/api/commission-account-mappings-api.ts +1207 -0
  6. package/api/financial-accounts-api.ts +150 -20
  7. package/api/financial-transactions-api.ts +8 -4
  8. package/api/number-ranges-api.ts +16 -8
  9. package/api/personal-accounts-api.ts +16 -8
  10. package/api/product-account-mappings-api.ts +1715 -0
  11. package/api.ts +4 -0
  12. package/base.ts +174 -41
  13. package/common.ts +3 -2
  14. package/configuration.ts +20 -0
  15. package/dist/api/accounting-configs-api.d.ts +25 -25
  16. package/dist/api/accounting-configs-api.js +73 -49
  17. package/dist/api/booking-entries-api.d.ts +121 -7
  18. package/dist/api/booking-entries-api.js +211 -14
  19. package/dist/api/commission-account-mappings-api.d.ts +685 -0
  20. package/dist/api/commission-account-mappings-api.js +1022 -0
  21. package/dist/api/financial-accounts-api.d.ts +82 -16
  22. package/dist/api/financial-accounts-api.js +134 -24
  23. package/dist/api/financial-transactions-api.d.ts +2 -2
  24. package/dist/api/financial-transactions-api.js +8 -6
  25. package/dist/api/health-api.d.ts +1 -1
  26. package/dist/api/number-ranges-api.d.ts +4 -4
  27. package/dist/api/number-ranges-api.js +22 -14
  28. package/dist/api/personal-accounts-api.d.ts +4 -4
  29. package/dist/api/personal-accounts-api.js +22 -14
  30. package/dist/api/product-account-mappings-api.d.ts +972 -0
  31. package/dist/api/product-account-mappings-api.js +1447 -0
  32. package/dist/api.d.ts +2 -0
  33. package/dist/api.js +2 -0
  34. package/dist/base.d.ts +24 -0
  35. package/dist/base.js +178 -59
  36. package/dist/common.d.ts +1 -1
  37. package/dist/common.js +1 -0
  38. package/dist/configuration.d.ts +17 -0
  39. package/dist/configuration.js +2 -0
  40. package/dist/models/account-mapping-class.d.ts +2 -0
  41. package/dist/models/account-mapping-class.js +3 -1
  42. package/dist/models/accounting-config-class.d.ts +11 -0
  43. package/dist/models/accounting-config-class.js +5 -0
  44. package/dist/models/accounting-config-data-dto-default-account-mappings.d.ts +8 -0
  45. package/dist/models/accounting-config-data-dto-default-account-mappings.js +3 -1
  46. package/dist/models/booking-entry-class.d.ts +34 -0
  47. package/dist/models/booking-entry-class.js +10 -1
  48. package/dist/models/commission-account-mapping-class.d.ts +49 -0
  49. package/dist/models/commission-agreement-account-mapping-detail-class.d.ts +44 -0
  50. package/dist/models/commission-agreement-account-mapping-detail-class.js +15 -0
  51. package/dist/models/commission-agreement-partner-class.d.ts +30 -0
  52. package/dist/models/commission-agreement-partner-class.js +15 -0
  53. package/dist/models/commission-agreement-with-account-mapping-class.d.ts +43 -0
  54. package/dist/models/commission-agreement-with-account-mapping-class.js +15 -0
  55. package/dist/models/commission-type-account-mapping-class.d.ts +31 -0
  56. package/dist/models/commission-type-account-mapping-class.js +15 -0
  57. package/dist/models/create-booking-entry-request-dto.d.ts +21 -0
  58. package/dist/models/create-booking-entry-request-dto.js +9 -0
  59. package/dist/models/create-financial-account-request-dto.d.ts +8 -0
  60. package/dist/models/create-financial-account-request-dto.js +3 -1
  61. package/dist/models/create-or-correct-opening-balance-dto.d.ts +25 -0
  62. package/dist/models/create-or-correct-opening-balance-dto.js +15 -0
  63. package/dist/models/create-or-correct-opening-balance-response-class.d.ts +25 -0
  64. package/dist/models/create-or-correct-opening-balance-response-class.js +15 -0
  65. package/dist/models/financial-account-class.d.ts +24 -1
  66. package/dist/models/financial-account-class.js +5 -1
  67. package/dist/models/financial-transaction-class.d.ts +6 -0
  68. package/dist/models/financial-transaction-data-dto.d.ts +7 -0
  69. package/dist/models/financial-transaction-data-dto.js +1 -0
  70. package/dist/models/get-activation-snapshot-response-class.d.ts +25 -0
  71. package/dist/models/get-activation-snapshot-response-class.js +15 -0
  72. package/dist/models/index.d.ts +33 -1
  73. package/dist/models/index.js +33 -1
  74. package/dist/models/list-commission-account-mappings-response-class.d.ts +43 -0
  75. package/dist/models/list-commission-account-mappings-response-class.js +15 -0
  76. package/dist/models/list-commission-agreements-with-account-mappings-response-class.d.ts +43 -0
  77. package/dist/models/list-commission-agreements-with-account-mappings-response-class.js +15 -0
  78. package/dist/models/list-commission-type-account-mappings-response-class.d.ts +43 -0
  79. package/dist/models/list-commission-type-account-mappings-response-class.js +15 -0
  80. package/dist/models/list-product-account-mappings-response-class.d.ts +43 -0
  81. package/dist/models/list-product-account-mappings-response-class.js +15 -0
  82. package/dist/models/list-products-with-account-mappings-response-class.d.ts +43 -0
  83. package/dist/models/list-products-with-account-mappings-response-class.js +15 -0
  84. package/dist/models/opening-balance-item-dto.d.ts +41 -0
  85. package/dist/models/opening-balance-item-dto.js +20 -0
  86. package/dist/models/personal-account-class.d.ts +6 -0
  87. package/dist/models/post-financial-event-request-dto.d.ts +45 -0
  88. package/dist/models/post-financial-event-request-dto.js +24 -0
  89. package/dist/models/post-financial-event-response-class.d.ts +25 -0
  90. package/dist/models/post-financial-event-response-class.js +15 -0
  91. package/dist/models/premium-item-account-mapping-class.d.ts +37 -0
  92. package/dist/models/premium-item-account-mapping-class.js +15 -0
  93. package/dist/models/product-account-mapping-class.d.ts +61 -0
  94. package/dist/models/product-account-mapping-class.js +15 -0
  95. package/dist/models/product-account-mapping-detail-class.d.ts +56 -0
  96. package/dist/models/product-account-mapping-detail-class.js +15 -0
  97. package/dist/models/product-risk-carrier-class.d.ts +42 -0
  98. package/dist/models/product-risk-carrier-class.js +15 -0
  99. package/dist/models/product-version-account-mapping-detail-class.d.ts +50 -0
  100. package/dist/models/product-version-account-mapping-detail-class.js +15 -0
  101. package/dist/models/product-version-with-account-mappings-class.d.ts +42 -0
  102. package/dist/models/product-version-with-account-mappings-class.js +15 -0
  103. package/dist/models/product-with-account-mappings-class.d.ts +49 -0
  104. package/dist/models/product-with-account-mappings-class.js +15 -0
  105. package/dist/models/put-premium-item-account-body-dto.d.ts +24 -0
  106. package/dist/models/put-premium-item-account-body-dto.js +15 -0
  107. package/dist/models/put-product-category-account-body-dto.d.ts +24 -0
  108. package/dist/models/put-product-category-account-body-dto.js +15 -0
  109. package/dist/models/put-product-risk-carrier-body-dto.d.ts +24 -0
  110. package/dist/models/put-product-risk-carrier-body-dto.js +15 -0
  111. package/dist/models/put-product-version-category-account-body-dto.d.ts +24 -0
  112. package/dist/models/put-product-version-category-account-body-dto.js +15 -0
  113. package/dist/models/resolved-account-mapping-class.d.ts +31 -0
  114. package/dist/models/resolved-account-mapping-class.js +15 -0
  115. package/dist/models/resolved-commission-account-mapping-class.d.ts +37 -0
  116. package/dist/models/resolved-commission-account-mapping-class.js +21 -0
  117. package/dist/models/update-commission-agreement-account-body-dto.d.ts +24 -0
  118. package/dist/models/update-commission-agreement-account-body-dto.js +15 -0
  119. package/dist/models/update-commission-type-account-body-dto.d.ts +24 -0
  120. package/dist/models/update-commission-type-account-body-dto.js +15 -0
  121. package/dist/models/update-financial-account-body-dto.d.ts +48 -0
  122. package/dist/models/update-financial-account-body-dto.js +15 -0
  123. package/dist/models/update-financial-account-response-class.d.ts +25 -0
  124. package/dist/models/update-financial-account-response-class.js +15 -0
  125. package/models/account-mapping-class.ts +3 -1
  126. package/models/accounting-config-class.ts +14 -0
  127. package/models/accounting-config-data-dto-default-account-mappings.ts +9 -1
  128. package/models/booking-entry-class.ts +35 -0
  129. package/models/commission-account-mapping-class.ts +55 -0
  130. package/models/commission-agreement-account-mapping-detail-class.ts +50 -0
  131. package/models/commission-agreement-partner-class.ts +36 -0
  132. package/models/commission-agreement-with-account-mapping-class.ts +49 -0
  133. package/models/commission-type-account-mapping-class.ts +37 -0
  134. package/models/create-booking-entry-request-dto.ts +24 -0
  135. package/models/create-financial-account-request-dto.ts +9 -1
  136. package/models/create-or-correct-opening-balance-dto.ts +31 -0
  137. package/models/create-or-correct-opening-balance-response-class.ts +31 -0
  138. package/models/financial-account-class.ts +25 -1
  139. package/models/financial-transaction-class.ts +6 -0
  140. package/models/financial-transaction-data-dto.ts +7 -0
  141. package/models/get-activation-snapshot-response-class.ts +31 -0
  142. package/models/index.ts +33 -1
  143. package/models/list-commission-account-mappings-response-class.ts +49 -0
  144. package/models/list-commission-agreements-with-account-mappings-response-class.ts +49 -0
  145. package/models/list-commission-type-account-mappings-response-class.ts +49 -0
  146. package/models/list-product-account-mappings-response-class.ts +49 -0
  147. package/models/list-products-with-account-mappings-response-class.ts +49 -0
  148. package/models/opening-balance-item-dto.ts +50 -0
  149. package/models/personal-account-class.ts +6 -0
  150. package/models/post-financial-event-request-dto.ts +54 -0
  151. package/models/post-financial-event-response-class.ts +31 -0
  152. package/models/premium-item-account-mapping-class.ts +43 -0
  153. package/models/product-account-mapping-class.ts +67 -0
  154. package/models/product-account-mapping-detail-class.ts +62 -0
  155. package/models/product-risk-carrier-class.ts +48 -0
  156. package/models/product-version-account-mapping-detail-class.ts +56 -0
  157. package/models/product-version-with-account-mappings-class.ts +48 -0
  158. package/models/product-with-account-mappings-class.ts +55 -0
  159. package/models/put-premium-item-account-body-dto.ts +30 -0
  160. package/models/put-product-category-account-body-dto.ts +30 -0
  161. package/models/put-product-risk-carrier-body-dto.ts +30 -0
  162. package/models/put-product-version-category-account-body-dto.ts +30 -0
  163. package/models/resolved-account-mapping-class.ts +37 -0
  164. package/models/resolved-commission-account-mapping-class.ts +46 -0
  165. package/models/update-commission-agreement-account-body-dto.ts +30 -0
  166. package/models/update-commission-type-account-body-dto.ts +30 -0
  167. package/models/update-financial-account-body-dto.ts +54 -0
  168. package/models/update-financial-account-response-class.ts +31 -0
  169. package/package.json +2 -2
  170. package/dist/models/get-subledger-settings-response-class.d.ts +0 -36
  171. package/models/get-subledger-settings-response-class.ts +0 -42
  172. /package/dist/models/{get-subledger-settings-response-class.js → commission-account-mapping-class.js} +0 -0
package/api.ts CHANGED
@@ -22,18 +22,22 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj
22
22
  import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
23
23
  import { AccountingConfigsApi } from './api';
24
24
  import { BookingEntriesApi } from './api';
25
+ import { CommissionAccountMappingsApi } from './api';
25
26
  import { FinancialAccountsApi } from './api';
26
27
  import { FinancialTransactionsApi } from './api';
27
28
  import { HealthApi } from './api';
28
29
  import { NumberRangesApi } from './api';
29
30
  import { PersonalAccountsApi } from './api';
31
+ import { ProductAccountMappingsApi } from './api';
30
32
 
31
33
 
32
34
  export * from './api/accounting-configs-api';
33
35
  export * from './api/booking-entries-api';
36
+ export * from './api/commission-account-mappings-api';
34
37
  export * from './api/financial-accounts-api';
35
38
  export * from './api/financial-transactions-api';
36
39
  export * from './api/health-api';
37
40
  export * from './api/number-ranges-api';
38
41
  export * from './api/personal-accounts-api';
42
+ export * from './api/product-account-mappings-api';
39
43
 
package/base.ts CHANGED
@@ -32,9 +32,20 @@ export const COLLECTION_FORMATS = {
32
32
  pipes: "|",
33
33
  };
34
34
 
35
+ export interface SessionClass {
36
+ sub: string;
37
+ username?: string;
38
+ email?: string;
39
+ tenantSlug?: string;
40
+ permissions?: string;
41
+ expiresAt?: number;
42
+ }
43
+
35
44
  export interface LoginClass {
36
45
  accessToken: string;
37
46
  permissions: string;
47
+ authMode?: string;
48
+ session?: SessionClass;
38
49
  }
39
50
 
40
51
  export interface SwitchWorkspaceRequest {
@@ -45,6 +56,8 @@ export interface SwitchWorkspaceRequest {
45
56
  export interface SwitchWorkspaceResponseClass {
46
57
  accessToken: string;
47
58
  permissions: string;
59
+ authMode?: string;
60
+ session?: SessionClass;
48
61
  }
49
62
 
50
63
  export enum Environment {
@@ -77,10 +90,19 @@ interface TokenData {
77
90
  accessToken?: string;
78
91
  username?: string;
79
92
  permissions?: string;
93
+ // 'both' or 'session' when authservice keeps the tokens in a server session.
94
+ authMode?: string;
95
+ sub?: string;
80
96
  }
81
97
 
82
98
  const NETWORK_ERROR_MESSAGE = "Network Error";
83
99
  const TOKEN_DATA = 'APP_TOKEN';
100
+ // Sent only to authservice, to ask for a server session.
101
+ const AUTH_MODE_HEADER = 'X-Emil-Auth-Mode';
102
+ // Names the account on every call; one browser session can hold several.
103
+ const ACCOUNT_HEADER = 'X-Emil-Account';
104
+ const SESSION_MODES = ['both', 'session'];
105
+ const RESEND_SAFE_METHODS = ['get', 'head', 'options'];
84
106
 
85
107
  /**
86
108
  *
@@ -102,10 +124,18 @@ export class BaseAPI {
102
124
  this.configuration = configuration;
103
125
  this.basePath = configuration.basePath || this.basePath;
104
126
 
105
- // Use config token if provided, otherwise use tokenData token
106
- const configToken = this.configuration.accessToken;
107
- const storedToken = accessToken ? `Bearer ${accessToken}` : '';
108
- this.configuration.accessToken = configToken || storedToken;
127
+ if (configuration.cookieAuth) {
128
+ this.configuration.username = this.configuration.username || this.tokenData.username;
129
+ }
130
+
131
+ if (this.usesSession()) {
132
+ this.useSessionAuth();
133
+ } else {
134
+ // Use config token if provided, otherwise use tokenData token
135
+ const configToken = this.configuration.accessToken;
136
+ const storedToken = accessToken ? `Bearer ${accessToken}` : '';
137
+ this.configuration.accessToken = configToken || storedToken;
138
+ }
109
139
  } else {
110
140
  const { accessToken, username } = this.tokenData;
111
141
 
@@ -119,6 +149,107 @@ export class BaseAPI {
119
149
  this.attachInterceptor(axios);
120
150
  }
121
151
 
152
+ // The app's own account wins over APP_TOKEN, which holds whichever tab wrote last.
153
+ private sessionAccount(): string | undefined {
154
+ return this.configuration.account || this.tokenData.sub;
155
+ }
156
+
157
+ // Apps may pass the address as the second argument only; authservice is on the same host.
158
+ private authBasePath(): string {
159
+ return this.configuration.basePath || this.basePath;
160
+ }
161
+
162
+ private usesSession(): boolean {
163
+ return !!this.configuration.cookieAuth && SESSION_MODES.indexOf(this.tokenData.authMode) !== -1 && !!this.sessionAccount();
164
+ }
165
+
166
+ private useSessionAuth() {
167
+ const { headers, ...baseOptions } = this.configuration.baseOptions || {};
168
+ this.configuration.accessToken = '';
169
+ this.configuration.baseOptions = {
170
+ ...baseOptions,
171
+ withCredentials: true,
172
+ headers: { ...headers, [ACCOUNT_HEADER]: this.sessionAccount() },
173
+ };
174
+ }
175
+
176
+ private useHeaderAuth(accessToken: string) {
177
+ this.configuration.accessToken = accessToken ? `Bearer ${accessToken}` : '';
178
+ this.tokenData.accessToken = accessToken;
179
+ delete this.tokenData.authMode;
180
+ delete this.tokenData.sub;
181
+ if (this.configuration.cookieAuth) {
182
+ const { withCredentials, headers, ...baseOptions } = this.configuration.baseOptions || {};
183
+ const { [ACCOUNT_HEADER]: account, ...otherHeaders } = headers || {};
184
+ this.configuration.baseOptions = { ...baseOptions, headers: otherHeaders };
185
+ }
186
+ }
187
+
188
+ private applyTokenReply({ accessToken, authMode, session }: LoginClass) {
189
+ if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && session?.sub) {
190
+ this.tokenData.authMode = authMode;
191
+ this.tokenData.sub = session.sub;
192
+ if (this.configuration.account) {
193
+ // A workspace switch moves the app to another account.
194
+ this.configuration.account = session.sub;
195
+ }
196
+ // Both keeps the token for apps not moved yet; session mode keeps no token at all.
197
+ if (authMode === 'both' && accessToken) {
198
+ this.tokenData.accessToken = accessToken;
199
+ } else {
200
+ delete this.tokenData.accessToken;
201
+ }
202
+ this.useSessionAuth();
203
+ } else {
204
+ this.useHeaderAuth(accessToken);
205
+ }
206
+ }
207
+
208
+ private sessionHeaders(): Record<string, string> {
209
+ if (!this.configuration.cookieAuth) {
210
+ return {};
211
+ }
212
+ return {
213
+ [AUTH_MODE_HEADER]: 'session',
214
+ ...(this.usesSession() && { [ACCOUNT_HEADER]: this.sessionAccount() }),
215
+ };
216
+ }
217
+
218
+ private withCurrentAuth(config: AxiosRequestConfig): AxiosRequestConfig {
219
+ delete config.headers['Authorization'];
220
+ delete config.headers[ACCOUNT_HEADER];
221
+ if (this.usesSession()) {
222
+ config.headers[ACCOUNT_HEADER] = this.sessionAccount();
223
+ config.withCredentials = true;
224
+ } else if (this.configuration.accessToken) {
225
+ config.headers['Authorization'] = this.configuration.accessToken;
226
+ }
227
+ return config;
228
+ }
229
+
230
+ // Both keeps the token, so a session call the browser could not complete can be sent again with it.
231
+ private canRetryWithToken(config: AxiosRequestConfig): boolean {
232
+ return !!config.withCredentials && !!config.headers?.[ACCOUNT_HEADER]
233
+ && !!this.tokenData.accessToken && this.tokenData.authMode !== 'session';
234
+ }
235
+
236
+ // A network error can come after the server ran the call, so only a call that is safe to repeat is sent again.
237
+ private canResend(config: AxiosRequestConfig): boolean {
238
+ return RESEND_SAFE_METHODS.indexOf((config.method || 'get').toLowerCase()) !== -1
239
+ || Object.keys(config.headers || {}).some((name) => name.toLowerCase() === 'idempotency-key');
240
+ }
241
+
242
+ private switchToToken() {
243
+ this.useHeaderAuth(this.tokenData.accessToken);
244
+ this.storeTokenData(this.tokenData);
245
+ }
246
+
247
+ private retryWithToken(axios: AxiosInstance, config: AxiosRequestConfig) {
248
+ this.switchToToken();
249
+ config.withCredentials = false;
250
+ return axios(this.withCurrentAuth(config));
251
+ }
252
+
122
253
  selectEnvironment(env: Environment) {
123
254
  this.selectBasePath(env);
124
255
  }
@@ -138,8 +269,8 @@ export class BaseAPI {
138
269
  async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
139
270
  const options: AxiosRequestConfig = {
140
271
  method: 'POST',
141
- url: `${this.configuration.basePath}/authservice/v1/login`,
142
- headers: { 'Content-Type': 'application/json' },
272
+ url: `${this.authBasePath()}/authservice/v1/login`,
273
+ headers: { 'Content-Type': 'application/json', ...(this.configuration.cookieAuth && { [AUTH_MODE_HEADER]: 'session' }) },
143
274
  data: {
144
275
  username,
145
276
  password,
@@ -149,13 +280,10 @@ export class BaseAPI {
149
280
 
150
281
  const response = await globalAxios.request<LoginClass>(options);
151
282
 
152
- const { data: { accessToken, permissions } } = response;
153
-
154
283
  this.configuration.username = username;
155
- this.configuration.accessToken = `Bearer ${accessToken}`;
156
284
  this.tokenData.username = username;
157
- this.tokenData.accessToken = accessToken;
158
- this.tokenData.permissions = permissions;
285
+ this.tokenData.permissions = response.data.permissions;
286
+ this.applyTokenReply(response.data);
159
287
 
160
288
  // Switch workspace if provided
161
289
  if (targetWorkspace) {
@@ -175,10 +303,11 @@ export class BaseAPI {
175
303
  async switchWorkspace(targetWorkspace: string): Promise<void> {
176
304
  const options: AxiosRequestConfig = {
177
305
  method: 'POST',
178
- url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
306
+ url: `${this.authBasePath()}/authservice/v1/workspaces/switch`,
179
307
  headers: {
180
308
  'Content-Type': 'application/json',
181
- 'Authorization': `Bearer ${this.configuration.accessToken}`,
309
+ ...this.sessionHeaders(),
310
+ ...(!this.usesSession() && !!this.configuration.accessToken && { 'Authorization': this.configuration.accessToken as string }),
182
311
  },
183
312
  data: {
184
313
  username: this.configuration.username,
@@ -189,11 +318,8 @@ export class BaseAPI {
189
318
 
190
319
  const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
191
320
 
192
- const { data: { accessToken, permissions } } = response;
193
-
194
- this.configuration.accessToken = `Bearer ${accessToken}`;
195
- this.tokenData.accessToken = accessToken;
196
- this.tokenData.permissions = permissions;
321
+ this.tokenData.permissions = response.data.permissions;
322
+ this.applyTokenReply(response.data);
197
323
 
198
324
  this.storeTokenData({
199
325
  ...this.tokenData
@@ -219,9 +345,10 @@ export class BaseAPI {
219
345
 
220
346
  const options: AxiosRequestConfig = {
221
347
  method: 'POST',
222
- url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
348
+ url: `${this.authBasePath()}/authservice/v1/refresh-token`,
223
349
  headers: {
224
350
  'Content-Type': 'application/json',
351
+ ...this.sessionHeaders(),
225
352
  },
226
353
  data: { username: username },
227
354
  withCredentials: true,
@@ -262,20 +389,22 @@ export class BaseAPI {
262
389
  && !originalConfig._retry) {
263
390
  originalConfig._retry = true;
264
391
  try {
265
- const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
266
- const accessToken = `Bearer ${tokenString}`;
267
- this.tokenData.permissions = permissions;
268
-
269
- delete originalConfig.headers['Authorization']
270
-
271
- originalConfig.headers['Authorization'] = accessToken;
272
-
273
- this.configuration.accessToken = accessToken;
274
- this.tokenData.accessToken = tokenString;
275
-
392
+ const reply = await this.refreshTokenInternal();
393
+ this.tokenData.permissions = reply.permissions;
394
+ this.applyTokenReply(reply);
276
395
  this.storeTokenData(this.tokenData);
277
396
 
278
- return axios(originalConfig);
397
+ if (!this.usesSession()) {
398
+ return axios(this.withCurrentAuth(originalConfig));
399
+ }
400
+
401
+ // Both mode: if the browser does not send the session cookie (another site), use the token.
402
+ return axios(this.withCurrentAuth(originalConfig)).catch((retryError) => {
403
+ if (retryError?.response?.status !== 401 || !this.tokenData.accessToken) {
404
+ return Promise.reject(retryError);
405
+ }
406
+ return this.retryWithToken(axios, originalConfig);
407
+ });
279
408
  } catch (_error) {
280
409
  if (_error.response && _error.response.data) {
281
410
  return Promise.reject(_error.response.data);
@@ -283,26 +412,30 @@ export class BaseAPI {
283
412
  return Promise.reject(_error);
284
413
  }
285
414
  }
415
+ } else if (err.message === NETWORK_ERROR_MESSAGE && this.canRetryWithToken(originalConfig)) {
416
+ // Both mode: the browser blocked the session call or hid its reply; later calls use the token.
417
+ if (!this.canResend(originalConfig)) {
418
+ this.switchToToken();
419
+ return Promise.reject(err);
420
+ }
421
+ return this.retryWithToken(axios, originalConfig);
286
422
  } else if (err.message === NETWORK_ERROR_MESSAGE
287
- && originalConfig.headers.hasOwnProperty('Authorization')
423
+ && (originalConfig.headers.hasOwnProperty('Authorization')
424
+ || (this.configuration.cookieAuth && originalConfig.withCredentials && this.canResend(originalConfig)))
288
425
  && _retry_count < 4
289
426
  ) {
290
427
  _retry_count++;
291
428
  try {
292
- const { accessToken: tokenString, permissions } = await this.refreshTokenInternal();
293
- const accessToken = `Bearer ${tokenString}`;
294
- this.tokenData.permissions = permissions;
429
+ // In session mode an unreadable 401 (no CORS headers on the error reply) also lands here.
430
+ const reply = await this.refreshTokenInternal();
431
+ this.tokenData.permissions = reply.permissions;
295
432
 
296
433
  _retry = true;
297
- originalConfig.headers['Authorization'] = accessToken;
298
-
299
- this.configuration.accessToken = accessToken;
300
- this.tokenData.accessToken = tokenString;
301
-
434
+ this.applyTokenReply(reply);
302
435
  this.storeTokenData(this.tokenData);
303
436
 
304
437
  return axios.request({
305
- ...originalConfig,
438
+ ...this.withCurrentAuth(originalConfig),
306
439
  });
307
440
  } catch (_error) {
308
441
  if (_error.response && _error.response.data) {
package/common.ts CHANGED
@@ -130,9 +130,10 @@ export const toPathString = function (url: URL) {
130
130
  * @export
131
131
  */
132
132
  export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
133
- return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
133
+ // Typed by hand: since axios 1.20, request() returns an internal axios type that SDK declarations cannot name.
134
+ return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH): Promise<R> => {
134
135
  const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
135
- return axios.request<T, R>(axiosRequestArgs);
136
+ return axios.request<T, R>(axiosRequestArgs) as Promise<R>;
136
137
  };
137
138
  }
138
139
 
package/configuration.ts CHANGED
@@ -21,6 +21,8 @@ export interface ConfigurationParameters {
21
21
  basePath?: string;
22
22
  baseOptions?: any;
23
23
  formDataCtor?: new () => any;
24
+ cookieAuth?: boolean;
25
+ account?: string;
24
26
  }
25
27
 
26
28
  export class Configuration {
@@ -74,6 +76,22 @@ export class Configuration {
74
76
  */
75
77
  formDataCtor?: new () => any;
76
78
 
79
+ /**
80
+ * Use a server session when authservice makes one; otherwise the token, as without this option.
81
+ * Set `account` too, so each SDK object keeps its own account.
82
+ *
83
+ * @type {boolean}
84
+ * @memberof Configuration
85
+ */
86
+ cookieAuth?: boolean;
87
+ /**
88
+ * The session account (Cognito sub) this app shows, so the SDK never takes another tab's account.
89
+ *
90
+ * @type {string}
91
+ * @memberof Configuration
92
+ */
93
+ account?: string;
94
+
77
95
  constructor(param: ConfigurationParameters = {}) {
78
96
  this.apiKey = param.apiKey;
79
97
  this.username = param.username;
@@ -82,6 +100,8 @@ export class Configuration {
82
100
  this.basePath = param.basePath;
83
101
  this.baseOptions = param.baseOptions;
84
102
  this.formDataCtor = param.formDataCtor;
103
+ this.cookieAuth = param.cookieAuth;
104
+ this.account = param.account;
85
105
  }
86
106
 
87
107
  /**
@@ -16,7 +16,7 @@ import { CreateAndEnableSubledgerRequestDto } from '../models';
16
16
  import { CreateAndEnableSubledgerResponseClass } from '../models';
17
17
  import { ExportAccountingConfigResponseClass } from '../models';
18
18
  import { GetAccountingCategoriesResponseClass } from '../models';
19
- import { GetSubledgerSettingsResponseClass } from '../models';
19
+ import { GetActivationSnapshotResponseClass } from '../models';
20
20
  import { ValidateAccountingConfigRequestDto } from '../models';
21
21
  import { ValidateAccountingConfigResponseClass } from '../models';
22
22
  /**
@@ -59,13 +59,13 @@ export declare const AccountingConfigsApiAxiosParamCreator: (configuration?: Con
59
59
  */
60
60
  getAccountingCategories: (authorization?: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
61
61
  /**
62
- * Returns the activation date and accounting configuration settings for the active subledger. **Required Permissions** \"accounting-management.financial-accounts.view\"
63
- * @summary Retrieve the get subledger settings
62
+ * Returns the subledger configuration as it was when the subledger was enabled, along with who created it, when, and its enablement status. **Required Permissions** \"accounting-management.financial-accounts.view\"
63
+ * @summary Retrieve the get activation snapshot
64
64
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
65
65
  * @param {*} [options] Override http request option.
66
66
  * @throws {RequiredError}
67
67
  */
68
- getSubledgerSettings: (authorization?: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
68
+ getActivationSnapshot: (authorization?: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
69
69
  /**
70
70
  * This will reset the subledger, and remove all config and accounts. **Required Permissions** \"accounting-management.financial-accounts.delete\"
71
71
  * @summary Delete the reset subledger
@@ -133,13 +133,13 @@ export declare const AccountingConfigsApiFp: (configuration?: Configuration) =>
133
133
  */
134
134
  getAccountingCategories(authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetAccountingCategoriesResponseClass>>;
135
135
  /**
136
- * Returns the activation date and accounting configuration settings for the active subledger. **Required Permissions** \"accounting-management.financial-accounts.view\"
137
- * @summary Retrieve the get subledger settings
136
+ * Returns the subledger configuration as it was when the subledger was enabled, along with who created it, when, and its enablement status. **Required Permissions** \"accounting-management.financial-accounts.view\"
137
+ * @summary Retrieve the get activation snapshot
138
138
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
139
139
  * @param {*} [options] Override http request option.
140
140
  * @throws {RequiredError}
141
141
  */
142
- getSubledgerSettings(authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetSubledgerSettingsResponseClass>>;
142
+ getActivationSnapshot(authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetActivationSnapshotResponseClass>>;
143
143
  /**
144
144
  * This will reset the subledger, and remove all config and accounts. **Required Permissions** \"accounting-management.financial-accounts.delete\"
145
145
  * @summary Delete the reset subledger
@@ -207,13 +207,13 @@ export declare const AccountingConfigsApiFactory: (configuration?: Configuration
207
207
  */
208
208
  getAccountingCategories(authorization?: string, options?: any): AxiosPromise<GetAccountingCategoriesResponseClass>;
209
209
  /**
210
- * Returns the activation date and accounting configuration settings for the active subledger. **Required Permissions** \"accounting-management.financial-accounts.view\"
211
- * @summary Retrieve the get subledger settings
210
+ * Returns the subledger configuration as it was when the subledger was enabled, along with who created it, when, and its enablement status. **Required Permissions** \"accounting-management.financial-accounts.view\"
211
+ * @summary Retrieve the get activation snapshot
212
212
  * @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
213
213
  * @param {*} [options] Override http request option.
214
214
  * @throws {RequiredError}
215
215
  */
216
- getSubledgerSettings(authorization?: string, options?: any): AxiosPromise<GetSubledgerSettingsResponseClass>;
216
+ getActivationSnapshot(authorization?: string, options?: any): AxiosPromise<GetActivationSnapshotResponseClass>;
217
217
  /**
218
218
  * This will reset the subledger, and remove all config and accounts. **Required Permissions** \"accounting-management.financial-accounts.delete\"
219
219
  * @summary Delete the reset subledger
@@ -306,15 +306,15 @@ export interface AccountingConfigsApiGetAccountingCategoriesRequest {
306
306
  readonly authorization?: string;
307
307
  }
308
308
  /**
309
- * Request parameters for getSubledgerSettings operation in AccountingConfigsApi.
309
+ * Request parameters for getActivationSnapshot operation in AccountingConfigsApi.
310
310
  * @export
311
- * @interface AccountingConfigsApiGetSubledgerSettingsRequest
311
+ * @interface AccountingConfigsApiGetActivationSnapshotRequest
312
312
  */
313
- export interface AccountingConfigsApiGetSubledgerSettingsRequest {
313
+ export interface AccountingConfigsApiGetActivationSnapshotRequest {
314
314
  /**
315
315
  * Bearer Token: provided by the login endpoint under the name accessToken.
316
316
  * @type {string}
317
- * @memberof AccountingConfigsApiGetSubledgerSettings
317
+ * @memberof AccountingConfigsApiGetActivationSnapshot
318
318
  */
319
319
  readonly authorization?: string;
320
320
  }
@@ -384,7 +384,7 @@ export declare class AccountingConfigsApi extends BaseAPI {
384
384
  * @throws {RequiredError}
385
385
  * @memberof AccountingConfigsApi
386
386
  */
387
- createAndEnableSubledger(requestParameters: AccountingConfigsApiCreateAndEnableSubledgerRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateAndEnableSubledgerResponseClass, any, {}>>;
387
+ createAndEnableSubledger(requestParameters: AccountingConfigsApiCreateAndEnableSubledgerRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateAndEnableSubledgerResponseClass, any, {}, any>>;
388
388
  /**
389
389
  * This will create and enable the subledger, using an accounting config from a file. **Required Permissions** \"accounting-management.financial-accounts.create\"
390
390
  * @summary Create the create and enable subledger from file
@@ -393,7 +393,7 @@ export declare class AccountingConfigsApi extends BaseAPI {
393
393
  * @throws {RequiredError}
394
394
  * @memberof AccountingConfigsApi
395
395
  */
396
- createAndEnableSubledgerFromFile(requestParameters: AccountingConfigsApiCreateAndEnableSubledgerFromFileRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateAndEnableSubledgerResponseClass, any, {}>>;
396
+ createAndEnableSubledgerFromFile(requestParameters: AccountingConfigsApiCreateAndEnableSubledgerFromFileRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateAndEnableSubledgerResponseClass, any, {}, any>>;
397
397
  /**
398
398
  * This will export the accounting config. **Required Permissions** \"accounting-management.financial-accounts.view\"
399
399
  * @summary Retrieve the export accounting config
@@ -402,7 +402,7 @@ export declare class AccountingConfigsApi extends BaseAPI {
402
402
  * @throws {RequiredError}
403
403
  * @memberof AccountingConfigsApi
404
404
  */
405
- exportAccountingConfig(requestParameters?: AccountingConfigsApiExportAccountingConfigRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ExportAccountingConfigResponseClass, any, {}>>;
405
+ exportAccountingConfig(requestParameters?: AccountingConfigsApiExportAccountingConfigRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ExportAccountingConfigResponseClass, any, {}, any>>;
406
406
  /**
407
407
  * This will get the accounting categories. **Required Permissions** \"accounting-management.financial-accounts.view\"
408
408
  * @summary Retrieve the accounting categories
@@ -411,16 +411,16 @@ export declare class AccountingConfigsApi extends BaseAPI {
411
411
  * @throws {RequiredError}
412
412
  * @memberof AccountingConfigsApi
413
413
  */
414
- getAccountingCategories(requestParameters?: AccountingConfigsApiGetAccountingCategoriesRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetAccountingCategoriesResponseClass, any, {}>>;
414
+ getAccountingCategories(requestParameters?: AccountingConfigsApiGetAccountingCategoriesRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetAccountingCategoriesResponseClass, any, {}, any>>;
415
415
  /**
416
- * Returns the activation date and accounting configuration settings for the active subledger. **Required Permissions** \"accounting-management.financial-accounts.view\"
417
- * @summary Retrieve the get subledger settings
418
- * @param {AccountingConfigsApiGetSubledgerSettingsRequest} requestParameters Request parameters.
416
+ * Returns the subledger configuration as it was when the subledger was enabled, along with who created it, when, and its enablement status. **Required Permissions** \"accounting-management.financial-accounts.view\"
417
+ * @summary Retrieve the get activation snapshot
418
+ * @param {AccountingConfigsApiGetActivationSnapshotRequest} requestParameters Request parameters.
419
419
  * @param {*} [options] Override http request option.
420
420
  * @throws {RequiredError}
421
421
  * @memberof AccountingConfigsApi
422
422
  */
423
- getSubledgerSettings(requestParameters?: AccountingConfigsApiGetSubledgerSettingsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetSubledgerSettingsResponseClass, any, {}>>;
423
+ getActivationSnapshot(requestParameters?: AccountingConfigsApiGetActivationSnapshotRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetActivationSnapshotResponseClass, any, {}, any>>;
424
424
  /**
425
425
  * This will reset the subledger, and remove all config and accounts. **Required Permissions** \"accounting-management.financial-accounts.delete\"
426
426
  * @summary Delete the reset subledger
@@ -429,7 +429,7 @@ export declare class AccountingConfigsApi extends BaseAPI {
429
429
  * @throws {RequiredError}
430
430
  * @memberof AccountingConfigsApi
431
431
  */
432
- resetSubledger(requestParameters?: AccountingConfigsApiResetSubledgerRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>;
432
+ resetSubledger(requestParameters?: AccountingConfigsApiResetSubledgerRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}, any>>;
433
433
  /**
434
434
  * This will validate accounting config. **Required Permissions** \"accounting-management.financial-accounts.create\"
435
435
  * @summary Create the validate accounting config
@@ -438,7 +438,7 @@ export declare class AccountingConfigsApi extends BaseAPI {
438
438
  * @throws {RequiredError}
439
439
  * @memberof AccountingConfigsApi
440
440
  */
441
- validateAccountingConfig(requestParameters: AccountingConfigsApiValidateAccountingConfigRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ValidateAccountingConfigResponseClass, any, {}>>;
441
+ validateAccountingConfig(requestParameters: AccountingConfigsApiValidateAccountingConfigRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ValidateAccountingConfigResponseClass, any, {}, any>>;
442
442
  /**
443
443
  * This will validate accounting config from a file. **Required Permissions** \"accounting-management.financial-accounts.create\"
444
444
  * @summary Create the validate accounting config from file
@@ -447,5 +447,5 @@ export declare class AccountingConfigsApi extends BaseAPI {
447
447
  * @throws {RequiredError}
448
448
  * @memberof AccountingConfigsApi
449
449
  */
450
- validateAccountingConfigFromFile(requestParameters: AccountingConfigsApiValidateAccountingConfigFromFileRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ValidateAccountingConfigResponseClass, any, {}>>;
450
+ validateAccountingConfigFromFile(requestParameters: AccountingConfigsApiValidateAccountingConfigFromFileRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ValidateAccountingConfigResponseClass, any, {}, any>>;
451
451
  }