@distilled.cloud/discord 1.0.0-rc.13 → 1.0.0-rc.14
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/lib/credentials.d.ts +2 -2
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +6 -8
- package/lib/credentials.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/protocol.d.ts +3 -3
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +3 -5
- package/lib/protocol.js.map +1 -1
- package/lib/retry.d.ts +1 -1
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -1
- package/lib/retry.js.map +1 -1
- package/lib/services/discord.d.ts +74 -12
- package/lib/services/discord.d.ts.map +1 -1
- package/lib/services/discord.js +770 -2414
- package/lib/services/discord.js.map +1 -1
- package/package.json +12 -10
- package/src/credentials.ts +13 -19
- package/src/errors.ts +1 -2
- package/src/index.ts +1 -5
- package/src/protocol.ts +29 -43
- package/src/retry.ts +4 -9
- package/src/services/discord.ts +4816 -7347
- package/lib/response-validation.test.d.ts +0 -4
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -31
- package/lib/response-validation.test.js.map +0 -1
- package/src/response-validation.test.ts +0 -45
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/discord",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.14",
|
|
4
|
+
"license": "Apache-2.0",
|
|
4
5
|
"repository": {
|
|
5
6
|
"type": "git",
|
|
6
7
|
"url": "https://github.com/alchemy-run/distilled",
|
|
7
8
|
"directory": "packages/discord"
|
|
8
9
|
},
|
|
9
|
-
"license": "Apache-2.0",
|
|
10
|
-
"type": "module",
|
|
11
|
-
"sideEffects": false,
|
|
12
10
|
"files": [
|
|
13
11
|
"lib",
|
|
14
12
|
"src"
|
|
15
13
|
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./lib/index.d.ts",
|
|
@@ -58,20 +58,22 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
61
|
+
"@distilled.cloud/core": "1.0.0-rc.14"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@types/
|
|
65
|
-
"@types/node": "26.2.0",
|
|
66
|
-
"@effect/platform-bun": "^4.0.0"
|
|
64
|
+
"@types/node": "26.2.0"
|
|
67
65
|
},
|
|
68
66
|
"peerDependencies": {
|
|
69
67
|
"effect": "^4.0.0"
|
|
70
68
|
},
|
|
69
|
+
"distilled": {
|
|
70
|
+
"generatedAt": "2026-10-05",
|
|
71
|
+
"specUpdatedAt": "2026-10-03"
|
|
72
|
+
},
|
|
71
73
|
"scripts": {
|
|
72
74
|
"build": "tsc -b",
|
|
73
|
-
"convert": "bun scripts/convert.ts",
|
|
74
|
-
"generate": "bun scripts/convert.ts && bun scripts/generate.ts",
|
|
75
|
+
"convert": "node --conditions=bun scripts/convert.ts",
|
|
76
|
+
"generate": "node --conditions=bun scripts/convert.ts && node --conditions=bun scripts/generate.ts",
|
|
75
77
|
"typecheck": "tsc -p tsconfig.json",
|
|
76
78
|
"specs:fetch": "git submodule update --force --init --depth=1 specs/spec-mirror-discord",
|
|
77
79
|
"specs:update": "git submodule update --remote --force --depth=1 specs/spec-mirror-discord"
|
package/src/credentials.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
1
2
|
/**
|
|
2
3
|
* Discord credentials — hand-written.
|
|
3
4
|
*
|
|
@@ -17,7 +18,6 @@ import * as Context from "effect/Context";
|
|
|
17
18
|
import * as Effect from "effect/Effect";
|
|
18
19
|
import * as Layer from "effect/Layer";
|
|
19
20
|
import * as Redacted from "effect/Redacted";
|
|
20
|
-
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Discord HTTP API base URL. The trailing `/v10` is the API version the spec
|
|
@@ -35,20 +35,17 @@ export interface Config {
|
|
|
35
35
|
readonly apiBaseUrl: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export class Credentials extends Context.Service<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
>()("DiscordCredentials") {}
|
|
38
|
+
export class Credentials extends Context.Service<Credentials, Effect.Effect<Config>>()(
|
|
39
|
+
"DiscordCredentials",
|
|
40
|
+
) {}
|
|
42
41
|
|
|
43
42
|
const envConfig = EffectConfig.all({
|
|
44
43
|
// DISCORD_BOT_TOKEN is the spelling discord.js and most hosting platforms
|
|
45
44
|
// use; DISCORD_TOKEN is the fallback.
|
|
46
|
-
token: EffectConfig.
|
|
47
|
-
EffectConfig.orElse(() => EffectConfig.
|
|
48
|
-
),
|
|
49
|
-
tokenType: EffectConfig.String("DISCORD_TOKEN_TYPE").pipe(
|
|
50
|
-
EffectConfig.withDefault("Bot"),
|
|
45
|
+
token: EffectConfig.Redacted("DISCORD_BOT_TOKEN").pipe(
|
|
46
|
+
EffectConfig.orElse(() => EffectConfig.Redacted("DISCORD_TOKEN")),
|
|
51
47
|
),
|
|
48
|
+
tokenType: EffectConfig.String("DISCORD_TOKEN_TYPE").pipe(EffectConfig.withDefault("Bot")),
|
|
52
49
|
apiBaseUrl: EffectConfig.String("DISCORD_API_URL").pipe(
|
|
53
50
|
EffectConfig.withDefault(DEFAULT_API_BASE_URL),
|
|
54
51
|
),
|
|
@@ -60,33 +57,30 @@ export const CredentialsFromEnv = Layer.succeed(
|
|
|
60
57
|
Effect.mapError(
|
|
61
58
|
() =>
|
|
62
59
|
new ConfigError({
|
|
63
|
-
message:
|
|
64
|
-
"DISCORD_BOT_TOKEN (or DISCORD_TOKEN) environment variable is required",
|
|
60
|
+
message: "DISCORD_BOT_TOKEN (or DISCORD_TOKEN) environment variable is required",
|
|
65
61
|
}),
|
|
66
62
|
),
|
|
67
63
|
Effect.map(({ token, tokenType, apiBaseUrl }) => ({
|
|
68
|
-
token
|
|
64
|
+
token,
|
|
69
65
|
// Anything but an explicit `Bearer` means a bot token — the OAuth2
|
|
70
66
|
// flavor is the opt-in.
|
|
71
|
-
tokenType: (tokenType.toLowerCase() === "bearer"
|
|
72
|
-
? "Bearer"
|
|
73
|
-
: "Bot") as TokenType,
|
|
67
|
+
tokenType: (tokenType.toLowerCase() === "bearer" ? "Bearer" : "Bot") as TokenType,
|
|
74
68
|
apiBaseUrl,
|
|
75
69
|
})),
|
|
76
70
|
Effect.orDie,
|
|
77
71
|
),
|
|
78
72
|
);
|
|
79
73
|
|
|
80
|
-
/** Convenience layer from a
|
|
74
|
+
/** Convenience layer from a redacted token + optional token type / base URL. */
|
|
81
75
|
export const credentials = (config: {
|
|
82
|
-
readonly token: string
|
|
76
|
+
readonly token: Redacted.Redacted<string>;
|
|
83
77
|
readonly tokenType?: TokenType;
|
|
84
78
|
readonly apiBaseUrl?: string;
|
|
85
79
|
}): Layer.Layer<Credentials> =>
|
|
86
80
|
Layer.succeed(
|
|
87
81
|
Credentials,
|
|
88
82
|
Effect.succeed({
|
|
89
|
-
token:
|
|
83
|
+
token: config.token,
|
|
90
84
|
tokenType: config.tokenType ?? "Bot",
|
|
91
85
|
apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL,
|
|
92
86
|
}),
|
package/src/errors.ts
CHANGED
|
@@ -22,10 +22,9 @@ export {
|
|
|
22
22
|
DEFAULT_ERRORS,
|
|
23
23
|
API_ERRORS,
|
|
24
24
|
} from "@distilled.cloud/core/errors";
|
|
25
|
+
import * as Category from "@distilled.cloud/core/category";
|
|
25
26
|
import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
|
|
26
|
-
|
|
27
27
|
import * as Schema from "effect/Schema";
|
|
28
|
-
import * as Category from "@distilled.cloud/core/category";
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* Unknown Discord error — returned when a failed response's HTTP status has
|
package/src/index.ts
CHANGED
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
export * from "./credentials.ts";
|
|
9
9
|
export * from "./errors.ts";
|
|
10
10
|
export * as T from "./traits.ts";
|
|
11
|
-
export {
|
|
12
|
-
DiscordProtocol,
|
|
13
|
-
type DiscordOpError,
|
|
14
|
-
type DiscordOpContext,
|
|
15
|
-
} from "./protocol.ts";
|
|
11
|
+
export { DiscordProtocol, type DiscordOpError, type DiscordOpContext } from "./protocol.ts";
|
|
16
12
|
export * as Retry from "./retry.ts";
|
|
17
13
|
export * as Services from "./services/index.ts";
|
package/src/protocol.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type * as API from "@distilled.cloud/core/api";
|
|
2
|
+
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
3
|
+
import { makeRestProtocol, type RestErrorEnvelope } from "@distilled.cloud/core/protocol-rest";
|
|
1
4
|
/**
|
|
2
5
|
* DiscordProtocol — the shared bearer-REST protocol instantiated for Discord.
|
|
3
6
|
*
|
|
@@ -13,22 +16,12 @@
|
|
|
13
16
|
* bucket hints without extra configuration.
|
|
14
17
|
*/
|
|
15
18
|
import * as Effect from "effect/Effect";
|
|
16
|
-
import type * as Layer from "effect/Layer";
|
|
17
|
-
import * as Redacted from "effect/Redacted";
|
|
18
19
|
import type * as HttpClient from "effect/http/HttpClient";
|
|
19
20
|
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
20
|
-
import type * as
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
23
|
-
makeRestProtocol,
|
|
24
|
-
type RestErrorEnvelope,
|
|
25
|
-
} from "@distilled.cloud/core/protocol-rest";
|
|
21
|
+
import type * as Layer from "effect/Layer";
|
|
22
|
+
import * as Redacted from "effect/Redacted";
|
|
26
23
|
import { Credentials, type Config } from "./credentials.ts";
|
|
27
|
-
import {
|
|
28
|
-
UnknownDiscordError,
|
|
29
|
-
type DefaultErrors,
|
|
30
|
-
DiscordParseError,
|
|
31
|
-
} from "./errors.ts";
|
|
24
|
+
import { UnknownDiscordError, type DefaultErrors, DiscordParseError } from "./errors.ts";
|
|
32
25
|
|
|
33
26
|
/**
|
|
34
27
|
* Error channel shared by every generated Discord operation. Generated
|
|
@@ -36,10 +29,7 @@ import {
|
|
|
36
29
|
* DiscordOpError, DiscordOpContext>` explicitly so the compiler never infers
|
|
37
30
|
* these back out of the schema generics.
|
|
38
31
|
*/
|
|
39
|
-
export type DiscordOpError =
|
|
40
|
-
| DefaultErrors
|
|
41
|
-
| ConfigError
|
|
42
|
-
| HttpClientError.HttpClientError;
|
|
32
|
+
export type DiscordOpError = DefaultErrors | ConfigError | HttpClientError.HttpClientError;
|
|
43
33
|
|
|
44
34
|
/** Context (requirements) shared by every generated Discord operation. */
|
|
45
35
|
export type DiscordOpContext = Credentials | HttpClient.HttpClient;
|
|
@@ -60,10 +50,7 @@ const errorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
|
|
|
60
50
|
: typeof b.error === "string"
|
|
61
51
|
? b.error
|
|
62
52
|
: undefined;
|
|
63
|
-
const code =
|
|
64
|
-
typeof b.code === "number" || typeof b.code === "string"
|
|
65
|
-
? b.code
|
|
66
|
-
: undefined;
|
|
53
|
+
const code = typeof b.code === "number" || typeof b.code === "string" ? b.code : undefined;
|
|
67
54
|
return { code, message };
|
|
68
55
|
};
|
|
69
56
|
|
|
@@ -86,26 +73,25 @@ const numericCode = (code: string | number | undefined): number | undefined => {
|
|
|
86
73
|
return Number.isFinite(n) ? n : undefined;
|
|
87
74
|
};
|
|
88
75
|
|
|
89
|
-
export const DiscordProtocol: Layer.Layer<API.Protocol> =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
export const DiscordProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>({
|
|
77
|
+
// Resolved on the CALLING fiber per request (the layer is memoized per
|
|
78
|
+
// process); the Credentials service holds an effect so rotating tokens
|
|
79
|
+
// Just Work.
|
|
80
|
+
credentials: Effect.gen(function* () {
|
|
81
|
+
const resolve = yield* Credentials;
|
|
82
|
+
return yield* resolve;
|
|
83
|
+
}),
|
|
84
|
+
baseUrl: (creds) => creds.apiBaseUrl,
|
|
85
|
+
headers: (creds) => ({
|
|
86
|
+
Authorization: `${creds.tokenType} ${Redacted.value(creds.token)}`,
|
|
87
|
+
}),
|
|
88
|
+
errorEnvelope,
|
|
89
|
+
unknownError: ({ code, message, body }) =>
|
|
90
|
+
new UnknownDiscordError({
|
|
91
|
+
code: numericCode(code),
|
|
92
|
+
message,
|
|
93
|
+
errors: errorDetails(body),
|
|
94
|
+
body,
|
|
101
95
|
}),
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
new UnknownDiscordError({
|
|
105
|
-
code: numericCode(code),
|
|
106
|
-
message,
|
|
107
|
-
errors: errorDetails(body),
|
|
108
|
-
body,
|
|
109
|
-
}),
|
|
110
|
-
parseError: ({ body, cause }) => new DiscordParseError({ body, cause }),
|
|
111
|
-
});
|
|
96
|
+
parseError: ({ body, cause }) => new DiscordParseError({ body, cause }),
|
|
97
|
+
});
|
package/src/retry.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Retries from "@distilled.cloud/core/retry";
|
|
1
2
|
/**
|
|
2
3
|
* Discord retry surface — a veneer over `@distilled.cloud/core/retry`.
|
|
3
4
|
*
|
|
@@ -18,7 +19,6 @@
|
|
|
18
19
|
import * as Context from "effect/Context";
|
|
19
20
|
import * as Effect from "effect/Effect";
|
|
20
21
|
import * as Layer from "effect/Layer";
|
|
21
|
-
import * as Retries from "@distilled.cloud/core/retry";
|
|
22
22
|
|
|
23
23
|
export type Options = Retries.Options;
|
|
24
24
|
export type Factory = Retries.Factory;
|
|
@@ -31,16 +31,11 @@ export class Retry extends Context.Service<Retry, Policy>()("DiscordRetry") {}
|
|
|
31
31
|
export const policy: {
|
|
32
32
|
(
|
|
33
33
|
options: Options,
|
|
34
|
-
): <A, E, R>(
|
|
35
|
-
effect: Effect.Effect<A, E, R>,
|
|
36
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
34
|
+
): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
37
35
|
(
|
|
38
36
|
factory: Factory,
|
|
39
|
-
): <A, E, R>(
|
|
40
|
-
|
|
41
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
42
|
-
} = (optionsOrFactory: Options | Factory) =>
|
|
43
|
-
Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
37
|
+
): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
38
|
+
} = (optionsOrFactory: Options | Factory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
44
39
|
|
|
45
40
|
/** Disables all automatic retries. */
|
|
46
41
|
export const none: <A, E, R>(
|