@distilled.cloud/porkbun 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 ADDED
@@ -0,0 +1,34 @@
1
+ # @distilled.cloud/porkbun
2
+
3
+ Effect-native SDK for [porkbun](https://www.npmjs.com/package/@distilled.cloud/porkbun).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @distilled.cloud/porkbun 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 Porkbun from "@distilled.cloud/porkbun";
17
+
18
+ const program = Effect.gen(function* () {
19
+ const result = yield* Porkbun.listDomains({});
20
+ return result;
21
+ });
22
+
23
+ const Live = Layer.mergeAll(
24
+ FetchHttpClient.layer,
25
+ Porkbun.CredentialsFromEnv,
26
+ Porkbun.PorkbunProtocol,
27
+ );
28
+
29
+ program.pipe(Effect.provide(Live), Effect.runPromise);
30
+ ```
31
+
32
+ ## Auth
33
+
34
+ Required: `PORKBUN_API_KEY`, `PORKBUN_SECRET_API_KEY`. Optional: `PORKBUN_API_BASE_URL`.
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/unstable/http/HttpClient";
3
- import type * as HttpClientError from "effect/unstable/http/HttpClientError";
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 { UnknownPorkbunError } from "./errors.ts";
7
+ import { UnknownPorkbunError, PorkbunParseError } from "./errors.ts";
8
8
  /**
9
9
  * Error channel shared by every generated Porkbun operation. Generated
10
10
  * service files annotate operations with `API.OperationMethod<I, O,
11
11
  * PorkbunOpError, PorkbunOpContext>` explicitly so the compiler never infers
12
12
  * these back out of the schema generics.
13
13
  */
14
- export type PorkbunOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownPorkbunError | ConfigError | HttpClientError.HttpClientError;
14
+ export type PorkbunOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownPorkbunError | ConfigError | HttpClientError.HttpClientError | PorkbunParseError;
15
15
  /** Context (requirements) shared by every generated Porkbun operation. */
16
16
  export type PorkbunOpContext = Credentials | HttpClient.HttpClient;
17
17
  export declare const PorkbunProtocol: Layer.Layer<API.Protocol>;
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,KAAK,UAAU,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,KAAK,eAAe,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AAKtD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAA8B,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACtB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,mBAAmB,GACnB,WAAW,GACX,eAAe,CAAC,eAAe,CAAC;AAEpC,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAiBnE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAsBlD,CAAC"}
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,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,EAA8B,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACtB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,mBAAmB,GACnB,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,iBAAiB,CAAC;AAEtB,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAiBnE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAuBlD,CAAC"}
package/lib/protocol.js CHANGED
@@ -18,7 +18,7 @@
18
18
  import * as Effect from "effect/Effect";
19
19
  import { makeRestProtocol, } from "@distilled.cloud/core/protocol-rest";
20
20
  import { Credentials, formatHeaders } from "./credentials.js";
21
- import { UnknownPorkbunError } from "./errors.js";
21
+ import { UnknownPorkbunError, PorkbunParseError } from "./errors.js";
22
22
  /**
23
23
  * Porkbun error bodies are `{ status: "ERROR", message, code?, next_action? }`.
24
24
  */
@@ -54,5 +54,6 @@ export const PorkbunProtocol = makeRestProtocol({
54
54
  message,
55
55
  body,
56
56
  }),
57
+ parseError: ({ body, cause }) => new PorkbunParseError({ body, cause }),
57
58
  });
58
59
  //# sourceMappingURL=protocol.js.map
@@ -1 +1 @@
1
- {"version":3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K,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;KAC3D,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAC1B,gBAAgB,CAAS;IACvB,mEAAmE;IACnE,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC;IACxB,CAAC,CAAC;IACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU;IACpC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;IACxC,aAAa;IACb,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CACxC,IAAI,mBAAmB,CAAC;QACtB,IAAI,EACF,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,KAAK,SAAS;gBAClB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBACd,CAAC,CAAC,SAAS;QACjB,OAAO;QACP,IAAI;KACL,CAAC;IACJ,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,IAAI,iBAAiB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;CACxE,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { PorkbunParseError } from "./errors.ts";
2
+ import type { PorkbunOpError } from "./protocol.ts";
3
+ export declare const parseErrorIsDeclared: [PorkbunParseError] extends [PorkbunOpError] ? true : false;
4
+ //# 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,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAoCpD,eAAO,MAAM,oBAAoB,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,cAAc,CAAC,GAC3E,IAAI,GACJ,KAAY,CAAC"}
@@ -0,0 +1,32 @@
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 { PorkbunParseError } from "./errors.js";
6
+ import * as Retry from "./retry.js";
7
+ import { getPing } from "./services/porkbun.js";
8
+ // getPing declares `{ status: string; yourIp: string; xForwardedFor?: string; credentialsValid?: boolean }`.
9
+ const run = (body) => runValidationModes(getPing({}).pipe(Retry.none, Effect.provide(fromApiKey({ apiKey: "test", secretApiKey: "test" }))), { body });
10
+ describe("Porkbun response validation", () => {
11
+ test("a matching body succeeds unchanged in both modes", async () => {
12
+ const body = { status: "SUCCESS", yourIp: "203.0.113.1" };
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 body = { status: "SUCCESS" };
19
+ const { lenient, strict } = await run(JSON.stringify(body));
20
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
21
+ expect(strict._tag).toBe("Failure");
22
+ expect(strict.failure).toBeInstanceOf(PorkbunParseError);
23
+ });
24
+ test("a non-JSON body: lenient returns the text, strict fails", async () => {
25
+ const { lenient, strict } = await run("not json");
26
+ expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
27
+ expect(strict.failure).toBeInstanceOf(PorkbunParseError);
28
+ });
29
+ });
30
+ // PorkbunParseError is part of every operation's declared error type.
31
+ export const parseErrorIsDeclared = true;
32
+ //# sourceMappingURL=response-validation.test.js.map
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EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;QACnF,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QACnC,MAAM,EAAE,OAAO,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,iBAAiB,CAAC,CAAC;IACpE,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,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAErB,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distilled.cloud/porkbun",
3
- "version": "1.0.0-rc.12",
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.12"
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": ">=4.0.0-rc.115 || >=4.0.0"
72
+ "@effect/platform-bun": "^4.0.0"
73
73
  },
74
74
  "peerDependencies": {
75
- "effect": ">=4.0.0-rc.115 || >=4.0.0"
75
+ "effect": "^4.0.0"
76
76
  },
77
77
  "scripts": {
78
78
  "build": "tsc -b",
package/src/protocol.ts CHANGED
@@ -17,8 +17,8 @@
17
17
  */
18
18
  import * as Effect from "effect/Effect";
19
19
  import type * as Layer from "effect/Layer";
20
- import type * as HttpClient from "effect/unstable/http/HttpClient";
21
- import type * as HttpClientError from "effect/unstable/http/HttpClientError";
20
+ import type * as HttpClient from "effect/http/HttpClient";
21
+ import type * as HttpClientError from "effect/http/HttpClientError";
22
22
  import type * as API from "@distilled.cloud/core/api";
23
23
  import {
24
24
  makeRestProtocol,
@@ -26,7 +26,7 @@ import {
26
26
  } from "@distilled.cloud/core/protocol-rest";
27
27
  import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
28
28
  import { Credentials, formatHeaders, type Config } from "./credentials.ts";
29
- import { UnknownPorkbunError } from "./errors.ts";
29
+ import { UnknownPorkbunError, PorkbunParseError } from "./errors.ts";
30
30
 
31
31
  /**
32
32
  * Error channel shared by every generated Porkbun operation. Generated
@@ -38,7 +38,8 @@ export type PorkbunOpError =
38
38
  | InstanceType<(typeof API_ERRORS)[number]>
39
39
  | UnknownPorkbunError
40
40
  | ConfigError
41
- | HttpClientError.HttpClientError;
41
+ | HttpClientError.HttpClientError
42
+ | PorkbunParseError;
42
43
 
43
44
  /** Context (requirements) shared by every generated Porkbun operation. */
44
45
  export type PorkbunOpContext = Credentials | HttpClient.HttpClient;
@@ -80,4 +81,5 @@ export const PorkbunProtocol: Layer.Layer<API.Protocol> =
80
81
  message,
81
82
  body,
82
83
  }),
84
+ parseError: ({ body, cause }) => new PorkbunParseError({ body, cause }),
83
85
  });
@@ -0,0 +1,46 @@
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 { PorkbunParseError } from "./errors.ts";
6
+ import * as Retry from "./retry.ts";
7
+ import { getPing } from "./services/porkbun.ts";
8
+ import type { PorkbunOpError } from "./protocol.ts";
9
+
10
+ // getPing declares `{ status: string; yourIp: string; xForwardedFor?: string; credentialsValid?: boolean }`.
11
+ const run = (body: string) =>
12
+ runValidationModes(
13
+ getPing({}).pipe(
14
+ Retry.none,
15
+ Effect.provide(fromApiKey({ apiKey: "test", secretApiKey: "test" })),
16
+ ),
17
+ { body },
18
+ );
19
+
20
+ describe("Porkbun response validation", () => {
21
+ test("a matching body succeeds unchanged in both modes", async () => {
22
+ const body = { status: "SUCCESS", yourIp: "203.0.113.1" };
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 body = { status: "SUCCESS" };
30
+ const { lenient, strict } = await run(JSON.stringify(body));
31
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
32
+ expect(strict._tag).toBe("Failure");
33
+ expect((strict as any).failure).toBeInstanceOf(PorkbunParseError);
34
+ });
35
+
36
+ test("a non-JSON body: lenient returns the text, strict fails", async () => {
37
+ const { lenient, strict } = await run("not json");
38
+ expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
39
+ expect((strict as any).failure).toBeInstanceOf(PorkbunParseError);
40
+ });
41
+ });
42
+
43
+ // PorkbunParseError is part of every operation's declared error type.
44
+ export const parseErrorIsDeclared: [PorkbunParseError] extends [PorkbunOpError]
45
+ ? true
46
+ : false = true;