@tillhub/schemas 6.182.0 → 6.183.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,11 @@
1
+ # [6.183.0](https://github.com/tillhub/schemas/compare/v6.182.0...v6.183.0) (2022-12-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * **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)
7
+ * **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)
8
+
1
9
  # [6.182.0](https://github.com/tillhub/schemas/compare/v6.181.0...v6.182.0) (2022-12-13)
2
10
 
3
11
 
@@ -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: {
@@ -91,7 +91,7 @@ const simple = {
91
91
  minLength: 1
92
92
  }
93
93
  }),
94
- type: oneOf({
94
+ type: {
95
95
  description: 'The type of stock book',
96
96
  type: 'string',
97
97
  enum: [
@@ -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,27 @@
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
+ enum: eventTypeEnum
23
+ }
24
+ }, ['id', 'created_at', 'qty_change', 'type'])
14
25
 
15
26
  const eventOverrideData = {
16
27
  product: {
@@ -43,15 +54,8 @@ const eventOverrideData = {
43
54
  },
44
55
  reason: oneOf({
45
56
  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
+ type: 'string',
58
+ example: 'Not arbitrary reason'
55
59
  })
56
60
  }
57
61
 
@@ -64,7 +68,9 @@ module.exports = {
64
68
  additionalProperties: false,
65
69
  required: [
66
70
  'id',
71
+ 'created_at',
67
72
  'qty_change',
73
+ 'type',
68
74
  'product',
69
75
  'location'
70
76
  ],
@@ -72,6 +78,6 @@ module.exports = {
72
78
  ...eventBaseData,
73
79
  ...eventOverrideData
74
80
  }
75
- })
81
+ }, { eventEntityExample: 'stocks-book' })
76
82
  }
77
83
  }
@@ -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.183.0",
4
4
  "private": false,
5
5
  "description": "All Tillhub API OpenAPI 3 compatible JSON Schemas.",
6
6
  "main": "./lib/index.js",