@superdurable/connector-gitlab 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,222 @@
1
+ import { G as GetProjectInput, P as Project, C as Connection, L as ListIssuesInput, I as IssuesPage, U as UpdateIssueLabelsInput, a as Issue, O as Operations, b as Config, c as Credentials } from './connection-CmsyOQVf.js';
2
+ export { d as ConfigSchema, e as CredentialSource, f as GetProjectInputSchema, g as IssueSchema, h as IssuesPageSchema, i as ListIssuesInputSchema, j as ProjectSchema, k as UpdateIssueLabelsInputSchema, n as newConnection, l as newConnectionWithOperations } from './connection-CmsyOQVf.js';
3
+ import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
4
+ import { QueryDefinition, MutationDefinition, QueryStepConfig, Query, QueryResult, MutationStepConfig, Mutation, MutationResult, QueryStep, MutationStep, Call, QueryAttempt, MutationAttempt, CredentialProvider, Failure } from '@superdurable/connectors-sdk';
5
+ import { StepTarget } from '@superdurable/dex';
6
+ import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
7
+ import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
8
+ import 'zod';
9
+
10
+ /** Stable connector identity. */
11
+ declare const ConnectorID = "gitlab";
12
+ /** Provider identity for named connections. */
13
+ declare const ProviderID = "gitlab";
14
+ /** Branch IDs for getProject. */
15
+ declare const GetProjectBranch: {
16
+ readonly Found: "found";
17
+ readonly NotFound: "notFound";
18
+ readonly ProviderRejected: "providerRejected";
19
+ readonly InvalidResponse: "invalidResponse";
20
+ readonly Defect: "defect";
21
+ };
22
+ /** Read one GitLab project by numeric ID or namespace path. */
23
+ declare const GetProjectBranchFound: "found";
24
+ /** The requested resource does not exist or is inaccessible. */
25
+ declare const GetProjectBranchNotFound: "notFound";
26
+ /** The provider rejected the request. */
27
+ declare const GetProjectBranchProviderRejected: "providerRejected";
28
+ /** The provider returned malformed or oversized JSON. */
29
+ declare const GetProjectBranchInvalidResponse: "invalidResponse";
30
+ /** Local input or connection credentials are invalid. */
31
+ declare const GetProjectBranchDefect: "defect";
32
+ /** Manifest definition for getProject. */
33
+ declare const GetProjectDefinition: QueryDefinition;
34
+ /** Manifest metadata for getProject. */
35
+ declare const GetProjectMetadata: {
36
+ readonly kind: "query";
37
+ readonly idempotency: "none";
38
+ readonly authorization: "required";
39
+ };
40
+ /** Branch IDs for listIssues. */
41
+ declare const ListIssuesBranch: {
42
+ readonly Listed: "listed";
43
+ readonly NotFound: "notFound";
44
+ readonly ProviderRejected: "providerRejected";
45
+ readonly InvalidResponse: "invalidResponse";
46
+ readonly Defect: "defect";
47
+ };
48
+ /** List the first page of issues for a GitLab project. */
49
+ declare const ListIssuesBranchListed: "listed";
50
+ /** The requested resource does not exist or is inaccessible. */
51
+ declare const ListIssuesBranchNotFound: "notFound";
52
+ /** The provider rejected the request. */
53
+ declare const ListIssuesBranchProviderRejected: "providerRejected";
54
+ /** The provider returned malformed or oversized JSON. */
55
+ declare const ListIssuesBranchInvalidResponse: "invalidResponse";
56
+ /** Local input or connection credentials are invalid. */
57
+ declare const ListIssuesBranchDefect: "defect";
58
+ /** Manifest definition for listIssues. */
59
+ declare const ListIssuesDefinition: QueryDefinition;
60
+ /** Manifest metadata for listIssues. */
61
+ declare const ListIssuesMetadata: {
62
+ readonly kind: "query";
63
+ readonly idempotency: "none";
64
+ readonly authorization: "required";
65
+ };
66
+ /** Branch IDs for updateIssueLabels. */
67
+ declare const UpdateIssueLabelsBranch: {
68
+ readonly Updated: "updated";
69
+ readonly NotFound: "notFound";
70
+ readonly ProviderRejected: "providerRejected";
71
+ readonly InvalidResponse: "invalidResponse";
72
+ readonly Defect: "defect";
73
+ };
74
+ /** Replace one GitLab issue's complete label set; repeating the request is safe. */
75
+ declare const UpdateIssueLabelsBranchUpdated: "updated";
76
+ /** The requested resource does not exist or is inaccessible. */
77
+ declare const UpdateIssueLabelsBranchNotFound: "notFound";
78
+ /** The provider rejected the request. */
79
+ declare const UpdateIssueLabelsBranchProviderRejected: "providerRejected";
80
+ /** The provider returned malformed or oversized JSON. */
81
+ declare const UpdateIssueLabelsBranchInvalidResponse: "invalidResponse";
82
+ /** Local input or connection credentials are invalid. */
83
+ declare const UpdateIssueLabelsBranchDefect: "defect";
84
+ /** Manifest definition for updateIssueLabels. */
85
+ declare const UpdateIssueLabelsDefinition: MutationDefinition;
86
+ /** Manifest metadata for updateIssueLabels. */
87
+ declare const UpdateIssueLabelsMetadata: {
88
+ readonly kind: "mutation";
89
+ readonly idempotency: "required";
90
+ readonly authorization: "required";
91
+ };
92
+
93
+ /** Configuration for the getProject connector Step. */
94
+ interface GetProjectStepConfig<StepInput, OperationInput = GetProjectInput, OperationOutput = Project> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
95
+ /** Named connection supplying this operation. */
96
+ connection: Connection<{
97
+ getProject(): Query<OperationInput, OperationOutput>;
98
+ }>;
99
+ /** Name matching the bound connection. */
100
+ connectionName: string;
101
+ /** Read one GitLab project by numeric ID or namespace path. */
102
+ found: StepTarget<QueryResult<OperationOutput>>;
103
+ /** The requested resource does not exist or is inaccessible. */
104
+ notFound?: StepTarget<QueryResult<OperationOutput>>;
105
+ /** The provider rejected the request. */
106
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
107
+ /** The provider returned malformed or oversized JSON. */
108
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
109
+ /** Local input or connection credentials are invalid. */
110
+ defect?: StepTarget<QueryResult<OperationOutput>>;
111
+ }
112
+ /** Build the getProject Step from a named connection. */
113
+ declare function newGetProjectStep<StepInput, OperationInput = GetProjectInput, OperationOutput = Project>(configuration: GetProjectStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
114
+ /** Configuration for the listIssues connector Step. */
115
+ interface ListIssuesStepConfig<StepInput, OperationInput = ListIssuesInput, OperationOutput = IssuesPage> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
116
+ /** Named connection supplying this operation. */
117
+ connection: Connection<{
118
+ listIssues(): Query<OperationInput, OperationOutput>;
119
+ }>;
120
+ /** Name matching the bound connection. */
121
+ connectionName: string;
122
+ /** List the first page of issues for a GitLab project. */
123
+ listed: StepTarget<QueryResult<OperationOutput>>;
124
+ /** The requested resource does not exist or is inaccessible. */
125
+ notFound?: StepTarget<QueryResult<OperationOutput>>;
126
+ /** The provider rejected the request. */
127
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
128
+ /** The provider returned malformed or oversized JSON. */
129
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
130
+ /** Local input or connection credentials are invalid. */
131
+ defect?: StepTarget<QueryResult<OperationOutput>>;
132
+ }
133
+ /** Build the listIssues Step from a named connection. */
134
+ declare function newListIssuesStep<StepInput, OperationInput = ListIssuesInput, OperationOutput = IssuesPage>(configuration: ListIssuesStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
135
+ /** Configuration for the updateIssueLabels connector Step. */
136
+ interface UpdateIssueLabelsStepConfig<StepInput, OperationInput = UpdateIssueLabelsInput, OperationOutput = Issue> extends Omit<MutationStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
137
+ /** Named connection supplying this operation. */
138
+ connection: Connection<{
139
+ updateIssueLabels(): Mutation<OperationInput, OperationOutput>;
140
+ }>;
141
+ /** Name matching the bound connection. */
142
+ connectionName: string;
143
+ /** Replace one GitLab issue's complete label set; repeating the request is safe. */
144
+ updated: StepTarget<MutationResult<OperationOutput>>;
145
+ /** The requested resource does not exist or is inaccessible. */
146
+ notFound?: StepTarget<MutationResult<OperationOutput>>;
147
+ /** The provider rejected the request. */
148
+ providerRejected?: StepTarget<MutationResult<OperationOutput>>;
149
+ /** The provider returned malformed or oversized JSON. */
150
+ invalidResponse?: StepTarget<MutationResult<OperationOutput>>;
151
+ /** Local input or connection credentials are invalid. */
152
+ defect?: StepTarget<MutationResult<OperationOutput>>;
153
+ }
154
+ /** Build the updateIssueLabels Step from a named connection. */
155
+ declare function newUpdateIssueLabelsStep<StepInput, OperationInput = UpdateIssueLabelsInput, OperationOutput = Issue>(configuration: UpdateIssueLabelsStepConfig<StepInput, OperationInput, OperationOutput>): MutationStep<StepInput, OperationInput, OperationOutput>;
156
+
157
+ /** Bind a named GitLab project connection to the production client. */
158
+ declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
159
+
160
+ /** Read one GitLab project by ID or namespace path. */
161
+ declare class GetProjectOperation implements Query<GetProjectInput, Project> {
162
+ private readonly client;
163
+ /** Bind the authenticated client. */ constructor(client: GitLabClient);
164
+ /** Return the manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
165
+ /** Validate and classify one project lookup. */
166
+ invoke(call: Call, input: GetProjectInput): Promise<QueryAttempt<Project>>;
167
+ }
168
+ /** Read the first issue page for one project. */
169
+ declare class ListIssuesOperation implements Query<ListIssuesInput, IssuesPage> {
170
+ private readonly client;
171
+ /** Bind the authenticated client. */ constructor(client: GitLabClient);
172
+ /** Return the manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
173
+ /** Validate and classify one issue list. */
174
+ invoke(call: Call, input: ListIssuesInput): Promise<QueryAttempt<IssuesPage>>;
175
+ }
176
+ /** Replace the complete label set on a GitLab issue. */
177
+ declare class UpdateIssueLabelsOperation implements Mutation<UpdateIssueLabelsInput, Issue> {
178
+ private readonly client;
179
+ /** Bind the authenticated client. */ constructor(client: GitLabClient);
180
+ /** Return the manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
181
+ /** Reuse the Dex Call ID because absolute replacement is repeat safe. */ idempotencyKey(callId: string): string;
182
+ /** Validate and classify one absolute label replacement. */
183
+ invoke(call: Call, input: UpdateIssueLabelsInput): Promise<MutationAttempt<Issue>>;
184
+ }
185
+
186
+ /** Injectable bounded HTTP sender. */
187
+ type GitLabRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
188
+ /** Optional transport and clock for deterministic provider tests. */
189
+ interface GitLabClientOptions {
190
+ /** Override the production HTTP sender. */ send?: GitLabRequestSender;
191
+ /** Override the clock used for Retry-After dates. */ now?: () => Date;
192
+ }
193
+ /** Classified response from one GitLab exchange. */
194
+ type GitLabExchange = {
195
+ response: ProviderResponse;
196
+ } | {
197
+ branch: 'retry' | 'notFound' | 'providerRejected' | 'invalidResponse' | 'defect';
198
+ failure: Failure;
199
+ retryAfterMs: number;
200
+ };
201
+ /** Validated GitLab client with credentials resolved for each call. */
202
+ declare class GitLabClient {
203
+ private readonly baseUrl;
204
+ private readonly maxResponseBytes;
205
+ private readonly timeoutMs;
206
+ private readonly credentials;
207
+ private readonly send;
208
+ private readonly now;
209
+ /** Validate local configuration without contacting GitLab. */
210
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: GitLabClientOptions);
211
+ /** Bind the project query. */ getProject(): GetProjectOperation;
212
+ /** Bind the issue page query. */ listIssues(): ListIssuesOperation;
213
+ /** Bind the absolute label replacement mutation. */ updateIssueLabels(): UpdateIssueLabelsOperation;
214
+ /** Resolve credentials, send one request, and classify the provider response. */
215
+ exchange(call: Call, operation: string, method: 'GET' | 'PUT', path: string, body?: string): Promise<GitLabExchange>;
216
+ private classifyStatus;
217
+ private failure;
218
+ }
219
+ /** Encode one Go url.PathEscape segment, preserving its RFC 3986 path subdelimiters. */
220
+ declare function pathEscape(value: string): string;
221
+
222
+ export { Config, Connection, ConnectorID, Credentials, GetProjectBranch, GetProjectBranchDefect, GetProjectBranchFound, GetProjectBranchInvalidResponse, GetProjectBranchNotFound, GetProjectBranchProviderRejected, GetProjectDefinition, GetProjectInput, GetProjectMetadata, GetProjectOperation, type GetProjectStepConfig, GitLabClient, type GitLabClientOptions, type GitLabRequestSender, Issue, IssuesPage, ListIssuesBranch, ListIssuesBranchDefect, ListIssuesBranchInvalidResponse, ListIssuesBranchListed, ListIssuesBranchNotFound, ListIssuesBranchProviderRejected, ListIssuesDefinition, ListIssuesInput, ListIssuesMetadata, ListIssuesOperation, type ListIssuesStepConfig, Project, ProviderID, UpdateIssueLabelsBranch, UpdateIssueLabelsBranchDefect, UpdateIssueLabelsBranchInvalidResponse, UpdateIssueLabelsBranchNotFound, UpdateIssueLabelsBranchProviderRejected, UpdateIssueLabelsBranchUpdated, UpdateIssueLabelsDefinition, UpdateIssueLabelsInput, UpdateIssueLabelsMetadata, UpdateIssueLabelsOperation, type UpdateIssueLabelsStepConfig, newGetProjectStep, newListIssuesStep, newProjectConnection, newUpdateIssueLabelsStep, pathEscape };
package/dist/index.js ADDED
@@ -0,0 +1,362 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ GetProjectBranch,
6
+ GetProjectBranchDefect,
7
+ GetProjectBranchFound,
8
+ GetProjectBranchInvalidResponse,
9
+ GetProjectBranchNotFound,
10
+ GetProjectBranchProviderRejected,
11
+ GetProjectDefinition,
12
+ GetProjectInputSchema,
13
+ GetProjectMetadata,
14
+ IssueSchema,
15
+ IssuesPageSchema,
16
+ ListIssuesBranch,
17
+ ListIssuesBranchDefect,
18
+ ListIssuesBranchInvalidResponse,
19
+ ListIssuesBranchListed,
20
+ ListIssuesBranchNotFound,
21
+ ListIssuesBranchProviderRejected,
22
+ ListIssuesDefinition,
23
+ ListIssuesInputSchema,
24
+ ListIssuesMetadata,
25
+ ProjectSchema,
26
+ ProviderID,
27
+ UpdateIssueLabelsBranch,
28
+ UpdateIssueLabelsBranchDefect,
29
+ UpdateIssueLabelsBranchInvalidResponse,
30
+ UpdateIssueLabelsBranchNotFound,
31
+ UpdateIssueLabelsBranchProviderRejected,
32
+ UpdateIssueLabelsBranchUpdated,
33
+ UpdateIssueLabelsDefinition,
34
+ UpdateIssueLabelsInputSchema,
35
+ UpdateIssueLabelsMetadata,
36
+ newConnection,
37
+ newConnectionWithOperations,
38
+ newProjectConnection
39
+ } from "./chunk-LGQA5VXE.js";
40
+
41
+ // src/generated/steps.ts
42
+ import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
43
+ function newGetProjectStep(configuration) {
44
+ const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
45
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
46
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getProject(), connection: connection.reference, branches: [
47
+ goToBranch("found", found),
48
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
49
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
50
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
51
+ ...defect ? [goToBranch("defect", defect)] : []
52
+ ] });
53
+ }
54
+ function newListIssuesStep(configuration) {
55
+ const { connection, connectionName, listed, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
56
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
57
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listIssues(), connection: connection.reference, branches: [
58
+ goToBranch("listed", listed),
59
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
60
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
61
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
62
+ ...defect ? [goToBranch("defect", defect)] : []
63
+ ] });
64
+ }
65
+ function newUpdateIssueLabelsStep(configuration) {
66
+ const { connection, connectionName, updated, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
67
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
68
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateIssueLabels(), connection: connection.reference, branches: [
69
+ goToBranch("updated", updated),
70
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
71
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
72
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
73
+ ...defect ? [goToBranch("defect", defect)] : []
74
+ ] });
75
+ }
76
+
77
+ // src/project.ts
78
+ import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
79
+ import { z } from "zod";
80
+
81
+ // src/client.ts
82
+ import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
83
+ import { SecretString } from "@superdurable/connectors-sdk";
84
+
85
+ // src/operations.ts
86
+ import { newMutationBranch, newMutationRetry, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
87
+ var emptyProject = { id: 0, name: "", path_with_namespace: "", web_url: "" };
88
+ var emptyIssue = { id: 0, iid: 0, title: "", labels: [], web_url: "" };
89
+ var emptyPage = { issues: [] };
90
+ var GetProjectOperation = class {
91
+ /** Bind the authenticated client. */
92
+ constructor(client) {
93
+ this.client = client;
94
+ }
95
+ client;
96
+ /** Return the manifest definition. */
97
+ definition() {
98
+ return GetProjectDefinition;
99
+ }
100
+ /** Validate and classify one project lookup. */
101
+ async invoke(call, input) {
102
+ if (!input.projectId?.trim()) return queryDefect("getProject", emptyProject, "projectId is required");
103
+ const result = await this.client.exchange(call, "getProject", "GET", `/projects/${pathEscape(input.projectId)}`);
104
+ if (!("response" in result)) return queryOutcome(result, emptyProject);
105
+ try {
106
+ const value = JSON.parse(Buffer.from(result.response.body).toString("utf8"));
107
+ if (!value || typeof value !== "object" || !Number.isSafeInteger(value.id) || value.id <= 0) throw new Error("missing project ID");
108
+ return newQueryBranch("found", { id: value.id, name: stringField(value.name), path_with_namespace: stringField(value.path_with_namespace), web_url: stringField(value.web_url) }, {});
109
+ } catch {
110
+ return queryFailure("getProject", "invalidResponse", emptyProject);
111
+ }
112
+ }
113
+ };
114
+ var ListIssuesOperation = class {
115
+ /** Bind the authenticated client. */
116
+ constructor(client) {
117
+ this.client = client;
118
+ }
119
+ client;
120
+ /** Return the manifest definition. */
121
+ definition() {
122
+ return ListIssuesDefinition;
123
+ }
124
+ /** Validate and classify one issue list. */
125
+ async invoke(call, input) {
126
+ if (!input.projectId?.trim()) return queryDefect("listIssues", emptyPage, "projectId is required");
127
+ const result = await this.client.exchange(call, "listIssues", "GET", `/projects/${pathEscape(input.projectId)}/issues`);
128
+ if (!("response" in result)) return queryOutcome(result, emptyPage);
129
+ try {
130
+ const values = JSON.parse(Buffer.from(result.response.body).toString("utf8"));
131
+ if (!Array.isArray(values)) throw new Error("missing issues");
132
+ return newQueryBranch("listed", { issues: values.map(decodeIssue) }, {});
133
+ } catch {
134
+ return queryFailure("listIssues", "invalidResponse", emptyPage);
135
+ }
136
+ }
137
+ };
138
+ var UpdateIssueLabelsOperation = class {
139
+ /** Bind the authenticated client. */
140
+ constructor(client) {
141
+ this.client = client;
142
+ }
143
+ client;
144
+ /** Return the manifest definition. */
145
+ definition() {
146
+ return UpdateIssueLabelsDefinition;
147
+ }
148
+ /** Reuse the Dex Call ID because absolute replacement is repeat safe. */
149
+ idempotencyKey(callId) {
150
+ return callId;
151
+ }
152
+ /** Validate and classify one absolute label replacement. */
153
+ async invoke(call, input) {
154
+ if (!input.projectId?.trim() || !Number.isSafeInteger(input.issueIid) || input.issueIid <= 0) return mutationDefect("updateIssueLabels", "projectId and positive issueIid are required");
155
+ const labels = input.labels ?? [];
156
+ if (!Array.isArray(labels) || labels.some((label) => typeof label !== "string" || !label.trim() || label.includes(","))) return mutationDefect("updateIssueLabels", "labels must be nonblank and cannot contain commas");
157
+ const form = new URLSearchParams({ labels: labels.join(",") }).toString();
158
+ const result = await this.client.exchange(call, "updateIssueLabels", "PUT", `/projects/${pathEscape(input.projectId)}/issues/${input.issueIid}`, form);
159
+ if (!("response" in result)) return mutationOutcome(result);
160
+ try {
161
+ const value = decodeIssue(JSON.parse(Buffer.from(result.response.body).toString("utf8")));
162
+ if (value.id <= 0 || value.iid <= 0) throw new Error("missing issue identity");
163
+ return newMutationBranch("updated", value, {});
164
+ } catch {
165
+ return mutationFailure("updateIssueLabels", "invalidResponse", "PROTOCOL", "response was malformed");
166
+ }
167
+ }
168
+ };
169
+ function stringField(value) {
170
+ if (value === void 0 || value === null) return "";
171
+ if (typeof value !== "string") throw new Error("invalid string field");
172
+ return value;
173
+ }
174
+ function integerField(value) {
175
+ if (value === void 0 || value === null) return 0;
176
+ if (typeof value !== "number" || !Number.isSafeInteger(value)) throw new Error("invalid integer field");
177
+ return value;
178
+ }
179
+ function decodeIssue(input) {
180
+ if (!input || typeof input !== "object") throw new Error("invalid issue");
181
+ const issue = input;
182
+ if (issue.labels !== void 0 && issue.labels !== null && (!Array.isArray(issue.labels) || issue.labels.some((label) => typeof label !== "string"))) throw new Error("invalid labels");
183
+ return { id: integerField(issue.id), iid: integerField(issue.iid), title: stringField(issue.title), labels: issue.labels ?? [], web_url: stringField(issue.web_url) };
184
+ }
185
+ function failure(operation, kind, message) {
186
+ return { kind, provider: "gitlab", operation, message };
187
+ }
188
+ function queryDefect(operation, empty, message) {
189
+ return newQueryBranch("defect", empty, {}, failure(operation, "VALIDATION", message));
190
+ }
191
+ function mutationDefect(operation, message) {
192
+ return newMutationBranch("defect", emptyIssue, {}, failure(operation, "VALIDATION", message));
193
+ }
194
+ function queryFailure(operation, branch, empty) {
195
+ return newQueryBranch(branch, empty, {}, failure(operation, "PROTOCOL", "response was malformed"));
196
+ }
197
+ function mutationFailure(operation, branch, kind, message) {
198
+ return newMutationBranch(branch, emptyIssue, {}, failure(operation, kind, message));
199
+ }
200
+ function queryOutcome(result, empty) {
201
+ if (result.branch === "retry") return newQueryRetry(result.failure, result.retryAfterMs);
202
+ return newQueryBranch(result.branch, empty, {}, result.failure);
203
+ }
204
+ function mutationOutcome(result) {
205
+ if (result.branch === "retry") return newMutationRetry(result.failure, result.retryAfterMs);
206
+ return newMutationBranch(result.branch, emptyIssue, {}, result.failure);
207
+ }
208
+
209
+ // src/client.ts
210
+ var defaultBaseUrl = "https://gitlab.com/api/v4";
211
+ var defaultMaxResponseBytes = 2097152;
212
+ var defaultTimeoutMs = 15e3;
213
+ var GitLabClient = class {
214
+ baseUrl;
215
+ maxResponseBytes;
216
+ timeoutMs;
217
+ credentials;
218
+ send;
219
+ now;
220
+ /** Validate local configuration without contacting GitLab. */
221
+ constructor(config, credentials, options = {}) {
222
+ if (!credentials) throw new TypeError("GitLab credential source is required");
223
+ this.baseUrl = validateBaseURL(config.baseUrl || defaultBaseUrl);
224
+ this.maxResponseBytes = config.maxResponseBytes || defaultMaxResponseBytes;
225
+ this.timeoutMs = config.timeoutMs || defaultTimeoutMs;
226
+ if (!Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("maxResponseBytes must be positive");
227
+ if (!Number.isFinite(this.timeoutMs) || this.timeoutMs <= 0) throw new TypeError("timeoutMs must be positive");
228
+ this.credentials = credentials;
229
+ this.send = options.send ?? sendProviderRequest;
230
+ this.now = options.now ?? (() => /* @__PURE__ */ new Date());
231
+ }
232
+ /** Bind the project query. */
233
+ getProject() {
234
+ return new GetProjectOperation(this);
235
+ }
236
+ /** Bind the issue page query. */
237
+ listIssues() {
238
+ return new ListIssuesOperation(this);
239
+ }
240
+ /** Bind the absolute label replacement mutation. */
241
+ updateIssueLabels() {
242
+ return new UpdateIssueLabelsOperation(this);
243
+ }
244
+ /** Resolve credentials, send one request, and classify the provider response. */
245
+ async exchange(call, operation, method, path, body) {
246
+ let token;
247
+ try {
248
+ const credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
249
+ if (!(credentials.accessToken instanceof SecretString)) throw new TypeError("invalid credential");
250
+ token = credentials.accessToken.reveal();
251
+ if (!token || !isHeaderSafeCredential(token)) throw new TypeError("invalid credential");
252
+ } catch {
253
+ return this.failure("defect", operation, "AUTHENTICATION", "connection credentials are unavailable");
254
+ }
255
+ try {
256
+ const response = await this.send({
257
+ url: this.baseUrl + path,
258
+ method,
259
+ headers: { "PRIVATE-TOKEN": token, Accept: "application/json", ...body !== void 0 ? { "Content-Type": "application/x-www-form-urlencoded" } : {} },
260
+ ...body !== void 0 ? { body: Buffer.from(body, "utf8") } : {},
261
+ maxResponseBytes: this.maxResponseBytes,
262
+ timeoutMs: this.timeoutMs,
263
+ addressPolicy: this.baseUrl === defaultBaseUrl ? "publicHTTPS" : "privateNetworkHTTP",
264
+ signal: call.context.cancellationSignal
265
+ });
266
+ const statusOutcome = this.classifyStatus(operation, response.status, response.headers);
267
+ if (statusOutcome) return statusOutcome;
268
+ return { response };
269
+ } catch (error) {
270
+ if (error instanceof BodyTooLargeError) {
271
+ const statusOutcome = this.classifyStatus(operation, error.status, error.headers);
272
+ if (statusOutcome) return statusOutcome;
273
+ return this.failure("invalidResponse", operation, "RESPONSE_TOO_LARGE", "response exceeded the configured limit");
274
+ }
275
+ return this.failure("retry", operation, "AVAILABILITY", "GitLab request failed");
276
+ }
277
+ }
278
+ classifyStatus(operation, status, headers) {
279
+ if (status === void 0 || status === 200) return void 0;
280
+ if (status === 429 || status === 408 || status === 409 || status >= 500) {
281
+ return this.failure("retry", operation, status === 429 ? "RATE_LIMIT" : "AVAILABILITY", `GitLab returned HTTP ${status}`, parseRetryAfter(header(headers, "retry-after"), this.now()));
282
+ }
283
+ if (status === 404) return this.failure("notFound", operation, "NOT_FOUND", `GitLab returned HTTP ${status}`);
284
+ const kind = status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : status === 400 || status === 422 ? "VALIDATION" : "PROVIDER_REJECTION";
285
+ return this.failure("providerRejected", operation, kind, `GitLab returned HTTP ${status}`);
286
+ }
287
+ failure(branch, operation, kind, message, retryAfterMs = 0) {
288
+ return { branch, failure: { kind, provider: "gitlab", operation, message }, retryAfterMs };
289
+ }
290
+ };
291
+ function header(headers, name) {
292
+ const value = headers?.[name];
293
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
294
+ }
295
+ function pathEscape(value) {
296
+ return encodeURIComponent(value).replace(/%24/g, "$").replace(/%26/g, "&").replace(/%2B/g, "+").replace(/%3A/g, ":").replace(/%3D/g, "=").replace(/%40/g, "@").replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
297
+ }
298
+
299
+ // src/project.ts
300
+ function newProjectConnection2(project, connectionName) {
301
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
302
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "gitlab" && entry.connectionName === name);
303
+ if (!selected) throw new TypeError("GitLab project connection is not configured");
304
+ const config = z.object({ baseUrl: z.string().optional(), timeoutMs: z.number().optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
305
+ const credentials = {
306
+ async resolve(call, signal) {
307
+ void call;
308
+ const fields = await loadedProject.resolveCredential("gitlab", name, signal);
309
+ const decoded = z.object({ access_token: z.string().min(1) }).parse(fields);
310
+ return { accessToken: new SecretString2(decoded.access_token) };
311
+ }
312
+ };
313
+ return new GitLabClient(config, credentials);
314
+ });
315
+ }
316
+ export {
317
+ ConfigSchema,
318
+ Connection,
319
+ ConnectorID,
320
+ GetProjectBranch,
321
+ GetProjectBranchDefect,
322
+ GetProjectBranchFound,
323
+ GetProjectBranchInvalidResponse,
324
+ GetProjectBranchNotFound,
325
+ GetProjectBranchProviderRejected,
326
+ GetProjectDefinition,
327
+ GetProjectInputSchema,
328
+ GetProjectMetadata,
329
+ GetProjectOperation,
330
+ GitLabClient,
331
+ IssueSchema,
332
+ IssuesPageSchema,
333
+ ListIssuesBranch,
334
+ ListIssuesBranchDefect,
335
+ ListIssuesBranchInvalidResponse,
336
+ ListIssuesBranchListed,
337
+ ListIssuesBranchNotFound,
338
+ ListIssuesBranchProviderRejected,
339
+ ListIssuesDefinition,
340
+ ListIssuesInputSchema,
341
+ ListIssuesMetadata,
342
+ ListIssuesOperation,
343
+ ProjectSchema,
344
+ ProviderID,
345
+ UpdateIssueLabelsBranch,
346
+ UpdateIssueLabelsBranchDefect,
347
+ UpdateIssueLabelsBranchInvalidResponse,
348
+ UpdateIssueLabelsBranchNotFound,
349
+ UpdateIssueLabelsBranchProviderRejected,
350
+ UpdateIssueLabelsBranchUpdated,
351
+ UpdateIssueLabelsDefinition,
352
+ UpdateIssueLabelsInputSchema,
353
+ UpdateIssueLabelsMetadata,
354
+ UpdateIssueLabelsOperation,
355
+ newConnection,
356
+ newConnectionWithOperations,
357
+ newGetProjectStep,
358
+ newListIssuesStep,
359
+ newProjectConnection2 as newProjectConnection,
360
+ newUpdateIssueLabelsStep,
361
+ pathEscape
362
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ import { MockQuery, MockMutation, Case } from '@superdurable/connectors-sdk/connectormock';
2
+ import { Failure } from '@superdurable/connectors-sdk';
3
+ import { O as Operations, C as Connection, G as GetProjectInput, P as Project, L as ListIssuesInput, I as IssuesPage, U as UpdateIssueLabelsInput, a as Issue } from './connection-CmsyOQVf.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for GetProjectInput in scripted cases. */
7
+ declare const emptyGetProjectInput: GetProjectInput;
8
+ /** Go zero value for Project in scripted cases. */
9
+ declare const emptyProject: Project;
10
+ /** Go zero value for ListIssuesInput in scripted cases. */
11
+ declare const emptyListIssuesInput: ListIssuesInput;
12
+ /** Go zero value for Issue in scripted cases. */
13
+ declare const emptyIssue: Issue;
14
+ /** Go zero value for IssuesPage in scripted cases. */
15
+ declare const emptyIssuesPage: IssuesPage;
16
+ /** Go zero value for UpdateIssueLabelsInput in scripted cases. */
17
+ declare const emptyUpdateIssueLabelsInput: UpdateIssueLabelsInput;
18
+ /** Script the found branch. */
19
+ declare function getProjectFound(value: Project, failure?: Failure): Case<Project>;
20
+ /** Script the notFound branch. */
21
+ declare function getProjectNotFound(value: Project, failure?: Failure): Case<Project>;
22
+ /** Script the providerRejected branch. */
23
+ declare function getProjectProviderRejected(value: Project, failure?: Failure): Case<Project>;
24
+ /** Script the invalidResponse branch. */
25
+ declare function getProjectInvalidResponse(value: Project, failure?: Failure): Case<Project>;
26
+ /** Script the defect branch. */
27
+ declare function getProjectDefect(value: Project, failure?: Failure): Case<Project>;
28
+ /** Script a safe retry of getProject. */
29
+ declare function getProjectRetry(failure: Failure, retryAfterMs?: number): Case<Project>;
30
+ /** Manifest scenario foundDefault for getProject. */
31
+ declare function getProjectFoundDefault(): Case<Project>;
32
+ /** Default getProject scenario. */
33
+ declare function getProjectDefault(): Case<Project>;
34
+ /** Script the listed branch. */
35
+ declare function listIssuesListed(value: IssuesPage, failure?: Failure): Case<IssuesPage>;
36
+ /** Script the notFound branch. */
37
+ declare function listIssuesNotFound(value: IssuesPage, failure?: Failure): Case<IssuesPage>;
38
+ /** Script the providerRejected branch. */
39
+ declare function listIssuesProviderRejected(value: IssuesPage, failure?: Failure): Case<IssuesPage>;
40
+ /** Script the invalidResponse branch. */
41
+ declare function listIssuesInvalidResponse(value: IssuesPage, failure?: Failure): Case<IssuesPage>;
42
+ /** Script the defect branch. */
43
+ declare function listIssuesDefect(value: IssuesPage, failure?: Failure): Case<IssuesPage>;
44
+ /** Script a safe retry of listIssues. */
45
+ declare function listIssuesRetry(failure: Failure, retryAfterMs?: number): Case<IssuesPage>;
46
+ /** Manifest scenario listedDefault for listIssues. */
47
+ declare function listIssuesListedDefault(): Case<IssuesPage>;
48
+ /** Default listIssues scenario. */
49
+ declare function listIssuesDefault(): Case<IssuesPage>;
50
+ /** Script the updated branch. */
51
+ declare function updateIssueLabelsUpdated(value: Issue, failure?: Failure): Case<Issue>;
52
+ /** Script the notFound branch. */
53
+ declare function updateIssueLabelsNotFound(value: Issue, failure?: Failure): Case<Issue>;
54
+ /** Script the providerRejected branch. */
55
+ declare function updateIssueLabelsProviderRejected(value: Issue, failure?: Failure): Case<Issue>;
56
+ /** Script the invalidResponse branch. */
57
+ declare function updateIssueLabelsInvalidResponse(value: Issue, failure?: Failure): Case<Issue>;
58
+ /** Script the defect branch. */
59
+ declare function updateIssueLabelsDefect(value: Issue, failure?: Failure): Case<Issue>;
60
+ /** Script a safe retry of updateIssueLabels. */
61
+ declare function updateIssueLabelsRetry(failure: Failure, retryAfterMs?: number): Case<Issue>;
62
+ /** Manifest scenario updatedDefault for updateIssueLabels. */
63
+ declare function updateIssueLabelsUpdatedDefault(): Case<Issue>;
64
+ /** Default updateIssueLabels scenario. */
65
+ declare function updateIssueLabelsDefault(): Case<Issue>;
66
+ /** Scripted operations and manifest defaults for this connector. */
67
+ declare class GeneratedMock implements Operations {
68
+ #private;
69
+ constructor(connectionName: string);
70
+ connection(): Connection;
71
+ getProject(): MockQuery<GetProjectInput, Project>;
72
+ listIssues(): MockQuery<ListIssuesInput, IssuesPage>;
73
+ updateIssueLabels(): MockMutation<UpdateIssueLabelsInput, Issue>;
74
+ assertNoFailures(): void;
75
+ }
76
+
77
+ export { GeneratedMock, emptyGetProjectInput, emptyIssue, emptyIssuesPage, emptyListIssuesInput, emptyProject, emptyUpdateIssueLabelsInput, getProjectDefault, getProjectDefect, getProjectFound, getProjectFoundDefault, getProjectInvalidResponse, getProjectNotFound, getProjectProviderRejected, getProjectRetry, listIssuesDefault, listIssuesDefect, listIssuesInvalidResponse, listIssuesListed, listIssuesListedDefault, listIssuesNotFound, listIssuesProviderRejected, listIssuesRetry, updateIssueLabelsDefault, updateIssueLabelsDefect, updateIssueLabelsInvalidResponse, updateIssueLabelsNotFound, updateIssueLabelsProviderRejected, updateIssueLabelsRetry, updateIssueLabelsUpdated, updateIssueLabelsUpdatedDefault };