@flowerforce/flowerbase 1.8.1-beta.1 → 1.8.1-beta.2

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
@@ -484,6 +484,7 @@ Ensure the following environment variables are set in your .env file or deployme
484
484
  | `PORT` | The port on which the server will run. | `3000` |
485
485
  | `MONGODB_URL` | MongoDB connection URI, including username, password, and database name. | `mongodb+srv://user:pass@cluster.mongodb.net/mydb` |
486
486
  | `JWT_SECRET` | Secret used to sign and verify JWT tokens (choose a strong secret). | `supersecretkey123!` |
487
+ | `FUNCTION_CALL_BODY_LIMIT_BYTES` | Max request body size in bytes for `POST /api/client/<version>/app/:appId/functions/call`. | `52428800` |
487
488
  | `HOST` | The host address the server binds to (usually `0.0.0.0` for public access). | `0.0.0.0` |
488
489
  | `API_VERSION` | API version used in client base path. | `v2.0` |
489
490
  | `HTTPS_SCHEMA` | The schema for your server requests (usually `https` or `http`). | `http` |
@@ -518,6 +519,7 @@ PROJECT_ID=your-project-id
518
519
  PORT=3000
519
520
  MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/dbname
520
521
  JWT_SECRET=your-jwt-secret
522
+ FUNCTION_CALL_BODY_LIMIT_BYTES=52428800
521
523
  HOST=0.0.0.0
522
524
  API_VERSION=v2.0
523
525
  HTTPS_SCHEMA=http
@@ -3,6 +3,7 @@ export declare const DEFAULT_CONFIG: {
3
3
  PORT: number;
4
4
  MONGODB_URL: string;
5
5
  JWT_SECRET: string;
6
+ FUNCTION_CALL_BODY_LIMIT_BYTES: number;
6
7
  API_VERSION: string;
7
8
  HTTPS_SCHEMA: string;
8
9
  HOST: string;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAsBpC,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCsB,eAAe,EAAE;;;;;;CAMjE,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,YAAY,QAAiC,CAAA;AAE1D,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAA;AAE7E,eAAO,MAAM,WAAW;;;;;;;mBAOqB,aAAa;;;;;;;;;CAOzD,CAAA;AAED,eAAO,MAAM,SAAS;;;CAGrB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAsBpC,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoCsB,eAAe,EAAE;;;;;;CAMjE,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,YAAY,QAAiC,CAAA;AAE1D,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAA;AAE7E,eAAO,MAAM,WAAW;;;;;;;mBAOqB,aAAa;;;;;;;;;CAOzD,CAAA;AAED,eAAO,MAAM,SAAS;;;CAGrB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAA"}
package/dist/constants.js CHANGED
@@ -31,6 +31,7 @@ exports.DEFAULT_CONFIG = {
31
31
  PORT: Number(process.env.PORT) || 3000,
32
32
  MONGODB_URL: process.env.MONGODB_URL || '',
33
33
  JWT_SECRET: process.env.JWT_SECRET || '',
34
+ FUNCTION_CALL_BODY_LIMIT_BYTES: Number(process.env.FUNCTION_CALL_BODY_LIMIT_BYTES) || 50 * 1024 * 1024,
34
35
  API_VERSION: process.env.API_VERSION || 'v2.0',
35
36
  HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
36
37
  HOST: process.env.HOST || '0.0.0.0',
@@ -1 +1 @@
1
- {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAIvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAmHhD,eAAO,MAAM,iCAAiC,GAAI,OAAO,OAAO,KAAG,OA0BlE,CAAA;AAID,eAAO,MAAM,6BAA6B,GAAI,OAAO,OAAO,KAAG,OAgD9D,CAAA;AAqHD,eAAO,MAAM,oCAAoC,GAAI,QAAQ,QAAQ,YAClC,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAyRjC,CAAA"}
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAmHhD,eAAO,MAAM,iCAAiC,GAAI,OAAO,OAAO,KAAG,OA0BlE,CAAA;AAID,eAAO,MAAM,6BAA6B,GAAI,OAAO,OAAO,KAAG,OAgD9D,CAAA;AAqHD,eAAO,MAAM,oCAAoC,GAAI,QAAQ,QAAQ,YAClC,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBA0RjC,CAAA"}
@@ -22,6 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.functionsController = exports.shouldSkipReadabilityLookupForChange = exports.mapWatchFilterToDocumentQuery = exports.mapWatchFilterToChangeStreamMatch = void 0;
24
24
  const bson_1 = require("bson");
25
+ const constants_1 = require("../../constants");
25
26
  const services_1 = require("../../services");
26
27
  const context_1 = require("../../utils/context");
27
28
  const utils_1 = require("./utils");
@@ -273,6 +274,7 @@ exports.shouldSkipReadabilityLookupForChange = shouldSkipReadabilityLookupForCha
273
274
  const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0, function* (app, { functionsList, rules }) {
274
275
  app.addHook('preHandler', app.jwtAuthentication);
275
276
  app.post('/call', {
277
+ bodyLimit: constants_1.DEFAULT_CONFIG.FUNCTION_CALL_BODY_LIMIT_BYTES,
276
278
  schema: {
277
279
  tags: ['Functions']
278
280
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.8.1-beta.1",
3
+ "version": "1.8.1-beta.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/constants.ts CHANGED
@@ -25,6 +25,7 @@ export const DEFAULT_CONFIG = {
25
25
  PORT: Number(process.env.PORT) || 3000,
26
26
  MONGODB_URL: process.env.MONGODB_URL || '',
27
27
  JWT_SECRET: process.env.JWT_SECRET || '',
28
+ FUNCTION_CALL_BODY_LIMIT_BYTES: Number(process.env.FUNCTION_CALL_BODY_LIMIT_BYTES) || 50 * 1024 * 1024,
28
29
  API_VERSION: process.env.API_VERSION || 'v2.0',
29
30
  HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
30
31
  HOST: process.env.HOST || '0.0.0.0',
@@ -0,0 +1,60 @@
1
+ import Fastify, { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
2
+ import { GenerateContext } from '../../../utils/context'
3
+ import { functionsController } from '../controller'
4
+
5
+ jest.mock('../../../utils/context', () => ({
6
+ GenerateContext: jest.fn()
7
+ }))
8
+
9
+ describe('functionsController', () => {
10
+ let app: FastifyInstance
11
+
12
+ beforeEach(async () => {
13
+ app = Fastify()
14
+
15
+ app.decorate('jwtAuthentication', async (request: FastifyRequest, _reply: FastifyReply) => {
16
+ ;(request as any).user = {
17
+ id: '507f191e810c19729de860ea',
18
+ typ: 'access'
19
+ }
20
+ })
21
+
22
+ ;(GenerateContext as jest.Mock).mockResolvedValue({ ok: true })
23
+
24
+ await app.register(functionsController, {
25
+ functionsList: {
26
+ largePayloadEcho: {
27
+ code: 'exports = () => ({ ok: true })'
28
+ }
29
+ },
30
+ rules: {}
31
+ })
32
+ await app.ready()
33
+ })
34
+
35
+ afterEach(async () => {
36
+ await app.close()
37
+ jest.clearAllMocks()
38
+ })
39
+
40
+ it('accepts payloads larger than Fastify default body limit on POST /call', async () => {
41
+ const largeValue = 'x'.repeat(2 * 1024 * 1024)
42
+
43
+ const response = await app.inject({
44
+ method: 'POST',
45
+ url: '/call',
46
+ payload: {
47
+ name: 'largePayloadEcho',
48
+ arguments: [{ largeValue }]
49
+ }
50
+ })
51
+
52
+ expect(response.statusCode).toBe(200)
53
+ expect(JSON.parse(response.body)).toEqual({ ok: true })
54
+ expect(GenerateContext).toHaveBeenCalledWith(
55
+ expect.objectContaining({
56
+ args: [{ largeValue }]
57
+ })
58
+ )
59
+ })
60
+ })
@@ -2,6 +2,7 @@ import type { ServerResponse } from 'http'
2
2
  import { EJSON, ObjectId } from 'bson'
3
3
  import type { FastifyRequest } from 'fastify'
4
4
  import type { Document } from 'mongodb'
5
+ import { DEFAULT_CONFIG } from '../../constants'
5
6
  import { services } from '../../services'
6
7
  import { GenerateContext } from '../../utils/context'
7
8
  import { Base64Function, FunctionCallBase64Dto, FunctionCallDto } from './dtos'
@@ -331,6 +332,7 @@ export const functionsController: FunctionController = async (
331
332
  app.addHook('preHandler', app.jwtAuthentication)
332
333
 
333
334
  app.post<{ Body: FunctionCallDto }>('/call', {
335
+ bodyLimit: DEFAULT_CONFIG.FUNCTION_CALL_BODY_LIMIT_BYTES,
334
336
  schema: {
335
337
  tags: ['Functions']
336
338
  }