@distilled.cloud/digitalocean 1.0.0-rc.11 → 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 +4 -4
- 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 +6 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +39 -0
- package/lib/response-validation.test.js.map +1 -0
- package/package.json +4 -4
- package/src/protocol.ts +7 -4
- package/src/response-validation.test.ts +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @distilled.cloud/digitalocean
|
|
2
|
+
|
|
3
|
+
Effect-native SDK for [digitalocean](https://www.npmjs.com/package/@distilled.cloud/digitalocean).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @distilled.cloud/digitalocean 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 DigitalOcean from "@distilled.cloud/digitalocean";
|
|
17
|
+
|
|
18
|
+
const program = Effect.gen(function* () {
|
|
19
|
+
const result = yield* DigitalOcean.accountGet({});
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const Live = Layer.mergeAll(
|
|
24
|
+
FetchHttpClient.layer,
|
|
25
|
+
DigitalOcean.CredentialsFromEnv,
|
|
26
|
+
DigitalOcean.DigitalOceanProtocol,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Auth
|
|
33
|
+
|
|
34
|
+
Required: `DIGITALOCEAN_ACCESS_TOKEN`, `DIGITALOCEAN_API_KEY`. Optional: `DIGITALOCEAN_API_BASE_URL`. Sent as `Authorization: Bearer`.
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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 { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
6
6
|
import { Credentials } from "./credentials.ts";
|
|
7
|
-
import { UnknownDigitalOceanError } from "./errors.ts";
|
|
7
|
+
import { UnknownDigitalOceanError, DigitalOceanParseError } from "./errors.ts";
|
|
8
8
|
/**
|
|
9
9
|
* Error channel shared by every generated DigitalOcean operation. Generated
|
|
10
10
|
* service files annotate operations with `API.OperationMethod<I, O,
|
|
11
11
|
* DigitalOceanOpError, DigitalOceanOpContext>` explicitly so the compiler
|
|
12
12
|
* never infers these back out of the schema generics.
|
|
13
13
|
*/
|
|
14
|
-
export type DigitalOceanOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownDigitalOceanError | ConfigError | HttpClientError.HttpClientError;
|
|
14
|
+
export type DigitalOceanOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownDigitalOceanError | ConfigError | HttpClientError.HttpClientError | DigitalOceanParseError;
|
|
15
15
|
/** Context (requirements) shared by every generated DigitalOcean operation. */
|
|
16
16
|
export type DigitalOceanOpContext = Credentials | HttpClient.HttpClient;
|
|
17
17
|
export declare const DigitalOceanProtocol: Layer.Layer<API.Protocol>;
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAmBA,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":"AAmBA,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;AAKtD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAC3B,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,wBAAwB,GACxB,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,sBAAsB,CAAC;AAE3B,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAsBxE,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CA0BvD,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -20,7 +20,7 @@ import * as Effect from "effect/Effect";
|
|
|
20
20
|
import * as Redacted from "effect/Redacted";
|
|
21
21
|
import { makeRestProtocol, } from "@distilled.cloud/core/protocol-rest";
|
|
22
22
|
import { Credentials } from "./credentials.js";
|
|
23
|
-
import { UnknownDigitalOceanError } from "./errors.js";
|
|
23
|
+
import { UnknownDigitalOceanError, DigitalOceanParseError } from "./errors.js";
|
|
24
24
|
/**
|
|
25
25
|
* DigitalOcean error bodies are `{ id, message, request_id? }` — `id` is the
|
|
26
26
|
* machine-readable half (`not_found`, `forbidden`, …). A response that
|
|
@@ -62,5 +62,6 @@ export const DigitalOceanProtocol = makeRestProtocol({
|
|
|
62
62
|
message,
|
|
63
63
|
body,
|
|
64
64
|
}),
|
|
65
|
+
parseError: ({ body, cause }) => new DigitalOceanParseError({ body, cause }),
|
|
65
66
|
});
|
|
66
67
|
//# 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;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EACL,gBAAgB,GAEjB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EACL,gBAAgB,GAEjB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAkB/E;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,IAAa,EAAiC,EAAE;IACrE,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChE,MAAM,CAAC,GAAG,IAA+B,C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CAAC,SAAS;QACjB,OAAO;QACP,IAAI;KACL,CAAC;IACJ,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAC9B,IAAI,sBAAsB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;CAC9C,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DigitalOceanParseError } from "./errors.ts";
|
|
2
|
+
import type { DigitalOceanOpError } from "./protocol.ts";
|
|
3
|
+
export declare const parseErrorIsDeclared: [DigitalOceanParseError] extends [
|
|
4
|
+
DigitalOceanOpError
|
|
5
|
+
] ? true : false;
|
|
6
|
+
//# sourceMappingURL=response-validation.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.d.ts","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AA2CzD,eAAO,MAAM,oBAAoB,EAAE,CAAC,sBAAsB,CAAC,SAAS;IAClE,mBAAmB;CACpB,GACG,IAAI,GACJ,KAAY,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { fromApiKey } from "./credentials.js";
|
|
5
|
+
import { DigitalOceanParseError } from "./errors.js";
|
|
6
|
+
import * as Retry from "./retry.js";
|
|
7
|
+
import { getBalance } from "./services/digitalocean.js";
|
|
8
|
+
// getBalance declares only optional string members (`account_balance?: string`, …),
|
|
9
|
+
// so the mismatch is a wrong primitive type.
|
|
10
|
+
const run = (body) => runValidationModes(getBalance({}).pipe(Retry.none, Effect.provide(fromApiKey({ apiKey: "test" }))), { body });
|
|
11
|
+
describe("DigitalOcean response validation", () => {
|
|
12
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
13
|
+
const body = {
|
|
14
|
+
month_to_date_balance: "0.00",
|
|
15
|
+
account_balance: "0.00",
|
|
16
|
+
month_to_date_usage: "0.00",
|
|
17
|
+
generated_at: "2026-01-01T00:00:00Z",
|
|
18
|
+
};
|
|
19
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
20
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
21
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
22
|
+
});
|
|
23
|
+
test("a member with the wrong primitive type: lenient returns it, strict fails", async () => {
|
|
24
|
+
const body = { account_balance: 0 };
|
|
25
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
26
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
27
|
+
expect(strict._tag).toBe("Failure");
|
|
28
|
+
expect(strict.failure).toBeInstanceOf(DigitalOceanParseError);
|
|
29
|
+
});
|
|
30
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
31
|
+
const { lenient, strict } = await run("not json");
|
|
32
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
33
|
+
expect(strict._tag).toBe("Failure");
|
|
34
|
+
expect(strict.failure).toBeInstanceOf(DigitalOceanParseError);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
// DigitalOceanParseError is part of every operation's declared error type.
|
|
38
|
+
export const parseErrorIsDeclared = true;
|
|
39
|
+
//# 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,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,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;QACzE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACxE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,oBAAoB,GAIrB,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/digitalocean",
|
|
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",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
67
|
+
"@distilled.cloud/core": "1.0.0-rc.13"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/bun": "1.3.14",
|
|
71
71
|
"@types/node": "26.2.0",
|
|
72
|
-
"@effect/platform-bun": "
|
|
72
|
+
"@effect/platform-bun": "^4.0.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"effect": "
|
|
75
|
+
"effect": "^4.0.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsc -b",
|
package/src/protocol.ts
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
import * as Effect from "effect/Effect";
|
|
20
20
|
import type * as Layer from "effect/Layer";
|
|
21
21
|
import * as Redacted from "effect/Redacted";
|
|
22
|
-
import type * as HttpClient from "effect/
|
|
23
|
-
import type * as HttpClientError from "effect/
|
|
22
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
23
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
24
24
|
import type * as API from "@distilled.cloud/core/api";
|
|
25
25
|
import {
|
|
26
26
|
makeRestProtocol,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
} from "@distilled.cloud/core/protocol-rest";
|
|
29
29
|
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
30
30
|
import { Credentials, type Config } from "./credentials.ts";
|
|
31
|
-
import { UnknownDigitalOceanError } from "./errors.ts";
|
|
31
|
+
import { UnknownDigitalOceanError, DigitalOceanParseError } from "./errors.ts";
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Error channel shared by every generated DigitalOcean operation. Generated
|
|
@@ -40,7 +40,8 @@ export type DigitalOceanOpError =
|
|
|
40
40
|
| InstanceType<(typeof API_ERRORS)[number]>
|
|
41
41
|
| UnknownDigitalOceanError
|
|
42
42
|
| ConfigError
|
|
43
|
-
| HttpClientError.HttpClientError
|
|
43
|
+
| HttpClientError.HttpClientError
|
|
44
|
+
| DigitalOceanParseError;
|
|
44
45
|
|
|
45
46
|
/** Context (requirements) shared by every generated DigitalOcean operation. */
|
|
46
47
|
export type DigitalOceanOpContext = Credentials | HttpClient.HttpClient;
|
|
@@ -89,4 +90,6 @@ export const DigitalOceanProtocol: Layer.Layer<API.Protocol> =
|
|
|
89
90
|
message,
|
|
90
91
|
body,
|
|
91
92
|
}),
|
|
93
|
+
parseError: ({ body, cause }) =>
|
|
94
|
+
new DigitalOceanParseError({ body, cause }),
|
|
92
95
|
});
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { fromApiKey } from "./credentials.ts";
|
|
5
|
+
import { DigitalOceanParseError } from "./errors.ts";
|
|
6
|
+
import * as Retry from "./retry.ts";
|
|
7
|
+
import { getBalance } from "./services/digitalocean.ts";
|
|
8
|
+
import type { DigitalOceanOpError } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
// getBalance declares only optional string members (`account_balance?: string`, …),
|
|
11
|
+
// so the mismatch is a wrong primitive type.
|
|
12
|
+
const run = (body: string) =>
|
|
13
|
+
runValidationModes(
|
|
14
|
+
getBalance({}).pipe(
|
|
15
|
+
Retry.none,
|
|
16
|
+
Effect.provide(fromApiKey({ apiKey: "test" })),
|
|
17
|
+
),
|
|
18
|
+
{ body },
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
describe("DigitalOcean response validation", () => {
|
|
22
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
23
|
+
const body = {
|
|
24
|
+
month_to_date_balance: "0.00",
|
|
25
|
+
account_balance: "0.00",
|
|
26
|
+
month_to_date_usage: "0.00",
|
|
27
|
+
generated_at: "2026-01-01T00:00:00Z",
|
|
28
|
+
};
|
|
29
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
30
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
31
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("a member with the wrong primitive type: lenient returns it, strict fails", async () => {
|
|
35
|
+
const body = { account_balance: 0 };
|
|
36
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
37
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
38
|
+
expect(strict._tag).toBe("Failure");
|
|
39
|
+
expect((strict as any).failure).toBeInstanceOf(DigitalOceanParseError);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
43
|
+
const { lenient, strict } = await run("not json");
|
|
44
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
45
|
+
expect(strict._tag).toBe("Failure");
|
|
46
|
+
expect((strict as any).failure).toBeInstanceOf(DigitalOceanParseError);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// DigitalOceanParseError is part of every operation's declared error type.
|
|
51
|
+
export const parseErrorIsDeclared: [DigitalOceanParseError] extends [
|
|
52
|
+
DigitalOceanOpError,
|
|
53
|
+
]
|
|
54
|
+
? true
|
|
55
|
+
: false = true;
|