@tillhub/schemas 6.182.0 → 6.184.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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [6.184.0](https://github.com/tillhub/schemas/compare/v6.183.0...v6.184.0) (2022-12-15)
2
+
3
+
4
+ ### Features
5
+
6
+ * **stocks-book:** align schema with requirements v5 #UNTIL-5820 ([1333558](https://github.com/tillhub/schemas/commit/1333558)), closes [#UNTIL-5820](https://github.com/tillhub/schemas/issues/UNTIL-5820)
7
+
8
+ # [6.183.0](https://github.com/tillhub/schemas/compare/v6.182.0...v6.183.0) (2022-12-14)
9
+
10
+
11
+ ### Features
12
+
13
+ * **stocks-book:** add transaction event schema #UNTIL-5820 ([b458c35](https://github.com/tillhub/schemas/commit/b458c35)), closes [#UNTIL-5820](https://github.com/tillhub/schemas/issues/UNTIL-5820)
14
+ * **stocks-book:** align schema with requirements v4 #UNTIL-5820 ([eae9837](https://github.com/tillhub/schemas/commit/eae9837)), closes [#UNTIL-5820](https://github.com/tillhub/schemas/issues/UNTIL-5820)
15
+
1
16
  # [6.182.0](https://github.com/tillhub/schemas/compare/v6.181.0...v6.182.0) (2022-12-13)
2
17
 
3
18
 
@@ -1,4 +1,8 @@
1
- module.exports.getEvent = function getEvent (payload) {
1
+ module.exports.getEvent = function getEvent (payload, {
2
+ eventEntityExample = 'ice-cream',
3
+ eventTypeExample = 'create',
4
+ eventVersionExample = 0
5
+ } = {}) {
2
6
  return {
3
7
  description: 'The webhook data set',
4
8
  type: 'object',
@@ -18,17 +22,17 @@ module.exports.getEvent = function getEvent (payload) {
18
22
  },
19
23
  eventEntity: {
20
24
  description: 'The entity name the event refers to',
21
- example: 'transaction',
25
+ example: eventEntityExample,
22
26
  type: 'string'
23
27
  },
24
28
  eventType: {
25
29
  description: 'The event type (e.g. create, update, delete)',
26
- example: 'create',
30
+ example: eventTypeExample,
27
31
  type: 'string'
28
32
  },
29
33
  eventVersion: {
30
34
  description: 'The event payload version',
31
- example: 0,
35
+ example: eventVersionExample,
32
36
  type: 'number'
33
37
  },
34
38
  entityInstanceId: {
@@ -9,12 +9,12 @@ const simple = {
9
9
  type: 'object'
10
10
  }),
11
11
  qty: {
12
- description: 'The quantity of product remain after book',
12
+ description: 'The quantity of product remain after stock booking',
13
13
  example: 11,
14
14
  type: 'number'
15
15
  },
16
16
  qty_change: {
17
- description: 'The quantity change with the book',
17
+ description: 'The quantity change with the stock booking',
18
18
  example: -2,
19
19
  type: 'number'
20
20
  },
@@ -72,27 +72,27 @@ const simple = {
72
72
  type: 'object'
73
73
  }),
74
74
  reason: oneOf({
75
- description: 'Alphanumerical UUID of the reason',
75
+ description: 'Alphanumerical UUID of the reason: the association with user generated entity which can be specifically set when booking things out manually',
76
76
  example: 'a1c1d0c6-f38b-4d89-ae26-7f1aea34985c',
77
77
  type: 'string',
78
78
  format: 'uuid'
79
79
  }),
80
80
  comments: oneOf({
81
- description: 'Additional comments for stock book',
81
+ description: 'Additional comments for stock booking',
82
82
  example: 'Actualized due to inventarisation',
83
83
  type: 'string',
84
84
  maxLength: 2048
85
85
  }),
86
86
  images: oneOf({
87
- description: 'Images associated with stock book',
87
+ description: 'Images associated with stock booking',
88
88
  type: 'array',
89
89
  items: {
90
90
  type: 'string',
91
91
  minLength: 1
92
92
  }
93
93
  }),
94
- type: oneOf({
95
- description: 'The type of stock book',
94
+ type: {
95
+ description: 'The type of stock booking',
96
96
  type: 'string',
97
97
  enum: [
98
98
  'add',
@@ -107,7 +107,7 @@ const simple = {
107
107
  'delivery_note_refund',
108
108
  'delivery_note_cancellation'
109
109
  ]
110
- })
110
+ }
111
111
  }
112
112
 
113
113
  module.exports.simple = simple
@@ -1,16 +1,28 @@
1
1
  const pick = require('just-pick')
2
2
  const { oneOf } = require('../../helpers/payload-or-null')
3
3
  const baseObject = require('../../common/base')
4
- const { getEvent } = require('../../common/wenhooks')
4
+ const { getEvent } = require('../../common/webhooks')
5
5
  const baseProduct = require('../../v1/products/base').response
6
6
  const baseBranch = require('../../v0/branches/base')
7
- const baseReason = require('../../v0/reasons/base')
8
7
  const baseStockBook = require('./base').simple
9
8
 
9
+ /**
10
+ * We transform all possible types into more generic ones:
11
+ * 'transfer': 'add', 'deduct', 'goods_in', 'goods_out', 'relocation'
12
+ * 'sale': 'sale', 'cancellation', 'refund'
13
+ * 'delivery_note': 'delivery_note', 'delivery_note_cancellation', 'delivery_note_refund"
14
+ */
15
+ const eventTypeEnum = ['transfer', 'sale', 'delivery_note']
16
+
10
17
  const eventBaseData = pick({
11
18
  ...baseObject({ entityName: 'stock book' }),
12
- ...baseStockBook
13
- }, ['id', 'created_at', 'qty_change', 'type', 'channel'])
19
+ ...baseStockBook,
20
+ type: {
21
+ ...baseStockBook.type,
22
+ description: `The type of stock booking: \n'transfer' - indicates a stock change made by the operator for the logistic purpose, positive value for goods-in and negative value for goods-out \n'sale' - indicates a stock change triggered by a sale, positive value for a successful transaction and negative value for a refund or cancellation \n'delivery_note' - indicates a stock change triggered by a delivery note, positive value for a successful delivery note and negative value for a refund or cancellation`,
23
+ enum: eventTypeEnum
24
+ }
25
+ }, ['id', 'created_at', 'qty_change', 'type'])
14
26
 
15
27
  const eventOverrideData = {
16
28
  product: {
@@ -42,16 +54,9 @@ const eventOverrideData = {
42
54
  ])
43
55
  },
44
56
  reason: oneOf({
45
- description: 'The reason of stock book',
46
- type: 'object',
47
- additionalProperties: false,
48
- properties: pick({
49
- ...baseObject(),
50
- ...baseReason
51
- }, [
52
- 'name',
53
- 'type'
54
- ])
57
+ description: 'The reason name: the user generated text which can be specifically set when booking things out manually',
58
+ type: 'string',
59
+ example: 'Not arbitrary reason'
55
60
  })
56
61
  }
57
62
 
@@ -64,7 +69,9 @@ module.exports = {
64
69
  additionalProperties: false,
65
70
  required: [
66
71
  'id',
72
+ 'created_at',
67
73
  'qty_change',
74
+ 'type',
68
75
  'product',
69
76
  'location'
70
77
  ],
@@ -72,6 +79,6 @@ module.exports = {
72
79
  ...eventBaseData,
73
80
  ...eventOverrideData
74
81
  }
75
- })
82
+ }, { eventEntityExample: 'stocks-book' })
76
83
  }
77
84
  }
@@ -3,7 +3,7 @@ const itemsCreate = require('./components/items/create.request')
3
3
  const paymentsCreate = require('./components/payments/create.request')
4
4
  const statusCreate = require('../statuses/create.request')
5
5
 
6
- module.exports = {
6
+ module.exports.request = {
7
7
  $id: 'https://schemas.tillhub.com/v1/transactions.create.request.schema.json',
8
8
  $schema: 'http://json-schema.org/draft-07/schema#',
9
9
  type: 'object',
@@ -1,7 +1,7 @@
1
1
  const commonResponse = require('../../common/response')
2
2
 
3
3
  module.exports.create = {
4
- request: require('./create.request'),
4
+ request: require('./create').request,
5
5
  response: {
6
6
  $id: 'https://schemas.tillhub.com/v1/transactions.post.response.schema.json',
7
7
  $schema: 'http://json-schema.org/draft-07/schema#',
@@ -28,12 +28,13 @@ module.exports.get = {
28
28
 
29
29
  module.exports.legacy = {
30
30
  create: {
31
- request: require('./legacy/create.request'),
31
+ request: require('./legacy/create').request,
32
32
  response: {
33
33
  $id: 'https://schemas.tillhub.com/v1/transactions.legacy.post.response.schema.json',
34
34
  $schema: 'http://json-schema.org/draft-07/schema#',
35
35
  ...commonResponse({ resultItems: require('./legacy/response') })
36
- }
36
+ },
37
+ event: require('./legacy/create').event
37
38
  }
38
39
  }
39
40
 
@@ -1,9 +1,11 @@
1
+ const { getEvent } = require('../../../common/webhooks')
1
2
  const statusCreate = require('../../statuses/create.request')
2
3
  const base = require('./base')
4
+ const response = require('./response')
3
5
  const itemsCreate = require('./items/create.request')
4
6
  const paymentsCreate = require('./payments/create.request')
5
7
 
6
- module.exports = {
8
+ module.exports.request = {
7
9
  $id: 'https://schemas.tillhub.com/v1/transactions.legacy.create.request.schema.json',
8
10
  $schema: 'http://json-schema.org/draft-07/schema#',
9
11
  type: 'object',
@@ -34,3 +36,9 @@ module.exports = {
34
36
  }
35
37
  }
36
38
  }
39
+
40
+ module.exports.event = {
41
+ $id: 'https://schemas.tillhub.com/v1/transactions.legacy.create.event.schema.json',
42
+ $schema: 'http://json-schema.org/draft-07/schema#',
43
+ ...getEvent(response, { eventEntityExample: 'transaction' })
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tillhub/schemas",
3
- "version": "6.182.0",
3
+ "version": "6.184.0",
4
4
  "private": false,
5
5
  "description": "All Tillhub API OpenAPI 3 compatible JSON Schemas.",
6
6
  "main": "./lib/index.js",