diff --git a/package.json b/package.json index f46a59151..9b8437b73 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@babel/runtime": "7.10.1", "bluebird": "2.9.25", "core-js": "3.6.5", - "forest-express": "9.0.0-beta.9", + "forest-express": "9.0.0-beta.11", "http-errors": "1.6.1", "lodash": "4.17.21", "moment": "2.19.4", diff --git a/types/index.d.ts b/types/index.d.ts index 2fac9a32b..0f8e2e63a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -32,6 +32,65 @@ export interface User { renderingId: number; } +export interface ForestRequest extends Request { + user: User, +} + +// Base attributes for actions requests (content of request.data.body.attributes) +interface ActionRequestAttributes { + collection_name: string, + ids: string[], + parent_collection_name: string, + parent_collection_id: string, + parent_association_name: string, + all_records: boolean, + all_records_subset_query: Query, + all_records_ids_excluded: string[], + smart_action_id: string, +} + +// Base body from requests for action routes / hooks +interface ActionRequestBody { + data: { + attributes: ActionRequestAttributes, + type: 'action-requests', + }, +} + +// Base body from requests for classic smart action routes +interface SmartActionRequestBody { + data: { + attributes: ActionRequestAttributes & { values: Record }, + type: 'custom-action-requests', + }, +} + +// Base body from requests for smart action hooks +interface SmartActionHookRequestBody { + data: { + attributes: ActionRequestAttributes & { + fields: SmartActionChangeHookField[], + changedField: string, + }, + type: 'custom-action-hook-requests', + }, +} + +// Concrete smart action request for classic smart action routes +export interface SmartActionRequest extends ForestRequest { + body: SmartActionRequestBody, +} + +// Request passed to smart action load hooks +export interface SmartActionLoadHookRequest extends ForestRequest { + body: ActionRequestBody, +} + +// Request passed to smart action change hooks +export interface SmartActionChangeHookRequest extends ForestRequest { + body: SmartActionHookRequestBody, +} + // Everything related to Forest constants export const PUBLIC_ROUTES: string[]; @@ -54,7 +113,7 @@ export class RecordGetter extends AbstractRecordTool< export class RecordsGetter extends AbstractRecordTool { getAll(query: Query): Promise; - getIdsFromRequest(request: Request): Promise; + getIdsFromRequest(request: SmartActionRequest | SmartActionLoadHookRequest | SmartActionChangeHookRequest): Promise; } export class RecordsCounter extends AbstractRecordTool { @@ -218,16 +277,16 @@ export interface SmartActionLoadHookField extends SmartActionHookField { position: number, } -export interface SmartActionLoadHook { - (context: { fields: SmartActionLoadHookField[], record: M }): SmartActionLoadHookField[] +export interface SmartActionLoadHook { + (context: { fields: SmartActionLoadHookField[], request: SmartActionLoadHookRequest }): SmartActionLoadHookField[] } export interface SmartActionChangeHookField extends SmartActionHookField { previousValue: any, } -export interface SmartActionChangeHook { - (context: { fields: SmartActionChangeHookField[], record: M, changedField: SmartActionChangeHookField }): SmartActionChangeHookField[] +export interface SmartActionChangeHook { + (context: { fields: SmartActionChangeHookField[], changedField: SmartActionChangeHookField, request: SmartActionChangeHookRequest }): SmartActionChangeHookField[] } export interface SmartActionHooks { diff --git a/yarn.lock b/yarn.lock index 9a5364f4a..7116ec0e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5067,10 +5067,10 @@ for-in@^1.0.2: resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" integrity sha1-gQaNKVqBQuwKxybG4iAMMPttXoA= -forest-express@9.0.0-beta.9: - version "9.0.0-beta.9" - resolved "https://registry.yarnpkg.com/forest-express/-/forest-express-9.0.0-beta.9.tgz#c92f7ea63ddb160667c419a60bfb35b8b97187fd" - integrity sha512-P6hSk0JZNee3e/eCTbVxzhQd5te+Q77xBuvv4jN5sg60S7ZbYLKNtgm9rpyLjs1iclLZMx/sHn/EbyHb48drwA== +forest-express@9.0.0-beta.11: + version "9.0.0-beta.11" + resolved "https://registry.yarnpkg.com/forest-express/-/forest-express-9.0.0-beta.11.tgz#99b553c60ac6da76567c13f38fb5a78ad17d0e55" + integrity sha512-ufU/dIe9WTlQGCR2KJIS/wAXvvEb300Xk2GL1iXHSr4uny8zFlnPXwZlZHdWSC8FQZlnclvUj1xfsanf/WWt1A== dependencies: "@babel/runtime" "7.10.1" base32-encode "1.1.1"