monday-sdk-js 0.4.0 → 0.4.2

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.4.0",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "repository": "https://github.com/mondaycom/monday-sdk-js",
6
6
  "main": "src/index.js",
@@ -47,6 +47,7 @@
47
47
  "precommit": "yarn lint && yarn style-check",
48
48
  "lint": "eslint './src/**/*.*'",
49
49
  "style-check": "prettier --check './src/**/*.js'",
50
+ "style-fix": "prettier --write './src/**/*.js'",
50
51
  "compile-types": "tsc --noEmit"
51
52
  }
52
53
  }
package/src/client.js CHANGED
@@ -6,6 +6,11 @@ const { initBackgroundTracking } = require("./services/background-tracking-servi
6
6
 
7
7
  const EMPTY_ARRAY = [];
8
8
 
9
+ const STORAGE_SEGMENT_KINDS = {
10
+ GLOBAL: "v2",
11
+ INSTANCE: "instance"
12
+ };
13
+
9
14
  class MondayClientSdk {
10
15
  constructor(options = {}) {
11
16
  this._clientId = options.clientId;
@@ -26,6 +31,9 @@ class MondayClientSdk {
26
31
  this._receiveMessage = this._receiveMessage.bind(this);
27
32
 
28
33
  this.storage = {
34
+ setItem: this.setStorageItem.bind(this),
35
+ getItem: this.getStorageItem.bind(this),
36
+ deleteItem: this.deleteStorageItem.bind(this),
29
37
  instance: {
30
38
  setItem: this.setStorageInstanceItem.bind(this),
31
39
  getItem: this.getStorageInstanceItem.bind(this),
@@ -110,16 +118,28 @@ class MondayClientSdk {
110
118
  window.location = url;
111
119
  }
112
120
 
121
+ setStorageItem(key, value, options = {}) {
122
+ return this._localApi("storage", { method: "set", key, value, options, segment: STORAGE_SEGMENT_KINDS.GLOBAL });
123
+ }
124
+
125
+ getStorageItem(key, options = {}) {
126
+ return this._localApi("storage", { method: "get", key, options, segment: STORAGE_SEGMENT_KINDS.GLOBAL });
127
+ }
128
+
129
+ deleteStorageItem(key, options = {}) {
130
+ return this._localApi("storage", { method: "delete", key, options, segment: STORAGE_SEGMENT_KINDS.GLOBAL });
131
+ }
132
+
113
133
  setStorageInstanceItem(key, value, options = {}) {
114
- return this._localApi("storage", { method: "set", key, value, options, segment: "instance" });
134
+ return this._localApi("storage", { method: "set", key, value, options, segment: STORAGE_SEGMENT_KINDS.INSTANCE });
115
135
  }
116
136
 
117
137
  getStorageInstanceItem(key, options = {}) {
118
- return this._localApi("storage", { method: "get", key, options, segment: "instance" });
138
+ return this._localApi("storage", { method: "get", key, options, segment: STORAGE_SEGMENT_KINDS.INSTANCE });
119
139
  }
120
140
 
121
141
  deleteStorageInstanceItem(key, options = {}) {
122
- return this._localApi("storage", { method: "delete", key, options, segment: "instance" });
142
+ return this._localApi("storage", { method: "delete", key, options, segment: STORAGE_SEGMENT_KINDS.INSTANCE });
123
143
  }
124
144
 
125
145
  _localApi(method, args) {
@@ -1,4 +1,4 @@
1
- interface APIOptions {
1
+ export interface APIOptions {
2
2
  /**
3
3
  * Access token for the API
4
4
  * If not set, will use the credentials of the current user (client only)
@@ -12,9 +12,9 @@ interface APIOptions {
12
12
 
13
13
  /**
14
14
  * A string specifying which version of the API should be used
15
- * If not set, will use the default version (stable)
15
+ * If not set, will use the current API version
16
16
  */
17
- apiVersion?: string;
17
+ apiVersion?: string | undefined;
18
18
  }
19
19
 
20
20
  interface OAuthOptions {
@@ -46,6 +46,12 @@ export interface ClientApi {
46
46
  */
47
47
  setToken(token: string): void;
48
48
 
49
+ /**
50
+ * Allows to set the API version for future requests.
51
+ * @param version A string specifying which version of the API should be used
52
+ */
53
+ setApiVersion(version: string): void;
54
+
49
55
  /**
50
56
  * Performs a client-side redirection of the user to the monday OAuth screen with your client ID embedded in the URL,
51
57
  * sin order to get their approval to generate a temporary OAuth token based on your requested permission scopes.
@@ -17,7 +17,7 @@ interface GetResponse {
17
17
  interface DeleteResponse {
18
18
  data: {
19
19
  success: boolean;
20
- value: any;
20
+ value: any;
21
21
  };
22
22
  errorMessage?: string | undefined;
23
23
  method: string;
@@ -70,7 +70,7 @@ export interface ClientData {
70
70
  * @param params object containing the data you want to update
71
71
  */
72
72
  set(
73
- type: SettableTypes,
73
+ type: SettableTypes,
74
74
  params: object,
75
75
  ): Promise<any>;
76
76
 
@@ -84,26 +84,50 @@ export interface ClientData {
84
84
  * Apps cannot share storage across accounts or even across apps installed in the same location.
85
85
  */
86
86
  storage: {
87
+ /**
88
+ * Returns a stored value from the database under `key` for the app (**without any reference to the instance**)
89
+ * @param {string} key - Used to access to stored data
90
+ */
91
+ getItem(key: string): Promise<GetResponse>;
92
+
93
+ /**
94
+ * Deletes a stored value from the database under `key` for the app (**without any reference to the instance**)
95
+ * @param {string} key - Used to delete the stored data
96
+ */
97
+ deleteItem(key: string): Promise<DeleteResponse>;
98
+
99
+ /**
100
+ * Stores `value` under `key` in the database for the app (**without any reference to the instance**)
101
+ * @param {string} key - Used to delete the stored data
102
+ * @param {any} value - The value to store
103
+ * @param {object=} options
104
+ * @param {string=} options.previous_version - Use the new version of the storage (instance-less)
105
+ */
106
+ setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
107
+ /***
108
+ * The instance storage is a key-value database that is scoped to a specific app instance.
109
+ * **Does not work** for instance-less apps.
110
+ */
87
111
  instance: {
88
112
  /**
89
- * Returns a stored value from the database under `key`
113
+ * Returns a stored value from the database under `key` for a specific app instance
90
114
  * @param key
91
115
  */
92
116
  getItem(key: string): Promise<GetResponse>;
93
-
117
+
94
118
  /**
95
- * Deletes a stored value from the database under `key`
119
+ * Deletes a stored value from the database under `key` for a specific app instance
96
120
  * @param key
97
121
  */
98
122
  deleteItem(key: string): Promise<DeleteResponse>;
99
-
123
+
100
124
  /**
101
- * Stores `value` under `key` in the database
125
+ * Stores `value` under `key` in the database for a specific app instance
102
126
  * @param key
103
127
  * @param value
104
128
  * @param options
105
129
  */
106
130
  setItem(key: string, value: any, options?: { previous_version?: string }): Promise<SetResponse>;
107
131
  };
108
- };
132
+ };
109
133
  }
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Original Definitions were contributed by: Josh Parnham <https://github.com/josh->
2
2
  import { ClientData } from './client-data.interface';
3
3
  import { ClientExecute } from './client-execute.interface';
4
- import { ClientApi } from './client-api.interface';
4
+ import { ClientApi, APIOptions } from './client-api.interface';
5
5
 
6
6
  export as namespace mondaySdk;
7
7
 
@@ -10,7 +10,9 @@ 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, apiVersion: string } >): Promise<any>;
13
+ setApiVersion(version: string): void;
14
+
15
+ api(query: string, options?: APIOptions): Promise<any>;
14
16
 
15
17
  oauthToken(code: string, clientId: string, clientSecret: string): Promise<any>;
16
18
  }
@@ -19,12 +21,14 @@ declare function init(
19
21
  config?: Partial<{
20
22
  clientId: string;
21
23
  apiToken: string;
24
+ apiVersion: string;
22
25
  }>,
23
26
  ): MondayClientSdk;
24
27
 
25
28
  declare function init(
26
29
  config?: Partial<{
27
30
  token: string;
31
+ apiVersion: string;
28
32
  }>,
29
33
  ): MondayServerSdk;
30
34