@distilled.cloud/slack 1.0.0-rc.15 → 1.0.0-rc.17
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/lib/.lazy.json +1 -0
- package/lib/_bundle/lazy.js +4 -0
- package/lib/_bundle/sdk.js +2 -0
- package/lib/_bundle/sdk.js.map +1 -0
- package/lib/credentials.d.ts +1 -1
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +1 -53
- package/lib/errors.d.ts +31 -31
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -59
- package/lib/index.d.ts +1 -1
- package/lib/index.js +0 -10
- package/lib/index.lazy.js +7 -0
- package/lib/pagination.d.ts +2 -2
- package/lib/pagination.js +1 -31
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +1 -231
- package/lib/retry.d.ts +2 -2
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -45
- package/lib/services/admin.d.ts +123 -575
- package/lib/services/admin.d.ts.map +1 -1
- package/lib/services/admin.js +141 -2884
- package/lib/services/admin.js.map +1 -1
- package/lib/services/agents.d.ts +13 -55
- package/lib/services/agents.d.ts.map +1 -1
- package/lib/services/agents.js +1 -314
- package/lib/services/agents.js.map +1 -1
- package/lib/services/api.d.ts +0 -4
- package/lib/services/api.d.ts.map +1 -1
- package/lib/services/api.js +1 -23
- package/lib/services/api.js.map +1 -1
- package/lib/services/apps.d.ts +25 -106
- package/lib/services/apps.d.ts.map +1 -1
- package/lib/services/apps.js +35 -515
- package/lib/services/apps.js.map +1 -1
- package/lib/services/assistant.d.ts +6 -40
- package/lib/services/assistant.d.ts.map +1 -1
- package/lib/services/assistant.js +1 -209
- package/lib/services/assistant.js.map +1 -1
- package/lib/services/auth.d.ts +4 -15
- package/lib/services/auth.d.ts.map +1 -1
- package/lib/services/auth.js +1 -96
- package/lib/services/auth.js.map +1 -1
- package/lib/services/blocks.d.ts +1 -7
- package/lib/services/blocks.d.ts.map +1 -1
- package/lib/services/blocks.js +1 -26
- package/lib/services/blocks.js.map +1 -1
- package/lib/services/bookmarks.d.ts +4 -15
- package/lib/services/bookmarks.d.ts.map +1 -1
- package/lib/services/bookmarks.js +1 -81
- package/lib/services/bookmarks.js.map +1 -1
- package/lib/services/bots.d.ts +1 -9
- package/lib/services/bots.d.ts.map +1 -1
- package/lib/services/bots.js +1 -59
- package/lib/services/bots.js.map +1 -1
- package/lib/services/calls.d.ts +6 -22
- package/lib/services/calls.d.ts.map +1 -1
- package/lib/services/calls.js +1 -115
- package/lib/services/calls.js.map +1 -1
- package/lib/services/canvases.d.ts +7 -35
- package/lib/services/canvases.d.ts.map +1 -1
- package/lib/services/canvases.js +1 -140
- package/lib/services/canvases.js.map +1 -1
- package/lib/services/chat.d.ts +14 -83
- package/lib/services/chat.d.ts.map +1 -1
- package/lib/services/chat.js +1 -387
- package/lib/services/chat.js.map +1 -1
- package/lib/services/conversations.d.ts +31 -116
- package/lib/services/conversations.d.ts.map +1 -1
- package/lib/services/conversations.js +40 -696
- package/lib/services/conversations.js.map +1 -1
- package/lib/services/dialog.d.ts +1 -4
- package/lib/services/dialog.d.ts.map +1 -1
- package/lib/services/dialog.js +1 -22
- package/lib/services/dialog.js.map +1 -1
- package/lib/services/dnd.d.ts +5 -17
- package/lib/services/dnd.d.ts.map +1 -1
- package/lib/services/dnd.js +1 -96
- package/lib/services/dnd.js.map +1 -1
- package/lib/services/emoji.d.ts +1 -8
- package/lib/services/emoji.d.ts.map +1 -1
- package/lib/services/emoji.js +1 -34
- package/lib/services/emoji.js.map +1 -1
- package/lib/services/entity.d.ts +4 -16
- package/lib/services/entity.d.ts.map +1 -1
- package/lib/services/entity.js +1 -76
- package/lib/services/entity.js.map +1 -1
- package/lib/services/files.d.ts +16 -80
- package/lib/services/files.d.ts.map +1 -1
- package/lib/services/files.js +1 -439
- package/lib/services/files.js.map +1 -1
- package/lib/services/functions.d.ts +8 -49
- package/lib/services/functions.d.ts.map +1 -1
- package/lib/services/functions.js +1 -208
- package/lib/services/functions.js.map +1 -1
- package/lib/services/index.js +0 -2
- package/lib/services/lists.d.ts +13 -55
- package/lib/services/lists.d.ts.map +1 -1
- package/lib/services/lists.js +1 -254
- package/lib/services/lists.js.map +1 -1
- package/lib/services/migration.d.ts +1 -7
- package/lib/services/migration.d.ts.map +1 -1
- package/lib/services/migration.js +1 -32
- package/lib/services/migration.js.map +1 -1
- package/lib/services/oauth.d.ts +7 -43
- package/lib/services/oauth.d.ts.map +1 -1
- package/lib/services/oauth.js +1 -294
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/openid.d.ts +3 -10
- package/lib/services/openid.d.ts.map +1 -1
- package/lib/services/openid.js +1 -84
- package/lib/services/openid.js.map +1 -1
- package/lib/services/pins.d.ts +3 -13
- package/lib/services/pins.d.ts.map +1 -1
- package/lib/services/pins.js +1 -66
- package/lib/services/pins.js.map +1 -1
- package/lib/services/reactions.d.ts +5 -17
- package/lib/services/reactions.d.ts.map +1 -1
- package/lib/services/reactions.js +1 -102
- package/lib/services/reactions.js.map +1 -1
- package/lib/services/reminders.d.ts +5 -17
- package/lib/services/reminders.d.ts.map +1 -1
- package/lib/services/reminders.js +1 -88
- package/lib/services/reminders.js.map +1 -1
- package/lib/services/rtm.d.ts +2 -11
- package/lib/services/rtm.d.ts.map +1 -1
- package/lib/services/rtm.js +1 -61
- package/lib/services/rtm.js.map +1 -1
- package/lib/services/search.d.ts +4 -35
- package/lib/services/search.d.ts.map +1 -1
- package/lib/services/search.js +1 -172
- package/lib/services/search.js.map +1 -1
- package/lib/services/stars.d.ts +4 -26
- package/lib/services/stars.d.ts.map +1 -1
- package/lib/services/stars.js +1 -134
- package/lib/services/stars.js.map +1 -1
- package/lib/services/team.d.ts +11 -63
- package/lib/services/team.d.ts.map +1 -1
- package/lib/services/team.js +1 -295
- package/lib/services/team.js.map +1 -1
- package/lib/services/tooling.d.ts +2 -5
- package/lib/services/tooling.d.ts.map +1 -1
- package/lib/services/tooling.js +1 -33
- package/lib/services/tooling.js.map +1 -1
- package/lib/services/usergroups.d.ts +7 -31
- package/lib/services/usergroups.d.ts.map +1 -1
- package/lib/services/usergroups.js +1 -151
- package/lib/services/usergroups.js.map +1 -1
- package/lib/services/users.d.ts +14 -48
- package/lib/services/users.d.ts.map +1 -1
- package/lib/services/users.js +1 -255
- package/lib/services/users.js.map +1 -1
- package/lib/services/views.d.ts +4 -14
- package/lib/services/views.d.ts.map +1 -1
- package/lib/services/views.js +1 -78
- package/lib/services/views.js.map +1 -1
- package/lib/services/workflows.d.ts +8 -51
- package/lib/services/workflows.d.ts.map +1 -1
- package/lib/services/workflows.js +1 -193
- package/lib/services/workflows.js.map +1 -1
- package/lib/services.lazy/admin.js +3 -0
- package/lib/services.lazy/agents.js +1 -0
- package/lib/services.lazy/api.js +1 -0
- package/lib/services.lazy/apps.js +3 -0
- package/lib/services.lazy/assistant.js +1 -0
- package/lib/services.lazy/auth.js +1 -0
- package/lib/services.lazy/blocks.js +1 -0
- package/lib/services.lazy/bookmarks.js +1 -0
- package/lib/services.lazy/bots.js +1 -0
- package/lib/services.lazy/calls.js +1 -0
- package/lib/services.lazy/canvases.js +1 -0
- package/lib/services.lazy/chat.js +1 -0
- package/lib/services.lazy/conversations.js +3 -0
- package/lib/services.lazy/dialog.js +1 -0
- package/lib/services.lazy/dnd.js +1 -0
- package/lib/services.lazy/emoji.js +1 -0
- package/lib/services.lazy/entity.js +1 -0
- package/lib/services.lazy/files.js +1 -0
- package/lib/services.lazy/functions.js +1 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/lists.js +1 -0
- package/lib/services.lazy/migration.js +1 -0
- package/lib/services.lazy/oauth.js +1 -0
- package/lib/services.lazy/openid.js +1 -0
- package/lib/services.lazy/pins.js +1 -0
- package/lib/services.lazy/reactions.js +1 -0
- package/lib/services.lazy/reminders.js +1 -0
- package/lib/services.lazy/rtm.js +1 -0
- package/lib/services.lazy/search.js +1 -0
- package/lib/services.lazy/stars.js +1 -0
- package/lib/services.lazy/team.js +1 -0
- package/lib/services.lazy/tooling.js +1 -0
- package/lib/services.lazy/usergroups.js +1 -0
- package/lib/services.lazy/users.js +1 -0
- package/lib/services.lazy/views.js +1 -0
- package/lib/services.lazy/workflows.js +1 -0
- package/lib/traits.d.ts +1 -1
- package/lib/traits.js +1 -12
- package/package.json +10 -8
- package/src/credentials.ts +20 -21
- package/src/errors.ts +31 -27
- package/src/index.ts +1 -1
- package/src/pagination.ts +2 -2
- package/src/protocol.ts +30 -29
- package/src/retry.ts +6 -6
- package/src/services/admin.ts +2717 -3451
- package/src/services/agents.ts +380 -370
- package/src/services/api.ts +31 -21
- package/src/services/apps.ts +569 -621
- package/src/services/assistant.ts +235 -270
- package/src/services/auth.ts +118 -100
- package/src/services/blocks.ts +33 -29
- package/src/services/bookmarks.ts +101 -83
- package/src/services/bots.ts +74 -67
- package/src/services/calls.ts +118 -124
- package/src/services/canvases.ts +171 -178
- package/src/services/chat.ts +428 -496
- package/src/services/conversations.ts +675 -761
- package/src/services/dialog.ts +30 -17
- package/src/services/dnd.ts +125 -99
- package/src/services/emoji.ts +46 -42
- package/src/services/entity.ts +94 -92
- package/src/services/files.ts +536 -531
- package/src/services/functions.ts +209 -274
- package/src/services/lists.ts +289 -304
- package/src/services/migration.ts +39 -37
- package/src/services/oauth.ts +345 -361
- package/src/services/openid.ts +137 -122
- package/src/services/pins.ts +83 -70
- package/src/services/reactions.ts +119 -103
- package/src/services/reminders.ts +112 -90
- package/src/services/rtm.ts +73 -65
- package/src/services/search.ts +193 -244
- package/src/services/stars.ts +101 -160
- package/src/services/team.ts +333 -369
- package/src/services/tooling.ts +43 -30
- package/src/services/usergroups.ts +175 -179
- package/src/services/users.ts +301 -268
- package/src/services/views.ts +85 -80
- package/src/services/workflows.ts +184 -269
- package/src/traits.ts +1 -1
- package/lib/credentials.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/protocol.js.map +0 -1
- package/lib/protocol.test.d.ts +0 -2
- package/lib/protocol.test.d.ts.map +0 -1
- package/lib/protocol.test.js +0 -288
- package/lib/protocol.test.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/services/index.js.map +0 -1
- package/lib/traits.js.map +0 -1
- package/src/protocol.test.ts +0 -372
- /package/lib/{index.js.map → index.lazy.js.map} +0 -0
package/src/errors.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Slack-specific error types.
|
|
3
3
|
*
|
|
4
|
-
* Slack reports failures as `{ "ok": false, "error": "<slug>" }`
|
|
5
|
-
* with HTTP 200
|
|
4
|
+
* Slack reports failures as `{ "ok": false, "error": "<slug>" }` -- usually
|
|
5
|
+
* with HTTP 200 -- so the interesting field is the machine-readable `error`
|
|
6
6
|
* slug, not the status. The protocol maps the well-known infrastructure
|
|
7
7
|
* slugs (auth, throttling, server hiccups) onto core's shared HTTP error
|
|
8
8
|
* classes and surfaces everything else as {@link SlackError} with the slug
|
|
@@ -30,49 +30,53 @@ import * as Category from "@distilled.cloud/core/category";
|
|
|
30
30
|
import { withCategory } from "@distilled.cloud/core/error-category";
|
|
31
31
|
import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
|
|
32
32
|
import { DurationSchema, RETRYABLE } from "@distilled.cloud/core/errors";
|
|
33
|
-
import * as Schema from "
|
|
33
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* A Slack API error envelope: `ok: false` with a machine-readable slug.
|
|
37
|
-
* `code` is the slug (`channel_not_found`, `invalid_blocks`,
|
|
37
|
+
* `code` is the slug (`channel_not_found`, `invalid_blocks`, ...) -- the field
|
|
38
38
|
* to branch on; the per-method slugs are listed in each operation's doc
|
|
39
39
|
* comment. `needed`/`provided` carry scope detail on `missing_scope`;
|
|
40
40
|
* `messages` carries the envelope's `response_metadata.messages` (per-field
|
|
41
41
|
* validation detail on `invalid_arguments`).
|
|
42
42
|
*/
|
|
43
|
-
export class SlackError
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
export class SlackError
|
|
44
|
+
extends /*@__PURE__*/ Schema.TaggedError<SlackError>()("SlackError", {
|
|
45
|
+
code: Schema.String,
|
|
46
|
+
message: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
47
|
+
needed: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
48
|
+
provided: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
49
|
+
messages: /*@__PURE__*/ Schema.optional(/*@__PURE__*/ Schema.Array(Schema.String)),
|
|
50
|
+
}) {}
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
|
-
* Slack rate limit
|
|
53
|
+
* Slack rate limit -- a 429 or the `rate_limited`/`ratelimited` slug. Slack
|
|
53
54
|
* answers with a `Retry-After` header the default retry policy honors.
|
|
54
55
|
*/
|
|
55
|
-
export class SlackRateLimited
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
export class SlackRateLimited
|
|
57
|
+
extends /*@__PURE__*/ Schema.TaggedError<SlackRateLimited>()("SlackRateLimited", {
|
|
58
|
+
code: Schema.String,
|
|
59
|
+
message: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
60
|
+
retryAfter: /*@__PURE__*/ Schema.optional(DurationSchema),
|
|
61
|
+
}).pipe(/*@__PURE__*/ withCategory(RETRYABLE), Category.withThrottlingError) {}
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
|
-
* HTTP error
|
|
64
|
+
* HTTP error -- a non-2xx response without a parseable Slack error envelope
|
|
63
65
|
* (proxy pages, HTML 5xx bodies).
|
|
64
66
|
*/
|
|
65
|
-
export class SlackHttpError
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
export class SlackHttpError
|
|
68
|
+
extends /*@__PURE__*/ Schema.TaggedError<SlackHttpError>()("SlackHttpError", {
|
|
69
|
+
status: Schema.Number,
|
|
70
|
+
message: Schema.String,
|
|
71
|
+
body: /*@__PURE__*/ Schema.optional(Schema.String),
|
|
72
|
+
}) {}
|
|
70
73
|
|
|
71
74
|
/** Schema parse error wrapper. */
|
|
72
|
-
export class SlackParseError
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
export class SlackParseError
|
|
76
|
+
extends /*@__PURE__*/ Schema.TaggedError<SlackParseError>()("SlackParseError", {
|
|
77
|
+
body: Schema.Unknown,
|
|
78
|
+
cause: Schema.Unknown,
|
|
79
|
+
}).pipe(Category.withParseError) {}
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
82
|
* Errors any Slack operation may surface in addition to the shared HTTP
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @distilled.cloud/slack
|
|
2
|
+
* @distilled.cloud/slack -- Slack Web API SDK for Effect.
|
|
3
3
|
*
|
|
4
4
|
* `./services` is generated by `scripts/generate.ts` from the Smithy models
|
|
5
5
|
* in `.generated-specs` (written by `scripts/convert.ts` from the JSON twins
|
package/src/pagination.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Slack pagination
|
|
2
|
+
* Slack pagination -- hand-written.
|
|
3
3
|
*
|
|
4
4
|
* Slack's cursor convention: pass `cursor` (from the previous response's
|
|
5
5
|
* `response_metadata.next_cursor`), and an EMPTY `next_cursor` means the
|
|
6
|
-
* last page
|
|
6
|
+
* last page -- which is exactly core's cursor traversal (`isTerminalToken`
|
|
7
7
|
* treats `""` as terminal). Paginated operations are compiled with this
|
|
8
8
|
* strategy by scripts/generate.ts from the `smithy.api#paginated` traits the
|
|
9
9
|
* converter stamps.
|
package/src/protocol.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as API from "@distilled.cloud/core/api";
|
|
2
|
+
import { debugHttp } from "@distilled.cloud/core/debug";
|
|
2
3
|
import {
|
|
3
4
|
ConfigError,
|
|
4
5
|
GatewayTimeout,
|
|
@@ -20,28 +21,28 @@ import { validateResponse } from "@distilled.cloud/core/response-validation";
|
|
|
20
21
|
import { parseRetryAfterForStatus, parseServerRetryHint } from "@distilled.cloud/core/retry-after";
|
|
21
22
|
import { httpSymbol, querySymbol, type HttpTrait } from "@distilled.cloud/core/trait";
|
|
22
23
|
/**
|
|
23
|
-
* SlackProtocol
|
|
24
|
+
* SlackProtocol -- hand-written.
|
|
24
25
|
*
|
|
25
26
|
* Speaks the Slack Web API convention. The generic request/response machinery
|
|
26
27
|
* (trait-driven request building, recursive wire-name mapping, typed-error
|
|
27
28
|
* matcher evaluation) lives in `@distilled.cloud/core/protocol-http`; this
|
|
28
29
|
* module supplies what is Slack's own:
|
|
29
30
|
*
|
|
30
|
-
* request: credentials
|
|
31
|
-
* empty token
|
|
31
|
+
* request: credentials -> `Authorization: Bearer <token>` (omitted for an
|
|
32
|
+
* empty token -- the OAuth exchange methods authenticate with
|
|
32
33
|
* `client_id`/`client_secret` args instead), and array-valued
|
|
33
|
-
* query args joined with commas (`channel_ids=C1,C2`
|
|
34
|
+
* query args joined with commas (`channel_ids=C1,C2` -- Slack
|
|
34
35
|
* reads comma-separated lists, not repeated params)
|
|
35
36
|
*
|
|
36
|
-
* response: `{ "ok": true,
|
|
37
|
+
* response: `{ "ok": true, ...payload }` -- the payload shares the envelope's
|
|
37
38
|
* level, so a successful body maps onto the output schema
|
|
38
39
|
* directly (`ok` is a modeled member).
|
|
39
|
-
* `{ "ok": false, "error": "<slug>" }`
|
|
40
|
+
* `{ "ok": false, "error": "<slug>" }` -- usually WITH HTTP 200 --
|
|
40
41
|
* becomes a typed error: per-op matcher classes first, then the
|
|
41
|
-
* infrastructure slugs (auth
|
|
42
|
-
* SlackRateLimited, server hiccups
|
|
42
|
+
* infrastructure slugs (auth -> Unauthorized, throttling ->
|
|
43
|
+
* SlackRateLimited, server hiccups -> retryable 5xx classes),
|
|
43
44
|
* then {@link SlackError} carrying the slug.
|
|
44
|
-
* A successful NON-JSON body is returned as raw bytes
|
|
45
|
+
* A successful NON-JSON body is returned as raw bytes -- the one
|
|
45
46
|
* method that answers this way (`admin.analytics.getFile`) sends
|
|
46
47
|
* a gzipped NDJSON file.
|
|
47
48
|
*/
|
|
@@ -80,13 +81,13 @@ export type SlackOpContext = Credentials | HttpClient.HttpClient;
|
|
|
80
81
|
const fail = (e: unknown): Effect.Effect<never> => Effect.fail(e) as Effect.Effect<never>;
|
|
81
82
|
|
|
82
83
|
/**
|
|
83
|
-
* Envelope slugs that mean "the token is no good" on ANY method
|
|
84
|
+
* Envelope slugs that mean "the token is no good" on ANY method -- mapped to
|
|
84
85
|
* the shared Unauthorized class so one catch handles credential problems
|
|
85
86
|
* across the SDK. Permission-shaped slugs (`missing_scope`, `no_permission`,
|
|
86
|
-
* `access_denied`,
|
|
87
|
+
* `access_denied`, ...) stay {@link SlackError}: they carry method-specific
|
|
87
88
|
* detail (`needed`/`provided`) the shared class would drop.
|
|
88
89
|
*/
|
|
89
|
-
const AUTH_SLUGS = new Set([
|
|
90
|
+
const AUTH_SLUGS = /*@__PURE__*/ new Set([
|
|
90
91
|
"not_authed",
|
|
91
92
|
"invalid_auth",
|
|
92
93
|
"account_inactive",
|
|
@@ -94,7 +95,7 @@ const AUTH_SLUGS = new Set([
|
|
|
94
95
|
"token_expired",
|
|
95
96
|
]);
|
|
96
97
|
|
|
97
|
-
/** Envelope slugs that are Slack-side hiccups
|
|
98
|
+
/** Envelope slugs that are Slack-side hiccups -- retryable server errors. */
|
|
98
99
|
const SERVER_SLUGS: Record<string, (message: string) => unknown> = {
|
|
99
100
|
internal_error: (message) => new InternalServerError({ message }),
|
|
100
101
|
fatal_error: (message) => new InternalServerError({ message }),
|
|
@@ -106,12 +107,12 @@ const SERVER_SLUGS: Record<string, (message: string) => unknown> = {
|
|
|
106
107
|
* Serialize input members the way Slack's wire wants them, before the
|
|
107
108
|
* generic request builder runs:
|
|
108
109
|
*
|
|
109
|
-
*
|
|
110
|
+
* * Array-valued QUERY args join with commas (`channel_ids=C1,C2`) --
|
|
110
111
|
* core's default would repeat the param instead.
|
|
111
|
-
*
|
|
112
|
+
* * On form-urlencoded operations, every non-scalar body member is
|
|
112
113
|
* flattened to the string Slack's form convention reads: ID lists
|
|
113
114
|
* comma-joined, rich values (blocks, barrier subjects, datastore items)
|
|
114
|
-
* JSON-encoded
|
|
115
|
+
* JSON-encoded -- core's default is Stripe-style bracket notation, which
|
|
115
116
|
* Slack does not speak.
|
|
116
117
|
*/
|
|
117
118
|
const serializeForWire = (input: unknown, inputAst: AST.AST): unknown => {
|
|
@@ -142,7 +143,7 @@ const serializeForWire = (input: unknown, inputAst: AST.AST): unknown => {
|
|
|
142
143
|
};
|
|
143
144
|
|
|
144
145
|
// The protocol layer is memoized per process by `API.make` (see
|
|
145
|
-
// `OperationConfig.protocol`), so the build must not capture credentials
|
|
146
|
+
// `OperationConfig.protocol`), so the build must not capture credentials --
|
|
146
147
|
// `encode` resolves Credentials from the calling fiber's context on every
|
|
147
148
|
// request instead. Like the error channel above, the requirement is erased at
|
|
148
149
|
// this boundary (Protocol effects are typed with no requirements) and
|
|
@@ -157,7 +158,7 @@ const encode = ({ input, inputAst }: { readonly input: unknown; readonly inputAs
|
|
|
157
158
|
inputAst,
|
|
158
159
|
baseUrl: creds.apiBaseUrl,
|
|
159
160
|
// An empty token means a credential-less call (the OAuth exchange
|
|
160
|
-
// methods)
|
|
161
|
+
// methods) -- no Authorization header at all.
|
|
161
162
|
headers: token === "" ? {} : { authorization: `Bearer ${token}` },
|
|
162
163
|
});
|
|
163
164
|
});
|
|
@@ -177,7 +178,7 @@ const decode = ({
|
|
|
177
178
|
// decodes from the same buffer.
|
|
178
179
|
const bytes = new Uint8Array(yield* response.arrayBuffer.pipe(Effect.orDie));
|
|
179
180
|
const text = new TextDecoder().decode(bytes);
|
|
180
|
-
if (
|
|
181
|
+
if (debugHttp()) {
|
|
181
182
|
console.error(`[distilled] <- ${response.status} ${text.slice(0, 400)}`);
|
|
182
183
|
}
|
|
183
184
|
|
|
@@ -189,13 +190,13 @@ const decode = ({
|
|
|
189
190
|
json = parsed as Record<string, unknown>;
|
|
190
191
|
}
|
|
191
192
|
} catch {
|
|
192
|
-
// non-JSON
|
|
193
|
+
// non-JSON -- a binary success payload or an HTML error page
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
const status = response.status;
|
|
196
197
|
const headers = response.headers as Record<string, string | undefined>;
|
|
197
198
|
|
|
198
|
-
// Slack reports failures as `ok: false`, usually WITH HTTP 200
|
|
199
|
+
// Slack reports failures as `ok: false`, usually WITH HTTP 200 -- a
|
|
199
200
|
// non-2xx status without an envelope (proxy pages) is also a failure.
|
|
200
201
|
const failed = status >= 400 || json?.ok === false;
|
|
201
202
|
if (failed) {
|
|
@@ -213,9 +214,9 @@ const decode = ({
|
|
|
213
214
|
slug ??
|
|
214
215
|
(json === undefined && text.trim() ? text.trim() : `HTTP ${status}`);
|
|
215
216
|
|
|
216
|
-
// 1. Per-operation typed error (matcher metadata on the class
|
|
217
|
+
// 1. Per-operation typed error (matcher metadata on the class -- none
|
|
217
218
|
// are generated today, but model patches can add them). Slack's
|
|
218
|
-
// error codes are string slugs, and matcher `code`s are numeric
|
|
219
|
+
// error codes are string slugs, and matcher `code`s are numeric --
|
|
219
220
|
// a patch-declared class matches on `status`/`message` instead
|
|
220
221
|
// (`message` is the slug when the envelope carries no detail).
|
|
221
222
|
const typed = matchTypedError(errorClasses, status, [{ message }], {
|
|
@@ -224,7 +225,7 @@ const decode = ({
|
|
|
224
225
|
});
|
|
225
226
|
if (typed !== undefined) return yield* fail(typed);
|
|
226
227
|
|
|
227
|
-
// 2. Throttling
|
|
228
|
+
// 2. Throttling -- the 429 or its envelope spellings.
|
|
228
229
|
if (status === 429 || slug === "rate_limited" || slug === "ratelimited") {
|
|
229
230
|
return yield* fail(
|
|
230
231
|
new SlackRateLimited({
|
|
@@ -243,7 +244,7 @@ const decode = ({
|
|
|
243
244
|
return yield* fail(SERVER_SLUGS[slug]!(message));
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
// 4. Any other envelope slug
|
|
247
|
+
// 4. Any other envelope slug -> SlackError, the slug preserved.
|
|
247
248
|
if (slug !== undefined) {
|
|
248
249
|
return yield* fail(
|
|
249
250
|
new SlackError({
|
|
@@ -277,7 +278,7 @@ const decode = ({
|
|
|
277
278
|
return yield* fail(new SlackHttpError({ status, message, body: text.slice(0, 2000) }));
|
|
278
279
|
}
|
|
279
280
|
|
|
280
|
-
// Successful non-JSON body: raw bytes (the analytics file download
|
|
281
|
+
// Successful non-JSON body: raw bytes (the analytics file download --
|
|
281
282
|
// modeled as a Document output, so the bytes pass through verbatim).
|
|
282
283
|
// Strict mode fails them for every other (struct) output.
|
|
283
284
|
if (json === undefined) {
|
|
@@ -289,7 +290,7 @@ const decode = ({
|
|
|
289
290
|
}
|
|
290
291
|
|
|
291
292
|
// 2xx envelope: the body IS the payload (`ok` rides along as a modeled
|
|
292
|
-
// member). Wire
|
|
293
|
+
// member). Wire->TS key mapping is schema-driven; sensitive members
|
|
293
294
|
// (OAuth access/refresh tokens) wrap in Redacted. Strict mode checks the
|
|
294
295
|
// mapped payload against the output schema first.
|
|
295
296
|
const mapped = yield* validateResponse(
|
|
@@ -300,9 +301,9 @@ const decode = ({
|
|
|
300
301
|
return wrapSensitive(outputAst, mapped);
|
|
301
302
|
});
|
|
302
303
|
|
|
303
|
-
export const SlackProtocol: Layer.Layer<API.Protocol> = Layer.succeed(
|
|
304
|
+
export const SlackProtocol: Layer.Layer<API.Protocol> = /*@__PURE__*/ Layer.succeed(
|
|
304
305
|
API.Protocol,
|
|
305
|
-
API.Protocol.of({
|
|
306
|
+
/*@__PURE__*/ API.Protocol.of({
|
|
306
307
|
// Erase encode's Credentials requirement (see comment above).
|
|
307
308
|
encode: (args) => encode(args) as Effect.Effect<HttpClientRequest.HttpClientRequest>,
|
|
308
309
|
decode,
|
package/src/retry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Retries from "@distilled.cloud/core/retry";
|
|
2
2
|
/**
|
|
3
|
-
* Slack retry surface
|
|
3
|
+
* Slack retry surface -- a veneer over `@distilled.cloud/core/retry`.
|
|
4
4
|
*
|
|
5
5
|
* The `Retry` service tag is threaded into every generated operation via
|
|
6
6
|
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
@@ -25,7 +25,7 @@ export type Factory = Retries.Factory;
|
|
|
25
25
|
export type Policy = Retries.Policy;
|
|
26
26
|
|
|
27
27
|
/** Context tag for configuring retry behavior of Slack API calls. */
|
|
28
|
-
export class Retry extends Context.Service<Retry, Policy>()("SlackRetry") {}
|
|
28
|
+
export class Retry extends /*@__PURE__*/ Context.Service<Retry, Policy>()("SlackRetry") {}
|
|
29
29
|
|
|
30
30
|
/** Provides a custom retry policy to every Slack API call below it. */
|
|
31
31
|
export const policy: {
|
|
@@ -40,8 +40,8 @@ export const policy: {
|
|
|
40
40
|
/** Disables all automatic retries. */
|
|
41
41
|
export const none: <A, E, R>(
|
|
42
42
|
effect: Effect.Effect<A, E, R>,
|
|
43
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>> = Effect.provide(
|
|
44
|
-
Layer.succeed(Retry, { while: () => false }),
|
|
43
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ Effect.provide(
|
|
44
|
+
/*@__PURE__*/ Layer.succeed(Retry, { while: () => false }),
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -60,7 +60,7 @@ export const throttlingOptions: Options = Retries.throttlingOptions;
|
|
|
60
60
|
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
61
61
|
export const throttling: <A, E, R>(
|
|
62
62
|
effect: Effect.Effect<A, E, R>,
|
|
63
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>> = policy(Retries.throttlingFactory);
|
|
63
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.throttlingFactory);
|
|
64
64
|
|
|
65
65
|
/** Retry options that retry all transient errors indefinitely. */
|
|
66
66
|
export const transientOptions: Options = Retries.transientOptions;
|
|
@@ -68,4 +68,4 @@ export const transientOptions: Options = Retries.transientOptions;
|
|
|
68
68
|
/** Retries all transient errors indefinitely (honoring server hints). */
|
|
69
69
|
export const transient: <A, E, R>(
|
|
70
70
|
effect: Effect.Effect<A, E, R>,
|
|
71
|
-
) => Effect.Effect<A, E, Exclude<R, Retry>> = policy(Retries.transientFactory);
|
|
71
|
+
) => Effect.Effect<A, E, Exclude<R, Retry>> = /*@__PURE__*/ policy(Retries.transientFactory);
|