@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
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@gls_spain/gps-common",
3
+ "version": "27.0.0",
4
+ "description": "Errors, schemas and documentation for the Parcel Shops project",
5
+ "main": "index.js",
6
+ "keywords": [
7
+ "gls"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git@github.com:GLS-Spain/gps-common.git"
12
+ },
13
+ "author": {
14
+ "name": "Cristóbal Valverde Albo",
15
+ "email": "cristobal.valverde@gls-spain.es"
16
+ },
17
+ "license": "UNLICENSED",
18
+ "homepage": "https://github.com/GLS-Spain/gps-common",
19
+ "config": {
20
+ "commitizen": {
21
+ "path": "node_modules/cz-conventional-changelog"
22
+ }
23
+ },
24
+ "husky": {
25
+ "hooks": {
26
+ "pre-commit": "npm run test"
27
+ }
28
+ },
29
+ "devDependencies": {
30
+ "@semantic-release/changelog": "latest",
31
+ "@semantic-release/git": "latest",
32
+ "@semantic-release/npm": "latest",
33
+ "@semantic-release/release-notes-generator": "latest",
34
+ "@types/jest": "latest",
35
+ "ajv": "^6.11.0",
36
+ "commitizen": "latest",
37
+ "cz-conventional-changelog": "latest",
38
+ "eslint": "latest",
39
+ "eslint-config-airbnb-base": "latest",
40
+ "eslint-config-prettier": "latest",
41
+ "eslint-plugin-import": "latest",
42
+ "husky": "latest",
43
+ "jest": "latest",
44
+ "prettier": "latest",
45
+ "redoc-cli": "^0.9.5",
46
+ "semantic-release": "latest"
47
+ },
48
+ "dependencies": {
49
+ "@gls_spain/ajv-options": "^1.0.0",
50
+ "@gls_spain/common-errors": "^1.0.0",
51
+ "@gls_spain/common-json-schemas": "^1.0.0",
52
+ "@gls_spain/winston-transports": "^1.0.0",
53
+ "lodash": "^4.17.15",
54
+ "winston": "^3.2.1",
55
+ "yargs": "^15.1.0"
56
+ },
57
+ "scripts": {
58
+ "commit": "git-cz",
59
+ "semantic-release": "semantic-release",
60
+ "test": "jest",
61
+ "build-json-schemas": "node scripts/build-json-schemas.js --output=build/schemas",
62
+ "build-documentation": "node scripts/build-documentation.js --output=build/documentation/documentation.html"
63
+ },
64
+ "bin": {
65
+ "build-gls-parcel-shops-schemas": "scripts/build-json-schemas.js",
66
+ "build-gls-parcel-shops-documentation": "scripts/build-documentation.js"
67
+ }
68
+ }
@@ -0,0 +1,5 @@
1
+ const { objectWithUuid } = require('@gls_spain/common-json-schemas');
2
+
3
+ const becomeRequest = () => objectWithUuid();
4
+
5
+ module.exports = { becomeRequest };
@@ -0,0 +1,172 @@
1
+ const {
2
+ uuid,
3
+ dateRange,
4
+ address: genericAddress,
5
+ objectWithUuid,
6
+ email,
7
+ phone,
8
+ Point,
9
+ Polygon,
10
+ mergeSchemas,
11
+ } = require('@gls_spain/common-json-schemas');
12
+ const { timezones } = require('@gls_spain/ajv-options');
13
+
14
+ const date = () => ({ type: 'string', format: 'date' });
15
+
16
+ const address = () =>
17
+ mergeSchemas(genericAddress(), {
18
+ properties: { country: { minLength: 2, maxLength: 2, description: 'ISO 3166-1 alpha 2 country code' } },
19
+ });
20
+
21
+ const addressWithRequiredLocation = () => mergeSchemas(address(), { required: ['location'] });
22
+
23
+ const findAll = () => ({
24
+ title: 'find all',
25
+ type: 'object',
26
+ additionalProperties: false,
27
+ });
28
+
29
+ const findById = () => mergeSchemas(objectWithUuid(), { title: 'find by _id' });
30
+
31
+ const findByIds = () => ({
32
+ title: 'find by _ids',
33
+ type: 'object',
34
+ properties: { _ids: { type: 'array', items: uuid(), uniqueItems: true } },
35
+ required: ['_ids'],
36
+ additionalProperties: false,
37
+ });
38
+
39
+ const findByName = () => ({
40
+ title: 'find by name',
41
+ type: 'object',
42
+ properties: { name: { type: 'string', minLength: 3, description: 'search in name' } },
43
+ required: ['name'],
44
+ additionalProperties: false,
45
+ });
46
+
47
+ const findByAddress = () => ({
48
+ title: 'find by address',
49
+ type: 'object',
50
+ properties: { address: { type: 'string', minLength: 3, description: 'search in address fields' } },
51
+ required: ['address'],
52
+ additionalProperties: false,
53
+ });
54
+
55
+ const findByCircularArea = () => ({
56
+ title: 'find by circular area',
57
+ type: 'object',
58
+ properties: {
59
+ point: mergeSchemas(Point(), { description: 'center of the circular area to search' }),
60
+ maxDistance: { type: 'number', exclusiveMinimum: 0, description: 'radius of the circular area in meters' },
61
+ },
62
+ required: ['point', 'maxDistance'],
63
+ additionalProperties: false,
64
+ });
65
+
66
+ const findByPolygonalArea = () => ({
67
+ title: 'find by polygonal area',
68
+ type: 'object',
69
+ properties: { polygon: mergeSchemas(Polygon(), { description: 'search inside this polygonal area' }) },
70
+ required: ['polygon'],
71
+ additionalProperties: false,
72
+ });
73
+
74
+ const findByDate = () => ({
75
+ title: 'find by date',
76
+ type: 'object',
77
+ properties: { date: date() },
78
+ required: ['date'],
79
+ additionalProperties: false,
80
+ });
81
+
82
+ const findByDateRange = () => ({
83
+ title: 'find by date range',
84
+ type: 'object',
85
+ properties: { dateRange: dateRange() },
86
+ required: ['dateRange'],
87
+ additionalProperties: false,
88
+ });
89
+
90
+ const timezone = () => ({ type: 'string', format: 'timezone' });
91
+
92
+ const timezoneNames = () => ({ type: 'string', enum: timezones });
93
+
94
+ const objectWithUuidAndName = () => ({
95
+ title: '_id and name',
96
+ type: 'object',
97
+ properties: {
98
+ _id: uuid(),
99
+ name: { type: 'string' },
100
+ },
101
+ required: ['_id', 'name'],
102
+ additionalProperties: false,
103
+ });
104
+
105
+ const tags = () => ({
106
+ type: 'array',
107
+ items: { type: 'string' },
108
+ uniqueItems: true,
109
+ });
110
+
111
+ const contact = () => ({
112
+ title: 'contact',
113
+ type: 'object',
114
+ properties: {
115
+ name: { type: 'string' },
116
+ email: email(),
117
+ phone: phone(),
118
+ },
119
+ required: ['name', 'email', 'phone'],
120
+ additionalProperties: false,
121
+ });
122
+
123
+ const fiscal = () => ({
124
+ title: 'fiscal data',
125
+ type: 'object',
126
+ properties: {
127
+ iban: { type: 'string' },
128
+ businessName: { type: 'string' },
129
+ nif: { type: 'string' },
130
+ contacts: {
131
+ type: 'array',
132
+ items: contact(),
133
+ },
134
+ address: address(),
135
+ paymentMethod: { type: 'string', enum: ['transfer', 'confirming'] },
136
+ dueDays: { type: 'integer', minimum: 0 },
137
+ activity: { type: 'string', description: 'IAE' },
138
+ retention: { type: 'integer', description: 'invoice retention percentage' },
139
+ },
140
+ required: ['iban', 'businessName', 'nif', 'contacts', 'address', 'paymentMethod', 'dueDays', 'activity', 'retention'],
141
+ additionalProperties: false,
142
+ });
143
+
144
+ const findByFiscal = () => ({
145
+ title: 'find by fiscal',
146
+ type: 'object',
147
+ properties: { fiscal: { type: 'string', minLength: 3, description: 'search by fiscal data' } },
148
+ required: ['fiscal'],
149
+ additionalProperties: false,
150
+ });
151
+
152
+ module.exports = {
153
+ date,
154
+ address,
155
+ addressWithRequiredLocation,
156
+ findAll,
157
+ findById,
158
+ findByIds,
159
+ findByName,
160
+ findByAddress,
161
+ findByCircularArea,
162
+ findByPolygonalArea,
163
+ findByDate,
164
+ findByDateRange,
165
+ timezone,
166
+ timezoneNames,
167
+ objectWithUuidAndName,
168
+ tags,
169
+ contact,
170
+ fiscal,
171
+ findByFiscal,
172
+ };
@@ -0,0 +1,84 @@
1
+ const { money, updateSelfRequest, updateResponse, pickProperties } = require('@gls_spain/common-json-schemas');
2
+
3
+ const derivationRate = () => ({
4
+ title: 'derivation rate',
5
+ type: 'object',
6
+ properties: {
7
+ constant: { ...money(), description: 'fixed amount paid in cents, per package' },
8
+ variableStart: { type: 'number', description: 'weight threshold in kg to start paying the variable, per package' },
9
+ variable: { ...money(), description: 'amount paid in cents for each additional kg beyond the weight threshold, per package' },
10
+ },
11
+ required: ['constant', 'variableStart', 'variable'],
12
+ additionalProperties: false,
13
+ description: 'pricePerPackage = constant + max(0, weight - variableStart) * variable',
14
+ });
15
+
16
+ const derivationSettings = () => ({
17
+ title: 'derivation settings',
18
+ type: 'object',
19
+ properties: {
20
+ networkRate: derivationRate(),
21
+ shopRate: derivationRate(),
22
+ },
23
+ required: ['networkRate', 'shopRate'],
24
+ additionalProperties: false,
25
+ });
26
+
27
+ const expirationSettings = () => ({
28
+ title: 'expiration settings',
29
+ type: 'object',
30
+ properties: {
31
+ expirationDays: {
32
+ type: 'integer',
33
+ minimum: 1,
34
+ description: 'how many natural days it takes for the expedition to expire after arrival, e.g. 10 days',
35
+ },
36
+ reminderDays: {
37
+ type: 'array',
38
+ items: { type: 'integer', minimum: 1 },
39
+ uniqueItems: true,
40
+ description: 'on which days after arrival should a pickup reminder be sent, e.g. on days 3, 6 and 9',
41
+ },
42
+ },
43
+ required: ['expirationDays', 'reminderDays'],
44
+ additionalProperties: false,
45
+ });
46
+
47
+ const defaults = () => ({
48
+ title: 'defaults',
49
+ type: 'object',
50
+ properties: {
51
+ derivationSettings: derivationSettings(),
52
+ expirationSettings: expirationSettings(),
53
+ },
54
+ required: ['derivationSettings', 'expirationSettings'],
55
+ additionalProperties: false,
56
+ });
57
+
58
+ const getDefaultsResponse = () => ({
59
+ type: 'object',
60
+ properties: {
61
+ get: defaults(),
62
+ },
63
+ required: ['get'],
64
+ additionalProperties: false,
65
+ });
66
+
67
+ const updateDefaultsRequest = () =>
68
+ updateSelfRequest({
69
+ type: 'object',
70
+ properties: { ...pickProperties(defaults(), ['derivationSettings', 'expirationSettings']) },
71
+ minProperties: 1,
72
+ additionalProperties: false,
73
+ });
74
+
75
+ const updateDefaultsResponse = () => updateResponse(defaults());
76
+
77
+ module.exports = {
78
+ derivationSettings,
79
+ expirationSettings,
80
+ defaults,
81
+ getDefaultsResponse,
82
+ updateDefaultsRequest,
83
+ updateDefaultsResponse,
84
+ };