@kravc/dos 1.11.18 → 1.11.20

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.
@@ -3,4 +3,16 @@
3
3
  const Read = require('../src/operations/Read')
4
4
  const Profile = require('./Profile')
5
5
 
6
- module.exports = Read(Profile)
6
+ class ReadProfile extends Read(Profile) {
7
+ static get query() {
8
+ return {
9
+ id: {
10
+ description: 'Profile ID',
11
+ required: true,
12
+ example: 'PRO_1'
13
+ }
14
+ }
15
+ }
16
+ }
17
+
18
+ module.exports = ReadProfile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/dos",
3
- "version": "1.11.18",
3
+ "version": "1.11.20",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
package/src/Document.js CHANGED
@@ -9,6 +9,8 @@ const DocumentNotFoundError = require('./errors/DocumentNotFoundError')
9
9
  const { get, omit, capitalize, cloneDeep } = require('lodash')
10
10
 
11
11
  const STORE = {}
12
+ const SYSTEM = 'SYSTEM'
13
+ const IDENTITY_SUBJECT_PATH = 'identity.sub'
12
14
 
13
15
  class Document extends Component {
14
16
  static get idKey() {
@@ -88,12 +90,7 @@ class Document extends Component {
88
90
 
89
91
  const { validator } = context
90
92
  mutation = validator.normalize(mutation, this.id)
91
-
92
- const identitySubjectId = get(context, 'identity.sub')
93
-
94
- if (identitySubjectId) {
95
- mutation.createdBy = identitySubjectId
96
- }
93
+ mutation.createdBy = get(context, IDENTITY_SUBJECT_PATH, SYSTEM)
97
94
 
98
95
  const timestamp = new Date().toJSON()
99
96
  mutation.createdAt = timestamp
@@ -191,12 +188,7 @@ class Document extends Component {
191
188
 
192
189
  static async update(context, query, mutation, originalDocument = null) {
193
190
  mutation = omit(mutation, [ this.idKey, 'createdAt', 'createdBy' ])
194
-
195
- const identitySubjectId = get(context, 'identity.sub')
196
-
197
- if (identitySubjectId) {
198
- mutation.updatedBy = identitySubjectId
199
- }
191
+ mutation.updatedBy = get(context, IDENTITY_SUBJECT_PATH, SYSTEM)
200
192
 
201
193
  const timestamp = new Date().toJSON()
202
194
  mutation.updatedAt = timestamp
@@ -58,14 +58,14 @@ describe('Document', () => {
58
58
  expect(profile.attributes.name).to.eql('Olga')
59
59
  })
60
60
 
61
- it('creates document without identity in context', async () => {
61
+ it('creates document without identity in context as SYSTEM', async () => {
62
62
  const context = { validator }
63
63
  const profile = await Profile.create(context, { name: 'Oleg' })
64
64
 
65
65
  expect(profile.id).to.exist
66
66
  expect(profile.attributes.name).to.eql('Oleg')
67
67
  expect(profile.attributes.createdAt).to.exist
68
- expect(profile.attributes.createdBy).to.not.exist
68
+ expect(profile.attributes.createdBy).to.eql('SYSTEM')
69
69
  })
70
70
 
71
71
  it('returns exiting document from the context', async () => {
@@ -115,14 +115,14 @@ describe('Document', () => {
115
115
  expect(profile.attributes.updatedBy).to.exist
116
116
  })
117
117
 
118
- it('updates document without identity in context', async () => {
118
+ it('updates document without identity in context as SYSTEM', async () => {
119
119
  const context = { validator }
120
120
  const { id } = await Profile.create(context, { name: 'Gustav' })
121
121
 
122
122
  const profile = await Profile.update(context, { id }, { name: 'Jack' })
123
123
 
124
124
  expect(profile.attributes.updatedAt).to.exist
125
- expect(profile.attributes.updatedBy).to.not.exist
125
+ expect(profile.attributes.updatedBy).to.eql('SYSTEM')
126
126
  })
127
127
 
128
128
  it('throws "DocumentNotFoundError" if document not found', async () => {
@@ -291,7 +291,7 @@ describe('Service', () => {
291
291
  expect(response.statusCode).to.eql(201)
292
292
 
293
293
  request = {
294
- url: 'http://localhost:3000/api/UpdateProfile?id=HELLO_WORLD',
294
+ url: 'http://localhost:3000/api/UpdateProfile?id=HELLO_WORLD&tags=["tag1","tag2"]',
295
295
  body: JSON.stringify({ name: 'HTTP test!' }),
296
296
  method: 'PATCH',
297
297
  headers: { authorization }
@@ -65,6 +65,18 @@ const createContext = (service, request, extraContext = {}) => {
65
65
  context.query = queryStringParameters
66
66
  }
67
67
 
68
+ const queryKeys = Object.keys(context.query)
69
+
70
+ for (const queryKey of queryKeys) {
71
+ const value = context.query[queryKey]
72
+
73
+ const isJsonArray = `${value}`.startsWith('["')
74
+
75
+ if (isJsonArray) {
76
+ context.query[queryKey] = JSON.parse(value)
77
+ }
78
+ }
79
+
68
80
  if (body) {
69
81
  const isJSON = isString(body)
70
82
 
@@ -80,7 +80,11 @@ const createSpec = (operations, schemasMap, url) => {
80
80
 
81
81
  for (const name in query) {
82
82
  const queryParameter = { in: 'query', name, type: 'string', ...query[name] }
83
- delete queryParameter.example
83
+
84
+ if (queryParameter.example) {
85
+ queryParameter['x-example'] = queryParameter.example
86
+ delete queryParameter.example
87
+ }
84
88
 
85
89
  parameters.push(queryParameter)
86
90
  }