@90soft/parse-server-kit 1.0.0 → 2.0.1
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/README.md +424 -0
- package/dist/decorators/cloudDecorator.d.ts +7 -0
- package/dist/decorators/cloudDecorator.d.ts.map +1 -0
- package/dist/decorators/cloudDecorator.js +77 -0
- package/dist/decorators/cloudDecorator.js.map +1 -0
- package/dist/decorators/cloudRegistry.d.ts +9 -0
- package/dist/decorators/cloudRegistry.d.ts.map +1 -0
- package/dist/decorators/cloudRegistry.js +26 -0
- package/dist/decorators/cloudRegistry.js.map +1 -0
- package/dist/decorators/cronDecorator.d.ts +6 -0
- package/dist/decorators/cronDecorator.d.ts.map +1 -0
- package/dist/decorators/cronDecorator.js +28 -0
- package/dist/decorators/cronDecorator.js.map +1 -0
- package/dist/decorators/cronRegistry.d.ts +13 -0
- package/dist/decorators/cronRegistry.d.ts.map +1 -0
- package/dist/decorators/cronRegistry.js +96 -0
- package/dist/decorators/cronRegistry.js.map +1 -0
- package/dist/decorators/routeDecorator.d.ts +35 -0
- package/dist/decorators/routeDecorator.d.ts.map +1 -0
- package/dist/decorators/routeDecorator.js +160 -0
- package/dist/decorators/routeDecorator.js.map +1 -0
- package/dist/decorators/triggerDecorator.d.ts +19 -0
- package/dist/decorators/triggerDecorator.d.ts.map +1 -0
- package/dist/decorators/triggerDecorator.js +45 -0
- package/dist/decorators/triggerDecorator.js.map +1 -0
- package/dist/decorators/triggerRegistry.d.ts +10 -0
- package/dist/decorators/triggerRegistry.d.ts.map +1 -0
- package/dist/decorators/triggerRegistry.js +87 -0
- package/dist/decorators/triggerRegistry.js.map +1 -0
- package/dist/decorators/types/cloudTypes.d.ts +32 -0
- package/dist/decorators/types/cloudTypes.d.ts.map +1 -0
- package/dist/decorators/types/cloudTypes.js +3 -0
- package/dist/decorators/types/cloudTypes.js.map +1 -0
- package/dist/decorators/types/common.d.ts +14 -0
- package/dist/decorators/types/common.d.ts.map +1 -0
- package/dist/decorators/types/common.js +3 -0
- package/dist/decorators/types/common.js.map +1 -0
- package/dist/decorators/types/cronTypes.d.ts +32 -0
- package/dist/decorators/types/cronTypes.d.ts.map +1 -0
- package/dist/decorators/types/cronTypes.js +21 -0
- package/dist/decorators/types/cronTypes.js.map +1 -0
- package/dist/decorators/types/fieldValidation.d.ts +36 -0
- package/dist/decorators/types/fieldValidation.d.ts.map +1 -0
- package/dist/decorators/types/fieldValidation.js +135 -0
- package/dist/decorators/types/fieldValidation.js.map +1 -0
- package/dist/decorators/types/triggerTypes.d.ts +14 -0
- package/dist/decorators/types/triggerTypes.d.ts.map +1 -0
- package/dist/decorators/types/triggerTypes.js +3 -0
- package/dist/decorators/types/triggerTypes.js.map +1 -0
- package/dist/index.d.ts +25 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -6
- package/dist/index.js.map +1 -1
- package/dist/middleware/middleware.d.ts +41 -0
- package/dist/middleware/middleware.d.ts.map +1 -0
- package/dist/middleware/middleware.js +154 -0
- package/dist/middleware/middleware.js.map +1 -0
- package/dist/swagger/index.d.ts +9 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +37 -0
- package/dist/swagger/index.js.map +1 -0
- package/dist/swagger/swaggerRegistry.d.ts +79 -0
- package/dist/swagger/swaggerRegistry.d.ts.map +1 -0
- package/dist/swagger/swaggerRegistry.js +115 -0
- package/dist/swagger/swaggerRegistry.js.map +1 -0
- package/dist/swagger/swaggerSpec.d.ts +69 -0
- package/dist/swagger/swaggerSpec.d.ts.map +1 -0
- package/dist/swagger/swaggerSpec.js +174 -0
- package/dist/swagger/swaggerSpec.js.map +1 -0
- package/dist/utils/ACL.d.ts +19 -0
- package/dist/utils/ACL.d.ts.map +1 -0
- package/dist/utils/ACL.js +35 -0
- package/dist/utils/ACL.js.map +1 -0
- package/dist/utils/constants.d.ts +13 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +19 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/dynamicImport.d.ts +2 -0
- package/dist/utils/dynamicImport.d.ts.map +1 -0
- package/dist/utils/dynamicImport.js +21 -0
- package/dist/utils/dynamicImport.js.map +1 -0
- package/dist/utils/helper.d.ts +15 -0
- package/dist/utils/helper.d.ts.map +1 -0
- package/dist/utils/helper.js +93 -0
- package/dist/utils/helper.js.map +1 -0
- package/package.json +21 -5
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
interface MongoDBValidatorProperty {
|
|
3
|
+
bsonType?: string | string[];
|
|
4
|
+
minimum?: number;
|
|
5
|
+
maximum?: number;
|
|
6
|
+
minLength?: number;
|
|
7
|
+
maxLength?: number;
|
|
8
|
+
enum?: (string | null)[];
|
|
9
|
+
pattern?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
interface MongoDBValidator {
|
|
13
|
+
$jsonSchema: {
|
|
14
|
+
bsonType: 'object';
|
|
15
|
+
properties: Record<string, MongoDBValidatorProperty>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface ValidationInfo {
|
|
19
|
+
className: string;
|
|
20
|
+
validator: MongoDBValidator;
|
|
21
|
+
}
|
|
22
|
+
interface ValidationError {
|
|
23
|
+
field: string;
|
|
24
|
+
message: string;
|
|
25
|
+
value?: any;
|
|
26
|
+
}
|
|
27
|
+
interface ValidationResult {
|
|
28
|
+
valid: boolean;
|
|
29
|
+
errors: ValidationError[];
|
|
30
|
+
}
|
|
31
|
+
export declare function validateObject(object: Parse.Object): ValidationResult;
|
|
32
|
+
export declare function validateOrThrow(object: Parse.Object): void;
|
|
33
|
+
export declare function getValidators(): ValidationInfo[];
|
|
34
|
+
export declare function applyMongoValidators(parseServerInstance?: any): Promise<void>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=fieldValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldValidation.d.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";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateObject = validateObject;
|
|
4
|
+
exports.validateOrThrow = validateOrThrow;
|
|
5
|
+
exports.getValidators = getValidators;
|
|
6
|
+
exports.applyMongoValidators = applyMongoValidators;
|
|
7
|
+
require("reflect-metadata");
|
|
8
|
+
const schemaTypes_1 = require("./schemaTypes");
|
|
9
|
+
const helper_1 = require("../../utils/helper");
|
|
10
|
+
function validateObject(object) {
|
|
11
|
+
const className = object.className;
|
|
12
|
+
const classConstructor = Parse.Object.extend(className);
|
|
13
|
+
const fields = Reflect.getMetadata('parse:fields', classConstructor) || {};
|
|
14
|
+
const errors = [];
|
|
15
|
+
for (const [fieldName, meta] of Object.entries(fields)) {
|
|
16
|
+
const value = object.get(fieldName);
|
|
17
|
+
if (value === null || value === undefined) {
|
|
18
|
+
if (meta.required) {
|
|
19
|
+
errors.push({ field: fieldName, message: `Field '${fieldName}' is required` });
|
|
20
|
+
}
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (meta.type === 'Number' && typeof value === 'number') {
|
|
24
|
+
if (meta.min !== undefined && value < meta.min) {
|
|
25
|
+
errors.push({ field: fieldName, message: `Field '${fieldName}' must be at least ${meta.min}, got ${value}`, value });
|
|
26
|
+
}
|
|
27
|
+
if (meta.max !== undefined && value > meta.max) {
|
|
28
|
+
errors.push({ field: fieldName, message: `Field '${fieldName}' must be at most ${meta.max}, got ${value}`, value });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (meta.type === 'String' && typeof value === 'string') {
|
|
32
|
+
if (meta.minLength !== undefined && value.length < meta.minLength) {
|
|
33
|
+
errors.push({ field: fieldName, message: `Field '${fieldName}' must have at least ${meta.minLength} characters, got ${value.length}`, value });
|
|
34
|
+
}
|
|
35
|
+
if (meta.maxLength !== undefined && value.length > meta.maxLength) {
|
|
36
|
+
errors.push({ field: fieldName, message: `Field '${fieldName}' must have at most ${meta.maxLength} characters, got ${value.length}`, value });
|
|
37
|
+
}
|
|
38
|
+
if (meta.enum !== undefined && !meta.enum.includes(value)) {
|
|
39
|
+
errors.push({ field: fieldName, message: `Field '${fieldName}' must be one of: ${meta.enum.join(', ')}. Got '${value}'`, value });
|
|
40
|
+
}
|
|
41
|
+
if (meta.pattern !== undefined) {
|
|
42
|
+
const regex = new RegExp(meta.pattern);
|
|
43
|
+
if (!regex.test(value)) {
|
|
44
|
+
errors.push({ field: fieldName, message: `Field '${fieldName}' must match pattern: ${meta.pattern}. Got '${value}'`, value });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { valid: errors.length === 0, errors };
|
|
50
|
+
}
|
|
51
|
+
function validateOrThrow(object) {
|
|
52
|
+
const result = validateObject(object);
|
|
53
|
+
if (!result.valid) {
|
|
54
|
+
const messages = result.errors.map(e => e.message).join('; ');
|
|
55
|
+
throw new Parse.Error(Parse.Error.VALIDATION_ERROR, messages);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function buildValidator(className) {
|
|
59
|
+
const classConstructor = Parse.Object.extend(className);
|
|
60
|
+
const fields = Reflect.getMetadata('parse:fields', classConstructor) || {};
|
|
61
|
+
const properties = {};
|
|
62
|
+
let hasValidation = false;
|
|
63
|
+
for (const [fieldName, meta] of Object.entries(fields)) {
|
|
64
|
+
if (meta.type === 'Number' && (meta.min !== undefined || meta.max !== undefined)) {
|
|
65
|
+
hasValidation = true;
|
|
66
|
+
properties[fieldName] = {
|
|
67
|
+
bsonType: ['int', 'long', 'double', 'decimal', 'null'],
|
|
68
|
+
...(meta.min !== undefined && { minimum: meta.min }),
|
|
69
|
+
...(meta.max !== undefined && { maximum: meta.max }),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (meta.type === 'String' && (meta.minLength !== undefined || meta.maxLength !== undefined || meta.enum !== undefined || meta.pattern !== undefined)) {
|
|
73
|
+
hasValidation = true;
|
|
74
|
+
properties[fieldName] = {
|
|
75
|
+
bsonType: ['string', 'null'],
|
|
76
|
+
...(meta.minLength !== undefined && { minLength: meta.minLength }),
|
|
77
|
+
...(meta.maxLength !== undefined && { maxLength: meta.maxLength }),
|
|
78
|
+
...(meta.enum !== undefined && { enum: [...meta.enum, null] }),
|
|
79
|
+
...(meta.pattern !== undefined && { pattern: meta.pattern }),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!hasValidation)
|
|
84
|
+
return null;
|
|
85
|
+
return { $jsonSchema: { bsonType: 'object', properties } };
|
|
86
|
+
}
|
|
87
|
+
function getValidators() {
|
|
88
|
+
const validators = [];
|
|
89
|
+
for (const className of schemaTypes_1.classNames) {
|
|
90
|
+
const validator = buildValidator(className);
|
|
91
|
+
if (validator)
|
|
92
|
+
validators.push({ className, validator });
|
|
93
|
+
}
|
|
94
|
+
return validators;
|
|
95
|
+
}
|
|
96
|
+
async function applyMongoValidators(parseServerInstance) {
|
|
97
|
+
const validators = getValidators();
|
|
98
|
+
if (validators.length === 0) {
|
|
99
|
+
console.log('[Validators] No MongoDB validators to apply');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
console.log(`[Validators] Applying ${validators.length} MongoDB validator(s)...`);
|
|
103
|
+
try {
|
|
104
|
+
const config = parseServerInstance?.config;
|
|
105
|
+
const adapter = config?.databaseController?.adapter || config?.database?.adapter;
|
|
106
|
+
const db = adapter?.database || adapter?.client?.db() || adapter?.mongoClient?.db();
|
|
107
|
+
if (!db) {
|
|
108
|
+
console.warn('[Validators] Could not access database adapter.');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for (const { className, validator } of validators) {
|
|
112
|
+
const [validatorErr] = await (0, helper_1.catchError)(db.command({
|
|
113
|
+
collMod: className,
|
|
114
|
+
validator: validator,
|
|
115
|
+
validationLevel: 'moderate',
|
|
116
|
+
validationAction: 'error',
|
|
117
|
+
}));
|
|
118
|
+
if (validatorErr) {
|
|
119
|
+
if (validatorErr.codeName === 'NamespaceNotFound') {
|
|
120
|
+
console.log(`[Validators] Collection ${className} doesn't exist yet`);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
console.error(`[Validators] Failed for ${className}:`, validatorErr.message);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.log(`[Validators] Applied validator for: ${className}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.error('[Validators] Error:', error.message);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=fieldValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldValidation.js","sourceRoot":"","sources":["../../../src/decorators/types/fieldValidation.ts"],"names":[],"mappings":";;AAiDA,wCA+CC;AAED,0CAMC;AAoCD,sCAOC;AAED,oDAyCC;AA9LD,4BAA0B;AAC1B,+CAAyC;AACzC,+CAA8C;AA+C9C,SAAgB,cAAc,CAAC,MAAoB;IACjD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACnC,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACxD,MAAM,MAAM,GACV,OAAO,CAAC,WAAW,CAAC,cAAc,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC;IAE9D,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEpC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC1C,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClB,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,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OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ClassNameType } from './schemaTypes';
|
|
2
|
+
export type TriggerType = 'beforeSave' | 'afterSave' | 'beforeDelete' | 'afterDelete' | 'beforeFind' | 'afterFind' | 'beforeLogin' | 'afterLogin' | 'afterLogout' | 'beforeSaveFile' | 'afterSaveFile' | 'beforeDeleteFile' | 'afterDeleteFile' | 'beforeConnect' | 'beforeSubscribe' | 'afterEvent';
|
|
3
|
+
export interface TriggerMetadata {
|
|
4
|
+
type: TriggerType;
|
|
5
|
+
className: ClassNameType;
|
|
6
|
+
handler: Function;
|
|
7
|
+
description?: string;
|
|
8
|
+
validation?: Parse.Cloud.Validator;
|
|
9
|
+
}
|
|
10
|
+
export interface TriggerConfig {
|
|
11
|
+
description?: string;
|
|
12
|
+
validation?: Parse.Cloud.Validator;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=triggerTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggerTypes.d.ts","sourceRoot":"","sources":["../../../src/decorators/types/triggerTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAE5C,MAAM,MAAM,WAAW,GACnB,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,aAAa,GAC3D,YAAY,GAAG,WAAW,GAC1B,aAAa,GAAG,YAAY,GAAG,aAAa,GAC5C,gBAAgB,GAAG,eAAe,GAAG,kBAAkB,GAAG,iBAAiB,GAC3E,eAAe,GAAG,iBAAiB,GAAG,YAAY,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,EAAE,QAAQ,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggerTypes.js","sourceRoot":"","sources":["../../../src/decorators/types/triggerTypes.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
export { ParseClass, ParseField, getSchemaDefinition, onClassRegistered, onFieldRegistered
|
|
2
|
-
export type { ParseClassOptions, ParseFieldOptions, AllowedFieldType
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
1
|
+
export { ParseClass, ParseField, getSchemaDefinition, onClassRegistered, onFieldRegistered } from './decorators/parseDecorators';
|
|
2
|
+
export type { ParseClassOptions, ParseFieldOptions, AllowedFieldType } from './decorators/parseDecorators';
|
|
3
|
+
export { CloudFunction, ProtectedCloudFunction, onFunctionRegistered } from './decorators/cloudDecorator';
|
|
4
|
+
export { CloudFunctionRegistry } from './decorators/cloudRegistry';
|
|
5
|
+
export { BeforeSave, AfterSave, BeforeDelete, AfterDelete, BeforeFind, AfterFind, BeforeLogin, AfterLogin, AfterLogout, BeforeSaveFile, AfterSaveFile, BeforeDeleteFile, AfterDeleteFile, BeforeConnect, BeforeSubscribe, AfterEvent } from './decorators/triggerDecorator';
|
|
6
|
+
export { TriggerRegistry } from './decorators/triggerRegistry';
|
|
7
|
+
export { Cron, CronSchedule, CronRegistry } from './decorators/cronDecorator';
|
|
8
|
+
export { Route, RouteRegistry } from './decorators/routeDecorator';
|
|
9
|
+
export { classNames } from './decorators/types/schemaTypes';
|
|
10
|
+
export type { ClassNameType, CLPParamsOption, classLevelPermissions, ClassAclTemplate, AclTemplatePermissions, ProtectedFields, CompoundIndex, Fields, Indexes, SchemaDefinition } from './decorators/types/schemaTypes';
|
|
11
|
+
export type { HttpMethod, RouteConfig, CloudFunctionMetadata, SwaggerDocConfig } from './decorators/types/cloudTypes';
|
|
12
|
+
export type { TriggerType, TriggerMetadata, TriggerConfig } from './decorators/types/triggerTypes';
|
|
13
|
+
export type { CronJobMetadata, CronConfig } from './decorators/types/cronTypes';
|
|
14
|
+
export type { AuthRole, MultiLangs, Filter } from './decorators/types/common';
|
|
15
|
+
export { validateObject, validateOrThrow, getValidators, applyMongoValidators } from './decorators/types/fieldValidation';
|
|
5
16
|
export { BaseModel } from './models/BaseModel';
|
|
17
|
+
export { implementACL } from './utils/ACL';
|
|
18
|
+
export { UserRoles, roleKey, MAX_QUERY_LIMIT } from './utils/constants';
|
|
19
|
+
export type { RoleString } from './utils/constants';
|
|
20
|
+
export { catchError, getUserRoles, getUsersRoles, formatCount, generateRandomPassword, generateRandomInteger, generateRandomString, sleep } from './utils/helper';
|
|
21
|
+
export { importFiles } from './utils/dynamicImport';
|
|
22
|
+
export { validateFunctionRoutes, validateEntityRoutes, restrictRoutes, removeResultMiddleware, conditionalJsonMiddleware } from './middleware/middleware';
|
|
23
|
+
export { SwaggerRegistry } from './swagger/swaggerRegistry';
|
|
24
|
+
export type { SwaggerModelSchema, SwaggerPropertySchema, SwaggerFunctionSchema } from './swagger/swaggerRegistry';
|
|
25
|
+
export { generateSwaggerSpec, getSwaggerJson } from './swagger/swaggerSpec';
|
|
26
|
+
export { setupSwagger } from './swagger/index';
|
|
6
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,iBAAiB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AAc,EAAE,eAAe,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAG1H,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAC3D,sBAAsB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,cAAc,EACnE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAGrF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClH,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// @90soft/parse-server-kit
|
|
3
|
-
// Decorators + BaseModel + Schema Types
|
|
2
|
+
// @90soft/parse-server-kit — complete toolkit for Parse Server
|
|
4
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.BaseModel = exports.classNames = exports.onFieldRegistered = exports.onClassRegistered = exports.getSchemaDefinition = exports.ParseField = exports.ParseClass = void 0;
|
|
6
|
-
|
|
4
|
+
exports.importFiles = exports.sleep = exports.generateRandomString = exports.generateRandomInteger = exports.generateRandomPassword = exports.formatCount = exports.getUsersRoles = exports.getUserRoles = exports.catchError = exports.MAX_QUERY_LIMIT = exports.roleKey = exports.UserRoles = exports.implementACL = exports.BaseModel = exports.applyMongoValidators = exports.getValidators = exports.validateOrThrow = exports.validateObject = exports.classNames = exports.RouteRegistry = exports.Route = exports.CronRegistry = exports.CronSchedule = exports.Cron = exports.TriggerRegistry = exports.AfterEvent = exports.BeforeSubscribe = exports.BeforeConnect = exports.AfterDeleteFile = exports.BeforeDeleteFile = exports.AfterSaveFile = exports.BeforeSaveFile = exports.AfterLogout = exports.AfterLogin = exports.BeforeLogin = exports.AfterFind = exports.BeforeFind = exports.AfterDelete = exports.BeforeDelete = exports.AfterSave = exports.BeforeSave = exports.CloudFunctionRegistry = exports.onFunctionRegistered = exports.ProtectedCloudFunction = exports.CloudFunction = exports.onFieldRegistered = exports.onClassRegistered = exports.getSchemaDefinition = exports.ParseField = exports.ParseClass = void 0;
|
|
5
|
+
exports.setupSwagger = exports.getSwaggerJson = exports.generateSwaggerSpec = exports.SwaggerRegistry = exports.conditionalJsonMiddleware = exports.removeResultMiddleware = exports.restrictRoutes = exports.validateEntityRoutes = exports.validateFunctionRoutes = void 0;
|
|
6
|
+
// ── Decorators ──
|
|
7
7
|
var parseDecorators_1 = require("./decorators/parseDecorators");
|
|
8
8
|
Object.defineProperty(exports, "ParseClass", { enumerable: true, get: function () { return parseDecorators_1.ParseClass; } });
|
|
9
9
|
Object.defineProperty(exports, "ParseField", { enumerable: true, get: function () { return parseDecorators_1.ParseField; } });
|
|
10
10
|
Object.defineProperty(exports, "getSchemaDefinition", { enumerable: true, get: function () { return parseDecorators_1.getSchemaDefinition; } });
|
|
11
11
|
Object.defineProperty(exports, "onClassRegistered", { enumerable: true, get: function () { return parseDecorators_1.onClassRegistered; } });
|
|
12
12
|
Object.defineProperty(exports, "onFieldRegistered", { enumerable: true, get: function () { return parseDecorators_1.onFieldRegistered; } });
|
|
13
|
-
|
|
13
|
+
var cloudDecorator_1 = require("./decorators/cloudDecorator");
|
|
14
|
+
Object.defineProperty(exports, "CloudFunction", { enumerable: true, get: function () { return cloudDecorator_1.CloudFunction; } });
|
|
15
|
+
Object.defineProperty(exports, "ProtectedCloudFunction", { enumerable: true, get: function () { return cloudDecorator_1.ProtectedCloudFunction; } });
|
|
16
|
+
Object.defineProperty(exports, "onFunctionRegistered", { enumerable: true, get: function () { return cloudDecorator_1.onFunctionRegistered; } });
|
|
17
|
+
var cloudRegistry_1 = require("./decorators/cloudRegistry");
|
|
18
|
+
Object.defineProperty(exports, "CloudFunctionRegistry", { enumerable: true, get: function () { return cloudRegistry_1.CloudFunctionRegistry; } });
|
|
19
|
+
var triggerDecorator_1 = require("./decorators/triggerDecorator");
|
|
20
|
+
Object.defineProperty(exports, "BeforeSave", { enumerable: true, get: function () { return triggerDecorator_1.BeforeSave; } });
|
|
21
|
+
Object.defineProperty(exports, "AfterSave", { enumerable: true, get: function () { return triggerDecorator_1.AfterSave; } });
|
|
22
|
+
Object.defineProperty(exports, "BeforeDelete", { enumerable: true, get: function () { return triggerDecorator_1.BeforeDelete; } });
|
|
23
|
+
Object.defineProperty(exports, "AfterDelete", { enumerable: true, get: function () { return triggerDecorator_1.AfterDelete; } });
|
|
24
|
+
Object.defineProperty(exports, "BeforeFind", { enumerable: true, get: function () { return triggerDecorator_1.BeforeFind; } });
|
|
25
|
+
Object.defineProperty(exports, "AfterFind", { enumerable: true, get: function () { return triggerDecorator_1.AfterFind; } });
|
|
26
|
+
Object.defineProperty(exports, "BeforeLogin", { enumerable: true, get: function () { return triggerDecorator_1.BeforeLogin; } });
|
|
27
|
+
Object.defineProperty(exports, "AfterLogin", { enumerable: true, get: function () { return triggerDecorator_1.AfterLogin; } });
|
|
28
|
+
Object.defineProperty(exports, "AfterLogout", { enumerable: true, get: function () { return triggerDecorator_1.AfterLogout; } });
|
|
29
|
+
Object.defineProperty(exports, "BeforeSaveFile", { enumerable: true, get: function () { return triggerDecorator_1.BeforeSaveFile; } });
|
|
30
|
+
Object.defineProperty(exports, "AfterSaveFile", { enumerable: true, get: function () { return triggerDecorator_1.AfterSaveFile; } });
|
|
31
|
+
Object.defineProperty(exports, "BeforeDeleteFile", { enumerable: true, get: function () { return triggerDecorator_1.BeforeDeleteFile; } });
|
|
32
|
+
Object.defineProperty(exports, "AfterDeleteFile", { enumerable: true, get: function () { return triggerDecorator_1.AfterDeleteFile; } });
|
|
33
|
+
Object.defineProperty(exports, "BeforeConnect", { enumerable: true, get: function () { return triggerDecorator_1.BeforeConnect; } });
|
|
34
|
+
Object.defineProperty(exports, "BeforeSubscribe", { enumerable: true, get: function () { return triggerDecorator_1.BeforeSubscribe; } });
|
|
35
|
+
Object.defineProperty(exports, "AfterEvent", { enumerable: true, get: function () { return triggerDecorator_1.AfterEvent; } });
|
|
36
|
+
var triggerRegistry_1 = require("./decorators/triggerRegistry");
|
|
37
|
+
Object.defineProperty(exports, "TriggerRegistry", { enumerable: true, get: function () { return triggerRegistry_1.TriggerRegistry; } });
|
|
38
|
+
var cronDecorator_1 = require("./decorators/cronDecorator");
|
|
39
|
+
Object.defineProperty(exports, "Cron", { enumerable: true, get: function () { return cronDecorator_1.Cron; } });
|
|
40
|
+
Object.defineProperty(exports, "CronSchedule", { enumerable: true, get: function () { return cronDecorator_1.CronSchedule; } });
|
|
41
|
+
Object.defineProperty(exports, "CronRegistry", { enumerable: true, get: function () { return cronDecorator_1.CronRegistry; } });
|
|
42
|
+
var routeDecorator_1 = require("./decorators/routeDecorator");
|
|
43
|
+
Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return routeDecorator_1.Route; } });
|
|
44
|
+
Object.defineProperty(exports, "RouteRegistry", { enumerable: true, get: function () { return routeDecorator_1.RouteRegistry; } });
|
|
45
|
+
// ── Types ──
|
|
14
46
|
var schemaTypes_1 = require("./decorators/types/schemaTypes");
|
|
15
47
|
Object.defineProperty(exports, "classNames", { enumerable: true, get: function () { return schemaTypes_1.classNames; } });
|
|
16
|
-
//
|
|
48
|
+
// ── Validation ──
|
|
49
|
+
var fieldValidation_1 = require("./decorators/types/fieldValidation");
|
|
50
|
+
Object.defineProperty(exports, "validateObject", { enumerable: true, get: function () { return fieldValidation_1.validateObject; } });
|
|
51
|
+
Object.defineProperty(exports, "validateOrThrow", { enumerable: true, get: function () { return fieldValidation_1.validateOrThrow; } });
|
|
52
|
+
Object.defineProperty(exports, "getValidators", { enumerable: true, get: function () { return fieldValidation_1.getValidators; } });
|
|
53
|
+
Object.defineProperty(exports, "applyMongoValidators", { enumerable: true, get: function () { return fieldValidation_1.applyMongoValidators; } });
|
|
54
|
+
// ── Models ──
|
|
17
55
|
var BaseModel_1 = require("./models/BaseModel");
|
|
18
56
|
Object.defineProperty(exports, "BaseModel", { enumerable: true, get: function () { return BaseModel_1.BaseModel; } });
|
|
57
|
+
// ── ACL & Permissions ──
|
|
58
|
+
var ACL_1 = require("./utils/ACL");
|
|
59
|
+
Object.defineProperty(exports, "implementACL", { enumerable: true, get: function () { return ACL_1.implementACL; } });
|
|
60
|
+
var constants_1 = require("./utils/constants");
|
|
61
|
+
Object.defineProperty(exports, "UserRoles", { enumerable: true, get: function () { return constants_1.UserRoles; } });
|
|
62
|
+
Object.defineProperty(exports, "roleKey", { enumerable: true, get: function () { return constants_1.roleKey; } });
|
|
63
|
+
Object.defineProperty(exports, "MAX_QUERY_LIMIT", { enumerable: true, get: function () { return constants_1.MAX_QUERY_LIMIT; } });
|
|
64
|
+
// ── Utilities ──
|
|
65
|
+
var helper_1 = require("./utils/helper");
|
|
66
|
+
Object.defineProperty(exports, "catchError", { enumerable: true, get: function () { return helper_1.catchError; } });
|
|
67
|
+
Object.defineProperty(exports, "getUserRoles", { enumerable: true, get: function () { return helper_1.getUserRoles; } });
|
|
68
|
+
Object.defineProperty(exports, "getUsersRoles", { enumerable: true, get: function () { return helper_1.getUsersRoles; } });
|
|
69
|
+
Object.defineProperty(exports, "formatCount", { enumerable: true, get: function () { return helper_1.formatCount; } });
|
|
70
|
+
Object.defineProperty(exports, "generateRandomPassword", { enumerable: true, get: function () { return helper_1.generateRandomPassword; } });
|
|
71
|
+
Object.defineProperty(exports, "generateRandomInteger", { enumerable: true, get: function () { return helper_1.generateRandomInteger; } });
|
|
72
|
+
Object.defineProperty(exports, "generateRandomString", { enumerable: true, get: function () { return helper_1.generateRandomString; } });
|
|
73
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return helper_1.sleep; } });
|
|
74
|
+
var dynamicImport_1 = require("./utils/dynamicImport");
|
|
75
|
+
Object.defineProperty(exports, "importFiles", { enumerable: true, get: function () { return dynamicImport_1.importFiles; } });
|
|
76
|
+
// ── Middleware ──
|
|
77
|
+
var middleware_1 = require("./middleware/middleware");
|
|
78
|
+
Object.defineProperty(exports, "validateFunctionRoutes", { enumerable: true, get: function () { return middleware_1.validateFunctionRoutes; } });
|
|
79
|
+
Object.defineProperty(exports, "validateEntityRoutes", { enumerable: true, get: function () { return middleware_1.validateEntityRoutes; } });
|
|
80
|
+
Object.defineProperty(exports, "restrictRoutes", { enumerable: true, get: function () { return middleware_1.restrictRoutes; } });
|
|
81
|
+
Object.defineProperty(exports, "removeResultMiddleware", { enumerable: true, get: function () { return middleware_1.removeResultMiddleware; } });
|
|
82
|
+
Object.defineProperty(exports, "conditionalJsonMiddleware", { enumerable: true, get: function () { return middleware_1.conditionalJsonMiddleware; } });
|
|
83
|
+
// ── Swagger ──
|
|
84
|
+
var swaggerRegistry_1 = require("./swagger/swaggerRegistry");
|
|
85
|
+
Object.defineProperty(exports, "SwaggerRegistry", { enumerable: true, get: function () { return swaggerRegistry_1.SwaggerRegistry; } });
|
|
86
|
+
var swaggerSpec_1 = require("./swagger/swaggerSpec");
|
|
87
|
+
Object.defineProperty(exports, "generateSwaggerSpec", { enumerable: true, get: function () { return swaggerSpec_1.generateSwaggerSpec; } });
|
|
88
|
+
Object.defineProperty(exports, "getSwaggerJson", { enumerable: true, get: function () { return swaggerSpec_1.getSwaggerJson; } });
|
|
89
|
+
var index_1 = require("./swagger/index");
|
|
90
|
+
Object.defineProperty(exports, "setupSwagger", { enumerable: true, get: function () { return index_1.setupSwagger; } });
|
|
19
91
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+DAA+D;;;;AAE/D,mBAAmB;AACnB,gEAAiI;AAAxH,6GAAA,UAAU,OAAA;AAAE,6GAAA,UAAU,OAAA;AAAE,sHAAA,mBAAmB,OAAA;AAAE,oHAAA,iBAAiB,OAAA;AAAE,oHAAA,iBAAiB,OAAA;AAG1F,8DAA0G;AAAjG,+GAAA,aAAa,OAAA;AAAE,wHAAA,sBAAsB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AACpE,4DAAmE;AAA1D,sHAAA,qBAAqB,OAAA;AAE9B,kEAGoF;AAH3E,8GAAA,UAAU,OAAA;AAAE,6GAAA,SAAS,OAAA;AAAE,gHAAA,YAAY,OAAA;AAAE,+GAAA,WAAW,OAAA;AAAE,8GAAA,UAAU,OAAA;AAAE,6GAAA,SAAS,OAAA;AAC9E,+GAAA,WAAW,OAAA;AAAE,8GAAA,UAAU,OAAA;AAAE,+GAAA,WAAW,OAAA;AACpC,kHAAA,cAAc,OAAA;AAAE,iHAAA,aAAa,OAAA;AAAE,oHAAA,gBAAgB,OAAA;AAAE,mHAAA,eAAe,OAAA;AAChE,iHAAA,aAAa,OAAA;AAAE,mHAAA,eAAe,OAAA;AAAE,8GAAA,UAAU,OAAA;AAC5C,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;AAExB,4DAA8E;AAArE,qGAAA,IAAI,OAAA;AAAE,6GAAA,YAAY,OAAA;AAAE,6GAAA,YAAY,OAAA;AAEzC,8DAAmE;AAA1D,uGAAA,KAAK,OAAA;AAAE,+GAAA,aAAa,OAAA;AAE7B,cAAc;AACd,8DAA4D;AAAnD,yGAAA,UAAU,OAAA;AASnB,mBAAmB;AACnB,sEAA0H;AAAjH,iHAAA,cAAc,OAAA;AAAE,kHAAA,eAAe,OAAA;AAAE,gHAAA,aAAa,OAAA;AAAE,uHAAA,oBAAoB,OAAA;AAE7E,eAAe;AACf,gDAA+C;AAAtC,sGAAA,SAAS,OAAA;AAElB,0BAA0B;AAC1B,mCAA2C;AAAlC,mGAAA,YAAY,OAAA;AACrB,+CAAwE;AAA/D,sGAAA,SAAS,OAAA;AAAE,oGAAA,OAAO,OAAA;AAAE,4GAAA,eAAe,OAAA;AAG5C,kBAAkB;AAClB,yCACqG;AAD5F,oGAAA,UAAU,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AAAE,qGAAA,WAAW,OAAA;AAC3D,gHAAA,sBAAsB,OAAA;AAAE,+GAAA,qBAAqB,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,+FAAA,KAAK,OAAA;AAC5E,uDAAoD;AAA3C,4GAAA,WAAW,OAAA;AAEpB,mBAAmB;AACnB,sDACqF;AAD5E,oHAAA,sBAAsB,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AAAE,4GAAA,cAAc,OAAA;AACnE,oHAAA,sBAAsB,OAAA;AAAE,uHAAA,yBAAyB,OAAA;AAEnD,gBAAgB;AAChB,6DAA4D;AAAnD,kHAAA,eAAe,OAAA;AAExB,qDAA4E;AAAnE,kHAAA,mBAAmB,OAAA;AAAE,6GAAA,cAAc,OAAA;AAC5C,yCAA+C;AAAtC,qGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import express, { NextFunction, Request, Response } from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Validates legacy /functions/* routes.
|
|
4
|
+
* Skips if already handled by validateEntityRoutes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function validateFunctionRoutes(req: Request, res: Response, next: NextFunction): void | express.Response<any, Record<string, any>>;
|
|
7
|
+
/**
|
|
8
|
+
* Validates entity-based routes: /api/{entity}/{action}
|
|
9
|
+
* Resolves to a cloud function name and rewrites the URL for Parse Server.
|
|
10
|
+
*
|
|
11
|
+
* Flow:
|
|
12
|
+
* 1. Skip CORS preflight (OPTIONS)
|
|
13
|
+
* 2. Skip non-entity routes (pass to next middleware)
|
|
14
|
+
* 3. Resolve route → cloud function name
|
|
15
|
+
* 4. Validate HTTP method
|
|
16
|
+
* 5. Rewrite URL to /functions/{name} with query string preserved
|
|
17
|
+
* 6. Merge GET query params into body (Parse reads from body)
|
|
18
|
+
* 7. Convert to POST for Parse Server
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateEntityRoutes(req: Request, res: Response, next: NextFunction): void | express.Response<any, Record<string, any>>;
|
|
21
|
+
/**
|
|
22
|
+
* Extracts master key from the request body during JSON parsing.
|
|
23
|
+
* Used as the `verify` callback in express.json().
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractMasterKey(req: any, res: Response, buf: Buffer, encoding: BufferEncoding): void;
|
|
26
|
+
/**
|
|
27
|
+
* Restricts access to internal Parse Server endpoints.
|
|
28
|
+
* Only entity routes, system routes, and rewritten /functions routes pass through.
|
|
29
|
+
* Direct /classes, /schemas, /batch access is blocked.
|
|
30
|
+
*/
|
|
31
|
+
export declare function restrictRoutes(req: any, res: Response, next: NextFunction): void | express.Response<any, Record<string, any>>;
|
|
32
|
+
/**
|
|
33
|
+
* Conditionally applies JSON parsing middleware, skipping file upload routes.
|
|
34
|
+
*/
|
|
35
|
+
export declare function conditionalJsonMiddleware(req: Request, res: Response, next: NextFunction): void;
|
|
36
|
+
/**
|
|
37
|
+
* Removes the {result: ...} wrapper from Parse Server cloud function responses.
|
|
38
|
+
* Applies to entity routes and rewritten /functions routes.
|
|
39
|
+
*/
|
|
40
|
+
export declare function removeResultMiddleware(req: any, res: any, next: any): any;
|
|
41
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAC,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAKjE;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,qDAoBnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,qDA0CnB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,cAAc,QAUzB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,qDAwBzE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,QAWnB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,OAmBnE"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateFunctionRoutes = validateFunctionRoutes;
|
|
7
|
+
exports.validateEntityRoutes = validateEntityRoutes;
|
|
8
|
+
exports.extractMasterKey = extractMasterKey;
|
|
9
|
+
exports.restrictRoutes = restrictRoutes;
|
|
10
|
+
exports.conditionalJsonMiddleware = conditionalJsonMiddleware;
|
|
11
|
+
exports.removeResultMiddleware = removeResultMiddleware;
|
|
12
|
+
const express_1 = __importDefault(require("express"));
|
|
13
|
+
const cloudRegistry_1 = require("../decorators/cloudRegistry");
|
|
14
|
+
const routeDecorator_1 = require("../decorators/routeDecorator");
|
|
15
|
+
/**
|
|
16
|
+
* Validates legacy /functions/* routes.
|
|
17
|
+
* Skips if already handled by validateEntityRoutes.
|
|
18
|
+
*/
|
|
19
|
+
function validateFunctionRoutes(req, res, next) {
|
|
20
|
+
// Skip if already handled by entity route middleware
|
|
21
|
+
if (req._entityRouteHandled) {
|
|
22
|
+
return next();
|
|
23
|
+
}
|
|
24
|
+
const functionName = req.path.split('/')[1];
|
|
25
|
+
const metadata = cloudRegistry_1.CloudFunctionRegistry.getFunction(functionName);
|
|
26
|
+
if (!metadata) {
|
|
27
|
+
return res.status(404).json({ message: 'Function not found' });
|
|
28
|
+
}
|
|
29
|
+
if (!metadata.config.methods.includes(req.method)) {
|
|
30
|
+
return res.status(405).json({ message: 'Method not allowed' });
|
|
31
|
+
}
|
|
32
|
+
req.method = 'POST';
|
|
33
|
+
return next();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validates entity-based routes: /api/{entity}/{action}
|
|
37
|
+
* Resolves to a cloud function name and rewrites the URL for Parse Server.
|
|
38
|
+
*
|
|
39
|
+
* Flow:
|
|
40
|
+
* 1. Skip CORS preflight (OPTIONS)
|
|
41
|
+
* 2. Skip non-entity routes (pass to next middleware)
|
|
42
|
+
* 3. Resolve route → cloud function name
|
|
43
|
+
* 4. Validate HTTP method
|
|
44
|
+
* 5. Rewrite URL to /functions/{name} with query string preserved
|
|
45
|
+
* 6. Merge GET query params into body (Parse reads from body)
|
|
46
|
+
* 7. Convert to POST for Parse Server
|
|
47
|
+
*/
|
|
48
|
+
function validateEntityRoutes(req, res, next) {
|
|
49
|
+
const routePath = req.path;
|
|
50
|
+
// Skip CORS preflight — let cors() middleware handle them
|
|
51
|
+
if (req.method === 'OPTIONS') {
|
|
52
|
+
return next();
|
|
53
|
+
}
|
|
54
|
+
// Only handle requests that match a registered entity prefix
|
|
55
|
+
if (!routeDecorator_1.RouteRegistry.isRegisteredPrefix(routePath)) {
|
|
56
|
+
return next();
|
|
57
|
+
}
|
|
58
|
+
const functionName = routeDecorator_1.RouteRegistry.resolve(routePath);
|
|
59
|
+
if (!functionName) {
|
|
60
|
+
return res.status(404).json({ message: 'Route not found' });
|
|
61
|
+
}
|
|
62
|
+
const metadata = cloudRegistry_1.CloudFunctionRegistry.getFunction(functionName);
|
|
63
|
+
if (!metadata) {
|
|
64
|
+
return res.status(404).json({ message: 'Function not found' });
|
|
65
|
+
}
|
|
66
|
+
if (!metadata.config.methods.includes(req.method)) {
|
|
67
|
+
return res.status(405).json({ message: 'Method not allowed' });
|
|
68
|
+
}
|
|
69
|
+
// Rewrite URL to /functions/{functionName} so Parse Server handles it
|
|
70
|
+
// Preserve query string for GET requests
|
|
71
|
+
const queryString = req.originalUrl.split('?')[1];
|
|
72
|
+
req.url = `/functions/${functionName}${queryString ? '?' + queryString : ''}`;
|
|
73
|
+
// Merge GET query params into body — Parse Server reads params from body
|
|
74
|
+
if (req.method === 'GET' && req.query && Object.keys(req.query).length > 0) {
|
|
75
|
+
req.body = { ...req.body, ...req.query };
|
|
76
|
+
}
|
|
77
|
+
req.method = 'POST';
|
|
78
|
+
req._entityRouteHandled = true;
|
|
79
|
+
return next();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Extracts master key from the request body during JSON parsing.
|
|
83
|
+
* Used as the `verify` callback in express.json().
|
|
84
|
+
*/
|
|
85
|
+
function extractMasterKey(req, res, buf, encoding) {
|
|
86
|
+
try {
|
|
87
|
+
const body = JSON.parse(buf.toString(encoding));
|
|
88
|
+
if (body && (body.masterKey || body._MasterKey)) {
|
|
89
|
+
req['x-master-key'] = body.masterKey || body._MasterKey;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
throw res.status(400).json({ message: 'Error parsing JSON body' });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Restricts access to internal Parse Server endpoints.
|
|
98
|
+
* Only entity routes, system routes, and rewritten /functions routes pass through.
|
|
99
|
+
* Direct /classes, /schemas, /batch access is blocked.
|
|
100
|
+
*/
|
|
101
|
+
function restrictRoutes(req, res, next) {
|
|
102
|
+
const systemRoutes = ['/health', '/serverInfo', '/files'];
|
|
103
|
+
// Master key bypasses all restrictions
|
|
104
|
+
if (req['x-master-key'] === process.env.masterKey) {
|
|
105
|
+
return next();
|
|
106
|
+
}
|
|
107
|
+
// Allow system routes
|
|
108
|
+
if (systemRoutes.some(route => req.path.startsWith(route))) {
|
|
109
|
+
return next();
|
|
110
|
+
}
|
|
111
|
+
// Allow registered entity route prefixes
|
|
112
|
+
if (routeDecorator_1.RouteRegistry.isRegisteredPrefix(req.path)) {
|
|
113
|
+
return next();
|
|
114
|
+
}
|
|
115
|
+
// Allow /functions for internal use (rewritten by validateEntityRoutes)
|
|
116
|
+
if (req.path.startsWith('/functions')) {
|
|
117
|
+
return next();
|
|
118
|
+
}
|
|
119
|
+
return res.status(403).json({ message: 'Route not allowed' });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Conditionally applies JSON parsing middleware, skipping file upload routes.
|
|
123
|
+
*/
|
|
124
|
+
function conditionalJsonMiddleware(req, res, next) {
|
|
125
|
+
if (req.path.startsWith(`${process.env.mountPath}/files`)) {
|
|
126
|
+
return next();
|
|
127
|
+
}
|
|
128
|
+
express_1.default.json({
|
|
129
|
+
limit: '10mb',
|
|
130
|
+
type: ['text/plain'],
|
|
131
|
+
verify: extractMasterKey,
|
|
132
|
+
})(req, res, next);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Removes the {result: ...} wrapper from Parse Server cloud function responses.
|
|
136
|
+
* Applies to entity routes and rewritten /functions routes.
|
|
137
|
+
*/
|
|
138
|
+
function removeResultMiddleware(req, res, next) {
|
|
139
|
+
const mountPath = process.env.mountPath || '/api';
|
|
140
|
+
const pathAfterMount = req.path.replace(mountPath, '');
|
|
141
|
+
const isEntityRoute = routeDecorator_1.RouteRegistry.isRegisteredPrefix(pathAfterMount);
|
|
142
|
+
const isFunctionRoute = req.path.includes('/functions');
|
|
143
|
+
if (!isEntityRoute && !isFunctionRoute)
|
|
144
|
+
return next();
|
|
145
|
+
const originalJson = res.json.bind(res);
|
|
146
|
+
res.json = (body) => {
|
|
147
|
+
if (body && typeof body === 'object' && 'result' in body) {
|
|
148
|
+
return originalJson(body.result);
|
|
149
|
+
}
|
|
150
|
+
return originalJson(body);
|
|
151
|
+
};
|
|
152
|
+
next();
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware/middleware.ts"],"names":[],"mappings":";;;;;AASA,wDAuBC;AAeD,oDA6CC;AAMD,4CAcC;AAOD,wCAwBC;AAKD,8DAcC;AAMD,wDAmBC;AA3LD,sDAAiE;AACjE,+DAAkE;AAClE,iEAA2D;AAG3D;;;GAGG;AACH,SAAgB,sBAAsB,CACpC,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,qDAAqD;IACrD,IAAK,GAAW,CAAC,mBAAmB,EAAE,CAAC;QACrC,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,qCAAqB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAEjE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC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QAC1D,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,iBAAO,CAAC,IAAI,CAAC;QACX,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,CAAC,YAAY,CAAC;QACpB,MAAM,EAAE,gBAAgB;KACzB,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAS;IAClE,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM,CAAC;IAClD,MAAM,cAAc,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAEvD,MAAM,aAAa,GAAG,8BAAa,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACvE,MAAM,eAAe,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAExD,IAAI,CAAC,aAAa,IAAI,CAAC,eAAe;QAAE,OAAO,IAAI,EAAE,CAAC;IAEtD,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAExC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAS,EAAE,EAAE;QACvB,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACzD,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;IAEF,IAAI,EAAE,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import { SwaggerConfig } from './swaggerSpec';
|
|
3
|
+
export { SwaggerRegistry } from './swaggerRegistry';
|
|
4
|
+
export { generateSwaggerSpec, getSwaggerJson } from './swaggerSpec';
|
|
5
|
+
/**
|
|
6
|
+
* Setup Swagger UI for the Express app
|
|
7
|
+
*/
|
|
8
|
+
export declare function setupSwagger(app: Express, config: SwaggerConfig, path?: string): void;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/swagger/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAsB,aAAa,EAAC,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,mBAAmB,EAAE,cAAc,EAAC,MAAM,eAAe,CAAC;AAElE;;GAEG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,aAAa,EACrB,IAAI,GAAE,MAAoB,QA0B3B"}
|