/** * (c) Copyright Ascensio System SIA 2026 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @license */ /** * @module * @mergeModuleWith */ import type { TFrameConfig, TInitConfig } from "../types"; import { SDKInstance } from "../instance"; /** * Manages multiple {@link SDKInstance} objects and provides convenience wrappers * for each {@link SDKMode}. * * Calling any `init*` method with a `frameId` that already exists reinitializes * the existing instance; otherwise a new instance is created and stored in {@link SDK.frames}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const instance = sdk.initManager({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * }); * ``` */ export declare class SDK { /** * Registry of all active instances, keyed by {@link TFrameConfig.frameId}. * Updated automatically by every `init*` call. */ frames: Record; /** * Core factory method. Creates a new {@link SDKInstance} for the given config, * or reinitializes the existing one if `frameId` is already in {@link SDK.frames}. * Stores the result in {@link SDK.frames}. * * Prefer the mode-specific wrappers ({@link SDK.initManager}, {@link SDK.initEditor}, etc.) * which set `mode` automatically. * * @param config - Frame configuration. See {@link TFrameConfig}. * @returns The created or reinitialized {@link SDKInstance}. * * @example * ```typescript * import { SDK, SDKMode } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * * // Create a manager instance * const instance = sdk.init({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * mode: SDKMode.Manager, * }); * * // Reinitialize the same frame in a different mode — sdk.frames['ds-frame'] is reused * sdk.init({ frameId: 'ds-frame', src: 'https://portal.example.com', mode: SDKMode.Editor, id: 42 }); * ``` */ init: (config: TFrameConfig) => SDKInstance; /** * @deprecated Use {@link SDK.init} or a mode-specific wrapper instead. * * @param config - Frame configuration. See {@link TFrameConfig}. * @returns The created or reinitialized {@link SDKInstance}. */ initFrame: (config: TFrameConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.Manager} mode — a file/folder browser * with full CRUD operations on rooms, folders, and files. * Forces `mode` to {@link SDKMode.Manager}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK, ManagerViewMode, FilterSortBy, FilterSortOrder } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const instance = sdk.initManager({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * viewAs: ManagerViewMode.Table, * showFilter: true, * showMenu: true, * filter: { sortBy: FilterSortBy.Name, sortOrder: FilterSortOrder.Ascending }, * events: { * onAppReady: () => console.log('ready'), * onFileManagerClick: (item) => console.log('clicked:', item), * }, * }); * ``` * * @example * The rooms of one room group, pinned: search and filters inside the frame stay within the group. * ```typescript * const dealRooms = sdk.initManager({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * rootPath: '/rooms/shared/', * filter: { groupId: '42' }, * }); * ``` */ initManager: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.Viewer} mode — read-only document viewer. * Forces `mode` to {@link SDKMode.Viewer}. Requires {@link TFrameConfig.id}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const instance = sdk.initViewer({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * id: 42, * events: { * onAppReady: () => console.log('ready'), * onNoAccess: () => console.warn('access denied'), * onNotFound: () => console.warn('document not found'), * }, * }); * ``` */ initViewer: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.Editor} mode — full document editor. * Forces `mode` to {@link SDKMode.Editor}. Requires {@link TFrameConfig.id}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK, EditorType } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const instance = sdk.initEditor({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * id: 42, * editorType: EditorType.Desktop, * editorCustomization: { autosave: true, forcesave: true }, * events: { * onAppReady: () => console.log('ready'), * onEditorCloseCallback: () => history.back(), * }, * }); * ``` */ initEditor: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.RoomSelector} mode — a dialog for selecting a room. * Forces `mode` to {@link SDKMode.RoomSelector}. * The selected room is returned via {@link TFrameEvents.onSelectCallback}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const instance = sdk.initRoomSelector({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * showSelectorHeader: true, * showSelectorCancel: true, * events: { * onSelectCallback: (room) => console.log('selected:', room), * onCloseCallback: () => console.log('cancelled'), * }, * }); * ``` */ initRoomSelector: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.FileSelector} mode — a dialog for selecting a file. * Forces `mode` to {@link SDKMode.FileSelector}. * The selected file is returned via {@link TFrameEvents.onSelectCallback}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK, SelectorFilterType } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const instance = sdk.initFileSelector({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * selectorType: SelectorFilterType.UserOnly, * withBreadCrumbs: true, * withSearch: true, * events: { * onSelectCallback: (file) => console.log('selected:', file), * onCloseCallback: () => console.log('cancelled'), * }, * }); * ``` */ initFileSelector: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.System} mode — a blank page with a loader, * used to call system methods ({@link SDKInstance.login}, {@link SDKInstance.logout}, * {@link SDKInstance.getUserInfo}) without rendering any ONLYOFFICE Apps UI. * Forces `mode` to {@link SDKMode.System}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const system = sdk.initSystem({ * frameId: 'ds-system', * src: 'https://portal.example.com', * events: { onAppReady: () => console.log('system ready') }, * }); * * system.getUserInfo().then((user) => console.log('current user:', user)); * ``` */ initSystem: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.PublicRoom} mode — anonymous access to view, * edit, comment on, and review documents in a public room. * Forces `mode` to {@link SDKMode.PublicRoom}. Requires {@link TFrameConfig.requestToken}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const instance = sdk.initPublicRoom({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * requestToken: 'public-room-token', * events: { * onAppReady: () => console.log('ready'), * }, * }); * ``` * * @example * With filter and header options. * ```typescript * const instance = sdk.initPublicRoom({ * frameId: 'ds-frame', * src: 'https://portal.example.com', * requestToken: 'public-room-token', * showFilter: true, * showHeader: true, * }); * ``` */ initPublicRoom: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.Uploader} mode — a file upload interface. * Forces `mode` to {@link SDKMode.Uploader}. Requires {@link TFrameConfig.id} * (the target folder ID). * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const uploader = sdk.initUploader({ * frameId: 'ds-uploader', * src: 'https://portal.example.com', * id: 'folder-id', * acceptExtensions: '.docx,.xlsx,.pdf', * isMultipleUpload: true, * events: { * onUploadSuccess: (files) => { * if (Array.isArray(files)) console.log('uploaded:', files.map((f) => f.response?.title)); * }, * onUploadProgress: (p) => console.log(p.fileName, p.percent), * onUploadError: (err) => console.error('error' in err ? err.error : err.message), * }, * }); * ``` */ initUploader: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.Forms} mode — a forms gallery for the room specified by {@link TFrameConfig.id}. * Forces `mode` to {@link SDKMode.Forms}. Sets `showMenu` to `true` by default. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const forms = sdk.initForms({ * frameId: 'ds-forms', * src: 'https://portal.example.com', * id: 'room-id', * showMenu: true, * events: { * onCustomAction: (data) => console.log('action:', data), * }, * }); * ``` */ initForms: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.Chat} mode — a full-page AI chat interface. * The chat is bound to the AI agent when {@link TFrameConfig.agentId} is set; * otherwise it is bound to the current user. Forces `mode` to {@link SDKMode.Chat}. * * :::note * The page renders a composer only when the frame's user is signed in and is not a guest. * Otherwise it shows a no-access state (a "Chat history" control without an input) and fires * {@link TFrameEvents.onNoAccess} — {@link TFrameEvents.onAppReady} still arrives. AI disabled * on the portal hides the composer too, without the event. In OAuth mode the token must carry * the scopes that read the user's profile; a token that cannot load the profile lands in the * same no-access state. * ::: * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const chat = sdk.initChat({ * frameId: 'ds-chat', * src: 'https://portal.example.com', * agentId: 123, * events: { * onAppReady: () => console.log('chat ready'), * }, * }); * ``` */ initChat: (config: TInitConfig) => SDKInstance; /** * Initializes a frame in {@link SDKMode.Personal} mode — a file/folder manager for the * user's personal space: My Documents, Favorites, Recent, Shared with me, and Trash. The initial * section is controlled by {@link TFrameConfig.personalDestination}; the frame has no navigation * menu of its own, so the host switches sections with {@link SDKInstance.navigateSection}. * * Forces `mode` to {@link SDKMode.Personal}. * * @param config - Frame configuration; `mode` is set by the wrapper. See {@link TInitConfig}. * @returns The initialized {@link SDKInstance}. * * @example * ```typescript * import { SDK } from '@onlyoffice/docspace-sdk-js'; * * const sdk = new SDK(); * const personal = sdk.initPersonal({ * frameId: 'ds-personal', * src: 'https://portal.example.com', * personalDestination: 'favorites', * events: { * onAppReady: () => console.log('ready'), * onNavigate: (data) => console.log('section:', data.section), * onFileManagerClick: (file) => console.log('opened file:', file), * }, * }); * ``` */ initPersonal: (config: TInitConfig) => SDKInstance; }