@moloodev/platform 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/src/index.ts +2 -0
- package/src/publish-target.ts +20 -3
- package/src/publisher-handle.ts +18 -0
- package/src/qualified-name.ts +5 -3
- package/src/builtin-editors.ts +0 -15
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moloodev/platform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts",
|
|
7
|
-
"./builtin-editors": "./src/builtin-editors.ts",
|
|
8
7
|
"./network": "./src/network.ts",
|
|
9
8
|
"./dev-certs": "./src/dev-certs.ts",
|
|
10
9
|
"./constants": "./src/constants.ts",
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
"@types/node": "^24.13.3",
|
|
24
23
|
"tsx": "^4.23.13",
|
|
25
24
|
"typescript": "^7.0.2",
|
|
26
|
-
"@moloodev/typescript-config": "0.
|
|
25
|
+
"@moloodev/typescript-config": "0.6.0"
|
|
27
26
|
},
|
|
28
27
|
"publishConfig": {
|
|
29
28
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -90,3 +90,5 @@ export * from "./file-delivery";
|
|
|
90
90
|
export { loopbackOrigin } from "./editor-dev";
|
|
91
91
|
|
|
92
92
|
export type { PublishTarget } from "./publish-target";
|
|
93
|
+
export { PUBLISH_ERROR_MESSAGES, publishErrorBody } from "./publish-target";
|
|
94
|
+
export { isPublisherHandle, isReservedPublisherHandle, reservedPublishers } from "./publisher-handle";
|
package/src/publish-target.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
export type PublishTarget =
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type PublishTarget = { kind: "workspace"; workspaceSlug: string };
|
|
2
|
+
|
|
3
|
+
/** Shared copy for API responses and CLI fallbacks. Services return only codes. */
|
|
4
|
+
export const PUBLISH_ERROR_MESSAGES = {
|
|
5
|
+
invalid_publisher_handle: "Publisher handles must be 2–39 lowercase letters, digits or hyphens, start with a letter, and have no trailing or consecutive hyphens.",
|
|
6
|
+
publisher_reserved: "This publisher handle is reserved. Choose another handle.",
|
|
7
|
+
publisher_taken: "This publisher is managed by another workspace. Select its managing workspace or choose another handle.",
|
|
8
|
+
publisher_suspended: "This publisher is suspended. Contact moloo support.",
|
|
9
|
+
forbidden: "You must be an owner or admin of the publisher's managing workspace.",
|
|
10
|
+
invalid_manifest: "The editor manifest is invalid.",
|
|
11
|
+
unknown_workspace: "The selected workspace does not exist.",
|
|
12
|
+
unknown_editor: "No submitted editor with this manifest id exists in the selected workspace.",
|
|
13
|
+
checks_failed: "Editor checks failed. Fix the findings before publishing again.",
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export function publishErrorBody(error: string): { error: string; message?: string } {
|
|
17
|
+
const message = Object.hasOwn(PUBLISH_ERROR_MESSAGES, error)
|
|
18
|
+
? PUBLISH_ERROR_MESSAGES[error as keyof typeof PUBLISH_ERROR_MESSAGES] : undefined;
|
|
19
|
+
return { error, ...(message ? { message } : {}) };
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const HANDLE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
2
|
+
|
|
3
|
+
export const reservedPublishers: readonly string[] = [
|
|
4
|
+
"moloo", "admin", "administrator", "official", "system", "support", "api", "app",
|
|
5
|
+
"www", "root", "staff", "team", "help", "security", "null", "undefined",
|
|
6
|
+
"auth", "id", "login", "oauth", "account", "accounts", "billing", "status",
|
|
7
|
+
"internal", "platform", "moderator", "abuse", "postmaster", "webmaster",
|
|
8
|
+
"static", "cdn", "preview", "dev", "localhost", "local", "mail",
|
|
9
|
+
];
|
|
10
|
+
const RESERVED = new Set(reservedPublishers);
|
|
11
|
+
|
|
12
|
+
export function isPublisherHandle(handle: string): boolean {
|
|
13
|
+
return handle.length >= 2 && handle.length <= 39 && HANDLE.exec(handle)?.[0] === handle;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isReservedPublisherHandle(handle: string): boolean {
|
|
17
|
+
return RESERVED.has(handle);
|
|
18
|
+
}
|
package/src/qualified-name.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Shared by editor ids and asset kind ids.
|
|
4
4
|
* @see https://code.visualstudio.com/api/references/extension-manifest
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
import { isPublisherHandle } from "./publisher-handle";
|
|
7
|
+
|
|
8
|
+
const QUALIFIED_NAME = /^([^.]+)\.([a-z0-9A-Z][a-z0-9-A-Z]*)$/;
|
|
7
9
|
|
|
8
10
|
export type QualifiedName = {
|
|
9
11
|
publisher: string;
|
|
@@ -12,10 +14,10 @@ export type QualifiedName = {
|
|
|
12
14
|
|
|
13
15
|
export function parseQualifiedName(id: string): QualifiedName | null {
|
|
14
16
|
const match = QUALIFIED_NAME.exec(id);
|
|
15
|
-
if (!match) return null;
|
|
17
|
+
if (!match || !isPublisherHandle(match[1]!)) return null;
|
|
16
18
|
return { publisher: match[1]!, name: match[2]! };
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export function isQualifiedName(id: string): boolean {
|
|
20
|
-
return
|
|
22
|
+
return parseQualifiedName(id) !== null;
|
|
21
23
|
}
|
package/src/builtin-editors.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const builtinEditors = [
|
|
2
|
-
{ id: "091d9isv5yp3x5mhwum08p1f", publisherHandle: "moloo", slug: "markdown" },
|
|
3
|
-
{ id: "1o5gtual80gchlsd5uug3wfv", publisherHandle: "moloo", slug: "loop" },
|
|
4
|
-
{ id: "g6qihgfq096rsp3k1kimttvy", publisherHandle: "moloo", slug: "table" },
|
|
5
|
-
{ id: "2cnatugu7hupo4stgh2srv68", publisherHandle: "moloo", slug: "bundle" },
|
|
6
|
-
{ id: "uqq597gzhpzkds0mrmc2zdtu", publisherHandle: "moloo", slug: "layout" },
|
|
7
|
-
] as const;
|
|
8
|
-
|
|
9
|
-
export function builtinEditorId(
|
|
10
|
-
slug: (typeof builtinEditors)[number]["slug"],
|
|
11
|
-
): string {
|
|
12
|
-
const row = builtinEditors.find((item) => item.slug === slug);
|
|
13
|
-
if (row === undefined) throw new Error(`builtin editor ${slug} is missing`);
|
|
14
|
-
return row.id;
|
|
15
|
-
}
|