mosquito-transport-js 0.2.3 → 0.2.4
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/package.json +2 -2
- package/src/helpers/utils.js +1 -1
- package/src/helpers/variables.js +1 -0
- package/src/index.d.ts +29 -4
- package/src/index.js +17 -20
- package/src/products/auth/accessor.js +3 -2
- package/src/products/auth/index.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosquito-transport-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Javascript web sdk for mosquito-transport (https://github.com/deflexable/mosquito-transport)",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
38
|
"set-large-timeout": "^1.0.1",
|
|
39
39
|
"socket.io-client": "^4.6.2",
|
|
40
|
-
"subscription-listener": "^1.1.
|
|
40
|
+
"subscription-listener": "^1.1.2",
|
|
41
41
|
"tweetnacl": "^1.0.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
package/src/helpers/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServerReachableListener, StoreReadyListener } from "./listeners";
|
|
2
2
|
import { CACHE_PROTOCOL, CACHE_STORAGE_PATH, DEFAULT_CACHE_PASSWORD } from "./values";
|
|
3
3
|
import { CacheStore, Scoped } from "./variables";
|
|
4
|
-
import { decryptString, encryptString,
|
|
4
|
+
import { decryptString, encryptString, serializeE2E } from "./peripherals";
|
|
5
5
|
|
|
6
6
|
export const updateCacheStore = () => {
|
|
7
7
|
try { window } catch (_) { return; }
|
package/src/helpers/variables.js
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -290,6 +290,7 @@ interface DocumentFind {
|
|
|
290
290
|
$or?: any[];
|
|
291
291
|
$text?: {
|
|
292
292
|
$search: string;
|
|
293
|
+
$field: string;
|
|
293
294
|
$language?: string;
|
|
294
295
|
$caseSensitive?: boolean;
|
|
295
296
|
$diacriticSensitive?: boolean;
|
|
@@ -319,8 +320,11 @@ interface MTAuth {
|
|
|
319
320
|
listenVerifiedStatus: (callback?: (verified?: boolean) => void, onError?: (error?: ErrorResponse) => void) => () => void;
|
|
320
321
|
listenAuthToken: (callback: (token: string) => void) => () => void;
|
|
321
322
|
getAuthToken: () => Promise<string>;
|
|
322
|
-
|
|
323
|
-
|
|
323
|
+
getRefreshToken: () => Promise<string>;
|
|
324
|
+
getRefreshTokenData: () => Promise<RefreshTokenData>;
|
|
325
|
+
parseToken: () => string;
|
|
326
|
+
listenAuth: (callback: (auth: TokenEventData) => void) => () => void;
|
|
327
|
+
getAuth: () => Promise<TokenEventData>;
|
|
324
328
|
signOut: () => Promise<void>;
|
|
325
329
|
forceRefreshToken: () => Promise<string>;
|
|
326
330
|
}
|
|
@@ -341,14 +345,35 @@ interface AuthData {
|
|
|
341
345
|
signupMethod: 'google' | 'apple' | 'custom' | 'github' | 'twitter' | 'facebook' | string;
|
|
342
346
|
currentAuthMethod: 'google' | 'apple' | 'custom' | 'github' | 'twitter' | 'facebook' | string;
|
|
343
347
|
joinedOn: number;
|
|
344
|
-
encryptionKey: string;
|
|
345
348
|
uid: string;
|
|
346
349
|
claims: Object;
|
|
347
350
|
emailVerified: boolean;
|
|
351
|
+
tokenID: string;
|
|
352
|
+
disabled: boolean;
|
|
353
|
+
entityOf: string;
|
|
348
354
|
profile: {
|
|
349
355
|
photo: string;
|
|
350
356
|
name: string;
|
|
351
|
-
}
|
|
357
|
+
},
|
|
358
|
+
exp: number;
|
|
359
|
+
aud: string;
|
|
360
|
+
iss: string;
|
|
361
|
+
sub: string;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
interface RefreshTokenData {
|
|
365
|
+
uid: string;
|
|
366
|
+
tokenID: string;
|
|
367
|
+
isRefreshToken: true;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
interface TokenEventData extends AuthData {
|
|
371
|
+
tokenManager: TokenManager | null;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface TokenManager {
|
|
375
|
+
refreshToken: string;
|
|
376
|
+
accessToken: string;
|
|
352
377
|
}
|
|
353
378
|
|
|
354
379
|
declare type Base64String = string;
|
package/src/index.js
CHANGED
|
@@ -300,26 +300,23 @@ export class MosquitoTransport {
|
|
|
300
300
|
const validateReleaseCacheProp = (prop) => {
|
|
301
301
|
const cacheList = [...Object.values(CACHE_PROTOCOL)];
|
|
302
302
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
} else throw `Unexpected property named ${k}`;
|
|
321
|
-
});
|
|
322
|
-
}
|
|
303
|
+
Object.entries(prop).forEach(([k, v]) => {
|
|
304
|
+
if (k === 'cachePassword') {
|
|
305
|
+
if (typeof v !== 'string' || v.trim().length <= 0)
|
|
306
|
+
throw `Invalid value supplied to cachePassword, value must be a string and greater than 0 characters`;
|
|
307
|
+
} else if (k === 'cacheProtocol') {
|
|
308
|
+
if (!cacheList.includes(`${v}`)) throw `unknown value supplied to ${k}, expected any of ${cacheList}`;
|
|
309
|
+
} else if (k === 'io') {
|
|
310
|
+
Object.entries(v).forEach(([k, v]) => {
|
|
311
|
+
if (k === 'input' || k === 'output') {
|
|
312
|
+
if (typeof v !== 'function')
|
|
313
|
+
throw `Invalid value supplied to "io.${k}", expected a function but got "${v}"`;
|
|
314
|
+
} else throw `Unexpected property named "io.${k}"`;
|
|
315
|
+
});
|
|
316
|
+
} else throw `Unexpected property named ${k}`;
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
if (!prop?.io && !prop?.cacheProtocol) throw 'You need to provide either "io" or "cacheProtocol"';
|
|
323
320
|
}
|
|
324
321
|
|
|
325
322
|
const validator = {
|
|
@@ -2,8 +2,8 @@ import setLargeTimeout from "set-large-timeout";
|
|
|
2
2
|
import { doSignOut } from ".";
|
|
3
3
|
import EngineApi from "../../helpers/EngineApi";
|
|
4
4
|
import { AuthTokenListener, TokenRefreshListener } from "../../helpers/listeners";
|
|
5
|
-
import { decodeBinary, deserializeE2E, listenReachableServer
|
|
6
|
-
import {
|
|
5
|
+
import { decodeBinary, deserializeE2E, listenReachableServer } from "../../helpers/peripherals";
|
|
6
|
+
import { awaitStore, buildFetchInterface, simplifyError, updateCacheStore } from "../../helpers/utils";
|
|
7
7
|
import { CacheStore, Scoped } from "../../helpers/variables";
|
|
8
8
|
|
|
9
9
|
export const listenToken = (callback, projectUrl) =>
|
|
@@ -15,6 +15,7 @@ export const listenToken = (callback, projectUrl) =>
|
|
|
15
15
|
export const injectFreshToken = async (config, { token, refreshToken }) => {
|
|
16
16
|
const { projectUrl } = config;
|
|
17
17
|
|
|
18
|
+
await awaitStore();
|
|
18
19
|
CacheStore.AuthStore[projectUrl] = { token, refreshToken };
|
|
19
20
|
Scoped.AuthJWTToken[projectUrl] = token;
|
|
20
21
|
updateCacheStore();
|
|
@@ -105,6 +105,13 @@ export class MTAuth {
|
|
|
105
105
|
|
|
106
106
|
listenAuthToken = (callback) => listenToken(callback, this.builder.projectUrl);
|
|
107
107
|
|
|
108
|
+
getRefreshToken = async () => {
|
|
109
|
+
await awaitStore();
|
|
110
|
+
return CacheStore.AuthStore[this.builder.projectUrl]?.refreshToken;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
parseToken = (token) => parseToken(token);
|
|
114
|
+
|
|
108
115
|
getAuthToken = () => new Promise(resolve => {
|
|
109
116
|
const l = listenToken(t => {
|
|
110
117
|
l();
|