@gls_spain/gps-common 32.4.0 → 33.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/.idea/workspace.xml +51 -21
- package/CHANGELOG.md +25 -0
- package/errors/InconsistentSalesSettingsError.js +11 -0
- package/errors/InvalidSaleDestinationError.js +11 -0
- package/errors/NetworkCannotBeUpdatedError.js +11 -0
- package/errors/SaleAlreadyExistsError.js +11 -0
- package/errors/ShopCannotBeUpdatedError.js +11 -0
- package/errors/index.js +15 -0
- package/open-api-spec/index.js +486 -308
- package/package.json +1 -1
- package/schemas/definitions/common.js +259 -1
- package/schemas/definitions/defaults.js +88 -2
- package/schemas/definitions/expeditions.js +4 -1
- package/schemas/definitions/gls-spain-integration-events.js +10 -0
- package/schemas/definitions/historic-records.js +5 -2
- package/schemas/definitions/networks.js +26 -4
- package/schemas/definitions/sales.js +163 -0
- package/schemas/definitions/shops.js +3 -1
- package/schemas/index.js +28 -5
- package/schemas/definitions/init.js +0 -50
package/open-api-spec/index.js
CHANGED
|
@@ -18,9 +18,11 @@ const {
|
|
|
18
18
|
UserCannotBeDeletedError,
|
|
19
19
|
NetworkDoesNotExistError,
|
|
20
20
|
NetworkAlreadyExistsError,
|
|
21
|
+
NetworkCannotBeUpdatedError,
|
|
21
22
|
NetworkCannotBeDeletedError,
|
|
22
23
|
ShopDoesNotExistError,
|
|
23
24
|
ShopAlreadyExistsError,
|
|
25
|
+
ShopCannotBeUpdatedError,
|
|
24
26
|
ShopCannotBeDeletedError,
|
|
25
27
|
ShopNotEnabledError,
|
|
26
28
|
WrongPasswordError,
|
|
@@ -36,9 +38,11 @@ const {
|
|
|
36
38
|
ZoneDoesNotExistError,
|
|
37
39
|
ZoneAlreadyExistsError,
|
|
38
40
|
ZoneCannotBeDeletedError,
|
|
41
|
+
SaleAlreadyExistsError,
|
|
42
|
+
InconsistentSalesSettingsError,
|
|
43
|
+
InvalidSaleDestinationError,
|
|
39
44
|
} = require('../errors');
|
|
40
45
|
const { timezoneNames } = require('../schemas/definitions/common');
|
|
41
|
-
const { initRequest, initResponse } = require('../schemas/definitions/init');
|
|
42
46
|
const { loginResponse } = require('../schemas/definitions/login');
|
|
43
47
|
const { logoutResponse } = require('../schemas/definitions/logout');
|
|
44
48
|
const { becomeRequest } = require('../schemas/definitions/become');
|
|
@@ -133,6 +137,7 @@ const {
|
|
|
133
137
|
priceEvent,
|
|
134
138
|
upsertShopEvent,
|
|
135
139
|
upsertNetworkEvent,
|
|
140
|
+
upsertSaleEvent,
|
|
136
141
|
} = require('../schemas/definitions/gls-spain-integration-events');
|
|
137
142
|
const {
|
|
138
143
|
representative,
|
|
@@ -162,6 +167,17 @@ const {
|
|
|
162
167
|
} = require('../schemas/definitions/zones');
|
|
163
168
|
const { integration, findIntegrationsRequest, findIntegrationsResponse } = require('../schemas/definitions/integrations');
|
|
164
169
|
const { historicRecord, findHistoricRecordsRequest, findHistoricRecordsResponse } = require('../schemas/definitions/historic-records');
|
|
170
|
+
const {
|
|
171
|
+
sale,
|
|
172
|
+
createSaleRequest,
|
|
173
|
+
createSaleResponse,
|
|
174
|
+
findSalesSuperAdminRequest,
|
|
175
|
+
findSalesNetworkAdminRequest,
|
|
176
|
+
findSalesShopUserRequest,
|
|
177
|
+
findSalesResponse,
|
|
178
|
+
checkSalePriceRequest,
|
|
179
|
+
checkSalePriceResponse,
|
|
180
|
+
} = require('../schemas/definitions/sales');
|
|
165
181
|
|
|
166
182
|
const openApiSpec = { openapi: '3.0.2' };
|
|
167
183
|
|
|
@@ -198,36 +214,20 @@ openApiSpec.servers = [
|
|
|
198
214
|
openApiSpec['x-tagGroups'] = [
|
|
199
215
|
{
|
|
200
216
|
name: '',
|
|
201
|
-
tags: ['Introduction', 'Errors', 'Data formats'],
|
|
217
|
+
tags: ['Introduction', 'Errors', 'Deleting', 'Data formats', 'Historic records introduction'],
|
|
202
218
|
},
|
|
203
219
|
{
|
|
204
|
-
name: '
|
|
220
|
+
name: 'BACKGROUND PROCESSES',
|
|
205
221
|
tags: [
|
|
206
|
-
'
|
|
207
|
-
'
|
|
208
|
-
'
|
|
209
|
-
'
|
|
210
|
-
'
|
|
211
|
-
'
|
|
212
|
-
'
|
|
213
|
-
'Shop',
|
|
214
|
-
'Shop user',
|
|
215
|
-
'Expedition',
|
|
216
|
-
'Pod',
|
|
222
|
+
'Types of background processes',
|
|
223
|
+
'Eventual consistency',
|
|
224
|
+
'Expeditions expiration',
|
|
225
|
+
'GLS Spain integration',
|
|
226
|
+
'GLS International integration',
|
|
227
|
+
'GLS SMS integration',
|
|
228
|
+
'Ingenico integration',
|
|
217
229
|
],
|
|
218
230
|
},
|
|
219
|
-
{
|
|
220
|
-
name: 'HISTORIC RECORDS',
|
|
221
|
-
tags: ['Historic records introduction'],
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
name: 'BACKGROUND WORK',
|
|
225
|
-
tags: ['Background work', 'Eventual consistency', 'Expeditions expiration'],
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
name: 'INTEGRATIONS',
|
|
229
|
-
tags: ['Integrations introduction', 'GLS Spain'],
|
|
230
|
-
},
|
|
231
231
|
{
|
|
232
232
|
name: 'ENDPOINTS',
|
|
233
233
|
tags: [
|
|
@@ -243,6 +243,7 @@ openApiSpec['x-tagGroups'] = [
|
|
|
243
243
|
'Shop users',
|
|
244
244
|
'Expeditions',
|
|
245
245
|
'Pods',
|
|
246
|
+
'Sales',
|
|
246
247
|
'Historic records',
|
|
247
248
|
'Integrations',
|
|
248
249
|
],
|
|
@@ -255,29 +256,27 @@ openApiSpec.tags = [
|
|
|
255
256
|
description: `
|
|
256
257
|
This is the API for managing GLS parcel shops, which are establishments that can store packages for the customers to pick up.
|
|
257
258
|
|
|
258
|
-
Parcel shops are grouped by networks, which are the companies or associations that have a deal with GLS to use their
|
|
259
|
-
|
|
259
|
+
Parcel shops are grouped by networks, which are the companies or associations that have a deal with GLS to use their establishments as
|
|
260
|
+
parcel shops.
|
|
260
261
|
|
|
261
262
|
The API can be used by 3 kinds of users:
|
|
262
263
|
|
|
263
264
|
- Super admins: these are the GLS staff that manage the entire API. They can:
|
|
264
265
|
|
|
265
266
|
- Manage all kinds of users, including other super admins.
|
|
266
|
-
- Manage networks.
|
|
267
|
-
- Manage shops from any network.
|
|
267
|
+
- Manage networks, zones, representatives, historic records and integrations.
|
|
268
|
+
- Manage shops, expeditions and sales from any network.
|
|
268
269
|
|
|
269
270
|
- Network admins: these are the managers of a single network. They can:
|
|
270
271
|
|
|
271
|
-
- Manage shops from their network.
|
|
272
|
+
- Manage shops, expeditions and sales from their network.
|
|
272
273
|
- Manage their shop users.
|
|
273
274
|
|
|
274
275
|
- Shop users: these are the staff that work at the parcel shops. They can:
|
|
275
276
|
|
|
276
277
|
- View the shop inventory.
|
|
277
|
-
- Receive
|
|
278
|
-
-
|
|
279
|
-
- Receive returns from customers.
|
|
280
|
-
- Give returns to GLS drivers.
|
|
278
|
+
- Receive and deliver packages.
|
|
279
|
+
- Sell delivery services to people.
|
|
281
280
|
- etc...
|
|
282
281
|
|
|
283
282
|
Every endpoint of this documentation has a caption before its name indicating who can use it: **[S]** for super admins,
|
|
@@ -301,6 +300,16 @@ An endpoint can return more than one error with the same HTTP status, e.g.:
|
|
|
301
300
|
- \`500 UserCannotBeDeletedError\`.
|
|
302
301
|
|
|
303
302
|
You will need to look at the name to differentiate them.`,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'Deleting',
|
|
306
|
+
description: `
|
|
307
|
+
All resources have a \`deletable\` field that indicates if they can be deleted. It starts as \`true\` when the resource is created and it
|
|
308
|
+
changes to \`false\` when it is referenced as a dependency by another resource. Once changed it never changes back to \`true\`, even if the
|
|
309
|
+
dependent is deleted.
|
|
310
|
+
|
|
311
|
+
Trying to delete a non deletable resource will throw a deletion error, for example \`500 ShopCannotBeDeletedError\` when it is a shop.
|
|
312
|
+
`,
|
|
304
313
|
},
|
|
305
314
|
{
|
|
306
315
|
name: 'Data formats',
|
|
@@ -308,7 +317,7 @@ You will need to look at the name to differentiate them.`,
|
|
|
308
317
|
The API follows the [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md)
|
|
309
318
|
and the [JSON Schema draft 7 standard](https://json-schema.org/understanding-json-schema/index.html) for data types.
|
|
310
319
|
|
|
311
|
-
There are
|
|
320
|
+
There are three string formats that require special consideration: \`uuid\`, \`date-time\` and \`timezone\`.
|
|
312
321
|
|
|
313
322
|
#### Strings with uuid format
|
|
314
323
|
|
|
@@ -340,167 +349,39 @@ The full list of allowed timezone names is:
|
|
|
340
349
|
|
|
341
350
|
<SchemaDefinition schemaRef="#/components/schemas/timezoneNames" />
|
|
342
351
|
`,
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
name: 'Defaults',
|
|
346
|
-
description: `
|
|
347
|
-
The API has some default settings for networks and shops that do not specify their own, like the rate prices for deliveries and pickups,
|
|
348
|
-
the maximum number of days that an expedition can be in a shop before returning it, etc.
|
|
349
|
-
|
|
350
|
-
Super administrators can view and update this default settings using the [config](#tag/Config) endpoints.
|
|
351
|
-
|
|
352
|
-
<SchemaDefinition schemaRef="#/components/schemas/defaults" />`,
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
name: 'Counters',
|
|
356
|
-
description: `
|
|
357
|
-
Some of the API resources have fields that are auto incremental values. The API keeps a counter for each of these fields to know what the
|
|
358
|
-
next value to use is.
|
|
359
|
-
|
|
360
|
-
Super administrators can view the last values used for each auto incremental field using the [config](#tag/Config) endpoints.
|
|
361
|
-
|
|
362
|
-
<SchemaDefinition schemaRef="#/components/schemas/counters" />`,
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
name: 'Super admin',
|
|
366
|
-
description: `
|
|
367
|
-
Super administrators can manage all the resources of the API.
|
|
368
|
-
|
|
369
|
-
An initial super administrator is created when the API is deployed (see [config](#tag/Config)) and then that super administrator
|
|
370
|
-
can create additional super administrators using the [super admins](#tag/Super-admins) endpoints.
|
|
371
|
-
|
|
372
|
-
<SchemaDefinition schemaRef="#/components/schemas/superAdmin" />`,
|
|
373
|
-
},
|
|
374
|
-
{
|
|
375
|
-
name: 'Network',
|
|
376
|
-
description: `
|
|
377
|
-
Networks represent the providers of parcel shops, e.g. the companies or associations that have a deal with GLS to use
|
|
378
|
-
their establishments as parcel shops. Every parcel shop belongs to a single network.
|
|
379
|
-
|
|
380
|
-
Super administrators can manage networks using the [networks](#tag/Networks) endpoints.
|
|
381
|
-
|
|
382
|
-
<SchemaDefinition schemaRef="#/components/schemas/network" />`,
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
name: 'Network admin',
|
|
386
|
-
description: `
|
|
387
|
-
Network administrators are associated with a single network and they can view the parcel shops that belong to their network.
|
|
388
|
-
|
|
389
|
-
Super administrators can manage network administrators using the [network admins](#tag/Network-admins) endpoints.
|
|
390
|
-
|
|
391
|
-
<SchemaDefinition schemaRef="#/components/schemas/networkAdmin" />`,
|
|
392
|
-
},
|
|
393
|
-
{
|
|
394
|
-
name: 'Zone',
|
|
395
|
-
description: `
|
|
396
|
-
Zones are geographic areas that define the commissions that the sales representatives earn for their work on the shops in those areas.
|
|
397
|
-
|
|
398
|
-
Super administrators can create and manage zones using the [zones](#tag/Zones) endpoints, and then associate them to parcel shops and sales
|
|
399
|
-
representatives on creation or update.
|
|
400
|
-
|
|
401
|
-
<SchemaDefinition schemaRef="#/components/schemas/zone" />`,
|
|
402
|
-
},
|
|
403
|
-
{
|
|
404
|
-
name: 'Sales representative',
|
|
405
|
-
description: `
|
|
406
|
-
Sales representatives are the GLS staff that make deals with businesses to open establishments as parcel shops. Each parcel shop
|
|
407
|
-
in the API has two representatives associated to it: the one that made the deal to open the shop and the one that is currently
|
|
408
|
-
managing it.
|
|
409
|
-
|
|
410
|
-
Super administrators can create and manage sales representatives using the [sales representatives](#tag/Sales-representatives)
|
|
411
|
-
endpoints, and then associate them to parcel shops on creation or update.
|
|
412
|
-
|
|
413
|
-
<SchemaDefinition schemaRef="#/components/schemas/representative" />`,
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
name: 'Shop',
|
|
417
|
-
description: `
|
|
418
|
-
Parcel shops are the establishments that GLS and the customers can use to deliver and pickup expeditions instead of doing
|
|
419
|
-
it at the customers home.
|
|
420
|
-
|
|
421
|
-
Every parcel shop is associated to a network, and it must have at least one shop user associated to it for the parcel
|
|
422
|
-
shop to function.
|
|
423
|
-
|
|
424
|
-
Super administrators can manage shops from any network and network administrators can view shops from their own network
|
|
425
|
-
using the [shops](#tag/Shops) endpoints.
|
|
426
|
-
|
|
427
|
-
<SchemaDefinition schemaRef="#/components/schemas/shop" />`,
|
|
428
|
-
},
|
|
429
|
-
{
|
|
430
|
-
name: 'Shop user',
|
|
431
|
-
description: `
|
|
432
|
-
Shop users are associated with a single shop and they have limited capabilities to manage the shop and its expeditions,
|
|
433
|
-
e.g. they can edit some of the shop properties or receive and deliver expeditions, but not edit anything else about them.
|
|
434
|
-
|
|
435
|
-
Super administrators can manage shop users from any network and network administrators can view shop users from their
|
|
436
|
-
own network using the [shop users](#tag/Shop-users) endpoints.
|
|
437
|
-
|
|
438
|
-
<SchemaDefinition schemaRef="#/components/schemas/shopUser" />`,
|
|
439
|
-
},
|
|
440
|
-
{
|
|
441
|
-
name: 'Expedition',
|
|
442
|
-
description: `
|
|
443
|
-
Expeditions are the packages that are delivered and picked up at parcel shops.
|
|
444
|
-
|
|
445
|
-
Super administrators can manage expeditions using the [expeditions](#tag/Expeditions) endpoints. Shop users can also use
|
|
446
|
-
some of those endpoints to receive and give expeditions from and to GLS and customers.
|
|
447
|
-
|
|
448
|
-
<SchemaDefinition schemaRef="#/components/schemas/expedition" />`,
|
|
449
|
-
},
|
|
450
|
-
{
|
|
451
|
-
name: 'Pod',
|
|
452
|
-
description: `
|
|
453
|
-
Expeditions that have been picked up by or delivered to a customer have a POD (Proof Of Delivery) associated to them that contains the
|
|
454
|
-
signature of the customer.
|
|
455
|
-
|
|
456
|
-
Pods are created automatically by the API when an expedition is picked up by or delivered to a customer.
|
|
457
|
-
|
|
458
|
-
Super administrators, network administrators and shop users can use the [pods](#tag/Pods) endpoints to find the pods of the
|
|
459
|
-
expeditions they have access to.
|
|
460
|
-
|
|
461
|
-
<SchemaDefinition schemaRef="#/components/schemas/pod" />`,
|
|
462
352
|
},
|
|
463
353
|
{
|
|
464
354
|
name: 'Historic records introduction',
|
|
465
355
|
'x-displayName': 'Historic records',
|
|
466
356
|
description: `
|
|
467
|
-
Every time the API creates, updates or deletes a resource it
|
|
468
|
-
the action, the time it occurred and the user that made it.
|
|
469
|
-
|
|
470
|
-
The only exception are \`pods\` which have no records because they are created when their expeditions are delivered and they are never
|
|
471
|
-
updated. They are also never deleted because they need to remain accessible via the historic records of expeditions.
|
|
357
|
+
Every time the API creates, updates or deletes a resource it creates a historic record that stores the action taken (create, update, or
|
|
358
|
+
delete), the full document as it was after the action, the time it occurred and the user that made it.
|
|
472
359
|
|
|
473
360
|
These historic records serve two purposes:
|
|
474
361
|
|
|
475
|
-
- They allow to track the full history of a
|
|
476
|
-
- They are the basis for the [
|
|
477
|
-
|
|
478
|
-
The \`actionKeys\` lists the paths of the updated fields for an \`update\` action. The depth of the paths may vary:
|
|
479
|
-
|
|
480
|
-
- Usually it is just the root key, for example an update of any field in a shop address is just \`address\`.
|
|
481
|
-
- Some updated are more specific, for example delivering an expedition is \`status.code\` and \`status.givenTo\`.
|
|
362
|
+
- They allow to track the full history of a resource.
|
|
363
|
+
- They are the basis for the [background processes](#tag/Types-of-background-processes) of the API.
|
|
482
364
|
|
|
483
|
-
|
|
484
|
-
their values the result of that integration for that record.
|
|
485
|
-
|
|
486
|
-
Super administrators can search the historic records using the [historic records](#tag/Historic-records) endpoints.
|
|
487
|
-
|
|
488
|
-
<SchemaDefinition schemaRef="#/components/schemas/historicRecord" />`,
|
|
365
|
+
See the [historic records](#tag/Historic-records) endpoints for more information.`,
|
|
489
366
|
},
|
|
490
367
|
{
|
|
491
|
-
name: '
|
|
368
|
+
name: 'Types of background processes',
|
|
492
369
|
description: `
|
|
493
|
-
|
|
494
|
-
|
|
370
|
+
The API runs two types of processes in the background:
|
|
371
|
+
|
|
372
|
+
- Some processes execute an action at regular time intervals.
|
|
373
|
+
- Some processes execute an action every time a new historic record is created.
|
|
374
|
+
|
|
375
|
+
This section explains what each kind of background process does.`,
|
|
495
376
|
},
|
|
496
377
|
{
|
|
497
378
|
name: 'Eventual consistency',
|
|
498
379
|
description: `
|
|
499
|
-
|
|
500
|
-
|
|
380
|
+
When one resource depends on another it stores the \`_id\` of its dependency, for example each shop stores the network it belongs to in
|
|
381
|
+
its \`network._id\` field.
|
|
501
382
|
|
|
502
|
-
|
|
503
|
-
|
|
383
|
+
When a resource also needs other fields of its dependency very often it makes sense to store them with the \`_id\`, for example each shop
|
|
384
|
+
also stores the name of its network in its \`network.name\` field.
|
|
504
385
|
|
|
505
386
|
This is called denormalization and it saves a lot of queries for the full dependency each time these fields are needed. The downside is
|
|
506
387
|
that an update in the dependency requires updating the dependents too. There are two strategies to do this:
|
|
@@ -510,64 +391,53 @@ are thousands or millions of dependents.
|
|
|
510
391
|
- **Eventual consistency**: only the dependency is updated immediately, and the dependents are updated later in the background. The update
|
|
511
392
|
endpoint returns very fast but for a few seconds the dependents are outdated.
|
|
512
393
|
|
|
513
|
-
|
|
514
|
-
|
|
394
|
+
The API runs an eventual consistency background process that watches the historic records. When a record updates the appropriate field in
|
|
395
|
+
a dependency, the background process updates also all the relevant dependents.`,
|
|
515
396
|
},
|
|
516
397
|
{
|
|
517
398
|
name: 'Expeditions expiration',
|
|
518
399
|
description: `
|
|
519
|
-
Delivery expeditions can only be in a shop for a certain amount of time before GLS returns them to the sender. This
|
|
400
|
+
Delivery expeditions can only be in a shop for a certain amount of time before GLS returns them to the sender. This time limit is
|
|
520
401
|
calculated when the expedition is received at a shop and stored in its \`status.expiration\` field.
|
|
521
402
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
The API periodically checks these moments and when the time comes it updates the expedition and stores an historic record of the update. It
|
|
526
|
-
is then the responsibility of some integration to respond to that historic record. See [integrations](#tag/Integrations-introduction)
|
|
527
|
-
for more information.`,
|
|
528
|
-
},
|
|
529
|
-
{
|
|
530
|
-
name: 'Integrations introduction',
|
|
531
|
-
'x-displayName': 'Integrations',
|
|
532
|
-
description: `
|
|
533
|
-
Some of the background work of this API are integrations with other systems. These integrations work by scanning the historic records in
|
|
534
|
-
chronological order and deciding what to do for each one, if anything. The integrations store their results in the \`integrations\` field
|
|
535
|
-
of each record.
|
|
536
|
-
|
|
537
|
-
Super administrators can search the historic records by integration name and result to find for example those records where the integration
|
|
538
|
-
failed and why. See the [historic records](#tag/Historic-records) endpoints for more information.
|
|
403
|
+
There are two values that need to be checked periodically: a list of moments when the customer needs to be reminded to pick up the
|
|
404
|
+
expedition, and the moment the expedition expires.
|
|
539
405
|
|
|
540
|
-
|
|
541
|
-
what networks it applies to:
|
|
406
|
+
The API runs two background processes that check these two values at regular intervals:
|
|
542
407
|
|
|
543
|
-
|
|
408
|
+
- One process checks when a reminder has expired and updates the expedition, moving said reminder from
|
|
409
|
+
\`status.expiration.pendingReminders\` to \`status.expiration.sentReminders\`.
|
|
410
|
+
- The other process checks when an expedition has expired and updates its \`status.code\` to \`expired\`.
|
|
544
411
|
|
|
545
|
-
|
|
412
|
+
Both processes only update an expedition and create the appropriate historic record. It is then the responsibility of other background
|
|
413
|
+
processes to do something in response to those historic records being created.`,
|
|
546
414
|
},
|
|
547
415
|
{
|
|
548
|
-
name: 'GLS Spain',
|
|
416
|
+
name: 'GLS Spain integration',
|
|
549
417
|
description: `
|
|
550
|
-
|
|
418
|
+
The API is integrated with the main systems of GLS Spain. The integration goes in both directions:
|
|
551
419
|
|
|
552
|
-
- GLS Spain has a super admin user to access
|
|
553
|
-
-
|
|
420
|
+
- GLS Spain has a super admin user to access the API and manage its resources, e.g. creating expeditions.
|
|
421
|
+
- The API runs a background process that watches the historic records and sends events to GLS.
|
|
554
422
|
|
|
555
423
|
This integration configuration can be found using the [find integrations endpoint](#tag/Integrations/paths/~1integrations~1find/post),
|
|
556
|
-
under the \`
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
|
562
|
-
|
|
|
563
|
-
| upsert
|
|
564
|
-
|
|
|
565
|
-
|
|
|
566
|
-
|
|
|
567
|
-
|
|
|
568
|
-
|
|
|
569
|
-
|
|
|
570
|
-
|
|
|
424
|
+
under the \`glsSpain\` name. Its \`networks\` field lists the networks that the shops, expeditions and sales must belong to for the events
|
|
425
|
+
to be sent. All other networks are ignored.
|
|
426
|
+
|
|
427
|
+
The following table lists the events that are sent along with the historic records that causes them:
|
|
428
|
+
|
|
429
|
+
| Event | Historic record |
|
|
430
|
+
| :--- | :--- |
|
|
431
|
+
| upsert network | Network update |
|
|
432
|
+
| upsert shop | Shop create or update |
|
|
433
|
+
| upsert sale | Sale create or update |
|
|
434
|
+
| receive from driver | Expedition update (received from driver) |
|
|
435
|
+
| receive from customer | Expedition update (received from customer) |
|
|
436
|
+
| give to customer | Expedition update (given to customer) |
|
|
437
|
+
| give to driver | Expedition update (given to driver) |
|
|
438
|
+
| expiration reminder | Expedition update (reminder moved from pending to sent) |
|
|
439
|
+
| expired | Expedition update (status changed to expired) |
|
|
440
|
+
| price | Expedition update (received from driver or customer)<br/>Expedition update (price changed after reception) |
|
|
571
441
|
|
|
572
442
|
The following are the request bodies sent for each event:
|
|
573
443
|
|
|
@@ -583,6 +453,12 @@ Sent when a shop is created or updated.
|
|
|
583
453
|
|
|
584
454
|
<SchemaDefinition schemaRef="#/components/schemas/upsertShopEvent" />
|
|
585
455
|
|
|
456
|
+
## Upsert sale event
|
|
457
|
+
|
|
458
|
+
Sent when a sale is created or updated.
|
|
459
|
+
|
|
460
|
+
<SchemaDefinition schemaRef="#/components/schemas/upsertSaleEvent" />
|
|
461
|
+
|
|
586
462
|
## Receive from driver event
|
|
587
463
|
|
|
588
464
|
Sent when a shop receives an expedition from a driver.
|
|
@@ -609,22 +485,42 @@ Sent when a shop delivers an expedition to a driver.
|
|
|
609
485
|
|
|
610
486
|
## Expiration reminder event
|
|
611
487
|
|
|
612
|
-
Sent when
|
|
488
|
+
Sent when an expedition expiration reminder has been moved from pending to sent.
|
|
613
489
|
|
|
614
490
|
<SchemaDefinition schemaRef="#/components/schemas/expirationReminderEvent" />
|
|
615
491
|
|
|
616
492
|
## Expired event
|
|
617
493
|
|
|
618
|
-
Sent when
|
|
494
|
+
Sent when an expedtions status has been changed to expired.
|
|
619
495
|
|
|
620
496
|
<SchemaDefinition schemaRef="#/components/schemas/expiredEvent" />
|
|
621
497
|
|
|
622
498
|
## Price event
|
|
623
499
|
|
|
624
|
-
Sent for the first time when an expedition is received at a shop, and after that any time the
|
|
500
|
+
Sent for the first time when an expedition is received at a shop, and after that any time the price is updated.
|
|
625
501
|
|
|
626
502
|
<SchemaDefinition schemaRef="#/components/schemas/priceEvent" />`,
|
|
627
503
|
},
|
|
504
|
+
{
|
|
505
|
+
name: 'GLS International integration',
|
|
506
|
+
description: `
|
|
507
|
+
The API is integrated with the GLS International ParcelShop API in order to export the shops in this API to the international database.
|
|
508
|
+
|
|
509
|
+
There is a background process that watches the historic records and each time a shop is created, updated or deleted, it is sent to the
|
|
510
|
+
international API.
|
|
511
|
+
|
|
512
|
+
This integration configuration can be found using the [find integrations endpoint](#tag/Integrations/paths/~1integrations~1find/post),
|
|
513
|
+
under the \`glsInternationalExport\` name. Its \`networks\` field lists the networks that the shops must belong to for them to be reported
|
|
514
|
+
to the international API. All other networks are ignored.`,
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: 'GLS SMS integration', // todo
|
|
518
|
+
description: `TODO`,
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: 'Ingenico integration', // todo
|
|
522
|
+
description: `TODO`,
|
|
523
|
+
},
|
|
628
524
|
{
|
|
629
525
|
name: 'Authentication',
|
|
630
526
|
description: `
|
|
@@ -650,68 +546,107 @@ The endpoints that require so will indicate it in their description.`,
|
|
|
650
546
|
{ name: 'Documentation' },
|
|
651
547
|
{
|
|
652
548
|
name: 'Config',
|
|
653
|
-
description: `API
|
|
549
|
+
description: `API global configuration.
|
|
550
|
+
|
|
551
|
+
This section contains the \`defaults\` object, which is a single object in the API that holds the configuration for:
|
|
552
|
+
|
|
553
|
+
- The derivation settings, which are the price rates for deliveries and pickups.
|
|
554
|
+
- The expiration settings, which include when do deliveries expire and when to send pickup reminders to the customers.
|
|
555
|
+
- The sales settings, which is the price table for sales based on the package size and destination.
|
|
654
556
|
|
|
655
|
-
|
|
557
|
+
The derivation and expiration settings can be overridden at the network and shop level if they need custom values other than the defaults.
|
|
656
558
|
|
|
657
|
-
|
|
658
|
-
|
|
559
|
+
The sales settings cannot be overridden at the network or shop levels. Instead, networks contain the percentages of the price that are paid
|
|
560
|
+
to the network and the shop.
|
|
659
561
|
|
|
660
|
-
|
|
562
|
+
This section also contains an endpoint to view the \`counters\` object, which keeps track of the last value used in each auto incremental
|
|
563
|
+
field used for any resource in the API.
|
|
661
564
|
|
|
662
|
-
|
|
663
|
-
- Network specific values: each network can have its custom settings, which override the default ones.
|
|
664
|
-
- Shop specific values: each shop can have its custom settings, which override the network and default ones.
|
|
565
|
+
## Defaults schema
|
|
665
566
|
|
|
666
|
-
|
|
567
|
+
<SchemaDefinition schemaRef="#/components/schemas/defaults" />
|
|
568
|
+
|
|
569
|
+
## Counters schema
|
|
570
|
+
|
|
571
|
+
<SchemaDefinition schemaRef="#/components/schemas/counters" />`,
|
|
667
572
|
},
|
|
668
573
|
{
|
|
669
574
|
name: 'Super admins',
|
|
670
575
|
description: `Create and manage super admins.
|
|
671
576
|
|
|
672
|
-
Super
|
|
577
|
+
Super administrators can manage all the resources of the API.
|
|
578
|
+
|
|
579
|
+
An initial super admin is created when the API is deployed and then that super admin can create additional super admins.
|
|
580
|
+
|
|
581
|
+
## Super admin schema
|
|
582
|
+
|
|
583
|
+
<SchemaDefinition schemaRef="#/components/schemas/superAdmin" />
|
|
584
|
+
`,
|
|
673
585
|
},
|
|
674
586
|
{
|
|
675
587
|
name: 'Networks',
|
|
676
588
|
description: `Create and manage networks.
|
|
677
589
|
|
|
678
|
-
Networks
|
|
590
|
+
Networks represent the providers of parcel shops, e.g. the companies or associations that have a deal with GLS to use their establishments
|
|
591
|
+
as parcel shops. Every parcel shop belongs to a single network.
|
|
679
592
|
|
|
680
|
-
A network that has
|
|
681
|
-
|
|
593
|
+
A network that has its \`readonly\` property set to \`true\` cannot be updated or have shops added to it. Readonly networks usually have
|
|
594
|
+
their shops come from an integration.
|
|
682
595
|
|
|
683
596
|
A network may have custom derivation and expiration settings or use the defaults defined in [config](#tag/Config):
|
|
684
597
|
|
|
685
598
|
- If it has \`derivationSettings\` or \`expirationSettings\` properties it means it has custom settings.
|
|
686
599
|
- If not, then the values in its \`defaults\` property will be used, which are a copy of the default values.
|
|
687
|
-
|
|
688
|
-
See [create](#tag/Networks/paths/~1networks~1create/post) and [update](#tag/Networks/paths/~1networks~1update/post) on
|
|
689
|
-
how to set or remove the custom properties.
|
|
690
600
|
|
|
691
|
-
|
|
601
|
+
## Network schema
|
|
602
|
+
|
|
603
|
+
<SchemaDefinition schemaRef="#/components/schemas/network" />`,
|
|
692
604
|
},
|
|
693
605
|
{
|
|
694
606
|
name: 'Network admins',
|
|
695
607
|
description: `Create and manage network admins.
|
|
696
608
|
|
|
697
|
-
Network admins are associated to a
|
|
609
|
+
Network admins are associated to a single network and can view its resources, like their shops and shop users.
|
|
610
|
+
|
|
611
|
+
## Network admin schema
|
|
612
|
+
|
|
613
|
+
<SchemaDefinition schemaRef="#/components/schemas/networkAdmin" />`,
|
|
698
614
|
},
|
|
699
615
|
{
|
|
700
616
|
name: 'Zones',
|
|
701
617
|
description: `Create and manage zones.
|
|
702
618
|
|
|
703
619
|
Zones define geographic areas that both the shops and the sales representatives are associated to. They define the commissions the sales
|
|
704
|
-
representatives earn for the shops they open or manage.
|
|
705
|
-
|
|
620
|
+
representatives earn for the shops they open or manage in that area.
|
|
621
|
+
|
|
622
|
+
## Zone schema
|
|
623
|
+
|
|
624
|
+
<SchemaDefinition schemaRef="#/components/schemas/zone" />`,
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
name: 'Sales representatives',
|
|
628
|
+
description: `Create and manage sales representatives.
|
|
629
|
+
|
|
630
|
+
Sales representatives are the GLS staff that make deals with businesses to open establishments as parcel shops. Each parcel shop in the API
|
|
631
|
+
has two representatives associated to it: the one that made the deal to open the shop and the one that is currently managing it. They can
|
|
632
|
+
be the same representative.
|
|
633
|
+
|
|
634
|
+
## Sales representative schema
|
|
635
|
+
|
|
636
|
+
<SchemaDefinition schemaRef="#/components/schemas/representative" />`,
|
|
706
637
|
},
|
|
707
638
|
{
|
|
708
639
|
name: 'Shops',
|
|
709
640
|
description: `Create and manage shops.
|
|
710
641
|
|
|
711
|
-
|
|
642
|
+
Parcel shops are the establishments that GLS and the customers can use to deliver and pickup expeditions instead of doing
|
|
643
|
+
it at the customers home.
|
|
712
644
|
|
|
713
|
-
|
|
714
|
-
|
|
645
|
+
Every parcel shop is associated to a network on creation, and it must have at least one shop user associated to it for the parcel
|
|
646
|
+
shop to function.
|
|
647
|
+
|
|
648
|
+
A shop that has its \`readonly\` property set to \`true\` cannot be updated or have expeditions added to it. Readonly shops usually come
|
|
649
|
+
from an integration.
|
|
715
650
|
|
|
716
651
|
A shop may have custom derivation and expiration settings, use its network values or use the defaults defined in [config](#tag/Config):
|
|
717
652
|
|
|
@@ -720,9 +655,6 @@ A shop may have custom derivation and expiration settings, use its network value
|
|
|
720
655
|
- If it doesn't have settings in its \`network\` property then the values in its \`defaults\` property will be used, which are a copy of
|
|
721
656
|
the default values.
|
|
722
657
|
|
|
723
|
-
See [create](#tag/Shops/paths/~1shops~1create/post) and [update](#tag/Shops/paths/~1shops~1update/post) on how to set or remove
|
|
724
|
-
the custom properties.
|
|
725
|
-
|
|
726
658
|
### Status
|
|
727
659
|
|
|
728
660
|
A shop can be enabled or disabled as indicated by its \`status.code\` property. This property cannot be set directly,
|
|
@@ -734,30 +666,34 @@ instead its value depends on the other \`status\` properties:
|
|
|
734
666
|
| X | √ | \`disabled\` |
|
|
735
667
|
| X | X | \`enabled\` |
|
|
736
668
|
|
|
737
|
-
|
|
669
|
+
## Shop schema
|
|
670
|
+
|
|
671
|
+
<SchemaDefinition schemaRef="#/components/schemas/shop" />`,
|
|
738
672
|
},
|
|
739
673
|
{
|
|
740
674
|
name: 'Shop users',
|
|
741
675
|
description: `Create and manage shop users.
|
|
742
676
|
|
|
743
|
-
Shop users are associated with a single shop and they have limited capabilities to manage the shop and
|
|
677
|
+
Shop users are associated with a single shop and they have limited capabilities to manage the shop expeditions, e.g. they can receive and
|
|
678
|
+
deliver expeditions, but not edit anything else about them.
|
|
679
|
+
|
|
680
|
+
## Shop user schema
|
|
681
|
+
|
|
682
|
+
<SchemaDefinition schemaRef="#/components/schemas/shopUser" />`,
|
|
744
683
|
},
|
|
745
684
|
{
|
|
746
685
|
name: 'Expeditions',
|
|
747
686
|
description: `Create and manage expeditions.
|
|
748
687
|
|
|
749
|
-
Expeditions are the packages that are delivered and picked up
|
|
750
|
-
|
|
751
|
-
An expedition that has pods associated to it will have its \`deletable\` property automatically set to \`false\` and cannot be deleted.
|
|
688
|
+
Expeditions are the packages that are delivered and picked up at parcel shops.
|
|
752
689
|
|
|
753
690
|
### Types
|
|
754
691
|
|
|
755
|
-
There are
|
|
692
|
+
There are 2 kinds of expeditions, indicated in its \`type\` property:
|
|
756
693
|
|
|
757
|
-
- \`delivery\`:
|
|
758
|
-
- \`pickup\`:
|
|
759
|
-
|
|
760
|
-
at the parcel shop for a driver to retrieve it later.
|
|
694
|
+
- \`delivery\`: when a driver leaves an expedition at a parcel shop for the customer to retrieve it later.
|
|
695
|
+
- \`pickup\`: when a customer leaves an expedition at a parcel shop for the driver to retrieve it later. It can be because of a return or
|
|
696
|
+
a sale.
|
|
761
697
|
|
|
762
698
|
### Status
|
|
763
699
|
|
|
@@ -769,9 +705,8 @@ The \`status.code\` property of an expedition indicates the situation of an expe
|
|
|
769
705
|
The expedition is then scheduled to be given to the driver to return it to the original sender.
|
|
770
706
|
- \`delivered\`: the final status for any expedition, meaning that it has been given to the customer or driver and is no longer in the parcel shop.
|
|
771
707
|
|
|
772
|
-
The \`status\` of an expedition cannot be updated with a regular [update](#tag/Expeditions/paths/~1expeditions~1update/post)
|
|
773
|
-
|
|
774
|
-
\`status\` properties:
|
|
708
|
+
The \`status\` of an expedition cannot be updated with a regular [update](#tag/Expeditions/paths/~1expeditions~1update/post) because it has
|
|
709
|
+
a predetermined life cycle. The following endpoints update an expedition status and add or remove additional \`status\` properties:
|
|
775
710
|
|
|
776
711
|
| Operation | Type | From status | To status | New status properties |
|
|
777
712
|
| :--- | :--- | :--- | :--- | :--- |
|
|
@@ -782,25 +717,70 @@ because it has a predetermined life cycle. The following endpoints update an exp
|
|
|
782
717
|
| [giveToDriver](#tag/Expeditions/paths/~1expeditions~1giveToDriver/post) | delivery<br/>pickup | inShopExpired<br/>inShop | delivered<br/>delivered | givenTo<br/>givenTo |
|
|
783
718
|
| [redirect](#tag/Expeditions/paths/~1expeditions~1redirect/post) | any | any | incoming | clear everything |
|
|
784
719
|
|
|
785
|
-
|
|
720
|
+
## Expedition schema
|
|
721
|
+
|
|
722
|
+
<SchemaDefinition schemaRef="#/components/schemas/expedition" />`,
|
|
786
723
|
},
|
|
787
724
|
{
|
|
788
725
|
name: 'Pods',
|
|
789
|
-
description: `Find expeditions PODS (Proof Of Delivery)
|
|
726
|
+
description: `Find expeditions PODS (Proof Of Delivery).
|
|
727
|
+
|
|
728
|
+
When an expedition is picked up by a customer or delivered to a customer, the API will automatically create a POD with the customer
|
|
729
|
+
signature and reference the POD from the expedition \`status.receivedFrom.customer.pod\` or \`status.givenTo.customer.pod\` fields.
|
|
730
|
+
|
|
731
|
+
PODs are never updated or deleted even if their expedition is deleted, since they still need to be accessed from that expedition historic
|
|
732
|
+
records. Since they are part of their expedition historic records, PODs do not have historic records on their own.
|
|
733
|
+
|
|
734
|
+
## Pod schema
|
|
735
|
+
|
|
736
|
+
<SchemaDefinition schemaRef="#/components/schemas/pod" />`,
|
|
790
737
|
},
|
|
791
738
|
{
|
|
792
|
-
name: 'Sales
|
|
793
|
-
description: `Create and
|
|
739
|
+
name: 'Sales', // todo
|
|
740
|
+
description: `Create and find sales.
|
|
741
|
+
|
|
742
|
+
Customers can go to a parcel shop at any time and pay to have a package sent to an allowed destination.
|
|
743
|
+
|
|
744
|
+
The allowed destinations and the price of the service can be found in the [\`defaults\` object](#tag/Config/paths/~1config~1defaults~1get/get).
|
|
745
|
+
|
|
746
|
+
The process for a sale is the following:
|
|
794
747
|
|
|
795
|
-
|
|
748
|
+
- A shop user creates a sale by asking the customer for the destination and sender personal data, package size, etc.
|
|
749
|
+
- The API will use the Ingenico integration to prepare the payment and send the customer an SMS with a link where he can pay for the service.
|
|
750
|
+
- If Ingenico responds that the customer has paid the API will use the GLS Spain integration to notify GLS of the new sale.
|
|
751
|
+
- GLS Spain will then create a pickup expedition associated to the sale which will be picked up by a driver.
|
|
752
|
+
|
|
753
|
+
## Sale schema
|
|
754
|
+
|
|
755
|
+
<SchemaDefinition schemaRef="#/components/schemas/sale" />`,
|
|
796
756
|
},
|
|
797
757
|
{
|
|
798
758
|
name: 'Historic records',
|
|
799
|
-
description: `Find historic records
|
|
759
|
+
description: `Find historic records.
|
|
760
|
+
|
|
761
|
+
The \`actionKeys\` field lists the paths of the updated fields for an \`update\` action. The depth of the paths may vary:
|
|
762
|
+
|
|
763
|
+
- Usually it is just the keys at the root of the document, for example an update of any field in a shop address is just \`address\`.
|
|
764
|
+
- Some updates are more specific, for example delivering an expedition is \`status.code\` and \`status.givenTo\`.
|
|
765
|
+
|
|
766
|
+
The \`integrations\` field is where each integration stores what it did with the historic record. Its properties are the names of the
|
|
767
|
+
integrations and their values the result of that integration for that historic record.
|
|
768
|
+
|
|
769
|
+
## Historic record schema
|
|
770
|
+
|
|
771
|
+
<SchemaDefinition schemaRef="#/components/schemas/historicRecord" />`,
|
|
800
772
|
},
|
|
801
773
|
{
|
|
802
774
|
name: 'Integrations',
|
|
803
|
-
description: `Find integrations configurations
|
|
775
|
+
description: `Find integrations configurations.
|
|
776
|
+
|
|
777
|
+
Some of the background work of this API are integrations with other systems. These integrations work by scanning the historic records in
|
|
778
|
+
chronological order and deciding what to do for each one, if anything. The integrations store their results in the \`integrations\` field
|
|
779
|
+
of each record.
|
|
780
|
+
|
|
781
|
+
## Integration schema
|
|
782
|
+
|
|
783
|
+
<SchemaDefinition schemaRef="#/components/schemas/integration" />`,
|
|
804
784
|
},
|
|
805
785
|
];
|
|
806
786
|
|
|
@@ -846,9 +826,11 @@ const errors = {
|
|
|
846
826
|
userCannotBeDeleted: new UserCannotBeDeletedError(),
|
|
847
827
|
networkDoesNotExist: new NetworkDoesNotExistError(),
|
|
848
828
|
networkAlreadyExists: new NetworkAlreadyExistsError(),
|
|
829
|
+
networkCannotBeUpdated: new NetworkCannotBeUpdatedError(),
|
|
849
830
|
networkCannotBeDeleted: new NetworkCannotBeDeletedError(),
|
|
850
831
|
shopDoesNotExist: new ShopDoesNotExistError(),
|
|
851
832
|
shopAlreadyExists: new ShopAlreadyExistsError(),
|
|
833
|
+
shopCannotBeUpdated: new ShopCannotBeUpdatedError(),
|
|
852
834
|
shopCannotBeDeleted: new ShopCannotBeDeletedError(),
|
|
853
835
|
shopNotEnabled: new ShopNotEnabledError(),
|
|
854
836
|
wrongPassword: new WrongPasswordError(),
|
|
@@ -864,6 +846,9 @@ const errors = {
|
|
|
864
846
|
zoneDoesNotExist: new ZoneDoesNotExistError(),
|
|
865
847
|
zoneAlreadyExists: new ZoneAlreadyExistsError(),
|
|
866
848
|
zoneCannotBeDeleted: new ZoneCannotBeDeletedError(),
|
|
849
|
+
saleAlreadyExists: new SaleAlreadyExistsError(),
|
|
850
|
+
inconsistentSalesSettings: new InconsistentSalesSettingsError(),
|
|
851
|
+
invalidSaleDestination: new InvalidSaleDestinationError(),
|
|
867
852
|
};
|
|
868
853
|
|
|
869
854
|
const responses = {
|
|
@@ -931,6 +916,10 @@ const responses = {
|
|
|
931
916
|
description: 'The network already exists.',
|
|
932
917
|
content: { 'application/json': { schema: specificHttpError(errors.networkAlreadyExists) } },
|
|
933
918
|
},
|
|
919
|
+
networkCannotBeUpdated: {
|
|
920
|
+
description: 'The network cannot be updated.',
|
|
921
|
+
content: { 'application/json': { schema: specificHttpError(errors.networkCannotBeUpdated) } },
|
|
922
|
+
},
|
|
934
923
|
networkCannotBeDeleted: {
|
|
935
924
|
description: 'The network cannot be deleted.',
|
|
936
925
|
content: { 'application/json': { schema: specificHttpError(errors.networkCannotBeDeleted) } },
|
|
@@ -943,6 +932,10 @@ const responses = {
|
|
|
943
932
|
description: 'The shop already exists.',
|
|
944
933
|
content: { 'application/json': { schema: specificHttpError(errors.shopAlreadyExists) } },
|
|
945
934
|
},
|
|
935
|
+
shopCannotBeUpdated: {
|
|
936
|
+
description: 'The shop cannot be updated.',
|
|
937
|
+
content: { 'application/json': { schema: specificHttpError(errors.shopCannotBeUpdated) } },
|
|
938
|
+
},
|
|
946
939
|
shopCannotBeDeleted: {
|
|
947
940
|
description: 'The shop cannot be deleted.',
|
|
948
941
|
content: { 'application/json': { schema: specificHttpError(errors.shopCannotBeDeleted) } },
|
|
@@ -1003,6 +996,18 @@ const responses = {
|
|
|
1003
996
|
description: 'The zone cannot be deleted.',
|
|
1004
997
|
content: { 'application/json': { schema: specificHttpError(errors.zoneCannotBeDeleted) } },
|
|
1005
998
|
},
|
|
999
|
+
saleAlreadyExists: {
|
|
1000
|
+
description: 'The sale already exists.',
|
|
1001
|
+
content: { 'application/json': { schema: specificHttpError(errors.saleAlreadyExists) } },
|
|
1002
|
+
},
|
|
1003
|
+
inconsistentSalesSettings: {
|
|
1004
|
+
description: 'The sales settings are inconsistent.',
|
|
1005
|
+
content: { 'application/json': { schema: specificHttpError(errors.inconsistentSalesSettings) } },
|
|
1006
|
+
},
|
|
1007
|
+
invalidSaleDestination: {
|
|
1008
|
+
description: 'The sale destination is invalid.',
|
|
1009
|
+
content: { 'application/json': { schema: specificHttpError(errors.invalidSaleDestination) } },
|
|
1010
|
+
},
|
|
1006
1011
|
};
|
|
1007
1012
|
|
|
1008
1013
|
const securitySchemes = {
|
|
@@ -1057,11 +1062,13 @@ openApiSpec.components = {
|
|
|
1057
1062
|
priceEvent: priceEvent(),
|
|
1058
1063
|
upsertShopEvent: upsertShopEvent(),
|
|
1059
1064
|
upsertNetworkEvent: upsertNetworkEvent(),
|
|
1065
|
+
upsertSaleEvent: upsertSaleEvent(),
|
|
1060
1066
|
timezoneNames: timezoneNames(),
|
|
1061
1067
|
representative: representative(),
|
|
1062
1068
|
zone: zone(),
|
|
1063
1069
|
historicRecord: historicRecord(),
|
|
1064
1070
|
integration: integration(),
|
|
1071
|
+
sale: sale(),
|
|
1065
1072
|
},
|
|
1066
1073
|
};
|
|
1067
1074
|
|
|
@@ -1219,32 +1226,6 @@ ${securitySchemes.basicAuth}`,
|
|
|
1219
1226
|
},
|
|
1220
1227
|
},
|
|
1221
1228
|
},
|
|
1222
|
-
'/config/init': {
|
|
1223
|
-
post: {
|
|
1224
|
-
tags: ['Config'],
|
|
1225
|
-
summary: '[!] Init API deployment',
|
|
1226
|
-
description: `
|
|
1227
|
-
Initializes and sets up the API when deployed in a new environment.
|
|
1228
|
-
|
|
1229
|
-
This initial super admin cannot be deleted later. You can add more super admins and disable this one's login though.
|
|
1230
|
-
|
|
1231
|
-
${securitySchemes.emptyDatabase}`,
|
|
1232
|
-
requestBody: {
|
|
1233
|
-
content: { 'application/json': { schema: initRequest() } },
|
|
1234
|
-
required: true,
|
|
1235
|
-
},
|
|
1236
|
-
responses: {
|
|
1237
|
-
' 200': {
|
|
1238
|
-
description: 'Contains the created super admin and default values.',
|
|
1239
|
-
content: { 'application/json': { schema: initResponse() } },
|
|
1240
|
-
},
|
|
1241
|
-
' 400': responses.badRequest,
|
|
1242
|
-
' 415': responses.unsupportedMediaType,
|
|
1243
|
-
' 500': responses.internalServerError,
|
|
1244
|
-
' 500 ': responses.databaseNotEmpty,
|
|
1245
|
-
},
|
|
1246
|
-
},
|
|
1247
|
-
},
|
|
1248
1229
|
'/config/defaults/get': {
|
|
1249
1230
|
get: {
|
|
1250
1231
|
tags: ['Config'],
|
|
@@ -1276,7 +1257,11 @@ ${securitySchemes.superAdminRole}`,
|
|
|
1276
1257
|
description: `
|
|
1277
1258
|
Update the default settings.
|
|
1278
1259
|
|
|
1279
|
-
|
|
1260
|
+
If the \`derivationSettings\` or \`expirationSettings\` are updated, the update will propagate to the \`defaults\` property of all networks
|
|
1261
|
+
and shops.
|
|
1262
|
+
|
|
1263
|
+
If the \`salesSettings\` contain duplicated zones, countries or postal codes, or if a country or postal codes references a non existent
|
|
1264
|
+
zone, the API will return a \`500 InconsistentSalesSettingsError\`.
|
|
1280
1265
|
|
|
1281
1266
|
${securitySchemes.tokens}
|
|
1282
1267
|
${securitySchemes.superAdminRole}`,
|
|
@@ -1298,6 +1283,7 @@ ${securitySchemes.superAdminRole}`,
|
|
|
1298
1283
|
' 415': responses.unsupportedMediaType,
|
|
1299
1284
|
' 500': responses.internalServerError,
|
|
1300
1285
|
' 500 ': responses.defaultsDoNotExist,
|
|
1286
|
+
' 500 ': responses.inconsistentSalesSettings,
|
|
1301
1287
|
},
|
|
1302
1288
|
},
|
|
1303
1289
|
},
|
|
@@ -1475,6 +1461,8 @@ ${descriptions.createIdIsOptional}
|
|
|
1475
1461
|
|
|
1476
1462
|
${descriptions.optionalArrayPropertiesEmptyByDefault}
|
|
1477
1463
|
|
|
1464
|
+
The \`readonly\` property defaults to \`false\` if not provided.
|
|
1465
|
+
|
|
1478
1466
|
To set custom \`derivationSettings\` and \`expirationSettings\` provide theses properties, or do not provide them and the values under the
|
|
1479
1467
|
\`defaults\` property will be used.
|
|
1480
1468
|
|
|
@@ -1566,6 +1554,9 @@ Finds a network and updates the provided properties.
|
|
|
1566
1554
|
|
|
1567
1555
|
${descriptions.updateSetAddOrRemove}
|
|
1568
1556
|
|
|
1557
|
+
If the network has its \`readonly\` property set to \`true\` then it cannot be updated and the API will return a
|
|
1558
|
+
\`500 NetworkCannotBeUpdatedError\`.
|
|
1559
|
+
|
|
1569
1560
|
The \`derivationSettings\` and \`expirationSettings\` properties can be updated with a value or with \`null\`, which will remove them. The
|
|
1570
1561
|
update will propagate to the \`network\` property of all the shops in the network.
|
|
1571
1562
|
|
|
@@ -1589,6 +1580,7 @@ ${securitySchemes.superAdminRole}`,
|
|
|
1589
1580
|
' 415': responses.unsupportedMediaType,
|
|
1590
1581
|
' 500': responses.internalServerError,
|
|
1591
1582
|
' 500 ': responses.networkDoesNotExist,
|
|
1583
|
+
' 500 ': responses.networkCannotBeUpdated,
|
|
1592
1584
|
},
|
|
1593
1585
|
},
|
|
1594
1586
|
},
|
|
@@ -1957,6 +1949,9 @@ ${descriptions.createIdIsOptional}
|
|
|
1957
1949
|
|
|
1958
1950
|
${descriptions.optionalArrayPropertiesEmptyByDefault}
|
|
1959
1951
|
|
|
1952
|
+
The \`zones\` property associates a representative with one or more zones. If any of the provided zones do not exist the API will return a
|
|
1953
|
+
\`500 ZoneDoesNotExistError\`.
|
|
1954
|
+
|
|
1960
1955
|
${securitySchemes.tokens}
|
|
1961
1956
|
${securitySchemes.superAdminRole}`,
|
|
1962
1957
|
requestBody: {
|
|
@@ -1976,7 +1971,8 @@ ${securitySchemes.superAdminRole}`,
|
|
|
1976
1971
|
' 403': responses.forbidden,
|
|
1977
1972
|
' 415': responses.unsupportedMediaType,
|
|
1978
1973
|
' 500': responses.internalServerError,
|
|
1979
|
-
' 500 ': responses.
|
|
1974
|
+
' 500 ': responses.zoneDoesNotExist,
|
|
1975
|
+
' 500 ': responses.representativeAlreadyExists,
|
|
1980
1976
|
},
|
|
1981
1977
|
},
|
|
1982
1978
|
},
|
|
@@ -2147,8 +2143,10 @@ ${descriptions.createIdIsOptional}
|
|
|
2147
2143
|
|
|
2148
2144
|
${descriptions.optionalArrayPropertiesEmptyByDefault}
|
|
2149
2145
|
|
|
2150
|
-
The \`network._id\` property that associates a shop with his network cannot be changed after creation.
|
|
2151
|
-
|
|
2146
|
+
The \`network._id\` property that associates a shop with his network cannot be changed after creation. If the provided network does not
|
|
2147
|
+
exist the API will return a \`500 NetworkDoesNotExistError\`, and if it is readonly it will return a \`500 NetworkCannotBeUpdatedError\`.
|
|
2148
|
+
|
|
2149
|
+
The \`readonly\` property defaults to \`false\` if not provided.
|
|
2152
2150
|
|
|
2153
2151
|
See [shops](#tag/Shops) for information about the \`status\` property.
|
|
2154
2152
|
|
|
@@ -2175,7 +2173,8 @@ ${securitySchemes.superAdminRole}`,
|
|
|
2175
2173
|
' 415': responses.unsupportedMediaType,
|
|
2176
2174
|
' 500': responses.internalServerError,
|
|
2177
2175
|
' 500 ': responses.networkDoesNotExist,
|
|
2178
|
-
' 500 ': responses.
|
|
2176
|
+
' 500 ': responses.networkCannotBeUpdated,
|
|
2177
|
+
' 500 ': responses.shopAlreadyExists,
|
|
2179
2178
|
},
|
|
2180
2179
|
},
|
|
2181
2180
|
},
|
|
@@ -2253,6 +2252,9 @@ Finds a shop and updates the provided properties.
|
|
|
2253
2252
|
|
|
2254
2253
|
${descriptions.updateSetAddOrRemove}
|
|
2255
2254
|
|
|
2255
|
+
If the shop has its \`readonly\` property set to \`true\` then it cannot be updated and the API will return a
|
|
2256
|
+
\`500 ShopCannotBeUpdatedError\`.
|
|
2257
|
+
|
|
2256
2258
|
See [shops](#tag/Shops) for information about the \`status\` property.
|
|
2257
2259
|
|
|
2258
2260
|
${securitySchemes.tokens}
|
|
@@ -2275,6 +2277,7 @@ ${securitySchemes.superAdminRole}`,
|
|
|
2275
2277
|
' 415': responses.unsupportedMediaType,
|
|
2276
2278
|
' 500': responses.internalServerError,
|
|
2277
2279
|
' 500 ': responses.shopDoesNotExist,
|
|
2280
|
+
' 500 ': responses.shopCannotBeUpdated,
|
|
2278
2281
|
},
|
|
2279
2282
|
},
|
|
2280
2283
|
},
|
|
@@ -2531,8 +2534,8 @@ An expedition can be associated on creation to either a shop or a network:
|
|
|
2531
2534
|
- Provide a shop when it is known at which shop it is going to be received. That shop network will be inserted automatically.
|
|
2532
2535
|
- Provide a network when it can be received at any shop in it. When a shop receives it, that shop will be added to the expedition.
|
|
2533
2536
|
|
|
2534
|
-
If the provided shop does not exist the API will return a \`500 ShopDoesNotExistError\`,
|
|
2535
|
-
will return a \`500
|
|
2537
|
+
If the provided shop does not exist the API will return a \`500 ShopDoesNotExistError\`, if it is not enabled it will return a
|
|
2538
|
+
\`500 ShopNotEnabledError\`, and if it is readonly it will return a \`500 ShopCannotBeUpdatedError\`.
|
|
2536
2539
|
|
|
2537
2540
|
If the provided network does not exist the API will return a \`500 NetworkDoesNotExistError\`.
|
|
2538
2541
|
|
|
@@ -2560,7 +2563,8 @@ ${securitySchemes.superAdminRole}`,
|
|
|
2560
2563
|
' 500 ': responses.expeditionAlreadyExists,
|
|
2561
2564
|
' 500 ': responses.shopDoesNotExist,
|
|
2562
2565
|
' 500 ': responses.shopNotEnabled,
|
|
2563
|
-
' 500 ': responses.
|
|
2566
|
+
' 500 ': responses.shopCannotBeUpdated,
|
|
2567
|
+
' 500 ': responses.networkDoesNotExist,
|
|
2564
2568
|
},
|
|
2565
2569
|
},
|
|
2566
2570
|
},
|
|
@@ -3036,6 +3040,181 @@ ${securitySchemes.anyRole}`,
|
|
|
3036
3040
|
},
|
|
3037
3041
|
},
|
|
3038
3042
|
},
|
|
3043
|
+
'/sales/create': {
|
|
3044
|
+
post: {
|
|
3045
|
+
tags: ['Sales'],
|
|
3046
|
+
summary: '[U] Create',
|
|
3047
|
+
description: `
|
|
3048
|
+
Creates a new sale.
|
|
3049
|
+
|
|
3050
|
+
${descriptions.createIdIsOptional}
|
|
3051
|
+
|
|
3052
|
+
${descriptions.optionalArrayPropertiesEmptyByDefault}
|
|
3053
|
+
|
|
3054
|
+
The \`network\` and \`shop\` fields of the new sale will be the same as the shop user that creates it.
|
|
3055
|
+
|
|
3056
|
+
The \`status.code\` will be \`pending\`.
|
|
3057
|
+
|
|
3058
|
+
The \`settings\` field will be created by combining the \`salesSettings\` from the \`default\` object and the \`salesSettings\` from the
|
|
3059
|
+
sale \`network\` as they are when the sale is created. This way the sale will keep the right settings values even if the \`default\` or
|
|
3060
|
+
the \`network\` are updated later.
|
|
3061
|
+
|
|
3062
|
+
The \`price\` field will be calculated from the \`size\` and \`settings\` fields.
|
|
3063
|
+
|
|
3064
|
+
${securitySchemes.tokens}
|
|
3065
|
+
${securitySchemes.shopUserRole}`,
|
|
3066
|
+
requestBody: {
|
|
3067
|
+
content: { 'application/json': { schema: createSaleRequest() } },
|
|
3068
|
+
required: true,
|
|
3069
|
+
},
|
|
3070
|
+
responses: {
|
|
3071
|
+
' 200': {
|
|
3072
|
+
description: 'Contains the created sale.',
|
|
3073
|
+
content: { 'application/json': { schema: createSaleResponse() } },
|
|
3074
|
+
},
|
|
3075
|
+
' 400': responses.badRequest,
|
|
3076
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3077
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3078
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3079
|
+
' 401 ': responses.unauthorized,
|
|
3080
|
+
' 403': responses.forbidden,
|
|
3081
|
+
' 415': responses.unsupportedMediaType,
|
|
3082
|
+
' 500': responses.internalServerError,
|
|
3083
|
+
' 500 ': responses.saleAlreadyExists,
|
|
3084
|
+
},
|
|
3085
|
+
},
|
|
3086
|
+
},
|
|
3087
|
+
'/sales/find': {
|
|
3088
|
+
post: {
|
|
3089
|
+
tags: ['Sales'],
|
|
3090
|
+
summary: '[S] Find',
|
|
3091
|
+
description: `
|
|
3092
|
+
Finds sales by one of several filters.
|
|
3093
|
+
|
|
3094
|
+
${descriptions.findLimitTip}
|
|
3095
|
+
|
|
3096
|
+
${securitySchemes.tokens}
|
|
3097
|
+
${securitySchemes.superAdminRole}`,
|
|
3098
|
+
requestBody: {
|
|
3099
|
+
content: { 'application/json': { schema: findSalesSuperAdminRequest() } },
|
|
3100
|
+
required: true,
|
|
3101
|
+
},
|
|
3102
|
+
responses: {
|
|
3103
|
+
' 200': {
|
|
3104
|
+
description: 'Contains the found sales.',
|
|
3105
|
+
content: { 'application/json': { schema: findSalesResponse() } },
|
|
3106
|
+
},
|
|
3107
|
+
' 400': responses.badRequest,
|
|
3108
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3109
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3110
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3111
|
+
' 401 ': responses.unauthorized,
|
|
3112
|
+
' 403': responses.forbidden,
|
|
3113
|
+
' 415': responses.unsupportedMediaType,
|
|
3114
|
+
' 500': responses.internalServerError,
|
|
3115
|
+
},
|
|
3116
|
+
},
|
|
3117
|
+
},
|
|
3118
|
+
'/sales/find ': {
|
|
3119
|
+
post: {
|
|
3120
|
+
tags: ['Sales'],
|
|
3121
|
+
summary: '[N] Find',
|
|
3122
|
+
description: `
|
|
3123
|
+
Finds sales by one of several filters.
|
|
3124
|
+
|
|
3125
|
+
The results will be limited to the network the admin belongs to, so for example if he finds by \`_id\` and the sale is from another
|
|
3126
|
+
network, the find will return no results.
|
|
3127
|
+
|
|
3128
|
+
${descriptions.findLimitTip}
|
|
3129
|
+
|
|
3130
|
+
${securitySchemes.tokens}
|
|
3131
|
+
${securitySchemes.networkAdminRole}`,
|
|
3132
|
+
requestBody: {
|
|
3133
|
+
content: { 'application/json': { schema: findSalesNetworkAdminRequest() } },
|
|
3134
|
+
required: true,
|
|
3135
|
+
},
|
|
3136
|
+
responses: {
|
|
3137
|
+
' 200': {
|
|
3138
|
+
description: 'Contains the found sales.',
|
|
3139
|
+
content: { 'application/json': { schema: findSalesResponse() } },
|
|
3140
|
+
},
|
|
3141
|
+
' 400': responses.badRequest,
|
|
3142
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3143
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3144
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3145
|
+
' 401 ': responses.unauthorized,
|
|
3146
|
+
' 403': responses.forbidden,
|
|
3147
|
+
' 415': responses.unsupportedMediaType,
|
|
3148
|
+
' 500': responses.internalServerError,
|
|
3149
|
+
},
|
|
3150
|
+
},
|
|
3151
|
+
},
|
|
3152
|
+
'/sales/find ': {
|
|
3153
|
+
post: {
|
|
3154
|
+
tags: ['Sales'],
|
|
3155
|
+
summary: '[U] Find',
|
|
3156
|
+
description: `
|
|
3157
|
+
Finds sales by one of several filters.
|
|
3158
|
+
|
|
3159
|
+
The results will be limited to the shop the user belongs to, so for example if he finds by \`_id\` and the sale is from another
|
|
3160
|
+
network or shop, the find will return no results.
|
|
3161
|
+
|
|
3162
|
+
${descriptions.findLimitTip}
|
|
3163
|
+
|
|
3164
|
+
${securitySchemes.tokens}
|
|
3165
|
+
${securitySchemes.shopUserRole}`,
|
|
3166
|
+
requestBody: {
|
|
3167
|
+
content: { 'application/json': { schema: findSalesShopUserRequest() } },
|
|
3168
|
+
required: true,
|
|
3169
|
+
},
|
|
3170
|
+
responses: {
|
|
3171
|
+
' 200': {
|
|
3172
|
+
description: 'Contains the found sales.',
|
|
3173
|
+
content: { 'application/json': { schema: findSalesResponse() } },
|
|
3174
|
+
},
|
|
3175
|
+
' 400': responses.badRequest,
|
|
3176
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3177
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3178
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3179
|
+
' 401 ': responses.unauthorized,
|
|
3180
|
+
' 403': responses.forbidden,
|
|
3181
|
+
' 415': responses.unsupportedMediaType,
|
|
3182
|
+
' 500': responses.internalServerError,
|
|
3183
|
+
},
|
|
3184
|
+
},
|
|
3185
|
+
},
|
|
3186
|
+
'/sales/checkPrices': {
|
|
3187
|
+
post: {
|
|
3188
|
+
tags: ['Sales'],
|
|
3189
|
+
summary: '[SNU] Check prices',
|
|
3190
|
+
description: `
|
|
3191
|
+
Finds the price for a sale based on its package size and destination.
|
|
3192
|
+
|
|
3193
|
+
If the destination is invalid the API will return a \`500 InvalidSaleDestinationError\`.
|
|
3194
|
+
|
|
3195
|
+
${securitySchemes.tokens}
|
|
3196
|
+
${securitySchemes.anyRole}`,
|
|
3197
|
+
requestBody: {
|
|
3198
|
+
content: { 'application/json': { schema: checkSalePriceRequest() } },
|
|
3199
|
+
required: true,
|
|
3200
|
+
},
|
|
3201
|
+
responses: {
|
|
3202
|
+
' 200': {
|
|
3203
|
+
description: 'Contains the price of the sale.',
|
|
3204
|
+
content: { 'application/json': { schema: checkSalePriceResponse() } },
|
|
3205
|
+
},
|
|
3206
|
+
' 400': responses.badRequest,
|
|
3207
|
+
' 401': responses.invalidUserInCookieOrHeader,
|
|
3208
|
+
' 401 ': responses.invalidCookieOrHeader,
|
|
3209
|
+
' 401 ': responses.missingCookieOrHeader,
|
|
3210
|
+
' 401 ': responses.unauthorized,
|
|
3211
|
+
' 403': responses.forbidden,
|
|
3212
|
+
' 415': responses.unsupportedMediaType,
|
|
3213
|
+
' 500': responses.internalServerError,
|
|
3214
|
+
' 500 ': responses.invalidSaleDestination,
|
|
3215
|
+
},
|
|
3216
|
+
},
|
|
3217
|
+
},
|
|
3039
3218
|
'/historicRecords/find': {
|
|
3040
3219
|
post: {
|
|
3041
3220
|
tags: ['Historic records'],
|
|
@@ -3077,8 +3256,7 @@ ${securitySchemes.superAdminRole}`,
|
|
|
3077
3256
|
description: `
|
|
3078
3257
|
Finds all the integrations of the API and what networks they apply to.
|
|
3079
3258
|
|
|
3080
|
-
To see what each integration
|
|
3081
|
-
section.
|
|
3259
|
+
To see what each integration does read the [background processes](#tag/Types-of-background-processes) section.
|
|
3082
3260
|
|
|
3083
3261
|
${descriptions.findLimitTip}
|
|
3084
3262
|
|