@premiumsarl/premium-nodejs-library 4.0.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 +132 -0
- package/dist/auth/index.d.ts +19 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +61 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/db/mysql.d.ts +26 -0
- package/dist/db/mysql.d.ts.map +1 -0
- package/dist/db/mysql.js +64 -0
- package/dist/db/mysql.js.map +1 -0
- package/dist/db/prisma.d.ts +21 -0
- package/dist/db/prisma.d.ts.map +1 -0
- package/dist/db/prisma.js +34 -0
- package/dist/db/prisma.js.map +1 -0
- package/dist/email/index.d.ts +23 -0
- package/dist/email/index.d.ts.map +1 -0
- package/dist/email/index.js +79 -0
- package/dist/email/index.js.map +1 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +193 -0
- package/dist/index.js.map +1 -0
- package/dist/otp/index.d.ts +40 -0
- package/dist/otp/index.d.ts.map +1 -0
- package/dist/otp/index.js +85 -0
- package/dist/otp/index.js.map +1 -0
- package/dist/payments/paytech.d.ts +32 -0
- package/dist/payments/paytech.d.ts.map +1 -0
- package/dist/payments/paytech.js +65 -0
- package/dist/payments/paytech.js.map +1 -0
- package/dist/payments/stripe.d.ts +18 -0
- package/dist/payments/stripe.d.ts.map +1 -0
- package/dist/payments/stripe.js +24 -0
- package/dist/payments/stripe.js.map +1 -0
- package/dist/responses/core.d.ts +23 -0
- package/dist/responses/core.d.ts.map +1 -0
- package/dist/responses/core.js +45 -0
- package/dist/responses/core.js.map +1 -0
- package/dist/responses/express.d.ts +17 -0
- package/dist/responses/express.d.ts.map +1 -0
- package/dist/responses/express.js +67 -0
- package/dist/responses/express.js.map +1 -0
- package/dist/responses/nextjs.d.ts +15 -0
- package/dist/responses/nextjs.d.ts.map +1 -0
- package/dist/responses/nextjs.js +45 -0
- package/dist/responses/nextjs.js.map +1 -0
- package/dist/storage/s3.d.ts +66 -0
- package/dist/storage/s3.d.ts.map +1 -0
- package/dist/storage/s3.js +172 -0
- package/dist/storage/s3.js.map +1 -0
- package/dist/storage/supabase.d.ts +41 -0
- package/dist/storage/supabase.d.ts.map +1 -0
- package/dist/storage/supabase.js +83 -0
- package/dist/storage/supabase.js.map +1 -0
- package/dist/utils/date.d.ts +29 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +79 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/misc.d.ts +25 -0
- package/dist/utils/misc.d.ts.map +1 -0
- package/dist/utils/misc.js +50 -0
- package/dist/utils/misc.js.map +1 -0
- package/dist/utils/string.d.ts +29 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +56 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/validation/index.d.ts +46 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +189 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSuccessFullResponse = exports.generateServerErrorResponse = exports.generateSuccessResponseWithData = exports.generateSuccessResponse = exports.generateErrorResponse = exports.generateForbiddenErrorResponse = exports.generateBadGatewayResponse = exports.generateUnauthorizedResponse = exports.generateBadRequestResponse = void 0;
|
|
4
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
5
|
+
/**
|
|
6
|
+
* Express response adapter functions.
|
|
7
|
+
* Used by babel-lambda-api and other Express projects.
|
|
8
|
+
*
|
|
9
|
+
* These accept Express `res` object directly — backward
|
|
10
|
+
* compatible with the original base_nodejs_library API.
|
|
11
|
+
*/
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
|
+
const generateBadRequestResponse = (response, data) => {
|
|
14
|
+
return response
|
|
15
|
+
.status(http_status_codes_1.StatusCodes.BAD_REQUEST)
|
|
16
|
+
.json({ status: false, message: data });
|
|
17
|
+
};
|
|
18
|
+
exports.generateBadRequestResponse = generateBadRequestResponse;
|
|
19
|
+
const generateUnauthorizedResponse = (response, data) => {
|
|
20
|
+
return response
|
|
21
|
+
.status(http_status_codes_1.StatusCodes.UNAUTHORIZED)
|
|
22
|
+
.json({ status: false, message: data });
|
|
23
|
+
};
|
|
24
|
+
exports.generateUnauthorizedResponse = generateUnauthorizedResponse;
|
|
25
|
+
const generateBadGatewayResponse = (response, data) => {
|
|
26
|
+
return response
|
|
27
|
+
.status(http_status_codes_1.StatusCodes.BAD_GATEWAY)
|
|
28
|
+
.json({ status: false, message: data });
|
|
29
|
+
};
|
|
30
|
+
exports.generateBadGatewayResponse = generateBadGatewayResponse;
|
|
31
|
+
const generateForbiddenErrorResponse = (response, data) => {
|
|
32
|
+
return response
|
|
33
|
+
.status(http_status_codes_1.StatusCodes.FORBIDDEN)
|
|
34
|
+
.json({ status: false, message: data });
|
|
35
|
+
};
|
|
36
|
+
exports.generateForbiddenErrorResponse = generateForbiddenErrorResponse;
|
|
37
|
+
const generateErrorResponse = (response, data) => {
|
|
38
|
+
return response
|
|
39
|
+
.status(http_status_codes_1.StatusCodes.INTERNAL_SERVER_ERROR)
|
|
40
|
+
.json({ status: false, message: data });
|
|
41
|
+
};
|
|
42
|
+
exports.generateErrorResponse = generateErrorResponse;
|
|
43
|
+
const generateSuccessResponse = (response, data) => {
|
|
44
|
+
return response
|
|
45
|
+
.status(http_status_codes_1.StatusCodes.OK)
|
|
46
|
+
.json({ status: true, message: data });
|
|
47
|
+
};
|
|
48
|
+
exports.generateSuccessResponse = generateSuccessResponse;
|
|
49
|
+
const generateSuccessResponseWithData = (response, data) => {
|
|
50
|
+
return response
|
|
51
|
+
.status(http_status_codes_1.StatusCodes.OK)
|
|
52
|
+
.json({ status: true, data });
|
|
53
|
+
};
|
|
54
|
+
exports.generateSuccessResponseWithData = generateSuccessResponseWithData;
|
|
55
|
+
const generateServerErrorResponse = (response, data, statusCode) => {
|
|
56
|
+
return response
|
|
57
|
+
.status(statusCode)
|
|
58
|
+
.json({ status: false, message: data });
|
|
59
|
+
};
|
|
60
|
+
exports.generateServerErrorResponse = generateServerErrorResponse;
|
|
61
|
+
const generateSuccessFullResponse = (response, responseData) => {
|
|
62
|
+
return response
|
|
63
|
+
.status(http_status_codes_1.StatusCodes.OK)
|
|
64
|
+
.json(responseData);
|
|
65
|
+
};
|
|
66
|
+
exports.generateSuccessFullResponse = generateSuccessFullResponse;
|
|
67
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/responses/express.ts"],"names":[],"mappings":";;;AAAA,yDAAgD;AAEhD;;;;;;GAMG;AAEH,uDAAuD;AAEhD,MAAM,0BAA0B,GAAG,CACtC,QAAa,EACb,IAAY,EACT,EAAE;IACL,OAAO,QAAQ;SACV,MAAM,CAAC,+BAAW,CAAC,WAAW,CAAC;SAC/B,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC,CAAC;AAPW,QAAA,0BAA0B,8BAOrC;AAEK,MAAM,4BAA4B,GAAG,CACxC,QAAa,EACb,IAAY,EACT,EAAE;IACL,OAAO,QAAQ;SACV,MAAM,CAAC,+BAAW,CAAC,YAAY,CAAC;SAChC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC,CAAC;AAPW,QAAA,4BAA4B,gCAOvC;AAEK,MAAM,0BAA0B,GAAG,CACtC,QAAa,EACb,IAAY,EACT,EAAE;IACL,OAAO,QAAQ;SACV,MAAM,CAAC,+BAAW,CAAC,WAAW,CAAC;SAC/B,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC,C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,CAAC;AAChD,CAAC,CAAC;AARW,QAAA,2BAA2B,+BAQtC;AAEK,MAAM,2BAA2B,GAAG,CACvC,QAAa,EACb,YAAoB,EACjB,EAAE;IACL,OAAO,QAAQ;SACV,MAAM,CAAC,+BAAW,CAAC,EAAE,CAAC;SACtB,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5B,CAAC,CAAC;AAPW,QAAA,2BAA2B,+BAOtC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js App Router response adapters.
|
|
3
|
+
* Used by GrooMe-nodeJS and admin panel.
|
|
4
|
+
*
|
|
5
|
+
* Returns NextResponse objects compatible with
|
|
6
|
+
* Next.js API route handlers.
|
|
7
|
+
*/
|
|
8
|
+
/// <reference types="node" />
|
|
9
|
+
export declare const successResponse: (data: unknown, status?: number) => Response;
|
|
10
|
+
export declare const errorResponse: (message: string, status?: number) => Response;
|
|
11
|
+
export declare const unauthorizedResponse: (message?: string) => Response;
|
|
12
|
+
export declare const forbiddenResponse: (message?: string) => Response;
|
|
13
|
+
export declare const notFoundResponse: (message?: string) => Response;
|
|
14
|
+
export declare const serverErrorResponse: (message?: string) => Response;
|
|
15
|
+
//# sourceMappingURL=nextjs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../src/responses/nextjs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;AAgBH,eAAO,MAAM,eAAe,SAClB,OAAO,sBAEd,QAKF,CAAC;AAEF,eAAO,MAAM,aAAa,YACb,MAAM,sBAEhB,QAKF,CAAC;AAEF,eAAO,MAAM,oBAAoB,wBAE9B,QAKF,CAAC;AAEF,eAAO,MAAM,iBAAiB,wBAE3B,QAKF,CAAC;AAEF,eAAO,MAAM,gBAAgB,wBAE1B,QAKF,CAAC;AAEF,eAAO,MAAM,mBAAmB,wBAE7B,QAKF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Next.js App Router response adapters.
|
|
4
|
+
* Used by GrooMe-nodeJS and admin panel.
|
|
5
|
+
*
|
|
6
|
+
* Returns NextResponse objects compatible with
|
|
7
|
+
* Next.js API route handlers.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.serverErrorResponse = exports.notFoundResponse = exports.forbiddenResponse = exports.unauthorizedResponse = exports.errorResponse = exports.successResponse = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Create a JSON response.
|
|
13
|
+
* Uses global Response (available in Next.js edge/node).
|
|
14
|
+
*/
|
|
15
|
+
function jsonResponse(body, status) {
|
|
16
|
+
return new Response(JSON.stringify(body), {
|
|
17
|
+
status,
|
|
18
|
+
headers: { "Content-Type": "application/json" },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const successResponse = (data, status = 200) => {
|
|
22
|
+
return jsonResponse({ status: true, ...data }, status);
|
|
23
|
+
};
|
|
24
|
+
exports.successResponse = successResponse;
|
|
25
|
+
const errorResponse = (message, status = 400) => {
|
|
26
|
+
return jsonResponse({ status: false, message }, status);
|
|
27
|
+
};
|
|
28
|
+
exports.errorResponse = errorResponse;
|
|
29
|
+
const unauthorizedResponse = (message = "Unauthorized") => {
|
|
30
|
+
return jsonResponse({ status: false, message }, 401);
|
|
31
|
+
};
|
|
32
|
+
exports.unauthorizedResponse = unauthorizedResponse;
|
|
33
|
+
const forbiddenResponse = (message = "Forbidden") => {
|
|
34
|
+
return jsonResponse({ status: false, message }, 403);
|
|
35
|
+
};
|
|
36
|
+
exports.forbiddenResponse = forbiddenResponse;
|
|
37
|
+
const notFoundResponse = (message = "Not found") => {
|
|
38
|
+
return jsonResponse({ status: false, message }, 404);
|
|
39
|
+
};
|
|
40
|
+
exports.notFoundResponse = notFoundResponse;
|
|
41
|
+
const serverErrorResponse = (message = "Internal server error") => {
|
|
42
|
+
return jsonResponse({ status: false, message }, 500);
|
|
43
|
+
};
|
|
44
|
+
exports.serverErrorResponse = serverErrorResponse;
|
|
45
|
+
//# sourceMappingURL=nextjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../../src/responses/nextjs.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH;;;GAGG;AACH,SAAS,YAAY,CACjB,IAA6B,EAC7B,MAAc;IAEd,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACtC,MAAM;QACN,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAClD,CAAC,CAAC;AACP,CAAC;AAEM,MAAM,eAAe,GAAG,CAC3B,IAAa,EACb,MAAM,GAAG,GAAG,EACJ,EAAE;IACV,OAAO,YAAY,CACf,EAAE,MAAM,EAAE,IAAI,EAAE,GAAI,IAAe,EAAE,EACrC,MAAM,CACT,CAAC;AACN,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B;AAEK,MAAM,aAAa,GAAG,CACzB,OAAe,EACf,MAAM,GAAG,GAAG,EACJ,EAAE;IACV,OAAO,YAAY,CACf,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAC1B,MAAM,CACT,CAAC;AACN,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEK,MAAM,oBAAoB,GAAG,CAChC,OAAO,GAAG,cAAc,EAChB,EAAE;IACV,OAAO,YAAY,CACf,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAC1B,GAAG,CACN,CAAC;AACN,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B;AAEK,MAAM,iBAAiB,GAAG,CAC7B,OAAO,GAAG,WAAW,EACb,EAAE;IACV,OAAO,YAAY,CACf,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAC1B,GAAG,CACN,CAAC;AACN,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B;AAEK,MAAM,gBAAgB,GAAG,CAC5B,OAAO,GAAG,WAAW,EACb,EAAE;IACV,OAAO,YAAY,CACf,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAC1B,GAAG,CACN,CAAC;AACN,CAAC,CAAC;AAPW,QAAA,gBAAgB,oBAO3B;AAEK,MAAM,mBAAmB,GAAG,CAC/B,OAAO,GAAG,uBAAuB,EACzB,EAAE;IACV,OAAO,YAAY,CACf,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAC1B,GAAG,CACN,CAAC;AACN,CAAC,CAAC;AAPW,QAAA,mBAAmB,uBAO9B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS S3 file storage operations.
|
|
3
|
+
* Used by babel-lambda-api for file uploads.
|
|
4
|
+
*/
|
|
5
|
+
/// <reference types="node" />
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
/**
|
|
8
|
+
* Extract the S3 object key from a full S3 URL.
|
|
9
|
+
*/
|
|
10
|
+
export declare const extractKeyFromObjectUrl: (objectUrl: string) => string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Validate if a URL matches the S3 URL pattern.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isValidS3Url: (url: string) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Build the public URL for an S3 object.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getS3FileUrl: (bucketName: string, fileName: string, region: string) => string;
|
|
19
|
+
interface S3Config {
|
|
20
|
+
region: string;
|
|
21
|
+
accessKey: string;
|
|
22
|
+
secretKey: string;
|
|
23
|
+
bucketName: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Upload files to an S3 bucket.
|
|
27
|
+
*
|
|
28
|
+
* @param config - S3 configuration
|
|
29
|
+
* @param files - Single file or array of file objects
|
|
30
|
+
* with `path` property
|
|
31
|
+
* @returns URLs of uploaded files
|
|
32
|
+
*/
|
|
33
|
+
export declare const uploadFilesToS3: (config: S3Config, files: {
|
|
34
|
+
path: string;
|
|
35
|
+
}[] | {
|
|
36
|
+
path: string;
|
|
37
|
+
}) => Promise<{
|
|
38
|
+
status: boolean;
|
|
39
|
+
data?: string[];
|
|
40
|
+
message?: string;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Delete a file from an S3 bucket.
|
|
44
|
+
*
|
|
45
|
+
* @param config - S3 configuration
|
|
46
|
+
* @param fileUrl - Full URL of the file to delete
|
|
47
|
+
*/
|
|
48
|
+
export declare const deleteFileFromS3: (config: S3Config, fileUrl: string) => Promise<{
|
|
49
|
+
status: boolean;
|
|
50
|
+
message: string;
|
|
51
|
+
}>;
|
|
52
|
+
export declare const uploadFiles3Bucket: (Region: string, AccessKey: string, SecretKey: string, BucketName: string, _LocalStorageFilesPath: string, FileObjectPath: {
|
|
53
|
+
path: string;
|
|
54
|
+
}[] | {
|
|
55
|
+
path: string;
|
|
56
|
+
}) => Promise<{
|
|
57
|
+
status: boolean;
|
|
58
|
+
data?: string[] | undefined;
|
|
59
|
+
message?: string | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
export declare const deleteFileFroms3Bucket: (Region: string, AccessKey: string, SecretKey: string, BucketName: string, FilePath: string) => Promise<{
|
|
62
|
+
status: boolean;
|
|
63
|
+
message: string;
|
|
64
|
+
}>;
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../src/storage/s3.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAGH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAU7B;;GAEG;AACH,eAAO,MAAM,uBAAuB,cACrB,MAAM,KAClB,MAAM,GAAG,IAWX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,QAAS,MAAM,KAAG,OAI1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,eACT,MAAM,YACR,MAAM,UACR,MAAM,KACf,MAEF,CAAC;AAEF,UAAU,QAAQ;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,WAChB,QAAQ,SACT;IAAE,MAAM,MAAM,CAAA;CAAE,EAAE,GAAG;IAAE,MAAM,MAAM,CAAA;CAAE,KAC7C,QAAQ;IACP,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAqDA,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,WACjB,QAAQ,WACP,MAAM,KAChB,QAAQ;IACP,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACnB,CAmCA,CAAC;AAGF,eAAO,MAAM,kBAAkB,WACnB,MAAM,aACH,MAAM,aACN,MAAM,cACL,MAAM,0BACM,MAAM,kBACd;IAAE,MAAM,MAAM,CAAA;CAAE,EAAE,GAAG;IAAE,MAAM,MAAM,CAAA;CAAE;YAlH7C,OAAO;;;EA6HlB,CAAC;AAEF,eAAO,MAAM,sBAAsB,WACvB,MAAM,aACH,MAAM,aACN,MAAM,cACL,MAAM,YACR,MAAM;YAhER,OAAO;aACN,MAAM;EA0ElB,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AWS S3 file storage operations.
|
|
4
|
+
* Used by babel-lambda-api for file uploads.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.deleteFileFroms3Bucket = exports.uploadFiles3Bucket = exports.deleteFileFromS3 = exports.uploadFilesToS3 = exports.getS3FileUrl = exports.isValidS3Url = exports.extractKeyFromObjectUrl = void 0;
|
|
31
|
+
const promises_1 = require("fs/promises");
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const fs = __importStar(require("fs"));
|
|
34
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
35
|
+
const { S3Client, PutObjectCommand, DeleteObjectCommand, } = require("@aws-sdk/client-s3");
|
|
36
|
+
/**
|
|
37
|
+
* Extract the S3 object key from a full S3 URL.
|
|
38
|
+
*/
|
|
39
|
+
const extractKeyFromObjectUrl = (objectUrl) => {
|
|
40
|
+
try {
|
|
41
|
+
const parsedUrl = new URL(objectUrl);
|
|
42
|
+
return parsedUrl.pathname.substring(1);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error("Error extracting key from URL:", error);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.extractKeyFromObjectUrl = extractKeyFromObjectUrl;
|
|
50
|
+
/**
|
|
51
|
+
* Validate if a URL matches the S3 URL pattern.
|
|
52
|
+
*/
|
|
53
|
+
const isValidS3Url = (url) => {
|
|
54
|
+
const s3UrlPattern = /^https:\/\/(?:[a-z0-9.-]+)\.s3\.(?:[a-z0-9.-]+)\.amazonaws\.com\/(.+)$/i;
|
|
55
|
+
return s3UrlPattern.test(url);
|
|
56
|
+
};
|
|
57
|
+
exports.isValidS3Url = isValidS3Url;
|
|
58
|
+
/**
|
|
59
|
+
* Build the public URL for an S3 object.
|
|
60
|
+
*/
|
|
61
|
+
const getS3FileUrl = (bucketName, fileName, region) => {
|
|
62
|
+
return `https://${bucketName}.s3.${region}.amazonaws.com/${fileName}`;
|
|
63
|
+
};
|
|
64
|
+
exports.getS3FileUrl = getS3FileUrl;
|
|
65
|
+
/**
|
|
66
|
+
* Upload files to an S3 bucket.
|
|
67
|
+
*
|
|
68
|
+
* @param config - S3 configuration
|
|
69
|
+
* @param files - Single file or array of file objects
|
|
70
|
+
* with `path` property
|
|
71
|
+
* @returns URLs of uploaded files
|
|
72
|
+
*/
|
|
73
|
+
const uploadFilesToS3 = async (config, files) => {
|
|
74
|
+
const s3Client = new S3Client({
|
|
75
|
+
region: config.region,
|
|
76
|
+
credentials: {
|
|
77
|
+
accessKeyId: config.accessKey,
|
|
78
|
+
secretAccessKey: config.secretKey,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const fileArray = Array.isArray(files)
|
|
82
|
+
? files
|
|
83
|
+
: [files];
|
|
84
|
+
const uploadedUrls = [];
|
|
85
|
+
for (const file of fileArray) {
|
|
86
|
+
try {
|
|
87
|
+
if (!fs.existsSync(file.path)) {
|
|
88
|
+
return {
|
|
89
|
+
status: false,
|
|
90
|
+
message: "Source file not found",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const ext = path.extname(file.path);
|
|
94
|
+
const timestamp = Date.now();
|
|
95
|
+
const filename = `file-${timestamp}${ext}`;
|
|
96
|
+
const buffer = await (0, promises_1.readFile)(file.path);
|
|
97
|
+
await s3Client.send(new PutObjectCommand({
|
|
98
|
+
Bucket: config.bucketName,
|
|
99
|
+
Key: filename,
|
|
100
|
+
Body: buffer,
|
|
101
|
+
}));
|
|
102
|
+
uploadedUrls.push((0, exports.getS3FileUrl)(config.bucketName, filename, config.region));
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const msg = error instanceof Error
|
|
106
|
+
? error.message
|
|
107
|
+
: "Upload failed";
|
|
108
|
+
return { status: false, message: msg };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { status: true, data: uploadedUrls };
|
|
112
|
+
};
|
|
113
|
+
exports.uploadFilesToS3 = uploadFilesToS3;
|
|
114
|
+
/**
|
|
115
|
+
* Delete a file from an S3 bucket.
|
|
116
|
+
*
|
|
117
|
+
* @param config - S3 configuration
|
|
118
|
+
* @param fileUrl - Full URL of the file to delete
|
|
119
|
+
*/
|
|
120
|
+
const deleteFileFromS3 = async (config, fileUrl) => {
|
|
121
|
+
const s3Client = new S3Client({
|
|
122
|
+
region: config.region,
|
|
123
|
+
credentials: {
|
|
124
|
+
accessKeyId: config.accessKey,
|
|
125
|
+
secretAccessKey: config.secretKey,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
const key = (0, exports.extractKeyFromObjectUrl)(fileUrl);
|
|
129
|
+
if (!key) {
|
|
130
|
+
return {
|
|
131
|
+
status: false,
|
|
132
|
+
message: "Invalid object URL",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
await s3Client.send(new DeleteObjectCommand({
|
|
137
|
+
Bucket: config.bucketName,
|
|
138
|
+
Key: key,
|
|
139
|
+
}));
|
|
140
|
+
return {
|
|
141
|
+
status: true,
|
|
142
|
+
message: "File deleted",
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
const msg = error instanceof Error
|
|
147
|
+
? error.message
|
|
148
|
+
: "Delete failed";
|
|
149
|
+
return { status: false, message: msg };
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
exports.deleteFileFromS3 = deleteFileFromS3;
|
|
153
|
+
// --- Backward compatibility aliases ---
|
|
154
|
+
const uploadFiles3Bucket = async (Region, AccessKey, SecretKey, BucketName, _LocalStorageFilesPath, FileObjectPath) => {
|
|
155
|
+
return (0, exports.uploadFilesToS3)({
|
|
156
|
+
region: Region,
|
|
157
|
+
accessKey: AccessKey,
|
|
158
|
+
secretKey: SecretKey,
|
|
159
|
+
bucketName: BucketName,
|
|
160
|
+
}, FileObjectPath);
|
|
161
|
+
};
|
|
162
|
+
exports.uploadFiles3Bucket = uploadFiles3Bucket;
|
|
163
|
+
const deleteFileFroms3Bucket = async (Region, AccessKey, SecretKey, BucketName, FilePath) => {
|
|
164
|
+
return (0, exports.deleteFileFromS3)({
|
|
165
|
+
region: Region,
|
|
166
|
+
accessKey: AccessKey,
|
|
167
|
+
secretKey: SecretKey,
|
|
168
|
+
bucketName: BucketName,
|
|
169
|
+
}, FilePath);
|
|
170
|
+
};
|
|
171
|
+
exports.deleteFileFroms3Bucket = deleteFileFroms3Bucket;
|
|
172
|
+
//# sourceMappingURL=s3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.js","sourceRoot":"","sources":["../../src/storage/s3.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,0CAAuC;AACvC,2CAA6B;AAC7B,uCAAyB;AAEzB,0DAA0D;AAC1D,MAAM,EACF,QAAQ,EACR,gBAAgB,EAChB,mBAAmB,GACtB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElC;;G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AAsB,GAAG,KAAK,EACvC,MAAc,EACd,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,QAAgB,EAClB,EAAE;IACA,OAAO,IAAA,wBAAgB,EACnB;QACI,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,UAAU,EAAE,UAAU;KACzB,EACD,QAAQ,CACX,CAAC;AACN,CAAC,CAAC;AAhBW,QAAA,sBAAsB,0BAgBjC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supabase Storage helpers.
|
|
3
|
+
* Used by GrooMe for file uploads (profile pics,
|
|
4
|
+
* business thumbnails, event images).
|
|
5
|
+
*
|
|
6
|
+
* Requires @supabase/supabase-js as a peer dependency.
|
|
7
|
+
*/
|
|
8
|
+
/// <reference types="node" />
|
|
9
|
+
interface SupabaseStorageConfig {
|
|
10
|
+
supabaseUrl: string;
|
|
11
|
+
supabaseServiceKey: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a Supabase admin client for storage operations.
|
|
15
|
+
* Lazy-loaded to avoid import errors when Supabase
|
|
16
|
+
* is not installed.
|
|
17
|
+
*/
|
|
18
|
+
export declare const createSupabaseStorageClient: (config: SupabaseStorageConfig) => any;
|
|
19
|
+
/**
|
|
20
|
+
* Upload a file to Supabase Storage.
|
|
21
|
+
*
|
|
22
|
+
* @param client - Supabase client
|
|
23
|
+
* @param bucket - Storage bucket name
|
|
24
|
+
* @param filePath - Path within the bucket
|
|
25
|
+
* @param fileBuffer - File content as Buffer
|
|
26
|
+
* @param contentType - MIME type
|
|
27
|
+
*/
|
|
28
|
+
export declare const uploadToSupabase: (client: ReturnType<typeof createSupabaseStorageClient>, bucket: string, filePath: string, fileBuffer: Buffer, contentType: string) => Promise<{
|
|
29
|
+
status: boolean;
|
|
30
|
+
url?: string;
|
|
31
|
+
message?: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Delete a file from Supabase Storage.
|
|
35
|
+
*/
|
|
36
|
+
export declare const deleteFromSupabase: (client: ReturnType<typeof createSupabaseStorageClient>, bucket: string, filePaths: string[]) => Promise<{
|
|
37
|
+
status: boolean;
|
|
38
|
+
message: string;
|
|
39
|
+
}>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=supabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/storage/supabase.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;AAEH,UAAU,qBAAqB;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,WAC5B,qBAAqB,QAWhC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,WACjB,WAAW,kCAAkC,CAAC,UAC9C,MAAM,YACJ,MAAM,cACJ,MAAM,eACL,MAAM,KACpB,QAAQ;IACP,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CA8BA,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,WACnB,WAAW,kCAAkC,CAAC,UAC9C,MAAM,aACH,MAAM,EAAE,KACpB,QAAQ;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAqB9C,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Supabase Storage helpers.
|
|
4
|
+
* Used by GrooMe for file uploads (profile pics,
|
|
5
|
+
* business thumbnails, event images).
|
|
6
|
+
*
|
|
7
|
+
* Requires @supabase/supabase-js as a peer dependency.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.deleteFromSupabase = exports.uploadToSupabase = exports.createSupabaseStorageClient = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Create a Supabase admin client for storage operations.
|
|
13
|
+
* Lazy-loaded to avoid import errors when Supabase
|
|
14
|
+
* is not installed.
|
|
15
|
+
*/
|
|
16
|
+
const createSupabaseStorageClient = (config) => {
|
|
17
|
+
// Dynamic import to avoid hard dependency
|
|
18
|
+
// eslint-disable-next-line
|
|
19
|
+
const { createClient } = require("@supabase/supabase-js");
|
|
20
|
+
return createClient(config.supabaseUrl, config.supabaseServiceKey);
|
|
21
|
+
};
|
|
22
|
+
exports.createSupabaseStorageClient = createSupabaseStorageClient;
|
|
23
|
+
/**
|
|
24
|
+
* Upload a file to Supabase Storage.
|
|
25
|
+
*
|
|
26
|
+
* @param client - Supabase client
|
|
27
|
+
* @param bucket - Storage bucket name
|
|
28
|
+
* @param filePath - Path within the bucket
|
|
29
|
+
* @param fileBuffer - File content as Buffer
|
|
30
|
+
* @param contentType - MIME type
|
|
31
|
+
*/
|
|
32
|
+
const uploadToSupabase = async (client, bucket, filePath, fileBuffer, contentType) => {
|
|
33
|
+
try {
|
|
34
|
+
const { error } = await client.storage
|
|
35
|
+
.from(bucket)
|
|
36
|
+
.upload(filePath, fileBuffer, {
|
|
37
|
+
contentType,
|
|
38
|
+
upsert: true,
|
|
39
|
+
});
|
|
40
|
+
if (error) {
|
|
41
|
+
return {
|
|
42
|
+
status: false,
|
|
43
|
+
message: error.message,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const { data: { publicUrl }, } = client.storage
|
|
47
|
+
.from(bucket)
|
|
48
|
+
.getPublicUrl(filePath);
|
|
49
|
+
return { status: true, url: publicUrl };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const msg = error instanceof Error
|
|
53
|
+
? error.message
|
|
54
|
+
: "Upload failed";
|
|
55
|
+
return { status: false, message: msg };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.uploadToSupabase = uploadToSupabase;
|
|
59
|
+
/**
|
|
60
|
+
* Delete a file from Supabase Storage.
|
|
61
|
+
*/
|
|
62
|
+
const deleteFromSupabase = async (client, bucket, filePaths) => {
|
|
63
|
+
try {
|
|
64
|
+
const { error } = await client.storage
|
|
65
|
+
.from(bucket)
|
|
66
|
+
.remove(filePaths);
|
|
67
|
+
if (error) {
|
|
68
|
+
return {
|
|
69
|
+
status: false,
|
|
70
|
+
message: error.message,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return { status: true, message: "Deleted" };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const msg = error instanceof Error
|
|
77
|
+
? error.message
|
|
78
|
+
: "Delete failed";
|
|
79
|
+
return { status: false, message: msg };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.deleteFromSupabase = deleteFromSupabase;
|
|
83
|
+
//# sourceMappingURL=supabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.js","sourceRoot":"","sources":["../../src/storage/supabase.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAOH;;;;GAIG;AACI,MAAM,2BAA2B,GAAG,CACvC,MAA6B,EAC/B,EAAE;IACA,0CAA0C;IAC1C,2BAA2B;IAC3B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAC5B,uBAAuB,CAC1B,CAAC;IACF,OAAO,YAAY,CACf,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,kBAAkB,CAC5B,CAAC;AACN,CAAC,CAAC;AAZW,QAAA,2BAA2B,+BAYtC;AAEF;;;;;;;;GAQG;AACI,MAAM,gBAAgB,GAAG,KAAK,EACjC,MAAsD,EACtD,MAAc,EACd,QAAgB,EAChB,UAAkB,EAClB,WAAmB,EAKpB,EAAE;IACD,IAAI,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO;aACjC,IAAI,CAAC,MAAM,C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AAY,KAAK;YAClB,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,eAAe,CAAC;QAC1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IAC3C,CAAC;AACL,CAAC,CAAC;AAzBW,QAAA,kBAAkB,sBAyB7B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date utility functions.
|
|
3
|
+
* Replaces moment.js with native Date APIs.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Format a date as YYYY-MM-DD HH:mm:ss (DB format).
|
|
7
|
+
*/
|
|
8
|
+
export declare const dBDateFormatModule: (date?: Date) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Check if a date string (YYYY-MM-DD) is in the past.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isPastDate: (date: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Validate and parse a date string.
|
|
15
|
+
* Returns formatted YYYY-MM-DD or null.
|
|
16
|
+
*/
|
|
17
|
+
export declare const validateAndConvertDate: (date: string) => string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Convert datetime to DD-MM-YYYY hh:mm:ssa format.
|
|
20
|
+
*/
|
|
21
|
+
export declare const convertDateTimeFormat: (date: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Get the current year and ISO week number.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getYearAndWeekNumber: () => [
|
|
26
|
+
number,
|
|
27
|
+
number
|
|
28
|
+
];
|
|
29
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,UACpB,IAAI,KACZ,MAaF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,OAMzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,SACzB,MAAM,KACb,MAAM,GAAG,IAWX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,SACxB,MAAM,KACb,MAkBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,QAAO;IACpC,MAAM;IACN,MAAM;CAiBT,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Date utility functions.
|
|
4
|
+
* Replaces moment.js with native Date APIs.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getYearAndWeekNumber = exports.convertDateTimeFormat = exports.validateAndConvertDate = exports.isPastDate = exports.dBDateFormatModule = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Format a date as YYYY-MM-DD HH:mm:ss (DB format).
|
|
10
|
+
*/
|
|
11
|
+
const dBDateFormatModule = (date) => {
|
|
12
|
+
const d = date ? new Date(date) : new Date();
|
|
13
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
14
|
+
return (`${d.getFullYear()}-` +
|
|
15
|
+
`${pad(d.getMonth() + 1)}-` +
|
|
16
|
+
`${pad(d.getDate())} ` +
|
|
17
|
+
`${pad(d.getHours())}:` +
|
|
18
|
+
`${pad(d.getMinutes())}:` +
|
|
19
|
+
`${pad(d.getSeconds())}`);
|
|
20
|
+
};
|
|
21
|
+
exports.dBDateFormatModule = dBDateFormatModule;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a date string (YYYY-MM-DD) is in the past.
|
|
24
|
+
*/
|
|
25
|
+
const isPastDate = (date) => {
|
|
26
|
+
const inputDate = new Date(date);
|
|
27
|
+
inputDate.setHours(0, 0, 0, 0);
|
|
28
|
+
const today = new Date();
|
|
29
|
+
today.setHours(0, 0, 0, 0);
|
|
30
|
+
return inputDate < today;
|
|
31
|
+
};
|
|
32
|
+
exports.isPastDate = isPastDate;
|
|
33
|
+
/**
|
|
34
|
+
* Validate and parse a date string.
|
|
35
|
+
* Returns formatted YYYY-MM-DD or null.
|
|
36
|
+
*/
|
|
37
|
+
const validateAndConvertDate = (date) => {
|
|
38
|
+
const parsed = new Date(date);
|
|
39
|
+
if (isNaN(parsed.getTime()))
|
|
40
|
+
return null;
|
|
41
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
42
|
+
return (`${parsed.getFullYear()}-` +
|
|
43
|
+
`${pad(parsed.getMonth() + 1)}-` +
|
|
44
|
+
`${pad(parsed.getDate())}`);
|
|
45
|
+
};
|
|
46
|
+
exports.validateAndConvertDate = validateAndConvertDate;
|
|
47
|
+
/**
|
|
48
|
+
* Convert datetime to DD-MM-YYYY hh:mm:ssa format.
|
|
49
|
+
*/
|
|
50
|
+
const convertDateTimeFormat = (date) => {
|
|
51
|
+
const d = new Date(date);
|
|
52
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
53
|
+
const day = pad(d.getDate());
|
|
54
|
+
const month = pad(d.getMonth() + 1);
|
|
55
|
+
const year = d.getFullYear();
|
|
56
|
+
const hours = d.getHours();
|
|
57
|
+
const minutes = pad(d.getMinutes());
|
|
58
|
+
const seconds = pad(d.getSeconds());
|
|
59
|
+
const ampm = hours >= 12 ? "pm" : "am";
|
|
60
|
+
const h12 = pad(hours % 12 || 12);
|
|
61
|
+
return (`${day}-${month}-${year} ` +
|
|
62
|
+
`${h12}:${minutes}:${seconds}${ampm}`);
|
|
63
|
+
};
|
|
64
|
+
exports.convertDateTimeFormat = convertDateTimeFormat;
|
|
65
|
+
/**
|
|
66
|
+
* Get the current year and ISO week number.
|
|
67
|
+
*/
|
|
68
|
+
const getYearAndWeekNumber = () => {
|
|
69
|
+
const now = new Date();
|
|
70
|
+
const year = now.getFullYear();
|
|
71
|
+
// ISO week calculation
|
|
72
|
+
const janFirst = new Date(year, 0, 1);
|
|
73
|
+
const dayOfYear = Math.floor((now.getTime() - janFirst.getTime()) /
|
|
74
|
+
86400000) + 1;
|
|
75
|
+
const weekNumber = Math.ceil((dayOfYear + janFirst.getDay()) / 7);
|
|
76
|
+
return [year, weekNumber];
|
|
77
|
+
};
|
|
78
|
+
exports.getYearAndWeekNumber = getYearAndWeekNumber;
|
|
79
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAC9B,IAAW,EACL,EAAE;IACR,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;IAC7C,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CACtB,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAElC,OAAO,CACH,GAAG,CAAC,CAAC,WAAW,EAAE,GAAG;QACrB,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,GAAG;QAC3B,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG;QACtB,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG;QACvB,GAAG,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,GAAG;QACzB,GAAG,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,CAC3B,CAAC;AACN,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B;AAEF;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,IAAY,EAAW,EAAE;IAChD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,E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