@sdflc/backend-helpers 1.0.24 → 1.0.27

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 (40) hide show
  1. package/README.md +175 -0
  2. package/build/{baseController.d.ts → BaseController.d.ts} +0 -0
  3. package/build/{baseController.js → BaseController.js} +0 -0
  4. package/build/{baseCore.d.ts → BaseCore.d.ts} +13 -20
  5. package/build/{baseCore.js → BaseCore.js} +116 -152
  6. package/build/{baseGateway.d.ts → BaseGateway.d.ts} +15 -11
  7. package/build/{baseGateway.js → BaseGateway.js} +138 -97
  8. package/build/{dataCache.d.ts → DataCache.d.ts} +0 -0
  9. package/build/{dataCache.js → DataCache.js} +2 -2
  10. package/build/{database.d.ts → Database.d.ts} +0 -0
  11. package/build/{database.js → Database.js} +0 -0
  12. package/build/{dbMigratorAndSeeder.d.ts → DbMigratorAndSeeder.d.ts} +0 -0
  13. package/build/{dbMigratorAndSeeder.js → DbMigratorAndSeeder.js} +5 -1
  14. package/build/apiContext.d.ts +3 -3
  15. package/build/apiContext.js +89 -32
  16. package/build/constants.d.ts +4 -5
  17. package/build/constants.js +23 -4
  18. package/build/dbSeeder.js +5 -1
  19. package/build/dbTableHelpers.d.ts +2 -0
  20. package/build/dbTableHelpers.js +48 -27
  21. package/build/index.d.ts +9 -11
  22. package/build/index.js +19 -20
  23. package/build/interfaces/ApiContext.d.ts +23 -0
  24. package/build/interfaces/{BaseCoreInterface.js → ApiContext.js} +0 -0
  25. package/build/interfaces/ApiContextInterface.d.ts +5 -1
  26. package/build/interfaces/BaseCorePropsInterface.d.ts +31 -0
  27. package/build/interfaces/{BaseGatewayInterface.js → BaseCorePropsInterface.js} +0 -0
  28. package/build/interfaces/BaseGatewayPropsInterface.d.ts +28 -0
  29. package/build/interfaces/BaseGatewayPropsInterface.js +2 -0
  30. package/build/interfaces/CacheInterface.d.ts +3 -3
  31. package/build/interfaces/JwtTokenSecretAndSettings.d.ts +5 -0
  32. package/build/interfaces/JwtTokenSecretAndSettings.js +2 -0
  33. package/build/interfaces/index.d.ts +4 -2
  34. package/build/resolversHelpers.js +11 -10
  35. package/build/userToken.js +3 -3
  36. package/package.json +68 -68
  37. package/build/baseGatewayHelpers.d.ts +0 -20
  38. package/build/baseGatewayHelpers.js +0 -87
  39. package/build/interfaces/BaseCoreInterface.d.ts +0 -43
  40. package/build/interfaces/BaseGatewayInterface.d.ts +0 -26
package/README.md CHANGED
@@ -1,3 +1,178 @@
1
1
  # Backend Helpers
2
2
 
3
3
  This library has a variety of classes and functions to simplify building backend applications with the specific architecture within `@sdflc` ecosystem.
4
+
5
+ ## Classes
6
+
7
+ ### BaseCore
8
+
9
+ This is the class that should be extended when you create a new core class. This is where all the business logic should be happeninng when processing request.
10
+
11
+ #### Constructor
12
+
13
+ Here are the props to be passed to the BaseCore constructor:
14
+
15
+ - db: Database - an object of Database class
16
+ - context?: any - the request context where you can add all you need, optional
17
+ - gateway?: any - main gateway class object that will be working with DB or 3rd part API
18
+ - gateways?: any - an object
19
+ - isProduction: boolean - true when the app is in production
20
+ - logLevel: LoggerLevels - log leves: 0 - none, 1 - errors, 2 - warnings, 3 - messages, 4 - all
21
+ - logger?: Logger - object of Logger class to be used as logger
22
+ - name?: string - name of the core
23
+ - requestId: string - Unique ID of a request processed, can be used for troubleshooting
24
+ - doAuth: boolean - call authorize method or not an incoming request
25
+ - doingWhat?: BaseCoreDoingWhatInterface - an object with text descriptions of each action, used to generate generic error message sent to user on an exception
26
+ - validators?: BaseCoreValidatorsInterface - an object with validator functions to be used to validate incoming data
27
+ - gwSpace?: BaseGateway - gateway to find a space, i.e. configration of the app. Each app can have several configurations to be used as one instance for different applications
28
+ - interserviceApiKey?: string - API key to be used to authenticate incoming request from another microservice, optional
29
+ - jwtSecret?: string - secret to be used to validate Authorize Bearer token on incoming request, optional
30
+ - verifytokenArgs?: VerifyUserTokenArgs - optional parameters for JWT token validation, like algorithm, etc
31
+
32
+ #### getDb()
33
+
34
+ #### getRequestId()
35
+
36
+ #### getContext(key?: string)
37
+
38
+ #### getGateways()
39
+
40
+ #### success(data: any, code?: number): any
41
+
42
+ #### failure(code: number, errorMsg: string, data?: any)
43
+
44
+ #### validationFailure(ex: any): any
45
+
46
+ #### exceptionFailure(ex: any, doingWhat: string | any, data?: any)
47
+
48
+ #### checkResult(args: any)
49
+
50
+ #### runAction(opt: CoreActionInterface)
51
+
52
+ #### Default Actions
53
+
54
+ ##### list(args: any)
55
+
56
+ ##### get(args: any)
57
+
58
+ ##### getMany(args: any)
59
+
60
+ ##### create(args: any)
61
+
62
+ ##### createMany(args: any)
63
+
64
+ ##### update(args: any)
65
+
66
+ ##### updateMany(args: any)
67
+
68
+ ##### set(args: any)
69
+
70
+ ##### remove(args: any)
71
+
72
+ ##### removeMany(args: any)
73
+
74
+ #### Default Action related events
75
+
76
+ ##### beforeList(params: any, opt?: BaseCoreActionsInterface): Promise<any>
77
+
78
+ ##### afterList(params: any, opt?: BaseCoreActionsInterface): Promise<any>
79
+
80
+ ##### beforeCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>
81
+
82
+ ##### afterCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>
83
+
84
+ ##### beforeCreateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>
85
+
86
+ ##### afterCreateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>
87
+
88
+ ##### beforeUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>
89
+
90
+ ##### afterUpdate(params: any, opt?: BaseCoreActionsInterface): Promise<any>
91
+
92
+ ##### beforeUpdateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>
93
+
94
+ #### afterUpdateMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>
95
+
96
+ ##### beforeSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>
97
+
98
+ ##### afterSet(params: any, opt?: BaseCoreActionsInterface): Promise<any>
99
+
100
+ ##### beforeRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>
101
+
102
+ ##### afterRemove(params: any, opt?: BaseCoreActionsInterface): Promise<any>
103
+
104
+ ##### beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>
105
+
106
+ ##### afterRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>
107
+
108
+ ##### onException(params: any, opt?: BaseCoreActionsInterface): Promise<any>
109
+
110
+ #### Authorization
111
+
112
+ #### authenticate(params: any, opt?: BaseCoreActionsInterface)
113
+
114
+ ### BaseGateway
115
+
116
+ This is the class that should be extended when you create a new gateway class. This is where your code works with database or 3rd party API or do some works of the lowest level. Gateways are used by the core classes to actually do the job to implement one or another business logic.
117
+
118
+ #### constructor(props: BaseGatewayInterface)
119
+
120
+ #### generateId(args?: any)
121
+
122
+ #### onListFilter(query: any, filterParams: any)
123
+
124
+ #### onUpdateFilter(query: any, filterParams: any)
125
+
126
+ #### onRemoveFilter(query: any, filterParams: any)
127
+
128
+ #### transformOnCreate(args: any)
129
+
130
+ #### transformOnUpdate(params: any, where?: any)
131
+
132
+ #### transformOnRemove(args?: any)
133
+
134
+ #### getDb()
135
+
136
+ #### getBuilder()
137
+
138
+ #### getIdField()
139
+
140
+ #### getCore()
141
+
142
+ #### setCore(core: BaseCore)
143
+
144
+ #### get(id: any)
145
+
146
+ #### getMany(ids: any[])
147
+
148
+ #### list(args?: ListArgsInterface)
149
+
150
+ #### create(args: any)
151
+
152
+ #### update(where: any, params: any)
153
+
154
+ #### updateMany(params: any): Promise<any[]>
155
+
156
+ #### increment(where: any, params: any)
157
+
158
+ #### decrement(where: any, params: any)
159
+
160
+ #### set(params: any): Promise<any[]>
161
+
162
+ #### remove(where: any, hardRemove = false)
163
+
164
+ ### buildDefaultGatewayProps = (args: any)
165
+
166
+ This function builds configuration object for a gateways inherited from the BaseGateway classs
167
+
168
+ ### BaseController
169
+
170
+ Base constroller class is used to create request handlers for RESTful API and provides some methods to simplify the task of working with requests and responses
171
+
172
+ #### json(method: any)
173
+
174
+ ### Application Context
175
+
176
+ #### createApiContext = async (args: ApiContextInterface)
177
+
178
+ #### createContextDefault = async (args: any)
File without changes
@@ -1,29 +1,15 @@
1
1
  import { Logger } from '@sdflc/utils';
2
- import { BaseCoreInterface, BaseCoreDoingWhatInterface, BaseCoreActionsInterface, CoreActionInterface, BaseCoreValidatorsInterface } from './interfaces';
3
- import { VerifyUserTokenArgs } from './interfaces/VerifyUserTokenArgs';
4
- import { BaseGateway } from './baseGateway';
5
- import { Database } from './database';
2
+ import { Database } from './Database';
3
+ import { BaseCorePropsInterface, BaseCoreActionsInterface, CoreActionInterface, BaseCoreValidatorsInterface, JwtTokenSecretAndSettings, ApiContext } from './interfaces';
6
4
  declare class BaseCore {
7
- protected props: BaseCoreInterface;
8
- protected db: Database;
9
- protected context: any;
10
- protected doingWhat?: BaseCoreDoingWhatInterface;
5
+ protected config: BaseCorePropsInterface;
11
6
  protected logger: Logger;
12
- protected name?: string;
13
- protected gateway?: BaseGateway;
14
- protected gateways?: any;
15
- protected gwSpace?: BaseGateway;
16
- protected interserviceApiKey?: string;
17
- protected jwtSecret: string;
18
- protected verifytokenArgs?: VerifyUserTokenArgs;
19
- protected requestId: string;
20
- protected validators: BaseCoreValidatorsInterface;
21
- protected doAuth: boolean;
22
- constructor(props: BaseCoreInterface);
7
+ constructor(props: BaseCorePropsInterface);
23
8
  getDb(): Database;
24
9
  getRequestId(): string;
25
- getContext(key?: string): any;
10
+ getContext(): ApiContext;
26
11
  getGateways(): any;
12
+ getValidators(): BaseCoreValidatorsInterface;
27
13
  success(data: any, code?: number): any;
28
14
  failure(code: number, errorMsg: string, data?: any): any;
29
15
  validationFailure(ex: any): any;
@@ -40,6 +26,7 @@ declare class BaseCore {
40
26
  set(args: any): Promise<any>;
41
27
  remove(args: any): Promise<any>;
42
28
  removeMany(args: any): Promise<any>;
29
+ defaultAfterAndBefore(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
43
30
  beforeList(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
44
31
  afterList(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
45
32
  beforeCreate(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
@@ -57,6 +44,12 @@ declare class BaseCore {
57
44
  beforeRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
58
45
  afterRemoveMany(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
59
46
  onException(params: any, opt?: BaseCoreActionsInterface): Promise<any>;
47
+ /**
48
+ * Returns JWT secret and its settings to verify received JWT token
49
+ * @param params Object of parameters passed to the authenticate method
50
+ * @returns Object with the jwtSecret and verifyTokenArgs
51
+ */
52
+ getJwtTokenSecretAndSettings(params: any): Promise<JwtTokenSecretAndSettings>;
60
53
  authenticate(params: any, opt?: BaseCoreActionsInterface): Promise<any[]>;
61
54
  }
62
55
  export { BaseCore };