@distilled.cloud/stripe 0.16.1 → 0.16.3
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/lib/client.d.ts.map +1 -1
- package/lib/client.js +8 -2
- package/lib/client.js.map +1 -1
- package/lib/retry.d.ts +23 -12
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +23 -11
- package/lib/retry.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +11 -1
- package/src/retry.ts +31 -11
package/lib/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAcxC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAsIjD;;GAEG;AACH,eAAO,MAAM,GAAG;;;CASd,CAAC"}
|
package/lib/client.js
CHANGED
|
@@ -8,6 +8,8 @@ import * as Effect from "effect/Effect";
|
|
|
8
8
|
import * as Redacted from "effect/Redacted";
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
10
|
import { makeAPI } from "@distilled.cloud/core/client";
|
|
11
|
+
import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
|
|
12
|
+
import { Retry } from "./retry.js";
|
|
11
13
|
import { HTTP_STATUS_MAP, STRIPE_HTTP_STATUS_MAP, ApiError, CardError, IdempotencyError, InvalidRequestError, UnknownStripeError, StripeParseError, } from "./errors.js";
|
|
12
14
|
import { Credentials } from "./credentials.js";
|
|
13
15
|
// Re-export for convenience
|
|
@@ -38,7 +40,7 @@ const StripeErrorResponse = Schema.Struct({
|
|
|
38
40
|
* 1. The error.type field (card_error, idempotency_error, invalid_request_error, api_error)
|
|
39
41
|
* 2. HTTP status code (400, 401, 402, 403, 404, 409, 424, 429, 500+)
|
|
40
42
|
*/
|
|
41
|
-
const matchError = (status, errorBody) => {
|
|
43
|
+
const matchError = (status, errorBody, _errors, headers) => {
|
|
42
44
|
try {
|
|
43
45
|
const parsed = Schema.decodeUnknownSync(StripeErrorResponse)(errorBody);
|
|
44
46
|
const err = parsed.error;
|
|
@@ -102,7 +104,10 @@ const matchError = (status, errorBody) => {
|
|
|
102
104
|
// Fall back to standard HTTP status errors (400, 401, 403, 404, etc.)
|
|
103
105
|
const CoreErrorClass = HTTP_STATUS_MAP[status];
|
|
104
106
|
if (CoreErrorClass) {
|
|
105
|
-
return Effect.fail(new CoreErrorClass({
|
|
107
|
+
return Effect.fail(new CoreErrorClass({
|
|
108
|
+
message: err.message ?? "",
|
|
109
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
110
|
+
}));
|
|
106
111
|
}
|
|
107
112
|
return Effect.fail(new UnknownStripeError({
|
|
108
113
|
type: err.type,
|
|
@@ -127,5 +132,6 @@ export const API = makeAPI({
|
|
|
127
132
|
}),
|
|
128
133
|
matchError,
|
|
129
134
|
ParseError: StripeParseError,
|
|
135
|
+
retry: Retry,
|
|
130
136
|
});
|
|
131
137
|
//# sourceMappingURL=client.js.map
|
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,QAAQ,EACR,SAAS,EACT,gBAAgB,E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IAClE,CAAC;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,OAAO,CAAc;IACtC,WAAW,EAAE,WAAkB;IAC/B,UAAU,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU;IAC5C,cAAc,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC;QAC/B,aAAa,EAAE,UAAU,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;KACxD,CAAC;IACF,UAAU;IACV,UAAU,EAAE,gBAAuB;IACnC,KAAK,EAAE,KAAY;CACpB,CAAC,CAAC"}
|
package/lib/retry.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stripe retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/stripe/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* Stripe API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as Stripe from "@distilled.cloud/stripe";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(Stripe.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(Stripe.Retry.Retry, customPolicy));
|
|
15
|
+
* ```
|
|
3
16
|
*/
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
17
|
import * as Context from "effect/Context";
|
|
6
|
-
|
|
7
|
-
import type
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import { type Policy } from "@distilled.cloud/core/retry";
|
|
20
|
+
export { type Options, type Factory, type Policy, makeDefault, jittered, capped, throttlingOptions, transientOptions, throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
|
|
8
21
|
declare const Retry_base: Context.ServiceClass<Retry, "StripeRetry", Policy>;
|
|
9
|
-
/**
|
|
10
|
-
* Context tag for configuring retry behavior of Stripe API calls.
|
|
11
|
-
*/
|
|
22
|
+
/** Context tag for configuring retry behavior of Stripe API calls. */
|
|
12
23
|
export declare class Retry extends Retry_base {
|
|
13
24
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Provides a custom retry policy to all Stripe API calls.
|
|
16
|
-
*/
|
|
25
|
+
/** Provides a custom retry policy to every Stripe API call below it. */
|
|
17
26
|
export declare const policy: (optionsOrFactory: Policy) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
18
|
-
/**
|
|
19
|
-
* Disables all automatic retries.
|
|
20
|
-
*/
|
|
27
|
+
/** Disables all automatic retries. */
|
|
21
28
|
export declare const none: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
29
|
+
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
30
|
+
export declare const throttling: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
31
|
+
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
32
|
+
export declare const transient: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
22
33
|
//# sourceMappingURL=retry.d.ts.map
|
package/lib/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EACL,KAAK,MAAM,EAGZ,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;;AAErC,sEAAsE;AACtE,qBAAa,KAAM,SAAQ,UAA+C;CAAG;AAE7E,wEAAwE;AACxE,eAAO,MAAM,MAAM,qBAAsB,MAAM,sFACS,CAAC;AAEzD,sCAAsC;AACtC,eAAO,MAAM,IAAI,mFAEhB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,UAAU,mFAA4B,CAAC;AAEpD,oFAAoF;AACpF,eAAO,MAAM,SAAS,mFAA2B,CAAC"}
|
package/lib/retry.js
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stripe retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/stripe/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* Stripe API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as Stripe from "@distilled.cloud/stripe";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(Stripe.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(Stripe.Retry.Retry, customPolicy));
|
|
15
|
+
* ```
|
|
3
16
|
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
4
18
|
import * as Effect from "effect/Effect";
|
|
5
19
|
import * as Layer from "effect/Layer";
|
|
6
|
-
import
|
|
7
|
-
export { makeDefault, jittered, capped, throttlingOptions, transientOptions, } from "@distilled.cloud/core/retry";
|
|
8
|
-
/**
|
|
9
|
-
* Context tag for configuring retry behavior of Stripe API calls.
|
|
10
|
-
*/
|
|
20
|
+
import { throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
|
|
21
|
+
export { makeDefault, jittered, capped, throttlingOptions, transientOptions, throttlingFactory, transientFactory, } from "@distilled.cloud/core/retry";
|
|
22
|
+
/** Context tag for configuring retry behavior of Stripe API calls. */
|
|
11
23
|
export class Retry extends Context.Service()("StripeRetry") {
|
|
12
24
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Provides a custom retry policy to all Stripe API calls.
|
|
15
|
-
*/
|
|
25
|
+
/** Provides a custom retry policy to every Stripe API call below it. */
|
|
16
26
|
export const policy = (optionsOrFactory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
17
|
-
/**
|
|
18
|
-
* Disables all automatic retries.
|
|
19
|
-
*/
|
|
27
|
+
/** Disables all automatic retries. */
|
|
20
28
|
export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
|
|
29
|
+
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
30
|
+
export const throttling = policy(throttlingFactory);
|
|
31
|
+
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
32
|
+
export const transient = policy(transientFactory);
|
|
21
33
|
//# sourceMappingURL=retry.js.map
|
package/lib/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAIL,WAAW,EACX,QAAQ,EACR,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,sEAAsE;AACtE,MAAM,OAAO,KAAM,SAAQ,OAAO,CAAC,OAAO,EAAiB,CAAC,aAAa,CAAC;CAAG;AAE7E,wEAAwE;AACxE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,gBAAwB,EAAE,EAAE,CACjD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEzD,sCAAsC;AACtC,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAChC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAC7C,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEpD,oFAAoF;AACpF,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/stripe",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"specs:update": "git -C specs/stripe-openapi fetch && git -C specs/stripe-openapi checkout master && git -C specs/stripe-openapi pull"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@distilled.cloud/core": "0.16.
|
|
77
|
+
"@distilled.cloud/core": "0.16.3",
|
|
78
78
|
"effect": "4.0.0-beta.58"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
package/src/client.ts
CHANGED
|
@@ -8,6 +8,8 @@ import * as Effect from "effect/Effect";
|
|
|
8
8
|
import * as Redacted from "effect/Redacted";
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
10
|
import { makeAPI } from "@distilled.cloud/core/client";
|
|
11
|
+
import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
|
|
12
|
+
import { Retry } from "./retry.ts";
|
|
11
13
|
import {
|
|
12
14
|
HTTP_STATUS_MAP,
|
|
13
15
|
STRIPE_HTTP_STATUS_MAP,
|
|
@@ -54,6 +56,8 @@ const StripeErrorResponse = Schema.Struct({
|
|
|
54
56
|
const matchError = (
|
|
55
57
|
status: number,
|
|
56
58
|
errorBody: unknown,
|
|
59
|
+
_errors?: readonly unknown[],
|
|
60
|
+
headers?: Record<string, string | undefined>,
|
|
57
61
|
): Effect.Effect<never, unknown> => {
|
|
58
62
|
try {
|
|
59
63
|
const parsed = Schema.decodeUnknownSync(StripeErrorResponse)(errorBody);
|
|
@@ -131,7 +135,12 @@ const matchError = (
|
|
|
131
135
|
// Fall back to standard HTTP status errors (400, 401, 403, 404, etc.)
|
|
132
136
|
const CoreErrorClass = (HTTP_STATUS_MAP as any)[status];
|
|
133
137
|
if (CoreErrorClass) {
|
|
134
|
-
return Effect.fail(
|
|
138
|
+
return Effect.fail(
|
|
139
|
+
new CoreErrorClass({
|
|
140
|
+
message: err.message ?? "",
|
|
141
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
135
144
|
}
|
|
136
145
|
|
|
137
146
|
return Effect.fail(
|
|
@@ -159,4 +168,5 @@ export const API = makeAPI<Credentials>({
|
|
|
159
168
|
}),
|
|
160
169
|
matchError,
|
|
161
170
|
ParseError: StripeParseError as any,
|
|
171
|
+
retry: Retry as any,
|
|
162
172
|
});
|
package/src/retry.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stripe retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/stripe/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* Stripe API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as Stripe from "@distilled.cloud/stripe";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(Stripe.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(Stripe.Retry.Retry, customPolicy));
|
|
15
|
+
* ```
|
|
3
16
|
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
4
18
|
import * as Effect from "effect/Effect";
|
|
5
19
|
import * as Layer from "effect/Layer";
|
|
6
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
type Policy,
|
|
22
|
+
throttlingFactory,
|
|
23
|
+
transientFactory,
|
|
24
|
+
} from "@distilled.cloud/core/retry";
|
|
25
|
+
|
|
7
26
|
export {
|
|
8
27
|
type Options,
|
|
9
28
|
type Factory,
|
|
@@ -13,23 +32,24 @@ export {
|
|
|
13
32
|
capped,
|
|
14
33
|
throttlingOptions,
|
|
15
34
|
transientOptions,
|
|
35
|
+
throttlingFactory,
|
|
36
|
+
transientFactory,
|
|
16
37
|
} from "@distilled.cloud/core/retry";
|
|
17
|
-
import type { Policy } from "@distilled.cloud/core/retry";
|
|
18
38
|
|
|
19
|
-
/**
|
|
20
|
-
* Context tag for configuring retry behavior of Stripe API calls.
|
|
21
|
-
*/
|
|
39
|
+
/** Context tag for configuring retry behavior of Stripe API calls. */
|
|
22
40
|
export class Retry extends Context.Service<Retry, Policy>()("StripeRetry") {}
|
|
23
41
|
|
|
24
|
-
/**
|
|
25
|
-
* Provides a custom retry policy to all Stripe API calls.
|
|
26
|
-
*/
|
|
42
|
+
/** Provides a custom retry policy to every Stripe API call below it. */
|
|
27
43
|
export const policy = (optionsOrFactory: Policy) =>
|
|
28
44
|
Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
29
45
|
|
|
30
|
-
/**
|
|
31
|
-
* Disables all automatic retries.
|
|
32
|
-
*/
|
|
46
|
+
/** Disables all automatic retries. */
|
|
33
47
|
export const none = Effect.provide(
|
|
34
48
|
Layer.succeed(Retry, { while: () => false }),
|
|
35
49
|
);
|
|
50
|
+
|
|
51
|
+
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
52
|
+
export const throttling = policy(throttlingFactory);
|
|
53
|
+
|
|
54
|
+
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
55
|
+
export const transient = policy(transientFactory);
|