@distilled.cloud/adyen 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 ADDED
@@ -0,0 +1,34 @@
1
+ # @distilled.cloud/adyen
2
+
3
+ Effect-native SDK for [adyen](https://www.npmjs.com/package/@distilled.cloud/adyen).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @distilled.cloud/adyen 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 Adyen from "@distilled.cloud/adyen";
17
+
18
+ const program = Effect.gen(function* () {
19
+ const result = yield* Adyen.postPaymentMethods({});
20
+ return result;
21
+ });
22
+
23
+ const Live = Layer.mergeAll(
24
+ FetchHttpClient.layer,
25
+ Adyen.CredentialsFromEnv,
26
+ Adyen.AdyenProtocol,
27
+ );
28
+
29
+ program.pipe(Effect.provide(Live), Effect.runPromise);
30
+ ```
31
+
32
+ ## Auth
33
+
34
+ Required: `ADYEN_API_KEY`. Optional: `ADYEN_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 { UnknownAdyenError } from "./errors.ts";
7
+ import { UnknownAdyenError, AdyenParseError } from "./errors.ts";
8
8
  /**
9
9
  * Error channel shared by every generated Adyen operation. Generated service
10
10
  * files annotate operations with `API.OperationMethod<I, O, AdyenOpError,
11
11
  * AdyenOpContext>` explicitly so the compiler never infers these back out of
12
12
  * the schema generics.
13
13
  */
14
- export type AdyenOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownAdyenError | ConfigError | HttpClientError.HttpClientError;
14
+ export type AdyenOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownAdyenError | ConfigError | HttpClientError.HttpClientError | AdyenParseError;
15
15
  /** Context (requirements) shared by every generated Adyen operation. */
16
16
  export type AdyenOpContext = Credentials | HttpClient.HttpClient;
17
17
  export declare const AdyenProtocol: Layer.Layer<API.Protocol>;
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,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,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACpB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,iBAAiB,GACjB,WAAW,GACX,eAAe,CAAC,eAAe,CAAC;AAEpC,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAkBjE,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAwBhD,CAAC"}
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAiBA,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,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACpB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,iBAAiB,GACjB,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,eAAe,CAAC;AAEpB,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAkBjE,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAyBhD,CAAC"}
package/lib/protocol.js CHANGED
@@ -18,7 +18,7 @@ import * as Effect from "effect/Effect";
18
18
  import * as Redacted from "effect/Redacted";
19
19
  import { makeRestProtocol, } from "@distilled.cloud/core/protocol-rest";
20
20
  import { Credentials } from "./credentials.js";
21
- import { UnknownAdyenError } from "./errors.js";
21
+ import { UnknownAdyenError, AdyenParseError } from "./errors.js";
22
22
  /**
23
23
  * Adyen Checkout errors are a flat `ServiceError`:
24
24
  * `{ status?, errorCode?, message?, errorType?, pspReference? }`.
@@ -57,5 +57,6 @@ export const AdyenProtocol = makeRestProtocol({
57
57
  message,
58
58
  body,
59
59
  }),
60
+ parseError: ({ body, cause }) => new AdyenParseError({ body, cause }),
60
61
  });
61
62
  //# sourceMappingURL=protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol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QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QACjD,OAAO,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;KAC3D,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GACxB,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,CAAC;QACnB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;KAC1C,CAAC;IACF,aAAa;IACb,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CACxC,IAAI,iBAAiB,CAAC;QACpB,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,eAAe,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;CACtE,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { AdyenParseError } from "./errors.ts";
2
+ import type { AdyenOpError } from "./protocol.ts";
3
+ export declare const parseErrorIsDeclared: [AdyenParseError] extends [AdyenOpError] ? 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,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AA4ClD,eAAO,MAAM,oBAAoB,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,YAAY,CAAC,GACvE,IAAI,GACJ,KAAY,CAAC"}
@@ -0,0 +1,40 @@
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 { AdyenParseError } from "./errors.js";
6
+ import * as Retry from "./retry.js";
7
+ import { getPaymentLink } from "./services/adyen.js";
8
+ // getPaymentLink declares required `amount`, `id`, `merchantAccount`,
9
+ // `reference`, `status`, and `url`.
10
+ const run = (body) => runValidationModes(getPaymentLink({ linkId: "PL123" }).pipe(Retry.none, Effect.provide(fromApiKey({ apiKey: "test" }))), { body });
11
+ describe("Adyen response validation", () => {
12
+ test("a matching body succeeds unchanged in both modes", async () => {
13
+ const body = {
14
+ amount: { currency: "EUR", value: 1000 },
15
+ id: "PL123",
16
+ merchantAccount: "TestMerchant",
17
+ reference: "order-1",
18
+ status: "active",
19
+ url: "https://test.adyen.link/PL123",
20
+ };
21
+ const { lenient, strict } = await run(JSON.stringify(body));
22
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
23
+ expect(strict).toMatchObject({ _tag: "Success", success: body });
24
+ });
25
+ test("a body missing required members: lenient returns it, strict fails", async () => {
26
+ const body = { id: "PL123" };
27
+ const { lenient, strict } = await run(JSON.stringify(body));
28
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
29
+ expect(strict._tag).toBe("Failure");
30
+ expect(strict.failure).toBeInstanceOf(AdyenParseError);
31
+ });
32
+ test("a non-JSON body: lenient returns the text, strict fails", async () => {
33
+ const { lenient, strict } = await run("not json");
34
+ expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
35
+ expect(strict.failure).toBeInstanceOf(AdyenParseError);
36
+ });
37
+ });
38
+ // AdyenParseError is part of every operation's declared error type.
39
+ export const parseErrorIsDeclared = true;
40
+ //# 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,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,sEAAsE;AACtE,oCAAoC;AACpC,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAC3B,kBAAkB,CAChB,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CACtC,KAAK,CAAC,IAAI,EACV,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAC/C,EACD,EAAE,IAAI,EAAE,CACT,CAAC;AAEJ,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,IAAI,GAAG;YACX,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;YACxC,EAAE,EAAE,OAAO;YACX,eAAe,EAAE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C;QACxE,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAErB,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distilled.cloud/adyen",
3
- "version": "1.0.0-rc.11",
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.11"
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
  import * as Effect from "effect/Effect";
18
18
  import type * as Layer from "effect/Layer";
19
19
  import * as Redacted from "effect/Redacted";
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, type Config } from "./credentials.ts";
29
- import { UnknownAdyenError } from "./errors.ts";
29
+ import { UnknownAdyenError, AdyenParseError } from "./errors.ts";
30
30
 
31
31
  /**
32
32
  * Error channel shared by every generated Adyen operation. Generated service
@@ -38,7 +38,8 @@ export type AdyenOpError =
38
38
  | InstanceType<(typeof API_ERRORS)[number]>
39
39
  | UnknownAdyenError
40
40
  | ConfigError
41
- | HttpClientError.HttpClientError;
41
+ | HttpClientError.HttpClientError
42
+ | AdyenParseError;
42
43
 
43
44
  /** Context (requirements) shared by every generated Adyen operation. */
44
45
  export type AdyenOpContext = Credentials | HttpClient.HttpClient;
@@ -83,4 +84,5 @@ export const AdyenProtocol: Layer.Layer<API.Protocol> =
83
84
  message,
84
85
  body,
85
86
  }),
87
+ parseError: ({ body, cause }) => new AdyenParseError({ body, cause }),
86
88
  });
@@ -0,0 +1,54 @@
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 { AdyenParseError } from "./errors.ts";
6
+ import * as Retry from "./retry.ts";
7
+ import { getPaymentLink } from "./services/adyen.ts";
8
+ import type { AdyenOpError } from "./protocol.ts";
9
+
10
+ // getPaymentLink declares required `amount`, `id`, `merchantAccount`,
11
+ // `reference`, `status`, and `url`.
12
+ const run = (body: string) =>
13
+ runValidationModes(
14
+ getPaymentLink({ linkId: "PL123" }).pipe(
15
+ Retry.none,
16
+ Effect.provide(fromApiKey({ apiKey: "test" })),
17
+ ),
18
+ { body },
19
+ );
20
+
21
+ describe("Adyen response validation", () => {
22
+ test("a matching body succeeds unchanged in both modes", async () => {
23
+ const body = {
24
+ amount: { currency: "EUR", value: 1000 },
25
+ id: "PL123",
26
+ merchantAccount: "TestMerchant",
27
+ reference: "order-1",
28
+ status: "active",
29
+ url: "https://test.adyen.link/PL123",
30
+ };
31
+ const { lenient, strict } = await run(JSON.stringify(body));
32
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
33
+ expect(strict).toMatchObject({ _tag: "Success", success: body });
34
+ });
35
+
36
+ test("a body missing required members: lenient returns it, strict fails", async () => {
37
+ const body = { id: "PL123" };
38
+ const { lenient, strict } = await run(JSON.stringify(body));
39
+ expect(lenient).toMatchObject({ _tag: "Success", success: body });
40
+ expect(strict._tag).toBe("Failure");
41
+ expect((strict as any).failure).toBeInstanceOf(AdyenParseError);
42
+ });
43
+
44
+ test("a non-JSON body: lenient returns the text, strict fails", async () => {
45
+ const { lenient, strict } = await run("not json");
46
+ expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
47
+ expect((strict as any).failure).toBeInstanceOf(AdyenParseError);
48
+ });
49
+ });
50
+
51
+ // AdyenParseError is part of every operation's declared error type.
52
+ export const parseErrorIsDeclared: [AdyenParseError] extends [AdyenOpError]
53
+ ? true
54
+ : false = true;