monday-sdk-js 0.4.7 → 0.4.9

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/README.md CHANGED
@@ -42,4 +42,4 @@ const monday = window.mondaySdk()
42
42
 
43
43
  ## Docs
44
44
 
45
- To get started, check out the [SDK Documentation](https://developer.monday.com/apps/docs/introduction-to-the-sdk)
45
+ To get started, check out the [SDK Documentation](https://developer.monday.com/apps/docs/introduction-to-the-sdk)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monday-sdk-js",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "private": false,
5
5
  "repository": "https://github.com/mondaycom/monday-sdk-js",
6
6
  "main": "src/index.js",
package/src/client.js CHANGED
@@ -3,6 +3,7 @@ const { MONDAY_OAUTH_URL } = require("./constants.js");
3
3
  const { convertToArrayIfNeeded } = require("./helpers");
4
4
  const { initScrollHelperIfNeeded } = require("./helpers/ui-helpers");
5
5
  const { initBackgroundTracking } = require("./services/background-tracking-service");
6
+ const { logWarnings } = require("./helpers/monday-api-helpers");
6
7
 
7
8
  const EMPTY_ARRAY = [];
8
9
 
@@ -65,17 +66,14 @@ class MondayClientSdk {
65
66
  const token = options.token || this._apiToken;
66
67
  const apiVersion = options.apiVersion || this._apiVersion;
67
68
 
69
+ let responsePromise;
68
70
  if (token) {
69
- return mondayApiClient.execute(params, token, { apiVersion });
71
+ responsePromise = mondayApiClient.execute(params, token, { apiVersion });
70
72
  } else {
71
- return new Promise((resolve, reject) => {
72
- this._localApi("api", { params, apiVersion })
73
- .then(result => {
74
- resolve(result.data);
75
- })
76
- .catch(err => reject(err));
77
- });
73
+ responsePromise = this._localApi("api", { params, apiVersion }).then(result => result.data);
78
74
  }
75
+
76
+ return responsePromise.then(logWarnings);
79
77
  }
80
78
 
81
79
  listen(typeOrTypes, callback, params) {
@@ -0,0 +1,43 @@
1
+ const logWarnings = res => {
2
+ const warnings = res && res.extensions && res.extensions.warnings;
3
+ if (!warnings || !Array.isArray(warnings)) return res;
4
+
5
+ warnings.forEach(warning => {
6
+ if (!warning || !warning.message) return;
7
+
8
+ try {
9
+ const locations =
10
+ warning.locations && warning.locations.map(loc => `line ${loc.line}, column ${loc.column}`).join("; ");
11
+ const path = warning.path && warning.path.join(" → ");
12
+
13
+ let message = warning.message;
14
+
15
+ // remove the dot at the end of the message
16
+ message = message.replace(/\.$/, "");
17
+ // start the message with lower case letter
18
+ message = message.charAt(0).toLowerCase() + message.slice(1);
19
+
20
+ const messageParts = [
21
+ "[monday API]",
22
+ `${path}:`,
23
+ message,
24
+ locations && `@ ${locations}`,
25
+ warning.extensions ? ["\n\nAdditional details:", warning.extensions] : undefined
26
+ ]
27
+ .flat()
28
+ .filter(Boolean);
29
+
30
+ console.warn(...messageParts);
31
+ } catch (e) {
32
+ if (warning) {
33
+ console.warn("[monday API] Warning:", warning);
34
+ }
35
+ }
36
+ });
37
+
38
+ return res;
39
+ };
40
+
41
+ module.exports = {
42
+ logWarnings
43
+ };
package/src/server.js CHANGED
@@ -1,3 +1,4 @@
1
+ const { logWarnings } = require("./helpers/monday-api-helpers");
1
2
  const mondayApiClient = require("./monday-api-client");
2
3
  const { oauthToken } = require("./services/oauth-service.js");
3
4
 
@@ -21,14 +22,14 @@ class MondayServerSdk {
21
22
  this._apiVersion = apiVersion;
22
23
  }
23
24
 
24
- async api(query, options = {}) {
25
+ api(query, options = {}) {
25
26
  const params = { query, variables: options.variables };
26
27
  const token = options.token || this._token;
27
28
  const apiVersion = options.apiVersion || this._apiVersion;
28
29
 
29
30
  if (!token) throw new Error(TOKEN_MISSING_ERROR);
30
31
 
31
- return await mondayApiClient.execute(params, token, { apiVersion });
32
+ return mondayApiClient.execute(params, token, { apiVersion }).then(logWarnings);
32
33
  }
33
34
 
34
35
  oauthToken(code, clientId, clientSecret) {
@@ -7,11 +7,10 @@ type BlockTypes = 'normal text' | 'large title' | 'medium title' | 'small title'
7
7
  * Block content in delta format
8
8
  */
9
9
  interface BlockContent { deltaFormat: Array<object> };
10
-
11
10
  export interface ClientExecute {
12
11
  /**
13
- * Type fallback to account for new execute methods during the AI hackathon.
14
- * This will be removed when the 0.4.0 version goes out of beta.
12
+ * Type fallback to account for new execute methods during the AI hackathon.
13
+ * This will be removed when the 0.4.0 version goes out of beta.
15
14
  */
16
15
  execute (type: any, params?: any): Promise<any>;
17
16
 
@@ -205,6 +204,40 @@ export interface ClientExecute {
205
204
  },
206
205
  ): Promise<{ data: Record<string, any> }>;
207
206
  /**
207
+ * Doc command, This method adds multiple blocks to the beginning of a workdoc using HTML..
208
+ * @param type Which action to perform
209
+ */
210
+ execute(type: 'addMultiBlocksFromHtml'): Promise<{ html: string }>; /**
211
+ /**
212
+ * Doc command, This method opens the app modal on the first selected block when multiple are open.
213
+ * @param type Which action to perform
214
+ */
215
+ execute(type: 'openAppOnFirstTextualSelectedBlock'): Promise<{ data: any }>; /**
216
+ /**
217
+ * Doc command This method opens the app on the next block when multiple are selected. This is only available after calling the "openAppOnFirstTextualBlock" function.
218
+ * @param type Which action to perform
219
+ */
220
+ execute(type: 'moveToNextSelectedTextualBlock'): Promise<{ data: any }>; /**
221
+ /**
222
+ * Doc command This method opens the app on the next block when multiple are selected. This is only available after calling the "openAppOnFirstTextualBlock" function.
223
+ * @param type Which action to perform
224
+ */
225
+ execute(type: 'moveToPrevSelectedTextualBlock'): Promise<{ data: any }>; /**
226
+ /**
227
+ * Doc command, This method replaces the highlighted text with text of your choosing at the beginning of the block.
228
+ * @param type Which action to perform
229
+ */
230
+ execute(type: 'replaceHighlightText'): Promise<{ text: string }>; /**
231
+ /**
232
+ * Item Update section, This method creates or changes the content of an item's update.
233
+ * @param type Which action to perform
234
+ */
235
+ execute(type: 'updatePostContentAction'): Promise<{ suggestedRephrase: string }>; /**
236
+ /**
237
+ * This method closes the AI assistant's dialog.
238
+ * @param type Which action to perform
239
+ */
240
+ execute(type: 'closeDialog'): Promise<{ data: any }>; /**
208
241
  * Closes the modal window.
209
242
  * @param type Which action to perform
210
243
  */