diff --git a/package-lock.json b/package-lock.json index 1305d360..08bb0b11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "monday-sdk-js", - "version": "0.5.1", + "version": "0.5.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "monday-sdk-js", - "version": "0.5.1", + "version": "0.5.3", "license": "MIT", "dependencies": { "node-fetch": "^2.6.0" diff --git a/package.json b/package.json index bbc90391..483479d4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/ts-tests/monday-sdk-js-module.test.ts b/ts-tests/monday-sdk-js-module.test.ts index ebbe9f66..27edbd1c 100644 --- a/ts-tests/monday-sdk-js-module.test.ts +++ b/ts-tests/monday-sdk-js-module.test.ts @@ -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 -monday.get('settings'); // $ExpectType Promise -monday.get('itemIds'); // $ExpectType Promise -monday.get('sessionToken'); // $ExpectType Promise - -monday.set('settings', {'text' : 'this is a test', 'number' : 23}); // $ExpectType Promise - -monday.listen('context', res => res); // $ExpectType void - -monday.execute('openItemCard', { itemId: 123 }); // $ExpectType Promise -monday.execute('confirm', { message: 'Hello' }); // $ExpectType Promise<{ data: { confirm: boolean; }; }> -monday.execute('notice', { message: 'Hello' }); // $ExpectType Promise -// $ExpectType Promise -monday.execute('openFilesDialog', { - boardId: 12345, - itemId: 23456, - columnId: 'files', - assetId: 34567, -}); -// $ExpectType Promise -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 -// $ExpectType Promise -monday.execute('addDocBlock', { - type : 'normal text', - content : {'deltaFormat' : [{'insert' : 'test'}]} -}); -// $ExpectType Promise -monday.execute('updateDocBlock', { - id : '1234-1234-23434dsf', - content : {'deltaFormat' : [{'insert' : 'test'}]} -}); -// $ExpectType Promise -monday.execute('addMultiBlocks', { - afterBlockId : '1234-1234-23434dsf', - blocks: [ - { - type: 'normal text', - content: { deltaFormat : [{ 'insert' : 'test' }] } - } - ] -}); -monday.execute('closeDocModal'); // $ExpectType Promise - -monday.oauth({ clientId: 'clientId' }); - -monday.storage.instance.getItem('test'); // $ExpectType Promise -monday.storage.instance.setItem('test', '123'); // $ExpectType Promise -monday.storage.instance.deleteItem('test'); // $ExpectType Promise - -const mondayServer = mondaySdk({ token: '123', apiVersion: '2023-10' }); - -mondayServer.setToken('123'); // $ExpectType void -mondayServer.setApiVersion('2023-10'); // $ExpectType void -mondayServer.api('test'); // $ExpectType Promise -mondayServer.api('test', { token: 'test' }); // $ExpectType Promise -mondayServer.api('test', { variables: { variable1: 'test' } }); // $ExpectType Promise -mondayServer.api('test', { token: 'test', variables: { variable1: 'test' } }); // $ExpectType Promise -mondayServer.api('test', { token: 'test', apiVersion: '2023-07' }); // $ExpectType Promise -mondayServer.oauthToken('test', 'test', 'test'); // $ExpectType Promise +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 & { + 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"); diff --git a/types/client-context.type.ts b/types/client-context.type.ts index 339cd8a7..7608533e 100644 --- a/types/client-context.type.ts +++ b/types/client-context.type.ts @@ -32,6 +32,11 @@ type AppVersion = { }; }; +export type Permissions = { + approvedScopes: string[]; + requiredScopes: string[]; +}; + export type BaseContext = { themeConfig?: Theme; theme: string; @@ -40,6 +45,7 @@ export type BaseContext = { region: string; app: App; appVersion: AppVersion; + permissions: Permissions; }; export type AppFeatureBoardViewContext = BaseContext & { diff --git a/types/client-data.interface.ts b/types/client-data.interface.ts index 14d8f710..738d4564 100644 --- a/types/client-data.interface.ts +++ b/types/client-data.interface.ts @@ -1,29 +1,49 @@ import { AppFeatureContextMap, AppFeatureTypes } from "./client-context.type"; +export type LocationResponse = Record & { + href: string; + search: string; +}; + +export type FilterResponse = Record & { + term: string; + rules: (Record & { + column_id?: string; + compare_value?: string[]; + compare_attribute?: string; + operator?: string; + })[]; + operator: string | null; +}; + type SubscribableEventsResponse = { context: AppFeatureContextMap[AppFeatureType]; settings: Record; itemIds: number[]; events: Record; + 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 = { + data: T; errorMessage?: string | undefined; method: string; requestId: string; type?: string | undefined; -} +}; -interface DeleteResponse { +type DeleteResponse = { data: { success: boolean; value: any; @@ -32,7 +52,7 @@ interface DeleteResponse { method: string; requestId: string; type?: string | undefined; -} +}; interface SetResponse { data: { @@ -52,6 +72,8 @@ export type GetterResponse; itemIds: number[]; sessionToken: string; + location: LocationResponse; + filter: FilterResponse; }; export interface ClientData { /** @@ -70,8 +92,8 @@ export interface ClientData { AppFeatureType extends AppFeatureTypes = AppFeatureTypes >( type: T, - params?: object & { appFeatureType?: AppFeatureType } - ): Promise[T] & CustomResponse>; + params?: Record & { appFeatureType?: AppFeatureType } + ): Promise[T] & CustomResponse>>; /** * Creates a listener which allows subscribing to certain types of client-side events. @@ -87,7 +109,7 @@ export interface ClientData { >( typeOrTypes: T | ReadonlyArray, callback: (res: { data: SubscribableEventsResponse[T] & CustomResponse }) => void, - params?: object & { appFeatureType?: AppFeatureType } + params?: Record & { appFeatureType?: AppFeatureType } ): () => void; /** @@ -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; + getItem(key: string): Promise; /** * Deletes a stored value from the database under `key` for the app (**without any reference to the instance**) @@ -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; + getItem(key: string): Promise; /** * Deletes a stored value from the database under `key` for a specific app instance diff --git a/types/index.d.ts b/types/index.d.ts index 6fc16a3a..51c44d73 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,22 +1,22 @@ // Original Definitions were contributed by: Josh Parnham -import { MondayClientSdk } from './client-sdk.interface'; -import { MondayServerSdk } from './server-sdk.interface'; +import { MondayClientSdk } from "./client-sdk.interface"; +import { MondayServerSdk } from "./server-sdk.interface"; export as namespace mondaySdk; declare function init( - config?: Partial<{ - clientId: string; - apiToken: string; - apiVersion: string; - }>, + config?: Partial<{ + clientId: string; + apiToken: string; + apiVersion: string; + }> ): MondayClientSdk; declare function init( - config?: Partial<{ - token: string; - apiVersion: string; - }>, + config?: Partial<{ + token: string; + apiVersion: string; + }> ): MondayServerSdk; export = init;