UNPKG

3.89 kBTypeScriptView Raw
1import type { DefaultElements, ISO8601Timestamp, MetaLinkProps, Link, MakeRequest, SysLink, ScheduledActionReferenceFilters, BasicCursorPaginationOptions, CollectionProp } from '../common-types';
2/**
3 * Represents that state of the scheduled action
4 */
5declare enum ScheduledActionStatus {
6 /** action is pending execution */
7 scheduled = "scheduled",
8 /** action has been started and pending completion */
9 inProgress = "inProgress",
10 /** action was completed successfully (terminal state) */
11 succeeded = "succeeded",
12 /** action failed to complete (terminal state) */
13 failed = "failed",
14 /** action was canceled by a user (terminal state) */
15 canceled = "canceled"
16}
17type SchedulableEntityType = 'Entry' | 'Asset' | 'Release';
18type SchedulableActionType = 'publish' | 'unpublish';
19type ErrorDetail = {
20 error: any;
21};
22interface ScheduledActionFailedError {
23 sys: {
24 type: 'Error';
25 id: string;
26 };
27 message?: string;
28 details?: {
29 errors: ErrorDetail[];
30 };
31}
32export interface CursorPaginatedCollectionProp<TObj> extends Omit<CollectionProp<TObj>, 'total' | 'skip'> {
33 pages?: BasicCursorPaginationOptions;
34}
35export type ScheduledActionSysProps = {
36 id: string;
37 type: 'ScheduledAction';
38 version: number;
39 space: SysLink;
40 status: ScheduledActionStatus;
41 createdAt: ISO8601Timestamp;
42 createdBy: Link<'User'> | Link<'AppDefinition'>;
43 /** an ISO8601 date string representing when an action was moved to canceled */
44 canceledAt?: ISO8601Timestamp;
45 canceledBy?: Link<'User'> | Link<'AppDefinition'>;
46 /** an ISO8601 date string representing when an action was updated */
47 updatedAt: ISO8601Timestamp;
48 updatedBy: Link<'User'> | Link<'AppDefinition'>;
49};
50export type ScheduledActionPayloadProps = {
51 withReferences?: Record<ScheduledActionReferenceFilters, string[]>;
52};
53export type ScheduledActionProps = {
54 sys: ScheduledActionSysProps;
55 action: SchedulableActionType;
56 entity: Link<SchedulableEntityType>;
57 environment?: {
58 sys: MetaLinkProps;
59 };
60 scheduledFor: {
61 datetime: ISO8601Timestamp;
62 /**
63 * A valid IANA timezone Olson identifier
64 *
65 * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
66 * @example 'Asia/Kolkata'
67 */
68 timezone?: string;
69 };
70 /**
71 * The Contentful-style error that occurred during execution if sys.status is failed
72 *
73 * @example
74 * {
75 * sys: {
76 * type: 'Error',
77 * id: 'InvalidEntry'
78 * },
79 * message: 'Entry is invalid',
80 * details: {
81 * errors: [...]
82 * }
83 * }
84 */
85 error?: ScheduledActionFailedError;
86 payload?: ScheduledActionPayloadProps;
87};
88export type CreateUpdateScheduledActionProps = Pick<ScheduledActionProps, 'action' | 'entity' | 'environment' | 'scheduledFor' | 'payload'>;
89export type ScheduledActionCollection = CursorPaginatedCollectionProp<ScheduledActionProps>;
90export interface ScheduledActionQueryOptions {
91 'environment.sys.id': string;
92 [key: string]: any;
93 limit?: number;
94 next?: string;
95 prev?: string;
96}
97export type ScheduledActionApi = {
98 delete(): Promise<ScheduledAction>;
99 update(): Promise<ScheduledAction>;
100};
101export interface ScheduledAction extends ScheduledActionProps, DefaultElements<ScheduledActionProps>, ScheduledActionApi {
102}
103export default function getInstanceMethods(makeRequest: MakeRequest): ScheduledActionApi;
104/**
105 * @private
106 */
107export declare function wrapScheduledAction(makeRequest: MakeRequest, data: ScheduledActionProps): ScheduledAction;
108/**
109 * @private
110 */
111export declare const wrapScheduledActionCollection: (makeRequest: MakeRequest, data: CollectionProp<ScheduledActionProps>) => import("../common-types").Collection<ScheduledAction, ScheduledActionProps>;
112export {};