create-anywherescada-app 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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "create-anywherescada-app",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Create a SvelteKit app connected to AnywhereScada",
5
5
  "type": "module",
6
6
  "bin": {
7
- "create-anywherescada-app": "./dist/index.js"
7
+ "create-anywherescada-app": "dist/index.js"
8
8
  },
9
9
  "files": [
10
10
  "dist",
@@ -22,6 +22,10 @@
22
22
  "iot",
23
23
  "sparkplug"
24
24
  ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/joyautomation/create-anywherescada-app"
28
+ },
25
29
  "author": "Joy Automation",
26
30
  "license": "MIT",
27
31
  "devDependencies": {
@@ -22,6 +22,7 @@
22
22
  "dependencies": {
23
23
  "@fontsource/space-grotesk": "^5.2.8",
24
24
  "@joyautomation/salt": "^0.0.21",
25
+ "graphql": "^16.9.0",
25
26
  "graphql-ws": "^6.0.0",
26
27
  "sass": "^1.89.0",
27
28
  "ws": "^8.19.0"
@@ -61,9 +61,9 @@
61
61
 
62
62
  const eventSource = new EventSource('/api/subscribe');
63
63
 
64
- eventSource.onopen = () => {
64
+ eventSource.addEventListener('connected', () => {
65
65
  connected = true;
66
- };
66
+ });
67
67
 
68
68
  eventSource.addEventListener('metricUpdate', (event) => {
69
69
  const updates: MetricUpdate[] = JSON.parse(event.data);
@@ -15,6 +15,9 @@ export const GET: RequestHandler = () => {
15
15
  start(controller) {
16
16
  const encoder = new TextEncoder();
17
17
 
18
+ // Send initial event so EventSource fires onopen
19
+ controller.enqueue(encoder.encode('event: connected\ndata: true\n\n'));
20
+
18
21
  const client = createClient({
19
22
  url: `wss://api.anywherescada.com/graphql?token=${ANYWHERESCADA_API_KEY}`,
20
23
  webSocketImpl: WebSocket
@@ -26,11 +29,14 @@ export const GET: RequestHandler = () => {
26
29
  next: (result) => {
27
30
  if (result.data?.metricUpdate) {
28
31
  const data = `event: metricUpdate\ndata: ${JSON.stringify(result.data.metricUpdate)}\n\n`;
29
- controller.enqueue(encoder.encode(data));
32
+ try {
33
+ controller.enqueue(encoder.encode(data));
34
+ } catch {
35
+ // Stream already closed
36
+ }
30
37
  }
31
38
  },
32
- error: (err) => {
33
- console.error('Subscription error:', err);
39
+ error: () => {
34
40
  try {
35
41
  controller.close();
36
42
  } catch {