UNPKG

2.67 kBTypeScriptView Raw
1import { EventEmitter } from './event';
2export default class Bearer {
3 readonly clientId: string | undefined;
4 static readonly authorizedListener: EventEmitter;
5 secured?: boolean;
6 config: TBearerOptions;
7 private registeredIntegrations;
8 private observer?;
9 private debounceRefresh;
10 constructor(clientId: string | undefined, options?: Partial<TBearerOptions>);
11 /**
12 * `connect` lets you easily retrieve `auth-id` for an integration using OAuth authentication. Before using it, you'll need to generate a `setup-id` with the setup component of your integration
13 * @argument {string} integration the identifier of the Integration you want to connect to ex: 12345-attach-github-pull-request
14 * @argument {string} setupId Setup's identifier you received earlier, a Bearer reference containing all required information about auth mechanism
15 * @argument {Object} options Optional parameters like authId if you already have one
16 */
17 connect: (integration: string, setupId?: string | undefined, { authId }?: {
18 authId?: string | undefined;
19 }) => Promise<{
20 integration: string;
21 authId: string;
22 }>;
23 private _jsonRequest;
24 invoke: <DataPayload = any>(integrationId: string, functionName: string, { query, ...params }?: {
25 [key: string]: any;
26 query?: Record<string, string> | undefined;
27 }) => Promise<TFetchBearerData<DataPayload>>;
28 /**
29 * Retrieve all dom elements starting by bearer- and ask for assets urls if
30 */
31 loadMissingIntegrations: () => void;
32 /**
33 * check wether if an integration is resgistered
34 */
35 registeredIntegration: (tagName: string) => boolean;
36 /**
37 * load integration asset or wait until dom is loaded
38 */
39 private initialIntegrationLoading;
40 /**
41 * Register a DOM observer so that we can load integration assets only when we need them
42 */
43 private registerDomObserver;
44 private observerCallback;
45 /**
46 * remove dom observer
47 */
48 private disconnectObserver;
49 /**
50 * retrieve corresponding integration asset url
51 */
52 private sendTags;
53}
54export declare type TBearerOptions = {
55 secured?: boolean;
56 domObserver: boolean;
57 integrationHost: string;
58 refreshDebounceDelay: number;
59};
60/**
61 * Extract/format element tag names given a regexp
62 * @param elements
63 * @param filter
64 */
65export declare function findElements(elements: HTMLCollection | NodeListOf<Element>, filter?: RegExp): string[];
66export declare type TFetchBearerData<T = any> = {
67 data: T;
68 referenceId?: string;
69};