ryuu.js
Version:
Ryuu JavaScript Utility Library
115 lines (114 loc) • 5.09 kB
TypeScript
import { onDataUpdated } from "./models/services/dataset";
import { onFiltersUpdated, requestFiltersUpdate } from "./models/services/filters";
import { onVariablesUpdated, requestVariablesUpdate } from "./models/services/variables";
import { onAppDataUpdated, requestAppDataUpdate } from "./models/services/appdata";
import { navigate } from "./models/services/navigation";
import { get, getAll, post, put, delete as del, domoHttp } from "./models/services/http";
import { isSuccess, isVerifiedOrigin, getQueryParams, setFormatHeaders } from "./utils/general";
import { AskReplyMap } from "./models/interfaces/ask-reply";
import { handleAck, handleReply } from "./utils/ask-reply";
/**
* The Domo class provides a unified API for interacting with Domo platform features in client applications.
*
* It exposes HTTP methods, event listeners, emitters, and utility functions for working with datasets, filters, variables, app data, and navigation.
*
* Key features:
* - HTTP request methods (get, post, put, delete, domoHttp)
* - Batch request support via getAll
* - Event listeners for data, filters, variables, and app data updates
* - Emitters for sending variables, app data, and navigation events
* - Utility functions for environment, origin verification, and query parsing
* - Handles cross-frame communication and DOM mutation observation for token injection
*/
declare class Domo {
private static requests;
static channel?: MessageChannel;
static connected: boolean;
static listeners: {
[index: string]: Function[];
};
static get: typeof get;
static getAll: typeof getAll;
static post: typeof post;
static put: typeof put;
static delete: typeof del;
static domoHttp: typeof domoHttp;
static onDataUpdated: typeof onDataUpdated;
static onFiltersUpdated: typeof onFiltersUpdated;
static onAppDataUpdated: typeof onAppDataUpdated;
static onVariablesUpdated: typeof onVariablesUpdated;
static readonly onFiltersUpdate: typeof onFiltersUpdated;
static readonly onDataUpdate: typeof onDataUpdated;
static readonly onAppData: typeof onAppDataUpdated;
static requestFiltersUpdate: typeof requestFiltersUpdate;
static requestVariablesUpdate: typeof requestVariablesUpdate;
static requestAppDataUpdate: typeof requestAppDataUpdate;
static navigate: typeof navigate;
static readonly filterContainer: typeof requestFiltersUpdate;
static readonly sendVariables: typeof requestVariablesUpdate;
static readonly sendAppData: typeof requestAppDataUpdate;
static handleAck: typeof handleAck;
static handleReply: typeof handleReply;
static getRequests: () => AskReplyMap;
static getRequest: (requestId: string) => {
request: {
payload: any;
onAck?: Function;
onReply?: Function;
status: import("./models/interfaces/ask-reply").AskRequestStatus;
sentAt?: number;
ackAt?: number;
repliedAt?: number;
};
response?: {
payload?: any;
status: import("./models/interfaces/ask-reply").AskResponseStatus;
error?: Error;
repliedAt?: number;
};
};
static readonly env: import(".").QueryParams;
static readonly __util: {
isVerifiedOrigin: typeof isVerifiedOrigin;
getQueryParams: typeof getQueryParams;
setFormatHeaders: typeof setFormatHeaders;
isSuccess: typeof isSuccess;
};
/**
* Connects to the parent window's Domo instance using a MessageChannel.
* This method sets up message handlers for various events like filtersUpdated, appData, and variablesUpdated.
* It also sends a subscription message to the parent window.
*
* Also sets up a legacy window.postMessage listener for backward compatibility with v4.7.0 and earlier.
*
* @param skipFilters - If true, skips the initial filter updates.
*/
private static connect;
/**
* Allows consumers to override or extend static methods/properties of the Domo class.
*
* Example Usage:
* import Domo, { get as originalGet } from 'domo.js';
*
* Domo.extend({
* get: (url, options) => {
* // custom logic
* return originalGet(url, options);
* }
* });
*
* @param overrides An object whose keys are static method/property names and values are the new implementations.
*/
static extend(overrides: Partial<Record<keyof typeof Domo, any>>): void;
}
/**
* MutationObserver callback that injects the authentication token into any newly added HTML elements.
*
* This function is triggered whenever nodes are added to the DOM (either in the document or head).
* It retrieves the current token and applies it to any new HTMLElement using the handleNode utility.
*
* @param mutations - An array of MutationRecord objects representing the changes to the DOM.
*/
declare const __mutationObserverCallback: (mutations: any) => void;
export default Domo;
export { Domo, __mutationObserverCallback };