Skip to content

Commit 42d3208

Browse files
authored
fixing the type of get response (#139)
* fixing the type of get response * add tests for get response types * test types * add more test for global storage types * remove fro ts-tests
1 parent 96bc10a commit 42d3208

File tree

5 files changed

+122
-77
lines changed

5 files changed

+122
-77
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "monday-sdk-js",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"private": false,
55
"repository": "https://github.com/mondaycom/monday-sdk-js",
66
"main": "src/index.js",

ts-tests/monday-sdk-js-module.test.ts

Lines changed: 97 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,114 @@
1-
import mondaySdk from '../types';
1+
import mondaySdk from "../types";
22
const monday = mondaySdk();
33

4-
monday.api('test'); // $ExpectType Promise<{ data: object; }>
4+
monday.api("test");
55

6-
monday.setApiVersion('2023-10'); // $ExpectType void
7-
mondaySdk({ apiVersion: '2023-10' });
8-
monday.api('test', { apiVersion: '2023-07' }); // $ExpectType Promise<{ data: object; }>
6+
monday.setApiVersion("2023-10");
7+
mondaySdk({ apiVersion: "2023-10" });
8+
monday.api("test", { apiVersion: "2023-07" });
99

10-
monday.setToken('test'); // $ExpectType void
10+
monday.setToken("test");
1111

12-
monday.get('context'); // $ExpectType Promise<any>
13-
monday.get('settings'); // $ExpectType Promise<any>
14-
monday.get('itemIds'); // $ExpectType Promise<any>
15-
monday.get('sessionToken'); // $ExpectType Promise<any>
12+
monday.get("context", { appFeatureType: "AppFeatureBoardView" }).then(res => {
13+
const { data }: { data: { app: { id: number }; theme: string; boardId: number; viewMode: string } } = res;
14+
});
15+
16+
monday.get<{ text: string; level: number }>("settings").then(res => {
17+
const { data }: { data: { text: string; level: number } } = res;
18+
});
19+
20+
monday.get("itemIds").then(res => {
21+
const { data }: { data: number[] } = res;
22+
});
23+
24+
monday.get("sessionToken").then(res => {
25+
const { data }: { data: string } = res;
26+
});
27+
28+
monday.set("settings", { text: "this is a test", number: 23 });
1629

17-
monday.set('settings', {'text' : 'this is a test', 'number' : 23}); // $ExpectType Promise<any>
30+
monday.listen(
31+
"context",
32+
res => {
33+
const { data }: { data: { app: { id: number }; theme: string; itemId: number } } = res;
34+
},
35+
{ appFeatureType: "AppFeatureItemView" }
36+
);
1837

19-
monday.listen('context', res => res); // $ExpectType void
38+
monday.execute("openItemCard", { itemId: 123 });
39+
monday.execute("confirm", { message: "Hello" });
40+
monday.execute("notice", { message: "Hello" });
2041

21-
monday.execute('openItemCard', { itemId: 123 }); // $ExpectType Promise<any>
22-
monday.execute('confirm', { message: 'Hello' }); // $ExpectType Promise<{ data: { confirm: boolean; }; }>
23-
monday.execute('notice', { message: 'Hello' }); // $ExpectType Promise<any>
24-
// $ExpectType Promise<any>
25-
monday.execute('openFilesDialog', {
26-
boardId: 12345,
27-
itemId: 23456,
28-
columnId: 'files',
29-
assetId: 34567,
42+
monday.execute("openFilesDialog", {
43+
boardId: 12345,
44+
itemId: 23456,
45+
columnId: "files",
46+
assetId: 34567
3047
});
31-
// $ExpectType Promise<any>
32-
monday.execute('triggerFilesUpload', {
33-
boardId: 12345,
34-
itemId: 23456,
35-
columnId: 'files',
48+
49+
monday.execute("triggerFilesUpload", {
50+
boardId: 12345,
51+
itemId: 23456,
52+
columnId: "files"
3653
});
37-
monday.execute('openAppFeatureModal', { urlPath: '/path', urlParams: {}, width: '100px', height: '100px' }); // $ExpectType Promise<{ data: any; }>
38-
monday.execute('closeAppFeatureModal'); // $ExpectType Promise<{ data: any; }>
39-
monday.execute('valueCreatedForUser'); // $ExpectType Promise<any}>
40-
// $ExpectType Promise<any>
41-
monday.execute('addDocBlock', {
42-
type : 'normal text',
43-
content : {'deltaFormat' : [{'insert' : 'test'}]}
54+
monday.execute("openAppFeatureModal", { urlPath: "/path", urlParams: {}, width: "100px", height: "100px" });
55+
monday.execute("closeAppFeatureModal");
56+
monday.execute("valueCreatedForUser");
57+
58+
monday.execute("addDocBlock", {
59+
type: "normal text",
60+
content: { deltaFormat: [{ insert: "test" }] }
4461
});
45-
// $ExpectType Promise<any>
46-
monday.execute('updateDocBlock', {
47-
id : '1234-1234-23434dsf',
48-
content : {'deltaFormat' : [{'insert' : 'test'}]}
62+
63+
monday.execute("updateDocBlock", {
64+
id: "1234-1234-23434dsf",
65+
content: { deltaFormat: [{ insert: "test" }] }
4966
});
50-
// $ExpectType Promise<any>
51-
monday.execute('addMultiBlocks', {
52-
afterBlockId : '1234-1234-23434dsf',
53-
blocks: [
54-
{
55-
type: 'normal text',
56-
content: { deltaFormat : [{ 'insert' : 'test' }] }
57-
}
58-
]
67+
68+
monday.execute("addMultiBlocks", {
69+
afterBlockId: "1234-1234-23434dsf",
70+
blocks: [
71+
{
72+
type: "normal text",
73+
content: { deltaFormat: [{ insert: "test" }] }
74+
}
75+
]
5976
});
60-
monday.execute('closeDocModal'); // $ExpectType Promise<any>
77+
monday.execute("closeDocModal");
6178

62-
monday.oauth({ clientId: 'clientId' });
79+
monday.oauth({ clientId: "clientId" });
6380

64-
monday.storage.instance.getItem('test'); // $ExpectType Promise<GetResponse>
65-
monday.storage.instance.setItem('test', '123'); // $ExpectType Promise<SetResponse>
66-
monday.storage.instance.deleteItem('test'); // $ExpectType Promise<DeleteResponse>
81+
monday.storage.instance.getItem("test").then(res => {
82+
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
83+
});
84+
85+
monday.storage.instance.setItem("test", "123").then(res => {
86+
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
87+
});
88+
89+
monday.storage.instance.deleteItem("test").then(res => {
90+
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
91+
});
92+
93+
monday.storage.getItem("test").then(res => {
94+
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
95+
});
96+
97+
monday.storage.setItem("test", "123").then(res => {
98+
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
99+
});
100+
101+
monday.storage.deleteItem("test").then(res => {
102+
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
103+
});
67104

68-
const mondayServer = mondaySdk({ token: '123', apiVersion: '2023-10' });
105+
const mondayServer = mondaySdk({ token: "123", apiVersion: "2023-10" });
69106

70-
mondayServer.setToken('123'); // $ExpectType void
71-
mondayServer.setApiVersion('2023-10'); // $ExpectType void
72-
mondayServer.api('test'); // $ExpectType Promise<any>
73-
mondayServer.api('test', { token: 'test' }); // $ExpectType Promise<any>
74-
mondayServer.api('test', { variables: { variable1: 'test' } }); // $ExpectType Promise<any>
75-
mondayServer.api('test', { token: 'test', variables: { variable1: 'test' } }); // $ExpectType Promise<any>
76-
mondayServer.api('test', { token: 'test', apiVersion: '2023-07' }); // $ExpectType Promise<any>
77-
mondayServer.oauthToken('test', 'test', 'test'); // $ExpectType Promise<any>
107+
mondayServer.setToken("123");
108+
mondayServer.setApiVersion("2023-10");
109+
mondayServer.api("test");
110+
mondayServer.api("test", { token: "test" });
111+
mondayServer.api("test", { variables: { variable1: "test" } });
112+
mondayServer.api("test", { token: "test", variables: { variable1: "test" } });
113+
mondayServer.api("test", { token: "test", apiVersion: "2023-07" });
114+
mondayServer.oauthToken("test", "test", "test");

types/client-context.type.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ type AppVersion = {
3232
};
3333
};
3434

35+
export type Permissions = {
36+
approvedScopes: string[];
37+
requiredScopes: string[];
38+
};
39+
3540
export type BaseContext = {
3641
themeConfig?: Theme;
3742
theme: string;
@@ -40,6 +45,7 @@ export type BaseContext = {
4045
region: string;
4146
app: App;
4247
appVersion: AppVersion;
48+
permissions: Permissions;
4349
};
4450

4551
export type AppFeatureBoardViewContext = BaseContext & {

types/client-data.interface.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ type SubscribableEvents = keyof SubscribableEventsResponse;
1111

1212
type SettableTypes = "settings";
1313

14-
interface GetResponse {
15-
data: {
16-
success: boolean;
17-
value: any;
18-
version?: any;
19-
};
14+
type StorageResponse = {
15+
success: boolean;
16+
value: any;
17+
version?: any;
18+
};
19+
20+
type Response<T = StorageResponse> = {
21+
data: T;
2022
errorMessage?: string | undefined;
2123
method: string;
2224
requestId: string;
2325
type?: string | undefined;
24-
}
26+
};
2527

26-
interface DeleteResponse {
28+
type DeleteResponse = {
2729
data: {
2830
success: boolean;
2931
value: any;
@@ -32,7 +34,7 @@ interface DeleteResponse {
3234
method: string;
3335
requestId: string;
3436
type?: string | undefined;
35-
}
37+
};
3638

3739
interface SetResponse {
3840
data: {
@@ -70,8 +72,8 @@ export interface ClientData {
7072
AppFeatureType extends AppFeatureTypes = AppFeatureTypes
7173
>(
7274
type: T,
73-
params?: object & { appFeatureType?: AppFeatureType }
74-
): Promise<GetterResponse<AppFeatureType>[T] & CustomResponse>;
75+
params?: Record<string, any> & { appFeatureType?: AppFeatureType }
76+
): Promise<Response<GetterResponse<AppFeatureType>[T] & CustomResponse>>;
7577

7678
/**
7779
* Creates a listener which allows subscribing to certain types of client-side events.
@@ -86,7 +88,7 @@ export interface ClientData {
8688
>(
8789
typeOrTypes: T | ReadonlyArray<T>,
8890
callback: (res: { data: SubscribableEventsResponse<AppFeatureType>[T] & CustomResponse }) => void,
89-
params?: object & { appFeatureType?: AppFeatureType }
91+
params?: Record<string, any> & { appFeatureType?: AppFeatureType }
9092
): void;
9193

9294
/**
@@ -110,7 +112,7 @@ export interface ClientData {
110112
* Returns a stored value from the database under `key` for the app (**without any reference to the instance**)
111113
* @param {string} key - Used to access to stored data
112114
*/
113-
getItem(key: string): Promise<GetResponse>;
115+
getItem(key: string): Promise<Response>;
114116

115117
/**
116118
* Deletes a stored value from the database under `key` for the app (**without any reference to the instance**)
@@ -135,7 +137,7 @@ export interface ClientData {
135137
* Returns a stored value from the database under `key` for a specific app instance
136138
* @param key
137139
*/
138-
getItem(key: string): Promise<GetResponse>;
140+
getItem(key: string): Promise<Response>;
139141

140142
/**
141143
* Deletes a stored value from the database under `key` for a specific app instance

0 commit comments

Comments
 (0)