mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Moved everything to global scope.
This commit is contained in:
parent
662c4e6185
commit
ae342fbcdb
@ -1,11 +1,9 @@
|
||||
import * as cloudflareApps from "cloudflare-apps";
|
||||
|
||||
declare function describe(desc: string, f: () => void): void;
|
||||
declare function it(desc: string, f: () => void): void;
|
||||
|
||||
describe("Globals", () => {
|
||||
it("INSTALL_OPTIONS returns InstallOptions (dictionary)", () => {
|
||||
const options: cloudflareApps.InstallOptions = INSTALL_OPTIONS;
|
||||
const options: CloudflareApps.InstallOptions = INSTALL_OPTIONS;
|
||||
});
|
||||
|
||||
it("INSTALL_ID should return string", () => {
|
||||
@ -13,11 +11,11 @@ describe("Globals", () => {
|
||||
});
|
||||
|
||||
it("INSTALL_SCOPE returns InstallScope (dictionary)", () => {
|
||||
const scope: cloudflareApps.InstallScope = INSTALL_SCOPE;
|
||||
const scope: CloudflareApps.InstallScope = INSTALL_SCOPE;
|
||||
});
|
||||
|
||||
it("INSTALL_PRODUCT returns InstallProduct", () => {
|
||||
const product: cloudflareApps.InstallProduct | undefined = INSTALL_PRODUCT;
|
||||
const product: CloudflareApps.InstallProduct | undefined = INSTALL_PRODUCT;
|
||||
|
||||
if (product != null) {
|
||||
const id = product.id;
|
||||
@ -29,7 +27,7 @@ describe("Globals", () => {
|
||||
});
|
||||
|
||||
it("CloudflareApps is CloudflareApps object", () => {
|
||||
const apps: cloudflareApps.CloudflareApps = CloudflareApps;
|
||||
const apps: CloudflareApps.CloudflareApps = CloudflareApps;
|
||||
});
|
||||
});
|
||||
|
||||
@ -62,7 +60,7 @@ describe("CloudflareApps methods", () => {
|
||||
describe("CloudflareApps properties", () => {
|
||||
it("installs", () => {
|
||||
const appId = "preview";
|
||||
const app: cloudflareApps.App | undefined = CloudflareApps.installs[appId];
|
||||
const app: CloudflareApps.App | undefined = CloudflareApps.installs[appId];
|
||||
|
||||
if (app != null) {
|
||||
const id: string = app.appId;
|
||||
@ -70,7 +68,7 @@ describe("CloudflareApps properties", () => {
|
||||
});
|
||||
|
||||
it("proxy", () => {
|
||||
const proxy: cloudflareApps.CloudflareAppsProxy = CloudflareApps.proxy;
|
||||
const proxy: CloudflareApps.CloudflareAppsProxy = CloudflareApps.proxy;
|
||||
const siteId: string = proxy.embedSiteId;
|
||||
});
|
||||
|
||||
|
||||
221
types/cloudflare-apps/index.d.ts
vendored
221
types/cloudflare-apps/index.d.ts
vendored
@ -4,117 +4,122 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
declare global {
|
||||
/**
|
||||
* An object which contains all of the options the installer specified,
|
||||
* based on the structure given in the options section of your `install.json`.
|
||||
*/
|
||||
const INSTALL_OPTIONS: InstallOptions;
|
||||
// tslint:disable-next-line:no-single-declare-module
|
||||
declare module "cloudflare-apps" {
|
||||
global {
|
||||
/**
|
||||
* An object which contains all of the options the installer specified,
|
||||
* based on the structure given in the options section of your `install.json`.
|
||||
*/
|
||||
const INSTALL_OPTIONS: CloudflareApps.InstallOptions;
|
||||
|
||||
/**
|
||||
* A string ID which is equal to the ID of this install.
|
||||
* Its primary purpose is to allow you to easily distinguish between your app being loaded
|
||||
* in the Cloudflare Preview or the installer’s live website.
|
||||
*/
|
||||
const INSTALL_ID: string;
|
||||
/**
|
||||
* A string ID which is equal to the ID of this install.
|
||||
* Its primary purpose is to allow you to easily distinguish between your app being loaded
|
||||
* in the Cloudflare Preview or the installer’s live website.
|
||||
*/
|
||||
const INSTALL_ID: string;
|
||||
|
||||
/**
|
||||
* An object which you can use to store arbitrary values
|
||||
* which you would like to be accessable from other Cloudflare scripts,
|
||||
* without polluting the global scope.
|
||||
* For example, it’s commonly used to share an update function with its update handler.
|
||||
*/
|
||||
const INSTALL_SCOPE: InstallScope;
|
||||
/**
|
||||
* An object which you can use to store arbitrary values
|
||||
* which you would like to be accessable from other Cloudflare scripts,
|
||||
* without polluting the global scope.
|
||||
* For example, it’s commonly used to share an update function with its update handler.
|
||||
*/
|
||||
const INSTALL_SCOPE: CloudflareApps.InstallScope;
|
||||
|
||||
/**
|
||||
* This object is specific to paid apps. It allows you to know which product the user has purchased.
|
||||
* When you create a paid app you will be given product ids for each of the plans you wish to sell the product for.
|
||||
* `INSTALL_PRODUCT.id` will then be that id for the plan the user has purchased.
|
||||
* This value is absent for free apps and will always be set for paid apps even if the user is on a free plan.
|
||||
*/
|
||||
const INSTALL_PRODUCT: InstallProduct | undefined;
|
||||
/**
|
||||
* This object is specific to paid apps. It allows you to know which product the user has purchased.
|
||||
* When you create a paid app you will be given product ids for each of the plans you wish to sell the product for.
|
||||
* `INSTALL_PRODUCT.id` will then be that id for the plan the user has purchased.
|
||||
* This value is absent for free apps and will always be set for paid apps even if the user is on a free plan.
|
||||
*/
|
||||
const INSTALL_PRODUCT: CloudflareApps.InstallProduct | undefined;
|
||||
|
||||
/**
|
||||
* It's the same as CloudflareApps variable.
|
||||
*
|
||||
* DON'T use this variable directly.
|
||||
* BAD Example:
|
||||
* ```ts
|
||||
* const apps: cloudflareApps.CloudflareApps = INSTALL;
|
||||
* ```
|
||||
* -------------------------------------------------
|
||||
* Use directly properties and methods.
|
||||
* GOOD Example:
|
||||
* ```ts
|
||||
* const siteId: string = INSTALL.siteId;
|
||||
* ```
|
||||
*/
|
||||
const INSTALL: CloudflareApps;
|
||||
/**
|
||||
* It's the same as CloudflareApps variable.
|
||||
*
|
||||
* DON'T use this variable directly.
|
||||
* BAD Example:
|
||||
* ```ts
|
||||
* const apps: cloudflareApps.CloudflareApps = INSTALL;
|
||||
* ```
|
||||
* -------------------------------------------------
|
||||
* Use directly properties and methods.
|
||||
* GOOD Example:
|
||||
* ```ts
|
||||
* const siteId: string = INSTALL.siteId;
|
||||
* ```
|
||||
*/
|
||||
const INSTALL: CloudflareApps.CloudflareApps;
|
||||
|
||||
/**
|
||||
* This is undocumented global variable.
|
||||
* The documentation may arrive later.
|
||||
*/
|
||||
const CloudflareApps: CloudflareApps;
|
||||
}
|
||||
|
||||
export interface InstallOptions {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface InstallScope {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface InstallProduct {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface CloudflareAppsMethods {
|
||||
createElement<T extends Element>(options: ElementLocation, previousElement?: T): T;
|
||||
|
||||
matchPage(patterns: string[]): boolean;
|
||||
|
||||
querySelector<K extends keyof ElementTagNameMap>(selectors: K): ElementTagNameMap[K] | null;
|
||||
querySelector(selectors: string): Element | null;
|
||||
}
|
||||
|
||||
export interface CloudflareApps extends CloudflareAppsMethods {
|
||||
installs: { [id: string]: App | undefined };
|
||||
proxy: CloudflareAppsProxy;
|
||||
siteId: string;
|
||||
}
|
||||
|
||||
export interface App {
|
||||
appId: string;
|
||||
options: InstallOptions;
|
||||
scope: InstallScope;
|
||||
}
|
||||
|
||||
export interface CloudflareAppsProxy {
|
||||
embedSiteId: string;
|
||||
hasRocketEmbed: boolean;
|
||||
originalURL: OriginalURL;
|
||||
}
|
||||
|
||||
export interface OriginalURL {
|
||||
raw: string;
|
||||
parsed: OriginalURLParsed;
|
||||
}
|
||||
|
||||
export interface OriginalURLParsed {
|
||||
fragment: string;
|
||||
host: string;
|
||||
path: string;
|
||||
scheme: "https" | "http";
|
||||
query: URLQuery;
|
||||
}
|
||||
|
||||
export interface URLQuery {
|
||||
[key: string]: string[];
|
||||
}
|
||||
|
||||
export interface ElementLocation {
|
||||
method: "before" | "prepend" | "append" | "after" | "replace";
|
||||
selector: string;
|
||||
/**
|
||||
* This is undocumented global variable.
|
||||
* The documentation may arrive later.
|
||||
*/
|
||||
const CloudflareApps: CloudflareApps.CloudflareApps;
|
||||
|
||||
namespace CloudflareApps {
|
||||
interface InstallOptions {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface InstallScope {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface InstallProduct {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface CloudflareAppsMethods {
|
||||
createElement<T extends Element>(options: ElementLocation, previousElement?: T): T;
|
||||
|
||||
matchPage(patterns: string[]): boolean;
|
||||
|
||||
querySelector<K extends keyof ElementTagNameMap>(selectors: K): ElementTagNameMap[K] | null;
|
||||
querySelector(selectors: string): Element | null;
|
||||
}
|
||||
|
||||
interface CloudflareApps extends CloudflareAppsMethods {
|
||||
installs: { [id: string]: App | undefined };
|
||||
proxy: CloudflareAppsProxy;
|
||||
siteId: string;
|
||||
}
|
||||
|
||||
interface App {
|
||||
appId: string;
|
||||
options: InstallOptions;
|
||||
scope: InstallScope;
|
||||
}
|
||||
|
||||
interface CloudflareAppsProxy {
|
||||
embedSiteId: string;
|
||||
hasRocketEmbed: boolean;
|
||||
originalURL: OriginalURL;
|
||||
}
|
||||
|
||||
interface OriginalURL {
|
||||
raw: string;
|
||||
parsed: OriginalURLParsed;
|
||||
}
|
||||
|
||||
interface OriginalURLParsed {
|
||||
fragment: string;
|
||||
host: string;
|
||||
path: string;
|
||||
scheme: "https" | "http";
|
||||
query: URLQuery;
|
||||
}
|
||||
|
||||
interface URLQuery {
|
||||
[key: string]: string[];
|
||||
}
|
||||
|
||||
interface ElementLocation {
|
||||
method: "before" | "prepend" | "append" | "after" | "replace";
|
||||
selector: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user