import type { Contract, JsonSchema, QueryOptions } from 'autumndb'; import { AxiosRequestConfig } from 'axios'; import { AuthSdk } from './auth'; import { CardSdk } from './card'; import { JellyfishCursor } from './cursor'; import { EventSdk } from './event'; import { IntegrationsSdk } from './integrations'; import { JellyfishStreamManager } from './stream'; import { ExtendedSocket, SdkQueryOptions } from './types'; /** * @summary Set the mask option to the supplied mask if it is set * - unless the ignoreMask option is set. * @param options - the query options * @returns the query options without the ignoreMask */ export declare const applyMask: (options: SdkQueryOptions, mask: JsonSchema | null) => QueryOptions; /** * @namespace JellyfishSDK */ export declare class JellyfishSDK { private API_URL; private readonly API_PREFIX; private authToken?; readonly auth: AuthSdk; readonly card: CardSdk; readonly event: EventSdk; readonly integrations: IntegrationsSdk; readonly streamManager: JellyfishStreamManager; private API_BASE; private cancelTokenSources; /** * A JSON schema filter that will be applied to all queries */ private _globalQueryMask; /** * @name JellyfishSDK * @class * @public * * @param {String} API_URL - The URL of the Jellyfish API * @param {String} API_PREFIX - The prefix used for the API endpoint, e.g. v1, v2 * @param {String=} authToken - An optional authentication token to instantiate the SDK with */ constructor(API_URL: string, API_PREFIX: string, authToken?: string | null | undefined); get globalQueryMask(): JsonSchema | null; set globalQueryMask(mask: JsonSchema | null); /** * @summary Load config object from the API * @name getConfig * @public * @function * @memberof JellyfishSDK * * @description Retrieve configuration data from the API * * @fulfil {Object} - Config object * @returns {Promise} * * @example * sdk.getConfig() * .then((config) => { * console.log(config); * }); */ getConfig: () => Promise; /** * @summary Retrieve a file form the API * @name getFile * @public * @function * @memberof JellyfishSDK * * @description Retrieve a file from the API * * @param {String} cardId - The id of the card this file is attached to * @param {String} name - The name of the file * * @fulfil {File} - The requested file * @returns {Promise} */ getFile: (cardId: Contract['id'], name: string) => Promise; /** * @summary Set the API url * @name setApiUrl * @public * @function * @memberof JellyfishSDK * * @description Set the url of the Jellyfish API instance the SDK should * communicate with * * @param {String} apiUrl - The API url * * @example * sdk.setApiUrl('http://localhost:8000') */ setApiUrl(apiUrl: string): void; /** * @summary Get the API url * @name getApiUrl * @public * @function * @memberof JellyfishSDK * * @description Get the url of the Jellyfish API instance the SDK should * communicate with * * @returns {String|undefined} The API url * * @example * const url = sdk.getApiUrl() * console.log(url) //--> 'http://localhost:8000' */ getApiUrl(): string; /** * @summary Set the base API url * @name setApiBase * @public * @function * @memberof JellyfishSDK * * @description Set the url and path prefix to use when sending requests to * the API * * @param {String} apiUrl - The API url * @param {String} apiPrefix - The API path prefix * * @example * sdk.setApiBase('http://localhost:8000', 'api/v2') */ setApiBase(apiUrl: string, apiPrefix: string): void; /** * @summary Set the auth token * @name setAauthToken * @public * @function * @memberof JellyfishSDK * * @description Set authentication token used when sending request to the API * * @param {String} token - The authentication token * * @example * sdk.setAuthToken('799de256-31bb-4399-b2d2-3c2a2483ddd8') */ setAuthToken(token: string | null): void; /** * @summary Get the auth token * @name getAauthToken * @public * @function * @memberof JellyfishSDK * * @description Get authentication token used when sending request to the API * * @returns {String|undefined} The authentication token if it has been set * * @example * const token = sdk.getAuthToken( * console.log(token) //--> '799de256-31bb-4399-b2d2-3c2a2483ddd8' */ getAuthToken(): string | null | undefined; /** * @summary clear the auth token * @name clearAuthToken * @public * @function * @memberof JellyfishSDK * * @description Clear the authentication token used when sending request to the API * * @example * sdk.clearAuthToken() */ clearAuthToken(): void; /** * @summary Cancel all network requests * @name cancelAllRequests * @public * @function * @memberof JellyfishSDK * * @description Cancel all network requests that are currently in progress, * optionally providing a reason for doing so. * * @param {String} [reason='Operation canceled by user'] - The reason for * cancelling the network requests * * @example * sdk.cancelAllRequests() */ cancelAllRequests(reason?: string): void; /** * @summary Cancel all streams * @name cancelAllstreams * @public * @function * @memberof JellyfishSDK * * @description Close all open streams to the Jellyfish API * * @example * sdk.cancelAllStreams() */ cancelAllStreams(): void; request(endpoint: string, options?: AxiosRequestConfig): Promise; /** * @summary Send a GET request to the API * @name get * @public * @function * @memberof JellyfishSDK * * @description Send a get request to the Jellyfish API. Uses Axios under the * hood. * * @param {String} endpoint - The endpoint to send the POST request to * @param {Object} [options] - Request configuration options. See https://github.com/axios/axios#request-config * * @fulfil {Object} - Request response object * @returns {Promise} */ get(endpoint: string, options?: AxiosRequestConfig): Promise; /** * @summary Send a POST request to the API * @name post * @public * @function * @memberof JellyfishSDK * * @description Send a POST request to the Jellyfish API. Uses Axios under the * hood. Requests are automatically authorized using a token if it has * been set. * * @param {String} endpoint - The endpoint to send the POST request to * @param {Object} body - The body data to send * @param {Object} [options] - Request configuration options. See https://github.com/axios/axios#request-config * * @fulfil {Object} - Request response object * @returns {Promise} * * @example * sdk.post('action', { foo: 'bar'}) * .then((data) => { * console.log(data); * }); */ post(endpoint: string, body: TBody, options?: AxiosRequestConfig): Promise; /** * @summary Send a query request to the API * @name query * @public * @function * @memberof JellyfishSDK * * @description Query the API for contract data, using a JSON schema. Contracts that * match the JSON schema are returned * * @param {Object} schema - The JSON schema to query with * @param {Object} [options] - Additional options * @param {Number} [options.limit] - Limit the number of results * @param {Number} [options.skip] - Skip a set amount of results * @param {String} [options.sortBy] - Sort by the specified field * @param {String} [options.sortDir] - Sort direction, defaults to ascending order. To sort by descending order, specify 'desc'. * * @fulfil {Object[]} - An array of contracts that match the schema * @returns {Promise} * * @example * const schema = { * type: 'object', * properties: { * type: { * const: 'thread@1.0.0' * } * } * }; * * const options = { * limit: 10, * sortBy: 'created_at', * sortDir: 'desc', * }; * * sdk.query(schema, options) * .then((contracts) => { * console.log(contracts); * }); */ query(schema: JsonSchema, options?: SdkQueryOptions): Promise; /** * @summary Send a view request to the API * @name view * @public * @function * @memberof JellyfishSDK * * @description Query the API for card data, referencing a view template by * slug@version and providing its params and options. Internally, it uses * `query`, so any constraint specific to it is also applied * * @param {String} viewSlug - the slug@version of the view to use * @param {Object} params - the optional params used by the view template * @param {Object} [options] - Additional options * @param {Number} [options.limit] - Limit the number of results * @param {Number} [options.skip] - Skip a set amount of results * * @fulfil {Object[]} - An array of cards that match the schema specified by the view * @returns {Promise} * * @example * const params = { * types: [ 'view', 'view@1.0.0' ] * } * * sdk.view('view-all-by-type@1.0.0', params) * .then((cards) => { * console.log(cards); * }); */ view(viewSlug: string, params?: any, options?: SdkQueryOptions): Promise; /** * @summary Get all cards by type * @name getByType * @public * @function * @memberof JellyfishSDK * * @param {String} type - The card type * @fulfil {Object[]} - The resulting cards * @returns {Promise} */ getByType(type: string): Promise; /** * @summary Get a card by type and id * @name getById * @public * @function * @memberof JellyfishSDK * * @param {String} id - The card id * @fulfil {Object} - The resulting card * @returns {Promise} */ getById(id: Contract['id']): Promise; /** * @summary Get a card by type and slug * @name getBySlug * @public * @function * @memberof JellyfishSDK * * @param {String} slug - The card slug * @fulfil {Object} - The resulting card * @returns {Promise} */ getBySlug(slug: string): Promise; /** * @typedef {Object} ActionResponse * @property {Boolean} error - True if an error occurred, false otherwise * @property {Object} data - The response payload * @property {String} data.id - The id of the action request * @property {Object} data.results - The results of running the action request * @property {*} data.results.data - The end response produced by the action request * @property {Boolean} data.results.error - True if the action request * encountered an error, false otherwise * @property {String} data.results.timestamp - A timestamp of when the action * request was processed */ /** * @summary Send an action to the API * @name action * @public * @function * @memberof JellyfishSDK * * @description Send an action to the API, the request will resolve * once the action is complete * * @param {Object} body - The action request * @param {String} body.card - The slug or UUID of the target card * @param {String} body.type - The type of the target card * @param {String} body.action - The name of the action to run * @param {*} [body.arguments] - The arguments to use when running the * action * @param {*} [body.transient] - The transient arguments to use when running the * action * * @fulfil {ActionResponse} - An action response object * @returns {Promise} * * @example * sdk.action({ * card: 'thread', * action: 'action-create-card@1.0.0', * arguments: { * data: { * description: 'lorem ipsum dolor sit amet' * } * } * }) * .then((response) => { * console.log(response); * }); */ action(body: { card: string; type: string; action: string; arguments?: { [key: string]: any; }; }): Promise; /** * @summary Stream cards from the API * @name stream * @public * @function * @memberof JellyfishSDK * * @description Stream updates and insertions for cards that match a JSON * schema * * @param {JsonSchema} query - The JSON schema to query with * @param {SdkQueryOptions} options - Extra query options to use * * @fulfil {EventEmitter} * @returns {Promise} * * @example * const schema = { * type: 'object', * properties: { * type: { * const: 'thread' * } * } * }; * * const stream = sdk.stream(schema) * * stream.on('update', (data) => { * console.log(data); * }) * * stream.on('streamError', (error) => { * console.error(error); * }) */ stream(query: JsonSchema, options?: SdkQueryOptions): ExtendedSocket; /** * @summary Create a cursor * @name getCursor * @public * @function * @memberof JellyfishSDK * * @description Create a cursor object to query, stream and page contracts from the API * * @param {JsonSchema} query - The JSON schema to query with * @param {SdkQueryOptions} options - Extra query options to use * * @fulfil {EventEmitter} * @returns {Promise} * * @example * const schema = { * type: 'object', * properties: { * type: { * const: 'thread' * } * } * }; * * const cursor = sdk.getCursor(schema) * * cursor.on('update', (data) => { * console.log(data); * }) * * const results = await cursor.nextPage() */ getCursor(query: JsonSchema, options: SdkQueryOptions): JellyfishCursor; } /** * @summary Initialize a new JellyfishSdk instance * @name getSdk * @public * @function * * @param {Object} options - The SDK options * @param {String} options.apiUrl - The api url to send requests to * @param {String} options.apiPrefix - The path prefix to use for API requests * @param {String} options.authToken - An auth token to use when making requests * * @returns {Object} A new JellyfishSdk instance * * @example * const sdk = getSdk({ * apiUrl: 'http://localhost:8000', * apiPrefix: 'api/v2', * authToken: '799de256-31bb-4399-b2d2-3c2a2483ddd8' * }) */ export declare const getSdk: ({ apiUrl, apiPrefix, authToken, }: { apiUrl: string; apiPrefix: string; authToken?: string | undefined; }) => JellyfishSDK;