@modular-rest/server 1.11.6 → 1.11.8

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 (37) hide show
  1. package/package-lock.json +1373 -0
  2. package/package.json +5 -5
  3. package/types/src/application.d.ts +97 -0
  4. package/types/src/class/cms_trigger.d.ts +24 -0
  5. package/types/src/class/collection_definition.d.ts +36 -0
  6. package/types/src/class/combinator.d.ts +30 -0
  7. package/types/src/class/database_trigger.d.ts +24 -0
  8. package/types/src/class/db_schemas.d.ts +2 -0
  9. package/types/src/class/directory.d.ts +2 -0
  10. package/types/src/class/paginator.d.ts +8 -0
  11. package/types/src/class/reply.d.ts +8 -0
  12. package/types/src/class/security.d.ts +109 -0
  13. package/types/src/class/trigger_operator.d.ts +19 -0
  14. package/types/src/class/user.d.ts +24 -0
  15. package/types/src/class/validator.d.ts +9 -0
  16. package/types/src/config.d.ts +101 -0
  17. package/types/src/events.d.ts +7 -0
  18. package/types/src/helper/data_insertion.d.ts +4 -0
  19. package/types/src/helper/presetup_services.d.ts +5 -0
  20. package/types/src/index.d.ts +72 -0
  21. package/types/src/middlewares.d.ts +9 -0
  22. package/types/src/services/data_provider/router.d.ts +3 -0
  23. package/types/src/services/data_provider/service.d.ts +40 -0
  24. package/types/src/services/data_provider/typeCasters.d.ts +3 -0
  25. package/types/src/services/file/db.d.ts +3 -0
  26. package/types/src/services/file/router.d.ts +3 -0
  27. package/types/src/services/file/service.d.ts +81 -0
  28. package/types/src/services/functions/router.d.ts +3 -0
  29. package/types/src/services/functions/service.d.ts +23 -0
  30. package/types/src/services/jwt/router.d.ts +3 -0
  31. package/types/src/services/jwt/service.d.ts +10 -0
  32. package/types/src/services/user_manager/db.d.ts +3 -0
  33. package/types/src/services/user_manager/permissionManager.d.ts +3 -0
  34. package/types/src/services/user_manager/router.d.ts +3 -0
  35. package/types/src/services/user_manager/service.d.ts +131 -0
  36. package/types/test.d.ts +1 -0
  37. package/test.js +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-rest/server",
3
- "version": "1.11.6",
3
+ "version": "1.11.8",
4
4
  "description": "a nodejs module based on KOAJS for developing Rest-APIs in a modular solution.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  "types": "./types/index.d.ts",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/navidshad/modular-rest.git"
13
+ "url": "git+https://github.com/modular-rest/modular-rest.git"
14
14
  },
15
15
  "keywords": [
16
16
  "app",
@@ -21,9 +21,9 @@
21
21
  "author": "Navid Shad <navidshad72@gmail.com> (http://navid-shad.ir)",
22
22
  "license": "MIT",
23
23
  "bugs": {
24
- "url": "https://github.com/navidshad/modular-rest/issues"
24
+ "url": "https://github.com/modular-rest/modular-rest/issues"
25
25
  },
26
- "homepage": "https://github.com/navidshad/modular-rest#readme",
26
+ "homepage": "https://github.com/modular-rest/modular-rest#readme",
27
27
  "dependencies": {
28
28
  "@koa/cors": "^3.1.0",
29
29
  "colog": "^1.0.4",
@@ -44,4 +44,4 @@
44
44
  "@types/koa__cors": "^5.0.0",
45
45
  "typescript": "^5.3.3"
46
46
  }
47
- }
47
+ }
@@ -0,0 +1,97 @@
1
+ export = createRest;
2
+ /**
3
+ * Create a modular REST instance with Koa and MongoDB support.
4
+ * @param {{
5
+ * cors?: Cors; // CORS options.
6
+ * modulesPath?: string; // Root directory of your router.js/db.js files.
7
+ * uploadDirectory?: string; // Root directory of your uploaded files.
8
+ * koaBodyOptions?: object; // Options for koa-body.
9
+ * staticPath?: {
10
+ * rootDir: string; // Root directory of your static files.
11
+ * rootPath: string; // Root path of your static files, defaults to '/assets'.
12
+ * maxage?: number; // Browser cache max-age in milliseconds. Defaults to 0.
13
+ * hidden?: boolean; // Allow transfer of hidden files. Defaults to false.
14
+ * index?: string; // Default file name. Defaults to 'index.html'.
15
+ * defer?: boolean; // If true, serves after return next(), allowing any downstream middleware to respond first. Defaults to false.
16
+ * gzip?: boolean; // Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. Defaults to true.
17
+ * br?: boolean; // Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists. Note that brotli is only accepted over https. Defaults to false.
18
+ * setHeaders?: Function; // Function to set custom headers on response.
19
+ * extensions?: boolean|Array; // Try to match extensions from passed array to search for file when no extension is suffixed in URL. First found is served. Defaults to false.
20
+ * };
21
+ * onBeforeInit?: (koaApp:Koa) => void; // A callback called before initializing the Koa server.
22
+ * onAfterInit?: (koaApp:Koa) => void; // A callback called after server initialization.
23
+ * port?: number; // Server port.
24
+ * dontListen?: boolean; // If true, the server will not run and will only return the Koa app object.
25
+ * mongo?: {
26
+ * dbPrefix: string; // A prefix for your database name.
27
+ * mongoBaseAddress: string; // The address of your MongoDB server without any database specification.
28
+ * addressMap?: string; // Specific addresses for each database.
29
+ * };
30
+ * keypair?: {
31
+ * private: string; // Private key for RSA authentication.
32
+ * public: string; // Public key for RSA authentication.
33
+ * };
34
+ * adminUser?: {
35
+ * email: string; // Admin user email.
36
+ * password: string; // Admin user password.
37
+ * };
38
+ * verificationCodeGeneratorMethod: () => string; // A method to return a verification code when registering a new user.
39
+ * collectionDefinitions?: CollectionDefinition[]; // An array of additional collection definitions.
40
+ * permissionGroups?: PermissionGroup[]; // An array of additional permission groups.
41
+ * authTriggers?: CmsTrigger[]; // An array of additional database triggers for the auth collection.
42
+ * fileTriggers?: CmsTrigger[]; // An array of additional database triggers for the auth collection.
43
+ * }} options
44
+ * @returns {Promise<{app: Koa, server: Server}>}
45
+ */
46
+ declare function createRest(options: {
47
+ cors?: Cors;
48
+ modulesPath?: string;
49
+ uploadDirectory?: string;
50
+ koaBodyOptions?: object;
51
+ staticPath?: {
52
+ rootDir: string;
53
+ rootPath: string;
54
+ maxage?: number;
55
+ hidden?: boolean;
56
+ index?: string;
57
+ defer?: boolean;
58
+ gzip?: boolean;
59
+ br?: boolean;
60
+ setHeaders?: Function;
61
+ extensions?: boolean | any[];
62
+ };
63
+ onBeforeInit?: (koaApp: Koa) => void;
64
+ onAfterInit?: (koaApp: Koa) => void;
65
+ port?: number;
66
+ dontListen?: boolean;
67
+ mongo?: {
68
+ dbPrefix: string;
69
+ mongoBaseAddress: string;
70
+ addressMap?: string;
71
+ };
72
+ keypair?: {
73
+ private: string;
74
+ public: string;
75
+ };
76
+ adminUser?: {
77
+ email: string;
78
+ password: string;
79
+ };
80
+ verificationCodeGeneratorMethod: () => string;
81
+ collectionDefinitions?: CollectionDefinition[];
82
+ permissionGroups?: PermissionGroup[];
83
+ authTriggers?: CmsTrigger[];
84
+ fileTriggers?: CmsTrigger[];
85
+ }): Promise<{
86
+ app: Koa;
87
+ server: Server;
88
+ }>;
89
+ declare namespace createRest {
90
+ export { Koa, server, Cors, PermissionGroup, CmsTrigger };
91
+ }
92
+ import cors = require("@koa/cors");
93
+ type Cors = import('@koa/cors').Options;
94
+ type Koa = import('koa');
95
+ type PermissionGroup = import('./class/security.js').PermissionGroup;
96
+ type CmsTrigger = import('./class/cms_trigger.js');
97
+ type server = import('http').Server;
@@ -0,0 +1,24 @@
1
+ export = CmsTrigger;
2
+ /**
3
+ * `CmsTrigger` is a class that defines a callback to be called on a specific database transaction.
4
+ *
5
+ * @class
6
+ */
7
+ declare class CmsTrigger {
8
+ /**
9
+ * Creates a new instance of `CmsTrigger`.
10
+ *
11
+ * @param {'update-one' | 'insert-one' | 'remove-one' } operation - The operation to be triggered.
12
+ * @param {function({query: any, queryResult: any}): void} [callback=(context) => {}] - The callback to be called when the operation is executed. The callback function takes an object as parameter with two properties: 'query' and 'queryResult'.
13
+ * @constructor
14
+ */
15
+ constructor(operation: 'update-one' | 'insert-one' | 'remove-one', callback?: (arg0: {
16
+ query: any;
17
+ queryResult: any;
18
+ }) => void);
19
+ operation: "update-one" | "insert-one" | "remove-one";
20
+ callback: (arg0: {
21
+ query: any;
22
+ queryResult: any;
23
+ }) => void;
24
+ }
@@ -0,0 +1,36 @@
1
+ export = CollectionDefinition;
2
+ /**
3
+ * @typedef {import('./security.js').Permission} Permission
4
+ * @typedef {import('./database_trigger.js')} DatabaseTrigger
5
+ */
6
+ declare class CollectionDefinition {
7
+ /**
8
+ * This class helps to create a mongoose collection
9
+ * associated with permissions and triggers.
10
+ *
11
+ * @class
12
+ * @param {Object} option
13
+ * @param {string} option.db - Database name
14
+ * @param {string} option.collection - Collection name
15
+ * @param {Object} option.schema - Mongoose schema
16
+ * @param {Array<Permission>} option.permissions - A list of permissions for this collection
17
+ * @param {Array<DatabaseTrigger>=} option.triggers - A database trigger
18
+ */
19
+ constructor({ db, collection, schema, permissions, triggers }: {
20
+ db: string;
21
+ collection: string;
22
+ schema: any;
23
+ permissions: Array<Permission>;
24
+ triggers?: Array<DatabaseTrigger> | undefined;
25
+ });
26
+ database: string;
27
+ collection: string;
28
+ schema: any;
29
+ permissions: import("./security.js").Permission[];
30
+ triggers: import("./database_trigger.js")[];
31
+ }
32
+ declare namespace CollectionDefinition {
33
+ export { Permission, DatabaseTrigger };
34
+ }
35
+ type Permission = import('./security.js').Permission;
36
+ type DatabaseTrigger = import('./database_trigger.js');
@@ -0,0 +1,30 @@
1
+ export = Combinator.instance;
2
+ declare var instance: Combinator;
3
+ declare class Combinator {
4
+ static get instance(): Combinator;
5
+ combineRoutesByFilePath(rootDirectory: any, app: any): Promise<void>;
6
+ /**
7
+ *
8
+ * @param {object} option
9
+ * @param {string} option.rootDirectory root directory of files
10
+ * @param {object} option.filename an object of {name, extension}
11
+ * @param {string} option.filename.name name of file
12
+ * @param {string} option.filename.extension the extension of the file
13
+ * @param {boolean} option.combineWithRoot combine all file content and return theme as a object
14
+ * @param {boolean} option.convertToArray return file content as an array instead an object
15
+ */
16
+ combineModulesByFilePath({ rootDirectory, filename, combineWithRoot, convertToArray, }: {
17
+ rootDirectory: string;
18
+ filename: {
19
+ name: string;
20
+ extension: string;
21
+ };
22
+ combineWithRoot: boolean;
23
+ convertToArray: boolean;
24
+ }): Promise<any>;
25
+ combineFunctionsByFilePath({ rootDirectory, filename }: {
26
+ rootDirectory: any;
27
+ filename: any;
28
+ }): Promise<void>;
29
+ extendObj(obj: any, src: any): any;
30
+ }
@@ -0,0 +1,24 @@
1
+ export = DatabaseTrigger;
2
+ /**
3
+ * `DatabaseTrigger` is a class that defines a callback to be called on a specific database transaction.
4
+ *
5
+ * @class
6
+ */
7
+ declare class DatabaseTrigger {
8
+ /**
9
+ * Creates a new instance of `DatabaseTrigger`.
10
+ *
11
+ * @param {'find' | 'find-one' | 'count' | 'update-one' | 'insert-one' | 'remove-one' | 'aggregate'} operation - The operation to be triggered. Supported operations are: 'find', 'find-one', 'count', 'update-one', 'insert-one', 'remove-one', 'aggregate'.
12
+ * @param {function({query: any, queryResult: any}): void} [callback=(context) => {}] - The callback to be called when the operation is executed. The callback function takes an object as parameter with two properties: 'query' and 'queryResult'.
13
+ * @constructor
14
+ */
15
+ constructor(operation: 'find' | 'find-one' | 'count' | 'update-one' | 'insert-one' | 'remove-one' | 'aggregate', callback?: (arg0: {
16
+ query: any;
17
+ queryResult: any;
18
+ }) => void);
19
+ operation: "find" | "count" | "aggregate" | "find-one" | "update-one" | "insert-one" | "remove-one";
20
+ callback: (arg0: {
21
+ query: any;
22
+ queryResult: any;
23
+ }) => void;
24
+ }
@@ -0,0 +1,2 @@
1
+ import mongoose = require("mongoose");
2
+ export let file: mongoose.Schema<mongoose.Document<any, any, any>, mongoose.Model<mongoose.Document<any, any, any>, any, any>, undefined, {}>;
@@ -0,0 +1,2 @@
1
+ export function walk(dir: any, settings: any, done: any): void;
2
+ export function find(dir: any, settings: any): Promise<any>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates a pagination object based on the given parameters.
3
+ * @param {number} count - The total number of items to paginate.
4
+ * @param {number} perPage - The number of items to display per page.
5
+ * @param {number} page - The current page number.
6
+ * @returns {Object} - An object containing pagination information.
7
+ */
8
+ export function create(count: number, perPage: number, page: number): any;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates a response object with the given status and detail.
3
+ *
4
+ * @param {string} status - The status of the response. Can be "s" for success, "f" for fail, or "e" for error.
5
+ * @param {Object} [detail={}] - The detail of the response. Can contain any additional information about the response.
6
+ * @returns {Object} - The response object with the given status and detail.
7
+ */
8
+ export function create(status: string, detail?: any): any;
@@ -0,0 +1,109 @@
1
+ export type PermissionType = ('user_access' | 'upload_file_access' | 'remove_file_access' | 'anonymous_access' | 'advanced_settings');
2
+ /**
3
+ * Class representing an access definition.
4
+ */
5
+ export class AccessDefinition {
6
+ /**
7
+ * Create an access definition.
8
+ * @param {Object} options - The options for the access definition.
9
+ * @param {string} options.database - The name of the database.
10
+ * @param {string} options.collection - The name of the collection.
11
+ * @param {Array.<Permission>} options.permissionList - The list of permissions.
12
+ */
13
+ constructor({ database, collection, permissionList }: {
14
+ database: string;
15
+ collection: string;
16
+ permissionList: Array<Permission>;
17
+ });
18
+ database: string;
19
+ collection: string;
20
+ permissionList: Permission[];
21
+ }
22
+ /**
23
+ * @typedef {('user_access'|'upload_file_access'|'remove_file_access'|'anonymous_access'|'advanced_settings')} PermissionType
24
+ */
25
+ /**
26
+ * Class representing a permission.
27
+ */
28
+ export class Permission {
29
+ /**
30
+ * Create a permission.
31
+ * @param {Object} options - The options for the permission.
32
+ * @param {PermissionType} options.type - The type of the permission.
33
+ * @param {boolean} [options.read=false] - The read access of the permission.
34
+ * @param {boolean} [options.write=false] - The write access of the permission.
35
+ * @param {boolean} [options.onlyOwnData=false] - If true, users can perform CRUD on documents that they created already.
36
+ * @param {string} [options.ownerIdField='refId'] - The name of the field that contains the owner's id of the document.
37
+ */
38
+ constructor({ type, read, write, onlyOwnData, ownerIdField, }: {
39
+ type: PermissionType;
40
+ read?: boolean;
41
+ write?: boolean;
42
+ onlyOwnData?: boolean;
43
+ ownerIdField?: string;
44
+ });
45
+ type: PermissionType;
46
+ read: boolean;
47
+ write: boolean;
48
+ onlyOwnData: boolean;
49
+ ownerIdField: string;
50
+ }
51
+ /**
52
+ * Class representing different types of permissions.
53
+ * Each static getter returns a string that represents a specific type of permission.
54
+ */
55
+ export class PermissionTypes {
56
+ /**
57
+ * Get the string representing god access permission type.
58
+ * @return {string} The god access permission type.
59
+ */
60
+ static get god_access(): string;
61
+ /**
62
+ * Get the string representing advanced settings permission type.
63
+ * @return {string} The advanced settings permission type.
64
+ */
65
+ static get advanced_settings(): string;
66
+ /**
67
+ * Get the string representing user access permission type.
68
+ * @return {string} The user access permission type.
69
+ */
70
+ static get user_access(): string;
71
+ /**
72
+ * Get the string representing upload file access permission type.
73
+ * @return {string} The upload file access permission type.
74
+ */
75
+ static get upload_file_access(): string;
76
+ /**
77
+ * Get the string representing remove file access permission type.
78
+ * @return {string} The remove file access permission type.
79
+ */
80
+ static get remove_file_access(): string;
81
+ }
82
+ export class PermissionGroup {
83
+ /**
84
+ * Create a permission group.
85
+ * @param {Object} options - The options for the permission group.
86
+ * @param {string} options.title - The title of the permission group.
87
+ * @param {boolean} [options.isDefault=false] - If true, the permission group is the default permission group.
88
+ * @param {boolean} [options.isAnonymous=false] - If true, the permission group is the anonymous permission group.
89
+ * @param {Array.<PermissionType>} [options.validPermissionTypes=[]] - The valid permission types of the permission group.
90
+ * @return {PermissionGroup} The created permission group.
91
+ */
92
+ constructor({ title, isDefault, isAnonymous, validPermissionTypes, }: {
93
+ title: string;
94
+ isDefault?: boolean;
95
+ isAnonymous?: boolean;
96
+ validPermissionTypes?: Array<PermissionType>;
97
+ });
98
+ title: string;
99
+ isDefault: boolean;
100
+ isAnonymous: boolean;
101
+ validPermissionTypes: PermissionType[];
102
+ }
103
+ /**
104
+ * Class representing access types.
105
+ */
106
+ export class AccessTypes {
107
+ static get read(): string;
108
+ static get write(): string;
109
+ }
@@ -0,0 +1,19 @@
1
+ export = TriggerOperator.instance;
2
+ declare var instance: TriggerOperator;
3
+ declare class TriggerOperator {
4
+ static get instance(): TriggerOperator;
5
+ triggers: any[];
6
+ /**
7
+ * add a collection trigger
8
+ * @param {object} trigger DatabaseTrigger object
9
+ */
10
+ addTrigger(trigger: object): void;
11
+ /**
12
+ * Call a trigger
13
+ * @param {'find' | 'find-one' | 'count' | 'update-one' | 'insert-one' | 'remove-one' | 'aggregate'} operation operation name
14
+ * @param {string} database database name
15
+ * @param {string} collection collection name
16
+ * @param {string} data
17
+ */
18
+ call(operation: 'find' | 'find-one' | 'count' | 'update-one' | 'insert-one' | 'remove-one' | 'aggregate', database: string, collection: string, data: string): void;
19
+ }
@@ -0,0 +1,24 @@
1
+ export = User;
2
+ declare class User {
3
+ static loadFromModel(model: any): Promise<any>;
4
+ static createFromModel(model: any, detail: any): Promise<any>;
5
+ static notValid(object: any): string;
6
+ constructor(id: any, permissionGroup: any, phone: any, email: any, password: any, type: any, model: any);
7
+ id: any;
8
+ permissionGroup: any;
9
+ email: any;
10
+ phone: any;
11
+ password: any;
12
+ type: any;
13
+ dbModel: any;
14
+ getBrief(): {
15
+ id: any;
16
+ permissionGroup: import("./security").PermissionGroup;
17
+ phone: any;
18
+ email: any;
19
+ type: any;
20
+ };
21
+ setNewDetail(detail: any): void;
22
+ hasPermission(permissionField: any): boolean;
23
+ save(): Promise<void>;
24
+ }
@@ -0,0 +1,9 @@
1
+ export = validate;
2
+ /**
3
+ * Validates an object by checking if it contains all the required fields.
4
+ * @param {Object} obj - The object to be validated.
5
+ * @param {string|Object} requiredFields - The list of required fields. If it's a string, it should contain keys separated by spaces. If it's an object, it should contain key-value pairs where the key is the field name and the value is a boolean indicating whether the field is required or not.
6
+ * @returns {boolean} - Returns true if the object contains all the required fields, otherwise returns false.
7
+ * @throws {string} - Throws an error if the requiredFields parameter is not a string or an object.
8
+ */
9
+ declare function validate(obj: any, requiredFields: string | any): boolean;
@@ -0,0 +1,101 @@
1
+ export type Koa = import('koa');
2
+ export type Cors = import('@koa/cors').Options;
3
+ export type CollectionDefinition = import('./class/collection_definition.js');
4
+ export type PermissionGroup = import('./class/security.js').PermissionGroup;
5
+ export type CmsTrigger = import('./class/cms_trigger.js');
6
+ export type Config = {
7
+ cors?: Cors;
8
+ modulesPath?: string;
9
+ koaBodyOptions?: object;
10
+ staticPath?: {
11
+ rootDir: string;
12
+ rootPath: string;
13
+ maxage?: number;
14
+ hidden?: boolean;
15
+ index?: string;
16
+ defer?: boolean;
17
+ gzip?: boolean;
18
+ br?: boolean;
19
+ setHeaders?: Function;
20
+ extensions?: boolean | any[];
21
+ };
22
+ onBeforeInit?: (koaApp: Koa) => void;
23
+ onAfterInit?: (koaApp: Koa) => void;
24
+ port?: number;
25
+ dontListen?: boolean;
26
+ mongo?: {
27
+ dbPrefix: string;
28
+ mongoBaseAddress: string;
29
+ addressMap?: string;
30
+ };
31
+ keypair?: {
32
+ private: string;
33
+ public: string;
34
+ };
35
+ adminUser?: {
36
+ email: string;
37
+ password: string;
38
+ };
39
+ verificationCodeGeneratorMethod: () => string;
40
+ collectionDefinitions?: CollectionDefinition[];
41
+ permissionGroups?: PermissionGroup[];
42
+ authTriggers?: DatabaseTrigger[];
43
+ fileTriggers?: CmsTrigger[];
44
+ };
45
+ /**
46
+ * @param {Config} options
47
+ */
48
+ export function setConfig(options: Config): void;
49
+ /**
50
+ * @typedef {import('koa')} Koa
51
+ * @typedef {import('@koa/cors').Options} Cors
52
+ * @typedef {import('./class/collection_definition.js')} CollectionDefinition
53
+ * @typedef {import('./class/security.js').PermissionGroup} PermissionGroup
54
+ * @typedef {import('./class/cms_trigger.js')} CmsTrigger
55
+ */
56
+ /**
57
+ * @typedef {{
58
+ * cors?: Cors; // CORS options.
59
+ * modulesPath?: string; // Root directory of your router.js/db.js files.
60
+ * koaBodyOptions?: object; // Options for koa-body.
61
+ * staticPath?: {
62
+ * rootDir: string; // Root directory of your static files.
63
+ * rootPath: string; // Root path of your static files, defaults to '/assets'.
64
+ * maxage?: number; // Browser cache max-age in milliseconds. Defaults to 0.
65
+ * hidden?: boolean; // Allow transfer of hidden files. Defaults to false.
66
+ * index?: string; // Default file name. Defaults to 'index.html'.
67
+ * defer?: boolean; // If true, serves after return next(), allowing any downstream middleware to respond first. Defaults to false.
68
+ * gzip?: boolean; // Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. Defaults to true.
69
+ * br?: boolean; // Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists. Note that brotli is only accepted over https. Defaults to false.
70
+ * setHeaders?: Function; // Function to set custom headers on response.
71
+ * extensions?: boolean|Array; // Try to match extensions from passed array to search for file when no extension is suffixed in URL. First found is served. Defaults to false.
72
+ * };
73
+ * onBeforeInit?: (koaApp:Koa) => void; // A callback called before initializing the Koa server.
74
+ * onAfterInit?: (koaApp:Koa) => void; // A callback called after server initialization.
75
+ * port?: number; // Server port.
76
+ * dontListen?: boolean; // If true, the server will not run and will only return the Koa app object.
77
+ * mongo?: {
78
+ * dbPrefix: string; // A prefix for your database name.
79
+ * mongoBaseAddress: string; // The address of your MongoDB server without any database specification.
80
+ * addressMap?: string; // Specific addresses for each database.
81
+ * };
82
+ * keypair?: {
83
+ * private: string; // Private key for RSA authentication.
84
+ * public: string; // Public key for RSA authentication.
85
+ * };
86
+ * adminUser?: {
87
+ * email: string; // Admin user email.
88
+ * password: string; // Admin user password.
89
+ * };
90
+ * verificationCodeGeneratorMethod: () => string; // A method to return a verification code when registering a new user.
91
+ * collectionDefinitions?: CollectionDefinition[]; // An array of additional collection definitions.
92
+ * permissionGroups?: PermissionGroup[]; // An array of additional permission groups.
93
+ * authTriggers?: DatabaseTrigger[]; // An array of additional database triggers for the auth collection.
94
+ * fileTriggers?: CmsTrigger[]; // An array of additional database triggers for the auth collection.
95
+ * }} Config
96
+ * @exports Config
97
+ */
98
+ /**
99
+ * @type {Config}
100
+ */
101
+ export const config: Config;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * onBeforeInit: (koaApp:Koa) => void; // A callback called before initializing the Koa server.
3
+ * onAfterInit: (koaApp:Koa) => void; // A callback called after server initialization.
4
+ * onNewUser:
5
+ */
6
+ declare function registerEventCallback(event: any, callback: any): void;
7
+ declare const eventCallbacks: any[];
@@ -0,0 +1,4 @@
1
+ export function createAdminUser({ email, password }: {
2
+ email: any;
3
+ password: any;
4
+ }): Promise<never>;
@@ -0,0 +1,5 @@
1
+ export function setup({ keypair, adminUser, uploadDirectory }: {
2
+ keypair: any;
3
+ adminUser: any;
4
+ uploadDirectory: any;
5
+ }): Promise<void>;
@@ -0,0 +1,72 @@
1
+ declare const _exports: {
2
+ defineFunction: typeof defineFunction;
3
+ TypeCasters: {
4
+ ObjectId: import("mongoose").Types.ObjectIdConstructor;
5
+ Date: (dateValue: any) => Date;
6
+ };
7
+ validator: typeof validator;
8
+ reply: typeof reply;
9
+ paginator: typeof paginator;
10
+ getCollection: typeof getCollection;
11
+ getFile: (fileId: string) => Promise<any>;
12
+ getFileLink: (fileId: string) => Promise<any>;
13
+ getFilePath: (fileId: any) => Promise<string>;
14
+ removeFile: (fileId: string) => Promise<any>;
15
+ storeFile: ({ file, ownerId, tag, removeFileAfterStore }: {
16
+ file: {
17
+ path: string;
18
+ type: string;
19
+ name: string;
20
+ size: number;
21
+ };
22
+ ownerId: string;
23
+ tag: string;
24
+ removeFileAfterStore?: boolean;
25
+ }) => Promise<any>;
26
+ middleware: typeof middleware;
27
+ userManager: {
28
+ tempIds: {};
29
+ setCustomVerificationCodeGeneratorMethod(generatorMethod: Function): void;
30
+ verificationCodeGeneratorMethod: Function;
31
+ generateVerificationCode(id: string, idType: any): Promise<import("./class/user")>;
32
+ getUserById(id: string): Promise<import("./class/user")>;
33
+ getUserByIdentity(id: string, idType: string): Promise<import("./class/user")>;
34
+ getUserByToken(token: string): Promise<import("./class/user")>;
35
+ isCodeValid(id: string, code: string): boolean;
36
+ loginUser(id?: string, idType?: string, password?: string): Promise<string>;
37
+ issueTokenForUser(email: string): Promise<string>;
38
+ loginAnonymous(): Promise<string>;
39
+ registerTemporaryID(id: string, type: string, code: string): void;
40
+ submitPasswordForTemporaryID(id: string, password: string, code: string): Promise<boolean>;
41
+ changePasswordForTemporaryID(id: string, password: string, code: string): Promise<boolean>;
42
+ registerUser(detail: any): Promise<string>;
43
+ changePassword(query: any, newPass: string): Promise<void>;
44
+ };
45
+ AccessDefinition: typeof SecurityClass.AccessDefinition;
46
+ Permission: typeof SecurityClass.Permission;
47
+ PermissionTypes: typeof SecurityClass.PermissionTypes;
48
+ PermissionGroup: typeof SecurityClass.PermissionGroup;
49
+ AccessTypes: typeof SecurityClass.AccessTypes;
50
+ createRest: typeof createRest;
51
+ CollectionDefinition: typeof CollectionDefinition;
52
+ Schemas: {
53
+ file: Schema<import("mongoose").Document<any, any, any>, import("mongoose").Model<import("mongoose").Document<any, any, any>, any, any>, undefined, {}>;
54
+ };
55
+ Schema: typeof Schema;
56
+ DatabaseTrigger: typeof DatabaseTrigger;
57
+ CmsTrigger: typeof CmsTrigger;
58
+ };
59
+ export = _exports;
60
+ import { defineFunction } from "./services/functions/service";
61
+ import validator = require("./class/validator");
62
+ import reply = require("./class/reply");
63
+ import paginator = require("./class/paginator");
64
+ import { getCollection } from "./services/data_provider/service";
65
+ import middleware = require("./middlewares");
66
+ import SecurityClass = require("./class/security");
67
+ import createRest = require("./application");
68
+ import CollectionDefinition = require("./class/collection_definition");
69
+ import Schema_1 = require("mongoose");
70
+ import Schema = Schema_1.Schema;
71
+ import DatabaseTrigger = require("./class/database_trigger");
72
+ import CmsTrigger = require("./class/cms_trigger");
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Authentication middleware
3
+ * It checks if incoming request has a valid token in header.authorization
4
+ *
5
+ * @param {Object} ctx - Koa context
6
+ * @param {Function} next - Koa next function
7
+ * @returns {Promise<void>}
8
+ */
9
+ export function auth(ctx: any, next: Function): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export let name: string;
2
+ declare let dataProvider: any;
3
+ export { dataProvider as main };