@gls_spain/gps-common 34.9.2 → 34.9.3

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 (81) hide show
  1. package/.eslintignore +1 -1
  2. package/.eslintrc.json +11 -11
  3. package/.idea/codeStyles/Project.xml +36 -36
  4. package/.idea/codeStyles/codeStyleConfig.xml +4 -4
  5. package/.idea/gps-common.iml +11 -11
  6. package/.idea/inspectionProfiles/Project_Default.xml +6 -6
  7. package/.idea/jsLibraryMappings.xml +5 -5
  8. package/.idea/misc.xml +5 -5
  9. package/.idea/modules.xml +7 -7
  10. package/.idea/prettier.xml +6 -6
  11. package/.idea/scopes/Source_files.xml +2 -2
  12. package/.idea/vcs.xml +5 -5
  13. package/.prettierignore +4 -4
  14. package/.prettierrc.json +13 -13
  15. package/.releaserc +17 -17
  16. package/CHANGELOG.md +1264 -1257
  17. package/README.md +103 -103
  18. package/errors/CountersDoNotExistError.js +11 -11
  19. package/errors/DatabaseNotEmptyError.js +11 -11
  20. package/errors/DefaultsDoNotExistError.js +11 -11
  21. package/errors/ExpeditionAlreadyExistsError.js +11 -11
  22. package/errors/ExpeditionCannotBeDeletedError.js +11 -11
  23. package/errors/ExpeditionCannotBeUpdatedError.js +11 -11
  24. package/errors/ExpeditionDoesNotExistError.js +11 -11
  25. package/errors/GLSRecordingError.js +11 -11
  26. package/errors/GLSSpainError.js +11 -11
  27. package/errors/InconsistentSalesSettingsError.js +11 -11
  28. package/errors/InvalidSaleDestinationError.js +11 -11
  29. package/errors/LabelDoesNotExistError.js +11 -11
  30. package/errors/NetworkAlreadyExistsError.js +11 -11
  31. package/errors/NetworkCannotBeDeletedError.js +11 -11
  32. package/errors/NetworkCannotBeUpdatedError.js +11 -11
  33. package/errors/NetworkDoesNotExistError.js +11 -11
  34. package/errors/RepresentativeAlreadyExistsError.js +11 -11
  35. package/errors/RepresentativeCannotBeDeletedError.js +11 -11
  36. package/errors/RepresentativeDoesNotExistError.js +11 -11
  37. package/errors/SaleAlreadyExistsError.js +11 -11
  38. package/errors/SaleDoesNotExistError.js +11 -11
  39. package/errors/ShopAlreadyExistsError.js +11 -11
  40. package/errors/ShopCannotBeDeletedError.js +11 -11
  41. package/errors/ShopCannotBeUpdatedError.js +11 -11
  42. package/errors/ShopCannotSellError.js +11 -11
  43. package/errors/ShopDoesNotExistError.js +11 -11
  44. package/errors/ShopNotEnabledError.js +11 -11
  45. package/errors/UserAlreadyExistsError.js +11 -11
  46. package/errors/UserCannotBeDeletedError.js +11 -11
  47. package/errors/UserCannotBeUpdatedError.js +11 -11
  48. package/errors/UserDoesNotExistError.js +11 -11
  49. package/errors/WrongNetworkError.js +11 -11
  50. package/errors/WrongPasswordError.js +11 -11
  51. package/errors/WrongShopError.js +11 -11
  52. package/errors/ZoneAlreadyExistsError.js +11 -11
  53. package/errors/ZoneCannotBeDeletedError.js +11 -11
  54. package/errors/ZoneDoesNotExistError.js +11 -11
  55. package/errors/index.js +118 -118
  56. package/index.js +9 -9
  57. package/index.test.js +36 -36
  58. package/jest.config.js +5 -5
  59. package/open-api-spec/index.js +3715 -3715
  60. package/package.json +65 -69
  61. package/schemas/definitions/become.js +5 -5
  62. package/schemas/definitions/common.js +462 -451
  63. package/schemas/definitions/counters.js +43 -43
  64. package/schemas/definitions/defaults.js +140 -140
  65. package/schemas/definitions/expeditions.js +867 -867
  66. package/schemas/definitions/gls-spain-integration-events.js +139 -139
  67. package/schemas/definitions/historic-records.js +90 -90
  68. package/schemas/definitions/integrations.js +38 -38
  69. package/schemas/definitions/login.js +38 -38
  70. package/schemas/definitions/logout.js +8 -8
  71. package/schemas/definitions/networks.js +123 -123
  72. package/schemas/definitions/pods.js +26 -26
  73. package/schemas/definitions/representatives.js +194 -194
  74. package/schemas/definitions/sales.js +253 -249
  75. package/schemas/definitions/shops.js +404 -404
  76. package/schemas/definitions/users.js +337 -337
  77. package/schemas/definitions/zones.js +92 -92
  78. package/schemas/index.js +400 -400
  79. package/scripts/build-documentation.js +40 -40
  80. package/scripts/build-json-schemas.js +35 -35
  81. package/.idea/workspace.xml +0 -699
@@ -1,249 +1,253 @@
1
- const {
2
- uuid,
3
- datetime,
4
- email,
5
- phone,
6
- money,
7
- createRequest,
8
- createResponse,
9
- findRequest,
10
- findResponse,
11
- updateRequest,
12
- updateResponse,
13
- mergeSchemas,
14
- pickProperties,
15
- objectWithUuid,
16
- } = require('@gls_spain/common-json-schemas');
17
- const { country, findAll, findById, findByOptionalCreatedAtRange } = require('./common');
18
- const { address } = require('./common');
19
- const { saleSize, salesSettings } = require('./defaults');
20
- const { network, objectWithNetworkId } = require('./networks');
21
- const { shop, objectWithShopId } = require('./shops');
22
-
23
- const sale = () => ({
24
- title: 'sale',
25
- type: 'object',
26
- properties: {
27
- _id: uuid(),
28
- createdAt: datetime(),
29
- updatedAt: datetime(),
30
- deletable: { type: 'boolean' },
31
- network: {
32
- type: 'object',
33
- properties: { ...pickProperties(network(), ['_id', 'name']) },
34
- required: ['_id', 'name'],
35
- additionalProperties: false,
36
- },
37
- shop: {
38
- type: 'object',
39
- properties: { ...pickProperties(shop(), ['_id', 'name']) },
40
- required: ['_id', 'name'],
41
- additionalProperties: false,
42
- },
43
- status: {
44
- type: 'object',
45
- properties: {
46
- // todo add paidAt if status=paymentRequested
47
- code: {
48
- type: 'string',
49
- enum: ['invalidOrIncomplete', 'cancelledByCustomer', 'authorizationRefused', 'paymentRequested', 'paymentDeleted', 'refund'],
50
- },
51
- },
52
- required: ['code'],
53
- additionalProperties: false,
54
- },
55
- size: saleSize(),
56
- price: money(),
57
- settings: mergeSchemas(salesSettings(), network().properties.salesSettings, {
58
- description: 'a copy of both the defaults sale settings and the network sale settings as they were when the sale was created',
59
- }),
60
- destination: {
61
- type: 'object',
62
- properties: {
63
- name: { type: 'string', trim: true },
64
- address: address(),
65
- emails: { type: 'array', items: email(), uniqueItems: true },
66
- phones: { type: 'array', items: phone(), uniqueItems: true },
67
- notes: { type: 'string', trim: true },
68
- },
69
- required: ['name', 'address', 'emails', 'phones'],
70
- additionalProperties: false,
71
- },
72
- sender: {
73
- type: 'object',
74
- properties: {
75
- name: { type: 'string', trim: true },
76
- nif: { type: 'string', trim: true },
77
- address: address(),
78
- emails: { type: 'array', items: email(), uniqueItems: true, minItems: 1 },
79
- phones: { type: 'array', items: phone(), uniqueItems: true, minItems: 1 },
80
- fiscal: {
81
- type: 'object',
82
- properties: {
83
- name: { type: 'string', trim: true },
84
- nif: { type: 'string', trim: true },
85
- address: address(),
86
- emails: { type: 'array', items: email(), uniqueItems: true },
87
- phones: { type: 'array', items: phone(), uniqueItems: true },
88
- },
89
- required: ['name', 'nif', 'address', 'emails', 'phones'],
90
- additionalProperties: false,
91
- },
92
- notes: { type: 'string', trim: true },
93
- reference: { type: 'string', trim: true },
94
- },
95
- required: ['name', 'nif', 'address', 'emails', 'phones', 'fiscal'],
96
- additionalProperties: false,
97
- },
98
- payment: {
99
- type: 'object',
100
- properties: {
101
- statusHistory: {
102
- type: 'array',
103
- items: {
104
- type: 'object',
105
- properties: {
106
- at: datetime(),
107
- status: { type: 'integer' },
108
- error: { type: 'integer' },
109
- },
110
- required: ['at', 'status', 'error'],
111
- additionalProperties: false,
112
- },
113
- },
114
- orderId: { type: 'string' },
115
- payId: { type: 'string', description: 'only available after payment' },
116
- fullUrl: { type: 'string' },
117
- shortId: { type: 'string' },
118
- },
119
- required: ['statusHistory', 'orderId', 'fullUrl', 'shortId'],
120
- additionalProperties: false,
121
- },
122
- },
123
- required: [
124
- '_id',
125
- 'createdAt',
126
- 'updatedAt',
127
- 'deletable',
128
- 'network',
129
- 'shop',
130
- 'status',
131
- 'size',
132
- 'price',
133
- 'settings',
134
- 'destination',
135
- 'sender',
136
- 'payment',
137
- ],
138
- additionalProperties: false,
139
- });
140
-
141
- const createSaleRequest = () =>
142
- createRequest({
143
- type: 'object',
144
- properties: {
145
- ...pickProperties(sale(), ['_id', 'createdAt', 'size', 'destination', 'sender']),
146
- },
147
- required: ['size', 'destination', 'sender'],
148
- additionalProperties: false,
149
- });
150
-
151
- const createSaleResponse = () => createResponse(sale());
152
-
153
- const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
154
-
155
- const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
156
-
157
- const findSalesSuperAdminRequest = () =>
158
- findRequest({
159
- oneOf: [
160
- mergeSchemas(findByNetwork(), findByOptionalCreatedAtRange()),
161
- mergeSchemas(findByShop(), findByOptionalCreatedAtRange()),
162
- findById(),
163
- ],
164
- });
165
-
166
- const findSalesNetworkAdminRequest = () =>
167
- findRequest({
168
- oneOf: [
169
- mergeSchemas(findAll(), findByOptionalCreatedAtRange()),
170
- mergeSchemas(findByShop(), findByOptionalCreatedAtRange()),
171
- findById(),
172
- ],
173
- });
174
-
175
- const findSalesShopUserRequest = () => findRequest({ oneOf: [mergeSchemas(findAll(), findByOptionalCreatedAtRange()), findById()] });
176
-
177
- const findSalesResponse = () => findResponse(sale());
178
-
179
- const checkSalePriceRequest = () => ({
180
- type: 'object',
181
- properties: {
182
- size: saleSize(),
183
- country: country(),
184
- postalCode: { type: 'string', trim: true },
185
- },
186
- required: ['size', 'country', 'postalCode'],
187
- additionalProperties: false,
188
- });
189
-
190
- const checkSalePriceResponse = () => ({
191
- type: 'object',
192
- properties: {
193
- zone: { type: 'string' },
194
- price: money(),
195
- },
196
- required: ['zone', 'price'],
197
- additionalProperties: false,
198
- });
199
-
200
- const updateSaleRequest = () =>
201
- updateRequest(findById(), {
202
- type: 'object',
203
- properties: { ...pickProperties(sale(), ['status']) },
204
- minProperties: 1,
205
- additionalProperties: false,
206
- });
207
-
208
- const updateSaleResponse = () => updateResponse(sale());
209
-
210
- const downloadSaleLabelRequest = () => ({
211
- type: 'object',
212
- properties: {
213
- download: objectWithUuid(),
214
- },
215
- required: ['download'],
216
- additionalProperties: false,
217
- });
218
-
219
- const downloadSaleLabelResponse = () => ({
220
- type: 'object',
221
- properties: {
222
- download: {
223
- type: 'object',
224
- properties: {
225
- label: { type: 'string', description: 'a PDF file encoded as a Base64 string' },
226
- },
227
- required: ['label'],
228
- additionalProperties: false,
229
- },
230
- },
231
- required: ['download'],
232
- additionalProperties: false,
233
- });
234
-
235
- module.exports = {
236
- sale,
237
- createSaleRequest,
238
- createSaleResponse,
239
- findSalesSuperAdminRequest,
240
- findSalesNetworkAdminRequest,
241
- findSalesShopUserRequest,
242
- findSalesResponse,
243
- checkSalePriceRequest,
244
- checkSalePriceResponse,
245
- updateSaleRequest,
246
- updateSaleResponse,
247
- downloadSaleLabelRequest,
248
- downloadSaleLabelResponse,
249
- };
1
+ const {
2
+ uuid,
3
+ datetime,
4
+ email,
5
+ phone,
6
+ money,
7
+ createRequest,
8
+ createResponse,
9
+ findRequest,
10
+ findResponse,
11
+ updateRequest,
12
+ updateResponse,
13
+ mergeSchemas,
14
+ pickProperties,
15
+ objectWithUuid,
16
+ } = require('@gls_spain/common-json-schemas');
17
+ const { country, findAll, findById, findByOptionalCreatedAtRange, nifType } = require('./common');
18
+ const { address } = require('./common');
19
+ const { saleSize, salesSettings } = require('./defaults');
20
+ const { network, objectWithNetworkId } = require('./networks');
21
+ const { shop, objectWithShopId } = require('./shops');
22
+
23
+ const sale = () => ({
24
+ title: 'sale',
25
+ type: 'object',
26
+ properties: {
27
+ _id: uuid(),
28
+ createdAt: datetime(),
29
+ updatedAt: datetime(),
30
+ deletable: { type: 'boolean' },
31
+ network: {
32
+ type: 'object',
33
+ properties: { ...pickProperties(network(), ['_id', 'name']) },
34
+ required: ['_id', 'name'],
35
+ additionalProperties: false,
36
+ },
37
+ shop: {
38
+ type: 'object',
39
+ properties: { ...pickProperties(shop(), ['_id', 'name']) },
40
+ required: ['_id', 'name'],
41
+ additionalProperties: false,
42
+ },
43
+ status: {
44
+ type: 'object',
45
+ properties: {
46
+ // todo add paidAt if status=paymentRequested
47
+ code: {
48
+ type: 'string',
49
+ enum: ['invalidOrIncomplete', 'cancelledByCustomer', 'authorizationRefused', 'paymentRequested', 'paymentDeleted', 'refund'],
50
+ },
51
+ },
52
+ required: ['code'],
53
+ additionalProperties: false,
54
+ },
55
+ size: saleSize(),
56
+ price: money(),
57
+ settings: mergeSchemas(salesSettings(), network().properties.salesSettings, {
58
+ description: 'a copy of both the defaults sale settings and the network sale settings as they were when the sale was created',
59
+ }),
60
+ destination: {
61
+ type: 'object',
62
+ properties: {
63
+ name: { type: 'string', trim: true },
64
+ address: address(),
65
+ emails: { type: 'array', items: email(), uniqueItems: true },
66
+ phones: { type: 'array', items: phone(), uniqueItems: true },
67
+ notes: { type: 'string', trim: true },
68
+ },
69
+ required: ['name', 'address', 'emails', 'phones'],
70
+ additionalProperties: false,
71
+ },
72
+ sender: {
73
+ type: 'object',
74
+ properties: {
75
+ name: { type: 'string', trim: true },
76
+ nif: { type: 'string', trim: true },
77
+ nifType: nifType(),
78
+ countryPassport: country(),
79
+ address: address(),
80
+ emails: { type: 'array', items: email(), uniqueItems: true, minItems: 1 },
81
+ phones: { type: 'array', items: phone(), uniqueItems: true, minItems: 1 },
82
+ fiscal: {
83
+ type: 'object',
84
+ properties: {
85
+ name: { type: 'string', trim: true },
86
+ nif: { type: 'string', trim: true },
87
+ nifType: nifType(),
88
+ countryPassport: country(),
89
+ address: address(),
90
+ emails: { type: 'array', items: email(), uniqueItems: true },
91
+ phones: { type: 'array', items: phone(), uniqueItems: true },
92
+ },
93
+ required: ['name', 'nif', 'address', 'emails', 'phones' , 'nifType'],
94
+ additionalProperties: false,
95
+ },
96
+ notes: { type: 'string', trim: true },
97
+ reference: { type: 'string', trim: true },
98
+ },
99
+ required: ['name', 'nif', 'address', 'emails', 'phones', 'fiscal'],
100
+ additionalProperties: false,
101
+ },
102
+ payment: {
103
+ type: 'object',
104
+ properties: {
105
+ statusHistory: {
106
+ type: 'array',
107
+ items: {
108
+ type: 'object',
109
+ properties: {
110
+ at: datetime(),
111
+ status: { type: 'integer' },
112
+ error: { type: 'integer' },
113
+ },
114
+ required: ['at', 'status', 'error'],
115
+ additionalProperties: false,
116
+ },
117
+ },
118
+ orderId: { type: 'string' },
119
+ payId: { type: 'string', description: 'only available after payment' },
120
+ fullUrl: { type: 'string' },
121
+ shortId: { type: 'string' },
122
+ },
123
+ required: ['statusHistory', 'orderId', 'fullUrl', 'shortId'],
124
+ additionalProperties: false,
125
+ },
126
+ },
127
+ required: [
128
+ '_id',
129
+ 'createdAt',
130
+ 'updatedAt',
131
+ 'deletable',
132
+ 'network',
133
+ 'shop',
134
+ 'status',
135
+ 'size',
136
+ 'price',
137
+ 'settings',
138
+ 'destination',
139
+ 'sender',
140
+ 'payment',
141
+ ],
142
+ additionalProperties: false,
143
+ });
144
+
145
+ const createSaleRequest = () =>
146
+ createRequest({
147
+ type: 'object',
148
+ properties: {
149
+ ...pickProperties(sale(), ['_id', 'createdAt', 'size', 'destination', 'sender']),
150
+ },
151
+ required: ['size', 'destination', 'sender'],
152
+ additionalProperties: false,
153
+ });
154
+
155
+ const createSaleResponse = () => createResponse(sale());
156
+
157
+ const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
158
+
159
+ const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
160
+
161
+ const findSalesSuperAdminRequest = () =>
162
+ findRequest({
163
+ oneOf: [
164
+ mergeSchemas(findByNetwork(), findByOptionalCreatedAtRange()),
165
+ mergeSchemas(findByShop(), findByOptionalCreatedAtRange()),
166
+ findById(),
167
+ ],
168
+ });
169
+
170
+ const findSalesNetworkAdminRequest = () =>
171
+ findRequest({
172
+ oneOf: [
173
+ mergeSchemas(findAll(), findByOptionalCreatedAtRange()),
174
+ mergeSchemas(findByShop(), findByOptionalCreatedAtRange()),
175
+ findById(),
176
+ ],
177
+ });
178
+
179
+ const findSalesShopUserRequest = () => findRequest({ oneOf: [mergeSchemas(findAll(), findByOptionalCreatedAtRange()), findById()] });
180
+
181
+ const findSalesResponse = () => findResponse(sale());
182
+
183
+ const checkSalePriceRequest = () => ({
184
+ type: 'object',
185
+ properties: {
186
+ size: saleSize(),
187
+ country: country(),
188
+ postalCode: { type: 'string', trim: true },
189
+ },
190
+ required: ['size', 'country', 'postalCode'],
191
+ additionalProperties: false,
192
+ });
193
+
194
+ const checkSalePriceResponse = () => ({
195
+ type: 'object',
196
+ properties: {
197
+ zone: { type: 'string' },
198
+ price: money(),
199
+ },
200
+ required: ['zone', 'price'],
201
+ additionalProperties: false,
202
+ });
203
+
204
+ const updateSaleRequest = () =>
205
+ updateRequest(findById(), {
206
+ type: 'object',
207
+ properties: { ...pickProperties(sale(), ['status']) },
208
+ minProperties: 1,
209
+ additionalProperties: false,
210
+ });
211
+
212
+ const updateSaleResponse = () => updateResponse(sale());
213
+
214
+ const downloadSaleLabelRequest = () => ({
215
+ type: 'object',
216
+ properties: {
217
+ download: objectWithUuid(),
218
+ },
219
+ required: ['download'],
220
+ additionalProperties: false,
221
+ });
222
+
223
+ const downloadSaleLabelResponse = () => ({
224
+ type: 'object',
225
+ properties: {
226
+ download: {
227
+ type: 'object',
228
+ properties: {
229
+ label: { type: 'string', description: 'a PDF file encoded as a Base64 string' },
230
+ },
231
+ required: ['label'],
232
+ additionalProperties: false,
233
+ },
234
+ },
235
+ required: ['download'],
236
+ additionalProperties: false,
237
+ });
238
+
239
+ module.exports = {
240
+ sale,
241
+ createSaleRequest,
242
+ createSaleResponse,
243
+ findSalesSuperAdminRequest,
244
+ findSalesNetworkAdminRequest,
245
+ findSalesShopUserRequest,
246
+ findSalesResponse,
247
+ checkSalePriceRequest,
248
+ checkSalePriceResponse,
249
+ updateSaleRequest,
250
+ updateSaleResponse,
251
+ downloadSaleLabelRequest,
252
+ downloadSaleLabelResponse,
253
+ };