@caruuto/caruuto-js 0.1.0 → 0.2.1
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 +12 -0
- package/lib/helpers.js +6 -2
- package/lib/performFetch.js +14 -11
- package/lib/terminators.js +28 -0
- package/package.json +1 -1
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
|
|
81
|
+
url = this.options.caruutoUrl + '/api/contentTypes'
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
// if (options.stats) {
|
package/lib/performFetch.js
CHANGED
|
@@ -32,23 +32,26 @@ module.exports = function (CaruutoClient) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (requestObject.body) {
|
|
35
|
-
options.body = requestObject.body
|
|
36
|
-
}
|
|
35
|
+
options.body = JSON.stringify(requestObject.body)
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
requestObject.headers['content-type'] !== 'application/json'
|
|
42
|
-
) {
|
|
43
|
-
options.json = false
|
|
37
|
+
if (options.headers['content-type'] !== 'application/json') {
|
|
38
|
+
options.headers['content-type'] = 'application/json'
|
|
39
|
+
}
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
|
|
42
|
+
// if (
|
|
43
|
+
// requestObject.headers &&
|
|
44
|
+
// requestObject.headers['content-type'] &&
|
|
45
|
+
// requestObject.headers['content-type'] !== 'application/json'
|
|
46
|
+
// ) {
|
|
47
|
+
// options.json = false
|
|
48
|
+
// } else {
|
|
49
|
+
// options.json = true
|
|
50
|
+
// }
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
debug(`Querying URI: ${decodeURIComponent(options.uri)}`)
|
|
49
53
|
|
|
50
54
|
const response = await fetch(options.uri, options).catch(err => {
|
|
51
|
-
console.log('err :>> ', err)
|
|
52
55
|
return Promise.reject(err)
|
|
53
56
|
})
|
|
54
57
|
|
package/lib/terminators.js
CHANGED
|
@@ -14,6 +14,8 @@ module.exports = function (CaruutoClient) {
|
|
|
14
14
|
uri: this._buildURL()
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
this._setHeader('content-type', 'application/json')
|
|
18
|
+
|
|
17
19
|
// if (this._isValidHook()) {
|
|
18
20
|
// requestPayload.body = data
|
|
19
21
|
|
|
@@ -81,6 +83,8 @@ module.exports = function (CaruutoClient) {
|
|
|
81
83
|
uri: this._buildURL({
|
|
82
84
|
useParams: true
|
|
83
85
|
})
|
|
86
|
+
}).then(response => {
|
|
87
|
+
return response
|
|
84
88
|
})
|
|
85
89
|
}
|
|
86
90
|
|
|
@@ -175,6 +179,8 @@ module.exports = function (CaruutoClient) {
|
|
|
175
179
|
uri: this._buildURL()
|
|
176
180
|
}
|
|
177
181
|
|
|
182
|
+
this._setHeader('content-type', 'application/json')
|
|
183
|
+
|
|
178
184
|
// if (this._isValidHook()) {
|
|
179
185
|
// requestPayload.body = update
|
|
180
186
|
|
|
@@ -207,4 +213,26 @@ module.exports = function (CaruutoClient) {
|
|
|
207
213
|
|
|
208
214
|
return this._createRequestObject(requestPayload)
|
|
209
215
|
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Sync a database content type with the specified JSON schema.
|
|
219
|
+
*
|
|
220
|
+
* @param {Object} schema
|
|
221
|
+
* @return Promise
|
|
222
|
+
* @api public
|
|
223
|
+
*/
|
|
224
|
+
CaruutoClient.prototype.syncSchema = function (schema) {
|
|
225
|
+
this.headers = {
|
|
226
|
+
'content-type': 'application/json'
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const requestPayload = {
|
|
230
|
+
method: 'POST',
|
|
231
|
+
uri: this._buildURL({ syncSchema: true })
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
requestPayload.body = schema
|
|
235
|
+
|
|
236
|
+
return this._createRequestObject(requestPayload)
|
|
237
|
+
}
|
|
210
238
|
}
|