@gls_spain/gps-common 28.0.1 → 30.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": "28.0.1",
3
+ "version": "30.0.0",
4
4
  "description": "Errors, schemas and documentation for the Parcel Shops project",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -104,12 +104,6 @@ const objectWithUuidAndName = () => ({
104
104
  additionalProperties: false,
105
105
  });
106
106
 
107
- const tags = () => ({
108
- type: 'array',
109
- items: { type: 'string', trim: true },
110
- uniqueItems: true,
111
- });
112
-
113
107
  const contact = () => ({
114
108
  title: 'contact',
115
109
  type: 'object',
@@ -167,7 +161,6 @@ module.exports = {
167
161
  timezone,
168
162
  timezoneNames,
169
163
  objectWithUuidAndName,
170
- tags,
171
164
  contact,
172
165
  fiscal,
173
166
  findByFiscal,
@@ -1,4 +1,4 @@
1
- const { money, updateSelfRequest, updateResponse, pickProperties } = require('@gls_spain/common-json-schemas');
1
+ const { uuid, datetime, money, updateSelfRequest, updateResponse, pickProperties } = require('@gls_spain/common-json-schemas');
2
2
 
3
3
  const derivationRate = () => ({
4
4
  title: 'derivation rate',
@@ -48,10 +48,14 @@ const defaults = () => ({
48
48
  title: 'defaults',
49
49
  type: 'object',
50
50
  properties: {
51
+ _id: uuid(),
52
+ createdAt: datetime(),
53
+ updatedAt: datetime(),
54
+ deletable: { type: 'boolean' },
51
55
  derivationSettings: derivationSettings(),
52
56
  expirationSettings: expirationSettings(),
53
57
  },
54
- required: ['derivationSettings', 'expirationSettings'],
58
+ required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'derivationSettings', 'expirationSettings'],
55
59
  additionalProperties: false,
56
60
  });
57
61
 
@@ -17,7 +17,7 @@ const {
17
17
  mergeSchemas,
18
18
  pickProperties,
19
19
  } = require('@gls_spain/common-json-schemas');
20
- const { date, findById, findByIds, tags } = require('./common');
20
+ const { date, findById, findByIds } = require('./common');
21
21
  const { address } = require('./common');
22
22
  const { network, objectWithNetworkId } = require('./networks');
23
23
  const { shop, objectWithShopId } = require('./shops');
@@ -125,8 +125,8 @@ const expedition = () => ({
125
125
  deletable: { type: 'boolean' },
126
126
  network: {
127
127
  type: 'object',
128
- properties: { ...pickProperties(network(), ['_id', 'name', 'integrations']) },
129
- required: ['_id', 'name', 'integrations'],
128
+ properties: { ...pickProperties(network(), ['_id', 'name']) },
129
+ required: ['_id', 'name'],
130
130
  additionalProperties: false,
131
131
  },
132
132
  shop: {
@@ -325,7 +325,6 @@ const createExpeditionWithShop = () => ({
325
325
  'packages',
326
326
  'notes',
327
327
  ]),
328
- tags: tags(),
329
328
  },
330
329
  required: [
331
330
  'shop',
@@ -372,7 +371,6 @@ const createExpeditionWithNetwork = () => ({
372
371
  'packages',
373
372
  'notes',
374
373
  ]),
375
- tags: tags(),
376
374
  },
377
375
  required: [
378
376
  'network',
@@ -1,25 +1,51 @@
1
- const { uuid, datetime, findRequest, findResponse, mergeSchemas, pickProperties } = require('@gls_spain/common-json-schemas');
2
- const { network, objectWithNetworkId } = require('./networks');
3
- const { shop, objectWithShopId } = require('./shops');
4
- const { expedition, objectWithExpeditionId } = require('./expeditions');
1
+ const { uuid, datetime, objectWithUuid, findRequest, findResponse, pickProperties } = require('@gls_spain/common-json-schemas');
2
+ const { superAdmin, networkAdmin, shopUser } = require('./users');
3
+ const { defaults } = require('./defaults');
4
+ const { network } = require('./networks');
5
+ const { zone } = require('./zones');
6
+ const { representative } = require('./representatives');
7
+ const { shop } = require('./shops');
8
+ const { expedition } = require('./expeditions');
5
9
  const { integration } = require('./integrations');
6
10
 
7
- const baseHistoricRecord = () => ({
11
+ const historicRecord = () => ({
12
+ title: 'historicRecord',
8
13
  type: 'object',
9
14
  properties: {
10
15
  _id: uuid(),
11
16
  createdAt: datetime(),
12
17
  updatedAt: datetime(),
18
+ deletable: { type: 'boolean' },
19
+ type: {
20
+ type: 'string',
21
+ enum: ['defaults', 'superAdmin', 'network', 'networkAdmin', 'zone', 'representative', 'shop', 'shopUser', 'expedition'],
22
+ },
13
23
  action: { type: 'string', enum: ['create', 'update', 'delete'] },
14
- actionExtras: { type: 'array', items: { type: 'string' }, description: 'additional details about the action, e.g. what was updated' },
24
+ actionDetails: {
25
+ type: 'array',
26
+ items: {
27
+ type: 'string',
28
+ enum: [
29
+ 'receiveFromDriver',
30
+ 'receiveFromCustomer',
31
+ 'giveToDriver',
32
+ 'giveToCustomer',
33
+ 'redirect',
34
+ 'expirationReminder',
35
+ 'expired',
36
+ 'price',
37
+ ],
38
+ },
39
+ },
15
40
  actor: { type: 'string', description: 'the username of the user who made the action' },
41
+ document: { oneOf: [defaults(), superAdmin(), network(), networkAdmin(), zone(), representative(), shop(), shopUser(), expedition()] },
16
42
  integrations: {
17
43
  type: 'object',
18
44
  additionalProperties: {
19
45
  type: 'object',
20
46
  properties: {
21
47
  at: datetime(),
22
- result: { type: 'string', enum: ['completed', 'failed', 'ignored', 'blocked', 'needsReview'] },
48
+ result: { type: 'string', enum: ['inProgress', 'completed', 'failed', 'ignored', 'blocked', 'needsReview'] },
23
49
  message: { type: 'string' },
24
50
  },
25
51
  required: ['at', 'result', 'message'],
@@ -28,73 +54,30 @@ const baseHistoricRecord = () => ({
28
54
  description: 'one property per integration where the property name is the name of the integration',
29
55
  },
30
56
  },
31
- required: ['_id', 'createdAt', 'updatedAt', 'action', 'actionExtras', 'actor', 'integrations'],
57
+ required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'type', 'action', 'actionDetails', 'actor', 'document', 'integrations'],
32
58
  additionalProperties: false,
33
59
  });
34
60
 
35
- const networkHistoricRecord = () =>
36
- mergeSchemas(baseHistoricRecord(), {
37
- title: 'network historic record',
38
- properties: {
39
- network: network(),
40
- },
41
- required: ['network'],
42
- additionalProperties: false,
43
- });
44
-
45
- const shopHistoricRecord = () =>
46
- mergeSchemas(baseHistoricRecord(), {
47
- title: 'shop historic record',
48
- properties: {
49
- shop: shop(),
50
- },
51
- required: ['shop'],
52
- additionalProperties: false,
53
- });
54
-
55
- const expeditionHistoricRecord = () =>
56
- mergeSchemas(baseHistoricRecord(), {
57
- title: 'expedition historic record',
58
- properties: {
59
- actionExtras: {
60
- type: 'array',
61
- items: {
62
- type: 'string',
63
- enum: [
64
- 'receiveFromDriver',
65
- 'receiveFromCustomer',
66
- 'giveToDriver',
67
- 'giveToCustomer',
68
- 'redirect',
69
- 'expirationReminder',
70
- 'expired',
71
- 'price',
72
- ],
73
- },
74
- },
75
- expedition: expedition(),
76
- },
77
- required: ['expedition'],
78
- additionalProperties: false,
79
- });
80
-
81
- const historicRecord = () => ({ oneOf: [networkHistoricRecord(), shopHistoricRecord(), expeditionHistoricRecord()] });
82
-
83
- const findByNetwork = () => mergeSchemas(objectWithNetworkId(), { title: 'find by network' });
84
-
85
- const findByShop = () => mergeSchemas(objectWithShopId(), { title: 'find by shop' });
86
-
87
- const findByExpedition = () => mergeSchemas(objectWithExpeditionId(), { title: 'find by expedition' });
61
+ const findByTypeAndDocumentId = () => ({
62
+ title: 'find by type and document _id',
63
+ type: 'object',
64
+ properties: {
65
+ ...pickProperties(historicRecord(), ['type']),
66
+ document: objectWithUuid(),
67
+ },
68
+ required: ['type', 'document'],
69
+ additionalProperties: false,
70
+ });
88
71
 
89
- const findByIntegrationAndResult = () => ({
90
- title: 'find by integration and result',
72
+ const findByIntegrationNameAndResult = () => ({
73
+ title: 'find by integration name and result',
91
74
  type: 'object',
92
75
  properties: {
93
76
  integration: {
94
77
  type: 'object',
95
78
  properties: {
96
79
  ...pickProperties(integration(), ['name']),
97
- ...pickProperties(baseHistoricRecord().properties.integrations.additionalProperties, ['result']),
80
+ ...pickProperties(historicRecord().properties.integrations.additionalProperties, ['result']),
98
81
  },
99
82
  required: ['name', 'result'],
100
83
  additionalProperties: false,
@@ -104,15 +87,11 @@ const findByIntegrationAndResult = () => ({
104
87
  additionalProperties: false,
105
88
  });
106
89
 
107
- const findHistoricRecordsRequest = () =>
108
- findRequest({ oneOf: [findByNetwork(), findByShop(), findByExpedition(), findByIntegrationAndResult()] });
90
+ const findHistoricRecordsRequest = () => findRequest({ oneOf: [findByTypeAndDocumentId(), findByIntegrationNameAndResult()] });
109
91
 
110
92
  const findHistoricRecordsResponse = () => findResponse(historicRecord());
111
93
 
112
94
  module.exports = {
113
- networkHistoricRecord,
114
- shopHistoricRecord,
115
- expeditionHistoricRecord,
116
95
  historicRecord,
117
96
  findHistoricRecordsRequest,
118
97
  findHistoricRecordsResponse,
@@ -9,6 +9,7 @@ const integration = () => ({
9
9
  _id: uuid(),
10
10
  createdAt: datetime(),
11
11
  updatedAt: datetime(),
12
+ deletable: { type: 'boolean' },
12
13
  name: { type: 'string' },
13
14
  enabled: { type: 'boolean' },
14
15
  networks: mergeSchemas(omit(findByIds(), 'title'), { description: 'the integration only applies to these networks' }),
@@ -12,7 +12,7 @@ const {
12
12
  deleteResponse,
13
13
  pickProperties,
14
14
  } = require('@gls_spain/common-json-schemas');
15
- const { findAll, findById, findByName, objectWithUuidAndName, tags, contact, fiscal } = require('./common');
15
+ const { findAll, findById, findByName, objectWithUuidAndName, contact, fiscal } = require('./common');
16
16
  const { defaults, derivationSettings, expirationSettings } = require('./defaults');
17
17
 
18
18
  const network = () => ({
@@ -25,7 +25,6 @@ const network = () => ({
25
25
  deletable: { type: 'boolean' },
26
26
  defaults: defaults(),
27
27
  name: { type: 'string', trim: true },
28
- integrations: { type: 'array', items: { type: 'string', enum: ['gls'] }, uniqueItems: true },
29
28
  contacts: {
30
29
  type: 'array',
31
30
  items: contact(),
@@ -34,7 +33,7 @@ const network = () => ({
34
33
  derivationSettings: derivationSettings(),
35
34
  expirationSettings: expirationSettings(),
36
35
  },
37
- required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'defaults', 'name', 'integrations', 'contacts'],
36
+ required: ['_id', 'createdAt', 'updatedAt', 'deletable', 'defaults', 'name', 'contacts'],
38
37
  additionalProperties: false,
39
38
  });
40
39
 
@@ -49,17 +48,7 @@ const createNetworkRequest = () =>
49
48
  createRequest({
50
49
  type: 'object',
51
50
  properties: {
52
- ...pickProperties(network(), [
53
- '_id',
54
- 'createdAt',
55
- 'name',
56
- 'integrations',
57
- 'contacts',
58
- 'fiscal',
59
- 'derivationSettings',
60
- 'expirationSettings',
61
- ]),
62
- tags: tags(),
51
+ ...pickProperties(network(), ['_id', 'createdAt', 'name', 'contacts', 'fiscal', 'derivationSettings', 'expirationSettings']),
63
52
  },
64
53
  required: ['name'],
65
54
  additionalProperties: false,
@@ -16,7 +16,7 @@ const {
16
16
  deleteResponse,
17
17
  pickProperties,
18
18
  } = require('@gls_spain/common-json-schemas');
19
- const { findAll, findById, findByName, objectWithUuidAndName, tags } = require('./common');
19
+ const { findAll, findById, findByName, objectWithUuidAndName } = require('./common');
20
20
  const { zone } = require('./zones');
21
21
 
22
22
  const representative = () => ({
@@ -58,7 +58,6 @@ const createRepresentativeRequest = () =>
58
58
  properties: {
59
59
  ...pickProperties(representative(), ['_id', 'createdAt', 'name', 'emails', 'phones', 'nif']),
60
60
  zones: setRepresentativesZones(),
61
- tags: tags(),
62
61
  },
63
62
  required: ['name', 'nif'],
64
63
  additionalProperties: false,
@@ -24,7 +24,6 @@ const {
24
24
  findByCircularArea,
25
25
  findByPolygonalArea,
26
26
  timezone,
27
- tags,
28
27
  contact,
29
28
  fiscal,
30
29
  findByFiscal,
@@ -96,8 +95,8 @@ const shop = () => ({
96
95
  defaults: defaults(),
97
96
  network: {
98
97
  type: 'object',
99
- properties: { ...pickProperties(network(), ['_id', 'name', 'integrations', 'derivationSettings', 'expirationSettings']) },
100
- required: ['_id', 'name', 'integrations'],
98
+ properties: { ...pickProperties(network(), ['_id', 'name', 'derivationSettings', 'expirationSettings']) },
99
+ required: ['_id', 'name'],
101
100
  additionalProperties: false,
102
101
  },
103
102
  zone: {
@@ -215,7 +214,6 @@ const createShopRequest = () =>
215
214
  'derivationSettings',
216
215
  'expirationSettings',
217
216
  ]),
218
- tags: tags(),
219
217
  },
220
218
  required: ['network', 'status', 'name', 'address', 'openingSchedule', 'timezone'],
221
219
  additionalProperties: false,
@@ -16,7 +16,7 @@ const {
16
16
  mergeSchemas,
17
17
  pickProperties,
18
18
  } = require('@gls_spain/common-json-schemas');
19
- const { address, findAll, findById, findByName, tags } = require('./common');
19
+ const { address, findAll, findById, findByName } = require('./common');
20
20
  const { network, objectWithNetworkId } = require('./networks');
21
21
  const { shop, objectWithShopId } = require('./shops');
22
22
 
@@ -34,7 +34,7 @@ const baseUser = () => ({
34
34
  description: 'a unique username that cannot be changed later',
35
35
  },
36
36
  loginEnabled: { type: 'boolean' },
37
- integrations: { type: 'array', items: { type: 'string', enum: ['glsApi', 'canReceiveAllFromDriver'] }, uniqueItems: true },
37
+ permissions: { type: 'array', items: { type: 'string', enum: ['canReceiveAllFromDriver'] }, uniqueItems: true },
38
38
  role: { type: 'string' },
39
39
  name: { type: 'string', trim: true },
40
40
  emails: { type: 'array', items: email(), uniqueItems: true },
@@ -42,7 +42,7 @@ const baseUser = () => ({
42
42
  nif: { type: 'string', trim: true },
43
43
  address: address(),
44
44
  },
45
- required: ['_id', 'createdAt', 'updatedAt', 'username', 'deletable', 'loginEnabled', 'integrations', 'role', 'name', 'emails', 'phones'],
45
+ required: ['_id', 'createdAt', 'updatedAt', 'username', 'deletable', 'loginEnabled', 'permissions', 'role', 'name', 'emails', 'phones'],
46
46
  additionalProperties: false,
47
47
  });
48
48
 
@@ -55,8 +55,8 @@ const networkAdmin = () =>
55
55
  role: { enum: ['networkAdmin'] },
56
56
  network: {
57
57
  type: 'object',
58
- properties: { ...pickProperties(network(), ['_id', 'name', 'integrations']) },
59
- required: ['_id', 'name', 'integrations'],
58
+ properties: { ...pickProperties(network(), ['_id', 'name']) },
59
+ required: ['_id', 'name'],
60
60
  additionalProperties: false,
61
61
  },
62
62
  },
@@ -70,8 +70,8 @@ const shopUser = () =>
70
70
  role: { enum: ['shopUser'] },
71
71
  network: {
72
72
  type: 'object',
73
- properties: { ...pickProperties(network(), ['_id', 'name', 'integrations']) },
74
- required: ['_id', 'name', 'integrations'],
73
+ properties: { ...pickProperties(network(), ['_id', 'name']) },
74
+ required: ['_id', 'name'],
75
75
  additionalProperties: false,
76
76
  },
77
77
  shop: {
@@ -88,19 +88,7 @@ const createSuperAdminRequest = () =>
88
88
  createRequest({
89
89
  type: 'object',
90
90
  properties: {
91
- ...pickProperties(superAdmin(), [
92
- '_id',
93
- 'createdAt',
94
- 'username',
95
- 'loginEnabled',
96
- 'integrations',
97
- 'name',
98
- 'emails',
99
- 'phones',
100
- 'nif',
101
- 'address',
102
- ]),
103
- tags: tags(),
91
+ ...pickProperties(superAdmin(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
104
92
  password: password(),
105
93
  },
106
94
  required: ['username', 'loginEnabled', 'name', 'password'],
@@ -145,19 +133,7 @@ const createNetworkAdminRequest = () =>
145
133
  {
146
134
  type: 'object',
147
135
  properties: {
148
- ...pickProperties(networkAdmin(), [
149
- '_id',
150
- 'createdAt',
151
- 'username',
152
- 'loginEnabled',
153
- 'integrations',
154
- 'name',
155
- 'emails',
156
- 'phones',
157
- 'nif',
158
- 'address',
159
- ]),
160
- tags: tags(),
136
+ ...pickProperties(networkAdmin(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
161
137
  password: password(),
162
138
  },
163
139
  required: ['username', 'loginEnabled', 'name', 'password'],
@@ -236,19 +212,7 @@ const createShopUserRequest = () =>
236
212
  {
237
213
  type: 'object',
238
214
  properties: {
239
- ...pickProperties(shopUser(), [
240
- '_id',
241
- 'createdAt',
242
- 'username',
243
- 'loginEnabled',
244
- 'integrations',
245
- 'name',
246
- 'emails',
247
- 'phones',
248
- 'nif',
249
- 'address',
250
- ]),
251
- tags: tags(),
215
+ ...pickProperties(shopUser(), ['_id', 'createdAt', 'username', 'loginEnabled', 'name', 'emails', 'phones', 'nif', 'address']),
252
216
  password: password(),
253
217
  },
254
218
  required: ['username', 'loginEnabled', 'name', 'password'],