@superdurable/connector-doc2x 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Super Durable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # Doc2X TypeScript connector
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@superdurable/connector-doc2x` provides `getParseStatus` for an existing Doc2X PDF parsing task. It reads `status` and `progress` (percent, 0–100), without returning PDF text, result URLs, or provider failure details.
4
+
5
+ In Dex Web Connections, sign in at [Doc2X Open Platform](https://open.noedgeai.com), open **API Keys**, create or select a platform API Key and store it as the secret `apiKey`. A blank key prevents requests. The Query input `uid` comes from the PDF preupload API. The provider endpoint is fixed; leave timeout and maxResponseBytes blank for their displayed defaults unless an approved network or response requires adjustment.
6
+
7
+ The [runnable Flow](examples/basic/) uses the static connection `doc2x`. `npm run check` replays all Go-recorded provider scenarios, including retry and invalid response behavior. Live authorization and task state remain unverified without a user-controlled connection.
@@ -0,0 +1,60 @@
1
+ {
2
+ "connectorId": "doc2x",
3
+ "releaseTag": "connectors/doc2x/go/v0.1.0",
4
+ "package": {
5
+ "ecosystem": "npm",
6
+ "name": "@superdurable/connector-doc2x",
7
+ "version": "0.1.0"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "newGetParseStatusStep",
12
+ "kind": "query",
13
+ "operationId": "getParseStatus",
14
+ "inputType": "GetParseStatusInput",
15
+ "description": "Read the status and progress of an existing PDF parse task.",
16
+ "fields": {
17
+ "stepType": "stepType",
18
+ "annotations": "annotations",
19
+ "connectionName": "connectionName",
20
+ "resultAttribute": "resultAttribute"
21
+ },
22
+ "branches": [
23
+ {
24
+ "id": "found",
25
+ "field": "found",
26
+ "optional": false
27
+ },
28
+ {
29
+ "id": "providerRejected",
30
+ "field": "providerRejected",
31
+ "optional": true
32
+ },
33
+ {
34
+ "id": "invalidResponse",
35
+ "field": "invalidResponse",
36
+ "optional": true
37
+ },
38
+ {
39
+ "id": "defect",
40
+ "field": "defect",
41
+ "optional": true
42
+ }
43
+ ],
44
+ "inputSchema": {
45
+ "additionalProperties": false,
46
+ "description": "GetParseStatusInput names a PDF parsing task created by Doc2X preupload.",
47
+ "properties": {
48
+ "uid": {
49
+ "description": "UID is the opaque task identifier returned by preupload.",
50
+ "type": "string"
51
+ }
52
+ },
53
+ "required": [
54
+ "uid"
55
+ ],
56
+ "type": "object"
57
+ }
58
+ }
59
+ ]
60
+ }
@@ -0,0 +1,116 @@
1
+ // src/generated/models.ts
2
+ import { z } from "zod";
3
+ import { SecretString } from "@superdurable/connectors-sdk";
4
+ var ConfigSchema = z.object({
5
+ "timeoutMs": z.number().int().optional(),
6
+ "maxResponseBytes": z.number().int().optional()
7
+ });
8
+ var CredentialMaterialError = class extends TypeError {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "CredentialMaterialError";
12
+ }
13
+ };
14
+ var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
15
+ "project credential decoding failed",
16
+ "shared project credential decoding failed",
17
+ "project credential decoding failed: this connector version does not support shared credentials"
18
+ ]);
19
+ function isCredentialMaterialError(error) {
20
+ return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
21
+ }
22
+ function decodeCredentials(value) {
23
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
24
+ const fields = value;
25
+ const allowed = /* @__PURE__ */ new Set(["apiKey"]);
26
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
27
+ if (fields["apiKey"] != null && !(typeof fields["apiKey"] === "string")) throw new CredentialMaterialError("credential apiKey has an invalid type");
28
+ const credentials = {};
29
+ if (!fields["apiKey"]) throw new CredentialMaterialError("credential apiKey is required");
30
+ credentials.apiKey = new SecretString(fields["apiKey"] ?? "");
31
+ return credentials;
32
+ }
33
+ var GetParseStatusInputSchema = z.strictObject({
34
+ "uid": z.string()
35
+ });
36
+ var GetParseStatusOutputSchema = z.strictObject({
37
+ "status": z.string(),
38
+ "progress": z.number().int()
39
+ });
40
+
41
+ // src/generated/definitions.ts
42
+ var ConnectorID = "doc2x";
43
+ var ProviderID = "doc2x";
44
+ var GetParseStatusBranch = {
45
+ Found: "found",
46
+ ProviderRejected: "providerRejected",
47
+ InvalidResponse: "invalidResponse",
48
+ Defect: "defect"
49
+ };
50
+ var GetParseStatusBranchFound = GetParseStatusBranch.Found;
51
+ var GetParseStatusBranchProviderRejected = GetParseStatusBranch.ProviderRejected;
52
+ var GetParseStatusBranchInvalidResponse = GetParseStatusBranch.InvalidResponse;
53
+ var GetParseStatusBranchDefect = GetParseStatusBranch.Defect;
54
+ var GetParseStatusDefinition = {
55
+ operation: { connectorId: ConnectorID, operationId: "getParseStatus" },
56
+ branches: [
57
+ { id: "found", description: "Doc2X returned the current task state." },
58
+ { id: "providerRejected", description: "Doc2X rejected the key or task identifier.", optional: true },
59
+ { id: "invalidResponse", description: "Doc2X returned malformed or oversized status data.", optional: true },
60
+ { id: "defect", description: "The local API Key or task identifier is invalid.", optional: true }
61
+ ],
62
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
63
+ };
64
+ var GetParseStatusMetadata = { kind: "query", idempotency: "none", authorization: "required" };
65
+
66
+ // src/generated/connection.ts
67
+ import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
68
+ var Connection = class {
69
+ /** Stable provider and connection name. */
70
+ reference;
71
+ /** Bound provider operations. */
72
+ operations;
73
+ /** Validate a reference and bind operations. */
74
+ constructor(reference, operations) {
75
+ this.reference = ConnectionRefSchema.parse(reference);
76
+ if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
77
+ if (!operations) throw new TypeError("connector operations are required");
78
+ this.operations = operations;
79
+ }
80
+ };
81
+ function newConnection(client, reference) {
82
+ if (!client) throw new TypeError("connector client is required");
83
+ return new Connection(reference, client);
84
+ }
85
+ function newConnectionWithOperations(operations, reference) {
86
+ return new Connection(reference, operations);
87
+ }
88
+ function newProjectConnection(project, connectionName, createClient) {
89
+ if (!project) throw new TypeError("loaded project is required");
90
+ const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
91
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
92
+ if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
93
+ return newConnection(createClient(project, connectionName), reference);
94
+ }
95
+
96
+ export {
97
+ ConfigSchema,
98
+ CredentialMaterialError,
99
+ isCredentialMaterialError,
100
+ decodeCredentials,
101
+ GetParseStatusInputSchema,
102
+ GetParseStatusOutputSchema,
103
+ ConnectorID,
104
+ ProviderID,
105
+ GetParseStatusBranch,
106
+ GetParseStatusBranchFound,
107
+ GetParseStatusBranchProviderRejected,
108
+ GetParseStatusBranchInvalidResponse,
109
+ GetParseStatusBranchDefect,
110
+ GetParseStatusDefinition,
111
+ GetParseStatusMetadata,
112
+ Connection,
113
+ newConnection,
114
+ newConnectionWithOperations,
115
+ newProjectConnection
116
+ };
@@ -0,0 +1,72 @@
1
+ import { CredentialProvider, SecretString, Query, ConnectionRef } from '@superdurable/connectors-sdk';
2
+ import { z } from 'zod';
3
+
4
+ /** Connector configuration; omitted fields use manifest defaults. */
5
+ interface Config {
6
+ /** Maximum duration of one HTTPS status request as a positive Go duration such as 5s or 1m. Blank uses the displayed default; increase only for a slow approved network. Runtime value in milliseconds. */
7
+ timeoutMs?: number;
8
+ /** Maximum status response size in bytes as a positive integer. Blank uses the displayed default; increase only if the provider adds more metadata. */
9
+ maxResponseBytes?: number;
10
+ }
11
+ /** Runtime schema for manifest configuration. */
12
+ declare const ConfigSchema: z.ZodObject<{
13
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
14
+ maxResponseBytes: z.ZodOptional<z.ZodNumber>;
15
+ }, z.core.$strip>;
16
+ /** Private connector credentials resolved by the host. */
17
+ interface Credentials {
18
+ /** Secret API Key from https://open.noedgeai.com > API Keys. Sign in, create or select a key and copy it into Dex Connections. Blank prevents requests; never paste a Doc2X desktop login token. */
19
+ apiKey: SecretString;
20
+ }
21
+ /** Stored credential material that fails the connector credential checks, so no retry can succeed. */
22
+ declare class CredentialMaterialError extends TypeError {
23
+ constructor(message: string);
24
+ }
25
+ /** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
26
+ declare function isCredentialMaterialError(error: unknown): boolean;
27
+ /** Decode private credential fields for the connector. */
28
+ declare function decodeCredentials(value: unknown): Credentials;
29
+ /** Host-owned source of private connector credentials. */
30
+ type CredentialSource = CredentialProvider<Credentials>;
31
+ /** GetParseStatusInput names a PDF parsing task created by Doc2X preupload. */
32
+ interface GetParseStatusInput {
33
+ /** UID is the opaque task identifier returned by preupload. */
34
+ "uid": string;
35
+ }
36
+ /** GetParseStatusOutput contains only task state and completion percent. */
37
+ interface GetParseStatusOutput {
38
+ /** Status is processing, failed, or success. */
39
+ "status": string;
40
+ /** Progress is a percentage between zero and one hundred. */
41
+ "progress": number;
42
+ }
43
+ /** Runtime validator for GetParseStatusInput. */
44
+ declare const GetParseStatusInputSchema: z.ZodObject<{
45
+ uid: z.ZodString;
46
+ }, z.core.$strict>;
47
+ /** Runtime validator for GetParseStatusOutput. */
48
+ declare const GetParseStatusOutputSchema: z.ZodObject<{
49
+ status: z.ZodString;
50
+ progress: z.ZodNumber;
51
+ }, z.core.$strict>;
52
+
53
+ /** Typed operations supplied by a client or mock. */
54
+ interface Operations {
55
+ /** Invoke getParseStatus through this connection. */
56
+ getParseStatus(): Query<GetParseStatusInput, GetParseStatusOutput>;
57
+ }
58
+ /** Named connector connection kept outside Flow state. */
59
+ declare class Connection<BoundOperations = Operations> {
60
+ /** Stable provider and connection name. */
61
+ readonly reference: ConnectionRef;
62
+ /** Bound provider operations. */
63
+ readonly operations: BoundOperations;
64
+ /** Validate a reference and bind operations. */
65
+ constructor(reference: ConnectionRef, operations: BoundOperations);
66
+ }
67
+ /** Bind a client to a named connection. */
68
+ declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
69
+ /** Bind scripted operations to a named connection. */
70
+ declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
71
+
72
+ export { Connection as C, type GetParseStatusInput as G, type Operations as O, type GetParseStatusOutput as a, type Config as b, type Credentials as c, ConfigSchema as d, CredentialMaterialError as e, type CredentialSource as f, GetParseStatusInputSchema as g, GetParseStatusOutputSchema as h, decodeCredentials as i, isCredentialMaterialError as j, newConnectionWithOperations as k, newConnection as n };
@@ -0,0 +1,89 @@
1
+ import { G as GetParseStatusInput, a as GetParseStatusOutput, C as Connection, O as Operations, b as Config, c as Credentials } from './connection-BXvryV0h.js';
2
+ export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, g as GetParseStatusInputSchema, h as GetParseStatusOutputSchema, i as decodeCredentials, j as isCredentialMaterialError, n as newConnection, k as newConnectionWithOperations } from './connection-BXvryV0h.js';
3
+ import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, CredentialProvider, Call, QueryAttempt } from '@superdurable/connectors-sdk';
4
+ import { StepTarget } from '@superdurable/dex';
5
+ import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
6
+ import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
7
+ import 'zod';
8
+
9
+ /** Stable connector identity. */
10
+ declare const ConnectorID = "doc2x";
11
+ /** Provider identity for named connections. */
12
+ declare const ProviderID = "doc2x";
13
+ /** Branch IDs for getParseStatus. */
14
+ declare const GetParseStatusBranch: {
15
+ readonly Found: "found";
16
+ readonly ProviderRejected: "providerRejected";
17
+ readonly InvalidResponse: "invalidResponse";
18
+ readonly Defect: "defect";
19
+ };
20
+ /** Doc2X returned the current task state. */
21
+ declare const GetParseStatusBranchFound: "found";
22
+ /** Doc2X rejected the key or task identifier. */
23
+ declare const GetParseStatusBranchProviderRejected: "providerRejected";
24
+ /** Doc2X returned malformed or oversized status data. */
25
+ declare const GetParseStatusBranchInvalidResponse: "invalidResponse";
26
+ /** The local API Key or task identifier is invalid. */
27
+ declare const GetParseStatusBranchDefect: "defect";
28
+ /** Manifest definition for getParseStatus. */
29
+ declare const GetParseStatusDefinition: QueryDefinition;
30
+ /** Manifest metadata for getParseStatus. */
31
+ declare const GetParseStatusMetadata: {
32
+ readonly kind: "query";
33
+ readonly idempotency: "none";
34
+ readonly authorization: "required";
35
+ };
36
+
37
+ /** Configuration for the getParseStatus connector Step. */
38
+ interface GetParseStatusStepConfig<StepInput, OperationInput = GetParseStatusInput, OperationOutput = GetParseStatusOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
39
+ /** Named connection supplying this operation. */
40
+ connection: Connection<{
41
+ getParseStatus(): Query<OperationInput, OperationOutput>;
42
+ }>;
43
+ /** Name matching the bound connection. */
44
+ connectionName: string;
45
+ /** Doc2X returned the current task state. */
46
+ found: StepTarget<QueryResult<OperationOutput>>;
47
+ /** Doc2X rejected the key or task identifier. */
48
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
49
+ /** Doc2X returned malformed or oversized status data. */
50
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
51
+ /** The local API Key or task identifier is invalid. */
52
+ defect?: StepTarget<QueryResult<OperationOutput>>;
53
+ }
54
+ /** Build the getParseStatus Step from a named connection. */
55
+ declare function newGetParseStatusStep<StepInput, OperationInput = GetParseStatusInput, OperationOutput = GetParseStatusOutput>(configuration: GetParseStatusStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
56
+
57
+ /** Open one named Doc2x connection from Dex project configuration. */
58
+ declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
59
+
60
+ /** Optional provider sender for isolated conformance replay. */
61
+ interface Doc2xClientOptions {
62
+ /** Sender; omitted uses the SDK HTTPS transport. */ send?: (request: ProviderRequest) => Promise<ProviderResponse>;
63
+ }
64
+ /** Read a Doc2X PDF task's status without returning document contents. */
65
+ declare class Doc2xClient {
66
+ private readonly credentials;
67
+ private readonly timeoutMs;
68
+ private readonly maxResponseBytes;
69
+ private readonly send;
70
+ /** Validate local settings without contacting Doc2X. */
71
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: Doc2xClientOptions);
72
+ /** Bind the parse-status Query. */ getParseStatus(): GetParseStatusOperation;
73
+ /** Send one bounded parse-status request. */
74
+ readStatus(call: Call, uid: string): Promise<{
75
+ response?: ProviderResponse;
76
+ error?: 'credential' | 'transport' | 'tooLarge';
77
+ retryAfterMs: number;
78
+ }>;
79
+ }
80
+ /** Read the current state and progress of an existing PDF task. */
81
+ declare class GetParseStatusOperation implements Query<GetParseStatusInput, GetParseStatusOutput> {
82
+ private readonly client;
83
+ /** Bind the provider client. */ constructor(client: Doc2xClient);
84
+ /** Return the generated Query definition. */ definition(): QueryDefinition;
85
+ /** Classify one status request according to the Go connector contract. */
86
+ invoke(call: Call, input: GetParseStatusInput): Promise<QueryAttempt<GetParseStatusOutput>>;
87
+ }
88
+
89
+ export { Config, Connection, ConnectorID, Credentials, Doc2xClient, type Doc2xClientOptions, GetParseStatusBranch, GetParseStatusBranchDefect, GetParseStatusBranchFound, GetParseStatusBranchInvalidResponse, GetParseStatusBranchProviderRejected, GetParseStatusDefinition, GetParseStatusInput, GetParseStatusMetadata, GetParseStatusOutput, type GetParseStatusStepConfig, ProviderID, newGetParseStatusStep, newProjectConnection };
package/dist/index.js ADDED
@@ -0,0 +1,186 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ CredentialMaterialError,
6
+ GetParseStatusBranch,
7
+ GetParseStatusBranchDefect,
8
+ GetParseStatusBranchFound,
9
+ GetParseStatusBranchInvalidResponse,
10
+ GetParseStatusBranchProviderRejected,
11
+ GetParseStatusDefinition,
12
+ GetParseStatusInputSchema,
13
+ GetParseStatusMetadata,
14
+ GetParseStatusOutputSchema,
15
+ ProviderID,
16
+ decodeCredentials,
17
+ isCredentialMaterialError,
18
+ newConnection,
19
+ newConnectionWithOperations,
20
+ newProjectConnection
21
+ } from "./chunk-S732DLQB.js";
22
+
23
+ // src/generated/steps.ts
24
+ import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
25
+ function newGetParseStatusStep(configuration) {
26
+ const { connection, connectionName, found, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
27
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
28
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getParseStatus(), connection: connection.reference, branches: [
29
+ goToBranch("found", found),
30
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
31
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
32
+ ...defect ? [goToBranch("defect", defect)] : []
33
+ ] });
34
+ }
35
+
36
+ // src/client.ts
37
+ import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
38
+ import { BodyTooLargeError, parseRetryAfter, sendProviderRequest } from "@superdurable/connectors-sdk/providerhttp";
39
+ var endpoint = "https://v2.doc2x.noedgeai.com/api/v2/parse/status";
40
+ var emptyOutput = { status: "", progress: 0 };
41
+ var Doc2xClient = class {
42
+ /** Validate local settings without contacting Doc2X. */
43
+ constructor(config, credentials, options = {}) {
44
+ this.credentials = credentials;
45
+ if (!config || !credentials) throw new TypeError("Doc2X configuration and credentials are required");
46
+ this.timeoutMs = config.timeoutMs || 15e3;
47
+ this.maxResponseBytes = config.maxResponseBytes || 1048576;
48
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0 || this.maxResponseBytes > 16 << 20) throw new TypeError("Doc2X request limits are invalid");
49
+ this.send = options.send ?? sendProviderRequest;
50
+ }
51
+ credentials;
52
+ timeoutMs;
53
+ maxResponseBytes;
54
+ send;
55
+ /** Bind the parse-status Query. */
56
+ getParseStatus() {
57
+ return new GetParseStatusOperation(this);
58
+ }
59
+ /** Send one bounded parse-status request. */
60
+ async readStatus(call, uid) {
61
+ let apiKey = "";
62
+ try {
63
+ const credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
64
+ apiKey = credentials.apiKey instanceof SecretString ? credentials.apiKey.reveal() : "";
65
+ } catch {
66
+ return { error: "credential", retryAfterMs: 0 };
67
+ }
68
+ if (!apiKey || apiKey.length > 1024 || /[^\x21-\x7e]/.test(apiKey)) return { error: "credential", retryAfterMs: 0 };
69
+ const url = endpoint + "?" + new URLSearchParams({ uid }).toString();
70
+ const request = { url, method: "GET", headers: { Authorization: "Bearer " + apiKey, Accept: "application/json" }, timeoutMs: this.timeoutMs, maxResponseBytes: this.maxResponseBytes, addressPolicy: "publicHTTPS", signal: call.context.cancellationSignal };
71
+ let response;
72
+ try {
73
+ response = await this.send(request);
74
+ } catch (error) {
75
+ if (error instanceof BodyTooLargeError && error.status !== void 0) return { response: { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() }, error: "tooLarge", retryAfterMs: 0 };
76
+ return { error: "transport", retryAfterMs: 0 };
77
+ }
78
+ return { response, error: response.body.length > this.maxResponseBytes ? "tooLarge" : void 0, retryAfterMs: parseRetryAfter(header(response.headers, "retry-after")) };
79
+ }
80
+ };
81
+ var GetParseStatusOperation = class {
82
+ /** Bind the provider client. */
83
+ constructor(client) {
84
+ this.client = client;
85
+ }
86
+ client;
87
+ /** Return the generated Query definition. */
88
+ definition() {
89
+ return GetParseStatusDefinition;
90
+ }
91
+ /** Classify one status request according to the Go connector contract. */
92
+ async invoke(call, input) {
93
+ const uid = input?.uid;
94
+ if (typeof uid !== "string" || !uid || uid.length > 256 || uid.trim() !== uid || Array.from(uid).some((character) => character.charCodeAt(0) === 0 || character === "\r" || character === "\n")) return branch("defect", "VALIDATION");
95
+ const exchange = await this.client.readStatus(call, uid);
96
+ if (exchange.error === "credential") return branch("defect", "AUTHENTICATION");
97
+ if (exchange.error === "transport" || !exchange.response) return retry("AVAILABILITY");
98
+ const { status, body } = exchange.response;
99
+ if (status === 429) return retry("RATE_LIMIT", exchange.retryAfterMs);
100
+ if (status === 408 || status >= 500) return retry("AVAILABILITY", exchange.retryAfterMs);
101
+ if (status !== 200) return branch("providerRejected", status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : "PROVIDER_REJECTION");
102
+ if (exchange.error === "tooLarge") return branch("invalidResponse", "RESPONSE_TOO_LARGE");
103
+ let wire;
104
+ try {
105
+ wire = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
106
+ } catch {
107
+ return branch("invalidResponse", "PROTOCOL");
108
+ }
109
+ if (!isRecord(wire)) return branch("invalidResponse", "PROTOCOL");
110
+ if (wire.code !== "success") return branch("providerRejected", "PROVIDER_REJECTION");
111
+ if (!isRecord(wire.data) || !["processing", "failed", "success"].includes(String(wire.data.status))) return branch("invalidResponse", "PROTOCOL");
112
+ const progress = wire.data.progress ?? 0;
113
+ if (!Number.isInteger(progress) || progress < 0 || progress > 100) return branch("invalidResponse", "PROTOCOL");
114
+ return newQueryBranch("found", { status: wire.data.status, progress }, {});
115
+ }
116
+ };
117
+ function isRecord(value) {
118
+ return value !== null && typeof value === "object" && !Array.isArray(value);
119
+ }
120
+ function header(headers, name) {
121
+ const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
122
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
123
+ }
124
+ function failure(kind) {
125
+ return { provider: "doc2x", operation: "getParseStatus", kind, message: "Doc2X parse-status query failed" };
126
+ }
127
+ function branch(name, kind) {
128
+ return newQueryBranch(name, emptyOutput, {}, failure(kind));
129
+ }
130
+ function retry(kind, delay = 0) {
131
+ return newQueryRetry(failure(kind), delay);
132
+ }
133
+
134
+ // src/project.ts
135
+ function newProjectConnection2(project, connectionName) {
136
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
137
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "doc2x" && entry.connectionName === name);
138
+ if (!selected) throw new TypeError("Doc2x project connection is not configured");
139
+ const fields = selected.configuration;
140
+ const config = ConfigSchema.parse({ ...fields, ...fields.timeout !== void 0 ? { timeoutMs: parseDurationMilliseconds(fields.timeout) } : {} });
141
+ const credentials = {
142
+ async resolve(_call, signal) {
143
+ return decodeCredentials(await loadedProject.resolveCredential("doc2x", name, signal));
144
+ }
145
+ };
146
+ return new Doc2xClient(config, credentials);
147
+ });
148
+ }
149
+ function parseDurationMilliseconds(value) {
150
+ if (typeof value === "number") return Math.ceil(value / 1e6);
151
+ if (typeof value !== "string") throw new TypeError("timeout must be a duration");
152
+ let remaining = value;
153
+ let milliseconds = 0;
154
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
155
+ while (remaining) {
156
+ const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
157
+ if (!part) throw new TypeError("timeout must be a positive Go duration");
158
+ milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
159
+ remaining = remaining.slice(part[0].length);
160
+ }
161
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("timeout must resolve to positive whole milliseconds");
162
+ return milliseconds;
163
+ }
164
+ export {
165
+ ConfigSchema,
166
+ Connection,
167
+ ConnectorID,
168
+ CredentialMaterialError,
169
+ Doc2xClient,
170
+ GetParseStatusBranch,
171
+ GetParseStatusBranchDefect,
172
+ GetParseStatusBranchFound,
173
+ GetParseStatusBranchInvalidResponse,
174
+ GetParseStatusBranchProviderRejected,
175
+ GetParseStatusDefinition,
176
+ GetParseStatusInputSchema,
177
+ GetParseStatusMetadata,
178
+ GetParseStatusOutputSchema,
179
+ ProviderID,
180
+ decodeCredentials,
181
+ isCredentialMaterialError,
182
+ newConnection,
183
+ newConnectionWithOperations,
184
+ newGetParseStatusStep,
185
+ newProjectConnection2 as newProjectConnection
186
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
2
+ import { Failure } from '@superdurable/connectors-sdk';
3
+ import { O as Operations, C as Connection, G as GetParseStatusInput, a as GetParseStatusOutput } from './connection-BXvryV0h.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for GetParseStatusInput in scripted cases. */
7
+ declare const emptyGetParseStatusInput: GetParseStatusInput;
8
+ /** Go zero value for GetParseStatusOutput in scripted cases. */
9
+ declare const emptyGetParseStatusOutput: GetParseStatusOutput;
10
+ /** Script the found branch. */
11
+ declare function getParseStatusFound(value: GetParseStatusOutput, failure?: Failure): Case<GetParseStatusOutput>;
12
+ /** Script the providerRejected branch. */
13
+ declare function getParseStatusProviderRejected(value: GetParseStatusOutput, failure?: Failure): Case<GetParseStatusOutput>;
14
+ /** Script the invalidResponse branch. */
15
+ declare function getParseStatusInvalidResponse(value: GetParseStatusOutput, failure?: Failure): Case<GetParseStatusOutput>;
16
+ /** Script the defect branch. */
17
+ declare function getParseStatusDefect(value: GetParseStatusOutput, failure?: Failure): Case<GetParseStatusOutput>;
18
+ /** Script a safe retry of getParseStatus. */
19
+ declare function getParseStatusRetry(failure: Failure, retryAfterMs?: number): Case<GetParseStatusOutput>;
20
+ /** Manifest scenario processing for getParseStatus. */
21
+ declare function getParseStatusProcessing(): Case<GetParseStatusOutput>;
22
+ /** Default getParseStatus scenario. */
23
+ declare function getParseStatusDefault(): Case<GetParseStatusOutput>;
24
+ /** Manifest scenario completed for getParseStatus. */
25
+ declare function getParseStatusCompleted(): Case<GetParseStatusOutput>;
26
+ /** Scripted operations and manifest defaults for this connector. */
27
+ declare class GeneratedMock implements Operations {
28
+ #private;
29
+ constructor(connectionName: string);
30
+ connection(): Connection;
31
+ getParseStatus(): MockQuery<GetParseStatusInput, GetParseStatusOutput>;
32
+ assertNoFailures(): void;
33
+ }
34
+
35
+ export { GeneratedMock, emptyGetParseStatusInput, emptyGetParseStatusOutput, getParseStatusCompleted, getParseStatusDefault, getParseStatusDefect, getParseStatusFound, getParseStatusInvalidResponse, getParseStatusProcessing, getParseStatusProviderRejected, getParseStatusRetry };
package/dist/mock.js ADDED
@@ -0,0 +1,73 @@
1
+ import {
2
+ GetParseStatusDefinition,
3
+ GetParseStatusInputSchema,
4
+ GetParseStatusOutputSchema,
5
+ ProviderID,
6
+ newConnectionWithOperations
7
+ } from "./chunk-S732DLQB.js";
8
+
9
+ // src/generated/mock.ts
10
+ import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
11
+ var emptyGetParseStatusInput = GetParseStatusInputSchema.parse({
12
+ "uid": ""
13
+ });
14
+ var emptyGetParseStatusOutput = GetParseStatusOutputSchema.parse({
15
+ "status": "",
16
+ "progress": 0
17
+ });
18
+ function getParseStatusFound(value, failure) {
19
+ return branchCase("found", value, failure);
20
+ }
21
+ function getParseStatusProviderRejected(value, failure) {
22
+ return branchCase("providerRejected", value, failure);
23
+ }
24
+ function getParseStatusInvalidResponse(value, failure) {
25
+ return branchCase("invalidResponse", value, failure);
26
+ }
27
+ function getParseStatusDefect(value, failure) {
28
+ return branchCase("defect", value, failure);
29
+ }
30
+ function getParseStatusRetry(failure, retryAfterMs = 0) {
31
+ return retryCase(failure, retryAfterMs);
32
+ }
33
+ function getParseStatusProcessing() {
34
+ const value = GetParseStatusOutputSchema.parse({ "progress": 50, "status": "processing" });
35
+ return branchCase("found", value);
36
+ }
37
+ function getParseStatusDefault() {
38
+ return getParseStatusProcessing();
39
+ }
40
+ function getParseStatusCompleted() {
41
+ const value = GetParseStatusOutputSchema.parse({ "progress": 100, "status": "success" });
42
+ return branchCase("found", value);
43
+ }
44
+ var GeneratedMock = class {
45
+ #getParseStatus;
46
+ #connection;
47
+ constructor(connectionName) {
48
+ this.#getParseStatus = newQuery(GetParseStatusDefinition).default(getParseStatusDefault());
49
+ this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
50
+ }
51
+ connection() {
52
+ return this.#connection;
53
+ }
54
+ getParseStatus() {
55
+ return this.#getParseStatus;
56
+ }
57
+ assertNoFailures() {
58
+ this.#getParseStatus.assertNoFailures();
59
+ }
60
+ };
61
+ export {
62
+ GeneratedMock,
63
+ emptyGetParseStatusInput,
64
+ emptyGetParseStatusOutput,
65
+ getParseStatusCompleted,
66
+ getParseStatusDefault,
67
+ getParseStatusDefect,
68
+ getParseStatusFound,
69
+ getParseStatusInvalidResponse,
70
+ getParseStatusProcessing,
71
+ getParseStatusProviderRejected,
72
+ getParseStatusRetry
73
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@superdurable/connector-doc2x",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Doc2X PDF parse status connector for Dex TypeScript applications",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/superdurable/dex-connectors-library.git",
9
+ "directory": "connectors/doc2x/typescript"
10
+ },
11
+ "type": "module",
12
+ "engines": {
13
+ "node": "^22.0.0 || ^24.0.0"
14
+ },
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ },
22
+ "./mock": {
23
+ "types": "./dist/mock.d.ts",
24
+ "import": "./dist/mock.js"
25
+ },
26
+ "./dex-connector.json": "./dex-connector.json"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE",
32
+ "dex-connector.json"
33
+ ],
34
+ "scripts": {
35
+ "prepack": "npm run build",
36
+ "build": "tsup src/index.ts src/mock.ts --format esm --dts --clean",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint src test examples",
39
+ "test": "vitest run --exclude test/integration/**",
40
+ "test:integration": "vitest run test/integration/*.integration.test.ts",
41
+ "example:worker": "tsx examples/basic/worker.ts",
42
+ "example:start": "tsx examples/basic/start.ts",
43
+ "check": "npm run typecheck && npm run lint && npm test && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@superdurable/connectors-sdk": "0.1.1",
47
+ "@superdurable/dex": ">=1.28.0",
48
+ "zod": "^4.1.0"
49
+ },
50
+ "devDependencies": {
51
+ "@eslint/js": "^9.0.0",
52
+ "@types/node": "^22.0.0",
53
+ "eslint": "^9.0.0",
54
+ "tsup": "^8.0.0",
55
+ "tsx": "^4.23.15",
56
+ "typescript": "^5.9.0",
57
+ "typescript-eslint": "^8.0.0",
58
+ "vitest": "^3.0.0",
59
+ "yaml": "^2.9.1"
60
+ }
61
+ }