ggez-banking-sdk 0.4.28 → 0.4.29

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.
@@ -87,8 +87,14 @@ const fillCreateUserData = (data) => {
87
87
  }
88
88
  return userData;
89
89
  };
90
+ const mimeToExtension = {
91
+ "image/jpeg": ".jpg",
92
+ "image/png": ".png",
93
+ "image/webp": ".webp",
94
+ "image/gif": ".gif",
95
+ };
90
96
  const fillCreateUserWithGoogleData = async (data) => {
91
- const base64 = await getBase64(data.picture);
97
+ const pictureResult = await getBase64(data.picture);
92
98
  const userData = fillCreateUserData(data);
93
99
  const externalAuth = {
94
100
  id: 0,
@@ -99,7 +105,8 @@ const fillCreateUserWithGoogleData = async (data) => {
99
105
  verification_status: EntityVerificationStatus.Verified,
100
106
  };
101
107
  userData.external_auth = [externalAuth];
102
- if (base64) {
108
+ if (pictureResult) {
109
+ const ext = mimeToExtension[pictureResult.mimeType] ?? ".jpg";
103
110
  const documentData = {
104
111
  info: {
105
112
  type: DocumentType.Profile_Picture,
@@ -108,8 +115,8 @@ const fillCreateUserWithGoogleData = async (data) => {
108
115
  attachment: [
109
116
  {
110
117
  file_name: data.loginId,
111
- file_extension: ".jpg",
112
- content: base64,
118
+ file_extension: ext,
119
+ content: pictureResult.content,
113
120
  },
114
121
  ],
115
122
  };
@@ -1,4 +1,7 @@
1
1
  declare const pad: (number: number) => string;
2
2
  declare const padMilliseconds: (number: number) => string;
3
- declare const getBase64: (url: string) => Promise<string | null>;
3
+ declare const getBase64: (url: string) => Promise<{
4
+ content: string;
5
+ mimeType: string;
6
+ } | null>;
4
7
  export { pad, padMilliseconds, getBase64 };
@@ -4,13 +4,17 @@ const getBase64 = async (url) => {
4
4
  try {
5
5
  const response = await fetch(url);
6
6
  const blob = await response.blob();
7
- const base64 = new Promise((resolve, reject) => {
7
+ const mimeType = blob.type || "image/jpeg";
8
+ const content = await new Promise((resolve, reject) => {
8
9
  const reader = new FileReader();
9
10
  reader.onload = () => {
10
11
  if (reader.result instanceof ArrayBuffer) {
11
12
  const binaryData = new Uint8Array(reader.result);
12
- const base64Data = btoa(String.fromCharCode(...binaryData));
13
- resolve(base64Data);
13
+ let binary = "";
14
+ for (let i = 0; i < binaryData.byteLength; i++) {
15
+ binary += String.fromCharCode(binaryData[i]);
16
+ }
17
+ resolve(btoa(binary));
14
18
  }
15
19
  else {
16
20
  reject(new Error("Failed to read as ArrayBuffer"));
@@ -18,9 +22,9 @@ const getBase64 = async (url) => {
18
22
  };
19
23
  reader.readAsArrayBuffer(blob);
20
24
  });
21
- return await base64;
25
+ return { content, mimeType };
22
26
  }
23
- catch (error) {
27
+ catch {
24
28
  return null;
25
29
  }
26
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ggez-banking-sdk",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "description": "A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",