mosquito-transport-js 0.3.6 → 0.3.8
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 +1 -1
- package/src/index.d.ts +10 -6
- package/src/index.js +8 -2
- package/src/products/auth/index.js +8 -9
- package/src/products/http_callable/index.js +2 -2
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -389,12 +389,12 @@ interface MTAuth {
|
|
|
389
389
|
twitterSignin: () => Promise<SignupResult>;
|
|
390
390
|
githubSignin: () => Promise<SignupResult>;
|
|
391
391
|
listenVerifiedStatus: (callback?: (verified?: boolean) => void, onError?: (error?: ErrorResponse) => void) => () => void;
|
|
392
|
-
listenAuthToken: (callback: (token: string) => void) => () => void;
|
|
393
|
-
getAuthToken: () => Promise<string>;
|
|
394
|
-
getRefreshToken: () => Promise<string>;
|
|
395
|
-
getRefreshTokenData: () => Promise<RefreshTokenData>;
|
|
392
|
+
listenAuthToken: (callback: (token: string | null) => void) => () => void;
|
|
393
|
+
getAuthToken: () => Promise<string | null>;
|
|
394
|
+
getRefreshToken: () => Promise<string | undefined>;
|
|
395
|
+
getRefreshTokenData: () => Promise<RefreshTokenData | undefined>;
|
|
396
396
|
parseToken: (token: string) => AuthData | RefreshTokenData;
|
|
397
|
-
listenAuth: (callback: (auth: TokenEventData) => void) => () => void;
|
|
397
|
+
listenAuth: (callback: (auth: TokenEventData | null) => void) => () => void;
|
|
398
398
|
getAuth: () => Promise<TokenEventData>;
|
|
399
399
|
signOut: () => Promise<void>;
|
|
400
400
|
forceRefreshToken: () => Promise<string>;
|
|
@@ -437,10 +437,14 @@ interface RefreshTokenData {
|
|
|
437
437
|
uid: string;
|
|
438
438
|
tokenID: string;
|
|
439
439
|
isRefreshToken: true;
|
|
440
|
+
exp: number;
|
|
441
|
+
aud: string;
|
|
442
|
+
iss: string;
|
|
443
|
+
sub: string;
|
|
440
444
|
}
|
|
441
445
|
|
|
442
446
|
interface TokenEventData extends AuthData {
|
|
443
|
-
tokenManager: TokenManager
|
|
447
|
+
tokenManager: TokenManager;
|
|
444
448
|
}
|
|
445
449
|
|
|
446
450
|
interface TokenManager {
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deserializeE2E, listenReachableServer, serializeE2E } from "./helpers/peripherals";
|
|
2
2
|
import { awaitStore, releaseCacheStore } from "./helpers/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { CacheStore, Scoped } from "./helpers/variables";
|
|
4
4
|
import { MTCollection, batchWrite, trySendPendingWrite } from "./products/database";
|
|
5
5
|
import { MTStorage } from "./products/storage";
|
|
6
6
|
import { ServerReachableListener, TokenRefreshListener } from "./helpers/listeners";
|
|
@@ -14,7 +14,7 @@ import { Validator } from 'guard-object';
|
|
|
14
14
|
import sendMessage from "./helpers/broadcaster";
|
|
15
15
|
import cloneDeep from 'lodash.clonedeep';
|
|
16
16
|
import { Buffer } from 'buffer';
|
|
17
|
-
import MTAuth from './products/auth';
|
|
17
|
+
import MTAuth, { purgePendingToken } from './products/auth';
|
|
18
18
|
|
|
19
19
|
const {
|
|
20
20
|
_listenCollection,
|
|
@@ -133,6 +133,12 @@ export class MosquitoTransport {
|
|
|
133
133
|
validateReleaseCacheProp({ ...prop });
|
|
134
134
|
Scoped.ReleaseCacheData = { ...prop };
|
|
135
135
|
releaseCacheStore({ ...prop });
|
|
136
|
+
// purge residue tokens
|
|
137
|
+
awaitStore().then(() => {
|
|
138
|
+
Object.keys(CacheStore.PendingAuthPurge).forEach(k => {
|
|
139
|
+
purgePendingToken(k);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
getDatabase = (dbName, dbUrl) => ({
|
|
@@ -8,13 +8,6 @@ import { deserializeE2E, encodeBinary, serializeE2E } from "../../helpers/periph
|
|
|
8
8
|
import { simplifyCaughtError, simplifyError } from "simplify-error";
|
|
9
9
|
import cloneDeep from "lodash.clonedeep";
|
|
10
10
|
|
|
11
|
-
// purge residue tokens
|
|
12
|
-
awaitStore().then(() => {
|
|
13
|
-
Object.keys(CacheStore.PendingAuthPurge).forEach(k => {
|
|
14
|
-
purgePendingToken(k);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
11
|
const {
|
|
19
12
|
_listenUserVerification,
|
|
20
13
|
_signOut,
|
|
@@ -126,6 +119,12 @@ export default class MTAuth {
|
|
|
126
119
|
return CacheStore.AuthStore[this.builder.projectUrl]?.refreshToken;
|
|
127
120
|
}
|
|
128
121
|
|
|
122
|
+
getRefreshTokenData = async () => {
|
|
123
|
+
await awaitStore();
|
|
124
|
+
const { refreshToken } = CacheStore.AuthStore[this.builder.projectUrl] || {};
|
|
125
|
+
return refreshToken && parseToken(refreshToken);
|
|
126
|
+
}
|
|
127
|
+
|
|
129
128
|
parseToken = (token) => parseToken(token);
|
|
130
129
|
|
|
131
130
|
getAuthToken = () => new Promise(resolve => {
|
|
@@ -290,7 +289,7 @@ export const revokeAuthIntance = async (builder, authStore) => {
|
|
|
290
289
|
await purgePendingToken(nodeId);
|
|
291
290
|
};
|
|
292
291
|
|
|
293
|
-
const purgePendingToken = async (nodeId) => {
|
|
292
|
+
export const purgePendingToken = async (nodeId) => {
|
|
294
293
|
const {
|
|
295
294
|
auth: { token, refreshToken: r_token },
|
|
296
295
|
data: { projectUrl, serverE2E_PublicKey, accessKey, uglify, extraHeaders }
|
|
@@ -300,7 +299,7 @@ const purgePendingToken = async (nodeId) => {
|
|
|
300
299
|
try {
|
|
301
300
|
let isConnected;
|
|
302
301
|
try {
|
|
303
|
-
isConnected = (await (await fetch(_areYouOk(projectUrl))).json()).status === 'yes';
|
|
302
|
+
isConnected = (await (await fetch(_areYouOk(projectUrl))).json(), { cache: 'no-cache' }).status === 'yes';
|
|
304
303
|
} catch (_) { }
|
|
305
304
|
|
|
306
305
|
if (!isConnected)
|
|
@@ -61,8 +61,8 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
61
61
|
if ('uglified' in rawHeader)
|
|
62
62
|
throw '"uglified" in header is a reserved prop';
|
|
63
63
|
|
|
64
|
-
if (isBaseUrl && !rawApproach)
|
|
65
|
-
|
|
64
|
+
// if (isBaseUrl && !rawApproach)
|
|
65
|
+
// throw `please set { rawApproach: true } if you're trying to access different endpoint at "${input}"`;
|
|
66
66
|
|
|
67
67
|
if (body !== undefined) {
|
|
68
68
|
if (
|