@superdurable/connectors-sdk 0.1.0 → 0.2.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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { C as Call, b as MutationResult, c as QueryResult, d as ConnectorConfigurationUI, e as ConnectionRef, P as ProgressUpdate } from './credentials-vrvW0d4j.js';
2
- export { f as BranchDefinition, g as BranchDefinitionSchema, B as BranchID, a as CallID, h as CallIDNamespace, i as CallIDSchema, j as CallProgressOptions, k as ConnectionRefSchema, l as ConnectorConfigurationRef, m as ConnectorConfigurationRefSchema, n as ConnectorConfigurationUISchema, o as ConnectorUIBinding, p as ConnectorUIBindingSchema, q as ConnectorUIUnit, r as ConnectorUIUnitSchema, s as ContextCredentialProvider, t as CredentialProvider, u as CredentialRefreshDriver, v as CredentialRefreshResult, w as CredentialRefreshState, D as DefectBranchID, F as Failure, x as FailureKind, y as FailureKindSchema, z as FailureSchema, I as IdempotencyKey, M as MutationAttempt, A as MutationDefinitionWire, E as MutationDefinitionWireSchema, G as MutationResultSchema, O as OperationRef, H as OperationRefSchema, J as Progress, Q as QueryAttempt, K as QueryDefinitionWire, L as QueryDefinitionWireSchema, N as QueryResultSchema, R as ReauthorizationRequiredError, S as Receipt, T as ReceiptDraft, V as ReceiptSchema, W as RefreshingCredentialProvider, X as RejectedCredentialRefreshingProvider, Y as RetryError, Z as RetryPolicy, _ as SecretString, $ as StaticCredentialProvider, a0 as StepDefaultsWire, a1 as StepDefaultsWireSchema, U as UncertainBranchID, a2 as createCall, a3 as defaultConnectorStepExecuteRetryPolicy, a4 as defaultIdempotencyKey, a5 as deriveCallID, a6 as newMutationBranch, a7 as newMutationRetry, a8 as newMutationUncertain, a9 as newQueryBranch, aa as newQueryRetry, ab as resolveCredential, ac as resolveCredentialAfterRejection, ad as retryPolicyToGoWire, ae as zeroReceipt } from './credentials-vrvW0d4j.js';
3
- import { M as Mutation, b as Query } from './operation-Ca8rfacf.js';
4
- export { a as MutationDefinition, Q as QueryDefinition, S as StepDefaults, v as validateMutationDefinition, c as validateQueryDefinition } from './operation-Ca8rfacf.js';
1
+ import { a as MutationResult, b as QueryResult, c as ConnectorConfigurationUI, d as ConnectionRef } from './types-D6De3sry.js';
2
+ export { e as BranchDefinition, f as BranchDefinitionSchema, B as BranchID, C as CallID, g as CallIDNamespace, h as CallIDSchema, i as ConnectionRefSchema, j as ConnectorConfigurationRef, k as ConnectorConfigurationRefSchema, l as ConnectorConfigurationUISchema, m as ConnectorUIBinding, n as ConnectorUIBindingSchema, o as ConnectorUIUnit, p as ConnectorUIUnitSchema, D as DefectBranchID, F as Failure, q as FailureKind, r as FailureKindSchema, s as FailureSchema, I as IdempotencyKey, M as MutationAttempt, t as MutationDefinitionWire, u as MutationDefinitionWireSchema, v as MutationResultSchema, O as OperationRef, w as OperationRefSchema, Q as QueryAttempt, x as QueryDefinitionWire, y as QueryDefinitionWireSchema, z as QueryResultSchema, R as ReauthorizationRequiredError, A as Receipt, E as ReceiptDraft, G as ReceiptSchema, H as RetryError, J as RetryPolicy, S as StepDefaultsWire, K as StepDefaultsWireSchema, U as UncertainBranchID, L as defaultConnectorStepExecuteRetryPolicy, N as defaultIdempotencyKey, P as deriveCallID, T as newMutationBranch, V as newMutationRetry, W as newMutationUncertain, X as newQueryBranch, Y as newQueryRetry, Z as retryPolicyToGoWire, _ as zeroReceipt } from './types-D6De3sry.js';
3
+ import { C as Call, P as ProgressUpdate } from './credentials-JqG97kJ5.js';
4
+ export { a as CallProgressOptions, b as ContextCredentialProvider, c as CredentialProvider, d as CredentialRefreshDriver, e as CredentialRefreshResult, f as CredentialRefreshState, g as Progress, R as RefreshingCredentialProvider, h as RejectedCredentialRefreshingProvider, S as SecretString, i as StaticCredentialProvider, j as createCall, r as resolveCredential, k as resolveCredentialAfterRejection } from './credentials-JqG97kJ5.js';
5
+ import { M as Mutation, b as Query } from './operation-CASLOg86.js';
6
+ export { a as MutationDefinition, Q as QueryDefinition, S as StepDefaults, v as validateMutationDefinition, c as validateQueryDefinition } from './operation-CASLOg86.js';
5
7
  import { StepTarget, Step, Codec, Attribute, Stream, BufferedTextStreamOptions, StepOptions, AsyncContext, StepDecision, StepRef } from '@superdurable/dex';
6
8
  import 'zod';
7
9
 
package/dist/index.js CHANGED
@@ -1,14 +1,24 @@
1
+ import {
2
+ MutationStep,
3
+ QueryStep,
4
+ goToBranch,
5
+ newMutationStep,
6
+ newQueryStep,
7
+ runMutation,
8
+ runQuery,
9
+ stepRef
10
+ } from "./chunk-NQQJS6OC.js";
1
11
  import {
2
12
  validateMutationDefinition,
3
13
  validateQueryDefinition
4
- } from "./chunk-2NBM7P4T.js";
14
+ } from "./chunk-32YJXBE4.js";
5
15
  import {
6
16
  SecretString,
7
17
  StaticCredentialProvider,
8
18
  createCall,
9
19
  resolveCredential,
10
20
  resolveCredentialAfterRejection
11
- } from "./chunk-KD5DYYSU.js";
21
+ } from "./chunk-QDMBAWXD.js";
12
22
  import {
13
23
  BranchDefinitionSchema,
14
24
  CallIDNamespace,
@@ -19,16 +29,12 @@ import {
19
29
  ConnectorUIBindingSchema,
20
30
  ConnectorUIUnitSchema,
21
31
  DefectBranchID,
22
- FailureKindSchema,
23
- FailureSchema,
24
32
  MutationDefinitionWireSchema,
25
33
  MutationResultSchema,
26
34
  OperationRefSchema,
27
35
  QueryDefinitionWireSchema,
28
36
  QueryResultSchema,
29
- ReauthorizationRequiredError,
30
37
  ReceiptSchema,
31
- RetryError,
32
38
  StepDefaultsWireSchema,
33
39
  UncertainBranchID,
34
40
  defaultConnectorStepExecuteRetryPolicy,
@@ -41,291 +47,13 @@ import {
41
47
  newQueryRetry,
42
48
  retryPolicyToGoWire,
43
49
  zeroReceipt
44
- } from "./chunk-SOXYPIMO.js";
45
-
46
- // src/run_operation.ts
47
- async function runQuery(operation, call, input) {
48
- if (!operation) return defectResult(void 0, call, "connector query is required");
49
- const definition = operation.definition();
50
- try {
51
- validateQueryDefinition(definition);
52
- } catch (error) {
53
- return defectResult(definition, call, `invalid query definition: ${safeErrorMessage(error)}`);
54
- }
55
- const invalidCall = validateCall(call, definition.operation);
56
- if (invalidCall) return defectResult(definition, call, invalidCall);
57
- const attempt = await operation.invoke(call, input);
58
- return resultFromAttempt(definition, call, attempt, "query");
59
- }
60
- async function runMutation(operation, call, input) {
61
- if (!operation) return defectResult(void 0, call, "connector mutation is required");
62
- const definition = operation.definition();
63
- try {
64
- validateMutationDefinition(definition);
65
- } catch (error) {
66
- return defectResult(definition, call, `invalid mutation definition: ${safeErrorMessage(error)}`);
67
- }
68
- const invalidCall = validateCall(call, definition.operation);
69
- if (invalidCall) return defectResult(definition, call, invalidCall);
70
- const chosenKey = operation.idempotencyKey(call.id, input) || call.id;
71
- if (!chosenKey.trim()) return defectResult(definition, call, "mutation returned an invalid idempotency key");
72
- const mutationCall = { ...call, context: call.context, idempotencyKey: chosenKey };
73
- Object.defineProperty(mutationCall, "context", { value: call.context, enumerable: false });
74
- for (const method of ["reportProgress", "writeText", "hasProgressStream", "hasTextStream"]) Object.defineProperty(mutationCall, method, { value: call[method], enumerable: false });
75
- const attempt = await operation.invoke(mutationCall, input);
76
- return resultFromAttempt(definition, mutationCall, attempt, "mutation");
77
- }
78
- function resultFromAttempt(definition, call, attempt, operationKind) {
79
- if (!attempt || typeof attempt !== "object") return defectResult(definition, call, `${operationKind} returned an invalid attempt`);
80
- if (attempt.kind === "retry") {
81
- const failure = FailureSchema.safeParse(attempt.failure);
82
- if (!failure.success || !Number.isSafeInteger(attempt.retryAfterMs) || attempt.retryAfterMs < 0) return defectResult(definition, call, `${operationKind} returned an invalid retry attempt`);
83
- throw new RetryError(failure.data, attempt.retryAfterMs);
84
- }
85
- if (attempt.kind === "branch" || operationKind === "mutation" && attempt.kind === "uncertain") {
86
- const branch = attempt.kind === "uncertain" ? UncertainBranchID : attempt.branch;
87
- if (!definition.branches.some((declared) => declared.id === branch)) {
88
- return defectResult(definition, call, attempt.kind === "uncertain" ? "mutation returned uncertainty without declaring the uncertain branch" : `${operationKind} returned an unknown branch`);
89
- }
90
- const failure = "failure" in attempt && attempt.failure !== void 0 ? FailureSchema.safeParse(attempt.failure) : void 0;
91
- if (failure && !failure.success) return defectResult(definition, call, `${operationKind} returned an invalid failure`);
92
- if (attempt.kind === "uncertain" && !failure) return defectResult(definition, call, "mutation returned an invalid uncertainty failure");
93
- let receipt;
94
- try {
95
- receipt = completeReceipt(attempt.receipt, call);
96
- } catch (error) {
97
- return defectResult(definition, call, safeErrorMessage(error));
98
- }
99
- const result = { branch, value: attempt.value, receipt };
100
- if (failure?.success) result.failure = failure.data;
101
- return result;
102
- }
103
- return defectResult(definition, call, `${operationKind} returned an invalid attempt`);
104
- }
105
- function completeReceipt(draft, call) {
106
- if (draft.callId && draft.callId !== call.id) throw new TypeError("operation returned a receipt for another call");
107
- if (draft.idempotencyKey && draft.idempotencyKey !== call.idempotencyKey) throw new TypeError("operation returned a receipt with another idempotency key");
108
- return ReceiptSchema.parse({ ...draft, callId: call.id, ...call.idempotencyKey ? { idempotencyKey: call.idempotencyKey } : {}, provider: draft.provider || call.operation.connectorId, observedAt: draft.observedAt && draft.observedAt !== "0001-01-01T00:00:00Z" ? draft.observedAt : (/* @__PURE__ */ new Date()).toISOString() });
109
- }
110
- function validateCall(call, operation) {
111
- if (!call) return "connector call is required";
112
- if (!CallIDSchema.safeParse(call.id).success) return "call ID must be a UUID";
113
- if (!ConnectionRefSchema.safeParse(call.connection).success) return "connection provider and name are required";
114
- if (!OperationRefSchema.safeParse(call.operation).success || call.operation.connectorId !== operation.connectorId || call.operation.operationId !== operation.operationId) return "connector call operation does not match the definition";
115
- return void 0;
116
- }
117
- function defectResult(definition, call, message) {
118
- const operation = definition?.operation;
119
- const failure = { kind: "LOCAL_DEFECT", provider: operation?.connectorId || "connector", operation: operation?.operationId || "invoke", message };
120
- const receipt = call && CallIDSchema.safeParse(call.id).success ? completeReceipt({}, call) : void 0;
121
- return { branch: DefectBranchID, value: void 0, receipt, failure };
122
- }
123
- function safeErrorMessage(error) {
124
- return error instanceof Error ? error.message : "invalid value";
125
- }
126
-
127
- // src/step.ts
128
- import { StepRef, forceFail, goTo, retryAfter } from "@superdurable/dex";
129
- function goToBranch(branch, target) {
130
- return target ? { branch, target } : { branch };
131
- }
132
- function stepRef(stepType) {
133
- return new StepRef(stepType);
134
- }
135
- var QueryStep = class {
136
- inputCodec;
137
- #configuration;
138
- #options;
139
- #ui;
140
- #targets;
141
- #optional;
142
- #identity;
143
- /** Validate static wiring before registering the Step in a Flow. */
144
- constructor(configuration) {
145
- if (!configuration?.operation) throw new TypeError("query operation is required");
146
- const definition = configuration.operation.definition();
147
- validateQueryDefinition(definition);
148
- validateFactoryConfiguration(configuration);
149
- const routes = validateBranchTargets(definition.branches, configuration.branches);
150
- this.#configuration = configuration;
151
- this.#options = mergeStepOptions(definition.stepDefaults, configuration.stepOptionsOverride);
152
- this.#ui = ConnectorConfigurationUISchema.parse(configuration.configurationUI ?? { units: [] });
153
- this.#targets = routes.targets;
154
- this.#optional = routes.optional;
155
- this.#identity = { operation: definition.operation, connection: configuration.connection };
156
- if (configuration.inputCodec) this.inputCodec = configuration.inputCodec;
157
- }
158
- /** Stable Dex Step type. */
159
- getStepType() {
160
- return this.#configuration.stepType;
161
- }
162
- /** Isolated Execute options, including connector retry defaults. */
163
- getStepOptions() {
164
- return cloneStepOptions(this.#options);
165
- }
166
- /** Group metadata for Connector Studio. */
167
- annotations() {
168
- return { ...this.#configuration.annotations };
169
- }
170
- /** Isolated connector UI composition. */
171
- configurationUI() {
172
- return structuredClone(this.#ui);
173
- }
174
- /** Invoke, persist the optional terminal Attribute, and route the selected branch. */
175
- async execute(context, input) {
176
- const operationInput = this.#configuration.mapToOperationInput(input);
177
- const call = createCall(context, this.#identity.connection, this.#identity.operation, {
178
- ...this.#configuration.progressStream ? { progressStream: this.#configuration.progressStream } : {},
179
- ...this.#configuration.textStream ? { textStream: this.#configuration.textStream } : {},
180
- ...this.#configuration.textOptions ? { textOptions: this.#configuration.textOptions } : {}
181
- });
182
- let result;
183
- try {
184
- result = await runQuery(this.#configuration.operation, call, operationInput);
185
- } catch (error) {
186
- throwDexRetry(error);
187
- }
188
- if (this.#configuration.resultAttribute) context.setAttribute(this.#configuration.resultAttribute, result);
189
- return routeBranch(this.#targets, this.#optional, result, this.#identity, "query");
190
- }
191
- };
192
- var MutationStep = class {
193
- inputCodec;
194
- #configuration;
195
- #options;
196
- #ui;
197
- #targets;
198
- #optional;
199
- #identity;
200
- /** Validate static wiring before registering the Step in a Flow. */
201
- constructor(configuration) {
202
- if (!configuration?.operation) throw new TypeError("mutation operation is required");
203
- const definition = configuration.operation.definition();
204
- validateMutationDefinition(definition);
205
- validateFactoryConfiguration(configuration);
206
- const routes = validateBranchTargets(definition.branches, configuration.branches);
207
- this.#configuration = configuration;
208
- this.#options = mergeStepOptions(definition.stepDefaults, configuration.stepOptionsOverride);
209
- this.#ui = ConnectorConfigurationUISchema.parse(configuration.configurationUI ?? { units: [] });
210
- this.#targets = routes.targets;
211
- this.#optional = routes.optional;
212
- this.#identity = { operation: definition.operation, connection: configuration.connection };
213
- if (configuration.inputCodec) this.inputCodec = configuration.inputCodec;
214
- }
215
- /** Stable Dex Step type. */
216
- getStepType() {
217
- return this.#configuration.stepType;
218
- }
219
- /** Isolated Execute options, including connector retry defaults. */
220
- getStepOptions() {
221
- return cloneStepOptions(this.#options);
222
- }
223
- /** Group metadata for Connector Studio. */
224
- annotations() {
225
- return { ...this.#configuration.annotations };
226
- }
227
- /** Isolated connector UI composition. */
228
- configurationUI() {
229
- return structuredClone(this.#ui);
230
- }
231
- /** Invoke, persist the optional terminal Attribute, and route the selected branch. */
232
- async execute(context, input) {
233
- const operationInput = this.#configuration.mapToOperationInput(input);
234
- const call = createCall(context, this.#identity.connection, this.#identity.operation, {
235
- ...this.#configuration.progressStream ? { progressStream: this.#configuration.progressStream } : {},
236
- ...this.#configuration.textStream ? { textStream: this.#configuration.textStream } : {},
237
- ...this.#configuration.textOptions ? { textOptions: this.#configuration.textOptions } : {}
238
- });
239
- let result;
240
- try {
241
- result = await runMutation(this.#configuration.operation, call, operationInput);
242
- } catch (error) {
243
- throwDexRetry(error);
244
- }
245
- if (this.#configuration.resultAttribute) context.setAttribute(this.#configuration.resultAttribute, result);
246
- return routeBranch(this.#targets, this.#optional, result, this.#identity, "mutation");
247
- }
248
- };
249
- function newQueryStep(configuration) {
250
- return new QueryStep(configuration);
251
- }
252
- function newMutationStep(configuration) {
253
- return new MutationStep(configuration);
254
- }
255
- function validateFactoryConfiguration(configuration) {
256
- if (!configuration.stepType?.trim()) throw new TypeError("stable Step type is required");
257
- if (!/^[a-z][a-z0-9-]*$/.test(configuration.annotations?.groupId ?? "") || !configuration.annotations.groupLabel?.trim() || !configuration.annotations.explanation?.trim()) throw new TypeError("Step group, group label, and explanation are required");
258
- ConnectionRefSchema.parse(configuration.connection);
259
- if (typeof configuration.mapToOperationInput !== "function") throw new TypeError("mapToOperationInput is required");
260
- }
261
- function validateBranchTargets(definitions, routes) {
262
- const expected = new Map(definitions.map((branch) => [branch.id, branch]));
263
- const targets = /* @__PURE__ */ new Map();
264
- const optional = new Set(definitions.filter((branch) => branch.optional).map((branch) => branch.id));
265
- for (const route of routes) {
266
- if (!expected.has(route.branch)) throw new TypeError(`branch target ${route.branch} is not declared by the operation`);
267
- if (!route.target) {
268
- if (!optional.has(route.branch)) throw new TypeError(`branch target ${route.branch} must name a Step`);
269
- continue;
270
- }
271
- if (route.target instanceof StepRef && !route.target.stepType.trim()) throw new TypeError(`branch target ${route.branch} must name a Step`);
272
- if (typeof route.target === "object" && !(route.target instanceof StepRef) && !route.target.getStepType().trim()) throw new TypeError(`branch target ${route.branch} must name a Step`);
273
- if (targets.has(route.branch)) throw new TypeError(`branch target ${route.branch} is duplicated`);
274
- targets.set(route.branch, route.target);
275
- }
276
- for (const branch of definitions) if (!branch.optional && !targets.has(branch.id)) throw new TypeError(`branch target ${branch.id} is required`);
277
- return { targets, optional };
278
- }
279
- function mergeStepOptions(defaults, override) {
280
- if (override && Object.keys(override).some((key) => key.startsWith("waitFor") && override[key] !== void 0)) throw new TypeError("execute-only connector Step rejects WaitFor options");
281
- const merged = {
282
- ...override?.executeMethodTimeoutMs || defaults.executeMethodTimeoutMs ? { executeMethodTimeoutMs: override?.executeMethodTimeoutMs || defaults.executeMethodTimeoutMs } : {},
283
- ...override?.heartbeatTimeoutMs || defaults.heartbeatTimeoutMs ? { heartbeatTimeoutMs: override?.heartbeatTimeoutMs || defaults.heartbeatTimeoutMs } : {},
284
- executeRetry: { ...override?.executeRetry ?? defaults.executeRetry ?? defaultConnectorStepExecuteRetryPolicy() },
285
- ...override?.executeDurability || (defaults.executeDurability !== "default" ? defaults.executeDurability : void 0) ? { executeDurability: override?.executeDurability ?? defaults.executeDurability } : {},
286
- ...override?.executeFailure ? { executeFailure: override.executeFailure } : {},
287
- ...override?.executeLockAttributes ? { executeLockAttributes: override.executeLockAttributes } : {},
288
- ...override?.executeLoadAttributeMaps ? { executeLoadAttributeMaps: override.executeLoadAttributeMaps } : {},
289
- ...override?.executeLoadAttributeMapInstances ? { executeLoadAttributeMapInstances: override.executeLoadAttributeMapInstances } : {},
290
- ...override?.executeLoadChannels ? { executeLoadChannels: override.executeLoadChannels } : {},
291
- ...override?.executeLoadChannelMaps ? { executeLoadChannelMaps: override.executeLoadChannelMaps } : {},
292
- ...override?.executeLoadChannelMapInstances ? { executeLoadChannelMapInstances: override.executeLoadChannelMapInstances } : {}
293
- };
294
- return cloneStepOptions(merged);
295
- }
296
- function cloneStepOptions(options) {
297
- return {
298
- ...options,
299
- ...options.executeRetry ? { executeRetry: { ...options.executeRetry } } : {},
300
- ...options.executeLockAttributes ? { executeLockAttributes: [...options.executeLockAttributes] } : {},
301
- ...options.executeLoadAttributeMaps ? { executeLoadAttributeMaps: [...options.executeLoadAttributeMaps] } : {},
302
- ...options.executeLoadAttributeMapInstances ? { executeLoadAttributeMapInstances: [...options.executeLoadAttributeMapInstances] } : {},
303
- ...options.executeLoadChannels ? { executeLoadChannels: [...options.executeLoadChannels] } : {},
304
- ...options.executeLoadChannelMaps ? { executeLoadChannelMaps: [...options.executeLoadChannelMaps] } : {},
305
- ...options.executeLoadChannelMapInstances ? { executeLoadChannelMapInstances: [...options.executeLoadChannelMapInstances] } : {}
306
- };
307
- }
308
- function routeBranch(targets, optional, result, identity, operationKind) {
309
- const target = targets.get(result.branch);
310
- if (target) return goTo(target, result);
311
- if (optional.has(result.branch)) {
312
- let reason = `${identity.operation.connectorId} ${identity.operation.operationId} (connection ${identity.connection.name}) selected branch ${result.branch} with no target`;
313
- if (result.failure) reason += `: ${result.failure.kind}: ${boundedFailureMessage(result.failure.message)}`;
314
- return forceFail(reason);
315
- }
316
- throw new TypeError(`${operationKind} result selected unconfigured branch ${result.branch}`);
317
- }
318
- function boundedFailureMessage(message) {
319
- const bytes = Buffer.from(message);
320
- if (bytes.length <= 1024) return message;
321
- let end = 1024;
322
- while (end > 0 && (bytes[end] & 192) === 128) end--;
323
- return `${bytes.subarray(0, end).toString("utf8")} (truncated)`;
324
- }
325
- function throwDexRetry(error) {
326
- if (error instanceof RetryError && error.retryAfterMs >= 1e3) throw retryAfter(Math.floor(error.retryAfterMs / 1e3), error);
327
- throw error;
328
- }
50
+ } from "./chunk-BQGYGCOQ.js";
51
+ import {
52
+ FailureKindSchema,
53
+ FailureSchema,
54
+ ReauthorizationRequiredError,
55
+ RetryError
56
+ } from "./chunk-IHG6ADQG.js";
329
57
  export {
330
58
  BranchDefinitionSchema,
331
59
  CallIDNamespace,
@@ -1,8 +1,36 @@
1
1
  import { KeyObject } from 'node:crypto';
2
- import { _ as SecretString } from '../credentials-vrvW0d4j.js';
2
+ import { d as CredentialRefreshDriver, f as CredentialRefreshState, e as CredentialRefreshResult, S as SecretString } from '../credentials-JqG97kJ5.js';
3
+ import '../types-D6De3sry.js';
3
4
  import 'zod';
4
5
  import '@superdurable/dex';
5
6
 
7
+ type ManifestObject = Record<string, unknown>;
8
+ /** Manifest-backed OAuth and service-account grant options emitted by connectorctl. */
9
+ interface ManifestCredentialRefreshOptions {
10
+ /** Safe provider name used in token endpoint errors. */ providerName: string;
11
+ /** Validated spec.auth declaration, encoded using the manifest JSON contract. */ auth: ManifestObject;
12
+ /** Credential wire field name to connector runtime property. */ credentialFields: Readonly<Record<string, string>>;
13
+ /** Startup-pinned connection settings that value sources may read. */ settings?: Readonly<Record<string, string>>;
14
+ /** Caller-owned token HTTP transport. */ fetch?: typeof fetch;
15
+ /** Clock for deterministic tests. */ now?: () => Date;
16
+ }
17
+ /** Exchange manifest-declared grants while a credential provider owns admission and storage.
18
+ *
19
+ * Missing expiry keeps an existing access token. Refresh sends each active grant
20
+ * and reports the earliest expiry. Declared sub-500 terminal errors require
21
+ * reauthorization; other token endpoint failures remain retryable. A credential
22
+ * with multiple methods must carry authMethodId.
23
+ */
24
+ declare class ManifestCredentialRefreshDriver<C extends object> implements CredentialRefreshDriver<C> {
25
+ #private;
26
+ /** Bind validated auth data, pinned settings, a caller-owned transport, and a clock. */
27
+ constructor(options: ManifestCredentialRefreshOptions);
28
+ /** Check declared access fields against the host's single credential expiry. */
29
+ refreshRequired(state: CredentialRefreshState<C>): boolean;
30
+ /** Send each active grant and return one complete credential with the earliest expiry. */
31
+ refresh(state: CredentialRefreshState<C>, signal: AbortSignal): Promise<CredentialRefreshResult<C>>;
32
+ }
33
+
6
34
  /** Longest early-refresh window in milliseconds. */
7
35
  declare const RefreshSkewMs = 300000;
8
36
  /** OAuth token endpoint client authentication. */
@@ -15,6 +43,7 @@ interface ClientCredentials {
15
43
  }
16
44
  /** Successful replacement material from one OAuth grant. */
17
45
  declare class TokenResponse {
46
+ #private;
18
47
  /** Replacement access token. */ readonly accessToken: SecretString;
19
48
  /** Rotated refresh token, empty when the provider retained it. */ readonly refreshToken: SecretString;
20
49
  /** Access lifetime in milliseconds; zero only when explicitly accepted. */ readonly expiresInMs: number;
@@ -31,9 +60,12 @@ declare class TokenResponse {
31
60
  scope: string;
32
61
  tokenType: string;
33
62
  retainedFields: Record<string, unknown>;
63
+ mappedCredentialFields?: Record<string, SecretString>;
34
64
  });
35
65
  /** Keep the previous refresh token when no rotated value was returned. */
36
66
  nextRefreshToken(prior: SecretString): SecretString;
67
+ /** Reveal only one declared credential mapping at the provider boundary. */
68
+ mappedCredentialValue(path: string): string | undefined;
37
69
  }
38
70
  /** One provider token endpoint and its declared response rules. */
39
71
  interface TokenEndpointOptions {
@@ -44,6 +76,7 @@ interface TokenEndpointOptions {
44
76
  /** Accept a successful response without token_type. */ acceptsMissingTokenType?: boolean;
45
77
  /** Accept a successful response without expires_in. */ acceptsMissingExpiresIn?: boolean;
46
78
  /** Non-standard, non-secret top-level fields to retain. */ retainedResponseFields?: readonly string[];
79
+ /** Dotted response paths mapped into private connector credentials. */ credentialMappingPaths?: readonly string[];
47
80
  /** Send JSON instead of form encoding when the provider requires it. */ usesJSONRequestBody?: boolean;
48
81
  /** Permit a declared HTTP endpoint, including private-network identity servers. */ allowsPlainHTTP?: boolean;
49
82
  /** Fixed non-secret grant parameters that cannot override OAuth grant fields. */ additionalRequestParameters?: Readonly<Record<string, string>>;
@@ -73,6 +106,7 @@ declare function isRefreshRequiredWithIssueTime(hasAccessToken: boolean, issuedA
73
106
  declare function hasAllScopes(returnedScope: string, requiredScopes: readonly string[]): boolean;
74
107
  /** Check set equality of returned and required scopes. */
75
108
  declare function hasExactScopes(returnedScope: string, requiredScopes: readonly string[]): boolean;
109
+
76
110
  /** Claims of an RS256 JWT bearer assertion. */
77
111
  interface JWTBearerAssertion {
78
112
  /** iss claim. */ issuer: string;
@@ -87,4 +121,4 @@ declare function parseRSAPrivateKeyPEM(pemText: string): KeyObject;
87
121
  /** Sign a JWT bearer grant assertion with RS256. */
88
122
  declare function signJWTBearerAssertion(assertion: JWTBearerAssertion, privateKey: KeyObject): SecretString;
89
123
 
90
- export { type ClientAuthenticationMethod, type ClientCredentials, type JWTBearerAssertion, RefreshSkewMs, TokenEndpoint, type TokenEndpointOptions, TokenResponse, forcedRefreshFloorMs, hasAllScopes, hasExactScopes, isRefreshRequired, isRefreshRequiredWithIssueTime, parseRSAPrivateKeyPEM, proportionalRefreshSkewMs, signJWTBearerAssertion };
124
+ export { type ClientAuthenticationMethod, type ClientCredentials, type JWTBearerAssertion, ManifestCredentialRefreshDriver, RefreshSkewMs, TokenEndpoint, type TokenEndpointOptions, TokenResponse, forcedRefreshFloorMs, hasAllScopes, hasExactScopes, isRefreshRequired, isRefreshRequiredWithIssueTime, parseRSAPrivateKeyPEM, proportionalRefreshSkewMs, signJWTBearerAssertion };