@caruuto/caruuto-js 0.3.2 → 0.3.4
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/CHANGELOG.md +11 -0
- 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 +3 -2
- package/x.js +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
7
7
|
|
|
8
|
+
## 0.3.4 - 2024-05-08
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Added encoding package referenced by node-fetch to remove console warning:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
warn - ../caruuto-js/node_modules/node-fetch/lib/index.js
|
|
16
|
+
Module not found: Can't resolve 'encoding' in '../caruuto-js/node_modules/node-fetch/lib'
|
|
17
|
+
```
|
|
18
|
+
|
|
8
19
|
## 0.3.1 - 2024-01-16
|
|
9
20
|
|
|
10
21
|
### Fixed
|
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.4",
|
|
4
4
|
"description": "A high-level library for interacting with Caruuto",
|
|
5
5
|
"exports": "./index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"author": "Jim Lambie <jim@27.works>",
|
|
11
11
|
"license": "GPL",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"cross-fetch": "^
|
|
13
|
+
"cross-fetch": "^4.0.0",
|
|
14
14
|
"debug": "^2.6.1",
|
|
15
|
+
"encoding": "^0.1.13",
|
|
15
16
|
"got": "^11.0.0",
|
|
16
17
|
"mocha": "^10.2.0",
|
|
17
18
|
"query-string": "5.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
|
})()
|