rts2003-so 1.0.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/LICENSE +21 -0
- package/README.md +55 -0
- package/index.js +143 -0
- package/package.json +28 -0
- package/test.js +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Briansaw
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# deep-clone
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/aws-sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/aws-sdk)
|
|
5
|
+
|
|
6
|
+
Simple deep clone JavaScript native types, like Object, Array, and primitives.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
Install with [npm](https://www.npmjs.com/):
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
$ npm install --save rts-2003-so
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
const { SingleSignOn, RTS2003_SO_ENDPOINT, RTS2003_SO_SECRET_KEY } = require('rts2003-so');
|
|
20
|
+
|
|
21
|
+
process.env.RTS2003_SO_ENDPOINT = 'custom-endpoint';
|
|
22
|
+
process.env.RTS2003_SO_SECRET_KEY = 'custom-secret-key';
|
|
23
|
+
|
|
24
|
+
// show env
|
|
25
|
+
console.log('ENDPOINT Key:', RTS2003_SO_ENDPOINT);
|
|
26
|
+
console.log('SECRET_KEY Key:', RTS2003_SO_SECRET_KEY);
|
|
27
|
+
|
|
28
|
+
// use new class
|
|
29
|
+
const sso = new SingleSignOn();
|
|
30
|
+
|
|
31
|
+
// user register
|
|
32
|
+
const result = sso.userRegister({
|
|
33
|
+
"email": "string",
|
|
34
|
+
"first_name": "string",
|
|
35
|
+
"last_name": "string",
|
|
36
|
+
"is_active": 0,
|
|
37
|
+
"created_by": 0
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// user update
|
|
41
|
+
const result = sso.userUpdate({
|
|
42
|
+
"id": 0,
|
|
43
|
+
"email": "string",
|
|
44
|
+
"first_name": "string",
|
|
45
|
+
"last_name": "string",
|
|
46
|
+
"is_active": 0,
|
|
47
|
+
"updated_by": 0
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// user delete
|
|
51
|
+
const result = sso.userDelete({
|
|
52
|
+
"id": 0,
|
|
53
|
+
"deleted_by": 0
|
|
54
|
+
});
|
|
55
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const fetch = require('node-fetch');
|
|
2
|
+
|
|
3
|
+
const RTS2003_SO_ENDPOINT = process.env.RTS2003_SO_ENDPOINT || '';
|
|
4
|
+
const RTS2003_SO_SECRET_KEY = process.env.RTS2003_SO_SECRET_KEY || '';
|
|
5
|
+
|
|
6
|
+
class SingleSignOn {
|
|
7
|
+
constructor(RTS2003_SO_ENDPOINT, RTS2003_SO_SECRET_KEY) {
|
|
8
|
+
this.endpoint = RTS2003_SO_ENDPOINT;
|
|
9
|
+
this.secretKey = RTS2003_SO_SECRET_KEY;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async userRegister(dataToSend = {
|
|
13
|
+
email,
|
|
14
|
+
first_name,
|
|
15
|
+
last_name,
|
|
16
|
+
is_active,
|
|
17
|
+
created_by
|
|
18
|
+
}) {
|
|
19
|
+
try {
|
|
20
|
+
if (!this.endpoint) {
|
|
21
|
+
return { message: "Environment endpoint not found", statusCode: 400, error: false };
|
|
22
|
+
}
|
|
23
|
+
if (!this.secretKey) {
|
|
24
|
+
return { message: "Environment secret key not found", statusCode: 400, error: false };
|
|
25
|
+
}
|
|
26
|
+
if (!dataToSend.email) {
|
|
27
|
+
return { message: "Field email not found", statusCode: 400, error: false };
|
|
28
|
+
}
|
|
29
|
+
if (!secret_key.first_name) {
|
|
30
|
+
return { message: "Field first_name not found", statusCode: 400, error: false };
|
|
31
|
+
}
|
|
32
|
+
if (!secret_key.last_name) {
|
|
33
|
+
return { message: "Field last_name not found", statusCode: 400, error: false };
|
|
34
|
+
}
|
|
35
|
+
if (!secret_key.is_active) {
|
|
36
|
+
return { message: "Field is_active not found", statusCode: 400, error: false };
|
|
37
|
+
}
|
|
38
|
+
if (!secret_key.created_by) {
|
|
39
|
+
return { message: "Field created_by not found", statusCode: 400, error: false };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const response = await fetch(`${this.endpoint}/user/register/${this.secretKey}`, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(dataToSend)
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const responseData = await response.json();
|
|
51
|
+
|
|
52
|
+
return responseData;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return { message: error, statusCode: 500, error: true };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async userUpdate(dataToSend = {
|
|
59
|
+
id,
|
|
60
|
+
first_name,
|
|
61
|
+
last_name,
|
|
62
|
+
is_active,
|
|
63
|
+
updated_by
|
|
64
|
+
}) {
|
|
65
|
+
try {
|
|
66
|
+
if (!this.endpoint) {
|
|
67
|
+
return { message: "Environment endpoint not found", statusCode: 400, error: false };
|
|
68
|
+
}
|
|
69
|
+
if (!this.secretKey) {
|
|
70
|
+
return { message: "Environment secret key not found", statusCode: 400, error: false };
|
|
71
|
+
}
|
|
72
|
+
if (!dataToSend.id) {
|
|
73
|
+
return { message: "Field id not found", statusCode: 400, error: false };
|
|
74
|
+
}
|
|
75
|
+
if (!secret_key.first_name) {
|
|
76
|
+
return { message: "Field first_name not found", statusCode: 400, error: false };
|
|
77
|
+
}
|
|
78
|
+
if (!secret_key.last_name) {
|
|
79
|
+
return { message: "Field last_name not found", statusCode: 400, error: false };
|
|
80
|
+
}
|
|
81
|
+
if (!secret_key.is_active) {
|
|
82
|
+
return { message: "Field is_active not found", statusCode: 400, error: false };
|
|
83
|
+
}
|
|
84
|
+
if (!secret_key.updated_by) {
|
|
85
|
+
return { message: "Field updated_by not found", statusCode: 400, error: false };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const response = await fetch(`${this.endpoint}/user/update/${this.secretKey}`, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify(dataToSend)
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const responseData = await response.json();
|
|
97
|
+
|
|
98
|
+
return responseData;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return { message: error, statusCode: 500, error: true };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async userDelete(dataToSend = {
|
|
105
|
+
id,
|
|
106
|
+
deleted_by
|
|
107
|
+
}) {
|
|
108
|
+
try {
|
|
109
|
+
if (!this.endpoint) {
|
|
110
|
+
return { message: "Environment endpoint not found", statusCode: 400, error: false };
|
|
111
|
+
}
|
|
112
|
+
if (!this.secretKey) {
|
|
113
|
+
return { message: "Environment secret key not found", statusCode: 400, error: false };
|
|
114
|
+
}
|
|
115
|
+
if (!dataToSend.id) {
|
|
116
|
+
return { message: "Field id not found", statusCode: 400, error: false };
|
|
117
|
+
}
|
|
118
|
+
if (!secret_key.deleted_by) {
|
|
119
|
+
return { message: "Field deleted_by not found", statusCode: 400, error: false };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const response = await fetch(`${this.endpoint}/user/delete/${this.secretKey}`, {
|
|
123
|
+
method: 'POST',
|
|
124
|
+
headers: {
|
|
125
|
+
'Content-Type': 'application/json',
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify(dataToSend)
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const responseData = await response.json();
|
|
131
|
+
|
|
132
|
+
return responseData;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return { message: error, statusCode: 500, error: true };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = {
|
|
140
|
+
RTS2003_SO_ENDPOINT,
|
|
141
|
+
RTS2003_SO_SECRET_KEY,
|
|
142
|
+
SingleSignOn
|
|
143
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rts2003-so",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "RTS2003 SO is service order, manage user, like register, update, delete.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest -o ./test.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/briansaw/rts2003-so.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"RTS2003",
|
|
15
|
+
"so",
|
|
16
|
+
"service-order",
|
|
17
|
+
"RTS2003 service-order"
|
|
18
|
+
],
|
|
19
|
+
"author": "Briansaw (https://github.com/briansaw)",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/briansaw/rts2003-so/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/briansaw/rts2003-so#readme",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"node-fetch": "^3.3.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/test.js
ADDED