@distilled.cloud/steel 0.0.0 → 1.0.0-rc.19

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 (102) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +66 -4
  3. package/lib/.lazy.json +1 -0
  4. package/lib/_bundle/lazy.js +4 -0
  5. package/lib/_bundle/sdk.js +2 -0
  6. package/lib/_bundle/sdk.js.map +1 -0
  7. package/lib/credentials.d.ts +24 -0
  8. package/lib/credentials.d.ts.map +1 -0
  9. package/lib/credentials.js +1 -0
  10. package/lib/errors.d.ts +42 -0
  11. package/lib/errors.d.ts.map +1 -0
  12. package/lib/errors.js +1 -0
  13. package/lib/index.d.ts +26 -0
  14. package/lib/index.d.ts.map +1 -0
  15. package/lib/index.js +7 -0
  16. package/lib/index.lazy.js +7 -0
  17. package/lib/index.lazy.js.map +1 -0
  18. package/lib/pagination.d.ts +10 -0
  19. package/lib/pagination.d.ts.map +1 -0
  20. package/lib/pagination.js +1 -0
  21. package/lib/protocol.d.ts +19 -0
  22. package/lib/protocol.d.ts.map +1 -0
  23. package/lib/protocol.js +1 -0
  24. package/lib/retry.d.ts +50 -0
  25. package/lib/retry.d.ts.map +1 -0
  26. package/lib/retry.js +1 -0
  27. package/lib/services/api_keys.d.ts +63 -0
  28. package/lib/services/api_keys.d.ts.map +1 -0
  29. package/lib/services/api_keys.js +2 -0
  30. package/lib/services/api_keys.js.map +1 -0
  31. package/lib/services/auth.d.ts +32 -0
  32. package/lib/services/auth.d.ts.map +1 -0
  33. package/lib/services/auth.js +2 -0
  34. package/lib/services/auth.js.map +1 -0
  35. package/lib/services/browser_tools.d.ts +166 -0
  36. package/lib/services/browser_tools.d.ts.map +1 -0
  37. package/lib/services/browser_tools.js +2 -0
  38. package/lib/services/browser_tools.js.map +1 -0
  39. package/lib/services/captchas.d.ts +72 -0
  40. package/lib/services/captchas.d.ts.map +1 -0
  41. package/lib/services/captchas.js +2 -0
  42. package/lib/services/captchas.js.map +1 -0
  43. package/lib/services/credentials.d.ts +127 -0
  44. package/lib/services/credentials.d.ts.map +1 -0
  45. package/lib/services/credentials.js +2 -0
  46. package/lib/services/credentials.js.map +1 -0
  47. package/lib/services/extensions.d.ts +122 -0
  48. package/lib/services/extensions.d.ts.map +1 -0
  49. package/lib/services/extensions.js +2 -0
  50. package/lib/services/extensions.js.map +1 -0
  51. package/lib/services/files.d.ts +144 -0
  52. package/lib/services/files.d.ts.map +1 -0
  53. package/lib/services/files.js +2 -0
  54. package/lib/services/files.js.map +1 -0
  55. package/lib/services/index.d.ts +11 -0
  56. package/lib/services/index.d.ts.map +1 -0
  57. package/lib/services/index.js +10 -0
  58. package/lib/services/profiles.d.ts +422 -0
  59. package/lib/services/profiles.d.ts.map +1 -0
  60. package/lib/services/profiles.js +2 -0
  61. package/lib/services/profiles.js.map +1 -0
  62. package/lib/services/projects.d.ts +50 -0
  63. package/lib/services/projects.d.ts.map +1 -0
  64. package/lib/services/projects.js +2 -0
  65. package/lib/services/projects.js.map +1 -0
  66. package/lib/services/sessions.d.ts +1977 -0
  67. package/lib/services/sessions.d.ts.map +1 -0
  68. package/lib/services/sessions.js +44 -0
  69. package/lib/services/sessions.js.map +1 -0
  70. package/lib/services.lazy/api_keys.js +1 -0
  71. package/lib/services.lazy/auth.js +1 -0
  72. package/lib/services.lazy/browser_tools.js +1 -0
  73. package/lib/services.lazy/captchas.js +1 -0
  74. package/lib/services.lazy/credentials.js +1 -0
  75. package/lib/services.lazy/extensions.js +1 -0
  76. package/lib/services.lazy/files.js +1 -0
  77. package/lib/services.lazy/index.js +3 -0
  78. package/lib/services.lazy/profiles.js +1 -0
  79. package/lib/services.lazy/projects.js +1 -0
  80. package/lib/services.lazy/sessions.js +4 -0
  81. package/lib/traits.d.ts +11 -0
  82. package/lib/traits.d.ts.map +1 -0
  83. package/lib/traits.js +1 -0
  84. package/package.json +82 -2
  85. package/src/credentials.ts +63 -0
  86. package/src/errors.ts +51 -0
  87. package/src/index.ts +25 -0
  88. package/src/pagination.ts +9 -0
  89. package/src/protocol.ts +77 -0
  90. package/src/retry.ts +69 -0
  91. package/src/services/api_keys.ts +124 -0
  92. package/src/services/auth.ts +101 -0
  93. package/src/services/browser_tools.ts +338 -0
  94. package/src/services/captchas.ts +216 -0
  95. package/src/services/credentials.ts +292 -0
  96. package/src/services/extensions.ts +338 -0
  97. package/src/services/files.ts +456 -0
  98. package/src/services/index.ts +11 -0
  99. package/src/services/profiles.ts +871 -0
  100. package/src/services/projects.ts +146 -0
  101. package/src/services/sessions.ts +4515 -0
  102. package/src/traits.ts +46 -0
@@ -0,0 +1,77 @@
1
+ import type * as API from "@distilled.cloud/core/api";
2
+ import type { API_ERRORS, ConfigError, InvalidInput } from "@distilled.cloud/core/errors";
3
+ import { makeRestProtocol, type RestErrorEnvelope } from "@distilled.cloud/core/protocol-rest";
4
+ import type { SdkError } from "@distilled.cloud/core/sdk-error";
5
+ /**
6
+ * SteelProtocol -- the shared REST protocol instantiated for the Steel API.
7
+ *
8
+ * request: credentials -> `steel-api-key: <key>` + base URL (default
9
+ * https://api.steel.dev), resolved from the calling fiber on
10
+ * every request
11
+ *
12
+ * response: 2xx JSON is the payload, downloads are bytes; non-2xx
13
+ * `{ error, message, code }` (or the commands endpoints'
14
+ * `{ error: { code, message } }`) bodies map to the operation's
15
+ * typed error classes, then the shared HTTP-status classes, then
16
+ * {@link UnknownSteelError}.
17
+ */
18
+ import * as Effect from "effect/Effect";
19
+ import type * as HttpClient from "effect/http/HttpClient";
20
+ import type * as HttpClientError from "effect/http/HttpClientError";
21
+ import type * as Layer from "effect/Layer";
22
+ import * as Redacted from "effect/Redacted";
23
+ import { Credentials, type Config } from "./credentials.ts";
24
+ import { SteelParseError, UnknownSteelError } from "./errors.ts";
25
+
26
+ /**
27
+ * Error channel shared by every generated Steel operation. Generated service
28
+ * files annotate operations with `API.OperationMethod<I, O, SteelOpError,
29
+ * SteelOpContext>` explicitly so the compiler never infers these back out of
30
+ * the schema generics.
31
+ */
32
+ export type SteelOpError =
33
+ | InstanceType<(typeof API_ERRORS)[number]>
34
+ | UnknownSteelError
35
+ | ConfigError
36
+ | HttpClientError.HttpClientError
37
+ | SteelParseError
38
+ | InvalidInput
39
+ | SdkError;
40
+
41
+ /** Context (requirements) shared by every generated Steel operation. */
42
+ export type SteelOpContext = Credentials | HttpClient.HttpClient;
43
+
44
+ const str = (value: unknown): string | undefined => (typeof value === "string" ? value : undefined);
45
+
46
+ const errorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
47
+ if (body === null || typeof body !== "object") return undefined;
48
+ const rec = body as Record<string, unknown>;
49
+ // `{ error: { code, message } }` (session commands) or the flat
50
+ // `{ error: "<title>", message, code }` every other endpoint returns.
51
+ const nested =
52
+ rec.error !== null && typeof rec.error === "object"
53
+ ? (rec.error as Record<string, unknown>)
54
+ : rec;
55
+ const code = str(nested.code);
56
+ const message = str(nested.message) ?? str(rec.error);
57
+ if (code === undefined && message === undefined) return undefined;
58
+ return { code, message };
59
+ };
60
+
61
+ export const SteelProtocol: Layer.Layer<API.Protocol> = /*@__PURE__*/ makeRestProtocol<Config>({
62
+ // Resolved on the calling fiber per request, so a rotated key is picked up
63
+ // without rebuilding the layer.
64
+ credentials: /*@__PURE__*/ Effect.flatMap(Credentials, (resolve) => resolve),
65
+ baseUrl: (creds) => creds.baseUrl,
66
+ headers: (creds) => ({
67
+ "steel-api-key": Redacted.value(creds.apiKey),
68
+ }),
69
+ errorEnvelope,
70
+ unknownError: ({ code, message, body }) =>
71
+ new UnknownSteelError({
72
+ code: typeof code === "string" ? code : code !== undefined ? String(code) : undefined,
73
+ message,
74
+ body,
75
+ }),
76
+ parseError: ({ body, cause }) => new SteelParseError({ body, cause }),
77
+ });
package/src/retry.ts ADDED
@@ -0,0 +1,69 @@
1
+ import * as Retries from "@distilled.cloud/core/retry";
2
+ /**
3
+ * Steel retry surface -- a veneer over `@distilled.cloud/core/retry`.
4
+ *
5
+ * The `Retry` service tag is threaded into every generated operation via
6
+ * `API.make({ retry: Retry })`, so a caller-installed policy applies to all
7
+ * Steel calls below it and core's `makeDefault` is the fallback when none is
8
+ * provided.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import * as Steel from "@distilled.cloud/steel";
13
+ *
14
+ * myEffect.pipe(Steel.Retry.transient);
15
+ * ```
16
+ */
17
+ import * as Context from "effect/Context";
18
+ import * as Effect from "effect/Effect";
19
+ import * as Layer from "effect/Layer";
20
+
21
+ export type Options = Retries.Options;
22
+ export type Factory = Retries.Factory;
23
+ export type Policy = Retries.Policy;
24
+
25
+ /** Context tag for configuring retry behavior of Steel API calls. */
26
+ export class Retry extends /*@__PURE__*/ Context.Service<Retry, Policy>()("SteelRetry") {}
27
+
28
+ /** Provides a custom retry policy to every Steel API call below it. */
29
+ export const policy: {
30
+ (
31
+ options: Options,
32
+ ): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
33
+ (
34
+ factory: Factory,
35
+ ): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
36
+ } = (optionsOrFactory: Options | Factory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
37
+
38
+ /** Disables all automatic retries. */
39
+ export const none: <A, E, R>(
40
+ effect: Effect.Effect<A, E, R>,
41
+ ) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ Effect.provide(
42
+ /*@__PURE__*/ Layer.succeed(Retry, { while: () => false }),
43
+ );
44
+
45
+ /**
46
+ * The default retry policy (core's): transient/throttling/retryable errors,
47
+ * capped exponential backoff with jitter, server `retryAfter` hints honored
48
+ * with precedence.
49
+ */
50
+ export const makeDefault: Factory = Retries.makeDefault;
51
+
52
+ export const jittered = Retries.jittered;
53
+ export const capped = Retries.capped;
54
+
55
+ /** Retry options that retry all throttling errors indefinitely. */
56
+ export const throttlingOptions: Options = Retries.throttlingOptions;
57
+
58
+ /** Retries all throttling errors indefinitely (honoring server hints). */
59
+ export const throttling: <A, E, R>(
60
+ effect: Effect.Effect<A, E, R>,
61
+ ) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.throttlingFactory);
62
+
63
+ /** Retry options that retry all transient errors indefinitely. */
64
+ export const transientOptions: Options = Retries.transientOptions;
65
+
66
+ /** Retries all transient errors indefinitely. */
67
+ export const transient: <A, E, R>(
68
+ effect: Effect.Effect<A, E, R>,
69
+ ) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.transientFactory);
@@ -0,0 +1,124 @@
1
+ import * as API from "@distilled.cloud/core/api";
2
+ import * as C from "@distilled.cloud/core/category";
3
+ // AUTO-GENERATED by scripts/generate.ts from .generated-specs (specs/spec-mirror-steel/specs/openapi.json). Do not edit.
4
+ import * as S from "@distilled.cloud/core/schema-lite";
5
+ import * as __L from "@distilled.cloud/core/schema-lite";
6
+ import type * as Redacted from "effect/Redacted";
7
+ import { UnknownSteelError } from "../errors.ts";
8
+ import { SteelProtocol, type SteelOpError, type SteelOpContext } from "../protocol.ts";
9
+ import * as Retry from "../retry.ts";
10
+ import * as T from "../traits.ts";
11
+ // Schema table, filled on first reach (see __S at the end).
12
+ const __s: any[] = [];
13
+
14
+ export type { SteelOpError, SteelOpContext };
15
+
16
+ /** Span facts shared by every operation (com.distilled.telemetry#service). */
17
+ const TELEMETRY = {
18
+ system: "steel-api",
19
+ responseHeaders: [
20
+ { header: "x-request-id", name: "http.response.header.x-request-id", transform: "list" },
21
+ { header: "request-id", name: "http.response.header.request-id", transform: "list" },
22
+ ],
23
+ prefix: "Steel",
24
+ service: "ApiKeys",
25
+ propagate: "w3c",
26
+ } as const;
27
+
28
+ export class BadRequest
29
+ extends /*@__PURE__*/ T.applyErrorMatchers(
30
+ /*@__PURE__*/ S.TaggedError<BadRequest>()("BadRequest", {
31
+ code: S.Number,
32
+ message: S.String,
33
+ }).pipe(C.withBadRequestError),
34
+ [{ status: 400 }],
35
+ ) {}
36
+
37
+ export class Forbidden
38
+ extends /*@__PURE__*/ T.applyErrorMatchers(
39
+ /*@__PURE__*/ S.TaggedError<Forbidden>()("Forbidden", {
40
+ code: S.Number,
41
+ message: S.String,
42
+ }).pipe(C.withAuthError),
43
+ [{ status: 403 }],
44
+ ) {}
45
+
46
+ export class NotFound
47
+ extends /*@__PURE__*/ T.applyErrorMatchers(
48
+ /*@__PURE__*/ S.TaggedError<NotFound>()("NotFound", {
49
+ code: S.Number,
50
+ message: S.String,
51
+ }).pipe(C.withBadRequestError),
52
+ [{ status: 404 }],
53
+ ) {}
54
+
55
+ /** Defaults to `project`. Global API keys may only create project-scoped keys. Only organization admins using dashboard authentication may create a `global` key; projectId is ignored for those keys. */
56
+ export type CreateApiKeyRequestScopeType = "project" | "global";
57
+ export interface CreateApiKeyRequest {
58
+ /** A human-readable label for the new key. Defaults to Default. */
59
+ name?: string | undefined;
60
+ /** The active project to bind the new key to, belonging to the authenticated organization. Required when authenticating with a global API key. Dashboard users may omit it to use their default project. */
61
+ projectId?: string | undefined;
62
+ /** Defaults to `project`. Global API keys may only create project-scoped keys. Only organization admins using dashboard authentication may create a `global` key; projectId is ignored for those keys. */
63
+ scopeType?: CreateApiKeyRequestScopeType | (string & {}) | undefined;
64
+ }
65
+ /** `project` pins the key to one project. `global` authorizes access across the organization and has no project binding. */
66
+ export type ApiKeyResponseScopeType = "project" | "global";
67
+ export interface ApiKeyResponse {
68
+ createdAt: string;
69
+ id: string;
70
+ /** The full secret on creation or rotation only. Metadata reads return a masked preview. Store a newly created secret securely; it cannot be retrieved later. */
71
+ key: string | Redacted.Redacted<string>;
72
+ name?: string | undefined;
73
+ /** The pinned project, or null for a global key, which binds to no project. */
74
+ projectId: string | null;
75
+ /** `project` pins the key to one project. `global` authorizes access across the organization and has no project binding. */
76
+ scopeType: ApiKeyResponseScopeType;
77
+ updatedAt: string;
78
+ }
79
+ export type CreateApiKeyError = BadRequest | Forbidden | NotFound | SteelOpError;
80
+ /** Create an API key Create a project-scoped API key using a global (organization-scoped) API key. Supply projectId for an active project in the authenticated organization; scopeType must be project or omitted. Project-scoped API keys cannot create keys, and global keys cannot create other global keys. Dashboard users may also create project keys, or global keys with organization admin access. Returns the full secret once with Cache-Control: no-store; save it securely. The new key is independent: revoking the creating global key does not revoke keys it created. Missing projectId returns 400; insufficient scope returns 403; an unavailable or foreign project returns 404. */
81
+ export const createApiKey: API.OperationMethod<
82
+ CreateApiKeyRequest,
83
+ ApiKeyResponse,
84
+ CreateApiKeyError,
85
+ SteelOpContext
86
+ > = /*@__PURE__*/ API.make(() => ({
87
+ input: __S(0, __c0, 0) as any as S.Schema<CreateApiKeyRequest>,
88
+ output: __S(1, __c0, 1) as any as S.Schema<ApiKeyResponse>,
89
+ errors: [BadRequest, Forbidden, NotFound, UnknownSteelError],
90
+ protocol: SteelProtocol,
91
+ retry: Retry.Retry,
92
+ telemetry: TELEMETRY,
93
+ span: "CreateApiKey",
94
+ }));
95
+
96
+ // Schema builders: each runs one schema initializer, on that schema's first use.
97
+ function __c0(j: number): any {
98
+ switch (j) {
99
+ case 0:
100
+ return S.suspend(() =>
101
+ S.Struct({
102
+ name: S.optional(S.String),
103
+ projectId: S.optional(S.String),
104
+ scopeType: S.optional(S.String),
105
+ }).pipe(T.Http({ method: "POST", uri: "/v1/api-keys", code: 200 })),
106
+ ).annotate({ identifier: "CreateApiKeyRequest" });
107
+ case 1:
108
+ return S.suspend(() =>
109
+ S.Struct({
110
+ createdAt: S.String,
111
+ id: S.String,
112
+ key: S.String.pipe(T.SensitiveValue({})),
113
+ name: S.optional(S.String),
114
+ projectId: S.NullOr(S.String),
115
+ scopeType: S.String,
116
+ updatedAt: S.String,
117
+ }),
118
+ ).annotate({ identifier: "ApiKeyResponse" });
119
+ }
120
+ }
121
+ // Schema table: entry i is schema j of builder f, made on first reach.
122
+ function __S(i: number, f: (j: number) => unknown, j: number): any {
123
+ return (__s[i] ??= __L.at(f, j));
124
+ }
@@ -0,0 +1,101 @@
1
+ import * as API from "@distilled.cloud/core/api";
2
+ // AUTO-GENERATED by scripts/generate.ts from .generated-specs (specs/spec-mirror-steel/specs/openapi.json). Do not edit.
3
+ import * as S from "@distilled.cloud/core/schema-lite";
4
+ import * as __L from "@distilled.cloud/core/schema-lite";
5
+ import { UnknownSteelError } from "../errors.ts";
6
+ import { SteelProtocol, type SteelOpError, type SteelOpContext } from "../protocol.ts";
7
+ import * as Retry from "../retry.ts";
8
+ import * as T from "../traits.ts";
9
+ // Schema table, filled on first reach (see __S at the end).
10
+ const __s: any[] = [];
11
+
12
+ export type { SteelOpError, SteelOpContext };
13
+
14
+ /** Span facts shared by every operation (com.distilled.telemetry#service). */
15
+ const TELEMETRY = {
16
+ system: "steel-api",
17
+ responseHeaders: [
18
+ { header: "x-request-id", name: "http.response.header.x-request-id", transform: "list" },
19
+ { header: "request-id", name: "http.response.header.request-id", transform: "list" },
20
+ ],
21
+ prefix: "Steel",
22
+ service: "Auth",
23
+ propagate: "w3c",
24
+ } as const;
25
+
26
+ export interface GetWellKnownJwksRequest {}
27
+ /** A single JSON Web Key (JWK). */
28
+ export interface JwksKeysItem {
29
+ /** The specific cryptographic algorithm used with the key (e.g., 'RS256'). */
30
+ alg?: string | undefined;
31
+ /** The exponent for the RSA public key. */
32
+ e?: string | undefined;
33
+ /** The unique identifier for the key. */
34
+ kid?: string | undefined;
35
+ /** The key type, identifying the algorithm family (e.g., 'RSA'). */
36
+ kty?: string | undefined;
37
+ /** The modulus for the RSA public key. */
38
+ n?: string | undefined;
39
+ /** The intended use of the public key (e.g., 'sig' for signature). */
40
+ use?: string | undefined;
41
+ [key: string]: unknown;
42
+ }
43
+ /** A list of JSON Web Keys. */
44
+ export type JwksKeysList = Array<JwksKeysItem>;
45
+ /** A JSON Web Key Set (JWKS) containing a list of public keys. */
46
+ export interface Jwks {
47
+ /** A list of JSON Web Keys. */
48
+ keys: JwksKeysList;
49
+ }
50
+ export type GetWellKnownJwksError = SteelOpError;
51
+ /** Get Public Keys (JWKS) Provides the JSON Web Key Set (JWKS) for verifying JWTs issued by this service. */
52
+ export const getWellKnownJwks: API.OperationMethod<
53
+ GetWellKnownJwksRequest,
54
+ Jwks,
55
+ GetWellKnownJwksError,
56
+ SteelOpContext
57
+ > = /*@__PURE__*/ API.make(() => ({
58
+ input: __S(0, __c0, 0) as any as S.Schema<GetWellKnownJwksRequest>,
59
+ output: __S(3, __c0, 3) as any as S.Schema<Jwks>,
60
+ errors: [UnknownSteelError],
61
+ protocol: SteelProtocol,
62
+ retry: Retry.Retry,
63
+ telemetry: TELEMETRY,
64
+ span: "GetWellKnownJwks",
65
+ }));
66
+
67
+ // Schema builders: each runs one schema initializer, on that schema's first use.
68
+ function __c0(j: number): any {
69
+ switch (j) {
70
+ case 0:
71
+ return S.suspend(() =>
72
+ S.Struct({}).pipe(T.Http({ method: "GET", uri: "/.well-known/jwks.json", code: 200 })),
73
+ ).annotate({ identifier: "GetWellKnownJwksRequest" });
74
+ case 1:
75
+ return S.suspend(() =>
76
+ S.StructWithRest(
77
+ S.Struct({
78
+ alg: S.optional(S.String),
79
+ e: S.optional(S.String),
80
+ kid: S.optional(S.String),
81
+ kty: S.optional(S.String),
82
+ n: S.optional(S.String),
83
+ use: S.optional(S.String),
84
+ }),
85
+ [S.Record(S.String, S.Unknown)],
86
+ ),
87
+ ).annotate({ identifier: "JwksKeysItem" });
88
+ case 2:
89
+ return S.Array(__S(1, __c0, 1));
90
+ case 3:
91
+ return S.suspend(() =>
92
+ S.Struct({
93
+ keys: __S(2, __c0, 2),
94
+ }),
95
+ ).annotate({ identifier: "Jwks" });
96
+ }
97
+ }
98
+ // Schema table: entry i is schema j of builder f, made on first reach.
99
+ function __S(i: number, f: (j: number) => unknown, j: number): any {
100
+ return (__s[i] ??= __L.at(f, j));
101
+ }