@distilled.cloud/trigger-dev 1.0.0-rc.12 → 1.0.0-rc.14
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 +34 -0
- package/lib/credentials.d.ts +2 -2
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +3 -3
- package/lib/credentials.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/protocol.d.ts +5 -5
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +4 -7
- package/lib/protocol.js.map +1 -1
- package/lib/retry.d.ts +1 -1
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -1
- package/lib/retry.js.map +1 -1
- package/lib/services/trigger-dev.d.ts +136 -13
- package/lib/services/trigger-dev.d.ts.map +1 -1
- package/lib/services/trigger-dev.js +223 -389
- package/lib/services/trigger-dev.js.map +1 -1
- package/package.json +13 -11
- package/src/credentials.ts +9 -12
- package/src/errors.ts +1 -1
- package/src/index.ts +1 -6
- package/src/protocol.ts +26 -30
- package/src/retry.ts +3 -11
- package/src/services/trigger-dev.ts +605 -823
package/src/index.ts
CHANGED
|
@@ -28,9 +28,4 @@ export * as Services from "./services/index.ts";
|
|
|
28
28
|
// same-named shared ones from ./errors.ts — the ops actually raise the
|
|
29
29
|
// service-local classes.
|
|
30
30
|
export * from "./services/trigger-dev.ts";
|
|
31
|
-
export {
|
|
32
|
-
BadRequest,
|
|
33
|
-
Conflict,
|
|
34
|
-
NotFound,
|
|
35
|
-
UnprocessableEntity,
|
|
36
|
-
} from "./services/trigger-dev.ts";
|
|
31
|
+
export { BadRequest, Conflict, NotFound, UnprocessableEntity } from "./services/trigger-dev.ts";
|
package/src/protocol.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type * as API from "@distilled.cloud/core/api";
|
|
2
|
+
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
3
|
+
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
1
4
|
/**
|
|
2
5
|
* TriggerDevProtocol — hand-written.
|
|
3
6
|
*
|
|
@@ -15,15 +18,12 @@
|
|
|
15
18
|
* HTTP-status classes, then {@link UnknownTriggerDevError}.
|
|
16
19
|
*/
|
|
17
20
|
import * as Effect from "effect/Effect";
|
|
21
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
22
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
18
23
|
import type * as Layer from "effect/Layer";
|
|
19
24
|
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 { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
24
|
-
import type { API_ERRORS, ConfigError } from "@distilled.cloud/core/errors";
|
|
25
25
|
import { Credentials, type Config } from "./credentials.ts";
|
|
26
|
-
import { UnknownTriggerDevError } from "./errors.ts";
|
|
26
|
+
import { UnknownTriggerDevError, TriggerDevParseError } from "./errors.ts";
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Error channel shared by every generated Trigger.dev operation. Generated
|
|
@@ -36,32 +36,28 @@ export type TriggerDevOpError =
|
|
|
36
36
|
| InstanceType<(typeof API_ERRORS)[number]>
|
|
37
37
|
| UnknownTriggerDevError
|
|
38
38
|
| ConfigError
|
|
39
|
-
| HttpClientError.HttpClientError
|
|
39
|
+
| HttpClientError.HttpClientError
|
|
40
|
+
| TriggerDevParseError;
|
|
40
41
|
|
|
41
42
|
/** Context (requirements) shared by every generated Trigger.dev operation. */
|
|
42
43
|
export type TriggerDevOpContext = Credentials | HttpClient.HttpClient;
|
|
43
44
|
|
|
44
|
-
export const TriggerDevProtocol: Layer.Layer<API.Protocol> =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
export const TriggerDevProtocol: Layer.Layer<API.Protocol> = makeRestProtocol<Config>({
|
|
46
|
+
// The Credentials service holds an effect — resolving it here (per
|
|
47
|
+
// request, on the calling fiber) picks up context-provided credentials.
|
|
48
|
+
credentials: Effect.gen(function* () {
|
|
49
|
+
const resolve = yield* Credentials;
|
|
50
|
+
return yield* resolve;
|
|
51
|
+
}),
|
|
52
|
+
baseUrl: (creds) => creds.apiBaseUrl,
|
|
53
|
+
headers: (creds) => ({
|
|
54
|
+
Authorization: `Bearer ${Redacted.value(creds.apiKey)}`,
|
|
55
|
+
}),
|
|
56
|
+
unknownError: ({ code, message, body }) =>
|
|
57
|
+
new UnknownTriggerDevError({
|
|
58
|
+
code: typeof code === "string" ? code : code !== undefined ? String(code) : undefined,
|
|
59
|
+
message,
|
|
60
|
+
body,
|
|
55
61
|
}),
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
code:
|
|
59
|
-
typeof code === "string"
|
|
60
|
-
? code
|
|
61
|
-
: code !== undefined
|
|
62
|
-
? String(code)
|
|
63
|
-
: undefined,
|
|
64
|
-
message,
|
|
65
|
-
body,
|
|
66
|
-
}),
|
|
67
|
-
});
|
|
62
|
+
parseError: ({ body, cause }) => new TriggerDevParseError({ body, cause }),
|
|
63
|
+
});
|
package/src/retry.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Policy, throttlingFactory, transientFactory } from "@distilled.cloud/core/retry";
|
|
1
2
|
/**
|
|
2
3
|
* Trigger.dev retry configuration.
|
|
3
4
|
*
|
|
@@ -16,11 +17,6 @@
|
|
|
16
17
|
import * as Context from "effect/Context";
|
|
17
18
|
import * as Effect from "effect/Effect";
|
|
18
19
|
import * as Layer from "effect/Layer";
|
|
19
|
-
import {
|
|
20
|
-
type Policy,
|
|
21
|
-
throttlingFactory,
|
|
22
|
-
transientFactory,
|
|
23
|
-
} from "@distilled.cloud/core/retry";
|
|
24
20
|
|
|
25
21
|
export {
|
|
26
22
|
type Options,
|
|
@@ -36,18 +32,14 @@ export {
|
|
|
36
32
|
} from "@distilled.cloud/core/retry";
|
|
37
33
|
|
|
38
34
|
/** Context tag for configuring retry behavior of Trigger.dev API calls. */
|
|
39
|
-
export class Retry extends Context.Service<Retry, Policy>()(
|
|
40
|
-
"TriggerDevRetry",
|
|
41
|
-
) {}
|
|
35
|
+
export class Retry extends Context.Service<Retry, Policy>()("TriggerDevRetry") {}
|
|
42
36
|
|
|
43
37
|
/** Provides a custom retry policy to every Trigger.dev API call below it. */
|
|
44
38
|
export const policy = (optionsOrFactory: Policy) =>
|
|
45
39
|
Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
46
40
|
|
|
47
41
|
/** Disables all automatic retries. */
|
|
48
|
-
export const none = Effect.provide(
|
|
49
|
-
Layer.succeed(Retry, { while: () => false }),
|
|
50
|
-
);
|
|
42
|
+
export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
|
|
51
43
|
|
|
52
44
|
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
53
45
|
export const throttling = policy(throttlingFactory);
|