samva 0.0.1 → 0.2.0

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 (79) hide show
  1. package/AGENTS.md +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +392 -5
  4. package/dist/categories-CsUa8ojo.js +143 -0
  5. package/dist/client/client/client.gen.d.ts +2 -0
  6. package/dist/client/client/index.d.ts +10 -0
  7. package/dist/client/client/types.gen.d.ts +120 -0
  8. package/dist/client/client/utils.gen.d.ts +37 -0
  9. package/dist/client/client.gen.d.ts +12 -0
  10. package/dist/client/core/auth.gen.d.ts +25 -0
  11. package/dist/client/core/bodySerializer.gen.d.ts +25 -0
  12. package/dist/client/core/params.gen.d.ts +43 -0
  13. package/dist/client/core/pathSerializer.gen.d.ts +33 -0
  14. package/dist/client/core/queryKeySerializer.gen.d.ts +18 -0
  15. package/dist/client/core/serverSentEvents.gen.d.ts +71 -0
  16. package/dist/client/core/types.gen.d.ts +83 -0
  17. package/dist/client/core/utils.gen.d.ts +19 -0
  18. package/dist/client/sdk.gen.d.ts +1558 -0
  19. package/dist/client/types.gen.d.ts +7917 -0
  20. package/dist/client-BqkU-sFv.js +6049 -0
  21. package/dist/effect/api-keys.d.ts +190 -0
  22. package/dist/effect/api-keys.js +27 -0
  23. package/dist/effect/campaigns.d.ts +2055 -0
  24. package/dist/effect/campaigns.js +33 -0
  25. package/dist/effect/categories.d.ts +65 -0
  26. package/dist/effect/categories.js +2 -0
  27. package/dist/effect/client.d.ts +9 -0
  28. package/dist/effect/client.js +13 -0
  29. package/dist/effect/contacts.d.ts +1278 -0
  30. package/dist/effect/contacts.js +39 -0
  31. package/dist/effect/conversations.d.ts +1604 -0
  32. package/dist/effect/conversations.js +23 -0
  33. package/dist/effect/design.d.ts +209 -0
  34. package/dist/effect/design.js +13 -0
  35. package/dist/effect/email.d.ts +1022 -0
  36. package/dist/effect/email.js +111 -0
  37. package/dist/effect/generated-metadata.d.ts +54 -0
  38. package/dist/effect/generated.d.ts +32156 -0
  39. package/dist/effect/index.d.ts +36 -0
  40. package/dist/effect/index.js +17 -0
  41. package/dist/effect/internal/client.d.ts +35 -0
  42. package/dist/effect/internal/operation.d.ts +466 -0
  43. package/dist/effect/messages.d.ts +1047 -0
  44. package/dist/effect/messages.js +23 -0
  45. package/dist/effect/operations.d.ts +97 -0
  46. package/dist/effect/operations.js +15 -0
  47. package/dist/effect/organizations.d.ts +559 -0
  48. package/dist/effect/organizations.js +21 -0
  49. package/dist/effect/pagination.d.ts +37 -0
  50. package/dist/effect/retry.d.ts +60 -0
  51. package/dist/effect/retry.js +112 -0
  52. package/dist/effect/runtime.d.ts +7 -0
  53. package/dist/effect/scheduled-messages.d.ts +1009 -0
  54. package/dist/effect/scheduled-messages.js +17 -0
  55. package/dist/effect/templates.d.ts +2591 -0
  56. package/dist/effect/templates.js +66 -0
  57. package/dist/effect/webhooks.d.ts +228 -0
  58. package/dist/effect/webhooks.js +33 -0
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.js +2 -0
  61. package/dist/normalize-LkWl4HUF.js +82 -0
  62. package/dist/normalize.d.ts +87 -0
  63. package/dist/operation-Ccqh_yxb.js +596 -0
  64. package/dist/promises/errors.gen.d.ts +179 -0
  65. package/dist/promises/index.d.ts +153 -0
  66. package/dist/promises/index.js +2 -0
  67. package/dist/promises/types.gen.d.ts +1 -0
  68. package/dist/promises-Dgv8UmCC.js +5911 -0
  69. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  70. package/dist/service-map.d.ts +732 -0
  71. package/dist/webhooks/effect.d.ts +1 -0
  72. package/dist/webhooks/effect.js +1 -0
  73. package/dist/webhooks/promise.d.ts +1 -0
  74. package/dist/webhooks/promise.js +1 -0
  75. package/package.json +151 -4
  76. package/CLAUDE.md +0 -111
  77. package/bun.lock +0 -29
  78. package/index.ts +0 -1
  79. package/tsconfig.json +0 -29
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Default-on retry for the Effect SDK.
3
+ *
4
+ * Every retry-safe operation — reads and idempotency-keyed sends — retries out
5
+ * of the box: transient failures back off with jittered exponential delay, and
6
+ * `429 RateLimitedError` honors the server's `retryAfterSeconds` hint (capped).
7
+ * Eligibility is decided by the {@link isRetryable} category predicate; the set
8
+ * of retry-safe operations is decided by the module adapter (GET/HEAD reads and keyed
9
+ * sends), so keyless mutating operations are never auto-retried.
10
+ *
11
+ * The policy is read from context via {@link Service} using
12
+ * `Effect.serviceOption`, so the default applies when the service is absent and
13
+ * no operation gains a requirement. Install {@link layerDisabled} to turn
14
+ * retries off, or {@link layer} for a custom schedule/options.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { Effect } from "effect";
19
+ * import * as Retry from "samva/effect/retry";
20
+ *
21
+ * // Disable auto-retry for a program:
22
+ * program.pipe(Effect.provide(Retry.layerDisabled));
23
+ * ```
24
+ */
25
+ import { Context, Effect, Layer } from "effect";
26
+ /**
27
+ * A retry policy: the transform applied to each retry-safe operation. Modeled as
28
+ * a function so policies can wrap the effect arbitrarily (retry options, custom
29
+ * schedules, or no-op passthrough).
30
+ */
31
+ export interface Interface {
32
+ readonly retry: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
33
+ }
34
+ declare const Service_base: Context.ServiceClass<Service, "samva/Retry", Interface>;
35
+ /**
36
+ * Context service carrying the SDK's retry policy. Absent → {@link defaultPolicy}
37
+ * (read through `Effect.serviceOption`, so no operation gains a requirement).
38
+ */
39
+ export declare class Service extends Service_base {
40
+ }
41
+ export declare const defaultPolicy: Interface;
42
+ export declare const disabledPolicy: Interface;
43
+ export declare const fromOptions: (options: Effect.Retry.Options<unknown>) => Interface;
44
+ export declare const layerDefault: Layer.Layer<Service>;
45
+ export declare const layerDisabled: Layer.Layer<Service>;
46
+ export declare const layer: (options: Effect.Retry.Options<unknown>) => Layer.Layer<Service>;
47
+ /**
48
+ * Apply the ambient {@link Service} policy to a retry-safe operation. Reads
49
+ * the policy optionally (default when absent) and keeps the effect's `R`.
50
+ */
51
+ export declare const withRetry: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
52
+ /**
53
+ * Generate a v4-shaped idempotency key through Effect's `Random` service —
54
+ * deterministic under a seeded/`TestClock` runtime and platform-neutral (no Web
55
+ * Crypto or bare `Math.random` at the call site). Facade sends evaluate this
56
+ * once per logical call so the key is stable across auto-retries within the call
57
+ * and distinct across calls.
58
+ */
59
+ export declare const generateIdempotencyKey: Effect.Effect<string>;
60
+ export {};
@@ -0,0 +1,112 @@
1
+ import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.js";
2
+ import { h as isRetryable } from "../categories-CsUa8ojo.js";
3
+ import { Context, Duration, Effect, Layer, Option, Random, Schedule } from "effect";
4
+ import * as Predicate$1 from "effect/Predicate";
5
+ //#region src/effect/retry.ts
6
+ /**
7
+ * Default-on retry for the Effect SDK.
8
+ *
9
+ * Every retry-safe operation — reads and idempotency-keyed sends — retries out
10
+ * of the box: transient failures back off with jittered exponential delay, and
11
+ * `429 RateLimitedError` honors the server's `retryAfterSeconds` hint (capped).
12
+ * Eligibility is decided by the {@link isRetryable} category predicate; the set
13
+ * of retry-safe operations is decided by the module adapter (GET/HEAD reads and keyed
14
+ * sends), so keyless mutating operations are never auto-retried.
15
+ *
16
+ * The policy is read from context via {@link Service} using
17
+ * `Effect.serviceOption`, so the default applies when the service is absent and
18
+ * no operation gains a requirement. Install {@link layerDisabled} to turn
19
+ * retries off, or {@link layer} for a custom schedule/options.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { Effect } from "effect";
24
+ * import * as Retry from "samva/effect/retry";
25
+ *
26
+ * // Disable auto-retry for a program:
27
+ * program.pipe(Effect.provide(Retry.layerDisabled));
28
+ * ```
29
+ */
30
+ var retry_exports = /* @__PURE__ */ __exportAll({
31
+ Service: () => Service,
32
+ defaultPolicy: () => defaultPolicy,
33
+ disabledPolicy: () => disabledPolicy,
34
+ fromOptions: () => fromOptions,
35
+ generateIdempotencyKey: () => generateIdempotencyKey,
36
+ layer: () => layer,
37
+ layerDefault: () => layerDefault,
38
+ layerDisabled: () => layerDisabled,
39
+ withRetry: () => withRetry
40
+ });
41
+ /** Retries beyond the initial attempt — total attempts = 1 + `MAX_RETRIES`. */
42
+ const MAX_RETRIES = 3;
43
+ /** First backoff delay; each subsequent attempt multiplies by `BACKOFF_FACTOR`. */
44
+ const BASE_DELAY = Duration.millis(200);
45
+ const BACKOFF_FACTOR = 2;
46
+ /** Ceiling on how long we honor a server `retryAfterSeconds` hint. */
47
+ const MAX_SERVER_HINT = Duration.seconds(60);
48
+ /**
49
+ * Server-provided delay for a `429`: the `retryAfterSeconds` field the api emits
50
+ * on `RateLimitedError`, capped at {@link MAX_SERVER_HINT}. Returns `undefined`
51
+ * for any other error so the jittered backoff delay stands.
52
+ */
53
+ const serverHintDelay = (error) => {
54
+ if (!Predicate$1.isTagged(error, "RateLimitedError")) return void 0;
55
+ const seconds = error.retryAfterSeconds;
56
+ if (typeof seconds !== "number" || !Number.isFinite(seconds) || seconds < 0) return void 0;
57
+ return Duration.min(Duration.seconds(seconds), MAX_SERVER_HINT);
58
+ };
59
+ /** Jittered exponential backoff for the transient-failure path. */
60
+ const jitteredBackoff = Schedule.jittered(Schedule.exponential(BASE_DELAY, BACKOFF_FACTOR));
61
+ /**
62
+ * Retry a retry-safe effect under the default policy: transient/throttled
63
+ * failures ({@link isRetryable}), bounded to {@link MAX_RETRIES}, delayed by
64
+ * jittered exponential backoff — except a `429` whose `retryAfterSeconds` hint
65
+ * overrides the computed delay (exactly, un-jittered, capped). The schedule
66
+ * reads the just-failed error from its step metadata (`input`).
67
+ */
68
+ const defaultSchedule = Schedule.modifyDelay(jitteredBackoff, ({ duration, input }) => Effect.succeed(serverHintDelay(input) ?? duration));
69
+ const defaultRetry = (effect) => Effect.retry(effect, {
70
+ while: isRetryable,
71
+ times: MAX_RETRIES,
72
+ schedule: defaultSchedule
73
+ });
74
+ /**
75
+ * Context service carrying the SDK's retry policy. Absent → {@link defaultPolicy}
76
+ * (read through `Effect.serviceOption`, so no operation gains a requirement).
77
+ */
78
+ var Service = class extends Context.Service()("samva/Retry") {};
79
+ const defaultPolicy = { retry: defaultRetry };
80
+ const disabledPolicy = { retry: (effect) => effect };
81
+ const fromOptions = (options) => ({ retry: (effect) => Effect.retry(effect, options) });
82
+ const layerDefault = Layer.succeed(Service, defaultPolicy);
83
+ const layerDisabled = Layer.succeed(Service, disabledPolicy);
84
+ const layer = (options) => Layer.succeed(Service, fromOptions(options));
85
+ /**
86
+ * Apply the ambient {@link Service} policy to a retry-safe operation. Reads
87
+ * the policy optionally (default when absent) and keeps the effect's `R`.
88
+ */
89
+ const withRetry = (effect) => Effect.serviceOption(Service).pipe(Effect.flatMap((policyOption) => Option.getOrElse(policyOption, () => defaultPolicy).retry(effect)));
90
+ const HEX = "0123456789abcdef";
91
+ /**
92
+ * Generate a v4-shaped idempotency key through Effect's `Random` service —
93
+ * deterministic under a seeded/`TestClock` runtime and platform-neutral (no Web
94
+ * Crypto or bare `Math.random` at the call site). Facade sends evaluate this
95
+ * once per logical call so the key is stable across auto-retries within the call
96
+ * and distinct across calls.
97
+ */
98
+ const generateIdempotencyKey = Effect.gen(function* () {
99
+ const chars = [];
100
+ for (let index = 0; index < 32; index += 1) {
101
+ let nibble = yield* Random.nextIntBetween(0, 15);
102
+ if (index === 12) nibble = 4;
103
+ else if (index === 16) nibble = nibble & 3 | 8;
104
+ chars.push(HEX[nibble]);
105
+ }
106
+ const hex = chars.join("");
107
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
108
+ });
109
+ //#endregion
110
+ export { Service, defaultPolicy, disabledPolicy, fromOptions, generateIdempotencyKey, layer, layerDefault, layerDisabled, retry_exports as t, withRetry };
111
+
112
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1,7 @@
1
+ import { Schema } from "effect";
2
+ /** Decode wire secrets to redacted values and require redacted values when encoding. */
3
+ export declare const Sensitive: <A, E, RD, RE>(schema: Schema.Codec<A, E, RD, RE>) => Schema.RedactedFromValue<Schema.Codec<A, E, RD, RE>>;
4
+ export declare const SensitiveString: Schema.RedactedFromValue<Schema.Codec<string, string, never, never>>;
5
+ export type SensitiveString = typeof SensitiveString.Type;
6
+ export declare const AbsoluteInstant: Schema.decodeTo<Schema.Date, Schema.String, never, never>;
7
+ export type AbsoluteInstant = typeof AbsoluteInstant.Type;