temba 0.11.0 → 0.12.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 CHANGED
@@ -62,7 +62,7 @@ Alternatively, add Temba to your app manually:
62
62
  2. Example code to create a Temba server:
63
63
 
64
64
  ```js
65
- import temba from "temba"
65
+ import temba from 'temba'
66
66
  const server = temba.create()
67
67
 
68
68
  const port = process.env.PORT || 3000
@@ -226,14 +226,10 @@ const config = {
226
226
  requestBodyValidator: {
227
227
  post: (resourceName, requestBody) => {
228
228
  // Do not allow Pokemons to be created: 400 Bad Request
229
- if (resourceName === 'pokemons')
230
- return 'You are not allowed to create new Pokemons'
229
+ if (resourceName === 'pokemons') return 'You are not allowed to create new Pokemons'
231
230
 
232
231
  // Add a genre to Star Trek films:
233
- if (
234
- resourceName === 'movies' &&
235
- requestBody.title.startsWith('Star Trek')
236
- )
232
+ if (resourceName === 'movies' && requestBody.title.startsWith('Star Trek'))
237
233
  return { ...requestBody, genre: 'Science Fiction' }
238
234
 
239
235
  // If you end up here, void will be returned, so the request will just be saved.
@@ -244,6 +240,46 @@ const config = {
244
240
  const server = temba.create(config)
245
241
  ```
246
242
 
243
+ ## Response body interception
244
+
245
+ To change the response body of a `GET` request, configure a `responseBodyInterceptor`, and return the updated response body:
246
+
247
+ ```js
248
+ const config = {
249
+ responseBodyInterceptor: (resourceName, responseBody, id) => {
250
+ if (resourceName === 'movies') {
251
+ if (id) {
252
+ // responseBody is an object
253
+ return {
254
+ ...responseBody,
255
+ stuff: 'more stuff',
256
+ }
257
+ } else {
258
+ // responseBody is an array
259
+ return responseBody.map((x) => ({
260
+ ...x,
261
+ stuff: 'more stuff',
262
+ }))
263
+ }
264
+ }
265
+
266
+ // If you end up here, the response body will just be returned unchanged.
267
+ },
268
+ }
269
+
270
+ const server = temba.create(config)
271
+ ```
272
+
273
+ `responseBodyInterceptor` is a callback function that provides the `resourceName`, `responseBody`, and the `id`. Depending on whether it's a collection or item request, the `responseBody` is either an array or object, and the `id' can be `undefined`.
274
+
275
+ In the example above we check for the `id` being defined, but a runtime check to determine the type of `responseBody` would also suffice.
276
+
277
+ Whatever you return in this function will become the response body and will be serialized as JSON and returned to the client.
278
+
279
+ If you don't return anything, the response body will be sent as-is.
280
+
281
+ The `responseBodyInterceptor` will only be called when the response was successful, i.e. a `200 OK` status code.
282
+
247
283
  ## Custom router
248
284
 
249
285
  Although `temba.create()` returns an Express instance, adding your own routes, as you would normally do with Express, is not possible:
@@ -280,7 +316,7 @@ router.get('/about', (req, res) => {
280
316
 
281
317
  // Add the custom router to Temba config
282
318
  const config = {
283
- customRouter: router
319
+ customRouter: router,
284
320
  }
285
321
 
286
322
  const server = temba.create(config)
@@ -312,10 +348,10 @@ const config = {
312
348
  const server = temba.create(config)
313
349
  ```
314
350
 
315
- * `/` will be handled by Temba, and will return the `staticFolder` (`build`) folder contents
316
- * `/stuff` and `/api/stuff` will be handled by the custom router
317
- * `/movies` will return a `404 Not Found`, because of `apiPrefix`
318
- * `/api/movies` will return movies, handled by Temba
351
+ - `/` will be handled by Temba, and will return the `staticFolder` (`build`) folder contents
352
+ - `/stuff` and `/api/stuff` will be handled by the custom router
353
+ - `/movies` will return a `404 Not Found`, because of `apiPrefix`
354
+ - `/api/movies` will return movies, handled by Temba
319
355
 
320
356
  ### Config settings overview
321
357
 
@@ -356,8 +392,8 @@ These are all the possible settings:
356
392
  | `resourceNames` | See [Allowing specific resources only](#allowing-specific-resources-only) |
357
393
  | `connectionString` | See [MongoDB](#mongodb) |
358
394
  | `staticFolder` | See [Static assets](#static-assets) |
359
- | `apiPrefix` | See [API prefix](#api-prefix) |
360
- | `customRouter` | See [Custom router](#custom-router) |
395
+ | `apiPrefix` | See [API prefix](#api-prefix) |
396
+ | `customRouter` | See [Custom router](#custom-router) |
361
397
  | `cacheControl` | The `Cache-control` response header value for each GET request. |
362
398
  | `delay` | After processing the request, the delay in milliseconds before the request should be sent. |
363
399
  | `requestBodyValidator` | See [Request body validation or mutation](#request-body-validation-or-mutation) |
package/config/index.d.ts CHANGED
@@ -1,17 +1,18 @@
1
1
  import { Router } from 'express';
2
- import { RequestBodyValidator } from '../routes/types';
2
+ import { RequestBodyValidator, ResponseBodyInterceptor } from '../routes/types';
3
3
  export declare type Config = {
4
4
  validateResources: boolean;
5
5
  resourceNames: string[];
6
6
  apiPrefix: string;
7
7
  cacheControl: string;
8
8
  requestBodyValidator: RequestBodyValidator;
9
+ responseBodyInterceptor: ResponseBodyInterceptor;
9
10
  staticFolder: string;
10
11
  connectionString: string;
11
12
  delay: number;
12
13
  customRouter: Router;
13
14
  };
14
- export declare type RouterConfig = Pick<Config, 'validateResources' | 'resourceNames' | 'apiPrefix' | 'cacheControl' | 'requestBodyValidator'>;
15
+ export declare type RouterConfig = Pick<Config, 'validateResources' | 'resourceNames' | 'apiPrefix' | 'cacheControl' | 'requestBodyValidator' | 'responseBodyInterceptor'>;
15
16
  export declare type UserConfig = {
16
17
  resourceNames?: string[];
17
18
  validateResources?: boolean;
@@ -21,6 +22,7 @@ export declare type UserConfig = {
21
22
  cacheControl?: string;
22
23
  delay?: number;
23
24
  requestBodyValidator?: RequestBodyValidator;
25
+ responseBodyInterceptor?: ResponseBodyInterceptor;
24
26
  customRouter?: Router;
25
27
  };
26
28
  export declare function initConfig(userConfig: UserConfig): Config;
package/config/index.js CHANGED
@@ -20,6 +20,9 @@ const defaultConfig = {
20
20
  // do nothing
21
21
  },
22
22
  },
23
+ responseBodyInterceptor: (resourceName, responseBody, id) => {
24
+ return responseBody;
25
+ },
23
26
  customRouter: null,
24
27
  };
25
28
  function initConfig(userConfig) {
@@ -64,6 +67,9 @@ function initConfig(userConfig) {
64
67
  config.requestBodyValidator.put = userConfig.requestBodyValidator.put;
65
68
  }
66
69
  }
70
+ if (userConfig.responseBodyInterceptor) {
71
+ config.responseBodyInterceptor = userConfig.responseBodyInterceptor;
72
+ }
67
73
  if (userConfig.customRouter) {
68
74
  config.customRouter = userConfig.customRouter;
69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,GAAG,CAAA;SACtE;KACF;IAED,IAAI,UAAU,CAAC,uBAAuB,EAAE;QACtC,MAAM,CAAC,uBAAuB,GAAG,UAAU,CAAC,uBAAuB,CAAA;KACpE;IAED,IAAI,UAAU,CAAC,YAAY,EAAE;QAC3B,MAAM,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAA;KAC9C;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAnED,gCAmEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "temba",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "description": "Get a simple MongoDB REST API with zero coding in less than 30 seconds (seriously).",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/routes/get.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare function createGetRoutes(queries: any, cacheControl: any): {
1
+ declare function createGetRoutes(queries: any, cacheControl: any, responseBodyInterceptor: any): {
2
2
  handleGetResource: (req: any, res: any, next: any) => Promise<any>;
3
3
  };
4
4
  export { createGetRoutes };
package/routes/get.js CHANGED
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createGetRoutes = void 0;
13
- function createGetRoutes(queries, cacheControl) {
13
+ function createGetRoutes(queries, cacheControl, responseBodyInterceptor) {
14
14
  function handleGetResource(req, res, next) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  try {
@@ -22,13 +22,43 @@ function createGetRoutes(queries, cacheControl) {
22
22
  res.status(404);
23
23
  return res.send();
24
24
  }
25
+ let theItem = item;
26
+ if (responseBodyInterceptor) {
27
+ try {
28
+ theItem = responseBodyInterceptor(resourceName, item, id);
29
+ if (!theItem)
30
+ theItem = item;
31
+ }
32
+ catch (error) {
33
+ return res
34
+ .status(500)
35
+ .json({
36
+ message: 'Error in responseBodyInterceptor: ' + error.message,
37
+ });
38
+ }
39
+ }
25
40
  res.status(200);
26
- res.json(item);
41
+ res.json(theItem);
27
42
  return res.send();
28
43
  }
29
44
  const items = yield queries.getAll(resourceName);
45
+ let theItems = items;
46
+ if (responseBodyInterceptor) {
47
+ try {
48
+ theItems = responseBodyInterceptor(resourceName, items);
49
+ if (!theItems)
50
+ theItems = items;
51
+ }
52
+ catch (error) {
53
+ return res
54
+ .status(500)
55
+ .json({
56
+ message: 'Error in responseBodyInterceptor: ' + error.message,
57
+ });
58
+ }
59
+ }
30
60
  res.status(200);
31
- res.json(items);
61
+ res.json(theItems);
32
62
  return res.send();
33
63
  }
34
64
  catch (error) {
package/routes/get.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/routes/get.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAS,eAAe,CAAC,OAAO,EAAE,YAAY;IAC5C,SAAe,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI;;YAC7C,IAAI;gBACF,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;gBAE5C,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,CAAA;gBAEtC,IAAI,EAAE,EAAE;oBACN,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;oBAEpD,IAAI,CAAC,IAAI,EAAE;wBACT,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;wBACf,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;qBAClB;oBAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;oBACf,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBACd,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;iBAClB;gBAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;gBAChD,GAAG,CAAC,MAAM,CAAC,G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BACL;qBACF;oBAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;oBACf,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;oBACjB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;iBAClB;gBAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;gBAEhD,IAAI,QAAQ,GAAG,KAAK,CAAA;gBACpB,IAAI,uBAAuB,EAAE;oBAC3B,IAAI;wBACF,QAAQ,GAAG,uBAAuB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;wBACvD,IAAI,CAAC,QAAQ;4BAAE,QAAQ,GAAG,KAAK,CAAA;qBAChC;oBAAC,OAAO,KAAK,EAAE;wBACd,OAAO,GAAG;6BACP,MAAM,CAAC,GAAG,CAAC;6BACX,IAAI,CAAC;4BACJ,OAAO,EAAE,oCAAoC,GAAG,KAAK,CAAC,OAAO;yBAC9D,CAAC,CAAA;qBACL;iBACF;gBAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBACf,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBAClB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;aAClB;YAAC,OAAO,KAAc,EAAE;gBACvB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;aACnB;QACH,CAAC;KAAA;IAED,OAAO;QACL,iBAAiB;KAClB,CAAA;AACH,CAAC;AAEQ,0CAAe"}
@@ -1,5 +1,5 @@
1
1
  import { RouterConfig } from '../config';
2
- declare function createResourceRouter(queries: any, routerCounfig: RouterConfig): import("express-serve-static-core").Router;
2
+ declare function createResourceRouter(queries: any, routerConfig: RouterConfig): import("express-serve-static-core").Router;
3
3
  declare const rootRouter: import("express-serve-static-core").Router;
4
4
  declare function handleMethodNotAllowed(_: any, res: any): void;
5
5
  declare function handleNotFound(_: any, res: any): void;
package/routes/routes.js CHANGED
@@ -20,9 +20,9 @@ const patch_1 = require("./patch");
20
20
  const delete_1 = require("./delete");
21
21
  const urlMiddleware_1 = require("../urls/urlMiddleware");
22
22
  const express_1 = __importDefault(require("express"));
23
- function createResourceRouter(queries, routerCounfig) {
24
- const { validateResources, resourceNames, apiPrefix, cacheControl, requestBodyValidator, } = routerCounfig;
25
- const { handleGetResource } = (0, get_1.createGetRoutes)(queries, cacheControl);
23
+ function createResourceRouter(queries, routerConfig) {
24
+ const { validateResources, resourceNames, apiPrefix, cacheControl, requestBodyValidator, responseBodyInterceptor, } = routerConfig;
25
+ const { handleGetResource } = (0, get_1.createGetRoutes)(queries, cacheControl, responseBodyInterceptor);
26
26
  const { handlePost } = (0, post_1.createPostRoutes)(queries, requestBodyValidator);
27
27
  const { handlePut } = (0, put_1.createPutRoutes)(queries, requestBodyValidator);
28
28
  const { handlePatch } = (0, patch_1.createPatchRoutes)(queries, requestBodyValidator);
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes/routes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuC;AACvC,iCAAyC;AACzC,+BAAuC;AACvC,mCAA2C;AAC3C,qCAA6C;AAC7C,yDAG8B;AAE9B,sDAA6B;AAG7B,SAAS,oBAAoB,CAC3B,OAAO,EACP,aAA2B;IAG3B,MAAM,EACJ,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,YAAY,EACZ,oBAAoB,GACrB,GAAG,aAAa,CAAA;IACjB,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,qBAAe,EAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IACpE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,uBAAgB,EAAC,OAAO,EAAE,oBAAoB,CAAC,CAAA;IACtE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,qBAAe,EAAC,OAAO,EAAE,oBAAoB,CAAC,CAAA;IACpE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,yBAAiB,EAAC,OAAO,EAAE,oBAAoB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
6
6
  };
7
+ export declare type ResponseBodyInterceptor = (resourceName: string, responseBody: unknown, id?: string) => unknown;