@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.
Files changed (70) hide show
  1. package/README.md +132 -0
  2. package/dist/auth/index.d.ts +19 -0
  3. package/dist/auth/index.d.ts.map +1 -0
  4. package/dist/auth/index.js +61 -0
  5. package/dist/auth/index.js.map +1 -0
  6. package/dist/db/mysql.d.ts +26 -0
  7. package/dist/db/mysql.d.ts.map +1 -0
  8. package/dist/db/mysql.js +64 -0
  9. package/dist/db/mysql.js.map +1 -0
  10. package/dist/db/prisma.d.ts +21 -0
  11. package/dist/db/prisma.d.ts.map +1 -0
  12. package/dist/db/prisma.js +34 -0
  13. package/dist/db/prisma.js.map +1 -0
  14. package/dist/email/index.d.ts +23 -0
  15. package/dist/email/index.d.ts.map +1 -0
  16. package/dist/email/index.js +79 -0
  17. package/dist/email/index.js.map +1 -0
  18. package/dist/index.d.ts +104 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +193 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/otp/index.d.ts +40 -0
  23. package/dist/otp/index.d.ts.map +1 -0
  24. package/dist/otp/index.js +85 -0
  25. package/dist/otp/index.js.map +1 -0
  26. package/dist/payments/paytech.d.ts +32 -0
  27. package/dist/payments/paytech.d.ts.map +1 -0
  28. package/dist/payments/paytech.js +65 -0
  29. package/dist/payments/paytech.js.map +1 -0
  30. package/dist/payments/stripe.d.ts +18 -0
  31. package/dist/payments/stripe.d.ts.map +1 -0
  32. package/dist/payments/stripe.js +24 -0
  33. package/dist/payments/stripe.js.map +1 -0
  34. package/dist/responses/core.d.ts +23 -0
  35. package/dist/responses/core.d.ts.map +1 -0
  36. package/dist/responses/core.js +45 -0
  37. package/dist/responses/core.js.map +1 -0
  38. package/dist/responses/express.d.ts +17 -0
  39. package/dist/responses/express.d.ts.map +1 -0
  40. package/dist/responses/express.js +67 -0
  41. package/dist/responses/express.js.map +1 -0
  42. package/dist/responses/nextjs.d.ts +15 -0
  43. package/dist/responses/nextjs.d.ts.map +1 -0
  44. package/dist/responses/nextjs.js +45 -0
  45. package/dist/responses/nextjs.js.map +1 -0
  46. package/dist/storage/s3.d.ts +66 -0
  47. package/dist/storage/s3.d.ts.map +1 -0
  48. package/dist/storage/s3.js +172 -0
  49. package/dist/storage/s3.js.map +1 -0
  50. package/dist/storage/supabase.d.ts +41 -0
  51. package/dist/storage/supabase.d.ts.map +1 -0
  52. package/dist/storage/supabase.js +83 -0
  53. package/dist/storage/supabase.js.map +1 -0
  54. package/dist/utils/date.d.ts +29 -0
  55. package/dist/utils/date.d.ts.map +1 -0
  56. package/dist/utils/date.js +79 -0
  57. package/dist/utils/date.js.map +1 -0
  58. package/dist/utils/misc.d.ts +25 -0
  59. package/dist/utils/misc.d.ts.map +1 -0
  60. package/dist/utils/misc.js +50 -0
  61. package/dist/utils/misc.js.map +1 -0
  62. package/dist/utils/string.d.ts +29 -0
  63. package/dist/utils/string.d.ts.map +1 -0
  64. package/dist/utils/string.js +56 -0
  65. package/dist/utils/string.js.map +1 -0
  66. package/dist/validation/index.d.ts +46 -0
  67. package/dist/validation/index.d.ts.map +1 -0
  68. package/dist/validation/index.js +189 -0
  69. package/dist/validation/index.js.map +1 -0
  70. package/package.json +66 -0
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # premium_nodejs_library
2
+
3
+ Shared Node.js library for **Premium SARL** projects (Babel, GrooMe, etc.).
4
+
5
+ > Formerly `base_nodejs_library`. Renamed in v4.0.0.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ # From npm (once published)
11
+ npm install premium_nodejs_library
12
+
13
+ # Or link locally during development
14
+ npm link ../Libraries/base_nodejs_library
15
+ ```
16
+
17
+ ## Modules
18
+
19
+ | Module | Import Path | Used By |
20
+ |---|---|---|
21
+ | **Auth** | `premium_nodejs_library` → `hashPassword`, `generateJWT` | Babel, GrooMe |
22
+ | **Email** | `premium_nodejs_library` → `sendEmail`, `sendEmailWithName` | Babel, GrooMe |
23
+ | **Responses (Express)** | `premium_nodejs_library` → `generateBadRequestResponse`, etc. | Babel |
24
+ | **Responses (Next.js)** | `premium_nodejs_library` → `successResponse`, `errorResponse` | GrooMe |
25
+ | **Responses (Core)** | `premium_nodejs_library` → `makeSuccess`, `makeError` | Any framework |
26
+ | **Storage (S3)** | `premium_nodejs_library` → `uploadFilesToS3`, `deleteFileFromS3` | Babel |
27
+ | **Storage (Supabase)** | `premium_nodejs_library` → `uploadToSupabase`, `deleteFromSupabase` | GrooMe |
28
+ | **Payments (Stripe)** | `premium_nodejs_library` → `createStripeClient` | GrooMe |
29
+ | **Payments (PayTech)** | `premium_nodejs_library` → `createPayTechPayment` | GrooMe |
30
+ | **OTP & Twilio** | `premium_nodejs_library` → `generateOtp`, `twilioSendOTP` | Babel |
31
+ | **Validation** | `premium_nodejs_library` → `isValidEmail`, `checkEmptyString` | Both |
32
+ | **DB (MySQL)** | `premium_nodejs_library` → `runAnyQuery`, `selectQueryModule` | Babel |
33
+ | **DB (Prisma)** | `premium_nodejs_library` → `createPrismaSingleton` | GrooMe |
34
+ | **Utils (String)** | `premium_nodejs_library` → `normalizeString`, `capitalizeFirstLetter` | Both |
35
+ | **Utils (Date)** | `premium_nodejs_library` → `isPastDate`, `dBDateFormatModule` | Both |
36
+ | **Utils (Misc)** | `premium_nodejs_library` → `applyPagination`, `randomNumberModule` | Both |
37
+
38
+ ## Usage
39
+
40
+ ### Babel (Express)
41
+ ```ts
42
+ // Named imports (recommended)
43
+ import {
44
+ hashPassword,
45
+ generateJWT,
46
+ generateBadRequestResponse,
47
+ uploadFiles3Bucket,
48
+ runAnyQuery,
49
+ } from "premium_nodejs_library";
50
+
51
+ // Default import (backward compatible)
52
+ import base from "premium_nodejs_library";
53
+ base.hashPassword("secret");
54
+ ```
55
+
56
+ ### GrooMe (Next.js)
57
+ ```ts
58
+ import {
59
+ hashPassword,
60
+ generateJWT,
61
+ successResponse,
62
+ errorResponse,
63
+ createPrismaSingleton,
64
+ createStripeClient,
65
+ sendEmailWithName,
66
+ } from "premium_nodejs_library";
67
+ ```
68
+
69
+ ## Peer Dependencies
70
+
71
+ These are **optional** — install only what your project needs:
72
+
73
+ | Package | Required By |
74
+ |---|---|
75
+ | `express` | Babel (Express response adapters) |
76
+ | `mysql2` | Babel (MySQL queries) |
77
+ | `stripe` | GrooMe (Stripe payments) |
78
+ | `@supabase/supabase-js` | GrooMe (Supabase storage) |
79
+ | `@prisma/client` | GrooMe (Prisma ORM) |
80
+
81
+ ## Migration from base_nodejs_library
82
+
83
+ 1. Update `package.json`: `"premium_nodejs_library": "4.0.0"`
84
+ 2. **No code changes needed** — all function names are identical
85
+ 3. The default export (`import base from "..."`) still works
86
+
87
+ ### What changed in v4.0.0
88
+ - **Renamed** from `base_nodejs_library`
89
+ - **Modularized** from 1 file (751 lines) → 13 focused modules
90
+ - **Removed `moment.js`** — uses native Date APIs
91
+ - **Switched `bcrypt` → `bcryptjs`** — pure JS, works on serverless (Vercel)
92
+ - **Added Next.js response adapters** for GrooMe
93
+ - **Added Supabase, Stripe, PayTech, Prisma** modules
94
+ - **Optional peer dependencies** — install only what you need
95
+
96
+ ## Development
97
+
98
+ ```bash
99
+ # Build
100
+ npm run build
101
+
102
+ # Clean
103
+ npm run clean
104
+ ```
105
+
106
+ ## Project Structure
107
+
108
+ ```
109
+ src/
110
+ ├── index.ts ← Barrel re-exports + default export
111
+ ├── auth/index.ts ← JWT + bcrypt
112
+ ├── email/index.ts ← SendGrid
113
+ ├── responses/
114
+ │ ├── core.ts ← Framework-agnostic
115
+ │ ├── express.ts ← Express adapters
116
+ │ └── nextjs.ts ← Next.js adapters
117
+ ├── storage/
118
+ │ ├── s3.ts ← AWS S3
119
+ │ └── supabase.ts ← Supabase Storage
120
+ ├── payments/
121
+ │ ├── stripe.ts ← Stripe client
122
+ │ └── paytech.ts ← PayTech gateway
123
+ ├── otp/index.ts ← OTP + Twilio
124
+ ├── validation/index.ts ← Input validators
125
+ ├── db/
126
+ │ ├── mysql.ts ← Raw MySQL queries
127
+ │ └── prisma.ts ← Prisma singleton
128
+ └── utils/
129
+ ├── string.ts ← String manipulation
130
+ ├── date.ts ← Date formatting
131
+ └── misc.ts ← Pagination, random, env
132
+ ```
@@ -0,0 +1,19 @@
1
+ import * as JWT from "jsonwebtoken";
2
+ /**
3
+ * Hash a plaintext password with bcryptjs.
4
+ */
5
+ export declare const hashPassword: (password: string) => Promise<string>;
6
+ /**
7
+ * Compare a plaintext password against a bcrypt hash.
8
+ */
9
+ export declare const compareHashedPassword: (password: string, hashedPassword: string) => Promise<boolean>;
10
+ /**
11
+ * Sign a JWT with the given payload, secret key, and
12
+ * expiration time.
13
+ */
14
+ export declare const generateJWT: (payload: JWT.JwtPayload, tokenKey: string, expiryTime?: string | number) => string;
15
+ /**
16
+ * Verify and decode a JWT token.
17
+ */
18
+ export declare const verifyJWT: (token: string, tokenKey: string) => JWT.JwtPayload | string;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAIpC;;GAEG;AACH,eAAO,MAAM,YAAY,aACX,MAAM,KACjB,QAAQ,MAAM,CAEhB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,aACpB,MAAM,kBACA,MAAM,KACvB,QAAQ,OAAO,CAEjB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,YACX,IAAI,UAAU,YACb,MAAM,eACJ,MAAM,GAAG,MAAM,KAC5B,MASF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,UACX,MAAM,YACH,MAAM,KACjB,IAAI,UAAU,GAAG,MAEnB,CAAC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.verifyJWT = exports.generateJWT = exports.compareHashedPassword = exports.hashPassword = void 0;
27
+ const bcrypt = __importStar(require("bcryptjs"));
28
+ const JWT = __importStar(require("jsonwebtoken"));
29
+ const BCRYPT_SALT_ROUNDS = 10;
30
+ /**
31
+ * Hash a plaintext password with bcryptjs.
32
+ */
33
+ const hashPassword = async (password) => {
34
+ return bcrypt.hash(password, BCRYPT_SALT_ROUNDS);
35
+ };
36
+ exports.hashPassword = hashPassword;
37
+ /**
38
+ * Compare a plaintext password against a bcrypt hash.
39
+ */
40
+ const compareHashedPassword = async (password, hashedPassword) => {
41
+ return bcrypt.compare(password, hashedPassword);
42
+ };
43
+ exports.compareHashedPassword = compareHashedPassword;
44
+ /**
45
+ * Sign a JWT with the given payload, secret key, and
46
+ * expiration time.
47
+ */
48
+ const generateJWT = (payload, tokenKey, expiryTime = "24h") => {
49
+ return JWT.sign(payload, tokenKey, {
50
+ expiresIn: expiryTime,
51
+ });
52
+ };
53
+ exports.generateJWT = generateJWT;
54
+ /**
55
+ * Verify and decode a JWT token.
56
+ */
57
+ const verifyJWT = (token, tokenKey) => {
58
+ return JWT.verify(token, tokenKey);
59
+ };
60
+ exports.verifyJWT = verifyJWT;
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,kDAAoC;AAEpC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;GAEG;AACI,MAAM,YAAY,GAAG,KAAK,EAC7B,QAAgB,EACD,EAAE;IACjB,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AACrD,CAAC,CAAC;AAJW,QAAA,YAAY,gBAIvB;AAEF;;GAEG;AACI,MAAM,qBAAqB,GAAG,KAAK,EACtC,QAAgB,EAChB,cAAsB,EACN,EAAE;IAClB,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AACpD,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC;AAEF;;;GAGG;AACI,MAAM,WAAW,GAAG,CACvB,OAAuB,EACvB,QAAgB,EAChB,aAA8B,KAAK,EAC7B,EAAE;IACR,OAAO,GAAG,CAAC,IAAI,CACX,OAAiB,EACjB,QAAQ,EACR;QACI,SAAS,EACL,UAA0C;KACjD,CACJ,CAAC;AACN,CAAC,CAAC;AAbW,QAAA,WAAW,eAatB;AAEF;;GAEG;AACI,MAAM,SAAS,GAAG,CACrB,KAAa,EACb,QAAgB,EACO,EAAE;IACzB,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AALW,QAAA,SAAS,aAKpB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * MySQL database helpers.
3
+ * Used by babel-lambda-api.
4
+ *
5
+ * Requires mysql2 as a peer dependency.
6
+ */
7
+ export interface DbConnection {
8
+ query: (sql: string, values: any[], callback: (err: {
9
+ message: string;
10
+ } | null, data: any) => void) => void;
11
+ }
12
+ export interface QueryResult {
13
+ status: boolean;
14
+ message?: string;
15
+ data?: any;
16
+ }
17
+ /**
18
+ * Run an arbitrary SQL query.
19
+ */
20
+ export declare const runAnyQuery: (dbCon: DbConnection, sql: string, values: any[]) => Promise<QueryResult>;
21
+ /**
22
+ * Build and run a SELECT query with optional
23
+ * WHERE, GROUP BY, ORDER BY, and LIMIT clauses.
24
+ */
25
+ export declare const selectQueryModule: (dbCon: DbConnection, table: string, columns: string, where: string | null, groupBy: string | null, orderBy: string | null, limit: string | null, values: any[]) => Promise<QueryResult>;
26
+ //# sourceMappingURL=mysql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/db/mysql.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,CACH,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EAAE,EACb,QAAQ,EAAE,CACN,GAAG,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,EAC/B,IAAI,EAAE,GAAG,KACR,IAAI,KACR,IAAI,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;CACd;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,UACb,YAAY,OACd,MAAM,UACH,GAAG,EAAE,KACd,QAAQ,WAAW,CAarB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,UACnB,YAAY,SACZ,MAAM,WACJ,MAAM,SACR,MAAM,GAAG,IAAI,WACX,MAAM,GAAG,IAAI,WACb,MAAM,GAAG,IAAI,SACf,MAAM,GAAG,IAAI,UACZ,GAAG,EAAE,KACd,QAAQ,WAAW,CA+BrB,CAAC"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * MySQL database helpers.
4
+ * Used by babel-lambda-api.
5
+ *
6
+ * Requires mysql2 as a peer dependency.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.selectQueryModule = exports.runAnyQuery = void 0;
10
+ /**
11
+ * Run an arbitrary SQL query.
12
+ */
13
+ const runAnyQuery = (dbCon, sql, values) => {
14
+ return new Promise((resolve) => {
15
+ dbCon.query(sql, values, (err, data) => {
16
+ if (err) {
17
+ resolve({
18
+ status: false,
19
+ message: err.message,
20
+ });
21
+ }
22
+ else {
23
+ resolve({ status: true, data });
24
+ }
25
+ });
26
+ });
27
+ };
28
+ exports.runAnyQuery = runAnyQuery;
29
+ /**
30
+ * Build and run a SELECT query with optional
31
+ * WHERE, GROUP BY, ORDER BY, and LIMIT clauses.
32
+ */
33
+ const selectQueryModule = (dbCon, table, columns, where, groupBy, orderBy, limit, values) => {
34
+ return new Promise((resolve) => {
35
+ const whereClause = where
36
+ ? ` WHERE ${where}`
37
+ : "";
38
+ const groupByClause = groupBy
39
+ ? ` GROUP BY ${groupBy}`
40
+ : "";
41
+ const orderByClause = orderBy
42
+ ? ` ORDER BY ${orderBy}`
43
+ : "";
44
+ const limitClause = limit
45
+ ? ` LIMIT ${limit}`
46
+ : "";
47
+ const sql = `SELECT ${columns} FROM ${table}` +
48
+ `${whereClause}${groupByClause}` +
49
+ `${orderByClause}${limitClause}`;
50
+ dbCon.query(sql, values, (err, data) => {
51
+ if (err) {
52
+ resolve({
53
+ status: false,
54
+ message: err.message,
55
+ });
56
+ }
57
+ else {
58
+ resolve({ status: true, data });
59
+ }
60
+ });
61
+ });
62
+ };
63
+ exports.selectQueryModule = selectQueryModule;
64
+ //# sourceMappingURL=mysql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.js","sourceRoot":"","sources":["../../src/db/mysql.ts"],"names":[],"mappings":";AAAA;;;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,aAAa,EAAE;YAChC,GAAG,aAAa,GAAG,WAAW,EAAE,CAAC;QAErC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACnC,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,CAAC;oBACJ,MAAM,EAAE,KAAK;oBACb,OAAO,EAAE,GAAG,CAAC,OAAO;iBACvB,CAAC,CAAC;YACP,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YACpC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAxCW,QAAA,iBAAiB,qBAwC5B"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Prisma client singleton factory.
3
+ * Used by GrooMe-nodeJS and GrooMe admin panel.
4
+ *
5
+ * Requires @prisma/client as a peer dependency.
6
+ */
7
+ /**
8
+ * Create a hot-reload-safe Prisma client singleton.
9
+ *
10
+ * Usage:
11
+ * ```ts
12
+ * import { PrismaClient } from "@prisma/client";
13
+ * import { createPrismaSingleton } from
14
+ * "premium_nodejs_library/db/prisma";
15
+ *
16
+ * export const prisma =
17
+ * createPrismaSingleton(PrismaClient);
18
+ * ```
19
+ */
20
+ export declare const createPrismaSingleton: <T extends new () => any>(PrismaClientClass: T) => InstanceType<T>;
21
+ //# sourceMappingURL=prisma.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/db/prisma.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,uBACV,GAAG,0CAiB1B,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /**
3
+ * Prisma client singleton factory.
4
+ * Used by GrooMe-nodeJS and GrooMe admin panel.
5
+ *
6
+ * Requires @prisma/client as a peer dependency.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createPrismaSingleton = void 0;
10
+ /* eslint-disable @typescript-eslint/no-explicit-any */
11
+ /**
12
+ * Create a hot-reload-safe Prisma client singleton.
13
+ *
14
+ * Usage:
15
+ * ```ts
16
+ * import { PrismaClient } from "@prisma/client";
17
+ * import { createPrismaSingleton } from
18
+ * "premium_nodejs_library/db/prisma";
19
+ *
20
+ * export const prisma =
21
+ * createPrismaSingleton(PrismaClient);
22
+ * ```
23
+ */
24
+ const createPrismaSingleton = (PrismaClientClass) => {
25
+ const globalForPrisma = globalThis;
26
+ const prisma = globalForPrisma.prisma ??
27
+ new PrismaClientClass();
28
+ if (process.env.NODE_ENV !== "production") {
29
+ globalForPrisma.prisma = prisma;
30
+ }
31
+ return prisma;
32
+ };
33
+ exports.createPrismaSingleton = createPrismaSingleton;
34
+ //# sourceMappingURL=prisma.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma.js","sourceRoot":"","sources":["../../src/db/prisma.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uDAAuD;AAEvD;;;;;;;;;;;;GAYG;AACI,MAAM,qBAAqB,GAAG,CAGjC,iBAAoB,EACL,EAAE;IACjB,MAAM,eAAe,GAAG,UAEvB,CAAC;IAEF,MAAM,MAAM,GACR,eAAe,CAAC,MAAM;QACtB,IAAI,iBAAiB,EAAE,CAAC;IAE5B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QACxC,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAlBW,QAAA,qBAAqB,yBAkBhC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Send an email via SendGrid.
3
+ *
4
+ * @param to - Recipient email address
5
+ * @param from - Sender email address
6
+ * @param subject - Email subject
7
+ * @param message - HTML or plain text message
8
+ * @param apiKey - SendGrid API key
9
+ */
10
+ export declare const sendEmail: (to: string, from: string, subject: string, message: string, apiKey: string) => Promise<void>;
11
+ /**
12
+ * Send an email with separate from name and address.
13
+ */
14
+ export declare const sendEmailWithName: (options: {
15
+ to: string;
16
+ toName?: string;
17
+ fromEmail: string;
18
+ fromName: string;
19
+ subject: string;
20
+ html: string;
21
+ apiKey: string;
22
+ }) => Promise<void>;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/email/index.ts"],"names":[],"mappings":"AAeA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,OACd,MAAM,QACJ,MAAM,WACH,MAAM,WACN,MAAM,UACP,MAAM,KACf,QAAQ,IAAI,CAgCd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAAmB;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB,KAAG,QAAQ,IAAI,CAsBf,CAAC"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sendEmailWithName = exports.sendEmail = void 0;
7
+ const mail_1 = __importDefault(require("@sendgrid/mail"));
8
+ let sgInitialized = false;
9
+ /**
10
+ * Lazily initialize SendGrid with an API key.
11
+ * Safe for build-time (Vercel) and serverless.
12
+ */
13
+ function initSendGrid(apiKey) {
14
+ if (!sgInitialized) {
15
+ mail_1.default.setApiKey(apiKey);
16
+ sgInitialized = true;
17
+ }
18
+ }
19
+ /**
20
+ * Send an email via SendGrid.
21
+ *
22
+ * @param to - Recipient email address
23
+ * @param from - Sender email address
24
+ * @param subject - Email subject
25
+ * @param message - HTML or plain text message
26
+ * @param apiKey - SendGrid API key
27
+ */
28
+ const sendEmail = async (to, from, subject, message, apiKey) => {
29
+ try {
30
+ initSendGrid(apiKey);
31
+ const msg = {
32
+ to,
33
+ from,
34
+ subject,
35
+ text: message,
36
+ html: message,
37
+ };
38
+ await mail_1.default.send(msg);
39
+ console.log("Email sent successfully");
40
+ }
41
+ catch (error) {
42
+ const err = error;
43
+ if (err.response) {
44
+ console.error("Error sending email:", err.response.body);
45
+ }
46
+ else {
47
+ console.error("Error sending email:", err.message);
48
+ }
49
+ throw new Error("Failed to send email");
50
+ }
51
+ };
52
+ exports.sendEmail = sendEmail;
53
+ /**
54
+ * Send an email with separate from name and address.
55
+ */
56
+ const sendEmailWithName = async (options) => {
57
+ initSendGrid(options.apiKey);
58
+ const msg = {
59
+ to: {
60
+ email: options.to,
61
+ name: options.toName,
62
+ },
63
+ from: {
64
+ email: options.fromEmail,
65
+ name: options.fromName,
66
+ },
67
+ subject: options.subject,
68
+ html: options.html,
69
+ };
70
+ try {
71
+ await mail_1.default.send(msg);
72
+ }
73
+ catch (error) {
74
+ console.error("[SendGrid] Failed:", error);
75
+ throw error;
76
+ }
77
+ };
78
+ exports.sendEmailWithName = sendEmailWithName;
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/email/index.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAoC;AAEpC,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B;;;GAGG;AACH,SAAS,YAAY,CAAC,MAAc;IAChC,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,cAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,aAAa,GAAG,IAAI,CAAC;IACzB,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACI,MAAM,SAAS,GAAG,KAAK,EAC1B,EAAU,E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;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC,CAAC;AA9BW,QAAA,iBAAiB,qBA8B5B"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * premium_nodejs_library v4.0.0
3
+ *
4
+ * Shared Node.js library for Premium SARL projects.
5
+ * Provides auth, email, responses, storage, payments,
6
+ * OTP, validation, DB, and utility modules.
7
+ *
8
+ * BACKWARD COMPATIBLE with base_nodejs_library.
9
+ * All original exports are preserved.
10
+ */
11
+ export { hashPassword, compareHashedPassword, generateJWT, verifyJWT, } from "./auth";
12
+ export { sendEmail, sendEmailWithName, } from "./email";
13
+ export { makeSuccess, makeSuccessMessage, makeError, makeUnauthorized, makeForbidden, makeNotFound, makeServerError, makeBadGateway, } from "./responses/core";
14
+ export type { ApiResponse } from "./responses/core";
15
+ export { generateBadRequestResponse, generateUnauthorizedResponse, generateBadGatewayResponse, generateForbiddenErrorResponse, generateErrorResponse, generateSuccessResponse, generateSuccessResponseWithData, generateServerErrorResponse, generateSuccessFullResponse, } from "./responses/express";
16
+ export { successResponse, errorResponse, unauthorizedResponse, forbiddenResponse, notFoundResponse, serverErrorResponse, } from "./responses/nextjs";
17
+ export { extractKeyFromObjectUrl, isValidS3Url, getS3FileUrl, uploadFilesToS3, deleteFileFromS3, uploadFiles3Bucket, deleteFileFroms3Bucket, } from "./storage/s3";
18
+ export { createSupabaseStorageClient, uploadToSupabase, deleteFromSupabase, } from "./storage/supabase";
19
+ export { createStripeClient } from "./payments/stripe";
20
+ export { createPayTechPayment, } from "./payments/paytech";
21
+ export { generateOtp, generateOtpExpiryTime, isOtpExpired, twilioSendOTP, twilioVerifyOTP, otpValidator, } from "./otp";
22
+ export type { TwilioConfig } from "./otp";
23
+ export { checkRequiredValidation, isValidEmail, isValidTime, isValidEndTime, checkEmptyString, validateEmailAndPhone, checkExistingUser, checkVerifiedUserInfo, } from "./validation";
24
+ export { runAnyQuery, selectQueryModule, } from "./db/mysql";
25
+ export { createPrismaSingleton, } from "./db/prisma";
26
+ export { capitalizeFirstLetter, removeSpecialCharactersFromNormalString, removeSpecialCharactersFromURL, removeAccents, normalizeDataNFD, normalizeString, } from "./utils/string";
27
+ export { dBDateFormatModule, isPastDate, validateAndConvertDate, convertDateTimeFormat, getYearAndWeekNumber, } from "./utils/date";
28
+ export { applyPagination, randomNumberModule, removeKeysFromJoinData, getContextFromEnvironment, } from "./utils/misc";
29
+ declare const _default: {
30
+ hashPassword: (password: string) => Promise<string>;
31
+ compareHashedPassword: (password: string, hashedPassword: string) => Promise<boolean>;
32
+ generateJWT: (payload: import("jsonwebtoken").JwtPayload, tokenKey: string, expiryTime?: string | number) => string;
33
+ verifyJWT: (token: string, tokenKey: string) => string | import("jsonwebtoken").JwtPayload;
34
+ sendEmail: (to: string, from: string, subject: string, message: string, apiKey: string) => Promise<void>;
35
+ generateBadRequestResponse: (response: any, data: string) => any;
36
+ generateUnauthorizedResponse: (response: any, data: string) => any;
37
+ generateBadGatewayResponse: (response: any, data: string) => any;
38
+ generateForbiddenErrorResponse: (response: any, data: string) => any;
39
+ generateErrorResponse: (response: any, data: any) => any;
40
+ generateSuccessResponse: (response: any, data: any) => any;
41
+ generateSuccessResponseWithData: (response: any, data: any) => any;
42
+ generateServerErrorResponse: (response: any, data: string, statusCode: number) => any;
43
+ generateSuccessFullResponse: (response: any, responseData: object) => any;
44
+ extractKeyFromObjectUrl: (objectUrl: string) => string | null;
45
+ uploadFiles3Bucket: (Region: string, AccessKey: string, SecretKey: string, BucketName: string, _LocalStorageFilesPath: string, FileObjectPath: {
46
+ path: string;
47
+ } | {
48
+ path: string;
49
+ }[]) => Promise<{
50
+ status: boolean;
51
+ data?: string[] | undefined;
52
+ message?: string | undefined;
53
+ }>;
54
+ deleteFileFroms3Bucket: (Region: string, AccessKey: string, SecretKey: string, BucketName: string, FilePath: string) => Promise<{
55
+ status: boolean;
56
+ message: string;
57
+ }>;
58
+ isValidS3Url: (url: string) => boolean;
59
+ twilioSendOTP: (to: string, mode: string, config: import("./otp").TwilioConfig) => Promise<import("axios").AxiosResponse<any, any>>;
60
+ twilioVerifyOTP: (to: string, code: string, config: import("./otp").TwilioConfig) => Promise<import("axios").AxiosResponse<any, any>>;
61
+ generateOtp: () => string;
62
+ isOtpExpired: (otpExpiresAt: Date) => boolean;
63
+ generateOtpExpiryTime: () => Date;
64
+ otpValidator: (user: {
65
+ phoneOtpCode?: number | undefined;
66
+ emailOtpCode?: number | undefined;
67
+ phoneOtpExpiresAt?: Date | undefined;
68
+ emailOtpExpiresAt?: Date | undefined;
69
+ }, phone: string | null, otpCode: number) => string | undefined;
70
+ checkRequiredValidation: (data: {
71
+ field: string;
72
+ value: unknown;
73
+ type: string;
74
+ }[]) => Promise<{
75
+ status: boolean;
76
+ message?: string | undefined;
77
+ }>;
78
+ isValidEmail: (email: string) => boolean;
79
+ isValidTime: (time: string) => boolean;
80
+ isValidEndTime: (startTime: string, endTime: string) => boolean;
81
+ checkEmptyString: (data: unknown) => boolean;
82
+ validateEmailAndPhone: (email: string | null, phone: string | null) => string | null;
83
+ checkExistingUser: (existingUserByEmail: Record<string, unknown> | null, existingUserByPhone: Record<string, unknown> | null) => Record<string, unknown> | undefined;
84
+ checkVerifiedUserInfo: (existingUser: Record<string, unknown>, email: string | null, phone: string | null) => string | undefined;
85
+ runAnyQuery: (dbCon: import("./db/mysql").DbConnection, sql: string, values: any[]) => Promise<import("./db/mysql").QueryResult>;
86
+ selectQueryModule: (dbCon: import("./db/mysql").DbConnection, table: string, columns: string, where: string | null, groupBy: string | null, orderBy: string | null, limit: string | null, values: any[]) => Promise<import("./db/mysql").QueryResult>;
87
+ capitalizeFirstLetter: (sentence: string) => string;
88
+ removeSpecialCharactersFromNormalString: (str: string) => string;
89
+ removeSpecialCharactersFromURL: (str: string) => string;
90
+ removeAccents: (str: string) => string;
91
+ normalizeDataNFD: (str: string) => string;
92
+ normalizeString: (str: string) => string;
93
+ dBDateFormatModule: (date?: Date | undefined) => string;
94
+ isPastDate: (date: string) => boolean;
95
+ validateAndConvertDate: (date: string) => string | null;
96
+ convertDateTimeFormat: (date: string) => string;
97
+ getYearAndWeekNumber: () => [number, number];
98
+ applyPagination: <T>(data: T[], page: number, limit: number) => T[];
99
+ randomNumberModule: (Min: number, Max: number) => number;
100
+ removeKeysFromJoinData: (data: Record<string, unknown>) => unknown[];
101
+ getContextFromEnvironment: (environment: string) => string;
102
+ };
103
+ export default _default;
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACH,YAAY,EACZ,qBAAqB,EACrB,WAAW,EACX,SAAS,GACZ,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACH,SAAS,EACT,iBAAiB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACH,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,cAAc,GACjB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EACH,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,8BAA8B,EAC9B,qBAAqB,EACrB,uBAAuB,EACvB,+BAA+B,EAC/B,2BAA2B,EAC3B,2BAA2B,GAC9B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACH,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,GACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACH,uBAAuB,EACvB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,gBAAgB,EAEhB,kBAAkB,EAClB,sBAAsB,GACzB,MA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