mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-06 12:37:46 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18c735a920 | ||
|
|
331618b77a | ||
|
|
5f601ecf65 | ||
|
|
8eeef06c9c | ||
|
|
bc9335abcf | ||
|
|
792fedc759 | ||
|
|
e343455e77 | ||
|
|
7a7931b0d0 | ||
|
|
b3c26fd1a7 | ||
|
|
26fa0aef86 | ||
|
|
74ecefac8b | ||
|
|
8855195c09 | ||
|
|
227636620e | ||
|
|
5866739942 | ||
|
|
0eacb0e7c4 | ||
|
|
c0efb9a732 | ||
|
|
71484de76e | ||
|
|
be73efff0b | ||
|
|
a00c394526 | ||
|
|
3d57b22b26 | ||
|
|
995bbedbb6 | ||
|
|
d638acb5d2 | ||
|
|
f87006d3e8 | ||
|
|
fcab6f2532 | ||
|
|
4c552faaf5 | ||
|
|
7ea8776750 | ||
|
|
b9487a78df | ||
|
|
4addcb43e0 | ||
|
|
05444f54ad | ||
|
|
a7139cc510 | ||
|
|
ddbf96d1d1 | ||
|
|
a40e1f6ee9 | ||
|
|
b37ec6d21e | ||
|
|
b868a95db1 | ||
|
|
7d18553ff0 | ||
|
|
e83d09070a |
5
.github/workflows/bump_version.yml
vendored
5
.github/workflows/bump_version.yml
vendored
@@ -5,11 +5,6 @@ on:
|
|||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: The version to bump to
|
description: The version to bump to
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths:
|
|
||||||
- plexjs/**
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update_typescript_version:
|
update_typescript_version:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ files:
|
|||||||
destinationFilename: package.json
|
destinationFilename: package.json
|
||||||
npmName: plexjs
|
npmName: plexjs
|
||||||
npmRepository: lukehagar
|
npmRepository: lukehagar
|
||||||
npmVersion: 0.0.15
|
npmVersion: 0.0.22
|
||||||
useSingleRequestParameter: true
|
useSingleRequestParameter: true
|
||||||
sortParamsByRequiredFlag: true
|
sortParamsByRequiredFlag: true
|
||||||
gitUserID: lukehagar
|
gitUserID: lukehagar
|
||||||
|
|||||||
6
examples/.eslintignore
Normal file
6
examples/.eslintignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# don't ever lint node_modules
|
||||||
|
node_modules
|
||||||
|
# don't lint build output (make sure it's set to your correct build folder name)
|
||||||
|
build
|
||||||
|
# don't lint nyc coverage output
|
||||||
|
coverage
|
||||||
19
examples/.eslintrc
Normal file
19
examples/.eslintrc
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"plugins": ["@typescript-eslint", "prettier", "jest"],
|
||||||
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"prettier"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"no-console": 1,
|
||||||
|
"prettier/prettier": 2
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": true,
|
||||||
|
"jest/globals": true
|
||||||
|
}
|
||||||
|
}
|
||||||
107
examples/.gitignore
vendored
Normal file
107
examples/.gitignore
vendored
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
.env.test
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
.vscode-test
|
||||||
43
examples/README.md
Normal file
43
examples/README.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# 🧰 Simple TypeScript Starter | 2022
|
||||||
|
|
||||||
|
> We talk about a lot of **advanced Node.js and TypeScript** concepts on [the blog](https://khalilstemmler.com), particularly focused around Domain-Driven Design and large-scale enterprise application patterns. However, I received a few emails from readers that were interested in seeing what a basic TypeScript starter project looks like. So I've put together just that.
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- Minimal
|
||||||
|
- TypeScript v4
|
||||||
|
- Testing with Jest
|
||||||
|
- Linting with Eslint and Prettier
|
||||||
|
- Pre-commit hooks with Husky
|
||||||
|
- VS Code debugger scripts
|
||||||
|
- Local development with Nodemon
|
||||||
|
|
||||||
|
### Scripts
|
||||||
|
|
||||||
|
#### `npm run start:dev`
|
||||||
|
|
||||||
|
Starts the application in development using `nodemon` and `ts-node` to do hot reloading.
|
||||||
|
|
||||||
|
#### `npm run start`
|
||||||
|
|
||||||
|
Starts the app in production by first building the project with `npm run build`, and then executing the compiled JavaScript at `build/index.js`.
|
||||||
|
|
||||||
|
#### `npm run build`
|
||||||
|
|
||||||
|
Builds the app at `build`, cleaning the folder first.
|
||||||
|
|
||||||
|
#### `npm run test`
|
||||||
|
|
||||||
|
Runs the `jest` tests once.
|
||||||
|
|
||||||
|
#### `npm run test:dev`
|
||||||
|
|
||||||
|
Run the `jest` tests in watch mode, waiting for file changes.
|
||||||
|
|
||||||
|
#### `npm run prettier-format`
|
||||||
|
|
||||||
|
Format your code.
|
||||||
|
|
||||||
|
#### `npm run prettier-watch`
|
||||||
|
|
||||||
|
Format your code in watch mode, waiting for file changes.
|
||||||
@@ -1 +0,0 @@
|
|||||||
import { Configuration } from "@lukehagar/plexjs";
|
|
||||||
6
examples/nodemon.json
Normal file
6
examples/nodemon.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"watch": ["src"],
|
||||||
|
"ext": ".ts,.js",
|
||||||
|
"ignore": [],
|
||||||
|
"exec": "npx ts-node ./src/index.ts"
|
||||||
|
}
|
||||||
17904
examples/package-lock.json
generated
Normal file
17904
examples/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "examples",
|
"name": "typescript-starter",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Examples using the plexjs package",
|
"description": "A basic typescript app starter for 2023.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "npx ts-node index.ts",
|
"build": "rimraf ./build && tsc",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"dev": "npx nodemon",
|
||||||
|
"start": "npm run build && node build/index.js"
|
||||||
},
|
},
|
||||||
"author": "lukehagar",
|
"keywords": [],
|
||||||
"license": "MIT",
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@lukehagar/plexjs": "^0.0.7"
|
"@lukehagar/plexjs": "^0.0.21",
|
||||||
|
"@types/jest": "^29.5.1",
|
||||||
|
"@types/node": "^18.6.1",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
||||||
|
"@typescript-eslint/parser": "^5.31.0",
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
|
"nodemon": "^2.0.19",
|
||||||
|
"onchange": "^7.1.0",
|
||||||
|
"rimraf": "^5.0.0",
|
||||||
|
"run-script-os": "^1.1.6",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
|
"typescript": "^5.0.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jest-cucumber": "^3.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
examples/src/index.ts
Normal file
19
examples/src/index.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import {
|
||||||
|
Configuration,
|
||||||
|
ServerApi,
|
||||||
|
DevicesApi,
|
||||||
|
UserApi,
|
||||||
|
} from "@lukehagar/plexjs";
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const config = new Configuration({
|
||||||
|
basePath: process.env.BASE_PATH,
|
||||||
|
plexToken: process.env.PLEX_TOKEN,
|
||||||
|
});
|
||||||
|
|
||||||
|
new ServerApi(config).getServerCapabilities().then((resp) => console.log(resp));
|
||||||
|
|
||||||
|
new DevicesApi(config).getDevices().then((resp) => console.log(resp));
|
||||||
|
|
||||||
|
new UserApi(config).getUserDetails().then((resp) => console.log(resp));
|
||||||
16
examples/tsconfig.json
Normal file
16
examples/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"module": "commonjs",
|
||||||
|
"lib": ["es6"],
|
||||||
|
"allowJs": true,
|
||||||
|
"outDir": "build",
|
||||||
|
"rootDir": "src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"types": ["node", "jest"],
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["src/**/*.spec.ts"]
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
Arguments:
|
|
||||||
C:\Program Files\nodejs\node.exe C:\Users\Luke\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js add --dev plexjs
|
|
||||||
|
|
||||||
PATH:
|
|
||||||
C:\Python311\Scripts\;C:\Python311\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\Go\bin;C:\Users\Luke\.console-ninja\.bin;C:\Users\Luke\AppData\Local\Microsoft\WindowsApps;C:\Users\Luke\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Luke\AppData\Local\GitHubDesktop\bin;C:\Users\Luke\go\bin;C:\Users\Luke\AppData\Roaming\npm;C:\Users\Luke\go\bin
|
|
||||||
|
|
||||||
Yarn version:
|
|
||||||
1.22.19
|
|
||||||
|
|
||||||
Node version:
|
|
||||||
18.14.2
|
|
||||||
|
|
||||||
Platform:
|
|
||||||
win32 x64
|
|
||||||
|
|
||||||
Trace:
|
|
||||||
Error: https://registry.yarnpkg.com/plexjs: Not found
|
|
||||||
at params.callback [as _callback] (C:\Users\Luke\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:66145:18)
|
|
||||||
at self.callback (C:\Users\Luke\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:140890:22)
|
|
||||||
at Request.emit (node:events:513:28)
|
|
||||||
at Request.<anonymous> (C:\Users\Luke\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:141862:10)
|
|
||||||
at Request.emit (node:events:513:28)
|
|
||||||
at IncomingMessage.<anonymous> (C:\Users\Luke\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:141784:12)
|
|
||||||
at Object.onceWrapper (node:events:627:28)
|
|
||||||
at IncomingMessage.emit (node:events:525:35)
|
|
||||||
at endReadableNT (node:internal/streams/readable:1359:12)
|
|
||||||
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
|
|
||||||
|
|
||||||
npm manifest:
|
|
||||||
{
|
|
||||||
"name": "examples",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "Examples using the plexjs package",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "npx ts-node index.ts",
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "lukehagar",
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
||||||
|
|
||||||
yarn manifest:
|
|
||||||
No manifest
|
|
||||||
|
|
||||||
Lockfile:
|
|
||||||
No lockfile
|
|
||||||
4372
examples/yarn.lock
4372
examples/yarn.lock
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
## plexjs@0.0.15
|
## plexjs@0.0.22
|
||||||
|
|
||||||
This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
|
This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ navigate to the folder of your consuming project and run one of the following co
|
|||||||
_published:_
|
_published:_
|
||||||
|
|
||||||
```
|
```
|
||||||
npm install plexjs@0.0.15 --save
|
npm install plexjs@0.0.22 --save
|
||||||
```
|
```
|
||||||
|
|
||||||
_unPublished (not recommended):_
|
_unPublished (not recommended):_
|
||||||
|
|||||||
3201
plexjs/api.ts
3201
plexjs/api.ts
File diff suppressed because it is too large
Load Diff
@@ -14,14 +14,83 @@
|
|||||||
|
|
||||||
import { IAxiosRetryConfig } from "axios-retry";
|
import { IAxiosRetryConfig } from "axios-retry";
|
||||||
|
|
||||||
export interface ConfigurationParameters {
|
export type ConfigurationParameters = {
|
||||||
|
plexToken?: string;
|
||||||
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
clientIdentifier?: string;
|
||||||
|
device?: string;
|
||||||
|
deviceName?: string;
|
||||||
|
platform?: string;
|
||||||
|
platformVersion?: string;
|
||||||
|
product?: string;
|
||||||
|
version?: string;
|
||||||
basePath?: string;
|
basePath?: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Configuration {
|
export class Configuration {
|
||||||
|
/**
|
||||||
|
* Plex Media Server or Plex.TV Authentication token
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
plexToken?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UUID, serial number, or other number unique per device
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
clientIdentifier?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device name and model number, eg iPhone3,2, Motorola XOOM™, LG5200TV
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
device?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customized Device Name
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
deviceName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Platform name, eg iOS, MacOSX, Android, LG, etc
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
platform?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operating system version, eg 4.3.1, 10.6.7, 3.2
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
platformVersion?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plex application name, eg Laika, Plex Media Server, Media Link
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
product?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plex application version number
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
version?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parameter for apiKey security
|
* parameter for apiKey security
|
||||||
* @param name security name
|
* @param name security name
|
||||||
@@ -63,10 +132,42 @@ export class Configuration {
|
|||||||
retriesConfig?: IAxiosRetryConfig
|
retriesConfig?: IAxiosRetryConfig
|
||||||
|
|
||||||
constructor(param: ConfigurationParameters = {}) {
|
constructor(param: ConfigurationParameters = {}) {
|
||||||
|
this.plexToken = param.plexToken || "";
|
||||||
|
this.clientIdentifier = param.clientIdentifier || "plexjs";
|
||||||
|
this.device = param.device || "plexjs";
|
||||||
|
this.deviceName = param.deviceName || "plexjs";
|
||||||
|
this.platform = param.platform || "plexjs";
|
||||||
|
this.platformVersion = param.platformVersion || "0.0.22";
|
||||||
|
this.product = param.product || "plexjs";
|
||||||
|
this.version = param.version || "0.0.22";
|
||||||
|
|
||||||
this.apiKey = param.apiKey;
|
this.apiKey = (header: string) => {
|
||||||
|
switch (header) {
|
||||||
|
case "X-Plex-Token":
|
||||||
|
return this.plexToken
|
||||||
|
case "X-Plex-Client-Identifier":
|
||||||
|
return this.clientIdentifier
|
||||||
|
case "X-Plex-Device-Name":
|
||||||
|
return this.deviceName
|
||||||
|
case "X-Plex-Device":
|
||||||
|
return this.device
|
||||||
|
case "X-Plex-Platform-Version":
|
||||||
|
return this.platformVersion
|
||||||
|
case "X-Plex-Platform":
|
||||||
|
return this.platform
|
||||||
|
case "X-Plex-Product":
|
||||||
|
return this.product
|
||||||
|
case "X-Plex-Version":
|
||||||
|
return this.version
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
this.basePath = param.basePath;
|
this.basePath = param.basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setAuthToken(token: string) {
|
||||||
|
this.plexToken = token
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,5 +14,5 @@
|
|||||||
|
|
||||||
|
|
||||||
export * from "./api";
|
export * from "./api";
|
||||||
export * from "./configuration";
|
export {Configuration, ConfigurationParameters} from "./configuration";
|
||||||
|
|
||||||
|
|||||||
4
plexjs/package-lock.json
generated
4
plexjs/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@lukehagar/plexjs",
|
"name": "@lukehagar/plexjs",
|
||||||
"version": "0.0.15",
|
"version": "0.0.22",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lukehagar/plexjs",
|
"name": "@lukehagar/plexjs",
|
||||||
"version": "0.0.15",
|
"version": "0.0.22",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.26.1",
|
"axios": "^0.26.1",
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@lukehagar/plexjs",
|
"name": "@lukehagar/plexjs",
|
||||||
"version": "0.0.15",
|
"version": "0.0.22",
|
||||||
"description": "Community Made Plex JS/TS Module",
|
"description": "Community Made Plex JS/TS Module",
|
||||||
"author": "Luke Hagar",
|
"author": "Luke Hagar",
|
||||||
"type": "module",
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/LukeHagar/plexjs.git"
|
"url": "https://github.com/LukeHagar/plexjs.git"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"target": "ES5",
|
"target": "ES5",
|
||||||
"module": "CommonJS",
|
"module": "CommonJS",
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"outDir": "./dist",
|
"outDir": "dist",
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es6",
|
"es6",
|
||||||
@@ -12,10 +12,12 @@
|
|||||||
],
|
],
|
||||||
"typeRoots": [
|
"typeRoots": [
|
||||||
"node_modules/@types"
|
"node_modules/@types"
|
||||||
]
|
],
|
||||||
|
"sourceMap": true
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist",
|
"dist",
|
||||||
"node_modules"
|
"node_modules",
|
||||||
|
"./dist/**/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
36
readme.md
36
readme.md
@@ -2,10 +2,42 @@
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
A typescript sdk for accessing the Plex.tv and Plex Media Server REST API's.
|
A typescript sdk for interacting with Plex.tv and Plex Media Server REST API's.
|
||||||
|
|
||||||
|
Documentation for all of the available endpoints [can be found here](https://plexapi.dev/docs/plex)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
npm
|
||||||
```bash
|
```bash
|
||||||
npm install plexjs
|
npm install @lukehagar/plexjs
|
||||||
|
```
|
||||||
|
|
||||||
|
yarn
|
||||||
|
```bash
|
||||||
|
yarn add @lukehagar/plexjs
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import {
|
||||||
|
Configuration,
|
||||||
|
ServerApi,
|
||||||
|
DevicesApi,
|
||||||
|
UserApi,
|
||||||
|
} from "@lukehagar/plexjs";
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const config = new Configuration({
|
||||||
|
basePath: process.env.BASE_PATH,
|
||||||
|
plexToken: process.env.PLEX_TOKEN,
|
||||||
|
});
|
||||||
|
|
||||||
|
new ServerApi(config).getServerCapabilities().then((resp) => console.log(resp));
|
||||||
|
|
||||||
|
new DevicesApi(config).getDevices().then((resp) => console.log(resp));
|
||||||
|
|
||||||
|
new UserApi(config).getUserDetails().then((resp) => console.log(resp));
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -3,14 +3,83 @@
|
|||||||
{{>licenseInfo}}
|
{{>licenseInfo}}
|
||||||
import { IAxiosRetryConfig } from "axios-retry";
|
import { IAxiosRetryConfig } from "axios-retry";
|
||||||
|
|
||||||
export interface ConfigurationParameters {
|
export type ConfigurationParameters = {
|
||||||
|
plexToken?: string;
|
||||||
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
clientIdentifier?: string;
|
||||||
|
device?: string;
|
||||||
|
deviceName?: string;
|
||||||
|
platform?: string;
|
||||||
|
platformVersion?: string;
|
||||||
|
product?: string;
|
||||||
|
version?: string;
|
||||||
basePath?: string;
|
basePath?: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Configuration {
|
export class Configuration {
|
||||||
|
/**
|
||||||
|
* Plex Media Server or Plex.TV Authentication token
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
plexToken?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UUID, serial number, or other number unique per device
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
clientIdentifier?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Device name and model number, eg iPhone3,2, Motorola XOOM™, LG5200TV
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
device?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customized Device Name
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
deviceName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Platform name, eg iOS, MacOSX, Android, LG, etc
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
platform?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operating system version, eg 4.3.1, 10.6.7, 3.2
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
platformVersion?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plex application name, eg Laika, Plex Media Server, Media Link
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
product?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plex application version number
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof Configuration
|
||||||
|
*/
|
||||||
|
version?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parameter for apiKey security
|
* parameter for apiKey security
|
||||||
* @param name security name
|
* @param name security name
|
||||||
@@ -52,10 +121,42 @@ export class Configuration {
|
|||||||
retriesConfig?: IAxiosRetryConfig
|
retriesConfig?: IAxiosRetryConfig
|
||||||
|
|
||||||
constructor(param: ConfigurationParameters = {}) {
|
constructor(param: ConfigurationParameters = {}) {
|
||||||
|
this.plexToken = param.plexToken || "";
|
||||||
|
this.clientIdentifier = param.clientIdentifier || "{{npmName}}";
|
||||||
|
this.device = param.device || "{{npmName}}";
|
||||||
|
this.deviceName = param.deviceName || "{{npmName}}";
|
||||||
|
this.platform = param.platform || "{{npmName}}";
|
||||||
|
this.platformVersion = param.platformVersion || "{{npmVersion}}";
|
||||||
|
this.product = param.product || "{{npmName}}";
|
||||||
|
this.version = param.version || "{{npmVersion}}";
|
||||||
|
|
||||||
this.apiKey = param.apiKey;
|
this.apiKey = (header: string) => {
|
||||||
|
switch (header) {
|
||||||
|
case "X-Plex-Token":
|
||||||
|
return this.plexToken
|
||||||
|
case "X-Plex-Client-Identifier":
|
||||||
|
return this.clientIdentifier
|
||||||
|
case "X-Plex-Device-Name":
|
||||||
|
return this.deviceName
|
||||||
|
case "X-Plex-Device":
|
||||||
|
return this.device
|
||||||
|
case "X-Plex-Platform-Version":
|
||||||
|
return this.platformVersion
|
||||||
|
case "X-Plex-Platform":
|
||||||
|
return this.platform
|
||||||
|
case "X-Plex-Product":
|
||||||
|
return this.product
|
||||||
|
case "X-Plex-Version":
|
||||||
|
return this.version
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
this.basePath = param.basePath;
|
this.basePath = param.basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setAuthToken(token: string) {
|
||||||
|
this.plexToken = token
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
{{>licenseInfo}}
|
{{>licenseInfo}}
|
||||||
|
|
||||||
export * from "./api";
|
export * from "./api";
|
||||||
export * from "./configuration";
|
export {Configuration, ConfigurationParameters} from "./configuration";
|
||||||
{{#withSeparateModelsAndApi}}export * from "./{{tsModelPackage}}";{{/withSeparateModelsAndApi}}
|
{{#withSeparateModelsAndApi}}export * from "./{{tsModelPackage}}";{{/withSeparateModelsAndApi}}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"version": "{{npmVersion}}",
|
"version": "{{npmVersion}}",
|
||||||
"description": "Community Made Plex JS/TS Module",
|
"description": "Community Made Plex JS/TS Module",
|
||||||
"author": "Luke Hagar",
|
"author": "Luke Hagar",
|
||||||
"type": "module",
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/LukeHagar/plexjs.git"
|
"url": "https://github.com/LukeHagar/plexjs.git"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
|
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
|
||||||
"module": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}CommonJS{{/supportsES6}}",
|
"module": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}CommonJS{{/supportsES6}}",
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"outDir": "./dist",
|
"outDir": "dist",
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
{{^supportsES6}}
|
{{^supportsES6}}
|
||||||
"lib": [
|
"lib": [
|
||||||
@@ -14,10 +14,12 @@
|
|||||||
{{/supportsES6}}
|
{{/supportsES6}}
|
||||||
"typeRoots": [
|
"typeRoots": [
|
||||||
"node_modules/@types"
|
"node_modules/@types"
|
||||||
]
|
],
|
||||||
|
"sourceMap": true
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist",
|
"dist",
|
||||||
"node_modules"
|
"node_modules",
|
||||||
|
"./dist/**/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user