@distilled.cloud/adyen 0.0.0 → 1.0.0-rc.10

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.
Files changed (47) hide show
  1. package/LICENSE +201 -0
  2. package/lib/credentials.d.ts +30 -0
  3. package/lib/credentials.d.ts.map +1 -0
  4. package/lib/credentials.js +36 -0
  5. package/lib/credentials.js.map +1 -0
  6. package/lib/errors.d.ts +36 -0
  7. package/lib/errors.d.ts.map +1 -0
  8. package/lib/errors.js +26 -0
  9. package/lib/errors.js.map +1 -0
  10. package/lib/index.d.ts +24 -0
  11. package/lib/index.d.ts.map +1 -0
  12. package/lib/index.js +28 -0
  13. package/lib/index.js.map +1 -0
  14. package/lib/pagination.d.ts +9 -0
  15. package/lib/pagination.d.ts.map +1 -0
  16. package/lib/pagination.js +9 -0
  17. package/lib/pagination.js.map +1 -0
  18. package/lib/protocol.d.ts +18 -0
  19. package/lib/protocol.d.ts.map +1 -0
  20. package/lib/protocol.js +61 -0
  21. package/lib/protocol.js.map +1 -0
  22. package/lib/retry.d.ts +32 -0
  23. package/lib/retry.d.ts.map +1 -0
  24. package/lib/retry.js +32 -0
  25. package/lib/retry.js.map +1 -0
  26. package/lib/services/adyen.d.ts +5647 -0
  27. package/lib/services/adyen.d.ts.map +1 -0
  28. package/lib/services/adyen.js +3337 -0
  29. package/lib/services/adyen.js.map +1 -0
  30. package/lib/services/index.d.ts +2 -0
  31. package/lib/services/index.d.ts.map +1 -0
  32. package/lib/services/index.js +3 -0
  33. package/lib/services/index.js.map +1 -0
  34. package/lib/traits.d.ts +11 -0
  35. package/lib/traits.d.ts.map +1 -0
  36. package/lib/traits.js +11 -0
  37. package/lib/traits.js.map +1 -0
  38. package/package.json +77 -6
  39. package/src/credentials.ts +58 -0
  40. package/src/errors.ts +50 -0
  41. package/src/index.ts +35 -0
  42. package/src/pagination.ts +8 -0
  43. package/src/protocol.ts +86 -0
  44. package/src/retry.ts +54 -0
  45. package/src/services/adyen.ts +10692 -0
  46. package/src/services/index.ts +2 -0
  47. package/src/traits.ts +44 -0
package/src/errors.ts ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Adyen-specific error types.
3
+ *
4
+ * Re-exports the common HTTP errors from core and adds the Adyen fallback
5
+ * errors. Note the generated service module additionally defines its own
6
+ * per-status matcher classes (BadRequest/NotFound/…) for the statuses each
7
+ * operation declares — those share `_tag`s with the core classes here, so
8
+ * `catchTag` works against either.
9
+ */
10
+ export {
11
+ BadGateway,
12
+ BadRequest,
13
+ Conflict,
14
+ ConfigError,
15
+ Forbidden,
16
+ GatewayTimeout,
17
+ InternalServerError,
18
+ Locked,
19
+ NotFound,
20
+ ServiceUnavailable,
21
+ TooManyRequests,
22
+ Unauthorized,
23
+ UnprocessableEntity,
24
+ HTTP_STATUS_MAP,
25
+ DEFAULT_ERRORS,
26
+ API_ERRORS,
27
+ } from "@distilled.cloud/core/errors";
28
+ export type { DefaultErrors } from "@distilled.cloud/core/errors";
29
+
30
+ import * as Schema from "effect/Schema";
31
+ import * as Category from "@distilled.cloud/core/category";
32
+
33
+ /** Unknown Adyen error — returned when nothing else matches the failure. */
34
+ export class UnknownAdyenError extends Schema.TaggedError<UnknownAdyenError>()(
35
+ "UnknownAdyenError",
36
+ {
37
+ code: Schema.optional(Schema.String),
38
+ message: Schema.optional(Schema.String),
39
+ body: Schema.Unknown,
40
+ },
41
+ ).pipe(Category.withServerError) {}
42
+
43
+ /** Schema parse error wrapper. */
44
+ export class AdyenParseError extends Schema.TaggedError<AdyenParseError>()(
45
+ "AdyenParseError",
46
+ {
47
+ body: Schema.Unknown,
48
+ cause: Schema.Unknown,
49
+ },
50
+ ).pipe(Category.withParseError) {}
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @distilled.cloud/adyen — Adyen Checkout SDK for Effect.
3
+ *
4
+ * `./services` is generated by `scripts/generate.ts` from the Smithy model
5
+ * in `.generated-specs` (written by `scripts/convert.ts` from the OpenAPI
6
+ * spec). Everything else in this folder is hand-written.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import * as Adyen from "@distilled.cloud/adyen";
11
+ *
12
+ * const methods = yield* Adyen.Services.adyen.postPaymentMethods({});
13
+ * ```
14
+ */
15
+ export * from "./credentials.ts";
16
+ export * from "./errors.ts";
17
+ export * as T from "./traits.ts";
18
+ export {
19
+ AdyenProtocol,
20
+ type AdyenOpError,
21
+ type AdyenOpContext,
22
+ } from "./protocol.ts";
23
+ export { paginateCursor } from "./pagination.ts";
24
+ export * as Retry from "./retry.ts";
25
+ export * as Services from "./services/index.ts";
26
+ // Operations (and their request/response types) are importable straight off
27
+ // the package root. The service-local typed error classes shadow the
28
+ // same-named shared ones from ./errors.ts — the ops actually raise the
29
+ // service-local classes.
30
+ export * from "./services/adyen.ts";
31
+ export {
32
+ BadRequest,
33
+ Forbidden,
34
+ UnprocessableEntity,
35
+ } from "./services/adyen.ts";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Adyen pagination — hand-written.
3
+ *
4
+ * Checkout list-style endpoints are not cursor-paginated; this re-export is
5
+ * kept so generated operations can pass core's {@link paginateCursor}
6
+ * strategy to `API.makePaginated` if a later spec adds one.
7
+ */
8
+ export { paginateCursor } from "@distilled.cloud/core/pagination";
@@ -0,0 +1,86 @@
1
+ /**
2
+ * AdyenProtocol — hand-written.
3
+ *
4
+ * Adyen Checkout speaks JSON REST authenticated with `X-API-Key` (no
5
+ * response envelope), so the whole protocol is one `makeRestProtocol` call
6
+ * from `core/protocol-rest`:
7
+ *
8
+ * request: credentials → `X-API-Key: <apiKey>` + base URL
9
+ * (default https://checkout-test.adyen.com/v72), resolved from the
10
+ * calling fiber on every request
11
+ *
12
+ * response: 2xx JSON is the payload (sensitive members delivered as
13
+ * `Redacted`); non-2xx `{ errorCode?, message }` bodies map to the
14
+ * operation's typed error classes by status, then the shared
15
+ * HTTP-status classes, then {@link UnknownAdyenError}.
16
+ */
17
+ import * as Effect from "effect/Effect";
18
+ import type * as Layer from "effect/Layer";
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";
22
+ import type * as API from "@distilled.cloud/core/api";
23
+ import {
24
+ makeRestProtocol,
25
+ type RestErrorEnvelope,
26
+ } from "@distilled.cloud/core/protocol-rest";
27
+ import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
28
+ import { Credentials, type Config } from "./credentials.ts";
29
+ import { UnknownAdyenError } from "./errors.ts";
30
+
31
+ /**
32
+ * Error channel shared by every generated Adyen operation. Generated service
33
+ * files annotate operations with `API.OperationMethod<I, O, AdyenOpError,
34
+ * AdyenOpContext>` explicitly so the compiler never infers these back out of
35
+ * the schema generics.
36
+ */
37
+ export type AdyenOpError =
38
+ | InstanceType<(typeof API_ERRORS)[number]>
39
+ | UnknownAdyenError
40
+ | ConfigError
41
+ | HttpClientError.HttpClientError;
42
+
43
+ /** Context (requirements) shared by every generated Adyen operation. */
44
+ export type AdyenOpContext = Credentials | HttpClient.HttpClient;
45
+
46
+ /**
47
+ * Adyen Checkout errors are a flat `ServiceError`:
48
+ * `{ status?, errorCode?, message?, errorType?, pspReference? }`.
49
+ */
50
+ const errorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
51
+ if (body === null || typeof body !== "object") return undefined;
52
+ const obj = body as Record<string, unknown>;
53
+ const code = obj.errorCode;
54
+ const message = obj.message;
55
+ if (typeof code !== "string" && typeof message !== "string") return undefined;
56
+ return {
57
+ code: typeof code === "string" ? code : undefined,
58
+ message: typeof message === "string" ? message : undefined,
59
+ };
60
+ };
61
+
62
+ export const AdyenProtocol: Layer.Layer<API.Protocol> =
63
+ makeRestProtocol<Config>({
64
+ // The Credentials service holds an effect — resolving it here (per
65
+ // request, on the calling fiber) picks up context-provided credentials.
66
+ credentials: Effect.gen(function* () {
67
+ const resolve = yield* Credentials;
68
+ return yield* resolve;
69
+ }),
70
+ baseUrl: (creds) => creds.apiBaseUrl,
71
+ headers: (creds) => ({
72
+ "X-API-Key": Redacted.value(creds.apiKey),
73
+ }),
74
+ errorEnvelope,
75
+ unknownError: ({ code, message, body }) =>
76
+ new UnknownAdyenError({
77
+ code:
78
+ typeof code === "string"
79
+ ? code
80
+ : code !== undefined
81
+ ? String(code)
82
+ : undefined,
83
+ message,
84
+ body,
85
+ }),
86
+ });
package/src/retry.ts ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Adyen retry configuration.
3
+ *
4
+ * Defines the per-SDK `Retry` Context.Service tag that generated operations
5
+ * wire into `API.make`. Callers can install a blanket retry policy at the
6
+ * layer level and have every Adyen API call below it pick it up:
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import * as Adyen from "@distilled.cloud/adyen";
11
+ *
12
+ * myEffect.pipe(Adyen.Retry.transient);
13
+ * Effect.provide(myEffect, Layer.succeed(Adyen.Retry.Retry, customPolicy));
14
+ * ```
15
+ */
16
+ import * as Context from "effect/Context";
17
+ import * as Effect from "effect/Effect";
18
+ import * as Layer from "effect/Layer";
19
+ import {
20
+ type Policy,
21
+ throttlingFactory,
22
+ transientFactory,
23
+ } from "@distilled.cloud/core/retry";
24
+
25
+ export {
26
+ type Options,
27
+ type Factory,
28
+ type Policy,
29
+ makeDefault,
30
+ jittered,
31
+ capped,
32
+ throttlingOptions,
33
+ transientOptions,
34
+ throttlingFactory,
35
+ transientFactory,
36
+ } from "@distilled.cloud/core/retry";
37
+
38
+ /** Context tag for configuring retry behavior of Adyen API calls. */
39
+ export class Retry extends Context.Service<Retry, Policy>()("AdyenRetry") {}
40
+
41
+ /** Provides a custom retry policy to every Adyen API call below it. */
42
+ export const policy = (optionsOrFactory: Policy) =>
43
+ Effect.provide(Layer.succeed(Retry, optionsOrFactory));
44
+
45
+ /** Disables all automatic retries. */
46
+ export const none = Effect.provide(
47
+ Layer.succeed(Retry, { while: () => false }),
48
+ );
49
+
50
+ /** Apply the throttling retry policy (retries throttling errors indefinitely). */
51
+ export const throttling = policy(throttlingFactory);
52
+
53
+ /** Apply the transient retry policy (retries all transient errors indefinitely). */
54
+ export const transient = policy(transientFactory);