@jchat/addon-sdk 1.0.0-alpha.11 → 1.0.0-alpha.13
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 +21 -0
- package/README.md +339 -61
- package/dist/cli.d.mts +6 -7
- package/dist/cli.mjs +3 -2
- package/dist/contracts.d.mts +5 -6
- package/dist/contracts.mjs +38 -0
- package/dist/diagnostics.d.mts +8 -9
- package/dist/diagnostics.mjs +1 -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 -510
- package/dist/index.mjs +6 -338
- package/dist/index2.d.mts +478 -0
- package/dist/state.d.mts +1 -0
- package/dist/state.mjs +2 -0
- package/dist/types.d.mts +12 -0
- package/dist/vite.d.mts +7 -8
- package/dist/vite.mjs +51 -11
- package/package.json +93 -16
- package/skills/create-jchat-addon/SKILL.md +140 -0
- package/skills/jchat-addon-development/SKILL.md +260 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,514 +1,20 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//#region ../icon/dist/types.d.mts
|
|
7
|
-
//#region src/types.d.ts
|
|
8
|
-
type IconComponent = ComponentType<SVGProps<SVGSVGElement>>;
|
|
9
|
-
declare const ICON_NAMES: readonly ["Activity", "ArrowLeft", "ArrowRight", "Ban", "Bell", "BookOpen", "Brush", "Calendar", "Camera", "ChartBar", "Check", "CheckCheck", "CheckCircle2", "ChevronDown", "ChevronLeft", "ChevronRight", "ChevronUp", "CircleAlert", "CircleCheck", "CircleOff", "CirclePlay", "CirclePlus", "Clock", "Coffee", "Contact", "Cpu", "Database", "Dices", "Ellipsis", "Eraser", "ExternalLink", "Eye", "EyeOff", "Flag", "Flame", "FolderPlus", "Footprints", "Gamepad2", "Gift", "Globe", "HardDrive", "Headphones", "Heart", "Image", "Info", "Key", "KeyRound", "Layers", "LayoutDashboard", "LayoutList", "LayoutTemplate", "Link2", "ListOrdered", "Loader", "LoaderCircle", "Lock", "LogOut", "Mail", "Maximize", "Megaphone", "MemoryStick", "Menu", "MessageCircle", "MessageSquare", "Mic", "Minimize", "Minus", "Monitor", "Moon", "MoreHorizontal", "Music", "Music2", "Newspaper", "Palette", "Paperclip", "PartyPopper", "Pause", "PenLine", "Play", "Plus", "Radio", "Reply", "RotateCcw", "RotateCw", "Search", "Send", "Server", "Settings", "Shield", "ShieldAlert", "ShieldCheck", "SkipForward", "SlidersHorizontal", "Smartphone", "Smile", "Sparkles", "Square", "SquarePen", "Star", "Sun", "ThumbsDown", "ThumbsUp", "Timer", "Trash", "Trash2", "Trophy", "Upload", "User", "UserCheck", "UserCog", "UserMinus", "UserPen", "UserPlus", "UserRoundPlus", "Users", "UserX", "Utensils", "Video", "VideoOff", "Volume", "Volume2", "VolumeX", "X", "Youtube", "Zap"];
|
|
10
|
-
type IconName = (typeof ICON_NAMES)[number];
|
|
11
|
-
type IconPack = Record<IconName, IconComponent>;
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/i18n.d.ts
|
|
14
|
-
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"];
|
|
15
|
-
type HostLanguage = (typeof HOST_LANGUAGES)[number];
|
|
16
|
-
interface AddonLocaleValidationResult {
|
|
17
|
-
valid: boolean;
|
|
18
|
-
errors: string[];
|
|
19
|
-
missingFiles: string[];
|
|
20
|
-
missingKeys: Record<string, string[]>;
|
|
21
|
-
extraKeys: Record<string, string[]>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Validates that an addon's `locales/` directory contains valid translation files for all 11 host
|
|
25
|
-
* languages with 100% key parity against `en.json`.
|
|
26
|
-
*
|
|
27
|
-
* @param dirPath - Path to the addon's locales directory.
|
|
28
|
-
* @param domainName - Optional label for error messages (defaults to "Addon").
|
|
29
|
-
*/
|
|
30
|
-
declare function validateAddonLocales(dirPath: string, domainName?: string): AddonLocaleValidationResult;
|
|
31
|
-
type AddonTranslationDictionary = Record<string, unknown>;
|
|
32
|
-
type AddonTranslationResources = Record<string, AddonTranslationDictionary>;
|
|
33
|
-
type AddonLocaleLoader = (locale: string) => Promise<AddonTranslationDictionary> | AddonTranslationDictionary;
|
|
34
|
-
interface LocaleContextValue {
|
|
35
|
-
locale: string;
|
|
36
|
-
dir: "ltr" | "rtl";
|
|
37
|
-
}
|
|
38
|
-
declare const LocaleContext: import("react").Context<LocaleContextValue>;
|
|
39
|
-
interface TranslatorOptions {
|
|
40
|
-
resources?: AddonTranslationResources;
|
|
41
|
-
defaultLocale?: string;
|
|
42
|
-
fallbackLocale?: string;
|
|
43
|
-
}
|
|
44
|
-
type TranslateFunction<TKeys extends string = string> = (key: TKeys | (string & {}), paramsOrLang?: Record<string, unknown> | string, maybeLang?: string) => string;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a standalone translation function for backend server routes (`src/api.ts`) or utilities.
|
|
47
|
-
*
|
|
48
|
-
* @param resources - Dictionary of translation resources (e.g., `{ en: enJson, ta: taJson }`).
|
|
49
|
-
* @param defaultLocale - Default locale to use if not specified per call (defaults to "en").
|
|
50
|
-
* @param fallbackLocale - Fallback locale if a key is missing in the target language (defaults to
|
|
51
|
-
* "en").
|
|
52
|
-
*/
|
|
53
|
-
declare function createTranslator<TResources extends AddonTranslationResources = AddonTranslationResources>(resources?: TResources, defaultLocale?: string, fallbackLocale?: string): TranslateFunction<TResources extends {
|
|
54
|
-
en: infer TEn;
|
|
55
|
-
} ? TEn extends Record<string, unknown> ? Extract<keyof TEn, string> : string : string>;
|
|
56
|
-
/**
|
|
57
|
-
* Hook to access the current active host locale and text direction in an addon component.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ;```tsx
|
|
61
|
-
* import { useLocale } from "@jchat/addon-sdk"
|
|
62
|
-
*
|
|
63
|
-
* export default function MyAddon() {
|
|
64
|
-
* const { locale, dir, isRtl } = useLocale()
|
|
65
|
-
* return <div dir={dir}>Current language: {locale}</div>
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
declare function useLocale(): {
|
|
70
|
-
locale: string;
|
|
71
|
-
dir: "ltr" | "rtl";
|
|
72
|
-
isRtl: boolean;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Hook to access translation function and locale metadata inside addon components. Automatically
|
|
76
|
-
* synchronizes with host language switches and falls back to English. Supports static dictionary
|
|
77
|
-
* resources or dynamic async locale loaders.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ;```tsx
|
|
81
|
-
* import { useTranslation } from "@jchat/addon-sdk"
|
|
82
|
-
* import locales from "./locales"
|
|
83
|
-
*
|
|
84
|
-
* export default function MyAddon() {
|
|
85
|
-
* const { t, locale, dir } = useTranslation(locales)
|
|
86
|
-
* return (
|
|
87
|
-
* <div dir={dir}>
|
|
88
|
-
* <h1>{t("welcome", { name: "Guest" })}</h1>
|
|
89
|
-
* </div>
|
|
90
|
-
* )
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @param resourcesOrLoader - Addon-scoped translation dictionaries or async chunk loader.
|
|
95
|
-
* @param fallbackLocale - Fallback language code when a string is missing (default: "en").
|
|
96
|
-
*/
|
|
97
|
-
declare function useTranslation<TResources extends AddonTranslationResources | AddonLocaleLoader = AddonTranslationResources>(resourcesOrLoader?: TResources, fallbackLocale?: string): {
|
|
98
|
-
t: TranslateFunction<TResources extends {
|
|
99
|
-
en: infer TEn;
|
|
100
|
-
} ? TEn extends Record<string, unknown> ? Extract<keyof TEn, string> : string : string>;
|
|
101
|
-
locale: string;
|
|
102
|
-
dir: "ltr" | "rtl";
|
|
103
|
-
isRtl: boolean;
|
|
104
|
-
isReady: boolean;
|
|
105
|
-
};
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/query.d.ts
|
|
108
|
-
interface UseAddonQueryOptions<TData = unknown, TError = Error> extends Omit<UndefinedInitialDataOptions<TData, TError, TData, QueryKey>, "queryKey" | "queryFn"> {
|
|
109
|
-
/** The API path to fetch, automatically prefixed with `/api/v1/addons/<addonId>` */
|
|
110
|
-
path?: string;
|
|
111
|
-
/** Custom query key elements appended to the automatic path cache key */
|
|
112
|
-
queryKey?: QueryKey;
|
|
113
|
-
/** Custom query function override */
|
|
114
|
-
queryFn?: QueryFunction<TData, QueryKey>;
|
|
115
|
-
}
|
|
116
|
-
interface UseAddonMutationOptions<TData = unknown, TVariables = unknown, TError = Error, TContext = unknown> extends Omit<UseMutationOptions<TData, TError, TVariables, TContext>, "mutationFn"> {
|
|
117
|
-
/** The target API path, or a dynamic function of mutation variables */
|
|
118
|
-
path?: string | ((variables: TVariables) => string);
|
|
119
|
-
/** HTTP method to use (defaults to 'POST') */
|
|
120
|
-
method?: "POST" | "PUT" | "DELETE";
|
|
121
|
-
/** Query keys to automatically invalidate upon successful mutation */
|
|
122
|
-
invalidateQueries?: QueryKey[];
|
|
123
|
-
/** Custom mutation function override */
|
|
124
|
-
mutationFn?: MutationFunction<TData, TVariables>;
|
|
125
|
-
}
|
|
126
|
-
interface UseAddonInfiniteQueryOptions<TData = unknown, TError = Error, TPageParam = unknown> extends Omit<UndefinedInitialDataInfiniteOptions<TData, TError, InfiniteData<TData, TPageParam>, QueryKey, TPageParam>, "queryKey" | "queryFn"> {
|
|
127
|
-
/** The API path to fetch, or a dynamic function that receives pageParam and returns the path */
|
|
128
|
-
path?: string | ((pageParam: TPageParam) => string);
|
|
129
|
-
/** Custom query key elements appended to the automatic cache key */
|
|
130
|
-
queryKey?: QueryKey;
|
|
131
|
-
/** Custom query function override */
|
|
132
|
-
queryFn?: (context: QueryFunctionContext<QueryKey, TPageParam>) => Promise<TData>;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Perform a declarative, cached GET request using the host's shared React Query instance.
|
|
136
|
-
* Automatically injects authentication headers and prefixes addon paths.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ;```tsx
|
|
140
|
-
* const { data, isLoading } = useAddonQuery<{ polls: Poll[] }>({
|
|
141
|
-
* path: "/polls",
|
|
142
|
-
* queryKey: [siteId]
|
|
143
|
-
* })
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
declare function useAddonQuery<TData = unknown, TError = Error>(options: UseAddonQueryOptions<TData, TError>): UseQueryResult<TData, TError>;
|
|
147
|
-
/**
|
|
148
|
-
* Perform a paginated or infinite scrolling request using the host's shared React Query instance.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ;```tsx
|
|
152
|
-
* const { data, fetchNextPage, hasNextPage } = useAddonInfiniteQuery<GifResponse, Error, number>({
|
|
153
|
-
* path: (page) => `/trending?offset=${page * 20}`,
|
|
154
|
-
* initialPageParam: 0,
|
|
155
|
-
* getNextPageParam: (lastPage, allPages) => (lastPage.hasMore ? allPages.length : undefined)
|
|
156
|
-
* })
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
declare function useAddonInfiniteQuery<TData = unknown, TError = Error, TPageParam = unknown>(options: UseAddonInfiniteQueryOptions<TData, TError, TPageParam>): UseInfiniteQueryResult<InfiniteData<TData, TPageParam>, TError>;
|
|
160
|
-
/**
|
|
161
|
-
* Perform a declarative mutation using the host's shared React Query instance. Automatically
|
|
162
|
-
* executes the request and can invalidate specified query keys upon success.
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ;```tsx
|
|
166
|
-
* const { mutate, isPending } = useAddonMutation<Poll, CreatePollInput>({
|
|
167
|
-
* path: "/polls",
|
|
168
|
-
* method: "POST",
|
|
169
|
-
* invalidateQueries: [["/polls"]],
|
|
170
|
-
* onSuccess: () => sdk.toast("Poll created!", "success")
|
|
171
|
-
* })
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
declare function useAddonMutation<TData = unknown, TVariables = unknown, TError = Error, TContext = unknown>(options: UseAddonMutationOptions<TData, TVariables, TError, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
1
|
+
import { i as IconPack, n as IconComponent, r as IconName, t as ICON_NAMES } from "./types.mjs";
|
|
2
|
+
//#region ../icon/dist/index.d.mts
|
|
3
|
+
//#region src/packs/lucide.d.ts
|
|
4
|
+
declare const Youtube: IconComponent;
|
|
5
|
+
declare const lucidePack: IconPack;
|
|
175
6
|
//#endregion
|
|
176
7
|
//#region src/index.d.ts
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
* schema, and host API access. This package is always EXTERNALISED from addon bundles — the host
|
|
183
|
-
* app provides the runtime implementation.
|
|
184
|
-
*/
|
|
185
|
-
/** Minimal user profile accessible to addon backends. */
|
|
186
|
-
interface AddonUser {
|
|
187
|
-
/** Unique user identifier */
|
|
188
|
-
id: string;
|
|
189
|
-
/** Display name */
|
|
190
|
-
name: string;
|
|
191
|
-
/** Full display name */
|
|
192
|
-
displayName: string;
|
|
193
|
-
/** Full URL to the user's avatar image */
|
|
194
|
-
avatar: string;
|
|
195
|
-
/** User's gender identifier */
|
|
196
|
-
gender: string;
|
|
197
|
-
}
|
|
198
|
-
interface AddonRequestUser {
|
|
199
|
-
id: string;
|
|
200
|
-
permissions?: string[];
|
|
201
|
-
siteId?: string;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Typed, schema-scoped database facade for an addon. The host deliberately omits raw execution,
|
|
205
|
-
* schema switching, dialect/connection access, and lifecycle methods.
|
|
206
|
-
*/
|
|
207
|
-
type AddonDatabase<TDatabase = Record<string, Record<string, unknown>>> = Pick<Kysely<TDatabase>, "deleteFrom" | "fn" | "insertInto" | "selectFrom" | "transaction" | "updateTable">;
|
|
208
|
-
/**
|
|
209
|
-
* Scoped caching and key-value client provided to addon server instances. Keys are automatically
|
|
210
|
-
* namespaced by the host as `addon:<addonId>:<key>`.
|
|
211
|
-
*/
|
|
212
|
-
interface AddonCacheClient {
|
|
213
|
-
/** Retrieve a string or JSON-parsed value by key */
|
|
214
|
-
get: <T = string>(key: string) => Promise<T | null>;
|
|
215
|
-
/** Store a value with an optional time-to-live in seconds */
|
|
216
|
-
set: (key: string, value: unknown, ttlSeconds?: number) => Promise<void>;
|
|
217
|
-
/** Delete one or more keys */
|
|
218
|
-
del: (...keys: string[]) => Promise<number>;
|
|
219
|
-
/** Atomically increment a numeric counter and return the new value */
|
|
220
|
-
incr: (key: string) => Promise<number>;
|
|
221
|
-
/** Set a timeout on a key in seconds */
|
|
222
|
-
expire: (key: string, ttlSeconds: number) => Promise<boolean>;
|
|
223
|
-
/** Get the remaining time-to-live of a key in seconds (-2 if key does not exist, -1 if no TTL) */
|
|
224
|
-
ttl: (key: string) => Promise<number>;
|
|
225
|
-
}
|
|
226
|
-
interface AddonServerEmitTarget {
|
|
227
|
-
/** Target a specific site (defaults to the request user's siteId) */
|
|
228
|
-
siteId?: string;
|
|
229
|
-
/** Target a specific chat room */
|
|
230
|
-
roomId?: string;
|
|
231
|
-
/** Target a specific user */
|
|
232
|
-
userId?: string;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Context provided to an addon's server-side factory. Parameterize it with the addon's table
|
|
236
|
-
* interface: `AddonServerContext<MyAddonDatabase>`.
|
|
237
|
-
*/
|
|
238
|
-
interface AddonServerContext<TDatabase = Record<string, Record<string, unknown>>> {
|
|
239
|
-
/**
|
|
240
|
-
* Retrieve the encrypted settings for this addon for a specific site. Internal secrets are
|
|
241
|
-
* automatically decrypted using the host's master key.
|
|
242
|
-
*/
|
|
243
|
-
getConfig: (siteId: string) => Promise<Record<string, unknown>>;
|
|
244
|
-
/** Fetch a specific user's public profile */
|
|
245
|
-
getUser: (userId: string) => Promise<AddonUser | null>;
|
|
246
|
-
/** Efficiently fetch multiple user profiles in a single query. Returns a Map keyed by user ID. */
|
|
247
|
-
getUsers: (userIds: string[]) => Promise<Map<string, AddonUser>>;
|
|
248
|
-
/**
|
|
249
|
-
* Check whether the request user holds a given permission. Provides autocomplete for core Jchat
|
|
250
|
-
* permissions while also accepting any custom addon permission string.
|
|
251
|
-
*
|
|
252
|
-
* @param user - The user object from the request context
|
|
253
|
-
* @param permission - The permission to check, e.g., 'message.send' or 'addon.stories.view'
|
|
254
|
-
*/
|
|
255
|
-
hasPermission: (user: AddonRequestUser | null | undefined, permission: string) => boolean;
|
|
256
|
-
/**
|
|
257
|
-
* A Kysely database instance scoped entirely to your addon's tables. You cannot access core Jchat
|
|
258
|
-
* tables (Users, Rooms, etc.) through this instance.
|
|
259
|
-
*/
|
|
260
|
-
db: AddonDatabase<TDatabase>;
|
|
261
|
-
/** A secure, namespaced key-value cache client scoped to your addon (`addon:<addonId>:<key>`). */
|
|
262
|
-
cache: AddonCacheClient;
|
|
263
|
-
/**
|
|
264
|
-
* Broadcast a real-time event to connected clients across the site or room. Clients listen via
|
|
265
|
-
* `sdk.events.on('addon:<addonId>:<event>', callback)` or `sdk.events.on(event, callback)`.
|
|
266
|
-
*/
|
|
267
|
-
emit: (event: string, payload: unknown, target?: AddonServerEmitTarget) => Promise<void>;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Elysia app instance provided to addon server endpoints with Jchat macro metadata (e.g.
|
|
271
|
-
* requirePermission) typed.
|
|
272
|
-
*/
|
|
273
|
-
type AddonApp = Elysia<"", {
|
|
274
|
-
decorator: {};
|
|
275
|
-
store: {};
|
|
276
|
-
derive: {};
|
|
277
|
-
resolve: {
|
|
278
|
-
user: AddonRequestUser;
|
|
279
|
-
};
|
|
280
|
-
}, {
|
|
281
|
-
typebox: {};
|
|
282
|
-
error: {};
|
|
283
|
-
}, {
|
|
284
|
-
schema: {};
|
|
285
|
-
standaloneSchema: {};
|
|
286
|
-
macro: {
|
|
287
|
-
requirePermission?: string | string[];
|
|
288
|
-
};
|
|
289
|
-
macroFn: {};
|
|
290
|
-
parser: {};
|
|
291
|
-
response: {};
|
|
292
|
-
}>;
|
|
293
|
-
/**
|
|
294
|
-
* The entry point for your addon's server bundle. You should default-export a function matching
|
|
295
|
-
* this signature.
|
|
296
|
-
*
|
|
297
|
-
* @example
|
|
298
|
-
* ;```ts
|
|
299
|
-
* import { type AddonServerFactory } from '@jchat/addon-sdk'
|
|
300
|
-
*
|
|
301
|
-
* const factory: AddonServerFactory = ({ db, hasPermission }, app) => {
|
|
302
|
-
* return app.get('/trending', async () => { ... })
|
|
303
|
-
* }
|
|
304
|
-
* export default factory
|
|
305
|
-
* ```
|
|
306
|
-
*/
|
|
307
|
-
type AddonServerFactory<TDatabase = Record<string, Record<string, unknown>>> = (ctx: AddonServerContext<TDatabase>, app: AddonApp) => Elysia;
|
|
308
|
-
/** Props passed to your addon's root React component by the Jchat host. */
|
|
309
|
-
interface AddonProps {
|
|
310
|
-
/** The mount point where this addon instance is rendered (e.g., 'chat-sidebar') */
|
|
311
|
-
mountPoint: MountPoint;
|
|
312
|
-
/** Information about the currently logged-in user (if any) */
|
|
313
|
-
user?: {
|
|
314
|
-
id: string;
|
|
315
|
-
name: string;
|
|
316
|
-
displayName?: string;
|
|
317
|
-
avatar?: string;
|
|
318
|
-
gender?: string;
|
|
319
|
-
};
|
|
320
|
-
/** The ID of the room the user is currently viewing (if applicable) */
|
|
321
|
-
roomId?: string;
|
|
322
|
-
/** The ID of the active Jchat site */
|
|
323
|
-
siteId?: string;
|
|
324
|
-
/** The active user locale (e.g. 'en', 'ta', 'ar') */
|
|
325
|
-
locale?: string;
|
|
326
|
-
/** Text direction for the current locale */
|
|
327
|
-
dir?: "ltr" | "rtl";
|
|
328
|
-
}
|
|
329
|
-
interface AddonApi {
|
|
330
|
-
get: <TResponse = unknown>(path: string) => Promise<TResponse>;
|
|
331
|
-
post: <TResponse = unknown>(path: string, body?: AddonJsonBody) => Promise<TResponse>;
|
|
332
|
-
put: <TResponse = unknown>(path: string, body?: AddonJsonBody) => Promise<TResponse>;
|
|
333
|
-
delete: <TResponse = unknown>(path: string) => Promise<TResponse>;
|
|
334
|
-
}
|
|
335
|
-
/** First-class addon settings management interface provided by the host. */
|
|
336
|
-
interface AddonSettingsApi {
|
|
337
|
-
/** Fetch the current site's saved configuration for this addon */
|
|
338
|
-
get: <T = Record<string, unknown>>() => Promise<T | null>;
|
|
339
|
-
/** Save updated configuration for this addon for the current site */
|
|
340
|
-
save: <T = Record<string, unknown>>(settings: T) => Promise<void>;
|
|
341
|
-
}
|
|
342
|
-
type AddonEventListener = (data: unknown) => void;
|
|
343
|
-
/** A font option provided by the JChat host. */
|
|
344
|
-
interface AddonFont {
|
|
345
|
-
/** Display label shown to users (e.g. 'Modern', 'Elegant') */
|
|
346
|
-
label: string;
|
|
347
|
-
/** Font identifier stored in the database (e.g. 'poppins', 'lato') */
|
|
348
|
-
value: string;
|
|
349
|
-
/** CSS font-family string ready for use in inline styles */
|
|
350
|
-
family: string;
|
|
351
|
-
/** Google Fonts name for loading the font via a <link> tag */
|
|
352
|
-
googleName: string;
|
|
353
|
-
/** Relative size multiplier — apply this to base font sizes to match the host's rendering */
|
|
354
|
-
scale: number;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* The bridge between your addon and the Jchat host application. Use the `useAddonSDK()` hook to
|
|
358
|
-
* access this interface in your components.
|
|
359
|
-
*/
|
|
360
|
-
interface AddonSDK {
|
|
361
|
-
/**
|
|
362
|
-
* Make authenticated API calls to your addon's backend or core Jchat endpoints. All calls
|
|
363
|
-
* automatically include the current user's sessionId and site validation headers. Relative paths
|
|
364
|
-
* are automatically prefixed with `/api/v1/addons/<addonId>`.
|
|
365
|
-
*/
|
|
366
|
-
api: AddonApi;
|
|
367
|
-
/**
|
|
368
|
-
* First-class settings API to load and save addon configuration without boilerplate path
|
|
369
|
-
* construction.
|
|
370
|
-
*/
|
|
371
|
-
settings: AddonSettingsApi;
|
|
372
|
-
/**
|
|
373
|
-
* Display a temporary notification toast in the host UI.
|
|
374
|
-
*
|
|
375
|
-
* @param message - The text content to display
|
|
376
|
-
* @param variant - Visual style: 'default' (blue), 'success' (green), or 'error' (red)
|
|
377
|
-
*/
|
|
378
|
-
toast: (message: string, variant?: "default" | "success" | "error") => void;
|
|
379
|
-
/**
|
|
380
|
-
* Navigate the host application to a different internal route.
|
|
381
|
-
*
|
|
382
|
-
* @param path - The target location, e.g., '/settings' or '/addons/store'
|
|
383
|
-
*/
|
|
384
|
-
navigate: (path: string) => void;
|
|
385
|
-
/**
|
|
386
|
-
* Interaction utilities for the active Slate message editor. Only available if your addon is
|
|
387
|
-
* mounted near the chat input.
|
|
388
|
-
*/
|
|
389
|
-
editor: {
|
|
390
|
-
/**
|
|
391
|
-
* Trigger a specialized editor command defined by the host.
|
|
392
|
-
*
|
|
393
|
-
* @example
|
|
394
|
-
* sdk.editor.dispatchCommand("INSERT_YOUTUBE_COMMAND", "dQw4w9WgXcQ")
|
|
395
|
-
*/
|
|
396
|
-
dispatchCommand: (command: string, payload?: unknown) => void;
|
|
397
|
-
/**
|
|
398
|
-
* Insert a low-level Slate node directly at the user's cursor position.
|
|
399
|
-
*
|
|
400
|
-
* @param node - A valid Slate Descendant or Fragment object
|
|
401
|
-
*/
|
|
402
|
-
insertNode: (node: unknown) => void;
|
|
403
|
-
/**
|
|
404
|
-
* Upload and attach a file to the current message without inserting it inline. Users will see
|
|
405
|
-
* the file in the attachment bar below the editor.
|
|
406
|
-
*/
|
|
407
|
-
addAttachment: (attachment: {
|
|
408
|
-
url: string;
|
|
409
|
-
name: string;
|
|
410
|
-
type: string;
|
|
411
|
-
}) => void;
|
|
412
|
-
/** Force the browser focus back to the editor input */
|
|
413
|
-
focus: () => void;
|
|
414
|
-
};
|
|
415
|
-
/** Event Bus for reacting to real-time application state changes. */
|
|
416
|
-
events: {
|
|
417
|
-
/**
|
|
418
|
-
* Register a persistent listener for a specific event.
|
|
419
|
-
*
|
|
420
|
-
* @param event - Event name, e.g., 'room.message', 'user.typing'
|
|
421
|
-
*/
|
|
422
|
-
on: (event: string, callback: AddonEventListener) => void;
|
|
423
|
-
/** Unregister a previously attached listener */
|
|
424
|
-
off: (event: string, callback: AddonEventListener) => void;
|
|
425
|
-
};
|
|
426
|
-
/**
|
|
427
|
-
* The list of fonts available in this JChat deployment, as configured by the site administrator.
|
|
428
|
-
* Use this to build a font picker or apply a matching font family in your addon UI.
|
|
429
|
-
*/
|
|
430
|
-
supportedFonts?: AddonFont[];
|
|
431
|
-
/** The active user locale (e.g. 'en', 'ta', 'ar') */
|
|
432
|
-
locale: string;
|
|
433
|
-
/** Text direction for the active locale ('ltr' or 'rtl') */
|
|
434
|
-
dir: "ltr" | "rtl";
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Seed data for your addon's tables, provided inside the addon's isolated schema.
|
|
438
|
-
*
|
|
439
|
-
* These documents are inserted into the addon's dedicated schema on installation and can be used to
|
|
440
|
-
* provide default values, references, or supporting data. The host guarantees that these documents
|
|
441
|
-
* do not conflict with core schemas or other addons.
|
|
442
|
-
*/
|
|
443
|
-
interface AddonSeedDocument {
|
|
444
|
-
/** Addon-owned table name. Core prefixes the addon's isolated PostgreSQL schema. */
|
|
445
|
-
table: string;
|
|
446
|
-
/** Behavior when a row conflicts with an existing unique or primary key. */
|
|
447
|
-
conflict?: "error" | "ignore" | "update";
|
|
448
|
-
/** Required for update behavior; identifies the unique key used by ON CONFLICT. */
|
|
449
|
-
conflictColumns?: string[];
|
|
450
|
-
/** JSON-compatible rows inserted using parameterized values. */
|
|
451
|
-
rows: Record<string, unknown>[];
|
|
452
|
-
}
|
|
453
|
-
/** Define a manifest with full validation-friendly typing while preserving literal values. */
|
|
454
|
-
declare function defineAddonManifest<const TManifest extends AddonManifest>(manifest: TManifest): TManifest;
|
|
455
|
-
/** Define a typed server factory without widening its addon database interface. */
|
|
456
|
-
declare function defineAddonServer<TDatabase = Record<string, Record<string, unknown>>>(factory: AddonServerFactory<TDatabase>): AddonServerFactory<TDatabase>;
|
|
457
|
-
/**
|
|
458
|
-
* Access the host application's SDK. Provides authenticated API access, toast notifications, and
|
|
459
|
-
* navigation.
|
|
460
|
-
*
|
|
461
|
-
* This function is a shell; the real implementation is provided by the Jchat host environment at
|
|
462
|
-
* runtime.
|
|
463
|
-
*
|
|
464
|
-
* @example
|
|
465
|
-
* ;```tsx
|
|
466
|
-
* import { useAddonSDK } from "@jchat/addon-sdk"
|
|
467
|
-
*
|
|
468
|
-
* export default function MyAddon({ mountPoint }: AddonProps) {
|
|
469
|
-
* const sdk = useAddonSDK()
|
|
470
|
-
*
|
|
471
|
-
* const handleClick = async () => {
|
|
472
|
-
* const data = await sdk.api.get("/trending")
|
|
473
|
-
* sdk.toast("Fetched trending posts!", "success")
|
|
474
|
-
* }
|
|
475
|
-
* }
|
|
476
|
-
* ```
|
|
477
|
-
*/
|
|
478
|
-
declare function useAddonSDK(): AddonSDK;
|
|
479
|
-
/**
|
|
480
|
-
* Access the host application's active icon pack. Returns the icon set matching the site's
|
|
481
|
-
* configured icon pack preference.
|
|
482
|
-
*
|
|
483
|
-
* This function is a shell; the real implementation is provided by the Jchat host environment at
|
|
484
|
-
* runtime.
|
|
485
|
-
*
|
|
486
|
-
* @example
|
|
487
|
-
* ;```tsx
|
|
488
|
-
* import { useIcons } from "@jchat/addon-sdk"
|
|
489
|
-
*
|
|
490
|
-
* export default function MyAddon() {
|
|
491
|
-
* const { Icons } = useIcons()
|
|
492
|
-
* return <Icons.Send className="size-5" />
|
|
493
|
-
* }
|
|
494
|
-
* ```
|
|
495
|
-
*/
|
|
496
|
-
declare function useIcons(): {
|
|
497
|
-
Icons: IconPack;
|
|
8
|
+
declare const fa6Pack: IconPack;
|
|
9
|
+
declare const heroPack: IconPack;
|
|
10
|
+
declare const phosphorPack: IconPack;
|
|
11
|
+
declare const IconPackName: {
|
|
12
|
+
readonly LUCIDE: "lucide";
|
|
498
13
|
};
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
* ;```tsx
|
|
505
|
-
* import { getAddonSdkVersion } from "@jchat/addon-sdk"
|
|
506
|
-
*
|
|
507
|
-
* console.log(getAddonSdkVersion())
|
|
508
|
-
* ```
|
|
509
|
-
*
|
|
510
|
-
* @returns
|
|
511
|
-
*/
|
|
512
|
-
declare function getAddonSdkVersion(): string;
|
|
14
|
+
type IconPackName = (typeof IconPackName)[keyof typeof IconPackName];
|
|
15
|
+
declare const getIconPack: (_name?: string) => IconPack;
|
|
16
|
+
declare const isIconName: (value: string) => value is IconName;
|
|
17
|
+
declare function resolveIcon(packOrName?: IconPack | string, nameOrFallback?: string | IconName, fallback?: IconName): IconComponent;
|
|
18
|
+
declare const Icons: IconPack;
|
|
513
19
|
//#endregion
|
|
514
|
-
export {
|
|
20
|
+
export { getIconPack as a, lucidePack as c, fa6Pack as i, phosphorPack as l, Icons as n, heroPack as o, Youtube as r, isIconName as s, IconPackName as t, resolveIcon as u };
|