monday-sdk-js 0.3.2 → 0.3.4

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.3.2",
3
+ "version": "0.3.4",
4
4
  "private": false,
5
5
  "repository": "https://github.com/mondaycom/monday-sdk-js",
6
6
  "main": "src/index.js",
@@ -33,30 +33,30 @@ describe("Monday Client Test", () => {
33
33
 
34
34
  describe("setters", () => {
35
35
  it("should set client id correctly", () => {
36
- const newId = "newId";
37
- mondayClient.setClientId(newId);
38
- expect(mondayClient._clientId).to.equal(newId);
39
- });
40
-
41
- it("should set client id correctly (check biding)", () => {
42
36
  const newId = "newId";
43
37
  const { setClientId } = mondayClient;
38
+
44
39
  setClientId(newId);
40
+
45
41
  expect(mondayClient._clientId).to.equal(newId);
46
42
  });
47
43
 
48
44
  it("should set the api token correctly", () => {
49
45
  const newToken = "new toekn";
50
- mondayClient.setToken(newToken);
46
+ const { setToken } = mondayClient;
47
+
48
+ setToken(newToken);
49
+
51
50
  expect(mondayClient._apiToken).to.equal(newToken);
52
51
  });
53
52
 
54
- it("should set the api token correctly (check bindings)", () => {
55
- const newToken = "new toekn";
53
+ it("should set the version correctly", () => {
54
+ const newVersion = "2023-01";
55
+ const { setApiVersion } = mondayClient;
56
56
 
57
- const { setToken } = mondayClient;
58
- setToken(newToken);
59
- expect(mondayClient._apiToken).to.equal(newToken);
57
+ setApiVersion(newVersion);
58
+
59
+ expect(mondayClient._apiVersion).to.eq(newVersion);
60
60
  });
61
61
  });
62
62
 
package/src/client.js CHANGED
@@ -10,11 +10,13 @@ class MondayClientSdk {
10
10
  constructor(options = {}) {
11
11
  this._clientId = options.clientId;
12
12
  this._apiToken = options.apiToken;
13
+ this._apiVersion = options.apiVersion;
13
14
 
14
15
  this.listeners = {};
15
16
 
16
17
  this.setClientId = this.setClientId.bind(this);
17
18
  this.setToken = this.setToken.bind(this);
19
+ this.setApiVersion = this.setApiVersion.bind(this);
18
20
  this.api = this.api.bind(this);
19
21
  this.listen = this.listen.bind(this);
20
22
  this.get = this.get.bind(this);
@@ -46,11 +48,17 @@ class MondayClientSdk {
46
48
  this._apiToken = token;
47
49
  }
48
50
 
51
+ setApiVersion(apiVersion) {
52
+ this._apiVersion = apiVersion;
53
+ }
54
+
49
55
  api(query, options = {}) {
50
56
  const params = { query, variables: options.variables };
51
57
  const token = options.token || this._apiToken;
58
+ const apiVersion = options.apiVersion || this._apiVersion;
59
+
52
60
  if (token) {
53
- return mondayApiClient.execute(params, token);
61
+ return mondayApiClient.execute(params, token, { apiVersion });
54
62
  } else {
55
63
  return new Promise((resolve, reject) => {
56
64
  this._localApi("api", { params })
@@ -34,6 +34,17 @@ describe("mondayApiClient", () => {
34
34
  });
35
35
  });
36
36
 
37
+ it("should call node fetch with the version header", async () => {
38
+ const apiVersion = "2023-01";
39
+ await mondayApiClient.execute("query { boards { id, name }}", "api_token", { apiVersion });
40
+ assert.calledOnce(nodeFetchStub);
41
+ assert.calledWithExactly(nodeFetchStub, "https://api.monday.com/v2", {
42
+ body: '"query { boards { id, name }}"',
43
+ headers: { Authorization: "api_token", "Content-Type": "application/json", "API-Version": apiVersion },
44
+ method: "POST"
45
+ });
46
+ });
47
+
37
48
  it(`should throw ${mondayApiClient.TOKEN_IS_REQUIRED_ERROR}`, async () => {
38
49
  let errorMessage;
39
50
  try {
@@ -11,7 +11,8 @@ function apiRequest(url, data, token, options = {}) {
11
11
  body: JSON.stringify(data || {}),
12
12
  headers: {
13
13
  Authorization: token,
14
- "Content-Type": "application/json"
14
+ "Content-Type": "application/json",
15
+ ...(options.apiVersion ? { "API-Version": options.apiVersion } : {})
15
16
  }
16
17
  });
17
18
  }
@@ -17,6 +17,11 @@ describe("server sdk", () => {
17
17
  const serverSdk = initServerSdk({ token: "sometoken123" });
18
18
  expect(serverSdk._token).to.eq("sometoken123");
19
19
  });
20
+
21
+ it("should be able to init serverSdk with API version", () => {
22
+ const serverSdk = initServerSdk({ apiVersion: "2023-01" });
23
+ expect(serverSdk._apiVersion).to.eq("2023-01");
24
+ });
20
25
  });
21
26
 
22
27
  describe("setToken", () => {
@@ -36,6 +41,18 @@ describe("server sdk", () => {
36
41
  });
37
42
  });
38
43
 
44
+ describe("setApiVersion", () => {
45
+ it("should be able to set the version", () => {
46
+ const serverSdk = initServerSdk();
47
+ expect(serverSdk._apiVersion).to.eq(undefined);
48
+
49
+ const { setApiVersion } = serverSdk;
50
+ setApiVersion("2023-01");
51
+
52
+ expect(serverSdk._apiVersion).to.eq("2023-01");
53
+ });
54
+ });
55
+
39
56
  describe("api", () => {
40
57
  let mondayApiClientExecuteStub;
41
58
 
@@ -60,7 +77,8 @@ describe("server sdk", () => {
60
77
  assert.calledWithExactly(
61
78
  mondayApiClientExecuteStub,
62
79
  { query: "query { boards { id, name }}", variables: undefined },
63
- "api_token"
80
+ "api_token",
81
+ { apiVersion: undefined }
64
82
  );
65
83
  });
66
84
 
@@ -101,7 +119,8 @@ describe("server sdk", () => {
101
119
  `,
102
120
  variables: { columnValues: { numbers: 3 }, pulseName: "new pulse" }
103
121
  },
104
- "api_token"
122
+ "api_token",
123
+ { apiVersion: undefined }
105
124
  );
106
125
  });
107
126
 
@@ -120,7 +139,47 @@ describe("server sdk", () => {
120
139
  assert.calledWithExactly(
121
140
  mondayApiClientExecuteStub,
122
141
  { query: "query { boards { id, name }}", variables: undefined },
123
- "api_token_2"
142
+ "api_token_2",
143
+ { apiVersion: undefined }
144
+ );
145
+ });
146
+
147
+ it("should provide version to mondayApi", async () => {
148
+ const serverSdk = initServerSdk({ token: "api_token", apiVersion: "2023-01" });
149
+ serverSdk.setApiVersion("2023-04");
150
+ await serverSdk.api("query { boards { id, name }}");
151
+ assert.calledOnce(mondayApiClientExecuteStub);
152
+ assert.calledWithExactly(
153
+ mondayApiClientExecuteStub,
154
+ { query: "query { boards { id, name }}", variables: undefined },
155
+ "api_token",
156
+ { apiVersion: "2023-04" }
157
+ );
158
+ });
159
+
160
+ it("should prefer version from method options when calling mondayApi", async () => {
161
+ const serverSdk = initServerSdk({ token: "api_token", apiVersion: "2023-01" });
162
+ serverSdk.setApiVersion("2023-04");
163
+ await serverSdk.api("query { boards { id, name }}", { apiVersion: "2023-07" });
164
+ assert.calledOnce(mondayApiClientExecuteStub);
165
+ assert.calledWithExactly(
166
+ mondayApiClientExecuteStub,
167
+ { query: "query { boards { id, name }}", variables: undefined },
168
+ "api_token",
169
+ { apiVersion: "2023-07" }
170
+ );
171
+ });
172
+
173
+ it("should call to mondayApi prefer version from options", async () => {
174
+ const serverSdk = initServerSdk({ token: "api_token", apiVersion: "2023-01" });
175
+ serverSdk.setApiVersion("2023-04");
176
+ await serverSdk.api("query { boards { id, name }}", { apiVersion: "2023-07" });
177
+ assert.calledOnce(mondayApiClientExecuteStub);
178
+ assert.calledWithExactly(
179
+ mondayApiClientExecuteStub,
180
+ { query: "query { boards { id, name }}", variables: undefined },
181
+ "api_token",
182
+ { apiVersion: "2023-07" }
124
183
  );
125
184
  });
126
185
 
package/src/server.js CHANGED
@@ -6,8 +6,10 @@ const TOKEN_MISSING_ERROR = "Should send 'token' as an option or call mondaySdk.
6
6
  class MondayServerSdk {
7
7
  constructor(options = {}) {
8
8
  this._token = options.token;
9
+ this._apiVersion = options.apiVersion;
9
10
 
10
11
  this.setToken = this.setToken.bind(this);
12
+ this.setApiVersion = this.setApiVersion.bind(this);
11
13
  this.api = this.api.bind(this);
12
14
  }
13
15
 
@@ -15,13 +17,18 @@ class MondayServerSdk {
15
17
  this._token = token;
16
18
  }
17
19
 
20
+ setApiVersion(apiVersion) {
21
+ this._apiVersion = apiVersion;
22
+ }
23
+
18
24
  async api(query, options = {}) {
19
25
  const params = { query, variables: options.variables };
20
26
  const token = options.token || this._token;
27
+ const apiVersion = options.apiVersion || this._apiVersion;
21
28
 
22
29
  if (!token) throw new Error(TOKEN_MISSING_ERROR);
23
30
 
24
- return await mondayApiClient.execute(params, token);
31
+ return await mondayApiClient.execute(params, token, { apiVersion });
25
32
  }
26
33
 
27
34
  oauthToken(code, clientId, clientSecret) {
@@ -9,6 +9,12 @@ interface APIOptions {
9
9
  * An object containing GraphQL query variables
10
10
  */
11
11
  variables?: object | undefined;
12
+
13
+ /**
14
+ * A string specifying which version of the API should be used
15
+ * If not set, will use the default version (stable)
16
+ */
17
+ apiVersion?: string;
12
18
  }
13
19
 
14
20
  interface OAuthOptions {
@@ -184,13 +184,27 @@ export interface ClientExecute {
184
184
  height?: string;
185
185
  },
186
186
  ): Promise<{ data: any }>;
187
+ /**
188
+ * Opens the provided link in a new tab.
189
+ * @param type Which action to perform
190
+ * @param params Optional parameters for the action
191
+ */
192
+ execute(
193
+ type: 'openLinkInTab',
194
+ params: {
195
+ /**
196
+ * The URL to open a new tab with
197
+ */
198
+ url: string;
199
+ },
200
+ ): Promise<{ data: Record<string, any> }>;
187
201
  /**
188
202
  * Closes the modal window.
189
203
  * @param type Which action to perform
190
204
  */
191
205
  execute(type: 'closeAppFeatureModal'): Promise<{ data: any }>;
192
206
  /**
193
- * Notifies the monday platform when a user gains a first value in your app.
207
+ * Notifies the monday platform when a user gains a first value in your app.
194
208
  * @param type Which action to perform
195
209
  */
196
210
  execute(type: 'valueCreatedForUser'): Promise<any>;
@@ -207,9 +221,9 @@ export interface ClientExecute {
207
221
  */
208
222
  type: BlockTypes;
209
223
  /**
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.
224
+ * Used to specify where in the doc the new block should go.
225
+ * Provide the block's ID that will be above the new block.
226
+ * Without this parameter, the block will appear at the top of the doc.
213
227
  */
214
228
  afterBlockId?: string | undefined;
215
229
  /**
@@ -217,7 +231,7 @@ export interface ClientExecute {
217
231
  */
218
232
  content: BlockContent;
219
233
  },
220
- ): Promise<any>;
234
+ ): Promise<any>;
221
235
  /**
222
236
  * Updates a block's content
223
237
  * @param type Which action to perform
@@ -227,7 +241,7 @@ export interface ClientExecute {
227
241
  type: 'updateDocBlock',
228
242
  params: {
229
243
  /**
230
- * The block's unique identifier.
244
+ * The block's unique identifier.
231
245
  */
232
246
  id: string;
233
247
  /**
@@ -245,11 +259,11 @@ export interface ClientExecute {
245
259
  type: 'addMultiBlocks',
246
260
  params: {
247
261
  /**
248
- * The block's unique identifier.
262
+ * The block's unique identifier.
249
263
  */
250
264
  afterBlockId?: string | undefined;
251
265
  /**
252
- * The block's content in Delta format.
266
+ * The block's content in Delta format.
253
267
  * We support the following block types
254
268
  */
255
269
  blocks: Array<{ type: BlockTypes, content: BlockContent}>;
@@ -260,4 +274,4 @@ export interface ClientExecute {
260
274
  * @param type Which action to perform
261
275
  */
262
276
  execute (type: 'closeDocModal'): Promise<any>;
263
- }
277
+ }
package/types/index.d.ts CHANGED
@@ -10,7 +10,7 @@ type MondayClientSdk = ClientData & ClientExecute & ClientApi;
10
10
  interface MondayServerSdk {
11
11
  setToken(token: string): void;
12
12
 
13
- api(query: string, options?: Partial<{ token: string, variables: object } >): Promise<any>;
13
+ api(query: string, options?: Partial<{ token: string, variables: object, apiVersion: string } >): Promise<any>;
14
14
 
15
15
  oauthToken(code: string, clientId: string, clientSecret: string): Promise<any>;
16
16
  }