Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing the type of get response #139

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monday-sdk-js",
"version": "0.5.2",
"version": "0.5.3",
"private": false,
"repository": "https://github.com/mondaycom/monday-sdk-js",
"main": "src/index.js",
Expand Down
158 changes: 103 additions & 55 deletions ts-tests/monday-sdk-js-module.test.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rami-monday let's remove all the $ExpectType comments as we're not using typescript lint here anyway, so they don't have any influence and they are only confusing

Original file line number Diff line number Diff line change
@@ -1,77 +1,125 @@
import mondaySdk from '../types';
import mondaySdk from "../types";
const monday = mondaySdk();

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

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

monday.setToken('test'); // $ExpectType void
monday.setToken("test"); // $ExpectType void

monday.get('context'); // $ExpectType Promise<any>
monday.get('settings'); // $ExpectType Promise<any>
monday.get('itemIds'); // $ExpectType Promise<any>
monday.get('sessionToken'); // $ExpectType Promise<any>
monday.get("context", { appFeatureType: "AppFeatureBoardView" }).then(res => {
const { data } = res;
data.app.id; // $ExpectType number
data.permissions.approvedScopes; // $ExpectType string[]
data.theme; // $ExpectType string
data.boardId; // $ExpectType number
data.viewMode; // $ExpectType string
}); // $ExpectType Promise<{ data: string; }>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these assertions are not promising anything about the types of these primitives, i.e. if boardId changes to string, this test won't catch it. I recommend using https://www.npmjs.com/package/expect-type


monday.set('settings', {'text' : 'this is a test', 'number' : 23}); // $ExpectType Promise<any>
monday.get<{ text: string; level: number }>("settings").then(res => {
const { data } = res;
data.text; // $ExpectType string
data.level; // $ExpectType number
}); // $ExpectType Promise<{ data: object; }>

monday.listen('context', res => res); // $ExpectType void
monday.get("itemIds").then(res => {
const { data } = res;
data[0]; // $ExpectType number
}); // $ExpectType Promise<{ data: number[]; }>

monday.execute('openItemCard', { itemId: 123 }); // $ExpectType Promise<any>
monday.execute('confirm', { message: 'Hello' }); // $ExpectType Promise<{ data: { confirm: boolean; }; }>
monday.execute('notice', { message: 'Hello' }); // $ExpectType Promise<any>
monday.get("sessionToken").then(res => {
const { data } = res;
data; // $ExpectType string
}); // $ExpectType Promise<{ data: string; }>

monday.set("settings", { text: "this is a test", number: 23 }); // $ExpectType Promise<any>

monday.listen("context", res => res); // $ExpectType void

monday.execute("openItemCard", { itemId: 123 }); // $ExpectType Promise<any>
monday.execute("confirm", { message: "Hello" }); // $ExpectType Promise<{ data: { confirm: boolean; }; }>
monday.execute("notice", { message: "Hello" }); // $ExpectType Promise<any>
// $ExpectType Promise<any>
monday.execute('openFilesDialog', {
boardId: 12345,
itemId: 23456,
columnId: 'files',
assetId: 34567,
monday.execute("openFilesDialog", {
boardId: 12345,
itemId: 23456,
columnId: "files",
assetId: 34567
});
// $ExpectType Promise<any>
monday.execute('triggerFilesUpload', {
boardId: 12345,
itemId: 23456,
columnId: 'files',
monday.execute("triggerFilesUpload", {
boardId: 12345,
itemId: 23456,
columnId: "files"
});
monday.execute('openAppFeatureModal', { urlPath: '/path', urlParams: {}, width: '100px', height: '100px' }); // $ExpectType Promise<{ data: any; }>
monday.execute('closeAppFeatureModal'); // $ExpectType Promise<{ data: any; }>
monday.execute('valueCreatedForUser'); // $ExpectType Promise<any}>
monday.execute("openAppFeatureModal", { urlPath: "/path", urlParams: {}, width: "100px", height: "100px" }); // $ExpectType Promise<{ data: any; }>
monday.execute("closeAppFeatureModal"); // $ExpectType Promise<{ data: any; }>
monday.execute("valueCreatedForUser"); // $ExpectType Promise<any}>
// $ExpectType Promise<any>
monday.execute('addDocBlock', {
type : 'normal text',
content : {'deltaFormat' : [{'insert' : 'test'}]}
monday.execute("addDocBlock", {
type: "normal text",
content: { deltaFormat: [{ insert: "test" }] }
});
// $ExpectType Promise<any>
monday.execute('updateDocBlock', {
id : '1234-1234-23434dsf',
content : {'deltaFormat' : [{'insert' : 'test'}]}
monday.execute("updateDocBlock", {
id: "1234-1234-23434dsf",
content: { deltaFormat: [{ insert: "test" }] }
});
// $ExpectType Promise<any>
monday.execute('addMultiBlocks', {
afterBlockId : '1234-1234-23434dsf',
blocks: [
{
type: 'normal text',
content: { deltaFormat : [{ 'insert' : 'test' }] }
}
]
monday.execute("addMultiBlocks", {
afterBlockId: "1234-1234-23434dsf",
blocks: [
{
type: "normal text",
content: { deltaFormat: [{ insert: "test" }] }
}
]
});
monday.execute('closeDocModal'); // $ExpectType Promise<any>
monday.execute("closeDocModal"); // $ExpectType Promise<any>

monday.oauth({ clientId: "clientId" });

monday.storage.instance.getItem("test").then(res => {
const { data } = res;
data.success; // $ExpectType boolean
data.value; // $ExpectType any
}); // $ExpectType Promise<GetResponse>

monday.storage.instance.setItem("test", "123").then(res => {
const { data } = res;
data.success; // $ExpectType boolean
}); // $ExpectType Promise<SetResponse>

monday.storage.instance.deleteItem("test").then(res => {
const { data } = res;
data.success; // $ExpectType boolean
}); // $ExpectType Promise<DeleteResponse>

monday.storage.getItem("test").then(res => {
const { data } = res;
data.success; // $ExpectType boolean
data.value; // $ExpectType any
}); // $ExpectType Promise<GetResponse>

monday.oauth({ clientId: 'clientId' });
monday.storage.setItem("test", "123").then(res => {
const { data } = res;
data.success; // $ExpectType boolean
}); // $ExpectType Promise<SetResponse>

monday.storage.instance.getItem('test'); // $ExpectType Promise<GetResponse>
monday.storage.instance.setItem('test', '123'); // $ExpectType Promise<SetResponse>
monday.storage.instance.deleteItem('test'); // $ExpectType Promise<DeleteResponse>
monday.storage.deleteItem("test").then(res => {
const { data } = res;
data.success; // $ExpectType boolean
}); // $ExpectType Promise<DeleteResponse>

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

mondayServer.setToken('123'); // $ExpectType void
mondayServer.setApiVersion('2023-10'); // $ExpectType void
mondayServer.api('test'); // $ExpectType Promise<any>
mondayServer.api('test', { token: 'test' }); // $ExpectType Promise<any>
mondayServer.api('test', { variables: { variable1: 'test' } }); // $ExpectType Promise<any>
mondayServer.api('test', { token: 'test', variables: { variable1: 'test' } }); // $ExpectType Promise<any>
mondayServer.api('test', { token: 'test', apiVersion: '2023-07' }); // $ExpectType Promise<any>
mondayServer.oauthToken('test', 'test', 'test'); // $ExpectType Promise<any>
mondayServer.setToken("123"); // $ExpectType void
mondayServer.setApiVersion("2023-10"); // $ExpectType void
mondayServer.api("test"); // $ExpectType Promise<any>
mondayServer.api("test", { token: "test" }); // $ExpectType Promise<any>
mondayServer.api("test", { variables: { variable1: "test" } }); // $ExpectType Promise<any>
mondayServer.api("test", { token: "test", variables: { variable1: "test" } }); // $ExpectType Promise<any>
mondayServer.api("test", { token: "test", apiVersion: "2023-07" }); // $ExpectType Promise<any>
mondayServer.oauthToken("test", "test", "test"); // $ExpectType Promise<any>
6 changes: 6 additions & 0 deletions types/client-context.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type AppVersion = {
};
};

export type Permissions = {
approvedScopes: string[];
requiredScopes: string[];
};

export type BaseContext = {
themeConfig?: Theme;
theme: string;
Expand All @@ -40,6 +45,7 @@ export type BaseContext = {
region: string;
app: App;
appVersion: AppVersion;
permissions: Permissions;
};

export type AppFeatureBoardViewContext = BaseContext & {
Expand Down
30 changes: 16 additions & 14 deletions types/client-data.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ type SubscribableEvents = keyof SubscribableEventsResponse;

type SettableTypes = "settings";

interface GetResponse {
data: {
success: boolean;
value: any;
version?: any;
};
type StorageResponse = {
success: boolean;
value: any;
version?: any;
};

type Response<T = StorageResponse> = {
data: T;
errorMessage?: string | undefined;
method: string;
requestId: string;
type?: string | undefined;
}
};

interface DeleteResponse {
type DeleteResponse = {
data: {
success: boolean;
value: any;
Expand All @@ -32,7 +34,7 @@ interface DeleteResponse {
method: string;
requestId: string;
type?: string | undefined;
}
};

interface SetResponse {
data: {
Expand Down Expand Up @@ -70,8 +72,8 @@ export interface ClientData {
AppFeatureType extends AppFeatureTypes = AppFeatureTypes
>(
type: T,
params?: object & { appFeatureType?: AppFeatureType }
): Promise<GetterResponse<AppFeatureType>[T] & CustomResponse>;
params?: Record<string, any> & { appFeatureType?: AppFeatureType }
): Promise<Response<GetterResponse<AppFeatureType>[T] & CustomResponse>>;

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

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

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

/**
* Deletes a stored value from the database under `key` for a specific app instance
Expand Down
Loading