create-glanceway-source 1.0.0 → 1.2.0
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/README.md +77 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +580 -141
- package/package.json +19 -21
- package/templates/gitignore +24 -0
- package/templates/scripts/build.ts +103 -0
- package/templates/scripts/test.ts +475 -0
- package/{template → templates}/src/types.ts +24 -15
- package/{template → templates}/tsconfig.json +2 -3
- package/template/manifest.yaml.ejs +0 -6
- package/template/package.json.ejs +0 -14
- package/template/src/index.ts +0 -9
|
@@ -3,24 +3,27 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The main API object passed to your source function.
|
|
5
5
|
*/
|
|
6
|
-
export interface GlancewayAPI {
|
|
6
|
+
export interface GlancewayAPI<TConfig extends Record<string, unknown> = Record<string, unknown>> {
|
|
7
7
|
/** Send information items to Glanceway for display */
|
|
8
8
|
emit(items: InfoItem[]): void;
|
|
9
9
|
|
|
10
10
|
/** Make HTTP requests */
|
|
11
|
-
fetch(url: string, options?: FetchOptions): Promise<FetchResponse
|
|
11
|
+
fetch<T>(url: string, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
12
12
|
|
|
13
13
|
/** Log messages for debugging */
|
|
14
|
-
log(level:
|
|
14
|
+
log(level: "info" | "error" | "warn" | "debug", message: string): void;
|
|
15
15
|
|
|
16
16
|
/** Persistent key-value storage */
|
|
17
17
|
storage: StorageAPI;
|
|
18
18
|
|
|
19
19
|
/** Access user-configured values */
|
|
20
|
-
config: ConfigAPI
|
|
20
|
+
config: ConfigAPI<TConfig>;
|
|
21
21
|
|
|
22
22
|
/** Create WebSocket connections */
|
|
23
23
|
websocket: WebSocketAPI;
|
|
24
|
+
|
|
25
|
+
/** Current Glanceway app version */
|
|
26
|
+
appVersion: string;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/**
|
|
@@ -28,7 +31,7 @@ export interface GlancewayAPI {
|
|
|
28
31
|
*/
|
|
29
32
|
export interface InfoItem {
|
|
30
33
|
/** Unique identifier for the item */
|
|
31
|
-
id: string
|
|
34
|
+
id: string;
|
|
32
35
|
|
|
33
36
|
/** Main display text */
|
|
34
37
|
title: string;
|
|
@@ -48,7 +51,7 @@ export interface InfoItem {
|
|
|
48
51
|
*/
|
|
49
52
|
export interface FetchOptions {
|
|
50
53
|
/** HTTP method (default: GET) */
|
|
51
|
-
method?:
|
|
54
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
52
55
|
|
|
53
56
|
/** Request headers */
|
|
54
57
|
headers?: Record<string, string>;
|
|
@@ -63,7 +66,7 @@ export interface FetchOptions {
|
|
|
63
66
|
/**
|
|
64
67
|
* HTTP response
|
|
65
68
|
*/
|
|
66
|
-
export interface FetchResponse {
|
|
69
|
+
export interface FetchResponse<T> {
|
|
67
70
|
/** True if status code is 200-299 */
|
|
68
71
|
ok: boolean;
|
|
69
72
|
|
|
@@ -77,7 +80,10 @@ export interface FetchResponse {
|
|
|
77
80
|
text: string;
|
|
78
81
|
|
|
79
82
|
/** Parsed JSON (if response is valid JSON) */
|
|
80
|
-
json?:
|
|
83
|
+
json?: T;
|
|
84
|
+
|
|
85
|
+
/** Error message if request failed */
|
|
86
|
+
error?: string;
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
/**
|
|
@@ -87,10 +93,10 @@ export interface FetchResponse {
|
|
|
87
93
|
*/
|
|
88
94
|
export interface StorageAPI {
|
|
89
95
|
/** Get a stored value */
|
|
90
|
-
get(key: string):
|
|
96
|
+
get(key: string): string | undefined;
|
|
91
97
|
|
|
92
98
|
/** Store a value */
|
|
93
|
-
set(key: string, value:
|
|
99
|
+
set(key: string, value: string): void;
|
|
94
100
|
}
|
|
95
101
|
|
|
96
102
|
/**
|
|
@@ -98,12 +104,12 @@ export interface StorageAPI {
|
|
|
98
104
|
*
|
|
99
105
|
* Access user-configured values defined in manifest.yaml.
|
|
100
106
|
*/
|
|
101
|
-
export interface ConfigAPI {
|
|
107
|
+
export interface ConfigAPI<TConfig extends Record<string, unknown> = Record<string, unknown>> {
|
|
102
108
|
/** Get a config value by key */
|
|
103
|
-
get(key:
|
|
109
|
+
get<K extends keyof TConfig>(key: K): TConfig[K];
|
|
104
110
|
|
|
105
111
|
/** Get all config values */
|
|
106
|
-
getAll():
|
|
112
|
+
getAll(): TConfig;
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
/**
|
|
@@ -111,7 +117,10 @@ export interface ConfigAPI {
|
|
|
111
117
|
*/
|
|
112
118
|
export interface WebSocketAPI {
|
|
113
119
|
/** Connect to a WebSocket server */
|
|
114
|
-
connect(
|
|
120
|
+
connect(
|
|
121
|
+
url: string,
|
|
122
|
+
callbacks: WebSocketCallbacks,
|
|
123
|
+
): Promise<WebSocketConnection>;
|
|
115
124
|
}
|
|
116
125
|
|
|
117
126
|
/**
|
|
@@ -146,7 +155,7 @@ export interface WebSocketConnection {
|
|
|
146
155
|
* Source methods returned by your source function
|
|
147
156
|
*/
|
|
148
157
|
export interface SourceMethods {
|
|
149
|
-
/** Called
|
|
158
|
+
/** Called periodically based on user settings (NOT called on initial load) */
|
|
150
159
|
refresh?: () => Promise<void> | void;
|
|
151
160
|
|
|
152
161
|
/** Called when source is stopped (for cleanup) */
|
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
"skipLibCheck": true,
|
|
9
9
|
"forceConsistentCasingInFileNames": true,
|
|
10
10
|
"outDir": "dist",
|
|
11
|
-
"rootDir": "
|
|
12
|
-
"declaration": false
|
|
11
|
+
"rootDir": "."
|
|
13
12
|
},
|
|
14
|
-
"include": ["src/**/*"],
|
|
13
|
+
"include": ["src/**/*", "scripts/**/*"],
|
|
15
14
|
"exclude": ["node_modules", "dist"]
|
|
16
15
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "<%= name %>",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "<%= description %>",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.js && cp manifest.yaml dist/",
|
|
7
|
-
"dev": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.js --watch"
|
|
8
|
-
},
|
|
9
|
-
"devDependencies": {
|
|
10
|
-
"@types/node": "^20.10.0",
|
|
11
|
-
"esbuild": "^0.19.0",
|
|
12
|
-
"typescript": "^5.3.3"
|
|
13
|
-
}
|
|
14
|
-
}
|