@de./sdk-rn 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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/allend/Access.d.ts +12 -0
  4. package/dist/allend/Access.d.ts.map +1 -0
  5. package/dist/allend/Access.js +43 -0
  6. package/dist/allend/Access.js.map +1 -0
  7. package/dist/allend/DClient/Client.d.ts +11 -0
  8. package/dist/allend/DClient/Client.d.ts.map +1 -0
  9. package/dist/allend/DClient/Client.js +50 -0
  10. package/dist/allend/DClient/Client.js.map +1 -0
  11. package/dist/allend/DClient/Event.d.ts +19 -0
  12. package/dist/allend/DClient/Event.d.ts.map +1 -0
  13. package/dist/allend/DClient/Event.js +74 -0
  14. package/dist/allend/DClient/Event.js.map +1 -0
  15. package/dist/allend/DClient/Order.d.ts +50 -0
  16. package/dist/allend/DClient/Order.d.ts.map +1 -0
  17. package/dist/allend/DClient/Order.js +321 -0
  18. package/dist/allend/DClient/Order.js.map +1 -0
  19. package/dist/allend/MSI/Controls.d.ts +232 -0
  20. package/dist/allend/MSI/Controls.d.ts.map +1 -0
  21. package/dist/allend/MSI/Controls.js +668 -0
  22. package/dist/allend/MSI/Controls.js.map +1 -0
  23. package/dist/allend/MSI/Handles.d.ts +89 -0
  24. package/dist/allend/MSI/Handles.d.ts.map +1 -0
  25. package/dist/allend/MSI/Handles.js +328 -0
  26. package/dist/allend/MSI/Handles.js.map +1 -0
  27. package/dist/allend/MSI/Plugins.d.ts +23 -0
  28. package/dist/allend/MSI/Plugins.d.ts.map +1 -0
  29. package/dist/allend/MSI/Plugins.js +29 -0
  30. package/dist/allend/MSI/Plugins.js.map +1 -0
  31. package/dist/allend/MSI/index.d.ts +38 -0
  32. package/dist/allend/MSI/index.d.ts.map +1 -0
  33. package/dist/allend/MSI/index.js +176 -0
  34. package/dist/allend/MSI/index.js.map +1 -0
  35. package/dist/allend/index.d.ts +16 -0
  36. package/dist/allend/index.d.ts.map +1 -0
  37. package/dist/allend/index.js +12 -0
  38. package/dist/allend/index.js.map +1 -0
  39. package/dist/backend/Auth.d.ts +14 -0
  40. package/dist/backend/Auth.d.ts.map +1 -0
  41. package/dist/backend/Auth.js +84 -0
  42. package/dist/backend/Auth.js.map +1 -0
  43. package/dist/index.d.ts +13 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +12 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/utils/index.d.ts +6 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +3 -0
  50. package/dist/utils/index.js.map +1 -0
  51. package/dist/utils/stream.d.ts +21 -0
  52. package/dist/utils/stream.d.ts.map +1 -0
  53. package/dist/utils/stream.js +59 -0
  54. package/dist/utils/stream.js.map +1 -0
  55. package/package.json +81 -0
  56. package/src/allend/Access.ts +58 -0
  57. package/src/allend/DClient/Client.ts +76 -0
  58. package/src/allend/DClient/Event.ts +76 -0
  59. package/src/allend/DClient/Order.ts +452 -0
  60. package/src/allend/MSI/Controls.ts +703 -0
  61. package/src/allend/MSI/Handles.ts +387 -0
  62. package/src/allend/MSI/Plugins.ts +52 -0
  63. package/src/allend/MSI/index.tsx +254 -0
  64. package/src/allend/index.ts +14 -0
  65. package/src/backend/Auth.ts +112 -0
  66. package/src/index.ts +18 -0
  67. package/src/types/access.d.ts +7 -0
  68. package/src/types/auth.d.ts +26 -0
  69. package/src/types/index.d.ts +275 -0
  70. package/src/utils/index.ts +4 -0
  71. package/src/utils/stream.ts +68 -0
@@ -0,0 +1,112 @@
1
+ import type { AuthCredentials, AuthOptions, AuthRequestOptions } from '../types/auth'
2
+
3
+ const ACCESS_TOKEN_EXPIRY = 3.75 // in 3 minutes 45 seconds
4
+
5
+ type AuthResponse = {
6
+ error: boolean
7
+ message: string
8
+ token: string
9
+ }
10
+
11
+ export default class Auth {
12
+ private version: number
13
+ protected creds: AuthCredentials
14
+ private expiryTime?: any
15
+ private autorefresh?: boolean
16
+ private baseURL: string
17
+ public accessToken?: string
18
+
19
+ constructor( creds: AuthCredentials, options?: AuthOptions ){
20
+ if( !creds ) throw new Error('Undefined Credentials. Check https://doc.dedot.io/sdk/auth')
21
+ if( !creds.workspace ) throw new Error('Undefined Workspace Reference. Check https://doc.dedot.io/sdk/auth')
22
+ if( !creds.remoteOrigin ) throw new Error('Undefined Remote Origin. Check https://doc.dedot.io/sdk/auth')
23
+ if( !creds.cid ) throw new Error('Undefined Connector ID. Check https://doc.dedot.io/sdk/auth')
24
+ if( !creds.secret ) throw new Error('Undefined Connector Secret. Check https://doc.dedot.io/sdk/auth')
25
+
26
+ this.creds = creds
27
+ this.version = options?.version || 1
28
+ this.baseURL = options?.env === 'prod' ? 'https://api.dedot.io' : 'http://api.dedot.io:24800'
29
+ this.autorefresh = options?.autorefresh || false
30
+ }
31
+
32
+ private async request<T>( options: AuthRequestOptions ): Promise<T>{
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.creds.remoteOrigin,
42
+ 'x-user-agent': `De.remote/${this.version}.0`
43
+ }
44
+ }
45
+
46
+ if( this.accessToken )
47
+ rawOptions.headers.authorization = `Bearer ${this.accessToken}`
48
+
49
+ if( options.body )
50
+ rawOptions.headers['content-type'] = 'application/json'
51
+
52
+ options = { ...rawOptions, ...options }
53
+ if( !options.url )
54
+ throw new Error('Undefined request <url>')
55
+
56
+ console.log('Auth request', `${this.baseURL}/v${this.version}/${options.url.replace(/^\//, '')}`, options )
57
+
58
+ const response = await fetch(`${this.baseURL}/v${this.version}/${options.url.replace(/^\//, '')}`, options )
59
+
60
+ return await response.json() as T
61
+ }
62
+
63
+ async getToken(): Promise<string>{
64
+ const
65
+ { workspace, cid, secret } = this.creds,
66
+ options: AuthRequestOptions = {
67
+ url: '/access/token',
68
+ method: 'POST',
69
+ body: this.creds
70
+ },
71
+ { error, message, token } = await this.request<AuthResponse>( options )
72
+ if( error ) throw new Error( message )
73
+
74
+ // Set auto-refresh token every 4 mins
75
+ if( this.autorefresh ){
76
+ clearTimeout( this.expiryTime )
77
+ this.expiryTime = setTimeout( () => this.rotateToken(), ACCESS_TOKEN_EXPIRY * 60 * 1000 )
78
+ }
79
+
80
+ this.accessToken = token
81
+ return token
82
+ }
83
+
84
+ async rotateToken(){
85
+ if( !this.accessToken )
86
+ throw new Error('No access token found')
87
+
88
+ try {
89
+ const
90
+ options: AuthRequestOptions = {
91
+ url: '/access/token/rotate',
92
+ method: 'PATCH',
93
+ body: { secret: this.creds.secret }
94
+ },
95
+ { error, message, token } = await this.request<AuthResponse>( options )
96
+ if( error ) throw new Error( message )
97
+
98
+ // Set auto-refresh token every 4 mins
99
+ if( this.autorefresh ){
100
+ clearTimeout( this.expiryTime )
101
+ this.expiryTime = setTimeout( () => this.rotateToken(), ACCESS_TOKEN_EXPIRY * 60 * 1000 )
102
+ }
103
+
104
+ this.accessToken = token
105
+ return token
106
+ }
107
+ catch( error: any ){
108
+ console.error(`Refresh access token failed: ${error.message}`)
109
+ return await this.getToken() // Get new token instead
110
+ }
111
+ }
112
+ }
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import Utils from './utils'
2
+ import MSI from './allend/MSI'
3
+ import Auth from './backend/Auth'
4
+ import Order from './allend/DClient/Order'
5
+ import Event from './allend/DClient/Event'
6
+ import Client from './allend/DClient/Client'
7
+
8
+ // export const Auth = _Auth
9
+ // export const MSI = _MSI
10
+ // export const Utils = _Utils
11
+ const DClient = { Client, Order, Event }
12
+
13
+ export {
14
+ Auth,
15
+ MSI,
16
+ Utils,
17
+ DClient
18
+ }
@@ -0,0 +1,7 @@
1
+ export type AccessOptions = {
2
+ env?: 'dev' | 'prod'
3
+ version?: number
4
+ workspace: string
5
+ accessToken: string
6
+ remoteOrigin?: string
7
+ }
@@ -0,0 +1,26 @@
1
+ export type AuthOptions = {
2
+ env?: 'dev' | 'prod'
3
+ version?: number
4
+ autorefresh?: boolean
5
+ }
6
+
7
+ export type AuthCredentials = {
8
+ workspace: string
9
+ remoteOrigin: string
10
+ cid: string
11
+ secret: string
12
+ }
13
+
14
+ export type SocketAuthCredentials = {
15
+ utype: string
16
+ id: string
17
+ remoteOrigin: string
18
+ accessToken: string
19
+ }
20
+
21
+ export type AuthRequestOptions = {
22
+ url: string
23
+ method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'
24
+ headers?: { [index: string]: string }
25
+ body?: any
26
+ }
@@ -0,0 +1,275 @@
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 GPSLocation = Coordinates & {
25
+ heading?: number
26
+ }
27
+ export type ActivePosition = {
28
+ id: string
29
+ position: GPSLocation
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 = {
93
+ routeId: string | number
94
+ profile: string
95
+ origin?: Coordinates
96
+ destination?: Coordinates
97
+ waypoints: Coordinates[]
98
+ route: any
99
+ }
100
+ export type RouteOptions = {
101
+ id?: string | number
102
+ mode?: 'default' | 'navigation'
103
+ profile?: 'driving-traffic' | 'driving' | 'cycling' | 'biking' | 'walking' | 'transit'
104
+ unit?: 'metric' | 'imperial',
105
+ preference?: 'TRAFFIC_AWARE' | 'TRAFFIC_UNAWARE'
106
+ pointless?: boolean
107
+ styles?: any
108
+ animation?: AnimatedRouteOptions
109
+ }
110
+
111
+ export type SearchPlace = {
112
+ name: string
113
+ location: Coordinates,
114
+ address: string
115
+ }
116
+
117
+ export type Waypoint = {
118
+ no: number
119
+ type: 'pickup' | 'dropoff'
120
+ description: string
121
+ coordinates: Coordinates
122
+ address?: string
123
+ contact: {
124
+ type: string
125
+ reference: string
126
+ phone?: string
127
+ email?: string
128
+ }
129
+ }
130
+ export type WaypointIndex = 'origin' | 'destination' | number
131
+ export type WaypointOptions = {
132
+ no?: number
133
+ type?: 'pickup' | 'dropoff'
134
+ description?: string
135
+ coordinates?: Coordinates
136
+ address?: string
137
+ 'contact.type'?: string
138
+ 'contact.reference'?: string
139
+ 'contact.phone'?: string
140
+ 'contact.email'?: string
141
+ }
142
+
143
+ export type Package = {
144
+ waypointNo: number
145
+ careLevel: number
146
+ category: string
147
+ weight: number
148
+ note?: string
149
+ }
150
+ export type PackageOptions = {
151
+ waypointNo?: number
152
+ careLevel?: number
153
+ category?: string
154
+ weight?: number
155
+ note?: string
156
+ }
157
+
158
+ export type PaymentMode = 'cash' | 'card' | 'momo' | 'wigo'
159
+ export type OrderService = {
160
+ fees: {
161
+ total: {
162
+ amount: number
163
+ currency: string
164
+ },
165
+ tax: number
166
+ discount: number
167
+ }
168
+ payment: {
169
+ mode: PaymentMode
170
+ paid: boolean
171
+ }
172
+ xpress: string
173
+ }
174
+ export type OrderServiceOptions = {
175
+ 'fees.total.amount'?: number
176
+ 'fees.total.currency'?: string
177
+ 'fees.tax'?: string
178
+ 'fees.discount'?: string
179
+ 'payment.mode'?: PaymentMode
180
+ 'payment.option'?: string
181
+ 'payment.paid'?: boolean
182
+ xpress?: string
183
+ }
184
+ export type OrderOperator = {}
185
+ export type OrderStage = {
186
+ current: string
187
+ status: string
188
+ }
189
+
190
+ export type Message = {
191
+ type: 'text' | 'location' | 'media'
192
+ sender: string
193
+ content: string
194
+ timestamp: string
195
+ }
196
+ export type Caption = {
197
+ duration?: number
198
+ unit?: string
199
+ label?: string
200
+ }
201
+ export type Peer = {
202
+ utype: string
203
+ id: string
204
+ }
205
+
206
+ export type MapOptions = {
207
+ element: string
208
+ accessToken: string
209
+ version?: number
210
+ env?: 'dev' | 'prod'
211
+ }
212
+ export type MapLayerStyle = 'streets' | 'outdoors' | 'light' | 'dark' | 'satellite'
213
+ export type MapWaypoint = {
214
+ index?: number
215
+ coords: Coordinates
216
+ caption?: Caption
217
+ }
218
+
219
+ export type Entity = {
220
+ id: string
221
+ status: 'ACTIVE' | 'BUSY'
222
+ grade: '1H' | '2H' | '3H'
223
+ currentLocation: GPSLocation
224
+ static?: boolean
225
+ type: 'moto' | 'car' | 'bike' | 'truck' | 'plane' | 'ship' | 'restaurant' | 'hotel' | 'store' | 'office' | 'warehouse'
226
+ }
227
+ export type EntitySpecs = {
228
+ id: string
229
+ status: 'ACTIVE' | 'BUSY'
230
+ grade: '1H' | '2H' | '3H'
231
+ currentLocation: GPSLocation
232
+ static?: boolean
233
+ type: 'moto' | 'car' | 'bike' | 'truck' | 'plane' | 'ship' | 'restaurant' | 'hotel' | 'store' | 'office' | 'warehouse'
234
+ }
235
+
236
+ export interface UserLocationOptions {
237
+ // Base point styling options
238
+ borderRadius?: number
239
+ borderColor?: string
240
+ borderOpacity?: number
241
+ dotColor?: string
242
+ showInnerDot?: boolean
243
+ noRing?: boolean
244
+
245
+ // User location specific options
246
+ showDirectionArrow?: boolean
247
+ arrowColor?: string
248
+ arrowSize?: number
249
+ pulseAnimation?: boolean
250
+ accuracyCircle?: boolean
251
+ accuracyColor?: string
252
+ accuracyOpacity?: number
253
+
254
+ // Callbacks
255
+ onLocationUpdate?: ( location: GPSLocation ) => void
256
+ onLocationError?: ( error: GeolocationPositionError ) => void
257
+ }
258
+ export type DragPickOptions = {
259
+ snapToRoad?: boolean
260
+ pinPoints?: boolean
261
+ pointOptions?: CustomPointOptions
262
+ }
263
+ export type DragPickContentType = 'duration' | 'distance' | 'preloader'
264
+ export type DragPickContent = {
265
+ time?: number
266
+ unit?: 'min' | 'sec' | 'hr' | 'km' | 'mi' | 'm'
267
+ distance?: number
268
+ preloader?: boolean
269
+ }
270
+ export type DragPickEvent = 'dragstart' | 'dragend' | 'zoom_changed' | 'idle'
271
+ export interface DragPickInterface {
272
+ enable( origin?: Coordinates ): void
273
+ disable(): void
274
+ content( type: DragPickContentType, content: DragPickContent ): void
275
+ }
@@ -0,0 +1,4 @@
1
+
2
+ import Stream from './stream'
3
+
4
+ export default { Stream }
@@ -0,0 +1,68 @@
1
+
2
+ export type StreamDataListener = ( data: string ) => void
3
+
4
+ export default class Stream {
5
+ private _STALED: boolean = false
6
+ private _CLOSED: boolean = false
7
+ private _fns: StreamDataListener[] = []
8
+ private _exitFn = (() => {})
9
+ private _errorFn = (( error: Error ) => {})
10
+ private _downStream?: Stream
11
+ private _upStream?: Stream
12
+
13
+ private _upstream( stream: Stream ){
14
+ this._upStream = stream
15
+ return this
16
+ }
17
+ private _backpressure( data: any ){
18
+ !this._CLOSED && this._fns.map( fn => fn( data ) )
19
+ }
20
+
21
+ sync( data: any ){
22
+ !this._CLOSED && this._downStream?._backpressure( data )
23
+ }
24
+
25
+ on( _event: 'data', fn: StreamDataListener ){
26
+ if( this._CLOSED ) throw new Error('Stream closed')
27
+
28
+ this._fns.push( fn )
29
+ return this
30
+ }
31
+
32
+ pipe( stream: Stream ){
33
+ stream._upstream( this )
34
+ this._downStream = stream
35
+ return this
36
+ }
37
+
38
+ error( error: Error | string ){
39
+ // Throw error to self
40
+ this._errorFn( typeof error == 'string' ? new Error( error ) : error )
41
+ // Throw error to downstream pipe
42
+ this._downStream?.error( error )
43
+
44
+ return this
45
+ }
46
+
47
+ close(){
48
+ if( this._CLOSED ) return
49
+ this._CLOSED = true
50
+
51
+ this._fns = []
52
+ this._exitFn()
53
+
54
+ this._downStream?.close() // Close down streams
55
+ // this._upStream?.close() // Close up streams: Recursive loop call effect
56
+ }
57
+
58
+ isActive(){ return !this._CLOSED }
59
+
60
+ onerror( fn: ( error: Error ) => void ){
61
+ this._errorFn = fn
62
+ return this
63
+ }
64
+ onclose( fn: () => void ){
65
+ this._exitFn = fn
66
+ return this
67
+ }
68
+ }