monday-sdk-js 0.4.0 → 0.4.1

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.1",
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) {
@@ -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
  }