busroot-sdk 0.0.6 → 0.0.7-alpha
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/build/client.d.ts +23 -6
- package/build/client.d.ts.map +1 -1
- package/build/client.js +13 -3
- package/build/hooks.d.ts +2 -19
- package/build/hooks.d.ts.map +1 -1
- package/build/hooks.js +21 -27
- package/package.json +2 -1
package/build/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import z from "zod";
|
|
1
2
|
import { PlantSchema, PlantViewModel, ScheduleViewModel, BusrootSignals, SkuViewModel, StationSchema, StationViewModel, AccountViewModel, ApiKeyViewModel, AggregatedStationWindowsByStation, ProductionViewModel } from "./types";
|
|
2
|
-
import mqtt from "mqtt
|
|
3
|
+
import mqtt from "mqtt";
|
|
3
4
|
export declare const MqttEventType: {
|
|
4
5
|
StationMetricNew: string;
|
|
5
6
|
StationChanged: string;
|
|
@@ -10,18 +11,34 @@ export declare const MqttEventType: {
|
|
|
10
11
|
};
|
|
11
12
|
export type MqttEventType = keyof typeof MqttEventType;
|
|
12
13
|
export type Listener = (msg: any) => void;
|
|
13
|
-
export
|
|
14
|
+
export declare const Config: z.ZodObject<{
|
|
15
|
+
accountId: z.ZodString;
|
|
16
|
+
apiKey: z.ZodString;
|
|
17
|
+
apiEndpoint: z.ZodString;
|
|
18
|
+
mqttHost: z.ZodString;
|
|
19
|
+
enableMqtt: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
enableDebug: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
22
|
accountId: string;
|
|
15
23
|
apiKey: string;
|
|
16
24
|
apiEndpoint: string;
|
|
17
|
-
mqttHost
|
|
18
|
-
enableMqtt?: boolean;
|
|
19
|
-
enableDebug?: boolean;
|
|
20
|
-
}
|
|
25
|
+
mqttHost: string;
|
|
26
|
+
enableMqtt?: boolean | undefined;
|
|
27
|
+
enableDebug?: boolean | undefined;
|
|
28
|
+
}, {
|
|
29
|
+
accountId: string;
|
|
30
|
+
apiKey: string;
|
|
31
|
+
apiEndpoint: string;
|
|
32
|
+
mqttHost: string;
|
|
33
|
+
enableMqtt?: boolean | undefined;
|
|
34
|
+
enableDebug?: boolean | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
export type Config = z.infer<typeof Config>;
|
|
21
37
|
declare class BusrootClient {
|
|
22
38
|
config: Config;
|
|
23
39
|
mqttClient: mqtt.MqttClient | undefined;
|
|
24
40
|
listenersByEventType: Map<"StationMetricNew" | "StationChanged" | "ScheduleChanged" | "ScheduleStarted" | "ScheduleEnded" | "ProductionNew", Set<Listener>>;
|
|
41
|
+
static version: string;
|
|
25
42
|
constructor(config: Config);
|
|
26
43
|
destroy(): void;
|
|
27
44
|
private get;
|
package/build/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iCAAiC,EACjC,mBAAmB,EACpB,MAAM,SAAS,CAAC;AACjB,OAAO,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EACL,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,iCAAiC,EACjC,mBAAmB,EACpB,MAAM,SAAS,CAAC;AACjB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,eAAO,MAAM,aAAa;;;;;;;CAOzB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,aAAa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SAAS,EAAE,MAAM,CAAC;SACnB,KAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;MAUrC;IAED,IAAI,OAAO;wEAOJ;YACD,SAAS,EAAE,MAAM,CAAC;YAClB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;YACxB,SAAS,EAAE,MAAM,CAAC;YAClB,eAAe,EAAE,MAAM,CAAC;SACzB,KAAG,OAAO,CAAC,iCAAiC,EAAE,CAAC;MAWnD;IAED,GAAG;uBACoB,MAAM,KAAG,OAAO,CAAC,YAAY,CAAC;4BAKzB,OAAO,CAAC,YAAY,CAAC,KAAG,OAAO,CAAC,YAAY,CAAC;MAKvE;IAEF,QAAQ;0BACkB,MAAM,KAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;iCAK9B,OAAO,CAAC,iBAAiB,CAAC,KAAG,OAAO,CAAC,iBAAiB,CAAC;MAKtF;IAEF,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ;IAU3C,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ;CAW7C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/build/client.js
CHANGED
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BusrootClient = exports.MqttEventType = void 0;
|
|
7
|
-
const
|
|
6
|
+
exports.BusrootClient = exports.Config = exports.MqttEventType = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const mqtt_1 = __importDefault(require("mqtt"));
|
|
8
9
|
exports.MqttEventType = {
|
|
9
10
|
StationMetricNew: "STATION_METRIC_NEW", // When a new station window is created and saved to DB.
|
|
10
11
|
StationChanged: "STATION_CHANGED", // When a station is added or edited. NOT IMPLEMENTED.
|
|
@@ -13,15 +14,24 @@ exports.MqttEventType = {
|
|
|
13
14
|
ScheduleEnded: "SCHEDULE_ENDED", // When a schedule ends (actualEndAt). NOT IMPLEMENTED.
|
|
14
15
|
ProductionNew: "PRODUCTION_NEW", // When new production is added. NOT IMPLEMENTED FOR MANUAL PRODUCTION YET.
|
|
15
16
|
};
|
|
17
|
+
exports.Config = zod_1.default.object({
|
|
18
|
+
accountId: zod_1.default.string().max(255),
|
|
19
|
+
apiKey: zod_1.default.string().max(255),
|
|
20
|
+
apiEndpoint: zod_1.default.string().max(255),
|
|
21
|
+
mqttHost: zod_1.default.string().max(255),
|
|
22
|
+
enableMqtt: zod_1.default.boolean().optional(),
|
|
23
|
+
enableDebug: zod_1.default.boolean().optional(),
|
|
24
|
+
});
|
|
16
25
|
class BusrootClient {
|
|
17
26
|
config;
|
|
18
27
|
mqttClient;
|
|
19
28
|
listenersByEventType = new Map();
|
|
29
|
+
static version = "v0";
|
|
20
30
|
constructor(config) {
|
|
21
31
|
this.config = config;
|
|
22
32
|
const trimmedAccountId = config.accountId.replace("account_", "");
|
|
23
33
|
if (config.enableMqtt === true && config.mqttHost !== null) {
|
|
24
|
-
this.mqttClient =
|
|
34
|
+
this.mqttClient = mqtt_1.default.connect({
|
|
25
35
|
host: config.mqttHost,
|
|
26
36
|
port: 8883,
|
|
27
37
|
username: "api-key",
|
package/build/hooks.d.ts
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
import { BusrootClient } from "./client";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
export declare const ConfigPayloadSchema: z.ZodObject<{
|
|
4
|
-
accountId: z.ZodString;
|
|
5
|
-
apiKey: z.ZodString;
|
|
6
|
-
apiEndpoint: z.ZodString;
|
|
7
|
-
mqttHost: z.ZodString;
|
|
8
|
-
}, "strip", z.ZodTypeAny, {
|
|
9
|
-
accountId: string;
|
|
10
|
-
apiKey: string;
|
|
11
|
-
apiEndpoint: string;
|
|
12
|
-
mqttHost: string;
|
|
13
|
-
}, {
|
|
14
|
-
accountId: string;
|
|
15
|
-
apiKey: string;
|
|
16
|
-
apiEndpoint: string;
|
|
17
|
-
mqttHost: string;
|
|
18
|
-
}>;
|
|
1
|
+
import { BusrootClient, Config } from "./client";
|
|
19
2
|
export declare function useBusroot(props?: {
|
|
20
|
-
|
|
3
|
+
config?: Config;
|
|
21
4
|
}): {
|
|
22
5
|
client: BusrootClient | undefined;
|
|
23
6
|
logout: () => void;
|
package/build/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMjD,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;EA2CrD"}
|
package/build/hooks.js
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ConfigPayloadSchema = void 0;
|
|
8
4
|
exports.useBusroot = useBusroot;
|
|
9
5
|
const react_1 = require("react");
|
|
10
6
|
const client_1 = require("./client");
|
|
11
|
-
const zod_1 = __importDefault(require("zod"));
|
|
12
7
|
// TODO: Should accept a JWT token with a limited expiry time, instead of an API key. MQTT auth will need to be altered to make this work.
|
|
13
8
|
// TODO: Account ID and API key should be saved to a local cookie and removed from the query param.
|
|
14
9
|
// TODO: Add logout functionality, that clears the cookies.
|
|
15
|
-
exports.ConfigPayloadSchema = zod_1.default.object({
|
|
16
|
-
accountId: zod_1.default.string().max(255),
|
|
17
|
-
apiKey: zod_1.default.string().max(255),
|
|
18
|
-
apiEndpoint: zod_1.default.string().max(255),
|
|
19
|
-
mqttHost: zod_1.default.string().max(255),
|
|
20
|
-
});
|
|
21
10
|
function useBusroot(props) {
|
|
22
|
-
const enableMqtt = props && props.enableMqtt;
|
|
11
|
+
const enableMqtt = props && props.config != null && props.config.enableMqtt === true;
|
|
23
12
|
const [client, setClient] = (0, react_1.useState)();
|
|
24
13
|
(0, react_1.useEffect)(() => {
|
|
25
14
|
if (typeof window === undefined) {
|
|
26
15
|
return;
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
17
|
+
if (props != null && props.config != null) {
|
|
18
|
+
setClient(new client_1.BusrootClient(props.config));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
22
|
+
const tokenParam = searchParams.get("busroot_token");
|
|
23
|
+
if (tokenParam != null && client == null) {
|
|
24
|
+
try {
|
|
25
|
+
const config = client_1.Config.parse(JSON.parse(atob(tokenParam)));
|
|
26
|
+
setClient(new client_1.BusrootClient({
|
|
27
|
+
accountId: config.accountId,
|
|
28
|
+
apiKey: config.apiKey,
|
|
29
|
+
apiEndpoint: config.apiEndpoint,
|
|
30
|
+
mqttHost: config.mqttHost,
|
|
31
|
+
enableMqtt,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
console.log(e.message);
|
|
36
|
+
}
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "busroot-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7-alpha",
|
|
4
4
|
"description": "An SDK for accessing Busroot from output.industries",
|
|
5
5
|
"homepage": "https://www.output.industries",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dev": "pnpm run lint && tsc -b --watch",
|
|
12
12
|
"build": "pnpm run lint && tsc --build --clean && tsc --build",
|
|
13
13
|
"lint": "eslint 'src/**/*.ts'",
|
|
14
|
+
"lint-fix": "eslint 'src/**/*.ts' --fix",
|
|
14
15
|
"test": "jest" },
|
|
15
16
|
"files": [
|
|
16
17
|
"build"
|