samva 0.29.1 → 0.31.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.
- package/AGENTS.md +23 -5
- package/README.md +166 -133
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/client/client/client.gen.js +1 -2
- package/dist/client/client/utils.gen.js +1 -2
- package/dist/client/client.gen.js +1 -2
- package/dist/client/core/auth.gen.js +1 -2
- package/dist/client/core/bodySerializer.gen.js +1 -2
- package/dist/client/core/params.gen.js +1 -2
- package/dist/client/core/pathSerializer.gen.js +1 -2
- package/dist/client/core/serverSentEvents.gen.js +1 -2
- package/dist/client/core/utils.gen.js +1 -2
- package/dist/client/sdk.gen.d.ts +218 -192
- package/dist/client/sdk.gen.js +2397 -1154
- package/dist/client/types.gen.d.ts +767 -376
- package/dist/client-attribution.js +1 -2
- package/dist/effect/agents.d.ts +33 -11
- package/dist/effect/agents.js +1 -2
- package/dist/effect/analytics.d.ts +6 -6
- package/dist/effect/analytics.js +1 -2
- package/dist/effect/api-keys.d.ts +8 -8
- package/dist/effect/api-keys.js +1 -2
- package/dist/effect/attachments.d.ts +4 -4
- package/dist/effect/attachments.js +1 -2
- package/dist/effect/brands.d.ts +6 -6
- package/dist/effect/brands.js +1 -2
- package/dist/effect/campaigns.d.ts +15 -16
- package/dist/effect/campaigns.js +1 -2
- package/dist/effect/categories.js +1 -2
- package/dist/effect/client.js +1 -2
- package/dist/effect/contact-groups.d.ts +10 -10
- package/dist/effect/contact-groups.js +1 -2
- package/dist/effect/contacts.d.ts +23 -24
- package/dist/effect/contacts.js +1 -2
- package/dist/effect/conversations.d.ts +16 -13
- package/dist/effect/conversations.js +1 -2
- package/dist/effect/custom-fields.d.ts +4 -4
- package/dist/effect/custom-fields.js +1 -2
- package/dist/effect/email.d.ts +61 -63
- package/dist/effect/email.js +1 -2
- package/dist/effect/events.d.ts +2 -4
- package/dist/effect/events.js +1 -2
- package/dist/effect/extension-installations.d.ts +9 -9
- package/dist/effect/extension-installations.js +1 -2
- package/dist/effect/extensions.d.ts +5 -5
- package/dist/effect/extensions.js +1 -2
- package/dist/effect/feedback.d.ts +1 -1
- package/dist/effect/feedback.js +1 -2
- package/dist/effect/generated/agents.d.ts +264 -22
- package/dist/effect/generated/agents.js +2 -3
- package/dist/effect/generated/analytics.js +1 -2
- package/dist/effect/generated/api-keys.js +1 -2
- package/dist/effect/generated/attachments.js +1 -2
- package/dist/effect/generated/brands.js +1 -2
- package/dist/effect/generated/campaigns.d.ts +160 -155
- package/dist/effect/generated/campaigns.js +7 -9
- package/dist/effect/generated/contact-events.js +1 -2
- package/dist/effect/generated/contact-groups.d.ts +26 -26
- package/dist/effect/generated/contact-groups.js +22 -19
- package/dist/effect/generated/contacts.d.ts +119 -90
- package/dist/effect/generated/contacts.js +32 -32
- package/dist/effect/generated/conversations.d.ts +26 -23
- package/dist/effect/generated/conversations.js +10 -10
- package/dist/effect/generated/custom-fields.d.ts +6 -6
- package/dist/effect/generated/custom-fields.js +3 -4
- package/dist/effect/generated/email.d.ts +38 -38
- package/dist/effect/generated/email.js +13 -14
- package/dist/effect/generated/events.d.ts +18 -9
- package/dist/effect/generated/events.js +8 -6
- package/dist/effect/generated/extension-installations.d.ts +2 -2
- package/dist/effect/generated/extension-installations.js +6 -3
- package/dist/effect/generated/extensions.js +1 -2
- package/dist/effect/generated/feedback.js +1 -2
- package/dist/effect/generated/index.d.ts +7 -5
- package/dist/effect/generated/journeys.js +1 -2
- package/dist/effect/generated/mailboxes.d.ts +44 -44
- package/dist/effect/generated/mailboxes.js +17 -18
- package/dist/effect/generated/media.js +1 -2
- package/dist/effect/generated/messages.d.ts +42 -42
- package/dist/effect/generated/messages.js +3 -4
- package/dist/effect/generated/namespaces.js +1 -2
- package/dist/effect/generated/{publication-domains.d.ts → newsletter-domains.d.ts} +304 -80
- package/dist/effect/generated/newsletter-domains.js +218 -0
- package/dist/effect/generated/{topic-issues.d.ts → newsletter-issues.d.ts} +330 -288
- package/dist/effect/generated/{topic-issues.js → newsletter-issues.js} +255 -246
- package/dist/effect/generated/newsletters.d.ts +741 -0
- package/dist/effect/generated/newsletters.js +143 -0
- package/dist/effect/generated/operations.js +1 -2
- package/dist/effect/generated/organizations.d.ts +9 -9
- package/dist/effect/generated/organizations.js +4 -5
- package/dist/effect/generated/scheduled-messages.d.ts +174 -169
- package/dist/effect/generated/scheduled-messages.js +7 -7
- package/dist/effect/generated/shared.d.ts +276 -208
- package/dist/effect/generated/shared.js +50 -36
- package/dist/effect/generated/subscriptions.js +1 -2
- package/dist/effect/generated/templates.d.ts +118 -67
- package/dist/effect/generated/templates.js +43 -35
- package/dist/effect/generated/topic-forms.d.ts +79 -19
- package/dist/effect/generated/topic-forms.js +13 -14
- package/dist/effect/generated/topics.d.ts +27 -65
- package/dist/effect/generated/topics.js +13 -20
- package/dist/effect/generated/webhooks.d.ts +9 -9
- package/dist/effect/generated/webhooks.js +4 -5
- package/dist/effect/generated/whoami.js +1 -2
- package/dist/effect/generated-metadata.d.ts +475 -70
- package/dist/effect/generated-metadata.js +642 -432
- package/dist/effect/index.d.ts +3 -2
- package/dist/effect/index.js +4 -3
- package/dist/effect/internal/client.d.ts +5 -0
- package/dist/effect/internal/client.js +9 -5
- package/dist/effect/internal/email-sender.d.ts +1 -1
- package/dist/effect/internal/email-sender.js +4 -3
- package/dist/effect/internal/mailbox-events.js +1 -2
- package/dist/effect/internal/operation.d.ts +4 -15
- package/dist/effect/internal/operation.js +21 -33
- package/dist/effect/internal/send.js +2 -3
- package/dist/effect/journeys.d.ts +14 -14
- package/dist/effect/journeys.js +1 -2
- package/dist/effect/mailboxes.d.ts +60 -70
- package/dist/effect/mailboxes.js +1 -2
- package/dist/effect/media.d.ts +5 -5
- package/dist/effect/media.js +1 -2
- package/dist/effect/messages.d.ts +9 -9
- package/dist/effect/messages.js +1 -2
- package/dist/effect/namespaces.d.ts +8 -8
- package/dist/effect/namespaces.js +1 -2
- package/dist/effect/newsletter-domains.d.ts +71 -0
- package/dist/effect/newsletter-domains.js +18 -0
- package/dist/effect/{topic-issues.d.ts → newsletter-issues.d.ts} +11 -15
- package/dist/effect/newsletter-issues.js +32 -0
- package/dist/effect/newsletters.d.ts +22 -0
- package/dist/effect/newsletters.js +20 -0
- package/dist/effect/operations.d.ts +3 -3
- package/dist/effect/operations.js +1 -2
- package/dist/effect/organizations.d.ts +8 -10
- package/dist/effect/organizations.js +1 -2
- package/dist/effect/pagination.js +1 -2
- package/dist/effect/retry.d.ts +4 -4
- package/dist/effect/retry.js +5 -6
- package/dist/effect/runtime.js +1 -2
- package/dist/effect/scheduled-messages.d.ts +5 -6
- package/dist/effect/scheduled-messages.js +1 -2
- package/dist/effect/subscriptions.d.ts +1 -1
- package/dist/effect/subscriptions.js +1 -2
- package/dist/effect/templates.d.ts +34 -43
- package/dist/effect/templates.js +1 -2
- package/dist/effect/topic-forms.d.ts +5 -5
- package/dist/effect/topic-forms.js +1 -2
- package/dist/effect/topics.d.ts +9 -13
- package/dist/effect/topics.js +1 -2
- package/dist/effect/webhooks.d.ts +11 -11
- package/dist/effect/webhooks.js +1 -2
- package/dist/effect/whoami.d.ts +1 -1
- package/dist/effect/whoami.js +1 -2
- package/dist/index.js +2 -2
- package/dist/inline-attachments.js +1 -2
- package/dist/mailbox/dispatch.d.ts +10 -0
- package/dist/mailbox/dispatch.js +66 -0
- package/dist/mailbox/index.d.ts +17 -0
- package/dist/mailbox/index.js +30 -0
- package/dist/mailbox/test.d.ts +25 -0
- package/dist/mailbox/test.js +174 -0
- package/dist/mailbox/types.d.ts +184 -0
- package/dist/mailbox/webhook.d.ts +10 -0
- package/dist/mailbox/webhook.js +41 -0
- package/dist/mailbox-events.js +1 -2
- package/dist/normalize.js +1 -2
- package/dist/package.js +2 -3
- package/dist/promises/client.d.ts +215 -0
- package/dist/promises/client.js +324 -0
- package/dist/promises/errors.gen.js +1 -2
- package/dist/promises/index.d.ts +2 -196
- package/dist/promises/index.js +3 -295
- package/dist/promises/request.d.ts +15 -0
- package/dist/promises/request.js +75 -0
- package/dist/promises/types.gen.d.ts +1 -1
- package/dist/request-policy.d.ts +3 -0
- package/dist/request-policy.js +16 -0
- package/dist/service-map.d.ts +78 -47
- package/dist/service-map.js +52 -32
- package/package.json +34 -18
- package/dist/effect/generated/publication-domains.js +0 -163
- package/dist/effect/publication-domains.d.ts +0 -14
- package/dist/effect/publication-domains.js +0 -17
- package/dist/effect/topic-issues.js +0 -33
package/dist/effect/index.d.ts
CHANGED
|
@@ -39,17 +39,18 @@ export * as Messages from "./messages";
|
|
|
39
39
|
export * as Namespaces from "./namespaces";
|
|
40
40
|
export * as Operations from "./operations";
|
|
41
41
|
export * as Organizations from "./organizations";
|
|
42
|
-
export * as
|
|
42
|
+
export * as NewsletterDomains from "./newsletter-domains";
|
|
43
43
|
export * as Retry from "./retry";
|
|
44
44
|
export * as ScheduledMessages from "./scheduled-messages";
|
|
45
45
|
export * as Subscriptions from "./subscriptions";
|
|
46
46
|
export * as Templates from "./templates";
|
|
47
47
|
export * as Topics from "./topics";
|
|
48
48
|
export * as TopicForms from "./topic-forms";
|
|
49
|
-
export * as
|
|
49
|
+
export * as NewsletterIssues from "./newsletter-issues";
|
|
50
50
|
export * as Webhooks from "./webhooks";
|
|
51
51
|
export * as Whoami from "./whoami";
|
|
52
52
|
export * from "./errors";
|
|
53
53
|
export { type ErrorCategory, categoriesOf, hasCategory, isAuthError, isValidationError, isNotFoundError, isConflictError, isThrottlingError, isBillingError, isTransient, isRetryable, catchCategory, catchAuthError, catchValidationError, catchNotFoundError, catchConflictError, catchThrottlingError, catchBillingError, catchTransient, } from "./categories";
|
|
54
54
|
export type { CursorPageEnvelope } from "./pagination";
|
|
55
55
|
export type { Json as JsonValue } from "effect/Schema";
|
|
56
|
+
export * as Newsletters from "./newsletters";
|
package/dist/effect/index.js
CHANGED
|
@@ -25,13 +25,14 @@ import { messages_exports } from "./messages.js";
|
|
|
25
25
|
import { namespaces_exports } from "./namespaces.js";
|
|
26
26
|
import { operations_exports } from "./operations.js";
|
|
27
27
|
import { organizations_exports } from "./organizations.js";
|
|
28
|
-
import {
|
|
28
|
+
import { newsletter_domains_exports } from "./newsletter-domains.js";
|
|
29
29
|
import { scheduled_messages_exports } from "./scheduled-messages.js";
|
|
30
30
|
import { subscriptions_exports } from "./subscriptions.js";
|
|
31
31
|
import { templates_exports } from "./templates.js";
|
|
32
32
|
import { topics_exports } from "./topics.js";
|
|
33
33
|
import { topic_forms_exports } from "./topic-forms.js";
|
|
34
|
-
import {
|
|
34
|
+
import { newsletter_issues_exports } from "./newsletter-issues.js";
|
|
35
35
|
import { webhooks_exports } from "./webhooks.js";
|
|
36
36
|
import { whoami_exports } from "./whoami.js";
|
|
37
|
-
|
|
37
|
+
import { newsletters_exports } from "./newsletters.js";
|
|
38
|
+
export { agents_exports as Agents, analytics_exports as Analytics, AnalyticsQueryError, api_keys_exports as ApiKeys, attachments_exports as Attachments, BillingProviderError, BrandAddressRequiredError, brands_exports as Brands, CampaignFooterRequiredError, campaigns_exports as Campaigns, client_exports as Client, ConflictError, contact_groups_exports as ContactGroups, contacts_exports as Contacts, conversations_exports as Conversations, custom_fields_exports as CustomFields, DeliveryUnavailableError, email_exports as Email, EmailChannelError, events_exports as Events, extension_installations_exports as ExtensionInstallations, extensions_exports as Extensions, ExternalServiceError, feedback_exports as Feedback, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, journeys_exports as Journeys, MailboxSendConflictError, MailboxSendRefusedError, mailboxes_exports as Mailboxes, media_exports as Media, MediaUploadError, messages_exports as Messages, namespaces_exports as Namespaces, newsletter_domains_exports as NewsletterDomains, newsletter_issues_exports as NewsletterIssues, newsletters_exports as Newsletters, OnboardingReviewRequiredError, operations_exports as Operations, organizations_exports as Organizations, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, retry_exports as Retry, scheduled_messages_exports as ScheduledMessages, SenderNotReadyError, subscriptions_exports as Subscriptions, TemplateSourceError, templates_exports as Templates, topic_forms_exports as TopicForms, topics_exports as Topics, UnauthorizedError, ValidationError, webhooks_exports as Webhooks, whoami_exports as Whoami, catchAuthError, catchBillingError, catchCategory, catchConflictError, catchNotFoundError, catchThrottlingError, catchTransient, catchValidationError, categoriesOf, hasCategory, isAuthError, isBillingError, isConflictError, isNotFoundError, isRetryable, isThrottlingError, isTransient, isValidationError };
|
|
@@ -6,13 +6,17 @@ import type { MailboxEventStreamConnection } from "../../mailbox-events";
|
|
|
6
6
|
import type { SamvaApi } from "../generated/index";
|
|
7
7
|
export interface ConfigBase {
|
|
8
8
|
readonly baseUrl?: string;
|
|
9
|
+
/** Generate the key once for each idempotent logical call. */
|
|
10
|
+
readonly idempotency?: ((operation: string) => string | undefined) | undefined;
|
|
9
11
|
readonly headers?: Readonly<Record<string, string | undefined>>;
|
|
10
12
|
}
|
|
11
13
|
export type Config = (ConfigBase & {
|
|
12
14
|
readonly apiKey: string | Redacted.Redacted<string>;
|
|
13
15
|
readonly authToken?: never;
|
|
16
|
+
readonly orgSlug?: never;
|
|
14
17
|
}) | (ConfigBase & {
|
|
15
18
|
readonly authToken: string;
|
|
19
|
+
readonly orgSlug?: string;
|
|
16
20
|
readonly apiKey?: never;
|
|
17
21
|
});
|
|
18
22
|
type Api = HttpApiClient.ForApi<typeof SamvaApi>;
|
|
@@ -30,6 +34,7 @@ export type OperationSuccess<Name extends Operation> = HttpApiClient.SuccessType
|
|
|
30
34
|
}>>>;
|
|
31
35
|
export type RawCall = (request?: unknown) => Effect.Effect<unknown, unknown>;
|
|
32
36
|
export interface Interface {
|
|
37
|
+
readonly idempotency?: ((operation: string) => string | undefined) | undefined;
|
|
33
38
|
/**
|
|
34
39
|
* The generated call for one endpoint. A group's client is built on the first call to any of its
|
|
35
40
|
* endpoints and reused, so a group the program never calls costs nothing.
|
|
@@ -6,18 +6,22 @@ import { Context, Effect, Layer, Redacted } from "effect";
|
|
|
6
6
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
7
7
|
import * as HttpClient from "effect/http/HttpClient";
|
|
8
8
|
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
9
|
-
|
|
9
|
+
// src/effect/internal/client.ts
|
|
10
10
|
const DEFAULT_BASE_URL = "https://api.samva.dev";
|
|
11
11
|
var Service = class extends Context.Service()("samva/Client") {};
|
|
12
|
-
const authHeaders = (config) => config.authToken !== void 0 ? {
|
|
12
|
+
const authHeaders = (config) => config.authToken !== void 0 ? {
|
|
13
|
+
Authorization: `Bearer ${config.authToken}`,
|
|
14
|
+
...config.orgSlug === void 0 ? {} : { "x-org-slug": config.orgSlug }
|
|
15
|
+
} : { "x-api-key": Redacted.isRedacted(config.apiKey) ? Redacted.value(config.apiKey) : config.apiKey };
|
|
13
16
|
const AuthorizationClient = HttpApiMiddleware.layerClient(ApiKeySecurityMiddleware, ({ next, request }) => next(request));
|
|
14
17
|
const make = (config) => Effect.gen(function* () {
|
|
15
18
|
const baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
16
19
|
const removesAttribution = Object.entries(config.headers ?? {}).some(([name, value]) => name.toLowerCase() === "x-samva-client" && value === void 0);
|
|
20
|
+
const requestHeaders = Object.fromEntries(Object.entries(config.headers ?? {}).filter(([name]) => name.toLowerCase() !== "idempotency-key"));
|
|
17
21
|
const storage = yield* HttpClient.HttpClient;
|
|
18
22
|
const httpClient = storage.pipe(HttpClient.mapRequest((request) => {
|
|
19
23
|
let attributed = HttpClientRequest.setHeader(request, CLIENT_ATTRIBUTION_HEADER, clientAttribution("typescript-effect"));
|
|
20
|
-
|
|
24
|
+
attributed = HttpClientRequest.setHeaders(attributed, requestHeaders);
|
|
21
25
|
if (removesAttribution) attributed = HttpClientRequest.removeHeader(attributed, CLIENT_ATTRIBUTION_HEADER);
|
|
22
26
|
return HttpClientRequest.setHeaders(attributed, authHeaders(config));
|
|
23
27
|
}));
|
|
@@ -36,7 +40,7 @@ const make = (config) => Effect.gen(function* () {
|
|
|
36
40
|
}));
|
|
37
41
|
};
|
|
38
42
|
const headers = removesAttribution ? {} : { [CLIENT_ATTRIBUTION_HEADER]: clientAttribution("typescript-effect") };
|
|
39
|
-
for (const [name, value] of Object.entries(
|
|
43
|
+
for (const [name, value] of Object.entries(requestHeaders)) if (value !== void 0) headers[name] = value;
|
|
40
44
|
const putUpload = (input) => storage.execute(HttpClientRequest.make(input.method)(input.url).pipe(HttpClientRequest.bodyUint8Array(input.bytes, uploadContentType(input.headers)), HttpClientRequest.setHeaders(input.headers))).pipe(Effect.mapError((cause) => new MediaUploadError({
|
|
41
45
|
filename: input.filename,
|
|
42
46
|
mediaId: input.mediaId,
|
|
@@ -47,6 +51,7 @@ const make = (config) => Effect.gen(function* () {
|
|
|
47
51
|
status: response.status
|
|
48
52
|
}))));
|
|
49
53
|
return Service.of({
|
|
54
|
+
idempotency: config.idempotency,
|
|
50
55
|
putUpload,
|
|
51
56
|
endpoint: (group, name) => Effect.flatMap(groupClient(group), (client) => {
|
|
52
57
|
const call = client[name];
|
|
@@ -63,7 +68,6 @@ const make = (config) => Effect.gen(function* () {
|
|
|
63
68
|
});
|
|
64
69
|
const layer = (config) => Layer.effect(Service, make(config));
|
|
65
70
|
const layerFetch = (config) => layer(config).pipe(Layer.provide(FetchHttpClient.layer));
|
|
66
|
-
//#endregion
|
|
67
71
|
export { Service, layer, layerFetch };
|
|
68
72
|
|
|
69
73
|
//# sourceMappingURL=client.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import type
|
|
2
|
+
import { type FlatRaw, Service } from "./client";
|
|
3
3
|
import { type RequestArg } from "./operation";
|
|
4
4
|
import type { ErgonomicEmailList, SendOptions } from "./send";
|
|
5
5
|
type AddSenderRequest = NonNullable<RequestArg<FlatRaw["emailAddSender"]>>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { replyToEmailsPayload } from "../../normalize.js";
|
|
2
2
|
import { generateIdempotencyKey, withRetry } from "../retry.js";
|
|
3
|
+
import { Service } from "./client.js";
|
|
3
4
|
import { callEndpoint, stripUndefined } from "./operation.js";
|
|
4
5
|
import { EmailGroup } from "../generated/email.js";
|
|
5
6
|
import { Effect } from "effect";
|
|
6
|
-
|
|
7
|
+
// src/effect/internal/email-sender.ts
|
|
7
8
|
const addEmailSender = Effect.fn("Email.addSender")(function* (input, options) {
|
|
8
|
-
const
|
|
9
|
+
const client = yield* Service;
|
|
10
|
+
const idempotencyKey = options?.idempotencyKey ?? client.idempotency?.("emailAddSender") ?? (yield* generateIdempotencyKey);
|
|
9
11
|
const { replyToEmails, ...sender } = input;
|
|
10
12
|
return yield* withRetry(callEndpoint(EmailGroup, "emailAddSender", {
|
|
11
13
|
headers: { "idempotency-key": idempotencyKey },
|
|
@@ -15,7 +17,6 @@ const addEmailSender = Effect.fn("Email.addSender")(function* (input, options) {
|
|
|
15
17
|
})
|
|
16
18
|
}));
|
|
17
19
|
});
|
|
18
|
-
//#endregion
|
|
19
20
|
export { addEmailSender };
|
|
20
21
|
|
|
21
22
|
//# sourceMappingURL=email-sender.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MailboxEventStream, MailboxEventStreamError } from "../../mailbox-events.js";
|
|
2
2
|
import { Service } from "./client.js";
|
|
3
3
|
import { Cause, Effect, Exit, Stream } from "effect";
|
|
4
|
-
|
|
4
|
+
// src/effect/internal/mailbox-events.ts
|
|
5
5
|
const toStreamError = (cause) => cause instanceof MailboxEventStreamError ? cause : new MailboxEventStreamError({
|
|
6
6
|
_tag: "StreamDisconnectedError",
|
|
7
7
|
message: String(cause)
|
|
@@ -27,7 +27,6 @@ const events = (options = {}) => Stream.scoped(Stream.unwrap(Effect.gen(function
|
|
|
27
27
|
catch: toStreamError
|
|
28
28
|
}).pipe(Effect.flatMap((next) => next.done ? Cause.done() : Effect.succeed(next.value))));
|
|
29
29
|
})));
|
|
30
|
-
//#endregion
|
|
31
30
|
export { events };
|
|
32
31
|
|
|
33
32
|
//# sourceMappingURL=mailbox-events.js.map
|
|
@@ -16,24 +16,13 @@ type FlattenRequest<Request> = (Request extends {
|
|
|
16
16
|
} ? Payload : unknown);
|
|
17
17
|
export type RequestArg<Method> = Method extends (request: infer Request, ...rest: ReadonlyArray<unknown>) => unknown ? Request : never;
|
|
18
18
|
type Input<Name extends SdkOperation> = Wire<FlattenRequest<NonNullable<RequestArg<FlatRaw[Name]>>>>;
|
|
19
|
-
|
|
20
|
-
readonly
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
} ? {
|
|
24
|
-
readonly idempotencyKey: Wire<Key>;
|
|
25
|
-
} : unknown;
|
|
19
|
+
export interface OperationOptions {
|
|
20
|
+
readonly idempotencyKey?: string | undefined;
|
|
21
|
+
}
|
|
26
22
|
export type OperationResult<Name extends SdkOperation> = Effect.Effect<OperationSuccess<Name>, Effect.Error<MethodReturn<FlatRaw[Name]>>, Service>;
|
|
27
|
-
type DirectOperation<Name extends SdkOperation> = {} extends Input<Name> ? (input?: Input<Name>) => OperationResult<Name> : (input: Input<Name>) => OperationResult<Name>;
|
|
28
23
|
type OperationFunction<Name extends SdkOperation> = (typeof SDK_OPERATION_CALLS)[Name] extends {
|
|
29
24
|
readonly kind: "none";
|
|
30
|
-
} ? (
|
|
31
|
-
readonly kind: "idempotentPayload" | "idempotentPath";
|
|
32
|
-
} ? (input: Input<Name> & IdempotencyKeyField<NonNullable<RequestArg<FlatRaw[Name]>>>) => OperationResult<Name> : (typeof SDK_OPERATION_CALLS)[Name] extends {
|
|
33
|
-
readonly kind: "optionalIdempotentPath" | "optionalIdempotentPathPayload";
|
|
34
|
-
} ? (input: Input<Name> & {
|
|
35
|
-
readonly idempotencyKey?: string | undefined;
|
|
36
|
-
}) => OperationResult<Name> : DirectOperation<Name>;
|
|
25
|
+
} ? (input?: never, options?: OperationOptions) => OperationResult<Name> : {} extends Input<Name> ? (input?: Input<Name>, options?: OperationOptions) => OperationResult<Name> : (input: Input<Name>, options?: OperationOptions) => OperationResult<Name>;
|
|
37
26
|
type EnvelopeItem<A> = A extends {
|
|
38
27
|
readonly items: ReadonlyArray<infer Item>;
|
|
39
28
|
} ? Item : never;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { SDK_OPERATION_CALLS } from "../../service-map.js";
|
|
2
1
|
import { SamvaOperations } from "../generated-metadata.js";
|
|
2
|
+
import { isRetrySafe } from "../../request-policy.js";
|
|
3
|
+
import { SDK_OPERATION_CALLS } from "../../service-map.js";
|
|
3
4
|
import { streamCursorItems, streamCursorPages } from "../pagination.js";
|
|
4
|
-
import { withRetry } from "../retry.js";
|
|
5
|
+
import { generateIdempotencyKey, withRetry } from "../retry.js";
|
|
5
6
|
import { Service } from "./client.js";
|
|
6
7
|
import { Effect, Predicate } from "effect";
|
|
7
|
-
|
|
8
|
-
const READ_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
|
|
8
|
+
// src/effect/internal/operation.ts
|
|
9
9
|
const MODULE_NAMES = {
|
|
10
10
|
agents: "Agents",
|
|
11
11
|
analytics: "Analytics",
|
|
@@ -46,19 +46,18 @@ const stripUndefined = (input) => {
|
|
|
46
46
|
if (Object.getPrototypeOf(input) !== Object.prototype) return input;
|
|
47
47
|
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0).map(([key, value]) => [key, stripUndefined(value)]));
|
|
48
48
|
};
|
|
49
|
-
const adapt = (operationName, rawCall, input) => {
|
|
49
|
+
const adapt = (operationName, rawCall, input, idempotencyKey) => {
|
|
50
50
|
const descriptor = SDK_OPERATION_CALLS[operationName];
|
|
51
|
-
const call =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (descriptor.kind === "idempotentPayload") {
|
|
56
|
-
const { idempotencyKey, ...payload } = input;
|
|
57
|
-
return call({
|
|
58
|
-
headers: { "idempotency-key": idempotencyKey },
|
|
59
|
-
payload: stripUndefined(payload)
|
|
51
|
+
const call = (request = {}) => {
|
|
52
|
+
const operation = rawCall({
|
|
53
|
+
...request,
|
|
54
|
+
...idempotencyKey === void 0 ? {} : { headers: { "idempotency-key": idempotencyKey } }
|
|
60
55
|
});
|
|
61
|
-
|
|
56
|
+
return isRetrySafe(operationName, input) ? withRetry(operation) : operation;
|
|
57
|
+
};
|
|
58
|
+
if (descriptor.kind === "none") return call();
|
|
59
|
+
if (descriptor.kind === "params") return call({ query: stripUndefined(input ?? {}) });
|
|
60
|
+
if (descriptor.kind === "payload") return call({ payload: stripUndefined(input ?? {}) });
|
|
62
61
|
const pathDescriptor = descriptor;
|
|
63
62
|
const inputRecord = input ?? {};
|
|
64
63
|
const params = {};
|
|
@@ -67,22 +66,7 @@ const adapt = (operationName, rawCall, input) => {
|
|
|
67
66
|
params[path] = inputRecord[path];
|
|
68
67
|
}
|
|
69
68
|
if (pathDescriptor.kind === "path") return call({ params });
|
|
70
|
-
|
|
71
|
-
params,
|
|
72
|
-
headers: { "idempotency-key": inputRecord.idempotencyKey }
|
|
73
|
-
});
|
|
74
|
-
const optionalKeyHeaders = { headers: inputRecord.idempotencyKey === void 0 ? {} : { "idempotency-key": inputRecord.idempotencyKey } };
|
|
75
|
-
if (pathDescriptor.kind === "optionalIdempotentPath") return call({
|
|
76
|
-
params,
|
|
77
|
-
...optionalKeyHeaders
|
|
78
|
-
});
|
|
79
|
-
const headerKey = pathDescriptor.kind === "optionalIdempotentPathPayload";
|
|
80
|
-
const remainingInput = stripUndefined(Object.fromEntries(Object.entries(inputRecord).filter(([key]) => !pathDescriptor.paths.includes(key) && !(headerKey && key === "idempotencyKey"))));
|
|
81
|
-
if (pathDescriptor.kind === "optionalIdempotentPathPayload") return call({
|
|
82
|
-
params,
|
|
83
|
-
payload: remainingInput,
|
|
84
|
-
...optionalKeyHeaders
|
|
85
|
-
});
|
|
69
|
+
const remainingInput = stripUndefined(Object.fromEntries(Object.entries(inputRecord).filter(([key]) => !pathDescriptor.paths.includes(key))));
|
|
86
70
|
return call({
|
|
87
71
|
params,
|
|
88
72
|
[pathDescriptor.kind === "pathParams" ? "query" : "payload"]: remainingInput
|
|
@@ -100,7 +84,12 @@ const forGroup = (group) => (operationName) => {
|
|
|
100
84
|
/** Call one endpoint with an already-shaped request, outside the direct-operation adapter. */
|
|
101
85
|
const callEndpoint = (group, name, request) => Effect.flatMap(Service, (client) => Effect.flatMap(client.endpoint(group, name), (call) => call(request)));
|
|
102
86
|
const make = (group, operationName) => {
|
|
103
|
-
const call = Effect.fn(traceName(operationName))((input
|
|
87
|
+
const call = Effect.fn(traceName(operationName))(function* (input, options) {
|
|
88
|
+
const client = yield* Service;
|
|
89
|
+
const rawCall = yield* client.endpoint(group, operationName);
|
|
90
|
+
const idempotencyKey = SamvaOperations[operationName].idempotent ? options?.idempotencyKey ?? client.idempotency?.(operationName) ?? (yield* generateIdempotencyKey) : void 0;
|
|
91
|
+
return yield* adapt(operationName, rawCall, input, idempotencyKey);
|
|
92
|
+
});
|
|
104
93
|
const operation = call;
|
|
105
94
|
if (SamvaOperations[operationName].paginated) {
|
|
106
95
|
const list = (input) => Effect.filterOrElse(call(input), isCursorPageEnvelope, () => Effect.die(/* @__PURE__ */ new Error(`${operationName} did not return a cursor page envelope`)));
|
|
@@ -111,7 +100,6 @@ const make = (group, operationName) => {
|
|
|
111
100
|
}
|
|
112
101
|
return operation;
|
|
113
102
|
};
|
|
114
|
-
//#endregion
|
|
115
103
|
export { callEndpoint, forGroup, stripUndefined };
|
|
116
104
|
|
|
117
105
|
//# sourceMappingURL=operation.js.map
|
|
@@ -6,7 +6,7 @@ import { callEndpoint, stripUndefined } from "./operation.js";
|
|
|
6
6
|
import { MediaGroup } from "../generated/media.js";
|
|
7
7
|
import { MessagesGroup } from "../generated/messages.js";
|
|
8
8
|
import { Effect } from "effect";
|
|
9
|
-
|
|
9
|
+
// src/effect/internal/send.ts
|
|
10
10
|
/**
|
|
11
11
|
* Inline attachment content over the API's request cap travels as media instead: the largest
|
|
12
12
|
* attachments are uploaded (create, put to the presigned URL, complete) and replaced by their
|
|
@@ -37,7 +37,7 @@ const uploadOversizedAttachments = (client, payload) => Effect.gen(function* ()
|
|
|
37
37
|
});
|
|
38
38
|
const sendPayload = (payload, options) => Effect.gen(function* () {
|
|
39
39
|
const client = yield* Service;
|
|
40
|
-
const idempotencyKey = options?.idempotencyKey ?? (yield* generateIdempotencyKey);
|
|
40
|
+
const idempotencyKey = options?.idempotencyKey ?? client.idempotency?.("messagesSend") ?? (yield* generateIdempotencyKey);
|
|
41
41
|
const prepared = yield* uploadOversizedAttachments(client, payload);
|
|
42
42
|
return yield* withRetry(callEndpoint(MessagesGroup, "messagesSend", {
|
|
43
43
|
payload: stripUndefined(prepared),
|
|
@@ -50,7 +50,6 @@ const sendMessage = Effect.fn("Messages.send")(function* (input, options) {
|
|
|
50
50
|
const sendEmail = Effect.fn("Email.send")(function* (input, options) {
|
|
51
51
|
return yield* sendPayload(buildEmailSendPayload(input), options);
|
|
52
52
|
});
|
|
53
|
-
//#endregion
|
|
54
53
|
export { sendEmail, sendMessage };
|
|
55
54
|
|
|
56
55
|
//# sourceMappingURL=send.js.map
|
|
@@ -2,7 +2,7 @@ export declare const list: ((input?: {
|
|
|
2
2
|
readonly status?: "active" | "archived" | "draft" | "paused" | null | undefined;
|
|
3
3
|
readonly limit?: number | null | undefined;
|
|
4
4
|
readonly cursor?: string | null | undefined;
|
|
5
|
-
} | undefined) => import("./internal/operation").OperationResult<"journeysList">) & {
|
|
5
|
+
} | undefined, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysList">) & {
|
|
6
6
|
readonly pages: (input?: {
|
|
7
7
|
readonly status?: "active" | "archived" | "draft" | "paused" | null | undefined;
|
|
8
8
|
readonly limit?: number | null | undefined;
|
|
@@ -210,17 +210,17 @@ export declare const create: (input: {
|
|
|
210
210
|
} | undefined;
|
|
211
211
|
readonly reentry?: boolean | undefined;
|
|
212
212
|
};
|
|
213
|
-
}) => import("./internal/operation").OperationResult<"journeysCreate">;
|
|
213
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysCreate">;
|
|
214
214
|
export declare const get: (input: {
|
|
215
215
|
readonly id: string;
|
|
216
|
-
}) => import("./internal/operation").OperationResult<"journeysGet">;
|
|
216
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysGet">;
|
|
217
217
|
export declare const update: (input: {
|
|
218
218
|
readonly id: string;
|
|
219
219
|
readonly name: string;
|
|
220
|
-
}) => import("./internal/operation").OperationResult<"journeysUpdate">;
|
|
220
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysUpdate">;
|
|
221
221
|
export declare const remove: (input: {
|
|
222
222
|
readonly id: string;
|
|
223
|
-
}) => import("./internal/operation").OperationResult<"journeysRemove">;
|
|
223
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysRemove">;
|
|
224
224
|
export declare const replaceDraft: (input: {
|
|
225
225
|
readonly id: string;
|
|
226
226
|
readonly revision: string;
|
|
@@ -399,35 +399,35 @@ export declare const replaceDraft: (input: {
|
|
|
399
399
|
} | undefined;
|
|
400
400
|
readonly reentry?: boolean | undefined;
|
|
401
401
|
};
|
|
402
|
-
}) => import("./internal/operation").OperationResult<"journeysReplaceDraft">;
|
|
402
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysReplaceDraft">;
|
|
403
403
|
export declare const publish: (input: {
|
|
404
404
|
readonly id: string;
|
|
405
405
|
readonly revision: string;
|
|
406
|
-
}) => import("./internal/operation").OperationResult<"journeysPublish">;
|
|
406
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysPublish">;
|
|
407
407
|
export declare const pause: (input: {
|
|
408
408
|
readonly id: string;
|
|
409
|
-
}) => import("./internal/operation").OperationResult<"journeysPause">;
|
|
409
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysPause">;
|
|
410
410
|
export declare const resume: (input: {
|
|
411
411
|
readonly id: string;
|
|
412
|
-
}) => import("./internal/operation").OperationResult<"journeysResume">;
|
|
412
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysResume">;
|
|
413
413
|
export declare const archive: (input: {
|
|
414
414
|
readonly id: string;
|
|
415
|
-
}) => import("./internal/operation").OperationResult<"journeysArchive">;
|
|
415
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysArchive">;
|
|
416
416
|
export declare const getVersion: (input: {
|
|
417
417
|
readonly id: string;
|
|
418
418
|
readonly version: string;
|
|
419
|
-
}) => import("./internal/operation").OperationResult<"journeysGetVersion">;
|
|
419
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysGetVersion">;
|
|
420
420
|
export declare const stats: (input: {
|
|
421
421
|
readonly id: string;
|
|
422
422
|
readonly version?: number | null | undefined;
|
|
423
|
-
}) => import("./internal/operation").OperationResult<"journeysStats">;
|
|
423
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysStats">;
|
|
424
424
|
export declare const listRuns: ((input: {
|
|
425
425
|
readonly id: string;
|
|
426
426
|
readonly status?: "active" | "exited" | "failed" | "paused" | null | undefined;
|
|
427
427
|
readonly contactId?: string | null | undefined;
|
|
428
428
|
readonly limit?: number | null | undefined;
|
|
429
429
|
readonly cursor?: string | null | undefined;
|
|
430
|
-
}) => import("./internal/operation").OperationResult<"journeysListRuns">) & {
|
|
430
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysListRuns">) & {
|
|
431
431
|
readonly pages: (input: {
|
|
432
432
|
readonly id: string;
|
|
433
433
|
readonly status?: "active" | "exited" | "failed" | "paused" | null | undefined;
|
|
@@ -489,4 +489,4 @@ export declare const listRuns: ((input: {
|
|
|
489
489
|
export declare const getRun: (input: {
|
|
490
490
|
readonly id: string;
|
|
491
491
|
readonly runId: string;
|
|
492
|
-
}) => import("./internal/operation").OperationResult<"journeysGetRun">;
|
|
492
|
+
}, options?: import("./internal/operation").OperationOptions) => import("./internal/operation").OperationResult<"journeysGetRun">;
|
package/dist/effect/journeys.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { forGroup } from "./internal/operation.js";
|
|
3
3
|
import { JourneysGroup } from "./generated/journeys.js";
|
|
4
|
-
|
|
4
|
+
// src/effect/journeys.ts
|
|
5
5
|
var journeys_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
archive: () => archive,
|
|
7
7
|
create: () => create,
|
|
@@ -33,7 +33,6 @@ const getVersion = /* @__PURE__ */ make("journeysGetVersion");
|
|
|
33
33
|
const stats = /* @__PURE__ */ make("journeysStats");
|
|
34
34
|
const listRuns = /* @__PURE__ */ make("journeysListRuns");
|
|
35
35
|
const getRun = /* @__PURE__ */ make("journeysGetRun");
|
|
36
|
-
//#endregion
|
|
37
36
|
export { archive, create, get, getRun, getVersion, journeys_exports, list, listRuns, pause, publish, remove, replaceDraft, resume, stats, update };
|
|
38
37
|
|
|
39
38
|
//# sourceMappingURL=journeys.js.map
|