@distilled.cloud/discord 1.0.0-rc.12 → 1.0.0-rc.13
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/README.md +34 -0
- package/lib/protocol.d.ts +2 -2
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +2 -1
- package/lib/protocol.js.map +1 -1
- package/lib/response-validation.test.d.ts +4 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +31 -0
- package/lib/response-validation.test.js.map +1 -0
- package/package.json +4 -4
- package/src/protocol.ts +8 -3
- package/src/response-validation.test.ts +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @distilled.cloud/discord
|
|
2
|
+
|
|
3
|
+
Effect-native SDK for [discord](https://www.npmjs.com/package/@distilled.cloud/discord).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @distilled.cloud/discord effect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Effect, Layer } from "effect";
|
|
15
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
16
|
+
import * as Discord from "@distilled.cloud/discord";
|
|
17
|
+
|
|
18
|
+
const program = Effect.gen(function* () {
|
|
19
|
+
const result = yield* Discord.listApplicationCommands({});
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const Live = Layer.mergeAll(
|
|
24
|
+
FetchHttpClient.layer,
|
|
25
|
+
Discord.CredentialsFromEnv,
|
|
26
|
+
Discord.DiscordProtocol,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Auth
|
|
33
|
+
|
|
34
|
+
Required: `DISCORD_BOT_TOKEN`, `DISCORD_TOKEN`, `DISCORD_TOKEN_TYPE`. Optional: `DISCORD_API_URL`. Sent as `Authorization: Bearer`.
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Layer from "effect/Layer";
|
|
2
|
-
import type * as HttpClient from "effect/
|
|
3
|
-
import type * as HttpClientError from "effect/
|
|
2
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
4
4
|
import type * as API from "@distilled.cloud/core/api";
|
|
5
5
|
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
6
6
|
import { Credentials } from "./credentials.ts";
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAKhE,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,WAAW,GACX,eAAe,CAAC,eAAe,CAAC;AAEpC,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AA4CnE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAsBlD,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -16,7 +16,7 @@ import * as Effect from "effect/Effect";
|
|
|
16
16
|
import * as Redacted from "effect/Redacted";
|
|
17
17
|
import { makeRestProtocol, } from "@distilled.cloud/core/protocol-rest";
|
|
18
18
|
import { Credentials } from "./credentials.js";
|
|
19
|
-
import { UnknownDiscordError } from "./errors.js";
|
|
19
|
+
import { UnknownDiscordError, DiscordParseError, } from "./errors.js";
|
|
20
20
|
/**
|
|
21
21
|
* Discord's error body is `{ code: <numeric JSON error code>, message }`.
|
|
22
22
|
* The OAuth2 token endpoints answer in the OAuth style instead
|
|
@@ -77,5 +77,6 @@ export const DiscordProtocol = makeRestProtocol({
|
|
|
77
77
|
errors: errorDetails(body),
|
|
78
78
|
body,
|
|
79
79
|
}),
|
|
80
|
+
parseError: ({ body, cause }) => new DiscordParseError({ body, cause }),
|
|
80
81
|
});
|
|
81
82
|
//# sourceMappingURL=protocol.js.map
|
package/lib/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAK5C,OAAO,EACL,gBAAgB,GAEjB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAK5C,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xE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.d.ts","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAmCpD,eAAO,MAAM,oBAAoB,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,cAAc,CAAC,GAC3E,IAAI,GACJ,KAAY,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runValidationModes } from "@distilled.cloud/core/testing";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { credentials } from "./credentials.js";
|
|
5
|
+
import { DiscordParseError } from "./errors.js";
|
|
6
|
+
import * as Retry from "./retry.js";
|
|
7
|
+
import { getGateway } from "./services/discord.js";
|
|
8
|
+
// getGateway declares `{ url: string }`.
|
|
9
|
+
const run = (body) => runValidationModes(getGateway({}).pipe(Retry.none, Effect.provide(credentials({ token: "test" }))), { body });
|
|
10
|
+
describe("Discord response validation", () => {
|
|
11
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
12
|
+
const body = { url: "wss://gateway.discord.gg" };
|
|
13
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
14
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
15
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
16
|
+
});
|
|
17
|
+
test("a body missing required members: lenient returns it, strict fails", async () => {
|
|
18
|
+
const { lenient, strict } = await run("{}");
|
|
19
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: {} });
|
|
20
|
+
expect(strict._tag).toBe("Failure");
|
|
21
|
+
expect(strict.failure).toBeInstanceOf(DiscordParseError);
|
|
22
|
+
});
|
|
23
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
24
|
+
const { lenient, strict } = await run("not json");
|
|
25
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
26
|
+
expect(strict.failure).toBeInstanceOf(DiscordParseError);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
// DiscordParseError is part of every operation's declared error type.
|
|
30
|
+
export const parseErrorIsDeclared = true;
|
|
31
|
+
//# sourceMappingURL=response-validation.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.js","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,yCAAyC;AACzC,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAC3B,kBAAkB,CAChB,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CACjB,KAAK,CAAC,IAAI,EACV,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAC/C,EACD,EAAE,IAAI,EAAE,CACT,CAAC;AAEJ,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,0BAA0B,EAAE,CAAC;QACjD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAA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|
{
|
|
2
2
|
"name": "@distilled.cloud/discord",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -58,15 +58,15 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
61
|
+
"@distilled.cloud/core": "1.0.0-rc.13"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/bun": "1.3.14",
|
|
65
65
|
"@types/node": "26.2.0",
|
|
66
|
-
"@effect/platform-bun": "
|
|
66
|
+
"@effect/platform-bun": "^4.0.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"effect": "
|
|
69
|
+
"effect": "^4.0.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsc -b",
|
package/src/protocol.ts
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
import * as Effect from "effect/Effect";
|
|
16
16
|
import type * as Layer from "effect/Layer";
|
|
17
17
|
import * as Redacted from "effect/Redacted";
|
|
18
|
-
import type * as HttpClient from "effect/
|
|
19
|
-
import type * as HttpClientError from "effect/
|
|
18
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
19
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
20
20
|
import type * as API from "@distilled.cloud/core/api";
|
|
21
21
|
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
22
22
|
import {
|
|
@@ -24,7 +24,11 @@ import {
|
|
|
24
24
|
type RestErrorEnvelope,
|
|
25
25
|
} from "@distilled.cloud/core/protocol-rest";
|
|
26
26
|
import { Credentials, type Config } from "./credentials.ts";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
UnknownDiscordError,
|
|
29
|
+
type DefaultErrors,
|
|
30
|
+
DiscordParseError,
|
|
31
|
+
} from "./errors.ts";
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Error channel shared by every generated Discord operation. Generated
|
|
@@ -103,4 +107,5 @@ export const DiscordProtocol: Layer.Layer<API.Protocol> =
|
|
|
103
107
|
errors: errorDetails(body),
|
|
104
108
|
body,
|
|
105
109
|
}),
|
|
110
|
+
parseError: ({ body, cause }) => new DiscordParseError({ body, cause }),
|
|
106
111
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runValidationModes } from "@distilled.cloud/core/testing";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { credentials } from "./credentials.ts";
|
|
5
|
+
import { DiscordParseError } from "./errors.ts";
|
|
6
|
+
import * as Retry from "./retry.ts";
|
|
7
|
+
import { getGateway } from "./services/discord.ts";
|
|
8
|
+
import type { DiscordOpError } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
// getGateway declares `{ url: string }`.
|
|
11
|
+
const run = (body: string) =>
|
|
12
|
+
runValidationModes(
|
|
13
|
+
getGateway({}).pipe(
|
|
14
|
+
Retry.none,
|
|
15
|
+
Effect.provide(credentials({ token: "test" })),
|
|
16
|
+
),
|
|
17
|
+
{ body },
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
describe("Discord response validation", () => {
|
|
21
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
22
|
+
const body = { url: "wss://gateway.discord.gg" };
|
|
23
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
24
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
25
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a body missing required members: lenient returns it, strict fails", async () => {
|
|
29
|
+
const { lenient, strict } = await run("{}");
|
|
30
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: {} });
|
|
31
|
+
expect(strict._tag).toBe("Failure");
|
|
32
|
+
expect((strict as any).failure).toBeInstanceOf(DiscordParseError);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
36
|
+
const { lenient, strict } = await run("not json");
|
|
37
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
38
|
+
expect((strict as any).failure).toBeInstanceOf(DiscordParseError);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// DiscordParseError is part of every operation's declared error type.
|
|
43
|
+
export const parseErrorIsDeclared: [DiscordParseError] extends [DiscordOpError]
|
|
44
|
+
? true
|
|
45
|
+
: false = true;
|