@emilgroup/notification-sdk-node 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.openapi-generator/FILES +38 -0
  2. package/.openapi-generator/VERSION +1 -0
  3. package/.openapi-generator-ignore +23 -0
  4. package/README.md +68 -0
  5. package/api/layouts-api.ts +663 -0
  6. package/api/notification-templates-api.ts +677 -0
  7. package/api/notifications-api.ts +165 -0
  8. package/api.ts +35 -0
  9. package/base.ts +284 -0
  10. package/common.ts +199 -0
  11. package/configuration.ts +109 -0
  12. package/dist/api/layouts-api.d.ts +364 -0
  13. package/dist/api/layouts-api.js +622 -0
  14. package/dist/api/notification-templates-api.d.ts +373 -0
  15. package/dist/api/notification-templates-api.js +628 -0
  16. package/dist/api/notifications-api.d.ts +93 -0
  17. package/dist/api/notifications-api.js +224 -0
  18. package/dist/api.d.ts +14 -0
  19. package/dist/api.js +32 -0
  20. package/dist/base.d.ts +77 -0
  21. package/dist/base.js +393 -0
  22. package/dist/common.d.ts +92 -0
  23. package/dist/common.js +277 -0
  24. package/dist/configuration.d.ts +90 -0
  25. package/dist/configuration.js +44 -0
  26. package/dist/index.d.ts +15 -0
  27. package/dist/index.js +36 -0
  28. package/dist/models/create-layout-request-dto.d.ts +48 -0
  29. package/dist/models/create-layout-request-dto.js +15 -0
  30. package/dist/models/create-layout-response-class.d.ts +25 -0
  31. package/dist/models/create-layout-response-class.js +15 -0
  32. package/dist/models/create-notification-template-request-dto.d.ts +66 -0
  33. package/dist/models/create-notification-template-request-dto.js +15 -0
  34. package/dist/models/create-notification-template-response-class.d.ts +25 -0
  35. package/dist/models/create-notification-template-response-class.js +15 -0
  36. package/dist/models/delete-layout-request-dto.d.ts +24 -0
  37. package/dist/models/delete-layout-request-dto.js +15 -0
  38. package/dist/models/delete-notification-template-request-dto.d.ts +24 -0
  39. package/dist/models/delete-notification-template-request-dto.js +15 -0
  40. package/dist/models/get-layout-request-dto.d.ts +24 -0
  41. package/dist/models/get-layout-request-dto.js +15 -0
  42. package/dist/models/get-layout-response-class.d.ts +25 -0
  43. package/dist/models/get-layout-response-class.js +15 -0
  44. package/dist/models/get-notification-template-request-dto.d.ts +30 -0
  45. package/dist/models/get-notification-template-request-dto.js +15 -0
  46. package/dist/models/get-notification-template-response-class.d.ts +25 -0
  47. package/dist/models/get-notification-template-response-class.js +15 -0
  48. package/dist/models/html-template-class.d.ts +60 -0
  49. package/dist/models/html-template-class.js +15 -0
  50. package/dist/models/index.d.ts +22 -0
  51. package/dist/models/index.js +38 -0
  52. package/dist/models/layout-class.d.ts +73 -0
  53. package/dist/models/layout-class.js +15 -0
  54. package/dist/models/list-layouts-response-class.d.ts +30 -0
  55. package/dist/models/list-layouts-response-class.js +15 -0
  56. package/dist/models/list-notification-templates-response-class.d.ts +30 -0
  57. package/dist/models/list-notification-templates-response-class.js +15 -0
  58. package/dist/models/notification-template-class.d.ts +98 -0
  59. package/dist/models/notification-template-class.js +15 -0
  60. package/dist/models/send-notification-request-dto.d.ts +66 -0
  61. package/dist/models/send-notification-request-dto.js +15 -0
  62. package/dist/models/send-notification-response-class.d.ts +24 -0
  63. package/dist/models/send-notification-response-class.js +15 -0
  64. package/dist/models/update-html-template-request-dto.d.ts +42 -0
  65. package/dist/models/update-html-template-request-dto.js +21 -0
  66. package/dist/models/update-layout-request-dto.d.ts +55 -0
  67. package/dist/models/update-layout-request-dto.js +15 -0
  68. package/dist/models/update-layout-response-class.d.ts +25 -0
  69. package/dist/models/update-layout-response-class.js +15 -0
  70. package/dist/models/update-notification-template-request-dto.d.ts +73 -0
  71. package/dist/models/update-notification-template-request-dto.js +15 -0
  72. package/dist/models/update-notification-template-response-class.d.ts +25 -0
  73. package/dist/models/update-notification-template-response-class.js +15 -0
  74. package/git_push.sh +57 -0
  75. package/index.ts +19 -0
  76. package/models/create-layout-request-dto.ts +54 -0
  77. package/models/create-layout-response-class.ts +31 -0
  78. package/models/create-notification-template-request-dto.ts +72 -0
  79. package/models/create-notification-template-response-class.ts +31 -0
  80. package/models/delete-layout-request-dto.ts +30 -0
  81. package/models/delete-notification-template-request-dto.ts +30 -0
  82. package/models/get-layout-request-dto.ts +30 -0
  83. package/models/get-layout-response-class.ts +31 -0
  84. package/models/get-notification-template-request-dto.ts +36 -0
  85. package/models/get-notification-template-response-class.ts +31 -0
  86. package/models/html-template-class.ts +66 -0
  87. package/models/index.ts +22 -0
  88. package/models/layout-class.ts +79 -0
  89. package/models/list-layouts-response-class.ts +36 -0
  90. package/models/list-notification-templates-response-class.ts +36 -0
  91. package/models/notification-template-class.ts +104 -0
  92. package/models/send-notification-request-dto.ts +72 -0
  93. package/models/send-notification-response-class.ts +30 -0
  94. package/models/update-html-template-request-dto.ts +51 -0
  95. package/models/update-layout-request-dto.ts +61 -0
  96. package/models/update-layout-response-class.ts +31 -0
  97. package/models/update-notification-template-request-dto.ts +79 -0
  98. package/models/update-notification-template-response-class.ts +31 -0
  99. package/package.json +29 -0
  100. package/tsconfig.json +22 -0
@@ -0,0 +1,165 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL NotificationService
5
+ * The EMIL NotificationService API description
6
+ *
7
+ * The version of the OpenAPI document: 1.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
17
+ import { Configuration } from '../configuration';
18
+ // Some imports not used depending on template conditions
19
+ // @ts-ignore
20
+ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
21
+ // @ts-ignore
22
+ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
23
+ // @ts-ignore
24
+ import { SendNotificationRequestDto } from '../models';
25
+ // @ts-ignore
26
+ import { SendNotificationResponseClass } from '../models';
27
+ // URLSearchParams not necessarily used
28
+ // @ts-ignore
29
+ import { URL, URLSearchParams } from 'url';
30
+ const FormData = require('form-data');
31
+ /**
32
+ * NotificationsApi - axios parameter creator
33
+ * @export
34
+ */
35
+ export const NotificationsApiAxiosParamCreator = function (configuration?: Configuration) {
36
+ return {
37
+ /**
38
+ *
39
+ * @param {SendNotificationRequestDto} sendNotificationRequestDto
40
+ * @param {string} [authorization] Bearer Token
41
+ * @param {*} [options] Override http request option.
42
+ * @throws {RequiredError}
43
+ */
44
+ sendNotification: async (sendNotificationRequestDto: SendNotificationRequestDto, authorization?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
45
+ // verify required parameter 'sendNotificationRequestDto' is not null or undefined
46
+ assertParamExists('sendNotification', 'sendNotificationRequestDto', sendNotificationRequestDto)
47
+ const localVarPath = `/notificationservice/v1/notifications`;
48
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
49
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
50
+ let baseOptions;
51
+ let baseAccessToken;
52
+ if (configuration) {
53
+ baseOptions = configuration.baseOptions;
54
+ baseAccessToken = configuration.accessToken;
55
+ }
56
+
57
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
58
+ const localVarHeaderParameter = {} as any;
59
+ const localVarQueryParameter = {} as any;
60
+
61
+ // authentication bearer required
62
+ // http bearer authentication required
63
+ await setBearerAuthToObject(localVarHeaderParameter, configuration)
64
+
65
+ if (authorization !== undefined && authorization !== null || baseAccessToken !== undefined && baseAccessToken !== null) {
66
+ localVarHeaderParameter['Authorization'] = String(authorization ? authorization : baseAccessToken);
67
+ }
68
+
69
+
70
+
71
+ localVarHeaderParameter['Content-Type'] = 'application/json';
72
+
73
+ setSearchParams(localVarUrlObj, localVarQueryParameter);
74
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
75
+ localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
76
+ localVarRequestOptions.data = serializeDataIfNeeded(sendNotificationRequestDto, localVarRequestOptions, configuration)
77
+
78
+ return {
79
+ url: toPathString(localVarUrlObj),
80
+ options: localVarRequestOptions,
81
+ };
82
+ },
83
+ }
84
+ };
85
+
86
+ /**
87
+ * NotificationsApi - functional programming interface
88
+ * @export
89
+ */
90
+ export const NotificationsApiFp = function(configuration?: Configuration) {
91
+ const localVarAxiosParamCreator = NotificationsApiAxiosParamCreator(configuration)
92
+ return {
93
+ /**
94
+ *
95
+ * @param {SendNotificationRequestDto} sendNotificationRequestDto
96
+ * @param {string} [authorization] Bearer Token
97
+ * @param {*} [options] Override http request option.
98
+ * @throws {RequiredError}
99
+ */
100
+ async sendNotification(sendNotificationRequestDto: SendNotificationRequestDto, authorization?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<SendNotificationResponseClass>> {
101
+ const localVarAxiosArgs = await localVarAxiosParamCreator.sendNotification(sendNotificationRequestDto, authorization, options);
102
+ return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
103
+ },
104
+ }
105
+ };
106
+
107
+ /**
108
+ * NotificationsApi - factory interface
109
+ * @export
110
+ */
111
+ export const NotificationsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
112
+ const localVarFp = NotificationsApiFp(configuration)
113
+ return {
114
+ /**
115
+ *
116
+ * @param {SendNotificationRequestDto} sendNotificationRequestDto
117
+ * @param {string} [authorization] Bearer Token
118
+ * @param {*} [options] Override http request option.
119
+ * @throws {RequiredError}
120
+ */
121
+ sendNotification(sendNotificationRequestDto: SendNotificationRequestDto, authorization?: string, options?: any): AxiosPromise<SendNotificationResponseClass> {
122
+ return localVarFp.sendNotification(sendNotificationRequestDto, authorization, options).then((request) => request(axios, basePath));
123
+ },
124
+ };
125
+ };
126
+
127
+ /**
128
+ * Request parameters for sendNotification operation in NotificationsApi.
129
+ * @export
130
+ * @interface NotificationsApiSendNotificationRequest
131
+ */
132
+ export interface NotificationsApiSendNotificationRequest {
133
+ /**
134
+ *
135
+ * @type {SendNotificationRequestDto}
136
+ * @memberof NotificationsApiSendNotification
137
+ */
138
+ readonly sendNotificationRequestDto: SendNotificationRequestDto
139
+
140
+ /**
141
+ * Bearer Token
142
+ * @type {string}
143
+ * @memberof NotificationsApiSendNotification
144
+ */
145
+ readonly authorization?: string
146
+ }
147
+
148
+ /**
149
+ * NotificationsApi - object-oriented interface
150
+ * @export
151
+ * @class NotificationsApi
152
+ * @extends {BaseAPI}
153
+ */
154
+ export class NotificationsApi extends BaseAPI {
155
+ /**
156
+ *
157
+ * @param {NotificationsApiSendNotificationRequest} requestParameters Request parameters.
158
+ * @param {*} [options] Override http request option.
159
+ * @throws {RequiredError}
160
+ * @memberof NotificationsApi
161
+ */
162
+ public sendNotification(requestParameters: NotificationsApiSendNotificationRequest, options?: AxiosRequestConfig) {
163
+ return NotificationsApiFp(this.configuration).sendNotification(requestParameters.sendNotificationRequestDto, requestParameters.authorization, options).then((request) => request(this.axios, this.basePath));
164
+ }
165
+ }
package/api.ts ADDED
@@ -0,0 +1,35 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL NotificationService
5
+ * The EMIL NotificationService API description
6
+ *
7
+ * The version of the OpenAPI document: 1.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ import { Configuration } from './configuration';
17
+ import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
18
+ // URLSearchParams not necessarily used
19
+ // @ts-ignore
20
+ import { URL, URLSearchParams } from 'url';
21
+ import FormData from 'form-data'
22
+ // Some imports not used depending on template conditions
23
+ // @ts-ignore
24
+ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
25
+ // @ts-ignore
26
+ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
27
+ import { LayoutsApi } from './api';
28
+ import { NotificationTemplatesApi } from './api';
29
+ import { NotificationsApi } from './api';
30
+
31
+
32
+ export * from './api/layouts-api';
33
+ export * from './api/notification-templates-api';
34
+ export * from './api/notifications-api';
35
+
package/base.ts ADDED
@@ -0,0 +1,284 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL NotificationService
5
+ * The EMIL NotificationService API description
6
+ *
7
+ * The version of the OpenAPI document: 1.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ import { Configuration } from "./configuration";
17
+ // Some imports not used depending on template conditions
18
+ // @ts-ignore
19
+ import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
20
+ import * as fs from 'fs';
21
+ import * as path from 'path';
22
+ import * as os from 'os';
23
+
24
+ export const BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
25
+ const CONFIG_DIRECTORY = '.emil';
26
+ const CONFIG_FILENAME = 'credentials';
27
+ const KEY_USERNAME = 'emil_username';
28
+ const KEY_PASSWORD = 'emil_password';
29
+
30
+ const filePath = os.homedir() + path.sep + CONFIG_DIRECTORY + path.sep + CONFIG_FILENAME;
31
+ /**
32
+ *
33
+ * @export
34
+ */
35
+ export const COLLECTION_FORMATS = {
36
+ csv: ",",
37
+ ssv: " ",
38
+ tsv: "\t",
39
+ pipes: "|",
40
+ };
41
+
42
+ export interface LoginClass {
43
+ accessToken: string;
44
+ permissions: Array<string>;
45
+ }
46
+
47
+ export enum Environment {
48
+ Production = 'https://apiv2.emil.de',
49
+ Test = 'https://apiv2-test.emil.de',
50
+ Development = 'https://apiv2-dev.emil.de',
51
+ }
52
+
53
+ let _retry_count = 0
54
+ let _retry = null
55
+
56
+ export function resetRetry() {
57
+ _retry_count = 0
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @export
63
+ * @interface RequestArgs
64
+ */
65
+ export interface RequestArgs {
66
+ url: string;
67
+ options: AxiosRequestConfig;
68
+ }
69
+
70
+ const NETWORK_ERROR_MESSAGE = "Network Error";
71
+
72
+ /**
73
+ *
74
+ * @export
75
+ * @class BaseAPI
76
+ */
77
+ export class BaseAPI {
78
+ protected configuration: Configuration;
79
+ private username?: string;
80
+ private password?: string;
81
+
82
+ constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
83
+ if (configuration) {
84
+ this.configuration = configuration;
85
+ this.basePath = configuration.basePath || this.basePath;
86
+ } else {
87
+ this.configuration = new Configuration({
88
+ basePath: this.basePath,
89
+ });
90
+ }
91
+
92
+ this.attachInterceptor(axios);
93
+ }
94
+
95
+ async initialize(env: Environment = Environment.Production) {
96
+ this.configuration.basePath = env;
97
+
98
+ await this.loadCredentials();
99
+
100
+ if (this.username) {
101
+ await this.authorize(this.username, this.password);
102
+ this.password = null; // to avoid keeping password loaded in memory.
103
+ }
104
+ }
105
+
106
+ private async loadCredentials() {
107
+ try {
108
+ await this.readConfigFile();
109
+ } catch (error) {
110
+ console.warn(`No credentials file found. Check that ${filePath} exists.`);
111
+ }
112
+
113
+ this.readEnvVariables();
114
+
115
+ if (!this.username) {
116
+ console.info(`No credentials found in credentials file or environment variables. Either provide some or use
117
+ authorize() function.`);
118
+ }
119
+ }
120
+
121
+ private async readConfigFile() {
122
+ const file = await fs.promises.readFile(filePath, 'utf-8');
123
+
124
+ const lines = file.split(os.EOL)
125
+ .filter(Boolean);
126
+
127
+ lines.forEach((line: string) => {
128
+ if (line.startsWith(KEY_USERNAME)) {
129
+ this.username = line.length > KEY_USERNAME.length + 1 ? line.substring(KEY_USERNAME.length + 1) : '';
130
+ } else if (line.startsWith(KEY_PASSWORD)) {
131
+ this.password = line.length > KEY_PASSWORD.length + 1 ? line.substring(KEY_PASSWORD.length + 1) : '';
132
+ }
133
+ });
134
+ }
135
+
136
+ private readEnvVariables(): boolean {
137
+ if (process.env.EMIL_USERNAME) {
138
+ this.username = process.env.EMIL_USERNAME;
139
+ this.password = process.env.EMIL_PASSWORD || '';
140
+
141
+ return true;
142
+ }
143
+
144
+ return false;
145
+ }
146
+
147
+ selectEnvironment(env: Environment) {
148
+ this.configuration.basePath = env;
149
+ }
150
+
151
+ async authorize(username: string, password: string): Promise<void> {
152
+ const options: AxiosRequestConfig = {
153
+ method: 'POST',
154
+ url: `${this.configuration.basePath}/authservice/v1/login`,
155
+ headers: { 'Content-Type': 'application/json' },
156
+ data: {
157
+ username,
158
+ password,
159
+ },
160
+ withCredentials: true,
161
+ };
162
+
163
+ const response = await globalAxios.request<LoginClass>(options);
164
+
165
+ const { data: { accessToken } } = response;
166
+ this.configuration.username = username;
167
+ this.configuration.accessToken = `Bearer ${accessToken}`;
168
+
169
+ const refreshToken = this.extractRefreshToken(response)
170
+ this.configuration.refreshToken = refreshToken;
171
+ }
172
+
173
+ async refreshTokenInternal(): Promise<string> {
174
+ const { username, refreshToken } = this.configuration;
175
+
176
+
177
+ if (!username || !refreshToken) {
178
+ return '';
179
+ }
180
+
181
+ const options: AxiosRequestConfig = {
182
+ method: 'POST',
183
+ url: `${this.configuration.basePath}/authservice/v1/refresh-token`,
184
+ headers: {
185
+ 'Content-Type': 'application/json',
186
+ Cookie: refreshToken,
187
+ },
188
+ data: { username: username },
189
+ withCredentials: true,
190
+ };
191
+
192
+ const { data: { accessToken } } = await globalAxios.request<LoginClass>(options);
193
+
194
+ return accessToken;
195
+ }
196
+
197
+ private extractRefreshToken(response: AxiosResponse): string {
198
+ if (response.headers && response.headers['set-cookie']
199
+ && response.headers['set-cookie'].length > 0) {
200
+
201
+ return `${response.headers['set-cookie'][0].split(';')[0]};`;
202
+ }
203
+
204
+ return '';
205
+ }
206
+
207
+ getConfiguration(): Configuration {
208
+ return this.configuration;
209
+ }
210
+
211
+ private attachInterceptor(axios: AxiosInstance) {
212
+ axios.interceptors.response.use(
213
+ (res) => {
214
+ return res;
215
+ },
216
+ async (err) => {
217
+ let originalConfig = err.config;
218
+ if (err.response) {
219
+ // Access Token was expired
220
+ if (err.response.status === 401 && !originalConfig._retry) {
221
+ originalConfig._retry = true;
222
+ try {
223
+ const tokenString = await this.refreshTokenInternal();
224
+ const accessToken = `Bearer ${tokenString}`;
225
+
226
+ originalConfig.headers['Authorization'] = `Bearer ${accessToken}`
227
+
228
+ this.configuration.accessToken = accessToken;
229
+
230
+ return axios.request(originalConfig);
231
+ } catch (_error) {
232
+ if (_error.response && _error.response.data) {
233
+ return Promise.reject(_error.response.data);
234
+ }
235
+ return Promise.reject(_error);
236
+ }
237
+ }
238
+ if (err.response.status === 403 && err.response.data) {
239
+ return Promise.reject(err.response.data);
240
+ }
241
+ } else if(err.message === NETWORK_ERROR_MESSAGE
242
+ && err.isAxiosError
243
+ && originalConfig.headers.hasOwnProperty('Authorization')
244
+ && _retry_count < 4
245
+ ){
246
+ _retry_count++;
247
+ try {
248
+ const tokenString = await this.refreshTokenInternal();
249
+ const accessToken = `Bearer ${tokenString}`;
250
+
251
+ _retry = true;
252
+ originalConfig.headers['Authorization'] = accessToken;
253
+
254
+ this.configuration.accessToken = accessToken;
255
+
256
+ return axios.request({
257
+ ...originalConfig,
258
+ });
259
+ } catch (_error) {
260
+ if (_error.response && _error.response.data) {
261
+ return Promise.reject(_error.response.data);
262
+ }
263
+ return Promise.reject(_error);
264
+ }
265
+ }
266
+ return Promise.reject(err);
267
+ }
268
+ );
269
+ }
270
+ };
271
+
272
+ /**
273
+ *
274
+ * @export
275
+ * @class RequiredError
276
+ * @extends {Error}
277
+ */
278
+ export class RequiredError extends Error {
279
+ name: "RequiredError" = "RequiredError";
280
+ constructor(public field: string, msg?: string) {
281
+ super(msg);
282
+ }
283
+ }
284
+
package/common.ts ADDED
@@ -0,0 +1,199 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * EMIL NotificationService
5
+ * The EMIL NotificationService API description
6
+ *
7
+ * The version of the OpenAPI document: 1.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+
16
+ import { Configuration } from "./configuration";
17
+ import { RequiredError, RequestArgs } from "./base";
18
+ import { AxiosInstance, AxiosResponse } from 'axios';
19
+ import { URL, URLSearchParams } from 'url';
20
+ /**
21
+ *
22
+ * @export
23
+ */
24
+ export const DUMMY_BASE_URL = 'https://example.com'
25
+
26
+ /**
27
+ *
28
+ * @throws {RequiredError}
29
+ * @export
30
+ */
31
+ export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
32
+ if (paramValue === null || paramValue === undefined) {
33
+ throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
34
+ }
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @export
40
+ */
41
+ export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
42
+ if (configuration && configuration.apiKey) {
43
+ const localVarApiKeyValue = typeof configuration.apiKey === 'function'
44
+ ? await configuration.apiKey(keyParamName)
45
+ : await configuration.apiKey;
46
+ object[keyParamName] = localVarApiKeyValue;
47
+ }
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @export
53
+ */
54
+ export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
55
+ if (configuration && (configuration.username || configuration.password)) {
56
+ object["auth"] = { username: configuration.username, password: configuration.password };
57
+ }
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @export
63
+ */
64
+ export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
65
+ if (configuration && configuration.accessToken) {
66
+ const accessToken = typeof configuration.accessToken === 'function'
67
+ ? await configuration.accessToken()
68
+ : await configuration.accessToken;
69
+ object["Authorization"] = "Bearer " + accessToken;
70
+ }
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @export
76
+ */
77
+ export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
78
+ if (configuration && configuration.accessToken) {
79
+ const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
80
+ ? await configuration.accessToken(name, scopes)
81
+ : await configuration.accessToken;
82
+ object["Authorization"] = "Bearer " + localVarAccessTokenValue;
83
+ }
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @export
89
+ */
90
+ export const setSearchParams = function (url: URL, ...objects: any[]) {
91
+ const searchParams = new URLSearchParams(url.search);
92
+ for (const object of objects) {
93
+ for (const key in object) {
94
+ if (Array.isArray(object[key])) {
95
+ searchParams.delete(key);
96
+ for (const item of object[key]) {
97
+ searchParams.append(key, item);
98
+ }
99
+ } else {
100
+ searchParams.set(key, object[key]);
101
+ }
102
+ }
103
+ }
104
+ url.search = searchParams.toString();
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @export
110
+ */
111
+ export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
112
+ const nonString = typeof value !== 'string';
113
+ const needsSerialization = nonString && configuration && configuration.isJsonMime
114
+ ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
115
+ : nonString;
116
+ return needsSerialization
117
+ ? JSON.stringify(value !== undefined ? value : {})
118
+ : (value || "");
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @export
124
+ */
125
+ export const toPathString = function (url: URL) {
126
+ return url.pathname + url.search + url.hash
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @export
132
+ */
133
+ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
134
+ return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
135
+ const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
136
+ return axios.request<T, R>(axiosRequestArgs);
137
+ };
138
+ }
139
+
140
+ /* tslint:disable */
141
+ /* eslint-disable */
142
+ /**
143
+ * EMIL NotificationService
144
+ * The EMIL NotificationService API description
145
+ *
146
+ * The version of the OpenAPI document: 1.0
147
+ *
148
+ *
149
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
150
+ * https://openapi-generator.tech
151
+ * Do not edit the class manually.
152
+ */
153
+
154
+
155
+ export interface IStorageConverter<D, SD> {
156
+ toStorageData( data: D ): SD;
157
+ fromStorageData( storageData: SD ): D;
158
+ }
159
+
160
+ export interface IStorage {
161
+ get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null;
162
+ set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void;
163
+ }
164
+
165
+ export class LocalStorage implements IStorage {
166
+ readonly storage: Storage;
167
+
168
+ constructor() {
169
+ this.storage = localStorage;
170
+ }
171
+
172
+ get<T>( key: string, converter?: IStorageConverter<T, any> ): T | null {
173
+ const jsonValue = this.storage.getItem( key );
174
+ if ( jsonValue === null ) {
175
+ return null;
176
+ }
177
+ const value = JSON.parse( jsonValue );
178
+ if ( converter !== undefined ) {
179
+ return converter.fromStorageData( value );
180
+ } else {
181
+ return value as T;
182
+ }
183
+ }
184
+
185
+ set<T>( key: string, value: T, converter?: IStorageConverter<T, any> ): void {
186
+ let valueToStore: any = value;
187
+ if ( converter !== undefined ) {
188
+ valueToStore = converter.toStorageData( value );
189
+ }
190
+ const jsonValue = JSON.stringify( valueToStore );
191
+ this.storage.setItem( key, jsonValue );
192
+ }
193
+ }
194
+
195
+ let _defaultStorage: IStorage = null;
196
+
197
+ export const defaultStorage = (): IStorage => {
198
+ return _defaultStorage || (_defaultStorage = new LocalStorage());
199
+ };