@zaflun/lumio-sdk 0.2.0 → 0.3.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/dist/index.d.ts +1 -1
- package/dist/lumio-runtime.global.js +773 -1476
- package/dist/server.d.ts +86 -1
- package/dist/server.js +43 -0
- package/package.json +2 -2
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LumioEventType } from '@zaflun/lumio-protocol';
|
|
2
|
+
|
|
1
3
|
interface Validator {
|
|
2
4
|
type: string;
|
|
3
5
|
isOptional: boolean;
|
|
@@ -135,4 +137,87 @@ declare function filter(field: string, op: string, value: unknown): {
|
|
|
135
137
|
value: unknown;
|
|
136
138
|
};
|
|
137
139
|
|
|
138
|
-
|
|
140
|
+
interface BotModuleContext {
|
|
141
|
+
auth: {
|
|
142
|
+
userId: string | null;
|
|
143
|
+
accountId: string | null;
|
|
144
|
+
role: string;
|
|
145
|
+
};
|
|
146
|
+
user: {
|
|
147
|
+
id: string;
|
|
148
|
+
name: string;
|
|
149
|
+
displayName: string;
|
|
150
|
+
platform: string;
|
|
151
|
+
role: string;
|
|
152
|
+
isMod: boolean;
|
|
153
|
+
isVip: boolean;
|
|
154
|
+
isSub: boolean;
|
|
155
|
+
} | null;
|
|
156
|
+
config: Record<string, unknown>;
|
|
157
|
+
db: {
|
|
158
|
+
get: (table: string, id: string) => Promise<Record<string, unknown> | null>;
|
|
159
|
+
list: (table: string) => Promise<Record<string, unknown>[]>;
|
|
160
|
+
insert: (table: string, row: Record<string, unknown>) => Promise<string>;
|
|
161
|
+
patch: (table: string, id: string, row: Record<string, unknown>) => Promise<void>;
|
|
162
|
+
delete: (table: string, id: string) => Promise<void>;
|
|
163
|
+
};
|
|
164
|
+
cache: {
|
|
165
|
+
get: (key: string) => Promise<unknown | null>;
|
|
166
|
+
set: (key: string, value: unknown, ttl?: number) => Promise<void>;
|
|
167
|
+
delete: (key: string) => Promise<void>;
|
|
168
|
+
increment: (key: string, by?: number) => Promise<number>;
|
|
169
|
+
};
|
|
170
|
+
secrets: {
|
|
171
|
+
get: (key: string) => Promise<string | null>;
|
|
172
|
+
};
|
|
173
|
+
fetch: (url: string, options?: RequestInit) => Promise<Response>;
|
|
174
|
+
defer: (fn: () => Promise<void>) => void;
|
|
175
|
+
}
|
|
176
|
+
interface HandlerResponse {
|
|
177
|
+
reply?: string;
|
|
178
|
+
actions?: Array<{
|
|
179
|
+
action: string;
|
|
180
|
+
params: Record<string, unknown>;
|
|
181
|
+
}>;
|
|
182
|
+
}
|
|
183
|
+
interface ModerationResponse {
|
|
184
|
+
block: boolean;
|
|
185
|
+
action?: "delete" | "timeout" | "ban";
|
|
186
|
+
duration?: number;
|
|
187
|
+
reason?: string;
|
|
188
|
+
}
|
|
189
|
+
interface ChatMessage {
|
|
190
|
+
text: string;
|
|
191
|
+
platformMessageId: string;
|
|
192
|
+
}
|
|
193
|
+
type CommandHandler = (ctx: BotModuleContext, args: string[]) => Promise<HandlerResponse | null>;
|
|
194
|
+
type KeywordHandler = (ctx: BotModuleContext, message: ChatMessage) => Promise<HandlerResponse | null>;
|
|
195
|
+
type PatternHandler = (ctx: BotModuleContext, message: ChatMessage, matched: string) => Promise<HandlerResponse | null>;
|
|
196
|
+
type EventHandler = (ctx: BotModuleContext, event: Record<string, unknown>) => Promise<HandlerResponse | null>;
|
|
197
|
+
type TimerHandler = (ctx: BotModuleContext) => Promise<HandlerResponse | null>;
|
|
198
|
+
type ModerateHandler = (ctx: BotModuleContext, message: ChatMessage) => Promise<ModerationResponse>;
|
|
199
|
+
declare function command(name: string, handler: CommandHandler): CommandHandler & {
|
|
200
|
+
__type: string;
|
|
201
|
+
__trigger: string;
|
|
202
|
+
};
|
|
203
|
+
declare function keyword(trigger: string, handler: KeywordHandler): KeywordHandler & {
|
|
204
|
+
__type: string;
|
|
205
|
+
__trigger: string;
|
|
206
|
+
};
|
|
207
|
+
declare function pattern(regex: string, handler: PatternHandler): PatternHandler & {
|
|
208
|
+
__type: string;
|
|
209
|
+
__trigger: string;
|
|
210
|
+
};
|
|
211
|
+
declare function event(eventType: LumioEventType | string, handler: EventHandler): EventHandler & {
|
|
212
|
+
__type: string;
|
|
213
|
+
__trigger: string;
|
|
214
|
+
};
|
|
215
|
+
declare function timer(name: string, handler: TimerHandler): TimerHandler & {
|
|
216
|
+
__type: string;
|
|
217
|
+
__trigger: string;
|
|
218
|
+
};
|
|
219
|
+
declare function moderate(handler: ModerateHandler): ModerateHandler & {
|
|
220
|
+
__type: string;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export { type ActionDefinition, type BotModuleContext, type ChatMessage, type DeleteRowDefinition, type DeleteRowOptions, type FetchActionDefinition, type FetchActionOptions, type HandlerConfig, type HandlerContext, type HandlerResponse, type InsertRowDefinition, type InsertRowOptions, type ModerationResponse, type MutationDefinition, type PatchRowDefinition, type PatchRowOptions, type QueryDefinition, type QueryRowsDefinition, type SchemaDefinition, type TableDefinition, type Validator, action, arg, command, defineSchema, defineTable, deleteRow, event, fetchAction, filter, identity, insertRow, keyword, moderate, mutation, patchRow, pattern, query, queryRows, secret, timer, v };
|
package/dist/server.js
CHANGED
|
@@ -112,20 +112,63 @@ function secret(name) {
|
|
|
112
112
|
function filter(field, op, value) {
|
|
113
113
|
return { __expr: "filter", field, op, value };
|
|
114
114
|
}
|
|
115
|
+
|
|
116
|
+
// src/server/bot-module.ts
|
|
117
|
+
function command(name, handler) {
|
|
118
|
+
const fn = handler;
|
|
119
|
+
fn.__type = "command";
|
|
120
|
+
fn.__trigger = name;
|
|
121
|
+
return fn;
|
|
122
|
+
}
|
|
123
|
+
function keyword(trigger, handler) {
|
|
124
|
+
const fn = handler;
|
|
125
|
+
fn.__type = "keyword";
|
|
126
|
+
fn.__trigger = trigger;
|
|
127
|
+
return fn;
|
|
128
|
+
}
|
|
129
|
+
function pattern(regex, handler) {
|
|
130
|
+
const fn = handler;
|
|
131
|
+
fn.__type = "pattern";
|
|
132
|
+
fn.__trigger = regex;
|
|
133
|
+
return fn;
|
|
134
|
+
}
|
|
135
|
+
function event(eventType, handler) {
|
|
136
|
+
const fn = handler;
|
|
137
|
+
fn.__type = "event";
|
|
138
|
+
fn.__trigger = eventType;
|
|
139
|
+
return fn;
|
|
140
|
+
}
|
|
141
|
+
function timer(name, handler) {
|
|
142
|
+
const fn = handler;
|
|
143
|
+
fn.__type = "timer";
|
|
144
|
+
fn.__trigger = name;
|
|
145
|
+
return fn;
|
|
146
|
+
}
|
|
147
|
+
function moderate(handler) {
|
|
148
|
+
const fn = handler;
|
|
149
|
+
fn.__type = "moderate";
|
|
150
|
+
return fn;
|
|
151
|
+
}
|
|
115
152
|
export {
|
|
116
153
|
action,
|
|
117
154
|
arg,
|
|
155
|
+
command,
|
|
118
156
|
defineSchema,
|
|
119
157
|
defineTable,
|
|
120
158
|
deleteRow,
|
|
159
|
+
event,
|
|
121
160
|
fetchAction,
|
|
122
161
|
filter,
|
|
123
162
|
identity,
|
|
124
163
|
insertRow,
|
|
164
|
+
keyword,
|
|
165
|
+
moderate,
|
|
125
166
|
mutation,
|
|
126
167
|
patchRow,
|
|
168
|
+
pattern,
|
|
127
169
|
query,
|
|
128
170
|
queryRows,
|
|
129
171
|
secret,
|
|
172
|
+
timer,
|
|
130
173
|
v
|
|
131
174
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zaflun/lumio-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Lumio Extension SDK — React components, hooks, and server utilities for building Lumio extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"react-reconciler": "^0.32.0",
|
|
26
|
-
"@zaflun/lumio-extension-types": "0.
|
|
26
|
+
"@zaflun/lumio-extension-types": "0.3.0",
|
|
27
27
|
"@zaflun/lumio-protocol": "0.1.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|