@jchat/addon-sdk 1.0.0-alpha.2 → 1.0.0-alpha.21
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/CHANGELOG.md +132 -0
- package/LICENSE +18 -196
- package/README.md +385 -20
- package/dist/cli.d.mts +35 -0
- package/dist/cli.mjs +136 -0
- package/dist/contracts.d.mts +43 -31
- package/dist/contracts.mjs +40 -0
- package/dist/diagnostics.d.mts +55 -9
- package/dist/diagnostics.mjs +66 -1
- package/dist/i18n-validator.d.mts +17 -0
- package/dist/i18n-validator.mjs +90 -0
- package/dist/i18n.mjs +191 -0
- package/dist/icon.d.mts +4 -0
- package/dist/icon.mjs +4 -0
- package/dist/index.d.mts +16 -253
- package/dist/index.mjs +131 -43
- package/dist/index2.d.mts +601 -0
- package/dist/state.d.mts +1 -0
- package/dist/state.mjs +2 -0
- package/dist/types.d.mts +12 -0
- package/dist/ui.d.mts +1 -0
- package/dist/ui.mjs +2 -0
- package/dist/vite.d.mts +64 -10
- package/dist/vite.mjs +227 -34
- package/package.json +119 -17
- package/skills/create-jchat-addon/SKILL.md +140 -0
- package/skills/jchat-addon-development/SKILL.md +260 -0
- package/tsconfig.addon.json +20 -0
- package/src/contracts.d.ts +0 -127
- package/src/contracts.ts +0 -132
- package/src/diagnostics.d.ts +0 -19
- package/src/diagnostics.test.ts +0 -106
- package/src/diagnostics.ts +0 -182
- package/src/index.d.ts +0 -249
- package/src/index.test.ts +0 -35
- package/src/index.ts +0 -299
- package/src/vite.test.ts +0 -62
- package/src/vite.ts +0 -289
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
import { i as IconPack, n as IconComponent, r as IconName } from "./types.mjs";
|
|
2
|
+
import { AddonCommandDefinition, AddonCommandParameter, AddonManifest, AddonPermissionDefinition, MOUNT_POINTS, MountPoint } from "./contracts.mjs";
|
|
3
|
+
import { InfiniteData, MutationFunction, QueryFunction, QueryFunctionContext, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryResult, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { Elysia, t } from "elysia";
|
|
5
|
+
import { ColumnType, Generated, Insertable, JSONColumnType, Kysely, Selectable, Updateable } from "kysely";
|
|
6
|
+
//#region src/i18n.d.ts
|
|
7
|
+
export declare const HOST_LANGUAGES: readonly ["ar", "bg", "hr", "de", "el", "en", "es", "fr", "he", "hi", "kn", "ml", "nl", "pt", "ro", "ru", "ta", "te", "tr", "ur"];
|
|
8
|
+
export type HostLanguage = (typeof HOST_LANGUAGES)[number];
|
|
9
|
+
export type AddonTranslationDictionary = Record<string, unknown>;
|
|
10
|
+
export type AddonTranslationResources = Record<string, AddonTranslationDictionary>;
|
|
11
|
+
export type AddonLocaleLoader = (locale: string) => Promise<AddonTranslationDictionary> | AddonTranslationDictionary;
|
|
12
|
+
export interface LocaleContextValue {
|
|
13
|
+
locale: string;
|
|
14
|
+
dir: "ltr" | "rtl";
|
|
15
|
+
}
|
|
16
|
+
export declare const LocaleContext: import("react").Context<LocaleContextValue>;
|
|
17
|
+
export interface TranslatorOptions {
|
|
18
|
+
resources?: AddonTranslationResources;
|
|
19
|
+
defaultLocale?: string;
|
|
20
|
+
fallbackLocale?: string;
|
|
21
|
+
}
|
|
22
|
+
export type TranslateFunction<TKeys extends string = string> = (key: TKeys | (string & {}), paramsOrLang?: Record<string, unknown> | string, maybeLang?: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a standalone translation function for backend server routes (`src/api.ts`) or utilities.
|
|
25
|
+
*
|
|
26
|
+
* @param resources - Dictionary of translation resources (e.g., `{ en: enJson, ta: taJson }`).
|
|
27
|
+
* @param defaultLocale - Default locale to use if not specified per call (defaults to "en").
|
|
28
|
+
* @param fallbackLocale - Fallback locale if a key is missing in the target language (defaults to
|
|
29
|
+
* "en").
|
|
30
|
+
*/
|
|
31
|
+
export declare function createTranslator<TResources extends AddonTranslationResources = AddonTranslationResources>(resources?: TResources, defaultLocale?: string, fallbackLocale?: string): TranslateFunction<TResources extends {
|
|
32
|
+
en: infer TEn;
|
|
33
|
+
} ? TEn extends Record<string, unknown> ? Extract<keyof TEn, string> : string : string>;
|
|
34
|
+
/**
|
|
35
|
+
* Hook to access the current active host locale and text direction in an addon component.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ;```tsx
|
|
39
|
+
* import { useLocale } from "@jchat/addon-sdk"
|
|
40
|
+
*
|
|
41
|
+
* export default function MyAddon() {
|
|
42
|
+
* const { locale, dir, isRtl } = useLocale()
|
|
43
|
+
* return <div dir={dir}>Current language: {locale}</div>
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function useLocale(): {
|
|
48
|
+
locale: string;
|
|
49
|
+
dir: "ltr" | "rtl";
|
|
50
|
+
isRtl: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Hook to access translation function and locale metadata inside addon components. Automatically
|
|
54
|
+
* synchronizes with host language switches and falls back to English. Supports static dictionary
|
|
55
|
+
* resources or dynamic async locale loaders.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ;```tsx
|
|
59
|
+
* import { useTranslation } from "@jchat/addon-sdk"
|
|
60
|
+
* import locales from "./locales"
|
|
61
|
+
*
|
|
62
|
+
* export default function MyAddon() {
|
|
63
|
+
* const { t, locale, dir } = useTranslation(locales)
|
|
64
|
+
* return (
|
|
65
|
+
* <div dir={dir}>
|
|
66
|
+
* <h1>{t("welcome", { name: "Guest" })}</h1>
|
|
67
|
+
* </div>
|
|
68
|
+
* )
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param resourcesOrLoader - Addon-scoped translation dictionaries or async chunk loader.
|
|
73
|
+
* @param fallbackLocale - Fallback language code when a string is missing (default: "en").
|
|
74
|
+
*/
|
|
75
|
+
export declare function useTranslation<TResources extends AddonTranslationResources | AddonLocaleLoader = AddonTranslationResources>(resourcesOrLoader?: TResources, fallbackLocale?: string): {
|
|
76
|
+
t: TranslateFunction<TResources extends {
|
|
77
|
+
en: infer TEn;
|
|
78
|
+
} ? TEn extends Record<string, unknown> ? Extract<keyof TEn, string> : string : string>;
|
|
79
|
+
locale: string;
|
|
80
|
+
dir: "ltr" | "rtl";
|
|
81
|
+
isRtl: boolean;
|
|
82
|
+
isReady: boolean;
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/query.d.ts
|
|
86
|
+
export interface UseAddonQueryOptions<TData = unknown, TError = Error> extends Omit<UndefinedInitialDataOptions<TData, TError, TData, QueryKey>, "queryKey" | "queryFn"> {
|
|
87
|
+
/** The API path to fetch, automatically prefixed with `/api/v1/addons/<addonId>` */
|
|
88
|
+
path?: string;
|
|
89
|
+
/** Custom query key elements appended to the automatic path cache key */
|
|
90
|
+
queryKey?: QueryKey;
|
|
91
|
+
/** Custom query function override */
|
|
92
|
+
queryFn?: QueryFunction<TData, QueryKey>;
|
|
93
|
+
}
|
|
94
|
+
export interface UseAddonMutationOptions<TData = unknown, TVariables = unknown, TError = Error, TContext = unknown> extends Omit<UseMutationOptions<TData, TError, TVariables, TContext>, "mutationFn"> {
|
|
95
|
+
/** The target API path, or a dynamic function of mutation variables */
|
|
96
|
+
path?: string | ((variables: TVariables) => string);
|
|
97
|
+
/** HTTP method to use (defaults to 'POST') */
|
|
98
|
+
method?: "POST" | "PUT" | "DELETE";
|
|
99
|
+
/** Query keys to automatically invalidate upon successful mutation */
|
|
100
|
+
invalidateQueries?: QueryKey[];
|
|
101
|
+
/** Custom mutation function override */
|
|
102
|
+
mutationFn?: MutationFunction<TData, TVariables>;
|
|
103
|
+
}
|
|
104
|
+
export interface UseAddonInfiniteQueryOptions<TData = unknown, TError = Error, TPageParam = unknown> extends Omit<UndefinedInitialDataInfiniteOptions<TData, TError, InfiniteData<TData, TPageParam>, QueryKey, TPageParam>, "queryKey" | "queryFn"> {
|
|
105
|
+
/** The API path to fetch, or a dynamic function that receives pageParam and returns the path */
|
|
106
|
+
path?: string | ((pageParam: TPageParam) => string);
|
|
107
|
+
/** Custom query key elements appended to the automatic cache key */
|
|
108
|
+
queryKey?: QueryKey;
|
|
109
|
+
/** Custom query function override */
|
|
110
|
+
queryFn?: (context: QueryFunctionContext<QueryKey, TPageParam>) => Promise<TData>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Perform a declarative, cached GET request using the host's shared React Query instance.
|
|
114
|
+
* Automatically injects authentication headers and prefixes addon paths.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ;```tsx
|
|
118
|
+
* const { data, isLoading } = useAddonQuery<{ polls: Poll[] }>({
|
|
119
|
+
* path: "/polls",
|
|
120
|
+
* queryKey: [siteId]
|
|
121
|
+
* })
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function useAddonQuery<TData = unknown, TError = Error>(options: UseAddonQueryOptions<TData, TError>): UseQueryResult<TData, TError>;
|
|
125
|
+
/**
|
|
126
|
+
* Perform a paginated or infinite scrolling request using the host's shared React Query instance.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ;```tsx
|
|
130
|
+
* const { data, fetchNextPage, hasNextPage } = useAddonInfiniteQuery<GifResponse, Error, number>({
|
|
131
|
+
* path: (page) => `/trending?offset=${page * 20}`,
|
|
132
|
+
* initialPageParam: 0,
|
|
133
|
+
* getNextPageParam: (lastPage, allPages) => (lastPage.hasMore ? allPages.length : undefined)
|
|
134
|
+
* })
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function useAddonInfiniteQuery<TData = unknown, TError = Error, TPageParam = unknown>(options: UseAddonInfiniteQueryOptions<TData, TError, TPageParam>): UseInfiniteQueryResult<InfiniteData<TData, TPageParam>, TError>;
|
|
138
|
+
/**
|
|
139
|
+
* Perform a declarative mutation using the host's shared React Query instance. Automatically
|
|
140
|
+
* executes the request and can invalidate specified query keys upon success.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ;```tsx
|
|
144
|
+
* const { mutate, isPending } = useAddonMutation<Poll, CreatePollInput>({
|
|
145
|
+
* path: "/polls",
|
|
146
|
+
* method: "POST",
|
|
147
|
+
* invalidateQueries: [["/polls"]],
|
|
148
|
+
* onSuccess: () => sdk.toast("Poll created!", "success")
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function useAddonMutation<TData = unknown, TVariables = unknown, TError = Error, TContext = unknown>(options: UseAddonMutationOptions<TData, TVariables, TError, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/index.d.ts
|
|
155
|
+
export type AddonJsonBody = Record<string, unknown> | unknown[] | null;
|
|
156
|
+
/**
|
|
157
|
+
* @jchat/addon-sdk
|
|
158
|
+
*
|
|
159
|
+
* Lightweight SDK for Jchat addon developers. Provides TypeScript types for addon props, manifest
|
|
160
|
+
* schema, and host API access. This package is always EXTERNALISED from addon bundles — the host
|
|
161
|
+
* app provides the runtime implementation.
|
|
162
|
+
*/
|
|
163
|
+
/** Minimal user profile accessible to addon backends. */
|
|
164
|
+
export interface AddonUser {
|
|
165
|
+
/** Unique user identifier */
|
|
166
|
+
id: string;
|
|
167
|
+
/** Display name */
|
|
168
|
+
name: string;
|
|
169
|
+
/** Full display name */
|
|
170
|
+
displayName: string;
|
|
171
|
+
/** Full URL to the user's avatar image */
|
|
172
|
+
avatar: string;
|
|
173
|
+
/** User's gender identifier */
|
|
174
|
+
gender: string;
|
|
175
|
+
}
|
|
176
|
+
export interface AddonRequestUser {
|
|
177
|
+
id: string;
|
|
178
|
+
permissions?: string[];
|
|
179
|
+
siteId?: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Typed, schema-scoped database facade for an addon. The host deliberately omits raw execution,
|
|
183
|
+
* schema switching, dialect/connection access, and lifecycle methods.
|
|
184
|
+
*/
|
|
185
|
+
export type AddonDatabase<TDatabase = Record<string, Record<string, unknown>>> = Pick<Kysely<TDatabase>, "deleteFrom" | "fn" | "insertInto" | "selectFrom" | "transaction" | "updateTable">;
|
|
186
|
+
/**
|
|
187
|
+
* Scoped caching and key-value client provided to addon server instances. Keys are automatically
|
|
188
|
+
* namespaced by the host as `addon:<addonId>:<key>`.
|
|
189
|
+
*/
|
|
190
|
+
export interface AddonCacheClient {
|
|
191
|
+
/** Retrieve a string or JSON-parsed value by key */
|
|
192
|
+
get: <T = string>(key: string) => Promise<T | null>;
|
|
193
|
+
/** Store a value with an optional time-to-live in seconds */
|
|
194
|
+
set: (key: string, value: unknown, ttlSeconds?: number) => Promise<void>;
|
|
195
|
+
/** Delete one or more keys */
|
|
196
|
+
del: (...keys: string[]) => Promise<number>;
|
|
197
|
+
/** Atomically increment a numeric counter and return the new value */
|
|
198
|
+
incr: (key: string) => Promise<number>;
|
|
199
|
+
/** Set a timeout on a key in seconds */
|
|
200
|
+
expire: (key: string, ttlSeconds: number) => Promise<boolean>;
|
|
201
|
+
/** Get the remaining time-to-live of a key in seconds (-2 if key does not exist, -1 if no TTL) */
|
|
202
|
+
ttl: (key: string) => Promise<number>;
|
|
203
|
+
}
|
|
204
|
+
export interface AddonServerEmitTarget {
|
|
205
|
+
/** Target a specific site (defaults to the request user's siteId) */
|
|
206
|
+
siteId?: string;
|
|
207
|
+
/** Target a specific chat room */
|
|
208
|
+
roomId?: string;
|
|
209
|
+
/** Target a specific user */
|
|
210
|
+
userId?: string;
|
|
211
|
+
}
|
|
212
|
+
export interface AddonMessageMutableData {
|
|
213
|
+
/** Message content (can be Slate JSON structure or string) */
|
|
214
|
+
content: unknown;
|
|
215
|
+
/** Optional message attachments */
|
|
216
|
+
attachments?: unknown[] | null;
|
|
217
|
+
/**
|
|
218
|
+
* Namespaced metadata bucket for this addon. Keyed as `metadata["addon:<addonId>"]`. Storing data
|
|
219
|
+
* here automatically attaches it to the message broadcast and database record.
|
|
220
|
+
*/
|
|
221
|
+
metadata: Record<string, unknown>;
|
|
222
|
+
}
|
|
223
|
+
export interface AddonMessageContext {
|
|
224
|
+
/** The site ID where the message is being sent */
|
|
225
|
+
siteId: string;
|
|
226
|
+
/** The chat room ID */
|
|
227
|
+
roomId: string;
|
|
228
|
+
/** The authenticated user sending the message (read-only) */
|
|
229
|
+
user: AddonRequestUser;
|
|
230
|
+
/** Mutable message payload */
|
|
231
|
+
message: AddonMessageMutableData;
|
|
232
|
+
/** Convenience method to set metadata under this addon's namespace */
|
|
233
|
+
setMetadata: (key: string, value: unknown) => void;
|
|
234
|
+
/**
|
|
235
|
+
* Abort the message sending pipeline with a user-facing error code and reason. Only active during
|
|
236
|
+
* `beforeValidate` and `transformContent`.
|
|
237
|
+
*/
|
|
238
|
+
abort: (error: {
|
|
239
|
+
code: string;
|
|
240
|
+
reason?: string;
|
|
241
|
+
}) => never;
|
|
242
|
+
}
|
|
243
|
+
export interface AddonMessageAfterSaveContext {
|
|
244
|
+
siteId: string;
|
|
245
|
+
roomId: string;
|
|
246
|
+
user: AddonRequestUser;
|
|
247
|
+
message: {
|
|
248
|
+
id: string;
|
|
249
|
+
content: unknown;
|
|
250
|
+
attachments?: unknown[] | null;
|
|
251
|
+
metadata?: Record<string, unknown> | null;
|
|
252
|
+
type: string;
|
|
253
|
+
createdAt: Date | string;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export interface AddonPipelineHooks {
|
|
257
|
+
/**
|
|
258
|
+
* Run before validation to inspect or guard actions (rate-limits, permission gates). Throw or
|
|
259
|
+
* call `context.abort()` to reject the message.
|
|
260
|
+
*/
|
|
261
|
+
beforeValidate?: (context: AddonMessageContext) => Promise<void> | void;
|
|
262
|
+
/** Run before persistence to mutate text, parse slash commands, or enrich metadata. */
|
|
263
|
+
transformContent?: (context: AddonMessageContext) => Promise<void> | void;
|
|
264
|
+
/** Run asynchronously after database save (fire-and-forget observers). */
|
|
265
|
+
afterSave?: (context: AddonMessageAfterSaveContext) => Promise<void> | void;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Context provided to an addon's server-side factory. Parameterize it with the addon's table
|
|
269
|
+
* interface: `AddonServerContext<MyAddonDatabase>`.
|
|
270
|
+
*/
|
|
271
|
+
export interface AddonServerContext<TDatabase = Record<string, Record<string, unknown>>> {
|
|
272
|
+
/**
|
|
273
|
+
* Elysia / TypeBox schema validator for defining route validation schemas (`body`, `query`,
|
|
274
|
+
* `params`, `headers`). Provided directly by the host runtime so your addon server bundle does
|
|
275
|
+
* not need to bundle Elysia.
|
|
276
|
+
*/
|
|
277
|
+
t: typeof t;
|
|
278
|
+
/**
|
|
279
|
+
* Retrieve the encrypted settings for this addon for a specific site. Internal secrets are
|
|
280
|
+
* automatically decrypted using the host's master key.
|
|
281
|
+
*/
|
|
282
|
+
getConfig: (siteId: string) => Promise<Record<string, unknown>>;
|
|
283
|
+
/** Fetch a specific user's public profile */
|
|
284
|
+
getUser: (userId: string) => Promise<AddonUser | null>;
|
|
285
|
+
/** Efficiently fetch multiple user profiles in a single query. Returns a Map keyed by user ID. */
|
|
286
|
+
getUsers: (userIds: string[]) => Promise<Map<string, AddonUser>>;
|
|
287
|
+
/**
|
|
288
|
+
* Check whether the request user holds a given permission. Provides autocomplete for core Jchat
|
|
289
|
+
* permissions while also accepting any custom addon permission string.
|
|
290
|
+
*
|
|
291
|
+
* @param user - The user object from the request context
|
|
292
|
+
* @param permission - The permission to check, e.g., 'message.send' or 'addon.stories.view'
|
|
293
|
+
*/
|
|
294
|
+
hasPermission: (user: AddonRequestUser | null | undefined, permission: string) => boolean;
|
|
295
|
+
/**
|
|
296
|
+
* A Kysely database instance scoped entirely to your addon's tables. You cannot access core Jchat
|
|
297
|
+
* tables (Users, Rooms, etc.) through this instance.
|
|
298
|
+
*/
|
|
299
|
+
db: AddonDatabase<TDatabase>;
|
|
300
|
+
/** A secure, namespaced key-value cache client scoped to your addon (`addon:<addonId>:<key>`). */
|
|
301
|
+
cache: AddonCacheClient;
|
|
302
|
+
/**
|
|
303
|
+
* Broadcast a real-time event to connected clients across the site or room. Clients listen via
|
|
304
|
+
* `sdk.events.on('addon:<addonId>:<event>', callback)` or `sdk.events.on(event, callback)`.
|
|
305
|
+
*/
|
|
306
|
+
emit: (event: string, payload: unknown, target?: AddonServerEmitTarget) => Promise<void>;
|
|
307
|
+
/**
|
|
308
|
+
* Register lifecycle interception hooks for chat messages. Hooks run in the core chat execution
|
|
309
|
+
* path with strict 50ms timeout guards and fail-open fault tolerance.
|
|
310
|
+
*/
|
|
311
|
+
pipeline?: {
|
|
312
|
+
register: (hooks: AddonPipelineHooks) => void;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Cryptographically verify that this addon instance holds a valid host license entitlement.
|
|
316
|
+
* Commercial paid addons should invoke this or call `verifyAddonEntitlement(addonId, context)`.
|
|
317
|
+
*
|
|
318
|
+
* @param expectedAddonId - The canonical addon ID defined by the publisher
|
|
319
|
+
* @returns True if valid, or false if entitlement is missing or invalid
|
|
320
|
+
*/
|
|
321
|
+
verifyEntitlement?: (expectedAddonId?: string) => boolean;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Elysia app instance provided to addon server endpoints with Jchat macro metadata (e.g.
|
|
325
|
+
* requirePermission) typed.
|
|
326
|
+
*/
|
|
327
|
+
export type AddonApp = Elysia<"", {
|
|
328
|
+
decorator: {};
|
|
329
|
+
store: {};
|
|
330
|
+
derive: {};
|
|
331
|
+
resolve: {
|
|
332
|
+
user: AddonRequestUser;
|
|
333
|
+
};
|
|
334
|
+
}, {
|
|
335
|
+
typebox: {};
|
|
336
|
+
error: {};
|
|
337
|
+
}, {
|
|
338
|
+
schema: {};
|
|
339
|
+
standaloneSchema: {};
|
|
340
|
+
macro: {
|
|
341
|
+
requirePermission?: string | string[];
|
|
342
|
+
};
|
|
343
|
+
macroFn: {};
|
|
344
|
+
parser: {};
|
|
345
|
+
response: {};
|
|
346
|
+
}>;
|
|
347
|
+
/**
|
|
348
|
+
* The entry point for your addon's server bundle. You should default-export a function matching
|
|
349
|
+
* this signature.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ;```ts
|
|
353
|
+
* import { type AddonServerFactory } from '@jchat/addon-sdk'
|
|
354
|
+
*
|
|
355
|
+
* const factory: AddonServerFactory = ({ db, hasPermission }, app) => {
|
|
356
|
+
* return app.get('/trending', async () => { ... })
|
|
357
|
+
* }
|
|
358
|
+
* export default factory
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
export type AddonServerFactory<TDatabase = Record<string, Record<string, unknown>>> = (ctx: AddonServerContext<TDatabase>, app: AddonApp) => Elysia;
|
|
362
|
+
/** Props passed to your addon's root React component by the Jchat host. */
|
|
363
|
+
export interface AddonProps {
|
|
364
|
+
/** The mount point where this addon instance is rendered (e.g., 'chat-sidebar') */
|
|
365
|
+
mountPoint: MountPoint;
|
|
366
|
+
/** Information about the currently logged-in user (if any) */
|
|
367
|
+
user?: {
|
|
368
|
+
id: string;
|
|
369
|
+
name: string;
|
|
370
|
+
displayName?: string;
|
|
371
|
+
avatar?: string;
|
|
372
|
+
gender?: string;
|
|
373
|
+
};
|
|
374
|
+
/** The ID of the room the user is currently viewing (if applicable) */
|
|
375
|
+
roomId?: string;
|
|
376
|
+
/** The ID of the active Jchat site */
|
|
377
|
+
siteId?: string;
|
|
378
|
+
/** The active user locale (e.g. 'en', 'ta', 'ar') */
|
|
379
|
+
locale?: string;
|
|
380
|
+
/** Text direction for the current locale */
|
|
381
|
+
dir?: "ltr" | "rtl";
|
|
382
|
+
/** The message object when rendered inside 'chat-message-card' or 'chat-message-flair' */
|
|
383
|
+
message?: unknown;
|
|
384
|
+
/** The addon's specific payload extracted from message.metadata */
|
|
385
|
+
addonData?: unknown;
|
|
386
|
+
}
|
|
387
|
+
export interface AddonApi {
|
|
388
|
+
get: <TResponse = unknown>(path: string) => Promise<TResponse>;
|
|
389
|
+
post: <TResponse = unknown>(path: string, body?: AddonJsonBody) => Promise<TResponse>;
|
|
390
|
+
put: <TResponse = unknown>(path: string, body?: AddonJsonBody) => Promise<TResponse>;
|
|
391
|
+
delete: <TResponse = unknown>(path: string) => Promise<TResponse>;
|
|
392
|
+
}
|
|
393
|
+
/** First-class addon settings management interface provided by the host. */
|
|
394
|
+
export interface AddonSettingsApi {
|
|
395
|
+
/** Fetch the current site's saved configuration for this addon */
|
|
396
|
+
get: <T = Record<string, unknown>>() => Promise<T | null>;
|
|
397
|
+
/** Save updated configuration for this addon for the current site */
|
|
398
|
+
save: <T = Record<string, unknown>>(settings: T) => Promise<void>;
|
|
399
|
+
}
|
|
400
|
+
export type AddonEventListener = (data: unknown) => void;
|
|
401
|
+
/** A font option provided by the JChat host. */
|
|
402
|
+
export interface AddonFont {
|
|
403
|
+
/** Display label shown to users (e.g. 'Modern', 'Elegant') */
|
|
404
|
+
label: string;
|
|
405
|
+
/** Font identifier stored in the database (e.g. 'poppins', 'lato') */
|
|
406
|
+
value: string;
|
|
407
|
+
/** CSS font-family string ready for use in inline styles */
|
|
408
|
+
family: string;
|
|
409
|
+
/** Google Fonts name for loading the font via a <link> tag */
|
|
410
|
+
googleName: string;
|
|
411
|
+
/** Relative size multiplier — apply this to base font sizes to match the host's rendering */
|
|
412
|
+
scale: number;
|
|
413
|
+
}
|
|
414
|
+
export interface AddonEditorInsertImagePayload {
|
|
415
|
+
src: string;
|
|
416
|
+
altText: string;
|
|
417
|
+
emoji?: {
|
|
418
|
+
col: number;
|
|
419
|
+
row: number;
|
|
420
|
+
size: number;
|
|
421
|
+
};
|
|
422
|
+
className?: string;
|
|
423
|
+
}
|
|
424
|
+
export interface AddonEditorInsertEmojiPayload {
|
|
425
|
+
col: number;
|
|
426
|
+
row: number;
|
|
427
|
+
unicode: string;
|
|
428
|
+
shortcode?: string;
|
|
429
|
+
}
|
|
430
|
+
export interface AddonEditorCommandMap {
|
|
431
|
+
INSERT_YOUTUBE_COMMAND: string;
|
|
432
|
+
INSERT_TEXT: string;
|
|
433
|
+
INSERT_TEXT_COMMAND: string;
|
|
434
|
+
INSERT_MENTION_COMMAND: string;
|
|
435
|
+
INSERT_IMAGE_COMMAND: AddonEditorInsertImagePayload;
|
|
436
|
+
INSERT_EMOJI_COMMAND: AddonEditorInsertEmojiPayload;
|
|
437
|
+
CLEAR_EDITOR: void;
|
|
438
|
+
CLEAR_EDITOR_COMMAND: void;
|
|
439
|
+
}
|
|
440
|
+
export type AddonEditorCommand = keyof AddonEditorCommandMap;
|
|
441
|
+
export interface AddonEditorApi {
|
|
442
|
+
/**
|
|
443
|
+
* Trigger a specialized editor command defined by the host.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* sdk.editor.dispatchCommand("INSERT_YOUTUBE_COMMAND", "dQw4w9WgXcQ")
|
|
447
|
+
*/
|
|
448
|
+
dispatchCommand: <C extends AddonEditorCommand>(command: C, ...args: AddonEditorCommandMap[C] extends void ? [payload?: undefined] : [payload: AddonEditorCommandMap[C]]) => void;
|
|
449
|
+
/**
|
|
450
|
+
* Insert a low-level Slate node directly at the user's cursor position.
|
|
451
|
+
*
|
|
452
|
+
* @param node - A valid Slate Descendant or Fragment object
|
|
453
|
+
*/
|
|
454
|
+
insertNode: (node: unknown) => void;
|
|
455
|
+
/**
|
|
456
|
+
* Upload and attach a file to the current message without inserting it inline. Users will see the
|
|
457
|
+
* file in the attachment bar below the editor.
|
|
458
|
+
*/
|
|
459
|
+
addAttachment: (attachment: {
|
|
460
|
+
url: string;
|
|
461
|
+
name: string;
|
|
462
|
+
type: string;
|
|
463
|
+
}) => void;
|
|
464
|
+
/** Force the browser focus back to the editor input */
|
|
465
|
+
focus: () => void;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* The bridge between your addon and the Jchat host application. Use the `useAddonSDK()` hook to
|
|
469
|
+
* access this interface in your components.
|
|
470
|
+
*/
|
|
471
|
+
export interface AddonSDK {
|
|
472
|
+
/**
|
|
473
|
+
* Make authenticated API calls to your addon's backend or core Jchat endpoints. All calls
|
|
474
|
+
* automatically include the current user's sessionId and site validation headers. Relative paths
|
|
475
|
+
* are automatically prefixed with `/api/v1/addons/<addonId>`.
|
|
476
|
+
*/
|
|
477
|
+
api: AddonApi;
|
|
478
|
+
/**
|
|
479
|
+
* First-class settings API to load and save addon configuration without boilerplate path
|
|
480
|
+
* construction.
|
|
481
|
+
*/
|
|
482
|
+
settings: AddonSettingsApi;
|
|
483
|
+
/**
|
|
484
|
+
* Display a temporary notification toast in the host UI.
|
|
485
|
+
*
|
|
486
|
+
* @param message - The text content to display
|
|
487
|
+
* @param variant - Visual style: 'default' (blue), 'success' (green), or 'error' (red)
|
|
488
|
+
*/
|
|
489
|
+
toast: (message: string, variant?: "default" | "success" | "error") => void;
|
|
490
|
+
/**
|
|
491
|
+
* Navigate the host application to a different internal route.
|
|
492
|
+
*
|
|
493
|
+
* @param path - The target location, e.g., '/settings' or '/addons/store'
|
|
494
|
+
*/
|
|
495
|
+
navigate: (path: string) => void;
|
|
496
|
+
/**
|
|
497
|
+
* Interaction utilities for the active Slate message editor. Only available if your addon is
|
|
498
|
+
* mounted near the chat input.
|
|
499
|
+
*/
|
|
500
|
+
editor: AddonEditorApi;
|
|
501
|
+
/** Event Bus for reacting to real-time application state changes. */
|
|
502
|
+
events: {
|
|
503
|
+
/**
|
|
504
|
+
* Register a persistent listener for a specific event.
|
|
505
|
+
*
|
|
506
|
+
* @param event - Event name, e.g., 'room.message', 'user.typing'
|
|
507
|
+
*/
|
|
508
|
+
on: (event: string, callback: AddonEventListener) => void;
|
|
509
|
+
/** Unregister a previously attached listener */
|
|
510
|
+
off: (event: string, callback: AddonEventListener) => void;
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* The list of fonts available in this JChat deployment, as configured by the site administrator.
|
|
514
|
+
* Use this to build a font picker or apply a matching font family in your addon UI.
|
|
515
|
+
*/
|
|
516
|
+
supportedFonts?: AddonFont[];
|
|
517
|
+
/** The active user locale (e.g. 'en', 'ta', 'ar') */
|
|
518
|
+
locale: string;
|
|
519
|
+
/** Text direction for the active locale ('ltr' or 'rtl') */
|
|
520
|
+
dir: "ltr" | "rtl";
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Seed data for your addon's tables, provided inside the addon's isolated schema.
|
|
524
|
+
*
|
|
525
|
+
* These documents are inserted into the addon's dedicated schema on installation and can be used to
|
|
526
|
+
* provide default values, references, or supporting data. The host guarantees that these documents
|
|
527
|
+
* do not conflict with core schemas or other addons.
|
|
528
|
+
*/
|
|
529
|
+
export interface AddonSeedDocument {
|
|
530
|
+
/** Addon-owned table name. Core prefixes the addon's isolated PostgreSQL schema. */
|
|
531
|
+
table: string;
|
|
532
|
+
/** Behavior when a row conflicts with an existing unique or primary key. */
|
|
533
|
+
conflict?: "error" | "ignore" | "update";
|
|
534
|
+
/** Required for update behavior; identifies the unique key used by ON CONFLICT. */
|
|
535
|
+
conflictColumns?: string[];
|
|
536
|
+
/** JSON-compatible rows inserted using parameterized values. */
|
|
537
|
+
rows: Record<string, unknown>[];
|
|
538
|
+
}
|
|
539
|
+
/** Define a manifest with full validation-friendly typing while preserving literal values. */
|
|
540
|
+
export declare function defineAddonManifest<const TManifest extends AddonManifest>(manifest: TManifest): TManifest;
|
|
541
|
+
/** Define a typed server factory without widening its addon database interface. */
|
|
542
|
+
export declare function defineAddonServer<TDatabase = Record<string, Record<string, unknown>>>(factory: AddonServerFactory<TDatabase>): AddonServerFactory<TDatabase>;
|
|
543
|
+
/**
|
|
544
|
+
* Access the host application's SDK. Provides authenticated API access, toast notifications, and
|
|
545
|
+
* navigation.
|
|
546
|
+
*
|
|
547
|
+
* This function is a shell; the real implementation is provided by the Jchat host environment at
|
|
548
|
+
* runtime.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ;```tsx
|
|
552
|
+
* import { useAddonSDK } from "@jchat/addon-sdk"
|
|
553
|
+
*
|
|
554
|
+
* export default function MyAddon({ mountPoint }: AddonProps) {
|
|
555
|
+
* const sdk = useAddonSDK()
|
|
556
|
+
*
|
|
557
|
+
* const handleClick = async () => {
|
|
558
|
+
* const data = await sdk.api.get("/trending")
|
|
559
|
+
* sdk.toast("Fetched trending posts!", "success")
|
|
560
|
+
* }
|
|
561
|
+
* }
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
export declare function useAddonSDK(): AddonSDK;
|
|
565
|
+
/**
|
|
566
|
+
* Get the version of the addon SDK. This is useful for checking compatibility with the host
|
|
567
|
+
* application.
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* ;```tsx
|
|
571
|
+
* import { getAddonSdkVersion } from "@jchat/addon-sdk"
|
|
572
|
+
*
|
|
573
|
+
* console.log(getAddonSdkVersion())
|
|
574
|
+
* ```
|
|
575
|
+
*
|
|
576
|
+
* @returns
|
|
577
|
+
*/
|
|
578
|
+
export declare function getAddonSdkVersion(): string;
|
|
579
|
+
/**
|
|
580
|
+
* Verifies purchase entitlement and identity integrity for commercial addons. Throws an error if
|
|
581
|
+
* the addon fails entitlement verification or if its manifest ID has been tampered with to
|
|
582
|
+
* impersonate another addon.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ;```ts
|
|
586
|
+
* export default defineAddonServer((context, app) => {
|
|
587
|
+
* verifyAddonEntitlement("tubescanpro", context)
|
|
588
|
+
* return app.get("/trending", async () => { ... })
|
|
589
|
+
* })
|
|
590
|
+
* ```
|
|
591
|
+
*
|
|
592
|
+
* @param addonId - The canonical addon ID defined by the publisher (e.g. 'tubescanpro')
|
|
593
|
+
* @param context - The AddonServerContext passed to the addon's server factory
|
|
594
|
+
* @returns True if valid
|
|
595
|
+
* @throws Error if entitlement verification fails
|
|
596
|
+
*/
|
|
597
|
+
export declare function verifyAddonEntitlement(addonId: string, context?: {
|
|
598
|
+
verifyEntitlement?: (expectedAddonId?: string) => boolean;
|
|
599
|
+
}): boolean;
|
|
600
|
+
//#endregion
|
|
601
|
+
export { type AddonCommandDefinition, type AddonCommandParameter, type AddonManifest, type AddonPermissionDefinition, type ColumnType, type Generated, type IconComponent, type IconName, type IconPack, type InfiniteData, type Insertable, type JSONColumnType, MOUNT_POINTS, type MountPoint, type QueryKey, type Selectable, type Updateable, useQueryClient };
|
package/dist/state.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "jotai";
|
package/dist/state.mjs
ADDED
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentType, SVGProps } from "react";
|
|
2
|
+
import { icons } from "lucide-react";
|
|
3
|
+
//#region ../icon/dist/types.d.mts
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type IconComponent = ComponentType<SVGProps<SVGSVGElement>>;
|
|
6
|
+
type LucideIconName = keyof typeof icons;
|
|
7
|
+
type IconName = LucideIconName | "Youtube";
|
|
8
|
+
declare const ICON_NAMES: readonly IconName[];
|
|
9
|
+
type IconPack = Record<IconName, IconComponent>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#endregion
|
|
12
|
+
export { IconPack as i, IconComponent as n, IconName as r, ICON_NAMES as t };
|
package/dist/ui.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@jchat/ui";
|
package/dist/ui.mjs
ADDED