@de./sdk 2.1.0 → 2.2.0
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/allend/Access.js +20 -5
- package/dist/allend/Access.js.map +1 -1
- package/dist/allend/Agent/realtime.d.ts +8 -11
- package/dist/allend/Agent/realtime.js +10 -42
- package/dist/allend/Agent/realtime.js.map +1 -1
- package/dist/allend/LSP/agents.d.ts +14 -1
- package/dist/allend/LSP/agents.js +38 -0
- package/dist/allend/LSP/agents.js.map +1 -1
- package/dist/allend/MSI/Handles.d.ts +10 -2
- package/dist/allend/MSI/Handles.js +11 -3
- package/dist/allend/MSI/Handles.js.map +1 -1
- package/dist/allend/MSI/index.d.ts +10 -0
- package/dist/allend/MSI/index.js +19 -0
- package/dist/allend/MSI/index.js.map +1 -1
- package/dist/allend/MSI/native.js +69 -35
- package/dist/allend/MSI/native.js.map +1 -1
- package/dist/allend/MSI/origin.d.ts +15 -0
- package/dist/allend/MSI/origin.js +25 -0
- package/dist/allend/MSI/origin.js.map +1 -0
- package/dist/allend/OTPAuth/index.d.ts +12 -18
- package/dist/allend/OTPAuth/index.js +17 -7
- package/dist/allend/OTPAuth/index.js.map +1 -1
- package/dist/allend/Realtime/index.d.ts +37 -10
- package/dist/allend/Realtime/index.js +56 -38
- package/dist/allend/Realtime/index.js.map +1 -1
- package/dist/allend/realtime-socket.d.ts +61 -0
- package/dist/allend/realtime-socket.js +122 -0
- package/dist/allend/realtime-socket.js.map +1 -0
- package/dist/backend/Auth.d.ts +14 -0
- package/dist/backend/Auth.js +16 -2
- package/dist/backend/Auth.js.map +1 -1
- package/dist/core.d.ts +2 -0
- package/dist/core.js.map +1 -1
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.js +24 -4
- package/dist/utils/index.js.map +1 -1
- package/package.json +13 -7
- package/src/allend/Access.ts +20 -4
- package/src/allend/Agent/realtime.ts +10 -47
- package/src/allend/LSP/agents.ts +46 -1
- package/src/allend/MSI/Handles.ts +12 -4
- package/src/allend/MSI/index.ts +20 -0
- package/src/allend/MSI/native.tsx +73 -34
- package/src/allend/MSI/origin.ts +20 -0
- package/src/allend/OTPAuth/index.ts +33 -25
- package/src/allend/Realtime/index.ts +88 -56
- package/src/allend/realtime-socket.ts +171 -0
- package/src/backend/Auth.ts +30 -2
- package/src/core.ts +4 -0
- package/src/utils/index.ts +27 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../../src/allend/MSI/native.tsx"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../../src/allend/MSI/native.tsx"],"names":[],"mappings":";;;;;AAmVA,wBAEC;;AAnVD,iCAAiH;AACjH,+CAAwF;AACxF,+DAA8C;AAC9C,4DAA4B;AAC5B,wDAA+B;AAC/B,0DAAiC;AACjC,wDAAgD;AAChD,oDAAwC;AACxC,sDAAuC;AAQvC,MACA,kBAAkB,GAAgC,EAAE;AAEpD,qDAAqD;AACrD,YAAY,GAAG,KAAK;AAEpB;;;;;;GAMG;AACH,uBAAuB,GAAG;IACxB,OAAO;IACP,OAAO;IACP,eAAe;IACf,kBAAkB;IAClB,wBAAwB;IACxB,qBAAqB;IACrB,sBAAsB;IACtB,mBAAmB;IACnB,OAAO;IACP,sBAAsB;CACvB,CAAA;AAED;;;;;GAKG;AACH,SAAS,eAAe;IACtB,OAAO;;;;;;;;;;;;;;;;;;;;;;;GAuBN,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,EAAE,GAAG,EAAE,WAAW,EAAc;IAClD,IAAI,GAAG,KAAK,KAAK;QAAG,OAAO,sBAAsB,CAAA;IAEjD,MAAM,IAAI,GAAG,WAAW;WACf,uBAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAA;IAEvE,OAAO,UAAU,IAAI,OAAO,CAAA;A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AAE,GAAG,EAAE,CAAA;AACjC,CAAC;AAED,MAAM,MAAM,GAAG,yBAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE;QACT,IAAI,EAAE,CAAC;QACP,eAAe,EAAE,SAAS;KAC3B;IACD,OAAO,EAAE;QACP,IAAI,EAAE,CAAC;QACP,eAAe,EAAE,aAAa;KAC/B;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a URL belongs to the MSI gateway itself.
|
|
3
|
+
*
|
|
4
|
+
* React Native's `originWhitelist` is prefix-matched and unanchored at the
|
|
5
|
+
* end, so a whitelist of `https://msi.dedot.io` also admits
|
|
6
|
+
* `https://msi.dedot.io.example.com`. That matters more in a WebView than it
|
|
7
|
+
* would in a browser: the injected bridge — and the auth secret baked into
|
|
8
|
+
* it — runs in whatever page the WebView ends up on. So the origin has to
|
|
9
|
+
* match exactly, and only a path, query or fragment separator may follow it.
|
|
10
|
+
*
|
|
11
|
+
* @param baseURL - Gateway origin, without a trailing slash
|
|
12
|
+
* @param url - URL the WebView is asking to navigate to
|
|
13
|
+
* @return - Whether the navigation is to the gateway
|
|
14
|
+
*/
|
|
15
|
+
export default function belongsToGateway(baseURL: string, url: string): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = belongsToGateway;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a URL belongs to the MSI gateway itself.
|
|
6
|
+
*
|
|
7
|
+
* React Native's `originWhitelist` is prefix-matched and unanchored at the
|
|
8
|
+
* end, so a whitelist of `https://msi.dedot.io` also admits
|
|
9
|
+
* `https://msi.dedot.io.example.com`. That matters more in a WebView than it
|
|
10
|
+
* would in a browser: the injected bridge — and the auth secret baked into
|
|
11
|
+
* it — runs in whatever page the WebView ends up on. So the origin has to
|
|
12
|
+
* match exactly, and only a path, query or fragment separator may follow it.
|
|
13
|
+
*
|
|
14
|
+
* @param baseURL - Gateway origin, without a trailing slash
|
|
15
|
+
* @param url - URL the WebView is asking to navigate to
|
|
16
|
+
* @return - Whether the navigation is to the gateway
|
|
17
|
+
*/
|
|
18
|
+
function belongsToGateway(baseURL, url) {
|
|
19
|
+
if (!url || !baseURL)
|
|
20
|
+
return false;
|
|
21
|
+
if (url === 'about:blank' || url === baseURL)
|
|
22
|
+
return true;
|
|
23
|
+
return ['/', '?', '#'].some(separator => url.startsWith(baseURL + separator));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin.js","sourceRoot":"","sources":["../../../src/allend/MSI/origin.ts"],"names":[],"mappings":";;AAcA,mCAKC;AAnBD;;;;;;;;;;;;;GAaG;AACH,SAAwB,gBAAgB,CAAE,OAAe,EAAE,GAAW;IACpE,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO;QAAG,OAAO,KAAK,CAAA;IACnC,IAAI,GAAG,KAAK,aAAa,IAAI,GAAG,KAAK,OAAO;QAAG,OAAO,IAAI,CAAA;IAE1D,OAAO,CAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAE,CAAC,IAAI,CAAE,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAE,OAAO,GAAG,SAAS,CAAE,CAAE,CAAA;AACrF,CAAC"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import type { SigninBody, CreateAccountBody } from '@de./types';
|
|
1
2
|
import type { AccessOptions, UserSession } from '../../types/access';
|
|
2
3
|
import AccessManager from '../Access';
|
|
3
4
|
import { type Res } from '../../utils';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Request bodies come from `@de./types`, which is what de.auth validates
|
|
7
|
+
* against — these were hand-declared here, and said `country?: string` where
|
|
8
|
+
* de.auth wants the Country OBJECT. Its schema is additionalProperties:false,
|
|
9
|
+
* so a caller trusting the SDK's type was answered `body/country must be
|
|
10
|
+
* object`. Nothing caught it because this client could not be constructed at
|
|
11
|
+
* all: AccessManager demanded a workspace context and a bearer token, which
|
|
12
|
+
* sign-in is what produces.
|
|
13
|
+
*/
|
|
14
|
+
export type { SigninBody, CreateAccountBody, VerificationBody, Country } from '@de./types';
|
|
11
15
|
export type SigninResult = {
|
|
12
16
|
/** What the caller must do next — verification, or account creation first. */
|
|
13
17
|
next: string;
|
|
@@ -19,16 +23,6 @@ export type SigninResult = {
|
|
|
19
23
|
*/
|
|
20
24
|
testVCode?: number;
|
|
21
25
|
};
|
|
22
|
-
export type CreateAccountBody = {
|
|
23
|
-
phone: string;
|
|
24
|
-
agreeTerms: boolean | string;
|
|
25
|
-
firstName?: string;
|
|
26
|
-
lastName?: string;
|
|
27
|
-
photo?: string;
|
|
28
|
-
type?: string;
|
|
29
|
-
country?: string;
|
|
30
|
-
newsletters?: boolean | string;
|
|
31
|
-
};
|
|
32
26
|
export type VerifyResult = {
|
|
33
27
|
ctoken?: string;
|
|
34
28
|
deviceId?: string;
|
|
@@ -51,7 +45,7 @@ export default class OTPAuth extends AccessManager {
|
|
|
51
45
|
resendSms(body: {
|
|
52
46
|
phone: string;
|
|
53
47
|
}): Promise<Res<void>>;
|
|
54
|
-
/**
|
|
48
|
+
/** A state change, so a POST — it was a GET, which is cacheable. */
|
|
55
49
|
signout(querystring?: {
|
|
56
50
|
allDevices?: boolean | string;
|
|
57
51
|
}): Promise<Res<void>>;
|
|
@@ -7,29 +7,39 @@ const Access_1 = __importDefault(require("../Access"));
|
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
class OTPAuth extends Access_1.default {
|
|
9
9
|
constructor(access) {
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* de.auth admits an agent that does not start with `De.service` only if
|
|
12
|
+
* the request carries an Authorization header — and the whole point of
|
|
13
|
+
* this client is the flow that has no token yet. The SDK's default
|
|
14
|
+
* platform is `proxy`, so every sign-in through it was answered 412
|
|
15
|
+
* before reaching a handler.
|
|
16
|
+
*
|
|
17
|
+
* `service` is the platform this client is for; a caller that knows
|
|
18
|
+
* better can still say so.
|
|
19
|
+
*/
|
|
20
|
+
super({ ...access, platform: access.platform || 'service' }, 'ASI');
|
|
11
21
|
}
|
|
12
22
|
// ── Sign-in ───────────────────────────────────────────────────────────────
|
|
13
23
|
/** Step 1 — sends the code. */
|
|
14
24
|
async signin(body) {
|
|
15
25
|
if (!body.phone)
|
|
16
26
|
throw new Error('<phone> argument required');
|
|
17
|
-
return this.request({ url: '/
|
|
27
|
+
return this.request({ url: '/auth/otp/send', method: 'POST', body });
|
|
18
28
|
}
|
|
19
29
|
/** Step 2 — exchanges the code for a session. */
|
|
20
30
|
async verify(body) {
|
|
21
|
-
return this.request({ url: '/
|
|
31
|
+
return this.request({ url: '/auth/otp/verify', method: 'POST', body });
|
|
22
32
|
}
|
|
23
33
|
/** Step 1a — for a phone de.auth has never seen. */
|
|
24
34
|
async setAccount(body) {
|
|
25
|
-
return this.request({ url: '/
|
|
35
|
+
return this.request({ url: '/auth/account/create', method: 'POST', body });
|
|
26
36
|
}
|
|
27
37
|
async resendSms(body) {
|
|
28
|
-
return this.request({ url: '/resend
|
|
38
|
+
return this.request({ url: '/auth/otp/resend', method: 'POST', body });
|
|
29
39
|
}
|
|
30
|
-
/**
|
|
40
|
+
/** A state change, so a POST — it was a GET, which is cacheable. */
|
|
31
41
|
async signout(querystring) {
|
|
32
|
-
return this.request({ url: `/
|
|
42
|
+
return this.request({ url: `/auth/session/revoke${(0, utils_1.qs)(querystring)}`, method: 'POST' });
|
|
33
43
|
}
|
|
34
44
|
// ── The signed-in person ──────────────────────────────────────────────────
|
|
35
45
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/allend/OTPAuth/index.ts"],"names":[],"mappings":";;;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I,CAAC,OAAO,CAAY,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IACzE,CAAC;CACD;AAlFD,0BAkFC"}
|
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { OrderTrackingEvent } from '@de./types';
|
|
2
|
+
import type { RTLocation, Message, Peer } from '../../types';
|
|
3
|
+
import RealtimeSocket, { type RealtimeConnectOptions } from '../realtime-socket';
|
|
4
|
+
/**
|
|
5
|
+
* Who this connection is, in De.'s vocabulary.
|
|
6
|
+
*
|
|
7
|
+
* A client is the party that engaged the provider — a CSP, a merchant, a
|
|
8
|
+
* branch. A customer is the person the delivery is handed to. They are not
|
|
9
|
+
* the same party and De. does not put them in the same room, so a customer
|
|
10
|
+
* app connecting as 'client' hears nothing addressed to customers and cannot
|
|
11
|
+
* redeem a customer's tracking token.
|
|
12
|
+
*/
|
|
13
|
+
export type RealtimeUserType = 'client' | 'customer' | 'vendor';
|
|
14
|
+
export default class Realtime extends RealtimeSocket {
|
|
15
|
+
private as;
|
|
16
|
+
protected get utype(): string;
|
|
17
|
+
/**
|
|
18
|
+
* @param id The uid the tracking session was issued for.
|
|
19
|
+
* @param utype Must equal the `role` that session was issued with.
|
|
20
|
+
* @param options `getToken` supplies a fresh access token per attempt —
|
|
21
|
+
* without it a reconnect after the token's short life is
|
|
22
|
+
* refused, and the app is left with an open socket that
|
|
23
|
+
* delivers nothing.
|
|
24
|
+
*/
|
|
25
|
+
connect(id: string, utype?: RealtimeUserType, options?: RealtimeConnectOptions): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* The rider's position, as it moves.
|
|
28
|
+
*
|
|
29
|
+
* Rate-limited by De. to 10 per second per sender, so this is a stream and
|
|
30
|
+
* not a trickle: render from it directly rather than re-fetching anything.
|
|
31
|
+
*/
|
|
32
|
+
onLocation(fn: (location: RTLocation) => void): this;
|
|
33
|
+
onRoute(fn: (route: any) => void): this;
|
|
34
|
+
onOrderUpdate(fn: (event: OrderTrackingEvent) => void): this;
|
|
35
|
+
onMessage(fn: (message: Message) => void): this;
|
|
36
|
+
sendMessage(message: Message): this;
|
|
37
|
+
onJoined(fn: (peer: Peer) => void): this;
|
|
11
38
|
onLeft(fn: (peer: Peer) => void): this;
|
|
12
39
|
onConnected(fn: (peer: Peer) => void): this;
|
|
13
40
|
onDisconnected(fn: (peer: Peer) => void): this;
|
|
@@ -3,44 +3,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var _a;
|
|
34
|
-
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
6
|
+
const realtime_socket_1 = __importDefault(require("../realtime-socket"));
|
|
7
|
+
class Realtime extends realtime_socket_1.default {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.as = 'client';
|
|
11
|
+
}
|
|
12
|
+
get utype() { return this.as; }
|
|
13
|
+
/**
|
|
14
|
+
* @param id The uid the tracking session was issued for.
|
|
15
|
+
* @param utype Must equal the `role` that session was issued with.
|
|
16
|
+
* @param options `getToken` supplies a fresh access token per attempt —
|
|
17
|
+
* without it a reconnect after the token's short life is
|
|
18
|
+
* refused, and the app is left with an open socket that
|
|
19
|
+
* delivers nothing.
|
|
20
|
+
*/
|
|
21
|
+
connect(id, utype = 'client', options) {
|
|
22
|
+
this.as = utype;
|
|
23
|
+
return this.open(id, options);
|
|
24
|
+
}
|
|
25
|
+
// ── Order room streams (after join) ─────────────────────────────────────
|
|
26
|
+
/**
|
|
27
|
+
* The rider's position, as it moves.
|
|
28
|
+
*
|
|
29
|
+
* Rate-limited by De. to 10 per second per sender, so this is a stream and
|
|
30
|
+
* not a trickle: render from it directly rather than re-fetching anything.
|
|
31
|
+
*/
|
|
32
|
+
onLocation(fn) {
|
|
33
|
+
var _a;
|
|
34
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.on('LOCATION-CHANGE', fn);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
onRoute(fn) {
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.on('ROUTE-CHANGE', fn);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
onOrderUpdate(fn) {
|
|
43
|
+
var _a;
|
|
44
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.on('ORDER_UPDATE', fn);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
onMessage(fn) {
|
|
48
|
+
var _a;
|
|
49
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.on('MESSAGE', fn);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
sendMessage(message) {
|
|
53
|
+
var _a;
|
|
54
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.emit('MESSAGE', message);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
// ── Presence ────────────────────────────────────────────────────────────
|
|
58
|
+
onJoined(fn) {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.on('JOINED', fn);
|
|
61
|
+
return this;
|
|
44
62
|
}
|
|
45
63
|
onLeft(fn) {
|
|
46
64
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/allend/Realtime/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/allend/Realtime/index.ts"],"names":[],"mappings":";;;;;AAGA,yEAAgF;AAoChF,MAAqB,QAAS,SAAQ,yBAAc;IAApD;;QACU,OAAE,GAAqB,QAAQ,CAAA;IAoEzC,CAAC;IAlEC,IAAc,KAAK,KAAa,OAAO,IAAI,CAAC,EAAE,CAAA,CAAC,CAAC;IAEhD;;;;;;;OAOG;IACH,OAAO,CAAE,EAAU,EAAE,QAA0B,QAAQ,EAAE,OAAgC;QACvF,IAAI,CAAC,EAAE,GAAG,KAAK,CAAA;QACf,OAAO,IAAI,CAAC,IAAI,CAAE,EAAE,EAAE,OAAO,CAAE,CAAA;IACjC,CAAC;IAED,2EAA2E;IAE3E;;;;;OAKG;IACH,UAAU,CAAE,EAAoC;;QAC9C,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,iBAAiB,EAAE,EAAE,CAAE,CAAA;QACpC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CAAE,EAA0B;;QACjC,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAE,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,aAAa,CAAE,EAAyC;;QACtD,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAE,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,SAAS,CAAE,EAAgC;;QACzC,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,SAAS,EAAE,EAAE,CAAE,CAAA;QAC5B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,WAAW,CAAE,OAAgB;;QAC3B,MAAA,IAAI,CAAC,GAAG,0CAAE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAE,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,2EAA2E;IAE3E,QAAQ,CAAE,EAA0B;;QAClC,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAE,CAAA;QAC3B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,CAAE,EAA0B;;QAChC,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAE,CAAA;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,WAAW,CAAE,EAA0B;;QACrC,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,WAAW,EAAE,EAAE,CAAE,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,cAAc,CAAE,EAA0B;;QACxC,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAE,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AArED,2BAqEC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AccessOptions } from '../types/access';
|
|
2
|
+
import { Socket } from 'socket.io-client';
|
|
3
|
+
import AccessManager from './Access';
|
|
4
|
+
export type RealtimeConnectOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* A fresh access token for each connection attempt.
|
|
7
|
+
*
|
|
8
|
+
* An app holds tokens it was given rather than credentials it can mint, so
|
|
9
|
+
* this is usually "ask my backend for a new tracking session". Omitted, the
|
|
10
|
+
* token this client was constructed with is used on every attempt, which is
|
|
11
|
+
* correct only for a process that rotates it in place.
|
|
12
|
+
*/
|
|
13
|
+
getToken?: () => string | Promise<string>;
|
|
14
|
+
};
|
|
15
|
+
export default abstract class RealtimeSocket extends AccessManager {
|
|
16
|
+
protected nsp?: Socket;
|
|
17
|
+
protected iosHost: string;
|
|
18
|
+
protected id?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Every room this socket asked to be in, by the token that got it there.
|
|
21
|
+
*
|
|
22
|
+
* Kept so a reconnect can restore them. A JRT outlives an ordinary blip, so
|
|
23
|
+
* replaying it is right; when one has expired the rejoin fails and
|
|
24
|
+
* `onRejoinError` is how the app learns to ask for a new session rather than
|
|
25
|
+
* sitting on a silent connection.
|
|
26
|
+
*/
|
|
27
|
+
private rooms;
|
|
28
|
+
private rejoinError?;
|
|
29
|
+
constructor(access: AccessOptions);
|
|
30
|
+
/** The `utype` this client connects as. Must match the JRT's `role`. */
|
|
31
|
+
protected abstract get utype(): string;
|
|
32
|
+
protected open(id: string, options?: RealtimeConnectOptions): Promise<void>;
|
|
33
|
+
/** Re-enter every room this socket was in before the connection dropped. */
|
|
34
|
+
private restore;
|
|
35
|
+
/**
|
|
36
|
+
* Enter an order room with a Join Room Token from
|
|
37
|
+
* `GET /v1/tracking/:reference?role=…`.
|
|
38
|
+
*/
|
|
39
|
+
join(jrtoken: string): Promise<boolean>;
|
|
40
|
+
/** Stop replaying a room — the order is closed, or the app navigated away. */
|
|
41
|
+
leave(jrtoken: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* A room could not be re-entered after a reconnect.
|
|
44
|
+
*
|
|
45
|
+
* Almost always an expired JRT. The app's answer is to ask its backend for a
|
|
46
|
+
* fresh tracking session and `join` again — and, since it is reconnecting,
|
|
47
|
+
* to `replay` from the `since` that came with it.
|
|
48
|
+
*/
|
|
49
|
+
onRejoinError(fn: (error: Error) => void): this;
|
|
50
|
+
/** Fires on every reconnect, which is where a client should replay its gap. */
|
|
51
|
+
onReconnect(fn: () => void): this;
|
|
52
|
+
disconnect(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Ask for everything a room emitted while this socket was away.
|
|
55
|
+
*
|
|
56
|
+
* `since` is the timestamp the tracking session came back with, or that of
|
|
57
|
+
* the last event actually seen. Reconnecting without it leaves a hole
|
|
58
|
+
* exactly as long as the outage.
|
|
59
|
+
*/
|
|
60
|
+
replay(reference: string, since: number): this;
|
|
61
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const socket_io_client_1 = __importDefault(require("socket.io-client"));
|
|
7
|
+
const Access_1 = __importDefault(require("./Access"));
|
|
8
|
+
const baseUrl_1 = require("../baseUrl");
|
|
9
|
+
class RealtimeSocket extends Access_1.default {
|
|
10
|
+
constructor(access) {
|
|
11
|
+
var _a;
|
|
12
|
+
super(access, 'API');
|
|
13
|
+
/**
|
|
14
|
+
* Every room this socket asked to be in, by the token that got it there.
|
|
15
|
+
*
|
|
16
|
+
* Kept so a reconnect can restore them. A JRT outlives an ordinary blip, so
|
|
17
|
+
* replaying it is right; when one has expired the rejoin fails and
|
|
18
|
+
* `onRejoinError` is how the app learns to ask for a new session rather than
|
|
19
|
+
* sitting on a silent connection.
|
|
20
|
+
*/
|
|
21
|
+
this.rooms = new Set();
|
|
22
|
+
// Socket.io is served by the same de.arch API server, so an explicit
|
|
23
|
+
// origin governs the socket exactly as it governs the requests.
|
|
24
|
+
this.iosHost = ((_a = access.baseUrl) === null || _a === void 0 ? void 0 : _a.replace(/\/+$/, ''))
|
|
25
|
+
|| (0, baseUrl_1.baseURL)('API', access.env || 'dev', access.devHostname);
|
|
26
|
+
}
|
|
27
|
+
open(id, options = {}) {
|
|
28
|
+
this.id = id;
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const credentials = async () => ({
|
|
31
|
+
utype: this.utype,
|
|
32
|
+
id,
|
|
33
|
+
remoteOrigin: (globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) ? globalThis.origin : this.remoteOrigin,
|
|
34
|
+
accessToken: options.getToken ? await options.getToken() : this.accessToken
|
|
35
|
+
});
|
|
36
|
+
this.nsp = (0, socket_io_client_1.default)(this.iosHost, {
|
|
37
|
+
// The function form — re-evaluated before every attempt, which is the
|
|
38
|
+
// whole point. The object form is read once, at construction.
|
|
39
|
+
auth: (cb) => {
|
|
40
|
+
credentials()
|
|
41
|
+
.then(cb)
|
|
42
|
+
// A token the app could not fetch is still an attempt: let De.
|
|
43
|
+
// refuse it and surface a connect_error, rather than hanging.
|
|
44
|
+
.catch(() => cb({ utype: this.utype, id }));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
this.nsp.on('connect', () => {
|
|
48
|
+
this.restore();
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
51
|
+
this.nsp.on('connect_error', reject);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Re-enter every room this socket was in before the connection dropped. */
|
|
55
|
+
restore() {
|
|
56
|
+
var _a;
|
|
57
|
+
for (const jrtoken of this.rooms)
|
|
58
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.emit('JOIN', jrtoken, (errmess) => {
|
|
59
|
+
var _a;
|
|
60
|
+
if (!errmess)
|
|
61
|
+
return;
|
|
62
|
+
this.rooms.delete(jrtoken);
|
|
63
|
+
(_a = this.rejoinError) === null || _a === void 0 ? void 0 : _a.call(this, new Error(errmess));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Enter an order room with a Join Room Token from
|
|
68
|
+
* `GET /v1/tracking/:reference?role=…`.
|
|
69
|
+
*/
|
|
70
|
+
join(jrtoken) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
var _a;
|
|
73
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.emit('JOIN', jrtoken, (errmess) => {
|
|
74
|
+
if (errmess)
|
|
75
|
+
return reject(new Error(errmess));
|
|
76
|
+
this.rooms.add(jrtoken);
|
|
77
|
+
resolve(true);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** Stop replaying a room — the order is closed, or the app navigated away. */
|
|
82
|
+
leave(jrtoken) {
|
|
83
|
+
this.rooms.delete(jrtoken);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A room could not be re-entered after a reconnect.
|
|
87
|
+
*
|
|
88
|
+
* Almost always an expired JRT. The app's answer is to ask its backend for a
|
|
89
|
+
* fresh tracking session and `join` again — and, since it is reconnecting,
|
|
90
|
+
* to `replay` from the `since` that came with it.
|
|
91
|
+
*/
|
|
92
|
+
onRejoinError(fn) {
|
|
93
|
+
this.rejoinError = fn;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
/** Fires on every reconnect, which is where a client should replay its gap. */
|
|
97
|
+
onReconnect(fn) {
|
|
98
|
+
var _a;
|
|
99
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.io.on('reconnect', fn);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
disconnect() {
|
|
103
|
+
var _a;
|
|
104
|
+
this.rooms.clear();
|
|
105
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Ask for everything a room emitted while this socket was away.
|
|
110
|
+
*
|
|
111
|
+
* `since` is the timestamp the tracking session came back with, or that of
|
|
112
|
+
* the last event actually seen. Reconnecting without it leaves a hole
|
|
113
|
+
* exactly as long as the outage.
|
|
114
|
+
*/
|
|
115
|
+
replay(reference, since) {
|
|
116
|
+
var _a;
|
|
117
|
+
(_a = this.nsp) === null || _a === void 0 ? void 0 : _a.emit('REPLAY', { room: `order:${reference}`, since });
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.default = RealtimeSocket;
|
|
122
|
+
//# sourceMappingURL=realtime-socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime-socket.js","sourceRoot":"","sources":["../../src/allend/realtime-socket.ts"],"names":[],"mappings":";;;;;AAGA,wEAA6C;AAC7C,sDAAoC;AACpC,wCAAoC;AAwCpC,MAA8B,cAAe,SAAQ,gBAAa;IAgBhE,YAAa,MAAqB;;QAChC,KAAK,CAAE,MAAM,EAAE,KAAK,CAAE,CAAA;QAZxB;;;;;;;WAOG;QACK,UAAK,GAAG,IAAI,GAAG,EAAU,CAAA;QAM/B,qEAAqE;QACrE,gEAAgE;QAChE,IAAI,CAAC,OAAO,GAAG,CAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,OAAO,CAAE,MAAM,EAAE,EAAE,CAAE;eACjC,IAAA,iBAAO,EAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,KAAK,EAAE,MAAM,CAAC,WAAW,CAAE,CAAA;IAC7E,CAAC;IAKS,IAAI,CAAE,EAAU,EAAE,UAAkC,EAAE;QAC9D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QAEZ,OAAO,IAAI,OAAO,CAAE,CAAE,OAAO,EAAE,MAAM,EAAG,EAAE;YACxC,MAAM,WAAW,GAAG,KAAK,IAAoC,EAAE,CAAC,CAAC;gBAC/D,KAAK,EAAS,IAAI,CAAC,KAAK;gBACxB,EAAE;gBACF,YAAY,EAAE,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,EAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,YAAsB;gBAClF,WAAW,EAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAqB;aACvF,CAAC,CAAA;YAEF,IAAI,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,IAAI,OAAO;oBAAG,OAAO,MAAM,CAAE,IAAI,KAAK,CAAE,OAAO,CAAE,CAAE,CAAA;gBAEnD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAE,OAAO,CAAE,CAAA;gBACzB,OAAO,CAAE,IAAI,CAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,8EAA8E;IAC9E,KAAK,CAAE,OAAe;QACpB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAE,OAAO,CAAE,CAAA;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,aAAa,CAAE,EAA4B;QACzC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,+EAA+E;IAC/E,WAAW,CAAE,EAAc;;QACzB,MAAA,IAAI,CAAC,GAAG,0CAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CAAE,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,UAAU;;QACR,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAClB,MAAA,IAAI,CAAC,GAAG,0CAAE,UAAU,EAAE,CAAA;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAE,SAAiB,EAAE,KAAa;;QACtC,MAAA,IAAI,CAAC,GAAG,0CAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA7HD,iCA6HC"}
|
package/dist/backend/Auth.d.ts
CHANGED
|
@@ -14,7 +14,20 @@ export type AuthConfig = {
|
|
|
14
14
|
* credentials are. Omit it for pure machine-to-machine access.
|
|
15
15
|
*/
|
|
16
16
|
uid?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Rotate the token ahead of expiry.
|
|
19
|
+
*
|
|
20
|
+
* Off by default, which is the trap: a long-lived process that forgets it
|
|
21
|
+
* works perfectly until the first expiry and then fails every call until
|
|
22
|
+
* it is restarted. Anything holding a token for longer than one request
|
|
23
|
+
* wants this on.
|
|
24
|
+
*/
|
|
17
25
|
autorefresh?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Minutes between rotations. Defaults to 3.75 — set it below the De.
|
|
28
|
+
* deployment's `API_ACCESS_TOKEN_EXPIRY` when that is not the default 4.
|
|
29
|
+
*/
|
|
30
|
+
rotateAfterMins?: number;
|
|
18
31
|
onNewToken?: (token: string) => void;
|
|
19
32
|
/** Host to substitute for `localhost` in `dev` (Eg. a native emulator) */
|
|
20
33
|
devHostname?: string;
|
|
@@ -29,6 +42,7 @@ export default class Auth {
|
|
|
29
42
|
private remoteOrigin?;
|
|
30
43
|
private refreshTimer?;
|
|
31
44
|
private autorefresh?;
|
|
45
|
+
private rotateAfterMins;
|
|
32
46
|
private onNewToken?;
|
|
33
47
|
private baseURL;
|
|
34
48
|
private isRotating;
|
package/dist/backend/Auth.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const baseUrl_1 = require("../baseUrl");
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* When to rotate, in minutes.
|
|
6
|
+
*
|
|
7
|
+
* De.'s own default token life is four minutes, so this beats it by fifteen
|
|
8
|
+
* seconds. It is a default and not a constant because the server's life is
|
|
9
|
+
* configurable — `API_ACCESS_TOKEN_EXPIRY` — and these two numbers are
|
|
10
|
+
* otherwise free to drift apart in the direction that breaks: a deployment
|
|
11
|
+
* that shortens the token to two minutes leaves every client rotating a
|
|
12
|
+
* credential that expired ninety seconds ago, and every call in between is
|
|
13
|
+
* answered 401 with nothing to say why.
|
|
14
|
+
*/
|
|
15
|
+
const ACCESS_TOKEN_EXPIRY = 3.75;
|
|
5
16
|
class Auth {
|
|
6
17
|
constructor(config) {
|
|
7
18
|
this.isRotating = false;
|
|
@@ -22,6 +33,9 @@ class Auth {
|
|
|
22
33
|
this.version = config.version || 1;
|
|
23
34
|
this.baseURL = (0, baseUrl_1.baseURL)('API', this.env, config.devHostname);
|
|
24
35
|
this.autorefresh = config.autorefresh || false;
|
|
36
|
+
this.rotateAfterMins = config.rotateAfterMins && config.rotateAfterMins > 0
|
|
37
|
+
? config.rotateAfterMins
|
|
38
|
+
: ACCESS_TOKEN_EXPIRY;
|
|
25
39
|
this.onNewToken = config.onNewToken;
|
|
26
40
|
}
|
|
27
41
|
async request({ url, ...options }) {
|
|
@@ -57,7 +71,7 @@ class Auth {
|
|
|
57
71
|
if (!this.autorefresh)
|
|
58
72
|
return;
|
|
59
73
|
this.clearRotation();
|
|
60
|
-
this.refreshTimer = setTimeout(() => this.rotateToken(),
|
|
74
|
+
this.refreshTimer = setTimeout(() => this.rotateToken(), this.rotateAfterMins * 60 * 1000);
|
|
61
75
|
}
|
|
62
76
|
/**
|
|
63
77
|
* Clear rotation timer
|