@caruuto/caruuto-js 0.3.1 → 0.3.3
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 +8 -0
- package/lib/helpers.js +5 -4
- package/lib/performFetch.js +4 -0
- package/lib/terminators.js +61 -0
- package/package.json +2 -2
- package/x.js +9 -6
package/index.js
CHANGED
|
@@ -17,6 +17,14 @@ const CaruutoClient = function (caruutoUrl, caruutoApiKey) {
|
|
|
17
17
|
'history',
|
|
18
18
|
'composed'
|
|
19
19
|
]
|
|
20
|
+
|
|
21
|
+
if (this.options.caruutoUrl === undefined) {
|
|
22
|
+
throw new Error('Caruuto URL is required')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (this.options.caruutoApiKey === undefined || !this.options.caruutoApiKey) {
|
|
26
|
+
throw new Error('Caruuto API Key is required')
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
// -----------------------------------------
|
package/lib/helpers.js
CHANGED
|
@@ -144,16 +144,17 @@ module.exports = function (CaruutoClient) {
|
|
|
144
144
|
* @api private
|
|
145
145
|
*/
|
|
146
146
|
CaruutoClient.prototype._createRequestObject = function (options) {
|
|
147
|
-
const parsedUri = url.
|
|
148
|
-
const requestObject =
|
|
147
|
+
const parsedUri = new url.URL(options.uri)
|
|
148
|
+
const requestObject = {
|
|
149
|
+
...options,
|
|
149
150
|
uri: {
|
|
150
151
|
href: parsedUri.href,
|
|
151
152
|
hostname: parsedUri.hostname,
|
|
152
|
-
path: parsedUri.
|
|
153
|
+
path: parsedUri.pathname,
|
|
153
154
|
port: parsedUri.port,
|
|
154
155
|
protocol: parsedUri.protocol
|
|
155
156
|
}
|
|
156
|
-
}
|
|
157
|
+
}
|
|
157
158
|
|
|
158
159
|
if (this.headers) {
|
|
159
160
|
requestObject.headers = this.headers
|
package/lib/performFetch.js
CHANGED
package/lib/terminators.js
CHANGED
|
@@ -163,6 +163,53 @@ module.exports = function (CaruutoClient) {
|
|
|
163
163
|
uri: this._buildURL({ status: true })
|
|
164
164
|
})
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Update the documents affect by the saved query
|
|
168
|
+
*
|
|
169
|
+
* @param {Object} update
|
|
170
|
+
* @return Promise
|
|
171
|
+
* @api public
|
|
172
|
+
*/
|
|
173
|
+
CaruutoClient.prototype.uploadFile = function (file) {
|
|
174
|
+
this.terminator = 'uploadFile'
|
|
175
|
+
|
|
176
|
+
const requestPayload = {
|
|
177
|
+
method: 'POST',
|
|
178
|
+
uri: this._buildURL()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// this._setHeader('content-type', 'application/json')
|
|
182
|
+
|
|
183
|
+
// if (this._isValidHook()) {
|
|
184
|
+
// requestPayload.body = update
|
|
185
|
+
|
|
186
|
+
// this._setHeader('content-type', 'text/plain')
|
|
187
|
+
// } else {
|
|
188
|
+
// if (this.isClient) {
|
|
189
|
+
// if (!this.isClient.id && !this.isClient.self) {
|
|
190
|
+
// throw new Error(
|
|
191
|
+
// 'Unable to run update on all clients. Please use whereClientIs() or whereClientIsSelf() filters.'
|
|
192
|
+
// )
|
|
193
|
+
// }
|
|
194
|
+
|
|
195
|
+
// // Remove `clientId` from the payload.
|
|
196
|
+
// if (update.clientId) {
|
|
197
|
+
// delete update.clientId
|
|
198
|
+
// }
|
|
199
|
+
|
|
200
|
+
// requestPayload.body = update
|
|
201
|
+
// } else {
|
|
202
|
+
|
|
203
|
+
requestPayload.body = {
|
|
204
|
+
file
|
|
205
|
+
}
|
|
206
|
+
// }
|
|
207
|
+
// }
|
|
208
|
+
|
|
209
|
+
console.log('requestPayload :>> ', requestPayload)
|
|
210
|
+
|
|
211
|
+
return this._createRequestObject(requestPayload)
|
|
212
|
+
}
|
|
166
213
|
|
|
167
214
|
/**
|
|
168
215
|
* Update the documents affect by the saved query
|
|
@@ -235,4 +282,18 @@ module.exports = function (CaruutoClient) {
|
|
|
235
282
|
|
|
236
283
|
return this._createRequestObject(requestPayload)
|
|
237
284
|
}
|
|
285
|
+
|
|
286
|
+
CaruutoClient.prototype.insertDataPoint = function (parameters) {
|
|
287
|
+
this.endpoint = 'respond'
|
|
288
|
+
|
|
289
|
+
const requestPayload = {
|
|
290
|
+
body: parameters,
|
|
291
|
+
method: 'POST',
|
|
292
|
+
uri: this._buildURL()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
this._setHeader('content-type', 'application/json')
|
|
296
|
+
|
|
297
|
+
return this._createRequestObject(requestPayload)
|
|
298
|
+
}
|
|
238
299
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caruuto/caruuto-js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A high-level library for interacting with Caruuto",
|
|
5
5
|
"exports": "./index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"eslint-plugin-react": "^7.32.2",
|
|
48
48
|
"form-data": "^4.0.0",
|
|
49
49
|
"husky": "^8.0.0",
|
|
50
|
-
"lint-staged": "^
|
|
50
|
+
"lint-staged": "^12.5.0",
|
|
51
51
|
"mockery": "^1.7.0",
|
|
52
52
|
"nock": "^12.0.0",
|
|
53
53
|
"nyc": "^15.0.1",
|
package/x.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
const { createClient } = require('./index')
|
|
2
2
|
|
|
3
3
|
;(async () => {
|
|
4
|
-
const x = createClient('https://
|
|
4
|
+
const x = createClient('https://localcaruuto.com/api', 'apiKey-xyz')
|
|
5
5
|
|
|
6
|
-
x.
|
|
7
|
-
// x.whereFieldContains('title', 'John')
|
|
8
|
-
x.goToPage(1)
|
|
6
|
+
// const signedUrl = await x.inMedia('radical').getSignedUrl('test.jpg')
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
// console.log(signedUrl)
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
const y = await x.insertDataPoint({
|
|
11
|
+
memberId: '0bcdd373-fbb6-4998-b0ed-57c842709acc',
|
|
12
|
+
optionId: '10',
|
|
13
|
+
questionId: 'f373b0a2-9c87-41f1-af49-f643da8f836c'
|
|
14
|
+
})
|
|
15
|
+
console.log('y :>> ', y)
|
|
13
16
|
})()
|