@superdurable/connector-sentry 0.0.0-stage → 0.1.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.
@@ -0,0 +1,218 @@
1
+ import { G as GetIssueInput, I as Issue, C as Connection, L as ListIssuesInput, a as IssuePage, U as UpdateIssueStatusInput, b as Config, c as Credentials, O as Operations } from './connection-e93NjxbJ.js';
2
+ export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, g as GetIssueInputSchema, h as IssuePageSchema, i as IssueSchema, j as ListIssuesInputSchema, k as UpdateIssueStatusInputSchema, l as decodeCredentials, m as isCredentialMaterialError, n as newConnection, o as newConnectionWithOperations } from './connection-e93NjxbJ.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 = "sentry";
12
+ /** Provider identity for named connections. */
13
+ declare const ProviderID = "sentry";
14
+ /** Branch IDs for listIssues. */
15
+ declare const ListIssuesBranch: {
16
+ readonly Listed: "listed";
17
+ readonly ProviderRejected: "providerRejected";
18
+ readonly InvalidResponse: "invalidResponse";
19
+ readonly Defect: "defect";
20
+ };
21
+ /** Sentry returned the requested result. */
22
+ declare const ListIssuesBranchListed: "listed";
23
+ /** The provider definitively rejected the request. */
24
+ declare const ListIssuesBranchProviderRejected: "providerRejected";
25
+ /** The provider returned malformed or oversized JSON. */
26
+ declare const ListIssuesBranchInvalidResponse: "invalidResponse";
27
+ /** Local input or connection credentials are invalid. */
28
+ declare const ListIssuesBranchDefect: "defect";
29
+ /** Manifest definition for listIssues. */
30
+ declare const ListIssuesDefinition: QueryDefinition;
31
+ /** Manifest metadata for listIssues. */
32
+ declare const ListIssuesMetadata: {
33
+ readonly kind: "query";
34
+ readonly idempotency: "none";
35
+ readonly authorization: "required";
36
+ };
37
+ /** Branch IDs for getIssue. */
38
+ declare const GetIssueBranch: {
39
+ readonly Found: "found";
40
+ readonly NotFound: "notFound";
41
+ readonly ProviderRejected: "providerRejected";
42
+ readonly InvalidResponse: "invalidResponse";
43
+ readonly Defect: "defect";
44
+ };
45
+ /** Sentry returned the requested result. */
46
+ declare const GetIssueBranchFound: "found";
47
+ /** The requested resource does not exist. */
48
+ declare const GetIssueBranchNotFound: "notFound";
49
+ /** The provider definitively rejected the request. */
50
+ declare const GetIssueBranchProviderRejected: "providerRejected";
51
+ /** The provider returned malformed or oversized JSON. */
52
+ declare const GetIssueBranchInvalidResponse: "invalidResponse";
53
+ /** Local input or connection credentials are invalid. */
54
+ declare const GetIssueBranchDefect: "defect";
55
+ /** Manifest definition for getIssue. */
56
+ declare const GetIssueDefinition: QueryDefinition;
57
+ /** Manifest metadata for getIssue. */
58
+ declare const GetIssueMetadata: {
59
+ readonly kind: "query";
60
+ readonly idempotency: "none";
61
+ readonly authorization: "required";
62
+ };
63
+ /** Branch IDs for updateIssueStatus. */
64
+ declare const UpdateIssueStatusBranch: {
65
+ readonly Updated: "updated";
66
+ readonly NotFound: "notFound";
67
+ readonly ProviderRejected: "providerRejected";
68
+ readonly InvalidResponse: "invalidResponse";
69
+ readonly Defect: "defect";
70
+ };
71
+ /** Sentry returned the requested result. */
72
+ declare const UpdateIssueStatusBranchUpdated: "updated";
73
+ /** The requested resource does not exist. */
74
+ declare const UpdateIssueStatusBranchNotFound: "notFound";
75
+ /** The provider definitively rejected the request. */
76
+ declare const UpdateIssueStatusBranchProviderRejected: "providerRejected";
77
+ /** Kept for compatibility and no longer selected: a malformed or oversized answer now retries, because repeating the absolute status update is safe. */
78
+ declare const UpdateIssueStatusBranchInvalidResponse: "invalidResponse";
79
+ /** Local input or connection credentials are invalid. */
80
+ declare const UpdateIssueStatusBranchDefect: "defect";
81
+ /** Manifest definition for updateIssueStatus. */
82
+ declare const UpdateIssueStatusDefinition: MutationDefinition;
83
+ /** Manifest metadata for updateIssueStatus. */
84
+ declare const UpdateIssueStatusMetadata: {
85
+ readonly kind: "mutation";
86
+ readonly idempotency: "required";
87
+ readonly authorization: "required";
88
+ };
89
+
90
+ /** Configuration for the listIssues connector Step. */
91
+ interface ListIssuesStepConfig<StepInput, OperationInput = ListIssuesInput, OperationOutput = IssuePage> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
92
+ /** Named connection supplying this operation. */
93
+ connection: Connection<{
94
+ listIssues(): Query<OperationInput, OperationOutput>;
95
+ }>;
96
+ /** Name matching the bound connection. */
97
+ connectionName: string;
98
+ /** Sentry returned the requested result. */
99
+ listed: StepTarget<QueryResult<OperationOutput>>;
100
+ /** The provider definitively rejected the request. */
101
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
102
+ /** The provider returned malformed or oversized JSON. */
103
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
104
+ /** Local input or connection credentials are invalid. */
105
+ defect?: StepTarget<QueryResult<OperationOutput>>;
106
+ }
107
+ /** Build the listIssues Step from a named connection. */
108
+ declare function newListIssuesStep<StepInput, OperationInput = ListIssuesInput, OperationOutput = IssuePage>(configuration: ListIssuesStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
109
+ /** Configuration for the getIssue connector Step. */
110
+ interface GetIssueStepConfig<StepInput, OperationInput = GetIssueInput, OperationOutput = Issue> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
111
+ /** Named connection supplying this operation. */
112
+ connection: Connection<{
113
+ getIssue(): Query<OperationInput, OperationOutput>;
114
+ }>;
115
+ /** Name matching the bound connection. */
116
+ connectionName: string;
117
+ /** Sentry returned the requested result. */
118
+ found: StepTarget<QueryResult<OperationOutput>>;
119
+ /** The requested resource does not exist. */
120
+ notFound?: StepTarget<QueryResult<OperationOutput>>;
121
+ /** The provider definitively rejected the request. */
122
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
123
+ /** The provider returned malformed or oversized JSON. */
124
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
125
+ /** Local input or connection credentials are invalid. */
126
+ defect?: StepTarget<QueryResult<OperationOutput>>;
127
+ }
128
+ /** Build the getIssue Step from a named connection. */
129
+ declare function newGetIssueStep<StepInput, OperationInput = GetIssueInput, OperationOutput = Issue>(configuration: GetIssueStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
130
+ /** Configuration for the updateIssueStatus connector Step. */
131
+ interface UpdateIssueStatusStepConfig<StepInput, OperationInput = UpdateIssueStatusInput, OperationOutput = Issue> extends Omit<MutationStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
132
+ /** Named connection supplying this operation. */
133
+ connection: Connection<{
134
+ updateIssueStatus(): Mutation<OperationInput, OperationOutput>;
135
+ }>;
136
+ /** Name matching the bound connection. */
137
+ connectionName: string;
138
+ /** Sentry returned the requested result. */
139
+ updated: StepTarget<MutationResult<OperationOutput>>;
140
+ /** The requested resource does not exist. */
141
+ notFound?: StepTarget<MutationResult<OperationOutput>>;
142
+ /** The provider definitively rejected the request. */
143
+ providerRejected?: StepTarget<MutationResult<OperationOutput>>;
144
+ /** Kept for compatibility and no longer selected: a malformed or oversized answer now retries, because repeating the absolute status update is safe. */
145
+ invalidResponse?: StepTarget<MutationResult<OperationOutput>>;
146
+ /** Local input or connection credentials are invalid. */
147
+ defect?: StepTarget<MutationResult<OperationOutput>>;
148
+ }
149
+ /** Build the updateIssueStatus Step from a named connection. */
150
+ declare function newUpdateIssueStatusStep<StepInput, OperationInput = UpdateIssueStatusInput, OperationOutput = Issue>(configuration: UpdateIssueStatusStepConfig<StepInput, OperationInput, OperationOutput>): MutationStep<StepInput, OperationInput, OperationOutput>;
151
+
152
+ /** Query one organization issue page. */
153
+ declare class ListIssuesOperation implements Query<ListIssuesInput, IssuePage> {
154
+ private readonly client;
155
+ /** Bind one Sentry client. */ constructor(client: SentryClient);
156
+ /** Return the manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
157
+ /** Validate and invoke one list attempt. */
158
+ invoke(call: Call, input: ListIssuesInput): Promise<QueryAttempt<IssuePage>>;
159
+ }
160
+ /** Query one organization issue. */
161
+ declare class GetIssueOperation implements Query<GetIssueInput, Issue> {
162
+ private readonly client;
163
+ /** Bind one Sentry client. */ constructor(client: SentryClient);
164
+ /** Return the manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
165
+ /** Validate and invoke one detail attempt. */
166
+ invoke(call: Call, input: GetIssueInput): Promise<QueryAttempt<Issue>>;
167
+ }
168
+ /** Set one issue's absolute status. */
169
+ declare class UpdateIssueStatusOperation implements Mutation<UpdateIssueStatusInput, Issue> {
170
+ private readonly client;
171
+ /** Bind one Sentry client. */ constructor(client: SentryClient);
172
+ /** Return the manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
173
+ /** Derive the same stable key as Go from the Call ID. */ idempotencyKey(callId: string): string;
174
+ /** Validate and invoke one status update attempt. */
175
+ invoke(call: Call, input: UpdateIssueStatusInput): Promise<MutationAttempt<Issue>>;
176
+ }
177
+
178
+ /** HTTP sender injectable for deterministic provider tests. */
179
+ type SentryRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
180
+ /** Dependencies for deterministic provider tests. */
181
+ interface SentryClientOptions {
182
+ /** Sender; omit to use the SDK's bounded, no-redirect transport. */
183
+ send?: SentryRequestSender;
184
+ /** Clock used to parse Retry-After. */
185
+ now?: () => Date;
186
+ }
187
+ /** Classified outcome of one provider exchange. */
188
+ type SentryExchange = {
189
+ body: Uint8Array;
190
+ } | {
191
+ branch: 'retry' | 'notFound' | 'providerRejected' | 'invalidResponse' | 'defect';
192
+ failure: Failure;
193
+ retryAfterMs: number;
194
+ };
195
+ /** Immutable Sentry HTTP settings with call-time credential resolution. */
196
+ declare class SentryClient {
197
+ private readonly credentials;
198
+ private readonly baseURL;
199
+ private readonly timeoutMs;
200
+ private readonly maxResponseBytes;
201
+ private readonly send;
202
+ private readonly now;
203
+ /** Validate configuration without contacting Sentry. */
204
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: SentryClientOptions);
205
+ /** Bind the issue list query. */ listIssues(): ListIssuesOperation;
206
+ /** Bind the issue detail query. */ getIssue(): GetIssueOperation;
207
+ /** Bind the absolute status mutation. */ updateIssueStatus(): UpdateIssueStatusOperation;
208
+ /** Send one request and classify Go-compatible provider failures. */
209
+ exchange(call: Call, operation: string, method: 'GET' | 'PUT', path: string, body?: Uint8Array, hasNotFoundBranch?: boolean): Promise<SentryExchange>;
210
+ /** Select providerRejected for a definite refusal; the safe PUT retries every other answer, including 409. */
211
+ private rejectedOrUnknown;
212
+ private failure;
213
+ }
214
+
215
+ /** Open one named Sentry connection declared in a Dex project. */
216
+ declare function newProjectConnection(project: LoadedProject, connectionName: string, options?: SentryClientOptions): Connection<Operations>;
217
+
218
+ export { Config, Connection, ConnectorID, Credentials, GetIssueBranch, GetIssueBranchDefect, GetIssueBranchFound, GetIssueBranchInvalidResponse, GetIssueBranchNotFound, GetIssueBranchProviderRejected, GetIssueDefinition, GetIssueInput, GetIssueMetadata, GetIssueOperation, type GetIssueStepConfig, Issue, IssuePage, ListIssuesBranch, ListIssuesBranchDefect, ListIssuesBranchInvalidResponse, ListIssuesBranchListed, ListIssuesBranchProviderRejected, ListIssuesDefinition, ListIssuesInput, ListIssuesMetadata, ListIssuesOperation, type ListIssuesStepConfig, ProviderID, SentryClient, type SentryClientOptions, type SentryRequestSender, UpdateIssueStatusBranch, UpdateIssueStatusBranchDefect, UpdateIssueStatusBranchInvalidResponse, UpdateIssueStatusBranchNotFound, UpdateIssueStatusBranchProviderRejected, UpdateIssueStatusBranchUpdated, UpdateIssueStatusDefinition, UpdateIssueStatusInput, UpdateIssueStatusMetadata, UpdateIssueStatusOperation, type UpdateIssueStatusStepConfig, newGetIssueStep, newListIssuesStep, newProjectConnection, newUpdateIssueStatusStep };
package/dist/index.js ADDED
@@ -0,0 +1,394 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ CredentialMaterialError,
6
+ GetIssueBranch,
7
+ GetIssueBranchDefect,
8
+ GetIssueBranchFound,
9
+ GetIssueBranchInvalidResponse,
10
+ GetIssueBranchNotFound,
11
+ GetIssueBranchProviderRejected,
12
+ GetIssueDefinition,
13
+ GetIssueInputSchema,
14
+ GetIssueMetadata,
15
+ IssuePageSchema,
16
+ IssueSchema,
17
+ ListIssuesBranch,
18
+ ListIssuesBranchDefect,
19
+ ListIssuesBranchInvalidResponse,
20
+ ListIssuesBranchListed,
21
+ ListIssuesBranchProviderRejected,
22
+ ListIssuesDefinition,
23
+ ListIssuesInputSchema,
24
+ ListIssuesMetadata,
25
+ ProviderID,
26
+ UpdateIssueStatusBranch,
27
+ UpdateIssueStatusBranchDefect,
28
+ UpdateIssueStatusBranchInvalidResponse,
29
+ UpdateIssueStatusBranchNotFound,
30
+ UpdateIssueStatusBranchProviderRejected,
31
+ UpdateIssueStatusBranchUpdated,
32
+ UpdateIssueStatusDefinition,
33
+ UpdateIssueStatusInputSchema,
34
+ UpdateIssueStatusMetadata,
35
+ decodeCredentials,
36
+ isCredentialMaterialError,
37
+ newConnection,
38
+ newConnectionWithOperations,
39
+ newProjectConnection
40
+ } from "./chunk-DLF3YZQL.js";
41
+
42
+ // src/generated/steps.ts
43
+ import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
44
+ function newListIssuesStep(configuration) {
45
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
46
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
47
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listIssues(), connection: connection.reference, branches: [
48
+ goToBranch("listed", listed),
49
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
50
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
51
+ ...defect ? [goToBranch("defect", defect)] : []
52
+ ] });
53
+ }
54
+ function newGetIssueStep(configuration) {
55
+ const { connection, connectionName, found, 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.getIssue(), connection: connection.reference, branches: [
58
+ goToBranch("found", found),
59
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
60
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
61
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
62
+ ...defect ? [goToBranch("defect", defect)] : []
63
+ ] });
64
+ }
65
+ function newUpdateIssueStatusStep(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.updateIssueStatus(), 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 { ReauthorizationRequiredError, SecretString } from "@superdurable/connectors-sdk";
84
+ import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
85
+
86
+ // src/operations.ts
87
+ import { newMutationBranch, newMutationRetry, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
88
+ var emptyIssue = { id: "", shortId: "", title: "", status: "" };
89
+ var emptyPage = { issues: [] };
90
+ var ListIssuesOperation = class {
91
+ /** Bind one Sentry client. */
92
+ constructor(client) {
93
+ this.client = client;
94
+ }
95
+ client;
96
+ /** Return the manifest definition. */
97
+ definition() {
98
+ return ListIssuesDefinition;
99
+ }
100
+ /** Validate and invoke one list attempt. */
101
+ async invoke(call, input) {
102
+ if (!input.organization) return queryFailure("listIssues", "defect", "VALIDATION", "organization slug is required", emptyPage);
103
+ const path = `/organizations/${pathEscape(input.organization)}/issues/${input.query ? `?query=${queryEscape(input.query)}` : ""}`;
104
+ const exchange = await this.client.exchange(call, "listIssues", "GET", path);
105
+ if ("branch" in exchange) return queryExchange(exchange, emptyPage);
106
+ try {
107
+ const value = JSON.parse(Buffer.from(exchange.body).toString("utf8"));
108
+ if (!Array.isArray(value)) throw new Error("issues missing");
109
+ return newQueryBranch("listed", { issues: value.map(decodeListedIssue) }, {});
110
+ } catch {
111
+ return queryFailure("listIssues", "invalidResponse", "PROTOCOL", "provider response is incomplete or malformed", emptyPage);
112
+ }
113
+ }
114
+ };
115
+ var GetIssueOperation = class {
116
+ /** Bind one Sentry client. */
117
+ constructor(client) {
118
+ this.client = client;
119
+ }
120
+ client;
121
+ /** Return the manifest definition. */
122
+ definition() {
123
+ return GetIssueDefinition;
124
+ }
125
+ /** Validate and invoke one detail attempt. */
126
+ async invoke(call, input) {
127
+ if (!input.organization || !input.id) return queryFailure("getIssue", "defect", "VALIDATION", "organization and issue ID are required", emptyIssue);
128
+ const exchange = await this.client.exchange(call, "getIssue", "GET", issuePath(input), void 0, true);
129
+ if ("branch" in exchange) return queryExchange(exchange, emptyIssue);
130
+ try {
131
+ return newQueryBranch("found", decodeIssue(JSON.parse(Buffer.from(exchange.body).toString("utf8"))), {});
132
+ } catch {
133
+ return queryFailure("getIssue", "invalidResponse", "PROTOCOL", "provider response is incomplete or malformed", emptyIssue);
134
+ }
135
+ }
136
+ };
137
+ var UpdateIssueStatusOperation = class {
138
+ /** Bind one Sentry client. */
139
+ constructor(client) {
140
+ this.client = client;
141
+ }
142
+ client;
143
+ /** Return the manifest definition. */
144
+ definition() {
145
+ return UpdateIssueStatusDefinition;
146
+ }
147
+ /** Derive the same stable key as Go from the Call ID. */
148
+ idempotencyKey(callId) {
149
+ return callId;
150
+ }
151
+ /** Validate and invoke one status update attempt. */
152
+ async invoke(call, input) {
153
+ if (!input.organization || !input.id) return mutationFailure("defect", "VALIDATION", "organization and issue ID are required");
154
+ if (!["resolved", "unresolved", "ignored"].includes(input.status)) return mutationFailure("defect", "VALIDATION", "status must be resolved, unresolved, or ignored");
155
+ const body = Buffer.from(JSON.stringify({ status: input.status }), "utf8");
156
+ const exchange = await this.client.exchange(call, "updateIssueStatus", "PUT", issuePath(input), body, true);
157
+ if ("branch" in exchange) return mutationExchange(exchange);
158
+ try {
159
+ return newMutationBranch("updated", decodeIssue(JSON.parse(Buffer.from(exchange.body).toString("utf8"))), {});
160
+ } catch {
161
+ return newMutationRetry({ kind: "PROTOCOL", provider: "sentry", operation: "updateIssueStatus", message: "provider response is incomplete or malformed" });
162
+ }
163
+ }
164
+ };
165
+ function issuePath(input) {
166
+ return `/organizations/${pathEscape(input.organization)}/issues/${pathEscape(input.id)}/`;
167
+ }
168
+ function pathEscape(value) {
169
+ return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%(24|26|2B|3D|3A|40)/gi, (encoded) => String.fromCharCode(parseInt(encoded.slice(1), 16)));
170
+ }
171
+ function queryEscape(value) {
172
+ return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%20/g, "+");
173
+ }
174
+ function decodeIssue(value) {
175
+ const issue = decodeIssueFields(value);
176
+ if (!issue.id) throw new Error("issue ID missing");
177
+ return issue;
178
+ }
179
+ function decodeListedIssue(value) {
180
+ return decodeIssueFields(value);
181
+ }
182
+ function decodeIssueFields(value) {
183
+ if (value === null) return emptyIssue;
184
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("invalid issue");
185
+ const object = value;
186
+ const field = (name) => {
187
+ const found = object[name];
188
+ if (found === void 0 || found === null) return "";
189
+ if (typeof found !== "string") throw new Error("invalid issue field");
190
+ return found;
191
+ };
192
+ return { id: field("id"), shortId: field("shortId"), title: field("title"), status: field("status") };
193
+ }
194
+ function queryExchange(exchange, empty) {
195
+ if (exchange.branch === "retry") return newQueryRetry(exchange.failure, exchange.retryAfterMs);
196
+ return newQueryBranch(exchange.branch === "notFound" ? "notFound" : exchange.branch, empty, {}, exchange.failure);
197
+ }
198
+ function mutationExchange(exchange) {
199
+ if (exchange.branch === "retry") return newMutationRetry(exchange.failure, exchange.retryAfterMs);
200
+ return newMutationBranch(exchange.branch, emptyIssue, {}, exchange.failure);
201
+ }
202
+ function queryFailure(operation, branch, kind, message, empty) {
203
+ return newQueryBranch(branch, empty, {}, { kind, provider: "sentry", operation, message });
204
+ }
205
+ function mutationFailure(branch, kind, message) {
206
+ return newMutationBranch(branch, emptyIssue, {}, { kind, provider: "sentry", operation: "updateIssueStatus", message });
207
+ }
208
+
209
+ // src/client.ts
210
+ var defaultBaseURL = "https://sentry.io/api/0";
211
+ var defaultMaxResponseBytes = 2097152;
212
+ var defaultTimeoutMs = 15e3;
213
+ var SentryClient = class {
214
+ /** Validate configuration without contacting Sentry. */
215
+ constructor(config, credentials, options = {}) {
216
+ this.credentials = credentials;
217
+ if (!credentials) throw new TypeError("Sentry credential provider is required");
218
+ this.baseURL = validateBaseURL(config.baseUrl || defaultBaseURL);
219
+ this.timeoutMs = config.timeoutMs || defaultTimeoutMs;
220
+ this.maxResponseBytes = config.maxResponseBytes || defaultMaxResponseBytes;
221
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs < 0) throw new TypeError("Sentry timeout is invalid");
222
+ if (!Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes < 0) throw new TypeError("Sentry maxResponseBytes is invalid");
223
+ this.send = options.send ?? sendProviderRequest;
224
+ this.now = options.now ?? (() => /* @__PURE__ */ new Date());
225
+ }
226
+ credentials;
227
+ baseURL;
228
+ timeoutMs;
229
+ maxResponseBytes;
230
+ send;
231
+ now;
232
+ /** Bind the issue list query. */
233
+ listIssues() {
234
+ return new ListIssuesOperation(this);
235
+ }
236
+ /** Bind the issue detail query. */
237
+ getIssue() {
238
+ return new GetIssueOperation(this);
239
+ }
240
+ /** Bind the absolute status mutation. */
241
+ updateIssueStatus() {
242
+ return new UpdateIssueStatusOperation(this);
243
+ }
244
+ /** Send one request and classify Go-compatible provider failures. */
245
+ async exchange(call, operation, method, path, body, hasNotFoundBranch = false) {
246
+ let resolved;
247
+ try {
248
+ resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
249
+ } catch (error) {
250
+ if (isTerminalCredentialError(error)) return this.failure(operation, "defect", "AUTHENTICATION", "connection credentials or request are invalid");
251
+ return this.failure(operation, "retry", "AVAILABILITY", "connection credentials could not be read, so nothing was sent");
252
+ }
253
+ if (!(resolved?.apiKey instanceof SecretString)) return this.failure(operation, "defect", "AUTHENTICATION", "connection credentials or request are invalid");
254
+ const token = resolved.apiKey.reveal();
255
+ if (!token.trim() || !isHeaderSafeCredential(token)) return this.failure(operation, "defect", "AUTHENTICATION", "connection credentials or request are invalid");
256
+ let response;
257
+ try {
258
+ response = await this.send({
259
+ url: this.baseURL + path,
260
+ method,
261
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/json", "User-Agent": "superdurable-sentry/0.1", ...body ? { "Content-Type": "application/json" } : {} },
262
+ ...body ? { body } : {},
263
+ maxResponseBytes: this.maxResponseBytes,
264
+ timeoutMs: this.timeoutMs,
265
+ addressPolicy: this.baseURL === defaultBaseURL ? "publicHTTPS" : "privateNetworkHTTP",
266
+ signal: call.context.cancellationSignal
267
+ });
268
+ } catch (error) {
269
+ if (error instanceof BodyTooLargeError) {
270
+ const status2 = error.status;
271
+ const retryAfter2 = parseRetryAfter(header({ status: status2 ?? 0, headers: error.headers ?? {}, body: new Uint8Array() }, "retry-after"), this.now());
272
+ if (status2 === 429) return this.failure(operation, "retry", "RATE_LIMIT", "provider rate limited the request", retryAfter2);
273
+ if (status2 === 408 || status2 !== void 0 && status2 >= 500) return this.failure(operation, "retry", "AVAILABILITY", "provider is temporarily unavailable", retryAfter2);
274
+ if (status2 === 404 && hasNotFoundBranch) return this.failure(operation, "notFound", "NOT_FOUND", "provider resource was not found");
275
+ if (status2 !== void 0 && (method === "GET" ? status2 !== 200 : ![200, 201, 202].includes(status2))) return this.rejectedOrUnknown(operation, method, status2);
276
+ if (method === "PUT") return this.failure(operation, "retry", "RESPONSE_TOO_LARGE", "provider response exceeded the configured limit");
277
+ return this.failure(operation, "invalidResponse", "RESPONSE_TOO_LARGE", "provider response exceeded the configured limit");
278
+ }
279
+ return this.failure(operation, "retry", "AVAILABILITY", "provider request failed");
280
+ }
281
+ const status = response.status;
282
+ const retryAfter = parseRetryAfter(header(response, "retry-after"), this.now());
283
+ if (status === 429) return this.failure(operation, "retry", "RATE_LIMIT", "provider rate limited the request", retryAfter);
284
+ if (status === 408 || status >= 500) return this.failure(operation, "retry", "AVAILABILITY", "provider is temporarily unavailable", retryAfter);
285
+ if (status === 404 && hasNotFoundBranch) return this.failure(operation, "notFound", "NOT_FOUND", "provider resource was not found");
286
+ if (method === "GET" ? status !== 200 : ![200, 201, 202].includes(status)) return this.rejectedOrUnknown(operation, method, status);
287
+ return { body: response.body };
288
+ }
289
+ /** Select providerRejected for a definite refusal; the safe PUT retries every other answer, including 409. */
290
+ rejectedOrUnknown(operation, method, status) {
291
+ if (method === "PUT" && !definiteRefusalStatuses.has(status)) return this.failure(operation, "retry", "AVAILABILITY", `provider answered HTTP ${status}, so the outcome is unknown`);
292
+ return this.failure(operation, "providerRejected", "PROVIDER_REJECTION", `provider rejected the request with HTTP ${status}`);
293
+ }
294
+ failure(operation, branch, kind, message, retryAfterMs = 0) {
295
+ return { branch, failure: { kind, provider: "sentry", operation, message }, retryAfterMs };
296
+ }
297
+ };
298
+ function isTerminalCredentialError(error) {
299
+ return error instanceof ReauthorizationRequiredError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError || error instanceof ObjectNotFoundError || isCredentialMaterialError(error);
300
+ }
301
+ var definiteRefusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
302
+ function header(response, name) {
303
+ const value = response.headers[name];
304
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
305
+ }
306
+
307
+ // src/project.ts
308
+ var projectSettingsSchema = z.strictObject({
309
+ baseUrl: z.string().optional(),
310
+ timeout: z.union([z.string(), z.number().int()]).optional(),
311
+ maxResponseBytes: z.number().int().optional()
312
+ });
313
+ function newProjectConnection2(project, connectionName, options = {}) {
314
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
315
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "sentry" && entry.connectionName === name);
316
+ if (!selected) throw new TypeError("Sentry project connection is not configured");
317
+ const settings = projectSettingsSchema.parse(selected.configuration);
318
+ const timeoutMs = typeof settings.timeout === "number" ? Math.ceil(settings.timeout / 1e6) : settings.timeout !== void 0 ? parseDurationMilliseconds(settings.timeout) : void 0;
319
+ const config = {
320
+ ...settings.baseUrl !== void 0 ? { baseUrl: settings.baseUrl } : {},
321
+ ...timeoutMs !== void 0 ? { timeoutMs } : {},
322
+ ...settings.maxResponseBytes !== void 0 ? { maxResponseBytes: settings.maxResponseBytes } : {}
323
+ };
324
+ const credentials = {
325
+ async resolve(call, signal) {
326
+ void call;
327
+ const fields = await loadedProject.resolveCredential("sentry", name, signal);
328
+ const decoded = z.object({ api_key: z.string().min(1) }).parse(fields);
329
+ return { apiKey: new SecretString2(decoded.api_key) };
330
+ }
331
+ };
332
+ return new SentryClient(config, credentials, options);
333
+ });
334
+ }
335
+ function parseDurationMilliseconds(value) {
336
+ let remaining = value;
337
+ let milliseconds = 0;
338
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
339
+ while (remaining) {
340
+ const component = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
341
+ if (!component) throw new TypeError("Sentry timeout must be a positive Go duration");
342
+ milliseconds += Number(component[1]) * (units[component[2] ?? ""] ?? NaN);
343
+ remaining = remaining.slice(component[0].length);
344
+ }
345
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("Sentry timeout must resolve to positive whole milliseconds");
346
+ return milliseconds;
347
+ }
348
+ export {
349
+ ConfigSchema,
350
+ Connection,
351
+ ConnectorID,
352
+ CredentialMaterialError,
353
+ GetIssueBranch,
354
+ GetIssueBranchDefect,
355
+ GetIssueBranchFound,
356
+ GetIssueBranchInvalidResponse,
357
+ GetIssueBranchNotFound,
358
+ GetIssueBranchProviderRejected,
359
+ GetIssueDefinition,
360
+ GetIssueInputSchema,
361
+ GetIssueMetadata,
362
+ GetIssueOperation,
363
+ IssuePageSchema,
364
+ IssueSchema,
365
+ ListIssuesBranch,
366
+ ListIssuesBranchDefect,
367
+ ListIssuesBranchInvalidResponse,
368
+ ListIssuesBranchListed,
369
+ ListIssuesBranchProviderRejected,
370
+ ListIssuesDefinition,
371
+ ListIssuesInputSchema,
372
+ ListIssuesMetadata,
373
+ ListIssuesOperation,
374
+ ProviderID,
375
+ SentryClient,
376
+ UpdateIssueStatusBranch,
377
+ UpdateIssueStatusBranchDefect,
378
+ UpdateIssueStatusBranchInvalidResponse,
379
+ UpdateIssueStatusBranchNotFound,
380
+ UpdateIssueStatusBranchProviderRejected,
381
+ UpdateIssueStatusBranchUpdated,
382
+ UpdateIssueStatusDefinition,
383
+ UpdateIssueStatusInputSchema,
384
+ UpdateIssueStatusMetadata,
385
+ UpdateIssueStatusOperation,
386
+ decodeCredentials,
387
+ isCredentialMaterialError,
388
+ newConnection,
389
+ newConnectionWithOperations,
390
+ newGetIssueStep,
391
+ newListIssuesStep,
392
+ newProjectConnection2 as newProjectConnection,
393
+ newUpdateIssueStatusStep
394
+ };