@caruuto/caruuto-js 0.1.0 → 0.2.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/index.js CHANGED
@@ -5,6 +5,18 @@ const CaruutoClient = function (caruutoUrl, caruutoApiKey) {
5
5
 
6
6
  this.options.version = '1'
7
7
  this.options.callback = this._processRequest.bind(this)
8
+
9
+ this.reservedProperties = [
10
+ '_id',
11
+ 'apiVersion',
12
+ 'createdBy',
13
+ 'createdAt',
14
+ 'lastModifiedAt',
15
+ 'lastModifiedBy',
16
+ 'v',
17
+ 'history',
18
+ 'composed'
19
+ ]
8
20
  }
9
21
 
10
22
  // -----------------------------------------
package/lib/helpers.js CHANGED
@@ -38,7 +38,7 @@ module.exports = function (CaruutoClient) {
38
38
  // console.log('options :>> ', options)
39
39
  options = options || {}
40
40
 
41
- options.version = `v${this.options.version || 0}`
41
+ options.version = this.customVersion || `v${this.options.version || 0}`
42
42
 
43
43
  let url = ''
44
44
 
@@ -65,6 +65,10 @@ module.exports = function (CaruutoClient) {
65
65
  url += '/sign'
66
66
  }
67
67
 
68
+ if (options.syncSchema) {
69
+ url += '/sync'
70
+ }
71
+
68
72
  // if (options.config) {
69
73
  // url += '/config'
70
74
  // }
@@ -74,7 +78,7 @@ module.exports = function (CaruutoClient) {
74
78
  }
75
79
 
76
80
  if (options.collections) {
77
- url += '/api/contentTypes'
81
+ url = this.options.caruutoUrl + '/api/contentTypes'
78
82
  }
79
83
 
80
84
  // if (options.stats) {
@@ -41,14 +41,13 @@ module.exports = function (CaruutoClient) {
41
41
  requestObject.headers['content-type'] !== 'application/json'
42
42
  ) {
43
43
  options.json = false
44
+ } else {
45
+ options.json = true
44
46
  }
45
47
 
46
48
  debug(`Querying URI: ${decodeURIComponent(options.uri)}`)
47
49
 
48
- // console.log('options :>> ', options)
49
-
50
50
  const response = await fetch(options.uri, options).catch(err => {
51
- console.log('err :>> ', err)
52
51
  return Promise.reject(err)
53
52
  })
54
53
 
@@ -81,6 +81,8 @@ module.exports = function (CaruutoClient) {
81
81
  uri: this._buildURL({
82
82
  useParams: true
83
83
  })
84
+ }).then(response => {
85
+ return response
84
86
  })
85
87
  }
86
88
 
@@ -207,4 +209,26 @@ module.exports = function (CaruutoClient) {
207
209
 
208
210
  return this._createRequestObject(requestPayload)
209
211
  }
212
+
213
+ /**
214
+ * Sync a database content type with the specified JSON schema.
215
+ *
216
+ * @param {Object} schema
217
+ * @return Promise
218
+ * @api public
219
+ */
220
+ CaruutoClient.prototype.syncSchema = function (schema) {
221
+ this.headers = {
222
+ 'content-type': 'application/json'
223
+ }
224
+
225
+ const requestPayload = {
226
+ method: 'POST',
227
+ uri: this._buildURL({ syncSchema: true })
228
+ }
229
+
230
+ requestPayload.body = schema
231
+
232
+ return this._createRequestObject(requestPayload)
233
+ }
210
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caruuto/caruuto-js",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A high-level library for interacting with Caruuto",
5
5
  "exports": "./index.js",
6
6
  "scripts": {