dfx 1.0.3 → 1.0.5
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/Cache/driver.d.ts +24 -0
- package/dist/Cache/driver.d.ts.map +1 -0
- package/dist/Cache/driver.js +3 -0
- package/dist/Cache/driver.js.map +1 -0
- package/dist/Cache/memory.d.ts +5 -0
- package/dist/Cache/memory.d.ts.map +1 -0
- package/dist/Cache/memory.js +48 -0
- package/dist/Cache/memory.js.map +1 -0
- package/dist/Cache/memoryTTL.d.ts +23 -0
- package/dist/Cache/memoryTTL.d.ts.map +1 -0
- package/dist/Cache/memoryTTL.js +113 -0
- package/dist/Cache/memoryTTL.js.map +1 -0
- package/dist/Cache/prelude.d.ts +32 -0
- package/dist/Cache/prelude.d.ts.map +1 -0
- package/dist/Cache/prelude.js +130 -0
- package/dist/Cache/prelude.js.map +1 -0
- package/dist/Cache.d.ts +81 -0
- package/dist/Cache.d.ts.map +1 -0
- package/dist/Cache.js +77 -0
- package/dist/Cache.js.map +1 -0
- package/dist/DiscordConfig.d.ts +35 -0
- package/dist/DiscordConfig.d.ts.map +1 -0
- package/dist/DiscordConfig.js +29 -0
- package/dist/DiscordConfig.js.map +1 -0
- package/dist/DiscordGateway/DiscordWS.d.ts +37 -0
- package/dist/DiscordGateway/DiscordWS.d.ts.map +1 -0
- package/dist/DiscordGateway/DiscordWS.js +74 -0
- package/dist/DiscordGateway/DiscordWS.js.map +1 -0
- package/dist/DiscordGateway/Messaging.d.ts +587 -0
- package/dist/DiscordGateway/Messaging.d.ts.map +1 -0
- package/dist/DiscordGateway/Messaging.js +34 -0
- package/dist/DiscordGateway/Messaging.js.map +1 -0
- package/dist/DiscordGateway/Shard/StateStore.d.ts +24 -0
- package/dist/DiscordGateway/Shard/StateStore.d.ts.map +1 -0
- package/dist/DiscordGateway/Shard/StateStore.js +41 -0
- package/dist/DiscordGateway/Shard/StateStore.js.map +1 -0
- package/dist/DiscordGateway/Shard/heartbeats.d.ts +8 -0
- package/dist/DiscordGateway/Shard/heartbeats.d.ts.map +1 -0
- package/dist/DiscordGateway/Shard/heartbeats.js +25 -0
- package/dist/DiscordGateway/Shard/heartbeats.js.map +1 -0
- package/dist/DiscordGateway/Shard/identify.d.ts +12 -0
- package/dist/DiscordGateway/Shard/identify.d.ts.map +1 -0
- package/dist/DiscordGateway/Shard/identify.js +26 -0
- package/dist/DiscordGateway/Shard/identify.js.map +1 -0
- package/dist/DiscordGateway/Shard/sendEvents.d.ts +8 -0
- package/dist/DiscordGateway/Shard/sendEvents.d.ts.map +1 -0
- package/dist/DiscordGateway/Shard/sendEvents.js +26 -0
- package/dist/DiscordGateway/Shard/sendEvents.js.map +1 -0
- package/dist/DiscordGateway/Shard/utils.d.ts +6 -0
- package/dist/DiscordGateway/Shard/utils.d.ts.map +1 -0
- package/dist/DiscordGateway/Shard/utils.js +3 -0
- package/dist/DiscordGateway/Shard/utils.js.map +1 -0
- package/dist/DiscordGateway/Shard.d.ts +29 -0
- package/dist/DiscordGateway/Shard.d.ts.map +1 -0
- package/dist/DiscordGateway/Shard.js +134 -0
- package/dist/DiscordGateway/Shard.js.map +1 -0
- package/dist/DiscordGateway/ShardStore.d.ts +19 -0
- package/dist/DiscordGateway/ShardStore.d.ts.map +1 -0
- package/dist/DiscordGateway/ShardStore.js +23 -0
- package/dist/DiscordGateway/ShardStore.js.map +1 -0
- package/dist/DiscordGateway/Sharder.d.ts +14 -0
- package/dist/DiscordGateway/Sharder.d.ts.map +1 -0
- package/dist/DiscordGateway/Sharder.js +57 -0
- package/dist/DiscordGateway/Sharder.js.map +1 -0
- package/dist/DiscordGateway.d.ts +33 -0
- package/dist/DiscordGateway.d.ts.map +1 -0
- package/dist/DiscordGateway.js +21 -0
- package/dist/DiscordGateway.js.map +1 -0
- package/dist/DiscordREST/Generated.d.ts +5577 -0
- package/dist/DiscordREST/Generated.d.ts.map +1 -0
- package/dist/DiscordREST/Generated.js +2302 -0
- package/dist/DiscordREST/Generated.js.map +1 -0
- package/dist/DiscordREST/utils.d.ts +14 -0
- package/dist/DiscordREST/utils.d.ts.map +1 -0
- package/dist/DiscordREST/utils.js +23 -0
- package/dist/DiscordREST/utils.js.map +1 -0
- package/dist/DiscordREST.d.ts +22 -0
- package/dist/DiscordREST.d.ts.map +1 -0
- package/dist/DiscordREST.js +123 -0
- package/dist/DiscordREST.js.map +1 -0
- package/dist/Helpers/flags.d.ts +28 -0
- package/dist/Helpers/flags.d.ts.map +1 -0
- package/dist/Helpers/flags.js +45 -0
- package/dist/Helpers/flags.js.map +1 -0
- package/dist/Helpers/intents.d.ts +25 -0
- package/dist/Helpers/intents.d.ts.map +1 -0
- package/dist/Helpers/intents.js +29 -0
- package/dist/Helpers/intents.js.map +1 -0
- package/dist/Helpers/interactions.d.ts +116 -0
- package/dist/Helpers/interactions.d.ts.map +1 -0
- package/dist/Helpers/interactions.js +114 -0
- package/dist/Helpers/interactions.js.map +1 -0
- package/dist/Helpers/members.d.ts +10 -0
- package/dist/Helpers/members.d.ts.map +1 -0
- package/dist/Helpers/members.js +10 -0
- package/dist/Helpers/members.js.map +1 -0
- package/dist/Helpers/permissions.d.ts +42 -0
- package/dist/Helpers/permissions.d.ts.map +1 -0
- package/dist/Helpers/permissions.js +84 -0
- package/dist/Helpers/permissions.js.map +1 -0
- package/dist/Helpers/ui.d.ts +105 -0
- package/dist/Helpers/ui.d.ts.map +1 -0
- package/dist/Helpers/ui.js +135 -0
- package/dist/Helpers/ui.js.map +1 -0
- package/dist/Interactions/builder.d.ts +48 -0
- package/dist/Interactions/builder.d.ts.map +1 -0
- package/dist/Interactions/builder.js +63 -0
- package/dist/Interactions/builder.js.map +1 -0
- package/dist/Interactions/commandHelper.d.ts +83 -0
- package/dist/Interactions/commandHelper.d.ts.map +1 -0
- package/dist/Interactions/commandHelper.js +47 -0
- package/dist/Interactions/commandHelper.js.map +1 -0
- package/dist/Interactions/context.d.ts +53 -0
- package/dist/Interactions/context.d.ts.map +1 -0
- package/dist/Interactions/context.js +35 -0
- package/dist/Interactions/context.js.map +1 -0
- package/dist/Interactions/definitions.d.ts +43 -0
- package/dist/Interactions/definitions.d.ts.map +1 -0
- package/dist/Interactions/definitions.js +51 -0
- package/dist/Interactions/definitions.js.map +1 -0
- package/dist/Interactions/error.d.ts +2 -0
- package/dist/Interactions/error.d.ts.map +1 -0
- package/dist/Interactions/error.js +2 -0
- package/dist/Interactions/error.js.map +1 -0
- package/dist/Interactions/gateway.d.ts +20 -0
- package/dist/Interactions/gateway.d.ts.map +1 -0
- package/dist/Interactions/gateway.js +75 -0
- package/dist/Interactions/gateway.js.map +1 -0
- package/dist/Interactions/handlers.d.ts +15 -0
- package/dist/Interactions/handlers.d.ts.map +1 -0
- package/dist/Interactions/handlers.js +61 -0
- package/dist/Interactions/handlers.js.map +1 -0
- package/dist/Interactions/index.d.ts +17 -0
- package/dist/Interactions/index.d.ts.map +1 -0
- package/dist/Interactions/index.js +11 -0
- package/dist/Interactions/index.js.map +1 -0
- package/dist/Interactions/utils.d.ts +61 -0
- package/dist/Interactions/utils.d.ts.map +1 -0
- package/dist/Interactions/utils.js +29 -0
- package/dist/Interactions/utils.js.map +1 -0
- package/dist/Interactions/webhook.d.ts +71 -0
- package/dist/Interactions/webhook.d.ts.map +1 -0
- package/dist/Interactions/webhook.js +56 -0
- package/dist/Interactions/webhook.js.map +1 -0
- package/dist/LICENSE +21 -0
- package/{examples/readme.ts → dist/README.md} +13 -3
- package/dist/RateLimit/memory.d.ts +3 -0
- package/dist/RateLimit/memory.d.ts.map +1 -0
- package/dist/RateLimit/memory.js +35 -0
- package/dist/RateLimit/memory.js.map +1 -0
- package/dist/RateLimit/utils.d.ts +3 -0
- package/dist/RateLimit/utils.d.ts.map +1 -0
- package/dist/RateLimit/utils.js +18 -0
- package/dist/RateLimit/utils.js.map +1 -0
- package/dist/RateLimit.d.ts +30 -0
- package/dist/RateLimit.d.ts.map +1 -0
- package/dist/RateLimit.js +28 -0
- package/dist/RateLimit.js.map +1 -0
- package/dist/gateway.d.ts +19 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +19 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/mjs/Cache/driver.mjs +3 -0
- package/dist/mjs/Cache/driver.mjs.map +1 -0
- package/dist/mjs/Cache/memory.mjs +48 -0
- package/dist/mjs/Cache/memory.mjs.map +1 -0
- package/dist/mjs/Cache/memoryTTL.mjs +119 -0
- package/dist/mjs/Cache/memoryTTL.mjs.map +1 -0
- package/dist/mjs/Cache/prelude.mjs +131 -0
- package/dist/mjs/Cache/prelude.mjs.map +1 -0
- package/dist/mjs/Cache.mjs +90 -0
- package/dist/mjs/Cache.mjs.map +1 -0
- package/dist/mjs/DiscordConfig.mjs +32 -0
- package/dist/mjs/DiscordConfig.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/DiscordWS.mjs +77 -0
- package/dist/mjs/DiscordGateway/DiscordWS.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Messaging.mjs +35 -0
- package/dist/mjs/DiscordGateway/Messaging.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Shard/StateStore.mjs +41 -0
- package/dist/mjs/DiscordGateway/Shard/StateStore.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Shard/heartbeats.mjs +25 -0
- package/dist/mjs/DiscordGateway/Shard/heartbeats.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Shard/identify.mjs +29 -0
- package/dist/mjs/DiscordGateway/Shard/identify.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Shard/sendEvents.mjs +26 -0
- package/dist/mjs/DiscordGateway/Shard/sendEvents.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Shard/utils.mjs +3 -0
- package/dist/mjs/DiscordGateway/Shard/utils.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Shard.mjs +147 -0
- package/dist/mjs/DiscordGateway/Shard.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/ShardStore.mjs +24 -0
- package/dist/mjs/DiscordGateway/ShardStore.mjs.map +1 -0
- package/dist/mjs/DiscordGateway/Sharder.mjs +67 -0
- package/dist/mjs/DiscordGateway/Sharder.mjs.map +1 -0
- package/dist/mjs/DiscordGateway.mjs +21 -0
- package/dist/mjs/DiscordGateway.mjs.map +1 -0
- package/dist/mjs/DiscordREST/Generated.mjs +2471 -0
- package/dist/mjs/DiscordREST/Generated.mjs.map +1 -0
- package/dist/mjs/DiscordREST/utils.mjs +21 -0
- package/dist/mjs/DiscordREST/utils.mjs.map +1 -0
- package/dist/mjs/DiscordREST.mjs +119 -0
- package/dist/mjs/DiscordREST.mjs.map +1 -0
- package/dist/mjs/Helpers/flags.mjs +45 -0
- package/dist/mjs/Helpers/flags.mjs.map +1 -0
- package/dist/mjs/Helpers/intents.mjs +27 -0
- package/dist/mjs/Helpers/intents.mjs.map +1 -0
- package/dist/mjs/Helpers/interactions.mjs +115 -0
- package/dist/mjs/Helpers/interactions.mjs.map +1 -0
- package/dist/mjs/Helpers/members.mjs +9 -0
- package/dist/mjs/Helpers/members.mjs.map +1 -0
- package/dist/mjs/Helpers/permissions.mjs +84 -0
- package/dist/mjs/Helpers/permissions.mjs.map +1 -0
- package/dist/mjs/Helpers/ui.mjs +137 -0
- package/dist/mjs/Helpers/ui.mjs.map +1 -0
- package/dist/mjs/Interactions/builder.mjs +56 -0
- package/dist/mjs/Interactions/builder.mjs.map +1 -0
- package/dist/mjs/Interactions/commandHelper.mjs +49 -0
- package/dist/mjs/Interactions/commandHelper.mjs.map +1 -0
- package/dist/mjs/Interactions/context.mjs +28 -0
- package/dist/mjs/Interactions/context.mjs.map +1 -0
- package/dist/mjs/Interactions/definitions.mjs +51 -0
- package/dist/mjs/Interactions/definitions.mjs.map +1 -0
- package/dist/mjs/Interactions/error.mjs +2 -0
- package/dist/mjs/Interactions/error.mjs.map +1 -0
- package/dist/mjs/Interactions/gateway.mjs +82 -0
- package/dist/mjs/Interactions/gateway.mjs.map +1 -0
- package/dist/mjs/Interactions/handlers.mjs +64 -0
- package/dist/mjs/Interactions/handlers.mjs.map +1 -0
- package/dist/mjs/Interactions/index.mjs +11 -0
- package/dist/mjs/Interactions/index.mjs.map +1 -0
- package/dist/mjs/Interactions/utils.mjs +26 -0
- package/dist/mjs/Interactions/utils.mjs.map +1 -0
- package/dist/mjs/Interactions/webhook.mjs +75 -0
- package/dist/mjs/Interactions/webhook.mjs.map +1 -0
- package/dist/mjs/RateLimit/memory.mjs +39 -0
- package/dist/mjs/RateLimit/memory.mjs.map +1 -0
- package/dist/mjs/RateLimit/utils.mjs +18 -0
- package/dist/mjs/RateLimit/utils.mjs.map +1 -0
- package/dist/mjs/RateLimit.mjs +28 -0
- package/dist/mjs/RateLimit.mjs.map +1 -0
- package/dist/mjs/gateway.mjs +19 -0
- package/dist/mjs/gateway.mjs.map +1 -0
- package/dist/mjs/index.mjs +18 -0
- package/dist/mjs/index.mjs.map +1 -0
- package/dist/mjs/types.mjs +356 -0
- package/dist/mjs/types.mjs.map +1 -0
- package/dist/mjs/utils/Effect.mjs +44 -0
- package/dist/mjs/utils/Effect.mjs.map +1 -0
- package/dist/mjs/version.mjs +2 -0
- package/dist/mjs/version.mjs.map +1 -0
- package/dist/mjs/webhooks.mjs +6 -0
- package/dist/mjs/webhooks.mjs.map +1 -0
- package/dist/package.json +48 -0
- package/dist/src/Cache/driver.ts +37 -0
- package/dist/src/Cache/memory.ts +83 -0
- package/dist/src/Cache/memoryTTL.ts +225 -0
- package/dist/src/Cache/prelude.ts +279 -0
- package/dist/src/Cache.ts +261 -0
- package/dist/src/DiscordConfig.ts +67 -0
- package/dist/src/DiscordGateway/DiscordWS.ts +157 -0
- package/dist/src/DiscordGateway/Messaging.ts +71 -0
- package/dist/src/DiscordGateway/Shard/StateStore.ts +72 -0
- package/dist/src/DiscordGateway/Shard/heartbeats.ts +60 -0
- package/dist/src/DiscordGateway/Shard/identify.ts +50 -0
- package/dist/src/DiscordGateway/Shard/sendEvents.ts +43 -0
- package/dist/src/DiscordGateway/Shard/utils.ts +13 -0
- package/dist/src/DiscordGateway/Shard.ts +205 -0
- package/dist/src/DiscordGateway/ShardStore.ts +42 -0
- package/dist/src/DiscordGateway/Sharder.ts +118 -0
- package/dist/src/DiscordGateway.ts +79 -0
- package/dist/src/DiscordREST/Generated.ts +10832 -0
- package/dist/src/DiscordREST/utils.ts +42 -0
- package/dist/src/DiscordREST.ts +256 -0
- package/dist/src/Helpers/flags.ts +73 -0
- package/dist/src/Helpers/intents.ts +35 -0
- package/dist/src/Helpers/interactions.ts +317 -0
- package/dist/src/Helpers/members.ts +18 -0
- package/dist/src/Helpers/permissions.ts +145 -0
- package/dist/src/Helpers/ui.ts +253 -0
- package/dist/src/Interactions/builder.ts +171 -0
- package/dist/src/Interactions/commandHelper.ts +231 -0
- package/dist/src/Interactions/context.ts +104 -0
- package/dist/src/Interactions/definitions.ts +144 -0
- package/dist/src/Interactions/error.ts +3 -0
- package/dist/src/Interactions/gateway.ts +193 -0
- package/dist/src/Interactions/handlers.ts +108 -0
- package/dist/src/Interactions/index.ts +30 -0
- package/dist/src/Interactions/utils.ts +93 -0
- package/dist/src/Interactions/webhook.ts +204 -0
- package/dist/src/RateLimit/memory.ts +63 -0
- package/dist/src/RateLimit/utils.ts +28 -0
- package/dist/src/RateLimit.ts +90 -0
- package/dist/src/gateway.ts +50 -0
- package/dist/src/index.ts +44 -0
- package/dist/src/types.ts +3090 -0
- package/dist/src/utils/Effect.ts +65 -0
- package/dist/src/version.ts +1 -0
- package/dist/src/webhooks.ts +25 -0
- package/dist/types.d.ts +2458 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +356 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/Effect.d.ts +5 -0
- package/dist/utils/Effect.d.ts.map +1 -0
- package/dist/utils/Effect.js +42 -0
- package/dist/utils/Effect.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/webhooks.d.ts +8 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +6 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +19 -11
- package/src/version.ts +1 -0
- package/.babel.cjs.json +0 -11
- package/.babel.mjs.json +0 -10
- package/.envrc +0 -1
- package/.gitmodules +0 -3
- package/.husky/pre-commit +0 -2
- package/.oxlintrc.json +0 -72
- package/.prettierignore +0 -0
- package/.prettierrc.json +0 -5
- package/.tool-versions +0 -1
- package/.vscode/debug.cjs +0 -8
- package/.vscode/launch.json +0 -23
- package/.vscode/settings.json +0 -29
- package/.vscode/tasks.json +0 -44
- package/AGENTS.md +0 -15
- package/CHANGELOG.md +0 -1566
- package/examples/.env.example +0 -5
- package/examples/interactions.ts +0 -79
- package/examples/registry.ts +0 -66
- package/flake.lock +0 -27
- package/flake.nix +0 -21
- package/lerna.json +0 -12
- package/pnpm-workspace.yaml +0 -7
- package/scripts/generate-client.sh +0 -10
- package/scripts/worktree-setup.sh +0 -8
- package/test/index.test.ts +0 -5
- package/vitest.config.ts +0 -22
- /package/{tsconfig.base.json → dist/tsconfig.base.json} +0 -0
- /package/{tsconfig.build.json → dist/tsconfig.build.json} +0 -0
- /package/{tsconfig.examples.json → dist/tsconfig.examples.json} +0 -0
- /package/{tsconfig.json → dist/tsconfig.json} +0 -0
- /package/{tsconfig.madge.json → dist/tsconfig.madge.json} +0 -0
- /package/{tsconfig.test.json → dist/tsconfig.test.json} +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import * as Chunk from "effect/Chunk"
|
|
2
|
+
import { identity } from "effect/Function"
|
|
3
|
+
import * as Option from "effect/Option"
|
|
4
|
+
import type * as Cause from "effect/Cause"
|
|
5
|
+
import type * as Config from "effect/Config"
|
|
6
|
+
import * as Redacted from "effect/Redacted"
|
|
7
|
+
import * as Effect from "effect/Effect"
|
|
8
|
+
import * as Layer from "effect/Layer"
|
|
9
|
+
import * as ServiceMap from "effect/ServiceMap"
|
|
10
|
+
import type * as D from "./definitions.ts"
|
|
11
|
+
import type { DefinitionNotFound } from "./handlers.ts"
|
|
12
|
+
import { handlers } from "./handlers.ts"
|
|
13
|
+
import type { DiscordInteraction, InteractionBuilder } from "./index.ts"
|
|
14
|
+
import { Interaction } from "./index.ts"
|
|
15
|
+
import type * as Discord from "../types.ts"
|
|
16
|
+
import * as Verify from "discord-verify"
|
|
17
|
+
import * as Data from "effect/Data"
|
|
18
|
+
|
|
19
|
+
export class BadWebhookSignature {
|
|
20
|
+
readonly _tag = "BadWebhookSignature"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type Headers = Record<string, string | Array<string> | undefined>
|
|
24
|
+
|
|
25
|
+
const checkSignature = (
|
|
26
|
+
publicKey: string,
|
|
27
|
+
headers: Headers,
|
|
28
|
+
body: string,
|
|
29
|
+
crypto: SubtleCrypto,
|
|
30
|
+
algorithm: any,
|
|
31
|
+
) =>
|
|
32
|
+
Effect.fromOption(
|
|
33
|
+
Option.all({
|
|
34
|
+
signature: Option.fromNullishOr(headers["x-signature-ed25519"]),
|
|
35
|
+
timestamp: Option.fromNullishOr(headers["x-signature-timestamp"]),
|
|
36
|
+
}),
|
|
37
|
+
).pipe(
|
|
38
|
+
Effect.flatMap(_ =>
|
|
39
|
+
Effect.promise(() =>
|
|
40
|
+
Verify.verify(
|
|
41
|
+
body,
|
|
42
|
+
_.signature as string,
|
|
43
|
+
_.timestamp as string,
|
|
44
|
+
publicKey,
|
|
45
|
+
crypto,
|
|
46
|
+
algorithm,
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
),
|
|
50
|
+
Effect.filterOrFail(identity, () => new BadWebhookSignature()),
|
|
51
|
+
Effect.catchCause(() => Effect.fail(new BadWebhookSignature())),
|
|
52
|
+
Effect.asVoid,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
export interface MakeConfigOpts {
|
|
56
|
+
readonly applicationId: string
|
|
57
|
+
readonly publicKey: Redacted.Redacted
|
|
58
|
+
readonly crypto: SubtleCrypto
|
|
59
|
+
readonly algorithm: keyof typeof Verify.PlatformAlgorithm
|
|
60
|
+
}
|
|
61
|
+
const makeConfig = ({
|
|
62
|
+
algorithm,
|
|
63
|
+
applicationId,
|
|
64
|
+
crypto,
|
|
65
|
+
publicKey,
|
|
66
|
+
}: MakeConfigOpts) => ({
|
|
67
|
+
applicationId,
|
|
68
|
+
publicKey: Redacted.value(publicKey),
|
|
69
|
+
crypto,
|
|
70
|
+
algorithm: Verify.PlatformAlgorithm[algorithm],
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
export class WebhookConfig extends ServiceMap.Service<
|
|
74
|
+
WebhookConfig,
|
|
75
|
+
ReturnType<typeof makeConfig>
|
|
76
|
+
>()("dfx/Interactions/WebhookConfig") {}
|
|
77
|
+
|
|
78
|
+
export const layer = (opts: MakeConfigOpts) =>
|
|
79
|
+
Layer.succeed(WebhookConfig, makeConfig(opts))
|
|
80
|
+
|
|
81
|
+
export const layerConfig: (
|
|
82
|
+
config: Config.Config<MakeConfigOpts>,
|
|
83
|
+
) => Layer.Layer<WebhookConfig, Config.ConfigError> = (
|
|
84
|
+
config: Config.Config<MakeConfigOpts>,
|
|
85
|
+
) => Layer.effect(WebhookConfig, Effect.map(config.asEffect(), makeConfig))
|
|
86
|
+
|
|
87
|
+
export class WebhookParseError extends Data.TaggedError("WebhookParseError")<{
|
|
88
|
+
cause: unknown
|
|
89
|
+
}> {}
|
|
90
|
+
|
|
91
|
+
const fromHeadersAndBody = (headers: Headers, body: string) =>
|
|
92
|
+
WebhookConfig.use(({ algorithm, crypto, publicKey }) =>
|
|
93
|
+
checkSignature(publicKey, headers, body, crypto, algorithm).pipe(
|
|
94
|
+
Effect.andThen(
|
|
95
|
+
Effect.try({
|
|
96
|
+
try: () => JSON.parse(body) as Discord.APIInteraction,
|
|
97
|
+
catch: cause => new WebhookParseError({ cause }),
|
|
98
|
+
}),
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
const run = <R, E>(
|
|
104
|
+
definitions: Chunk.Chunk<
|
|
105
|
+
readonly [
|
|
106
|
+
handler: D.InteractionDefinition<R, E>,
|
|
107
|
+
transform: (
|
|
108
|
+
self: Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>,
|
|
109
|
+
) => Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>,
|
|
110
|
+
]
|
|
111
|
+
>,
|
|
112
|
+
handleResponse: (
|
|
113
|
+
ix: Discord.APIInteraction,
|
|
114
|
+
_: Discord.CreateInteractionResponseRequest,
|
|
115
|
+
) => Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>,
|
|
116
|
+
) => {
|
|
117
|
+
const handler = handlers(definitions, handleResponse)
|
|
118
|
+
return (
|
|
119
|
+
headers: Headers,
|
|
120
|
+
body: string,
|
|
121
|
+
): Effect.Effect<
|
|
122
|
+
Discord.CreateInteractionResponseRequest,
|
|
123
|
+
BadWebhookSignature | WebhookParseError | E | DefinitionNotFound,
|
|
124
|
+
WebhookConfig | Exclude<R, DiscordInteraction>
|
|
125
|
+
> =>
|
|
126
|
+
Effect.flatMap(fromHeadersAndBody(headers, body), interaction =>
|
|
127
|
+
Effect.withSpan(
|
|
128
|
+
Effect.provideService(
|
|
129
|
+
handler[interaction.type](interaction),
|
|
130
|
+
Interaction,
|
|
131
|
+
interaction,
|
|
132
|
+
),
|
|
133
|
+
"dfx.Interaction",
|
|
134
|
+
{
|
|
135
|
+
attributes: { interactionId: interaction.id },
|
|
136
|
+
captureStackTrace: false,
|
|
137
|
+
},
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface HandleWebhookOpts<E> {
|
|
143
|
+
headers: Headers
|
|
144
|
+
body: string
|
|
145
|
+
success: (a: Discord.CreateInteractionResponseRequest) => Effect.Effect<void>
|
|
146
|
+
error: (e: Cause.Cause<E>) => Effect.Effect<void>
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @tsplus getter dfx/InteractionBuilder webhookHandler
|
|
151
|
+
*/
|
|
152
|
+
export const makeHandler = <R, E, TE>(
|
|
153
|
+
ix: InteractionBuilder<R, E, TE>,
|
|
154
|
+
): (({
|
|
155
|
+
body,
|
|
156
|
+
error,
|
|
157
|
+
headers,
|
|
158
|
+
success,
|
|
159
|
+
}: HandleWebhookOpts<
|
|
160
|
+
E | WebhookParseError | BadWebhookSignature | DefinitionNotFound
|
|
161
|
+
>) => Effect.Effect<void, never, WebhookConfig>) => {
|
|
162
|
+
const handle = run(
|
|
163
|
+
Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
|
|
164
|
+
(_i, r) => Effect.succeed(r),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
return ({
|
|
168
|
+
body,
|
|
169
|
+
error,
|
|
170
|
+
headers,
|
|
171
|
+
success,
|
|
172
|
+
}: HandleWebhookOpts<
|
|
173
|
+
E | WebhookParseError | BadWebhookSignature | DefinitionNotFound
|
|
174
|
+
>): Effect.Effect<void, never, WebhookConfig> =>
|
|
175
|
+
handle(headers, body).pipe(
|
|
176
|
+
Effect.flatMap(success),
|
|
177
|
+
Effect.catchCause(error),
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @tsplus getter dfx/InteractionBuilder simpleWebhookHandler
|
|
183
|
+
*/
|
|
184
|
+
export const makeSimpleHandler = <R, E, TE>(
|
|
185
|
+
ix: InteractionBuilder<R, E, TE>,
|
|
186
|
+
): (({
|
|
187
|
+
body,
|
|
188
|
+
headers,
|
|
189
|
+
}: {
|
|
190
|
+
headers: Headers
|
|
191
|
+
body: string
|
|
192
|
+
}) => Effect.Effect<
|
|
193
|
+
Discord.CreateInteractionResponseRequest,
|
|
194
|
+
BadWebhookSignature | WebhookParseError | DefinitionNotFound,
|
|
195
|
+
WebhookConfig
|
|
196
|
+
>) => {
|
|
197
|
+
const handle = run(
|
|
198
|
+
Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
|
|
199
|
+
(_i, r) => Effect.succeed(r),
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
return ({ body, headers }: { headers: Headers; body: string }) =>
|
|
203
|
+
handle(headers, body)
|
|
204
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as Option from "effect/Option"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import type { BucketDetails, RateLimitStoreService } from "../RateLimit.ts"
|
|
4
|
+
|
|
5
|
+
interface Counter {
|
|
6
|
+
count: number
|
|
7
|
+
expires: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const make = (): RateLimitStoreService => {
|
|
11
|
+
const buckets = new Map<string, BucketDetails>()
|
|
12
|
+
const routes = new Map<string, string>()
|
|
13
|
+
const counters = new Map<string, Counter>()
|
|
14
|
+
|
|
15
|
+
const getCounter = (key: string) =>
|
|
16
|
+
Option.filter(
|
|
17
|
+
Option.fromNullishOr(counters.get(key)),
|
|
18
|
+
c => c.expires > Date.now(),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const getBucketForRoute = (route: string) =>
|
|
22
|
+
Effect.sync(() => Option.fromNullishOr(buckets.get(routes.get(route)!)))
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
hasBucket: key => Effect.sync(() => buckets.has(key)),
|
|
26
|
+
|
|
27
|
+
putBucket: bucket =>
|
|
28
|
+
Effect.sync(() => {
|
|
29
|
+
buckets.set(bucket.key, bucket)
|
|
30
|
+
}),
|
|
31
|
+
|
|
32
|
+
getBucketForRoute,
|
|
33
|
+
|
|
34
|
+
putBucketRoute: (route, bucket) =>
|
|
35
|
+
Effect.sync(() => {
|
|
36
|
+
routes.set(route, bucket)
|
|
37
|
+
}),
|
|
38
|
+
|
|
39
|
+
removeCounter: key =>
|
|
40
|
+
Effect.sync(() => {
|
|
41
|
+
counters.delete(key)
|
|
42
|
+
}),
|
|
43
|
+
|
|
44
|
+
incrementCounter: (key, window, limit) =>
|
|
45
|
+
Effect.sync(() => {
|
|
46
|
+
const now = Date.now()
|
|
47
|
+
const perRequest = Math.ceil(window / limit)
|
|
48
|
+
const counter = Option.getOrElse(
|
|
49
|
+
getCounter(key),
|
|
50
|
+
(): Counter => ({
|
|
51
|
+
expires: now,
|
|
52
|
+
count: 0,
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
const count = counter.count + 1
|
|
57
|
+
const expires = counter.expires + perRequest
|
|
58
|
+
counters.set(key, { ...counter, count, expires })
|
|
59
|
+
|
|
60
|
+
return [count, expires - now]
|
|
61
|
+
}),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Duration } from "effect/Duration"
|
|
2
|
+
import { millis, zero } from "effect/Duration"
|
|
3
|
+
|
|
4
|
+
export const delayFrom = (
|
|
5
|
+
window: number,
|
|
6
|
+
limit: number,
|
|
7
|
+
count: number,
|
|
8
|
+
ttl: number,
|
|
9
|
+
): Duration => {
|
|
10
|
+
const perRequest = Math.ceil(window / limit)
|
|
11
|
+
|
|
12
|
+
const totalTime = count * perRequest
|
|
13
|
+
const elapsedTime = totalTime - ttl
|
|
14
|
+
const elapsedWindows = Math.floor(elapsedTime / window)
|
|
15
|
+
const completedRequests = elapsedWindows * limit
|
|
16
|
+
const remainingRequests = count - completedRequests
|
|
17
|
+
const remainingWindows = Math.floor((remainingRequests - 1) / limit)
|
|
18
|
+
const delayRemainder = elapsedTime % window
|
|
19
|
+
|
|
20
|
+
const requestRemainder = count % limit
|
|
21
|
+
const staggerDelay = requestRemainder * 50
|
|
22
|
+
|
|
23
|
+
if (remainingWindows === 0) {
|
|
24
|
+
return zero
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return millis(remainingWindows * window - delayRemainder + staggerDelay)
|
|
28
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as Duration from "effect/Duration"
|
|
2
|
+
import type * as Option from "effect/Option"
|
|
3
|
+
import * as Effect from "effect/Effect"
|
|
4
|
+
import * as Layer from "effect/Layer"
|
|
5
|
+
import * as Memory from "./RateLimit/memory.ts"
|
|
6
|
+
import { delayFrom } from "./RateLimit/utils.ts"
|
|
7
|
+
import * as ServiceMap from "effect/ServiceMap"
|
|
8
|
+
|
|
9
|
+
export type BucketDetails = {
|
|
10
|
+
key: "global" | string
|
|
11
|
+
resetAfter: number
|
|
12
|
+
limit: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RateLimitStoreService {
|
|
16
|
+
readonly hasBucket: (bucketKey: string) => Effect.Effect<boolean>
|
|
17
|
+
|
|
18
|
+
readonly putBucket: (bucket: BucketDetails) => Effect.Effect<void>
|
|
19
|
+
|
|
20
|
+
readonly getBucketForRoute: (
|
|
21
|
+
route: string,
|
|
22
|
+
) => Effect.Effect<Option.Option<BucketDetails>>
|
|
23
|
+
|
|
24
|
+
readonly putBucketRoute: (
|
|
25
|
+
route: string,
|
|
26
|
+
bucketKey: string,
|
|
27
|
+
) => Effect.Effect<void>
|
|
28
|
+
|
|
29
|
+
readonly incrementCounter: (
|
|
30
|
+
key: string,
|
|
31
|
+
window: number,
|
|
32
|
+
limit: number,
|
|
33
|
+
) => Effect.Effect<readonly [count: number, ttl: number]>
|
|
34
|
+
|
|
35
|
+
readonly removeCounter: (key: string) => Effect.Effect<void>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class RateLimitStore extends ServiceMap.Service<
|
|
39
|
+
RateLimitStore,
|
|
40
|
+
RateLimitStoreService
|
|
41
|
+
>()("dfx/RateLimit/RateLimitStore") {}
|
|
42
|
+
|
|
43
|
+
export const MemoryRateLimitStoreLive = Layer.sync(RateLimitStore, Memory.make)
|
|
44
|
+
|
|
45
|
+
const makeLimiter = Effect.gen(function* () {
|
|
46
|
+
const store = yield* RateLimitStore
|
|
47
|
+
|
|
48
|
+
const maybeWait = (
|
|
49
|
+
key: string,
|
|
50
|
+
window: Duration.Duration,
|
|
51
|
+
limit: number,
|
|
52
|
+
multiplier = 1.05,
|
|
53
|
+
) => {
|
|
54
|
+
const windowMs = Duration.toMillis(window) * multiplier
|
|
55
|
+
|
|
56
|
+
return store.incrementCounter(key, windowMs, limit).pipe(
|
|
57
|
+
Effect.map(([count, ttl]) => delayFrom(windowMs, limit, count, ttl)),
|
|
58
|
+
Effect.tap(d =>
|
|
59
|
+
Effect.annotateLogs(Effect.logTrace("maybeWait"), {
|
|
60
|
+
service: "RateLimit",
|
|
61
|
+
key,
|
|
62
|
+
window: Duration.toMillis(window),
|
|
63
|
+
windowMs,
|
|
64
|
+
limit,
|
|
65
|
+
delay: Duration.toMillis(d),
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
68
|
+
Effect.tap(_ =>
|
|
69
|
+
Duration.toMillis(_) === 0 ? Effect.void : Effect.sleep(_),
|
|
70
|
+
),
|
|
71
|
+
Effect.asVoid,
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { maybeWait }
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
export class RateLimiter extends ServiceMap.Service<
|
|
79
|
+
RateLimiter,
|
|
80
|
+
{
|
|
81
|
+
maybeWait: (
|
|
82
|
+
key: string,
|
|
83
|
+
window: Duration.Duration,
|
|
84
|
+
limit: number,
|
|
85
|
+
multiplier?: number,
|
|
86
|
+
) => Effect.Effect<void, never, never>
|
|
87
|
+
}
|
|
88
|
+
>()("dfx/RateLimit/RateLimiter") {}
|
|
89
|
+
|
|
90
|
+
export const RateLimiterLive = Layer.effect(RateLimiter, makeLimiter)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as CachePrelude from "./Cache/prelude.ts"
|
|
2
|
+
import type { DiscordGateway } from "./DiscordGateway.ts"
|
|
3
|
+
import { DiscordGatewayLive } from "./DiscordGateway.ts"
|
|
4
|
+
import * as DiscordWS from "./DiscordGateway/DiscordWS.ts"
|
|
5
|
+
import { JsonDiscordWSCodecLive } from "./DiscordGateway/DiscordWS.ts"
|
|
6
|
+
import * as Shard from "./DiscordGateway/Shard.ts"
|
|
7
|
+
import { ShardStateStore } from "./DiscordGateway/Shard/StateStore.ts"
|
|
8
|
+
import * as SendEvent from "./DiscordGateway/Shard/sendEvents.ts"
|
|
9
|
+
import * as ShardStore from "./DiscordGateway/ShardStore.ts"
|
|
10
|
+
import { MemoryShardStoreLive } from "./DiscordGateway/ShardStore.ts"
|
|
11
|
+
import type { DiscordREST } from "./DiscordREST.ts"
|
|
12
|
+
import { DiscordRESTLive } from "./DiscordREST.ts"
|
|
13
|
+
import type { InteractionsRegistry } from "./Interactions/gateway.ts"
|
|
14
|
+
import { InteractionsRegistryLive } from "./Interactions/gateway.ts"
|
|
15
|
+
import type { RateLimiter } from "./RateLimit.ts"
|
|
16
|
+
import { MemoryRateLimitStoreLive, RateLimiterLive } from "./RateLimit.ts"
|
|
17
|
+
import * as Layer from "effect/Layer"
|
|
18
|
+
import type * as HttpClient from "effect/unstable/http/HttpClient"
|
|
19
|
+
import type { DiscordConfig } from "./DiscordConfig.ts"
|
|
20
|
+
import type { WebSocketConstructor } from "effect/unstable/socket/Socket"
|
|
21
|
+
|
|
22
|
+
export { DiscordGateway, DiscordGatewayLive } from "./DiscordGateway.ts"
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
InteractionsRegistry,
|
|
26
|
+
InteractionsRegistryLive,
|
|
27
|
+
interactionsSync,
|
|
28
|
+
run as runIx,
|
|
29
|
+
setInteractionsSync,
|
|
30
|
+
} from "./Interactions/gateway.ts"
|
|
31
|
+
|
|
32
|
+
export { CachePrelude, DiscordWS, SendEvent, Shard, ShardStore }
|
|
33
|
+
|
|
34
|
+
export const DiscordLive: Layer.Layer<
|
|
35
|
+
RateLimiter | DiscordGateway | DiscordREST,
|
|
36
|
+
never,
|
|
37
|
+
DiscordConfig | WebSocketConstructor | HttpClient.HttpClient
|
|
38
|
+
> = Layer.mergeAll(RateLimiterLive, DiscordGatewayLive).pipe(
|
|
39
|
+
Layer.provideMerge(DiscordRESTLive),
|
|
40
|
+
Layer.provide(JsonDiscordWSCodecLive),
|
|
41
|
+
Layer.provide(MemoryRateLimitStoreLive),
|
|
42
|
+
Layer.provide(MemoryShardStoreLive),
|
|
43
|
+
Layer.provide(ShardStateStore.MemoryLive),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
export const DiscordIxLive: Layer.Layer<
|
|
47
|
+
RateLimiter | DiscordGateway | DiscordREST | InteractionsRegistry,
|
|
48
|
+
never,
|
|
49
|
+
DiscordConfig | WebSocketConstructor | HttpClient.HttpClient
|
|
50
|
+
> = InteractionsRegistryLive.pipe(Layer.provideMerge(DiscordLive))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { HttpClient } from "effect/unstable/http/HttpClient"
|
|
2
|
+
import * as Cache from "./Cache.ts"
|
|
3
|
+
import * as DiscordConfig from "./DiscordConfig.ts"
|
|
4
|
+
import type { DiscordREST } from "./DiscordREST.ts"
|
|
5
|
+
import { DiscordRESTLive } from "./DiscordREST.ts"
|
|
6
|
+
import * as Flags from "./Helpers/flags.ts"
|
|
7
|
+
import * as Intents from "./Helpers/intents.ts"
|
|
8
|
+
import * as IxHelpers from "./Helpers/interactions.ts"
|
|
9
|
+
import * as Members from "./Helpers/members.ts"
|
|
10
|
+
import * as Perms from "./Helpers/permissions.ts"
|
|
11
|
+
import * as UI from "./Helpers/ui.ts"
|
|
12
|
+
import * as Ix from "./Interactions/index.ts"
|
|
13
|
+
import { MemoryRateLimitStoreLive } from "./RateLimit.ts"
|
|
14
|
+
import * as Discord from "./types.ts"
|
|
15
|
+
import * as Layer from "effect/Layer"
|
|
16
|
+
|
|
17
|
+
export { DiscordREST, DiscordRESTLive } from "./DiscordREST.ts"
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
type BucketDetails,
|
|
21
|
+
MemoryRateLimitStoreLive,
|
|
22
|
+
RateLimitStore,
|
|
23
|
+
RateLimiter,
|
|
24
|
+
RateLimiterLive,
|
|
25
|
+
} from "./RateLimit.ts"
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
Cache,
|
|
29
|
+
Discord,
|
|
30
|
+
DiscordConfig,
|
|
31
|
+
Flags,
|
|
32
|
+
Intents,
|
|
33
|
+
Ix,
|
|
34
|
+
IxHelpers,
|
|
35
|
+
Members,
|
|
36
|
+
Perms,
|
|
37
|
+
UI,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const DiscordRESTMemoryLive: Layer.Layer<
|
|
41
|
+
DiscordREST,
|
|
42
|
+
never,
|
|
43
|
+
DiscordConfig.DiscordConfig | HttpClient
|
|
44
|
+
> = DiscordRESTLive.pipe(Layer.provide(MemoryRateLimitStoreLive))
|