monday-sdk-js 0.1.6 → 0.2.1

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.
Files changed (2) hide show
  1. package/package.json +8 -4
  2. package/types/index.d.ts +320 -0
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "monday-sdk-js",
3
- "version": "0.1.6",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "repository": "https://github.com/mondaycom/monday-sdk-js",
6
6
  "main": "src/index.js",
7
+ "types": "types/index.d.ts",
7
8
  "author": "talharamati <tal@monday.com>",
8
9
  "license": "MIT",
9
10
  "files": [
@@ -11,10 +12,10 @@
11
12
  "README.md",
12
13
  "dist/",
13
14
  "src/",
15
+ "types/",
14
16
  "server-sdk.js"
15
17
  ],
16
18
  "dependencies": {
17
- "@types/source-map": "^0.5.2",
18
19
  "node-fetch": "^2.6.0"
19
20
  },
20
21
  "devDependencies": {
@@ -34,7 +35,9 @@
34
35
  "sinon-chai": "^3.5.0",
35
36
  "webpack": "^4.38.0",
36
37
  "webpack-cli": "^3.3.6",
37
- "webpack-dev-server": "^3.7.2"
38
+ "webpack-dev-server": "^3.7.2",
39
+ "@types/source-map": "^0.5.2",
40
+ "typescript": "^4.9.5"
38
41
  },
39
42
  "scripts": {
40
43
  "start": "webpack-dev-server",
@@ -43,6 +46,7 @@
43
46
  "test:watch": "mocha './src/**/*-test.js' --watch",
44
47
  "precommit": "yarn lint && yarn style-check",
45
48
  "lint": "eslint './src/**/*.*'",
46
- "style-check": "prettier --check './src/**/*.js'"
49
+ "style-check": "prettier --check './src/**/*.js'",
50
+ "compile-types": "tsc --noEmit"
47
51
  }
48
52
  }
@@ -0,0 +1,320 @@
1
+ // Original Definitions were contributed by: Josh Parnham <https://github.com/josh->
2
+
3
+ export as namespace mondaySdk;
4
+
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
+ }
298
+
299
+ interface MondayServerSdk {
300
+ setToken(token: string): void;
301
+
302
+ api(query: string, options?: Partial<{ token: string, variables: object } >): Promise<any>;
303
+
304
+ oauthToken(code: string, clientId: string, clientSecret: string): Promise<any>;
305
+ }
306
+
307
+ declare function init(
308
+ config?: Partial<{
309
+ clientId: string;
310
+ apiToken: string;
311
+ }>,
312
+ ): MondayClientSdk;
313
+
314
+ declare function init(
315
+ config?: Partial<{
316
+ token: string;
317
+ }>,
318
+ ): MondayServerSdk;
319
+
320
+ export = init;