@caruuto/caruuto-js 0.3.6 → 0.4.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 +16 -14
- package/lib/extensions/email.js +57 -0
- package/lib/extensions/tokens.js +33 -0
- package/lib/extensions.js +50 -0
- package/lib/performFetch.js +3 -1
- package/package.json +3 -1
- package/scripts/coverage.js +2 -1
- package/x.js +26 -4
package/index.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
const CaruutoClient = function (caruutoUrl, caruutoApiKey) {
|
|
2
|
-
this.options =
|
|
1
|
+
const CaruutoClient = function (caruutoUrl, caruutoApiKey, options = {}) {
|
|
2
|
+
this.options = options
|
|
3
3
|
this.options.caruutoUrl = caruutoUrl
|
|
4
4
|
this.options.caruutoApiKey = caruutoApiKey
|
|
5
5
|
|
|
6
6
|
this.options.version = '1'
|
|
7
7
|
this.options.callback = this._processRequest.bind(this)
|
|
8
8
|
|
|
9
|
-
this.reservedProperties = [
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'lastModifiedAt',
|
|
15
|
-
'lastModifiedBy',
|
|
16
|
-
'v',
|
|
17
|
-
'history',
|
|
18
|
-
'composed'
|
|
9
|
+
this.reservedProperties = this.options.reservedProperties || [
|
|
10
|
+
'created_at',
|
|
11
|
+
'created_by',
|
|
12
|
+
'updated_at',
|
|
13
|
+
'updated_by'
|
|
19
14
|
]
|
|
20
15
|
|
|
21
16
|
if (this.options.caruutoUrl === undefined) {
|
|
@@ -51,11 +46,18 @@ require('./lib/filters')(CaruutoClient)
|
|
|
51
46
|
|
|
52
47
|
require('./lib/terminators')(CaruutoClient)
|
|
53
48
|
|
|
49
|
+
// -----------------------------------------
|
|
50
|
+
|
|
54
51
|
module.exports = CaruutoClient
|
|
55
52
|
|
|
56
53
|
/**
|
|
57
54
|
* Creates a new Caruuto Client.
|
|
58
55
|
*/
|
|
59
|
-
module.exports.createClient = (caruutoUrl, caruutoApiKey) => {
|
|
60
|
-
|
|
56
|
+
module.exports.createClient = (caruutoUrl, caruutoApiKey, options) => {
|
|
57
|
+
const client = new CaruutoClient(caruutoUrl, caruutoApiKey, options)
|
|
58
|
+
|
|
59
|
+
// Attach extensions once the client is created.
|
|
60
|
+
require('./lib/extensions')(CaruutoClient, client)
|
|
61
|
+
|
|
62
|
+
return client
|
|
61
63
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module.exports = function (CaruutoClient, clientInstance) {
|
|
2
|
+
CaruutoClient.prototype.email = {
|
|
3
|
+
find: function (query) {
|
|
4
|
+
this.endpoint = 'email'
|
|
5
|
+
|
|
6
|
+
this.query = query
|
|
7
|
+
|
|
8
|
+
const requestPayload = {
|
|
9
|
+
method: 'GET',
|
|
10
|
+
uri: this._buildURL({ useParams: true })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
this._setHeader('content-type', 'application/json')
|
|
14
|
+
|
|
15
|
+
return this._createRequestObject(requestPayload)
|
|
16
|
+
}.bind(clientInstance),
|
|
17
|
+
queue: function (data) {
|
|
18
|
+
this.endpoint = 'email'
|
|
19
|
+
|
|
20
|
+
const requestPayload = {
|
|
21
|
+
body: data,
|
|
22
|
+
method: 'POST',
|
|
23
|
+
uri: this._buildURL()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this._setHeader('content-type', 'application/json')
|
|
27
|
+
|
|
28
|
+
return this._createRequestObject(requestPayload)
|
|
29
|
+
}.bind(clientInstance),
|
|
30
|
+
update: function (data) {
|
|
31
|
+
this.endpoint = 'email'
|
|
32
|
+
|
|
33
|
+
const requestPayload = {
|
|
34
|
+
body: data,
|
|
35
|
+
method: 'PUT',
|
|
36
|
+
uri: this._buildURL()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this._setHeader('content-type', 'application/json')
|
|
40
|
+
|
|
41
|
+
return this._createRequestObject(requestPayload)
|
|
42
|
+
}.bind(clientInstance),
|
|
43
|
+
delete: function (data) {
|
|
44
|
+
this.endpoint = 'email'
|
|
45
|
+
|
|
46
|
+
const requestPayload = {
|
|
47
|
+
body: data,
|
|
48
|
+
method: 'DELETE',
|
|
49
|
+
uri: this._buildURL()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this._setHeader('content-type', 'application/json')
|
|
53
|
+
|
|
54
|
+
return this._createRequestObject(requestPayload)
|
|
55
|
+
}.bind(clientInstance)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module.exports = function (CaruutoClient, clientInstance) {
|
|
2
|
+
CaruutoClient.prototype.tokens = {
|
|
3
|
+
create: function (data) {
|
|
4
|
+
this.endpoint = 'tokens'
|
|
5
|
+
|
|
6
|
+
const requestPayload = {
|
|
7
|
+
body: data,
|
|
8
|
+
method: 'POST',
|
|
9
|
+
uri: this._buildURL()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
this._setHeader('content-type', 'application/json')
|
|
13
|
+
|
|
14
|
+
return this._createRequestObject(requestPayload)
|
|
15
|
+
}.bind(clientInstance),
|
|
16
|
+
verify: function (token) {
|
|
17
|
+
this.endpoint = 'tokens'
|
|
18
|
+
|
|
19
|
+
const requestPayload = {
|
|
20
|
+
body: {
|
|
21
|
+
token,
|
|
22
|
+
verify: true
|
|
23
|
+
},
|
|
24
|
+
method: 'POST',
|
|
25
|
+
uri: this._buildURL()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this._setHeader('content-type', 'application/json')
|
|
29
|
+
|
|
30
|
+
return this._createRequestObject(requestPayload)
|
|
31
|
+
}.bind(clientInstance)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Each extension should be added to the CaruutoClient prototype, so that
|
|
3
|
+
for example, the email extension can be used as:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
const client = new CaruutoClient()
|
|
7
|
+
client.email.send({ ... })
|
|
8
|
+
client.email.queue({ ... })
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The extension function should take the CaruutoClient prototype as an
|
|
12
|
+
argument and add methods to it.
|
|
13
|
+
For example:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
module.exports = function (CaruutoClient, clientInstance) {
|
|
17
|
+
CaruutoClient.prototype.email = {
|
|
18
|
+
queue: function (data) {
|
|
19
|
+
this.endpoint = 'email/queue'
|
|
20
|
+
|
|
21
|
+
const requestPayload = {
|
|
22
|
+
body: data,
|
|
23
|
+
method: 'POST',
|
|
24
|
+
uri: this._buildURL()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this._setHeader('content-type', 'application/json')
|
|
28
|
+
|
|
29
|
+
return this._createRequestObject(requestPayload)
|
|
30
|
+
}.bind(clientInstance)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
const emailExtension = require('./extensions/email')
|
|
37
|
+
const tokensExtension = require('./extensions/tokens')
|
|
38
|
+
|
|
39
|
+
// Load all extensions from the lib/extensions directory/
|
|
40
|
+
module.exports = function (CaruutoClient, clientInstance) {
|
|
41
|
+
if (typeof emailExtension === 'function') {
|
|
42
|
+
emailExtension(CaruutoClient, clientInstance)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof tokensExtension === 'function') {
|
|
46
|
+
tokensExtension(CaruutoClient, clientInstance)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Add any other extensions here.
|
|
50
|
+
}
|
package/lib/performFetch.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caruuto/caruuto-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "A high-level library for interacting with Caruuto",
|
|
5
5
|
"exports": "./index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"debug": "^2.6.1",
|
|
15
15
|
"encoding": "^0.1.13",
|
|
16
16
|
"got": "^11.0.0",
|
|
17
|
+
"human-interval": "^2.0.1",
|
|
17
18
|
"mocha": "^10.2.0",
|
|
18
19
|
"query-string": "5.0.1"
|
|
19
20
|
},
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
},
|
|
41
42
|
"homepage": "https://github.com/Caruuto/caruuto-js",
|
|
42
43
|
"devDependencies": {
|
|
44
|
+
"chai": "^5.2.0",
|
|
43
45
|
"coveralls": "^3.0.2",
|
|
44
46
|
"eslint": "8.5.0",
|
|
45
47
|
"eslint-config-next": "13.0.5",
|
package/scripts/coverage.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const exec = require('child_process').exec
|
|
4
4
|
|
|
5
|
-
if (process.env
|
|
5
|
+
if (process.env.CI) {
|
|
6
6
|
exec(
|
|
7
7
|
'cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js',
|
|
8
8
|
(err, out) => {
|
|
9
9
|
if (err) console.log(err)
|
|
10
|
+
console.log(out)
|
|
10
11
|
}
|
|
11
12
|
)
|
|
12
13
|
}
|
package/x.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
const { createClient } = require('./index')
|
|
2
2
|
|
|
3
3
|
;(async () => {
|
|
4
|
-
const x = createClient(
|
|
4
|
+
const x = createClient(
|
|
5
|
+
'https://localcaruuto.com/api',
|
|
6
|
+
'12345678900987654321',
|
|
7
|
+
{ reservedProperties: ['created_at'] }
|
|
8
|
+
)
|
|
5
9
|
|
|
6
10
|
// const signedUrl = await x.inMedia('radical').getSignedUrl('test.jpg')
|
|
7
11
|
|
|
@@ -17,10 +21,28 @@ const { createClient } = require('./index')
|
|
|
17
21
|
// const y = await x.find()
|
|
18
22
|
// console.log('y :>> ', y)
|
|
19
23
|
|
|
20
|
-
// const z = await x.
|
|
24
|
+
// const z = await x.tokens.create({
|
|
21
25
|
// email: 'jameslambie@gmail.com',
|
|
26
|
+
// expiry: 7200000,
|
|
22
27
|
// type: 'RESET'
|
|
23
28
|
// })
|
|
24
|
-
const z = await x.verifyToken('q8ug8epjx5hzcg48ku')
|
|
25
|
-
console.log('z :>> ', z)
|
|
29
|
+
// const z = await x.verifyToken('q8ug8epjx5hzcg48ku')
|
|
30
|
+
// console.log('z :>> ', z)
|
|
31
|
+
|
|
32
|
+
// console.log('p :>> ', await x.create({ x: 1 }))
|
|
33
|
+
|
|
34
|
+
console.log('x :>> ', x)
|
|
35
|
+
// console.log('x :>> ', x.email)
|
|
36
|
+
// console.log('x :>> ', x.email.queue)
|
|
37
|
+
// const xx = await x.email.queue({
|
|
38
|
+
// to: 'x@x.com',
|
|
39
|
+
// from: 'z@z.com',
|
|
40
|
+
// templateId: 'test'
|
|
41
|
+
// })
|
|
42
|
+
|
|
43
|
+
// console.log('xx :>> ', xx)
|
|
44
|
+
|
|
45
|
+
const zz = await x.email.find({ sent: true })
|
|
46
|
+
|
|
47
|
+
console.log('zz :>> ', zz)
|
|
26
48
|
})()
|