@d-najd/universal-media-tracker-sdk 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "@d-najd/universal-media-tracker-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
+ "types": "dist/index.d.ts",
5
+ "files": ["dist"],
4
6
  "main": "index.js",
5
7
  "scripts": {
6
8
  "build": "tsc"
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="MaterialThemeProjectNewConfig">
4
- <option name="metadata">
5
- <MTProjectMetadataState>
6
- <option name="migrated" value="true" />
7
- <option name="pristineConfig" value="false" />
8
- <option name="userId" value="-6b4e7951:198ec88be16:-7ffe" />
9
- </MTProjectMetadataState>
10
- </option>
11
- </component>
12
- </project>
package/src/pluginSdk.ts DELETED
@@ -1,87 +0,0 @@
1
- import PluginConfig from "./types/pluginConfig";
2
- import Handler from "./types/handler/base/handler";
3
- import CreateResourceHandler from "./types/handler/media/createResourceHandler";
4
- import ResourceHandler from "./types/handler/media/resourceHandler";
5
- import CreateCatalogHandler from "./types/handler/media/catalog/createCatalogHandler";
6
- import PluginSpec from "./types/pluginSpec";
7
-
8
- export default class Plugin {
9
- readonly config: PluginConfig
10
- private handlers = new Map<string, Handler>()
11
-
12
- private counter = 0
13
- private loaded = false
14
-
15
- constructor(options: PluginConfig) {
16
- this.config = options
17
- }
18
-
19
- /**
20
- * Don't define handlers here, they are part of the spec
21
- */
22
- onLoad(callback: () => Promise<void>) {
23
- this.onLoadCallback = async () => {
24
- await callback()
25
- this.loaded = true
26
- }
27
- }
28
-
29
- onUnload(callback: () => Promise<void>) {
30
- this.onUnloadCallback = async () => {
31
- await callback()
32
- this.loaded = false
33
- }
34
- }
35
-
36
- /**
37
- * @see Handler
38
- */
39
- defineResourceHandler(handler: CreateResourceHandler): string {
40
- const newHandler: ResourceHandler = {
41
- id: `${this.config.id}-custom-${this.counter++}`,
42
- name: `${this.config.name}`,
43
- ...handler
44
- }
45
-
46
- this.handlers.set(newHandler.id, newHandler)
47
- return newHandler.id
48
- }
49
-
50
- /**
51
- * Defines or overrides if a catalog handler has already been defined, if
52
- * you use multiple catalog handlers use `defineMediaHandler` instead
53
- * @see defineResourceHandler
54
- */
55
- defineCatalogHandler(handler: CreateCatalogHandler): string {
56
- const newHandler: CreateResourceHandler = {
57
- id: `${this.config.id}-catalog-handler`,
58
- ...handler,
59
- type: 'catalog-request'
60
- }
61
-
62
- return this.defineResourceHandler(newHandler)
63
- }
64
-
65
- // Used internally, private since its internal api
66
- // noinspection JSUnusedLocalSymbols
67
- private getSpec(): PluginSpec {
68
- if (!this.loaded) {
69
- throw Error("The plugin must be loaded before getting it's spec")
70
- }
71
-
72
- return {
73
- config: this.config,
74
- handlers: this.handlers,
75
- onLoad: this.onLoadCallback,
76
- onUnload: this.onUnloadCallback
77
- }
78
- }
79
-
80
- private onLoadCallback: () => Promise<void> = async () => {
81
- this.loaded = true
82
- }
83
-
84
- private onUnloadCallback: () => Promise<void> = async () => {
85
- this.loaded = false
86
- }
87
- }
@@ -1,7 +0,0 @@
1
- type BaseHandlerArgs = {
2
- readonly search?: string
3
- readonly skip?: number
4
- readonly pageSize?: number
5
- }
6
-
7
- export default BaseHandlerArgs
@@ -1,6 +0,0 @@
1
- // eslint-disable-next-line
2
- type BaseHandlerResponse<T = any> = {
3
- readonly data: T[]
4
- }
5
-
6
- export default BaseHandlerResponse
@@ -1,20 +0,0 @@
1
- /*
2
- * Represents a plugin handler.
3
- *
4
- * @remarks
5
- * - `type` can be a predefined `MediaHandlerTypes` value or any custom string.
6
- * Custom types must be handled by the plugin author.
7
- * - `id` is a unique identifier for the handler. If a handler with the same
8
- * id exists, it will be overridden.
9
- * - `name` name of the handler that will be displayed in the app
10
- * - `callback` callback function that is called when the handler is invoked
11
- */
12
-
13
- // eslint-disable-next-line
14
- type Handler<T = any, R = any> = {
15
- id: string
16
- type: string
17
- callback: (args: T) => Promise<R>
18
- }
19
-
20
- export default Handler
@@ -1,5 +0,0 @@
1
- import BaseHandlerArgs from "../../base/baseHandlerArgs";
2
-
3
- type CatalogHandlerArgs = BaseHandlerArgs & {}
4
-
5
- export default CatalogHandlerArgs
@@ -1,6 +0,0 @@
1
- import BaseHandlerResponse from "../../base/baseHandlerResponse";
2
- import MetaPreview from "./metaPreview";
3
-
4
- type CatalogHandlerResponse = BaseHandlerResponse<MetaPreview> & {}
5
-
6
- export default CatalogHandlerResponse
@@ -1,13 +0,0 @@
1
- import CreateResourceHandler from "../createResourceHandler";
2
- import CatalogHandlerArgs from "./catalogHandlerArgs";
3
- import CatalogHandlerResponse from "./catalogHandlerResponse";
4
- import ResourceHandlerType from "../resourceHandlerType";
5
-
6
- type CreateCatalogHandler = Omit<
7
- CreateResourceHandler<CatalogHandlerArgs, CatalogHandlerResponse>,
8
- 'type'
9
- > & {
10
- type?: ResourceHandlerType | string
11
- }
12
-
13
- export default CreateCatalogHandler
@@ -1,8 +0,0 @@
1
- type MetaPreview = {
2
- readonly id: string
3
- readonly type: string
4
- readonly name: string
5
- readonly poster: string
6
- }
7
-
8
- export default MetaPreview
@@ -1,13 +0,0 @@
1
- import BaseHandlerArgs from "../base/baseHandlerArgs";
2
- import BaseHandlerResponse from "../base/baseHandlerResponse";
3
- import ResourceHandler from "./resourceHandler";
4
-
5
- type CreateResourceHandler<
6
- T extends BaseHandlerArgs = BaseHandlerArgs,
7
- R extends BaseHandlerResponse = BaseHandlerResponse
8
- > = Omit<ResourceHandler<T, R>, 'id' | 'name'> & {
9
- id?: string
10
- name?: string
11
- }
12
-
13
- export default CreateResourceHandler
@@ -1,19 +0,0 @@
1
- import BaseHandlerArgs from "../base/baseHandlerArgs";
2
- import BaseHandlerResponse from "../base/baseHandlerResponse";
3
- import Handler from "../base/handler";
4
- import ResourceHandlerType from "./resourceHandlerType";
5
- import ResourceType from "./resourceType";
6
-
7
- type ResourceHandler<
8
- T extends BaseHandlerArgs = BaseHandlerArgs,
9
- R extends BaseHandlerResponse = BaseHandlerResponse
10
- > = Handler<T, R> & {
11
- /**
12
- * Displayed in the app
13
- */
14
- name: string
15
- type: ResourceHandlerType | string
16
- resourceType: ResourceType | string
17
- }
18
-
19
- export default ResourceHandler
@@ -1,3 +0,0 @@
1
- type ResourceHandlerType = 'catalog-request'
2
-
3
- export default ResourceHandlerType
@@ -1,3 +0,0 @@
1
- type ResourceType = 'movie' | 'series'
2
-
3
- export default ResourceType
@@ -1,7 +0,0 @@
1
- type PluginConfig = {
2
- readonly id: string
3
- readonly name: string
4
- readonly version: string
5
- }
6
-
7
- export default PluginConfig
@@ -1,9 +0,0 @@
1
- import PluginConfig from "./pluginConfig";
2
- import Handler from "./handler/base/handler";
3
-
4
- export default interface PluginSpec {
5
- readonly config: PluginConfig
6
- readonly onLoad: () => Promise<void>
7
- readonly onUnload: () => Promise<void>
8
- readonly handlers: Map<string, Handler>
9
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2018",
4
- "module": "ESNext",
5
- "declaration": true,
6
- "outDir": "dist",
7
- "strict": true,
8
- "esModuleInterop": true
9
- },
10
- "include": ["src"]
11
- }