@thelllabs/winehaus-sdk 0.0.4 → 0.0.7
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 +573 -31
- package/dist/cjs/sdk.js +34 -10
- package/dist/esm/api/api.js +572 -30
- package/dist/esm/sdk.js +34 -10
- package/dist/types/api/api.d.ts +1822 -181
- package/dist/types/interfaces.d.ts +6 -0
- package/dist/types/sdk.d.ts +10 -5
- package/dist/umd/index.ts +607 -41
- package/package.json +1 -1
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);
|