@jchat/addon-sdk 0.0.1
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/LICENSE +201 -0
- package/README.md +45 -0
- package/dist/contracts.d.mts +130 -0
- package/dist/diagnostics.d.mts +22 -0
- package/dist/diagnostics.mjs +1 -0
- package/dist/index.d.mts +240 -0
- package/dist/index.mjs +1 -0
- package/dist/vite.d.mts +29 -0
- package/dist/vite.mjs +10 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Md. Jabarullah
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @jchat/addon-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for building [JChat](https://jchat.app) addons.
|
|
4
|
+
|
|
5
|
+
Provides types, interfaces, and Vite build helpers for addon developers. This package is always
|
|
6
|
+
**externalised** from addon bundles — the JChat host app provides the runtime implementation at
|
|
7
|
+
load time.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @jchat/addon-sdk
|
|
13
|
+
# or
|
|
14
|
+
bun add @jchat/addon-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- Node.js 20+ or Bun 1.3+
|
|
20
|
+
- React 18+, Elysia, Kysely, and Vite as peer dependencies
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import type {
|
|
26
|
+
AddonManifest,
|
|
27
|
+
AddonServerContext,
|
|
28
|
+
AddonClientContext,
|
|
29
|
+
AddonProps,
|
|
30
|
+
} from "@jchat/addon-sdk"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For the Vite build plugin:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { jchatAddon } from "@jchat/addon-sdk/vite"
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
plugins: [jchatAddon()],
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Apache-2.0
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/contracts.d.ts
|
|
2
|
+
type AddonPermission = string;
|
|
3
|
+
/**
|
|
4
|
+
* Defines a single configuration field for an addon's settings panel. These are shown to site
|
|
5
|
+
* admins in the Jchat dashboard.
|
|
6
|
+
*/
|
|
7
|
+
interface ConfigSchemaField {
|
|
8
|
+
/** Unique key used to store and retrieve the value in `getConfig` */
|
|
9
|
+
key: string;
|
|
10
|
+
/** Data type for validation and UI rendering */
|
|
11
|
+
type: "string" | "number" | "boolean";
|
|
12
|
+
/** Human-readable label shown in the settings UI */
|
|
13
|
+
label: string;
|
|
14
|
+
/** If true, the admin must provide a value before saving */
|
|
15
|
+
required?: boolean;
|
|
16
|
+
/** Whether the value is sensitive (encrypted at rest and masked in the UI) */
|
|
17
|
+
secret?: boolean;
|
|
18
|
+
/** Default value pre-filled in the settings form for new installations */
|
|
19
|
+
default?: string | number | boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Definition of a custom permission introduced by an addon. */
|
|
22
|
+
interface AddonPermissionDefinition {
|
|
23
|
+
/** Permission identifier (recommended: `addon.<id>.<action>`) */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Short, human-readable name for the permission */
|
|
26
|
+
label: string;
|
|
27
|
+
/** Detailed description of what the permission grants (shown in Rank editor) */
|
|
28
|
+
description: string;
|
|
29
|
+
}
|
|
30
|
+
/** Valid locations where an addon can be rendered within the Jchat layout. */
|
|
31
|
+
declare const MOUNT_POINTS: {
|
|
32
|
+
/** Top of the main chat column */
|
|
33
|
+
readonly CHAT_HEADER: "chat-header";
|
|
34
|
+
/** Below the main chat header, above messages */
|
|
35
|
+
readonly CHAT_TOOLBAR: "chat-toolbar";
|
|
36
|
+
/** The persistent right-side sidebar */
|
|
37
|
+
readonly CHAT_SIDEBAR: "chat-sidebar";
|
|
38
|
+
/** Top of the left sidebar (room list) */
|
|
39
|
+
readonly SIDEBAR_TOP: "sidebar-top";
|
|
40
|
+
/** Bottom of the left sidebar */
|
|
41
|
+
readonly SIDEBAR_BOTTOM: "sidebar-bottom";
|
|
42
|
+
/** Action list shown when clicking a user's avatar */
|
|
43
|
+
readonly USER_POPOVER_ACTIONS: "user-popover-actions";
|
|
44
|
+
/** Menu shown when right-clicking a message */
|
|
45
|
+
readonly MESSAGE_CONTEXT_MENU: "message-context-menu";
|
|
46
|
+
/** Floating overlay rendered on top of the message stream */
|
|
47
|
+
readonly MESSAGE_FEED_OVERLAY: "message-feed-overlay";
|
|
48
|
+
/** Main admin dashboard area */
|
|
49
|
+
readonly ADMIN_PANEL: "admin-panel";
|
|
50
|
+
/** User or site settings dashboard area */
|
|
51
|
+
readonly SETTINGS_PANEL: "settings-panel";
|
|
52
|
+
/** The 'plus' (+) menu in the message composer */
|
|
53
|
+
readonly CHAT_PLUS_MENU: "chat-plus-menu";
|
|
54
|
+
/** Custom tab in the emoji/gif selection panel */
|
|
55
|
+
readonly EMOJI_PICKER_GIF_TAB: "emoji-picker-gif-tab";
|
|
56
|
+
/** Full-screen or modal dialog specifically for TubeScan */
|
|
57
|
+
readonly TUBESCAN_DIALOG: "tubescan-dialog";
|
|
58
|
+
};
|
|
59
|
+
/** Union type of all valid addon mount points. */
|
|
60
|
+
type MountPoint = (typeof MOUNT_POINTS)[keyof typeof MOUNT_POINTS];
|
|
61
|
+
/**
|
|
62
|
+
* The `manifest.json` schema required for every Jchat addon. This file describes how the addon is
|
|
63
|
+
* identified and mounted.
|
|
64
|
+
*/
|
|
65
|
+
interface AddonManifest {
|
|
66
|
+
/** Unique kebab-case addon identifier (must match the folder name) */
|
|
67
|
+
id: string;
|
|
68
|
+
/** Human-readable addon name */
|
|
69
|
+
name: string;
|
|
70
|
+
/** Semver version string (e.g. `1.2.0`) */
|
|
71
|
+
version: string;
|
|
72
|
+
/** Brief summary of what the addon does */
|
|
73
|
+
description?: string;
|
|
74
|
+
/** Author name, organization, or GitHub handle */
|
|
75
|
+
author?: string;
|
|
76
|
+
/** Support or documentation URL */
|
|
77
|
+
homepage?: string;
|
|
78
|
+
/** SPDX license identifier (e.g. `MIT`) */
|
|
79
|
+
license?: string;
|
|
80
|
+
/** Host and SDK versions this directly executed plugin was built and tested against */
|
|
81
|
+
compatibility: {
|
|
82
|
+
/** Supported JChat versions as a semantic-version range, for example `^1.0.0` */
|
|
83
|
+
jchat: string;
|
|
84
|
+
/** Supported `@jchat/addon-sdk` versions as a semantic-version range */
|
|
85
|
+
addonSdk: string;
|
|
86
|
+
};
|
|
87
|
+
/** Identity of the trusted publisher that signed this package. Required when migrations exist */
|
|
88
|
+
publisher?: {
|
|
89
|
+
id: string;
|
|
90
|
+
};
|
|
91
|
+
/** Signature over the canonical archive digest. Required when migrations exist */
|
|
92
|
+
signature?: {
|
|
93
|
+
algorithm: "rsa-sha256";
|
|
94
|
+
digest: string;
|
|
95
|
+
value: string;
|
|
96
|
+
};
|
|
97
|
+
/** Configuration for the React-based frontend bundle */
|
|
98
|
+
frontend?: {
|
|
99
|
+
/** Relative path to the pre-compiled ESM bundle (created by Vite) */
|
|
100
|
+
bundle: string;
|
|
101
|
+
/** List of UI locations where this addon should be active */
|
|
102
|
+
mountPoints: MountPoint[];
|
|
103
|
+
/** Optional path to a specific UI for the settings panel */
|
|
104
|
+
settings?: string;
|
|
105
|
+
/** Additional shared packages this addon imports from the host */
|
|
106
|
+
externals?: string[];
|
|
107
|
+
};
|
|
108
|
+
/** Configuration for the server-side API bundle */
|
|
109
|
+
server?: {
|
|
110
|
+
/** Relative path to the pre-compiled server bundle */
|
|
111
|
+
bundle?: string;
|
|
112
|
+
/** List of SQL files to run (in order) to set up the addon's database tables */
|
|
113
|
+
migrations?: string[];
|
|
114
|
+
/** List of declarative JSON master-data files to apply once, in order */
|
|
115
|
+
seeds?: string[];
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* The minimum permission required to see or use this addon. If provided, the host gates
|
|
119
|
+
* visibility in the UI and access to all server routes.
|
|
120
|
+
*/
|
|
121
|
+
accessPermission?: AddonPermission;
|
|
122
|
+
/** Full list of all permissions used by this addon for informational purposes */
|
|
123
|
+
permissions?: AddonPermission[];
|
|
124
|
+
/** Custom permissions that should be registered with the host application on installation */
|
|
125
|
+
permissionDefinitions?: AddonPermissionDefinition[];
|
|
126
|
+
/** Settings form structure shown to site admins. Values are stored encrypted per site */
|
|
127
|
+
configSchema?: ConfigSchemaField[];
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { MOUNT_POINTS as a, ConfigSchemaField as i, AddonPermission as n, MountPoint as o, AddonPermissionDefinition as r, AddonManifest as t };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as AddonManifest } from "./contracts.mjs";
|
|
2
|
+
//#region src/diagnostics.d.ts
|
|
3
|
+
type AddonDiagnosticStatus = "pass" | "warning" | "error";
|
|
4
|
+
interface AddonPackageDiagnostic {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
status: AddonDiagnosticStatus;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
interface AddonPackageDiagnosticOptions {
|
|
11
|
+
buildDir: string;
|
|
12
|
+
manifest: AddonManifest;
|
|
13
|
+
jchatVersion: string;
|
|
14
|
+
addonSdkVersion: string;
|
|
15
|
+
productionPackage?: boolean;
|
|
16
|
+
maxBytes?: number;
|
|
17
|
+
}
|
|
18
|
+
declare function createCompatibleMajorRange(version: string): string;
|
|
19
|
+
declare function diagnoseAddonPackage(options: AddonPackageDiagnosticOptions): AddonPackageDiagnostic[];
|
|
20
|
+
declare function hasAddonDiagnosticErrors(diagnostics: readonly AddonPackageDiagnostic[]): boolean;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { AddonDiagnosticStatus, AddonPackageDiagnostic, AddonPackageDiagnosticOptions, createCompatibleMajorRange, diagnoseAddonPackage, hasAddonDiagnosticErrors };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"node:fs";import*as t from"node:path";function n(e){try{Bun.semver.order(e,e)}catch{throw Error(`Invalid semantic version: ${e}`)}let t=/^(?:v|=)?(\d+)\./.exec(e)?.[1],n=t?Number(t):NaN;if(!Number.isSafeInteger(n))throw Error(`Invalid semantic version: ${e}`);return`>=${e} <${n+1}.0.0`}function r(n){let{buildDir:r,manifest:i}=n,c=[];c.push(a(`jchat`,`JChat compatibility`,n.jchatVersion,i.compatibility?.jchat),a(`addon-sdk`,`Addon SDK compatibility`,n.addonSdkVersion,i.compatibility?.addonSdk));let l=[[`frontend-bundle`,`Frontend bundle`,i.frontend?.bundle],[`server-bundle`,`Server bundle`,i.server?.bundle],...(i.server?.migrations??[]).map(e=>[`migration:${e}`,`Migration ${e}`,e]),...(i.server?.seeds??[]).map(e=>[`seed:${e}`,`Seed ${e}`,e])];for(let[t,n,i]of l){if(!i)continue;let a=o(r,i);c.push({id:t,label:n,status:a&&e.existsSync(a)&&e.statSync(a).isFile()?`pass`:`error`,message:a&&e.existsSync(a)&&e.statSync(a).isFile()?i:`Missing or unsafe build file: ${i}`})}let u=s(r),d=t.join(r,`${i.id}-${i.version}.zip`),f=e.existsSync(d)&&e.statSync(d).isFile(),p=n.productionPackage&&f?e.statSync(d).size:u.filter(e=>e!==d).reduce((t,n)=>t+e.statSync(n).size,0),m=n.maxBytes??25*1024*1024;c.push({id:`package-size`,label:`Package size`,status:p<=m?`pass`:`error`,message:`${p} of ${m} bytes`});let h=u.filter(e=>e.endsWith(`.map`));c.push({id:`source-maps`,label:`Source maps`,status:n.productionPackage&&h.length?`warning`:`pass`,message:h.length?`${h.length} source map(s) present`:`No source maps`});let g=!!(i.server?.migrations?.length||i.server?.seeds?.length);return c.push({id:`database-signature`,label:`Database file signature`,status:g&&n.productionPackage&&!i.signature?.value?`error`:g&&!i.signature?.value?`warning`:`pass`,message:g&&!i.signature?.value?n.productionPackage?`Production database files require a publisher signature`:`Unsigned database files are allowed only in the developer sandbox`:g?`Publisher signature present`:`No database files declared`}),n.productionPackage&&c.push({id:`production-archive`,label:`Production archive`,status:f?`pass`:`error`,message:f?t.basename(d):`Production archive is missing`}),c}function i(e){return e.some(({status:e})=>e===`error`)}function a(e,t,n,r){let i=!!(r&&Bun.semver.satisfies(n,r));return{id:e,label:t,status:i?`pass`:`error`,message:r?`${n} ${i?`satisfies`:`does not satisfy`} ${r}`:`Compatibility range is missing`}}function o(e,n){if(t.isAbsolute(n)||n.includes(`\\`)||n.split(`/`).includes(`..`))return null;let r=t.resolve(e,...n.replace(/^\.\//,``).split(`/`)),i=t.relative(t.resolve(e),r);return i&&!i.startsWith(`..`)&&!t.isAbsolute(i)?r:null}function s(n){return e.existsSync(n)?e.readdirSync(n,{recursive:!0,withFileTypes:!0}).filter(e=>e.isFile()).map(e=>t.join(e.parentPath,e.name)):[]}export{n as createCompatibleMajorRange,r as diagnoseAddonPackage,i as hasAddonDiagnosticErrors};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { a as MOUNT_POINTS, i as ConfigSchemaField, n as AddonPermission, o as MountPoint, r as AddonPermissionDefinition, t as AddonManifest } from "./contracts.mjs";
|
|
2
|
+
import { ComponentType, SVGProps } from "react";
|
|
3
|
+
import { Elysia } from "elysia";
|
|
4
|
+
import { Kysely } from "kysely";
|
|
5
|
+
//#region ../icon/dist/index.d.mts
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
type IconComponent = ComponentType<SVGProps<SVGSVGElement>>;
|
|
8
|
+
declare const ICON_NAMES: readonly ["ProfileMen", "ProfileWomen", "Stories", "Search", "AdminPanel", "Investigation", "Logout", "Users", "Settings", "RoomList", "AdminShip", "Announcement", "NewsFeed", "Ranks", "TopPoints", "Like", "DisLike", "Love", "Funny", "Comment", "Chat", "Brush", "Image", "Mic", "More", "Palette", "Smiley", "Send", "Private", "Action", "View", "Female", "Male", "LuSend", "Heart", "Trash", "HorizontalOption", "Menu", "UserGroup", "Globe", "Plus", "Loader", "X", "UserRoundPlus", "Footprints", "Calendar", "Volume", "Youtube", "Upload", "Play", "Pause", "Stop", "Ok", "ImageFill", "MicFill", "YoutubeFill", "PlusFill", "Music", "Gift", "Camera", "Envelope", "Key", "Signature", "UserPen", "Edit", "AddressCard", "Star", "StatusOnline", "StatusAway", "StatusBusy", "StatusEating", "StatusGaming", "StatusSinging", "StatusListening", "StatusStay"];
|
|
9
|
+
type IconName = (typeof ICON_NAMES)[number];
|
|
10
|
+
type IconPack = Record<IconName, IconComponent>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/index.d.ts
|
|
13
|
+
type AddonJsonBody = Record<string, unknown> | unknown[] | null;
|
|
14
|
+
/**
|
|
15
|
+
* @jchat/addon-sdk
|
|
16
|
+
*
|
|
17
|
+
* Lightweight SDK for Jchat addon developers. Provides TypeScript types for addon props, manifest
|
|
18
|
+
* schema, and host API access. This package is always EXTERNALISED from addon bundles — the host
|
|
19
|
+
* app provides the runtime implementation.
|
|
20
|
+
*/
|
|
21
|
+
/** Minimal user profile accessible to addon backends. */
|
|
22
|
+
interface AddonUser {
|
|
23
|
+
/** Unique user identifier */
|
|
24
|
+
id: string;
|
|
25
|
+
/** Display name */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Full display name */
|
|
28
|
+
displayName: string;
|
|
29
|
+
/** Full URL to the user's avatar image */
|
|
30
|
+
avatar: string;
|
|
31
|
+
/** User's gender identifier */
|
|
32
|
+
gender: string;
|
|
33
|
+
}
|
|
34
|
+
interface AddonRequestUser {
|
|
35
|
+
id?: string;
|
|
36
|
+
permissions?: string[];
|
|
37
|
+
siteId?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Typed, schema-scoped database facade for an addon. The host deliberately omits raw execution,
|
|
41
|
+
* schema switching, dialect/connection access, and lifecycle methods.
|
|
42
|
+
*/
|
|
43
|
+
type AddonDatabase<TDatabase = Record<string, Record<string, unknown>>> = Pick<Kysely<TDatabase>, "deleteFrom" | "fn" | "insertInto" | "selectFrom" | "transaction" | "updateTable">;
|
|
44
|
+
/**
|
|
45
|
+
* Context provided to an addon's server-side factory. Parameterize it with the addon's table
|
|
46
|
+
* interface: `AddonServerContext<MyAddonDatabase>`.
|
|
47
|
+
*/
|
|
48
|
+
interface AddonServerContext<TDatabase = Record<string, Record<string, unknown>>> {
|
|
49
|
+
/**
|
|
50
|
+
* Retrieve the encrypted settings for this addon for a specific site. Internal secrets are
|
|
51
|
+
* automatically decrypted using the host's master key.
|
|
52
|
+
*/
|
|
53
|
+
getConfig: (siteId: string) => Promise<Record<string, unknown>>;
|
|
54
|
+
/** Fetch a specific user's public profile */
|
|
55
|
+
getUser: (userId: string) => Promise<AddonUser | null>;
|
|
56
|
+
/** Efficiently fetch multiple user profiles in a single query. Returns a Map keyed by user ID. */
|
|
57
|
+
getUsers: (userIds: string[]) => Promise<Map<string, AddonUser>>;
|
|
58
|
+
/**
|
|
59
|
+
* Check whether the request user holds a given permission. Provides autocomplete for core Jchat
|
|
60
|
+
* permissions while also accepting any custom addon permission string.
|
|
61
|
+
*
|
|
62
|
+
* @param user - The user object from the request context
|
|
63
|
+
* @param permission - The permission to check, e.g., 'message.send' or 'addon.stories.view'
|
|
64
|
+
*/
|
|
65
|
+
hasPermission: (user: AddonRequestUser | null | undefined, permission: AddonPermission) => boolean;
|
|
66
|
+
/**
|
|
67
|
+
* A Kysely database instance scoped entirely to your addon's tables. You cannot access core Jchat
|
|
68
|
+
* tables (Users, Rooms, etc.) through this instance.
|
|
69
|
+
*/
|
|
70
|
+
db: AddonDatabase<TDatabase>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The entry point for your addon's server bundle. You should default-export a function matching
|
|
74
|
+
* this signature.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ;```ts
|
|
78
|
+
* import { type AddonServerFactory } from '@jchat/addon-sdk'
|
|
79
|
+
*
|
|
80
|
+
* const factory: AddonServerFactory = ({ db, hasPermission }, app) => {
|
|
81
|
+
* return app.get('/trending', async () => { ... })
|
|
82
|
+
* }
|
|
83
|
+
* export default factory
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
type AddonServerFactory<TDatabase = Record<string, Record<string, unknown>>> = (ctx: AddonServerContext<TDatabase>, app: Elysia) => Elysia;
|
|
87
|
+
/** Props passed to your addon's root React component by the Jchat host. */
|
|
88
|
+
interface AddonProps {
|
|
89
|
+
/** The mount point where this addon instance is rendered (e.g., 'chat-sidebar') */
|
|
90
|
+
mountPoint: MountPoint;
|
|
91
|
+
/** Information about the currently logged-in user (if any) */
|
|
92
|
+
user?: {
|
|
93
|
+
id: string;
|
|
94
|
+
name: string;
|
|
95
|
+
displayName?: string;
|
|
96
|
+
avatar?: string;
|
|
97
|
+
gender?: string;
|
|
98
|
+
};
|
|
99
|
+
/** The ID of the room the user is currently viewing (if applicable) */
|
|
100
|
+
roomId?: string;
|
|
101
|
+
/** The ID of the active Jchat site */
|
|
102
|
+
siteId?: string;
|
|
103
|
+
}
|
|
104
|
+
interface AddonApi {
|
|
105
|
+
get: <TResponse = unknown>(path: string) => Promise<TResponse>;
|
|
106
|
+
post: <TResponse = unknown>(path: string, body?: AddonJsonBody) => Promise<TResponse>;
|
|
107
|
+
put: <TResponse = unknown>(path: string, body?: AddonJsonBody) => Promise<TResponse>;
|
|
108
|
+
delete: <TResponse = unknown>(path: string) => Promise<TResponse>;
|
|
109
|
+
}
|
|
110
|
+
type AddonEventListener = (data: unknown) => void;
|
|
111
|
+
/**
|
|
112
|
+
* The bridge between your addon and the Jchat host application. Use the `useAddonSDK()` hook to
|
|
113
|
+
* access this interface in your components.
|
|
114
|
+
*/
|
|
115
|
+
interface AddonSDK {
|
|
116
|
+
/**
|
|
117
|
+
* Make authenticated API calls to your addon's backend or core Jchat endpoints. All calls
|
|
118
|
+
* automatically include the current user's sessionId and site validation headers.
|
|
119
|
+
*/
|
|
120
|
+
api: AddonApi;
|
|
121
|
+
/**
|
|
122
|
+
* Display a temporary notification toast in the host UI.
|
|
123
|
+
*
|
|
124
|
+
* @param message - The text content to display
|
|
125
|
+
* @param variant - Visual style: 'default' (blue), 'success' (green), or 'error' (red)
|
|
126
|
+
*/
|
|
127
|
+
toast: (message: string, variant?: "default" | "success" | "error") => void;
|
|
128
|
+
/**
|
|
129
|
+
* Navigate the host application to a different internal route.
|
|
130
|
+
*
|
|
131
|
+
* @param path - The target location, e.g., '/settings' or '/addons/store'
|
|
132
|
+
*/
|
|
133
|
+
navigate: (path: string) => void;
|
|
134
|
+
/**
|
|
135
|
+
* Interaction utilities for the active Slate message editor. Only available if your addon is
|
|
136
|
+
* mounted near the chat input.
|
|
137
|
+
*/
|
|
138
|
+
editor: {
|
|
139
|
+
/**
|
|
140
|
+
* Trigger a specialized editor command defined by the host.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* sdk.editor.dispatchCommand("INSERT_YOUTUBE_COMMAND", "dQw4w9WgXcQ")
|
|
144
|
+
*/
|
|
145
|
+
dispatchCommand: (command: string, payload?: unknown) => void;
|
|
146
|
+
/**
|
|
147
|
+
* Insert a low-level Slate node directly at the user's cursor position.
|
|
148
|
+
*
|
|
149
|
+
* @param node - A valid Slate Descendant or Fragment object
|
|
150
|
+
*/
|
|
151
|
+
insertNode: (node: unknown) => void;
|
|
152
|
+
/**
|
|
153
|
+
* Upload and attach a file to the current message without inserting it inline. Users will see
|
|
154
|
+
* the file in the attachment bar below the editor.
|
|
155
|
+
*/
|
|
156
|
+
addAttachment: (attachment: {
|
|
157
|
+
url: string;
|
|
158
|
+
name: string;
|
|
159
|
+
type: string;
|
|
160
|
+
}) => void;
|
|
161
|
+
/** Force the browser focus back to the editor input */
|
|
162
|
+
focus: () => void;
|
|
163
|
+
};
|
|
164
|
+
/** Event Bus for reacting to real-time application state changes. */
|
|
165
|
+
events: {
|
|
166
|
+
/**
|
|
167
|
+
* Register a persistent listener for a specific event.
|
|
168
|
+
*
|
|
169
|
+
* @param event - Event name, e.g., 'room.message', 'user.typing'
|
|
170
|
+
*/
|
|
171
|
+
on: (event: string, callback: AddonEventListener) => void;
|
|
172
|
+
/** Unregister a previously attached listener */
|
|
173
|
+
off: (event: string, callback: AddonEventListener) => void;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Seed data for your addon's tables, provided inside the addon's isolated schema.
|
|
178
|
+
*
|
|
179
|
+
* These documents are inserted into the addon's dedicated schema on installation and can be used to
|
|
180
|
+
* provide default values, references, or supporting data. The host guarantees that these documents
|
|
181
|
+
* do not conflict with core schemas or other addons.
|
|
182
|
+
*/
|
|
183
|
+
interface AddonSeedDocument {
|
|
184
|
+
/** Addon-owned table name. Core prefixes the addon's isolated PostgreSQL schema. */
|
|
185
|
+
table: string;
|
|
186
|
+
/** Behavior when a row conflicts with an existing unique or primary key. */
|
|
187
|
+
conflict?: "error" | "ignore" | "update";
|
|
188
|
+
/** Required for update behavior; identifies the unique key used by ON CONFLICT. */
|
|
189
|
+
conflictColumns?: string[];
|
|
190
|
+
/** JSON-compatible rows inserted using parameterized values. */
|
|
191
|
+
rows: Record<string, unknown>[];
|
|
192
|
+
}
|
|
193
|
+
/** Define a manifest with full validation-friendly typing while preserving literal values. */
|
|
194
|
+
declare function defineAddonManifest<const TManifest extends AddonManifest>(manifest: TManifest): TManifest;
|
|
195
|
+
/** Define a typed server factory without widening its addon database interface. */
|
|
196
|
+
declare function defineAddonServer<TDatabase = Record<string, Record<string, unknown>>>(factory: AddonServerFactory<TDatabase>): AddonServerFactory<TDatabase>;
|
|
197
|
+
/**
|
|
198
|
+
* Access the host application's SDK. Provides authenticated API access, toast notifications, and
|
|
199
|
+
* navigation.
|
|
200
|
+
*
|
|
201
|
+
* This function is a shell; the real implementation is provided by the Jchat host environment at
|
|
202
|
+
* runtime.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ;```tsx
|
|
206
|
+
* import { useAddonSDK } from "@jchat/addon-sdk"
|
|
207
|
+
*
|
|
208
|
+
* export default function MyAddon({ mountPoint }: AddonProps) {
|
|
209
|
+
* const sdk = useAddonSDK()
|
|
210
|
+
*
|
|
211
|
+
* const handleClick = async () => {
|
|
212
|
+
* const data = await sdk.api.get("/trending")
|
|
213
|
+
* sdk.toast("Fetched trending posts!", "success")
|
|
214
|
+
* }
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
declare function useAddonSDK(): AddonSDK;
|
|
219
|
+
/**
|
|
220
|
+
* Access the host application's active icon pack. Returns the icon set matching the site's
|
|
221
|
+
* configured icon pack preference.
|
|
222
|
+
*
|
|
223
|
+
* This function is a shell; the real implementation is provided by the Jchat host environment at
|
|
224
|
+
* runtime.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ;```tsx
|
|
228
|
+
* import { useIcons } from "@jchat/addon-sdk"
|
|
229
|
+
*
|
|
230
|
+
* export default function MyAddon() {
|
|
231
|
+
* const { Icons } = useIcons()
|
|
232
|
+
* return <Icons.Send className="size-5" />
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function useIcons(): {
|
|
237
|
+
Icons: IconPack;
|
|
238
|
+
};
|
|
239
|
+
//#endregion
|
|
240
|
+
export { AddonApi, AddonDatabase, AddonEventListener, AddonJsonBody, type AddonManifest, type AddonPermission, type AddonPermissionDefinition, AddonProps, AddonRequestUser, AddonSDK, AddonSeedDocument, AddonServerContext, AddonServerFactory, AddonUser, type ConfigSchemaField, MOUNT_POINTS, type MountPoint, defineAddonManifest, defineAddonServer, useAddonSDK, useIcons };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={CHAT_HEADER:`chat-header`,CHAT_TOOLBAR:`chat-toolbar`,CHAT_SIDEBAR:`chat-sidebar`,SIDEBAR_TOP:`sidebar-top`,SIDEBAR_BOTTOM:`sidebar-bottom`,USER_POPOVER_ACTIONS:`user-popover-actions`,MESSAGE_CONTEXT_MENU:`message-context-menu`,MESSAGE_FEED_OVERLAY:`message-feed-overlay`,ADMIN_PANEL:`admin-panel`,SETTINGS_PANEL:`settings-panel`,CHAT_PLUS_MENU:`chat-plus-menu`,EMOJI_PICKER_GIF_TAB:`emoji-picker-gif-tab`,TUBESCAN_DIALOG:`tubescan-dialog`};function t(e){return e}function n(e){return e}function r(){throw Error(`AddonSDK must be used within the Jchat host environment.`)}function i(){throw Error(`useIcons must be used within the Jchat host environment.`)}export{e as MOUNT_POINTS,t as defineAddonManifest,n as defineAddonServer,r as useAddonSDK,i as useIcons};
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as AddonManifest } from "./contracts.mjs";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
//#region src/vite.d.ts
|
|
4
|
+
interface EmbedCssOptions {
|
|
5
|
+
id?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Vite plugin that gathers CSS styles generated by Tailwind CSS and embeds them directly inside the
|
|
9
|
+
* main UI JavaScript bundle at the top, avoiding the need to load external stylesheet files.
|
|
10
|
+
*/
|
|
11
|
+
declare function jchatEmbedCss(options?: EmbedCssOptions): Plugin;
|
|
12
|
+
interface JchatAddonPluginOptions {
|
|
13
|
+
manifest: AddonManifest;
|
|
14
|
+
zip?: boolean;
|
|
15
|
+
signingPrivateKey?: string;
|
|
16
|
+
}
|
|
17
|
+
declare function createAddonServerBuildArguments(entryPath: string, outputPath: string, developmentBuild: boolean): string[];
|
|
18
|
+
declare function signAddonManifest(manifest: AddonManifest, files: readonly {
|
|
19
|
+
path: string;
|
|
20
|
+
contents: Buffer;
|
|
21
|
+
}[], privateKey: string): AddonManifest;
|
|
22
|
+
declare function requireAddonSigningKey(signingPrivateKey: string | undefined, developmentBuild: boolean): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Vite plugin to configure Jchat addon manifest generation, bundle backend scripts, copy
|
|
25
|
+
* migrations, declarative seed data, and zip production build artifacts.
|
|
26
|
+
*/
|
|
27
|
+
declare function jchatAddon(options: JchatAddonPluginOptions): Plugin;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { EmbedCssOptions, JchatAddonPluginOptions, createAddonServerBuildArguments, jchatAddon, jchatEmbedCss, requireAddonSigningKey, signAddonManifest };
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{execFileSync as n}from"node:child_process";import r from"node:crypto";function i(n){return{name:`jchat-embed-css`,apply:`build`,writeBundle(){let r=t.resolve(process.cwd(),`build`);if(!e.existsSync(r))return;let i=e.readdirSync(r),a=i.find(e=>e.endsWith(`.css`)),o=i.find(e=>e.includes(`ui`)&&e.endsWith(`.js`));if(!a||!o)return;let s=t.join(r,a),c=t.join(r,o),l=e.readFileSync(s,`utf-8`),u=e.readFileSync(c,`utf-8`);l.length<10?l=``:n?.id&&(l=l.replace(/:root\s*\{[^}]+\}/g,``),l=l.replace(/\.dark\s*\{[^}]+\}/g,``),l=l.replace(/\[data-theme=[^\]]+\]\s*\{[^}]+\}/g,``),l=l.replace(/\.dark\s*\[data-theme=[^\]]+\]\s*\{[^}]+\}/g,``),l=`@scope (#addon-${n.id}) {\n*, ::before, ::after { border-color: var(--border); }\n${l}\n}`),u=`
|
|
2
|
+
(function() {
|
|
3
|
+
if (typeof document !== 'undefined' && ${JSON.stringify(l)}.length > 0) {
|
|
4
|
+
const style = document.createElement('style');
|
|
5
|
+
style.type = 'text/css';
|
|
6
|
+
style.textContent = ${JSON.stringify(l)};
|
|
7
|
+
document.head.appendChild(style);
|
|
8
|
+
}
|
|
9
|
+
})();
|
|
10
|
+
`+u,e.writeFileSync(c,u);try{e.unlinkSync(s)}catch{}}}}function a(e,t,n){return[`build`,e,`--target=bun`,`--format=esm`,`--outfile=${t}`,n?`--sourcemap=external`:`--minify`]}function o(e){let t=e=>Array.isArray(e)?e.map(t):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>[e,t(n)])):e;return JSON.stringify(t(e))}function s(e,t,n){if(!e.publisher?.id)throw Error(`Signed addons require manifest.publisher.id`);let i={...e,signature:{algorithm:`rsa-sha256`,digest:``,value:``}},a=r.createHash(`sha256`);for(let e of[...t].sort((e,t)=>e.path.localeCompare(t.path)))a.update(e.path),a.update(`\0`),a.update(e.path===`manifest.json`?o(i):e.contents),a.update(`\0`);let s=a.digest(`hex`);return{...i,signature:{algorithm:`rsa-sha256`,digest:s,value:r.sign(`sha256`,Buffer.from(s),n).toString(`base64url`)}}}function c(e,t){if(e)return e;if(!t)throw Error(`Database-bearing addon builds require JCHAT_ADDON_SIGNING_PRIVATE_KEY`)}function l(r){let{manifest:i}=r,o=r.zip,l=!1;return{name:`jchat-addon`,apply:`build`,config(e,t){return{define:{"process.env.NODE_ENV":JSON.stringify(t.mode||`production`)}}},configResolved(e){l=e.mode===`development`,o===void 0&&(o=e.mode===`production`)},async writeBundle(){let u=process.cwd(),d=t.resolve(u,`package.json`);if(!e.existsSync(d))return;let f=JSON.parse(e.readFileSync(d,`utf-8`)),p=t.resolve(u,`build`);if(!e.existsSync(p))return;let m=e.readdirSync(p).find(e=>e.includes(`ui`)&&e.endsWith(`.js`));if(!m)return;let h={...i,version:f.version,frontend:{...i.frontend,bundle:`./${m}`,mountPoints:i.frontend?.mountPoints??[]}},g=t.resolve(u,`src/api.ts`),_=e.existsSync(g);_&&(n(`bun`,a(g,t.resolve(p,`api.js`),l),{stdio:`inherit`}),h={...h,server:{...h.server,bundle:`./api.js`}});let v=[...h.server?.migrations??[],...h.server?.seeds??[]];for(let n of[`migrations`,`seeds`])e.rmSync(t.resolve(p,n),{recursive:!0,force:!0});for(let n of v){if(t.isAbsolute(n)||n.includes(`\\`)||n.split(`/`).includes(`..`))throw Error(`Unsafe addon database file path: ${n}`);let r=t.resolve(u,n);if(!e.existsSync(r)||!e.statSync(r).isFile())throw Error(`Missing addon database file: ${n}`);let i=t.resolve(p,n);e.mkdirSync(t.dirname(i),{recursive:!0}),e.copyFileSync(r,i)}if(h.server?.migrations?.length||h.server?.seeds?.length){let n=c(r.signingPrivateKey??process.env.JCHAT_ADDON_SIGNING_PRIVATE_KEY,l);if(n){let r=[`manifest.json`,m,...h.server?.migrations??[],...h.server?.seeds??[]];_&&r.push(`api.js`),h=s(h,r.map(n=>({path:n,contents:n===`manifest.json`?Buffer.from(``):e.readFileSync(t.resolve(p,n))})),n)}}let y=JSON.stringify(h,null,2);if(e.writeFileSync(t.resolve(p,`manifest.json`),y),o){let r=`${h.id}-${f.version}.zip`,i=[`manifest.json`,m];e.existsSync(t.resolve(p,`api.js`))&&i.push(`api.js`);let a=t.resolve(p,`migrations`);e.existsSync(a)&&i.push(`migrations`);let o=t.resolve(p,`seeds`);e.existsSync(o)&&i.push(`seeds`),n(`tar`,[`-a`,`-cf`,r,...i],{cwd:p,stdio:`inherit`}),console.log(`Build Complete: ${h.id} v${f.version} → ${r}`)}}}}export{a as createAddonServerBuildArguments,l as jchatAddon,i as jchatEmbedCss,c as requireAddonSigningKey,s as signAddonManifest};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jchat/addon-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"addon",
|
|
7
|
+
"chat",
|
|
8
|
+
"elysia",
|
|
9
|
+
"jchat",
|
|
10
|
+
"plugin",
|
|
11
|
+
"sdk",
|
|
12
|
+
"vite"
|
|
13
|
+
],
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"import": "./dist/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./diagnostics": {
|
|
28
|
+
"types": "./dist/diagnostics.d.mts",
|
|
29
|
+
"import": "./dist/diagnostics.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./vite": {
|
|
32
|
+
"types": "./dist/vite.d.mts",
|
|
33
|
+
"import": "./dist/vite.mjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsdown",
|
|
41
|
+
"lint": "oxlint . --config=../../oxlint.json",
|
|
42
|
+
"format": "oxfmt . --write",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"prepack": "bun run build"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@jchat/icon": "1.0.0-alpha.1",
|
|
48
|
+
"@types/react": "^19.2.17",
|
|
49
|
+
"elysia": "^1.4.29",
|
|
50
|
+
"kysely": "^catalog:",
|
|
51
|
+
"tsdown": "^0.22.14",
|
|
52
|
+
"vite": "^8.1.5"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"elysia": "^1.4.29",
|
|
56
|
+
"kysely": "^catalog:",
|
|
57
|
+
"react": "^19.2.8",
|
|
58
|
+
"vite": "^8.1.5"
|
|
59
|
+
}
|
|
60
|
+
}
|