@gls_spain/gps-common 27.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.eslintrc.json +11 -0
  2. package/.idea/codeStyles/Project.xml +37 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/gps-common.iml +12 -0
  5. package/.idea/inspectionProfiles/Project_Default.xml +7 -0
  6. package/.idea/jsLibraryMappings.xml +6 -0
  7. package/.idea/misc.xml +6 -0
  8. package/.idea/modules.xml +8 -0
  9. package/.idea/vcs.xml +6 -0
  10. package/.idea/watcherTasks.xml +45 -0
  11. package/.prettierignore +5 -0
  12. package/.prettierrc.json +13 -0
  13. package/.releaserc +17 -0
  14. package/CHANGELOG.md +848 -0
  15. package/README.md +122 -0
  16. package/errors/DatabaseNotEmptyError.js +9 -0
  17. package/errors/DefaultsDoNotExistError.js +9 -0
  18. package/errors/ExpeditionAlreadyExistsError.js +9 -0
  19. package/errors/ExpeditionCannotBeDeletedError.js +9 -0
  20. package/errors/ExpeditionCannotBeUpdatedError.js +9 -0
  21. package/errors/ExpeditionDoesNotExistError.js +9 -0
  22. package/errors/JobDoesNotExistError.js +9 -0
  23. package/errors/NetworkAlreadyExistsError.js +9 -0
  24. package/errors/NetworkCannotBeDeletedError.js +9 -0
  25. package/errors/NetworkDoesNotExistError.js +9 -0
  26. package/errors/RepresentativeAlreadyExistsError.js +9 -0
  27. package/errors/RepresentativeCannotBeDeletedError.js +9 -0
  28. package/errors/RepresentativeDoesNotExistError.js +9 -0
  29. package/errors/ShopAlreadyExistsError.js +9 -0
  30. package/errors/ShopCannotBeDeletedError.js +9 -0
  31. package/errors/ShopDoesNotExistError.js +9 -0
  32. package/errors/ShopNotEnabledError.js +9 -0
  33. package/errors/UserAlreadyExistsError.js +9 -0
  34. package/errors/UserCannotBeDeletedError.js +9 -0
  35. package/errors/UserCannotBeUpdatedError.js +9 -0
  36. package/errors/UserDoesNotExistError.js +9 -0
  37. package/errors/WrongNetworkError.js +9 -0
  38. package/errors/WrongPasswordError.js +9 -0
  39. package/errors/WrongShopError.js +9 -0
  40. package/errors/ZoneAlreadyExistsError.js +9 -0
  41. package/errors/ZoneCannotBeDeletedError.js +9 -0
  42. package/errors/ZoneDoesNotExistError.js +9 -0
  43. package/errors/index.js +88 -0
  44. package/index.js +9 -0
  45. package/index.test.js +35 -0
  46. package/jest.config.js +5 -0
  47. package/open-api-spec/index.js +2920 -0
  48. package/package.json +68 -0
  49. package/schemas/definitions/become.js +5 -0
  50. package/schemas/definitions/common.js +172 -0
  51. package/schemas/definitions/defaults.js +84 -0
  52. package/schemas/definitions/expeditions.js +637 -0
  53. package/schemas/definitions/init.js +37 -0
  54. package/schemas/definitions/integration-events.js +127 -0
  55. package/schemas/definitions/jobs.js +124 -0
  56. package/schemas/definitions/login.js +38 -0
  57. package/schemas/definitions/logout.js +8 -0
  58. package/schemas/definitions/networks.js +107 -0
  59. package/schemas/definitions/pods.js +37 -0
  60. package/schemas/definitions/representatives.js +178 -0
  61. package/schemas/definitions/shops.js +352 -0
  62. package/schemas/definitions/users.js +373 -0
  63. package/schemas/definitions/zones.js +92 -0
  64. package/schemas/index.js +335 -0
  65. package/scripts/build-documentation.js +40 -0
  66. package/scripts/build-json-schemas.js +35 -0
@@ -0,0 +1,352 @@
1
+ const {
2
+ uuid,
3
+ objectWithUuid,
4
+ datetime,
5
+ timeRange,
6
+ createRequest,
7
+ createResponse,
8
+ findRequest,
9
+ findResponse,
10
+ updateRequest,
11
+ updateResponse,
12
+ deleteRequest,
13
+ deleteResponse,
14
+ schemaOrNull,
15
+ mergeSchemas,
16
+ pickProperties,
17
+ } = require('@gls_spain/common-json-schemas');
18
+ const {
19
+ addressWithRequiredLocation,
20
+ findAll,
21
+ findById,
22
+ findByName,
23
+ findByAddress,
24
+ findByCircularArea,
25
+ findByPolygonalArea,
26
+ timezone,
27
+ tags,
28
+ contact,
29
+ fiscal,
30
+ findByFiscal,
31
+ } = require('./common');
32
+ const { network, objectWithNetworkId } = require('./networks');
33
+ const { defaults, derivationSettings, expirationSettings } = require('./defaults');
34
+ const { zone } = require('./zones');
35
+ const { representative } = require('./representatives');
36
+
37
+ const shopDaySchedule = () => ({
38
+ title: 'array of time ranges',
39
+ type: 'array',
40
+ items: timeRange(),
41
+ minItems: 0,
42
+ maxItems: 2,
43
+ additionalProperties: false,
44
+ description: '[ ] or [ [HH:mm:ss, HH:mm:ss] ] or [ [HH:mm:ss, HH:mm:ss], [HH:mm:ss, HH:mm:ss] ]',
45
+ });
46
+
47
+ const shopSchedule = () => ({
48
+ oneOf: [
49
+ {
50
+ title: 'weekly schedule',
51
+ type: 'object',
52
+ properties: {
53
+ type: { type: 'string', enum: ['weekly'] },
54
+ weekly: shopDaySchedule(),
55
+ saturday: shopDaySchedule(),
56
+ },
57
+ required: ['type', 'weekly', 'saturday'],
58
+ additionalProperties: false,
59
+ },
60
+ {
61
+ title: 'daily schedule',
62
+ type: 'object',
63
+ properties: {
64
+ type: { type: 'string', enum: ['daily'] },
65
+ monday: shopDaySchedule(),
66
+ tuesday: shopDaySchedule(),
67
+ wednesday: shopDaySchedule(),
68
+ thursday: shopDaySchedule(),
69
+ friday: shopDaySchedule(),
70
+ saturday: shopDaySchedule(),
71
+ },
72
+ required: ['type', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
73
+ additionalProperties: false,
74
+ },
75
+ ],
76
+ });
77
+
78
+ const shopRepresentative = () => ({
79
+ type: 'object',
80
+ properties: {
81
+ ...pickProperties(representative(), ['_id', 'name']),
82
+ since: datetime(),
83
+ },
84
+ required: ['_id', 'name', 'since'],
85
+ additionalProperties: false,
86
+ });
87
+
88
+ const shop = () => ({
89
+ title: 'shop',
90
+ type: 'object',
91
+ properties: {
92
+ _id: uuid(),
93
+ createdAt: datetime(),
94
+ updatedAt: datetime(),
95
+ deletable: { type: 'boolean' },
96
+ defaults: defaults(),
97
+ network: {
98
+ type: 'object',
99
+ properties: { ...pickProperties(network(), ['_id', 'name', 'integrations', 'derivationSettings', 'expirationSettings']) },
100
+ required: ['_id', 'name', 'integrations'],
101
+ additionalProperties: false,
102
+ },
103
+ zone: {
104
+ type: 'object',
105
+ properties: { ...pickProperties(zone(), ['_id', 'name']) },
106
+ required: ['_id', 'name'],
107
+ additionalProperties: false,
108
+ },
109
+ openingRepresentative: shopRepresentative(),
110
+ managingRepresentative: shopRepresentative(),
111
+ status: {
112
+ type: 'object',
113
+ properties: {
114
+ code: { type: 'string', enum: ['enabled', 'disabled', 'manuallyDisabled'] },
115
+ disabled: {
116
+ type: 'object',
117
+ properties: {
118
+ at: datetime(),
119
+ },
120
+ required: ['at'],
121
+ additionalProperties: false,
122
+ },
123
+ manuallyDisabled: {
124
+ type: 'object',
125
+ properties: {
126
+ at: datetime(),
127
+ reason: { type: 'string' },
128
+ },
129
+ required: ['at', 'reason'],
130
+ additionalProperties: false,
131
+ },
132
+ },
133
+ required: ['code'],
134
+ additionalProperties: false,
135
+ },
136
+ name: { type: 'string' },
137
+ address: addressWithRequiredLocation(),
138
+ capabilities: {
139
+ type: 'array',
140
+ items: { type: 'string', enum: ['deliver', 'pickup'] },
141
+ uniqueItems: true,
142
+ },
143
+ openingSchedule: shopSchedule(),
144
+ timezone: timezone(),
145
+ contacts: {
146
+ type: 'array',
147
+ items: contact(),
148
+ },
149
+ fiscal: fiscal(),
150
+ notes: { type: 'string' },
151
+ derivationSettings: derivationSettings(),
152
+ expirationSettings: expirationSettings(),
153
+ },
154
+ required: [
155
+ '_id',
156
+ 'createdAt',
157
+ 'updatedAt',
158
+ 'deletable',
159
+ 'defaults',
160
+ 'network',
161
+ 'status',
162
+ 'name',
163
+ 'address',
164
+ 'capabilities',
165
+ 'openingSchedule',
166
+ 'timezone',
167
+ 'contacts',
168
+ 'fiscal',
169
+ ],
170
+ additionalProperties: false,
171
+ });
172
+
173
+ const objectWithShopId = () => ({
174
+ type: 'object',
175
+ properties: { shop: objectWithUuid() },
176
+ required: ['shop'],
177
+ additionalProperties: false,
178
+ });
179
+
180
+ const setShopStatus = () => ({
181
+ type: 'object',
182
+ properties: { ...pickProperties(shop().properties.status, ['disabled', 'manuallyDisabled']) },
183
+ additionalProperties: false,
184
+ });
185
+
186
+ const setShopRepresentative = () => ({
187
+ type: 'object',
188
+ properties: {
189
+ ...pickProperties(representative(), ['_id']),
190
+ since: datetime(),
191
+ },
192
+ required: ['_id', 'since'],
193
+ additionalProperties: false,
194
+ });
195
+
196
+ const createShopRequest = () =>
197
+ createRequest({
198
+ type: 'object',
199
+ properties: {
200
+ ...pickProperties(shop(), ['_id', 'createdAt']),
201
+ network: objectWithUuid(),
202
+ zone: objectWithUuid(),
203
+ openingRepresentative: setShopRepresentative(),
204
+ managingRepresentative: setShopRepresentative(),
205
+ status: setShopStatus(),
206
+ ...pickProperties(shop(), [
207
+ 'name',
208
+ 'address',
209
+ 'capabilities',
210
+ 'openingSchedule',
211
+ 'timezone',
212
+ 'contacts',
213
+ 'fiscal',
214
+ 'notes',
215
+ 'derivationSettings',
216
+ 'expirationSettings',
217
+ ]),
218
+ tags: tags(),
219
+ },
220
+ required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone', 'fiscal'],
221
+ additionalProperties: false,
222
+ });
223
+
224
+ const createShopResponse = () => createResponse(shop());
225
+
226
+ const findByStatus = () => ({
227
+ title: 'find by status',
228
+ type: 'object',
229
+ properties: {
230
+ status: {
231
+ type: 'object',
232
+ properties: { ...pickProperties(shop().properties.status, ['code']) },
233
+ required: ['code'],
234
+ additionalProperties: false,
235
+ },
236
+ },
237
+ required: ['status'],
238
+ additionalProperties: false,
239
+ });
240
+
241
+ const findByStatusAndName = () => mergeSchemas(findByStatus(), findByName(), { title: 'find by status and name' });
242
+
243
+ const findByStatusAndCircularArea = () => mergeSchemas(findByStatus(), findByCircularArea(), { title: 'find by status and circular area' });
244
+
245
+ const findByStatusAndPolygonalArea = () =>
246
+ mergeSchemas(findByStatus(), findByPolygonalArea(), { title: 'find by status and polygonal area' });
247
+
248
+ const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
249
+
250
+ const findByNetworkAndName = () => mergeSchemas(findByNetwork(), findByName(), { title: 'find by network and name' });
251
+
252
+ const findByNetworkAndAddress = () => mergeSchemas(findByNetwork(), findByAddress(), { title: 'find by network and address' });
253
+
254
+ const findByNetworkAndStatus = () => mergeSchemas(findByNetwork(), findByStatus(), { title: 'find by network and status' });
255
+
256
+ const findByNetworkAndStatusAndName = () =>
257
+ mergeSchemas(findByNetworkAndStatus(), findByName(), { title: 'find by network and status and name' });
258
+
259
+ const findByNetworkAndStatusAndCircularArea = () =>
260
+ mergeSchemas(findByNetwork(), findByStatusAndCircularArea(), { title: 'find by network and status and circular area' });
261
+
262
+ const findByNetworkAndStatusAndPolygonalArea = () =>
263
+ mergeSchemas(findByNetwork(), findByStatusAndPolygonalArea(), { title: 'find by network and status and polygonal area' });
264
+
265
+ const findByNetworkAndFiscal = () => mergeSchemas(findByNetwork(), findByFiscal(), { title: 'find by network and fiscal data' });
266
+
267
+ const findShopsSuperAdminRequest = () =>
268
+ findRequest({
269
+ oneOf: [
270
+ findAll(),
271
+ findById(),
272
+ findByStatus(),
273
+ findByName(),
274
+ findByAddress(),
275
+ findByStatusAndName(),
276
+ findByStatusAndCircularArea(),
277
+ findByStatusAndPolygonalArea(),
278
+ findByFiscal(),
279
+ findByNetwork(),
280
+ findByNetworkAndStatus(),
281
+ findByNetworkAndName(),
282
+ findByNetworkAndAddress(),
283
+ findByNetworkAndStatusAndName(),
284
+ findByNetworkAndStatusAndCircularArea(),
285
+ findByNetworkAndStatusAndPolygonalArea(),
286
+ findByNetworkAndFiscal(),
287
+ ],
288
+ });
289
+
290
+ const findShopsNetworkAdminRequest = () =>
291
+ findRequest({
292
+ oneOf: [
293
+ findAll(),
294
+ findById(),
295
+ findByStatus(),
296
+ findByName(),
297
+ findByAddress(),
298
+ findByStatusAndName(),
299
+ findByStatusAndCircularArea(),
300
+ findByStatusAndPolygonalArea(),
301
+ findByFiscal(),
302
+ ],
303
+ });
304
+
305
+ const findShopsResponse = () => findResponse(shop());
306
+
307
+ const updateShopRequest = () =>
308
+ updateRequest(
309
+ findById(),
310
+ {
311
+ type: 'object',
312
+ properties: {
313
+ zone: schemaOrNull(objectWithUuid()),
314
+ openingRepresentative: schemaOrNull(setShopRepresentative()),
315
+ managingRepresentative: schemaOrNull(setShopRepresentative()),
316
+ status: setShopStatus(),
317
+ ...pickProperties(
318
+ shop(),
319
+ ['name', 'address', 'capabilities', 'openingSchedule', 'contacts', 'fiscal'],
320
+ ['notes', 'derivationSettings', 'expirationSettings'],
321
+ ),
322
+ },
323
+ minProperties: 1,
324
+ additionalProperties: false,
325
+ },
326
+ {
327
+ type: 'object',
328
+ properties: { ...pickProperties(shop(), ['capabilities']) },
329
+ minProperties: 1,
330
+ additionalProperties: false,
331
+ },
332
+ );
333
+
334
+ const updateShopResponse = () => updateResponse(shop());
335
+
336
+ const deleteShopRequest = () => deleteRequest(findById());
337
+
338
+ const deleteShopResponse = () => deleteResponse(shop());
339
+
340
+ module.exports = {
341
+ shop,
342
+ objectWithShopId,
343
+ createShopRequest,
344
+ createShopResponse,
345
+ findShopsSuperAdminRequest,
346
+ findShopsNetworkAdminRequest,
347
+ findShopsResponse,
348
+ updateShopRequest,
349
+ updateShopResponse,
350
+ deleteShopRequest,
351
+ deleteShopResponse,
352
+ };