@thelllabs/winehaus-sdk 0.0.4 → 0.0.6
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/dist/cjs/api/api.js +12 -30
- package/dist/cjs/sdk.js +34 -10
- package/dist/esm/api/api.js +11 -29
- package/dist/esm/sdk.js +34 -10
- package/dist/types/api/api.d.ts +16 -31
- package/dist/types/interfaces.d.ts +6 -0
- package/dist/types/sdk.d.ts +10 -5
- package/dist/umd/index.ts +46 -40
- package/package.json +1 -1
package/dist/cjs/api/api.js
CHANGED
|
@@ -85,41 +85,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
85
85
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
86
86
|
};
|
|
87
87
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
88
|
-
exports.Api = exports.HttpClient = exports.ContentType = exports.
|
|
89
|
-
var CreateTenantUserDtoRolesEnum;
|
|
90
|
-
(function (CreateTenantUserDtoRolesEnum) {
|
|
91
|
-
CreateTenantUserDtoRolesEnum["Operator"] = "operator";
|
|
92
|
-
CreateTenantUserDtoRolesEnum["Admin"] = "admin";
|
|
93
|
-
CreateTenantUserDtoRolesEnum["Owner"] = "owner";
|
|
94
|
-
})(CreateTenantUserDtoRolesEnum = exports.CreateTenantUserDtoRolesEnum || (exports.CreateTenantUserDtoRolesEnum = {}));
|
|
95
|
-
var ListTenantUsersParamsRolesEnum;
|
|
96
|
-
(function (ListTenantUsersParamsRolesEnum) {
|
|
97
|
-
ListTenantUsersParamsRolesEnum["Operator"] = "operator";
|
|
98
|
-
ListTenantUsersParamsRolesEnum["Admin"] = "admin";
|
|
99
|
-
ListTenantUsersParamsRolesEnum["Owner"] = "owner";
|
|
100
|
-
})(ListTenantUsersParamsRolesEnum = exports.ListTenantUsersParamsRolesEnum || (exports.ListTenantUsersParamsRolesEnum = {}));
|
|
101
|
-
var ListTenantUsersParamsStatusEnum;
|
|
102
|
-
(function (ListTenantUsersParamsStatusEnum) {
|
|
103
|
-
ListTenantUsersParamsStatusEnum["Enabled"] = "enabled";
|
|
104
|
-
ListTenantUsersParamsStatusEnum["Blocked"] = "blocked";
|
|
105
|
-
})(ListTenantUsersParamsStatusEnum = exports.ListTenantUsersParamsStatusEnum || (exports.ListTenantUsersParamsStatusEnum = {}));
|
|
88
|
+
exports.Api = exports.HttpClient = exports.ContentType = exports.TenantUserStatusEnum = exports.TenantRoleEnum = exports.OrderByEnum = void 0;
|
|
106
89
|
var OrderByEnum;
|
|
107
90
|
(function (OrderByEnum) {
|
|
108
91
|
OrderByEnum["ASC"] = "ASC";
|
|
109
92
|
OrderByEnum["DESC"] = "DESC";
|
|
110
93
|
})(OrderByEnum = exports.OrderByEnum || (exports.OrderByEnum = {}));
|
|
111
|
-
var
|
|
112
|
-
(function (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
})(TenantUserEntityDtoStatusEnum = exports.TenantUserEntityDtoStatusEnum || (exports.TenantUserEntityDtoStatusEnum = {}));
|
|
94
|
+
var TenantRoleEnum;
|
|
95
|
+
(function (TenantRoleEnum) {
|
|
96
|
+
TenantRoleEnum["Operator"] = "operator";
|
|
97
|
+
TenantRoleEnum["Admin"] = "admin";
|
|
98
|
+
TenantRoleEnum["Owner"] = "owner";
|
|
99
|
+
})(TenantRoleEnum = exports.TenantRoleEnum || (exports.TenantRoleEnum = {}));
|
|
100
|
+
var TenantUserStatusEnum;
|
|
101
|
+
(function (TenantUserStatusEnum) {
|
|
102
|
+
TenantUserStatusEnum["Enabled"] = "enabled";
|
|
103
|
+
TenantUserStatusEnum["Blocked"] = "blocked";
|
|
104
|
+
})(TenantUserStatusEnum = exports.TenantUserStatusEnum || (exports.TenantUserStatusEnum = {}));
|
|
123
105
|
var axios_1 = __importDefault(require("axios"));
|
|
124
106
|
var ContentType;
|
|
125
107
|
(function (ContentType) {
|
package/dist/cjs/sdk.js
CHANGED
|
@@ -150,13 +150,13 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
150
150
|
case 0:
|
|
151
151
|
if (!(((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) === 401 &&
|
|
152
152
|
this.authToken &&
|
|
153
|
-
this.refreshToken &&
|
|
153
|
+
// ToDO: Uncomment this this.refreshToken &&
|
|
154
154
|
!refreshTokenUsed.has(this.refreshToken))) return [3 /*break*/, 4];
|
|
155
155
|
refreshTokenUsed.add(this.refreshToken);
|
|
156
156
|
_c.label = 1;
|
|
157
157
|
case 1:
|
|
158
158
|
_c.trys.push([1, 3, , 4]);
|
|
159
|
-
return [4 /*yield*/, this.refreshTokens()];
|
|
159
|
+
return [4 /*yield*/, this.refreshTokens({ throwError: true })];
|
|
160
160
|
case 2:
|
|
161
161
|
_c.sent();
|
|
162
162
|
return [3 /*break*/, 4];
|
|
@@ -184,10 +184,22 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
184
184
|
case 0:
|
|
185
185
|
if (!(opts === null || opts === void 0 ? void 0 : opts.avoidEvents))
|
|
186
186
|
this.emitter.emit('connecting');
|
|
187
|
+
if (!((credential === null || credential === void 0 ? void 0 : credential.email) && (credential === null || credential === void 0 ? void 0 : credential.password))) return [3 /*break*/, 2];
|
|
187
188
|
return [4 /*yield*/, this.authenticateAsUser(credential)];
|
|
188
189
|
case 1:
|
|
189
190
|
_a.sent();
|
|
190
|
-
this.
|
|
191
|
+
this.signInCredential = credential;
|
|
192
|
+
return [3 /*break*/, 5];
|
|
193
|
+
case 2:
|
|
194
|
+
if (!(credential === null || credential === void 0 ? void 0 : credential.authToken)) return [3 /*break*/, 4];
|
|
195
|
+
// ToDO add && (credential as any)?.refreshToken after refreshToken is ready
|
|
196
|
+
return [4 /*yield*/, this.authenticateAsToken(credential)];
|
|
197
|
+
case 3:
|
|
198
|
+
// ToDO add && (credential as any)?.refreshToken after refreshToken is ready
|
|
199
|
+
_a.sent();
|
|
200
|
+
return [3 /*break*/, 5];
|
|
201
|
+
case 4: throw new Error("Invalid auth credential type format");
|
|
202
|
+
case 5:
|
|
191
203
|
if (!(opts === null || opts === void 0 ? void 0 : opts.avoidEvents))
|
|
192
204
|
this.emitter.emit('connected');
|
|
193
205
|
this.hookTimer();
|
|
@@ -196,14 +208,17 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
196
208
|
});
|
|
197
209
|
});
|
|
198
210
|
};
|
|
199
|
-
WinehausSDK.prototype.reAuthenticate = function () {
|
|
211
|
+
WinehausSDK.prototype.reAuthenticate = function (opts) {
|
|
200
212
|
return __awaiter(this, void 0, void 0, function () {
|
|
201
213
|
return __generator(this, function (_a) {
|
|
202
214
|
switch (_a.label) {
|
|
203
215
|
case 0:
|
|
204
|
-
if (!this.
|
|
205
|
-
|
|
206
|
-
|
|
216
|
+
if (!this.signInCredential) {
|
|
217
|
+
if (opts === null || opts === void 0 ? void 0 : opts.throwError)
|
|
218
|
+
new Error("No SignIn set to make re-auth");
|
|
219
|
+
return [2 /*return*/];
|
|
220
|
+
}
|
|
221
|
+
return [4 /*yield*/, this.authenticate(this.signInCredential, { avoidEvents: true })];
|
|
207
222
|
case 1:
|
|
208
223
|
_a.sent();
|
|
209
224
|
return [2 /*return*/];
|
|
@@ -232,7 +247,8 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
232
247
|
return __generator(this, function (_b) {
|
|
233
248
|
switch (_b.label) {
|
|
234
249
|
case 0:
|
|
235
|
-
|
|
250
|
+
//Todo: add || !this.refreshToken after implementing it here
|
|
251
|
+
if (!this.authToken) {
|
|
236
252
|
return [2 /*return*/, this.clearTokens()];
|
|
237
253
|
}
|
|
238
254
|
if (!((_a = this.authTokenDecoded) === null || _a === void 0 ? void 0 : _a.exp)) {
|
|
@@ -277,14 +293,14 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
277
293
|
WinehausSDK.prototype.getRefreshToken = function () {
|
|
278
294
|
return this.refreshToken.toString();
|
|
279
295
|
};
|
|
280
|
-
WinehausSDK.prototype.refreshTokens = function () {
|
|
296
|
+
WinehausSDK.prototype.refreshTokens = function (opts) {
|
|
281
297
|
return __awaiter(this, void 0, void 0, function () {
|
|
282
298
|
return __generator(this, function (_a) {
|
|
283
299
|
switch (_a.label) {
|
|
284
300
|
case 0:
|
|
285
301
|
// ToDo: Refresh token is not implemented under this version. For a while, lets just re-auth
|
|
286
302
|
this.clearTokens();
|
|
287
|
-
return [4 /*yield*/, this.reAuthenticate()];
|
|
303
|
+
return [4 /*yield*/, this.reAuthenticate(opts)];
|
|
288
304
|
case 1:
|
|
289
305
|
_a.sent();
|
|
290
306
|
return [2 /*return*/];
|
|
@@ -310,6 +326,14 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
310
326
|
});
|
|
311
327
|
});
|
|
312
328
|
};
|
|
329
|
+
WinehausSDK.prototype.authenticateAsToken = function (credential) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
331
|
+
return __generator(this, function (_a) {
|
|
332
|
+
this.setTokens({ token: credential.authToken, refreshToken: credential.refreshToken });
|
|
333
|
+
return [2 /*return*/];
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
};
|
|
313
337
|
WinehausSDK.prototype.setTokens = function (data) {
|
|
314
338
|
this.setAuthToken(data.token);
|
|
315
339
|
this.setRefreshToken(data.refreshToken);
|
package/dist/esm/api/api.js
CHANGED
|
@@ -80,40 +80,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
80
80
|
}
|
|
81
81
|
return t;
|
|
82
82
|
};
|
|
83
|
-
export var CreateTenantUserDtoRolesEnum;
|
|
84
|
-
(function (CreateTenantUserDtoRolesEnum) {
|
|
85
|
-
CreateTenantUserDtoRolesEnum["Operator"] = "operator";
|
|
86
|
-
CreateTenantUserDtoRolesEnum["Admin"] = "admin";
|
|
87
|
-
CreateTenantUserDtoRolesEnum["Owner"] = "owner";
|
|
88
|
-
})(CreateTenantUserDtoRolesEnum || (CreateTenantUserDtoRolesEnum = {}));
|
|
89
|
-
export var ListTenantUsersParamsRolesEnum;
|
|
90
|
-
(function (ListTenantUsersParamsRolesEnum) {
|
|
91
|
-
ListTenantUsersParamsRolesEnum["Operator"] = "operator";
|
|
92
|
-
ListTenantUsersParamsRolesEnum["Admin"] = "admin";
|
|
93
|
-
ListTenantUsersParamsRolesEnum["Owner"] = "owner";
|
|
94
|
-
})(ListTenantUsersParamsRolesEnum || (ListTenantUsersParamsRolesEnum = {}));
|
|
95
|
-
export var ListTenantUsersParamsStatusEnum;
|
|
96
|
-
(function (ListTenantUsersParamsStatusEnum) {
|
|
97
|
-
ListTenantUsersParamsStatusEnum["Enabled"] = "enabled";
|
|
98
|
-
ListTenantUsersParamsStatusEnum["Blocked"] = "blocked";
|
|
99
|
-
})(ListTenantUsersParamsStatusEnum || (ListTenantUsersParamsStatusEnum = {}));
|
|
100
83
|
export var OrderByEnum;
|
|
101
84
|
(function (OrderByEnum) {
|
|
102
85
|
OrderByEnum["ASC"] = "ASC";
|
|
103
86
|
OrderByEnum["DESC"] = "DESC";
|
|
104
87
|
})(OrderByEnum || (OrderByEnum = {}));
|
|
105
|
-
export var
|
|
106
|
-
(function (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
})(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})(TenantUserEntityDtoStatusEnum || (TenantUserEntityDtoStatusEnum = {}));
|
|
88
|
+
export var TenantRoleEnum;
|
|
89
|
+
(function (TenantRoleEnum) {
|
|
90
|
+
TenantRoleEnum["Operator"] = "operator";
|
|
91
|
+
TenantRoleEnum["Admin"] = "admin";
|
|
92
|
+
TenantRoleEnum["Owner"] = "owner";
|
|
93
|
+
})(TenantRoleEnum || (TenantRoleEnum = {}));
|
|
94
|
+
export var TenantUserStatusEnum;
|
|
95
|
+
(function (TenantUserStatusEnum) {
|
|
96
|
+
TenantUserStatusEnum["Enabled"] = "enabled";
|
|
97
|
+
TenantUserStatusEnum["Blocked"] = "blocked";
|
|
98
|
+
})(TenantUserStatusEnum || (TenantUserStatusEnum = {}));
|
|
117
99
|
import axios from "axios";
|
|
118
100
|
export var ContentType;
|
|
119
101
|
(function (ContentType) {
|
package/dist/esm/sdk.js
CHANGED
|
@@ -121,13 +121,13 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
121
121
|
case 0:
|
|
122
122
|
if (!(((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) === 401 &&
|
|
123
123
|
this.authToken &&
|
|
124
|
-
this.refreshToken &&
|
|
124
|
+
// ToDO: Uncomment this this.refreshToken &&
|
|
125
125
|
!refreshTokenUsed.has(this.refreshToken))) return [3 /*break*/, 4];
|
|
126
126
|
refreshTokenUsed.add(this.refreshToken);
|
|
127
127
|
_c.label = 1;
|
|
128
128
|
case 1:
|
|
129
129
|
_c.trys.push([1, 3, , 4]);
|
|
130
|
-
return [4 /*yield*/, this.refreshTokens()];
|
|
130
|
+
return [4 /*yield*/, this.refreshTokens({ throwError: true })];
|
|
131
131
|
case 2:
|
|
132
132
|
_c.sent();
|
|
133
133
|
return [3 /*break*/, 4];
|
|
@@ -155,10 +155,22 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
155
155
|
case 0:
|
|
156
156
|
if (!(opts === null || opts === void 0 ? void 0 : opts.avoidEvents))
|
|
157
157
|
this.emitter.emit('connecting');
|
|
158
|
+
if (!((credential === null || credential === void 0 ? void 0 : credential.email) && (credential === null || credential === void 0 ? void 0 : credential.password))) return [3 /*break*/, 2];
|
|
158
159
|
return [4 /*yield*/, this.authenticateAsUser(credential)];
|
|
159
160
|
case 1:
|
|
160
161
|
_a.sent();
|
|
161
|
-
this.
|
|
162
|
+
this.signInCredential = credential;
|
|
163
|
+
return [3 /*break*/, 5];
|
|
164
|
+
case 2:
|
|
165
|
+
if (!(credential === null || credential === void 0 ? void 0 : credential.authToken)) return [3 /*break*/, 4];
|
|
166
|
+
// ToDO add && (credential as any)?.refreshToken after refreshToken is ready
|
|
167
|
+
return [4 /*yield*/, this.authenticateAsToken(credential)];
|
|
168
|
+
case 3:
|
|
169
|
+
// ToDO add && (credential as any)?.refreshToken after refreshToken is ready
|
|
170
|
+
_a.sent();
|
|
171
|
+
return [3 /*break*/, 5];
|
|
172
|
+
case 4: throw new Error("Invalid auth credential type format");
|
|
173
|
+
case 5:
|
|
162
174
|
if (!(opts === null || opts === void 0 ? void 0 : opts.avoidEvents))
|
|
163
175
|
this.emitter.emit('connected');
|
|
164
176
|
this.hookTimer();
|
|
@@ -167,14 +179,17 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
167
179
|
});
|
|
168
180
|
});
|
|
169
181
|
};
|
|
170
|
-
WinehausSDK.prototype.reAuthenticate = function () {
|
|
182
|
+
WinehausSDK.prototype.reAuthenticate = function (opts) {
|
|
171
183
|
return __awaiter(this, void 0, void 0, function () {
|
|
172
184
|
return __generator(this, function (_a) {
|
|
173
185
|
switch (_a.label) {
|
|
174
186
|
case 0:
|
|
175
|
-
if (!this.
|
|
176
|
-
|
|
177
|
-
|
|
187
|
+
if (!this.signInCredential) {
|
|
188
|
+
if (opts === null || opts === void 0 ? void 0 : opts.throwError)
|
|
189
|
+
new Error("No SignIn set to make re-auth");
|
|
190
|
+
return [2 /*return*/];
|
|
191
|
+
}
|
|
192
|
+
return [4 /*yield*/, this.authenticate(this.signInCredential, { avoidEvents: true })];
|
|
178
193
|
case 1:
|
|
179
194
|
_a.sent();
|
|
180
195
|
return [2 /*return*/];
|
|
@@ -203,7 +218,8 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
203
218
|
return __generator(this, function (_b) {
|
|
204
219
|
switch (_b.label) {
|
|
205
220
|
case 0:
|
|
206
|
-
|
|
221
|
+
//Todo: add || !this.refreshToken after implementing it here
|
|
222
|
+
if (!this.authToken) {
|
|
207
223
|
return [2 /*return*/, this.clearTokens()];
|
|
208
224
|
}
|
|
209
225
|
if (!((_a = this.authTokenDecoded) === null || _a === void 0 ? void 0 : _a.exp)) {
|
|
@@ -248,14 +264,14 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
248
264
|
WinehausSDK.prototype.getRefreshToken = function () {
|
|
249
265
|
return this.refreshToken.toString();
|
|
250
266
|
};
|
|
251
|
-
WinehausSDK.prototype.refreshTokens = function () {
|
|
267
|
+
WinehausSDK.prototype.refreshTokens = function (opts) {
|
|
252
268
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
269
|
return __generator(this, function (_a) {
|
|
254
270
|
switch (_a.label) {
|
|
255
271
|
case 0:
|
|
256
272
|
// ToDo: Refresh token is not implemented under this version. For a while, lets just re-auth
|
|
257
273
|
this.clearTokens();
|
|
258
|
-
return [4 /*yield*/, this.reAuthenticate()];
|
|
274
|
+
return [4 /*yield*/, this.reAuthenticate(opts)];
|
|
259
275
|
case 1:
|
|
260
276
|
_a.sent();
|
|
261
277
|
return [2 /*return*/];
|
|
@@ -281,6 +297,14 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
281
297
|
});
|
|
282
298
|
});
|
|
283
299
|
};
|
|
300
|
+
WinehausSDK.prototype.authenticateAsToken = function (credential) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
302
|
+
return __generator(this, function (_a) {
|
|
303
|
+
this.setTokens({ token: credential.authToken, refreshToken: credential.refreshToken });
|
|
304
|
+
return [2 /*return*/];
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
};
|
|
284
308
|
WinehausSDK.prototype.setTokens = function (data) {
|
|
285
309
|
this.setAuthToken(data.token);
|
|
286
310
|
this.setRefreshToken(data.refreshToken);
|
package/dist/types/api/api.d.ts
CHANGED
|
@@ -7,12 +7,7 @@ export interface CreateTenantUserDto {
|
|
|
7
7
|
*/
|
|
8
8
|
password?: string;
|
|
9
9
|
/** @example ["operator"] */
|
|
10
|
-
roles:
|
|
11
|
-
}
|
|
12
|
-
export declare enum CreateTenantUserDtoRolesEnum {
|
|
13
|
-
Operator = "operator",
|
|
14
|
-
Admin = "admin",
|
|
15
|
-
Owner = "owner"
|
|
10
|
+
roles: TenantRoleEnum[];
|
|
16
11
|
}
|
|
17
12
|
export interface HttpExceptionDto {
|
|
18
13
|
/** @example null */
|
|
@@ -27,15 +22,6 @@ export interface HttpExceptionDto {
|
|
|
27
22
|
/** @example "2022-07-25T17:24:07.042Z" */
|
|
28
23
|
timestamp: string;
|
|
29
24
|
}
|
|
30
|
-
export declare enum ListTenantUsersParamsRolesEnum {
|
|
31
|
-
Operator = "operator",
|
|
32
|
-
Admin = "admin",
|
|
33
|
-
Owner = "owner"
|
|
34
|
-
}
|
|
35
|
-
export declare enum ListTenantUsersParamsStatusEnum {
|
|
36
|
-
Enabled = "enabled",
|
|
37
|
-
Blocked = "blocked"
|
|
38
|
-
}
|
|
39
25
|
export declare enum OrderByEnum {
|
|
40
26
|
ASC = "ASC",
|
|
41
27
|
DESC = "DESC"
|
|
@@ -87,31 +73,30 @@ export interface SigninResponseDto {
|
|
|
87
73
|
token: string;
|
|
88
74
|
user: UserEntityDto;
|
|
89
75
|
}
|
|
76
|
+
export declare enum TenantRoleEnum {
|
|
77
|
+
Operator = "operator",
|
|
78
|
+
Admin = "admin",
|
|
79
|
+
Owner = "owner"
|
|
80
|
+
}
|
|
90
81
|
export interface TenantUserEntityDto {
|
|
91
|
-
roles:
|
|
82
|
+
roles: TenantRoleEnum[];
|
|
92
83
|
/** @example "enabled" */
|
|
93
|
-
status:
|
|
84
|
+
status: TenantUserStatusEnum;
|
|
94
85
|
/** @format uuid */
|
|
95
86
|
tenantId: string;
|
|
96
87
|
user: UserEntityDto;
|
|
97
88
|
/** @format uuid */
|
|
98
89
|
userId: string;
|
|
99
90
|
}
|
|
100
|
-
export declare enum TenantUserEntityDtoRolesEnum {
|
|
101
|
-
Operator = "operator",
|
|
102
|
-
Admin = "admin",
|
|
103
|
-
Owner = "owner"
|
|
104
|
-
}
|
|
105
|
-
/** @example "enabled" */
|
|
106
|
-
export declare enum TenantUserEntityDtoStatusEnum {
|
|
107
|
-
Enabled = "enabled",
|
|
108
|
-
Blocked = "blocked"
|
|
109
|
-
}
|
|
110
91
|
export interface TenantUserEntityPaginationDto {
|
|
111
92
|
items: TenantUserEntityDto[];
|
|
112
93
|
links?: PaginationLinksDto;
|
|
113
94
|
meta: PaginationMetaDto;
|
|
114
95
|
}
|
|
96
|
+
export declare enum TenantUserStatusEnum {
|
|
97
|
+
Enabled = "enabled",
|
|
98
|
+
Blocked = "blocked"
|
|
99
|
+
}
|
|
115
100
|
export interface UpdateUserPasswordDto {
|
|
116
101
|
/** @example "P@ssw0rd" */
|
|
117
102
|
currentPassword: string;
|
|
@@ -320,10 +305,10 @@ export declare namespace Admin {
|
|
|
320
305
|
* @example 1
|
|
321
306
|
*/
|
|
322
307
|
page?: number;
|
|
323
|
-
roles?:
|
|
308
|
+
roles?: TenantRoleEnum[];
|
|
324
309
|
search?: string;
|
|
325
310
|
sortBy?: string[];
|
|
326
|
-
status?:
|
|
311
|
+
status?: TenantUserStatusEnum[];
|
|
327
312
|
};
|
|
328
313
|
type RequestBody = never;
|
|
329
314
|
type RequestHeaders = {};
|
|
@@ -510,10 +495,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
510
495
|
* @example 1
|
|
511
496
|
*/
|
|
512
497
|
page?: number;
|
|
513
|
-
roles?:
|
|
498
|
+
roles?: TenantRoleEnum[];
|
|
514
499
|
search?: string;
|
|
515
500
|
sortBy?: string[];
|
|
516
|
-
status?:
|
|
501
|
+
status?: TenantUserStatusEnum[];
|
|
517
502
|
}, params?: RequestParams) => Promise<TenantUserEntityPaginationDto>;
|
|
518
503
|
};
|
|
519
504
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SigninDto } from './api/api';
|
|
1
2
|
export interface SDKOptions {
|
|
2
3
|
baseURL: string;
|
|
3
4
|
autoRefresh?: boolean;
|
|
@@ -14,3 +15,8 @@ export type SDKEvents = {
|
|
|
14
15
|
refreshToken: string;
|
|
15
16
|
};
|
|
16
17
|
};
|
|
18
|
+
export interface AuthenticatedCredential {
|
|
19
|
+
authToken: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
}
|
|
22
|
+
export type AuthCredential = SigninDto | AuthenticatedCredential;
|
package/dist/types/sdk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { SDKOptions, ApiSecurityDataType, SDKEvents } from './interfaces';
|
|
2
|
+
import { SDKOptions, ApiSecurityDataType, SDKEvents, AuthCredential } from './interfaces';
|
|
3
3
|
import { JwtPayload } from 'jwt-decode';
|
|
4
4
|
import { Api, SigninDto } from './api/api';
|
|
5
5
|
import { Emitter } from 'mitt';
|
|
@@ -11,7 +11,7 @@ export declare class WinehausSDK {
|
|
|
11
11
|
protected refreshToken: string;
|
|
12
12
|
protected options: SDKOptions;
|
|
13
13
|
protected autoRefreshTimer: NodeJS.Timeout | undefined;
|
|
14
|
-
protected
|
|
14
|
+
protected signInCredential: SigninDto | undefined;
|
|
15
15
|
emitter: Emitter<SDKEvents>;
|
|
16
16
|
protected defaultOptions: Partial<SDKOptions>;
|
|
17
17
|
constructor(options: SDKOptions);
|
|
@@ -20,10 +20,12 @@ export declare class WinehausSDK {
|
|
|
20
20
|
private hookTimer;
|
|
21
21
|
private hookInterceptors;
|
|
22
22
|
clearTokens(): void;
|
|
23
|
-
authenticate(credential:
|
|
23
|
+
authenticate(credential: AuthCredential, opts?: {
|
|
24
24
|
avoidEvents?: boolean;
|
|
25
25
|
}): Promise<void>;
|
|
26
|
-
reAuthenticate(
|
|
26
|
+
reAuthenticate(opts?: {
|
|
27
|
+
throwError?: boolean;
|
|
28
|
+
}): Promise<void>;
|
|
27
29
|
isAuthenticated(): boolean;
|
|
28
30
|
protected setAuthToken(token: string): void;
|
|
29
31
|
triggerRefreshToken(): Promise<void>;
|
|
@@ -31,8 +33,11 @@ export declare class WinehausSDK {
|
|
|
31
33
|
getAuthToken(): string;
|
|
32
34
|
protected setRefreshToken(refreshToken: string): void;
|
|
33
35
|
getRefreshToken(): string;
|
|
34
|
-
refreshTokens(
|
|
36
|
+
refreshTokens(opts?: {
|
|
37
|
+
throwError?: boolean;
|
|
38
|
+
}): Promise<void>;
|
|
35
39
|
private authenticateAsUser;
|
|
40
|
+
private authenticateAsToken;
|
|
36
41
|
private setTokens;
|
|
37
42
|
getAuthTokenDecoded(): JwtPayload | undefined;
|
|
38
43
|
getRefreshTokenDecoded(): JwtPayload | undefined;
|
package/dist/umd/index.ts
CHANGED
|
@@ -16087,13 +16087,13 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
16087
16087
|
case 0:
|
|
16088
16088
|
if (!(((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) === 401 &&
|
|
16089
16089
|
this.authToken &&
|
|
16090
|
-
this.refreshToken &&
|
|
16090
|
+
// ToDO: Uncomment this this.refreshToken &&
|
|
16091
16091
|
!refreshTokenUsed.has(this.refreshToken))) return [3 /*break*/, 4];
|
|
16092
16092
|
refreshTokenUsed.add(this.refreshToken);
|
|
16093
16093
|
_c.label = 1;
|
|
16094
16094
|
case 1:
|
|
16095
16095
|
_c.trys.push([1, 3, , 4]);
|
|
16096
|
-
return [4 /*yield*/, this.refreshTokens()];
|
|
16096
|
+
return [4 /*yield*/, this.refreshTokens({ throwError: true })];
|
|
16097
16097
|
case 2:
|
|
16098
16098
|
_c.sent();
|
|
16099
16099
|
return [3 /*break*/, 4];
|
|
@@ -16121,10 +16121,22 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
16121
16121
|
case 0:
|
|
16122
16122
|
if (!(opts === null || opts === void 0 ? void 0 : opts.avoidEvents))
|
|
16123
16123
|
this.emitter.emit('connecting');
|
|
16124
|
+
if (!((credential === null || credential === void 0 ? void 0 : credential.email) && (credential === null || credential === void 0 ? void 0 : credential.password))) return [3 /*break*/, 2];
|
|
16124
16125
|
return [4 /*yield*/, this.authenticateAsUser(credential)];
|
|
16125
16126
|
case 1:
|
|
16126
16127
|
_a.sent();
|
|
16127
|
-
this.
|
|
16128
|
+
this.signInCredential = credential;
|
|
16129
|
+
return [3 /*break*/, 5];
|
|
16130
|
+
case 2:
|
|
16131
|
+
if (!(credential === null || credential === void 0 ? void 0 : credential.authToken)) return [3 /*break*/, 4];
|
|
16132
|
+
// ToDO add && (credential as any)?.refreshToken after refreshToken is ready
|
|
16133
|
+
return [4 /*yield*/, this.authenticateAsToken(credential)];
|
|
16134
|
+
case 3:
|
|
16135
|
+
// ToDO add && (credential as any)?.refreshToken after refreshToken is ready
|
|
16136
|
+
_a.sent();
|
|
16137
|
+
return [3 /*break*/, 5];
|
|
16138
|
+
case 4: throw new Error("Invalid auth credential type format");
|
|
16139
|
+
case 5:
|
|
16128
16140
|
if (!(opts === null || opts === void 0 ? void 0 : opts.avoidEvents))
|
|
16129
16141
|
this.emitter.emit('connected');
|
|
16130
16142
|
this.hookTimer();
|
|
@@ -16133,14 +16145,17 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
16133
16145
|
});
|
|
16134
16146
|
});
|
|
16135
16147
|
};
|
|
16136
|
-
WinehausSDK.prototype.reAuthenticate = function () {
|
|
16148
|
+
WinehausSDK.prototype.reAuthenticate = function (opts) {
|
|
16137
16149
|
return __awaiter(this, void 0, void 0, function () {
|
|
16138
16150
|
return __generator(this, function (_a) {
|
|
16139
16151
|
switch (_a.label) {
|
|
16140
16152
|
case 0:
|
|
16141
|
-
if (!this.
|
|
16142
|
-
|
|
16143
|
-
|
|
16153
|
+
if (!this.signInCredential) {
|
|
16154
|
+
if (opts === null || opts === void 0 ? void 0 : opts.throwError)
|
|
16155
|
+
new Error("No SignIn set to make re-auth");
|
|
16156
|
+
return [2 /*return*/];
|
|
16157
|
+
}
|
|
16158
|
+
return [4 /*yield*/, this.authenticate(this.signInCredential, { avoidEvents: true })];
|
|
16144
16159
|
case 1:
|
|
16145
16160
|
_a.sent();
|
|
16146
16161
|
return [2 /*return*/];
|
|
@@ -16169,7 +16184,8 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
16169
16184
|
return __generator(this, function (_b) {
|
|
16170
16185
|
switch (_b.label) {
|
|
16171
16186
|
case 0:
|
|
16172
|
-
|
|
16187
|
+
//Todo: add || !this.refreshToken after implementing it here
|
|
16188
|
+
if (!this.authToken) {
|
|
16173
16189
|
return [2 /*return*/, this.clearTokens()];
|
|
16174
16190
|
}
|
|
16175
16191
|
if (!((_a = this.authTokenDecoded) === null || _a === void 0 ? void 0 : _a.exp)) {
|
|
@@ -16214,14 +16230,14 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
16214
16230
|
WinehausSDK.prototype.getRefreshToken = function () {
|
|
16215
16231
|
return this.refreshToken.toString();
|
|
16216
16232
|
};
|
|
16217
|
-
WinehausSDK.prototype.refreshTokens = function () {
|
|
16233
|
+
WinehausSDK.prototype.refreshTokens = function (opts) {
|
|
16218
16234
|
return __awaiter(this, void 0, void 0, function () {
|
|
16219
16235
|
return __generator(this, function (_a) {
|
|
16220
16236
|
switch (_a.label) {
|
|
16221
16237
|
case 0:
|
|
16222
16238
|
// ToDo: Refresh token is not implemented under this version. For a while, lets just re-auth
|
|
16223
16239
|
this.clearTokens();
|
|
16224
|
-
return [4 /*yield*/, this.reAuthenticate()];
|
|
16240
|
+
return [4 /*yield*/, this.reAuthenticate(opts)];
|
|
16225
16241
|
case 1:
|
|
16226
16242
|
_a.sent();
|
|
16227
16243
|
return [2 /*return*/];
|
|
@@ -16247,6 +16263,14 @@ var WinehausSDK = /** @class */ (function () {
|
|
|
16247
16263
|
});
|
|
16248
16264
|
});
|
|
16249
16265
|
};
|
|
16266
|
+
WinehausSDK.prototype.authenticateAsToken = function (credential) {
|
|
16267
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
16268
|
+
return __generator(this, function (_a) {
|
|
16269
|
+
this.setTokens({ token: credential.authToken, refreshToken: credential.refreshToken });
|
|
16270
|
+
return [2 /*return*/];
|
|
16271
|
+
});
|
|
16272
|
+
});
|
|
16273
|
+
};
|
|
16250
16274
|
WinehausSDK.prototype.setTokens = function (data) {
|
|
16251
16275
|
this.setAuthToken(data.token);
|
|
16252
16276
|
this.setRefreshToken(data.refreshToken);
|
|
@@ -18386,41 +18410,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18386
18410
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18387
18411
|
};
|
|
18388
18412
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
18389
|
-
exports.Api = exports.HttpClient = exports.ContentType = exports.
|
|
18390
|
-
var CreateTenantUserDtoRolesEnum;
|
|
18391
|
-
(function (CreateTenantUserDtoRolesEnum) {
|
|
18392
|
-
CreateTenantUserDtoRolesEnum["Operator"] = "operator";
|
|
18393
|
-
CreateTenantUserDtoRolesEnum["Admin"] = "admin";
|
|
18394
|
-
CreateTenantUserDtoRolesEnum["Owner"] = "owner";
|
|
18395
|
-
})(CreateTenantUserDtoRolesEnum = exports.CreateTenantUserDtoRolesEnum || (exports.CreateTenantUserDtoRolesEnum = {}));
|
|
18396
|
-
var ListTenantUsersParamsRolesEnum;
|
|
18397
|
-
(function (ListTenantUsersParamsRolesEnum) {
|
|
18398
|
-
ListTenantUsersParamsRolesEnum["Operator"] = "operator";
|
|
18399
|
-
ListTenantUsersParamsRolesEnum["Admin"] = "admin";
|
|
18400
|
-
ListTenantUsersParamsRolesEnum["Owner"] = "owner";
|
|
18401
|
-
})(ListTenantUsersParamsRolesEnum = exports.ListTenantUsersParamsRolesEnum || (exports.ListTenantUsersParamsRolesEnum = {}));
|
|
18402
|
-
var ListTenantUsersParamsStatusEnum;
|
|
18403
|
-
(function (ListTenantUsersParamsStatusEnum) {
|
|
18404
|
-
ListTenantUsersParamsStatusEnum["Enabled"] = "enabled";
|
|
18405
|
-
ListTenantUsersParamsStatusEnum["Blocked"] = "blocked";
|
|
18406
|
-
})(ListTenantUsersParamsStatusEnum = exports.ListTenantUsersParamsStatusEnum || (exports.ListTenantUsersParamsStatusEnum = {}));
|
|
18413
|
+
exports.Api = exports.HttpClient = exports.ContentType = exports.TenantUserStatusEnum = exports.TenantRoleEnum = exports.OrderByEnum = void 0;
|
|
18407
18414
|
var OrderByEnum;
|
|
18408
18415
|
(function (OrderByEnum) {
|
|
18409
18416
|
OrderByEnum["ASC"] = "ASC";
|
|
18410
18417
|
OrderByEnum["DESC"] = "DESC";
|
|
18411
18418
|
})(OrderByEnum = exports.OrderByEnum || (exports.OrderByEnum = {}));
|
|
18412
|
-
var
|
|
18413
|
-
(function (
|
|
18414
|
-
|
|
18415
|
-
|
|
18416
|
-
|
|
18417
|
-
})(
|
|
18418
|
-
|
|
18419
|
-
|
|
18420
|
-
|
|
18421
|
-
|
|
18422
|
-
|
|
18423
|
-
})(TenantUserEntityDtoStatusEnum = exports.TenantUserEntityDtoStatusEnum || (exports.TenantUserEntityDtoStatusEnum = {}));
|
|
18419
|
+
var TenantRoleEnum;
|
|
18420
|
+
(function (TenantRoleEnum) {
|
|
18421
|
+
TenantRoleEnum["Operator"] = "operator";
|
|
18422
|
+
TenantRoleEnum["Admin"] = "admin";
|
|
18423
|
+
TenantRoleEnum["Owner"] = "owner";
|
|
18424
|
+
})(TenantRoleEnum = exports.TenantRoleEnum || (exports.TenantRoleEnum = {}));
|
|
18425
|
+
var TenantUserStatusEnum;
|
|
18426
|
+
(function (TenantUserStatusEnum) {
|
|
18427
|
+
TenantUserStatusEnum["Enabled"] = "enabled";
|
|
18428
|
+
TenantUserStatusEnum["Blocked"] = "blocked";
|
|
18429
|
+
})(TenantUserStatusEnum = exports.TenantUserStatusEnum || (exports.TenantUserStatusEnum = {}));
|
|
18424
18430
|
var axios_1 = __importDefault(__webpack_require__(6425));
|
|
18425
18431
|
var ContentType;
|
|
18426
18432
|
(function (ContentType) {
|