@kravc/dos 1.8.9 → 1.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/dos",
3
- "version": "1.8.9",
3
+ "version": "1.9.0",
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
@@ -1,12 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const { get, omit, capitalize } = require('lodash')
4
3
  const { ulid } = require('ulid')
5
4
  const Component = require('./Component')
6
5
  const getIdPrefix = require('./helpers/getIdPrefix')
7
6
  const getComponentTitle = require('./helpers/getComponentTitle')
8
7
  const DocumentExistsError = require('./errors/DocumentExistsError')
9
8
  const DocumentNotFoundError = require('./errors/DocumentNotFoundError')
9
+ const { get, omit, capitalize, cloneDeep } = require('lodash')
10
10
 
11
11
  const STORE = {}
12
12
 
@@ -81,10 +81,10 @@ class Document extends Component {
81
81
  const { validator } = context
82
82
  mutation = validator.normalize(mutation, this.id)
83
83
 
84
- const accountId = get(context, 'identity.accountId')
84
+ const identitySubjectId = get(context, 'identity.sub')
85
85
 
86
- if (accountId) {
87
- mutation.createdBy = accountId
86
+ if (identitySubjectId) {
87
+ mutation.createdBy = identitySubjectId
88
88
  }
89
89
 
90
90
  const timestamp = new Date().toJSON()
@@ -139,7 +139,7 @@ class Document extends Component {
139
139
  }
140
140
 
141
141
  static _read({ id = 'NONE' }) {
142
- return STORE[this.name][id]
142
+ return cloneDeep(STORE[this.name][id])
143
143
  }
144
144
 
145
145
  static async index(context, query = {}, options = {}) {
@@ -151,7 +151,7 @@ class Document extends Component {
151
151
  }
152
152
 
153
153
  static _index() {
154
- const items = Object.values(STORE[this.name] || {})
154
+ const items = Object.values(STORE[this.name] || {}).map(cloneDeep)
155
155
 
156
156
  return { items, count: items.length }
157
157
  }
@@ -159,10 +159,10 @@ class Document extends Component {
159
159
  static async update(context, query, mutation, originalDocument = null) {
160
160
  mutation = omit(mutation, [ this.idKey, 'createdAt', 'createdBy' ])
161
161
 
162
- const accountId = get(context, 'identity.accountId')
162
+ const identitySubjectId = get(context, 'identity.sub')
163
163
 
164
- if (accountId) {
165
- mutation.updatedBy = accountId
164
+ if (identitySubjectId) {
165
+ mutation.updatedBy = identitySubjectId
166
166
  }
167
167
 
168
168
  const timestamp = new Date().toJSON()
@@ -201,7 +201,7 @@ class Document extends Component {
201
201
 
202
202
  STORE[this.name][id] = { ...item, ...mutation }
203
203
 
204
- return STORE[this.name][id]
204
+ return cloneDeep(STORE[this.name][id])
205
205
  }
206
206
 
207
207
  static async delete(context, query) {
@@ -22,7 +22,7 @@ Profile.schema = loadSync('examples/Profile.yaml')
22
22
 
23
23
  describe('Document', () => {
24
24
  const validator = new Validator([ Profile.schema ])
25
- const identity = { accountId: 'ACCOUNT_ID' }
25
+ const identity = { sub: 'USER_ID' }
26
26
  const getContext = () => ({ validator, identity })
27
27
 
28
28
  let id
@@ -19,7 +19,7 @@ class Profile extends Document {}
19
19
  Profile.schema = loadSync('examples/Profile.yaml')
20
20
 
21
21
  const validator = new Validator([ Profile.schema ])
22
- const identity = { accountId: 'ACCOUNT_ID' }
22
+ const identity = { sub: 'USER_ID' }
23
23
  const DEFAULT_CONTEXT = { validator, identity }
24
24
 
25
25
  describe('Operation', () => {
@@ -44,7 +44,7 @@ class SystemAuthorization {
44
44
  return { isAuthorized: false, error }
45
45
  }
46
46
 
47
- return { isAuthorized: true, accountId: 'SYSTEM' }
47
+ return { isAuthorized: true, isSystem: true }
48
48
  }
49
49
  }
50
50
 
@@ -5,14 +5,13 @@ const { privateKey: PRIVATE_KEY } = require('./keys')
5
5
 
6
6
  const createAccessToken = (options, attributes) => {
7
7
  const {
8
- algorithm = 'RS256',
8
+ algorithm = 'RS256',
9
9
  privateKey = PRIVATE_KEY,
10
10
  ...jwtOptions
11
11
  } = options
12
12
 
13
13
  const payload = {
14
- sub: 'SESSION_ID',
15
- accountId: 'ACCOUNT_ID',
14
+ sub: 'USER_ID',
16
15
  ...attributes
17
16
  }
18
17