ztechno_core 0.0.49 → 0.0.51

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.
@@ -1,6 +1,7 @@
1
+ import SMTPTransport from 'nodemailer/lib/smtp-transport';
1
2
  import { MailOptionsHtml, MailOptionsText, MailServiceOptions } from './typings/mail_types';
2
3
  export declare class ZMailService {
3
4
  private opt;
4
5
  constructor(opt: MailServiceOptions);
5
- send(mailOpts: MailOptionsText | MailOptionsHtml): Promise<any>;
6
+ send(mailOpts: MailOptionsText | MailOptionsHtml): Promise<SMTPTransport.SentMessageInfo>;
6
7
  }
@@ -1,13 +1,18 @@
1
1
  'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
2
7
  Object.defineProperty(exports, '__esModule', { value: true });
3
8
  exports.ZMailService = void 0;
4
- const nodemailer = require('nodemailer');
9
+ const nodemailer_1 = __importDefault(require('nodemailer'));
5
10
  class ZMailService {
6
11
  constructor(opt) {
7
12
  this.opt = opt;
8
13
  }
9
14
  send(mailOpts) {
10
- const mailTransporter = nodemailer.createTransport({
15
+ const mailTransporter = nodemailer_1.default.createTransport({
11
16
  service: 'gmail',
12
17
  auth: this.opt.auth,
13
18
  });
@@ -17,6 +22,8 @@ class ZMailService {
17
22
  subject: mailOpts.subject,
18
23
  text: mailOpts.body || undefined,
19
24
  html: mailOpts.html || undefined,
25
+ dkim: mailOpts.dkim,
26
+ priority: mailOpts.priority,
20
27
  };
21
28
  return new Promise((resolve, reject) => {
22
29
  mailTransporter.sendMail(mailDetails, function (err, data) {
@@ -2,16 +2,40 @@ import * as mysql from 'mysql';
2
2
  type ZOnErrorCallback = (err: mysql.MysqlError) => any;
3
3
  type ZOnLogCallback = (log: string) => any;
4
4
  export declare class ZSqlService {
5
+ private options;
5
6
  private pool;
6
7
  private defaultPoolconfig;
7
8
  private listeners;
8
9
  private databaseName;
9
10
  get database(): string;
10
- constructor(options: mysql.PoolConfig);
11
+ constructor(
12
+ options: mysql.PoolConfig & {
13
+ dateStringTimezone?: string;
14
+ },
15
+ );
11
16
  on(eventName: 'err', listener: ZOnErrorCallback): void;
12
17
  on(eventName: 'log', listener: ZOnLogCallback): void;
13
18
  private triggerEvent;
14
19
  private getPoolConnection;
20
+ exec(opt: {
21
+ query: string;
22
+ params?:
23
+ | any[]
24
+ | {
25
+ [key: string]: any;
26
+ };
27
+ }): Promise<{
28
+ insertId: number;
29
+ affectedRows: number;
30
+ }>;
31
+ exec<T = any>(opt: {
32
+ query: string;
33
+ params?:
34
+ | any[]
35
+ | {
36
+ [key: string]: any;
37
+ };
38
+ }): Promise<T>;
15
39
  query(
16
40
  sql: string,
17
41
  params?:
@@ -30,7 +54,8 @@ export declare class ZSqlService {
30
54
  | {
31
55
  [key: string]: any;
32
56
  },
33
- ): Promise<T>;
57
+ ): Promise<T[]>;
34
58
  private formatQueryParams;
59
+ private isSqlDate;
35
60
  }
36
61
  export {};
@@ -47,6 +47,7 @@ class ZSqlService {
47
47
  return this.databaseName;
48
48
  }
49
49
  constructor(options) {
50
+ this.options = options;
50
51
  this.defaultPoolconfig = {
51
52
  connectionLimit: 10,
52
53
  timeout: 20000,
@@ -82,6 +83,23 @@ class ZSqlService {
82
83
  this.pool.getConnection((err, con) => (err ? reject(err) : resolve(con)));
83
84
  });
84
85
  }
86
+ async exec(opt) {
87
+ const rows = await this.query(opt.query, opt.params);
88
+ if (!Array.isArray(rows)) {
89
+ return rows;
90
+ }
91
+ if (!this.options.dateStringTimezone) {
92
+ return rows;
93
+ }
94
+ return rows.map((row) => {
95
+ Object.keys(row).map((key) => {
96
+ if (this.isSqlDate(row[key])) {
97
+ row[key] = new Date(row[key] + this.options.dateStringTimezone);
98
+ }
99
+ });
100
+ return row;
101
+ });
102
+ }
85
103
  async query(sql, params) {
86
104
  try {
87
105
  const con = await this.getPoolConnection();
@@ -112,5 +130,19 @@ class ZSqlService {
112
130
  return values.hasOwnProperty(key) ? con.escape(values[key]) : txt;
113
131
  });
114
132
  }
133
+ isSqlDate(str) {
134
+ if (
135
+ str &&
136
+ typeof str === 'string' &&
137
+ str[4] === '-' &&
138
+ str[7] === '-' &&
139
+ str[10] === ' ' &&
140
+ str[13] === ':' &&
141
+ str[16] === ':'
142
+ ) {
143
+ return true;
144
+ }
145
+ return false;
146
+ }
115
147
  }
116
148
  exports.ZSqlService = ZSqlService;
@@ -1,20 +1,14 @@
1
- import { ZSqlService } from './sql_service';
2
1
  import { TranslateData, dbTranslationRow } from '.';
2
+ import { ATranslateLang, TranslateServiceOptions } from './typings/translate_types';
3
3
  export declare class ZTranslateService {
4
4
  private opt;
5
5
  private localCache;
6
6
  private get sql();
7
7
  surpressErrors: boolean;
8
- getLanguages(): string[];
8
+ getLanguages(): ATranslateLang[];
9
9
  getSourceLang(): string;
10
10
  getDefaultLang(): string;
11
- constructor(opt: {
12
- sqlService: ZSqlService;
13
- googleApiKey: string;
14
- languages?: string[];
15
- defaultLang?: string;
16
- sourceLang?: string;
17
- });
11
+ constructor(opt: TranslateServiceOptions);
18
12
  private codes;
19
13
  getLang(cookies: { [key: string]: string }): string;
20
14
  translateText(langOrReq: string | any, text: string): Promise<string>;
@@ -9,7 +9,12 @@ class ZTranslateService {
9
9
  return this.opt.sqlService;
10
10
  }
11
11
  getLanguages() {
12
- return this.opt.languages || ['en', 'nl'];
12
+ return (
13
+ this.opt.languages || [
14
+ { lang: 'en', text: 'English' },
15
+ { lang: 'nl', text: 'Nederlands' },
16
+ ]
17
+ );
13
18
  }
14
19
  getSourceLang() {
15
20
  return this.opt.sourceLang || 'en';
@@ -33,17 +38,14 @@ class ZTranslateService {
33
38
  [`&#8482`]: `™`,
34
39
  };
35
40
  translate.key = opt.googleApiKey;
36
- this.getLanguages().map((lang) => (this.localCache[lang] = {}));
41
+ this.getLanguages().map((lang) => (this.localCache[lang.lang] = {}));
37
42
  setInterval(() => this.clearLocalCache(), 1000 * 60 * 60); // Every Hour
38
43
  }
39
44
  getLang(cookies) {
40
45
  const defaultLang = this.getDefaultLang();
41
46
  const langKey = (cookies.lang || defaultLang).toLowerCase();
42
- const langs = this.getLanguages();
43
- if (!langs.includes(langKey)) {
44
- return defaultLang;
45
- }
46
- return langKey;
47
+ const foundLang = this.getLanguages().find((l) => l.lang === langKey);
48
+ return foundLang === undefined ? defaultLang : foundLang.lang;
47
49
  }
48
50
  async translateText(langOrReq, text) {
49
51
  const lang = typeof langOrReq === 'string' ? langOrReq : this.getLang(langOrReq.cookies);
@@ -1,3 +1,4 @@
1
+ import nodemailer from 'nodemailer';
1
2
  export type MailServiceOptions = {
2
3
  auth: {
3
4
  user: string;
@@ -9,7 +10,7 @@ export type MailOptionsBase = {
9
10
  recipient: string;
10
11
  subject: string;
11
12
  from?: string;
12
- };
13
+ } & Pick<nodemailer.SendMailOptions, 'dkim' | 'priority'>;
13
14
  export type MailOptionsText = MailOptionsBase & {
14
15
  body: string;
15
16
  };
@@ -1,3 +1,4 @@
1
+ import { ZSqlService } from '../sql_service';
1
2
  export type ZDom = {} & ZNode;
2
3
  export type ZNode = {
3
4
  getAttribute: (attr: string) => string;
@@ -32,3 +33,14 @@ export type dbTranslationRow = {
32
33
  key: string;
33
34
  value: string;
34
35
  };
36
+ export type ATranslateLang = {
37
+ lang: string;
38
+ text: string;
39
+ };
40
+ export type TranslateServiceOptions = {
41
+ sqlService: ZSqlService;
42
+ googleApiKey: string;
43
+ languages?: ATranslateLang[];
44
+ defaultLang?: string;
45
+ sourceLang?: string;
46
+ };
@@ -12,7 +12,7 @@ export declare class ZUserService {
12
12
  register({ email, pass, role, admin }: ZRequiredUserColumns): Promise<{
13
13
  session: string;
14
14
  }>;
15
- fetch(opt?: { limit: number }): Promise<any[]>;
15
+ fetch(opt?: { limit: number }): Promise<any[][]>;
16
16
  exists(
17
17
  opt:
18
18
  | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztechno_core",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "Core files for ztechno framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -29,6 +29,7 @@
29
29
  "devDependencies": {
30
30
  "@types/jest": "^29.2.3",
31
31
  "@types/mysql": "^2.15.21",
32
+ "@types/nodemailer": "^6.4.14",
32
33
  "jest": "^29.3.1",
33
34
  "prettier": "^2.7.1",
34
35
  "ts-jest": "^29.0.3",