@distilled.cloud/x 0.0.0-stage → 1.0.0-rc.21
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/README.md +114 -2
- 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 +29 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +1 -0
- package/lib/errors.d.ts +50 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +1 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.lazy.js +7 -0
- package/lib/index.lazy.js.map +1 -0
- package/lib/pagination.d.ts +11 -0
- package/lib/pagination.d.ts.map +1 -0
- package/lib/pagination.js +1 -0
- package/lib/protocol.d.ts +19 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +1 -0
- package/lib/retry.d.ts +50 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +1 -0
- package/lib/services/index.d.ts +2 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +1 -0
- package/lib/services/x.d.ts +10689 -0
- package/lib/services/x.d.ts.map +1 -0
- package/lib/services/x.js +368 -0
- package/lib/services/x.js.map +1 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/x.js +3 -0
- package/lib/traits.d.ts +12 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +1 -0
- package/package.json +88 -3
- package/src/credentials.ts +79 -0
- package/src/errors.ts +60 -0
- package/src/index.ts +25 -0
- package/src/pagination.ts +10 -0
- package/src/protocol.ts +73 -0
- package/src/retry.ts +69 -0
- package/src/services/index.ts +2 -0
- package/src/services/x.ts +29733 -0
- package/src/traits.ts +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @distilled.cloud/x
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Effect-native [X API v2](https://docs.x.com/x-api) SDK, generated from X's own
|
|
4
|
+
OpenAPI description, [`https://api.x.com/2/openapi.json`](https://api.x.com/2/openapi.json).
|
|
5
|
+
|
|
6
|
+
Every operation of the spec is here, exported from the package root: posts,
|
|
7
|
+
users, likes, reposts, bookmarks, lists, media upload, direct messages, Chat,
|
|
8
|
+
search, counts, Spaces, communities, Community Notes, trends, news,
|
|
9
|
+
broadcasts, compliance jobs, webhooks, Account Activity and the usage
|
|
10
|
+
endpoints.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @distilled.cloud/x effect
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
Publish a post with an image, reply to it, and read the replies that mention
|
|
21
|
+
you.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { readFile } from "node:fs/promises";
|
|
25
|
+
import { Effect, Layer, Stream } from "effect";
|
|
26
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
27
|
+
import * as X from "@distilled.cloud/x";
|
|
28
|
+
|
|
29
|
+
const program = Effect.gen(function* () {
|
|
30
|
+
const me = yield* X.getUsersMe({ user_fields: ["public_metrics"] });
|
|
31
|
+
const userId = me.data!.id;
|
|
32
|
+
|
|
33
|
+
// 1. Upload an image. The JSON body takes the file as base64.
|
|
34
|
+
const image = yield* Effect.tryPromise(() => readFile("launch.png"));
|
|
35
|
+
const upload = yield* X.uploadMedia({
|
|
36
|
+
media: image.toString("base64"),
|
|
37
|
+
media_category: "tweet_image",
|
|
38
|
+
});
|
|
39
|
+
const mediaId = upload.data!.id;
|
|
40
|
+
yield* X.createMediaMetadata({
|
|
41
|
+
id: mediaId,
|
|
42
|
+
metadata: { alt_text: { text: "The launch announcement card" } },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// 2. Post it, then reply to the post to start a thread.
|
|
46
|
+
const post = yield* X.createPosts({
|
|
47
|
+
text: "We just launched 🚀",
|
|
48
|
+
media: { media_ids: [mediaId] },
|
|
49
|
+
});
|
|
50
|
+
const postId = post.data!.id;
|
|
51
|
+
yield* X.createPosts({
|
|
52
|
+
text: "Read the changelog: https://example.com/changelog",
|
|
53
|
+
reply: { in_reply_to_tweet_id: postId },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// 3. Read the latest mentions, fetching more pages as the stream needs them.
|
|
57
|
+
const mentions = yield* X.getUsersMentions
|
|
58
|
+
.items({ id: userId, max_results: 100, post_fields: ["conversation_id", "created_at"] })
|
|
59
|
+
.pipe(Stream.take(200), Stream.runCollect);
|
|
60
|
+
yield* Effect.log(`${mentions.length} mention(s)`);
|
|
61
|
+
|
|
62
|
+
// 4. Like each reply to the launch post.
|
|
63
|
+
for (const mention of mentions) {
|
|
64
|
+
if (mention.conversation_id !== postId) continue;
|
|
65
|
+
yield* X.likePost({ id: userId, tweet_id: mention.id });
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const Live = Layer.mergeAll(FetchHttpClient.layer, X.CredentialsFromEnv);
|
|
70
|
+
|
|
71
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Auth
|
|
75
|
+
|
|
76
|
+
`X_BEARER_TOKEN` is sent as `Authorization: Bearer`. It is either:
|
|
77
|
+
|
|
78
|
+
- an OAuth 2.0 user access token (Authorization Code with PKCE), which acts
|
|
79
|
+
as that user: posting, liking, DMs, `/2/users/me`; or
|
|
80
|
+
- the app-only bearer token from the developer console, for public reads,
|
|
81
|
+
streams and compliance jobs.
|
|
82
|
+
|
|
83
|
+
`X_BASE_URL` sets another API origin (default `https://api.x.com`).
|
|
84
|
+
`X.fromBearerToken({ bearerToken: Redacted.make(token) })` builds the same
|
|
85
|
+
layer from a value. A user access token expires (after 2 hours by default);
|
|
86
|
+
to refresh it, provide your own `X.Credentials` layer, whose effect runs on
|
|
87
|
+
every request. OAuth 1.0a request signing is not supported: every operation
|
|
88
|
+
also accepts one of the two bearer tokens.
|
|
89
|
+
|
|
90
|
+
## Pagination
|
|
91
|
+
|
|
92
|
+
Lists that answer `meta.next_token` are paginated: `.pages(input)` streams
|
|
93
|
+
each response and `.items(input)` streams the entries of `data`.
|
|
94
|
+
|
|
95
|
+
## Streams
|
|
96
|
+
|
|
97
|
+
The streaming endpoints (filtered stream `streamPosts`, the sample and
|
|
98
|
+
firehose streams, the compliance streams and `activityStream`) hold the
|
|
99
|
+
connection open and write one JSON object per line. Call them with
|
|
100
|
+
`.stream(input)`, which emits each message as X writes it:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
yield* X.streamPosts
|
|
104
|
+
.stream({ tweet_fields: ["created_at"] })
|
|
105
|
+
.pipe(Stream.take(10), Stream.runForEach((message) => Effect.log(message.data?.text)));
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Errors
|
|
109
|
+
|
|
110
|
+
A failed call fails with core's status classes (`BadRequest`,
|
|
111
|
+
`Unauthorized`, `Forbidden`, `NotFound`, `TooManyRequests`, ...). Their
|
|
112
|
+
`message` is X's problem `detail`, and `body.type` the problem URL
|
|
113
|
+
(`https://api.x.com/2/problems/resource-not-found`). A 200 can carry
|
|
114
|
+
`errors` beside `data`, for example an id in a batch lookup that does not
|
|
115
|
+
exist.
|
package/lib/.lazy.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"serviceDirs":["services"],"twins":["index.js"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{api$D as e,api$call as t,api$named as n,api$op as r,api$opPaginated as i,api$opStreaming as a,category$withParseError as o,config$Redacted as s,config$String as c,config$all as l,config$withDefault as u,pagination$paginateCursor as ee,retry$capped as te,retry$jittered as ne,retry$makeDefault as re,retry$throttlingFactory as ie,retry$throttlingOptions as ae,retry$transientFactory as d,retry$transientOptions as f,schema_lite_typed$TaggedError as p,schema_lite_typed$Unknown as m,trait$Body as h,trait$FormDataFile as g,trait$Header as _,trait$Http as v,trait$HttpBody as y,trait$IdempotencyToken as b,trait$KeyDictionary as x,trait$Label as S,trait$Query as C,trait$ResponseCode as w,trait$UnionCases as T,trait$applyErrorMatchers as E,trait$bodySymbol as D,trait$errorMatchersSymbol as O,trait$formDataFileSymbol as k,trait$getErrorMatchers as A,trait$headerSymbol as j,trait$httpBodySymbol as M,trait$httpSymbol as N,trait$keyDictionarySymbol as P,trait$labelSymbol as F,trait$querySymbol as I,trait$responseCodeSymbol as L,trait$unionCasesSymbol as R}from"@distilled.cloud/core/_bundle/base";import{errors$API_ERRORS as z,errors$BadGateway as B,errors$BadRequest as V,errors$ConfigError as H,errors$Conflict as U,errors$DEFAULT_ERRORS as W,errors$Forbidden as G,errors$GatewayTimeout as K,errors$HTTP_STATUS_MAP as q,errors$InternalServerError as J,errors$Locked as oe,errors$NotFound as se,errors$ServiceUnavailable as ce,errors$TooManyRequests as le,errors$Unauthorized as ue,errors$UnknownErrorFields as de,errors$UnprocessableEntity as fe,protocol_http$originFromConfig as pe,protocol_rest$BinaryResponse as me,protocol_rest$BinaryStream as he,protocol_rest$RawResponse as ge,protocol_rest$RawResponseRoot as _e,protocol_rest$SensitiveValue as ve,protocol_rest$rawResponseRootSymbol as ye,protocol_rest$rawResponseSymbol as be,protocol_rest$restProtocol as xe,protocol_rest$sensitiveValueSymbol as Se,protocol_rest$unknownErrorProps as Ce,schema_lite$Array as we,schema_lite$Boolean as Te,schema_lite$NullOr as Ee,schema_lite$Number as De,schema_lite$Record as Oe,schema_lite$String as ke,schema_lite$Struct as Ae,schema_lite$Unknown as je,schema_lite$at as Me,schema_lite$optional as Ne,schema_lite$suspend as Pe}from"@distilled.cloud/core/_bundle/rest";import*as Y from"effect/Context";import*as X from"effect/Effect";import*as Z from"effect/Layer";import*as Fe from"effect/Redacted";import{ndjson as Ie}from"@distilled.cloud/core/ndjson";const Q=`https://api.x.com`;var Credentials=class extends (/*@__PURE__*/ Y.Service()(`XCredentials`)){};const check=(e,t)=>{const n=pe(`X base URL`,t??`https://api.x.com`);return typeof n===`string`?X.succeed(X.succeed({bearerToken:e,baseUrl:n})):X.fail(n)};const Le=/*@__PURE__*/ Z.effect(Credentials,/*@__PURE__*/ l({bearerToken:/*@__PURE__*/ s(`X_BEARER_TOKEN`),baseUrl:/*@__PURE__*/ c(`X_BASE_URL`).pipe(/*@__PURE__*/ u(Q))}).pipe(/*@__PURE__*/ X.mapError(()=>new H({message:`X_BEARER_TOKEN environment variable is required`})),/*@__PURE__*/ X.flatMap(({bearerToken:e,baseUrl:t})=>check(e,t))));const fromBearerToken=e=>Z.effect(Credentials,check(e.bearerToken,e.baseUrl));var UnknownXError=class extends (/*@__PURE__*/ p()(`UnknownXError`,de)){};var XParseError=class extends (/*@__PURE__*/ p()(`XParseError`,{body:m,cause:m}).pipe(o)){};const $=z;const str=e=>typeof e===`string`?e:void 0;const errorEnvelope=e=>{if(e===null||typeof e!==`object`)return void 0;const t=e;const n=Array.isArray(t.errors)?t.errors[0]:void 0;const r=n!==null&&typeof n===`object`?str(n.message):void 0;const i=str(t.type);const a=i===void 0||i===`about:blank`?void 0:i;const o=str(t.detail)??r??str(t.title);return o===void 0&&a===void 0?void 0:{code:a,message:o}};const Re=/*@__PURE__*/ xe({credentials:/*@__PURE__*/ X.flatten(Credentials),baseUrl:e=>e.baseUrl,headers:e=>({Authorization:`Bearer ${Fe.value(e.bearerToken)}`}),errorEnvelope,unknownError:e=>new UnknownXError(Ce(e)),parseError:({body:e,cause:t})=>new XParseError({body:e,cause:t})});var Retry=class extends (/*@__PURE__*/ Y.Service()(`XRetry`)){};const policy=e=>X.provide(Z.succeed(Retry,e));const ze=/*@__PURE__*/ X.provide(/*@__PURE__*/ Z.succeed(Retry,{while:()=>false}));const Be=re;const Ve=ne;const He=te;const Ue=ae;const We=/*@__PURE__*/ policy(ie);const Ge=f;const Ke=/*@__PURE__*/ policy(d);export{we as Xc,Te as Yc,e as a,t as b,Credentials as credentials$Credentials,Le as credentials$CredentialsFromEnv,Q as credentials$DEFAULT_BASE_URL,fromBearerToken as credentials$fromBearerToken,z as errors$API_ERRORS,B as errors$BadGateway,V as errors$BadRequest,H as errors$ConfigError,U as errors$Conflict,W as errors$DEFAULT_ERRORS,G as errors$Forbidden,K as errors$GatewayTimeout,q as errors$HTTP_STATUS_MAP,J as errors$InternalServerError,oe as errors$Locked,se as errors$NotFound,ce as errors$ServiceUnavailable,le as errors$TooManyRequests,ue as errors$Unauthorized,UnknownXError as errors$UnknownXError,fe as errors$UnprocessableEntity,XParseError as errors$XParseError,$ as errors$XServiceErrors,Ee as fd,De as gd,Oe as hd,ke as jd,he as kc,Ae as kd,n as l,r as n,i as o,a as p,ee as pagination$paginateCursor,je as pd,Re as protocol$XProtocol,Me as rd,Retry as retry$Retry,He as retry$capped,Ve as retry$jittered,Be as retry$makeDefault,ze as retry$none,policy as retry$policy,We as retry$throttling,Ue as retry$throttlingOptions,Ke as retry$transient,Ge as retry$transientOptions,me as traits$BinaryResponse,h as traits$Body,g as traits$FormDataFile,_ as traits$Header,v as traits$Http,y as traits$HttpBody,b as traits$IdempotencyToken,x as traits$KeyDictionary,S as traits$Label,C as traits$Query,ge as traits$RawResponse,_e as traits$RawResponseRoot,w as traits$ResponseCode,ve as traits$SensitiveValue,T as traits$UnionCases,E as traits$applyErrorMatchers,D as traits$bodySymbol,O as traits$errorMatchersSymbol,k as traits$formDataFileSymbol,A as traits$getErrorMatchers,j as traits$headerSymbol,M as traits$httpBodySymbol,N as traits$httpSymbol,P as traits$keyDictionarySymbol,F as traits$labelSymbol,Ie as traits$ndjson,I as traits$querySymbol,ye as traits$rawResponseRootSymbol,be as traits$rawResponseSymbol,L as traits$responseCodeSymbol,Se as traits$sensitiveValueSymbol,R as traits$unionCasesSymbol,Ne as wd,Pe as xd};
|
|
2
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","names":["Schema.Unknown","Category.withParseError","Retries.makeDefault","Retries.jittered","Retries.capped","Retries.throttlingOptions","Retries.throttlingFactory","Retries.transientOptions","Retries.transientFactory","D","call","named","op","opPaginated","opStreaming","withParseError","Redacted$3","String$2","all$1","withDefault","paginateCursor","capped$1","jittered$1","makeDefault$1","throttlingFactory","throttlingOptions$1","transientFactory","transientOptions$1","TaggedError$1","Unknown$1","Body","FormDataFile","Header","Http","HttpBody","IdempotencyToken","KeyDictionary","Label","Query","ResponseCode","UnionCases","applyErrorMatchers","bodySymbol","errorMatchersSymbol","formDataFileSymbol","getErrorMatchers","headerSymbol","httpBodySymbol","httpSymbol","keyDictionarySymbol","labelSymbol","querySymbol","responseCodeSymbol","unionCasesSymbol","API_ERRORS","BadGateway","BadRequest","ConfigError","Conflict","DEFAULT_ERRORS","Forbidden","GatewayTimeout","HTTP_STATUS_MAP","InternalServerError","Locked","NotFound","ServiceUnavailable","TooManyRequests","Unauthorized","UnknownErrorFields","UnprocessableEntity","originFromConfig","BinaryResponse","BinaryStream","RawResponse","RawResponseRoot","SensitiveValue","rawResponseRootSymbol","rawResponseSymbol","restProtocol","sensitiveValueSymbol","unknownErrorProps","Array$1","Boolean","NullOr","Number","Record","String","Struct","Unknown","at","optional","suspend","Context","Effect","Layer","Redacted","DEFAULT_BASE_URL","origin","baseUrl","CredentialsFromEnv","bearerToken","config","XServiceErrors","value","body","rec","first","firstMessage","type","code","message","XProtocol","creds","info","optionsOrFactory","none","makeDefault","jittered","capped","throttlingOptions","throttling","transientOptions","transient","ndjson"],"sources":["../../src/credentials.ts","../../src/errors.ts","../../src/protocol.ts","../../src/retry.ts"],"mappings":"y5EA8BA,MAAaiG,EAAmB,oBAShC,IAAa,YAAb,eACwB,gBAAQ,QAA4C,CAAC,CAAC,cAAc,EAAA,AAAE,CAAC,EAG/F,MAAM,OACJ,EACA,IACsD,CACtD,MAAMC,EAAS3B,GAAiB,aAAc4B,GAAA,mBAA2B,EACzE,OAAO,OAAOD,IAAW,SACrBJ,EAAO,QAAQA,EAAO,QAAQ,CAAE,cAAa,QAASI,CAAO,CAAC,CAAC,EAC/DJ,EAAO,KAAKI,CAAM,CACxB,EAOA,MAAaE,GAA0E,gBAAM,OAC3F,YACc,gBAAiB,CAC7B,YAA2B,gBAAsB,gBAAgB,EACjE,QAAuB,gBAAoB,YAAY,CAAC,CAAC,KACzC,gBAAyBH,CAAgB,CACzD,CACF,CAAC,CAAC,CAAC,KACa,gBAAO,aACb,IAAIxC,EAAY,CAAE,QAAS,iDAAkD,CAAC,CACtF,EACc,gBAAO,SAAS,CAAE,cAAa,aAAc,MAAM4C,EAAaF,CAAO,CAAC,CACxF,CACF,EAGA,MAAa,gBAAmB,GAI9BJ,EAAM,OAAO,YAAa,MAAMO,EAAO,YAAaA,EAAO,OAAO,CAAC,ECnCrE,IAAa,cAAb,eACwB,gBAAkC,CAAC,CAAC,gBAAiBjC,EAAkB,EAAA,AAAE,CAAC,EAGlG,IAAa,YAAb,eACwB,gBAAgC,CAAC,CAAC,cAAe,CACrE,KAAMrE,EACN,MAAOA,CACT,CAAC,CAAC,CAAC,KAAKC,CAAuB,EAAA,AAAE,CAAC,EAOpC,MAAasG,EAAiBjD,ECpB9B,MAAM,IAAO,GAAwC,OAAOkD,IAAU,SAAWA,EAAQ,IAAA,GASzF,MAAM,cAAiB,GAAiD,CACtE,GAAIC,IAAS,MAAQ,OAAOA,IAAS,SAAU,OAAO,IAAA,GACtD,MAAMC,EAAMD,EACZ,MAAME,EAAQ,MAAM,QAAQD,EAAI,MAAM,EAAKA,EAAI,OAAO,GAAiB,IAAA,GACvE,MAAME,EACJD,IAAU,MAAQ,OAAOA,IAAU,SAC/B,IAAKA,EAAkC,OAAO,EAC9C,IAAA,GACN,MAAME,EAAO,IAAIH,EAAI,IAAI,EACzB,MAAMI,EAAOD,IAAS,IAAA,IAAaA,IAAS,cAAgB,IAAA,GAAYA,EACxE,MAAME,EAAU,IAAIL,EAAI,MAAM,GAAKE,GAAgB,IAAIF,EAAI,KAAK,EAChE,OAAOK,IAAY,IAAA,IAAaD,IAAS,IAAA,GAAY,IAAA,GAAY,CAAE,OAAM,SAAQ,CACnF,EAEA,MAAaE,GAA0B,iBAAa,CAGlD,YAA2B,gBAAO,QAAQ,WAAW,EACrD,QAAU,GAAUC,EAAM,QAC1B,QAAU,IAAW,CACnB,cAAe,UAAUjB,GAAS,MAAMiB,EAAM,WAAW,GAC3D,GACA,cACA,aAAe,GAAS,IAAI,cAAchC,GAAkBiC,CAAI,CAAC,EACjE,YAAa,CAAE,OAAM,WAAY,IAAI,YAAY,CAAE,OAAM,OAAM,CAAC,CAClE,CAAC,EC/CD,IAAa,MAAb,eAAyC,gBAAQ,QAAuB,CAAC,CAAC,QAAQ,EAAA,AAAE,CAAC,EAGrF,MAAa,OAOR,GAAwCpB,EAAO,QAAQC,EAAM,QAAQ,MAAOoB,CAAgB,CAAC,EAGlG,MAAaC,GAE+C,gBAAO,QACnD,gBAAM,QAAQ,MAAO,CAAE,UAAa,KAAM,CAAC,CAC3D,EAOA,MAAaC,GAAuBnH,GAEpC,MAAaoH,GAAWnH,GACxB,MAAaoH,GAASnH,GAGtB,MAAaoH,GAA6BnH,GAG1C,MAAaoH,GAE+C,qBAAOnH,EAAyB,EAG5F,MAAaoH,GAA4BnH,EAGzC,MAAaoH,GAE+C,qBAAOnH,CAAwB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
/** X API v2 (the spec's `servers` entry). */
|
|
7
|
+
export declare const DEFAULT_BASE_URL = "https://api.x.com";
|
|
8
|
+
export interface Config {
|
|
9
|
+
/** OAuth 2.0 user access token or app-only bearer token. */
|
|
10
|
+
readonly bearerToken: Redacted.Redacted<string>;
|
|
11
|
+
/** API origin, without a trailing slash. */
|
|
12
|
+
readonly baseUrl: string;
|
|
13
|
+
}
|
|
14
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "XCredentials", Effect.Effect<Config, never, never>>;
|
|
15
|
+
export declare class Credentials extends /*@__PURE__*/ Credentials_base {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reads `X_BEARER_TOKEN` (required) and `X_BASE_URL` (optional), once: when
|
|
19
|
+
* the layer is built. A missing token or a bad base URL fails the layer
|
|
20
|
+
* with `ConfigError`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CredentialsFromEnv: Layer.Layer<Credentials, ConfigError>;
|
|
23
|
+
/** Credentials from a redacted bearer token and an optional base URL. */
|
|
24
|
+
export declare const fromBearerToken: (config: {
|
|
25
|
+
readonly bearerToken: Redacted.Redacted<string>;
|
|
26
|
+
readonly baseUrl?: string;
|
|
27
|
+
}) => Layer.Layer<Credentials, ConfigError>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sources":["../src/credentials.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C,6CAA6C;AAC7C,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AAEpD,MAAM,WAAW,MAAM;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;;AAED,qBAAa,WACX,SAAQ,aAAa,CAAC,gBAAqE;CAAG;AAahG;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAapE,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,eAAe,WAAY;IACtC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAC8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { credentials$Credentials as Credentials, credentials$CredentialsFromEnv as CredentialsFromEnv, credentials$DEFAULT_BASE_URL as DEFAULT_BASE_URL, credentials$fromBearerToken as fromBearerToken } from "./_bundle/sdk.js";
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X-specific error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the shared HTTP status errors from core and adds the X
|
|
5
|
+
* fallback and parse errors.
|
|
6
|
+
*
|
|
7
|
+
* X answers a failed call with `application/problem+json`:
|
|
8
|
+
* `{ type, title, detail, status }`, where `type` is a problem URL such as
|
|
9
|
+
* `https://api.x.com/2/problems/resource-not-found` (or `about:blank` for a
|
|
10
|
+
* bare 401/429) and `detail` the message. The spec declares only a
|
|
11
|
+
* `default` error response, so failures map to core's status classes; the
|
|
12
|
+
* problem `type` is the code of an {@link UnknownXError}.
|
|
13
|
+
*
|
|
14
|
+
* A 200 can also carry `errors` beside `data` (a post in a batch lookup
|
|
15
|
+
* that does not exist): that is part of the operation's output.
|
|
16
|
+
*/
|
|
17
|
+
export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
|
|
18
|
+
export type { DefaultErrors } from "@distilled.cloud/core/errors";
|
|
19
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
20
|
+
declare const UnknownXError_base: Schema.TaggedErrorClass<"UnknownXError", {
|
|
21
|
+
status: import("effect/Schema").Number;
|
|
22
|
+
code: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
23
|
+
message: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
24
|
+
body: import("effect/Schema").Unknown;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Unknown X error -- returned when an error response matches
|
|
28
|
+
* neither an operation's typed errors nor a shared HTTP status class.
|
|
29
|
+
*/
|
|
30
|
+
export declare class UnknownXError extends /*@__PURE__*/ UnknownXError_base {
|
|
31
|
+
}
|
|
32
|
+
declare const XParseError_base: Schema.TaggedErrorClass<"XParseError", {
|
|
33
|
+
readonly body: import("effect/Schema").Unknown;
|
|
34
|
+
readonly cause: import("effect/Schema").Unknown;
|
|
35
|
+
}> & (new (...args: any[]) => {
|
|
36
|
+
"@distilled.cloud/error/categories": {
|
|
37
|
+
ParseError: true;
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
/** A 2xx response that does not match the operation's output schema. */
|
|
41
|
+
export declare class XParseError extends /*@__PURE__*/ XParseError_base {
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The errors declared on the X service: any operation can return them,
|
|
45
|
+
* and every generated operation lists them as its `serviceErrors`. Today that
|
|
46
|
+
* is each of core's status classes (400, 401, 403, 404, 409, 429, the 5xx ...).
|
|
47
|
+
*/
|
|
48
|
+
export declare const XServiceErrors: readonly [typeof import("@distilled.cloud/core/errors").Unauthorized, typeof import("@distilled.cloud/core/errors").Forbidden, typeof import("@distilled.cloud/core/errors").NotFound, typeof import("@distilled.cloud/core/errors").BadRequest, typeof import("@distilled.cloud/core/errors").Conflict, typeof import("@distilled.cloud/core/errors").UnprocessableEntity, typeof import("@distilled.cloud/core/errors").TooManyRequests, typeof import("@distilled.cloud/core/errors").Locked, typeof import("@distilled.cloud/core/errors").InternalServerError, typeof import("@distilled.cloud/core/errors").BadGateway, typeof import("@distilled.cloud/core/errors").ServiceUnavailable, typeof import("@distilled.cloud/core/errors").GatewayTimeout];
|
|
49
|
+
export type XServiceError = InstanceType<(typeof XServiceErrors)[number]>;
|
|
50
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,KAAK,MAAM,MAAM,yCAAyC,CAAC;;;;;;;AAElE;;;GAGG;AACH,qBAAa,aACX,SAAQ,aAAa,CAAC,kBAAwE;CAAG;;;;;;;;;AAEnG,wEAAwE;AACxE,qBAAa,WACX,SAAQ,aAAa,CAAC,gBAGU;CAAG;AAErC;;;;GAIG;AACH,eAAO,MAAM,cAAc,+tBAAa,CAAC;AACzC,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { errors$API_ERRORS as API_ERRORS, errors$BadGateway as BadGateway, errors$BadRequest as BadRequest, errors$ConfigError as ConfigError, errors$Conflict as Conflict, errors$DEFAULT_ERRORS as DEFAULT_ERRORS, errors$Forbidden as Forbidden, errors$GatewayTimeout as GatewayTimeout, errors$HTTP_STATUS_MAP as HTTP_STATUS_MAP, errors$InternalServerError as InternalServerError, errors$Locked as Locked, errors$NotFound as NotFound, errors$ServiceUnavailable as ServiceUnavailable, errors$TooManyRequests as TooManyRequests, errors$Unauthorized as Unauthorized, errors$UnknownXError as UnknownXError, errors$UnprocessableEntity as UnprocessableEntity, errors$XParseError as XParseError, errors$XServiceErrors as XServiceErrors } from "./_bundle/sdk.js";
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/x -- X API SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy model
|
|
5
|
+
* that `scripts/convert.ts` converts from the OpenAPI document mirrored at
|
|
6
|
+
* `specs/spec-mirror-x/specs/openapi.json`. Everything else in this
|
|
7
|
+
* folder is hand-written.
|
|
8
|
+
*
|
|
9
|
+
* X API v2 is one service, so its operations are exported straight off
|
|
10
|
+
* the package root.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import * as X from "@distilled.cloud/x";
|
|
15
|
+
*
|
|
16
|
+
* const me = yield* X.getUsersMe({});
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export * from "./credentials.ts";
|
|
20
|
+
export * from "./errors.ts";
|
|
21
|
+
export * as T from "./traits.ts";
|
|
22
|
+
export { XProtocol, type XOpError, type XOpContext } from "./protocol.ts";
|
|
23
|
+
export { paginateCursor } from "./pagination.ts";
|
|
24
|
+
export * as Retry from "./retry.ts";
|
|
25
|
+
export * from "./services/x.ts";
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,iBAAiB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./credentials.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * as T from "./traits.js";
|
|
4
|
+
export { XProtocol } from "./protocol.js";
|
|
5
|
+
export { paginateCursor } from "./pagination.js";
|
|
6
|
+
export * as Retry from "./retry.js";
|
|
7
|
+
export * from "./services/x.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./credentials.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * as T from "./traits.js";
|
|
4
|
+
export { XProtocol } from "./protocol.js";
|
|
5
|
+
export { paginateCursor } from "./pagination.js";
|
|
6
|
+
export * as Retry from "./retry.js";
|
|
7
|
+
export * from "./services.lazy/x.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,SAAS,EAAkC,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X pagination -- hand-written.
|
|
3
|
+
*
|
|
4
|
+
* X API v2 lists answer `meta.next_token` beside the items in `data` and take
|
|
5
|
+
* it back as `pagination_token` (or `next_token` on search and counts);
|
|
6
|
+
* `patches/pagination.json` stamps that on each list, and generated
|
|
7
|
+
* operations pass core's {@link paginateCursor} strategy to
|
|
8
|
+
* `API.makePaginated`.
|
|
9
|
+
*/
|
|
10
|
+
export { paginateCursor } from "@distilled.cloud/core/pagination";
|
|
11
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pagination$paginateCursor as paginateCursor } from "./_bundle/sdk.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ErrorOf } from "@distilled.cloud/core/protocol";
|
|
2
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import { Credentials } from "./credentials.ts";
|
|
4
|
+
import { XParseError, UnknownXError, type XServiceError } from "./errors.ts";
|
|
5
|
+
/**
|
|
6
|
+
* What every generated X operation fails with besides its own errors: the
|
|
7
|
+
* errors declared on the service, and the errors declared on the protocol.
|
|
8
|
+
* Nobody lists the protocol's: its type carries what its code fails with (a
|
|
9
|
+
* response that does not match its schema, a failed response nothing declares,
|
|
10
|
+
* core's REST errors, and what resolving the credentials fails with).
|
|
11
|
+
* Generated service files annotate operations with `API.OperationMethod<I, O,
|
|
12
|
+
* XOpError, XOpContext>` explicitly so the compiler never infers
|
|
13
|
+
* these back out of the schema generics.
|
|
14
|
+
*/
|
|
15
|
+
export type XOpError = XServiceError | ErrorOf<typeof XProtocol>;
|
|
16
|
+
/** Context (requirements) shared by every generated X operation. */
|
|
17
|
+
export type XOpContext = Credentials | HttpClient.HttpClient;
|
|
18
|
+
export declare const XProtocol: import("@distilled.cloud/core/protocol").Protocol<UnknownXError | XParseError | import("@distilled.cloud/core/protocol-rest").RestProtocolError, Credentials>;
|
|
19
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAkB9D,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC,OAAO,SAAS,CAAC,CAAC;AAEjE,oEAAoE;AACpE,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAyB7D,eAAO,MAAM,SAAS,+JAWpB,CAAC"}
|
package/lib/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { protocol$XProtocol as XProtocol } from "./_bundle/sdk.js";
|
package/lib/retry.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as Retries from "@distilled.cloud/core/retry";
|
|
2
|
+
/**
|
|
3
|
+
* X retry surface -- a veneer over `@distilled.cloud/core/retry`.
|
|
4
|
+
*
|
|
5
|
+
* The `Retry` service tag is threaded into every generated operation via
|
|
6
|
+
* `API.make({ retry: Retry })`, so a caller-installed policy applies to all
|
|
7
|
+
* X calls below it and core's `makeDefault` is the fallback when none is
|
|
8
|
+
* provided.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import * as X from "@distilled.cloud/x";
|
|
13
|
+
*
|
|
14
|
+
* myEffect.pipe(X.Retry.transient);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
export type Options = Retries.Options;
|
|
20
|
+
export type Factory = Retries.Factory;
|
|
21
|
+
export type Policy = Retries.Policy;
|
|
22
|
+
declare const Retry_base: Context.ServiceClass<Retry, "XRetry", Retries.Policy>;
|
|
23
|
+
/** Context tag for configuring retry behavior of X API calls. */
|
|
24
|
+
export declare class Retry extends /*@__PURE__*/ Retry_base {
|
|
25
|
+
}
|
|
26
|
+
/** Provides a custom retry policy to every X API call below it. */
|
|
27
|
+
export declare const policy: {
|
|
28
|
+
(options: Options): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
29
|
+
(factory: Factory): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
30
|
+
};
|
|
31
|
+
/** Disables all automatic retries. */
|
|
32
|
+
export declare const none: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
33
|
+
/**
|
|
34
|
+
* The default retry policy (core's): transient/throttling/retryable errors,
|
|
35
|
+
* capped exponential backoff with jitter, server `retryAfter` hints honored
|
|
36
|
+
* with precedence.
|
|
37
|
+
*/
|
|
38
|
+
export declare const makeDefault: Factory;
|
|
39
|
+
export declare const jittered: <Error, Env>(self: import("effect/Schedule").Schedule<unknown, unknown, Error, Env>) => import("effect/Schedule").Schedule<unknown, unknown, Error, Env>;
|
|
40
|
+
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>;
|
|
41
|
+
/** Retry options that retry all throttling errors indefinitely. */
|
|
42
|
+
export declare const throttlingOptions: Options;
|
|
43
|
+
/** Retries all throttling errors indefinitely (honoring server hints). */
|
|
44
|
+
export declare const throttling: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
45
|
+
/** Retry options that retry all transient errors indefinitely. */
|
|
46
|
+
export declare const transientOptions: Options;
|
|
47
|
+
/** Retries all transient errors indefinitely. */
|
|
48
|
+
export declare const transient: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AACtC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AACtC,MAAM,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;;AAEpC,iEAAiE;AACjE,qBAAa,KAAM,SAAQ,aAAa,CAAC,UAA0C;CAAG;AAEtF,mEAAmE;AACnE,eAAO,MAAM,MAAM,EAAE;IACnB,CACE,OAAO,EAAE,OAAO,GACf,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACvF,CACE,OAAO,EAAE,OAAO,GACf,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;CACU,CAAC;AAEpG,sCAAsC;AACtC,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACzB,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,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,CAAmD,CAAC;AAE9F,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,OAAkC,CAAC;AAElE,iDAAiD;AACjD,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,CAAkD,CAAC"}
|
package/lib/retry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { retry$Retry as Retry, retry$capped as capped, retry$jittered as jittered, retry$makeDefault as makeDefault, retry$none as none, retry$policy as policy, retry$throttling as throttling, retry$throttlingOptions as throttlingOptions, retry$transient as transient, retry$transientOptions as transientOptions } from "./_bundle/sdk.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../../src/services/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as x from "./x.js";
|