@de./sdk 1.0.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/LICENSE +21 -0
- package/README.md +4391 -0
- package/dist/allend/Access.d.ts +15 -0
- package/dist/allend/Access.js +164 -0
- package/dist/allend/Access.js.map +1 -0
- package/dist/allend/DAuth/index.d.ts +20 -0
- package/dist/allend/DAuth/index.js +92 -0
- package/dist/allend/DAuth/index.js.map +1 -0
- package/dist/allend/DClient/Client.d.ts +10 -0
- package/dist/allend/DClient/Client.js +144 -0
- package/dist/allend/DClient/Client.js.map +1 -0
- package/dist/allend/DClient/Event.d.ts +18 -0
- package/dist/allend/DClient/Event.js +100 -0
- package/dist/allend/DClient/Event.js.map +1 -0
- package/dist/allend/DClient/Order.d.ts +49 -0
- package/dist/allend/DClient/Order.js +601 -0
- package/dist/allend/DClient/Order.js.map +1 -0
- package/dist/allend/IoTClient.d.ts +29 -0
- package/dist/allend/IoTClient.js +59 -0
- package/dist/allend/IoTClient.js.map +1 -0
- package/dist/allend/MSI/Controls.d.ts +256 -0
- package/dist/allend/MSI/Controls.js +763 -0
- package/dist/allend/MSI/Controls.js.map +1 -0
- package/dist/allend/MSI/Handles.d.ts +88 -0
- package/dist/allend/MSI/Handles.js +445 -0
- package/dist/allend/MSI/Handles.js.map +1 -0
- package/dist/allend/MSI/Plugins.d.ts +22 -0
- package/dist/allend/MSI/Plugins.js +38 -0
- package/dist/allend/MSI/Plugins.js.map +1 -0
- package/dist/allend/MSI/index.d.ts +55 -0
- package/dist/allend/MSI/index.js +155 -0
- package/dist/allend/MSI/index.js.map +1 -0
- package/dist/allend/index.d.ts +12 -0
- package/dist/allend/index.js +18 -0
- package/dist/allend/index.js.map +1 -0
- package/dist/backend/Auth.d.ts +38 -0
- package/dist/backend/Auth.js +286 -0
- package/dist/backend/Auth.js.map +1 -0
- package/dist/baseUrl.d.ts +12 -0
- package/dist/baseUrl.js +16 -0
- package/dist/baseUrl.js.map +1 -0
- package/dist/bundle.js +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/types/access.d.ts +8 -0
- package/dist/types/auth.d.ts +27 -0
- package/dist/types/index.d.ts +281 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/stream.d.ts +20 -0
- package/dist/utils/stream.js +63 -0
- package/dist/utils/stream.js.map +1 -0
- package/package.json +66 -0
- package/src/allend/Access.ts +78 -0
- package/src/allend/DAuth/index.ts +39 -0
- package/src/allend/DClient/Client.ts +76 -0
- package/src/allend/DClient/Event.ts +76 -0
- package/src/allend/DClient/Order.ts +452 -0
- package/src/allend/IoTClient.ts +68 -0
- package/src/allend/MSI/Controls.ts +760 -0
- package/src/allend/MSI/Handles.ts +387 -0
- package/src/allend/MSI/Plugins.ts +52 -0
- package/src/allend/MSI/index.ts +160 -0
- package/src/allend/index.ts +18 -0
- package/src/backend/Auth.ts +201 -0
- package/src/baseUrl.ts +13 -0
- package/src/index.ts +19 -0
- package/src/types/access.d.ts +8 -0
- package/src/types/auth.d.ts +27 -0
- package/src/types/index.d.ts +281 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/stream.ts +68 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
export type HTTPRequestOptions = {
|
|
2
|
+
url: string
|
|
3
|
+
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'
|
|
4
|
+
headers?: { [index: string]: string }
|
|
5
|
+
body?: any
|
|
6
|
+
}
|
|
7
|
+
export type HTTPResponse = {
|
|
8
|
+
error: boolean
|
|
9
|
+
message?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type LngLat = [number, number]
|
|
13
|
+
export type Coordinates = {
|
|
14
|
+
lng: number
|
|
15
|
+
lat: number
|
|
16
|
+
}
|
|
17
|
+
export type PickedLocation = {
|
|
18
|
+
point: {
|
|
19
|
+
x: number,
|
|
20
|
+
y: number
|
|
21
|
+
}
|
|
22
|
+
coordinates: Coordinates
|
|
23
|
+
}
|
|
24
|
+
export type RTLocation = Coordinates & {
|
|
25
|
+
heading?: number
|
|
26
|
+
}
|
|
27
|
+
export type ActivePosition = {
|
|
28
|
+
id: string
|
|
29
|
+
position: RTLocation
|
|
30
|
+
caption?: Caption
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configuration options for AnimatedPolyline
|
|
35
|
+
*/
|
|
36
|
+
export type AnimatedRouteNativePathType = 'dot' | 'solid'
|
|
37
|
+
export type AnimatedRouteNativeMethods = 'dot:flow'
|
|
38
|
+
| 'dot:fade'
|
|
39
|
+
| 'dot:pulse'
|
|
40
|
+
| 'dot:directional'
|
|
41
|
+
| 'solid:flow'
|
|
42
|
+
| 'solid:fade'
|
|
43
|
+
| 'solid:pulse'
|
|
44
|
+
| 'solid:directional'
|
|
45
|
+
export interface AnimatedRouteRules {
|
|
46
|
+
styles?: any;
|
|
47
|
+
speed?: number; // pixels per frame
|
|
48
|
+
fadeLength?: number; // length of fade effect in pixels
|
|
49
|
+
}
|
|
50
|
+
export interface AnimatedRoute {
|
|
51
|
+
key: number | null
|
|
52
|
+
currentOffset: number
|
|
53
|
+
rules: Required<AnimatedRouteRules>
|
|
54
|
+
startTime?: number;
|
|
55
|
+
polyline?: any
|
|
56
|
+
engine: any
|
|
57
|
+
path: Coordinates[]
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create the polyline
|
|
61
|
+
*/
|
|
62
|
+
create( pathType?: AnimatedRouteNativePathType ): void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Animation methods
|
|
66
|
+
*/
|
|
67
|
+
apply: Record<string, () => void>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Stop the current animation
|
|
71
|
+
*/
|
|
72
|
+
stop(): void;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Remove the polyline from the map and stop animation
|
|
76
|
+
*/
|
|
77
|
+
remove(): void;
|
|
78
|
+
}
|
|
79
|
+
export type AnimatedRouteOptions = AnimatedRouteNativeMethods | {
|
|
80
|
+
handler?: new (engine: Engine, path: Coordinates[], rules?: AnimatedRouteRules) => AnimatedRoute
|
|
81
|
+
method?: string
|
|
82
|
+
rules?: AnimatedRouteRules
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type Journey = {
|
|
86
|
+
routeId: string | number
|
|
87
|
+
origin?: MapWaypoint
|
|
88
|
+
destination?: MapWaypoint
|
|
89
|
+
waypoints?: MapWaypoint[]
|
|
90
|
+
options?: RouteOptions
|
|
91
|
+
}
|
|
92
|
+
export type ActiveDirection<RouteSpec> = {
|
|
93
|
+
routeId: string | number
|
|
94
|
+
profile: string
|
|
95
|
+
origin?: Coordinates
|
|
96
|
+
destination?: Coordinates
|
|
97
|
+
waypoints: Coordinates[]
|
|
98
|
+
route: RouteSpec | null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type RouteID = string | number
|
|
102
|
+
export type RoutesFitBoundsOptions = {
|
|
103
|
+
includes?: RouteID[]
|
|
104
|
+
margin?: number
|
|
105
|
+
}
|
|
106
|
+
export type RouteOptions = {
|
|
107
|
+
id?: string | number
|
|
108
|
+
mode?: 'default' | 'navigation'
|
|
109
|
+
profile?: 'driving-traffic' | 'driving' | 'cycling' | 'biking' | 'walking' | 'transit'
|
|
110
|
+
unit?: 'metric' | 'imperial',
|
|
111
|
+
preference?: 'TRAFFIC_AWARE' | 'TRAFFIC_UNAWARE'
|
|
112
|
+
pointless?: boolean
|
|
113
|
+
styles?: any
|
|
114
|
+
animation?: AnimatedRouteOptions
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type SearchPlace = {
|
|
118
|
+
name: string
|
|
119
|
+
location: Coordinates,
|
|
120
|
+
address: string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type Waypoint = {
|
|
124
|
+
no: number
|
|
125
|
+
type: 'pickup' | 'dropoff'
|
|
126
|
+
description: string
|
|
127
|
+
coordinates: Coordinates
|
|
128
|
+
address?: string
|
|
129
|
+
contact: {
|
|
130
|
+
type: string
|
|
131
|
+
reference: string
|
|
132
|
+
phone?: string
|
|
133
|
+
email?: string
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export type WaypointIndex = 'origin' | 'destination' | number
|
|
137
|
+
export type WaypointOptions = {
|
|
138
|
+
no?: number
|
|
139
|
+
type?: 'pickup' | 'dropoff'
|
|
140
|
+
description?: string
|
|
141
|
+
coordinates?: Coordinates
|
|
142
|
+
address?: string
|
|
143
|
+
'contact.type'?: string
|
|
144
|
+
'contact.reference'?: string
|
|
145
|
+
'contact.phone'?: string
|
|
146
|
+
'contact.email'?: string
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type Package = {
|
|
150
|
+
waypointNo: number
|
|
151
|
+
careLevel: number
|
|
152
|
+
category: string
|
|
153
|
+
weight: number
|
|
154
|
+
note?: string
|
|
155
|
+
}
|
|
156
|
+
export type PackageOptions = {
|
|
157
|
+
waypointNo?: number
|
|
158
|
+
careLevel?: number
|
|
159
|
+
category?: string
|
|
160
|
+
weight?: number
|
|
161
|
+
note?: string
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type PaymentMode = 'cash' | 'card' | 'momo' | 'wigo'
|
|
165
|
+
export type OrderService = {
|
|
166
|
+
fees: {
|
|
167
|
+
total: {
|
|
168
|
+
amount: number
|
|
169
|
+
currency: string
|
|
170
|
+
},
|
|
171
|
+
tax: number
|
|
172
|
+
discount: number
|
|
173
|
+
}
|
|
174
|
+
payment: {
|
|
175
|
+
mode: PaymentMode
|
|
176
|
+
paid: boolean
|
|
177
|
+
}
|
|
178
|
+
xpress: string
|
|
179
|
+
}
|
|
180
|
+
export type OrderServiceOptions = {
|
|
181
|
+
'fees.total.amount'?: number
|
|
182
|
+
'fees.total.currency'?: string
|
|
183
|
+
'fees.tax'?: string
|
|
184
|
+
'fees.discount'?: string
|
|
185
|
+
'payment.mode'?: PaymentMode
|
|
186
|
+
'payment.option'?: string
|
|
187
|
+
'payment.paid'?: boolean
|
|
188
|
+
xpress?: string
|
|
189
|
+
}
|
|
190
|
+
export type OrderOperator = {}
|
|
191
|
+
export type OrderStage = {
|
|
192
|
+
current: string
|
|
193
|
+
status: string
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type Message = {
|
|
197
|
+
type: 'text' | 'location' | 'media'
|
|
198
|
+
sender: string
|
|
199
|
+
content: string
|
|
200
|
+
timestamp: string
|
|
201
|
+
}
|
|
202
|
+
export type Caption = {
|
|
203
|
+
duration?: number
|
|
204
|
+
unit?: string
|
|
205
|
+
label?: string
|
|
206
|
+
}
|
|
207
|
+
export type Peer = {
|
|
208
|
+
utype: string
|
|
209
|
+
id: string
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export type MapOptions = {
|
|
213
|
+
element: string
|
|
214
|
+
accessToken: string
|
|
215
|
+
version?: number
|
|
216
|
+
env?: 'dev' | 'prod'
|
|
217
|
+
}
|
|
218
|
+
export type MapLayerStyle = 'streets' | 'outdoors' | 'light' | 'dark' | 'satellite'
|
|
219
|
+
export type MapWaypoint = {
|
|
220
|
+
index?: number
|
|
221
|
+
coords: Coordinates
|
|
222
|
+
caption?: Caption
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export type Entity = {
|
|
226
|
+
id: string
|
|
227
|
+
status: 'ACTIVE' | 'BUSY'
|
|
228
|
+
grade: '1H' | '2H' | '3H'
|
|
229
|
+
currentLocation: RTLocation
|
|
230
|
+
static?: boolean
|
|
231
|
+
type: 'moto' | 'car' | 'bike' | 'truck' | 'plane' | 'ship' | 'restaurant' | 'hotel' | 'store' | 'office' | 'warehouse'
|
|
232
|
+
}
|
|
233
|
+
export type EntitySpecs = {
|
|
234
|
+
id: string
|
|
235
|
+
status: 'ACTIVE' | 'BUSY'
|
|
236
|
+
grade: '1H' | '2H' | '3H'
|
|
237
|
+
currentLocation: RTLocation
|
|
238
|
+
static?: boolean
|
|
239
|
+
type: 'moto' | 'car' | 'bike' | 'truck' | 'plane' | 'ship' | 'restaurant' | 'hotel' | 'store' | 'office' | 'warehouse'
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface UserLocationOptions {
|
|
243
|
+
// Base point styling options
|
|
244
|
+
borderRadius?: number
|
|
245
|
+
borderColor?: string
|
|
246
|
+
borderOpacity?: number
|
|
247
|
+
dotColor?: string
|
|
248
|
+
showInnerDot?: boolean
|
|
249
|
+
noRing?: boolean
|
|
250
|
+
|
|
251
|
+
// User location specific options
|
|
252
|
+
showDirectionArrow?: boolean
|
|
253
|
+
arrowColor?: string
|
|
254
|
+
arrowSize?: number
|
|
255
|
+
pulseAnimation?: boolean
|
|
256
|
+
accuracyCircle?: boolean
|
|
257
|
+
accuracyColor?: string
|
|
258
|
+
accuracyOpacity?: number
|
|
259
|
+
|
|
260
|
+
// Callbacks
|
|
261
|
+
onLocationUpdate?: ( location: RTLocation ) => void
|
|
262
|
+
onLocationError?: ( error: GeolocationPositionError ) => void
|
|
263
|
+
}
|
|
264
|
+
export type DragPickOptions = {
|
|
265
|
+
snapToRoad?: boolean
|
|
266
|
+
pinPoints?: boolean
|
|
267
|
+
pointOptions?: CustomPointOptions
|
|
268
|
+
}
|
|
269
|
+
export type DragPickContentType = 'duration' | 'distance' | 'preloader'
|
|
270
|
+
export type DragPickContent = {
|
|
271
|
+
time?: number
|
|
272
|
+
unit?: 'min' | 'sec' | 'hr' | 'km' | 'mi' | 'm'
|
|
273
|
+
distance?: number
|
|
274
|
+
preloader?: boolean
|
|
275
|
+
}
|
|
276
|
+
export type DragPickEvent = 'dragstart' | 'dragend' | 'zoom_changed' | 'idle'
|
|
277
|
+
export interface DragPickInterface {
|
|
278
|
+
enable( origin?: Coordinates ): void
|
|
279
|
+
disable(): void
|
|
280
|
+
content( type: DragPickContentType, content: DragPickContent ): void
|
|
281
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
var stream_1 = __importDefault(require("./stream"));
|
|
7
|
+
exports.default = { Stream: stream_1.default };
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;AACA,oDAA6B;AAE7B,kBAAe,EAAE,MAAM,kBAAA,EAAE,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type StreamDataListener = (data: string) => void;
|
|
2
|
+
export default class Stream {
|
|
3
|
+
private _STALED;
|
|
4
|
+
private _CLOSED;
|
|
5
|
+
private _fns;
|
|
6
|
+
private _exitFn;
|
|
7
|
+
private _errorFn;
|
|
8
|
+
private _downStream?;
|
|
9
|
+
private _upStream?;
|
|
10
|
+
private _upstream;
|
|
11
|
+
private _backpressure;
|
|
12
|
+
sync(data: any): void;
|
|
13
|
+
on(_event: 'data', fn: StreamDataListener): this;
|
|
14
|
+
pipe(stream: Stream): this;
|
|
15
|
+
error(error: Error | string): this;
|
|
16
|
+
close(): void;
|
|
17
|
+
isActive(): boolean;
|
|
18
|
+
onerror(fn: (error: Error) => void): this;
|
|
19
|
+
onclose(fn: () => void): this;
|
|
20
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var Stream = /** @class */ (function () {
|
|
4
|
+
function Stream() {
|
|
5
|
+
this._STALED = false;
|
|
6
|
+
this._CLOSED = false;
|
|
7
|
+
this._fns = [];
|
|
8
|
+
this._exitFn = (function () { });
|
|
9
|
+
this._errorFn = (function (error) { });
|
|
10
|
+
}
|
|
11
|
+
Stream.prototype._upstream = function (stream) {
|
|
12
|
+
this._upStream = stream;
|
|
13
|
+
return this;
|
|
14
|
+
};
|
|
15
|
+
Stream.prototype._backpressure = function (data) {
|
|
16
|
+
!this._CLOSED && this._fns.map(function (fn) { return fn(data); });
|
|
17
|
+
};
|
|
18
|
+
Stream.prototype.sync = function (data) {
|
|
19
|
+
var _a;
|
|
20
|
+
!this._CLOSED && ((_a = this._downStream) === null || _a === void 0 ? void 0 : _a._backpressure(data));
|
|
21
|
+
};
|
|
22
|
+
Stream.prototype.on = function (_event, fn) {
|
|
23
|
+
if (this._CLOSED)
|
|
24
|
+
throw new Error('Stream closed');
|
|
25
|
+
this._fns.push(fn);
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
Stream.prototype.pipe = function (stream) {
|
|
29
|
+
stream._upstream(this);
|
|
30
|
+
this._downStream = stream;
|
|
31
|
+
return this;
|
|
32
|
+
};
|
|
33
|
+
Stream.prototype.error = function (error) {
|
|
34
|
+
var _a;
|
|
35
|
+
// Throw error to self
|
|
36
|
+
this._errorFn(typeof error == 'string' ? new Error(error) : error);
|
|
37
|
+
// Throw error to downstream pipe
|
|
38
|
+
(_a = this._downStream) === null || _a === void 0 ? void 0 : _a.error(error);
|
|
39
|
+
return this;
|
|
40
|
+
};
|
|
41
|
+
Stream.prototype.close = function () {
|
|
42
|
+
var _a;
|
|
43
|
+
if (this._CLOSED)
|
|
44
|
+
return;
|
|
45
|
+
this._CLOSED = true;
|
|
46
|
+
this._fns = [];
|
|
47
|
+
this._exitFn();
|
|
48
|
+
(_a = this._downStream) === null || _a === void 0 ? void 0 : _a.close(); // Close down streams
|
|
49
|
+
// this._upStream?.close() // Close up streams: Recursive loop call effect
|
|
50
|
+
};
|
|
51
|
+
Stream.prototype.isActive = function () { return !this._CLOSED; };
|
|
52
|
+
Stream.prototype.onerror = function (fn) {
|
|
53
|
+
this._errorFn = fn;
|
|
54
|
+
return this;
|
|
55
|
+
};
|
|
56
|
+
Stream.prototype.onclose = function (fn) {
|
|
57
|
+
this._exitFn = fn;
|
|
58
|
+
return this;
|
|
59
|
+
};
|
|
60
|
+
return Stream;
|
|
61
|
+
}());
|
|
62
|
+
exports.default = Stream;
|
|
63
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":";;AAGA;IAAA;QACU,YAAO,GAAY,KAAK,CAAA;QACxB,YAAO,GAAY,KAAK,CAAA;QACxB,SAAI,GAAyB,EAAE,CAAA;QAC/B,YAAO,GAAG,CAAC,cAAO,CAAC,CAAC,CAAA;QACpB,aAAQ,GAAG,CAAC,UAAE,KAAY,IAAO,CAAC,CAAC,CAAA;IA2D7C,CAAC;IAvDS,0BAAS,GAAjB,UAAmB,MAAc;QAC/B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC;IACO,8BAAa,GAArB,UAAuB,IAAS;QAC9B,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAE,UAAA,EAAE,IAAI,OAAA,EAAE,CAAE,IAAI,CAAE,EAAV,CAAU,CAAE,CAAA;IACpD,CAAC;IAED,qBAAI,GAAJ,UAAM,IAAS;;QACb,CAAC,IAAI,CAAC,OAAO,KAAI,MAAA,IAAI,CAAC,WAAW,0CAAE,aAAa,CAAE,IAAI,CAAE,CAAA,CAAA;IAC1D,CAAC;IAED,mBAAE,GAAF,UAAI,MAAc,EAAE,EAAsB;QACxC,IAAI,IAAI,CAAC,OAAO;YAAG,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;QAEnD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAE,EAAE,CAAE,CAAA;QACpB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,qBAAI,GAAJ,UAAM,MAAc;QAClB,MAAM,CAAC,SAAS,CAAE,IAAI,CAAE,CAAA;QACxB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAA;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sBAAK,GAAL,UAAO,KAAqB;;QAC1B,sBAAsB;QACtB,IAAI,CAAC,QAAQ,CAAE,OAAO,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAE,KAAK,CAAE,CAAC,CAAC,CAAE,KAAK,CAAE,CAAA;QACvE,iCAAiC;QACjC,MAAA,IAAI,CAAC,WAAW,0CAAE,KAAK,CAAE,KAAK,CAAE,CAAA;QAEhC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sBAAK,GAAL;;QACE,IAAI,IAAI,CAAC,OAAO;YAAG,OAAM;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAEnB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;QACd,IAAI,CAAC,OAAO,EAAE,CAAA;QAEd,MAAA,IAAI,CAAC,WAAW,0CAAE,KAAK,EAAE,CAAA,CAAC,qBAAqB;QAC/C,0EAA0E;IAC5E,CAAC;IAED,yBAAQ,GAAR,cAAY,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA,CAAC,CAAC;IAElC,wBAAO,GAAP,UAAS,EAA4B;QACnC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAA;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,wBAAO,GAAP,UAAS,EAAc;QACrB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IACH,aAAC;AAAD,CAAC,AAhED,IAgEC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@de./sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Complete SDK pack for MSI (Map Service Interface), IoTClient and DClient services",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/",
|
|
9
|
+
"src/",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./types": {
|
|
19
|
+
"types": "./dist/types/index.d.ts",
|
|
20
|
+
"default": "./dist/types/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"author": "SCOREX Corporation",
|
|
24
|
+
"private": false,
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build:tsc": "rimraf ./dist && tsc",
|
|
27
|
+
"build:webpack": "WEBPACK_ENV=build webpack",
|
|
28
|
+
"build:copy-types": "mkdir -p dist/types && cp -r src/types/* dist/types/",
|
|
29
|
+
"compile": "yarn build:tsc && yarn build:webpack && yarn build:copy-types",
|
|
30
|
+
"prepack": "yarn run compile",
|
|
31
|
+
"test": "Echo 'Error: No test specified' && exit 1",
|
|
32
|
+
"test:auth": "yarn build:tsc && jest test/auth.test.js",
|
|
33
|
+
"test:client": "yarn build:tsc && jest test/client.test.js",
|
|
34
|
+
"test:order": "yarn build:tsc && jest test/order.test.js",
|
|
35
|
+
"test:event": "yarn build:tsc && jest test/event.test.js"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"events": "^3.3.0",
|
|
39
|
+
"iframe.io": "^1.1.0",
|
|
40
|
+
"node-fetch": "2.6.1",
|
|
41
|
+
"socket.io-client": "^4.6.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/jest": "^29.5.0",
|
|
45
|
+
"@types/node-fetch": "^2.6.3",
|
|
46
|
+
"expect.js": "^0.3.1",
|
|
47
|
+
"jest": "^29.7.0",
|
|
48
|
+
"rimraf": "^4.4.0",
|
|
49
|
+
"ts-jest": "^29.0.5",
|
|
50
|
+
"ts-loader": "^9.4.2",
|
|
51
|
+
"typescript": "^5.0.2",
|
|
52
|
+
"webpack": "^5.77.0",
|
|
53
|
+
"webpack-cli": "^5.0.1"
|
|
54
|
+
},
|
|
55
|
+
"directories": {
|
|
56
|
+
"dist": "dist/",
|
|
57
|
+
"docs": "docs/",
|
|
58
|
+
"test": "test/"
|
|
59
|
+
},
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git://github.com/de-dot/de.sdk"
|
|
64
|
+
},
|
|
65
|
+
"keywords": []
|
|
66
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { AccessOptions } from '../types/access'
|
|
2
|
+
import type { HTTPRequestOptions } from '../types'
|
|
3
|
+
import { API_SERVER_BASEURL, ASI_SERVER_BASEURL } from '../baseUrl'
|
|
4
|
+
|
|
5
|
+
type AccessType = 'API' | 'ASI'
|
|
6
|
+
|
|
7
|
+
const USER_ACCOUNT_SERVICE = 'De.API'
|
|
8
|
+
|
|
9
|
+
export default class AccessManager {
|
|
10
|
+
private atype: AccessType
|
|
11
|
+
private version: number
|
|
12
|
+
private platform: AccessOptions['platform']
|
|
13
|
+
private baseURL: string
|
|
14
|
+
protected accessToken?: string
|
|
15
|
+
protected remoteOrigin?: string
|
|
16
|
+
|
|
17
|
+
constructor( options: AccessOptions, atype: AccessType ){
|
|
18
|
+
if( !options ) throw new Error('Undefined Access Configuration')
|
|
19
|
+
if( !options.context ) throw new Error('Undefined Context Reference. Check https://doc.dedot.io/sdk/auth')
|
|
20
|
+
if( !options.accessToken ) throw new Error('Undefined Access Token. Check https://doc.dedot.io/sdk/auth')
|
|
21
|
+
|
|
22
|
+
this.atype = atype
|
|
23
|
+
this.version = options.version || 1
|
|
24
|
+
this.platform = options.platform || 'proxy'
|
|
25
|
+
this.accessToken = options.accessToken
|
|
26
|
+
this.remoteOrigin = options.remoteOrigin
|
|
27
|
+
this.baseURL = this.atype === 'ASI'
|
|
28
|
+
? ASI_SERVER_BASEURL[ options.env || 'dev' ]
|
|
29
|
+
: API_SERVER_BASEURL[ options.env || 'dev' ]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async request<Response>({ url, ...options }: HTTPRequestOptions ): Promise<Response> {
|
|
33
|
+
const rawOptions: any = {
|
|
34
|
+
method: 'GET',
|
|
35
|
+
headers: {
|
|
36
|
+
/**
|
|
37
|
+
* Default User agent for SDK request calls
|
|
38
|
+
*
|
|
39
|
+
* NOTE: Later replace by latest SDK version
|
|
40
|
+
*/
|
|
41
|
+
origin: this.remoteOrigin,
|
|
42
|
+
'de-user-agent': `De.${this.platform}/${this.version}.0`
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if( this.atype === 'ASI' )
|
|
47
|
+
rawOptions.headers['de-auth-service'] = USER_ACCOUNT_SERVICE
|
|
48
|
+
|
|
49
|
+
if( this.accessToken )
|
|
50
|
+
rawOptions.headers.authorization = `Bearer ${this.accessToken}`
|
|
51
|
+
|
|
52
|
+
if( options.body ){
|
|
53
|
+
rawOptions.headers['content-type'] = 'application/json'
|
|
54
|
+
if( typeof options.body === 'object' )
|
|
55
|
+
options.body = JSON.stringify( options.body )
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if( typeof options.headers == 'object' )
|
|
59
|
+
options.headers = {
|
|
60
|
+
...options.headers,
|
|
61
|
+
...rawOptions.headers
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
options = { ...rawOptions, ...options }
|
|
65
|
+
|
|
66
|
+
url = `${this.baseURL}/v${this.version}/${url.replace(/^\//, '')}`
|
|
67
|
+
|
|
68
|
+
// Support fetch for in both node & browser environment
|
|
69
|
+
let fetch = globalThis?.window && globalThis?.fetch
|
|
70
|
+
if( !fetch )
|
|
71
|
+
fetch = ( await import('node-fetch') ).default as any
|
|
72
|
+
|
|
73
|
+
// console.log( options )
|
|
74
|
+
return await ( await fetch( url, options ) ).json() as Response
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setToken( token: string ): void { this.accessToken = token }
|
|
78
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { HTTPRequestOptions, HTTPResponse } from '../../types'
|
|
2
|
+
import type { AccessOptions } from '../../types/access'
|
|
3
|
+
import AccessManager from '../Access'
|
|
4
|
+
|
|
5
|
+
type SigninBody = {
|
|
6
|
+
type?: 'CUSTOMER' | 'VENDOR' | 'ADMIN',
|
|
7
|
+
phone: string,
|
|
8
|
+
device?: string, // JSON string
|
|
9
|
+
country?: string // ISO 3166-1 alpha-2
|
|
10
|
+
}
|
|
11
|
+
type SigninResponse = HTTPResponse & {
|
|
12
|
+
token: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default class DAuth extends AccessManager {
|
|
16
|
+
constructor( access: AccessOptions ){
|
|
17
|
+
super( access, 'ASI' )
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Signin
|
|
22
|
+
*/
|
|
23
|
+
async signin( body: SigninBody ): Promise<SigninResponse> {
|
|
24
|
+
if( !body.phone )
|
|
25
|
+
throw new Error('<phone> argument required')
|
|
26
|
+
|
|
27
|
+
const
|
|
28
|
+
options: HTTPRequestOptions = {
|
|
29
|
+
url: '/auth/signin',
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body
|
|
32
|
+
},
|
|
33
|
+
response = await this.request<SigninResponse>( options )
|
|
34
|
+
if( response.error ) throw new Error( response.message )
|
|
35
|
+
|
|
36
|
+
return response
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AccessOptions } from '../../types/access'
|
|
2
|
+
import type { HTTPRequestOptions, RTLocation, OrderService, HTTPResponse, Entity } from '../../types'
|
|
3
|
+
import AccessManager from '../Access'
|
|
4
|
+
|
|
5
|
+
type OrderServiceResponse = HTTPResponse & {
|
|
6
|
+
orders: OrderService[]
|
|
7
|
+
}
|
|
8
|
+
type NearbyResponse = HTTPResponse & {
|
|
9
|
+
nearby: Entity[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default class Client extends AccessManager {
|
|
13
|
+
private clientId: string
|
|
14
|
+
|
|
15
|
+
constructor( clientId: string, access: AccessOptions ){
|
|
16
|
+
if( !clientId )
|
|
17
|
+
throw new Error('Undefined <clientId>')
|
|
18
|
+
|
|
19
|
+
// Instanciate access
|
|
20
|
+
super( access, 'API' )
|
|
21
|
+
// ID/reference of the client on this session
|
|
22
|
+
this.clientId = clientId
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async fetchActiveOrders(){
|
|
26
|
+
if( !this.accessToken )
|
|
27
|
+
throw new Error('Authentication required')
|
|
28
|
+
|
|
29
|
+
const
|
|
30
|
+
options: HTTPRequestOptions = {
|
|
31
|
+
url: `/client/${this.clientId}/orders/actives`,
|
|
32
|
+
method: 'GET'
|
|
33
|
+
},
|
|
34
|
+
{ error, message, orders } = await this.request<OrderServiceResponse>( options )
|
|
35
|
+
if( error ) throw new Error( message )
|
|
36
|
+
|
|
37
|
+
return orders
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async fetchOrderHistory(){
|
|
41
|
+
if( !this.accessToken )
|
|
42
|
+
throw new Error('Authentication required')
|
|
43
|
+
|
|
44
|
+
const
|
|
45
|
+
options: HTTPRequestOptions = {
|
|
46
|
+
url: `/client/${this.clientId}/orders/history`,
|
|
47
|
+
method: 'GET'
|
|
48
|
+
},
|
|
49
|
+
{ error, message, orders } = await this.request<OrderServiceResponse>( options )
|
|
50
|
+
if( error ) throw new Error( message )
|
|
51
|
+
|
|
52
|
+
return orders
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async nearby( location: RTLocation ){
|
|
56
|
+
if( !this.accessToken )
|
|
57
|
+
throw new Error('Authentication required')
|
|
58
|
+
|
|
59
|
+
if( !location )
|
|
60
|
+
throw new Error('Undefined epicenter location')
|
|
61
|
+
|
|
62
|
+
if( !location.lng || !location.lat )
|
|
63
|
+
throw new Error('Invalid location coordinates')
|
|
64
|
+
|
|
65
|
+
const
|
|
66
|
+
options: HTTPRequestOptions = {
|
|
67
|
+
url: `/client/${this.clientId}/nearby`,
|
|
68
|
+
method: 'POST',
|
|
69
|
+
body: location
|
|
70
|
+
},
|
|
71
|
+
{ error, message, nearby } = await this.request<NearbyResponse>( options )
|
|
72
|
+
if( error ) throw new Error( message )
|
|
73
|
+
|
|
74
|
+
return nearby
|
|
75
|
+
}
|
|
76
|
+
}
|