@seedcord/kit 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/dist/index.mjs ADDED
@@ -0,0 +1,77 @@
1
+ import { a as Notice, i as NoticeCard, o as BuilderComponent, s as RowComponent, t as CustomId } from "./CustomId-5Zl_LdzZ.mjs";
2
+
3
+ //#region src/stops/Fault.ts
4
+ /**
5
+ * A generic fault you throw after catching an error you do not have a specific message for.
6
+ *
7
+ * The user sees a fixed generic reply with the tracking uuid, never the cause. `report` defaults to
8
+ * `true`, so the framework logs it and publishes it to the `handledException` bus. Pass `report: false`
9
+ * to show the generic reply without the bus publish. The original error is stored as the standard
10
+ * `cause`, so the real stack reaches the webhook. For a fault the user should see a real message,
11
+ * subclass {@link Notice} and write your own `render` instead.
12
+ *
13
+ * The framework also renders this for an unhandled throw, where it points the user at
14
+ * `ctx.developerUsername`.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { Fault } from '@seedcord/kit';
19
+ *
20
+ * try {
21
+ * await db.write(record);
22
+ * } catch (cause) {
23
+ * // user sees the generic reply with the uuid, the real error rides along as cause for the webhook
24
+ * throw new Fault({ cause });
25
+ *
26
+ * // pass report: false to show the same reply without publishing to the handledException bus
27
+ * // throw new Fault({ cause, report: false });
28
+ * }
29
+ * ```
30
+ */
31
+ var Fault = class extends Notice {
32
+ constructor(options) {
33
+ super("A fault occurred", options?.cause === void 0 ? void 0 : { cause: options.cause });
34
+ this.report = options?.report ?? true;
35
+ }
36
+ render(ctx) {
37
+ return { components: [new NoticeCard(`Something went wrong. Please reach out to ${ctx.developerUsername ?? "the developer"} with a way to reproduce the error and the following:\n### UUID: \`${ctx.uuid}\``, "Error").component] };
38
+ }
39
+ };
40
+
41
+ //#endregion
42
+ //#region src/stops/Silence.ts
43
+ /**
44
+ * Throw to stop a handler with no reply and no report.
45
+ *
46
+ * The framework boundary catches `Silence` before {@link Notice}, makes zero Discord calls, and stops.
47
+ * Ideally you'd only throw this in `EventHandlers` (or `Gates` for those), because it doesn't make sense to
48
+ * leave the user with no reply for an interaction.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { Silence } from '@seedcord/kit';
53
+ *
54
+ * // before any reply or defer, drop the interaction with no reply and no report
55
+ * if (await isBlacklisted(interaction.user.id)) throw new Silence('blacklisted user');
56
+ * ```
57
+ */
58
+ var Silence = class extends Error {
59
+ reason;
60
+ /**
61
+ * @param reason - Optional note written only to a debug log, never shown to the user or reported.
62
+ */
63
+ constructor(reason) {
64
+ super(reason ?? "Silence");
65
+ this.reason = reason;
66
+ Error.captureStackTrace(this, this.constructor);
67
+ }
68
+ };
69
+
70
+ //#endregion
71
+ //#region src/index.ts
72
+ /** Package version */
73
+ const version = "0.0.1";
74
+
75
+ //#endregion
76
+ export { BuilderComponent, CustomId, Fault, Notice, RowComponent, Silence, version };
77
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/stops/Fault.ts","../src/stops/Silence.ts","../src/index.ts"],"sourcesContent":["import { Notice } from './Notice';\nimport { NoticeCard } from './NoticeCard';\n\nimport type { RenderContext, ReplyResponse } from '@seedcord/types';\n\n/**\n * A generic fault you throw after catching an error you do not have a specific message for.\n *\n * The user sees a fixed generic reply with the tracking uuid, never the cause. `report` defaults to\n * `true`, so the framework logs it and publishes it to the `handledException` bus. Pass `report: false`\n * to show the generic reply without the bus publish. The original error is stored as the standard\n * `cause`, so the real stack reaches the webhook. For a fault the user should see a real message,\n * subclass {@link Notice} and write your own `render` instead.\n *\n * The framework also renders this for an unhandled throw, where it points the user at\n * `ctx.developerUsername`.\n *\n * @example\n * ```ts\n * import { Fault } from '@seedcord/kit';\n *\n * try {\n * await db.write(record);\n * } catch (cause) {\n * // user sees the generic reply with the uuid, the real error rides along as cause for the webhook\n * throw new Fault({ cause });\n *\n * // pass report: false to show the same reply without publishing to the handledException bus\n * // throw new Fault({ cause, report: false });\n * }\n * ```\n */\nexport class Fault extends Notice {\n public constructor(options?: { cause?: unknown; report?: boolean }) {\n super('A fault occurred', options?.cause === undefined ? undefined : { cause: options.cause });\n this.report = options?.report ?? true;\n }\n\n public render(ctx: RenderContext): ReplyResponse {\n const contact = ctx.developerUsername ?? 'the developer';\n const card = new NoticeCard(\n `Something went wrong. Please reach out to ${contact} with a way to reproduce the error and the following:\\n### UUID: \\`${ctx.uuid}\\``,\n 'Error'\n );\n return { components: [card.component] };\n }\n}\n","/**\n * Throw to stop a handler with no reply and no report.\n *\n * The framework boundary catches `Silence` before {@link Notice}, makes zero Discord calls, and stops.\n * Ideally you'd only throw this in `EventHandlers` (or `Gates` for those), because it doesn't make sense to\n * leave the user with no reply for an interaction.\n *\n * @example\n * ```ts\n * import { Silence } from '@seedcord/kit';\n *\n * // before any reply or defer, drop the interaction with no reply and no report\n * if (await isBlacklisted(interaction.user.id)) throw new Silence('blacklisted user');\n * ```\n */\nexport class Silence extends Error {\n /**\n * @param reason - Optional note written only to a debug log, never shown to the user or reported.\n */\n public constructor(public readonly reason?: string) {\n super(reason ?? 'Silence');\n\n Error.captureStackTrace(this, this.constructor);\n }\n}\n","export { BuilderComponent, RowComponent } from '@components/Component';\nexport { type RowType, type BuilderType } from '@components/builderTypes';\nexport { Notice } from '@stops/Notice';\nexport { Fault } from '@stops/Fault';\nexport { Silence } from '@stops/Silence';\nexport { CustomId } from '@customId/CustomId';\n\n/** Package version */\nexport const version = process.env.PACKAGE_VERSION ?? '0.0.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,QAAb,cAA2B,OAAO;CAC9B,AAAO,YAAY,SAAiD;EAChE,MAAM,oBAAoB,SAAS,UAAU,SAAY,SAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;EAC7F,KAAK,SAAS,SAAS,UAAU;CACrC;CAEA,AAAO,OAAO,KAAmC;EAM7C,OAAO,EAAE,YAAY,CAAC,IAJL,WACb,6CAFY,IAAI,qBAAqB,gBAEgB,qEAAqE,IAAI,KAAK,KACnI,OAEqB,CAAC,CAAC,SAAS,EAAE;CAC1C;AACJ;;;;;;;;;;;;;;;;;;;AC/BA,IAAa,UAAb,cAA6B,MAAM;CAII;;;;CAAnC,AAAO,YAAY,AAAgB,QAAiB;EAChD,MAAM,UAAU,SAAS;EADM;EAG/B,MAAM,kBAAkB,MAAM,KAAK,WAAW;CAClD;AACJ;;;;;AChBA,MAAa"}
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_CustomId = require('./CustomId-BuIoGHXw.cjs');
3
+
4
+ //#region src/customId/routing.ts
5
+ /**
6
+ * The route decorators store a handler's customId definitions here so the component base can decode
7
+ * against them at runtime.
8
+ *
9
+ * @internal
10
+ */
11
+ const ComponentDefsKey = Symbol("seedcord:customId:componentDefs");
12
+
13
+ //#endregion
14
+ exports.ComponentDefsKey = ComponentDefsKey;
15
+ exports.NoticeCard = require_CustomId.NoticeCard;
16
+ exports.decodeFor = require_CustomId.decodeFor;
17
+ exports.prefixOf = require_CustomId.prefixOf;
18
+ exports.setBotColor = require_CustomId.setBotColor;
19
+ //# sourceMappingURL=internal.index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.index.cjs","names":[],"sources":["../src/customId/routing.ts"],"sourcesContent":["import type { AnyCustomId } from './CustomId';\n\n/**\n * The route decorators store a handler's customId definitions here so the component base can decode\n * against them at runtime.\n *\n * @internal\n */\nexport const ComponentDefsKey = Symbol('seedcord:customId:componentDefs');\n\n/**\n * The phantom a component handler base carries. A route decorator constrains its argument to this, so\n * passing different definitions to the decorator and the handler's generic is a compile error. Never set at runtime.\n *\n * @internal\n */\nexport interface HasComponentDefs<Defs extends readonly AnyCustomId[]> {\n readonly __componentDefs?: Defs;\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAa,mBAAmB,OAAO,iCAAiC"}
@@ -0,0 +1 @@
1
+ export type * from './internal.index.d.mts'
@@ -0,0 +1,36 @@
1
+ import { a as DecodedParams, i as prefixOf, o as BuilderComponent, r as decodeFor, t as AnyCustomId } from "./CustomId-CbTZuUup.mjs";
2
+ import { ColorResolvable } from "discord.js";
3
+
4
+ //#region src/botColorHolder.d.ts
5
+ /** @internal */
6
+ declare function setBotColor(color: ColorResolvable | undefined): void;
7
+ //#endregion
8
+ //#region src/customId/routing.d.ts
9
+ /**
10
+ * The route decorators store a handler's customId definitions here so the component base can decode
11
+ * against them at runtime.
12
+ *
13
+ * @internal
14
+ */
15
+ declare const ComponentDefsKey: unique symbol;
16
+ /**
17
+ * The phantom a component handler base carries. A route decorator constrains its argument to this, so
18
+ * passing different definitions to the decorator and the handler's generic is a compile error. Never set at runtime.
19
+ *
20
+ * @internal
21
+ */
22
+ interface HasComponentDefs<Defs extends readonly AnyCustomId[]> {
23
+ readonly __componentDefs?: Defs;
24
+ }
25
+ //#endregion
26
+ //#region src/stops/NoticeCard.d.ts
27
+ /**
28
+ * Built fresh inside a {@link Notice}'s `render` to back its ComponentsV2 reply. The title renders as
29
+ * an h3 line with the description on the next line.
30
+ */
31
+ declare class NoticeCard extends BuilderComponent<'container'> {
32
+ constructor(description: string, title?: string);
33
+ }
34
+ //#endregion
35
+ export { type AnyCustomId, ComponentDefsKey, type DecodedParams, type HasComponentDefs, NoticeCard, decodeFor, prefixOf, setBotColor };
36
+ //# sourceMappingURL=internal.index.d.mts.map
@@ -0,0 +1,14 @@
1
+ import { c as setBotColor, i as NoticeCard, n as decodeFor, r as prefixOf } from "./CustomId-5Zl_LdzZ.mjs";
2
+
3
+ //#region src/customId/routing.ts
4
+ /**
5
+ * The route decorators store a handler's customId definitions here so the component base can decode
6
+ * against them at runtime.
7
+ *
8
+ * @internal
9
+ */
10
+ const ComponentDefsKey = Symbol("seedcord:customId:componentDefs");
11
+
12
+ //#endregion
13
+ export { ComponentDefsKey, NoticeCard, decodeFor, prefixOf, setBotColor };
14
+ //# sourceMappingURL=internal.index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.index.mjs","names":[],"sources":["../src/customId/routing.ts"],"sourcesContent":["import type { AnyCustomId } from './CustomId';\n\n/**\n * The route decorators store a handler's customId definitions here so the component base can decode\n * against them at runtime.\n *\n * @internal\n */\nexport const ComponentDefsKey = Symbol('seedcord:customId:componentDefs');\n\n/**\n * The phantom a component handler base carries. A route decorator constrains its argument to this, so\n * passing different definitions to the decorator and the handler's generic is a compile error. Never set at runtime.\n *\n * @internal\n */\nexport interface HasComponentDefs<Defs extends readonly AnyCustomId[]> {\n readonly __componentDefs?: Defs;\n}\n"],"mappings":";;;;;;;;;AAQA,MAAa,mBAAmB,OAAO,iCAAiC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@seedcord/kit",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "Reusable Seedcord building blocks: component builders, the Notice error tree, and the typed customId codec",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/seedcord/seedcord.git",
9
+ "directory": "packages/kit"
10
+ },
11
+ "types": "./dist/index.d.mts",
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/index.d.mts",
16
+ "default": "./dist/index.mjs"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "./internal": {
24
+ "import": {
25
+ "types": "./dist/internal.index.d.mts",
26
+ "default": "./dist/internal.index.mjs"
27
+ },
28
+ "require": {
29
+ "types": "./dist/internal.index.d.cts",
30
+ "default": "./dist/internal.index.cjs"
31
+ }
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "package.json",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "peerDependencies": {
41
+ "discord.js": "^14.26.4",
42
+ "typescript": "^6.0.3"
43
+ },
44
+ "dependencies": {
45
+ "@seedcord/errors": "0.0.1",
46
+ "@seedcord/types": "0.5.0"
47
+ },
48
+ "devDependencies": {
49
+ "discord.js": "^14.26.4",
50
+ "type-fest": "^5.7.0",
51
+ "vite": "^8.0.16",
52
+ "@seedcord/tsconfig": "2.0.0",
53
+ "@seedcord/tsdown-config": "2.0.0",
54
+ "@seedcord/eslint-config": "1.4.0"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "provenance": true
59
+ },
60
+ "scripts": {
61
+ "build": "tsdown",
62
+ "clean": "rm -rf dist",
63
+ "lint": "eslint 'src/**/*.{ts,tsx}' 'tests/**/*.{ts,tsx}' --cache",
64
+ "lint:fix": "eslint 'src/**/*.{ts,tsx}' 'tests/**/*.{ts,tsx}' --fix --cache",
65
+ "fmt": "prettier --write 'src/**/*.{ts,tsx,json,md}' 'tests/**/*.{ts,tsx,json,md}' --cache",
66
+ "fmt:check": "prettier --check 'src/**/*.{ts,tsx,json,md}' 'tests/**/*.{ts,tsx,json,md}' --cache",
67
+ "tc": "tsc --noEmit",
68
+ "test": "vitest run",
69
+ "test:watch": "vitest dev",
70
+ "coverage": "vitest run --coverage"
71
+ },
72
+ "readme": "<p align=\"center\">\n <img src=\"https://cdn.seedcord.org/assets/banner.webp\" alt=\"seedcord\" width=\"100%\" />\n</p>\n\n---\n\n_This repository is a work in progress._\n\n- There are no stable releases yet but changes are being made actively.\n- Till a major v1.0.0 release for seedcord, expect breaking changes in minor versions.\n- Documentation will come soon as well!\n\nIf you'd like to try it out, you can check out the code in `mock`\n"
73
+ }