@syndroo/sdk 0.4.0-rc.1
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 +202 -0
- package/NOTICE +9 -0
- package/README.md +172 -0
- package/dist/client.d.ts +109 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +354 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +104 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +162 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +45 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +298 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +159 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://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 2026 Grant Dai
|
|
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
|
+
https://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.
|
|
202
|
+
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Syndroo
|
|
2
|
+
Copyright 2026 Grant Dai
|
|
3
|
+
|
|
4
|
+
This distribution is part of the Syndroo project and is licensed under the
|
|
5
|
+
Apache License, Version 2.0. See `LICENSE` for the full text.
|
|
6
|
+
|
|
7
|
+
The published package has no runtime dependencies. It uses the global `fetch`
|
|
8
|
+
implementation of the Node.js runtime and therefore bundles no third-party
|
|
9
|
+
code.
|
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @syndroo/sdk
|
|
2
|
+
|
|
3
|
+
A thin TypeScript HTTP client for one deployed
|
|
4
|
+
[Syndroo](https://github.com/Syndroo/syndroo) instance.
|
|
5
|
+
|
|
6
|
+
The SDK wraps the documented `/v1` HTTP contract and adds no server behavior. It
|
|
7
|
+
has no runtime dependencies, ships no bundler or platform SDK, and never
|
|
8
|
+
reconciles your data on its own.
|
|
9
|
+
|
|
10
|
+
```text
|
|
11
|
+
your app / CLI / CI -> @syndroo/sdk -> Syndroo HTTP API -> Worker
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
Node.js 22 or newer. The client uses the runtime's global `fetch`, `AbortSignal`,
|
|
17
|
+
and Web Streams; there is no polyfill and no dependency to install.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @syndroo/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { SyndrooClient } from "@syndroo/sdk";
|
|
27
|
+
|
|
28
|
+
const syndroo = new SyndrooClient({
|
|
29
|
+
baseUrl: process.env.SYNDROO_BASE_URL!,
|
|
30
|
+
apiKey: process.env.SYNDROO_API_KEY!,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const receipt = await syndroo.posts.create(
|
|
34
|
+
{
|
|
35
|
+
content: "We just shipped a new release.",
|
|
36
|
+
platforms: ["bluesky"],
|
|
37
|
+
},
|
|
38
|
+
{ idempotencyKey: "release-announcement-001" },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const post = await syndroo.posts.get(receipt.id);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Two boundaries
|
|
45
|
+
|
|
46
|
+
**A create receipt is not a delivery.** `posts.create` returns an acceptance
|
|
47
|
+
result. HTTP `202` means the request was accepted for processing, and `queued`
|
|
48
|
+
means "waiting for a publication job". Nothing has reached a platform yet. Read
|
|
49
|
+
the post back and check each publication before telling a user that a post is
|
|
50
|
+
live:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const post = await syndroo.posts.wait(receipt.id, { timeoutMs: 60_000 });
|
|
54
|
+
|
|
55
|
+
if (post.status === "published") {
|
|
56
|
+
// Every selected platform confirmed.
|
|
57
|
+
} else if (post.status === "partial") {
|
|
58
|
+
// Some platforms confirmed; inspect each publication and do not resend the
|
|
59
|
+
// successful ones.
|
|
60
|
+
} else {
|
|
61
|
+
// failed: read errorCode, errorMessage, and errorAmbiguous per publication.
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
A `failed` publication with `errorAmbiguous: true` may still have been accepted
|
|
66
|
+
by the platform. Check the platform account by hand; do not resend that content
|
|
67
|
+
automatically.
|
|
68
|
+
|
|
69
|
+
**The API key belongs in a trusted environment.** Keep it in a server, CLI, or
|
|
70
|
+
CI credential store. Do not put it in a static page, a browser bundle, or a
|
|
71
|
+
`NEXT_PUBLIC_*` variable: `SYNDROO_API_KEY` can publish, and anyone who reads the
|
|
72
|
+
page can use it. Platform credentials stay in the Worker's secrets and are never
|
|
73
|
+
part of this client. The unauthenticated `/health` call is the only request that
|
|
74
|
+
sends no `Authorization` header.
|
|
75
|
+
|
|
76
|
+
## API
|
|
77
|
+
|
|
78
|
+
### `new SyndrooClient(options)`
|
|
79
|
+
|
|
80
|
+
| Option | Default | Meaning |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `baseUrl` | required | Origin of the instance, for example `https://syndroo.example.com`. `https` is required outside loopback; `http` is accepted for `localhost` and `127.0.0.1`, or anywhere with `allowInsecureHttp: true`. |
|
|
83
|
+
| `apiKey` | required | Instance API key, sent as a Bearer token. |
|
|
84
|
+
| `timeoutMs` | `30000` | Per-request deadline. |
|
|
85
|
+
| `waitTimeoutMs` | `60000` | Default total deadline for `posts.wait`. |
|
|
86
|
+
| `maxResponseBytes` | `8388608` | Response size limit. |
|
|
87
|
+
| `allowInsecureHttp` | `false` | Permit plaintext `http://` for a non-loopback host. |
|
|
88
|
+
|
|
89
|
+
Configuration problems throw `SyndrooConfigError` from the constructor, before
|
|
90
|
+
any request is made.
|
|
91
|
+
|
|
92
|
+
### Methods
|
|
93
|
+
|
|
94
|
+
| Call | HTTP | Notes |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `syndroo.health()` | `GET /health` | Unauthenticated reachability check. Proves the URL answers, not that the key or the platform credentials work. |
|
|
97
|
+
| `syndroo.posts.create(input, options?)` | `POST /v1/posts` | One request, never retried. `options.idempotencyKey` makes a retry safe. |
|
|
98
|
+
| `syndroo.posts.get(id, options?)` | `GET /v1/posts/<id>` | Read-only; safe to repeat. |
|
|
99
|
+
| `syndroo.posts.list({ limit }, options?)` | `GET /v1/posts` | `limit` is 1-100. |
|
|
100
|
+
| `syndroo.posts.wait(id, options?)` | repeated `GET /v1/posts/<id>` | Reads until `published`, `partial`, or `failed`, or until `timeoutMs`. |
|
|
101
|
+
|
|
102
|
+
`create` accepts `content`, `platforms`, optional per-platform `overrides`, and
|
|
103
|
+
an optional `scheduledAt`. The client validates the structure and sends your
|
|
104
|
+
object unchanged; it does not rewrite, trim, or truncate content.
|
|
105
|
+
Platform-specific length limits are enforced by the server and surface as typed
|
|
106
|
+
errors or as publication failures.
|
|
107
|
+
|
|
108
|
+
`wait` options: `timeoutMs` (total budget), `pollIntervalMs` (default `250`),
|
|
109
|
+
`maxPollIntervalMs` (default `2000`), and `signal`. Reading never creates,
|
|
110
|
+
cancels, or resends anything, so a wait timeout leaves the server-side work
|
|
111
|
+
running; `SyndrooWaitTimeoutError` keeps `postId`, `lastStatus`, `lastPost`, and
|
|
112
|
+
`lastError` so you can resume instead of starting over.
|
|
113
|
+
|
|
114
|
+
`scheduledAt` is submitted to the server, so a scheduled post does not depend on
|
|
115
|
+
this process staying alive.
|
|
116
|
+
|
|
117
|
+
## Errors
|
|
118
|
+
|
|
119
|
+
Every failure is a `SyndrooError`. Use `isSyndrooError()` to narrow, or the
|
|
120
|
+
exported classes:
|
|
121
|
+
|
|
122
|
+
| Class | Raised when |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `SyndrooConfigError` | The client configuration is unusable. No request is made. |
|
|
125
|
+
| `SyndrooValidationError` | An argument cannot become a valid request. No request is made. |
|
|
126
|
+
| `SyndrooApiError` | Syndroo answered with a documented error envelope. Carries `status`, `code`, `retryAfterMs`, and `retryable`. |
|
|
127
|
+
| `SyndrooResponseError` | The answer was not the documented JSON contract: not JSON, missing fields, or over the size limit. |
|
|
128
|
+
| `SyndrooAbortError` | You aborted through an `AbortSignal`. |
|
|
129
|
+
| `SyndrooTimeoutError` | The deadline elapsed before the response was received. |
|
|
130
|
+
| `SyndrooNetworkError` | No HTTP response arrived; `networkCode` carries codes such as `ECONNREFUSED`. |
|
|
131
|
+
| `SyndrooWaitTimeoutError` | `posts.wait` hit its deadline before a terminal status. |
|
|
132
|
+
|
|
133
|
+
Server codes such as `UNAUTHORIZED` (401), `POST_NOT_FOUND` (404),
|
|
134
|
+
`IDEMPOTENCY_CONFLICT` (409), `PLATFORM_NOT_CONFIGURED` (422), and
|
|
135
|
+
`SERVICE_UNAVAILABLE` (503) appear on `SyndrooApiError.code`.
|
|
136
|
+
|
|
137
|
+
`requestMayHaveBeenApplied` is the flag that decides whether a resend is safe. It
|
|
138
|
+
is `true` when a write may already have reached Syndroo: a timeout, an abort, a
|
|
139
|
+
network failure, or a 5xx after a `POST`. A 4xx is a decision, so it is `false`.
|
|
140
|
+
When it is `true`, look the post up with `posts.list` or repeat the identical
|
|
141
|
+
request with the same `Idempotency-Key` — never with a new key and never with
|
|
142
|
+
different content.
|
|
143
|
+
|
|
144
|
+
## Timeouts, aborts, and retries
|
|
145
|
+
|
|
146
|
+
- The SDK performs exactly one HTTP request per call. It never retries a write.
|
|
147
|
+
A silent retry without a stable idempotency key can duplicate a post.
|
|
148
|
+
- A timed-out `POST` is reported as an unknown outcome, not as "not created".
|
|
149
|
+
- `AbortSignal` is supported on every method; aborting a read is always safe.
|
|
150
|
+
- API errors carry no retry attempt, only `retryable` and `retryAfterMs`, so your
|
|
151
|
+
own policy decides.
|
|
152
|
+
- `posts.wait` absorbs transient failures (network errors, timeouts, 5xx, 429)
|
|
153
|
+
with bounded exponential backoff, honours `Retry-After`, and stops at the
|
|
154
|
+
first authentication, validation, or "not found" answer instead of polling.
|
|
155
|
+
|
|
156
|
+
## Redirects
|
|
157
|
+
|
|
158
|
+
The client never follows redirects. A `3xx` answer becomes a `SyndrooApiError`
|
|
159
|
+
with code `REDIRECT_NOT_FOLLOWED`, so the `Authorization` header can never be
|
|
160
|
+
forwarded to another host. Point `baseUrl` at the final API origin, for example
|
|
161
|
+
the `https://...workers.dev` URL of the deployment.
|
|
162
|
+
|
|
163
|
+
## Not in this version
|
|
164
|
+
|
|
165
|
+
The SDK is deliberately small. There is no preview, approval, retry, or cancel
|
|
166
|
+
endpoint, no dashboard, no media upload, and no OAuth handling, because the
|
|
167
|
+
server does not offer those operations yet. Direct HTTP remains the fallback for
|
|
168
|
+
anything this client does not cover.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SyndrooClient` — a thin, dependency-free client for the Syndroo HTTP API.
|
|
3
|
+
*
|
|
4
|
+
* The client wraps the documented `/v1` contract. It deliberately does not add
|
|
5
|
+
* server features: it creates, reads, lists, and waits, and it never invents a
|
|
6
|
+
* delivery result that the server did not report.
|
|
7
|
+
*/
|
|
8
|
+
import { type TransportConfig } from "./http.js";
|
|
9
|
+
import { type CreatePostInput, type HealthStatus, type PostDetail, type PostReceipt, type PostSummary } from "./types.js";
|
|
10
|
+
export declare const DEFAULT_WAIT_TIMEOUT_MS = 60000;
|
|
11
|
+
export declare const DEFAULT_POLL_INTERVAL_MS = 250;
|
|
12
|
+
export declare const DEFAULT_MAX_POLL_INTERVAL_MS = 2000;
|
|
13
|
+
export interface SyndrooClientOptions {
|
|
14
|
+
/** Origin of a deployed Syndroo instance, for example `https://syndroo.example.com`. */
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
/**
|
|
17
|
+
* The instance API key. Keep it in a server, CLI, or CI credential store;
|
|
18
|
+
* never in a static page or a `NEXT_PUBLIC_*` variable.
|
|
19
|
+
*/
|
|
20
|
+
apiKey: string;
|
|
21
|
+
/** Per-request deadline. Defaults to 30000ms. */
|
|
22
|
+
timeoutMs?: number | undefined;
|
|
23
|
+
/** Total deadline for `posts.wait`. Defaults to 60000ms. */
|
|
24
|
+
waitTimeoutMs?: number | undefined;
|
|
25
|
+
/** Maximum accepted response size in bytes. Defaults to 8 MiB. */
|
|
26
|
+
maxResponseBytes?: number | undefined;
|
|
27
|
+
/** Allow plaintext `http://` for a non-loopback host. Off by default. */
|
|
28
|
+
allowInsecureHttp?: boolean | undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface RequestOptions {
|
|
31
|
+
signal?: AbortSignal | undefined;
|
|
32
|
+
/** Per-request deadline in milliseconds. */
|
|
33
|
+
timeoutMs?: number | undefined;
|
|
34
|
+
}
|
|
35
|
+
export interface CreatePostOptions extends RequestOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Stable key for one logical post. Reuse the same key when retrying the same
|
|
38
|
+
* request; Syndroo replays the original result, and different content under
|
|
39
|
+
* the same key is rejected with HTTP 409.
|
|
40
|
+
*/
|
|
41
|
+
idempotencyKey?: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
export interface ListPostsOptions extends RequestOptions {
|
|
44
|
+
/** 1-100, defaults to the server default. */
|
|
45
|
+
limit?: number | undefined;
|
|
46
|
+
}
|
|
47
|
+
export interface WaitOptions extends RequestOptions {
|
|
48
|
+
/** Total wait budget in milliseconds, not a per-request timeout. */
|
|
49
|
+
timeoutMs?: number | undefined;
|
|
50
|
+
/** First interval between status reads. Defaults to 250ms. */
|
|
51
|
+
pollIntervalMs?: number | undefined;
|
|
52
|
+
/** Upper bound for the backoff. Defaults to 2000ms. */
|
|
53
|
+
maxPollIntervalMs?: number | undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Client for one Syndroo instance.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const syndroo = new SyndrooClient({
|
|
60
|
+
* baseUrl: process.env.SYNDROO_BASE_URL!,
|
|
61
|
+
* apiKey: process.env.SYNDROO_API_KEY!,
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* const receipt = await syndroo.posts.create(
|
|
65
|
+
* { content: "We just shipped a new release.", platforms: ["bluesky"] },
|
|
66
|
+
* { idempotencyKey: "release-announcement-001" },
|
|
67
|
+
* );
|
|
68
|
+
*
|
|
69
|
+
* const post = await syndroo.posts.get(receipt.id);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare class SyndrooClient {
|
|
73
|
+
#private;
|
|
74
|
+
readonly posts: PostsResource;
|
|
75
|
+
constructor(options: SyndrooClientOptions);
|
|
76
|
+
/**
|
|
77
|
+
* `GET /health`. Syndroo's health endpoint is unauthenticated, so the client
|
|
78
|
+
* sends no Authorization header here. It proves reachability, not that the
|
|
79
|
+
* API key is correct or that the deployment can publish.
|
|
80
|
+
*/
|
|
81
|
+
health(options?: RequestOptions): Promise<HealthStatus>;
|
|
82
|
+
}
|
|
83
|
+
/** The posts resource: create, read, list, and bounded status wait. */
|
|
84
|
+
export declare class PostsResource {
|
|
85
|
+
#private;
|
|
86
|
+
constructor(config: TransportConfig, defaultWaitTimeoutMs: number);
|
|
87
|
+
/**
|
|
88
|
+
* `POST /v1/posts`. The returned receipt is an acceptance result: HTTP 202
|
|
89
|
+
* means the request is queued for processing, not that any platform
|
|
90
|
+
* published it. The SDK performs exactly one request and never retries it.
|
|
91
|
+
*/
|
|
92
|
+
create(input: CreatePostInput, options?: CreatePostOptions): Promise<PostReceipt>;
|
|
93
|
+
/** `GET /v1/posts/<id>`. Read-only, so repeating it is safe. */
|
|
94
|
+
get(id: string, options?: RequestOptions): Promise<PostDetail>;
|
|
95
|
+
/** `GET /v1/posts`, newest first. */
|
|
96
|
+
list(options?: ListPostsOptions): Promise<PostSummary[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Reads the post until it reaches a terminal status (`published`, `partial`,
|
|
99
|
+
* or `failed`) or the wait budget runs out.
|
|
100
|
+
*
|
|
101
|
+
* Waiting is read-only: it never creates, cancels, or resends a post, so a
|
|
102
|
+
* timeout leaves the server-side work running and only stops this client from
|
|
103
|
+
* waiting. On timeout it throws `SyndrooWaitTimeoutError`, which keeps the
|
|
104
|
+
* post id, the last status, and the last transient error so a caller can
|
|
105
|
+
* resume instead of starting over.
|
|
106
|
+
*/
|
|
107
|
+
wait(id: string, options?: WaitOptions): Promise<PostDetail>;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,EAML,KAAK,eAAe,EACrB,MAAM,WAAW,CAAC;AACnB,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,WAAW,EAChB,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAC9C,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,4BAA4B,OAAQ,CAAC;AAIlD,MAAM,WAAW,oBAAoB;IACnC,wFAAwF;IACxF,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,4DAA4D;IAC5D,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,yEAAyE;IACzE,iBAAiB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IACjC,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,8DAA8D;IAC9D,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,aAAa;;IACxB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAI9B,YAAY,OAAO,EAAE,oBAAoB,EAYxC;IAED;;;;OAIG;IACG,MAAM,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAUhE;CACF;AAED,uEAAuE;AACvE,qBAAa,aAAa;;IAIxB,YAAY,MAAM,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,EAGhE;IAED;;;;OAIG;IACG,MAAM,CACV,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,WAAW,CAAC,CAmBtB;IAED,gEAAgE;IAC1D,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAUvE;IAED,qCAAqC;IAC/B,IAAI,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAYjE;IAED;;;;;;;;;OASG;IACG,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAgErE;CACF"}
|