@extk/expressive 0.5.2 → 0.5.4
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/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +34 -0
- package/dist/index.mjs +34 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -232,6 +232,7 @@ declare class SwaggerBuilder {
|
|
|
232
232
|
withDefaultSecurity(globalAuthMethods: AuthMethod[]): this;
|
|
233
233
|
get(): SwaggerConfig;
|
|
234
234
|
}
|
|
235
|
+
declare function formDataSchema(schema: Schema): Content;
|
|
235
236
|
declare function jsonSchema(schema: Schema): Content;
|
|
236
237
|
declare function jsonSchemaRef(name: string): Content;
|
|
237
238
|
declare function param(inP: Param['in'], id: string, schema: Schema, required?: boolean, description?: string, name?: string): Param;
|
|
@@ -243,6 +244,7 @@ declare const SWG: {
|
|
|
243
244
|
pathParam: typeof pathParam;
|
|
244
245
|
queryParam: typeof queryParam;
|
|
245
246
|
headerParam: typeof headerParam;
|
|
247
|
+
formDataSchema: typeof formDataSchema;
|
|
246
248
|
jsonSchema: typeof jsonSchema;
|
|
247
249
|
jsonSchemaRef: typeof jsonSchemaRef;
|
|
248
250
|
security: (name: string) => AuthMethod;
|
|
@@ -286,6 +288,7 @@ declare function bootstrap(container: Container): {
|
|
|
286
288
|
silently: (fn: () => Promise<void> | void) => Promise<void>;
|
|
287
289
|
notFoundMiddleware: (_req: express.Request, res: express.Response, _next: express.NextFunction) => void;
|
|
288
290
|
getErrorHandlerMiddleware: (errorMapper?: (err: Error & Record<string, unknown>) => ApiError | null | undefined) => (err: Error & Record<string, unknown>, req: express.Request, res: express.Response, _next: express.NextFunction) => Promise<void>;
|
|
291
|
+
getBasicAuthMiddleware: (basicAuthBase64: string, basicRealm?: string) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
|
|
289
292
|
expressiveServer: (configs?: {
|
|
290
293
|
app?: express.Express;
|
|
291
294
|
}) => ServerBuilder;
|
package/dist/index.d.ts
CHANGED
|
@@ -232,6 +232,7 @@ declare class SwaggerBuilder {
|
|
|
232
232
|
withDefaultSecurity(globalAuthMethods: AuthMethod[]): this;
|
|
233
233
|
get(): SwaggerConfig;
|
|
234
234
|
}
|
|
235
|
+
declare function formDataSchema(schema: Schema): Content;
|
|
235
236
|
declare function jsonSchema(schema: Schema): Content;
|
|
236
237
|
declare function jsonSchemaRef(name: string): Content;
|
|
237
238
|
declare function param(inP: Param['in'], id: string, schema: Schema, required?: boolean, description?: string, name?: string): Param;
|
|
@@ -243,6 +244,7 @@ declare const SWG: {
|
|
|
243
244
|
pathParam: typeof pathParam;
|
|
244
245
|
queryParam: typeof queryParam;
|
|
245
246
|
headerParam: typeof headerParam;
|
|
247
|
+
formDataSchema: typeof formDataSchema;
|
|
246
248
|
jsonSchema: typeof jsonSchema;
|
|
247
249
|
jsonSchemaRef: typeof jsonSchemaRef;
|
|
248
250
|
security: (name: string) => AuthMethod;
|
|
@@ -286,6 +288,7 @@ declare function bootstrap(container: Container): {
|
|
|
286
288
|
silently: (fn: () => Promise<void> | void) => Promise<void>;
|
|
287
289
|
notFoundMiddleware: (_req: express.Request, res: express.Response, _next: express.NextFunction) => void;
|
|
288
290
|
getErrorHandlerMiddleware: (errorMapper?: (err: Error & Record<string, unknown>) => ApiError | null | undefined) => (err: Error & Record<string, unknown>, req: express.Request, res: express.Response, _next: express.NextFunction) => Promise<void>;
|
|
291
|
+
getBasicAuthMiddleware: (basicAuthBase64: string, basicRealm?: string) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
|
|
289
292
|
expressiveServer: (configs?: {
|
|
290
293
|
app?: express.Express;
|
|
291
294
|
}) => ServerBuilder;
|
package/dist/index.js
CHANGED
|
@@ -131,6 +131,15 @@ var security = (name) => {
|
|
|
131
131
|
}
|
|
132
132
|
return securityRegistry[name];
|
|
133
133
|
};
|
|
134
|
+
function formDataSchema(schema) {
|
|
135
|
+
return {
|
|
136
|
+
content: {
|
|
137
|
+
"multipart/form-data": {
|
|
138
|
+
schema
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
134
143
|
function jsonSchema(schema) {
|
|
135
144
|
return {
|
|
136
145
|
content: {
|
|
@@ -176,6 +185,7 @@ var SWG = {
|
|
|
176
185
|
pathParam,
|
|
177
186
|
queryParam,
|
|
178
187
|
headerParam,
|
|
188
|
+
formDataSchema,
|
|
179
189
|
jsonSchema,
|
|
180
190
|
jsonSchemaRef,
|
|
181
191
|
security,
|
|
@@ -422,6 +432,30 @@ var buildMiddleware = (container) => {
|
|
|
422
432
|
}
|
|
423
433
|
res.status(finalError.httpStatusCode).json(new ApiErrorResponse(finalError.message, finalError.code, finalError.data));
|
|
424
434
|
};
|
|
435
|
+
},
|
|
436
|
+
getBasicAuthMiddleware: (basicAuthBase64, basicRealm) => {
|
|
437
|
+
return (req, res, next) => {
|
|
438
|
+
try {
|
|
439
|
+
const token = req.header("authorization");
|
|
440
|
+
if (!token || token.indexOf("Basic ") === -1) {
|
|
441
|
+
throw new UserUnauthorizedError("Missing Authorization Header");
|
|
442
|
+
}
|
|
443
|
+
const credentials = token.split(" ")[1];
|
|
444
|
+
if (basicAuthBase64 !== credentials) {
|
|
445
|
+
throw new UserUnauthorizedError("Invalid Authentication Credentials");
|
|
446
|
+
}
|
|
447
|
+
next();
|
|
448
|
+
} catch (error) {
|
|
449
|
+
if (basicRealm) {
|
|
450
|
+
res.set("WWW-Authenticate", `Basic realm="${basicRealm}"`);
|
|
451
|
+
}
|
|
452
|
+
if (error instanceof ApiError) {
|
|
453
|
+
return next(error);
|
|
454
|
+
}
|
|
455
|
+
logger.error(error);
|
|
456
|
+
return next(new UserUnauthorizedError());
|
|
457
|
+
}
|
|
458
|
+
};
|
|
425
459
|
}
|
|
426
460
|
};
|
|
427
461
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -70,6 +70,15 @@ var security = (name) => {
|
|
|
70
70
|
}
|
|
71
71
|
return securityRegistry[name];
|
|
72
72
|
};
|
|
73
|
+
function formDataSchema(schema) {
|
|
74
|
+
return {
|
|
75
|
+
content: {
|
|
76
|
+
"multipart/form-data": {
|
|
77
|
+
schema
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
73
82
|
function jsonSchema(schema) {
|
|
74
83
|
return {
|
|
75
84
|
content: {
|
|
@@ -115,6 +124,7 @@ var SWG = {
|
|
|
115
124
|
pathParam,
|
|
116
125
|
queryParam,
|
|
117
126
|
headerParam,
|
|
127
|
+
formDataSchema,
|
|
118
128
|
jsonSchema,
|
|
119
129
|
jsonSchemaRef,
|
|
120
130
|
security,
|
|
@@ -361,6 +371,30 @@ var buildMiddleware = (container) => {
|
|
|
361
371
|
}
|
|
362
372
|
res.status(finalError.httpStatusCode).json(new ApiErrorResponse(finalError.message, finalError.code, finalError.data));
|
|
363
373
|
};
|
|
374
|
+
},
|
|
375
|
+
getBasicAuthMiddleware: (basicAuthBase64, basicRealm) => {
|
|
376
|
+
return (req, res, next) => {
|
|
377
|
+
try {
|
|
378
|
+
const token = req.header("authorization");
|
|
379
|
+
if (!token || token.indexOf("Basic ") === -1) {
|
|
380
|
+
throw new UserUnauthorizedError("Missing Authorization Header");
|
|
381
|
+
}
|
|
382
|
+
const credentials = token.split(" ")[1];
|
|
383
|
+
if (basicAuthBase64 !== credentials) {
|
|
384
|
+
throw new UserUnauthorizedError("Invalid Authentication Credentials");
|
|
385
|
+
}
|
|
386
|
+
next();
|
|
387
|
+
} catch (error) {
|
|
388
|
+
if (basicRealm) {
|
|
389
|
+
res.set("WWW-Authenticate", `Basic realm="${basicRealm}"`);
|
|
390
|
+
}
|
|
391
|
+
if (error instanceof ApiError) {
|
|
392
|
+
return next(error);
|
|
393
|
+
}
|
|
394
|
+
logger.error(error);
|
|
395
|
+
return next(new UserUnauthorizedError());
|
|
396
|
+
}
|
|
397
|
+
};
|
|
364
398
|
}
|
|
365
399
|
};
|
|
366
400
|
};
|