@tillhub/schemas 6.177.0 → 6.178.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.178.0](https://github.com/tillhub/schemas/compare/v6.177.0...v6.178.0) (2022-12-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * **stocks-book:** add stocks book schemas #UNTIL-5820 ([8172c34](https://github.com/tillhub/schemas/commit/8172c34)), closes [#UNTIL-5820](https://github.com/tillhub/schemas/issues/UNTIL-5820)
7
+ * **stocks-book:** fix linter issues ([a4d1ba8](https://github.com/tillhub/schemas/commit/a4d1ba8))
8
+
1
9
  # [6.177.0](https://github.com/tillhub/schemas/compare/v6.176.0...v6.177.0) (2022-12-07)
2
10
 
3
11
 
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ description: 'Location type',
3
+ type: 'string',
4
+ enum: [
5
+ 'client',
6
+ 'branch',
7
+ 'warehouse',
8
+ 'warehouse_shelf'
9
+ ]
10
+ }
package/lib/v0/index.js CHANGED
@@ -14,6 +14,7 @@ module.exports.invoices = require('./invoices')
14
14
  module.exports.accounts = require('./accounts')
15
15
  module.exports.expense_accounts = require('./expense_accounts')
16
16
  module.exports.stock = require('./stock')
17
+ module.exports.stocks_book = require('./stocks_book')
17
18
  module.exports.payment_options = require('./payment_options')
18
19
  module.exports.discounts = require('./discounts')
19
20
  module.exports.staff = require('./staff')
@@ -1,59 +1,23 @@
1
- const { oneOf } = require('../../helpers/payload-or-null')
1
+ const { anyOf, oneOf } = require('../../helpers/payload-or-null')
2
+ const locationType = require('../../common/location_type')
2
3
 
3
4
  module.exports = {
4
- qty: {
5
- anyOf: [
6
- {
7
- type: 'null'
8
- },
9
- {
10
- type: 'number',
11
- description: 'The quantity of this item/product.'
12
- }
13
- ]
14
- },
15
- product: {
16
- anyOf: [
17
- {
18
- type: 'string',
19
- minLength: 1,
20
- maxLength: 64
21
- },
22
- {
23
- type: 'null'
24
- }
25
- ]
26
- },
27
- location: {
28
- anyOf: [
29
- {
30
- type: 'string',
31
- description: 'Alphanumerical uuid of the location, e.g. branch or warehouse',
32
- minLength: 1,
33
- maxLength: 64
34
- },
35
- {
36
- type: 'null'
37
- }
38
- ]
39
- },
40
- location_type: {
41
- anyOf: [
42
- {
43
- type: 'string',
44
- description: 'Location type of stock',
45
- 'enum': [
46
- 'client',
47
- 'branch',
48
- 'warehouse',
49
- 'warehouse_shelf'
50
- ]
51
- },
52
- {
53
- type: 'null'
54
- }
55
- ]
56
- },
5
+ qty: anyOf({
6
+ type: 'number',
7
+ description: 'The quantity of this item/product.'
8
+ }),
9
+ product: anyOf({
10
+ type: 'string',
11
+ minLength: 1,
12
+ maxLength: 64
13
+ }),
14
+ location: anyOf({
15
+ type: 'string',
16
+ description: 'Alphanumerical uuid of the location, e.g. branch or warehouse',
17
+ minLength: 1,
18
+ maxLength: 64
19
+ }),
20
+ location_type: anyOf(locationType),
57
21
  status: oneOf({
58
22
  type: 'string',
59
23
  'enum': [
@@ -1,4 +1,5 @@
1
1
  const { oneOf } = require('../../helpers/payload-or-null')
2
+ const locationType = require('../../common/location_type')
2
3
  const defaultResponse = require('./default-response')
3
4
 
4
5
  module.exports.request = {
@@ -29,15 +30,7 @@ module.exports.request = {
29
30
  description: 'Alphanumeric uuid of the location, e.g. branch uuid or warehouse uuid',
30
31
  format: 'uuid'
31
32
  },
32
- location_type: {
33
- type: 'string',
34
- 'enum': [
35
- 'client',
36
- 'branch',
37
- 'warehouse',
38
- 'warehouse_shelf'
39
- ]
40
- }
33
+ location_type: locationType
41
34
  },
42
35
  required: [
43
36
  'id'
@@ -52,14 +45,7 @@ module.exports.request = {
52
45
  description: 'Alphanumeric uuid of the location, e.g. branch uuid or warehouse uuid',
53
46
  format: 'uuid'
54
47
  },
55
- location_type: {
56
- type: 'string',
57
- 'enum': [
58
- 'branch',
59
- 'warehouse',
60
- 'warehouse_shelf'
61
- ]
62
- }
48
+ location_type: locationType
63
49
  },
64
50
  required: [
65
51
  'id'
@@ -1,5 +1,6 @@
1
1
 
2
2
  const { oneOf } = require('../../helpers/payload-or-null')
3
+ const locationType = require('../../common/location_type')
3
4
  const defaultResponse = require('./default-response')
4
5
 
5
6
  module.exports.request = {
@@ -98,15 +99,7 @@ module.exports.response = {
98
99
  description: 'Alphanumeric uuid of the location, e.g. branch uuid or warehouse uuid',
99
100
  format: 'uuid'
100
101
  },
101
- location_type: {
102
- type: 'string',
103
- 'enum': [
104
- 'client',
105
- 'branch',
106
- 'warehouse',
107
- 'warehouse_shelf'
108
- ]
109
- }
102
+ location_type: locationType
110
103
  },
111
104
  required: [
112
105
  'id'
@@ -121,14 +114,7 @@ module.exports.response = {
121
114
  description: 'Alphanumeric uuid of the location, e.g. branch uuid or warehouse uuid',
122
115
  format: 'uuid'
123
116
  },
124
- location_type: {
125
- type: 'string',
126
- 'enum': [
127
- 'branch',
128
- 'warehouse',
129
- 'warehouse_shelf'
130
- ]
131
- }
117
+ location_type: locationType
132
118
  },
133
119
  required: [
134
120
  'id'
@@ -0,0 +1,149 @@
1
+ const { oneOf } = require('../../helpers/payload-or-null')
2
+ const baseObject = require('../../common/base')
3
+ const locationType = require('../../common/location_type')
4
+ const baseProduct = require('../../v1/products/base').response
5
+ const baseBranch = require('../../v0/branches/base')
6
+
7
+ const simple = {
8
+ metadata: oneOf({
9
+ type: 'object'
10
+ }),
11
+ qty: {
12
+ description: 'The quantity of product remain after book',
13
+ example: 11,
14
+ type: 'number'
15
+ },
16
+ qty_change: {
17
+ description: 'The quantity change with the book',
18
+ example: -2,
19
+ type: 'number'
20
+ },
21
+ product: {
22
+ description: 'The product UUID',
23
+ example: 'b98992bf-52b8-49e5-a44c-9e20eb921422',
24
+ type: 'string',
25
+ format: 'uuid'
26
+ },
27
+ branch: {
28
+ description: 'The branch UUID (use location instead)',
29
+ deprecated: true,
30
+ example: '3f7d26f4-96ff-45b2-8fce-a5c0ca6040b2',
31
+ type: 'string',
32
+ format: 'uuid'
33
+ },
34
+ status: oneOf({
35
+ description: 'The status of the product',
36
+ type: 'string',
37
+ enum: [
38
+ 'available'
39
+ ]
40
+ }),
41
+ location: {
42
+ description: 'Alphanumerical UUID of the location, e.g. branch or warehouse',
43
+ example: '5b26131d-95e8-49a0-a9b4-58397569bba8',
44
+ type: 'string',
45
+ format: 'uuid'
46
+ },
47
+ location_type: locationType,
48
+ from: {
49
+ description: 'Alphanumerical UUID of the stock source location',
50
+ example: '75941a1a-01b0-47b8-806b-83bfa68f3bea',
51
+ type: 'string',
52
+ format: 'uuid'
53
+ },
54
+ to: {
55
+ description: 'Alphanumerical UUID of the stock target location',
56
+ example: '7b8806e7d-810f-4e18-b049-8e2cc6134a41',
57
+ type: 'string',
58
+ format: 'uuid'
59
+ },
60
+ channel: oneOf({
61
+ description: 'The channel from which stock deduction were made',
62
+ type: 'string',
63
+ enum: [
64
+ 'transfer',
65
+ 'transactions',
66
+ 'delivery_notes'
67
+ ]
68
+ }),
69
+ purchase: oneOf({
70
+ description: 'The purchase object data',
71
+ deprecated: true,
72
+ type: 'object'
73
+ }),
74
+ reason: oneOf({
75
+ description: 'Alphanumerical UUID of the reason',
76
+ example: 'a1c1d0c6-f38b-4d89-ae26-7f1aea34985c',
77
+ type: 'string',
78
+ format: 'uuid'
79
+ }),
80
+ comments: oneOf({
81
+ description: 'Additional comments for stock book',
82
+ example: 'Actualized due to inventarisation',
83
+ type: 'string',
84
+ maxLength: 2048
85
+ }),
86
+ images: oneOf({
87
+ description: 'Images associated with stock book',
88
+ type: 'array',
89
+ items: {
90
+ type: 'string',
91
+ minLength: 1
92
+ }
93
+ }),
94
+ type: oneOf({
95
+ description: 'The type of stock book',
96
+ type: 'string',
97
+ enum: [
98
+ 'add',
99
+ 'deduct',
100
+ 'goods_in',
101
+ 'goods_out',
102
+ 'relocation',
103
+ 'sale',
104
+ 'cancellation',
105
+ 'refund',
106
+ 'delivery_note',
107
+ 'delivery_note_refund',
108
+ 'delivery_note_cancellation'
109
+ ]
110
+ })
111
+ }
112
+
113
+ module.exports.simple = simple
114
+
115
+ module.exports.embedded = {
116
+ ...simple,
117
+ product: oneOf([simple.product, {
118
+ type: 'object',
119
+ additionalProperties: false,
120
+ properties: {
121
+ ...baseObject(),
122
+ ...baseProduct
123
+ }
124
+ }]),
125
+ location: oneOf([simple.location, {
126
+ type: 'object',
127
+ additionalProperties: false,
128
+ properties: {
129
+ ...baseObject(),
130
+ ...baseBranch
131
+ }
132
+ }]),
133
+ from: oneOf([simple.from, {
134
+ type: 'object',
135
+ additionalProperties: false,
136
+ properties: {
137
+ ...baseObject(),
138
+ ...baseBranch
139
+ }
140
+ }]),
141
+ to: oneOf([simple.to, {
142
+ type: 'object',
143
+ additionalProperties: false,
144
+ properties: {
145
+ ...baseObject(),
146
+ ...baseBranch
147
+ }
148
+ }])
149
+ }
@@ -0,0 +1,76 @@
1
+ const pick = require('just-pick')
2
+ const { oneOf } = require('../../helpers/payload-or-null')
3
+ const baseObject = require('../../common/base')
4
+ const baseProduct = require('../../v1/products/base').response
5
+ const baseBranch = require('../../v0/branches/base')
6
+ const baseReason = require('../../v0/reasons/base')
7
+ const baseStockBook = require('./base').simple
8
+
9
+ const eventEmbeddedData = {
10
+ product: oneOf({
11
+ type: 'object',
12
+ additionalProperties: false,
13
+ properties: pick({
14
+ ...baseObject(),
15
+ ...baseProduct
16
+ }, [
17
+ 'id',
18
+ 'name',
19
+ 'client_id',
20
+ 'custom_id',
21
+ 'custom_properties',
22
+ 'metadata',
23
+ 'product_group',
24
+ 'is_service'
25
+ ])
26
+ }),
27
+ location: oneOf({
28
+ type: 'object',
29
+ additionalProperties: false,
30
+ properties: pick({
31
+ ...baseObject(),
32
+ ...baseBranch
33
+ }, [
34
+ 'id',
35
+ 'name',
36
+ 'custom_id',
37
+ 'branch_number',
38
+ 'metadata'
39
+ ])
40
+ }),
41
+ reason: oneOf({
42
+ type: 'object',
43
+ additionalProperties: false,
44
+ properties: pick({
45
+ ...baseObject(),
46
+ ...baseReason
47
+ }, [
48
+ 'id',
49
+ 'name',
50
+ 'type'
51
+ ])
52
+ })
53
+ }
54
+
55
+ module.exports = {
56
+ event: {
57
+ $id: 'https://schemas.tillhub.com/v0/stocks-book.create.event.schema.json',
58
+ $schema: 'http://json-schema.org/draft-07/schema#',
59
+ type: 'object',
60
+ additionalProperties: false,
61
+ required: [
62
+ 'id',
63
+ 'qty',
64
+ 'qty_change',
65
+ 'product',
66
+ 'location',
67
+ 'from',
68
+ 'to'
69
+ ],
70
+ properties: {
71
+ ...baseObject(),
72
+ ...baseStockBook,
73
+ ...eventEmbeddedData
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,7 @@
1
+ const read = require('./read')
2
+ const create = require('./create')
3
+
4
+ module.exports = {
5
+ read,
6
+ create
7
+ }
@@ -0,0 +1,21 @@
1
+ const baseObject = require('../../common/base')
2
+ const commonResponse = require('../../common/response')
3
+ const base = require('./base').embedded
4
+
5
+ module.exports.all = {
6
+ response: {
7
+ $id: 'https://schemas.tillhub.com/v0/stocks-book.read.all.response.schema.json',
8
+ $schema: 'http://json-schema.org/draft-07/schema#',
9
+ additionalProperties: false,
10
+ ...commonResponse({
11
+ resultItems: {
12
+ type: 'object',
13
+ additionalProperties: false,
14
+ properties: {
15
+ ...baseObject(),
16
+ ...base
17
+ }
18
+ }
19
+ }, { hasCursor: true })
20
+ }
21
+ }
@@ -1,4 +1,5 @@
1
- const { oneOf } = require('../../helpers/payload-or-null')
1
+ const { anyOf, oneOf } = require('../../helpers/payload-or-null')
2
+ const locationType = require('../../common/location_type')
2
3
  const customProperties = require('../../common/custom_properties')
3
4
 
4
5
  const stockConfigurationLocation = {
@@ -25,23 +26,7 @@ const stockConfigurationLocation = {
25
26
  description: 'Threshold at which a reorder should be triggered',
26
27
  type: 'number'
27
28
  }),
28
- location_type: {
29
- anyOf: [
30
- {
31
- type: 'string',
32
- description: 'Type of stock to be created (supported only for bulk creation of products with stock)',
33
- enum: [
34
- 'client',
35
- 'branch',
36
- 'warehouse',
37
- 'warehouse_shelf'
38
- ]
39
- },
40
- {
41
- type: 'null'
42
- }
43
- ]
44
- },
29
+ location_type: anyOf(locationType),
45
30
  qty: oneOf({
46
31
  description: 'The amount/quantity of stock to be created (supported only for bulk creation of products with stock)',
47
32
  type: 'number'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tillhub/schemas",
3
- "version": "6.177.0",
3
+ "version": "6.178.0",
4
4
  "private": false,
5
5
  "description": "All Tillhub API OpenAPI 3 compatible JSON Schemas.",
6
6
  "main": "./lib/index.js",
@@ -0,0 +1,18 @@
1
+ const test = require('tape')
2
+ const validate = require('../helpers/validate-schema')
3
+
4
+ test('Stocks Book: create schema validation', function (t) {
5
+ const createEvent = require('../../lib/v0/stocks_book').create.event
6
+ const { valid, error } = validate(createEvent)
7
+ t.ok(valid, 'create event schema is valid')
8
+ t.error(error, 'should not get any error')
9
+ t.end()
10
+ })
11
+
12
+ test('Stocks Book: read schema validation', function (t) {
13
+ const readAllResponse = require('../../lib/v0/stocks_book').read.all.response
14
+ const { valid, error } = validate(readAllResponse)
15
+ t.ok(valid, 'read all response schema is valid')
16
+ t.error(error, 'should not get any error')
17
+ t.end()
18
+ })