@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/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);
|