monday-sdk-js 0.4.8 → 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 +1 -1
- package/package.json +1 -1
- package/src/client.js +6 -8
- package/src/helpers/monday-api-helpers.js +43 -0
- package/src/server.js +3 -2
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
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
|
-
|
|
71
|
+
responsePromise = mondayApiClient.execute(params, token, { apiVersion });
|
|
70
72
|
} else {
|
|
71
|
-
|
|
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
|
-
|
|
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
|
|
32
|
+
return mondayApiClient.execute(params, token, { apiVersion }).then(logWarnings);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
oauthToken(code, clientId, clientSecret) {
|