Skip to content

Commit

Permalink
Merge branch 'master' into clientdata-listen-ret-type
Browse files Browse the repository at this point in the history
  • Loading branch information
rami-monday committed Mar 13, 2024
2 parents 255b625 + 7d08f6f commit 082aff2
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 103 deletions.
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.4",
"private": false,
"repository": "https://github.com/mondaycom/monday-sdk-js",
"main": "src/index.js",
Expand Down
215 changes: 140 additions & 75 deletions ts-tests/monday-sdk-js-module.test.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,142 @@
import mondaySdk from '../types';
import mondaySdk from "../types";
const monday = mondaySdk();

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.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.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,
});
// $ExpectType Promise<any>
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}>
// $ExpectType Promise<any>
monday.execute('addDocBlock', {
type : 'normal text',
content : {'deltaFormat' : [{'insert' : 'test'}]}
});
// $ExpectType Promise<any>
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('closeDocModal'); // $ExpectType Promise<any>

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

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>

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>
monday.api("test");

monday.setApiVersion("2023-10");
mondaySdk({ apiVersion: "2023-10" });
monday.api("test", { apiVersion: "2023-07" });

monday.setToken("test");

monday.get("context", { appFeatureType: "AppFeatureBoardView" }).then(res => {
const { data }: { data: { app: { id: number }; theme: string; boardId: number; viewMode: string } } = res;
});

monday.get<{ text: string; level: number }>("settings").then(res => {
const { data }: { data: { text: string; level: number } } = res;
});

monday.get("itemIds").then(res => {
const { data }: { data: number[] } = res;
});

monday.get("sessionToken").then(res => {
const { data }: { data: string } = res;
});

monday.get("location").then(res => {
const {
data
}: {
data: {
href: string;
search: string;
};
} = res;
});

monday.get("filter").then(res => {
const {
data
}: {
data: {
term: string;
rules: (Record<string, any> & {
column_id?: string;
compare_value?: string[];
compare_attribute?: string;
operator?: string;
})[];
operator: string | null;
};
} = res;
});

monday.set("settings", { text: "this is a test", number: 23 });

monday.listen(
"context",
res => {
const { data }: { data: { app: { id: number }; theme: string; itemId: number } } = res;
},
{ appFeatureType: "AppFeatureItemView" }
);

monday.execute("openItemCard", { itemId: 123 });
monday.execute("confirm", { message: "Hello" });
monday.execute("notice", { message: "Hello" });

monday.execute("openFilesDialog", {
boardId: 12345,
itemId: 23456,
columnId: "files",
assetId: 34567
});

monday.execute("triggerFilesUpload", {
boardId: 12345,
itemId: 23456,
columnId: "files"
});
monday.execute("openAppFeatureModal", { urlPath: "/path", urlParams: {}, width: "100px", height: "100px" });
monday.execute("closeAppFeatureModal");
monday.execute("valueCreatedForUser");

monday.execute("addDocBlock", {
type: "normal text",
content: { deltaFormat: [{ insert: "test" }] }
});

monday.execute("updateDocBlock", {
id: "1234-1234-23434dsf",
content: { deltaFormat: [{ insert: "test" }] }
});

monday.execute("addMultiBlocks", {
afterBlockId: "1234-1234-23434dsf",
blocks: [
{
type: "normal text",
content: { deltaFormat: [{ insert: "test" }] }
}
]
});
monday.execute("closeDocModal");

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

monday.storage.instance.getItem("test").then(res => {
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
});

monday.storage.instance.setItem("test", "123").then(res => {
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
});

monday.storage.instance.deleteItem("test").then(res => {
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
});

monday.storage.getItem("test").then(res => {
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
});

monday.storage.setItem("test", "123").then(res => {
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
});

monday.storage.deleteItem("test").then(res => {
const { data }: { data: { error?: string; success: boolean }; errorMessage?: string } = res;
});

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

mondayServer.setToken("123");
mondayServer.setApiVersion("2023-10");
mondayServer.api("test");
mondayServer.api("test", { token: "test" });
mondayServer.api("test", { variables: { variable1: "test" } });
mondayServer.api("test", { token: "test", variables: { variable1: "test" } });
mondayServer.api("test", { token: "test", apiVersion: "2023-07" });
mondayServer.oauthToken("test", "test", "test");
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
50 changes: 36 additions & 14 deletions types/client-data.interface.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
import { AppFeatureContextMap, AppFeatureTypes } from "./client-context.type";

export type LocationResponse = Record<string, any> & {
href: string;
search: string;
};

export type FilterResponse = Record<string, any> & {
term: string;
rules: (Record<string, any> & {
column_id?: string;
compare_value?: string[];
compare_attribute?: string;
operator?: string;
})[];
operator: string | null;
};

type SubscribableEventsResponse<AppFeatureType extends AppFeatureTypes = AppFeatureTypes> = {
context: AppFeatureContextMap[AppFeatureType];
settings: Record<string, any>;
itemIds: number[];
events: Record<string, any>;
location: LocationResponse;
filter: FilterResponse;
};

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 +52,7 @@ interface DeleteResponse {
method: string;
requestId: string;
type?: string | undefined;
}
};

interface SetResponse {
data: {
Expand All @@ -52,6 +72,8 @@ export type GetterResponse<AppFeatureType extends AppFeatureTypes = AppFeatureTy
settings: Record<string, any>;
itemIds: number[];
sessionToken: string;
location: LocationResponse;
filter: FilterResponse;
};
export interface ClientData {
/**
Expand All @@ -70,8 +92,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 @@ -87,7 +109,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 @@ -111,7 +133,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 @@ -136,7 +158,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

0 comments on commit 082aff2

Please sign in to comment.