rts2003-so 1.0.3 → 1.1.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/README.md +10 -0
- package/index.js +64 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,4 +52,14 @@ const result = sso.userDelete({
|
|
|
52
52
|
"id": 0,
|
|
53
53
|
"deleted_by": 0
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
// user refresh token
|
|
57
|
+
const result = sso.userRefreshToken({
|
|
58
|
+
"token": "string"
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// user logout
|
|
62
|
+
const result = sso.userLogout({
|
|
63
|
+
"token": "string"
|
|
64
|
+
});
|
|
55
65
|
```
|
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const fetch =
|
|
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
4
|
const RTS2003_SO_SECRET_KEY = process.env.RTS2003_SO_SECRET_KEY || '';
|
|
5
5
|
|
|
6
6
|
class SingleSignOn {
|
|
7
|
-
constructor(RTS2003_SO_ENDPOINT, RTS2003_SO_SECRET_KEY) {
|
|
8
|
-
this.endpoint =
|
|
9
|
-
this.secretKey =
|
|
7
|
+
constructor(endpoint = RTS2003_SO_ENDPOINT, secretKey = RTS2003_SO_SECRET_KEY) {
|
|
8
|
+
this.endpoint = endpoint;
|
|
9
|
+
this.secretKey = secretKey;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async userRegister(dataToSend = {
|
|
@@ -134,6 +134,66 @@ class SingleSignOn {
|
|
|
134
134
|
return { message: error, statusCode: 500, error: true };
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
+
|
|
138
|
+
async userRefreshToken(dataToSend = {
|
|
139
|
+
token
|
|
140
|
+
}) {
|
|
141
|
+
try {
|
|
142
|
+
if (!this.endpoint) {
|
|
143
|
+
return { message: "Environment endpoint not found", statusCode: 400, error: false };
|
|
144
|
+
}
|
|
145
|
+
if (!this.secretKey) {
|
|
146
|
+
return { message: "Environment secret key not found", statusCode: 400, error: false };
|
|
147
|
+
}
|
|
148
|
+
if (!dataToSend.token) {
|
|
149
|
+
return { message: "Field token not found", statusCode: 400, error: false };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const response = await fetch(`${this.endpoint}/user/refresh-token/${this.secretKey}`, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'application/json',
|
|
156
|
+
},
|
|
157
|
+
body: JSON.stringify(dataToSend)
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const responseData = await response.json();
|
|
161
|
+
|
|
162
|
+
return responseData;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return { message: error, statusCode: 500, error: true };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async userLogout(dataToSend = {
|
|
169
|
+
token
|
|
170
|
+
}) {
|
|
171
|
+
try {
|
|
172
|
+
if (!this.endpoint) {
|
|
173
|
+
return { message: "Environment endpoint not found", statusCode: 400, error: false };
|
|
174
|
+
}
|
|
175
|
+
if (!this.secretKey) {
|
|
176
|
+
return { message: "Environment secret key not found", statusCode: 400, error: false };
|
|
177
|
+
}
|
|
178
|
+
if (!dataToSend.token) {
|
|
179
|
+
return { message: "Field token not found", statusCode: 400, error: false };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const response = await fetch(`${this.endpoint}/user/logout/${this.secretKey}`, {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
headers: {
|
|
185
|
+
'Content-Type': 'application/json',
|
|
186
|
+
},
|
|
187
|
+
body: JSON.stringify(dataToSend)
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const responseData = await response.json();
|
|
191
|
+
|
|
192
|
+
return responseData;
|
|
193
|
+
} catch (error) {
|
|
194
|
+
return { message: error, statusCode: 500, error: true };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
137
197
|
}
|
|
138
198
|
|
|
139
199
|
module.exports = {
|