@distilled.cloud/forgejo 0.0.0 → 1.0.0-rc.10
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 +71 -0
- package/lib/credentials.d.ts +35 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +57 -0
- package/lib/credentials.js.map +1 -0
- package/lib/errors.d.ts +56 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +36 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +28 -0
- package/lib/index.js.map +1 -0
- package/lib/protocol.d.ts +18 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +61 -0
- package/lib/protocol.js.map +1 -0
- package/lib/retry.d.ts +50 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +43 -0
- package/lib/retry.js.map +1 -0
- package/lib/services/activitypub.d.ts +121 -0
- package/lib/services/activitypub.d.ts.map +1 -0
- package/lib/services/activitypub.js +202 -0
- package/lib/services/activitypub.js.map +1 -0
- package/lib/services/admin.d.ts +1196 -0
- package/lib/services/admin.d.ts.map +1 -0
- package/lib/services/admin.js +1276 -0
- package/lib/services/admin.js.map +1 -0
- package/lib/services/index.d.ts +11 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +12 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/issue.d.ts +1479 -0
- package/lib/services/issue.d.ts.map +1 -0
- package/lib/services/issue.js +1732 -0
- package/lib/services/issue.js.map +1 -0
- package/lib/services/miscellaneous.d.ts +494 -0
- package/lib/services/miscellaneous.d.ts.map +1 -0
- package/lib/services/miscellaneous.js +471 -0
- package/lib/services/miscellaneous.js.map +1 -0
- package/lib/services/notification.d.ts +390 -0
- package/lib/services/notification.d.ts.map +1 -0
- package/lib/services/notification.js +344 -0
- package/lib/services/notification.js.map +1 -0
- package/lib/services/organization.d.ts +1593 -0
- package/lib/services/organization.d.ts.map +1 -0
- package/lib/services/organization.js +1672 -0
- package/lib/services/organization.js.map +1 -0
- package/lib/services/package.d.ts +347 -0
- package/lib/services/package.d.ts.map +1 -0
- package/lib/services/package.js +320 -0
- package/lib/services/package.js.map +1 -0
- package/lib/services/repository.d.ts +4770 -0
- package/lib/services/repository.d.ts.map +1 -0
- package/lib/services/repository.js +5446 -0
- package/lib/services/repository.js.map +1 -0
- package/lib/services/settings.d.ts +67 -0
- package/lib/services/settings.d.ts.map +1 -0
- package/lib/services/settings.js +87 -0
- package/lib/services/settings.js.map +1 -0
- package/lib/services/user.d.ts +1764 -0
- package/lib/services/user.d.ts.map +1 -0
- package/lib/services/user.js +1921 -0
- package/lib/services/user.js.map +1 -0
- package/lib/traits.d.ts +10 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +11 -0
- package/lib/traits.js.map +1 -0
- package/package.json +78 -6
- package/src/credentials.ts +89 -0
- package/src/errors.ts +72 -0
- package/src/index.ts +31 -0
- package/src/protocol.ts +86 -0
- package/src/retry.ts +74 -0
- package/src/services/activitypub.ts +415 -0
- package/src/services/admin.ts +3103 -0
- package/src/services/index.ts +11 -0
- package/src/services/issue.ts +3949 -0
- package/src/services/miscellaneous.ts +1118 -0
- package/src/services/notification.ts +847 -0
- package/src/services/organization.ts +4008 -0
- package/src/services/package.ts +767 -0
- package/src/services/repository.ts +12836 -0
- package/src/services/settings.ts +190 -0
- package/src/services/user.ts +4669 -0
- package/src/traits.ts +44 -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
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @distilled.cloud/forgejo
|
|
2
|
+
|
|
3
|
+
Effect-native SDK for the [Forgejo](https://forgejo.org/) REST API,
|
|
4
|
+
generated from the Swagger 2.0 document every Forgejo instance serves at
|
|
5
|
+
`/swagger.v1.json`.
|
|
6
|
+
|
|
7
|
+
## Spec source
|
|
8
|
+
|
|
9
|
+
The generator reads one file from the package's spec mirror:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
specs/spec-mirror-forgejo/specs/forgejo.spec.json
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Forgejo publishes no standalone spec artefact. Each running instance serves
|
|
16
|
+
the document describing its own version at `/swagger.v1.json`, rendered from
|
|
17
|
+
a Go template checked into the Forgejo repository
|
|
18
|
+
(`templates/swagger/v1_json.tmpl`). The mirror
|
|
19
|
+
([distilled-mirror/spec-mirror-forgejo](https://github.com/distilled-mirror/spec-mirror-forgejo),
|
|
20
|
+
fetch script under `stacks/distilled-submodules/spec-repos/forgejo/`) snapshots
|
|
21
|
+
that template at a **pinned release tag** with the two server-side
|
|
22
|
+
placeholders (`info.version`, `basePath`) filled in the way a root-mounted
|
|
23
|
+
instance would. Bump `FORGEJO_VERSION` in the fetch script to move to a newer
|
|
24
|
+
release.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm specs:fetch # check out the mirror (from packages/forgejo)
|
|
28
|
+
pnpm generate # convert + compile (see scripts/convert.ts)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Before the mirror exists, or to regenerate against today's upstream without
|
|
32
|
+
touching submodules, materialise it locally from the repo root:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm specs:local forgejo
|
|
36
|
+
DISTILLED_SPECS_LOCAL=1 pnpm generate forgejo
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Layout
|
|
40
|
+
|
|
41
|
+
- `scripts/convert.ts` — buckets the document's operations by tag, applies
|
|
42
|
+
the RFC-6902 patch chain under `patches/<tag>/<operationId>.json`, and
|
|
43
|
+
writes one Smithy model per tag to `.generated-specs/`.
|
|
44
|
+
- `scripts/generate.ts` — compiles the models into `src/services/<tag>.ts`.
|
|
45
|
+
- `src/credentials.ts`, `src/protocol.ts`, `src/errors.ts`, `src/retry.ts`,
|
|
46
|
+
`src/traits.ts` — hand-written; everything under `src/services/` is
|
|
47
|
+
generated and never edited by hand.
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import * as Forgejo from "@distilled.cloud/forgejo";
|
|
53
|
+
|
|
54
|
+
const program = Effect.gen(function* () {
|
|
55
|
+
const repo = yield* Forgejo.Services.repository.repoGet({
|
|
56
|
+
owner: "acme",
|
|
57
|
+
repo: "api",
|
|
58
|
+
});
|
|
59
|
+
return repo.clone_url;
|
|
60
|
+
}).pipe(
|
|
61
|
+
Effect.provide(
|
|
62
|
+
Forgejo.credentials({
|
|
63
|
+
baseUrl: "https://git.example.com",
|
|
64
|
+
token: process.env.FORGEJO_TOKEN!,
|
|
65
|
+
}),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`baseUrl` is the instance origin; the `/api/v1` prefix is appended when
|
|
71
|
+
missing. `FORGEJO_URL` / `FORGEJO_TOKEN` drive `CredentialsFromEnv`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Redacted from "effect/Redacted";
|
|
5
|
+
/**
|
|
6
|
+
* Path prefix of the Forgejo REST API, relative to the instance origin. The
|
|
7
|
+
* version is a PATH segment rather than a header, so it belongs to the base
|
|
8
|
+
* URL: the generated operations carry prefix-less routes (`/user/repos`,
|
|
9
|
+
* `/repos/{owner}/{repo}`).
|
|
10
|
+
*/
|
|
11
|
+
export declare const API_PATH = "/api/v1";
|
|
12
|
+
/**
|
|
13
|
+
* Normalize an instance origin (or an already-complete API root) into the
|
|
14
|
+
* API v1 base URL: trailing slashes are dropped and {@link API_PATH} is
|
|
15
|
+
* appended exactly once.
|
|
16
|
+
*/
|
|
17
|
+
export declare const normalizeBaseUrl: (baseUrl: string) => string;
|
|
18
|
+
export interface Config {
|
|
19
|
+
readonly token: Redacted.Redacted<string>;
|
|
20
|
+
/** Fully-qualified API root, e.g. `https://git.example.com/api/v1`. */
|
|
21
|
+
readonly apiBaseUrl: string;
|
|
22
|
+
}
|
|
23
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "ForgejoCredentials", Effect.Effect<Config, never, never>>;
|
|
24
|
+
export declare class Credentials extends Credentials_base {
|
|
25
|
+
}
|
|
26
|
+
export declare const CredentialsFromEnv: Layer.Layer<Credentials, never, never>;
|
|
27
|
+
/**
|
|
28
|
+
* Convenience layer from a plain token and the instance origin (or API root).
|
|
29
|
+
*/
|
|
30
|
+
export declare const credentials: (config: {
|
|
31
|
+
readonly token: string | Redacted.Redacted<string>;
|
|
32
|
+
readonly baseUrl: string;
|
|
33
|
+
}) => Layer.Layer<Credentials>;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAYA,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;AAG5C;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,YAAY,CAAC;AAElC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,YAAa,MAAM,KAAG,MAGlD,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,uEAAuE;IACvE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;;AAED,qBAAa,WAAY,SAAQ,gBAGR;CAAG;AAS5B,eAAO,MAAM,kBAAkB,wCAgB9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,WAAY;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAUxB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgejo credentials — hand-written.
|
|
3
|
+
*
|
|
4
|
+
* The `Credentials` service resolves `{ token, apiBaseUrl }` per request; the
|
|
5
|
+
* protocol layer formats the `Authorization: token <token>` header from it.
|
|
6
|
+
*
|
|
7
|
+
* Forgejo is self-hosted, so — unlike a single-tenant SaaS — there is no
|
|
8
|
+
* default API root: the instance URL is part of the credential. The token is
|
|
9
|
+
* an access token generated under Settings → Applications → Access Tokens on
|
|
10
|
+
* the instance (a `write:admin`-scoped one for the `/admin` endpoints).
|
|
11
|
+
*/
|
|
12
|
+
import * as EffectConfig from "effect/Config";
|
|
13
|
+
import * as Context from "effect/Context";
|
|
14
|
+
import * as Effect from "effect/Effect";
|
|
15
|
+
import * as Layer from "effect/Layer";
|
|
16
|
+
import * as Redacted from "effect/Redacted";
|
|
17
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
18
|
+
/**
|
|
19
|
+
* Path prefix of the Forgejo REST API, relative to the instance origin. The
|
|
20
|
+
* version is a PATH segment rather than a header, so it belongs to the base
|
|
21
|
+
* URL: the generated operations carry prefix-less routes (`/user/repos`,
|
|
22
|
+
* `/repos/{owner}/{repo}`).
|
|
23
|
+
*/
|
|
24
|
+
export const API_PATH = "/api/v1";
|
|
25
|
+
/**
|
|
26
|
+
* Normalize an instance origin (or an already-complete API root) into the
|
|
27
|
+
* API v1 base URL: trailing slashes are dropped and {@link API_PATH} is
|
|
28
|
+
* appended exactly once.
|
|
29
|
+
*/
|
|
30
|
+
export const normalizeBaseUrl = (baseUrl) => {
|
|
31
|
+
const trimmed = baseUrl.replace(/\/+$/, "");
|
|
32
|
+
return trimmed.endsWith(API_PATH) ? trimmed : `${trimmed}${API_PATH}`;
|
|
33
|
+
};
|
|
34
|
+
export class Credentials extends Context.Service()("ForgejoCredentials") {
|
|
35
|
+
}
|
|
36
|
+
const envConfig = EffectConfig.all({
|
|
37
|
+
// `FORGEJO_URL` / `FORGEJO_TOKEN` are the names Forgejo's own Actions
|
|
38
|
+
// runner and the Terraform/OpenTofu providers read.
|
|
39
|
+
token: EffectConfig.String("FORGEJO_TOKEN"),
|
|
40
|
+
baseUrl: EffectConfig.String("FORGEJO_URL"),
|
|
41
|
+
});
|
|
42
|
+
export const CredentialsFromEnv = Layer.succeed(Credentials, envConfig.pipe(Effect.mapError(() => new ConfigError({
|
|
43
|
+
message: "FORGEJO_URL and FORGEJO_TOKEN environment variables are required",
|
|
44
|
+
})), Effect.map(({ token, baseUrl }) => ({
|
|
45
|
+
token: Redacted.make(token),
|
|
46
|
+
apiBaseUrl: normalizeBaseUrl(baseUrl),
|
|
47
|
+
})), Effect.orDie));
|
|
48
|
+
/**
|
|
49
|
+
* Convenience layer from a plain token and the instance origin (or API root).
|
|
50
|
+
*/
|
|
51
|
+
export const credentials = (config) => Layer.succeed(Credentials, Effect.succeed({
|
|
52
|
+
token: typeof config.token === "string"
|
|
53
|
+
? Redacted.make(config.token)
|
|
54
|
+
: config.token,
|
|
55
|
+
apiBaseUrl: normalizeBaseUrl(config.baseUrl),
|
|
56
|
+
}));
|
|
57
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAC9C,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;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAU,EAAE;IAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC;AACxE,CAAC,CAAC;AAQF,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAG7C,CAAC,oBAAoB,CAAC;CAAG;AAE5B,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC;IACjC,sEAAsE;IACtE,oDAAoD;IACpD,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC;IAC3C,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC;CAC5C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAC7C,WAAW,EACX,SAAS,CAAC,IAAI,CACZ,MAAM,CAAC,QAAQ,CACb,GAAG,EAAE,CACH,IAAI,WAAW,CAAC;IACd,OAAO,EACL,kEAAkE;CACrE,CAAC,CACL,EACD,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IAClC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;IAC3B,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC;CACtC,CAAC,CAAC,EACH,MAAM,CAAC,KAAK,CACb,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAG3B,EAA4B,EAAE,CAC7B,KAAK,CAAC,OAAO,CACX,WAAW,EACX,MAAM,CAAC,OAAO,CAAC;IACb,KAAK,EACH,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAC9B,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAC7B,CAAC,CAAC,MAAM,CAAC,KAAK;IAClB,UAAU,EAAE,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC;CAC7C,CAAC,CACH,CAAC"}
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgejo-specific error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the common HTTP errors from core and adds the Forgejo-specific
|
|
5
|
+
* unknown-error and parse-error wrappers.
|
|
6
|
+
*
|
|
7
|
+
* Forgejo's failure envelope is `{ message, url }` — a human-readable message
|
|
8
|
+
* and a link to the API documentation. There is no machine-readable code, so
|
|
9
|
+
* the SDK dispatches on the HTTP status: the per-operation classes generated
|
|
10
|
+
* from each operation's declared responses (`NotFound`, `Forbidden`,
|
|
11
|
+
* `Conflict`, `UnprocessableEntity`, `Locked`, …) first, then core's shared
|
|
12
|
+
* status map, then {@link UnknownForgejoError}. The handful of failures
|
|
13
|
+
* Forgejo reports under a misleading status — an organization delete refused
|
|
14
|
+
* because it still owns repositories answers `500` — are typed per operation
|
|
15
|
+
* by message under `patches/`.
|
|
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
|
+
import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
|
|
19
|
+
import * as Schema from "effect/Schema";
|
|
20
|
+
declare const UnknownForgejoError_base: Schema.Class<UnknownForgejoError, Schema.TaggedStruct<"UnknownForgejoError", {
|
|
21
|
+
readonly code: Schema.optional<Schema.String>;
|
|
22
|
+
readonly message: Schema.optional<Schema.String>;
|
|
23
|
+
readonly body: Schema.Unknown;
|
|
24
|
+
}>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
|
|
25
|
+
"@distilled.cloud/error/categories": {
|
|
26
|
+
ServerError: true;
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Unknown Forgejo error — returned when a failed response's HTTP status has
|
|
31
|
+
* no mapped error class. Carries the raw body for later cataloging.
|
|
32
|
+
*/
|
|
33
|
+
export declare class UnknownForgejoError extends UnknownForgejoError_base {
|
|
34
|
+
}
|
|
35
|
+
declare const ForgejoParseError_base: Schema.Class<ForgejoParseError, Schema.TaggedStruct<"ForgejoParseError", {
|
|
36
|
+
readonly body: Schema.Unknown;
|
|
37
|
+
readonly cause: Schema.Unknown;
|
|
38
|
+
}>, import("effect/Cause").YieldableError> & (new (...args: any[]) => {
|
|
39
|
+
"@distilled.cloud/error/categories": {
|
|
40
|
+
ParseError: true;
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
/** Schema parse error wrapper. */
|
|
44
|
+
export declare class ForgejoParseError extends ForgejoParseError_base {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Errors any Forgejo operation may surface in addition to the per-operation
|
|
48
|
+
* typed status errors.
|
|
49
|
+
*/
|
|
50
|
+
export type ClientErrors = UnknownForgejoError | ForgejoParseError;
|
|
51
|
+
/**
|
|
52
|
+
* Default Forgejo operation errors: the shared HTTP status errors from core
|
|
53
|
+
* plus the client-level fallback/decode errors.
|
|
54
|
+
*/
|
|
55
|
+
export type DefaultErrors = CoreDefaultErrors | ClientErrors;
|
|
56
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","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,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEvF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;;;;;;;AAGxC;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,wBAOT;CAAG;;;;;;;;;AAEnC,kCAAkC;AAClC,qBAAa,iBAAkB,SAAQ,sBAMR;CAAG;AAElC;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,YAAY,CAAC"}
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgejo-specific error types.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the common HTTP errors from core and adds the Forgejo-specific
|
|
5
|
+
* unknown-error and parse-error wrappers.
|
|
6
|
+
*
|
|
7
|
+
* Forgejo's failure envelope is `{ message, url }` — a human-readable message
|
|
8
|
+
* and a link to the API documentation. There is no machine-readable code, so
|
|
9
|
+
* the SDK dispatches on the HTTP status: the per-operation classes generated
|
|
10
|
+
* from each operation's declared responses (`NotFound`, `Forbidden`,
|
|
11
|
+
* `Conflict`, `UnprocessableEntity`, `Locked`, …) first, then core's shared
|
|
12
|
+
* status map, then {@link UnknownForgejoError}. The handful of failures
|
|
13
|
+
* Forgejo reports under a misleading status — an organization delete refused
|
|
14
|
+
* because it still owns repositories answers `500` — are typed per operation
|
|
15
|
+
* by message under `patches/`.
|
|
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
|
+
import * as Schema from "effect/Schema";
|
|
19
|
+
import * as Category from "@distilled.cloud/core/category";
|
|
20
|
+
/**
|
|
21
|
+
* Unknown Forgejo error — returned when a failed response's HTTP status has
|
|
22
|
+
* no mapped error class. Carries the raw body for later cataloging.
|
|
23
|
+
*/
|
|
24
|
+
export class UnknownForgejoError extends Schema.TaggedError()("UnknownForgejoError", {
|
|
25
|
+
code: Schema.optional(Schema.String),
|
|
26
|
+
message: Schema.optional(Schema.String),
|
|
27
|
+
body: Schema.Unknown,
|
|
28
|
+
}).pipe(Category.withServerError) {
|
|
29
|
+
}
|
|
30
|
+
/** Schema parse error wrapper. */
|
|
31
|
+
export class ForgejoParseError extends Schema.TaggedError()("ForgejoParseError", {
|
|
32
|
+
body: Schema.Unknown,
|
|
33
|
+
cause: Schema.Unknown,
|
|
34
|
+
}).pipe(Category.withParseError) {
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","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;AAGtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAC;AAE3D;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,MAAM,CAAC,WAAW,EAAuB,CAChF,qBAAqB,EACrB;IACE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC,OAAO;CACrB,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;CAAG;AAEnC,kCAAkC;AAClC,MAAM,OAAO,iBAAkB,SAAQ,MAAM,CAAC,WAAW,EAAqB,CAC5E,mBAAmB,EACnB;IACE,IAAI,EAAE,MAAM,CAAC,OAAO;IACpB,KAAK,EAAE,MAAM,CAAC,OAAO;CACtB,CACF,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;CAAG"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/forgejo — Forgejo REST API SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy models in
|
|
5
|
+
* `.generated-specs` (written by `scripts/convert.ts` from the Swagger 2.0
|
|
6
|
+
* document in the `spec-mirror-forgejo` submodule under `specs/`). Everything
|
|
7
|
+
* else in this folder is hand-written.
|
|
8
|
+
*
|
|
9
|
+
* One module per Forgejo API tag — `repository`, `organization`, `user`,
|
|
10
|
+
* `issue`, `admin`, … — the same split the API reference uses.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import * as Forgejo from "@distilled.cloud/forgejo";
|
|
15
|
+
*
|
|
16
|
+
* const repo = yield* Forgejo.Services.repository.repoGet({
|
|
17
|
+
* owner: "acme",
|
|
18
|
+
* repo: "api",
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export * from "./credentials.ts";
|
|
23
|
+
export * from "./errors.ts";
|
|
24
|
+
export * as T from "./traits.ts";
|
|
25
|
+
export { ForgejoProtocol, type ForgejoOpError, type ForgejoOpContext, } from "./protocol.ts";
|
|
26
|
+
export * as Retry from "./retry.ts";
|
|
27
|
+
export * as Services from "./services/index.ts";
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EACL,eAAe,EACf,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/forgejo — Forgejo REST API SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy models in
|
|
5
|
+
* `.generated-specs` (written by `scripts/convert.ts` from the Swagger 2.0
|
|
6
|
+
* document in the `spec-mirror-forgejo` submodule under `specs/`). Everything
|
|
7
|
+
* else in this folder is hand-written.
|
|
8
|
+
*
|
|
9
|
+
* One module per Forgejo API tag — `repository`, `organization`, `user`,
|
|
10
|
+
* `issue`, `admin`, … — the same split the API reference uses.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import * as Forgejo from "@distilled.cloud/forgejo";
|
|
15
|
+
*
|
|
16
|
+
* const repo = yield* Forgejo.Services.repository.repoGet({
|
|
17
|
+
* owner: "acme",
|
|
18
|
+
* repo: "api",
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export * from "./credentials.js";
|
|
23
|
+
export * from "./errors.js";
|
|
24
|
+
export * as T from "./traits.js";
|
|
25
|
+
export { ForgejoProtocol, } from "./protocol.js";
|
|
26
|
+
export * as Retry from "./retry.js";
|
|
27
|
+
export * as Services from "./services/index.js";
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EACL,eAAe,GAGhB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as Layer from "effect/Layer";
|
|
2
|
+
import type * as HttpClient from "effect/unstable/http/HttpClient";
|
|
3
|
+
import type * as HttpClientError from "effect/unstable/http/HttpClientError";
|
|
4
|
+
import type * as API from "@distilled.cloud/core/api";
|
|
5
|
+
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
6
|
+
import { Credentials } from "./credentials.ts";
|
|
7
|
+
import { type DefaultErrors } from "./errors.ts";
|
|
8
|
+
/**
|
|
9
|
+
* Error channel shared by every generated Forgejo operation. Generated
|
|
10
|
+
* service files annotate operations with `API.OperationMethod<I, O,
|
|
11
|
+
* ForgejoOpError, ForgejoOpContext>` explicitly so the compiler never infers
|
|
12
|
+
* these back out of the schema generics.
|
|
13
|
+
*/
|
|
14
|
+
export type ForgejoOpError = DefaultErrors | ConfigError | HttpClientError.HttpClientError;
|
|
15
|
+
/** Context (requirements) shared by every generated Forgejo operation. */
|
|
16
|
+
export type ForgejoOpContext = Credentials | HttpClient.HttpClient;
|
|
17
|
+
export declare const ForgejoProtocol: Layer.Layer<API.Protocol>;
|
|
18
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,KAAK,eAAe,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAKhE,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,WAAW,GACX,eAAe,CAAC,eAAe,CAAC;AAEpC,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAenE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CA0BlD,CAAC"}
|
package/lib/protocol.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ForgejoProtocol — the shared bearer-REST protocol instantiated for Forgejo.
|
|
3
|
+
*
|
|
4
|
+
* Forgejo speaks plain JSON with no response envelope: list endpoints return
|
|
5
|
+
* a bare array, single resources return the object itself, and many
|
|
6
|
+
* mutations answer `204 No Content`. Failures carry `{ message, url }`; the
|
|
7
|
+
* message is the only signal, so typed errors beyond the status-derived ones
|
|
8
|
+
* (see `patches/`) match on it.
|
|
9
|
+
*
|
|
10
|
+
* Authentication is the `token` scheme (`Authorization: token <token>`),
|
|
11
|
+
* which Forgejo accepts for access tokens; `Bearer` is only honoured for
|
|
12
|
+
* OAuth2 tokens.
|
|
13
|
+
*
|
|
14
|
+
* Pagination is by page number (`page`/`limit`) with the total reported in
|
|
15
|
+
* an `X-Total-Count` response header and no in-body token, so no pagination
|
|
16
|
+
* trait is stamped on list operations — callers advance `page` until an
|
|
17
|
+
* empty page comes back. See `scripts/generate.ts`.
|
|
18
|
+
*/
|
|
19
|
+
import * as Effect from "effect/Effect";
|
|
20
|
+
import * as Redacted from "effect/Redacted";
|
|
21
|
+
import { makeRestProtocol, } from "@distilled.cloud/core/protocol-rest";
|
|
22
|
+
import { Credentials } from "./credentials.js";
|
|
23
|
+
import { UnknownForgejoError } from "./errors.js";
|
|
24
|
+
/**
|
|
25
|
+
* Forgejo error bodies are `{ message, url }`. A response that arrives
|
|
26
|
+
* without that envelope (a proxy 502, an HTML error page) falls through to
|
|
27
|
+
* the protocol's raw-text / `HTTP <status>` default.
|
|
28
|
+
*/
|
|
29
|
+
const errorEnvelope = (body) => {
|
|
30
|
+
if (body === null || typeof body !== "object")
|
|
31
|
+
return undefined;
|
|
32
|
+
const b = body;
|
|
33
|
+
return {
|
|
34
|
+
message: typeof b.message === "string" ? b.message : undefined,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export const ForgejoProtocol = makeRestProtocol({
|
|
38
|
+
// Resolved on the CALLING fiber per request (the layer is memoized per
|
|
39
|
+
// process); the Credentials service holds an effect, so a token rotated
|
|
40
|
+
// between calls is picked up without rebuilding the layer.
|
|
41
|
+
credentials: Effect.gen(function* () {
|
|
42
|
+
const resolve = yield* Credentials;
|
|
43
|
+
return yield* resolve;
|
|
44
|
+
}),
|
|
45
|
+
baseUrl: (creds) => creds.apiBaseUrl,
|
|
46
|
+
headers: (creds) => ({
|
|
47
|
+
Authorization: `token ${Redacted.value(creds.token)}`,
|
|
48
|
+
Accept: "application/json",
|
|
49
|
+
}),
|
|
50
|
+
errorEnvelope,
|
|
51
|
+
unknownError: ({ code, message, body }) => new UnknownForgejoError({
|
|
52
|
+
code: typeof code === "string"
|
|
53
|
+
? code
|
|
54
|
+
: code !== undefined
|
|
55
|
+
? String(code)
|
|
56
|
+
: undefined,
|
|
57
|
+
message,
|
|
58
|
+
body,
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAK5C,OAAO,EACL,gBAAgB,GAEjB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAsB,MAAM,aAAa,CAAC;AAgBtE;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,IAAa,EAAiC,EAAE;IACrE,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChE,MAAM,CAAC,GAAG,IAA+B,CAAC;IAC1C,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;KAC/D,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAC1B,gBAAgB,CAAS;IACvB,uEAAuE;IACvE,wEAAwE;IACxE,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC;IACxB,CAAC,CAAC;IACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU;IACpC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACnB,aAAa,EAAE,SAAS,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACrD,MAAM,EAAE,kBAAkB;KAC3B,CAAC;IACF,aAAa;IACb,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CACxC,IAAI,mBAAmB,CAAC;QACtB,IAAI,EACF,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,KAAK,SAAS;gBAClB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBACd,CAAC,CAAC,SAAS;QACjB,OAAO;QACP,IAAI;KACL,CAAC;CACL,CAAC,CAAC"}
|