@geniehr/utilities 1.0.9 → 1.0.11

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.
@@ -9,4 +9,10 @@ export declare class HttpClient {
9
9
  patch<T = any>(url: string, data: any, correlationId: string, config?: AxiosRequestConfig): Promise<T>;
10
10
  private formatError;
11
11
  }
12
+ export declare class GraphQLClient {
13
+ private url;
14
+ private headers;
15
+ constructor(url: string, headers?: Record<string, string>);
16
+ query<T = any>(query: string, variables?: Record<string, any>, additionalHeaders?: Record<string, string>): Promise<T>;
17
+ }
12
18
  export default HttpClient;
@@ -103,4 +103,40 @@ export class HttpClient {
103
103
  }
104
104
  }
105
105
  }
106
+ export class GraphQLClient {
107
+ url;
108
+ headers;
109
+ constructor(url, headers = {}) {
110
+ this.url = url;
111
+ this.headers = headers;
112
+ }
113
+ async query(query, variables = {}, additionalHeaders = {}) {
114
+ try {
115
+ const response = await fetch(this.url, {
116
+ method: 'POST',
117
+ headers: {
118
+ 'Content-Type': 'application/json',
119
+ ...this.headers,
120
+ ...additionalHeaders,
121
+ },
122
+ body: JSON.stringify({
123
+ query,
124
+ variables,
125
+ }),
126
+ });
127
+ if (!response.ok) {
128
+ throw new Error(`HTTP Error: ${response.statusText}`);
129
+ }
130
+ const result = await response.json();
131
+ if (result.errors) {
132
+ throw new Error(JSON.stringify(result.errors));
133
+ }
134
+ return result.data;
135
+ }
136
+ catch (error) {
137
+ // Improve error formatting to match existing style or be meaningful
138
+ throw new Error(`GraphQL Request Failed: ${error.message}`);
139
+ }
140
+ }
141
+ }
106
142
  export default HttpClient;
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { HttpStatusCode } from './shared/enums/HttpStatusCodes.js';
6
6
  export { InvalidRequestException, InvalidEnvironmentException, AppException } from './shared/exceptions/index.js';
7
7
  export { getAWSParameters, matchFace, registerFace, generatePresignedUrl, getCustomAttribute, updateCustomAttribute, executeS3Action } from './secrets/aws.js';
8
8
  export { CognitoUserService } from './secrets/CognitoUserService.js';
9
- export { HttpClient } from './apiUtils/httpUtils.js';
9
+ export { HttpClient, GraphQLClient } from './apiUtils/httpUtils.js';
10
10
  export { sendResponse } from './apiUtils/api.js';
11
11
  export { services } from './shared/services.js';
12
12
  export { ImageCompressor } from './shared/helper/ImageCompressor.js';
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ export { HttpStatusCode } from './shared/enums/HttpStatusCodes.js';
6
6
  export { InvalidRequestException, InvalidEnvironmentException, AppException } from './shared/exceptions/index.js';
7
7
  export { getAWSParameters, matchFace, registerFace, generatePresignedUrl, getCustomAttribute, updateCustomAttribute, executeS3Action } from './secrets/aws.js';
8
8
  export { CognitoUserService } from './secrets/CognitoUserService.js';
9
- export { HttpClient } from './apiUtils/httpUtils.js';
9
+ export { HttpClient, GraphQLClient } from './apiUtils/httpUtils.js';
10
10
  export { sendResponse } from './apiUtils/api.js';
11
11
  export { services } from './shared/services.js';
12
12
  export { ImageCompressor } from './shared/helper/ImageCompressor.js';
@@ -5,7 +5,8 @@
5
5
  export declare function getAWSParameters(nameOrPrefix: string): Promise<Record<string, string>>;
6
6
  export declare function matchFace(imageInBase64: string): Promise<import("@aws-sdk/client-rekognition").SearchFacesByImageCommandOutput>;
7
7
  export declare function registerFace(employeeId: string, imageInBase64: string): Promise<import("@aws-sdk/client-rekognition").IndexFacesCommandOutput>;
8
- export declare function generatePresignedUrl(entity: string, fileName: string, bucketName: string, idToken: string, action: 'put' | 'get', expiresIn?: number): Promise<string>;
8
+ export declare function generatePresignedUrl(bucketName: string, key: string, idToken: string, action: 'put' | 'get', expiresIn?: number): Promise<string>;
9
+ export declare function generatePresignedUrlLegacy(entity: string, fileName: string, bucketName: string, idToken: string, action: 'put' | 'get', expiresIn?: number): Promise<string>;
9
10
  export declare function executeS3Action(action: "put" | "get", bucketName: string, key: string, body?: Buffer, contentType?: string): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
10
11
  export declare function updateCustomAttribute(username: string, userPoolId: string, attributeName: string, attributeValue: string): Promise<{
11
12
  success: boolean;
@@ -83,7 +83,35 @@ export async function registerFace(employeeId, imageInBase64) {
83
83
  const result = await rekognition.send(command);
84
84
  return result;
85
85
  }
86
- export async function generatePresignedUrl(entity, fileName, bucketName, idToken, action, expiresIn = 3600) {
86
+ export async function generatePresignedUrl(bucketName, key, idToken, action, expiresIn = 3600) {
87
+ let token = idToken?.startsWith("Bearer ") ? idToken.split(" ")[1] : idToken;
88
+ const payload = JSON.parse(Buffer.from(token.split(".")[1], "base64").toString());
89
+ const userId = Number(payload["custom:id"]);
90
+ if (!userId)
91
+ throw new AppException("User ID not found in token", "E-User-ID-Not-Found");
92
+ const REGION = "ap-south-1";
93
+ const s3 = new S3Client({ region: REGION });
94
+ let command;
95
+ switch (action) {
96
+ case 'put':
97
+ command = new PutObjectCommand({
98
+ Bucket: bucketName,
99
+ Key: key,
100
+ });
101
+ break;
102
+ case 'get': command = new GetObjectCommand({
103
+ Bucket: bucketName,
104
+ Key: key,
105
+ });
106
+ }
107
+ try {
108
+ return await getSignedUrl(s3, command, { expiresIn });
109
+ }
110
+ catch (error) {
111
+ throw new AppException(`Failed to generate presigned URL: ${error instanceof Error ? error.message : "Unknown error"}`, "E-Presigned-URL-Generation-Failed");
112
+ }
113
+ }
114
+ export async function generatePresignedUrlLegacy(entity, fileName, bucketName, idToken, action, expiresIn = 3600) {
87
115
  let token = idToken?.startsWith("Bearer ") ? idToken.split(" ")[1] : idToken;
88
116
  const payload = JSON.parse(Buffer.from(token.split(".")[1], "base64").toString());
89
117
  const userId = Number(payload["custom:id"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geniehr/utilities",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/Genie-HR/ghr-utilities#readme",
6
6
  "bugs": {