@futdevpro/nts-dynamo 1.2.90
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/BuildPackage.bat +1 -0
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/lib/_constants/dynamobe-global.settings.d.ts +2 -0
- package/lib/_constants/dynamobe-global.settings.d.ts.map +1 -0
- package/lib/_constants/dynamobe-global.settings.js +11 -0
- package/lib/_enum/data-model-types.enum.d.ts +5 -0
- package/lib/_enum/data-model-types.enum.d.ts.map +1 -0
- package/lib/_enum/data-model-types.enum.js +9 -0
- package/lib/_enum/dynamobe-data-service-function.enum.d.ts +7 -0
- package/lib/_enum/dynamobe-data-service-function.enum.d.ts.map +1 -0
- package/lib/_enum/dynamobe-data-service-function.enum.js +14 -0
- package/lib/_enum/dynamobe-route-security.enum.d.ts +5 -0
- package/lib/_enum/dynamobe-route-security.enum.d.ts.map +1 -0
- package/lib/_enum/dynamobe-route-security.enum.js +9 -0
- package/lib/_enum/http/http-call-type.enum.d.ts +7 -0
- package/lib/_enum/http/http-call-type.enum.d.ts.map +1 -0
- package/lib/_enum/http/http-call-type.enum.js +11 -0
- package/lib/_enum/http/http-response-type.enum.d.ts +6 -0
- package/lib/_enum/http/http-response-type.enum.d.ts.map +1 -0
- package/lib/_enum/http/http-response-type.enum.js +10 -0
- package/lib/_enum/log-style.enum.d.ts +25 -0
- package/lib/_enum/log-style.enum.d.ts.map +1 -0
- package/lib/_enum/log-style.enum.js +29 -0
- package/lib/_enum/predefined-data-types.enum.d.ts +7 -0
- package/lib/_enum/predefined-data-types.enum.d.ts.map +1 -0
- package/lib/_enum/predefined-data-types.enum.js +11 -0
- package/lib/_models/dynamobe-api-call-params.d.ts +34 -0
- package/lib/_models/dynamobe-api-call-params.d.ts.map +1 -0
- package/lib/_models/dynamobe-api-call-params.js +24 -0
- package/lib/_models/dynamobe-app-params.d.ts +14 -0
- package/lib/_models/dynamobe-app-params.d.ts.map +1 -0
- package/lib/_models/dynamobe-app-params.js +13 -0
- package/lib/_models/dynamobe-data-model-params.d.ts +12 -0
- package/lib/_models/dynamobe-data-model-params.d.ts.map +1 -0
- package/lib/_models/dynamobe-data-model-params.js +14 -0
- package/lib/_models/dynamobe-endpoint-control.d.ts +28 -0
- package/lib/_models/dynamobe-endpoint-control.d.ts.map +1 -0
- package/lib/_models/dynamobe-endpoint-control.js +85 -0
- package/lib/_models/dynamobe-global-settings.d.ts +8 -0
- package/lib/_models/dynamobe-global-settings.d.ts.map +1 -0
- package/lib/_models/dynamobe-global-settings.js +6 -0
- package/lib/_models/fullstack-models/control-models/daily-usage-data.d.ts +17 -0
- package/lib/_models/fullstack-models/control-models/daily-usage-data.d.ts.map +1 -0
- package/lib/_models/fullstack-models/control-models/daily-usage-data.js +21 -0
- package/lib/_models/fullstack-models/control-models/dynamobe-data-property-params.d.ts +27 -0
- package/lib/_models/fullstack-models/control-models/dynamobe-data-property-params.d.ts.map +1 -0
- package/lib/_models/fullstack-models/control-models/dynamobe-data-property-params.js +66 -0
- package/lib/_models/fullstack-models/control-models/dynamobe-error.d.ts +17 -0
- package/lib/_models/fullstack-models/control-models/dynamobe-error.d.ts.map +1 -0
- package/lib/_models/fullstack-models/control-models/dynamobe-error.js +195 -0
- package/lib/_models/fullstack-models/control-models/geo-ip-location.d.ts +25 -0
- package/lib/_models/fullstack-models/control-models/geo-ip-location.d.ts.map +1 -0
- package/lib/_models/fullstack-models/control-models/geo-ip-location.js +2 -0
- package/lib/_models/fullstack-models/control-models/usage-action.d.ts +8 -0
- package/lib/_models/fullstack-models/control-models/usage-action.d.ts.map +1 -0
- package/lib/_models/fullstack-models/control-models/usage-action.js +12 -0
- package/lib/_models/fullstack-models/control-models/usage-data.d.ts +13 -0
- package/lib/_models/fullstack-models/control-models/usage-data.d.ts.map +1 -0
- package/lib/_models/fullstack-models/control-models/usage-data.js +15 -0
- package/lib/_models/fullstack-models/data-models/custom-data.d.ts +15 -0
- package/lib/_models/fullstack-models/data-models/custom-data.d.ts.map +1 -0
- package/lib/_models/fullstack-models/data-models/custom-data.js +23 -0
- package/lib/_models/fullstack-models/data-models/metadata.d.ts +16 -0
- package/lib/_models/fullstack-models/data-models/metadata.d.ts.map +1 -0
- package/lib/_models/fullstack-models/data-models/metadata.js +16 -0
- package/lib/_models/fullstack-models/data-models/usage-session.d.ts +33 -0
- package/lib/_models/fullstack-models/data-models/usage-session.d.ts.map +1 -0
- package/lib/_models/fullstack-models/data-models/usage-session.js +48 -0
- package/lib/_modules/test-route/custom-data.service.d.ts +5 -0
- package/lib/_modules/test-route/custom-data.service.d.ts.map +1 -0
- package/lib/_modules/test-route/custom-data.service.js +12 -0
- package/lib/_modules/test-route/test-controller.d.ts +5 -0
- package/lib/_modules/test-route/test-controller.d.ts.map +1 -0
- package/lib/_modules/test-route/test-controller.js +125 -0
- package/lib/_modules/usage-route/usage-controller.d.ts +6 -0
- package/lib/_modules/usage-route/usage-controller.d.ts.map +1 -0
- package/lib/_modules/usage-route/usage-controller.js +88 -0
- package/lib/_modules/usage-route/usage.service.d.ts +18 -0
- package/lib/_modules/usage-route/usage.service.d.ts.map +1 -0
- package/lib/_modules/usage-route/usage.service.js +110 -0
- package/lib/_services/dynamobe-api.service.d.ts +9 -0
- package/lib/_services/dynamobe-api.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-api.service.js +130 -0
- package/lib/_services/dynamobe-app.d.ts +11 -0
- package/lib/_services/dynamobe-app.d.ts.map +1 -0
- package/lib/_services/dynamobe-app.js +38 -0
- package/lib/_services/dynamobe-auth.service.d.ts +25 -0
- package/lib/_services/dynamobe-auth.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-auth.service.js +24 -0
- package/lib/_services/dynamobe-controller.service.d.ts +10 -0
- package/lib/_services/dynamobe-controller.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-controller.service.js +11 -0
- package/lib/_services/dynamobe-data.service.d.ts +51 -0
- package/lib/_services/dynamobe-data.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-data.service.js +224 -0
- package/lib/_services/dynamobe-db-service-collection.service.d.ts +5 -0
- package/lib/_services/dynamobe-db-service-collection.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-db-service-collection.service.js +7 -0
- package/lib/_services/dynamobe-db.service.d.ts +150 -0
- package/lib/_services/dynamobe-db.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-db.service.js +577 -0
- package/lib/_services/dynamobe-email-service-collection.service.d.ts +5 -0
- package/lib/_services/dynamobe-email-service-collection.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-email-service-collection.service.js +7 -0
- package/lib/_services/dynamobe-email.service.d.ts +32 -0
- package/lib/_services/dynamobe-email.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-email.service.js +144 -0
- package/lib/_services/dynamobe-global.service.d.ts +22 -0
- package/lib/_services/dynamobe-global.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-global.service.js +84 -0
- package/lib/_services/dynamobe-routing-module.service.d.ts +25 -0
- package/lib/_services/dynamobe-routing-module.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-routing-module.service.js +112 -0
- package/lib/_services/dynamobe-server.d.ts +31 -0
- package/lib/_services/dynamobe-server.d.ts.map +1 -0
- package/lib/_services/dynamobe-server.js +179 -0
- package/lib/_services/dynamobe-shared.service.d.ts +100 -0
- package/lib/_services/dynamobe-shared.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-shared.service.js +294 -0
- package/lib/_services/dynamobe-singleton.service.d.ts +5 -0
- package/lib/_services/dynamobe-singleton.service.d.ts.map +1 -0
- package/lib/_services/dynamobe-singleton.service.js +15 -0
- package/lib/index-newo.d.ts +0 -0
- package/lib/index-newo.d.ts.map +1 -0
- package/lib/index-newo.js +71 -0
- package/lib/index-old.d.ts +39 -0
- package/lib/index-old.js +49 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +49 -0
- package/lib/tsconfig.tsbuildinfo +2080 -0
- package/nodemon.json +6 -0
- package/package.json +52 -0
- package/src/_constants/dynamobe-global.settings.ts +11 -0
- package/src/_enum/data-model-types.enum.ts +6 -0
- package/src/_enum/dynamobe-data-service-function.enum.ts +11 -0
- package/src/_enum/dynamobe-route-security.enum.ts +6 -0
- package/src/_enum/http/http-call-type.enum.ts +8 -0
- package/src/_enum/http/http-response-type.enum.ts +7 -0
- package/src/_enum/log-style.enum.ts +30 -0
- package/src/_enum/predefined-data-types.enum.ts +8 -0
- package/src/_models/dynamobe-api-call-params.ts +62 -0
- package/src/_models/dynamobe-app-params.ts +24 -0
- package/src/_models/dynamobe-data-model-params.ts +23 -0
- package/src/_models/dynamobe-endpoint-control.ts +127 -0
- package/src/_models/dynamobe-global-settings.ts +9 -0
- package/src/_models/fullstack-models/control-models/daily-usage-data.ts +34 -0
- package/src/_models/fullstack-models/control-models/dynamobe-data-property-params.ts +98 -0
- package/src/_models/fullstack-models/control-models/dynamobe-error.ts +207 -0
- package/src/_models/fullstack-models/control-models/geo-ip-location.ts +26 -0
- package/src/_models/fullstack-models/control-models/usage-action.ts +18 -0
- package/src/_models/fullstack-models/control-models/usage-data.ts +26 -0
- package/src/_models/fullstack-models/data-models/custom-data.ts +37 -0
- package/src/_models/fullstack-models/data-models/metadata.ts +28 -0
- package/src/_models/fullstack-models/data-models/usage-session.ts +82 -0
- package/src/_modules/test-route/custom-data.service.ts +21 -0
- package/src/_modules/test-route/test-controller.ts +136 -0
- package/src/_modules/usage-route/usage-controller.ts +114 -0
- package/src/_modules/usage-route/usage.service.ts +125 -0
- package/src/_services/dynamobe-api.service.ts +135 -0
- package/src/_services/dynamobe-app.ts +49 -0
- package/src/_services/dynamobe-auth.service.ts +42 -0
- package/src/_services/dynamobe-controller.service.ts +20 -0
- package/src/_services/dynamobe-data.service.ts +215 -0
- package/src/_services/dynamobe-db-service-collection.service.ts +9 -0
- package/src/_services/dynamobe-db.service.ts +556 -0
- package/src/_services/dynamobe-email-service-collection.service.ts +9 -0
- package/src/_services/dynamobe-email.service.ts +169 -0
- package/src/_services/dynamobe-global.service.ts +99 -0
- package/src/_services/dynamobe-routing-module.service.ts +141 -0
- package/src/_services/dynamobe-server.ts +225 -0
- package/src/_services/dynamobe-shared.service.ts +320 -0
- package/src/_services/dynamobe-singleton.service.ts +16 -0
- package/src/index-newo.ts +71 -0
- package/src/index.ts +50 -0
- package/src/version.json +2 -0
- package/tsconfig.app.json +12 -0
- package/tsconfig.json +72 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import * as GeoIp from 'geoip-lite';
|
|
3
|
+
import { GeoIpLocation } from '../_models/fullstack-models/control-models/geo-ip-location';
|
|
4
|
+
import { LogStyle } from '../_enum/log-style.enum';
|
|
5
|
+
import { DynamoBEError } from '../_models/fullstack-models/control-models/dynamobe-error';
|
|
6
|
+
|
|
7
|
+
export const second = 1000;
|
|
8
|
+
export const minute = second * 60;
|
|
9
|
+
export const hour = minute * 60;
|
|
10
|
+
export const day = hour * 24;
|
|
11
|
+
export const week = day * 7;
|
|
12
|
+
export const month = day * 30.4368499;
|
|
13
|
+
export const year = day * 365.242199;
|
|
14
|
+
|
|
15
|
+
export class DBE_Shared {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* returns remapped object list by path list
|
|
19
|
+
* @param objList object list to map
|
|
20
|
+
* @param paths string list of path etc.:
|
|
21
|
+
* [ [ 'first', 'sub', 'label' ], [ 'first', 'dif', 'name' ]] will be...
|
|
22
|
+
* from
|
|
23
|
+
* {
|
|
24
|
+
* first: {
|
|
25
|
+
* sub: {
|
|
26
|
+
* label: 'vlmi'
|
|
27
|
+
* },
|
|
28
|
+
* dif: {
|
|
29
|
+
* name: 'asd'
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* }[]
|
|
33
|
+
* to
|
|
34
|
+
* { label: 'vlmi', name: 'asd' }[]
|
|
35
|
+
* @returns remapped object list (the final obj will use the deepest keys)
|
|
36
|
+
*/
|
|
37
|
+
static mapObjList(objList: object[], paths: string[][]): object[] {
|
|
38
|
+
let newObjList = [...objList];
|
|
39
|
+
newObjList = newObjList.map(obj => {
|
|
40
|
+
const newObj = {};
|
|
41
|
+
paths.forEach((path: string[]) => {
|
|
42
|
+
newObj[path[path.length - 1]] = this.getNestedData(obj, path);
|
|
43
|
+
});
|
|
44
|
+
return newObj;
|
|
45
|
+
});
|
|
46
|
+
return newObjList;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* returns nested value from object
|
|
51
|
+
* @param parentObj data source object
|
|
52
|
+
* @param nestedDataKeys path of value as string list
|
|
53
|
+
* etc.: ['nestLvl1', 'nestLvl2', 'nestLvl3'] as parentObj.nestLvl1.nestLvl2.nestLvl3
|
|
54
|
+
* @returns data from object by path
|
|
55
|
+
*/
|
|
56
|
+
static getNestedData(parentObj: object, nestedDataKeys: string[]): any {
|
|
57
|
+
let newData = {...parentObj};
|
|
58
|
+
nestedDataKeys.forEach((dk: string) => {
|
|
59
|
+
if (newData) {
|
|
60
|
+
newData = newData[dk];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return newData;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* recursive function that nests data
|
|
68
|
+
* @param newData the object that that is needed to be updated
|
|
69
|
+
* @param nestKeys the path where the data should be updated
|
|
70
|
+
* @param dataToSet the actual value that will be setted
|
|
71
|
+
* @returns modified data
|
|
72
|
+
*/
|
|
73
|
+
static nestData(parentObj: object, nestKeys: string[], dataToSet: any): object {
|
|
74
|
+
const newData = {...parentObj};
|
|
75
|
+
if (nestKeys.length > 1) {
|
|
76
|
+
const keys = [...nestKeys];
|
|
77
|
+
const nextNestKey = keys.shift();
|
|
78
|
+
newData[nextNestKey] = this.nestData(newData[nextNestKey], keys, dataToSet);
|
|
79
|
+
} else {
|
|
80
|
+
newData[nestKeys[0]] = dataToSet;
|
|
81
|
+
}
|
|
82
|
+
return newData;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* recursive function that adds to nested data
|
|
87
|
+
* @param newData the object that that is needed to be updated
|
|
88
|
+
* @param nestKeys the path where the data should be updated
|
|
89
|
+
* @param dataToAdd the actual value that will be setted
|
|
90
|
+
* @returns modified data
|
|
91
|
+
*/
|
|
92
|
+
static addToNestedData(parentObj: object, nestKeys: string[], dataToAdd: any): object {
|
|
93
|
+
const newData = {...parentObj};
|
|
94
|
+
if (nestKeys.length > 1) {
|
|
95
|
+
const keys = [...nestKeys];
|
|
96
|
+
const nextNestKey = keys.shift();
|
|
97
|
+
newData[nextNestKey] = this.addToNestedData(newData[nextNestKey], keys, dataToAdd);
|
|
98
|
+
} else {
|
|
99
|
+
newData[nestKeys[0]] += dataToAdd;
|
|
100
|
+
}
|
|
101
|
+
return newData;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* recursive function that pushes to nested data
|
|
106
|
+
* @param newData the object that that is needed to be updated
|
|
107
|
+
* @param nestKeys the path where the data should be updated
|
|
108
|
+
* @param dataToPush the actual value that will be setted
|
|
109
|
+
* @returns modified data
|
|
110
|
+
*/
|
|
111
|
+
static pushToNestedData(parentObj: object, nestKeys: string[], dataToPush: any): object {
|
|
112
|
+
const newData = {...parentObj};
|
|
113
|
+
if (nestKeys.length > 1) {
|
|
114
|
+
const keys = [...nestKeys];
|
|
115
|
+
const nextNestKey = keys.shift();
|
|
116
|
+
newData[nextNestKey] = this.pushToNestedData(newData[nextNestKey], keys, dataToPush);
|
|
117
|
+
} else {
|
|
118
|
+
if (Array.isArray(newData[nestKeys[0]])) {
|
|
119
|
+
newData[nestKeys[0]].push(dataToPush);
|
|
120
|
+
} else {
|
|
121
|
+
newData[nestKeys[0]] = [dataToPush];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return newData;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* recursive function that nests data on recursive data structure etc.: xData: { ..., 'nestedListKey': xData[] }
|
|
129
|
+
* @param newData the object that that is needed to be updated
|
|
130
|
+
* @param nestedListKey the location of nested dataList
|
|
131
|
+
* @param nestIndexes path to the subject ect.: xData.listKey[1].listKey[4].listKey[0] will be [1, 4, 0]
|
|
132
|
+
* @param dataToSet the actual value that will be setted on location
|
|
133
|
+
* @returns modified data
|
|
134
|
+
*/
|
|
135
|
+
static nestRecursiveListedData<T>(parentObj: T, nestedListKey: string, nestIndexes: number[], dataToSet: any): T {
|
|
136
|
+
const newData = {...parentObj};
|
|
137
|
+
if (nestIndexes.length > 1) {
|
|
138
|
+
const indexes = [...nestIndexes];
|
|
139
|
+
const nextLevelKey = indexes.shift();
|
|
140
|
+
newData[nestedListKey][nextLevelKey] = this.nestRecursiveListedData(
|
|
141
|
+
newData[nestedListKey][nextLevelKey], nestedListKey, indexes, dataToSet);
|
|
142
|
+
} else {
|
|
143
|
+
newData[nestedListKey][nestIndexes[0]] = dataToSet;
|
|
144
|
+
}
|
|
145
|
+
return newData;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static getAge(birthDate: Date | number | string) {
|
|
149
|
+
return this.getYear(+new Date() - +new Date(birthDate));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
static getYear(date: Date | number | string) {
|
|
153
|
+
if (typeof date === 'string') {
|
|
154
|
+
date = new Date(date);
|
|
155
|
+
}
|
|
156
|
+
return (+date / year);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static getHour(date: Date | number | string) {
|
|
160
|
+
if (typeof date === 'string') {
|
|
161
|
+
date = new Date(date);
|
|
162
|
+
}
|
|
163
|
+
return (+date / hour);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static getDateByAge(age: number) {
|
|
167
|
+
return new Date(+new Date() - (year * age));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static getDistanceInKilometres(
|
|
171
|
+
from: LocationCoordinates,
|
|
172
|
+
to: LocationCoordinates
|
|
173
|
+
): number {
|
|
174
|
+
|
|
175
|
+
const R = 6371; // kilometres
|
|
176
|
+
const φ1 = this.toRadians(from.latitude);
|
|
177
|
+
const φ2 = this.toRadians(to.latitude);
|
|
178
|
+
const Δφ = this.toRadians(to.latitude - from.latitude);
|
|
179
|
+
const Δλ = this.toRadians(to.longitude - from.longitude);
|
|
180
|
+
|
|
181
|
+
const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
|
|
182
|
+
Math.cos(φ1) * Math.cos(φ2) *
|
|
183
|
+
Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
|
|
184
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
185
|
+
|
|
186
|
+
return R * c;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static getLocationDegByKilometers(latiOrLong: 'latitude' | 'longitude', distanceInKm: number, latitude?: number): number {
|
|
190
|
+
if (latiOrLong === 'latitude') {
|
|
191
|
+
return distanceInKm / 110.574;
|
|
192
|
+
} else {
|
|
193
|
+
if (latitude) {
|
|
194
|
+
return distanceInKm / (Math.cos(this.toRadians(latitude)) * 111.320);
|
|
195
|
+
} else {
|
|
196
|
+
throw new DynamoBEError({ status: 417, message: 'When using getLocationDegByKilometers for longitude, you need to give latitude!' });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static toRadians(deg: number): number {
|
|
202
|
+
return deg * (Math.PI / 180);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static addMetadataToSchema(schema: any): any {
|
|
206
|
+
schema.__created = { type: Date };
|
|
207
|
+
schema.__createdBy = { type: String };
|
|
208
|
+
schema.__lastModified = { type: Date };
|
|
209
|
+
schema.__lastModifiedBy = { type: String };
|
|
210
|
+
return schema;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static oneHourAgo(): Date {
|
|
214
|
+
return new Date(+new Date() - hour);
|
|
215
|
+
}
|
|
216
|
+
static oneDayAgo(): Date {
|
|
217
|
+
return new Date(+new Date() - day);
|
|
218
|
+
}
|
|
219
|
+
static oneWeekAgo(): Date {
|
|
220
|
+
return new Date(+new Date() - week);
|
|
221
|
+
}
|
|
222
|
+
static oneMonthAgo(): Date {
|
|
223
|
+
return new Date(+new Date() - month);
|
|
224
|
+
}
|
|
225
|
+
static oneYearAgo(): Date {
|
|
226
|
+
return new Date(+new Date() - year);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
static getIpFromRequest(request: Request): string {
|
|
230
|
+
/* console.log('TESTTTT route:\n',
|
|
231
|
+
`\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n
|
|
232
|
+
HEADERS\n`, request.headers,
|
|
233
|
+
`\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n
|
|
234
|
+
ELSE\n`,
|
|
235
|
+
`\nremote `, request.socket.remoteAddress,
|
|
236
|
+
`\nlocal `, request.socket.localAddress,
|
|
237
|
+
); */
|
|
238
|
+
|
|
239
|
+
let ip: string;
|
|
240
|
+
if (request.headers['x-forwarded-for']) {
|
|
241
|
+
const route: string[] = (request.headers['x-forwarded-for'] as string).split(', ');
|
|
242
|
+
console.log('TESTTTT route:', route);
|
|
243
|
+
ip = route[route.length - 1];
|
|
244
|
+
} else {
|
|
245
|
+
ip = request.socket.remoteAddress;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* console.log(`ip from request: ${ip}`); */
|
|
249
|
+
return ip;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static getLocationDataByRequest(request: Request): GeoIpLocation {
|
|
253
|
+
return GeoIp.lookup(this.getIpFromRequest(request));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
static setLogStyle(styles: LogStyle[]): void {
|
|
257
|
+
let styleSets = '';
|
|
258
|
+
styles.forEach((style: LogStyle) => {
|
|
259
|
+
styleSets += style;
|
|
260
|
+
});
|
|
261
|
+
console.log(styleSets);
|
|
262
|
+
}
|
|
263
|
+
static resetLogStyle(): void {
|
|
264
|
+
console.log(LogStyle.reset);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
static logStyle(input: string, styles: LogStyle[], dontReset?: boolean): string {
|
|
268
|
+
let result = '';
|
|
269
|
+
styles.forEach((style: LogStyle) => {
|
|
270
|
+
result += style;
|
|
271
|
+
});
|
|
272
|
+
result += input;
|
|
273
|
+
if (!dontReset) {
|
|
274
|
+
result += LogStyle.reset;
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
static logSuccess(message: string, ...optionalParams: any[]): void {
|
|
280
|
+
if (0 < optionalParams.length) {
|
|
281
|
+
console.error(`${LogStyle.green}${LogStyle.bright}${message}`, ...optionalParams, LogStyle.reset);
|
|
282
|
+
} else {
|
|
283
|
+
console.error(`${LogStyle.green}${LogStyle.bright}${message}${LogStyle.reset}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
static logError(message: string, ...optionalParams: any[]): void {
|
|
288
|
+
if (0 < optionalParams.length) {
|
|
289
|
+
console.error(`${LogStyle.red}${LogStyle.bright}${message}`, ...optionalParams, LogStyle.reset);
|
|
290
|
+
} else {
|
|
291
|
+
console.error(`${LogStyle.red}${LogStyle.bright}${message}${LogStyle.reset}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
static logWarning(message: string, ...optionalParams: any[]): void {
|
|
296
|
+
if (0 < optionalParams.length) {
|
|
297
|
+
console.warn(`${LogStyle.yellow}${LogStyle.bright}${message}`, ...optionalParams, LogStyle.reset);
|
|
298
|
+
} else {
|
|
299
|
+
console.warn(`${LogStyle.yellow}${LogStyle.bright}${message}${LogStyle.reset}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface LocationCoordinates {
|
|
305
|
+
longitude: number;
|
|
306
|
+
latitude: number;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export const dynamoTitleLog =
|
|
310
|
+
`\x1b[32m \x1b[1m
|
|
311
|
+
|
|
312
|
+
||||||VVV VVV /// |||V ||| //VV |||V /||| /|||||V
|
|
313
|
+
||| VVV VVV /// |||VV ||| ///VVV |||VV //||| /// VVV
|
|
314
|
+
||| ||| VVV /// |||VVV ||| /// VVV |||VVV///||| ||| |||
|
|
315
|
+
||| ||| V|||/ ||| VVV ||| ||| ||| ||| VV// ||| ||| |||
|
|
316
|
+
||| ||| ||| ||| VVV||| |||||||||| ||| ||| ||| |||
|
|
317
|
+
||| /// ||| ||| VV||| ||| ||| ||| ||| VVV ///
|
|
318
|
+
||||||/// ||| ||| V||| ||| ||| ||| ||| V|||||/
|
|
319
|
+
|
|
320
|
+
By Future Development Program Kft.\x1b[0m`.replace(/V/g, '\\');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
export class DynamoBESingletonService {
|
|
3
|
+
/// --- --- --- SINGLETON --- --- --- \\\
|
|
4
|
+
protected static instance;
|
|
5
|
+
|
|
6
|
+
static getSingletonInstance() {
|
|
7
|
+
if (!this.instance) {
|
|
8
|
+
this.instance = new this();
|
|
9
|
+
}
|
|
10
|
+
return this.instance;
|
|
11
|
+
}
|
|
12
|
+
/// --- --- --- SINGLETON --- --- --- ///
|
|
13
|
+
|
|
14
|
+
// SINGLETON services are using private constructor
|
|
15
|
+
protected constructor() {}
|
|
16
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
// ENUMS
|
|
3
|
+
import { DataModelType } from './_enum/data-model-types.enum';
|
|
4
|
+
import { DynamoBEDSF } from './_enum/dynamobe-data-service-function.enum';
|
|
5
|
+
import { DynamoBERouteSecurity } from './_enum/dynamobe-route-security.enum';
|
|
6
|
+
import { LogStyle } from './_enum/log-style.enum';
|
|
7
|
+
import { PredefinedDataTypes } from './_enum/predefined-data-types.enum';
|
|
8
|
+
// HTTP ENUMS
|
|
9
|
+
import { HttpCallType } from './_enum/http/http-call-type.enum';
|
|
10
|
+
import { HttpResponseType } from './_enum/http/http-response-type.enum';
|
|
11
|
+
|
|
12
|
+
// MODELS
|
|
13
|
+
import { DynamoBEApiCallParams } from './_models/dynamobe-api-call-params';
|
|
14
|
+
import { DynamoBEAppParams } from './_models/dynamobe-app-params';
|
|
15
|
+
import { DynamoBEDataModelParams } from './_models/dynamobe-data-model-params';
|
|
16
|
+
import { DynamoBEEndpointParams } from './_models/dynamobe-endpoint-control';
|
|
17
|
+
import { DynamoBEGlobalSettings } from './_models/dynamobe-global-settings';
|
|
18
|
+
// FULLSTACK - CONTROL MODELS
|
|
19
|
+
import { DailyUsageData } from './_models/fullstack-models/control-models/daily-usage-data';
|
|
20
|
+
import { DynamoBEDataPropertyParams } from './_models/fullstack-models/control-models/dynamobe-data-property-params';
|
|
21
|
+
import { DynamoBEError } from './_models/fullstack-models/control-models/dynamobe-error';
|
|
22
|
+
import { GeoIpLocation } from './_models/fullstack-models/control-models/geo-ip-location';
|
|
23
|
+
import { DynamoUsageAction } from './_models/fullstack-models/control-models/usage-action';
|
|
24
|
+
import { DynamoUsageData } from './_models/fullstack-models/control-models/usage-data';
|
|
25
|
+
// FULLSTACK - DATA MODELS
|
|
26
|
+
import { Metadata } from './_models/fullstack-models/data-models/metadata';
|
|
27
|
+
import { CustomData, customDataModelParams } from './_models/fullstack-models/data-models/custom-data';
|
|
28
|
+
import { DynamoUsageSession, usageSessionModelParams } from './_models/fullstack-models/data-models/usage-session';
|
|
29
|
+
|
|
30
|
+
// MODULES
|
|
31
|
+
import { TestController } from './_modules/test-route/test-controller';
|
|
32
|
+
import { CustomDataService } from './_modules/test-route/custom-data.service';
|
|
33
|
+
import { UsageController } from './_modules/usage-route/usage-controller';
|
|
34
|
+
import { UsageService } from './_modules/usage-route/usage.service';
|
|
35
|
+
|
|
36
|
+
// SERVICES
|
|
37
|
+
import { DynamoBEApiService } from './_services/dynamobe-api.service';
|
|
38
|
+
import { DynamoBEApp } from './_services/dynamobe-app';
|
|
39
|
+
import { DynamoBEAuthService } from './_services/dynamobe-auth.service';
|
|
40
|
+
import { DynamoBEController } from './_services/dynamobe-controller.service';
|
|
41
|
+
import { DynamoBEDataService } from './_services/dynamobe-data.service';
|
|
42
|
+
import { DynamoBEDBServiceCollection } from './_services/dynamobe-db-service-collection.service';
|
|
43
|
+
import { DynamoBEDBService } from './_services/dynamobe-db.service';
|
|
44
|
+
import { DynamoBEEmailServiceCollection } from './_services/dynamobe-email-service-collection.service';
|
|
45
|
+
import { DynamoBEEmailService } from './_services/dynamobe-email.service';
|
|
46
|
+
import { DBE_Global_S } from './_services/dynamobe-global.service';
|
|
47
|
+
import { DynamoBERountingModule } from './_services/dynamobe-routing-module.service';
|
|
48
|
+
import { DynamoBEServer } from './_services/dynamobe-server';
|
|
49
|
+
import { DBE_Shared } from './_services/dynamobe-shared.service';
|
|
50
|
+
import { DynamoBESingletonService } from './_services/dynamobe-singleton.service';
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
// ENUMS
|
|
54
|
+
DataModelType, DynamoBEDSF, DynamoBERouteSecurity, LogStyle, PredefinedDataTypes,
|
|
55
|
+
HttpCallType, HttpResponseType,
|
|
56
|
+
|
|
57
|
+
// MODELS
|
|
58
|
+
DynamoBEApiCallParams, DynamoBEAppParams, DynamoBEDataModelParams, DynamoBEEndpointParams, DynamoBEGlobalSettings,
|
|
59
|
+
DailyUsageData, DynamoBEDataPropertyParams, DynamoBEError, GeoIpLocation, DynamoUsageAction, DynamoUsageData,
|
|
60
|
+
Metadata, CustomData, customDataModelParams, DynamoUsageSession, usageSessionModelParams,
|
|
61
|
+
|
|
62
|
+
// MODULES
|
|
63
|
+
TestController, CustomDataService, UsageController, UsageService,
|
|
64
|
+
|
|
65
|
+
// SERVICES
|
|
66
|
+
DynamoBEApiService, DynamoBEApp, DynamoBEAuthService, DynamoBEController, DynamoBEDataService, DynamoBEDBServiceCollection,
|
|
67
|
+
DynamoBEDBService, DynamoBEEmailServiceCollection, DynamoBEEmailService, DBE_Global_S, DynamoBERountingModule, DynamoBEServer,
|
|
68
|
+
DBE_Shared, DynamoBESingletonService
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
*/
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
// ENUMS
|
|
3
|
+
export * from './_enum/data-model-types.enum';
|
|
4
|
+
export * from './_enum/dynamobe-data-service-function.enum';
|
|
5
|
+
export * from './_enum/dynamobe-route-security.enum';
|
|
6
|
+
export * from './_enum/log-style.enum';
|
|
7
|
+
export * from './_enum/predefined-data-types.enum';
|
|
8
|
+
// HTTP ENUMS
|
|
9
|
+
export * from './_enum/http/http-call-type.enum';
|
|
10
|
+
export * from './_enum/http/http-response-type.enum';
|
|
11
|
+
|
|
12
|
+
// MODULES
|
|
13
|
+
export * from './_models/dynamobe-api-call-params';
|
|
14
|
+
export * from './_models/dynamobe-app-params';
|
|
15
|
+
export * from './_models/dynamobe-data-model-params';
|
|
16
|
+
export * from './_models/dynamobe-endpoint-control';
|
|
17
|
+
export * from './_models/dynamobe-global-settings';
|
|
18
|
+
// FULLSTACK - CONTROL MODELS
|
|
19
|
+
export * from './_models/fullstack-models/control-models/daily-usage-data';
|
|
20
|
+
export * from './_models/fullstack-models/control-models/dynamobe-data-property-params';
|
|
21
|
+
export * from './_models/fullstack-models/control-models/dynamobe-error';
|
|
22
|
+
export * from './_models/fullstack-models/control-models/geo-ip-location';
|
|
23
|
+
export * from './_models/fullstack-models/control-models/usage-action';
|
|
24
|
+
export * from './_models/fullstack-models/control-models/usage-data';
|
|
25
|
+
// FULLSTACK - DATA MODELS
|
|
26
|
+
export * from './_models/fullstack-models/data-models/custom-data';
|
|
27
|
+
export * from './_models/fullstack-models/data-models/metadata';
|
|
28
|
+
export * from './_models/fullstack-models/data-models/usage-session';
|
|
29
|
+
|
|
30
|
+
// MODULES
|
|
31
|
+
export * from './_modules/test-route/test-controller';
|
|
32
|
+
export * from './_modules/test-route/custom-data.service';
|
|
33
|
+
export * from './_modules/usage-route/usage-controller';
|
|
34
|
+
export * from './_modules/usage-route/usage.service';
|
|
35
|
+
|
|
36
|
+
// SERVICES
|
|
37
|
+
export * from './_services/dynamobe-api.service';
|
|
38
|
+
export * from './_services/dynamobe-app';
|
|
39
|
+
export * from './_services/dynamobe-auth.service';
|
|
40
|
+
export * from './_services/dynamobe-controller.service';
|
|
41
|
+
export * from './_services/dynamobe-data.service';
|
|
42
|
+
export * from './_services/dynamobe-db-service-collection.service';
|
|
43
|
+
export * from './_services/dynamobe-db.service';
|
|
44
|
+
export * from './_services/dynamobe-email-service-collection.service';
|
|
45
|
+
export * from './_services/dynamobe-email.service';
|
|
46
|
+
export * from './_services/dynamobe-global.service';
|
|
47
|
+
export * from './_services/dynamobe-routing-module.service';
|
|
48
|
+
export * from './_services/dynamobe-server';
|
|
49
|
+
export * from './_services/dynamobe-shared.service';
|
|
50
|
+
export * from './_services/dynamobe-singleton.service';
|
package/src/version.json
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Basic Options */
|
|
4
|
+
"incremental": true, /* Enable incremental compilation */
|
|
5
|
+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
|
|
6
|
+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
7
|
+
//"lib": ["es6"], /* Specify library files to be included in the compilation. */
|
|
8
|
+
//"allowJs": true, /* Allow javascript files to be compiled. */
|
|
9
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
10
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
11
|
+
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
12
|
+
//"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
13
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
14
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
15
|
+
"outDir": "lib", /* Redirect output structure to the directory. */
|
|
16
|
+
//"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
17
|
+
// "composite": true, /* Enable project compilation */
|
|
18
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
19
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
20
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
21
|
+
"importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
22
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
23
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
24
|
+
|
|
25
|
+
/* Strict Type-Checking Options */
|
|
26
|
+
// "strict": false, /* Enable all strict type-checking options. */
|
|
27
|
+
// "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
28
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
29
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
30
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
31
|
+
// "strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
|
|
32
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
33
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
34
|
+
|
|
35
|
+
/* Additional Checks */
|
|
36
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
37
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
38
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
39
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
40
|
+
|
|
41
|
+
/* Module Resolution Options */
|
|
42
|
+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
43
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
44
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
45
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
46
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
47
|
+
//"types": [ "./build/src/index.d.ts" ], /* Type declaration files to be included in compilation. */
|
|
48
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
49
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
50
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
51
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
52
|
+
|
|
53
|
+
/* Source Map Options */
|
|
54
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
55
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
56
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
57
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
58
|
+
|
|
59
|
+
/* Experimental Options */
|
|
60
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
61
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
62
|
+
|
|
63
|
+
"skipLibCheck": true,
|
|
64
|
+
"forceConsistentCasingInFileNames": true,
|
|
65
|
+
|
|
66
|
+
/* Advanced Options */
|
|
67
|
+
"resolveJsonModule": true /* Include modules imported with '.json' extension */
|
|
68
|
+
},
|
|
69
|
+
"include": [
|
|
70
|
+
"src"
|
|
71
|
+
]
|
|
72
|
+
}
|