@distilled.cloud/posthog 0.16.2 → 0.16.4
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 +25 -14
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +25 -13
- package/lib/retry.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +11 -1
- package/src/retry.ts +33 -13
package/lib/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAWxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA0D/C;;;;;GAKG;AACH,eAAO,MAAM,GAAG;;;CASd,CAAC"}
|
package/lib/client.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
8
|
import * as Schema from "effect/Schema";
|
|
9
9
|
import { makeAPI } from "@distilled.cloud/core/client";
|
|
10
|
+
import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
|
|
11
|
+
import { Retry } from "./retry.js";
|
|
10
12
|
import { HTTP_STATUS_MAP, UnknownPosthogError, PosthogParseError, } from "./errors.js";
|
|
11
13
|
// Re-export for backwards compatibility
|
|
12
14
|
export { UnknownPosthogError } from "./errors.js";
|
|
@@ -36,13 +38,16 @@ const ApiErrorResponse = Schema.Struct({
|
|
|
36
38
|
* Match a PostHog API error response to the appropriate error class based on
|
|
37
39
|
* HTTP status, falling back to `UnknownPosthogError`.
|
|
38
40
|
*/
|
|
39
|
-
const matchError = (status, errorBody) => {
|
|
41
|
+
const matchError = (status, errorBody, _errors, headers) => {
|
|
40
42
|
try {
|
|
41
43
|
const parsed = Schema.decodeUnknownSync(ApiErrorResponse)(errorBody);
|
|
42
44
|
const message = parsed.detail ?? parsed.message ?? parsed.error ?? "";
|
|
43
45
|
const ErrorClass = HTTP_STATUS_MAP[status];
|
|
44
46
|
if (ErrorClass) {
|
|
45
|
-
return Effect.fail(new ErrorClass({
|
|
47
|
+
return Effect.fail(new ErrorClass({
|
|
48
|
+
message,
|
|
49
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
50
|
+
}));
|
|
46
51
|
}
|
|
47
52
|
return Effect.fail(new UnknownPosthogError({
|
|
48
53
|
code: parsed.code ?? parsed.type,
|
|
@@ -68,5 +73,6 @@ export const API = makeAPI({
|
|
|
68
73
|
}),
|
|
69
74
|
matchError,
|
|
70
75
|
ParseError: PosthogParseError,
|
|
76
|
+
retry: Retry,
|
|
71
77
|
});
|
|
72
78
|
//# 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,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,wCAAwC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC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AAC,CAAC;AAEF;;;;;GAKG;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,EAA0B,EAAE,CAAC,CAAC;QACvD,aAAa,EAAE,UAAU,KAAK,CAAC,MAAM,EAAE;KACxC,CAAC;IACF,UAAU;IACV,UAAU,EAAE,iBAAwB;IACpC,KAAK,EAAE,KAAY;CACpB,CAAC,CAAC"}
|
package/lib/retry.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* PostHog retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/posthog/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* PostHog API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as PostHog from "@distilled.cloud/posthog";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(PostHog.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(PostHog.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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
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";
|
|
21
|
+
declare const Retry_base: Context.ServiceClass<Retry, "PostHogRetry", Policy>;
|
|
22
|
+
/** Context tag for configuring retry behavior of PostHog API calls. */
|
|
12
23
|
export declare class Retry extends Retry_base {
|
|
13
24
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Provides a custom retry policy to all Posthog API calls.
|
|
16
|
-
*/
|
|
25
|
+
/** Provides a custom retry policy to every PostHog 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,uEAAuE;AACvE,qBAAa,KAAM,SAAQ,UAAgD;CAAG;AAE9E,yEAAyE;AACzE,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
|
+
* PostHog retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/posthog/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* PostHog API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as PostHog from "@distilled.cloud/posthog";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(PostHog.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(PostHog.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
|
-
|
|
10
|
-
*/
|
|
11
|
-
export class Retry extends Context.Service()("PosthogRetry") {
|
|
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 PostHog API calls. */
|
|
23
|
+
export class Retry extends Context.Service()("PostHogRetry") {
|
|
12
24
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Provides a custom retry policy to all Posthog API calls.
|
|
15
|
-
*/
|
|
25
|
+
/** Provides a custom retry policy to every PostHog 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,uEAAuE;AACvE,MAAM,OAAO,KAAM,SAAQ,OAAO,CAAC,OAAO,EAAiB,CAAC,cAAc,CAAC;CAAG;AAE9E,yEAAyE;AACzE,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/posthog",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"specs:update": "git -C specs/distilled-spec-posthog fetch && git -C specs/distilled-spec-posthog checkout main && git -C specs/distilled-spec-posthog pull"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@distilled.cloud/core": "0.16.
|
|
76
|
+
"@distilled.cloud/core": "0.16.4",
|
|
77
77
|
"effect": "4.0.0-beta.58"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
package/src/client.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
8
|
import * as Schema from "effect/Schema";
|
|
9
9
|
import { makeAPI } from "@distilled.cloud/core/client";
|
|
10
|
+
import { parseRetryAfterForStatus } from "@distilled.cloud/core/retry-after";
|
|
11
|
+
import { Retry } from "./retry.ts";
|
|
10
12
|
import {
|
|
11
13
|
HTTP_STATUS_MAP,
|
|
12
14
|
UnknownPosthogError,
|
|
@@ -46,13 +48,20 @@ const ApiErrorResponse = Schema.Struct({
|
|
|
46
48
|
const matchError = (
|
|
47
49
|
status: number,
|
|
48
50
|
errorBody: unknown,
|
|
51
|
+
_errors?: readonly unknown[],
|
|
52
|
+
headers?: Record<string, string | undefined>,
|
|
49
53
|
): Effect.Effect<never, unknown> => {
|
|
50
54
|
try {
|
|
51
55
|
const parsed = Schema.decodeUnknownSync(ApiErrorResponse)(errorBody);
|
|
52
56
|
const message = parsed.detail ?? parsed.message ?? parsed.error ?? "";
|
|
53
57
|
const ErrorClass = (HTTP_STATUS_MAP as any)[status];
|
|
54
58
|
if (ErrorClass) {
|
|
55
|
-
return Effect.fail(
|
|
59
|
+
return Effect.fail(
|
|
60
|
+
new ErrorClass({
|
|
61
|
+
message,
|
|
62
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
56
65
|
}
|
|
57
66
|
return Effect.fail(
|
|
58
67
|
new UnknownPosthogError({
|
|
@@ -80,4 +89,5 @@ export const API = makeAPI<Credentials>({
|
|
|
80
89
|
}),
|
|
81
90
|
matchError,
|
|
82
91
|
ParseError: PosthogParseError as any,
|
|
92
|
+
retry: Retry as any,
|
|
83
93
|
});
|
package/src/retry.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* PostHog retry configuration.
|
|
3
|
+
*
|
|
4
|
+
* Defines the per-SDK `Retry` Context.Service tag that
|
|
5
|
+
* `packages/posthog/src/client.ts` wires into `makeAPI`. Callers can
|
|
6
|
+
* install a blanket retry policy at the layer level and have every
|
|
7
|
+
* PostHog API call below it pick it up:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import * as PostHog from "@distilled.cloud/posthog";
|
|
12
|
+
*
|
|
13
|
+
* myEffect.pipe(PostHog.Retry.transient);
|
|
14
|
+
* Effect.provide(myEffect, Layer.succeed(PostHog.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
|
-
|
|
21
|
-
*/
|
|
22
|
-
export class Retry extends Context.Service<Retry, Policy>()("PosthogRetry") {}
|
|
39
|
+
/** Context tag for configuring retry behavior of PostHog API calls. */
|
|
40
|
+
export class Retry extends Context.Service<Retry, Policy>()("PostHogRetry") {}
|
|
23
41
|
|
|
24
|
-
/**
|
|
25
|
-
* Provides a custom retry policy to all Posthog API calls.
|
|
26
|
-
*/
|
|
42
|
+
/** Provides a custom retry policy to every PostHog 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);
|