Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.6.10",
"description": "An SDK for making and publishing Stremio add-ons",
"main": "./src/index.js",
"types": "./src/index.d.ts",
"scripts": {
"pretest": "eslint --ignore-path .gitignore .",
"test": "tape test/*"
Expand Down
86 changes: 86 additions & 0 deletions src/builder.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
Manifest,
AddonInterface,
Cache,
MetaPreview,
MetaDetail,
Stream,
Subtitle,
AddonCatalog,
DefaultConfig,
CatalogHandlerArgs,
MetaHandlerArgs,
StreamHandlerArgs,
SubtitlesHandlerArgs,
AddonCatalogHandlerArgs
} from './types';

/**
* Creates an addon builder object with a given manifest.
*
* The manifest will determine the basic information of your addon (name, description, images), but most importantly, it will determine when and how your addon will be invoked by Stremio.
*
* Throws an error if the manifest is not valid.
*/
declare class addonBuilder {
/**
* Creates an addon builder object with a given manifest.
*/
constructor(manifest: Manifest);

/**
* Handles catalog requests, including search.
*
* Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineCatalogHandler.md
*/
defineCatalogHandler<Config = DefaultConfig>(handler: (args: CatalogHandlerArgs<Config>) => Promise<{ metas: MetaPreview[] } & Cache>): this;

/**
* Handles metadata requests (title, year, poster, background, etc.).
*
* Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineMetaHandler.md
*/
defineMetaHandler<Config = DefaultConfig>(
handler: (args: MetaHandlerArgs<Config>) => Promise<{ meta: MetaDetail } & Cache>,
): this;

/**
* Handles stream requests.
*
* The stream responses should be ordered from highest to lowest quality.
*
* Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineStreamHandler.md
*/
defineStreamHandler<Config = DefaultConfig>(
handler: (args: StreamHandlerArgs<Config>) => Promise<{ streams: Stream[] } & Cache>,
): this;

/**
* Handles subtitle requests.
*
* Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineSubtitlesHandler.md
*/
defineSubtitlesHandler<Config = DefaultConfig>(
handler: (args: SubtitlesHandlerArgs<Config>) => Promise<{ subtitles: Subtitle[] } & Cache>,
): this;

/**
* Handles addon catalog requests
*
* As opposed to defineCatalogHandler() which handles meta catalogs, this method handles catalogs of addon manifests.
* This means that an addon can be used to just pass a list of other addons that can be installed in Stremio.
*
* Docs: https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/requests/defineResourceHandler.md
*/
defineResourceHandler<Config = DefaultConfig>(resource: string, handler: (args: AddonCatalogHandlerArgs<Config>) => Promise<{ addons: AddonCatalog[] } & Cache>): this;

/**
* Turns the addon into an addonInterface, which is an immutable (frozen) object that has {manifest, get} where:
*
* * manifest is a regular manifest object
* * get is a function that takes one argument of the form { resource, type, id, extra } and returns a Promise
*/
getInterface(): AddonInterface;
}

export = addonBuilder;
8 changes: 8 additions & 0 deletions src/getRouter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AddonInterface } from './types';

/**
* Turns the addonInterface into an express router that serves the addon according to the protocol and a landing page on the root (/).
*/
declare function getRouter(addonInterface: AddonInterface): any;

export = getRouter;
6 changes: 6 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { default as addonBuilder } from './builder';
export { default as serveHTTP } from './serveHTTP';
export { default as getRouter } from './getRouter';
export { default as publishToCentral } from './publishToCentral';
export { default as landingTemplate } from './landingTemplate';
export * from './types';
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module.exports = {
serveHTTP: require('./serveHTTP'),
getRouter: require('./getRouter'),
publishToCentral: require('./publishToCentral'),
landingTemplate: require('./landingTemplate'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: The EN+ addon, and likely others as well, rely on this function. In the past, I worked around this by importing it directly from stremio-addon-sdk/src/landingTemplate, but that approach no longer works with TypeScript due to type restrictions. This seems like a good opportunity to properly export the function so that users can import it directly from stremio-addon-sdk, regardless of whether they’re using plain JavaScript or TypeScript.

}
12 changes: 12 additions & 0 deletions src/landingTemplate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Manifest } from './types';

/**
* Generates an HTML landing page for the addon.
*
* This template creates a web page that displays the addon information and provides
* an installation button for Stremio. If the addon has configuration options,
* it will also generate a form for users to configure the addon before installation.
*/
declare function landingTemplate(manifest: Manifest): string;

export = landingTemplate;
11 changes: 11 additions & 0 deletions src/publishToCentral.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Publish your addon to the central server.
*
* This method expects a string with the url to your manifest.json file.
*
* After using this method your addon will be available in the Community Addons list in Stremio for users to install and use.
* Please note that your addon needs to be publicly available with a URL in order for this to happen, as local addons that are not publicly available cannot be used by other Stremio users.
*/
declare function publishToCentral(url: string, apiURL?: string): Promise<any>;

export = publishToCentral;
25 changes: 25 additions & 0 deletions src/serveHTTP.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AddonInterface } from './types';

/**
* Starts the addon server
*
* This method is also special in that it will react to certain process arguments, such as:
* * --launch: launches Stremio in the web browser, and automatically installs/upgrades the addon
* * --install: installs the addon in the desktop version of Stremio
*/
declare function serveHTTP(
addonInterface: AddonInterface,
options?: {
port?: number | undefined;
/**
* (in seconds) cacheMaxAge means the Cache-Control header being set to max-age=$cacheMaxAge
*/
cacheMaxAge?: number | undefined;
/**
* Static directory to serve.
*/
static?: string | undefined;
},
): void;

export = serveHTTP;
Loading