@emilgroup/notification-sdk 0.8.1-beta.6 → 0.8.1-beta.60
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/.openapi-generator/FILES +23 -0
- package/README.md +2 -2
- package/api/email-mailboxes-api.ts +150 -0
- package/api/email-messages-api.ts +56 -36
- package/api/email-subscriptions-api.ts +781 -0
- package/api/email-tracking-api.ts +291 -48
- package/api/email-verifications-api.ts +24 -12
- package/api/layouts-api.ts +76 -46
- package/api/msgraph-webhooks-api.ts +278 -0
- package/api/notification-templates-api.ts +76 -46
- package/api/notifications-api.ts +121 -6
- package/api.ts +6 -0
- package/base.ts +174 -41
- package/common.ts +3 -2
- package/configuration.ts +20 -0
- package/dist/api/email-mailboxes-api.d.ts +87 -0
- package/dist/api/email-mailboxes-api.js +221 -0
- package/dist/api/email-messages-api.d.ts +44 -32
- package/dist/api/email-messages-api.js +62 -40
- package/dist/api/email-subscriptions-api.d.ts +432 -0
- package/dist/api/email-subscriptions-api.js +738 -0
- package/dist/api/email-tracking-api.d.ts +174 -44
- package/dist/api/email-tracking-api.js +261 -48
- package/dist/api/email-verifications-api.d.ts +18 -10
- package/dist/api/email-verifications-api.js +30 -16
- package/dist/api/health-api.d.ts +1 -1
- package/dist/api/layouts-api.d.ts +61 -41
- package/dist/api/layouts-api.js +81 -50
- package/dist/api/msgraph-webhooks-api.d.ts +168 -0
- package/dist/api/msgraph-webhooks-api.js +305 -0
- package/dist/api/notification-templates-api.d.ts +61 -41
- package/dist/api/notification-templates-api.js +81 -50
- package/dist/api/notifications-api.d.ts +66 -5
- package/dist/api/notifications-api.js +111 -8
- package/dist/api.d.ts +3 -0
- package/dist/api.js +3 -0
- package/dist/base.d.ts +24 -0
- package/dist/base.js +178 -59
- package/dist/common.d.ts +1 -1
- package/dist/common.js +1 -0
- package/dist/configuration.d.ts +17 -0
- package/dist/configuration.js +2 -0
- package/dist/models/assign-email-thread-entity-body-dto.d.ts +43 -0
- package/dist/models/assign-email-thread-entity-body-dto.js +22 -0
- package/dist/models/assign-email-thread-entity-response-class.d.ts +25 -0
- package/dist/models/assign-email-thread-entity-response-class.js +15 -0
- package/dist/models/catch-up-email-subscription-response-class.d.ts +24 -0
- package/dist/models/catch-up-email-subscription-response-class.js +15 -0
- package/dist/models/catch-up-email-subscriptions-request-dto.d.ts +24 -0
- package/dist/models/catch-up-email-subscriptions-request-dto.js +15 -0
- package/dist/models/catch-up-email-subscriptions-response-class.d.ts +30 -0
- package/dist/models/catch-up-email-subscriptions-response-class.js +15 -0
- package/dist/models/email-mailbox-class.d.ts +47 -0
- package/dist/models/email-mailbox-class.js +20 -0
- package/dist/models/email-message-class.d.ts +73 -7
- package/dist/models/email-message-class.js +22 -3
- package/dist/models/email-message-summary-class.d.ts +98 -0
- package/dist/models/email-message-summary-class.js +33 -0
- package/dist/models/email-subscription-class.d.ts +110 -0
- package/dist/models/email-subscription-class.js +23 -0
- package/dist/models/email-thread-class.d.ts +37 -5
- package/dist/models/entity-ref-class.d.ts +37 -0
- package/dist/models/entity-ref-class.js +22 -0
- package/dist/models/get-email-subscription-response-class.d.ts +25 -0
- package/dist/models/get-email-subscription-response-class.js +15 -0
- package/dist/models/grpc-send-email-request-dto.d.ts +137 -0
- package/dist/models/grpc-send-email-request-dto.js +22 -0
- package/dist/models/index.d.ts +20 -0
- package/dist/models/index.js +20 -0
- package/dist/models/inline-attachment-dto.d.ts +36 -0
- package/dist/models/inline-attachment-dto.js +15 -0
- package/dist/models/list-email-mailboxes-response-class.d.ts +43 -0
- package/dist/models/list-email-mailboxes-response-class.js +15 -0
- package/dist/models/list-email-subscriptions-response-class.d.ts +43 -0
- package/dist/models/list-email-subscriptions-response-class.js +15 -0
- package/dist/models/reconcile-email-subscriptions-request-dto.d.ts +24 -0
- package/dist/models/reconcile-email-subscriptions-request-dto.js +15 -0
- package/dist/models/reconcile-email-subscriptions-response-class.d.ts +48 -0
- package/dist/models/reconcile-email-subscriptions-response-class.js +15 -0
- package/dist/models/renew-email-subscription-response-class.d.ts +25 -0
- package/dist/models/renew-email-subscription-response-class.js +15 -0
- package/dist/models/send-email-request-dto.d.ts +131 -0
- package/dist/models/send-email-request-dto.js +22 -0
- package/dist/models/send-email-response-class.d.ts +24 -0
- package/dist/models/send-email-response-class.js +15 -0
- package/dist/models/send-notification-request-dto.d.ts +10 -1
- package/dist/models/send-notification-request-dto.js +2 -1
- package/dist/models/unassign-email-thread-entity-response-class.d.ts +25 -0
- package/dist/models/unassign-email-thread-entity-response-class.js +15 -0
- package/models/assign-email-thread-entity-body-dto.ts +52 -0
- package/models/assign-email-thread-entity-response-class.ts +31 -0
- package/models/catch-up-email-subscription-response-class.ts +30 -0
- package/models/catch-up-email-subscriptions-request-dto.ts +30 -0
- package/models/catch-up-email-subscriptions-response-class.ts +36 -0
- package/models/email-mailbox-class.ts +56 -0
- package/models/email-message-class.ts +78 -8
- package/models/email-message-summary-class.ts +109 -0
- package/models/email-subscription-class.ts +119 -0
- package/models/email-thread-class.ts +37 -5
- package/models/entity-ref-class.ts +46 -0
- package/models/get-email-subscription-response-class.ts +31 -0
- package/models/grpc-send-email-request-dto.ts +144 -0
- package/models/index.ts +20 -0
- package/models/inline-attachment-dto.ts +42 -0
- package/models/list-email-mailboxes-response-class.ts +49 -0
- package/models/list-email-subscriptions-response-class.ts +49 -0
- package/models/reconcile-email-subscriptions-request-dto.ts +30 -0
- package/models/reconcile-email-subscriptions-response-class.ts +54 -0
- package/models/renew-email-subscription-response-class.ts +31 -0
- package/models/send-email-request-dto.ts +138 -0
- package/models/send-email-response-class.ts +30 -0
- package/models/send-notification-request-dto.ts +9 -2
- package/models/unassign-email-thread-entity-response-class.ts +31 -0
- package/package.json +2 -2
package/api/notifications-api.ts
CHANGED
|
@@ -21,6 +21,10 @@ 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
|
// @ts-ignore
|
|
24
|
+
import { SendEmailRequestDto } from '../models';
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
import { SendEmailResponseClass } from '../models';
|
|
27
|
+
// @ts-ignore
|
|
24
28
|
import { SendNotificationRequestDto } from '../models';
|
|
25
29
|
// @ts-ignore
|
|
26
30
|
import { SendNotificationResponseClass } from '../models';
|
|
@@ -31,7 +35,57 @@ import { SendNotificationResponseClass } from '../models';
|
|
|
31
35
|
export const NotificationsApiAxiosParamCreator = function (configuration?: Configuration) {
|
|
32
36
|
return {
|
|
33
37
|
/**
|
|
34
|
-
*
|
|
38
|
+
* Sends an email with a caller-supplied HTML and/or text body, delivered as given. Attachments can reference documents already in S3 or be sent inline as base64. **Required Permissions** none
|
|
39
|
+
* @summary Send an email without a template
|
|
40
|
+
* @param {SendEmailRequestDto} sendEmailRequestDto
|
|
41
|
+
* @param {string} [authorization] Bearer Token
|
|
42
|
+
* @param {*} [options] Override http request option.
|
|
43
|
+
* @throws {RequiredError}
|
|
44
|
+
*/
|
|
45
|
+
sendEmail: async (sendEmailRequestDto: SendEmailRequestDto, authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
|
46
|
+
// verify required parameter 'sendEmailRequestDto' is not null or undefined
|
|
47
|
+
assertParamExists('sendEmail', 'sendEmailRequestDto', sendEmailRequestDto)
|
|
48
|
+
const localVarPath = `/notificationservice/v1/notifications/emails`;
|
|
49
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
50
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
51
|
+
let baseOptions;
|
|
52
|
+
let baseAccessToken;
|
|
53
|
+
if (configuration) {
|
|
54
|
+
baseOptions = configuration.baseOptions;
|
|
55
|
+
baseAccessToken = configuration.accessToken;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
|
|
59
|
+
const localVarHeaderParameter = {} as any;
|
|
60
|
+
const localVarQueryParameter = {} as any;
|
|
61
|
+
|
|
62
|
+
// authentication bearer required
|
|
63
|
+
// http bearer authentication required
|
|
64
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration)
|
|
65
|
+
|
|
66
|
+
// Only Authorization falls back to the configured token; an empty value is never sent.
|
|
67
|
+
const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
|
|
68
|
+
if (authorizationValue) {
|
|
69
|
+
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
75
|
+
|
|
76
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
77
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
78
|
+
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
|
79
|
+
localVarRequestOptions.data = serializeDataIfNeeded(sendEmailRequestDto, localVarRequestOptions, configuration)
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
url: toPathString(localVarUrlObj),
|
|
83
|
+
options: localVarRequestOptions,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Sends an email using the notification template identified by `templateSlug`. Provide `entityType` and `entityCode` to track replies in an email thread. **Required Permissions** none
|
|
88
|
+
* @summary Send a notification
|
|
35
89
|
* @param {SendNotificationRequestDto} sendNotificationRequestDto
|
|
36
90
|
* @param {string} [authorization] Bearer Token
|
|
37
91
|
* @param {*} [options] Override http request option.
|
|
@@ -58,8 +112,10 @@ export const NotificationsApiAxiosParamCreator = function (configuration?: Confi
|
|
|
58
112
|
// http bearer authentication required
|
|
59
113
|
await setBearerAuthToObject(localVarHeaderParameter, configuration)
|
|
60
114
|
|
|
61
|
-
|
|
62
|
-
|
|
115
|
+
// Only Authorization falls back to the configured token; an empty value is never sent.
|
|
116
|
+
const authorizationValue = 'Authorization'.toLowerCase() === 'authorization' ? (authorization || baseAccessToken) : authorization;
|
|
117
|
+
if (authorizationValue) {
|
|
118
|
+
localVarHeaderParameter['Authorization'] = String(authorizationValue);
|
|
63
119
|
}
|
|
64
120
|
|
|
65
121
|
|
|
@@ -87,7 +143,20 @@ export const NotificationsApiFp = function(configuration?: Configuration) {
|
|
|
87
143
|
const localVarAxiosParamCreator = NotificationsApiAxiosParamCreator(configuration)
|
|
88
144
|
return {
|
|
89
145
|
/**
|
|
90
|
-
*
|
|
146
|
+
* Sends an email with a caller-supplied HTML and/or text body, delivered as given. Attachments can reference documents already in S3 or be sent inline as base64. **Required Permissions** none
|
|
147
|
+
* @summary Send an email without a template
|
|
148
|
+
* @param {SendEmailRequestDto} sendEmailRequestDto
|
|
149
|
+
* @param {string} [authorization] Bearer Token
|
|
150
|
+
* @param {*} [options] Override http request option.
|
|
151
|
+
* @throws {RequiredError}
|
|
152
|
+
*/
|
|
153
|
+
async sendEmail(sendEmailRequestDto: SendEmailRequestDto, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<SendEmailResponseClass>> {
|
|
154
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.sendEmail(sendEmailRequestDto, authorization, options);
|
|
155
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Sends an email using the notification template identified by `templateSlug`. Provide `entityType` and `entityCode` to track replies in an email thread. **Required Permissions** none
|
|
159
|
+
* @summary Send a notification
|
|
91
160
|
* @param {SendNotificationRequestDto} sendNotificationRequestDto
|
|
92
161
|
* @param {string} [authorization] Bearer Token
|
|
93
162
|
* @param {*} [options] Override http request option.
|
|
@@ -108,7 +177,19 @@ export const NotificationsApiFactory = function (configuration?: Configuration,
|
|
|
108
177
|
const localVarFp = NotificationsApiFp(configuration)
|
|
109
178
|
return {
|
|
110
179
|
/**
|
|
111
|
-
*
|
|
180
|
+
* Sends an email with a caller-supplied HTML and/or text body, delivered as given. Attachments can reference documents already in S3 or be sent inline as base64. **Required Permissions** none
|
|
181
|
+
* @summary Send an email without a template
|
|
182
|
+
* @param {SendEmailRequestDto} sendEmailRequestDto
|
|
183
|
+
* @param {string} [authorization] Bearer Token
|
|
184
|
+
* @param {*} [options] Override http request option.
|
|
185
|
+
* @throws {RequiredError}
|
|
186
|
+
*/
|
|
187
|
+
sendEmail(sendEmailRequestDto: SendEmailRequestDto, authorization?: string, options?: any): AxiosPromise<SendEmailResponseClass> {
|
|
188
|
+
return localVarFp.sendEmail(sendEmailRequestDto, authorization, options).then((request) => request(axios, basePath));
|
|
189
|
+
},
|
|
190
|
+
/**
|
|
191
|
+
* Sends an email using the notification template identified by `templateSlug`. Provide `entityType` and `entityCode` to track replies in an email thread. **Required Permissions** none
|
|
192
|
+
* @summary Send a notification
|
|
112
193
|
* @param {SendNotificationRequestDto} sendNotificationRequestDto
|
|
113
194
|
* @param {string} [authorization] Bearer Token
|
|
114
195
|
* @param {*} [options] Override http request option.
|
|
@@ -120,6 +201,27 @@ export const NotificationsApiFactory = function (configuration?: Configuration,
|
|
|
120
201
|
};
|
|
121
202
|
};
|
|
122
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Request parameters for sendEmail operation in NotificationsApi.
|
|
206
|
+
* @export
|
|
207
|
+
* @interface NotificationsApiSendEmailRequest
|
|
208
|
+
*/
|
|
209
|
+
export interface NotificationsApiSendEmailRequest {
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @type {SendEmailRequestDto}
|
|
213
|
+
* @memberof NotificationsApiSendEmail
|
|
214
|
+
*/
|
|
215
|
+
readonly sendEmailRequestDto: SendEmailRequestDto
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Bearer Token
|
|
219
|
+
* @type {string}
|
|
220
|
+
* @memberof NotificationsApiSendEmail
|
|
221
|
+
*/
|
|
222
|
+
readonly authorization?: string
|
|
223
|
+
}
|
|
224
|
+
|
|
123
225
|
/**
|
|
124
226
|
* Request parameters for sendNotification operation in NotificationsApi.
|
|
125
227
|
* @export
|
|
@@ -149,7 +251,20 @@ export interface NotificationsApiSendNotificationRequest {
|
|
|
149
251
|
*/
|
|
150
252
|
export class NotificationsApi extends BaseAPI {
|
|
151
253
|
/**
|
|
152
|
-
*
|
|
254
|
+
* Sends an email with a caller-supplied HTML and/or text body, delivered as given. Attachments can reference documents already in S3 or be sent inline as base64. **Required Permissions** none
|
|
255
|
+
* @summary Send an email without a template
|
|
256
|
+
* @param {NotificationsApiSendEmailRequest} requestParameters Request parameters.
|
|
257
|
+
* @param {*} [options] Override http request option.
|
|
258
|
+
* @throws {RequiredError}
|
|
259
|
+
* @memberof NotificationsApi
|
|
260
|
+
*/
|
|
261
|
+
public sendEmail(requestParameters: NotificationsApiSendEmailRequest, options?: AxiosRequestConfig) {
|
|
262
|
+
return NotificationsApiFp(this.configuration).sendEmail(requestParameters.sendEmailRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Sends an email using the notification template identified by `templateSlug`. Provide `entityType` and `entityCode` to track replies in an email thread. **Required Permissions** none
|
|
267
|
+
* @summary Send a notification
|
|
153
268
|
* @param {NotificationsApiSendNotificationRequest} requestParameters Request parameters.
|
|
154
269
|
* @param {*} [options] Override http request option.
|
|
155
270
|
* @throws {RequiredError}
|
package/api.ts
CHANGED
|
@@ -20,20 +20,26 @@ import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResp
|
|
|
20
20
|
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
|
|
21
21
|
// @ts-ignore
|
|
22
22
|
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
|
|
23
|
+
import { EmailMailboxesApi } from './api';
|
|
23
24
|
import { EmailMessagesApi } from './api';
|
|
25
|
+
import { EmailSubscriptionsApi } from './api';
|
|
24
26
|
import { EmailTrackingApi } from './api';
|
|
25
27
|
import { EmailVerificationsApi } from './api';
|
|
26
28
|
import { HealthApi } from './api';
|
|
27
29
|
import { LayoutsApi } from './api';
|
|
30
|
+
import { MSGraphWebhooksApi } from './api';
|
|
28
31
|
import { NotificationTemplatesApi } from './api';
|
|
29
32
|
import { NotificationsApi } from './api';
|
|
30
33
|
|
|
31
34
|
|
|
35
|
+
export * from './api/email-mailboxes-api';
|
|
32
36
|
export * from './api/email-messages-api';
|
|
37
|
+
export * from './api/email-subscriptions-api';
|
|
33
38
|
export * from './api/email-tracking-api';
|
|
34
39
|
export * from './api/email-verifications-api';
|
|
35
40
|
export * from './api/health-api';
|
|
36
41
|
export * from './api/layouts-api';
|
|
42
|
+
export * from './api/msgraph-webhooks-api';
|
|
37
43
|
export * from './api/notification-templates-api';
|
|
38
44
|
export * from './api/notifications-api';
|
|
39
45
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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.
|
|
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.
|
|
158
|
-
this.
|
|
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.
|
|
306
|
+
url: `${this.authBasePath()}/authservice/v1/workspaces/switch`,
|
|
179
307
|
headers: {
|
|
180
308
|
'Content-Type': 'application/json',
|
|
181
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
266
|
-
|
|
267
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
293
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EMIL NotificationService
|
|
3
|
+
* The EMIL NotificationService API description
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: 1.0
|
|
6
|
+
* Contact: kontakt@emil.de
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
13
|
+
import { Configuration } from '../configuration';
|
|
14
|
+
import { RequestArgs, BaseAPI } from '../base';
|
|
15
|
+
import { ListEmailMailboxesResponseClass } from '../models';
|
|
16
|
+
/**
|
|
17
|
+
* EmailMailboxesApi - axios parameter creator
|
|
18
|
+
* @export
|
|
19
|
+
*/
|
|
20
|
+
export declare const EmailMailboxesApiAxiosParamCreator: (configuration?: Configuration) => {
|
|
21
|
+
/**
|
|
22
|
+
* Returns the mailboxes of the tenant, sorted by address: the ones its email channel is configured with, merged with the ones that still have messages. Each mailbox carries how many messages it holds per direction. Use the address as the `mailbox` filter when listing email threads or messages. **Required Permissions** \"notification-management.email-messages.view\"
|
|
23
|
+
* @summary List the email mailboxes
|
|
24
|
+
* @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
|
|
25
|
+
* @param {*} [options] Override http request option.
|
|
26
|
+
* @throws {RequiredError}
|
|
27
|
+
*/
|
|
28
|
+
listEmailMailboxes: (authorization?: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* EmailMailboxesApi - functional programming interface
|
|
32
|
+
* @export
|
|
33
|
+
*/
|
|
34
|
+
export declare const EmailMailboxesApiFp: (configuration?: Configuration) => {
|
|
35
|
+
/**
|
|
36
|
+
* Returns the mailboxes of the tenant, sorted by address: the ones its email channel is configured with, merged with the ones that still have messages. Each mailbox carries how many messages it holds per direction. Use the address as the `mailbox` filter when listing email threads or messages. **Required Permissions** \"notification-management.email-messages.view\"
|
|
37
|
+
* @summary List the email mailboxes
|
|
38
|
+
* @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
|
|
39
|
+
* @param {*} [options] Override http request option.
|
|
40
|
+
* @throws {RequiredError}
|
|
41
|
+
*/
|
|
42
|
+
listEmailMailboxes(authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ListEmailMailboxesResponseClass>>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* EmailMailboxesApi - factory interface
|
|
46
|
+
* @export
|
|
47
|
+
*/
|
|
48
|
+
export declare const EmailMailboxesApiFactory: (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) => {
|
|
49
|
+
/**
|
|
50
|
+
* Returns the mailboxes of the tenant, sorted by address: the ones its email channel is configured with, merged with the ones that still have messages. Each mailbox carries how many messages it holds per direction. Use the address as the `mailbox` filter when listing email threads or messages. **Required Permissions** \"notification-management.email-messages.view\"
|
|
51
|
+
* @summary List the email mailboxes
|
|
52
|
+
* @param {string} [authorization] Bearer Token: provided by the login endpoint under the name accessToken.
|
|
53
|
+
* @param {*} [options] Override http request option.
|
|
54
|
+
* @throws {RequiredError}
|
|
55
|
+
*/
|
|
56
|
+
listEmailMailboxes(authorization?: string, options?: any): AxiosPromise<ListEmailMailboxesResponseClass>;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Request parameters for listEmailMailboxes operation in EmailMailboxesApi.
|
|
60
|
+
* @export
|
|
61
|
+
* @interface EmailMailboxesApiListEmailMailboxesRequest
|
|
62
|
+
*/
|
|
63
|
+
export interface EmailMailboxesApiListEmailMailboxesRequest {
|
|
64
|
+
/**
|
|
65
|
+
* Bearer Token: provided by the login endpoint under the name accessToken.
|
|
66
|
+
* @type {string}
|
|
67
|
+
* @memberof EmailMailboxesApiListEmailMailboxes
|
|
68
|
+
*/
|
|
69
|
+
readonly authorization?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* EmailMailboxesApi - object-oriented interface
|
|
73
|
+
* @export
|
|
74
|
+
* @class EmailMailboxesApi
|
|
75
|
+
* @extends {BaseAPI}
|
|
76
|
+
*/
|
|
77
|
+
export declare class EmailMailboxesApi extends BaseAPI {
|
|
78
|
+
/**
|
|
79
|
+
* Returns the mailboxes of the tenant, sorted by address: the ones its email channel is configured with, merged with the ones that still have messages. Each mailbox carries how many messages it holds per direction. Use the address as the `mailbox` filter when listing email threads or messages. **Required Permissions** \"notification-management.email-messages.view\"
|
|
80
|
+
* @summary List the email mailboxes
|
|
81
|
+
* @param {EmailMailboxesApiListEmailMailboxesRequest} requestParameters Request parameters.
|
|
82
|
+
* @param {*} [options] Override http request option.
|
|
83
|
+
* @throws {RequiredError}
|
|
84
|
+
* @memberof EmailMailboxesApi
|
|
85
|
+
*/
|
|
86
|
+
listEmailMailboxes(requestParameters?: EmailMailboxesApiListEmailMailboxesRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListEmailMailboxesResponseClass, any, {}, any>>;
|
|
87
|
+
}
|