squarecommonblhelper 5.1.0 → 5.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 CHANGED
@@ -15,10 +15,16 @@ helper for common bl for my projects.
15
15
 
16
16
  ## changelog
17
17
 
18
+ ### v5.2.0
19
+
20
+ - AuthenticationCommonBL:
21
+ - add updateUserProfilePhotoV0.
22
+ - rename getUserProfilePhoto to getUserProfilePhotoV0.
23
+
18
24
  ### v5.1.0
19
25
 
20
26
  - AuthenticationCommonBL:
21
- - add getUserProfilePhoto
27
+ - add getUserProfilePhoto.
22
28
 
23
29
  ### v5.0.0
24
30
 
@@ -54,6 +54,11 @@ declare class AuthenticationCommonBL {
54
54
  data: null;
55
55
  log?: any;
56
56
  }>;
57
- getUserProfilePhoto(accessToken: string): Promise<Blob>;
57
+ getUserProfilePhotoV0(accessToken: string): Promise<Blob>;
58
+ updateUserProfilePhotoV0(accessToken: string, profilePhoto?: File): Promise<{
59
+ message: string | null;
60
+ data?: any;
61
+ log?: any;
62
+ }>;
58
63
  }
59
64
  export { AuthenticationCommonBL };
@@ -131,7 +131,7 @@ class AuthenticationCommonBL {
131
131
  throw error;
132
132
  }
133
133
  }
134
- async getUserProfilePhoto(accessToken) {
134
+ async getUserProfilePhotoV0(accessToken) {
135
135
  try {
136
136
  const data = await fetchFileData(
137
137
  // base url
@@ -152,5 +152,40 @@ class AuthenticationCommonBL {
152
152
  throw error;
153
153
  }
154
154
  }
155
+ async updateUserProfilePhotoV0(accessToken, profilePhoto) {
156
+ try {
157
+ const MAX_SIZE = 5 * 1024 * 1024; // 5 MiB
158
+ const ALLOWED_TYPES = ['image/png', 'image/jpeg'];
159
+ if (profilePhoto) {
160
+ if (!ALLOWED_TYPES.includes(profilePhoto.type)) {
161
+ throw new Error('invalid file type: only png or jpeg allowed');
162
+ }
163
+ if (profilePhoto.size > MAX_SIZE) {
164
+ throw new Error('file too large: must be under 5 MiB');
165
+ }
166
+ }
167
+ const formData = new FormData();
168
+ if (profilePhoto) {
169
+ formData.append("profile_photo", profilePhoto);
170
+ }
171
+ const data = await fetchJSONData(
172
+ // base url
173
+ this.commonBLBaseURL,
174
+ // endpoint
175
+ "update_user_profile_photo/v0",
176
+ // method
177
+ "PATCH",
178
+ // headers
179
+ { access_token: accessToken },
180
+ // body
181
+ formData,
182
+ // query params
183
+ undefined);
184
+ return data;
185
+ }
186
+ catch (error) {
187
+ throw error;
188
+ }
189
+ }
155
190
  }
156
191
  export { AuthenticationCommonBL };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squarecommonblhelper",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "helper for common bl for my projects.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "node": ">=18.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "squarecommons": "^2.2.0",
37
+ "squarecommons": "^2.3.0",
38
38
  "zod": "^3.24.1"
39
39
  }
40
40
  }