monday-sdk-js 0.2.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monday-sdk-js",
3
- "version": "0.2.1",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "repository": "https://github.com/mondaycom/monday-sdk-js",
6
6
  "main": "src/index.js",
@@ -0,0 +1,49 @@
1
+ interface APIOptions {
2
+ /**
3
+ * Access token for the API
4
+ * If not set, will use the credentials of the current user (client only)
5
+ */
6
+ token?: string | undefined;
7
+
8
+ /**
9
+ * An object containing GraphQL query variables
10
+ */
11
+ variables?: object | undefined;
12
+ }
13
+
14
+ interface OAuthOptions {
15
+ /**
16
+ * The OAuth client ID of the requesting application
17
+ * Defaults to your client ID
18
+ */
19
+ clientId?: string | undefined;
20
+
21
+ /**
22
+ * The URL of the monday OAuth endpoint
23
+ */
24
+ mondayOauthUrl?: string | undefined;
25
+ }
26
+
27
+ export interface ClientApi {
28
+ /**
29
+ * Used for querying the monday.com GraphQL API seamlessly on behalf of the connected user, or using a provided API token.
30
+ * For more information about the GraphQL API and all queries and mutations possible, read the [API Documentation](https://monday.com/developers/v2)
31
+ * @param query A [GraphQL](https://graphql.org/) query, can be either a query (retrieval operation) or a mutation (creation/update/deletion operation).
32
+ * Placeholders may be used, which will be substituted by the variables object passed within the options.
33
+ * @param options
34
+ */
35
+ api(query: string, options?: APIOptions): Promise<{ data: object }>;
36
+
37
+ /**
38
+ * Instead of passing the API token to the `api()` method on each request, you can set the API token once using:
39
+ * @param token Access token for the API
40
+ */
41
+ setToken(token: string): void;
42
+
43
+ /**
44
+ * Performs a client-side redirection of the user to the monday OAuth screen with your client ID embedded in the URL,
45
+ * sin order to get their approval to generate a temporary OAuth token based on your requested permission scopes.
46
+ * @param object An object with options
47
+ */
48
+ oauth(object?: OAuthOptions): void;
49
+ }
@@ -0,0 +1,109 @@
1
+ type SubscribableEvents = 'context' | 'settings' | 'itemIds' | 'events';
2
+
3
+ type SettableTypes = 'settings';
4
+
5
+ interface GetResponse {
6
+ data: {
7
+ success: boolean;
8
+ value: any;
9
+ version?: any;
10
+ };
11
+ errorMessage?: string | undefined;
12
+ method: string;
13
+ requestId: string;
14
+ type?: string | undefined;
15
+ }
16
+
17
+ interface DeleteResponse {
18
+ data: {
19
+ success: boolean;
20
+ value: any;
21
+ };
22
+ errorMessage?: string | undefined;
23
+ method: string;
24
+ requestId: string;
25
+ type?: string | undefined;
26
+ }
27
+
28
+ interface SetResponse {
29
+ data: {
30
+ success: boolean;
31
+ version: string;
32
+ reason?: string | undefined;
33
+ error?: string | undefined;
34
+ };
35
+ errorMessage?: string | undefined;
36
+ requestId: string;
37
+ method: string;
38
+ type?: string | undefined;
39
+ }
40
+
41
+
42
+ export interface ClientData {
43
+ /**
44
+ * Used for retrieving data from the parent monday.com application where your app is currently running.
45
+ * This object can only be used when your app is running inside an `iframe`. This can only be used in client-side apps.
46
+ * @param type The type of requested information (available values below)
47
+ * - `'context'` Information about where this app is currently displayed, depending on the type of feature
48
+ * - `'settings'` The application settings as configured by the user that installed the app
49
+ * - `'itemIds'` The list of item IDs that are filtered in the current board (or all items if no filters are applied)
50
+ * - `'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
51
+ * @param params Reserved for future use
52
+ */
53
+ get(type: 'context' | 'settings' | 'itemIds' | 'sessionToken', params?: object): Promise<any>;
54
+
55
+ /**
56
+ * Creates a listener which allows subscribing to certain types of client-side events.
57
+ * @param typeOrTypes The type, or array of types, of events to subscribe to
58
+ * @param callback A callback function that is fired when the listener is triggered by a client-side event
59
+ * @param params Reserved for future use
60
+ */
61
+ listen(
62
+ typeOrTypes: SubscribableEvents | ReadonlyArray<SubscribableEvents>,
63
+ callback: (res: { data: object }) => void,
64
+ params?: object,
65
+ ): void;
66
+
67
+ /**
68
+ * Set data in your application, such as updating settings
69
+ * @param type The type of data that can be set
70
+ * @param params object containing the data you want to update
71
+ */
72
+ set(
73
+ type: SettableTypes,
74
+ params: object,
75
+ ): Promise<any>;
76
+
77
+ /**
78
+ * The Storage API is in early beta stages, its API is likely to change
79
+ *
80
+ * The monday apps infrastructure includes a persistent, key-value database storage that developers
81
+ * can leverage to store data without having to create their own backend and maintain their own database.
82
+ *
83
+ * 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.
84
+ * Apps cannot share storage across accounts or even across apps installed in the same location.
85
+ */
86
+ storage: {
87
+ instance: {
88
+ /**
89
+ * Returns a stored value from the database under `key`
90
+ * @param key
91
+ */
92
+ getItem(key: string): Promise<GetResponse>;
93
+
94
+ /**
95
+ * Deletes a stored value from the database under `key`
96
+ * @param key
97
+ */
98
+ deleteItem(key: string): Promise<DeleteResponse>;
99
+
100
+ /**
101
+ * Stores `value` under `key` in the database
102
+ * @param key
103
+ * @param value
104
+ * @param options
105
+ */
106
+ setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
107
+ };
108
+ };
109
+ }
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Blocks that are supported by our SDK
3
+ */
4
+ type BlockTypes = 'normal text' | 'large title' | 'medium title' | 'small title' | 'bulleted list' | 'numbered list' | 'quote' | 'check list' | 'code';
5
+
6
+ /**
7
+ * Block content in delta format
8
+ */
9
+ interface BlockContent { deltaFormat: Array<object> };
10
+
11
+ export interface ClientExecute {
12
+ /**
13
+ * Opens a popup card with information from the selected item
14
+ * @param type Which action to perform
15
+ * @param params Optional parameters for the action
16
+ */
17
+ execute(
18
+ type: 'openItemCard',
19
+ params: {
20
+ /**
21
+ * The ID of the item to open
22
+ */
23
+ itemId: number;
24
+
25
+ /**
26
+ * On which view to open the item card.
27
+ * Can be "updates" / "columns"
28
+ * Defaults to "columns"
29
+ */
30
+ kind?: 'updates' | 'columns' | undefined;
31
+ },
32
+ ): Promise<any>;
33
+ /**
34
+ * Opens a confirmation dialog to the user **type** `'confirm'`
35
+ * @param type Which action to perform
36
+ * @param params Optional parameters for the action
37
+ */
38
+ execute(
39
+ type: 'confirm',
40
+ params: {
41
+ /**
42
+ * The message to display in the dialog
43
+ */
44
+ message: string;
45
+
46
+ /**
47
+ * The text for the confirmation button
48
+ * Defaults to "OK"
49
+ */
50
+ confirmButton?: string | undefined;
51
+
52
+ /**
53
+ * The text for the cancel button
54
+ * Defaults to "Cancel"
55
+ */
56
+ cancelButton?: string | undefined;
57
+
58
+ /**
59
+ * Either to exclude the cancel button
60
+ * Defaults to `false`
61
+ */
62
+ excludeCancelButton?: boolean | undefined;
63
+ },
64
+ ): Promise<{ data: { confirm: boolean } }>;
65
+ /**
66
+ * Display a message at the top of the user's page. Useful for success, error & general messages.
67
+ * @param type Which action to perform
68
+ * @param params Optional parameters for the action
69
+ */
70
+ execute(
71
+ type: 'notice',
72
+ params: {
73
+ /**
74
+ * The message to display
75
+ */
76
+ message: string;
77
+
78
+ /**
79
+ * The type of message to display. Can be "success" (green), "error" (red) or "info" (blue)
80
+ * Defaults to "info"
81
+ */
82
+ type?: 'success' | 'error' | 'info' | undefined;
83
+
84
+ /**
85
+ * The number of milliseconds to show the message until it closes
86
+ * Defaults to 5000
87
+ */
88
+ timeout?: number | undefined;
89
+ },
90
+ ): Promise<any>;
91
+ /**
92
+ * Opens a modal with the preview of an asset
93
+ * @param type Which action to perform
94
+ * @param params Optional parameters for the action
95
+ */
96
+ execute(
97
+ type: 'openFilesDialog',
98
+ params: {
99
+ /**
100
+ * The ID of the board
101
+ */
102
+ boardId: number;
103
+
104
+ /**
105
+ * The ID of the item, which contains an asset
106
+ */
107
+ itemId: number;
108
+
109
+ /**
110
+ * The ID of the column, which contains an asset
111
+ */
112
+ columnId: string;
113
+
114
+ /**
115
+ * The ID of the asset to open
116
+ */
117
+ assetId: number;
118
+ },
119
+ ): Promise<any>;
120
+ /**
121
+ * Opens a modal to let the current user upload a file to a specific file column.
122
+ *
123
+ * Returns a promise. In case of error, the promise is rejected
124
+ *
125
+ * After the file is successfully uploaded, the "change_column_value" event will be triggered. See the {@link listen} method to subscribe to these events.
126
+ *
127
+ * _Requires boards:write scope_
128
+ * @param type Which action to perform
129
+ * @param params Optional parameters for the action
130
+ */
131
+ execute(
132
+ type: 'triggerFilesUpload',
133
+ params: {
134
+ /**
135
+ * The ID of the board
136
+ */
137
+ boardId: number;
138
+
139
+ /**
140
+ * The ID of the item, which contains an asset
141
+ */
142
+ itemId: number;
143
+
144
+ /**
145
+ * The ID of the file column, where file should be uploaded
146
+ */
147
+ columnId: string;
148
+ },
149
+ ): Promise<any>;
150
+ /**
151
+ * Opens a new modal window as an iFrame.
152
+ * @param type Which action to perform
153
+ * @param params Optional parameters for the action
154
+ */
155
+ execute(
156
+ type: 'openAppFeatureModal',
157
+ params: {
158
+ /**
159
+ * The URL of the page displayed in the modal
160
+ * Defaults to current iFrame's URL
161
+ */
162
+ url?: string;
163
+
164
+ /**
165
+ * Subdirectory or path of the URL to open
166
+ */
167
+ urlPath?: string;
168
+
169
+ /**
170
+ * Query parameters for the URL
171
+ */
172
+ urlParams?: Record<string, string>;
173
+
174
+ /**
175
+ * The width of the modal
176
+ * Defaults to "0px"
177
+ */
178
+ width?: string;
179
+
180
+ /**
181
+ * The height of the modal
182
+ * Defaults to "0px"
183
+ */
184
+ height?: string;
185
+ },
186
+ ): Promise<{ data: any }>;
187
+ /**
188
+ * Closes the modal window.
189
+ * @param type Which action to perform
190
+ */
191
+ execute(type: 'closeAppFeatureModal'): Promise<{ data: any }>;
192
+ /**
193
+ * Notifies the monday platform when a user gains a first value in your app.
194
+ * @param type Which action to perform
195
+ */
196
+ execute(type: 'valueCreatedForUser'): Promise<any>;
197
+ /**
198
+ * Adds a new block to a workdoc.
199
+ * @param type Which action to perform
200
+ * @param params The new block's data
201
+ */
202
+ execute(
203
+ type: 'addDocBlock',
204
+ params: {
205
+ /**
206
+ * The block type
207
+ */
208
+ type: BlockTypes;
209
+ /**
210
+ * Used to specify where in the doc the new block should go.
211
+ * Provide the block's ID that will be above the new block.
212
+ * Without this parameter, the block will appear at the top of the doc.
213
+ */
214
+ afterBlockId?: string | undefined;
215
+ /**
216
+ * The block's content in Delta format.
217
+ */
218
+ content: BlockContent;
219
+ },
220
+ ): Promise<any>;
221
+ /**
222
+ * Updates a block's content
223
+ * @param type Which action to perform
224
+ * @param params The updated block's data
225
+ */
226
+ execute (
227
+ type: 'updateDocBlock',
228
+ params: {
229
+ /**
230
+ * The block's unique identifier.
231
+ */
232
+ id: string;
233
+ /**
234
+ * The block's content you want to update in Delta format.
235
+ */
236
+ content: BlockContent;
237
+ }
238
+ ): Promise<any>;
239
+ /**
240
+ * Adds multiple blocks to a workdoc.
241
+ * @param type Which action to perform
242
+ * @param params Data for the new blocks you want to create
243
+ */
244
+ execute (
245
+ type: 'addMultiBlocks',
246
+ params: {
247
+ /**
248
+ * The block's unique identifier.
249
+ */
250
+ afterBlockId?: string | undefined;
251
+ /**
252
+ * The block's content in Delta format.
253
+ * We support the following block types
254
+ */
255
+ blocks: Array<{ type: BlockTypes, content: BlockContent}>;
256
+ }
257
+ ): Promise<any>;
258
+ /**
259
+ * Closes the document block modal. If you don't call this method, the modal will close when the user clicks outside of it.
260
+ * @param type Which action to perform
261
+ */
262
+ execute (type: 'closeDocModal'): Promise<any>;
263
+ }
package/types/index.d.ts CHANGED
@@ -1,300 +1,11 @@
1
1
  // Original Definitions were contributed by: Josh Parnham <https://github.com/josh->
2
+ import { ClientData } from './client-data.interface';
3
+ import { ClientExecute } from './client-execute.interface';
4
+ import { ClientApi } from './client-api.interface';
2
5
 
3
6
  export as namespace mondaySdk;
4
7
 
5
- interface APIOptions {
6
- /**
7
- * Access token for the API
8
- * If not set, will use the credentials of the current user (client only)
9
- */
10
- token?: string | undefined;
11
-
12
- /**
13
- * An object containing GraphQL query variables
14
- */
15
- variables?: object | undefined;
16
- }
17
-
18
- type SubscribableEvents = 'context' | 'settings' | 'itemIds' | 'events';
19
-
20
- interface OAuthOptions {
21
- /**
22
- * The OAuth client ID of the requesting application
23
- * Defaults to your client ID
24
- */
25
- clientId?: string | undefined;
26
-
27
- /**
28
- * The URL of the monday OAuth endpoint
29
- */
30
- mondayOauthUrl?: string | undefined;
31
- }
32
-
33
- interface GetResponse {
34
- value: any;
35
- version: any;
36
- }
37
-
38
- interface SetResponse {
39
- success: boolean;
40
- reason?: string | undefined;
41
- }
42
-
43
- interface MondayClientSdk {
44
- /**
45
- * Used for querying the monday.com GraphQL API seamlessly on behalf of the connected user, or using a provided API token.
46
- * For more information about the GraphQL API and all queries and mutations possible, read the [API Documentation](https://monday.com/developers/v2)
47
- * @param query A [GraphQL](https://graphql.org/) query, can be either a query (retrieval operation) or a mutation (creation/update/deletion operation).
48
- * Placeholders may be used, which will be substituted by the variables object passed within the options.
49
- * @param options
50
- */
51
- api(query: string, options?: APIOptions): Promise<{ data: object }>;
52
-
53
- /**
54
- * Instead of passing the API token to the `api()` method on each request, you can set the API token once using:
55
- * @param token Access token for the API
56
- */
57
- setToken(token: string): void;
58
-
59
- /**
60
- * Used for retrieving data from the parent monday.com application where your app is currently running.
61
- * This object can only be used when your app is running inside an `iframe`. This can only be used in client-side apps.
62
- * @param type The type of requested information (available values below)
63
- * - `'context'` Information about where this app is currently displayed, depending on the type of feature
64
- * - `'settings'` The application settings as configured by the user that installed the app
65
- * - `'itemIds'` The list of item IDs that are filtered in the current board (or all items if no filters are applied)
66
- * - `'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
67
- * @param params Reserved for future use
68
- */
69
- get(type: 'context' | 'settings' | 'itemIds' | 'sessionToken', params?: object): Promise<any>;
70
-
71
- /**
72
- * Creates a listener which allows subscribing to certain types of client-side events.
73
- * @param typeOrTypes The type, or array of types, of events to subscribe to
74
- * @param callback A callback function that is fired when the listener is triggered by a client-side event
75
- * @param params Reserved for future use
76
- */
77
- listen(
78
- typeOrTypes: SubscribableEvents | ReadonlyArray<SubscribableEvents>,
79
- callback: (res: { data: object }) => void,
80
- params?: object,
81
- ): void;
82
-
83
- /**
84
- * Opens a popup card with information from the selected item
85
- * @param type Which action to perform
86
- * @param params Optional parameters for the action
87
- */
88
- execute(
89
- type: 'openItemCard',
90
- params: {
91
- /**
92
- * The ID of the item to open
93
- */
94
- itemId: number;
95
-
96
- /**
97
- * On which view to open the item card.
98
- * Can be "updates" / "columns"
99
- * Defaults to "columns"
100
- */
101
- kind?: 'updates' | 'columns' | undefined;
102
- },
103
- ): Promise<any>;
104
- /**
105
- * Opens a confirmation dialog to the user **type** `'confirm'`
106
- * @param type Which action to perform
107
- * @param params Optional parameters for the action
108
- */
109
- execute(
110
- type: 'confirm',
111
- params: {
112
- /**
113
- * The message to display in the dialog
114
- */
115
- message: string;
116
-
117
- /**
118
- * The text for the confirmation button
119
- * Defaults to "OK"
120
- */
121
- confirmButton?: string | undefined;
122
-
123
- /**
124
- * The text for the cancel button
125
- * Defaults to "Cancel"
126
- */
127
- cancelButton?: string | undefined;
128
-
129
- /**
130
- * Either to exclude the cancel button
131
- * Defaults to `false`
132
- */
133
- excludeCancelButton?: boolean | undefined;
134
- },
135
- ): Promise<{ data: { confirm: boolean } }>;
136
- /**
137
- * Display a message at the top of the user's page. Useful for success, error & general messages.
138
- * @param type Which action to perform
139
- * @param params Optional parameters for the action
140
- */
141
- execute(
142
- type: 'notice',
143
- params: {
144
- /**
145
- * The message to display
146
- */
147
- message: string;
148
-
149
- /**
150
- * The type of message to display. Can be "success" (green), "error" (red) or "info" (blue)
151
- * Defaults to "info"
152
- */
153
- type?: 'success' | 'error' | 'info' | undefined;
154
-
155
- /**
156
- * The number of milliseconds to show the message until it closes
157
- * Defaults to 5000
158
- */
159
- timeout?: number | undefined;
160
- },
161
- ): Promise<any>;
162
- /**
163
- * Opens a modal with the preview of an asset
164
- * @param type Which action to perform
165
- * @param params Optional parameters for the action
166
- */
167
- execute(
168
- type: 'openFilesDialog',
169
- params: {
170
- /**
171
- * The ID of the board
172
- */
173
- boardId: number;
174
-
175
- /**
176
- * The ID of the item, which contains an asset
177
- */
178
- itemId: number;
179
-
180
- /**
181
- * The ID of the column, which contains an asset
182
- */
183
- columnId: string;
184
-
185
- /**
186
- * The ID of the asset to open
187
- */
188
- assetId: number;
189
- },
190
- ): Promise<any>;
191
- /**
192
- * Opens a modal to let the current user upload a file to a specific file column.
193
- *
194
- * Returns a promise. In case of error, the promise is rejected
195
- *
196
- * After the file is successfully uploaded, the "change_column_value" event will be triggered. See the {@link listen} method to subscribe to these events.
197
- *
198
- * _Requires boards:write scope_
199
- * @param type Which action to perform
200
- * @param params Optional parameters for the action
201
- */
202
- execute(
203
- type: 'triggerFilesUpload',
204
- params: {
205
- /**
206
- * The ID of the board
207
- */
208
- boardId: number;
209
-
210
- /**
211
- * The ID of the item, which contains an asset
212
- */
213
- itemId: number;
214
-
215
- /**
216
- * The ID of the file column, where file should be uploaded
217
- */
218
- columnId: string;
219
- },
220
- ): Promise<any>;
221
- /**
222
- * Opens a new modal window as an iFrame.
223
- * @param type Which action to perform
224
- * @param params Optional parameters for the action
225
- */
226
- execute(
227
- type: 'openAppFeatureModal',
228
- params: {
229
- /**
230
- * The URL of the page displayed in the modal
231
- * Defaults to current iFrame's URL
232
- */
233
- url?: string;
234
-
235
- /**
236
- * Subdirectory or path of the URL to open
237
- */
238
- urlPath?: string;
239
-
240
- /**
241
- * Query parameters for the URL
242
- */
243
- urlParams?: Record<string, string>;
244
-
245
- /**
246
- * The width of the modal
247
- * Defaults to "0px"
248
- */
249
- width?: string;
250
-
251
- /**
252
- * The height of the modal
253
- * Defaults to "0px"
254
- */
255
- height?: string;
256
- },
257
- ): Promise<{ data: any }>;
258
- /**
259
- * Closes the modal window.
260
- * @param type Which action to perform
261
- * @param params Optional parameters for the action
262
- */
263
- execute(type: 'closeAppFeatureModal'): Promise<{ data: any }>;
264
-
265
- /**
266
- * Performs a client-side redirection of the user to the monday OAuth screen with your client ID embedded in the URL,
267
- * sin order to get their approval to generate a temporary OAuth token based on your requested permission scopes.
268
- * @param object An object with options
269
- */
270
- oauth(object?: OAuthOptions): void;
271
-
272
- /**
273
- * The Storage API is in early beta stages, its API is likely to change
274
- *
275
- * The monday apps infrastructure includes a persistent, key-value database storage that developers
276
- * can leverage to store data without having to create their own backend and maintain their own database.
277
- *
278
- * 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.
279
- * Apps cannot share storage across accounts or even across apps installed in the same location.
280
- */
281
- storage: {
282
- instance: {
283
- /**
284
- * Returns a stored value from the database under `key`
285
- * @param key
286
- */
287
- getItem(key: string): Promise<{ data: GetResponse }>;
288
-
289
- /**
290
- * Stores `value` under `key` in the database
291
- * @param key
292
- * @param value
293
- */
294
- setItem(key: string, value: any): Promise<SetResponse>;
295
- };
296
- };
297
- }
8
+ type MondayClientSdk = ClientData & ClientExecute & ClientApi;
298
9
 
299
10
  interface MondayServerSdk {
300
11
  setToken(token: string): void;