busroot-sdk 0.0.1 → 0.0.3
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/busroot.d.ts +277 -0
- package/build/client.d.ts +8 -6
- package/build/client.js +38 -34
- package/build/client.test.d.ts +0 -1
- package/build/hooks.d.ts +9 -5
- package/build/hooks.js +13 -3
- package/build/index.d.ts +1 -1
- package/package.json +3 -3
- package/build/client.d.ts.map +0 -1
- package/build/client.test.d.ts.map +0 -1
- package/build/common.d.ts +0 -973
- package/build/example.d.ts +0 -2
- package/build/example.d.ts.map +0 -1
- package/build/example.js +0 -31
- package/build/hooks.d.ts.map +0 -1
- package/build/index.d.ts.map +0 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
interface BusrootSignals {
|
|
4
|
+
timestamp?: number;
|
|
5
|
+
production_complete?: number;
|
|
6
|
+
bad_production_complete?: number;
|
|
7
|
+
production_count?: number;
|
|
8
|
+
production_count_good?: number;
|
|
9
|
+
bad_production_count?: number;
|
|
10
|
+
production_count_bad?: number;
|
|
11
|
+
sku_code?: string;
|
|
12
|
+
productive?: number;
|
|
13
|
+
line_speed?: number;
|
|
14
|
+
speed?: number;
|
|
15
|
+
status_code?: string;
|
|
16
|
+
electrical_kwh?: number;
|
|
17
|
+
electrical_kwh_interval?: number;
|
|
18
|
+
electrical_v?: number;
|
|
19
|
+
electrical_a?: number;
|
|
20
|
+
electrical_kw?: number;
|
|
21
|
+
electrical_hz?: number;
|
|
22
|
+
electrical_pf?: number;
|
|
23
|
+
rssi?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface PlantSchema {
|
|
27
|
+
code: string;
|
|
28
|
+
name: string;
|
|
29
|
+
timezone: string;
|
|
30
|
+
accountId: string;
|
|
31
|
+
dayStartHour: number;
|
|
32
|
+
createdAt?: string;
|
|
33
|
+
updatedAt?: string;
|
|
34
|
+
archivedAt?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare const StationSchema = z.object({
|
|
38
|
+
// Basics
|
|
39
|
+
accountId: z.string(),
|
|
40
|
+
code: z.string(),
|
|
41
|
+
name: z.string().trim().min(1).max(32),
|
|
42
|
+
groupCode: z.string(),
|
|
43
|
+
shiftPatternId: z.number().int().positive().nullish(),
|
|
44
|
+
moduleVisibility: z.array(z.nativeEnum(STATION_MODULE_VISIBILITY)).nullish(),
|
|
45
|
+
minimumCycleTime: z.number().int().gte(0).lte(TimeIntervals["12h"].ms).nullish(),
|
|
46
|
+
speedScale: z.number().gte(-9999).lte(9999).nullish(),
|
|
47
|
+
speedOffset: z.number().gte(-9999).lte(9999).nullish(),
|
|
48
|
+
speedToProductionRatio: z.number().gte(0).lte(99999).nullish(),
|
|
49
|
+
electricalPowerNominalKw: z.number().gte(0).nullish(),
|
|
50
|
+
|
|
51
|
+
// Defaults
|
|
52
|
+
idleCostPerMinute: z.number().gte(0).lte(99999).nullish(),
|
|
53
|
+
|
|
54
|
+
// Downtime Settings
|
|
55
|
+
downtimeDetectionMode: z.nativeEnum(DOWNTIME_DETECTION_MODE).default(DOWNTIME_DETECTION_MODE.UTILISATION).optional(),
|
|
56
|
+
utilisationDowntimeThreshold: z.preprocess((val) => (val === null ? TimeIntervals["1h"].ms : val), z.number().int().gte(0).optional()),
|
|
57
|
+
|
|
58
|
+
slowDurationThreshold: z.number().int().gte(0).nullish(),
|
|
59
|
+
forceAllShiftTimeAsPlannedProduction: z.boolean().default(true),
|
|
60
|
+
|
|
61
|
+
// Productive Settings
|
|
62
|
+
productiveStatusMode: z.nativeEnum(PRODUCTIVE_STATUS_MODE).default(PRODUCTIVE_STATUS_MODE.PRODUCTIVE_SIGNAL).optional(),
|
|
63
|
+
electricalUsageStoppedThresholdKw: z.number().gte(0).nullish(),
|
|
64
|
+
lineSpeedStoppedThreshold: z.number().gte(0).nullish(),
|
|
65
|
+
productiveHoldOnTime: z.number().int().gte(0).lte(TimeIntervals["1d"].ms).nullish(),
|
|
66
|
+
|
|
67
|
+
// Flags
|
|
68
|
+
allowInterruptionMode: z.boolean().default(false).optional(),
|
|
69
|
+
allowManualProduction: z.boolean().default(false).optional(),
|
|
70
|
+
allowQuickScheduleStart: z.boolean().default(false).optional(),
|
|
71
|
+
allowScheduleCutShort: z.boolean().default(false).optional(),
|
|
72
|
+
|
|
73
|
+
// Current State
|
|
74
|
+
currentOperatorInitials: z.string().min(3).max(3).nullish(),
|
|
75
|
+
statusCode: z.string().nullish(),
|
|
76
|
+
statusCodeUpdatedAt: z.string().nullish(),
|
|
77
|
+
|
|
78
|
+
// Performance Mode
|
|
79
|
+
cycleTime: z.number().int().gt(0).lte(TimeIntervals["12h"].ms).nullish(),
|
|
80
|
+
unitsPerMinute: z.number().int().gt(0).nullish(),
|
|
81
|
+
unitsPerHour: z.number().int().gt(0).nullish(),
|
|
82
|
+
lineSpeedTarget: z.number().gt(0).lte(99999).nullish(),
|
|
83
|
+
|
|
84
|
+
// System info
|
|
85
|
+
createdAt: z.string().nullish(),
|
|
86
|
+
updatedAt: z.string().nullish(),
|
|
87
|
+
archivedAt: z.string().nullish(),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
type StationSchema = z.infer<typeof StationSchema>;
|
|
91
|
+
|
|
92
|
+
declare const ApiKeySchema = z.object({
|
|
93
|
+
accountId: z.string(),
|
|
94
|
+
key: z.string(),
|
|
95
|
+
createdByUserId: z.number(),
|
|
96
|
+
expiresAt: z.string(),
|
|
97
|
+
createdAt: z.string().optional(),
|
|
98
|
+
updatedAt: z.string().optional(),
|
|
99
|
+
});
|
|
100
|
+
type ApiKeySchema = z.infer<typeof ApiKeySchema>;
|
|
101
|
+
|
|
102
|
+
declare const PlantViewModel = z.object({
|
|
103
|
+
code: z.string(),
|
|
104
|
+
name: z.string(),
|
|
105
|
+
timezone: z.string(),
|
|
106
|
+
now: z.string(),
|
|
107
|
+
stationGroups: z.array(StationGroupSchema.omit({ accountId: true })),
|
|
108
|
+
dayStartHour: z.number(),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
type PlantViewModel = z.infer<typeof PlantViewModel>;
|
|
112
|
+
|
|
113
|
+
declare const SkuViewModel = z.object({
|
|
114
|
+
code: z.string(),
|
|
115
|
+
name: z.string(),
|
|
116
|
+
cycleTime: z.number().nullish(),
|
|
117
|
+
specifications: z.object({ name: z.string(), value: z.string() }).array().nullish(),
|
|
118
|
+
instructionsUrl: z.string().nullish(),
|
|
119
|
+
lineSpeedTarget: z.number().nullish(),
|
|
120
|
+
downtimeDurationThresholdMultiplier: z.number().nullish(),
|
|
121
|
+
allowUseInQuickSchedule: z.boolean().nullish(),
|
|
122
|
+
unitsPerMinute: z.number().nullish(),
|
|
123
|
+
unitsPerHour: z.number().nullish(),
|
|
124
|
+
batchSize: z.number().nullish(),
|
|
125
|
+
value: z.number().nullish(),
|
|
126
|
+
minimumCycleTime: z.number().nullish(),
|
|
127
|
+
});
|
|
128
|
+
type SkuViewModel = z.infer<typeof SkuViewModel>;
|
|
129
|
+
|
|
130
|
+
type ApiKeyViewModel = ApiKeySchema;
|
|
131
|
+
|
|
132
|
+
declare const ScheduleViewModel = z.object({
|
|
133
|
+
id: z.number(),
|
|
134
|
+
stationCode: z.string(),
|
|
135
|
+
stationName: z.string().optional(),
|
|
136
|
+
accountId: z.string(),
|
|
137
|
+
plannedStartAt: z.string(),
|
|
138
|
+
plannedStartAtTimestamp: z.number(),
|
|
139
|
+
plannedEndAt: z.string().optional(),
|
|
140
|
+
plannedEndAtTimestamp: z.number().optional(),
|
|
141
|
+
workOrderReference: z.string().optional(),
|
|
142
|
+
plannedDuration: z.number().optional(),
|
|
143
|
+
plannedQuantity: z.number().optional(),
|
|
144
|
+
nonProductionReasonCode: z.string().optional(),
|
|
145
|
+
nonProductionReasonDescription: z.string().optional(),
|
|
146
|
+
skuCode: z.string().optional(),
|
|
147
|
+
skuName: z.string().optional(),
|
|
148
|
+
skuValue: z.number().optional(),
|
|
149
|
+
batchSize: z.number().optional(),
|
|
150
|
+
autoEndOnQuantityComplete: z.boolean().optional(),
|
|
151
|
+
|
|
152
|
+
cycleTime: z.number().optional(),
|
|
153
|
+
unitsPerMinute: z.number().optional(),
|
|
154
|
+
unitsPerHour: z.number().optional(),
|
|
155
|
+
lineSpeedTarget: z.number().optional(),
|
|
156
|
+
|
|
157
|
+
effectiveCycleTime: z.number().optional(),
|
|
158
|
+
effectiveUnitsPerMinute: z.number().optional(),
|
|
159
|
+
effectiveUnitsPerHour: z.number().optional(),
|
|
160
|
+
effectiveLineSpeedTarget: z.number().optional(),
|
|
161
|
+
effectiveBatchSize: z.number().optional(),
|
|
162
|
+
effectiveMinimumCycleTime: z.number().optional(),
|
|
163
|
+
|
|
164
|
+
deletedAt: z.string().optional(),
|
|
165
|
+
actualStartAt: z.string().optional(),
|
|
166
|
+
actualStartAtTimestamp: z.number().optional(),
|
|
167
|
+
actualEndAt: z.string().optional(),
|
|
168
|
+
actualEndAtTimestamp: z.number().optional(),
|
|
169
|
+
idealEndAt: z.string().optional(),
|
|
170
|
+
idealEndAtTimestamp: z.number().optional(),
|
|
171
|
+
quantityGood: z.number().optional(),
|
|
172
|
+
quantityBad: z.number().optional(),
|
|
173
|
+
quantityTotal: z.number().optional(),
|
|
174
|
+
skuGroupCode: z.string().optional(),
|
|
175
|
+
skuGroupName: z.string().optional(),
|
|
176
|
+
extendShift: z.boolean().optional(),
|
|
177
|
+
downtimeDurationThresholdMultiplier: z.number().optional(),
|
|
178
|
+
isStarted: z.boolean(),
|
|
179
|
+
isEnded: z.boolean(),
|
|
180
|
+
status: z.enum(["running", "planned", "deleted", "completed"]),
|
|
181
|
+
allowScheduleCutShort: z.boolean().optional(),
|
|
182
|
+
idealQuantity: z.number().optional(),
|
|
183
|
+
performanceModeFrom: z.enum(["schedule", "sku", "station", "none"]).optional(),
|
|
184
|
+
logs: z.array(z.string()).optional(),
|
|
185
|
+
priorityAt: z.string().optional(),
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
type ScheduleViewModel = z.infer<typeof ScheduleViewModel>;
|
|
189
|
+
|
|
190
|
+
declare const StationViewModel = z.object({
|
|
191
|
+
code: z.string(), // from station table
|
|
192
|
+
name: z.string(), // from station table
|
|
193
|
+
groupCode: z.string().nullish(), // from station table
|
|
194
|
+
groupName: z.string().nullish(), // from join with group table
|
|
195
|
+
allowScheduleStationFlexibility: z.boolean().nullish(), // from join with group table
|
|
196
|
+
plantCode: z.string(), // from station table
|
|
197
|
+
timezone: z.string(), // from join with plant table
|
|
198
|
+
accountId: z.string(), // from station table
|
|
199
|
+
currentOperatorInitials: z.string().nullish(), // from station table
|
|
200
|
+
|
|
201
|
+
cycleTime: z.number().nullish(), // from station table
|
|
202
|
+
unitsPerMinute: z.number().nullish(),
|
|
203
|
+
unitsPerHour: z.number().nullish(),
|
|
204
|
+
lineSpeedTarget: z.number().nullish(), // from station table
|
|
205
|
+
|
|
206
|
+
allowInterruptionMode: z.boolean().nullish(),
|
|
207
|
+
allowManualProduction: z.boolean().nullish(),
|
|
208
|
+
downtimeDetectionMode: z.nativeEnum(DOWNTIME_DETECTION_MODE), // from station table
|
|
209
|
+
utilisationDowntimeThreshold: z.number().nullish(), // from station table
|
|
210
|
+
slowDurationThreshold: z.number().nullish(), // from station table
|
|
211
|
+
electricalUsageStoppedThresholdKw: z.number().nullish(), // from station table
|
|
212
|
+
allowScheduleCutShort: z.boolean().nullish(), // from station table
|
|
213
|
+
productiveStatusMode: z.nativeEnum(PRODUCTIVE_STATUS_MODE), // from station table
|
|
214
|
+
lineSpeedStoppedThreshold: z.number().nullish(), // from station table
|
|
215
|
+
shiftPatternId: z.number().nullish(), // from station table
|
|
216
|
+
productiveHoldOnTime: z.number(), // from station table
|
|
217
|
+
minimumCycleTime: z.number().nullish(), // from station table
|
|
218
|
+
statusCode: z.string().nullish(), // from station table
|
|
219
|
+
statusCodeUpdatedAt: z.string().nullish(), // from station table
|
|
220
|
+
electricalPowerNominalKw: z.number().nullish(), // from station table
|
|
221
|
+
|
|
222
|
+
shiftPattern: ShiftPatternViewModel.optional(),
|
|
223
|
+
shifts: z.array(ShiftSchema), // from join with shift table. station.shiftPatternId or if null, stationGroup.shiftPatternId
|
|
224
|
+
|
|
225
|
+
currentShift: ShiftSchema.optional(), // the shift calculated to be in now. Null if not in any shift.
|
|
226
|
+
|
|
227
|
+
currentProductionSchedule: ProductionScheduleViewModel.nullish(), //The production schedule we are in for this station. null if no active production schedule.
|
|
228
|
+
nextProductionSchedule: ProductionScheduleViewModel.nullish(), //The production schedule that is next. null if no active production schedule.
|
|
229
|
+
|
|
230
|
+
currentNonProductionSchedule: NonProductionScheduleViewModel.nullish(), // The maintenance schedule we are in for this station. null if no active maintenance schedule.
|
|
231
|
+
|
|
232
|
+
currentStopReasonCode: z.string().nullish(), // The reason code for the 'stop' type issue that is ongoing for this station. unknown if no reason given. null if no ongoing 'stop' type issue.
|
|
233
|
+
stoppedSince: z.number().nullish(), // The startAt of the ongoing 'stop' type issue. null if no ongoing issue.
|
|
234
|
+
|
|
235
|
+
// TODO: Change this to stateCode. It doesn't match our API style to return the entire state object.
|
|
236
|
+
state: StationState,
|
|
237
|
+
idleCostPerMinute: z.number().nullish(),
|
|
238
|
+
moduleVisibility: z.array(z.nativeEnum(STATION_MODULE_VISIBILITY)).nullish(),
|
|
239
|
+
cachedAt: z.number().nullish(),
|
|
240
|
+
allowQuickScheduleStart: z.boolean().nullish(),
|
|
241
|
+
speedScale: z.number().nullish(),
|
|
242
|
+
speedOffset: z.number().nullish(),
|
|
243
|
+
speedToProductionRatio: z.number().nullish(),
|
|
244
|
+
|
|
245
|
+
forceAllShiftTimeAsPlannedProduction: z.boolean(), // This will cause any in shift time to be treated as planned production time for the sake of downtime detection and OEE.
|
|
246
|
+
|
|
247
|
+
lastStationWindow: StationWindowViewModel.nullish(),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
type StationViewModel = z.infer<typeof StationViewModel>;
|
|
251
|
+
|
|
252
|
+
declare const AccountViewModel = AccountSchema.merge(
|
|
253
|
+
z.object({
|
|
254
|
+
cursors: z
|
|
255
|
+
.array(
|
|
256
|
+
z.object({
|
|
257
|
+
type: z.string(),
|
|
258
|
+
timestamp: z.number(),
|
|
259
|
+
value: z.string(),
|
|
260
|
+
valueAgo: z.string(),
|
|
261
|
+
}),
|
|
262
|
+
)
|
|
263
|
+
.optional(),
|
|
264
|
+
redshiftConfig: z
|
|
265
|
+
.object({
|
|
266
|
+
host: z.string(),
|
|
267
|
+
port: z.number(),
|
|
268
|
+
username: z.string(),
|
|
269
|
+
})
|
|
270
|
+
.optional(),
|
|
271
|
+
}),
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
type AccountViewModel = z.infer<typeof AccountViewModel>;
|
|
275
|
+
|
|
276
|
+
export { AccountViewModel, PlantViewModel, ScheduleViewModel, SkuViewModel, StationSchema, StationViewModel };
|
|
277
|
+
export type { ApiKeyViewModel, BusrootSignals, PlantSchema };
|
package/build/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlantSchema, PlantViewModel, ScheduleViewModel, BusrootSignals, SkuViewModel, StationSchema, StationViewModel, AccountViewModel, ApiKeyViewModel } from "
|
|
1
|
+
import { PlantSchema, PlantViewModel, ScheduleViewModel, BusrootSignals, SkuViewModel, StationSchema, StationViewModel, AccountViewModel, ApiKeyViewModel } from "./busroot";
|
|
2
2
|
import mqtt from "mqtt/dist/mqtt.esm";
|
|
3
3
|
export declare const MqttEventType: {
|
|
4
4
|
StationMetricNew: string;
|
|
@@ -14,15 +14,18 @@ declare class Client {
|
|
|
14
14
|
config: {
|
|
15
15
|
accountId: string;
|
|
16
16
|
apiKey: string;
|
|
17
|
-
|
|
17
|
+
endpoint: string;
|
|
18
|
+
mqttHost?: string;
|
|
19
|
+
enableMqtt?: boolean;
|
|
18
20
|
};
|
|
19
|
-
mqttClient: mqtt.MqttClient;
|
|
21
|
+
mqttClient: mqtt.MqttClient | undefined;
|
|
20
22
|
listenersByEventType: Map<"StationMetricNew" | "StationChanged" | "ScheduleChanged" | "ScheduleStarted" | "ScheduleEnded" | "ProductionNew", Set<Listener>>;
|
|
21
|
-
apiUrl: string;
|
|
22
23
|
constructor(config: {
|
|
23
24
|
accountId: string;
|
|
24
25
|
apiKey: string;
|
|
25
|
-
|
|
26
|
+
endpoint: string;
|
|
27
|
+
mqttHost?: string;
|
|
28
|
+
enableMqtt?: boolean;
|
|
26
29
|
});
|
|
27
30
|
destroy(): void;
|
|
28
31
|
private get;
|
|
@@ -60,4 +63,3 @@ declare class Client {
|
|
|
60
63
|
off(event: MqttEventType, listener: Listener): void;
|
|
61
64
|
}
|
|
62
65
|
export { Client };
|
|
63
|
-
//# sourceMappingURL=client.d.ts.map
|
package/build/client.js
CHANGED
|
@@ -37,46 +37,50 @@ class Client {
|
|
|
37
37
|
return res.result;
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
for (const listener of listeners) {
|
|
55
|
-
try {
|
|
56
|
-
listener(JSON.parse(payload.toString()));
|
|
40
|
+
const trimmedAccountId = config.accountId.replace("account_", "");
|
|
41
|
+
if (config.enableMqtt === true && config.mqttHost !== null) {
|
|
42
|
+
this.mqttClient = mqtt_esm_1.default.connect({
|
|
43
|
+
host: config.mqttHost,
|
|
44
|
+
port: 8883,
|
|
45
|
+
username: "api-key",
|
|
46
|
+
password: this.config.apiKey,
|
|
47
|
+
clientId: trimmedAccountId + "/sdk",
|
|
48
|
+
});
|
|
49
|
+
this.mqttClient.on("message", (topic, payload) => {
|
|
50
|
+
const eventType = topic.toUpperCase().split("/").at(-1);
|
|
51
|
+
for (const [listenerEventType, listeners] of this.listenersByEventType) {
|
|
52
|
+
if (exports.MqttEventType[listenerEventType] !== eventType) {
|
|
53
|
+
continue;
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
for (const listener of listeners) {
|
|
56
|
+
try {
|
|
57
|
+
listener(JSON.parse(payload.toString()));
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
//
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
});
|
|
65
|
+
this.mqttClient.on("error", (error) => {
|
|
66
|
+
console.error(error);
|
|
67
|
+
});
|
|
68
|
+
this.mqttClient.on("connect", () => {
|
|
69
|
+
console.log("Connected to Busroot MQTT...");
|
|
70
|
+
});
|
|
71
|
+
this.mqttClient.on("reconnect", () => {
|
|
72
|
+
console.log("Disconnected from Busroot MQTT...");
|
|
73
|
+
});
|
|
74
|
+
this.mqttClient.subscribe(`busroot/v2/${trimmedAccountId}/events/#`);
|
|
75
|
+
}
|
|
74
76
|
}
|
|
75
77
|
destroy() {
|
|
76
|
-
this.mqttClient
|
|
78
|
+
if (this.mqttClient != null) {
|
|
79
|
+
this.mqttClient.end();
|
|
80
|
+
}
|
|
77
81
|
}
|
|
78
82
|
async get(path, query) {
|
|
79
|
-
let url = this.
|
|
83
|
+
let url = this.config.endpoint + path;
|
|
80
84
|
if (query != null) {
|
|
81
85
|
url +=
|
|
82
86
|
"?" +
|
|
@@ -95,7 +99,7 @@ class Client {
|
|
|
95
99
|
return resJson;
|
|
96
100
|
}
|
|
97
101
|
async post(path, body) {
|
|
98
|
-
const res = await fetch(this.
|
|
102
|
+
const res = await fetch(this.config.endpoint + path, {
|
|
99
103
|
headers: { "x-api-key": this.config.apiKey, "Content-Type": "application/json" },
|
|
100
104
|
method: "POST",
|
|
101
105
|
body: JSON.stringify(body),
|
package/build/client.test.d.ts
CHANGED
package/build/hooks.d.ts
CHANGED
|
@@ -3,18 +3,22 @@ import z from "zod";
|
|
|
3
3
|
export declare const ConfigPayloadSchema: z.ZodObject<{
|
|
4
4
|
accountId: z.ZodString;
|
|
5
5
|
apiKey: z.ZodString;
|
|
6
|
-
|
|
6
|
+
endpoint: z.ZodString;
|
|
7
|
+
mqttHost: z.ZodString;
|
|
7
8
|
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
host: string;
|
|
9
9
|
accountId: string;
|
|
10
10
|
apiKey: string;
|
|
11
|
+
endpoint: string;
|
|
12
|
+
mqttHost: string;
|
|
11
13
|
}, {
|
|
12
|
-
host: string;
|
|
13
14
|
accountId: string;
|
|
14
15
|
apiKey: string;
|
|
16
|
+
endpoint: string;
|
|
17
|
+
mqttHost: string;
|
|
15
18
|
}>;
|
|
16
|
-
export declare function useBusroot(
|
|
19
|
+
export declare function useBusroot(props?: {
|
|
20
|
+
enableMqtt?: boolean;
|
|
21
|
+
}): {
|
|
17
22
|
client: Client | undefined;
|
|
18
23
|
logout: () => void;
|
|
19
24
|
};
|
|
20
|
-
//# sourceMappingURL=hooks.d.ts.map
|
package/build/hooks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use client";
|
|
2
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
5
|
};
|
|
@@ -8,14 +9,17 @@ exports.useBusroot = useBusroot;
|
|
|
8
9
|
const react_1 = require("react");
|
|
9
10
|
const client_1 = require("./client");
|
|
10
11
|
const zod_1 = __importDefault(require("zod"));
|
|
12
|
+
// 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.
|
|
11
13
|
// TODO: Account ID and API key should be saved to a local cookie and removed from the query param.
|
|
12
14
|
// TODO: Add logout functionality, that clears the cookies.
|
|
13
15
|
exports.ConfigPayloadSchema = zod_1.default.object({
|
|
14
16
|
accountId: zod_1.default.string().max(255),
|
|
15
17
|
apiKey: zod_1.default.string().max(255),
|
|
16
|
-
|
|
18
|
+
endpoint: zod_1.default.string().max(255),
|
|
19
|
+
mqttHost: zod_1.default.string().max(255),
|
|
17
20
|
});
|
|
18
|
-
function useBusroot() {
|
|
21
|
+
function useBusroot(props) {
|
|
22
|
+
const enableMqtt = props && props.enableMqtt;
|
|
19
23
|
const [client, setClient] = (0, react_1.useState)();
|
|
20
24
|
(0, react_1.useEffect)(() => {
|
|
21
25
|
if (typeof window === undefined) {
|
|
@@ -26,7 +30,13 @@ function useBusroot() {
|
|
|
26
30
|
if (tokenParam != null && client == null) {
|
|
27
31
|
try {
|
|
28
32
|
const config = exports.ConfigPayloadSchema.parse(JSON.parse(atob(tokenParam)));
|
|
29
|
-
setClient(new client_1.Client({
|
|
33
|
+
setClient(new client_1.Client({
|
|
34
|
+
accountId: config.accountId,
|
|
35
|
+
apiKey: config.apiKey,
|
|
36
|
+
endpoint: config.endpoint,
|
|
37
|
+
mqttHost: config.mqttHost,
|
|
38
|
+
enableMqtt,
|
|
39
|
+
}));
|
|
30
40
|
}
|
|
31
41
|
catch (e) {
|
|
32
42
|
console.log(e.message);
|
package/build/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "busroot-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "An SDK for accessing Busroot.",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "An SDK for accessing Busroot from output.industries",
|
|
5
5
|
"homepage": "https://www.output.industries",
|
|
6
6
|
"main": "./build/index.js",
|
|
7
7
|
"types": "./build/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"example": "ts-node -r dotenv-expand/config ./src/example.ts",
|
|
11
11
|
"dev": "pnpm run lint && tsc -b --watch",
|
|
12
|
-
"build": "pnpm
|
|
12
|
+
"build": "pnpm run lint && tsc --build --clean && tsc --build && pnpm run rollup",
|
|
13
13
|
"lint": "eslint 'src/**/*.ts'",
|
|
14
14
|
"test": "jest",
|
|
15
15
|
"rollup": "rollup -c"
|
package/build/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,EAChB,MAAM,iBAAiB,CAAC;AACzB,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,cAAM,MAAM;IAKS,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAJ9E,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC;IAC5B,oBAAoB,wIAAwD;IAC5E,MAAM,EAAE,MAAM,CAAC;gBAEI,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IA4C9E,OAAO;YAIO,GAAG;YAyBH,IAAI;IAYlB,IAAI,OAAO;;MAQV;IAED,IAAI,OAAO;yBAEgB,MAAM,aAAa,MAAM,KAAG,OAAO,CAAC;YAAE,OAAO,EAAE,gBAAgB,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC;MAM5G;IAED,IAAI,MAAM;sBAEY,OAAO,CAAC,eAAe,CAAC;MAM7C;IAED,IAAI,KAAK;yBAEkB,MAAM,KAAG,OAAO,CAAC,cAAc,CAAC;gCAKzB,OAAO,CAAC,WAAW,CAAC,KAAG,OAAO,CAAC,cAAc,CAAC;MAM/E;IAED,IAAI,OAAO;2BAEkB,MAAM,KAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;gCAK/B,OAAO,CAAC,aAAa,CAAC,KAAG,OAAO,CAAC,gBAAgB,CAAC;8BAK1D,MAAM,WAAW,cAAc,KAAG,IAAI;MAI/D;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,MAAM,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../src/client.test.ts"],"names":[],"mappings":""}
|