@emilgroup/payment-sdk 1.13.1-beta.27 → 1.13.1-beta.29
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/base.ts +45 -1
- package/dist/base.d.ts +10 -1
- package/dist/base.js +41 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,11 +17,11 @@ Although this package can be used in both TypeScript and JavaScript, it is inten
|
|
|
17
17
|
Navigate to the folder of your consuming project and run one of the following commands:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
npm install @emilgroup/payment-sdk@1.13.1-beta.
|
|
20
|
+
npm install @emilgroup/payment-sdk@1.13.1-beta.29 --save
|
|
21
21
|
```
|
|
22
22
|
or
|
|
23
23
|
```
|
|
24
|
-
yarn add @emilgroup/payment-sdk@1.13.1-beta.
|
|
24
|
+
yarn add @emilgroup/payment-sdk@1.13.1-beta.29
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
And then you can import `PaymentsApi`.
|
package/base.ts
CHANGED
|
@@ -37,6 +37,16 @@ export interface LoginClass {
|
|
|
37
37
|
permissions: string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export interface SwitchWorkspaceRequest {
|
|
41
|
+
username: string;
|
|
42
|
+
targetWorkspace: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SwitchWorkspaceResponseClass {
|
|
46
|
+
accessToken: string;
|
|
47
|
+
permissions: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
export enum Environment {
|
|
41
51
|
Production = 'https://apiv2.emil.de',
|
|
42
52
|
Test = 'https://apiv2-test.emil.de',
|
|
@@ -119,7 +129,7 @@ export class BaseAPI {
|
|
|
119
129
|
return this.tokenData.permissions.split(',');
|
|
120
130
|
}
|
|
121
131
|
|
|
122
|
-
async authorize(username: string, password: string): Promise<void> {
|
|
132
|
+
async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
|
|
123
133
|
const options: AxiosRequestConfig = {
|
|
124
134
|
method: 'POST',
|
|
125
135
|
url: `${this.configuration.basePath}/authservice/v1/login`,
|
|
@@ -141,6 +151,40 @@ export class BaseAPI {
|
|
|
141
151
|
this.tokenData.accessToken = accessToken;
|
|
142
152
|
this.tokenData.permissions = permissions;
|
|
143
153
|
|
|
154
|
+
// Switch workspace if provided
|
|
155
|
+
if (targetWorkspace) {
|
|
156
|
+
await this.switchWorkspace(targetWorkspace);
|
|
157
|
+
} else {
|
|
158
|
+
// Only store if no workspace switch (since switchWorkspace will store after switching)
|
|
159
|
+
this.storeTokenData({
|
|
160
|
+
...this.tokenData
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async switchWorkspace(targetWorkspace: string): Promise<void> {
|
|
166
|
+
const options: AxiosRequestConfig = {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
|
|
169
|
+
headers: {
|
|
170
|
+
'Content-Type': 'application/json',
|
|
171
|
+
'Authorization': `Bearer ${this.configuration.accessToken}`,
|
|
172
|
+
},
|
|
173
|
+
data: {
|
|
174
|
+
username: this.configuration.username,
|
|
175
|
+
targetWorkspace,
|
|
176
|
+
} as SwitchWorkspaceRequest,
|
|
177
|
+
withCredentials: true,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
|
|
181
|
+
|
|
182
|
+
const { data: { accessToken, permissions } } = response;
|
|
183
|
+
|
|
184
|
+
this.configuration.accessToken = `Bearer ${accessToken}`;
|
|
185
|
+
this.tokenData.accessToken = accessToken;
|
|
186
|
+
this.tokenData.permissions = permissions;
|
|
187
|
+
|
|
144
188
|
this.storeTokenData({
|
|
145
189
|
...this.tokenData
|
|
146
190
|
});
|
package/dist/base.d.ts
CHANGED
|
@@ -26,6 +26,14 @@ export interface LoginClass {
|
|
|
26
26
|
accessToken: string;
|
|
27
27
|
permissions: string;
|
|
28
28
|
}
|
|
29
|
+
export interface SwitchWorkspaceRequest {
|
|
30
|
+
username: string;
|
|
31
|
+
targetWorkspace: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SwitchWorkspaceResponseClass {
|
|
34
|
+
accessToken: string;
|
|
35
|
+
permissions: string;
|
|
36
|
+
}
|
|
29
37
|
export declare enum Environment {
|
|
30
38
|
Production = "https://apiv2.emil.de",
|
|
31
39
|
Test = "https://apiv2-test.emil.de",
|
|
@@ -57,7 +65,8 @@ export declare class BaseAPI {
|
|
|
57
65
|
selectEnvironment(env: Environment): void;
|
|
58
66
|
selectBasePath(path: string): void;
|
|
59
67
|
getPermissions(): Array<string>;
|
|
60
|
-
authorize(username: string, password: string): Promise<void>;
|
|
68
|
+
authorize(username: string, password: string, targetWorkspace?: string): Promise<void>;
|
|
69
|
+
switchWorkspace(targetWorkspace: string): Promise<void>;
|
|
61
70
|
refreshTokenInternal(): Promise<LoginClass>;
|
|
62
71
|
private storeTokenData;
|
|
63
72
|
loadTokenData(): void;
|
package/dist/base.js
CHANGED
|
@@ -151,7 +151,7 @@ var BaseAPI = /** @class */ (function () {
|
|
|
151
151
|
}
|
|
152
152
|
return this.tokenData.permissions.split(',');
|
|
153
153
|
};
|
|
154
|
-
BaseAPI.prototype.authorize = function (username, password) {
|
|
154
|
+
BaseAPI.prototype.authorize = function (username, password, targetWorkspace) {
|
|
155
155
|
return __awaiter(this, void 0, void 0, function () {
|
|
156
156
|
var options, response, _a, accessToken, permissions;
|
|
157
157
|
return __generator(this, function (_b) {
|
|
@@ -176,6 +176,46 @@ var BaseAPI = /** @class */ (function () {
|
|
|
176
176
|
this.tokenData.username = username;
|
|
177
177
|
this.tokenData.accessToken = accessToken;
|
|
178
178
|
this.tokenData.permissions = permissions;
|
|
179
|
+
if (!targetWorkspace) return [3 /*break*/, 3];
|
|
180
|
+
return [4 /*yield*/, this.switchWorkspace(targetWorkspace)];
|
|
181
|
+
case 2:
|
|
182
|
+
_b.sent();
|
|
183
|
+
return [3 /*break*/, 4];
|
|
184
|
+
case 3:
|
|
185
|
+
// Only store if no workspace switch (since switchWorkspace will store after switching)
|
|
186
|
+
this.storeTokenData(__assign({}, this.tokenData));
|
|
187
|
+
_b.label = 4;
|
|
188
|
+
case 4: return [2 /*return*/];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
BaseAPI.prototype.switchWorkspace = function (targetWorkspace) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
+
var options, response, _a, accessToken, permissions;
|
|
196
|
+
return __generator(this, function (_b) {
|
|
197
|
+
switch (_b.label) {
|
|
198
|
+
case 0:
|
|
199
|
+
options = {
|
|
200
|
+
method: 'POST',
|
|
201
|
+
url: "".concat(this.configuration.basePath, "/authservice/v1/workspaces/switch"),
|
|
202
|
+
headers: {
|
|
203
|
+
'Content-Type': 'application/json',
|
|
204
|
+
'Authorization': "Bearer ".concat(this.configuration.accessToken),
|
|
205
|
+
},
|
|
206
|
+
data: {
|
|
207
|
+
username: this.configuration.username,
|
|
208
|
+
targetWorkspace: targetWorkspace,
|
|
209
|
+
},
|
|
210
|
+
withCredentials: true,
|
|
211
|
+
};
|
|
212
|
+
return [4 /*yield*/, axios_1.default.request(options)];
|
|
213
|
+
case 1:
|
|
214
|
+
response = _b.sent();
|
|
215
|
+
_a = response.data, accessToken = _a.accessToken, permissions = _a.permissions;
|
|
216
|
+
this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
217
|
+
this.tokenData.accessToken = accessToken;
|
|
218
|
+
this.tokenData.permissions = permissions;
|
|
179
219
|
this.storeTokenData(__assign({}, this.tokenData));
|
|
180
220
|
return [2 /*return*/];
|
|
181
221
|
}
|