This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+18
View File
@@ -0,0 +1,18 @@
import { UNAUTHORIZED, INVALID_ARGUMENT, INIT_FAILED, FORBIDDEN, INVALID_CONFIG, INVALID_ID_TOKEN, CREATE_SUBWINDOW_FAILED, EXCEPTION_IN_SUBWINDOW } from './consts';
declare const HTTPStatusCodeArray: string[];
export declare const HTTPStatusCodes: Set<string>;
declare type PublicErrorCode = typeof HTTPStatusCodeArray[number] | typeof FORBIDDEN | typeof INVALID_CONFIG | typeof INVALID_ID_TOKEN | typeof UNAUTHORIZED | typeof INVALID_ARGUMENT | typeof INIT_FAILED | 'THINGS_NO_LINKED_DEVICES' | 'BLUETOOTH_SETTING_OFF' | 'THINGS_TERMS_NOT_AGREED' | 'BLUETOOTH_NO_LOCATION_PERMISSION' | 'BLUETOOTH_LOCATION_DISABLED' | 'BLUETOOTH_LE_API_UNAVAILABLE' | 'BLUETOOTH_CONNECT_FAILED' | 'BLUETOOTH_ALREADY_CONNECTED' | 'BLUETOOTH_CONNECTION_LOST' | 'BLUETOOTH_UNSUPPORTED_OPERATION' | 'BLUETOOTH_SERVICE_NOT_FOUND' | 'BLUETOOTH_CHARACTERISTIC_NOT_FOUND' | 'UNKNOWN';
declare type InternalErrorCode = typeof CREATE_SUBWINDOW_FAILED | typeof EXCEPTION_IN_SUBWINDOW;
declare type AdErrorValue = 'ADS_APP_ID_NOT_SET' | 'ADS_FREQUENT_LOAD' | 'ADS_ALREADY_LOADED' | 'ADS_NO_FILL' | 'ADS_NOT_LOADED' | 'ADS_ADNETWORK_NOT_SUPPORTED' | 'CLIENT_UNSUPPORTED_OPERATION' | 'NETWORK_FAILURE' | 'INVALID_MESSAGE' | 'INVALID_ARGUMENTS' | 'INTERNAL_ERROR';
declare type UnpublishedErrorCode = 'LIFF.STATE_INVALID' | AdErrorValue;
export declare type ErrorCode = PublicErrorCode | InternalErrorCode | UnpublishedErrorCode;
/**
* Custom Liff Error with code & message
* @param {string} code
* @param {string} message
*/
export default class LiffError extends Error {
code: string | number;
constructor(code: ErrorCode, message: string);
}
export {};
+19
View File
@@ -0,0 +1,19 @@
/**
* decode Base64URL
* @export
* @param {string} str - string
* @returns {string}
*/
export declare function decode(str: string): string;
/**
* encode Base64URL
* @export
* @param {string} str - string
* @returns {string}
*/
export declare function encode(str: string): string;
declare const _default: {
decode: typeof decode;
encode: typeof encode;
};
export default _default;
+8
View File
@@ -0,0 +1,8 @@
/**
* compare two versions
* @export
* @param {string} version - string
* @param {string} comparedVersion - string
* @returns {-1|0|1} If version is higher, returns 1. same : 0, lower : -1.
*/
export default function compareVersion(version: string, comparedVersion: string): number;
+40
View File
@@ -0,0 +1,40 @@
import { ElementType } from './typeHelpers';
export declare const UNKNOWN = "UNKNOWN";
export declare const UNAUTHORIZED = "UNAUTHORIZED";
export declare const INVALID_ARGUMENT = "INVALID_ARGUMENT";
export declare const INIT_FAILED = "INIT_FAILED";
export declare const FORBIDDEN = "FORBIDDEN";
export declare const INVALID_CONFIG = "INVALID_CONFIG";
export declare const INVALID_ID_TOKEN = "INVALID_ID_TOKEN";
export declare const CREATE_SUBWINDOW_FAILED = "CREATE_SUBWINDOW_FAILED";
export declare const EXCEPTION_IN_SUBWINDOW = "EXCEPTION_IN_SUBWINDOW";
export declare const LIFF_EVENT = "liffEvent";
export declare const STORE_KEY = "LIFF_STORE";
export declare const PERMANENT_LINK_ORIGIN: string;
export declare const TORIMOCHI_URL = "https://torimochi.line-apps.com/1/req";
export declare const STORE_OBJECT: {
readonly ACCESS_TOKEN: "accessToken";
readonly ID_TOKEN: "IDToken";
readonly DECODED_ID_TOKEN: "decodedIDToken";
readonly FEATURE_TOKEN: "featureToken";
readonly FEATURES: "features";
readonly LOGIN_TMP: "loginTmp";
readonly CONFIG: "config";
readonly CONTEXT: "context";
readonly EXPIRES: "expires";
readonly RAW_CONTEXT: "rawContext";
readonly CLIENT_ID: "clientId";
};
export declare const STORE_SUBKEY_IS_IN_CLIENT = "isInClient";
export declare const LIFF_ATTR_DOM = "data-l-{0}";
export declare enum ROUTER_MODE {
NONE = "none",
HASH = "hash",
HISTORY = "history"
}
export declare const CREDENTIAL_KEYS: readonly ["context_token", "feature_token", "access_token", "id_token", "client_id"];
export declare type CREDENTIAL_OBJECTS = {
[key in ElementType<typeof CREDENTIAL_KEYS>]: string | null;
};
export declare const MAX_NUM_OF_SEND_MESSAGES = 5;
export declare const IFRAME_OPEN_ANIMATION_DURATION = 400;
+8
View File
@@ -0,0 +1,8 @@
/**
* string to ArrayBuffer
* https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
* @export
* @param {string} str - string
* @returns {ArrayBuffer}
*/
export declare function strToArrayBuffer(str: string): ArrayBuffer;
+7
View File
@@ -0,0 +1,7 @@
/**
* https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
* get cookie value by key
* @param {string} key
* @return {string}
*/
export default function get(key: string): string;
+9
View File
@@ -0,0 +1,9 @@
import set from './set';
import get from './get';
import remove from './remove';
declare const _default: {
set: typeof set;
get: typeof get;
remove: typeof remove;
};
export default _default;
+6
View File
@@ -0,0 +1,6 @@
/**
* https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
* @param {string} key
* @param {any} [options]
*/
export default function remove(key: string, options?: Record<string, unknown>): void;
+7
View File
@@ -0,0 +1,7 @@
/**
* https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
* @param {string} key
* @param {string | number} value
* @param {any} [options]
*/
export default function set(key: string, value: string | number, options?: Record<string, unknown>): void;
+8
View File
@@ -0,0 +1,8 @@
import LiffError, { ErrorCode } from './LiffError';
/**
* create custom liff error
* @param {string} code [description]
* @param {string} message [description]
* @return {LiffError} [description]
*/
export default function createError(code: ErrorCode, message?: string): LiffError;
+29
View File
@@ -0,0 +1,29 @@
import { AbstractIframe } from './abstract/AbstractIframe';
import { IframeEvent } from './windowPostMessage';
import { ROUTER_MODE } from '../consts';
export declare class ShareTargetPickerIFrame extends AbstractIframe {
protected routerMode: ROUTER_MODE;
protected submittedData: boolean | {};
private wrapperIn;
private originalBodyStyle;
private orgDocumentStyle;
private originalBodyPos;
private allowPostMessageOrigin;
constructor(url: string, accessToken: string, namespace?: Window);
init(routerMode?: ROUTER_MODE): Promise<void>;
protected prepareDom(): HTMLElement;
protected prepareStyle(): HTMLStyleElement;
cancel(): Promise<void>;
submit(): Promise<void>;
destroy(): Promise<void>;
protected changeBodyStyle(): void;
protected revertBodyStyle(): void;
private filter;
postMessageCallback(e: IframeEvent): Promise<void>;
/**
* TODO こいつらの処遇は後で決める
*/
protected historyAdd(): Promise<void>;
protected startWatchingHistoryChange(): void;
protected historyRemove(): void;
}
+13
View File
@@ -0,0 +1,13 @@
import { AbstractPopup } from './abstract/AbstractPopup';
import { IframeEvent } from './windowPostMessage';
export declare class ShareTargetPickerPopup extends AbstractPopup {
protected routerMode: any;
protected submittedData: boolean | {};
private allowPostMessageOrigin;
constructor(url: string, accessToken: string, namespace?: Window);
init(): Promise<void>;
cancel(): Promise<void>;
submit(): Promise<void>;
destroy(): Promise<void>;
postMessageCallback(e: IframeEvent): Promise<void>;
}
+12
View File
@@ -0,0 +1,12 @@
import { AbstractSubwindow } from './AbstractSubwindow';
export declare abstract class AbstractIframe extends AbstractSubwindow {
protected iframe: HTMLIFrameElement;
protected get postmessageDestination(): Window;
init(): Promise<void>;
protected prepareWindow(): Promise<void>;
protected breakWindow(): Promise<void>;
protected prepareDom(): HTMLElement;
protected prepareStyle(): HTMLStyleElement;
protected abstract changeBodyStyle(): void;
protected abstract revertBodyStyle(): void;
}
@@ -0,0 +1,8 @@
import { AbstractSubwindow } from './AbstractSubwindow';
export declare abstract class AbstractPopup extends AbstractSubwindow {
protected windowProxy: Window | null;
protected get postmessageDestination(): Window;
init(): Promise<void>;
prepareWindow(): Promise<void>;
breakWindow(): Promise<void>;
}
@@ -0,0 +1,22 @@
import { WindowPostMessage, IframeEvent } from '../windowPostMessage';
export declare abstract class AbstractSubwindow {
protected url: string;
protected uniqAttr: string;
protected namespace: Window;
protected accessToken: string;
protected windowPostMessage: WindowPostMessage;
protected contentElm: HTMLElement;
protected styleElm: HTMLStyleElement;
protected resolve: Function;
protected reject: Function;
protected pingHandler: any;
protected healthcheckHandler: any;
protected abstract postmessageDestination: Window;
constructor(url: string, accessToken: string, namespace?: Window);
init(): Promise<void>;
start(): Promise<null>;
destroy(): Promise<void>;
protected abstract prepareWindow(): Promise<void>;
protected abstract breakWindow(): Promise<void>;
postMessageCallback(e: IframeEvent): Promise<void>;
}
+2
View File
@@ -0,0 +1,2 @@
declare const _default: (uniq: string) => {};
export default _default;
+4
View File
@@ -0,0 +1,4 @@
export { default as listen } from './listen';
export { default as removeListen } from './removeListen';
export { default as messageTell, TellEvent } from './messageTell';
export { default as messageReceive, ReceiveEvent } from './messageReceive';
+21
View File
@@ -0,0 +1,21 @@
interface EventHandlers {
[k: string]: Function | null;
}
/**
* to retrieved cached values
*/
export declare function getEventHandlers(): EventHandlers;
/**
* Cleanup cached the variables, testing use
*/
export declare function _cleanupCache(): void;
/**
* main function to addEventListener with Promise which is resolve by being called at first time
* you can remove eventListener you added with this function by using `removeListen.ts`
* @param target Target Elements or Window
* @param key One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin".
* @param callback A function to execute when the event is triggered.
* @param options same as AddEventListenerOptions. see MDN if you find out more
*/
export default function listen(target: HTMLElement | HTMLDocument | Window, key: string, callback?: (e: Event) => void, options?: AddEventListenerOptions): Promise<Event>;
export {};
+5
View File
@@ -0,0 +1,5 @@
/**
* make a new unique attribute for HTMLElement to distinguish the elements created by LIFF SDK
* @param namespace
*/
export default function makeUniqAttr(namespace?: Window): string;
+23
View File
@@ -0,0 +1,23 @@
export interface ReceiveEvent extends MessageEvent {
data: {
name: string;
body: {} | {}[];
};
}
/**
* callback function called at first when receive a message event. (strictly speaking, listen.ts is called at very first)
* before calling callback you designated, this verifies if the name and origin are same as you expected
* @param name
* @param callback
* @param targetOrigin
*/
export declare function verifyCallback(name: string, callback: Function, targetOrigin: string): (event: ReceiveEvent) => void;
/**
* receive Event from another window calling postMessage.
* This is used for receiving data from another window like iframe, popup window, etc.
* @param target
* @param name
* @param callback
* @param targetOrigin
*/
export default function receive(target: Window, name: string, callback: Function, targetOrigin: string): void;
+14
View File
@@ -0,0 +1,14 @@
export interface TellEvent extends MessageEvent {
data: {
name: string;
body: {} | {}[];
};
}
/**
* call postMessage. This is used for sending data to another window like iframe, popup window, etc.
* @param target
* @param name
* @param body
* @param targetOrigin
*/
export default function messageTell(target: Window, name: string, body: {} | undefined, targetOrigin: string): void;
+1
View File
@@ -0,0 +1 @@
export default function removeListen(target: any, key: any): void;
@@ -0,0 +1,2 @@
export declare const getOriginOfUrl: (url: string) => string;
export declare const getUserPickerOrigin: () => string;
@@ -0,0 +1 @@
export {};
+19
View File
@@ -0,0 +1,19 @@
/**
* windowPostMessage.ts is deprecated since it features only userPicker feature.
* Please use message.ts when sending window.postMessage.
*/
export interface IframeEvent extends MessageEvent {
data: {
name: string;
body: any;
};
}
export declare class WindowPostMessage {
receiver: Window;
destination: Window;
listenKeyName: string;
constructor();
init(receiver: Window, destination: Window, callback: (e: IframeEvent) => Promise<void>): void;
send(name: string, body?: {}): void;
destroy(): void;
}
+2
View File
@@ -0,0 +1,2 @@
export declare const handleRes: (res: Response) => Promise<any>;
export default function (url: string, options?: RequestInit): Promise<any>;
+5
View File
@@ -0,0 +1,5 @@
export declare function createUrl({ subdomain, pathname, }: {
subdomain?: string;
pathname: string;
}): string;
export default function getEndPoint(key: string): string;
+6
View File
@@ -0,0 +1,6 @@
/**
* Hex to Base64
* @param {string} str [hex]
* @return {string} [base64]
*/
export default function hexToBase64(hex: string): string;
+1
View File
@@ -0,0 +1 @@
export {};
+7
View File
@@ -0,0 +1,7 @@
import parse from './parse';
import stringify from './stringify';
declare const _default: {
parse: typeof parse;
stringify: typeof stringify;
};
export default _default;
+10
View File
@@ -0,0 +1,10 @@
declare type Value = undefined | string;
declare type Query = Record<string, Value | Value[]>;
/**
* Parse url query string to object
* @export
* @param {string} search - query string
* @returns {{}} - query object
*/
export default function parse(search: string): Query;
export {};
+1
View File
@@ -0,0 +1 @@
export {};
+11
View File
@@ -0,0 +1,11 @@
declare type CanBeEncoded = Parameters<typeof encodeURIComponent>[0] | undefined;
declare type StringifiableValue = CanBeEncoded | CanBeEncoded[];
declare type Query = Record<string, StringifiableValue>;
/**
* Stringify object to url query string
* @export
* @param {{}} query - object
* @returns {string} - query string
*/
export default function stringify(query: Query): string;
export {};
+6
View File
@@ -0,0 +1,6 @@
/**
* return random alphanumeric string
* @param {number} length [length of sting]
* @return {string} [alphanumeric string]
*/
export default function randomAlphaNumericString(length: number): string;
+1
View File
@@ -0,0 +1 @@
export default function toStyle(styles: {}, important?: boolean): string;
+1
View File
@@ -0,0 +1 @@
export declare type ElementType<T extends ReadonlyArray<unknown>> = T extends ReadonlyArray<infer ElementType> ? ElementType : never;
+15
View File
@@ -0,0 +1,15 @@
/**
* check if a user uses IE
*/
export declare function isIE(userAgent?: string): boolean;
export declare function isIpad(userAgent?: string): boolean;
/**
* return true when UA includes `Line/0.0.0`
* @param userAgent
*/
export declare function isLINEBrowser(userAgent?: string): boolean;
/**
* return true when UA includes `Line/0.0.0 LIFF`
* @param userAgent
*/
export declare function isLIFFBrowser(userAgent?: string): boolean;