-
Notifications
You must be signed in to change notification settings - Fork 38
/
client-data.interface.ts
178 lines (161 loc) · 6.19 KB
/
client-data.interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { AppFeatureContextMap, AppFeatureTypes } from "./client-context.type";
export type LocationResponse = Record<string, any> & {
href: string;
search: string;
};
export type FilterResponse = Record<string, any> & {
term: string;
rules: (Record<string, any> & {
column_id?: string;
compare_value?: string[];
compare_attribute?: string;
operator?: string;
})[];
operator: string | null;
};
type SubscribableEventsResponse<AppFeatureType extends AppFeatureTypes = AppFeatureTypes> = {
context: AppFeatureContextMap[AppFeatureType];
settings: Record<string, any>;
itemIds: number[];
events: Record<string, any>;
location: LocationResponse;
filter: FilterResponse;
};
type SubscribableEvents = keyof SubscribableEventsResponse;
type SettableTypes = "settings";
type StorageResponse = {
success: boolean;
value: any;
version?: any;
};
type Response<T = StorageResponse> = {
data: T;
errorMessage?: string | undefined;
method: string;
requestId: string;
type?: string | undefined;
};
type DeleteResponse = {
data: {
success: boolean;
value: any;
};
errorMessage?: string | undefined;
method: string;
requestId: string;
type?: string | undefined;
};
interface SetResponse {
data: {
success: boolean;
version: string;
reason?: string | undefined;
error?: string | undefined;
};
errorMessage?: string | undefined;
requestId: string;
method: string;
type?: string | undefined;
}
export type GetterResponse<AppFeatureType extends AppFeatureTypes = AppFeatureTypes> = {
context: AppFeatureContextMap[AppFeatureType];
settings: Record<string, any>;
itemIds: number[];
sessionToken: string;
location: LocationResponse;
filter: FilterResponse;
};
export interface ClientData {
/**
* Used for retrieving data from the parent monday.com application where your app is currently running.
* This object can only be used when your app is running inside an `iframe`. This can only be used in client-side apps.
* @param type The type of requested information (available values below)
* - `'context'` Information about where this app is currently displayed, depending on the type of feature
* - `'settings'` The application settings as configured by the user that installed the app
* - `'itemIds'` The list of item IDs that are filtered in the current board (or all items if no filters are applied)
* - `'sessionToken'` A JWT token which is decoded with your app's secret and can be used as a session token between your app's frontend & backend
* @param params Reserved for future use
*/
get<
CustomResponse,
T extends keyof GetterResponse = keyof GetterResponse,
AppFeatureType extends AppFeatureTypes = AppFeatureTypes
>(
type: T,
params?: Record<string, any> & { appFeatureType?: AppFeatureType }
): Promise<Response<GetterResponse<AppFeatureType>[T] & CustomResponse>>;
/**
* Creates a listener which allows subscribing to certain types of client-side events.
* @param typeOrTypes The type, or array of types, of events to subscribe to
* @param callback A callback function that is fired when the listener is triggered by a client-side event
* @param params Reserved for future use
* @return Unsubscribe/unlisten from all added during this method call
*/
listen<
CustomResponse,
T extends SubscribableEvents = SubscribableEvents,
AppFeatureType extends AppFeatureTypes = AppFeatureTypes
>(
typeOrTypes: T | ReadonlyArray<T>,
callback: (res: { data: SubscribableEventsResponse<AppFeatureType>[T] & CustomResponse }) => void,
params?: Record<string, any> & { appFeatureType?: AppFeatureType }
): () => void;
/**
* Set data in your application, such as updating settings
* @param type The type of data that can be set
* @param params object containing the data you want to update
*/
set(type: SettableTypes, params: object): Promise<any>;
/**
* The Storage API is in early beta stages, its API is likely to change
*
* The monday apps infrastructure includes a persistent, key-value database storage that developers
* can leverage to store data without having to create their own backend and maintain their own database.
*
* The database currently offers instance-level storage only, meaning that each application instance (i.e. a single board view or a dashboard widget) maintains its own storage.
* Apps cannot share storage across accounts or even across apps installed in the same location.
*/
storage: {
/**
* Returns a stored value from the database under `key` for the app (**without any reference to the instance**)
* @param {string} key - Used to access to stored data
*/
getItem(key: string): Promise<Response>;
/**
* Deletes a stored value from the database under `key` for the app (**without any reference to the instance**)
* @param {string} key - Used to delete the stored data
*/
deleteItem(key: string): Promise<DeleteResponse>;
/**
* Stores `value` under `key` in the database for the app (**without any reference to the instance**)
* @param {string} key - Used to delete the stored data
* @param {any} value - The value to store
* @param {object=} options
* @param {string=} options.previous_version - Use the new version of the storage (instance-less)
*/
setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
/***
* The instance storage is a key-value database that is scoped to a specific app instance.
* **Does not work** for instance-less apps.
*/
instance: {
/**
* Returns a stored value from the database under `key` for a specific app instance
* @param key
*/
getItem(key: string): Promise<Response>;
/**
* Deletes a stored value from the database under `key` for a specific app instance
* @param key
*/
deleteItem(key: string): Promise<DeleteResponse>;
/**
* Stores `value` under `key` in the database for a specific app instance
* @param key
* @param value
* @param options
*/
setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
};
};
}