@distilled.cloud/tailscale 0.0.0-stage → 1.0.0-rc.19
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 +85 -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 +52 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +1 -0
- package/lib/errors.d.ts +25 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +1 -0
- package/lib/index.d.ts +34 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.lazy.js +8 -0
- package/lib/index.lazy.js.map +1 -0
- package/lib/pagination.d.ts +2 -0
- package/lib/pagination.d.ts.map +1 -0
- package/lib/pagination.js +1 -0
- package/lib/protocol.d.ts +17 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +1 -0
- package/lib/retry.d.ts +12 -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/tailscale.d.ts +2148 -0
- package/lib/services/tailscale.d.ts.map +1 -0
- package/lib/services/tailscale.js +136 -0
- package/lib/services/tailscale.js.map +1 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/tailscale.js +4 -0
- package/lib/traits.d.ts +3 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +1 -0
- package/package.json +87 -3
- package/src/credentials.ts +228 -0
- package/src/errors.ts +39 -0
- package/src/index.ts +40 -0
- package/src/pagination.ts +1 -0
- package/src/protocol.ts +120 -0
- package/src/retry.ts +28 -0
- package/src/services/index.ts +2 -0
- package/src/services/tailscale.ts +6000 -0
- package/src/traits.ts +37 -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,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @distilled.cloud/tailscale
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Effect-native Tailscale SDK, generated from the [Tailscale API OpenAPI document](https://api.tailscale.com/api/v2?outputOpenApiSchema=true). Operations cover devices, auth keys, DNS, policy files, users, webhooks, services and the rest of the `/api/v2` surface, with typed inputs, outputs and API errors.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @distilled.cloud/tailscale effect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Effect, Layer } from "effect";
|
|
15
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
16
|
+
import * as Tailscale from "@distilled.cloud/tailscale";
|
|
17
|
+
|
|
18
|
+
const program = Effect.gen(function* () {
|
|
19
|
+
const policy = yield* Tailscale.getPolicyFile({ tailnet: "-" });
|
|
20
|
+
return policy.eTag;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const Live = Tailscale.CredentialsFromEnv.pipe(
|
|
24
|
+
Layer.provideMerge(FetchHttpClient.layer),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Auth
|
|
31
|
+
|
|
32
|
+
`CredentialsFromEnv` reads these on every resolution, through the current `ConfigProvider`:
|
|
33
|
+
|
|
34
|
+
| Variable | Behavior |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `TAILSCALE_API_KEY` | Bearer API access token via `fromApiKey` |
|
|
37
|
+
| `TAILSCALE_OAUTH_CLIENT_ID` and `TAILSCALE_OAUTH_CLIENT_SECRET` | Client-credentials exchange at `{apiBaseUrl}/oauth/token`, cached until `expires_in` minus 60 seconds |
|
|
38
|
+
| `TAILSCALE_BASE_URL` | API origin. Default `https://api.tailscale.com`. The client calls `{origin}/api/v2` unless the value already ends in `/api/v2` |
|
|
39
|
+
|
|
40
|
+
Setting both an API key and an OAuth client, or only half an OAuth pair, fails with `ConfigError`.
|
|
41
|
+
|
|
42
|
+
The explicit layers are `fromApiKey({ apiKey, apiBaseUrl? })` and `fromClientCredentials({ clientId, clientSecret, scope?, apiBaseUrl? })`. Their `apiBaseUrl` is the full API root (default `https://api.tailscale.com/api/v2`), used as given. The OAuth layers need an `HttpClient` for the token exchange and share one exchange across concurrent requests.
|
|
43
|
+
|
|
44
|
+
Pass the tailnet to each operation. `"-"` is the default tailnet of the token in use.
|
|
45
|
+
|
|
46
|
+
## Policy file
|
|
47
|
+
|
|
48
|
+
Policy files travel as HuJSON text on `body`, comments preserved. `getPolicyFile` and `setPolicyFile` return the `ETag` as `eTag`; pass it as `ifMatch` to guard a write (a mismatch is `PreconditionFailed`).
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const current = yield* Tailscale.getPolicyFile({ tailnet: "-" });
|
|
52
|
+
yield* Tailscale.validateAndTestPolicyFile({ tailnet: "-", body: current.body });
|
|
53
|
+
const updated = yield* Tailscale.setPolicyFile({
|
|
54
|
+
tailnet: "-",
|
|
55
|
+
ifMatch: current.eTag,
|
|
56
|
+
body: current.body,
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Auth keys
|
|
61
|
+
|
|
62
|
+
`createKey` returns the new key's secret once, as a `Redacted` string on `key`.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { Effect, Redacted } from "effect";
|
|
66
|
+
|
|
67
|
+
const created = yield* Tailscale.createKey({
|
|
68
|
+
tailnet: "-",
|
|
69
|
+
description: "ci runner",
|
|
70
|
+
expirySeconds: 3600,
|
|
71
|
+
capabilities: {
|
|
72
|
+
devices: {
|
|
73
|
+
create: { reusable: false, ephemeral: true, preauthorized: true, tags: ["tag:ci"] },
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const authKey = Redacted.value(created.key!); // pass to `tailscale up --auth-key`
|
|
78
|
+
|
|
79
|
+
yield* Tailscale.deleteKey({ tailnet: "-", keyId: created.id! });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Tags on a key must be owned in the policy file's `tagOwners`.
|
|
83
|
+
|
|
84
|
+
## Spec source
|
|
85
|
+
|
|
86
|
+
The spec is mirrored as JSON in `specs/spec-mirror-tailscale`; corrections live in `patches/`. Run `pnpm generate tailscale` from the repository root to regenerate.
|
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$Protocol as t,api$call as n,api$error as r,api$named as i,api$newError as a,api$op as ee,api$opPaginated as te,category$withAuthError as ne,category$withBadRequestError as re,category$withConflictError as ie,category$withParseError as ae,category$withServerError as oe,config$Redacted as o,config$String as s,config$all as se,config$map as c,config$option as l,pagination$paginateCursor as ce,retry$capped as le,retry$jittered as ue,retry$makeDefault as de,retry$throttlingFactory as u,retry$throttlingOptions as fe,retry$transientFactory as d,retry$transientOptions as pe,schema_lite_typed$String as f,schema_lite_typed$TaggedError as p,schema_lite_typed$Unknown as m,schema_lite_typed$optional as h,trait$Body as me,trait$FormDataFile as he,trait$Header as ge,trait$Http as g,trait$HttpBody as _,trait$KeyDictionary as v,trait$Label as y,trait$Query as b,trait$ResponseCode as x,trait$UnionCases as S,trait$applyErrorMatchers as C,trait$bodySymbol as w,trait$errorMatchersSymbol as T,trait$formDataFileSymbol as E,trait$getErrorMatchers as D,trait$headerSymbol as O,trait$httpBodySymbol as k,trait$httpSymbol as A,trait$keyDictionarySymbol as j,trait$labelSymbol as M,trait$querySymbol as N,trait$responseCodeSymbol as P,trait$unionCasesSymbol as F}from"@distilled.cloud/core/_bundle/base";import{errors$API_ERRORS as I,errors$BadGateway as L,errors$BadRequest as _e,errors$ConfigError as R,errors$Conflict as ve,errors$DEFAULT_ERRORS as ye,errors$Forbidden as be,errors$GatewayTimeout as xe,errors$HTTP_STATUS_MAP as Se,errors$InternalServerError as Ce,errors$Locked as we,errors$NotFound as Te,errors$ServiceUnavailable as Ee,errors$TooManyRequests as De,errors$Unauthorized as Oe,errors$UnprocessableEntity as ke,protocol_http$getAnn as Ae,protocol_http$getProps as je,protocol_http$hasPropAnn as Me,protocol_http$resolveNode as z,protocol_http$responseHeaderMembers as Ne,protocol_http$withResponseHeaders as Pe,protocol_rest$BinaryResponse as Fe,protocol_rest$RawResponse as Ie,protocol_rest$RawResponseRoot as Le,protocol_rest$SensitiveValue as Re,protocol_rest$makeRestProtocol as ze,protocol_rest$rawResponseRootSymbol as B,protocol_rest$rawResponseSymbol as V,protocol_rest$sensitiveValueSymbol as Be,protocol_rest$validateSuccess as Ve,schema_lite$Array as He,schema_lite$Boolean as Ue,schema_lite$NullOr as We,schema_lite$Number as Ge,schema_lite$Record as Ke,schema_lite$String as qe,schema_lite$Struct as Je,schema_lite$TaggedError as Ye,schema_lite$Unknown as Xe,schema_lite$at as Ze,schema_lite$optional as Qe,schema_lite$suspend as $e}from"@distilled.cloud/core/_bundle/rest";import*as et from"effect/Clock";import*as H from"effect/Context";import*as U from"effect/Effect";import*as tt from"effect/Equal";import*as W from"effect/http/HttpClient";import*as G from"effect/http/HttpClientRequest";import*as K from"effect/http/HttpClientResponse";import*as q from"effect/Layer";import*as J from"effect/Option";import*as Y from"effect/Redacted";import*as X from"effect/Schema";import*as Z from"effect/SynchronizedRef";const Q=`https://api.tailscale.com/api/v2`;const nt=6e4;var Credentials=class extends H.Service()(`TailscaleCredentials`){};const fromApiKey=e=>q.succeed(Credentials,U.succeed({token:e.apiKey,apiBaseUrl:e.apiBaseUrl??`https://api.tailscale.com/api/v2`}));const rt=X.Struct({access_token:X.Redacted(X.String),expires_in:X.Number});const makeClientCredentials=e=>U.gen(function*(){const t=yield*W.HttpClient;const n=e.apiBaseUrl??`https://api.tailscale.com/api/v2`;const r=t.execute(G.post(`${n}/oauth/token`).pipe(G.bodyUrlParams({grant_type:`client_credentials`,client_id:e.clientId,client_secret:Y.value(e.clientSecret),...e.scope?{scope:e.scope}:{},...e.tokenTailnet?{tailnet:e.tokenTailnet}:{}}))).pipe(U.flatMap(K.filterStatusOk),U.flatMap(K.schemaBodyJson(rt)),U.mapError(e=>new R({message:`OAuth token exchange failed: ${e.message}`})));const i=yield*Z.make(J.none());return Z.modifyEffect(i,e=>U.gen(function*(){const t=yield*et.currentTimeMillis;if(J.isSome(e)&&t<e.value.refreshAt)return[e.value.config,e];const i=yield*r;const a={config:{token:i.access_token,apiBaseUrl:n},refreshAt:t+i.expires_in*1e3-nt};return[a.config,J.some(a)]}))});const fromClientCredentials=e=>q.effect(Credentials,makeClientCredentials(e));const apiBaseUrlFromOrigin=e=>{const t=e.replace(/\/+$/,``);return t.endsWith(`/api/v2`)?t:`${t}/api/v2`};const $=`TAILSCALE_API_KEY and TAILSCALE_OAUTH_CLIENT_ID/TAILSCALE_OAUTH_CLIENT_SECRET cannot both be set`;const nonEmpty=e=>J.filter(e,e=>Y.value(e).length>0);const it=/*@__PURE__*/ se({apiKey:l(o(`TAILSCALE_API_KEY`)).pipe(c(nonEmpty)),clientId:l(s(`TAILSCALE_OAUTH_CLIENT_ID`)),clientSecret:l(o(`TAILSCALE_OAUTH_CLIENT_SECRET`)).pipe(c(nonEmpty)),origin:l(s(`TAILSCALE_BASE_URL`))});const at=/*@__PURE__*/ q.effect(Credentials,U.gen(function*(){const e=yield*W.HttpClient;const t=yield*Z.make(J.none());const resolveOAuth=n=>Z.modifyEffect(t,t=>J.isSome(t)&&tt.equals(t.value.config,n)?U.succeed([t.value.resolve,t]):makeClientCredentials(n).pipe(U.provideService(W.HttpClient,e),U.map(e=>[e,J.some({config:n,resolve:e})]))).pipe(U.flatten);return U.gen(function*(){const e=yield*it.pipe(U.mapError(e=>new R({message:`Failed to read Tailscale configuration: ${e.message}`})));const t=J.getOrUndefined(e.apiKey);const n=J.getOrUndefined(e.clientId);const r=J.getOrUndefined(e.clientSecret);const i=J.match(e.origin,{onNone:()=>Q,onSome:apiBaseUrlFromOrigin});if(t&&(n||r))return yield*new R({message:$});if(t)return{token:t,apiBaseUrl:i};if(n&&r)return yield*resolveOAuth({clientId:n,clientSecret:r,apiBaseUrl:i});if(n||r)return yield*new R({message:`TAILSCALE_OAUTH_CLIENT_ID and TAILSCALE_OAUTH_CLIENT_SECRET are both required`});return yield*new R({message:`TAILSCALE_API_KEY or TAILSCALE_OAUTH_CLIENT_ID and TAILSCALE_OAUTH_CLIENT_SECRET is required`})})}));var UnknownTailscaleError=class extends p()(`UnknownTailscaleError`,{code:h(f),message:h(f),body:m}).pipe(oe){};var TailscaleParseError=class extends p()(`TailscaleParseError`,{body:m,cause:m}).pipe(ae){};const isStringAst=e=>z(e)._tag===`String`;const isRawRoot=e=>Ae(e,B)!==void 0;const rawStringMember=e=>je(e).find(e=>Me(e,V)&&isStringAst(e.type));const fail=e=>U.fail(e);const decodeRawString=(e,t,n)=>U.flatMap(e.text,r=>Ve(t,{value:n===void 0?r:Pe(Ne(t),{[n.name]:r},e.headers),body:r,nonJson:false},e=>new TailscaleParseError(e))).pipe(U.catch(fail));const ot=/*@__PURE__*/ ze({credentials:/*@__PURE__*/ U.flatMap(Credentials,e=>e),baseUrl:e=>e.apiBaseUrl,headers:e=>({Authorization:`Bearer ${Y.value(e.token)}`}),unknownError:({code:e,message:t,body:n})=>new UnknownTailscaleError({code:typeof e===`string`?e:e!==void 0?String(e):void 0,message:t,body:n}),parseError:({body:e,cause:t})=>new TailscaleParseError({body:e,cause:t})});const st=/*@__PURE__*/ q.effect(t,U.map(t,e=>t.of({encode:e.encode,decode:t=>{if(t.response.status<200||t.response.status>=300)return e.decode(t);const{outputAst:n}=t;if(isRawRoot(n)&&isStringAst(n))return decodeRawString(t.response,n,void 0);const r=rawStringMember(n);if(r!==void 0)return decodeRawString(t.response,n,r);if(isRawRoot(n)&&z(n)._tag===`Arrays`)return U.flatMap(t.response.text,n=>n.trim()===`null`?U.succeed([]):e.decode(t)).pipe(U.catch(fail));return e.decode(t)}}))).pipe(q.provide(ot));var Retry=class extends H.Service()(`TailscaleRetry`){};const policy=e=>U.provide(q.succeed(Retry,e));const ct=U.provide(q.succeed(Retry,{while:()=>false}));const lt=policy(u);const ut=policy(d);export{ie as Ba,He as Cc,Ue as Dc,We as Kc,Ge as Lc,Ke as Mc,qe as Oc,Je as Pc,Ye as Rc,Xe as Uc,Ze as Wc,e as a,Qe as ad,$e as bd,n as c,Credentials as credentials$Credentials,at as credentials$CredentialsFromEnv,Q as credentials$DEFAULT_API_BASE_URL,fromApiKey as credentials$fromApiKey,fromClientCredentials as credentials$fromClientCredentials,makeClientCredentials as credentials$makeClientCredentials,r as e,I as errors$API_ERRORS,L as errors$BadGateway,_e as errors$BadRequest,R as errors$ConfigError,ve as errors$Conflict,ye as errors$DEFAULT_ERRORS,be as errors$Forbidden,xe as errors$GatewayTimeout,Se as errors$HTTP_STATUS_MAP,Ce as errors$InternalServerError,we as errors$Locked,Te as errors$NotFound,Ee as errors$ServiceUnavailable,TailscaleParseError as errors$TailscaleParseError,De as errors$TooManyRequests,Oe as errors$Unauthorized,UnknownTailscaleError as errors$UnknownTailscaleError,ke as errors$UnprocessableEntity,i as k,a as l,ee as m,te as n,ce as pagination$paginateCursor,st as protocol$TailscaleProtocol,Retry as retry$Retry,le as retry$capped,ue as retry$jittered,de as retry$makeDefault,ct as retry$none,policy as retry$policy,lt as retry$throttling,u as retry$throttlingFactory,fe as retry$throttlingOptions,ut as retry$transient,d as retry$transientFactory,pe as retry$transientOptions,Fe as traits$BinaryResponse,me as traits$Body,he as traits$FormDataFile,ge as traits$Header,g as traits$Http,_ as traits$HttpBody,v as traits$KeyDictionary,y as traits$Label,b as traits$Query,Ie as traits$RawResponse,Le as traits$RawResponseRoot,x as traits$ResponseCode,Re as traits$SensitiveValue,S as traits$UnionCases,C as traits$applyErrorMatchers,w as traits$bodySymbol,T as traits$errorMatchersSymbol,E as traits$formDataFileSymbol,D as traits$getErrorMatchers,O as traits$headerSymbol,k as traits$httpBodySymbol,A as traits$httpSymbol,j as traits$keyDictionarySymbol,M as traits$labelSymbol,N as traits$querySymbol,B as traits$rawResponseRootSymbol,V as traits$rawResponseSymbol,P as traits$responseCodeSymbol,Be as traits$sensitiveValueSymbol,F as traits$unionCasesSymbol,ne as xa,re as ya};
|
|
2
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","names":["EffectConfig.option","EffectConfig.Redacted","EffectConfig.map","EffectConfig.String","Schema.TaggedError","Schema.optional","Schema.String","Schema.Unknown","Category.withServerError","Category.withParseError","API.Protocol","D","Protocol","call","error","named","newError","op","opPaginated","withAuthError","withBadRequestError","withConflictError","withParseError","withServerError","Redacted$3","String$3","all$1","map","option","paginateCursor","capped","jittered","makeDefault","throttlingFactory","throttlingOptions","transientFactory","transientOptions","String$2","TaggedError$1","Unknown$1","optional$1","Body","FormDataFile","Header","Http","HttpBody","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","UnprocessableEntity","getAnn","getProps","hasPropAnn","resolveNode","responseHeaderMembers","withResponseHeaders","BinaryResponse","RawResponse","RawResponseRoot","SensitiveValue","makeRestProtocol","rawResponseRootSymbol","rawResponseSymbol","sensitiveValueSymbol","validateSuccess","Array","Boolean","NullOr","Number","Record","String$1","Struct","TaggedError","Unknown","at","optional","suspend","Clock","Context","Effect","Equal","HttpClient","HttpClientRequest","HttpClientResponse","Layer","Option","Redacted","Schema","SynchronizedRef","DEFAULT_API_BASE_URL","TOKEN_REFRESH_WINDOW_MS","config","TokenResponse","client","apiBaseUrl","exchange","cause","cache","now","cached","token","next","trimmed","origin","BOTH_METHODS","value","v","EnvConfig","CredentialsFromEnv","oauth","current","resolve","env","apiKey","clientId","clientSecret","ast","outputAst","prop","response","member","text","info","TailscaleProtocolRest","creds","code","TailscaleProtocol","rest","args","optionsOrFactory","none","throttling","transient"],"sources":["../../src/credentials.ts","../../src/errors.ts","../../src/protocol.ts","../../src/retry.ts"],"mappings":"6+FAeA,MAAauH,EAAuB,mCAEpC,MAAMC,GAA0B,IAOhC,IAAa,YAAb,cAAiCZ,EAAQ,QAAyD,CAAC,CACjG,sBACF,CAAC,AAAC,CAAC,EAEH,MAAa,WAAc,GAQzBM,EAAM,QACJ,YACAL,EAAO,QAAQ,CACb,MAAOY,EAAO,OACd,WAAYA,EAAO,YAAA,kCACrB,CAAC,CACH,EAeF,MAAMC,GAAgBL,EAAO,OAAO,CAClC,aAAcA,EAAO,SAASA,EAAO,MAAM,EAC3C,WAAYA,EAAO,MACrB,CAAC,EAaD,MAAa,sBACX,GAEAR,EAAO,IAAI,WAAa,CACtB,MAAMc,EAAS,MAAOZ,EAAW,WACjC,MAAMa,EAAaH,EAAO,YAAA,mCAC1B,MAAMI,EAAWF,EACd,QACCX,EAAkB,KAAK,GAAGY,EAAW,aAAa,CAAC,CAAC,KAClDZ,EAAkB,c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AAK5C,EAAM,QAAQuC,EAAqB,CAAC,ECrG3C,IAAa,MAAb,cAA2B7C,EAAQ,QAAuB,CAAC,CAAC,gBAAgB,CAAC,AAAC,CAAC,EAE/E,MAAa,OAAU,GACrBC,EAAO,QAAQK,EAAM,QAAQ,MAAO6C,CAAgB,CAAC,EAEvD,MAAaC,GAAOnD,EAAO,QAAQK,EAAM,QAAQ,MAAO,CAAE,UAAa,KAAM,CAAC,CAAC,EAE/E,MAAa+C,GAAa,OAAOhI,CAAiB,EAElD,MAAaiI,GAAY,OAAO/H,CAAgB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 HttpClient from "effect/http/HttpClient";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
export declare const DEFAULT_API_BASE_URL = "https://api.tailscale.com/api/v2";
|
|
8
|
+
export interface Config {
|
|
9
|
+
readonly token: Redacted.Redacted<string>;
|
|
10
|
+
readonly apiBaseUrl: string;
|
|
11
|
+
}
|
|
12
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "TailscaleCredentials", Effect.Effect<Config, ConfigError, never>>;
|
|
13
|
+
export declare class Credentials extends Credentials_base {
|
|
14
|
+
}
|
|
15
|
+
export declare const fromApiKey: (config: {
|
|
16
|
+
readonly apiKey: Redacted.Redacted<string>;
|
|
17
|
+
/**
|
|
18
|
+
* The API root, including `/api/v2`, used as given. Default
|
|
19
|
+
* `DEFAULT_API_BASE_URL`. Unlike `TAILSCALE_BASE_URL`, it is not an origin.
|
|
20
|
+
*/
|
|
21
|
+
readonly apiBaseUrl?: string;
|
|
22
|
+
}) => Layer.Layer<Credentials>;
|
|
23
|
+
export interface ClientCredentialsConfig {
|
|
24
|
+
readonly clientId: string;
|
|
25
|
+
readonly clientSecret: Redacted.Redacted<string>;
|
|
26
|
+
readonly scope?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The API root, including `/api/v2`, used as given. Default
|
|
29
|
+
* `DEFAULT_API_BASE_URL`. Unlike `TAILSCALE_BASE_URL`, it is not an origin.
|
|
30
|
+
*/
|
|
31
|
+
readonly apiBaseUrl?: string;
|
|
32
|
+
/** Sent as the exchange's `tailnet` parameter to scope the token to an API-only tailnet. */
|
|
33
|
+
readonly tokenTailnet?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds the OAuth client-credentials token cache. The returned effect posts
|
|
37
|
+
* the exchange through the captured `HttpClient`, reuses the token until
|
|
38
|
+
* 60 seconds before `expires_in`, and serializes refreshes so concurrent
|
|
39
|
+
* resolutions of a stale token make one exchange.
|
|
40
|
+
*/
|
|
41
|
+
export declare const makeClientCredentials: (config: ClientCredentialsConfig) => Effect.Effect<Effect.Effect<Config, ConfigError>, never, HttpClient.HttpClient>;
|
|
42
|
+
export declare const fromClientCredentials: (config: ClientCredentialsConfig) => Layer.Layer<Credentials, never, HttpClient.HttpClient>;
|
|
43
|
+
/**
|
|
44
|
+
* Reads `TAILSCALE_API_KEY`, `TAILSCALE_OAUTH_CLIENT_ID`,
|
|
45
|
+
* `TAILSCALE_OAUTH_CLIENT_SECRET` and `TAILSCALE_BASE_URL`
|
|
46
|
+
* through `@distilled.cloud/core/config` on every resolution, so a provided
|
|
47
|
+
* `ConfigProvider` supplies them. The OAuth token cache belongs to the layer
|
|
48
|
+
* and is rebuilt when the OAuth variables change.
|
|
49
|
+
*/
|
|
50
|
+
export declare const CredentialsFromEnv: Layer.Layer<Credentials, never, HttpClient.HttpClient>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,8BA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AM,qBAAqB,WACxB,uBAAuB,KAC9B,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CACE,CAAC;AAqC3D;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CA2DnF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { credentials$Credentials as Credentials, credentials$CredentialsFromEnv as CredentialsFromEnv, credentials$DEFAULT_API_BASE_URL as DEFAULT_API_BASE_URL, credentials$fromApiKey as fromApiKey, credentials$fromClientCredentials as fromClientCredentials, credentials$makeClientCredentials as makeClientCredentials } from "./_bundle/sdk.js";
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { API_ERRORS, BadGateway, BadRequest, Conflict, ConfigError, DEFAULT_ERRORS, Forbidden, GatewayTimeout, HTTP_STATUS_MAP, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, } from "@distilled.cloud/core/errors";
|
|
2
|
+
export type { DefaultErrors } from "@distilled.cloud/core/errors";
|
|
3
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
4
|
+
declare const UnknownTailscaleError_base: Schema.TaggedErrorClass<"UnknownTailscaleError", {
|
|
5
|
+
readonly code: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
6
|
+
readonly message: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
7
|
+
readonly body: import("effect/Schema").Unknown;
|
|
8
|
+
}> & (new (...args: any[]) => {
|
|
9
|
+
"@distilled.cloud/error/categories": {
|
|
10
|
+
ServerError: true;
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
export declare class UnknownTailscaleError extends UnknownTailscaleError_base {
|
|
14
|
+
}
|
|
15
|
+
declare const TailscaleParseError_base: Schema.TaggedErrorClass<"TailscaleParseError", {
|
|
16
|
+
readonly body: import("effect/Schema").Unknown;
|
|
17
|
+
readonly cause: import("effect/Schema").Unknown;
|
|
18
|
+
}> & (new (...args: any[]) => {
|
|
19
|
+
"@distilled.cloud/error/categories": {
|
|
20
|
+
ParseError: true;
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
export declare class TailscaleParseError extends TailscaleParseError_base {
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,cAAc,EACd,SAAS,EACT,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,KAAK,MAAM,MAAM,yCAAyC,CAAC;;;;;;;;;;AAElE,qBAAa,qBAAsB,SAAQ,0BAOX;CAAG;;;;;;;;;AAEnC,qBAAa,mBAAoB,SAAQ,wBAMV;CAAG"}
|
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$TailscaleParseError as TailscaleParseError, errors$TooManyRequests as TooManyRequests, errors$Unauthorized as Unauthorized, errors$UnknownTailscaleError as UnknownTailscaleError, errors$UnprocessableEntity as UnprocessableEntity } from "./_bundle/sdk.js";
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/tailscale -- Tailscale SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy model
|
|
5
|
+
* in `.generated-specs` (written by `scripts/convert.ts` from the OpenAPI
|
|
6
|
+
* spec). Everything else in this folder is hand-written.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { Effect, Layer } from "effect";
|
|
11
|
+
* import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
12
|
+
* import * as Tailscale from "@distilled.cloud/tailscale";
|
|
13
|
+
*
|
|
14
|
+
* const program = Effect.gen(function* () {
|
|
15
|
+
* const policy = yield* Tailscale.getPolicyFile({ tailnet: "-" });
|
|
16
|
+
* return policy.eTag;
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const Live = Tailscale.CredentialsFromEnv.pipe(
|
|
20
|
+
* Layer.provideMerge(FetchHttpClient.layer),
|
|
21
|
+
* );
|
|
22
|
+
*
|
|
23
|
+
* program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export * from "./credentials.ts";
|
|
27
|
+
export * from "./errors.ts";
|
|
28
|
+
export * as T from "./traits.ts";
|
|
29
|
+
export { TailscaleProtocol, type TailscaleOpError, type TailscaleOpContext } from "./protocol.ts";
|
|
30
|
+
export { paginateCursor } from "./pagination.ts";
|
|
31
|
+
export * as Retry from "./retry.ts";
|
|
32
|
+
export * from "./services/tailscale.ts";
|
|
33
|
+
export { BadRequest, Conflict, Forbidden, NotFound, PreconditionFailed, UnprocessableEntity, } from "./services/tailscale.ts";
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./credentials.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * as T from "./traits.js";
|
|
4
|
+
export { TailscaleProtocol } from "./protocol.js";
|
|
5
|
+
export { paginateCursor } from "./pagination.js";
|
|
6
|
+
export * as Retry from "./retry.js";
|
|
7
|
+
export * from "./services/tailscale.js";
|
|
8
|
+
export { BadRequest, Conflict, Forbidden, NotFound, PreconditionFailed, UnprocessableEntity } from "./services/tailscale.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./credentials.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * as T from "./traits.js";
|
|
4
|
+
export { TailscaleProtocol } from "./protocol.js";
|
|
5
|
+
export { paginateCursor } from "./pagination.js";
|
|
6
|
+
export * as Retry from "./retry.js";
|
|
7
|
+
export * from "./services.lazy/tailscale.js";
|
|
8
|
+
export { BadRequest, Conflict, Forbidden, NotFound, PreconditionFailed, UnprocessableEntity } from "./services.lazy/tailscale.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAkD,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pagination$paginateCursor as paginateCursor } from "./_bundle/sdk.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as API from "@distilled.cloud/core/api";
|
|
2
|
+
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
3
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
4
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import { Credentials } from "./credentials.ts";
|
|
7
|
+
import { API_ERRORS } from "./errors.ts";
|
|
8
|
+
import { TailscaleParseError, UnknownTailscaleError } from "./errors.ts";
|
|
9
|
+
export type TailscaleOpError = InstanceType<(typeof API_ERRORS)[number]> | UnknownTailscaleError | ConfigError | HttpClientError.HttpClientError | TailscaleParseError;
|
|
10
|
+
export type TailscaleOpContext = Credentials | HttpClient.HttpClient;
|
|
11
|
+
/**
|
|
12
|
+
* Core's REST protocol, plus two things the Tailscale API does differently on
|
|
13
|
+
* a 2xx: policy files are HuJSON text, and an empty list can arrive as the
|
|
14
|
+
* JSON `null` (a Go nil slice), which decodes as `[]`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const TailscaleProtocol: Layer.Layer<API.Protocol>;
|
|
17
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAgBhE,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAEpE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzE,MAAM,MAAM,gBAAgB,GACxB,YAAY,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GACzC,qBAAqB,GACrB,WAAW,GACX,eAAe,CAAC,eAAe,GAC/B,mBAAmB,CAAC;AAExB,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AA0DrE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAsBZ,CAAC"}
|
package/lib/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { protocol$TailscaleProtocol as TailscaleProtocol } from "./_bundle/sdk.js";
|
package/lib/retry.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Policy } from "@distilled.cloud/core/retry";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
export { type Factory, type Options, type Policy, capped, jittered, makeDefault, throttlingFactory, throttlingOptions, transientFactory, transientOptions, } from "@distilled.cloud/core/retry";
|
|
5
|
+
declare const Retry_base: Context.ServiceClass<Retry, "TailscaleRetry", Policy>;
|
|
6
|
+
export declare class Retry extends Retry_base {
|
|
7
|
+
}
|
|
8
|
+
export declare const policy: (optionsOrFactory: Policy) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
9
|
+
export declare const none: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
10
|
+
export declare const throttling: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
11
|
+
export declare const transient: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Retry>>;
|
|
12
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAuC,MAAM,6BAA6B,CAAC;AAC/F,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,MAAM,EACN,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;;AAErC,qBAAa,KAAM,SAAQ,UAAkD;CAAG;AAEhF,eAAO,MAAM,MAAM,qBAAsB,MAAM,sFACS,CAAC;AAEzD,eAAO,MAAM,IAAI,mFAA+D,CAAC;AAEjF,eAAO,MAAM,UAAU,mFAA4B,CAAC;AAEpD,eAAO,MAAM,SAAS,mFAA2B,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$throttlingFactory as throttlingFactory, retry$throttlingOptions as throttlingOptions, retry$transient as transient, retry$transientFactory as transientFactory, retry$transientOptions as transientOptions } from "./_bundle/sdk.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as tailscale from "./tailscale.js";
|