aitum.js
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,2 +0,56 @@ | ||
import { AitumAPIClient } from './AitumAPIClient'; | ||
export { AitumAPIClient, }; | ||
import { AxiosInstance } from 'axios'; | ||
import { I as IRule, a as IGlobalVariable, b as IHypeTrainInfo, c as IPollInfo } from './IPollInfo-20d639a0.js'; | ||
declare class Aitum { | ||
private readonly base; | ||
constructor(base: AxiosInstance); | ||
/** | ||
* Get rules | ||
* | ||
* @description Get all Aitum rules | ||
*/ | ||
getRules(): Promise<IRule[]>; | ||
/** | ||
* Trigger a rule | ||
* | ||
* @description Trigger an Aitum rule | ||
* | ||
* @param rule - Rule to trigger | ||
*/ | ||
triggerRule(rule: IRule | string): Promise<void>; | ||
/** | ||
* Get global variables | ||
* | ||
* @description Get all global variables | ||
* | ||
* @returns | ||
*/ | ||
getGlobalVariables(): Promise<IGlobalVariable[]>; | ||
} | ||
declare class Twitch { | ||
private readonly base; | ||
constructor(base: AxiosInstance); | ||
/** | ||
* Get hype train | ||
* | ||
* @description Get the current Hype Train | ||
*/ | ||
getHypeTrain(): Promise<IHypeTrainInfo>; | ||
/** | ||
* Get poll | ||
* | ||
* @description Get the current poll | ||
*/ | ||
getPoll(): Promise<IPollInfo>; | ||
} | ||
declare class AitumAPIClient { | ||
private readonly ip; | ||
private readonly apiBase; | ||
readonly aitum: Aitum; | ||
readonly twitch: Twitch; | ||
constructor(ip?: string); | ||
} | ||
export { AitumAPIClient }; |
133
lib/index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AitumAPIClient = void 0; | ||
const AitumAPIClient_1 = require("./AitumAPIClient"); | ||
Object.defineProperty(exports, "AitumAPIClient", { enumerable: true, get: function () { return AitumAPIClient_1.AitumAPIClient; } }); | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
AitumAPIClient: () => AitumAPIClient | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/AitumAPIClient.ts | ||
var import_axios = __toESM(require("axios")); | ||
// src/Utils.ts | ||
function apiErrorHandler(error) { | ||
if (error.response) { | ||
return error.response.data.error; | ||
} else if (error.request) { | ||
return "Request timed out, please ensure Aitum is running."; | ||
} else { | ||
console.log("aitum.js request error", error.message); | ||
return error.message; | ||
} | ||
} | ||
// src/API/Aitum.ts | ||
var Aitum = class { | ||
constructor(base) { | ||
this.base = base; | ||
} | ||
async getRules() { | ||
try { | ||
const call = await this.base.get("aitum/rules"); | ||
let rules = []; | ||
for (const [k, v] of Object.entries(call.data.data)) { | ||
rules.push({ name: k, id: v }); | ||
} | ||
return rules; | ||
} catch (err) { | ||
throw new Error(apiErrorHandler(err)); | ||
} | ||
} | ||
async triggerRule(rule) { | ||
try { | ||
const ruleId = typeof rule === "object" ? rule.id : rule; | ||
await this.base.get(`aitum/rules/${ruleId}`); | ||
} catch (err) { | ||
throw new Error(apiErrorHandler(err)); | ||
} | ||
} | ||
async getGlobalVariables() { | ||
try { | ||
const call = await this.base.get("aitum/state"); | ||
let vars = []; | ||
for (const state of call.data.data) { | ||
vars.push({ | ||
id: state["_id"], | ||
name: state.name, | ||
type: state.type, | ||
value: state.value | ||
}); | ||
} | ||
return vars; | ||
} catch (err) { | ||
throw new Error(apiErrorHandler(err)); | ||
} | ||
} | ||
}; | ||
// src/API/Twitch.ts | ||
var Twitch = class { | ||
constructor(base) { | ||
this.base = base; | ||
} | ||
async getHypeTrain() { | ||
try { | ||
const call = await this.base.get("twitch/hypetrain"); | ||
return call.data.data; | ||
} catch (err) { | ||
throw new Error(apiErrorHandler(err)); | ||
} | ||
} | ||
async getPoll() { | ||
try { | ||
const call = await this.base.get("twitch/poll"); | ||
return call.data.data; | ||
} catch (err) { | ||
throw new Error(apiErrorHandler(err)); | ||
} | ||
} | ||
}; | ||
// src/AitumAPIClient.ts | ||
var AitumAPIClient = class { | ||
constructor(ip = "127.0.0.1") { | ||
this.ip = ip; | ||
this.apiBase = import_axios.default.create({ | ||
baseURL: `http://${ip}:7777/`, | ||
timeout: 2500 | ||
}); | ||
this.aitum = new Aitum(this.apiBase); | ||
this.twitch = new Twitch(this.apiBase); | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
AitumAPIClient | ||
}); |
{ | ||
"name": "aitum.js", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"keywords": [ | ||
@@ -10,2 +10,3 @@ "aitum", | ||
"main": "lib/index.js", | ||
"description": "API Wrapper library for Aitum's Public API", | ||
"types": "lib/index.d.ts", | ||
@@ -17,8 +18,13 @@ "files": [ | ||
"author": "David Marsh <david@aitum.tv>", | ||
"contributors": [{ | ||
"name": "Nuro", | ||
"url": "https://github.com/NuroDev" | ||
}], | ||
"license": "MIT", | ||
"private": false, | ||
"devDependencies": { | ||
"npm-run-all": "^4.1.5", | ||
"@types/node": "^18.11.9", | ||
"prettier": "^2.8.0", | ||
"rimraf": "^3.0.2", | ||
"run-s": "^0.0.0", | ||
"tsup": "^6.5.0", | ||
"typescript": "^4.9.3" | ||
@@ -30,7 +36,10 @@ }, | ||
"scripts": { | ||
"build:clean": "rimraf ./lib/* tsconfig.tsbuildinfo", | ||
"build:wait": "sleep 1", | ||
"build:generate": "./node_modules/typescript/bin/tsc", | ||
"build": "run-s build:*" | ||
"build": "tsup", | ||
"clean": "rimraf node_modules dist", | ||
"dev": "tsup --watch", | ||
"format": "prettier --write \"**/*.{js,json,ts}\"" | ||
}, | ||
"prettier": { | ||
"singleQuote": true | ||
} | ||
} |
@@ -1,3 +0,4 @@ | ||
# aitum.js | ||
<p align="center"> | ||
<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjMuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAxMDAwIDEwMDAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDEwMDAgMTAwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiNGRkZGRkY7fQo8L3N0eWxlPgo8cG9seWdvbiBjbGFzcz0ic3QwIiBwb2ludHM9IjQyNi40Nyw3My4yNCA5MjYuNDYsNTczLjIyIDkyNi40Niw3My4yNCAiLz4KPHBvbHlnb24gY2xhc3M9InN0MCIgcG9pbnRzPSI3My41NCw3MTkuMzMgNTczLjUzLDIxOS4zNSA3My41NCwyMTkuMzUgIi8+Cjxwb2x5Z29uIGNsYXNzPSJzdDAiIHBvaW50cz0iOTI2LjQ2LDU3My4yMiAyMTkuMzcsNTczLjIyIDU3Mi45Miw5MjYuNzYgIi8+Cjwvc3ZnPgo=" /> | ||
<br /> | ||
<a href="https://docs.aitum.tv/api">API Documentation</a> | ||
@@ -10,2 +11,4 @@ <br /> | ||
# aitum.js | ||
JS/TS library for Aitum's Public API. This library requires [Aitum](https://aitum.tv) to be installed and running. You can read the API documentation [here](https://docs.aitum.tv/en/api). | ||
@@ -12,0 +15,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13199
311
59
5
10
1