@sdflc/backend-helpers 1.0.81 → 1.0.83

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/build/BaseCore.js CHANGED
@@ -612,8 +612,8 @@ class BaseCore {
612
612
  }
613
613
  async extractCredentials(args) {
614
614
  const { req, space, authorization } = args;
615
- const token = req.cookies?.[space.cookieName] || authorization;
616
- const fingerprint = req.cookies?.[space.fingerprintCookieName] || args.fingerprint || '';
615
+ const token = req.cookies?.[space.cookieName] || req.headers?.[constants_1.HEADERS.AUTHORIZATION] || authorization;
616
+ const fingerprint = req.cookies?.[space.fingerprintCookieName] || req.headers?.[constants_1.HEADERS.FINGERPRINT] || args.fingerprint || '';
617
617
  return {
618
618
  token,
619
619
  fingerprint,
@@ -62,6 +62,26 @@ const SQLS = {
62
62
  FROM INFORMATION_SCHEMA.TABLES';
63
63
  `,
64
64
  },
65
+ mssql: {
66
+ listTablesSchema: (appSettings) => `
67
+ SELECT TABLE_NAME as table_name
68
+ FROM INFORMATION_SCHEMA.TABLES
69
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
70
+ `,
71
+ listTables: () => `
72
+ SELECT TABLE_NAME as table_name
73
+ FROM INFORMATION_SCHEMA.TABLES
74
+ `,
75
+ dropTablesSchema: (appSettings) => `
76
+ SELECT 'DROP TABLE IF EXISTS [${appSettings?.dbSchema}].[' + TABLE_NAME + '];' as cmd
77
+ FROM INFORMATION_SCHEMA.TABLES
78
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
79
+ `,
80
+ dropTables: () => `
81
+ SELECT 'DROP TABLE IF EXISTS ' + TABLE_NAME + ';' as cmd
82
+ FROM INFORMATION_SCHEMA.TABLES';
83
+ `,
84
+ },
65
85
  };
66
86
  class DbMigratorAndSeeder {
67
87
  knexHandle;
@@ -1,4 +1,5 @@
1
1
  import { DbFieldAddDefaultInterface } from './interfaces';
2
+ import { FIELDS } from './constants';
2
3
  export declare const dbFieldAddDefaults: (table: any, opt?: DbFieldAddDefaultInterface) => void;
3
4
  export declare const addOrderNo: (table: any, opt?: any) => any;
4
5
  export declare const addAmount: (table: any, fieldName: string) => any;
@@ -7,5 +8,6 @@ export declare const addUserId: (table: any, opt?: any) => any;
7
8
  export declare const addAccountId: (table: any, opt?: any) => any;
8
9
  export declare const addLang: (table: any, opt?: any) => any;
9
10
  export declare const defaultFields: (opt?: any) => {
10
- [x: number]: string;
11
+ [FIELDS.CREATED_AT]: string;
12
+ [FIELDS.UPDATED_AT]: string;
11
13
  };
@@ -3,7 +3,7 @@ import { Logger, ACCESS_RIGHTS, MeasureTool, StrOrderHelpers, LoggerLevels } fro
3
3
  import check from 'check-types';
4
4
  import { castArray } from 'lodash';
5
5
  import { validateGet, validateGetMany, validateRemove, validateRemoveMany } from './commonValidators';
6
- import { ACTIONS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP, FIELDS, ID_TYPES, ORDER_BYS } from './constants';
6
+ import { ACTIONS, DEFAULT_ORDER_NO, DEFAULT_ORDER_NO_STEP, FIELDS, HEADERS, ID_TYPES, ORDER_BYS } from './constants';
7
7
  import { getDefaultJwtAlgorithm, getDefaultJwtIssuer, verifyUserToken } from './userToken';
8
8
  const defaultValidate = ( /*args: any, opt?: BaseCoreActionsInterface*/) => {
9
9
  return [true, {}];
@@ -606,8 +606,8 @@ class BaseCore {
606
606
  }
607
607
  async extractCredentials(args) {
608
608
  const { req, space, authorization } = args;
609
- const token = req.cookies?.[space.cookieName] || authorization;
610
- const fingerprint = req.cookies?.[space.fingerprintCookieName] || args.fingerprint || '';
609
+ const token = req.cookies?.[space.cookieName] || req.headers?.[HEADERS.AUTHORIZATION] || authorization;
610
+ const fingerprint = req.cookies?.[space.fingerprintCookieName] || req.headers?.[HEADERS.FINGERPRINT] || args.fingerprint || '';
611
611
  return {
612
612
  token,
613
613
  fingerprint,
@@ -23,6 +23,26 @@ const SQLS = {
23
23
  FROM INFORMATION_SCHEMA.TABLES';
24
24
  `,
25
25
  },
26
+ mssql: {
27
+ listTablesSchema: (appSettings) => `
28
+ SELECT TABLE_NAME as table_name
29
+ FROM INFORMATION_SCHEMA.TABLES
30
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
31
+ `,
32
+ listTables: () => `
33
+ SELECT TABLE_NAME as table_name
34
+ FROM INFORMATION_SCHEMA.TABLES
35
+ `,
36
+ dropTablesSchema: (appSettings) => `
37
+ SELECT 'DROP TABLE IF EXISTS [${appSettings?.dbSchema}].[' + TABLE_NAME + '];' as cmd
38
+ FROM INFORMATION_SCHEMA.TABLES
39
+ WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
40
+ `,
41
+ dropTables: () => `
42
+ SELECT 'DROP TABLE IF EXISTS ' + TABLE_NAME + ';' as cmd
43
+ FROM INFORMATION_SCHEMA.TABLES';
44
+ `,
45
+ },
26
46
  };
27
47
  class DbMigratorAndSeeder {
28
48
  knexHandle;
@@ -1,4 +1,5 @@
1
1
  import { DbFieldAddDefaultInterface } from './interfaces';
2
+ import { FIELDS } from './constants';
2
3
  export declare const dbFieldAddDefaults: (table: any, opt?: DbFieldAddDefaultInterface) => void;
3
4
  export declare const addOrderNo: (table: any, opt?: any) => any;
4
5
  export declare const addAmount: (table: any, fieldName: string) => any;
@@ -7,5 +8,6 @@ export declare const addUserId: (table: any, opt?: any) => any;
7
8
  export declare const addAccountId: (table: any, opt?: any) => any;
8
9
  export declare const addLang: (table: any, opt?: any) => any;
9
10
  export declare const defaultFields: (opt?: any) => {
10
- [x: number]: string;
11
+ [FIELDS.CREATED_AT]: string;
12
+ [FIELDS.UPDATED_AT]: string;
11
13
  };
@@ -3,7 +3,7 @@ export * from './interfaces';
3
3
  export * from './configBulder';
4
4
  export * from './Database';
5
5
  export * from './dbHelpers';
6
- export * from './DbMigratorAndSeeder';
6
+ export * from './dbMigratorAndSeeder';
7
7
  export * from './dbSeeder';
8
8
  export * from './knexConfigBuilder';
9
9
  export * from './redisClient';
@@ -3,7 +3,7 @@ export * from './interfaces';
3
3
  export * from './configBulder';
4
4
  export * from './Database';
5
5
  export * from './dbHelpers';
6
- export * from './DbMigratorAndSeeder';
6
+ export * from './dbMigratorAndSeeder';
7
7
  export * from './dbSeeder';
8
8
  export * from './knexConfigBuilder';
9
9
  export * from './redisClient';
@@ -53,10 +53,11 @@ export const buildKnexConfig = (dirName, appConfig) => {
53
53
  ...sharedConfig,
54
54
  debug,
55
55
  migrations: {
56
+ // https://knexjs.org/guide/migrations.html#migration-api
56
57
  stub: path.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
57
58
  directory: path.join(dirName, migrationsFolder || defaultMigrationsFolder),
58
- tableName: migrationsTable ||
59
- `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
59
+ schemaName: useSchemaForMigrationsTable ? dbSchema : undefined,
60
+ tableName: migrationsTable || defaultMigrationsTable,
60
61
  },
61
62
  seeds: {
62
63
  directory: path.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
@@ -67,8 +68,8 @@ export const buildKnexConfig = (dirName, appConfig) => {
67
68
  debug,
68
69
  migrations: {
69
70
  directory: path.join(dirName, migrationsFolder || defaultMigrationsFolder),
70
- tableName: migrationsTable ||
71
- `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
71
+ schemaName: useSchemaForMigrationsTable ? dbSchema : undefined,
72
+ tableName: migrationsTable || defaultMigrationsTable,
72
73
  },
73
74
  seeds: {
74
75
  directory: path.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
package/build/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from './interfaces';
3
3
  export * from './configBulder';
4
4
  export * from './Database';
5
5
  export * from './dbHelpers';
6
- export * from './DbMigratorAndSeeder';
6
+ export * from './dbMigratorAndSeeder';
7
7
  export * from './dbSeeder';
8
8
  export * from './knexConfigBuilder';
9
9
  export * from './redisClient';
package/build/index.js CHANGED
@@ -19,7 +19,7 @@ __exportStar(require("./interfaces"), exports);
19
19
  __exportStar(require("./configBulder"), exports);
20
20
  __exportStar(require("./Database"), exports);
21
21
  __exportStar(require("./dbHelpers"), exports);
22
- __exportStar(require("./DbMigratorAndSeeder"), exports);
22
+ __exportStar(require("./dbMigratorAndSeeder"), exports);
23
23
  __exportStar(require("./dbSeeder"), exports);
24
24
  __exportStar(require("./knexConfigBuilder"), exports);
25
25
  __exportStar(require("./redisClient"), exports);
@@ -59,10 +59,11 @@ const buildKnexConfig = (dirName, appConfig) => {
59
59
  ...sharedConfig,
60
60
  debug,
61
61
  migrations: {
62
+ // https://knexjs.org/guide/migrations.html#migration-api
62
63
  stub: path_1.default.join(dirName, migrationsTemplateFileName || defaultMigrationsTemplateFileName),
63
64
  directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
64
- tableName: migrationsTable ||
65
- `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
65
+ schemaName: useSchemaForMigrationsTable ? dbSchema : undefined,
66
+ tableName: migrationsTable || defaultMigrationsTable,
66
67
  },
67
68
  seeds: {
68
69
  directory: path_1.default.join(dirName, seedsFolderDev || seedsFolder || defaultSeedsFolder),
@@ -73,8 +74,8 @@ const buildKnexConfig = (dirName, appConfig) => {
73
74
  debug,
74
75
  migrations: {
75
76
  directory: path_1.default.join(dirName, migrationsFolder || defaultMigrationsFolder),
76
- tableName: migrationsTable ||
77
- `${useSchemaForMigrationsTable ? `${dbSchema}.` : ''}${migrationsTable || defaultMigrationsTable}`,
77
+ schemaName: useSchemaForMigrationsTable ? dbSchema : undefined,
78
+ tableName: migrationsTable || defaultMigrationsTable,
78
79
  },
79
80
  seeds: {
80
81
  directory: path_1.default.join(dirName, seedsFolderProd || seedsFolder || defaultSeedsFolder),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.81",
3
+ "version": "1.0.83",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -41,20 +41,20 @@
41
41
  "@types/lodash": "^4.17.15",
42
42
  "@types/node": "^22.13.4",
43
43
  "@types/uuid": "^10.0.0",
44
- "@typescript-eslint/eslint-plugin": "^8.24.1",
45
- "@typescript-eslint/parser": "^8.24.1",
44
+ "@typescript-eslint/eslint-plugin": "^8.30.1",
45
+ "@typescript-eslint/parser": "^8.30.1",
46
46
  "eslint": "^9.20.1",
47
- "eslint-config-prettier": "^10.0.1",
47
+ "eslint-config-prettier": "^10.1.2",
48
48
  "eslint-plugin-jest": "^28.11.0",
49
- "eslint-plugin-prettier": "^5.2.3",
49
+ "eslint-plugin-prettier": "^5.2.6",
50
50
  "husky": "^9.1.7",
51
51
  "jest": "^29.7.0",
52
- "prettier": "^3.5.1",
52
+ "prettier": "^3.5.3",
53
53
  "rimraf": "^6.0.1",
54
54
  "run-script-os": "^1.1.6",
55
- "ts-jest": "^29.2.5",
55
+ "ts-jest": "^29.3.2",
56
56
  "ts-node": "^10.9.2",
57
- "typescript": "^5.7.3"
57
+ "typescript": "^5.8.3"
58
58
  },
59
59
  "dependencies": {
60
60
  "@sdflc/api-helpers": "^1.1.13",
@@ -71,7 +71,7 @@
71
71
  "jsonwebtoken": "^9.0.2",
72
72
  "knex": "^3.1.0",
73
73
  "lodash": "^4.17.21",
74
- "pg": "^8.13.3",
74
+ "pg": "^8.14.1",
75
75
  "redis": "^4.7.0",
76
76
  "uuid": "^11.1.0"
77
77
  }