monday-sdk-js 0.4.8 → 0.4.10

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.8",
3
+ "version": "0.4.10",
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) {
@@ -5,6 +5,7 @@ describe("constants", () => {
5
5
  //setup
6
6
  beforeEach(() => {
7
7
  process.env.NODE_ENV = "development";
8
+ process.env.MONDAY_DOMAIN = undefined;
8
9
  process.env.MONDAY_COM_PROTOCOL = undefined;
9
10
  process.env.MONDAY_COM_DOMAIN = undefined;
10
11
  process.env.MONDAY_SUBDOMAIN_API = undefined;
@@ -35,44 +36,79 @@ describe("constants", () => {
35
36
  expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq(MONDAY_OAUTH_TOKEN_URL);
36
37
  });
37
38
 
38
- it("constants should be correct", () => {
39
- const keys = Object.keys(constants);
40
- let key;
41
- let value;
42
- for (let i = 0; i < keys.length; i++) {
43
- key = keys[i];
44
- value = constants[key];
45
-
46
- switch (key) {
47
- case "MONDAY_DOMAIN": {
48
- expect(value).to.eq("monday.com");
49
- break;
50
- }
51
-
52
- case "MONDAY_PROTOCOL": {
53
- expect(value).to.eq("https");
54
- break;
55
- }
56
-
57
- case "MONDAY_API_URL": {
58
- expect(value).to.eq("https://api.monday.com/v2");
59
- break;
60
- }
61
-
62
- case "MONDAY_OAUTH_URL": {
63
- expect(value).to.eq("https://auth.monday.com/oauth2/authorize");
64
- break;
65
- }
66
-
67
- case "MONDAY_OAUTH_TOKEN_URL": {
68
- expect(value).to.eq("https://auth.monday.com/oauth2/token");
69
- break;
70
- }
71
-
72
- default: {
73
- throw new Error(`missing test for this constant: ${key}`);
74
- }
75
- }
76
- }
39
+ describe("check that constants are correct when NODE_ENV is development", () => {
40
+ it("MONDAY_DOMAIN should be correct", () => {
41
+ expect(constants.MONDAY_DOMAIN).to.eq("monday.com");
42
+ });
43
+
44
+ it("MONDAY_PROTOCOL should be correct", () => {
45
+ expect(constants.MONDAY_PROTOCOL).to.eq("https");
46
+ });
47
+
48
+ it("MONDAY_API_URL should be correct", () => {
49
+ expect(constants.MONDAY_API_URL).to.eq("https://api.monday.com/v2");
50
+ });
51
+
52
+ it("MONDAY_OAUTH_URL should be correct", () => {
53
+ expect(constants.MONDAY_OAUTH_URL).to.eq("https://auth.monday.com/oauth2/authorize");
54
+ });
55
+
56
+ it("MONDAY_OAUTH_TOKEN_URL should be correct", () => {
57
+ expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq("https://auth.monday.com/oauth2/token");
58
+ });
59
+ });
60
+
61
+ describe("check that constants are correct when NODE_ENV is undefined", () => {
62
+ beforeEach(() => {
63
+ process.env.NODE_ENV = undefined;
64
+ process.env.MONDAY_COM_DOMAIN = "should not be used";
65
+ });
66
+
67
+ it("MONDAY_DOMAIN should be correct", () => {
68
+ expect(constants.MONDAY_DOMAIN).to.eq("monday.com");
69
+ });
70
+
71
+ it("MONDAY_PROTOCOL should be correct", () => {
72
+ expect(constants.MONDAY_PROTOCOL).to.eq("https");
73
+ });
74
+
75
+ it("MONDAY_API_URL should be correct", () => {
76
+ expect(constants.MONDAY_API_URL).to.eq("https://api.monday.com/v2");
77
+ });
78
+
79
+ it("MONDAY_OAUTH_URL should be correct", () => {
80
+ expect(constants.MONDAY_OAUTH_URL).to.eq("https://auth.monday.com/oauth2/authorize");
81
+ });
82
+
83
+ it("MONDAY_OAUTH_TOKEN_URL should be correct", () => {
84
+ expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq("https://auth.monday.com/oauth2/token");
85
+ });
86
+ });
87
+
88
+ describe("check that constants are correct when NODE_ENV is undefined", () => {
89
+ beforeEach(() => {
90
+ process.env.NODE_ENV = "production";
91
+ process.env.MONDAY_COM_DOMAIN = "should not be used";
92
+ });
93
+
94
+ it("MONDAY_DOMAIN should be correct", () => {
95
+ expect(constants.MONDAY_DOMAIN).to.eq("monday.com");
96
+ });
97
+
98
+ it("MONDAY_PROTOCOL should be correct", () => {
99
+ expect(constants.MONDAY_PROTOCOL).to.eq("https");
100
+ });
101
+
102
+ it("MONDAY_API_URL should be correct", () => {
103
+ expect(constants.MONDAY_API_URL).to.eq("https://api.monday.com/v2");
104
+ });
105
+
106
+ it("MONDAY_OAUTH_URL should be correct", () => {
107
+ expect(constants.MONDAY_OAUTH_URL).to.eq("https://auth.monday.com/oauth2/authorize");
108
+ });
109
+
110
+ it("MONDAY_OAUTH_TOKEN_URL should be correct", () => {
111
+ expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq("https://auth.monday.com/oauth2/token");
112
+ });
77
113
  });
78
114
  });
package/src/constants.js CHANGED
@@ -7,7 +7,9 @@ function isNodeDevStageEnv() {
7
7
  }
8
8
 
9
9
  const getEnvOrDefault = (key, defaultVal) => {
10
- return isNodeDevStageEnv() && process.env[key] !== "undefined" ? process.env[key] : defaultVal;
10
+ return isNodeDevStageEnv() && process.env[key] !== "undefined" && process.env[key] !== undefined
11
+ ? process.env[key]
12
+ : defaultVal;
11
13
  };
12
14
 
13
15
  const MONDAY_PROTOCOL = () => getEnvOrDefault("MONDAY_COM_PROTOCOL", "https");
@@ -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) {