rts2003-so 1.1.4 → 1.4.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.
Files changed (3) hide show
  1. package/README.md +30 -7
  2. package/index.js +80 -6
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![NPM version](https://img.shields.io/npm/v/rts2003-so.svg)](https://www.npmjs.com/package/aws-sdk)
4
4
  [![NPM downloads](https://img.shields.io/npm/dm/rts2003-so)](https://www.npmjs.com/package/aws-sdk)
5
5
 
6
- RTS2003 SO is service order, manage user, like register, update, delete.
6
+ RTS2003 SO is service order, manage user, like register, update, delete, update password.
7
7
 
8
8
  ## Install
9
9
 
@@ -16,19 +16,26 @@ $ npm install --save rts2003-so
16
16
  ## Usage
17
17
 
18
18
  ```js
19
- const { SingleSignOn, RTS2003_SO_ENDPOINT, RTS2003_SO_SECRET_KEY } = require('rts2003-so');
19
+ const { SingleSignOn, RTS2003_SO_ENDPOINT, RTS2003_SO_CLIENT_KEY, RTS2003_SO_SECRET_KEY } = require('rts2003-so');
20
20
 
21
21
  process.env.RTS2003_SO_ENDPOINT = 'custom-endpoint';
22
+ process.env.RTS2003_SO_CLIENT_KEY = 'custom-client-id';
22
23
  process.env.RTS2003_SO_SECRET_KEY = 'custom-secret-key';
23
24
 
24
25
  // show env
25
26
  console.log('ENDPOINT Key:', RTS2003_SO_ENDPOINT);
27
+ console.log('CLIENT_KEY Key:', RTS2003_SO_CLIENT_KEY);
26
28
  console.log('SECRET_KEY Key:', RTS2003_SO_SECRET_KEY);
27
29
 
28
30
  // use new class
29
31
  const sso = new SingleSignOn();
30
32
 
31
- // user register
33
+ // api require
34
+ // process.env.RTS2003_SO_ENDPOINT = 'custom-endpoint';
35
+ // process.env.RTS2003_SO_CLIENT_KEY = 'custom-client-id';
36
+ // process.env.RTS2003_SO_SECRET_KEY = 'custom-secret-key';
37
+
38
+ // user register for api
32
39
  const result = sso.userRegister({
33
40
  "email": "string",
34
41
  "first_name": "string",
@@ -37,7 +44,7 @@ const result = sso.userRegister({
37
44
  "created_by": 0
38
45
  });
39
46
 
40
- // user update
47
+ // user update for api
41
48
  const result = sso.userUpdate({
42
49
  "id": 0,
43
50
  "email": "string",
@@ -47,18 +54,34 @@ const result = sso.userUpdate({
47
54
  "updated_by": 0
48
55
  });
49
56
 
50
- // user delete
57
+ // user delete for api
51
58
  const result = sso.userDelete({
52
59
  "id": 0,
53
60
  "deleted_by": 0
54
61
  });
55
62
 
56
- // user refresh token
63
+ // user get user by email for api
64
+ const result = sso.getUserByEmail({
65
+ "email": "string"
66
+ });
67
+
68
+ // user update password for api
69
+ const result = sso.userUpdatePassword({
70
+ "email": "string",
71
+ "current_password": "string",
72
+ "new_password": "string",
73
+ });
74
+
75
+ // frontend require
76
+ // process.env.RTS2003_SO_ENDPOINT = 'custom-endpoint';
77
+ // process.env.RTS2003_SO_CLIENT_KEY = 'custom-client-id';
78
+
79
+ // user refresh token for frontend
57
80
  const result = sso.userRefreshToken({
58
81
  "token": "string"
59
82
  });
60
83
 
61
- // user logout
84
+ // user logout for frontend
62
85
  const result = sso.userLogout({
63
86
  "token": "string"
64
87
  });
package/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
2
2
 
3
3
  const RTS2003_SO_ENDPOINT = process.env.RTS2003_SO_ENDPOINT || '';
4
+ const RTS2003_SO_CLIENT_KEY = process.env.RTS2003_SO_CLIENT_KEY || '';
4
5
  const RTS2003_SO_SECRET_KEY = process.env.RTS2003_SO_SECRET_KEY || '';
5
6
 
6
7
  class SingleSignOn {
7
- constructor(endpoint = RTS2003_SO_ENDPOINT, secretKey = RTS2003_SO_SECRET_KEY) {
8
+ constructor(endpoint = RTS2003_SO_ENDPOINT, clientId = RTS2003_SO_CLIENT_KEY, secretKey = RTS2003_SO_SECRET_KEY) {
8
9
  this.endpoint = endpoint;
10
+ this.clientId = clientId;
9
11
  this.secretKey = secretKey;
10
12
  }
11
13
 
@@ -20,6 +22,9 @@ class SingleSignOn {
20
22
  if (!this.endpoint) {
21
23
  return { message: "Environment endpoint not found", statusCode: 400, error: false };
22
24
  }
25
+ if (!this.clientId) {
26
+ return { message: "Environment client id not found", statusCode: 400, error: false };
27
+ }
23
28
  if (!this.secretKey) {
24
29
  return { message: "Environment secret key not found", statusCode: 400, error: false };
25
30
  }
@@ -39,7 +44,7 @@ class SingleSignOn {
39
44
  return { message: "Field created_by not found", statusCode: 400, error: false };
40
45
  }
41
46
 
42
- const response = await fetch(`${this.endpoint}/user/register/${this.secretKey}`, {
47
+ const response = await fetch(`${this.endpoint}/user/register/${this.clientId}/${this.secretKey}`, {
43
48
  method: 'POST',
44
49
  headers: {
45
50
  'Content-Type': 'application/json',
@@ -85,7 +90,7 @@ class SingleSignOn {
85
90
  return { message: "Field updated_by not found", statusCode: 400, error: false };
86
91
  }
87
92
 
88
- const response = await fetch(`${this.endpoint}/user/update/${this.secretKey}`, {
93
+ const response = await fetch(`${this.endpoint}/user/update/${this.clientId}/${this.secretKey}`, {
89
94
  method: 'POST',
90
95
  headers: {
91
96
  'Content-Type': 'application/json',
@@ -119,7 +124,75 @@ class SingleSignOn {
119
124
  return { message: "Field deleted_by not found", statusCode: 400, error: false };
120
125
  }
121
126
 
122
- const response = await fetch(`${this.endpoint}/user/delete/${this.secretKey}`, {
127
+ const response = await fetch(`${this.endpoint}/user/delete/${this.clientId}/${this.secretKey}`, {
128
+ method: 'POST',
129
+ headers: {
130
+ 'Content-Type': 'application/json',
131
+ },
132
+ body: JSON.stringify(dataToSend)
133
+ });
134
+
135
+ const responseData = await response.json();
136
+
137
+ return responseData;
138
+ } catch (error) {
139
+ return { message: error, statusCode: 500, error: true };
140
+ }
141
+ }
142
+
143
+ async getUserByEmail(dataToSend = {
144
+ email
145
+ }) {
146
+ try {
147
+ if (!this.endpoint) {
148
+ return { message: "Environment endpoint not found", statusCode: 400, error: false };
149
+ }
150
+ if (!this.secretKey) {
151
+ return { message: "Environment secret key not found", statusCode: 400, error: false };
152
+ }
153
+ if (!dataToSend.email) {
154
+ return { message: "Field email not found", statusCode: 400, error: false };
155
+ }
156
+
157
+ const response = await fetch(`${this.endpoint}/user/get-user-by-email/${this.clientId}/${this.secretKey}`, {
158
+ method: 'POST',
159
+ headers: {
160
+ 'Content-Type': 'application/json',
161
+ },
162
+ body: JSON.stringify(dataToSend)
163
+ });
164
+
165
+ const responseData = await response.json();
166
+
167
+ return responseData;
168
+ } catch (error) {
169
+ return { message: error, statusCode: 500, error: true };
170
+ }
171
+ }
172
+
173
+ async userUpdatePassword(dataToSend = {
174
+ email,
175
+ current_password,
176
+ new_password,
177
+ }) {
178
+ try {
179
+ if (!this.endpoint) {
180
+ return { message: "Environment endpoint not found", statusCode: 400, error: false };
181
+ }
182
+ if (!this.secretKey) {
183
+ return { message: "Environment secret key not found", statusCode: 400, error: false };
184
+ }
185
+ if (!dataToSend.email) {
186
+ return { message: "Field email not found", statusCode: 400, error: false };
187
+ }
188
+ if (!dataToSend.current_password) {
189
+ return { message: "Field current_password not found", statusCode: 400, error: false };
190
+ }
191
+ if (!dataToSend.new_password) {
192
+ return { message: "Field new_password not found", statusCode: 400, error: false };
193
+ }
194
+
195
+ const response = await fetch(`${this.endpoint}/user/update-password/${this.clientId}/${this.secretKey}`, {
123
196
  method: 'POST',
124
197
  headers: {
125
198
  'Content-Type': 'application/json',
@@ -149,7 +222,7 @@ class SingleSignOn {
149
222
  return { message: "Field token not found", statusCode: 400, error: false };
150
223
  }
151
224
 
152
- const response = await fetch(`${this.endpoint}/user/refresh-token/${this.secretKey}`, {
225
+ const response = await fetch(`${this.endpoint}/user/refresh-token/${this.clientId}`, {
153
226
  method: 'POST',
154
227
  headers: {
155
228
  'Content-Type': 'application/json',
@@ -179,7 +252,7 @@ class SingleSignOn {
179
252
  return { message: "Field token not found", statusCode: 400, error: false };
180
253
  }
181
254
 
182
- const response = await fetch(`${this.endpoint}/user/logout/${this.secretKey}`, {
255
+ const response = await fetch(`${this.endpoint}/user/logout/${this.clientId}`, {
183
256
  method: 'POST',
184
257
  headers: {
185
258
  'Content-Type': 'application/json',
@@ -198,6 +271,7 @@ class SingleSignOn {
198
271
 
199
272
  module.exports = {
200
273
  RTS2003_SO_ENDPOINT,
274
+ RTS2003_SO_CLIENT_KEY,
201
275
  RTS2003_SO_SECRET_KEY,
202
276
  SingleSignOn
203
277
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rts2003-so",
3
- "version": "1.1.4",
4
- "description": "RTS2003 SO is service order, manage user, like register, update, delete.",
3
+ "version": "1.4.0",
4
+ "description": "RTS2003 SO is service order, manage user, like re-token, logout, register, update, delete, update password, get user by email.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "jest -o ./test.js"