squarecommonblhelper 1.0.3 → 1.2.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/README.md +15 -0
- package/dist/authentication.d.ts +35 -0
- package/dist/authentication.js +134 -0
- package/dist/greeting.d.ts +14 -1
- package/dist/greeting.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/GreetingResponses.d.ts +77 -0
- package/dist/types/GreetingResponses.js +15 -0
- package/dist/utils.d.ts +5 -1
- package/example.js +8 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -15,6 +15,21 @@ helper for common bl for my projects.
|
|
|
15
15
|
|
|
16
16
|
## changelog
|
|
17
17
|
|
|
18
|
+
### v1.2.0
|
|
19
|
+
|
|
20
|
+
- add types in greeting:
|
|
21
|
+
- createGreetingV0
|
|
22
|
+
|
|
23
|
+
### v1.1.0
|
|
24
|
+
|
|
25
|
+
- add AuthenticationCommonBL class with the following methods:
|
|
26
|
+
- logoutV0
|
|
27
|
+
- generateAccessTokenV0
|
|
28
|
+
- deleteUserV0
|
|
29
|
+
- updateUsernameV0
|
|
30
|
+
- updatePasswordV0
|
|
31
|
+
- getUserDetailsV0
|
|
32
|
+
|
|
18
33
|
### v1.0.3
|
|
19
34
|
|
|
20
35
|
- experimental release.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare class AuthenticationCommonBL {
|
|
2
|
+
private commonBLBaseURL;
|
|
3
|
+
constructor(commonBLBaseURL?: string);
|
|
4
|
+
logoutV0(refreshToken: string): Promise<{
|
|
5
|
+
message: string | null;
|
|
6
|
+
data?: any;
|
|
7
|
+
log?: any;
|
|
8
|
+
}>;
|
|
9
|
+
generateAccessTokenV0(refreshToken: string): Promise<{
|
|
10
|
+
message: string | null;
|
|
11
|
+
data?: any;
|
|
12
|
+
log?: any;
|
|
13
|
+
}>;
|
|
14
|
+
deleteUserV0(accessToken: string, password: string): Promise<{
|
|
15
|
+
message: string | null;
|
|
16
|
+
data?: any;
|
|
17
|
+
log?: any;
|
|
18
|
+
}>;
|
|
19
|
+
updateUsernameV0(accessToken: string, newUsername: string): Promise<{
|
|
20
|
+
message: string | null;
|
|
21
|
+
data?: any;
|
|
22
|
+
log?: any;
|
|
23
|
+
}>;
|
|
24
|
+
updatePasswordV0(accessToken: string, oldPassword: string, newPassword: string): Promise<{
|
|
25
|
+
message: string | null;
|
|
26
|
+
data?: any;
|
|
27
|
+
log?: any;
|
|
28
|
+
}>;
|
|
29
|
+
getUserDetailsV0(accessToken: string): Promise<{
|
|
30
|
+
message: string | null;
|
|
31
|
+
data?: any;
|
|
32
|
+
log?: any;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export { AuthenticationCommonBL };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { fetchJSONData } from "squarecommons";
|
|
2
|
+
class AuthenticationCommonBL {
|
|
3
|
+
commonBLBaseURL;
|
|
4
|
+
constructor(commonBLBaseURL = "http://localhost:10110") {
|
|
5
|
+
this.commonBLBaseURL = commonBLBaseURL;
|
|
6
|
+
}
|
|
7
|
+
async logoutV0(refreshToken) {
|
|
8
|
+
try {
|
|
9
|
+
const data = await fetchJSONData(
|
|
10
|
+
// base url
|
|
11
|
+
this.commonBLBaseURL,
|
|
12
|
+
// endpoint
|
|
13
|
+
"logout/v0",
|
|
14
|
+
// method
|
|
15
|
+
"DELETE",
|
|
16
|
+
// headers
|
|
17
|
+
{ refresh_token: refreshToken },
|
|
18
|
+
// body
|
|
19
|
+
undefined,
|
|
20
|
+
// query params
|
|
21
|
+
undefined);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async generateAccessTokenV0(refreshToken) {
|
|
29
|
+
try {
|
|
30
|
+
const data = await fetchJSONData(
|
|
31
|
+
// base url
|
|
32
|
+
this.commonBLBaseURL,
|
|
33
|
+
// endpoint
|
|
34
|
+
"generate_access_token/v0",
|
|
35
|
+
// method
|
|
36
|
+
"GET",
|
|
37
|
+
// headers
|
|
38
|
+
{ refresh_token: refreshToken },
|
|
39
|
+
// body
|
|
40
|
+
undefined,
|
|
41
|
+
// query params
|
|
42
|
+
undefined);
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async deleteUserV0(accessToken, password) {
|
|
50
|
+
try {
|
|
51
|
+
const data = await fetchJSONData(
|
|
52
|
+
// base url
|
|
53
|
+
this.commonBLBaseURL,
|
|
54
|
+
// endpoint
|
|
55
|
+
"delete_user/v0",
|
|
56
|
+
// method
|
|
57
|
+
"DELETE",
|
|
58
|
+
// headers
|
|
59
|
+
{ access_token: accessToken },
|
|
60
|
+
// body
|
|
61
|
+
{ password: password },
|
|
62
|
+
// query params
|
|
63
|
+
undefined);
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async updateUsernameV0(accessToken, newUsername) {
|
|
71
|
+
try {
|
|
72
|
+
const data = await fetchJSONData(
|
|
73
|
+
// base url
|
|
74
|
+
this.commonBLBaseURL,
|
|
75
|
+
// endpoint
|
|
76
|
+
"update_username/v0",
|
|
77
|
+
// method
|
|
78
|
+
"PATCH",
|
|
79
|
+
// headers
|
|
80
|
+
{ access_token: accessToken },
|
|
81
|
+
// body
|
|
82
|
+
{ new_username: newUsername },
|
|
83
|
+
// query params
|
|
84
|
+
undefined);
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async updatePasswordV0(accessToken, oldPassword, newPassword) {
|
|
92
|
+
try {
|
|
93
|
+
const data = await fetchJSONData(
|
|
94
|
+
// base url
|
|
95
|
+
this.commonBLBaseURL,
|
|
96
|
+
// endpoint
|
|
97
|
+
"update_password/v0",
|
|
98
|
+
// method
|
|
99
|
+
"PATCH",
|
|
100
|
+
// headers
|
|
101
|
+
{ access_token: accessToken },
|
|
102
|
+
// body
|
|
103
|
+
{ old_password: oldPassword, new_password: newPassword },
|
|
104
|
+
// query params
|
|
105
|
+
undefined);
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async getUserDetailsV0(accessToken) {
|
|
113
|
+
try {
|
|
114
|
+
const data = await fetchJSONData(
|
|
115
|
+
// base url
|
|
116
|
+
this.commonBLBaseURL,
|
|
117
|
+
// endpoint
|
|
118
|
+
"get_user_details/v0",
|
|
119
|
+
// method
|
|
120
|
+
"GET",
|
|
121
|
+
// headers
|
|
122
|
+
{ access_token: accessToken },
|
|
123
|
+
// body
|
|
124
|
+
undefined,
|
|
125
|
+
// query params
|
|
126
|
+
undefined);
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export { AuthenticationCommonBL };
|
package/dist/greeting.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
declare class GreetingCommonBL {
|
|
2
2
|
private commonBLBaseURL;
|
|
3
3
|
constructor(commonBLBaseURL?: string);
|
|
4
|
-
createGreetingV0(greetingIsAnonymous: boolean, greetingAnonymousSenderName?: string, accessToken?: string, greetingText?: string): Promise<
|
|
4
|
+
createGreetingV0(greetingIsAnonymous: boolean, greetingAnonymousSenderName?: string, accessToken?: string, greetingText?: string): Promise<{
|
|
5
|
+
message: string | null;
|
|
6
|
+
data: {
|
|
7
|
+
main: {
|
|
8
|
+
greeting_anonymous_sender_name: string | null;
|
|
9
|
+
user_id: string | null;
|
|
10
|
+
greeting_id: number;
|
|
11
|
+
greeting_datetime: string;
|
|
12
|
+
greeting_is_anonymous: boolean;
|
|
13
|
+
greeting_text: string | null;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
log?: any;
|
|
17
|
+
}>;
|
|
5
18
|
}
|
|
6
19
|
export { GreetingCommonBL };
|
package/dist/greeting.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetchJSONData } from "squarecommons";
|
|
2
|
+
import { CreateGreetingV0ResponseZ } from "./types/GreetingResponses.js";
|
|
2
3
|
class GreetingCommonBL {
|
|
3
4
|
commonBLBaseURL;
|
|
4
5
|
constructor(commonBLBaseURL = "http://localhost:10110") {
|
|
@@ -20,7 +21,7 @@ class GreetingCommonBL {
|
|
|
20
21
|
greeting_anonymous_sender_name: greetingAnonymousSenderName,
|
|
21
22
|
greeting_text: greetingText,
|
|
22
23
|
});
|
|
23
|
-
return data;
|
|
24
|
+
return CreateGreetingV0ResponseZ.parse(data);
|
|
24
25
|
}
|
|
25
26
|
catch (error) {
|
|
26
27
|
throw error;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const CreateGreetingV0ResponseZ: z.ZodObject<z.objectUtil.extendShape<{
|
|
3
|
+
data: z.ZodAny;
|
|
4
|
+
message: z.ZodNullable<z.ZodString>;
|
|
5
|
+
log: z.ZodAny;
|
|
6
|
+
}, {
|
|
7
|
+
data: z.ZodObject<{
|
|
8
|
+
main: z.ZodArray<z.ZodObject<{
|
|
9
|
+
greeting_anonymous_sender_name: z.ZodNullable<z.ZodString>;
|
|
10
|
+
user_id: z.ZodNullable<z.ZodString>;
|
|
11
|
+
greeting_id: z.ZodNumber;
|
|
12
|
+
greeting_datetime: z.ZodString;
|
|
13
|
+
greeting_is_anonymous: z.ZodBoolean;
|
|
14
|
+
greeting_text: z.ZodNullable<z.ZodString>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
greeting_anonymous_sender_name: string | null;
|
|
17
|
+
user_id: string | null;
|
|
18
|
+
greeting_id: number;
|
|
19
|
+
greeting_datetime: string;
|
|
20
|
+
greeting_is_anonymous: boolean;
|
|
21
|
+
greeting_text: string | null;
|
|
22
|
+
}, {
|
|
23
|
+
greeting_anonymous_sender_name: string | null;
|
|
24
|
+
user_id: string | null;
|
|
25
|
+
greeting_id: number;
|
|
26
|
+
greeting_datetime: string;
|
|
27
|
+
greeting_is_anonymous: boolean;
|
|
28
|
+
greeting_text: string | null;
|
|
29
|
+
}>, "many">;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
main: {
|
|
32
|
+
greeting_anonymous_sender_name: string | null;
|
|
33
|
+
user_id: string | null;
|
|
34
|
+
greeting_id: number;
|
|
35
|
+
greeting_datetime: string;
|
|
36
|
+
greeting_is_anonymous: boolean;
|
|
37
|
+
greeting_text: string | null;
|
|
38
|
+
}[];
|
|
39
|
+
}, {
|
|
40
|
+
main: {
|
|
41
|
+
greeting_anonymous_sender_name: string | null;
|
|
42
|
+
user_id: string | null;
|
|
43
|
+
greeting_id: number;
|
|
44
|
+
greeting_datetime: string;
|
|
45
|
+
greeting_is_anonymous: boolean;
|
|
46
|
+
greeting_text: string | null;
|
|
47
|
+
}[];
|
|
48
|
+
}>;
|
|
49
|
+
}>, "strip", z.ZodTypeAny, {
|
|
50
|
+
message: string | null;
|
|
51
|
+
data: {
|
|
52
|
+
main: {
|
|
53
|
+
greeting_anonymous_sender_name: string | null;
|
|
54
|
+
user_id: string | null;
|
|
55
|
+
greeting_id: number;
|
|
56
|
+
greeting_datetime: string;
|
|
57
|
+
greeting_is_anonymous: boolean;
|
|
58
|
+
greeting_text: string | null;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
log?: any;
|
|
62
|
+
}, {
|
|
63
|
+
message: string | null;
|
|
64
|
+
data: {
|
|
65
|
+
main: {
|
|
66
|
+
greeting_anonymous_sender_name: string | null;
|
|
67
|
+
user_id: string | null;
|
|
68
|
+
greeting_id: number;
|
|
69
|
+
greeting_datetime: string;
|
|
70
|
+
greeting_is_anonymous: boolean;
|
|
71
|
+
greeting_text: string | null;
|
|
72
|
+
}[];
|
|
73
|
+
};
|
|
74
|
+
log?: any;
|
|
75
|
+
}>;
|
|
76
|
+
type CreateGreetingV0Response = z.infer<typeof CreateGreetingV0ResponseZ>;
|
|
77
|
+
export { CreateGreetingV0ResponseZ, CreateGreetingV0Response };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { APIOutputZ } from "squarecommons";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const CreateGreetingV0ResponseZ = APIOutputZ.extend({
|
|
4
|
+
data: z.object({
|
|
5
|
+
main: z.array(z.object({
|
|
6
|
+
greeting_anonymous_sender_name: z.string().nullable(),
|
|
7
|
+
user_id: z.string().nullable(),
|
|
8
|
+
greeting_id: z.number(),
|
|
9
|
+
greeting_datetime: z.string(),
|
|
10
|
+
greeting_is_anonymous: z.boolean(),
|
|
11
|
+
greeting_text: z.string().nullable(),
|
|
12
|
+
})),
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
export { CreateGreetingV0ResponseZ };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
declare class UtilsCommonBL {
|
|
2
2
|
private commonBLBaseURL;
|
|
3
3
|
constructor(commonBLBaseURL?: string);
|
|
4
|
-
getAppIdV0(appName: string): Promise<
|
|
4
|
+
getAppIdV0(appName: string): Promise<{
|
|
5
|
+
message: string | null;
|
|
6
|
+
data?: any;
|
|
7
|
+
log?: any;
|
|
8
|
+
}>;
|
|
5
9
|
}
|
|
6
10
|
export { UtilsCommonBL };
|
package/example.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
GreetingCommonBL,
|
|
3
|
+
UtilsCommonBL,
|
|
4
|
+
AuthenticationCommonBL,
|
|
5
|
+
} from "./dist/index.js";
|
|
2
6
|
|
|
3
7
|
let greetingCommonBL = new GreetingCommonBL();
|
|
4
8
|
console.log(await greetingCommonBL.createGreetingV0(true));
|
|
5
9
|
|
|
6
10
|
let utilsCommonBL = new UtilsCommonBL();
|
|
7
11
|
console.log(await utilsCommonBL.getAppIdV0("test"));
|
|
12
|
+
|
|
13
|
+
let authenticationCommonBL = new AuthenticationCommonBL();
|
|
14
|
+
console.log(await authenticationCommonBL.generateAccessTokenV0(""));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squarecommonblhelper",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "helper for common bl for my projects.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"node": ">=18.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"squarecommons": "^
|
|
37
|
+
"squarecommons": "^2.0.0",
|
|
38
|
+
"zod": "^3.24.1"
|
|
38
39
|
}
|
|
39
40
|
}
|