PHP 8.2.30
Preview: call-action-api.ts Size: 1.58 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/frontend/interfaces/action/call-action-api.ts

import { AxiosResponse } from 'axios'

import { ActionResponse } from '../../../backend/index.js'
import { DifferentActionParams } from '../../hooks/index.js'
import { ApiClient } from '../../utils/index.js'
import { ActionJSON } from './action-json.interface.js'

const api = new ApiClient()

export function callActionApi<K extends ActionResponse>(
  action: ActionJSON,
  params: DifferentActionParams,
  search?: Location['search'],
): Promise<AxiosResponse<K>> {
  let promise: Promise<AxiosResponse<K>>
  const { recordId, recordIds, resourceId } = params

  /* Temporary workaround to avoid breaking changes.
    TODO: For v8 release, rewrite actions to support PUT & DELETE methods.
    Actions should have an option to configure a default method for action buttons. */
  let method = 'get'
  if (action.name === 'delete') {
    method = 'post'
  }

  switch (action.actionType) {
  case 'record':
    if (!recordId) {
      throw new Error('You have to specify "recordId" for record action')
    }
    promise = api.recordAction({
      resourceId, actionName: action.name, recordId, search, method,
    }) as any
    break
  case 'resource':
    promise = api.resourceAction({
      resourceId, actionName: action.name, method,
    }) as any
    break
  case 'bulk':
    if (!recordIds) {
      throw new Error('You have to specify "recordIds" for bulk action')
    }
    promise = api.bulkAction({
      resourceId, actionName: action.name, recordIds, search, method,
    }) as any
    break
  default:
    throw new Error('"actionType" should be either record, resource or bulk')
  }
  return promise
}

Directory Contents

Dirs: 0 × Files: 11

Name Size Perms Modified Actions
325 B lrw-r--r-- 2026-02-28 00:31:58
Edit Download
1.04 KB lrw-r--r-- 2026-02-28 00:31:58
Edit Download
1.97 KB lrw-r--r-- 2026-02-28 00:31:58
Edit Download
1.07 KB lrw-r--r-- 2026-02-28 00:32:02
Edit Download
2.96 KB lrw-r--r-- 2026-02-28 00:32:02
Edit Download
146 B lrw-r--r-- 2026-02-28 00:32:02
Edit Download
1.58 KB lrw-r--r-- 2026-02-28 00:32:02
Edit Download
410 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
391 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
404 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
407 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).