UNPKG

3.34 kBTypeScriptView Raw
1import type { DefaultElements, ISO8601Timestamp, Link, MakeRequest, MakeRequestPayload, VersionedLink } from '../common-types';
2import type { AsyncActionProcessingOptions } from '../methods/action';
3/** Entity types supported by the BulkAction API */
4type Entity = 'Entry' | 'Asset';
5type Collection<T> = Array<T>;
6type EntityError = {
7 entity: VersionedLink<Entity> | Link<Entity>;
8 error: any;
9};
10export type BulkActionType = 'publish' | 'unpublish' | 'validate';
11/** Represents the state of the BulkAction */
12export declare enum BulkActionStatus {
13 /** BulkAction is pending execution */
14 created = "created",
15 /** BulkAction has been started and pending completion */
16 inProgress = "inProgress",
17 /** BulkAction was completed successfully (terminal state) */
18 succeeded = "succeeded",
19 /** BulkAction failed to complete (terminal state) */
20 failed = "failed"
21}
22declare const STATUSES: BulkActionStatus[];
23type BulkActionStatuses = typeof STATUSES[number];
24interface BulkActionFailedError {
25 sys: {
26 type: 'Error';
27 id: 'BulkActionFailed';
28 };
29 message?: string;
30 details?: {
31 errors: Collection<EntityError>;
32 };
33}
34export type BulkActionPayload = BulkActionPublishPayload | BulkActionUnpublishPayload | BulkActionValidatePayload;
35export interface BulkActionValidatePayload extends MakeRequestPayload {
36 action?: 'publish';
37 entities: {
38 sys?: {
39 type: 'Array';
40 };
41 items: Collection<Link<Entity>>;
42 };
43}
44export interface BulkActionUnpublishPayload extends MakeRequestPayload {
45 entities: {
46 sys?: {
47 type: 'Array';
48 };
49 items: Collection<Link<Entity>>;
50 };
51}
52export interface BulkActionPublishPayload extends MakeRequestPayload {
53 entities: {
54 sys?: {
55 type: 'Array';
56 };
57 items: Collection<VersionedLink<Entity>>;
58 };
59}
60export type BulkActionSysProps = {
61 id: string;
62 type: 'BulkAction';
63 status: BulkActionStatuses;
64 space: Link<'Space'>;
65 environment: Link<'Environment'>;
66 createdBy: Link<'User'>;
67 createdAt: ISO8601Timestamp;
68 updatedAt: ISO8601Timestamp;
69};
70/** The object returned by the BulkActions API */
71export interface BulkActionProps<TPayload extends BulkActionPayload = any> {
72 sys: BulkActionSysProps;
73 action: BulkActionType;
74 /** original payload when BulkAction was created */
75 payload: TPayload;
76 /** error information, if present */
77 error?: BulkActionFailedError;
78}
79export interface BulkActionApiMethods {
80 /** Performs a new GET request and returns the wrapper BulkAction */
81 get(): BulkAction;
82 /** Waits until the BulkAction is in one of the final states (`succeeded` or `failed`) and returns it. */
83 waitProcessing(options?: AsyncActionProcessingOptions): Promise<BulkAction>;
84}
85export interface BulkAction<T extends BulkActionPayload = any> extends BulkActionProps<T>, BulkActionApiMethods, DefaultElements<BulkActionProps<T>> {
86}
87/**
88 * @private
89 * @param makeRequest - function to make requests via an adapter
90 * @param data - Raw BulkAction data
91 * @return Wrapped BulkAction data
92 */
93export declare function wrapBulkAction<TPayload extends BulkActionPayload = any>(makeRequest: MakeRequest, data: BulkActionProps<BulkActionPayload>): BulkAction<TPayload>;
94export {};