@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.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/allend/Access.d.ts +12 -0
- package/dist/allend/Access.d.ts.map +1 -0
- package/dist/allend/Access.js +43 -0
- package/dist/allend/Access.js.map +1 -0
- package/dist/allend/DClient/Client.d.ts +11 -0
- package/dist/allend/DClient/Client.d.ts.map +1 -0
- package/dist/allend/DClient/Client.js +50 -0
- package/dist/allend/DClient/Client.js.map +1 -0
- package/dist/allend/DClient/Event.d.ts +19 -0
- package/dist/allend/DClient/Event.d.ts.map +1 -0
- package/dist/allend/DClient/Event.js +74 -0
- package/dist/allend/DClient/Event.js.map +1 -0
- package/dist/allend/DClient/Order.d.ts +50 -0
- package/dist/allend/DClient/Order.d.ts.map +1 -0
- package/dist/allend/DClient/Order.js +321 -0
- package/dist/allend/DClient/Order.js.map +1 -0
- package/dist/allend/MSI/Controls.d.ts +232 -0
- package/dist/allend/MSI/Controls.d.ts.map +1 -0
- package/dist/allend/MSI/Controls.js +668 -0
- package/dist/allend/MSI/Controls.js.map +1 -0
- package/dist/allend/MSI/Handles.d.ts +89 -0
- package/dist/allend/MSI/Handles.d.ts.map +1 -0
- package/dist/allend/MSI/Handles.js +328 -0
- package/dist/allend/MSI/Handles.js.map +1 -0
- package/dist/allend/MSI/Plugins.d.ts +23 -0
- package/dist/allend/MSI/Plugins.d.ts.map +1 -0
- package/dist/allend/MSI/Plugins.js +29 -0
- package/dist/allend/MSI/Plugins.js.map +1 -0
- package/dist/allend/MSI/index.d.ts +38 -0
- package/dist/allend/MSI/index.d.ts.map +1 -0
- package/dist/allend/MSI/index.js +176 -0
- package/dist/allend/MSI/index.js.map +1 -0
- package/dist/allend/index.d.ts +16 -0
- package/dist/allend/index.d.ts.map +1 -0
- package/dist/allend/index.js +12 -0
- package/dist/allend/index.js.map +1 -0
- package/dist/backend/Auth.d.ts +14 -0
- package/dist/backend/Auth.d.ts.map +1 -0
- package/dist/backend/Auth.js +84 -0
- package/dist/backend/Auth.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/stream.d.ts +21 -0
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +59 -0
- package/dist/utils/stream.js.map +1 -0
- package/package.json +81 -0
- package/src/allend/Access.ts +58 -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/MSI/Controls.ts +703 -0
- package/src/allend/MSI/Handles.ts +387 -0
- package/src/allend/MSI/Plugins.ts +52 -0
- package/src/allend/MSI/index.tsx +254 -0
- package/src/allend/index.ts +14 -0
- package/src/backend/Auth.ts +112 -0
- package/src/index.ts +18 -0
- package/src/types/access.d.ts +7 -0
- package/src/types/auth.d.ts +26 -0
- package/src/types/index.d.ts +275 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/stream.ts +68 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AccessOptions } from '../../types/access'
|
|
2
|
+
import type { HTTPRequestOptions, GPSLocation, OrderService, HTTPResponse, Entity } from '../../types'
|
|
3
|
+
import Access 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 Access {
|
|
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 )
|
|
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: GPSLocation ){
|
|
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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { GPSLocation , Message, Peer, OrderStage } from '../../types'
|
|
2
|
+
import type { SocketAuthCredentials } from '../../types/auth'
|
|
3
|
+
import type { AccessOptions } from '../../types/access'
|
|
4
|
+
import io, { Socket } from 'socket.io-client'
|
|
5
|
+
import Access from '../Access'
|
|
6
|
+
|
|
7
|
+
export default class Event extends Access {
|
|
8
|
+
private nsp?: Socket
|
|
9
|
+
private iosHost: string
|
|
10
|
+
|
|
11
|
+
constructor( access: AccessOptions ){
|
|
12
|
+
super( access )
|
|
13
|
+
|
|
14
|
+
// Socket server host
|
|
15
|
+
this.iosHost = access.env == 'prod' ?
|
|
16
|
+
'https://api.dedot.io' // Production server
|
|
17
|
+
: 'http://api.dedot.io:24800' // Development & staging server
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
connect( clientId: string ): Promise<void> {
|
|
21
|
+
return new Promise( ( resolve, reject ) => {
|
|
22
|
+
// Connect to main clients namespace
|
|
23
|
+
const auth: SocketAuthCredentials = {
|
|
24
|
+
utype: 'client',
|
|
25
|
+
id: clientId,
|
|
26
|
+
remoteOrigin: this.remoteOrigin as string,
|
|
27
|
+
accessToken: this.accessToken as string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.nsp = io( this.iosHost, { auth } )
|
|
31
|
+
this.nsp.on('connect', resolve )
|
|
32
|
+
this.nsp.on('connect_error', reject )
|
|
33
|
+
} )
|
|
34
|
+
}
|
|
35
|
+
disconnect(){
|
|
36
|
+
this.nsp?.disconnect()
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
join( jrtoken: string ): Promise<boolean> {
|
|
40
|
+
return new Promise( ( resolve, reject ) => {
|
|
41
|
+
this.nsp?.emit('JOIN', jrtoken, ( errmess?: string ) => {
|
|
42
|
+
errmess ? reject( new Error( errmess ) ) : resolve( true )
|
|
43
|
+
} )
|
|
44
|
+
} )
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
onLeft( fn: ( peer: Peer ) => void ){
|
|
48
|
+
this.nsp?.on('LEFT', fn )
|
|
49
|
+
return this
|
|
50
|
+
}
|
|
51
|
+
onConnected( fn: ( peer: Peer ) => void ){
|
|
52
|
+
this.nsp?.on('CONNECTED', fn )
|
|
53
|
+
return this
|
|
54
|
+
}
|
|
55
|
+
onDisconnected( fn: ( peer: Peer ) => void ){
|
|
56
|
+
this.nsp?.on('DISCONNECTED', fn )
|
|
57
|
+
return this
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
onRoute( fn: ( data: any ) => void ){
|
|
61
|
+
this.nsp?.on('ROUTE-CHANGE', fn )
|
|
62
|
+
return this
|
|
63
|
+
}
|
|
64
|
+
onStage( fn: ( data: OrderStage ) => void ){
|
|
65
|
+
this.nsp?.on('STAGE-CHANGE', fn )
|
|
66
|
+
return this
|
|
67
|
+
}
|
|
68
|
+
onLocation( fn: ( location: GPSLocation ) => void ){
|
|
69
|
+
this.nsp?.on('LOCATION-CHANGE', fn )
|
|
70
|
+
return this
|
|
71
|
+
}
|
|
72
|
+
onMessage( fn: ( payload: Message ) => void ){
|
|
73
|
+
this.nsp?.on('MESSAGE', fn )
|
|
74
|
+
return this
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import type { HTTPRequestOptions, HTTPResponse } from '../../types'
|
|
2
|
+
import type { AccessOptions } from '../../types/access'
|
|
3
|
+
import type {
|
|
4
|
+
Package, PackageOptions,
|
|
5
|
+
Waypoint, WaypointOptions,
|
|
6
|
+
OrderService, OrderServiceOptions, OrderOperator, OrderStage
|
|
7
|
+
} from '../../types'
|
|
8
|
+
import Access from '../Access'
|
|
9
|
+
|
|
10
|
+
type IntentTokenResponse = HTTPResponse & {
|
|
11
|
+
token: string
|
|
12
|
+
}
|
|
13
|
+
type JRTokenResponse = HTTPResponse & {
|
|
14
|
+
jrtoken: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type WaypointResponse = HTTPResponse & {
|
|
18
|
+
waypoint: Waypoint
|
|
19
|
+
}
|
|
20
|
+
type WaypointsResponse = HTTPResponse & {
|
|
21
|
+
waypoints: Waypoint[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PackageResponse = HTTPResponse & {
|
|
25
|
+
package: Package
|
|
26
|
+
}
|
|
27
|
+
type PackagesResponse = HTTPResponse & {
|
|
28
|
+
packages: Package[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type OrderServiceResponse = HTTPResponse & {
|
|
32
|
+
service: OrderService
|
|
33
|
+
}
|
|
34
|
+
type OrderOperators = {
|
|
35
|
+
[index: string]: OrderOperator
|
|
36
|
+
}
|
|
37
|
+
type OrderOperatorsResponse = HTTPResponse & {
|
|
38
|
+
operators: OrderOperators
|
|
39
|
+
}
|
|
40
|
+
type OrderStageResponse = HTTPResponse & {
|
|
41
|
+
stage: OrderStage
|
|
42
|
+
}
|
|
43
|
+
type CurrentRouteResponse = HTTPResponse & {
|
|
44
|
+
route: any
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default class Order extends Access {
|
|
48
|
+
private intentToken: string // Active order's intent token
|
|
49
|
+
|
|
50
|
+
constructor( access: AccessOptions ){
|
|
51
|
+
super( access )
|
|
52
|
+
|
|
53
|
+
this.intentToken = ''
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Order intent
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
async intent( clientId: string ): Promise<string> {
|
|
61
|
+
if( !clientId )
|
|
62
|
+
throw new Error('<clientId> argument required')
|
|
63
|
+
|
|
64
|
+
const
|
|
65
|
+
options: HTTPRequestOptions = {
|
|
66
|
+
url: '/order/intent',
|
|
67
|
+
method: 'POST',
|
|
68
|
+
body: { clientId }
|
|
69
|
+
},
|
|
70
|
+
{ error, message, token } = await this.request<IntentTokenResponse>( options )
|
|
71
|
+
if( error ) throw new Error( message )
|
|
72
|
+
|
|
73
|
+
this.intentToken = token
|
|
74
|
+
return token
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async unintent( token: string ): Promise<boolean> {
|
|
78
|
+
if( !token )
|
|
79
|
+
throw new Error('Undefined intent token')
|
|
80
|
+
|
|
81
|
+
const
|
|
82
|
+
options: HTTPRequestOptions = {
|
|
83
|
+
url: '/order/intent',
|
|
84
|
+
method: 'DELETE',
|
|
85
|
+
headers: { 'x-intent-token': token }
|
|
86
|
+
},
|
|
87
|
+
{ error, message } = await this.request<HTTPResponse>( options )
|
|
88
|
+
if( error ) throw new Error( message )
|
|
89
|
+
|
|
90
|
+
this.intentToken = ''
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Order waypoints
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
async addWaypoint( list: Waypoint | Waypoint[], token?: string ): Promise<Waypoint[]> {
|
|
99
|
+
if( !list )
|
|
100
|
+
throw new Error('Expect <list> argument to be [Waypoint or Waypoint<array>]')
|
|
101
|
+
|
|
102
|
+
token = token || this.intentToken
|
|
103
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
104
|
+
|
|
105
|
+
const
|
|
106
|
+
options: HTTPRequestOptions = {
|
|
107
|
+
url: '/order/waypoints/add',
|
|
108
|
+
method: 'PUT',
|
|
109
|
+
headers: { 'x-intent-token': token },
|
|
110
|
+
body: !Array.isArray( list ) ? [ list ] : list
|
|
111
|
+
},
|
|
112
|
+
{ error, message, waypoints } = await this.request<WaypointsResponse>( options )
|
|
113
|
+
if( error ) throw new Error( message )
|
|
114
|
+
|
|
115
|
+
return waypoints
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async getWaypoint( no: number, token?: string ): Promise<Waypoint> {
|
|
119
|
+
|
|
120
|
+
if( !no ) throw new Error('Expected waypoint number')
|
|
121
|
+
|
|
122
|
+
token = token || this.intentToken
|
|
123
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
124
|
+
|
|
125
|
+
const
|
|
126
|
+
options: HTTPRequestOptions = {
|
|
127
|
+
url: `/order/waypoints/${no}`,
|
|
128
|
+
method: 'GET',
|
|
129
|
+
headers: { 'x-intent-token': token }
|
|
130
|
+
},
|
|
131
|
+
{ error, message, waypoint } = await this.request<WaypointResponse>( options )
|
|
132
|
+
if( error ) throw new Error( message )
|
|
133
|
+
|
|
134
|
+
return waypoint
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async fetchWaypoints( token?: string ): Promise<Waypoint[]> {
|
|
138
|
+
|
|
139
|
+
token = token || this.intentToken
|
|
140
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
141
|
+
|
|
142
|
+
const
|
|
143
|
+
options: HTTPRequestOptions = {
|
|
144
|
+
url: `/order/waypoints`,
|
|
145
|
+
method: 'GET',
|
|
146
|
+
headers: { 'x-intent-token': token }
|
|
147
|
+
},
|
|
148
|
+
{ error, message, waypoints } = await this.request<WaypointsResponse>( options )
|
|
149
|
+
if( error ) throw new Error( message )
|
|
150
|
+
|
|
151
|
+
return waypoints
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async updateWaypoint( no: number, updates: WaypointOptions, token?: string ): Promise<Waypoint[]> {
|
|
155
|
+
|
|
156
|
+
if( !no ) throw new Error('Expected waypoint number')
|
|
157
|
+
|
|
158
|
+
if( !updates )
|
|
159
|
+
throw new Error('Expect <updates: WaypointOptions> to be object')
|
|
160
|
+
|
|
161
|
+
token = token || this.intentToken
|
|
162
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
163
|
+
|
|
164
|
+
const
|
|
165
|
+
options: HTTPRequestOptions = {
|
|
166
|
+
url: `/order/waypoints/${no}`,
|
|
167
|
+
method: 'PATCH',
|
|
168
|
+
headers: { 'x-intent-token': token },
|
|
169
|
+
body: updates
|
|
170
|
+
},
|
|
171
|
+
{ error, message, waypoints } = await this.request<WaypointsResponse>( options )
|
|
172
|
+
if( error ) throw new Error( message )
|
|
173
|
+
|
|
174
|
+
return waypoints
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async deleteWaypoint( no: number, token?: string ): Promise<Waypoint[]> {
|
|
178
|
+
|
|
179
|
+
if( !no ) throw new Error('Expected waypoint number')
|
|
180
|
+
|
|
181
|
+
token = token || this.intentToken
|
|
182
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
183
|
+
|
|
184
|
+
const
|
|
185
|
+
options: HTTPRequestOptions = {
|
|
186
|
+
url: `/order/waypoints/${no}`,
|
|
187
|
+
method: 'DELETE',
|
|
188
|
+
headers: { 'x-intent-token': token }
|
|
189
|
+
},
|
|
190
|
+
{ error, message, waypoints } = await this.request<WaypointsResponse>( options )
|
|
191
|
+
if( error ) throw new Error( message )
|
|
192
|
+
|
|
193
|
+
return waypoints
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Order packages
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
async addPackage( list: Package | Package[], token?: string ): Promise<Package[]> {
|
|
201
|
+
if( !list )
|
|
202
|
+
throw new Error('Expect <list> argument to be [Package or Package<array>]')
|
|
203
|
+
|
|
204
|
+
token = token || this.intentToken
|
|
205
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
206
|
+
|
|
207
|
+
const
|
|
208
|
+
options: HTTPRequestOptions = {
|
|
209
|
+
url: '/order/packages/add',
|
|
210
|
+
method: 'PUT',
|
|
211
|
+
headers: { 'x-intent-token': token },
|
|
212
|
+
body: !Array.isArray( list ) ? [ list ] : list
|
|
213
|
+
},
|
|
214
|
+
{ error, message, packages } = await this.request<PackagesResponse>( options )
|
|
215
|
+
if( error ) throw new Error( message )
|
|
216
|
+
|
|
217
|
+
return packages
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async getPackage( PTC: string, token?: string ): Promise<Package> {
|
|
221
|
+
if( !PTC )
|
|
222
|
+
throw new Error('Expected <PTC> Package Tracking Code')
|
|
223
|
+
|
|
224
|
+
token = token || this.intentToken
|
|
225
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
226
|
+
|
|
227
|
+
const
|
|
228
|
+
options: HTTPRequestOptions = {
|
|
229
|
+
url: `/order/packages/${PTC}`,
|
|
230
|
+
method: 'GET',
|
|
231
|
+
headers: { 'x-intent-token': token }
|
|
232
|
+
},
|
|
233
|
+
response = await this.request<PackageResponse>( options )
|
|
234
|
+
if( response.error )
|
|
235
|
+
throw new Error( response.message )
|
|
236
|
+
|
|
237
|
+
return response.package
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async fetchPackages( token?: string ): Promise<Package[]> {
|
|
241
|
+
token = token || this.intentToken
|
|
242
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
243
|
+
|
|
244
|
+
const
|
|
245
|
+
options: HTTPRequestOptions = {
|
|
246
|
+
url: `/order/packages`,
|
|
247
|
+
method: 'GET',
|
|
248
|
+
headers: { 'x-intent-token': token }
|
|
249
|
+
},
|
|
250
|
+
{ error, message, packages } = await this.request<PackagesResponse>( options )
|
|
251
|
+
if( error ) throw new Error( message )
|
|
252
|
+
|
|
253
|
+
return packages
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async updatePackage( PTC: number, updates: PackageOptions, token?: string ): Promise<Package[]> {
|
|
257
|
+
if( !PTC )
|
|
258
|
+
throw new Error('Expected Package Tracking Code')
|
|
259
|
+
|
|
260
|
+
if( !updates )
|
|
261
|
+
throw new Error('Expect <updates: PackageOptions> to be object')
|
|
262
|
+
|
|
263
|
+
token = token || this.intentToken
|
|
264
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
265
|
+
|
|
266
|
+
const
|
|
267
|
+
options: HTTPRequestOptions = {
|
|
268
|
+
url: `/order/packages/${PTC}`,
|
|
269
|
+
method: 'PATCH',
|
|
270
|
+
headers: { 'x-intent-token': token },
|
|
271
|
+
body: updates
|
|
272
|
+
},
|
|
273
|
+
{ error, message, packages } = await this.request<PackagesResponse>( options )
|
|
274
|
+
if( error ) throw new Error( message )
|
|
275
|
+
|
|
276
|
+
return packages
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async deletePackage( PTC: number, token?: string ): Promise<Package[]> {
|
|
280
|
+
if( !PTC )
|
|
281
|
+
throw new Error('Expected Package Tracking Code')
|
|
282
|
+
|
|
283
|
+
token = token || this.intentToken
|
|
284
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
285
|
+
|
|
286
|
+
const
|
|
287
|
+
options: HTTPRequestOptions = {
|
|
288
|
+
url: `/order/packages/${PTC}`,
|
|
289
|
+
method: 'DELETE',
|
|
290
|
+
headers: { 'x-intent-token': token }
|
|
291
|
+
},
|
|
292
|
+
{ error, message, packages } = await this.request<PackagesResponse>( options )
|
|
293
|
+
if( error ) throw new Error( message )
|
|
294
|
+
|
|
295
|
+
return packages
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Order service
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
async initiate( payload: OrderService, token?: string ): Promise<string> {
|
|
303
|
+
if( !payload )
|
|
304
|
+
throw new Error('Expect <payload> argument to be [OrderService]')
|
|
305
|
+
|
|
306
|
+
token = token || this.intentToken
|
|
307
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
308
|
+
|
|
309
|
+
const
|
|
310
|
+
options: HTTPRequestOptions = {
|
|
311
|
+
url: '/order/service',
|
|
312
|
+
method: 'POST',
|
|
313
|
+
headers: { 'x-intent-token': token },
|
|
314
|
+
body: payload
|
|
315
|
+
},
|
|
316
|
+
{ error, message, jrtoken } = await this.request<JRTokenResponse>( options )
|
|
317
|
+
if( error ) throw new Error( message )
|
|
318
|
+
|
|
319
|
+
return jrtoken
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async getService( token?: string ): Promise<OrderService>{
|
|
323
|
+
token = token || this.intentToken
|
|
324
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
325
|
+
|
|
326
|
+
const
|
|
327
|
+
options: HTTPRequestOptions = {
|
|
328
|
+
url: `/order/service`,
|
|
329
|
+
method: 'GET',
|
|
330
|
+
headers: { 'x-intent-token': token }
|
|
331
|
+
},
|
|
332
|
+
{ error, message, service } = await this.request<OrderServiceResponse>( options )
|
|
333
|
+
if( error ) throw new Error( message )
|
|
334
|
+
|
|
335
|
+
return service
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async updateService( updates: OrderServiceOptions, token?: string ): Promise<OrderService> {
|
|
339
|
+
if( !updates )
|
|
340
|
+
throw new Error('Expect <updates: OrderServiceOptions> to be object')
|
|
341
|
+
|
|
342
|
+
token = token || this.intentToken
|
|
343
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
344
|
+
|
|
345
|
+
const
|
|
346
|
+
options: HTTPRequestOptions = {
|
|
347
|
+
url: `/order/service`,
|
|
348
|
+
method: 'PATCH',
|
|
349
|
+
headers: { 'x-intent-token': token },
|
|
350
|
+
body: updates
|
|
351
|
+
},
|
|
352
|
+
{ error, message, service } = await this.request<OrderServiceResponse>( options )
|
|
353
|
+
if( error ) throw new Error( message )
|
|
354
|
+
|
|
355
|
+
return service
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async rateService( rating: number, token?: string ): Promise<boolean> {
|
|
359
|
+
if( !rating )
|
|
360
|
+
throw new Error('Expect <rating> to be number betwee 0 to 5')
|
|
361
|
+
|
|
362
|
+
token = token || this.intentToken
|
|
363
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
364
|
+
|
|
365
|
+
const
|
|
366
|
+
options: HTTPRequestOptions = {
|
|
367
|
+
url: `/order/service/rating`,
|
|
368
|
+
method: 'POST',
|
|
369
|
+
headers: { 'x-intent-token': token },
|
|
370
|
+
body: { rating }
|
|
371
|
+
},
|
|
372
|
+
{ error, message } = await this.request<HTTPResponse>( options )
|
|
373
|
+
if( error ) throw new Error( message )
|
|
374
|
+
|
|
375
|
+
return true
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Order operators
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
async getOperator( type: string, token?: string ): Promise<OrderOperator>{
|
|
383
|
+
if( !['LSP', 'partner', 'warehouse', 'agent'].includes( type ) )
|
|
384
|
+
throw new Error('Unknown order operator')
|
|
385
|
+
|
|
386
|
+
token = token || this.intentToken
|
|
387
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
388
|
+
|
|
389
|
+
const
|
|
390
|
+
options: HTTPRequestOptions = {
|
|
391
|
+
url: `/order/operators?type=${type}`,
|
|
392
|
+
method: 'GET',
|
|
393
|
+
headers: { 'x-intent-token': token }
|
|
394
|
+
},
|
|
395
|
+
{ error, message, operators } = await this.request<OrderOperatorsResponse>( options )
|
|
396
|
+
if( error ) throw new Error( message )
|
|
397
|
+
|
|
398
|
+
return operators[ type ]
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
async getOperators( token?: string ): Promise<OrderOperators>{
|
|
402
|
+
token = token || this.intentToken
|
|
403
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
404
|
+
|
|
405
|
+
const
|
|
406
|
+
options: HTTPRequestOptions = {
|
|
407
|
+
url: '/order/operators',
|
|
408
|
+
method: 'GET',
|
|
409
|
+
headers: { 'x-intent-token': token }
|
|
410
|
+
},
|
|
411
|
+
{ error, message, operators } = await this.request<OrderOperatorsResponse>( options )
|
|
412
|
+
if( error ) throw new Error( message )
|
|
413
|
+
|
|
414
|
+
return operators
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Order monitoring
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
async getCurrentStage( token?: string ): Promise<OrderStage>{
|
|
422
|
+
token = token || this.intentToken
|
|
423
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
424
|
+
|
|
425
|
+
const
|
|
426
|
+
options: HTTPRequestOptions = {
|
|
427
|
+
url: '/order/stage',
|
|
428
|
+
method: 'GET',
|
|
429
|
+
headers: { 'x-intent-token': token }
|
|
430
|
+
},
|
|
431
|
+
{ error, message, stage } = await this.request<OrderStageResponse>( options )
|
|
432
|
+
if( error ) throw new Error( message )
|
|
433
|
+
|
|
434
|
+
return stage
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
async getCurrentRoute( token?: string ): Promise<any>{
|
|
438
|
+
token = token || this.intentToken
|
|
439
|
+
if( !token ) throw new Error('Expected intent order token')
|
|
440
|
+
|
|
441
|
+
const
|
|
442
|
+
options: HTTPRequestOptions = {
|
|
443
|
+
url: '/order/route',
|
|
444
|
+
method: 'GET',
|
|
445
|
+
headers: { 'x-intent-token': token }
|
|
446
|
+
},
|
|
447
|
+
{ error, message, route } = await this.request<CurrentRouteResponse>( options )
|
|
448
|
+
if( error ) throw new Error( message )
|
|
449
|
+
|
|
450
|
+
return route
|
|
451
|
+
}
|
|
452
|
+
}
|