@emilgroup/notification-sdk-node 1.4.0 → 1.4.1-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.
- package/README.md +2 -2
- package/api/default-api.ts +8 -4
- package/api/email-verifications-api.ts +8 -8
- package/api/layouts-api.ts +60 -60
- package/api/notification-templates-api.ts +60 -60
- package/api/notifications-api.ts +4 -4
- package/base.ts +47 -5
- package/common.ts +2 -2
- package/configuration.ts +9 -0
- package/dist/api/default-api.d.ts +8 -4
- package/dist/api/default-api.js +8 -4
- package/dist/api/email-verifications-api.d.ts +8 -8
- package/dist/api/email-verifications-api.js +8 -8
- package/dist/api/layouts-api.d.ts +60 -60
- package/dist/api/layouts-api.js +41 -41
- package/dist/api/notification-templates-api.d.ts +60 -60
- package/dist/api/notification-templates-api.js +41 -41
- package/dist/api/notifications-api.d.ts +4 -4
- package/dist/api/notifications-api.js +4 -4
- package/dist/base.d.ts +11 -2
- package/dist/base.js +43 -4
- package/dist/common.js +2 -2
- package/dist/configuration.d.ts +6 -0
- package/dist/configuration.js +8 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -0
package/dist/base.js
CHANGED
|
@@ -162,7 +162,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
162
162
|
}
|
|
163
163
|
this.attachInterceptor(axios);
|
|
164
164
|
}
|
|
165
|
-
BaseAPI.prototype.initialize = function (env) {
|
|
165
|
+
BaseAPI.prototype.initialize = function (env, targetWorkspace) {
|
|
166
166
|
if (env === void 0) { env = Environment.Production; }
|
|
167
167
|
return __awaiter(this, void 0, void 0, function () {
|
|
168
168
|
return __generator(this, function (_a) {
|
|
@@ -173,7 +173,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
173
173
|
case 1:
|
|
174
174
|
_a.sent();
|
|
175
175
|
if (!this.username) return [3 /*break*/, 3];
|
|
176
|
-
return [4 /*yield*/, this.authorize(this.username, this.password)];
|
|
176
|
+
return [4 /*yield*/, this.authorize(this.username, this.password, targetWorkspace)];
|
|
177
177
|
case 2:
|
|
178
178
|
_a.sent();
|
|
179
179
|
this.password = null; // to avoid keeping password loaded in memory.
|
|
@@ -243,7 +243,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
243
243
|
BaseAPI.prototype.selectEnvironment = function (env) {
|
|
244
244
|
this.configuration.basePath = env;
|
|
245
245
|
};
|
|
246
|
-
BaseAPI.prototype.authorize = function (username, password) {
|
|
246
|
+
BaseAPI.prototype.authorize = function (username, password, targetWorkspace) {
|
|
247
247
|
return __awaiter(this, void 0, void 0, function () {
|
|
248
248
|
var options, response, accessToken, refreshToken;
|
|
249
249
|
return __generator(this, function (_a) {
|
|
@@ -267,6 +267,45 @@ var BaseAPI = /** @class */ (function () {
|
|
|
267
267
|
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
268
268
|
refreshToken = this.extractRefreshToken(response);
|
|
269
269
|
this.configuration.refreshToken = refreshToken;
|
|
270
|
+
if (!targetWorkspace) return [3 /*break*/, 3];
|
|
271
|
+
return [4 /*yield*/, this.switchWorkspace(targetWorkspace)];
|
|
272
|
+
case 2:
|
|
273
|
+
_a.sent();
|
|
274
|
+
_a.label = 3;
|
|
275
|
+
case 3: return [2 /*return*/];
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
BaseAPI.prototype.switchWorkspace = function (targetWorkspace) {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
+
var options, response, accessToken, refreshToken;
|
|
283
|
+
return __generator(this, function (_a) {
|
|
284
|
+
switch (_a.label) {
|
|
285
|
+
case 0:
|
|
286
|
+
options = {
|
|
287
|
+
method: 'POST',
|
|
288
|
+
url: "".concat(this.configuration.basePath, "/authservice/v1/workspaces/switch"),
|
|
289
|
+
headers: {
|
|
290
|
+
'Content-Type': 'application/json',
|
|
291
|
+
'Authorization': "Bearer ".concat(this.configuration.accessToken),
|
|
292
|
+
'Cookie': this.configuration.refreshToken,
|
|
293
|
+
},
|
|
294
|
+
data: {
|
|
295
|
+
username: this.configuration.username,
|
|
296
|
+
targetWorkspace: targetWorkspace,
|
|
297
|
+
},
|
|
298
|
+
withCredentials: true,
|
|
299
|
+
};
|
|
300
|
+
return [4 /*yield*/, axios_1.default.request(options)];
|
|
301
|
+
case 1:
|
|
302
|
+
response = _a.sent();
|
|
303
|
+
accessToken = response.data.accessToken;
|
|
304
|
+
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
305
|
+
refreshToken = this.extractRefreshToken(response);
|
|
306
|
+
if (refreshToken) {
|
|
307
|
+
this.configuration.refreshToken = refreshToken;
|
|
308
|
+
}
|
|
270
309
|
return [2 /*return*/];
|
|
271
310
|
}
|
|
272
311
|
});
|
|
@@ -330,7 +369,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
330
369
|
case 2:
|
|
331
370
|
tokenString = _a.sent();
|
|
332
371
|
accessToken = "Bearer ".concat(tokenString);
|
|
333
|
-
originalConfig.headers['Authorization'] =
|
|
372
|
+
originalConfig.headers['Authorization'] = accessToken;
|
|
334
373
|
this.configuration.accessToken = accessToken;
|
|
335
374
|
return [2 /*return*/, axios.request(originalConfig)];
|
|
336
375
|
case 3:
|
package/dist/common.js
CHANGED
|
@@ -141,7 +141,7 @@ var setBearerAuthToObject = function (object, configuration) {
|
|
|
141
141
|
_b.label = 4;
|
|
142
142
|
case 4:
|
|
143
143
|
accessToken = _a;
|
|
144
|
-
object["Authorization"] =
|
|
144
|
+
object["Authorization"] = configuration.getBearerToken(accessToken);
|
|
145
145
|
_b.label = 5;
|
|
146
146
|
case 5: return [2 /*return*/];
|
|
147
147
|
}
|
|
@@ -171,7 +171,7 @@ var setOAuthToObject = function (object, name, scopes, configuration) {
|
|
|
171
171
|
_b.label = 4;
|
|
172
172
|
case 4:
|
|
173
173
|
localVarAccessTokenValue = _a;
|
|
174
|
-
object["Authorization"] =
|
|
174
|
+
object["Authorization"] = configuration.getBearerToken(localVarAccessTokenValue);
|
|
175
175
|
_b.label = 5;
|
|
176
176
|
case 5: return [2 /*return*/];
|
|
177
177
|
}
|
package/dist/configuration.d.ts
CHANGED
|
@@ -87,4 +87,10 @@ export declare class Configuration {
|
|
|
87
87
|
* @return True if the given MIME is JSON, false otherwise.
|
|
88
88
|
*/
|
|
89
89
|
isJsonMime(mime: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Returns "Bearer" token.
|
|
92
|
+
* @param token - access token.
|
|
93
|
+
* @return Bearer token.
|
|
94
|
+
*/
|
|
95
|
+
getBearerToken(token?: string): string;
|
|
90
96
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -39,6 +39,14 @@ var Configuration = /** @class */ (function () {
|
|
|
39
39
|
var jsonMime = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
|
40
40
|
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Returns "Bearer" token.
|
|
44
|
+
* @param token - access token.
|
|
45
|
+
* @return Bearer token.
|
|
46
|
+
*/
|
|
47
|
+
Configuration.prototype.getBearerToken = function (token) {
|
|
48
|
+
return ('' + token).startsWith("Bearer") ? token : "Bearer " + token;
|
|
49
|
+
};
|
|
42
50
|
return Configuration;
|
|
43
51
|
}());
|
|
44
52
|
exports.Configuration = Configuration;
|
package/package.json
CHANGED