@vite-hub/forge 0.4.1 → 0.5.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.
Files changed (32) hide show
  1. package/README.md +11 -4
  2. package/dist/{association-Ds6Tgs0W-Cu9_YCGq.js → association-Ds6Tgs0W-CgBVH3ii.js} +1 -2
  3. package/dist/build/node.d.ts +1 -3
  4. package/dist/build/node.js +3 -6
  5. package/dist/build.d.ts +1 -1
  6. package/dist/build.js +1 -2
  7. package/dist/{forgejo-UNPc42cY.js → definition-BQFdu9ti-WxMjcAEl.js} +15 -13
  8. package/dist/{events-DW3SFUDA-D2rhS9D-.js → events-BL0zcgMf-9TwyYtCt.js} +3 -5
  9. package/dist/{events-uCMi3LHU-Bz79PQtq.js → events-DDdJnmD2-BSMoOqjV.js} +4 -5
  10. package/dist/{events-DjRw3KSr-C72gY7Vu.js → events-DHqSJ5KI-z2-5_1vo.js} +59 -60
  11. package/dist/{events-DmSWTdpS-BdJBABfI.js → events-DXE-Ul2S-BzTkugIK.js} +4 -5
  12. package/dist/{feed-BlzdKdNv-DbxuSgsx.js → feed-B1OiHFg0-DevZZe0y.js} +3 -5
  13. package/dist/{feed-CIaAZINm-Dpe9DxwK.js → feed-DROLF1tb-CtRfA_7N.js} +3 -5
  14. package/dist/{feed-BwdcTgZq-Bm_c8br8.js → feed-iWegqepj-ConxMpg4.js} +3 -5
  15. package/dist/forgejo-4sbZukng.js +6 -0
  16. package/dist/gitea-Cj7qy2X3.js +10 -0
  17. package/dist/{gitee-BXyl2_3W-dQOAjWqr.js → gitee-CKt4pEC0-BuLWggck.js} +2 -3
  18. package/dist/{github-CUiEF2FK.js → github-CHzhqYOr.js} +377 -293
  19. package/dist/{gitlab-zvWb9zOi.js → gitlab-CS0shW2u.js} +12 -10
  20. package/dist/{graphql-BDhuP5jN-BSpB8lWf.js → graphql-DxRA9BGO-BBbmTmWi.js} +43 -33
  21. package/dist/{identity-CmVEBLP5.js → identity-BwC2_3S9.js} +1 -2
  22. package/dist/{identity-CNTWZZuv.d.ts → identity-D2-HaDku.d.ts} +0 -2
  23. package/dist/index.d.ts +50 -44
  24. package/dist/index.js +149 -98
  25. package/dist/model-Biiu1CfI-CVLamGai.js +288 -0
  26. package/dist/{templates-BGDqQMu4-PSB43E1j.js → templates-0m5QBVIh-D1fZeoC-.js} +3 -3
  27. package/dist/{webhooks-Bc6QhmI8-CNgCERCq.js → webhooks-Bc6QhmI8-eK71_mJE.js} +1034 -98
  28. package/package.json +8 -7
  29. package/dist/events-C6C7lk1x-J8VCAjEX.js +0 -131
  30. package/dist/knot-bGebBK_B-CeDHcJUz.js +0 -350
  31. package/dist/tangled-8lg_73Wi-bSufNXiN.js +0 -43
  32. package/dist/utils-DC7MBR65-B7Vr2hFm.js +0 -1214
@@ -0,0 +1,288 @@
1
+ // ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/errors-DBJbfvy-.mjs
2
+ /** Base class for every error that forges throws. */
3
+ var ForgeError = class extends Error {
4
+ name = "ForgeError";
5
+ /** The forge that the request went to. */
6
+ forge;
7
+ instance;
8
+ url;
9
+ method;
10
+ constructor(message, context = {}, options) {
11
+ super(message, options);
12
+ this.forge = context.forge;
13
+ this.instance = context.instance;
14
+ this.url = context.url;
15
+ this.method = context.method;
16
+ }
17
+ };
18
+ /** The forge responded with an error. */
19
+ var ForgeApiError = class extends ForgeError {
20
+ name = "ForgeApiError";
21
+ status;
22
+ /** Truncated response body, for diagnostics. */
23
+ body;
24
+ constructor(message, status, body, context, options) {
25
+ super(message, context, options);
26
+ this.status = status;
27
+ this.body = body;
28
+ }
29
+ };
30
+ /** A 404: the resource does not exist, or the credential cannot see it. Many forges respond the same way to both. */
31
+ var NotFoundError = class extends ForgeApiError {
32
+ name = "NotFoundError";
33
+ };
34
+ /**
35
+ * A 401, or a 403 with a request budget of zero (GitHub GraphQL), for a request
36
+ * sent without credentials. A rejected credential is {@link TokenRevokedError}.
37
+ */
38
+ var AuthenticationRequiredError = class extends ForgeApiError {
39
+ name = "AuthenticationRequiredError";
40
+ };
41
+ /** The forge rate limited the request and a retry didn't help. Every rate limit rejects with this class, primary or secondary. */
42
+ var RateLimitedError = class extends ForgeApiError {
43
+ name = "RateLimitedError";
44
+ /** When to send again: after the forge's `retry-after`, or when a used-up budget resets. Absent when the forge names neither. */
45
+ resetAt;
46
+ /**
47
+ * Whether the forge applied a secondary limit, such as a limit on concurrent requests or on content creation,
48
+ * rather than a used-up request budget. No remaining-request counter predicts it.
49
+ */
50
+ secondary;
51
+ constructor(message, status, body, options = {}, errorOptions) {
52
+ super(message, status, body, options, errorOptions);
53
+ this.resetAt = options.resetAt;
54
+ this.secondary = options.secondary ?? false;
55
+ }
56
+ };
57
+ /** The credential was revoked or expired. */
58
+ var TokenRevokedError = class extends ForgeApiError {
59
+ name = "TokenRevokedError";
60
+ };
61
+ /** The credential is valid but lacks the scope or permission for this call. */
62
+ var InsufficientScopeError = class extends ForgeApiError {
63
+ name = "InsufficientScopeError";
64
+ /** Scopes that would allow the request, any one of them, where the forge names them (GitHub's `X-Accepted-OAuth-Scopes`). */
65
+ acceptedScopes;
66
+ /** Scopes the credential holds, where the forge reports them (GitHub's `X-OAuth-Scopes`). */
67
+ grantedScopes;
68
+ /** Fine-grained permissions that would allow the request, verbatim, such as `issues=write` (GitHub's `X-Accepted-GitHub-Permissions`). */
69
+ acceptedPermissionsRaw;
70
+ constructor(message, status, body, context, options) {
71
+ super(message, status, body, context, options);
72
+ this.acceptedScopes = context?.acceptedScopes;
73
+ this.grantedScopes = context?.grantedScopes;
74
+ this.acceptedPermissionsRaw = context?.acceptedPermissionsRaw;
75
+ }
76
+ };
77
+ /**
78
+ * The forge refused the request for a reason other than a missing scope or a
79
+ * rate limit: an organisation policy, an SSO requirement, a protected
80
+ * resource, a release the forge has marked immutable, or a resource that
81
+ * belongs to another app. A missing scope is
82
+ * {@link InsufficientScopeError}, and a rate limit {@link RateLimitedError}.
83
+ */
84
+ var ForbiddenError = class extends ForgeApiError {
85
+ name = "ForbiddenError";
86
+ /** Why the forge refused the request. */
87
+ reason;
88
+ /** The forge's own wording, for diagnostics and for reasons that have no `ForbiddenReason`. */
89
+ reasonRaw;
90
+ /** Where the user authorises the credential for the organisation, when `reason` is `sso_required` and the forge links it (GitHub's `X-GitHub-SSO`). */
91
+ ssoUrl;
92
+ constructor(message, status, body, reason, context, options) {
93
+ super(message, status, body, context, options);
94
+ this.reason = reason;
95
+ this.reasonRaw = context?.reasonRaw;
96
+ this.ssoUrl = context?.ssoUrl;
97
+ }
98
+ };
99
+ /** Body patterns that identify a 403 reason, most specific first. */
100
+ const FORBIDDEN_PATTERNS = [
101
+ ["org_restriction", /third[- ]party application|OAuth App access restrictions|organization has enabled OAuth|not authorized by the organization|blocked by the organization/i],
102
+ ["sso_required", /SAML|single sign[- ]on|\bSSO\b|must be granted .* organization/i],
103
+ ["resource_protected", /archived|read[- ]only|protected branch|repository has been disabled|is disabled/i],
104
+ ["unknown", /contributor list is too large[^".]*/i]
105
+ ];
106
+ /**
107
+ * Classifies a 403 body. Returns `undefined` for a body that names no policy
108
+ * the caller could act on, which stays {@link InsufficientScopeError}.
109
+ */
110
+ function forbiddenReason(body) {
111
+ for (const [reason, pattern] of FORBIDDEN_PATTERNS) {
112
+ const match = body.match(pattern);
113
+ if (match) return {
114
+ reason,
115
+ reasonRaw: match[0]
116
+ };
117
+ }
118
+ }
119
+ const SECONDARY_RATE_LIMIT_RE = /secondary rate limit|abuse detection|submitted too quickly/i;
120
+ /** Whether an error message names a secondary rate limit, such as GitHub's limits on concurrency and content creation. */
121
+ function isSecondaryRateLimit(message) {
122
+ return SECONDARY_RATE_LIMIT_RE.test(message);
123
+ }
124
+ /** The pull request cannot be merged yet, typically because of failing or pending checks or branch protection. */
125
+ var MergeBlockedError = class extends ForgeApiError {
126
+ name = "MergeBlockedError";
127
+ };
128
+ /** The merge conflicts with the base branch, or the head moved since `sha` was read. */
129
+ var MergeConflictError = class extends ForgeApiError {
130
+ name = "MergeConflictError";
131
+ };
132
+ /** `contents.commitFiles()` was given an `expectedHead`, or `threads.updateBranch()` a `sha`, and the branch no longer points at it. */
133
+ var BranchMovedError = class extends ForgeApiError {
134
+ name = "BranchMovedError";
135
+ };
136
+ /** A request or a pending merge exceeded `timeout`. */
137
+ var ForgeTimeoutError = class extends ForgeError {
138
+ name = "ForgeTimeoutError";
139
+ /** The timeout that was exceeded, in milliseconds. */
140
+ timeout;
141
+ constructor(message, timeout, context, options) {
142
+ super(message, context, options);
143
+ this.timeout = timeout;
144
+ }
145
+ };
146
+ /** The request never got a response: DNS, TLS, connection refused or a proxy refusal. */
147
+ var ForgeNetworkError = class extends ForgeError {
148
+ name = "ForgeNetworkError";
149
+ };
150
+ /** A delivery's signature didn't match. */
151
+ var WebhookVerificationError = class extends ForgeError {
152
+ name = "WebhookVerificationError";
153
+ };
154
+ /** The forge doesn't support the operation. */
155
+ var UnsupportedOperationError = class extends ForgeError {
156
+ name = "UnsupportedOperationError";
157
+ };
158
+ /** A write was called on a provider constructed with `readOnly: true`. */
159
+ var ReadOnlyError = class extends UnsupportedOperationError {
160
+ name = "ReadOnlyError";
161
+ };
162
+ /** `contents.getFile` was asked for text and the file's bytes are not valid UTF-8. */
163
+ var ContentNotTextError = class extends ForgeError {
164
+ name = "ContentNotTextError";
165
+ };
166
+ /** Maps a generic merge-endpoint failure onto {@link MergeBlockedError} or {@link MergeConflictError}. */
167
+ function toMergeError(error) {
168
+ if (!(error instanceof ForgeApiError) || error.constructor !== ForgeApiError) return error;
169
+ const context = {
170
+ forge: error.forge,
171
+ instance: error.instance,
172
+ url: error.url,
173
+ method: error.method
174
+ };
175
+ if (error.status === 405) return new MergeBlockedError("Pull request is not mergeable yet", error.status, error.body, context, { cause: error });
176
+ if (error.status === 406 || error.status === 409) return new MergeConflictError("Pull request conflicts with its base or the head has moved", error.status, error.body, context, { cause: error });
177
+ return error;
178
+ }
179
+ /** The thread ref has no number, or is a kind the provider cannot address. */
180
+ var UnresolvedThreadError = class extends ForgeError {
181
+ name = "UnresolvedThreadError";
182
+ };
183
+ /** No merge method was given, and the repository allows several or reports none. */
184
+ var MergeMethodRequiredError = class extends ForgeError {
185
+ name = "MergeMethodRequiredError";
186
+ /** The merge methods that the repository allows. */
187
+ allowed;
188
+ constructor(allowed, context, options) {
189
+ super(allowed.length ? `Repository allows ${allowed.join(", ")}; pass \`method\` to choose one` : "Repository reports no merge method this provider can use; pass `method` explicitly", context, options);
190
+ this.allowed = allowed;
191
+ }
192
+ };
193
+ /** Picks the only allowed merge method, or throws {@link MergeMethodRequiredError}. */
194
+ function soleMergeMethod(allowed, context) {
195
+ const methods = Object.keys(allowed).filter((method) => allowed[method]);
196
+ if (methods.length !== 1) throw new MergeMethodRequiredError(methods, context);
197
+ return methods[0];
198
+ }
199
+ // ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/model-Biiu1CfI.mjs
200
+ /** Whether `support` means the operation cannot be called. Test this rather than `support === false`: `'not_applicable'` is a non-empty string. Accepts the declaration-only levels too, so a declared level can be tested before it resolves. */
201
+ function isUnsupported(support) {
202
+ return support === false || support === "not_applicable";
203
+ }
204
+ /** Every name {@link ReactionContent} covers. */
205
+ const REACTION_CONTENTS = [
206
+ "+1",
207
+ "-1",
208
+ "laugh",
209
+ "confused",
210
+ "heart",
211
+ "hooray",
212
+ "rocket",
213
+ "eyes"
214
+ ];
215
+ /** The normalised name for a forge-native reaction name, or `'other'` where there is none. */
216
+ function reactionContent(raw) {
217
+ return REACTION_CONTENTS.includes(raw) ? raw : "other";
218
+ }
219
+ const CASE_INSENSITIVE = /* @__PURE__ */ new Set([
220
+ "github",
221
+ "gitlab",
222
+ "forgejo",
223
+ "gitea",
224
+ "bitbucket",
225
+ "gitee",
226
+ "azure-devops"
227
+ ]);
228
+ /** Whether `forge` treats owner and repository names case-insensitively. Unknown forges are assumed not to. */
229
+ function namesAreCaseInsensitive(forge) {
230
+ return CASE_INSENSITIVE.has(forge);
231
+ }
232
+ /** `repo` with `owner` and `name` lowercased where the forge ignores case, so equal repositories compare equal. */
233
+ function normaliseRepoName(repo) {
234
+ return namesAreCaseInsensitive(repo.forge) ? {
235
+ ...repo,
236
+ owner: repo.owner.toLowerCase(),
237
+ name: repo.name.toLowerCase()
238
+ } : repo;
239
+ }
240
+ /** Whether `ref` addresses an organisation, group or workspace rather than a repository, by its `kind`. */
241
+ function isNamespaceRef(ref) {
242
+ return ref.kind === "namespace";
243
+ }
244
+ /**
245
+ * The ref of a repository on `origin` from the `owner/name` that people type. The name is what follows the last
246
+ * slash, so a GitLab subgroup stays in `owner`.
247
+ * @param origin The forge and instance, such as a provider.
248
+ * @param slug The repository, such as `acme/widgets` or `acme/platform/widgets`.
249
+ * @throws {TypeError} When `slug` has no owner or no name.
250
+ * @example
251
+ * ```ts
252
+ * const repo = repoRef(provider, 'acme/widgets')
253
+ * ```
254
+ */
255
+ function repoRef(origin, slug) {
256
+ const last = slug.lastIndexOf("/");
257
+ if (last <= 0 || last === slug.length - 1) throw new TypeError(`Repository ${JSON.stringify(slug)} is not in the form owner/name`);
258
+ return {
259
+ forge: origin.forge,
260
+ instance: origin.instance,
261
+ owner: slug.slice(0, last),
262
+ name: slug.slice(last + 1)
263
+ };
264
+ }
265
+ /**
266
+ * The ref of an organisation, group, workspace or project on `origin`, as `orgs`, `repos.byOwner()` and
267
+ * namespace webhooks take it.
268
+ * @param origin The forge and instance, such as a provider.
269
+ * @param owner The namespace path, such as `acme`, `acme/platform` on GitLab or `acme/Widgets` on Azure DevOps.
270
+ * @example
271
+ * ```ts
272
+ * const teams = provider.orgs.teams(namespaceRef(provider, 'acme'))
273
+ * ```
274
+ */
275
+ function namespaceRef(origin, owner) {
276
+ return {
277
+ forge: origin.forge,
278
+ instance: origin.instance,
279
+ owner,
280
+ name: "",
281
+ kind: "namespace"
282
+ };
283
+ }
284
+ /** Whether a thread ref has a number, so that it is a `ResolvedThreadRef`. */
285
+ function isResolvedThread(thread) {
286
+ return typeof thread.number === "string" && thread.number !== "";
287
+ }
288
+ export { toMergeError as A, TokenRevokedError as C, forbiddenReason as D, WebhookVerificationError as E, isSecondaryRateLimit as O, ReadOnlyError as S, UnsupportedOperationError as T, InsufficientScopeError as _, namespaceRef as a, NotFoundError as b, repoRef as c, ContentNotTextError as d, ForbiddenError as f, ForgeTimeoutError as g, ForgeNetworkError as h, isUnsupported as i, soleMergeMethod as k, AuthenticationRequiredError as l, ForgeError as m, isNamespaceRef as n, normaliseRepoName as o, ForgeApiError as p, isResolvedThread as r, reactionContent as s, REACTION_CONTENTS as t, BranchMovedError as u, MergeBlockedError as v, UnresolvedThreadError as w, RateLimitedError as x, MergeConflictError as y };
@@ -1,5 +1,6 @@
1
- import { I as mapConcurrent, d as NotFoundError } from "./utils-DC7MBR65-B7Vr2hFm.js";
2
- //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/templates-BGDqQMu4.mjs
1
+ import { b as NotFoundError } from "./model-Biiu1CfI-CVLamGai.js";
2
+ import { z as mapConcurrent } from "./webhooks-Bc6QhmI8-eK71_mJE.js";
3
+ // ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/templates-0m5QBVIh.mjs
3
4
  /** Where GitHub looks for a pull request template and the legacy issue template, in its order of precedence. */
4
5
  const LOCATIONS = [
5
6
  ".github",
@@ -121,5 +122,4 @@ async function orEmpty(listing) {
121
122
  throw error;
122
123
  }
123
124
  }
124
- //#endregion
125
125
  export { readTemplates };