ztechno_core 0.0.110 → 0.0.112

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 (39) hide show
  1. package/package.json +1 -1
  2. package/lib/crypto_service.d.ts +0 -23
  3. package/lib/crypto_service.js +0 -100
  4. package/lib/engine_base.d.ts +0 -11
  5. package/lib/engine_base.js +0 -9
  6. package/lib/express.d.ts +0 -1
  7. package/lib/express.js +0 -18
  8. package/lib/mail_service.d.ts +0 -85
  9. package/lib/mail_service.js +0 -156
  10. package/lib/orm/mail_blacklist_orm.d.ts +0 -22
  11. package/lib/orm/mail_blacklist_orm.js +0 -79
  12. package/lib/orm/orm.d.ts +0 -8
  13. package/lib/orm/orm.js +0 -26
  14. package/lib/scripts/docker-build.d.ts +0 -14
  15. package/lib/scripts/docker-build.js +0 -91
  16. package/lib/scripts/docker-publish.d.ts +0 -19
  17. package/lib/scripts/docker-publish.js +0 -114
  18. package/lib/scripts/docker-push.d.ts +0 -8
  19. package/lib/scripts/docker-push.js +0 -87
  20. package/lib/scripts/docker-update.d.ts +0 -27
  21. package/lib/scripts/docker-update.js +0 -207
  22. package/lib/scripts/encrypt.d.ts +0 -1
  23. package/lib/scripts/encrypt.js +0 -4
  24. package/lib/sql_service.d.ts +0 -123
  25. package/lib/sql_service.js +0 -234
  26. package/lib/translate_service.d.ts +0 -48
  27. package/lib/translate_service.js +0 -908
  28. package/lib/typings/crypto_types.d.ts +0 -4
  29. package/lib/typings/crypto_types.js +0 -2
  30. package/lib/typings/index.d.ts +0 -4
  31. package/lib/typings/index.js +0 -36
  32. package/lib/typings/mail_types.d.ts +0 -95
  33. package/lib/typings/mail_types.js +0 -2
  34. package/lib/typings/translate_types.d.ts +0 -69
  35. package/lib/typings/translate_types.js +0 -46
  36. package/lib/typings/user_types.d.ts +0 -41
  37. package/lib/typings/user_types.js +0 -2
  38. package/lib/user_service.d.ts +0 -80
  39. package/lib/user_service.js +0 -216
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztechno_core",
3
- "version": "0.0.110",
3
+ "version": "0.0.112",
4
4
  "description": "Core files for ztechno framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,23 +0,0 @@
1
- import { HashStruct } from './typings';
2
- export declare class ZCryptoService {
3
- static encrypt(text: string): HashStruct;
4
- static decrypt(data: HashStruct): string;
5
- static decrypt(encrypted: string): string;
6
- static decryptJSON<T = any>(data: HashStruct): T;
7
- static decryptJSON<T = any>(data: string): T;
8
- static hash(
9
- hashAlgorithm: 'sha256' | 'sha512' | 'md5',
10
- data: string,
11
- opt?: {
12
- itt?: number;
13
- } & (
14
- | {
15
- saltMode: 'none';
16
- }
17
- | {
18
- saltMode: 'simple';
19
- salt: string;
20
- }
21
- ),
22
- ): string;
23
- }
@@ -1,100 +0,0 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __setModuleDefault =
23
- (this && this.__setModuleDefault) ||
24
- (Object.create
25
- ? function (o, v) {
26
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
27
- }
28
- : function (o, v) {
29
- o['default'] = v;
30
- });
31
- var __importStar =
32
- (this && this.__importStar) ||
33
- function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null)
37
- for (var k in mod)
38
- if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
39
- __setModuleDefault(result, mod);
40
- return result;
41
- };
42
- Object.defineProperty(exports, '__esModule', { value: true });
43
- exports.ZCryptoService = void 0;
44
- const crypto = __importStar(require('crypto'));
45
- const algorithm = 'aes-256-cbc';
46
- const key = Buffer.from([
47
- 253, 144, 73, 128, 71, 94, 34, 3, 28, 128, 194, 166, 132, 154, 14, 87, 221, 202, 92, 56, 139, 10, 38, 122, 120, 7,
48
- 149, 40, 211, 218, 217, 3,
49
- ]);
50
- const iv = Buffer.from([0, 209, 223, 20, 147, 45, 14, 107, 93, 6, 76, 206, 176, 55, 245, 134]);
51
- class ZCryptoService {
52
- static encrypt(text) {
53
- const cipher = crypto.createCipheriv(algorithm, key, iv);
54
- let encrypted = cipher.update(text);
55
- encrypted = Buffer.concat([encrypted, cipher.final()]);
56
- return { iv: iv.toString('hex'), encryptedData: encrypted.toString('hex') };
57
- }
58
- static decrypt(data) {
59
- if (typeof data === 'string') {
60
- const encryptedText = Buffer.from(data, 'hex');
61
- const decipher = crypto.createDecipheriv(algorithm, key, iv);
62
- let decrypted = decipher.update(encryptedText);
63
- decrypted = Buffer.concat([decrypted, decipher.final()]);
64
- return decrypted.toString();
65
- }
66
- const niv = Buffer.from(data.iv, 'hex');
67
- const encryptedText = Buffer.from(data.encryptedData, 'hex');
68
- const decipher = crypto.createDecipheriv(algorithm, key, niv);
69
- let decrypted = decipher.update(encryptedText);
70
- decrypted = Buffer.concat([decrypted, decipher.final()]);
71
- return decrypted.toString();
72
- }
73
- static decryptJSON(data) {
74
- try {
75
- const decrypted = ZCryptoService.decrypt(data);
76
- return JSON.parse(decrypted);
77
- } catch (err) {
78
- throw new Error(`Couldn't decrypt JSON ${JSON.stringify(data)}`);
79
- }
80
- }
81
- static hash(hashAlgorithm, data, opt) {
82
- const itt = opt?.itt || 1;
83
- let salt;
84
- if (opt && opt.saltMode === 'simple') {
85
- salt = opt.salt;
86
- data = data
87
- .split('')
88
- .map((c, i) => c + salt.charAt(i % salt.length))
89
- .join('');
90
- }
91
- let hash = data;
92
- for (let i = 0; i < itt; i++) {
93
- hash = crypto.createHash(hashAlgorithm).update(hash).digest('hex');
94
- }
95
- const cut = itt.toString().length + 1;
96
- hash = `${itt}$${hash.substring(cut)}`;
97
- return hash;
98
- }
99
- }
100
- exports.ZCryptoService = ZCryptoService;
@@ -1,11 +0,0 @@
1
- import { ZMailService } from './mail_service';
2
- import { ZSQLService } from './sql_service';
3
- import { ZTranslateService } from './translate_service';
4
- import { ZUserService } from './user_service';
5
- export declare class ZEngineBase {
6
- static mailService?: ZMailService;
7
- static sqlService?: ZSQLService;
8
- static translateService?: ZTranslateService;
9
- static userService?: ZUserService;
10
- protected static start(): any;
11
- }
@@ -1,9 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.ZEngineBase = void 0;
4
- class ZEngineBase {
5
- static start() {
6
- throw new Error(`Please Override ZEngineBase`);
7
- }
8
- }
9
- exports.ZEngineBase = ZEngineBase;
package/lib/express.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function middleware(): (req: Express.Request, res: Express.Response, next: any) => Promise<any>;
package/lib/express.js DELETED
@@ -1,18 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.middleware = void 0;
4
- function middleware() {
5
- return async (req, res, next) => {
6
- if (req.cookies === undefined) {
7
- throw new Error(`Module 'cookie-parser' isn't initialized. Please use app.use(cookieParser())`);
8
- }
9
- if (req.cookies.session === undefined) {
10
- return next();
11
- }
12
- const auth = await userService.auth({ session: req.cookies?.session });
13
- req.user = auth.user;
14
- // TODO: Implement assertAdmin or something like that
15
- next();
16
- };
17
- }
18
- exports.middleware = middleware;
@@ -1,85 +0,0 @@
1
- import {
2
- MailOptions,
3
- MailOptionsHtml,
4
- MailOptionsText,
5
- MailResponse,
6
- MailServiceOptions,
7
- ZMailBlacklist,
8
- ZMailSendOptTemplate,
9
- } from './typings';
10
- import { ZMailBlacklistOrm } from './orm/mail_blacklist_orm';
11
- export declare class ZMailService {
12
- private opt;
13
- protected get sql(): import('./sql_service').ZSQLService;
14
- protected blacklistOrm: ZMailBlacklistOrm;
15
- protected blacklist: ZMailBlacklist[];
16
- /**
17
- * Creates a new ZMailService instance
18
- * @param opt - Configuration options for the mail service including authentication, sender email, and SQL service
19
- */
20
- constructor(opt: MailServiceOptions);
21
- updateBlacklist(opt: Pick<ZMailBlacklist, 'email' | 'is_blacklisted' | 'hash'>): Promise<void>;
22
- /**
23
- * Refreshes the email blacklist from the database
24
- * @returns Promise that resolves when the blacklist has been refreshed
25
- */
26
- protected refreshBlacklist(): Promise<void>;
27
- /**
28
- * Fetches the content of a template file from the filesystem
29
- * @param template - Path to the template file to read
30
- * @returns Promise that resolves to the template content as a string
31
- * @throws Will throw an error if the file cannot be read
32
- * @private
33
- */
34
- private fetchTemplate;
35
- /**
36
- * Checks if an email is allowed to be sent by verifying it's not blacklisted
37
- * @param mailOpts - Mail options containing the recipient email to check
38
- * @returns Promise that resolves to true if email is allowed, false if blacklisted
39
- * @protected
40
- */
41
- protected allowSend(mailOpts: MailOptions): Promise<boolean>;
42
- /**
43
- * Sends an email with text content
44
- * @param mailOpts - Mail options with text body
45
- * @returns Promise that resolves to mail response or undefined if sending is not allowed
46
- */
47
- send(mailOpts: MailOptionsText): Promise<MailResponse | undefined>;
48
- /**
49
- * Sends an email with HTML content
50
- * @param mailOpts - Mail options with HTML body
51
- * @returns Promise that resolves to mail response or undefined if sending is not allowed
52
- */
53
- send(mailOpts: MailOptionsHtml): Promise<MailResponse | undefined>;
54
- /**
55
- * Sends an advanced email with text content, supporting templates and variable injection
56
- * @param mailOpts - Mail options with text body
57
- * @returns Promise that resolves to mail response
58
- */
59
- sendAdvanced(mailOpts: MailOptionsText): Promise<any>;
60
- /**
61
- * Sends an advanced email with HTML content, supporting templates and variable injection
62
- * @param mailOpts - Mail options with HTML body
63
- * @returns Promise that resolves to mail response
64
- */
65
- sendAdvanced(mailOpts: MailOptionsHtml): Promise<any>;
66
- /**
67
- * Sends an advanced email using a template file, supporting variable injection
68
- * @param mailOpts - Mail options with template path and injection variables
69
- * @returns Promise that resolves to mail response
70
- */
71
- sendAdvanced(mailOpts: ZMailSendOptTemplate): Promise<any>;
72
- /**
73
- * Injects variables into a body string by replacing placeholder tokens
74
- * @param body - The string content where variables should be injected
75
- * @param inject - Object containing key-value pairs where keys are variable names and values are replacement content
76
- * @returns Promise that resolves to the body string with all variables injected
77
- * @example
78
- * ```typescript
79
- * const result = await inject('Hello :name from :company', { name: 'John', company: 'ACME' });
80
- * // Returns: 'Hello John from ACME'
81
- * ```
82
- * @private
83
- */
84
- private inject;
85
- }
@@ -1,156 +0,0 @@
1
- 'use strict';
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod };
6
- };
7
- Object.defineProperty(exports, '__esModule', { value: true });
8
- exports.ZMailService = void 0;
9
- const nodemailer_1 = __importDefault(require('nodemailer'));
10
- const fs_1 = __importDefault(require('fs'));
11
- const promises_1 = __importDefault(require('fs/promises'));
12
- const path_1 = __importDefault(require('path'));
13
- const mail_blacklist_orm_1 = require('./orm/mail_blacklist_orm');
14
- class ZMailService {
15
- get sql() {
16
- return this.opt.sqlService;
17
- }
18
- /**
19
- * Creates a new ZMailService instance
20
- * @param opt - Configuration options for the mail service including authentication, sender email, and SQL service
21
- */
22
- constructor(opt) {
23
- this.opt = opt;
24
- this.blacklist = [];
25
- this.blacklistOrm = new mail_blacklist_orm_1.ZMailBlacklistOrm(opt);
26
- this.opt.dirTemplate = path_1.default.isAbsolute(this.opt.dirTemplate || '')
27
- ? this.opt.dirTemplate
28
- : path_1.default.join(process.cwd(), this.opt.dirTemplate || '');
29
- }
30
- async updateBlacklist(opt) {
31
- const newItem = await this.blacklistOrm.upsert(opt);
32
- const found = this.blacklist.find((item) => item.email === opt.email);
33
- if (found) {
34
- found.is_blacklisted = opt.is_blacklisted;
35
- return;
36
- }
37
- this.blacklist.push(newItem);
38
- return;
39
- }
40
- /**
41
- * Refreshes the email blacklist from the database
42
- * @returns Promise that resolves when the blacklist has been refreshed
43
- */
44
- async refreshBlacklist() {
45
- this.blacklist = await this.blacklistOrm.findAll();
46
- }
47
- /**
48
- * Fetches the content of a template file from the filesystem
49
- * @param template - Path to the template file to read
50
- * @returns Promise that resolves to the template content as a string
51
- * @throws Will throw an error if the file cannot be read
52
- * @private
53
- */
54
- async fetchTemplate(template) {
55
- const filepath = path_1.default.join(this.opt.dirTemplate, template);
56
- if (fs_1.default.existsSync(filepath)) {
57
- return await promises_1.default.readFile(filepath, { encoding: 'utf-8' });
58
- }
59
- throw new Error(`Template file not found: ${filepath}`);
60
- }
61
- /**
62
- * Checks if an email is allowed to be sent by verifying it's not blacklisted
63
- * @param mailOpts - Mail options containing the recipient email to check
64
- * @returns Promise that resolves to true if email is allowed, false if blacklisted
65
- * @protected
66
- */
67
- async allowSend(mailOpts) {
68
- const blacklistEntry = await this.blacklistOrm.findOne({ email: mailOpts.recipient, is_blacklisted: 1 });
69
- if (blacklistEntry) {
70
- return false;
71
- }
72
- return true;
73
- }
74
- /**
75
- * Sends an email with either text or HTML content
76
- * @param mailOpts - Mail options containing recipient, subject, and body/html content
77
- * @returns Promise that resolves to mail response or undefined if sending is not allowed
78
- */
79
- async send(mailOpts) {
80
- const allow = await this.allowSend(mailOpts);
81
- if (!allow) {
82
- return;
83
- }
84
- const mailTransporter = nodemailer_1.default.createTransport({
85
- service: 'gmail',
86
- auth: this.opt.auth,
87
- });
88
- const mailDetails = {
89
- from: mailOpts.from || this.opt.mailSender,
90
- to: mailOpts.recipient,
91
- subject: mailOpts.subject,
92
- text: mailOpts.body || undefined,
93
- html: mailOpts.html || undefined,
94
- dkim: mailOpts.dkim ?? this.opt.dkim,
95
- priority: mailOpts.priority,
96
- attachments: mailOpts.attachments,
97
- };
98
- return await new Promise((resolve, reject) => {
99
- mailTransporter.sendMail(mailDetails, function (err, data) {
100
- return err ? reject(err) : resolve(data);
101
- });
102
- });
103
- }
104
- /**
105
- * Sends an advanced email with enhanced features including template loading and variable injection.
106
- * Automatically generates unsubscribe hash and injects common variables like email and hashToUnsubscribe.
107
- * @param mailOpts - Mail options that can include template path, injection variables, and standard mail fields
108
- * @returns Promise that resolves to mail response from the underlying send method
109
- * @example
110
- * ```typescript
111
- * await mailService.sendAdvanced({
112
- * recipient: 'user@example.com',
113
- * subject: 'Welcome!',
114
- * template: './templates/welcome.html',
115
- * inject: { name: 'John', company: 'ACME Corp' }
116
- * });
117
- * ```
118
- */
119
- async sendAdvanced(mailOpts) {
120
- const opts = mailOpts;
121
- const hashToUnsubscribe = await this.blacklistOrm.genEmailUnsubscribeHash({ email: mailOpts.recipient });
122
- if (opts.template !== undefined) {
123
- opts.html = await this.fetchTemplate(opts.template);
124
- }
125
- if (opts.inject !== undefined) {
126
- const key = opts.html !== undefined ? 'html' : 'body';
127
- const baseInject = Object.assign({ email: mailOpts.recipient, hashToUnsubscribe }, this.opt.baseInject ?? {});
128
- opts[key] = await this.inject(opts[key], Object.assign(baseInject, opts.inject));
129
- }
130
- return await this.send(opts);
131
- }
132
- /**
133
- * Injects variables into a body string by replacing placeholder tokens
134
- * @param body - The string content where variables should be injected
135
- * @param inject - Object containing key-value pairs where keys are variable names and values are replacement content
136
- * @returns Promise that resolves to the body string with all variables injected
137
- * @example
138
- * ```typescript
139
- * const result = await inject('Hello :name from :company', { name: 'John', company: 'ACME' });
140
- * // Returns: 'Hello John from ACME'
141
- * ```
142
- * @private
143
- */
144
- async inject(body, inject) {
145
- // Sort variable names by length (longest first) to prevent partial matches
146
- const sortedKeys = Object.keys(inject ?? {}).sort((a, b) => b.length - a.length);
147
- sortedKeys.forEach((variableName) => {
148
- const key = `:${variableName}`;
149
- while (body.indexOf(key) !== -1) {
150
- body = body.replace(key, inject[variableName].toString());
151
- }
152
- });
153
- return body;
154
- }
155
- }
156
- exports.ZMailService = ZMailService;
@@ -1,22 +0,0 @@
1
- import { ZOrm } from './orm';
2
- import { ZSQLService } from '../sql_service';
3
- import { ZMailBlacklist, ZMailBlacklistSearch } from '../typings';
4
- export declare class ZMailBlacklistOrm extends ZOrm {
5
- private hashSalt;
6
- private sqlService;
7
- constructor(opt: { alias?: string; sqlService: ZSQLService; hashSalt?: string });
8
- genEmailUnsubscribeHash({ email }: { email: string }): Promise<string>;
9
- create(
10
- item: Omit<ZMailBlacklist, 'updated_at' | 'created_at'>,
11
- ): Promise<Omit<ZMailBlacklist, 'updated_at' | 'created_at'>>;
12
- findOne(conditions: Partial<ZMailBlacklist>): Promise<ZMailBlacklist>;
13
- findAll(
14
- conditions?: Partial<ZMailBlacklistSearch>,
15
- opt?: {
16
- limit?: number;
17
- },
18
- ): Promise<ZMailBlacklist[]>;
19
- update({ email, is_blacklisted }: Pick<ZMailBlacklist, 'email' | 'is_blacklisted'>): Promise<boolean>;
20
- upsert(item: Omit<ZMailBlacklist, 'updated_at' | 'created_at'>): Promise<ZMailBlacklist>;
21
- createTable(): Promise<void>;
22
- }
@@ -1,79 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.ZMailBlacklistOrm = void 0;
4
- const orm_1 = require('./orm');
5
- const crypto_service_1 = require('../crypto_service');
6
- class ZMailBlacklistOrm extends orm_1.ZOrm {
7
- constructor(opt) {
8
- super({ alias: opt.alias ?? 'email_blacklist' });
9
- this.sqlService = opt.sqlService;
10
- this.hashSalt = opt.hashSalt ?? 'ZTECHNO';
11
- }
12
- async genEmailUnsubscribeHash({ email }) {
13
- const existingHash = await this.findOne({ email });
14
- if (existingHash !== undefined) {
15
- return existingHash.hash;
16
- }
17
- const hash = crypto_service_1.ZCryptoService.hash('sha512', `${this.hashSalt}-${email}`);
18
- await this.create({ email, hash, is_blacklisted: 0 });
19
- return hash;
20
- }
21
- async create(item) {
22
- const res = await this.sqlService.query(
23
- `
24
- INSERT INTO \`${this.alias}\` (email, hash, is_blacklisted, updated_at, created_at)
25
- VALUES (:email, :hash, :is_blacklisted, NOW(), NOW())
26
- ON DUPLICATE KEY UPDATE hash=:hash, updated_at=NOW()
27
- `,
28
- item,
29
- );
30
- return item; // return Object.assign(item, { invoice_id: res.insertId }) as ZMailBlacklist
31
- }
32
- async findOne(conditions) {
33
- const rows = await this.findAll(conditions, { limit: 1 });
34
- return rows[0];
35
- }
36
- async findAll(conditions, opt) {
37
- const whereKeys = Object.keys(conditions ?? {});
38
- const whereClause = whereKeys.length ? `WHERE ${whereKeys.map((key) => `${key}=:${key}`).join(' AND ')}` : '';
39
- const limit = opt?.limit ? `LIMIT ${opt.limit}` : '';
40
- return await this.sqlService.exec({
41
- query: /*SQL*/ `SELECT * FROM \`${this.alias}\` ${whereClause} ${limit}`,
42
- params: conditions,
43
- });
44
- }
45
- async update({ email, is_blacklisted }) {
46
- const res = await this.sqlService.query(
47
- `
48
- UPDATE \`${this.alias}\` SET is_blacklisted=:is_blacklisted, updated_at=NOW() WHERE email=:email
49
- `,
50
- { email, is_blacklisted },
51
- );
52
- return res.affectedRows !== 0;
53
- }
54
- async upsert(item) {
55
- await this.sqlService.query(
56
- `
57
- INSERT INTO \`${this.alias}\` (email, hash, is_blacklisted, updated_at, created_at)
58
- VALUES (:email, :hash, :is_blacklisted, NOW(), NOW())
59
- ON DUPLICATE KEY UPDATE hash=:hash, is_blacklisted=:is_blacklisted, updated_at=NOW()
60
- `,
61
- item,
62
- );
63
- return item;
64
- }
65
- async createTable() {
66
- await this.sqlService.query(/*SQL*/ `
67
- CREATE TABLE \`${this.alias}\` (
68
- \`email\` varchar(512) NOT NULL,
69
- \`hash\` varchar(256) NOT NULL,
70
- \`is_blacklisted\` tinyint(1) NOT NULL DEFAULT 0,
71
- \`updated_at\` datetime NOT NULL DEFAULT current_timestamp(),
72
- \`created_at\` datetime NOT NULL DEFAULT current_timestamp(),
73
- PRIMARY KEY (\`email\`),
74
- KEY \`is_blacklisted\` (\`is_blacklisted\`)
75
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
76
- `);
77
- }
78
- }
79
- exports.ZMailBlacklistOrm = ZMailBlacklistOrm;
package/lib/orm/orm.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { ZSQLService } from '../sql_service';
2
- export declare class ZOrm {
3
- readonly alias: string;
4
- constructor(opt: { alias: string });
5
- ensureTableExists(sqlService: ZSQLService): Promise<void>;
6
- private checkTableExists;
7
- createTable(sqlService: ZSQLService): Promise<void>;
8
- }
package/lib/orm/orm.js DELETED
@@ -1,26 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.ZOrm = void 0;
4
- class ZOrm {
5
- constructor(opt) {
6
- this.alias = opt.alias;
7
- }
8
- async ensureTableExists(sqlService) {
9
- const exists = await this.checkTableExists(sqlService);
10
- if (!exists) {
11
- await this.createTable(sqlService);
12
- }
13
- }
14
- async checkTableExists(sqlService) {
15
- const res = await sqlService.query(`
16
- SELECT ENGINE, VERSION, CREATE_TIME FROM information_schema.tables
17
- WHERE table_schema = '${sqlService.database}' AND table_name = '${this.alias}'
18
- LIMIT 1
19
- `);
20
- return res.length > 0;
21
- }
22
- async createTable(sqlService) {
23
- throw new Error(`${this.alias} Create Table Statement Not Implemented!`);
24
- }
25
- }
26
- exports.ZOrm = ZOrm;
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Build a Docker image tagged as <awsAccountId>/<packagename>:latest
4
- * @param opt.packagename - Override the image name (defaults to package.json name)
5
- * @param opt.awsAccountId - Override the AWS Account ID (defaults to package.json config.awsAccountId)
6
- * @param opt.tag - Override the tag (defaults to "latest")
7
- * @param opt.context - Docker build context path (defaults to ".")
8
- */
9
- export declare function dockerBuild(opt?: {
10
- packagename?: string;
11
- awsAccountId?: string;
12
- tag?: string;
13
- context?: string;
14
- }): void;
@@ -1,91 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
- var __importDefault =
4
- (this && this.__importDefault) ||
5
- function (mod) {
6
- return mod && mod.__esModule ? mod : { default: mod };
7
- };
8
- Object.defineProperty(exports, '__esModule', { value: true });
9
- exports.dockerBuild = void 0;
10
- const child_process_1 = require('child_process');
11
- const path_1 = __importDefault(require('path'));
12
- const fs_1 = __importDefault(require('fs'));
13
- // ANSI color helpers
14
- const red = (msg) => `\x1b[31m${msg}\x1b[0m`;
15
- const green = (msg) => `\x1b[32m${msg}\x1b[0m`;
16
- const cyan = (msg) => `\x1b[36m${msg}\x1b[0m`;
17
- function loadPackageJson() {
18
- const pkgPath = path_1.default.join(process.cwd(), 'package.json');
19
- if (!fs_1.default.existsSync(pkgPath)) {
20
- throw new Error(`No package.json found in ${process.cwd()}`);
21
- }
22
- return JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf-8'));
23
- }
24
- /**
25
- * Build a Docker image tagged as <awsAccountId>/<packagename>:latest
26
- * @param opt.packagename - Override the image name (defaults to package.json name)
27
- * @param opt.awsAccountId - Override the AWS Account ID (defaults to package.json config.awsAccountId)
28
- * @param opt.tag - Override the tag (defaults to "latest")
29
- * @param opt.context - Docker build context path (defaults to ".")
30
- */
31
- function dockerBuild(opt) {
32
- const pkg = loadPackageJson();
33
- const packagename = opt?.packagename || pkg.name;
34
- const awsAccountId = opt?.awsAccountId || pkg.config?.awsAccountId || process.env.AWS_ACCOUNT_ID;
35
- const tag = opt?.tag || 'latest';
36
- const context = opt?.context || '.';
37
- if (!packagename) {
38
- throw new Error('Missing package name. Set "name" in package.json or pass --name.');
39
- }
40
- if (!awsAccountId) {
41
- throw new Error('Missing AWS Account ID. Set "config.awsAccountId" in package.json or AWS_ACCOUNT_ID env var.');
42
- }
43
- const image = `${awsAccountId}/${packagename}:${tag}`;
44
- const cmd = `docker build -t ${image} ${context}`;
45
- console.log(green(`[Docker Build]`));
46
- console.log(cyan(`> ${cmd}`));
47
- (0, child_process_1.execSync)(cmd, { stdio: 'inherit' });
48
- console.log(green(`✓ Built ${image}`));
49
- }
50
- exports.dockerBuild = dockerBuild;
51
- const USAGE = `
52
- Usage:
53
- ztechno-docker-build [options]
54
-
55
- Options:
56
- --name <name> Override image name (default: package.json "name")
57
- --account <id> Override AWS Account ID (default: package.json "config.awsAccountId")
58
- --tag <tag> Override tag (default: "latest")
59
- --context <path> Docker build context (default: ".")
60
- -h, --help Show this help
61
-
62
- package.json format:
63
- {
64
- "name": "my-image",
65
- "config": {
66
- "awsAccountId": "00028463827"
67
- }
68
- }
69
- `.trim();
70
- if (require.main === module) {
71
- try {
72
- const args = process.argv.slice(2);
73
- if (args.includes('--help') || args.includes('-h')) {
74
- console.log(USAGE);
75
- process.exit(0);
76
- }
77
- const getArg = (flag) => {
78
- const idx = args.indexOf(flag);
79
- return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : undefined;
80
- };
81
- dockerBuild({
82
- packagename: getArg('--name'),
83
- awsAccountId: getArg('--account'),
84
- tag: getArg('--tag'),
85
- context: getArg('--context'),
86
- });
87
- } catch (err) {
88
- console.error(red(`✗ Error: ${err.message}`));
89
- process.exit(1);
90
- }
91
- }