busroot-sdk 0.0.4 → 0.0.6

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { PlantSchema, PlantViewModel, ScheduleViewModel, BusrootSignals, SkuViewModel, StationSchema, StationViewModel, AccountViewModel, ApiKeyViewModel, AggregatedStationWindowsByStation } from "./busroot";
1
+ import { PlantSchema, PlantViewModel, ScheduleViewModel, BusrootSignals, SkuViewModel, StationSchema, StationViewModel, AccountViewModel, ApiKeyViewModel, AggregatedStationWindowsByStation, ProductionViewModel } from "./types";
2
2
  import mqtt from "mqtt/dist/mqtt.min";
3
3
  export declare const MqttEventType: {
4
4
  StationMetricNew: string;
@@ -10,23 +10,19 @@ export declare const MqttEventType: {
10
10
  };
11
11
  export type MqttEventType = keyof typeof MqttEventType;
12
12
  export type Listener = (msg: any) => void;
13
+ export interface Config {
14
+ accountId: string;
15
+ apiKey: string;
16
+ apiEndpoint: string;
17
+ mqttHost?: string;
18
+ enableMqtt?: boolean;
19
+ enableDebug?: boolean;
20
+ }
13
21
  declare class BusrootClient {
14
- config: {
15
- accountId: string;
16
- apiKey: string;
17
- apiEndpoint: string;
18
- mqttHost?: string;
19
- enableMqtt?: boolean;
20
- };
22
+ config: Config;
21
23
  mqttClient: mqtt.MqttClient | undefined;
22
24
  listenersByEventType: Map<"StationMetricNew" | "StationChanged" | "ScheduleChanged" | "ScheduleStarted" | "ScheduleEnded" | "ProductionNew", Set<Listener>>;
23
- constructor(config: {
24
- accountId: string;
25
- apiKey: string;
26
- apiEndpoint: string;
27
- mqttHost?: string;
28
- enableMqtt?: boolean;
29
- });
25
+ constructor(config: Config);
30
26
  destroy(): void;
31
27
  private get;
32
28
  private post;
@@ -51,10 +47,22 @@ declare class BusrootClient {
51
47
  createUpdate: (station: Partial<StationSchema>) => Promise<StationViewModel>;
52
48
  signal: (stationCode: string, payload: BusrootSignals) => void;
53
49
  };
50
+ get production(): {
51
+ get: ({ plantCode, stationCodes, rangeCode, }: {
52
+ plantCode: string;
53
+ stationCodes?: string[];
54
+ rangeCode: string;
55
+ }) => Promise<ProductionViewModel[]>;
56
+ getRaw: ({ plantCode, stationCodes, rangeCode, }: {
57
+ plantCode: string;
58
+ stationCodes?: string[];
59
+ rangeCode: string;
60
+ }) => Promise<ProductionViewModel[]>;
61
+ };
54
62
  get metrics(): {
55
63
  get: ({ plantCode, stationCodes, rangeCode, aggregateWindow, }: {
56
64
  plantCode: string;
57
- stationCodes: string[];
65
+ stationCodes?: string[];
58
66
  rangeCode: string;
59
67
  aggregateWindow: string;
60
68
  }) => Promise<AggregatedStationWindowsByStation[]>;
@@ -71,3 +79,4 @@ declare class BusrootClient {
71
79
  off(event: MqttEventType, listener: Listener): void;
72
80
  }
73
81
  export { BusrootClient };
82
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,oBAAoB,CAAC;AAEtC,eAAO,MAAM,aAAa;;;;;;;CAOzB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,aAAa,CAAC;AAEvD,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;AAS1C,MAAM,WAAW,MAAM;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE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zB,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
@@ -14,29 +14,11 @@ exports.MqttEventType = {
14
14
  ProductionNew: "PRODUCTION_NEW", // When new production is added. NOT IMPLEMENTED FOR MANUAL PRODUCTION YET.
15
15
  };
16
16
  class BusrootClient {
17
+ config;
18
+ mqttClient;
19
+ listenersByEventType = new Map();
17
20
  constructor(config) {
18
21
  this.config = config;
19
- this.listenersByEventType = new Map();
20
- this.sku = {
21
- get: async (skuCode) => {
22
- const res = await this.get("/sku", { skucodes: skuCode });
23
- return res.result;
24
- },
25
- createUpdate: async (sku) => {
26
- const res = await this.post("/sku", sku);
27
- return res.result;
28
- },
29
- };
30
- this.schedule = {
31
- get: async (scheduleId) => {
32
- const res = await this.get("/schedule", { ids: String(scheduleId) });
33
- return res.results;
34
- },
35
- createUpdate: async (schedule) => {
36
- const res = await this.post("/schedule", schedule);
37
- return res.result;
38
- },
39
- };
40
22
  const trimmedAccountId = config.accountId.replace("account_", "");
41
23
  if (config.enableMqtt === true && config.mqttHost !== null) {
42
24
  this.mqttClient = mqtt_min_1.default.connect({
@@ -85,15 +67,20 @@ class BusrootClient {
85
67
  url +=
86
68
  "?" +
87
69
  Object.entries(query)
70
+ .filter((value) => value[1] != null)
88
71
  .map((value) => value[0] + "=" + value[1])
89
72
  .join("&");
90
73
  }
74
+ if (this.config.enableDebug === true) {
75
+ console.log("Get Request: " + url);
76
+ }
91
77
  const res = await fetch(url, {
92
78
  headers: { "x-api-key": this.config.apiKey },
93
79
  method: "GET",
94
80
  });
95
81
  if (res.status !== 200) {
96
- throw new Error(`${res.status}: ${res.statusText}`);
82
+ const resBody = await res.json();
83
+ throw new Error(`${res.status}: ${res.statusText}: ${resBody.errorCode}`);
97
84
  }
98
85
  const resJson = await res.json();
99
86
  return resJson;
@@ -105,7 +92,8 @@ class BusrootClient {
105
92
  body: JSON.stringify(body),
106
93
  });
107
94
  if (res.status !== 200) {
108
- throw new Error(`${res.status}: ${res.statusText}`);
95
+ const resBody = await res.json();
96
+ throw new Error(`${res.status}: ${res.statusText}: ${resBody.errorCode}`);
109
97
  }
110
98
  const resJson = await res.json();
111
99
  return resJson;
@@ -161,12 +149,32 @@ class BusrootClient {
161
149
  },
162
150
  };
163
151
  }
152
+ get production() {
153
+ return {
154
+ get: async ({ plantCode, stationCodes, rangeCode, }) => {
155
+ const res = await this.get("/production", {
156
+ plantcode: plantCode,
157
+ stationcodes: stationCodes?.join(","),
158
+ rangecode: rangeCode,
159
+ });
160
+ return res.results;
161
+ },
162
+ getRaw: async ({ plantCode, stationCodes, rangeCode, }) => {
163
+ const res = await this.get("/production/raw", {
164
+ plantcode: plantCode,
165
+ stationcodes: stationCodes?.join(","),
166
+ rangecode: rangeCode,
167
+ });
168
+ return res.results;
169
+ },
170
+ };
171
+ }
164
172
  get metrics() {
165
173
  return {
166
174
  get: async ({ plantCode, stationCodes, rangeCode, aggregateWindow, }) => {
167
175
  const res = await this.get("/station-windows", {
168
176
  plantcode: plantCode,
169
- stationcodes: stationCodes.join(","),
177
+ stationcodes: stationCodes?.join(","),
170
178
  rangecode: rangeCode,
171
179
  aggregatewindow: aggregateWindow,
172
180
  });
@@ -174,6 +182,26 @@ class BusrootClient {
174
182
  },
175
183
  };
176
184
  }
185
+ sku = {
186
+ get: async (skuCode) => {
187
+ const res = await this.get("/sku", { skucodes: skuCode });
188
+ return res.result;
189
+ },
190
+ createUpdate: async (sku) => {
191
+ const res = await this.post("/sku", sku);
192
+ return res.result;
193
+ },
194
+ };
195
+ schedule = {
196
+ get: async (scheduleId) => {
197
+ const res = await this.get("/schedule", { ids: String(scheduleId) });
198
+ return res.results;
199
+ },
200
+ createUpdate: async (schedule) => {
201
+ const res = await this.post("/schedule", schedule);
202
+ return res.result;
203
+ },
204
+ };
177
205
  on(event, listener) {
178
206
  let set = this.listenersByEventType.get(event);
179
207
  if (!set) {
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=client.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../src/client.test.ts"],"names":[],"mappings":""}
package/build/hooks.d.ts CHANGED
@@ -22,3 +22,4 @@ export declare function useBusroot(props?: {
22
22
  client: BusrootClient | undefined;
23
23
  logout: () => void;
24
24
  };
25
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,CAAC,MAAM,KAAK,CAAC;AAMpB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;EAK9B,CAAC;AAEH,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE;;;EAuC1D"}
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./client";
2
2
  export * from "./hooks";
3
- export type { PlantSchema, PlantViewModel, ScheduleViewModel, BusrootSignals, SkuViewModel, StationSchema, StationViewModel, AccountViewModel, ApiKeyViewModel, } from "./busroot";
4
- export { formattedDuration, formattedDateTime } from "busroot-common/src/utils/times";
3
+ export * from "./utils";
4
+ export type { PlantSchema, PlantViewModel, ScheduleViewModel, BusrootSignals, SkuViewModel, StationSchema, StationViewModel, AccountViewModel, ApiKeyViewModel, } from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,YAAY,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,MAAM,SAAS,CAAC"}
package/build/index.js CHANGED
@@ -14,9 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.formattedDateTime = exports.formattedDuration = void 0;
18
17
  __exportStar(require("./client"), exports);
19
18
  __exportStar(require("./hooks"), exports);
20
- var times_1 = require("busroot-common/src/utils/times");
21
- Object.defineProperty(exports, "formattedDuration", { enumerable: true, get: function () { return times_1.formattedDuration; } });
22
- Object.defineProperty(exports, "formattedDateTime", { enumerable: true, get: function () { return times_1.formattedDateTime; } });
19
+ __exportStar(require("./utils"), exports);