@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gls_spain/gps-common",
3
- "version": "32.4.0",
3
+ "version": "33.0.0",
4
4
  "description": "Errors, schemas and documentation for the Parcel Shops project",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -13,9 +13,266 @@ const { timezones } = require('@gls_spain/ajv-options');
13
13
 
14
14
  const date = () => ({ type: 'string', format: 'date' });
15
15
 
16
+ const country = () => ({
17
+ type: 'string',
18
+ enum: [
19
+ 'AD',
20
+ 'AE',
21
+ 'AF',
22
+ 'AG',
23
+ 'AI',
24
+ 'AL',
25
+ 'AM',
26
+ 'AO',
27
+ 'AQ',
28
+ 'AR',
29
+ 'AS',
30
+ 'AT',
31
+ 'AU',
32
+ 'AW',
33
+ 'AX',
34
+ 'AZ',
35
+ 'BA',
36
+ 'BB',
37
+ 'BD',
38
+ 'BE',
39
+ 'BF',
40
+ 'BG',
41
+ 'BH',
42
+ 'BI',
43
+ 'BJ',
44
+ 'BL',
45
+ 'BM',
46
+ 'BN',
47
+ 'BO',
48
+ 'BQ',
49
+ 'BR',
50
+ 'BS',
51
+ 'BT',
52
+ 'BV',
53
+ 'BW',
54
+ 'BY',
55
+ 'BZ',
56
+ 'CA',
57
+ 'CC',
58
+ 'CD',
59
+ 'CF',
60
+ 'CG',
61
+ 'CH',
62
+ 'CI',
63
+ 'CK',
64
+ 'CL',
65
+ 'CM',
66
+ 'CN',
67
+ 'CO',
68
+ 'CR',
69
+ 'CU',
70
+ 'CV',
71
+ 'CW',
72
+ 'CX',
73
+ 'CY',
74
+ 'CZ',
75
+ 'DE',
76
+ 'DJ',
77
+ 'DK',
78
+ 'DM',
79
+ 'DO',
80
+ 'DZ',
81
+ 'EC',
82
+ 'EE',
83
+ 'EG',
84
+ 'EH',
85
+ 'ER',
86
+ 'ES',
87
+ 'ET',
88
+ 'FI',
89
+ 'FJ',
90
+ 'FK',
91
+ 'FM',
92
+ 'FO',
93
+ 'FR',
94
+ 'GA',
95
+ 'GB',
96
+ 'GD',
97
+ 'GE',
98
+ 'GF',
99
+ 'GG',
100
+ 'GH',
101
+ 'GI',
102
+ 'GL',
103
+ 'GM',
104
+ 'GN',
105
+ 'GP',
106
+ 'GQ',
107
+ 'GR',
108
+ 'GS',
109
+ 'GT',
110
+ 'GU',
111
+ 'GW',
112
+ 'GY',
113
+ 'HK',
114
+ 'HM',
115
+ 'HN',
116
+ 'HR',
117
+ 'HT',
118
+ 'HU',
119
+ 'ID',
120
+ 'IE',
121
+ 'IL',
122
+ 'IM',
123
+ 'IN',
124
+ 'IO',
125
+ 'IQ',
126
+ 'IR',
127
+ 'IS',
128
+ 'IT',
129
+ 'JE',
130
+ 'JM',
131
+ 'JO',
132
+ 'JP',
133
+ 'KE',
134
+ 'KG',
135
+ 'KH',
136
+ 'KI',
137
+ 'KM',
138
+ 'KN',
139
+ 'KP',
140
+ 'KR',
141
+ 'KW',
142
+ 'KY',
143
+ 'KZ',
144
+ 'LA',
145
+ 'LB',
146
+ 'LC',
147
+ 'LI',
148
+ 'LK',
149
+ 'LR',
150
+ 'LS',
151
+ 'LT',
152
+ 'LU',
153
+ 'LV',
154
+ 'LY',
155
+ 'MA',
156
+ 'MC',
157
+ 'MD',
158
+ 'ME',
159
+ 'MF',
160
+ 'MG',
161
+ 'MH',
162
+ 'MK',
163
+ 'ML',
164
+ 'MM',
165
+ 'MN',
166
+ 'MO',
167
+ 'MP',
168
+ 'MQ',
169
+ 'MR',
170
+ 'MS',
171
+ 'MT',
172
+ 'MU',
173
+ 'MV',
174
+ 'MW',
175
+ 'MX',
176
+ 'MY',
177
+ 'MZ',
178
+ 'NA',
179
+ 'NC',
180
+ 'NE',
181
+ 'NF',
182
+ 'NG',
183
+ 'NI',
184
+ 'NL',
185
+ 'NO',
186
+ 'NP',
187
+ 'NR',
188
+ 'NU',
189
+ 'NZ',
190
+ 'OM',
191
+ 'PA',
192
+ 'PE',
193
+ 'PF',
194
+ 'PG',
195
+ 'PH',
196
+ 'PK',
197
+ 'PL',
198
+ 'PM',
199
+ 'PN',
200
+ 'PR',
201
+ 'PS',
202
+ 'PT',
203
+ 'PW',
204
+ 'PY',
205
+ 'QA',
206
+ 'RE',
207
+ 'RO',
208
+ 'RS',
209
+ 'RU',
210
+ 'RW',
211
+ 'SA',
212
+ 'SB',
213
+ 'SC',
214
+ 'SD',
215
+ 'SE',
216
+ 'SG',
217
+ 'SH',
218
+ 'SI',
219
+ 'SJ',
220
+ 'SK',
221
+ 'SL',
222
+ 'SM',
223
+ 'SN',
224
+ 'SO',
225
+ 'SR',
226
+ 'SS',
227
+ 'ST',
228
+ 'SV',
229
+ 'SX',
230
+ 'SY',
231
+ 'SZ',
232
+ 'TC',
233
+ 'TD',
234
+ 'TF',
235
+ 'TG',
236
+ 'TH',
237
+ 'TJ',
238
+ 'TK',
239
+ 'TL',
240
+ 'TM',
241
+ 'TN',
242
+ 'TO',
243
+ 'TR',
244
+ 'TT',
245
+ 'TV',
246
+ 'TW',
247
+ 'TZ',
248
+ 'UA',
249
+ 'UG',
250
+ 'UM',
251
+ 'US',
252
+ 'UY',
253
+ 'UZ',
254
+ 'VA',
255
+ 'VC',
256
+ 'VE',
257
+ 'VG',
258
+ 'VI',
259
+ 'VN',
260
+ 'VU',
261
+ 'WF',
262
+ 'WS',
263
+ 'XK',
264
+ 'YE',
265
+ 'YT',
266
+ 'ZA',
267
+ 'ZM',
268
+ 'ZW',
269
+ ],
270
+ description: 'ISO 3166-1 alpha 2 country code',
271
+ });
272
+
16
273
  const address = () =>
17
274
  mergeSchemas(genericAddress(), {
18
- properties: { country: { minLength: 2, maxLength: 2, description: 'ISO 3166-1 alpha 2 country code' } },
275
+ properties: { country: country() },
19
276
  });
20
277
 
21
278
  const addressWithRequiredLocation = () => mergeSchemas(address(), { required: ['location'] });
@@ -147,6 +404,7 @@ const findByFiscal = () => ({
147
404
 
148
405
  module.exports = {
149
406
  date,
407
+ country,
150
408
  address,
151
409
  addressWithRequiredLocation,
152
410
  findAll,
@@ -1,4 +1,5 @@
1
1
  const { uuid, datetime, money, updateSelfRequest, updateResponse, pickProperties } = require('@gls_spain/common-json-schemas');
2
+ const { country } = require('./common');
2
3
 
3
4
  const derivationRate = () => ({
4
5
  title: 'derivation rate',
@@ -44,6 +45,88 @@ const expirationSettings = () => ({
44
45
  additionalProperties: false,
45
46
  });
46
47
 
48
+ const saleSize = () => ({
49
+ type: 'string',
50
+ enum: ['xs', 's', 'm', 'l', 'xl'],
51
+ });
52
+
53
+ const saleZone = () => ({
54
+ type: 'object',
55
+ properties: {
56
+ name: { type: 'string', trim: true },
57
+ prices: {
58
+ type: 'object',
59
+ properties: {
60
+ xs: money(),
61
+ s: money(),
62
+ m: money(),
63
+ l: money(),
64
+ xl: money(),
65
+ },
66
+ required: ['xs', 's', 'm', 'l', 'xl'],
67
+ additionalProperties: false,
68
+ },
69
+ },
70
+ required: ['name', 'prices'],
71
+ additionalProperties: false,
72
+ });
73
+
74
+ const salePostalCodeZone = () => ({
75
+ type: 'object',
76
+ properties: {
77
+ prefix: {
78
+ type: 'string',
79
+ description: 'include only the postal codes that begin with this prefix',
80
+ },
81
+ zone: {
82
+ oneOf: [
83
+ {
84
+ type: 'string',
85
+ description: 'name of the zone for this country and postal codes, must exist in the zones array',
86
+ },
87
+ {
88
+ type: 'null',
89
+ description: 'set to null to prevent sales to this country and postal codes',
90
+ },
91
+ ],
92
+ },
93
+ },
94
+ required: ['prefix', 'zone'],
95
+ additionalProperties: false,
96
+ });
97
+
98
+ const saleCountry = () => ({
99
+ type: 'object',
100
+ properties: {
101
+ country: country(),
102
+ postalCodesZones: { type: 'array', items: salePostalCodeZone(), uniqueItems: true },
103
+ defaultZone: {
104
+ oneOf: [
105
+ {
106
+ type: 'string',
107
+ description: 'name of the default zone for this country, must exist in the zones array',
108
+ },
109
+ {
110
+ type: 'null',
111
+ description: 'set to null to prevent sales to this country by default',
112
+ },
113
+ ],
114
+ },
115
+ },
116
+ required: ['country', 'postalCodesZones', 'defaultZone'],
117
+ });
118
+
119
+ const salesSettings = () => ({
120
+ title: 'sales settings',
121
+ type: 'object',
122
+ properties: {
123
+ zones: { type: 'array', items: saleZone(), uniqueItems: true, minItems: 1 },
124
+ countries: { type: 'array', items: saleCountry(), uniqueItems: true, minItems: 1 },
125
+ },
126
+ required: ['zones', 'countries'],
127
+ additionalProperties: false,
128
+ });
129
+
47
130
  const defaults = () => ({
48
131
  title: 'defaults',
49
132
  type: 'object',
@@ -54,8 +137,9 @@ const defaults = () => ({
54
137
  deletable: { type: 'boolean' },
55
138
  derivationSettings: derivationSettings(),
56
139
  expirationSettings: expirationSettings(),
140
+ salesSettings: salesSettings(),
57
141
  },
58
- required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'derivationSettings', 'expirationSettings'],
142
+ required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'derivationSettings', 'expirationSettings', 'salesSettings'],
59
143
  additionalProperties: false,
60
144
  });
61
145
 
@@ -71,7 +155,7 @@ const getDefaultsResponse = () => ({
71
155
  const updateDefaultsRequest = () =>
72
156
  updateSelfRequest({
73
157
  type: 'object',
74
- properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
158
+ properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings', 'salesSettings']) },
75
159
  minProperties: 1,
76
160
  additionalProperties: false,
77
161
  });
@@ -81,6 +165,8 @@ const updateDefaultsResponse = () => updateResponse(defaults());
81
165
  module.exports = {
82
166
  derivationSettings,
83
167
  expirationSettings,
168
+ saleSize,
169
+ salesSettings,
84
170
  defaults,
85
171
  getDefaultsResponse,
86
172
  updateDefaultsRequest,
@@ -136,7 +136,7 @@ const expedition = () => ({
136
136
  additionalProperties: false,
137
137
  description: 'not available for incoming expeditions that are not assigned to a shop until reception',
138
138
  },
139
- type: { type: 'string', enum: ['delivery', 'pickup', 'sale'] },
139
+ type: { type: 'string', enum: ['delivery', 'pickup'] },
140
140
  status: {
141
141
  type: 'object',
142
142
  properties: {
@@ -188,6 +188,7 @@ const expedition = () => ({
188
188
  additionalProperties: false,
189
189
  description: 'only available for deliveries and pickups after reception at the shop',
190
190
  },
191
+ sale: mergeSchemas(objectWithUuid(), { description: 'associated sale, only for pickups created because of a sale' }),
191
192
  barcodes: { type: 'array', items: { type: 'string', trim: true } },
192
193
  packageCount: { type: 'integer' },
193
194
  weight: { type: 'number' },
@@ -300,6 +301,7 @@ const createExpeditionWithShop = () => ({
300
301
  'scheduleCode',
301
302
  'date',
302
303
  'expectedDeliveryDate',
304
+ 'sale',
303
305
  'barcodes',
304
306
  'packageCount',
305
307
  'weight',
@@ -346,6 +348,7 @@ const createExpeditionWithNetwork = () => ({
346
348
  'scheduleCode',
347
349
  'date',
348
350
  'expectedDeliveryDate',
351
+ 'sale',
349
352
  'barcodes',
350
353
  'packageCount',
351
354
  'weight',
@@ -3,6 +3,7 @@ const { date } = require('./common');
3
3
  const { expedition, processedWithDriver, processedWithCustomerWithPod } = require('./expeditions');
4
4
  const { shop, objectWithShopId } = require('./shops');
5
5
  const { network, objectWithNetworkId } = require('./networks');
6
+ const { sale } = require('./sales');
6
7
 
7
8
  const objectWithExpirationDate = () => ({
8
9
  type: 'object',
@@ -116,6 +117,14 @@ const upsertNetworkEvent = () => ({
116
117
  additionalProperties: false,
117
118
  });
118
119
 
120
+ const upsertSaleEvent = () => ({
121
+ title: 'upsert sale',
122
+ type: 'object',
123
+ properties: { sale: sale() },
124
+ required: ['sale'],
125
+ additionalProperties: false,
126
+ });
127
+
119
128
  module.exports = {
120
129
  receiveFromDriverEvent,
121
130
  receiveFromCustomerEvent,
@@ -126,4 +135,5 @@ module.exports = {
126
135
  priceEvent,
127
136
  upsertShopEvent,
128
137
  upsertNetworkEvent,
138
+ upsertSaleEvent,
129
139
  };
@@ -7,6 +7,7 @@ const { representative } = require('./representatives');
7
7
  const { shop } = require('./shops');
8
8
  const { expedition } = require('./expeditions');
9
9
  const { integration } = require('./integrations');
10
+ const { sale } = require('./sales');
10
11
 
11
12
  const historicRecord = () => ({
12
13
  title: 'historicRecord',
@@ -18,9 +19,11 @@ const historicRecord = () => ({
18
19
  deletable: { type: 'boolean' },
19
20
  type: {
20
21
  type: 'string',
21
- enum: ['defaults', 'superAdmin', 'network', 'networkAdmin', 'zone', 'representative', 'shop', 'shopUser', 'expedition'],
22
+ enum: ['defaults', 'superAdmin', 'network', 'networkAdmin', 'zone', 'representative', 'shop', 'shopUser', 'expedition', 'sale'],
23
+ },
24
+ document: {
25
+ oneOf: [defaults(), superAdmin(), network(), networkAdmin(), zone(), representative(), shop(), shopUser(), expedition(), sale()],
22
26
  },
23
- document: { oneOf: [defaults(), superAdmin(), network(), networkAdmin(), zone(), representative(), shop(), shopUser(), expedition()] },
24
27
  action: { type: 'string', enum: ['create', 'update', 'delete'] },
25
28
  actionKeys: {
26
29
  type: 'array',
@@ -23,6 +23,7 @@ const network = () => ({
23
23
  createdAt: datetime(),
24
24
  updatedAt: datetime(),
25
25
  deletable: { type: 'boolean' },
26
+ readonly: { type: 'boolean', description: 'readonly networks do not allow updates or adding shops to them' },
26
27
  defaults: {
27
28
  type: 'object',
28
29
  properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
@@ -37,8 +38,17 @@ const network = () => ({
37
38
  fiscal: fiscal(),
38
39
  derivationSettings: derivationSettings(),
39
40
  expirationSettings: expirationSettings(),
41
+ salesSettings: {
42
+ type: 'object',
43
+ properties: {
44
+ networkPercentage: { type: 'integer', minimum: 0 },
45
+ shopPercentage: { type: 'integer', minimum: 0 },
46
+ },
47
+ required: ['networkPercentage', 'shopPercentage'],
48
+ additionalProperties: false,
49
+ },
40
50
  },
41
- required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'defaults', 'name', 'contacts'],
51
+ required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'readonly', 'defaults', 'name', 'contacts', 'salesSettings'],
42
52
  additionalProperties: false,
43
53
  });
44
54
 
@@ -53,9 +63,19 @@ const createNetworkRequest = () =>
53
63
  createRequest({
54
64
  type: 'object',
55
65
  properties: {
56
- ...pickProperties(network(), ['_id', 'createdAt', 'name', 'contacts', 'fiscal', 'derivationSettings', 'expirationSettings']),
66
+ ...pickProperties(network(), [
67
+ '_id',
68
+ 'createdAt',
69
+ 'readonly',
70
+ 'name',
71
+ 'contacts',
72
+ 'fiscal',
73
+ 'derivationSettings',
74
+ 'expirationSettings',
75
+ 'salesSettings',
76
+ ]),
57
77
  },
58
- required: ['name'],
78
+ required: ['name', 'salesSettings'],
59
79
  additionalProperties: false,
60
80
  });
61
81
 
@@ -75,7 +95,9 @@ const findNetworksResponse = () => findResponse(network());
75
95
  const updateNetworkRequest = () =>
76
96
  updateRequest(findById(), {
77
97
  type: 'object',
78
- properties: { ...pickProperties(network(), ['name', 'contacts'], ['fiscal', 'derivationSettings', 'expirationSettings']) },
98
+ properties: {
99
+ ...pickProperties(network(), ['name', 'contacts', 'salesSettings'], ['fiscal', 'derivationSettings', 'expirationSettings']),
100
+ },
79
101
  minProperties: 1,
80
102
  additionalProperties: false,
81
103
  });