@distilled.cloud/slack 0.0.0 → 1.0.0-rc.11
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/LICENSE +201 -0
- package/lib/credentials.d.ts +27 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +53 -0
- package/lib/credentials.js.map +1 -0
- package/lib/errors.d.ts +83 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +59 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/pagination.d.ts +31 -0
- package/lib/pagination.d.ts.map +1 -0
- package/lib/pagination.js +31 -0
- package/lib/pagination.js.map +1 -0
- package/lib/protocol.d.ts +18 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +230 -0
- package/lib/protocol.js.map +1 -0
- package/lib/retry.d.ts +52 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +45 -0
- package/lib/retry.js.map +1 -0
- package/lib/services/admin.d.ts +2796 -0
- package/lib/services/admin.d.ts.map +1 -0
- package/lib/services/admin.js +3217 -0
- package/lib/services/admin.js.map +1 -0
- package/lib/services/api.d.ts +23 -0
- package/lib/services/api.d.ts.map +1 -0
- package/lib/services/api.js +26 -0
- package/lib/services/api.js.map +1 -0
- package/lib/services/apps.d.ts +568 -0
- package/lib/services/apps.d.ts.map +1 -0
- package/lib/services/apps.js +584 -0
- package/lib/services/apps.js.map +1 -0
- package/lib/services/assistant.d.ts +290 -0
- package/lib/services/assistant.d.ts.map +1 -0
- package/lib/services/assistant.js +232 -0
- package/lib/services/assistant.js.map +1 -0
- package/lib/services/auth.d.ts +90 -0
- package/lib/services/auth.d.ts.map +1 -0
- package/lib/services/auth.js +114 -0
- package/lib/services/auth.js.map +1 -0
- package/lib/services/blocks.d.ts +31 -0
- package/lib/services/blocks.d.ts.map +1 -0
- package/lib/services/blocks.js +31 -0
- package/lib/services/blocks.js.map +1 -0
- package/lib/services/bookmarks.d.ts +91 -0
- package/lib/services/bookmarks.d.ts.map +1 -0
- package/lib/services/bookmarks.js +98 -0
- package/lib/services/bookmarks.js.map +1 -0
- package/lib/services/bots.d.ts +60 -0
- package/lib/services/bots.d.ts.map +1 -0
- package/lib/services/bots.js +68 -0
- package/lib/services/bots.js.map +1 -0
- package/lib/services/calls.d.ts +124 -0
- package/lib/services/calls.d.ts.map +1 -0
- package/lib/services/calls.js +136 -0
- package/lib/services/calls.js.map +1 -0
- package/lib/services/canvases.d.ts +152 -0
- package/lib/services/canvases.d.ts.map +1 -0
- package/lib/services/canvases.js +152 -0
- package/lib/services/canvases.js.map +1 -0
- package/lib/services/chat.d.ts +525 -0
- package/lib/services/chat.d.ts.map +1 -0
- package/lib/services/chat.js +436 -0
- package/lib/services/chat.js.map +1 -0
- package/lib/services/conversations.d.ts +642 -0
- package/lib/services/conversations.d.ts.map +1 -0
- package/lib/services/conversations.js +769 -0
- package/lib/services/conversations.js.map +1 -0
- package/lib/services/dialog.d.ts +20 -0
- package/lib/services/dialog.d.ts.map +1 -0
- package/lib/services/dialog.js +27 -0
- package/lib/services/dialog.js.map +1 -0
- package/lib/services/dnd.d.ts +94 -0
- package/lib/services/dnd.d.ts.map +1 -0
- package/lib/services/dnd.js +111 -0
- package/lib/services/dnd.js.map +1 -0
- package/lib/services/emoji.d.ts +35 -0
- package/lib/services/emoji.d.ts.map +1 -0
- package/lib/services/emoji.js +40 -0
- package/lib/services/emoji.js.map +1 -0
- package/lib/services/entity.d.ts +93 -0
- package/lib/services/entity.d.ts.map +1 -0
- package/lib/services/entity.js +89 -0
- package/lib/services/entity.js.map +1 -0
- package/lib/services/files.d.ts +473 -0
- package/lib/services/files.d.ts.map +1 -0
- package/lib/services/files.js +510 -0
- package/lib/services/files.js.map +1 -0
- package/lib/services/functions.d.ts +235 -0
- package/lib/services/functions.d.ts.map +1 -0
- package/lib/services/functions.js +256 -0
- package/lib/services/functions.js.map +1 -0
- package/lib/services/index.d.ts +35 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +36 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/lists.d.ts +300 -0
- package/lib/services/lists.d.ts.map +1 -0
- package/lib/services/lists.js +366 -0
- package/lib/services/lists.js.map +1 -0
- package/lib/services/migration.d.ts +34 -0
- package/lib/services/migration.d.ts.map +1 -0
- package/lib/services/migration.js +36 -0
- package/lib/services/migration.js.map +1 -0
- package/lib/services/oauth.d.ts +307 -0
- package/lib/services/oauth.d.ts.map +1 -0
- package/lib/services/oauth.js +278 -0
- package/lib/services/oauth.js.map +1 -0
- package/lib/services/openid.d.ts +86 -0
- package/lib/services/openid.d.ts.map +1 -0
- package/lib/services/openid.js +93 -0
- package/lib/services/openid.js.map +1 -0
- package/lib/services/pins.d.ts +64 -0
- package/lib/services/pins.d.ts.map +1 -0
- package/lib/services/pins.js +75 -0
- package/lib/services/pins.js.map +1 -0
- package/lib/services/reactions.d.ts +108 -0
- package/lib/services/reactions.d.ts.map +1 -0
- package/lib/services/reactions.js +119 -0
- package/lib/services/reactions.js.map +1 -0
- package/lib/services/reminders.d.ts +89 -0
- package/lib/services/reminders.d.ts.map +1 -0
- package/lib/services/reminders.js +109 -0
- package/lib/services/reminders.js.map +1 -0
- package/lib/services/rtm.d.ts +68 -0
- package/lib/services/rtm.d.ts.map +1 -0
- package/lib/services/rtm.js +74 -0
- package/lib/services/rtm.js.map +1 -0
- package/lib/services/search.d.ts +239 -0
- package/lib/services/search.d.ts.map +1 -0
- package/lib/services/search.js +190 -0
- package/lib/services/search.js.map +1 -0
- package/lib/services/stars.d.ts +126 -0
- package/lib/services/stars.d.ts.map +1 -0
- package/lib/services/stars.js +145 -0
- package/lib/services/stars.js.map +1 -0
- package/lib/services/team.d.ts +309 -0
- package/lib/services/team.d.ts.map +1 -0
- package/lib/services/team.js +333 -0
- package/lib/services/team.js.map +1 -0
- package/lib/services/tooling.d.ts +31 -0
- package/lib/services/tooling.d.ts.map +1 -0
- package/lib/services/tooling.js +38 -0
- package/lib/services/tooling.js.map +1 -0
- package/lib/services/usergroups.d.ts +183 -0
- package/lib/services/usergroups.d.ts.map +1 -0
- package/lib/services/usergroups.js +180 -0
- package/lib/services/usergroups.js.map +1 -0
- package/lib/services/users.d.ts +246 -0
- package/lib/services/users.d.ts.map +1 -0
- package/lib/services/users.js +309 -0
- package/lib/services/users.js.map +1 -0
- package/lib/services/views.d.ts +84 -0
- package/lib/services/views.d.ts.map +1 -0
- package/lib/services/views.js +95 -0
- package/lib/services/views.js.map +1 -0
- package/lib/services/workflows.d.ts +231 -0
- package/lib/services/workflows.d.ts.map +1 -0
- package/lib/services/workflows.js +238 -0
- package/lib/services/workflows.js.map +1 -0
- package/lib/traits.d.ts +11 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +12 -0
- package/lib/traits.js.map +1 -0
- package/package.json +82 -4
- package/src/credentials.ts +86 -0
- package/src/errors.ts +101 -0
- package/src/index.ts +20 -0
- package/src/pagination.ts +35 -0
- package/src/protocol.ts +326 -0
- package/src/retry.ts +76 -0
- package/src/services/admin.ts +7722 -0
- package/src/services/api.ts +58 -0
- package/src/services/apps.ts +1441 -0
- package/src/services/assistant.ts +639 -0
- package/src/services/auth.ts +241 -0
- package/src/services/blocks.ts +80 -0
- package/src/services/bookmarks.ts +223 -0
- package/src/services/bots.ts +144 -0
- package/src/services/calls.ts +318 -0
- package/src/services/canvases.ts +392 -0
- package/src/services/chat.ts +1191 -0
- package/src/services/conversations.ts +1754 -0
- package/src/services/dialog.ts +55 -0
- package/src/services/dnd.ts +246 -0
- package/src/services/emoji.ts +91 -0
- package/src/services/entity.ts +225 -0
- package/src/services/files.ts +1192 -0
- package/src/services/functions.ts +642 -0
- package/src/services/index.ts +35 -0
- package/src/services/lists.ts +832 -0
- package/src/services/migration.ts +85 -0
- package/src/services/oauth.ts +658 -0
- package/src/services/openid.ts +243 -0
- package/src/services/pins.ts +167 -0
- package/src/services/reactions.ts +272 -0
- package/src/services/reminders.ts +240 -0
- package/src/services/rtm.ts +162 -0
- package/src/services/search.ts +507 -0
- package/src/services/stars.ts +323 -0
- package/src/services/team.ts +834 -0
- package/src/services/tooling.ts +78 -0
- package/src/services/usergroups.ts +441 -0
- package/src/services/users.ts +685 -0
- package/src/services/views.ts +212 -0
- package/src/services/workflows.ts +605 -0
- package/src/traits.ts +45 -0
package/lib/protocol.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SlackProtocol — hand-written.
|
|
3
|
+
*
|
|
4
|
+
* Speaks the Slack Web API convention. The generic request/response machinery
|
|
5
|
+
* (trait-driven request building, recursive wire-name mapping, typed-error
|
|
6
|
+
* matcher evaluation) lives in `@distilled.cloud/core/protocol-http`; this
|
|
7
|
+
* module supplies what is Slack's own:
|
|
8
|
+
*
|
|
9
|
+
* request: credentials → `Authorization: Bearer <token>` (omitted for an
|
|
10
|
+
* empty token — the OAuth exchange methods authenticate with
|
|
11
|
+
* `client_id`/`client_secret` args instead), and array-valued
|
|
12
|
+
* query args joined with commas (`channel_ids=C1,C2` — Slack
|
|
13
|
+
* reads comma-separated lists, not repeated params)
|
|
14
|
+
*
|
|
15
|
+
* response: `{ "ok": true, …payload }` — the payload shares the envelope's
|
|
16
|
+
* level, so a successful body maps onto the output schema
|
|
17
|
+
* directly (`ok` is a modeled member).
|
|
18
|
+
* `{ "ok": false, "error": "<slug>" }` — usually WITH HTTP 200 —
|
|
19
|
+
* becomes a typed error: per-op matcher classes first, then the
|
|
20
|
+
* infrastructure slugs (auth → Unauthorized, throttling →
|
|
21
|
+
* SlackRateLimited, server hiccups → retryable 5xx classes),
|
|
22
|
+
* then {@link SlackError} carrying the slug.
|
|
23
|
+
* A successful NON-JSON body is returned as raw bytes — the one
|
|
24
|
+
* method that answers this way (`admin.analytics.getFile`) sends
|
|
25
|
+
* a gzipped NDJSON file.
|
|
26
|
+
*/
|
|
27
|
+
import * as Effect from "effect/Effect";
|
|
28
|
+
import * as Layer from "effect/Layer";
|
|
29
|
+
import * as Redacted from "effect/Redacted";
|
|
30
|
+
import * as API from "@distilled.cloud/core/api";
|
|
31
|
+
import { httpSymbol, querySymbol, } from "@distilled.cloud/core/trait";
|
|
32
|
+
import { buildRequest, getAnn, getProps, hasPropAnn, mapKeys, matchTypedError, } from "@distilled.cloud/core/protocol-http";
|
|
33
|
+
import { unwrapRedactedDeep, wrapSensitive, } from "@distilled.cloud/core/protocol-rest";
|
|
34
|
+
import { ConfigError, GatewayTimeout, HTTP_STATUS_MAP, InternalServerError, ServiceUnavailable, Unauthorized, } from "@distilled.cloud/core/errors";
|
|
35
|
+
import { parseRetryAfterForStatus, parseServerRetryHint, } from "@distilled.cloud/core/retry-after";
|
|
36
|
+
import { Credentials } from "./credentials.js";
|
|
37
|
+
import { SlackError, SlackHttpError, SlackRateLimited, } from "./errors.js";
|
|
38
|
+
// Bridge: Protocol.decode is typed as Effect<unknown> (no error channel), but
|
|
39
|
+
// Slack failures are real typed errors that an operation re-surfaces via its
|
|
40
|
+
// `errors: [...]` list. Fail with the instance and erase the error type here;
|
|
41
|
+
// `API.make`'s signature reintroduces it for callers.
|
|
42
|
+
const fail = (e) => Effect.fail(e);
|
|
43
|
+
/**
|
|
44
|
+
* Envelope slugs that mean "the token is no good" on ANY method — mapped to
|
|
45
|
+
* the shared Unauthorized class so one catch handles credential problems
|
|
46
|
+
* across the SDK. Permission-shaped slugs (`missing_scope`, `no_permission`,
|
|
47
|
+
* `access_denied`, …) stay {@link SlackError}: they carry method-specific
|
|
48
|
+
* detail (`needed`/`provided`) the shared class would drop.
|
|
49
|
+
*/
|
|
50
|
+
const AUTH_SLUGS = new Set([
|
|
51
|
+
"not_authed",
|
|
52
|
+
"invalid_auth",
|
|
53
|
+
"account_inactive",
|
|
54
|
+
"token_revoked",
|
|
55
|
+
"token_expired",
|
|
56
|
+
]);
|
|
57
|
+
/** Envelope slugs that are Slack-side hiccups — retryable server errors. */
|
|
58
|
+
const SERVER_SLUGS = {
|
|
59
|
+
internal_error: (message) => new InternalServerError({ message }),
|
|
60
|
+
fatal_error: (message) => new InternalServerError({ message }),
|
|
61
|
+
service_unavailable: (message) => new ServiceUnavailable({ message }),
|
|
62
|
+
request_timeout: (message) => new GatewayTimeout({ message }),
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Serialize input members the way Slack's wire wants them, before the
|
|
66
|
+
* generic request builder runs:
|
|
67
|
+
*
|
|
68
|
+
* • Array-valued QUERY args join with commas (`channel_ids=C1,C2`) —
|
|
69
|
+
* core's default would repeat the param instead.
|
|
70
|
+
* • On form-urlencoded operations, every non-scalar body member is
|
|
71
|
+
* flattened to the string Slack's form convention reads: ID lists
|
|
72
|
+
* comma-joined, rich values (blocks, barrier subjects, datastore items)
|
|
73
|
+
* JSON-encoded — core's default is Stripe-style bracket notation, which
|
|
74
|
+
* Slack does not speak.
|
|
75
|
+
*/
|
|
76
|
+
const serializeForWire = (input, inputAst) => {
|
|
77
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
78
|
+
return input;
|
|
79
|
+
}
|
|
80
|
+
const isForm = getAnn(inputAst, httpSymbol)?.contentType ===
|
|
81
|
+
"form-urlencoded";
|
|
82
|
+
const props = getProps(inputAst);
|
|
83
|
+
if (props.length === 0)
|
|
84
|
+
return input;
|
|
85
|
+
let out;
|
|
86
|
+
for (const prop of props) {
|
|
87
|
+
const key = String(prop.name);
|
|
88
|
+
const value = input[key];
|
|
89
|
+
if (value === null || typeof value !== "object")
|
|
90
|
+
continue;
|
|
91
|
+
const isQuery = hasPropAnn(prop, querySymbol);
|
|
92
|
+
if (Array.isArray(value) && (isQuery || isForm)) {
|
|
93
|
+
out ??= { ...input };
|
|
94
|
+
out[key] = value.every((v) => typeof v !== "object" || v === null)
|
|
95
|
+
? value.join(",")
|
|
96
|
+
: JSON.stringify(value);
|
|
97
|
+
}
|
|
98
|
+
else if (isForm && !isQuery) {
|
|
99
|
+
out ??= { ...input };
|
|
100
|
+
out[key] = JSON.stringify(value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return out ?? input;
|
|
104
|
+
};
|
|
105
|
+
// The protocol layer is memoized per process by `API.make` (see
|
|
106
|
+
// `OperationConfig.protocol`), so the build must not capture credentials —
|
|
107
|
+
// `encode` resolves Credentials from the calling fiber's context on every
|
|
108
|
+
// request instead. Like the error channel above, the requirement is erased at
|
|
109
|
+
// this boundary (Protocol effects are typed with no requirements) and
|
|
110
|
+
// reintroduced for callers by the generated `SlackOpContext` annotations.
|
|
111
|
+
const encode = ({ input, inputAst, }) => Effect.gen(function* () {
|
|
112
|
+
const resolveCredentials = yield* Credentials;
|
|
113
|
+
const creds = yield* resolveCredentials;
|
|
114
|
+
const token = Redacted.value(creds.token);
|
|
115
|
+
return buildRequest({
|
|
116
|
+
input: serializeForWire(unwrapRedactedDeep(input), inputAst),
|
|
117
|
+
inputAst,
|
|
118
|
+
baseUrl: creds.apiBaseUrl,
|
|
119
|
+
// An empty token means a credential-less call (the OAuth exchange
|
|
120
|
+
// methods) — no Authorization header at all.
|
|
121
|
+
headers: token === "" ? {} : { authorization: `Bearer ${token}` },
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
const decode = ({ response, outputAst, errors: errorClasses, }) => Effect.gen(function* () {
|
|
125
|
+
// Read as BYTES first: the analytics export answers a successful call
|
|
126
|
+
// with a gzipped file, which a text read would corrupt. Everything else
|
|
127
|
+
// decodes from the same buffer.
|
|
128
|
+
const bytes = new Uint8Array(yield* response.arrayBuffer.pipe(Effect.orDie));
|
|
129
|
+
const text = new TextDecoder().decode(bytes);
|
|
130
|
+
if (process.env.DISTILLED_DEBUG_HTTP) {
|
|
131
|
+
console.error(`[distilled] <- ${response.status} ${text.slice(0, 400)}`);
|
|
132
|
+
}
|
|
133
|
+
let json;
|
|
134
|
+
if (text.trim().length > 0) {
|
|
135
|
+
try {
|
|
136
|
+
const parsed = JSON.parse(text);
|
|
137
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
138
|
+
json = parsed;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// non-JSON — a binary success payload or an HTML error page
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const status = response.status;
|
|
146
|
+
const headers = response.headers;
|
|
147
|
+
// Slack reports failures as `ok: false`, usually WITH HTTP 200 — a
|
|
148
|
+
// non-2xx status without an envelope (proxy pages) is also a failure.
|
|
149
|
+
const failed = status >= 400 || json?.ok === false;
|
|
150
|
+
if (failed) {
|
|
151
|
+
const slug = typeof json?.error === "string" ? json.error : undefined;
|
|
152
|
+
// `response_metadata.messages` carries per-field validation detail
|
|
153
|
+
// (e.g. `invalid_arguments`); some envelopes use a bare `errors` list.
|
|
154
|
+
const detailMessages = [
|
|
155
|
+
...(json?.response_metadata
|
|
156
|
+
?.messages ?? []),
|
|
157
|
+
...(Array.isArray(json?.errors) ? json.errors : []),
|
|
158
|
+
].filter((m) => typeof m === "string");
|
|
159
|
+
const message = detailMessages[0] ??
|
|
160
|
+
slug ??
|
|
161
|
+
(json === undefined && text.trim() ? text.trim() : `HTTP ${status}`);
|
|
162
|
+
// 1. Per-operation typed error (matcher metadata on the class — none
|
|
163
|
+
// are generated today, but model patches can add them). Slack's
|
|
164
|
+
// error codes are string slugs, and matcher `code`s are numeric —
|
|
165
|
+
// a patch-declared class matches on `status`/`message` instead
|
|
166
|
+
// (`message` is the slug when the envelope carries no detail).
|
|
167
|
+
const typed = matchTypedError(errorClasses, status, [{ message }]);
|
|
168
|
+
if (typed !== undefined)
|
|
169
|
+
return yield* fail(typed);
|
|
170
|
+
// 2. Throttling — the 429 or its envelope spellings.
|
|
171
|
+
if (status === 429 || slug === "rate_limited" || slug === "ratelimited") {
|
|
172
|
+
return yield* fail(new SlackRateLimited({
|
|
173
|
+
code: slug ?? "rate_limited",
|
|
174
|
+
message,
|
|
175
|
+
retryAfter: parseServerRetryHint(headers),
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
// 3. Infrastructure slugs: credential problems and Slack-side hiccups.
|
|
179
|
+
if (slug !== undefined && AUTH_SLUGS.has(slug)) {
|
|
180
|
+
return yield* fail(new Unauthorized({ message: slug }));
|
|
181
|
+
}
|
|
182
|
+
if (slug !== undefined && slug in SERVER_SLUGS) {
|
|
183
|
+
return yield* fail(SERVER_SLUGS[slug](message));
|
|
184
|
+
}
|
|
185
|
+
// 4. Any other envelope slug → SlackError, the slug preserved.
|
|
186
|
+
if (slug !== undefined) {
|
|
187
|
+
return yield* fail(new SlackError({
|
|
188
|
+
code: slug,
|
|
189
|
+
...(message !== slug ? { message } : {}),
|
|
190
|
+
...(typeof json?.needed === "string"
|
|
191
|
+
? { needed: json.needed }
|
|
192
|
+
: {}),
|
|
193
|
+
...(typeof json?.provided === "string"
|
|
194
|
+
? { provided: json.provided }
|
|
195
|
+
: {}),
|
|
196
|
+
...(detailMessages.length > 0 ? { messages: detailMessages } : {}),
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
// 5. No envelope at all: HTTP-status classes / retryable 5xx / raw.
|
|
200
|
+
const StatusErrorClass = HTTP_STATUS_MAP[status];
|
|
201
|
+
if (StatusErrorClass) {
|
|
202
|
+
return yield* fail(new StatusErrorClass({
|
|
203
|
+
message,
|
|
204
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
if (status >= 500) {
|
|
208
|
+
return yield* fail(new InternalServerError({
|
|
209
|
+
message,
|
|
210
|
+
retryAfter: parseRetryAfterForStatus(status, headers),
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
return yield* fail(new SlackHttpError({ status, message, body: text.slice(0, 2000) }));
|
|
214
|
+
}
|
|
215
|
+
// Successful non-JSON body: raw bytes (the analytics file download —
|
|
216
|
+
// modeled as a Document output, so the bytes pass through verbatim).
|
|
217
|
+
if (json === undefined) {
|
|
218
|
+
return bytes;
|
|
219
|
+
}
|
|
220
|
+
// 2xx envelope: the body IS the payload (`ok` rides along as a modeled
|
|
221
|
+
// member). Wire→TS key mapping is schema-driven; sensitive members
|
|
222
|
+
// (OAuth access/refresh tokens) wrap in Redacted.
|
|
223
|
+
return wrapSensitive(outputAst, mapKeys(outputAst, json, "decode"));
|
|
224
|
+
});
|
|
225
|
+
export const SlackProtocol = Layer.succeed(API.Protocol, API.Protocol.of({
|
|
226
|
+
// Erase encode's Credentials requirement (see comment above).
|
|
227
|
+
encode: (args) => encode(args),
|
|
228
|
+
decode,
|
|
229
|
+
}));
|
|
230
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAMtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACjD,OAAO,EACL,UAAU,EACV,WAAW,GAEZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,UAAU,EACV,OAAO,EACP,eAAe,GAChB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,kBAAkB,EAClB,aAAa,GACd,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAEL,UAAU,EACV,cAAc,EACd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,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,aAAa,GAA8B,KAAK,CAAC,OAAO,CACnE,GAAG,CAAC,QAAQ,EACZ,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IACd,8DAA8D;IAC9D,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CACf,MAAM,CAAC,IAAI,CAAuD;IACpE,MAAM;CACP,CAAC,CACH,CAAC"}
|
package/lib/retry.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack retry surface — a veneer over `@distilled.cloud/core/retry`.
|
|
3
|
+
*
|
|
4
|
+
* The `Retry` service tag is threaded into every generated operation via
|
|
5
|
+
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
6
|
+
* Slack calls below it and core's `makeDefault` is the fallback when none is
|
|
7
|
+
* provided. Slack rate limits per method tier and answers 429s with a
|
|
8
|
+
* `Retry-After` header, which the default policy honors with precedence over
|
|
9
|
+
* its own backoff.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import * as Slack from "@distilled.cloud/slack";
|
|
14
|
+
*
|
|
15
|
+
* myEffect.pipe(Slack.Retry.throttling);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import * as Context from "effect/Context";
|
|
19
|
+
import * as Effect from "effect/Effect";
|
|
20
|
+
import * as Retries from "@distilled.cloud/core/retry";
|
|
21
|
+
export type Options = Retries.Options;
|
|
22
|
+
export type Factory = Retries.Factory;
|
|
23
|
+
export type Policy = Retries.Policy;
|
|
24
|
+
declare const Retry_base: Context.ServiceClass<Retry, "SlackRetry", Retries.Policy>;
|
|
25
|
+
/** Context tag for configuring retry behavior of Slack API calls. */
|
|
26
|
+
export declare class Retry extends Retry_base {
|
|
27
|
+
}
|
|
28
|
+
/** Provides a custom retry policy to every Slack API call below it. */
|
|
29
|
+
export declare const policy: {
|
|
30
|
+
(options: Options): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
31
|
+
(factory: Factory): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
32
|
+
};
|
|
33
|
+
/** Disables all automatic retries. */
|
|
34
|
+
export declare const none: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
35
|
+
/**
|
|
36
|
+
* The default retry policy (core's): transient/throttling/retryable errors,
|
|
37
|
+
* capped exponential backoff with jitter, server `retryAfter` hints honored
|
|
38
|
+
* with precedence.
|
|
39
|
+
*/
|
|
40
|
+
export declare const makeDefault: Factory;
|
|
41
|
+
export declare const jittered: <Error, Env>(self: import("effect/Schedule").Schedule<unknown, unknown, Error, Env>) => import("effect/Schedule").Schedule<unknown, unknown, Error, Env>;
|
|
42
|
+
export declare const capped: (max: import("effect/Duration").Duration) => <Error, Env>(self: import("effect/Schedule").Schedule<unknown, unknown, Error, Env>) => import("effect/Schedule").Schedule<unknown, unknown, Error, Env>;
|
|
43
|
+
/** Retry options that retry all throttling errors indefinitely. */
|
|
44
|
+
export declare const throttlingOptions: Options;
|
|
45
|
+
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
46
|
+
export declare const throttling: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
47
|
+
/** Retry options that retry all transient errors indefinitely. */
|
|
48
|
+
export declare const transientOptions: Options;
|
|
49
|
+
/** Retries all transient errors indefinitely (honoring server hints). */
|
|
50
|
+
export declare const transient: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","s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,CAEzC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,OAA6B,CAAC;AAExD,eAAO,MAAM,QAAQ,0JAAmB,CAAC;AACzC,eAAO,MAAM,MAAM,uMAAiB,CAAC;AAErC,mEAAmE;AACnE,eAAO,MAAM,iBAAiB,EAAE,OAAmC,CAAC;AAEpE,0EAA0E;AAC1E,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAqC,CAAC;AAEhF,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,OAAkC,CAAC;AAElE,yEAAyE;AACzE,eAAO,MAAM,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAoC,CAAC"}
|
package/lib/retry.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack retry surface — a veneer over `@distilled.cloud/core/retry`.
|
|
3
|
+
*
|
|
4
|
+
* The `Retry` service tag is threaded into every generated operation via
|
|
5
|
+
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
6
|
+
* Slack calls below it and core's `makeDefault` is the fallback when none is
|
|
7
|
+
* provided. Slack rate limits per method tier and answers 429s with a
|
|
8
|
+
* `Retry-After` header, which the default policy honors with precedence over
|
|
9
|
+
* its own backoff.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import * as Slack from "@distilled.cloud/slack";
|
|
14
|
+
*
|
|
15
|
+
* myEffect.pipe(Slack.Retry.throttling);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import * as Context from "effect/Context";
|
|
19
|
+
import * as Effect from "effect/Effect";
|
|
20
|
+
import * as Layer from "effect/Layer";
|
|
21
|
+
import * as Retries from "@distilled.cloud/core/retry";
|
|
22
|
+
/** Context tag for configuring retry behavior of Slack API calls. */
|
|
23
|
+
export class Retry extends Context.Service()("SlackRetry") {
|
|
24
|
+
}
|
|
25
|
+
/** Provides a custom retry policy to every Slack API call below it. */
|
|
26
|
+
export const policy = (optionsOrFactory) => Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
27
|
+
/** Disables all automatic retries. */
|
|
28
|
+
export const none = Effect.provide(Layer.succeed(Retry, { while: () => false }));
|
|
29
|
+
/**
|
|
30
|
+
* The default retry policy (core's): transient/throttling/retryable errors,
|
|
31
|
+
* capped exponential backoff with jitter, server `retryAfter` hints honored
|
|
32
|
+
* with precedence.
|
|
33
|
+
*/
|
|
34
|
+
export const makeDefault = Retries.makeDefault;
|
|
35
|
+
export const jittered = Retries.jittered;
|
|
36
|
+
export const capped = Retries.capped;
|
|
37
|
+
/** Retry options that retry all throttling errors indefinitely. */
|
|
38
|
+
export const throttlingOptions = Retries.throttlingOptions;
|
|
39
|
+
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
40
|
+
export const throttling = policy(Retries.throttlingFactory);
|
|
41
|
+
/** Retry options that retry all transient errors indefinitely. */
|
|
42
|
+
export const transientOptions = Retries.transientOptions;
|
|
43
|
+
/** Retries all transient errors indefinitely (honoring server hints). */
|
|
44
|
+
export const transient = policy(Retries.transientFactory);
|
|
45
|
+
//# sourceMappingURL=retry.js.map
|
package/lib/retry.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;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