@distilled.cloud/discord 1.0.0-rc.14 → 1.0.0-rc.16
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 +3 -3
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +35 -29
- package/lib/credentials.js.map +1 -1
- package/lib/errors.d.ts +14 -14
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +21 -21
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +7 -7
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +28 -31
- package/lib/protocol.js.map +1 -1
- package/lib/retry.d.ts +2 -2
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +34 -33
- package/lib/retry.js.map +1 -1
- package/lib/services/discord.d.ts +4 -1507
- package/lib/services/discord.d.ts.map +1 -1
- package/lib/services/discord.js +531 -11332
- package/lib/traits.d.ts +1 -1
- package/lib/traits.js +7 -7
- package/package.json +13 -9
- package/src/credentials.ts +25 -22
- package/src/errors.ts +11 -15
- package/src/index.ts +1 -1
- package/src/protocol.ts +5 -8
- package/src/retry.ts +6 -6
- package/src/services/discord.ts +10028 -14675
- package/src/traits.ts +1 -1
- package/lib/services/discord.js.map +0 -1
package/lib/traits.d.ts
CHANGED
package/lib/traits.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
8
|
export { Body, Header, Query, Label, Http, ResponseCode, HttpBody, FormDataFile, KeyDictionary, UnionCases, applyErrorMatchers, getErrorMatchers, bodySymbol, headerSymbol, querySymbol, labelSymbol, httpSymbol, responseCodeSymbol, httpBodySymbol, formDataFileSymbol, keyDictionarySymbol, unionCasesSymbol, errorMatchersSymbol, } from "@distilled.cloud/core/trait";
|
|
9
9
|
// Bearer-REST protocol traits (sensitive strings, bare-payload responses).
|
|
10
10
|
export { SensitiveValue, RawResponse, RawResponseRoot, sensitiveValueSymbol, rawResponseSymbol, rawResponseRootSymbol, } from "@distilled.cloud/core/protocol-rest";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/discord",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.16",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"types": "./lib/index.d.ts",
|
|
19
19
|
"bun": "./src/index.ts",
|
|
20
20
|
"worker": "./src/index.ts",
|
|
21
|
-
"
|
|
21
|
+
"module": "./lib/index.full.js",
|
|
22
|
+
"module-sync": "./lib/index.js",
|
|
23
|
+
"default": "./lib/index.full.js"
|
|
22
24
|
},
|
|
23
25
|
"./Credentials": {
|
|
24
26
|
"types": "./lib/credentials.d.ts",
|
|
@@ -54,27 +56,29 @@
|
|
|
54
56
|
"types": "./lib/services/*.d.ts",
|
|
55
57
|
"bun": "./src/services/*.ts",
|
|
56
58
|
"worker": "./src/services/*.ts",
|
|
57
|
-
"
|
|
59
|
+
"module": "./lib/services.full/*.js",
|
|
60
|
+
"module-sync": "./lib/services/*.js",
|
|
61
|
+
"default": "./lib/services.full/*.js"
|
|
58
62
|
}
|
|
59
63
|
},
|
|
60
64
|
"dependencies": {
|
|
61
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
65
|
+
"@distilled.cloud/core": "1.0.0-rc.16"
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
64
|
-
"@types/node": "26.
|
|
68
|
+
"@types/node": "26.6.5"
|
|
65
69
|
},
|
|
66
70
|
"peerDependencies": {
|
|
67
|
-
"effect": "^4.0.
|
|
71
|
+
"effect": "^4.0.5"
|
|
68
72
|
},
|
|
69
73
|
"distilled": {
|
|
70
|
-
"generatedAt": "2026-10-
|
|
74
|
+
"generatedAt": "2026-10-09",
|
|
71
75
|
"specUpdatedAt": "2026-10-03"
|
|
72
76
|
},
|
|
73
77
|
"scripts": {
|
|
74
|
-
"build": "
|
|
78
|
+
"build": "tsrs -b",
|
|
75
79
|
"convert": "node --conditions=bun scripts/convert.ts",
|
|
76
80
|
"generate": "node --conditions=bun scripts/convert.ts && node --conditions=bun scripts/generate.ts",
|
|
77
|
-
"typecheck": "
|
|
81
|
+
"typecheck": "tsrs -p tsconfig.json",
|
|
78
82
|
"specs:fetch": "git submodule update --force --init --depth=1 specs/spec-mirror-discord",
|
|
79
83
|
"specs:update": "git submodule update --remote --force --depth=1 specs/spec-mirror-discord"
|
|
80
84
|
}
|
package/src/credentials.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
2
1
|
/**
|
|
3
|
-
* Discord credentials
|
|
2
|
+
* Discord credentials -- hand-written.
|
|
4
3
|
*
|
|
5
4
|
* The `Credentials` service resolves `{ token, tokenType, apiBaseUrl }` per
|
|
6
5
|
* request; the protocol layer formats the `Authorization: <tokenType> <token>`
|
|
@@ -8,12 +7,13 @@ import { ConfigError } from "@distilled.cloud/core/errors";
|
|
|
8
7
|
*
|
|
9
8
|
* Discord authorizes HTTP API calls two ways, distinguished by the token
|
|
10
9
|
* prefix (https://discord.com/developers/docs/reference#authentication):
|
|
11
|
-
*
|
|
10
|
+
* * `Bot <token>` -- a bot token from the application's Bot page (the
|
|
12
11
|
* default; what almost every server-side integration uses)
|
|
13
|
-
*
|
|
14
|
-
* a user (`/users/@me`, `/users/@me/guilds`,
|
|
12
|
+
* * `Bearer <token>` -- an OAuth2 access token, for calls made on behalf of
|
|
13
|
+
* a user (`/users/@me`, `/users/@me/guilds`, ...)
|
|
15
14
|
*/
|
|
16
|
-
import * as EffectConfig from "
|
|
15
|
+
import * as EffectConfig from "@distilled.cloud/core/config";
|
|
16
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
17
17
|
import * as Context from "effect/Context";
|
|
18
18
|
import * as Effect from "effect/Effect";
|
|
19
19
|
import * as Layer from "effect/Layer";
|
|
@@ -21,12 +21,12 @@ import * as Redacted from "effect/Redacted";
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Discord HTTP API base URL. The trailing `/v10` is the API version the spec
|
|
24
|
-
* submodule describes
|
|
24
|
+
* submodule describes -- override via `DISCORD_API_URL` only to point at a
|
|
25
25
|
* proxy, not to change versions (the generated operations are v10-shaped).
|
|
26
26
|
*/
|
|
27
27
|
export const DEFAULT_API_BASE_URL = "https://discord.com/api/v10";
|
|
28
28
|
|
|
29
|
-
/** Authorization header prefix
|
|
29
|
+
/** Authorization header prefix -- see the module doc. */
|
|
30
30
|
export type TokenType = "Bot" | "Bearer";
|
|
31
31
|
|
|
32
32
|
export interface Config {
|
|
@@ -35,34 +35,37 @@ export interface Config {
|
|
|
35
35
|
readonly apiBaseUrl: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export class Credentials
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
export class Credentials
|
|
39
|
+
extends /*@__PURE__*/ Context.Service<Credentials, Effect.Effect<Config>>()(
|
|
40
|
+
"DiscordCredentials",
|
|
41
|
+
) {}
|
|
41
42
|
|
|
42
|
-
const envConfig = EffectConfig.all({
|
|
43
|
+
const envConfig = /*@__PURE__*/ EffectConfig.all({
|
|
43
44
|
// DISCORD_BOT_TOKEN is the spelling discord.js and most hosting platforms
|
|
44
45
|
// use; DISCORD_TOKEN is the fallback.
|
|
45
|
-
token: EffectConfig.Redacted("DISCORD_BOT_TOKEN").pipe(
|
|
46
|
-
EffectConfig.orElse(() => EffectConfig.Redacted("DISCORD_TOKEN")),
|
|
46
|
+
token: /*@__PURE__*/ EffectConfig.Redacted("DISCORD_BOT_TOKEN").pipe(
|
|
47
|
+
/*@__PURE__*/ EffectConfig.orElse(() => EffectConfig.Redacted("DISCORD_TOKEN")),
|
|
48
|
+
),
|
|
49
|
+
tokenType: /*@__PURE__*/ EffectConfig.String("DISCORD_TOKEN_TYPE").pipe(
|
|
50
|
+
/*@__PURE__*/ EffectConfig.withDefault("Bot"),
|
|
47
51
|
),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
EffectConfig.withDefault(DEFAULT_API_BASE_URL),
|
|
52
|
+
apiBaseUrl: /*@__PURE__*/ EffectConfig.String("DISCORD_API_URL").pipe(
|
|
53
|
+
/*@__PURE__*/ EffectConfig.withDefault(DEFAULT_API_BASE_URL),
|
|
51
54
|
),
|
|
52
55
|
});
|
|
53
56
|
|
|
54
|
-
export const CredentialsFromEnv = Layer.succeed(
|
|
57
|
+
export const CredentialsFromEnv = /*@__PURE__*/ Layer.succeed(
|
|
55
58
|
Credentials,
|
|
56
|
-
envConfig.pipe(
|
|
57
|
-
Effect.mapError(
|
|
59
|
+
/*@__PURE__*/ envConfig.pipe(
|
|
60
|
+
/*@__PURE__*/ Effect.mapError(
|
|
58
61
|
() =>
|
|
59
62
|
new ConfigError({
|
|
60
63
|
message: "DISCORD_BOT_TOKEN (or DISCORD_TOKEN) environment variable is required",
|
|
61
64
|
}),
|
|
62
65
|
),
|
|
63
|
-
Effect.map(({ token, tokenType, apiBaseUrl }) => ({
|
|
66
|
+
/*@__PURE__*/ Effect.map(({ token, tokenType, apiBaseUrl }) => ({
|
|
64
67
|
token,
|
|
65
|
-
// Anything but an explicit `Bearer` means a bot token
|
|
68
|
+
// Anything but an explicit `Bearer` means a bot token -- the OAuth2
|
|
66
69
|
// flavor is the opt-in.
|
|
67
70
|
tokenType: (tokenType.toLowerCase() === "bearer" ? "Bearer" : "Bot") as TokenType,
|
|
68
71
|
apiBaseUrl,
|
package/src/errors.ts
CHANGED
|
@@ -24,34 +24,30 @@ export {
|
|
|
24
24
|
} from "@distilled.cloud/core/errors";
|
|
25
25
|
import * as Category from "@distilled.cloud/core/category";
|
|
26
26
|
import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
|
|
27
|
-
import * as Schema from "
|
|
27
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Unknown Discord error
|
|
30
|
+
* Unknown Discord error -- returned when a failed response's HTTP status has
|
|
31
31
|
* no mapped error class. `code` is Discord's own JSON error code (e.g. 50001
|
|
32
32
|
* "Missing Access"), which is far more specific than the HTTP status and is
|
|
33
33
|
* the field worth branching on; `errors` carries the per-field validation
|
|
34
34
|
* detail Discord attaches to 400s. See
|
|
35
35
|
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#json.
|
|
36
36
|
*/
|
|
37
|
-
export class UnknownDiscordError
|
|
38
|
-
"UnknownDiscordError",
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
errors: Schema.optional(Schema.Unknown),
|
|
37
|
+
export class UnknownDiscordError
|
|
38
|
+
extends /*@__PURE__*/ Schema.TaggedError<UnknownDiscordError>()("UnknownDiscordError", {
|
|
39
|
+
code: /*@__PURE__*/ Schema.optional(Schema.Number),
|
|
40
|
+
message: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
41
|
+
errors: /*@__PURE__*/ Schema.optional(Schema.Unknown),
|
|
43
42
|
body: Schema.Unknown,
|
|
44
|
-
}
|
|
45
|
-
).pipe(Category.withServerError) {}
|
|
43
|
+
}).pipe(Category.withServerError) {}
|
|
46
44
|
|
|
47
45
|
/** Schema parse error wrapper. */
|
|
48
|
-
export class DiscordParseError
|
|
49
|
-
"DiscordParseError",
|
|
50
|
-
{
|
|
46
|
+
export class DiscordParseError
|
|
47
|
+
extends /*@__PURE__*/ Schema.TaggedError<DiscordParseError>()("DiscordParseError", {
|
|
51
48
|
body: Schema.Unknown,
|
|
52
49
|
cause: Schema.Unknown,
|
|
53
|
-
}
|
|
54
|
-
).pipe(Category.withParseError) {}
|
|
50
|
+
}).pipe(Category.withParseError) {}
|
|
55
51
|
|
|
56
52
|
/**
|
|
57
53
|
* Errors any Discord operation may surface in addition to the shared HTTP
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @distilled.cloud/discord
|
|
2
|
+
* @distilled.cloud/discord -- Discord HTTP API (v10) SDK for Effect.
|
|
3
3
|
*
|
|
4
4
|
* `./services` is generated by `scripts/generate.ts` from the Smithy model in
|
|
5
5
|
* `.generated-specs` (written by `scripts/convert.ts` from the Discord
|
package/src/protocol.ts
CHANGED
|
@@ -2,12 +2,12 @@ import type * as API from "@distilled.cloud/core/api";
|
|
|
2
2
|
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
3
3
|
import { makeRestProtocol, type RestErrorEnvelope } from "@distilled.cloud/core/protocol-rest";
|
|
4
4
|
/**
|
|
5
|
-
* DiscordProtocol
|
|
5
|
+
* DiscordProtocol -- the shared bearer-REST protocol instantiated for Discord.
|
|
6
6
|
*
|
|
7
7
|
* Discord speaks plain JSON with no response envelope: successful responses
|
|
8
8
|
* are the resource (or a bare array) verbatim. Failures carry
|
|
9
9
|
* `{ code, message, errors? }` where `code` is Discord's own numeric JSON
|
|
10
|
-
* error code
|
|
10
|
+
* error code -- the shared HTTP status map turns the status into the error
|
|
11
11
|
* class, and anything unmapped becomes {@link UnknownDiscordError} with the
|
|
12
12
|
* code and per-field `errors` detail preserved.
|
|
13
13
|
*
|
|
@@ -62,7 +62,7 @@ const errorDetails = (body: unknown): unknown => {
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Discord's JSON error code as a number. The OAuth2 endpoints answer with a
|
|
65
|
-
* string `error` slug instead of a numeric `code`
|
|
65
|
+
* string `error` slug instead of a numeric `code` -- those carry no numeric
|
|
66
66
|
* code at all, so anything unparseable is dropped rather than surfaced as
|
|
67
67
|
* NaN.
|
|
68
68
|
*/
|
|
@@ -73,14 +73,11 @@ const numericCode = (code: string | number | undefined): number | undefined => {
|
|
|
73
73
|
return Number.isFinite(n) ? n : undefined;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
export const DiscordProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>({
|
|
76
|
+
export const DiscordProtocol: Layer.Layer<API.Protocol> = /*@__PURE__*/ makeRestProtocol<Config>({
|
|
77
77
|
// Resolved on the CALLING fiber per request (the layer is memoized per
|
|
78
78
|
// process); the Credentials service holds an effect so rotating tokens
|
|
79
79
|
// Just Work.
|
|
80
|
-
credentials: Effect.
|
|
81
|
-
const resolve = yield* Credentials;
|
|
82
|
-
return yield* resolve;
|
|
83
|
-
}),
|
|
80
|
+
credentials: /*@__PURE__*/ Effect.flatMap(Credentials, (resolve) => resolve),
|
|
84
81
|
baseUrl: (creds) => creds.apiBaseUrl,
|
|
85
82
|
headers: (creds) => ({
|
|
86
83
|
Authorization: `${creds.tokenType} ${Redacted.value(creds.token)}`,
|
package/src/retry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Retries from "@distilled.cloud/core/retry";
|
|
2
2
|
/**
|
|
3
|
-
* Discord retry surface
|
|
3
|
+
* Discord retry surface -- a veneer over `@distilled.cloud/core/retry`.
|
|
4
4
|
*
|
|
5
5
|
* The `Retry` service tag is threaded into every generated operation via
|
|
6
6
|
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
@@ -25,7 +25,7 @@ export type Factory = Retries.Factory;
|
|
|
25
25
|
export type Policy = Retries.Policy;
|
|
26
26
|
|
|
27
27
|
/** Context tag for configuring retry behavior of Discord API calls. */
|
|
28
|
-
export class Retry extends Context.Service<Retry, Policy>()("DiscordRetry") {}
|
|
28
|
+
export class Retry extends /*@__PURE__*/ Context.Service<Retry, Policy>()("DiscordRetry") {}
|
|
29
29
|
|
|
30
30
|
/** Provides a custom retry policy to every Discord API call below it. */
|
|
31
31
|
export const policy: {
|
|
@@ -40,8 +40,8 @@ export const policy: {
|
|
|
40
40
|
/** Disables all automatic retries. */
|
|
41
41
|
export const none: <A, E, R>(
|
|
42
42
|
effect: Effect.Effect<A, E, R>,
|
|
43
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>> = Effect.provide(
|
|
44
|
-
Layer.succeed(Retry, { while: () => false }),
|
|
43
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ Effect.provide(
|
|
44
|
+
/*@__PURE__*/ Layer.succeed(Retry, { while: () => false }),
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -60,7 +60,7 @@ export const throttlingOptions: Options = Retries.throttlingOptions;
|
|
|
60
60
|
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
61
61
|
export const throttling: <A, E, R>(
|
|
62
62
|
effect: Effect.Effect<A, E, R>,
|
|
63
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>> = policy(Retries.throttlingFactory);
|
|
63
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.throttlingFactory);
|
|
64
64
|
|
|
65
65
|
/** Retry options that retry all transient errors indefinitely. */
|
|
66
66
|
export const transientOptions: Options = Retries.transientOptions;
|
|
@@ -68,4 +68,4 @@ export const transientOptions: Options = Retries.transientOptions;
|
|
|
68
68
|
/** Retries all transient errors indefinitely (honoring server hints). */
|
|
69
69
|
export const transient: <A, E, R>(
|
|
70
70
|
effect: Effect.Effect<A, E, R>,
|
|
71
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>> = policy(Retries.transientFactory);
|
|
71
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.transientFactory);
|