@superdurable/connector-coda 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 +21 -0
- package/README.md +29 -2
- package/dex-connector.json +82 -0
- package/dist/chunk-ZY4WUCOW.js +132 -0
- package/dist/connection-Bh8uZ-8W.d.ts +99 -0
- package/dist/index.d.ts +165 -0
- package/dist/index.js +281 -0
- package/dist/mock.d.ts +54 -0
- package/dist/mock.js +120 -0
- package/package.json +45 -4
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,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Coda TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-coda` provides the read-only `listRows` and
|
|
4
|
+
`getRow` operations for Dex TypeScript Flows. The generated operation
|
|
5
|
+
factories and models come from [the connector manifest](../connector.yaml);
|
|
6
|
+
`CodaClient` resolves the private API token for each call.
|
|
7
|
+
The encoded Step output preserves provider JSON number text, including integers
|
|
8
|
+
above JavaScript's safe integer range. Consumers that parse those values as
|
|
9
|
+
JavaScript numbers must use a lossless JSON parser to retain their precision.
|
|
10
|
+
|
|
11
|
+
The [runnable list example](examples/list-rows/) uses the static `coda`
|
|
12
|
+
connection and calls `newListRowsStep`. Its happy-path `listed` branch
|
|
13
|
+
completes the Flow; an unwired optional branch fails it. The operation inputs
|
|
14
|
+
contain only document, table, and row IDs, page size, and page token. Do not
|
|
15
|
+
put an API token in Flow input.
|
|
16
|
+
|
|
17
|
+
Install the package with `npm install @superdurable/connector-coda`. To
|
|
18
|
+
prepare a local Worker, create a private Dex project connection named `coda`
|
|
19
|
+
for provider `coda`. The connection must supply `api_token`; its
|
|
20
|
+
`baseUrl`, `timeout` (a Go duration), and `maxResponseBytes` fields may use manifest
|
|
21
|
+
defaults. Direct `CodaClient` configuration accepts `timeoutMs` in milliseconds.
|
|
22
|
+
[The runnable Worker and starter](examples/list-rows/README.md)
|
|
23
|
+
load that connection through `newProjectConnection`.
|
|
24
|
+
|
|
25
|
+
Run the package checks from this directory with `npm ci && npm run check`.
|
|
26
|
+
The [Go-recorded scenarios](../../../conformance/connectors/coda/scenarios.json)
|
|
27
|
+
verify request paths, headers, query parameters, outputs, branches, and retry
|
|
28
|
+
classification in TypeScript. The real Dex integration test uses a local Coda
|
|
29
|
+
HTTP fixture. Live Coda authorization, document permissions, and response
|
|
30
|
+
variants have not been verified.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "coda",
|
|
3
|
+
"releaseTag": "connectors/coda/go/v0.2.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-coda",
|
|
7
|
+
"version": "0.1.0"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newListRowsStep",
|
|
12
|
+
"kind": "query",
|
|
13
|
+
"operationId": "listRows",
|
|
14
|
+
"fields": {
|
|
15
|
+
"stepType": "stepType",
|
|
16
|
+
"annotations": "annotations",
|
|
17
|
+
"connectionName": "connectionName",
|
|
18
|
+
"resultAttribute": "resultAttribute"
|
|
19
|
+
},
|
|
20
|
+
"branches": [
|
|
21
|
+
{
|
|
22
|
+
"id": "listed",
|
|
23
|
+
"field": "listed",
|
|
24
|
+
"optional": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "providerRejected",
|
|
28
|
+
"field": "providerRejected",
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "invalidResponse",
|
|
33
|
+
"field": "invalidResponse",
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "defect",
|
|
38
|
+
"field": "defect",
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "newGetRowStep",
|
|
45
|
+
"kind": "query",
|
|
46
|
+
"operationId": "getRow",
|
|
47
|
+
"fields": {
|
|
48
|
+
"stepType": "stepType",
|
|
49
|
+
"annotations": "annotations",
|
|
50
|
+
"connectionName": "connectionName",
|
|
51
|
+
"resultAttribute": "resultAttribute"
|
|
52
|
+
},
|
|
53
|
+
"branches": [
|
|
54
|
+
{
|
|
55
|
+
"id": "found",
|
|
56
|
+
"field": "found",
|
|
57
|
+
"optional": false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "notFound",
|
|
61
|
+
"field": "notFound",
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "providerRejected",
|
|
66
|
+
"field": "providerRejected",
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "invalidResponse",
|
|
71
|
+
"field": "invalidResponse",
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "defect",
|
|
76
|
+
"field": "defect",
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/generated/models.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var ConfigSchema = z.object({
|
|
4
|
+
"baseUrl": z.string().optional(),
|
|
5
|
+
"timeoutMs": z.number().int().optional(),
|
|
6
|
+
"maxResponseBytes": z.number().int().optional()
|
|
7
|
+
});
|
|
8
|
+
var ListRowsInputSchema = z.strictObject({
|
|
9
|
+
"docId": z.string(),
|
|
10
|
+
"tableId": z.string(),
|
|
11
|
+
"limit": z.number().int().optional(),
|
|
12
|
+
"pageToken": z.string().optional()
|
|
13
|
+
});
|
|
14
|
+
var ListRowsOutputSchema = z.strictObject({
|
|
15
|
+
"data": z.unknown().nullable()
|
|
16
|
+
});
|
|
17
|
+
var GetRowInputSchema = z.strictObject({
|
|
18
|
+
"docId": z.string(),
|
|
19
|
+
"tableId": z.string(),
|
|
20
|
+
"rowId": z.string()
|
|
21
|
+
});
|
|
22
|
+
var GetRowOutputSchema = z.strictObject({
|
|
23
|
+
"data": z.unknown().nullable()
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// src/generated/definitions.ts
|
|
27
|
+
var ConnectorID = "coda";
|
|
28
|
+
var ProviderID = "coda";
|
|
29
|
+
var ListRowsBranch = {
|
|
30
|
+
Listed: "listed",
|
|
31
|
+
ProviderRejected: "providerRejected",
|
|
32
|
+
InvalidResponse: "invalidResponse",
|
|
33
|
+
Defect: "defect"
|
|
34
|
+
};
|
|
35
|
+
var ListRowsBranchListed = ListRowsBranch.Listed;
|
|
36
|
+
var ListRowsBranchProviderRejected = ListRowsBranch.ProviderRejected;
|
|
37
|
+
var ListRowsBranchInvalidResponse = ListRowsBranch.InvalidResponse;
|
|
38
|
+
var ListRowsBranchDefect = ListRowsBranch.Defect;
|
|
39
|
+
var ListRowsDefinition = {
|
|
40
|
+
operation: { connectorId: ConnectorID, operationId: "listRows" },
|
|
41
|
+
branches: [
|
|
42
|
+
{ id: "listed", description: "List one page of rows in a Coda table." },
|
|
43
|
+
{ id: "providerRejected", description: "The provider conclusively rejected the request or credentials.", optional: true },
|
|
44
|
+
{ id: "invalidResponse", description: "The provider returned malformed or oversized JSON.", optional: true },
|
|
45
|
+
{ id: "defect", description: "Local input, configuration, or credentials are invalid.", optional: true }
|
|
46
|
+
],
|
|
47
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
48
|
+
};
|
|
49
|
+
var ListRowsMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
50
|
+
var GetRowBranch = {
|
|
51
|
+
Found: "found",
|
|
52
|
+
NotFound: "notFound",
|
|
53
|
+
ProviderRejected: "providerRejected",
|
|
54
|
+
InvalidResponse: "invalidResponse",
|
|
55
|
+
Defect: "defect"
|
|
56
|
+
};
|
|
57
|
+
var GetRowBranchFound = GetRowBranch.Found;
|
|
58
|
+
var GetRowBranchNotFound = GetRowBranch.NotFound;
|
|
59
|
+
var GetRowBranchProviderRejected = GetRowBranch.ProviderRejected;
|
|
60
|
+
var GetRowBranchInvalidResponse = GetRowBranch.InvalidResponse;
|
|
61
|
+
var GetRowBranchDefect = GetRowBranch.Defect;
|
|
62
|
+
var GetRowDefinition = {
|
|
63
|
+
operation: { connectorId: ConnectorID, operationId: "getRow" },
|
|
64
|
+
branches: [
|
|
65
|
+
{ id: "found", description: "Get one row in a Coda table." },
|
|
66
|
+
{ id: "notFound", description: "The requested provider resource does not exist or is not visible.", optional: true },
|
|
67
|
+
{ id: "providerRejected", description: "The provider conclusively rejected the request or credentials.", optional: true },
|
|
68
|
+
{ id: "invalidResponse", description: "The provider returned malformed or oversized JSON.", optional: true },
|
|
69
|
+
{ id: "defect", description: "Local input, configuration, or credentials are invalid.", optional: true }
|
|
70
|
+
],
|
|
71
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
72
|
+
};
|
|
73
|
+
var GetRowMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
74
|
+
|
|
75
|
+
// src/generated/connection.ts
|
|
76
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
77
|
+
var Connection = class {
|
|
78
|
+
/** Stable provider and connection name. */
|
|
79
|
+
reference;
|
|
80
|
+
/** Bound provider operations. */
|
|
81
|
+
operations;
|
|
82
|
+
/** Validate a reference and bind operations. */
|
|
83
|
+
constructor(reference, operations) {
|
|
84
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
85
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
86
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
87
|
+
this.operations = operations;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function newConnection(client, reference) {
|
|
91
|
+
if (!client) throw new TypeError("connector client is required");
|
|
92
|
+
return new Connection(reference, client);
|
|
93
|
+
}
|
|
94
|
+
function newConnectionWithOperations(operations, reference) {
|
|
95
|
+
return new Connection(reference, operations);
|
|
96
|
+
}
|
|
97
|
+
function newProjectConnection(project, connectionName, createClient) {
|
|
98
|
+
if (!project) throw new TypeError("loaded project is required");
|
|
99
|
+
const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
100
|
+
const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
|
|
101
|
+
if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
|
|
102
|
+
return newConnection(createClient(project, connectionName), reference);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
ConfigSchema,
|
|
107
|
+
ListRowsInputSchema,
|
|
108
|
+
ListRowsOutputSchema,
|
|
109
|
+
GetRowInputSchema,
|
|
110
|
+
GetRowOutputSchema,
|
|
111
|
+
ConnectorID,
|
|
112
|
+
ProviderID,
|
|
113
|
+
ListRowsBranch,
|
|
114
|
+
ListRowsBranchListed,
|
|
115
|
+
ListRowsBranchProviderRejected,
|
|
116
|
+
ListRowsBranchInvalidResponse,
|
|
117
|
+
ListRowsBranchDefect,
|
|
118
|
+
ListRowsDefinition,
|
|
119
|
+
ListRowsMetadata,
|
|
120
|
+
GetRowBranch,
|
|
121
|
+
GetRowBranchFound,
|
|
122
|
+
GetRowBranchNotFound,
|
|
123
|
+
GetRowBranchProviderRejected,
|
|
124
|
+
GetRowBranchInvalidResponse,
|
|
125
|
+
GetRowBranchDefect,
|
|
126
|
+
GetRowDefinition,
|
|
127
|
+
GetRowMetadata,
|
|
128
|
+
Connection,
|
|
129
|
+
newConnection,
|
|
130
|
+
newConnectionWithOperations,
|
|
131
|
+
newProjectConnection
|
|
132
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { SecretString, CredentialProvider, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
|
+
interface Config {
|
|
6
|
+
/** Provider REST base URL; leave blank for the displayed public endpoint. Override only for a compatible gateway or loopback test server. */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Maximum time for one HTTP request as a positive Go duration such as 15s or 1m; blank uses the displayed default. Runtime value in milliseconds. */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** Maximum response body size in bytes; enter a positive integer to raise the safety limit for large pages. Blank uses the displayed default. */
|
|
11
|
+
maxResponseBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Runtime schema for manifest configuration. */
|
|
14
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
15
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
16
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
maxResponseBytes: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/** Private connector credentials resolved by the host. */
|
|
20
|
+
interface Credentials {
|
|
21
|
+
/** Secret Coda credential. Start at https://docs.superhuman.com/account and follow the authorization guide to create or find it; paste the token exactly, without Bearer. Blank prevents calls. It is sent only in a request header. */
|
|
22
|
+
apiToken: SecretString;
|
|
23
|
+
}
|
|
24
|
+
/** Host-owned source of private connector credentials. */
|
|
25
|
+
type CredentialSource = CredentialProvider<Credentials>;
|
|
26
|
+
/** ListRowsInput selects a Coda table page. */
|
|
27
|
+
interface ListRowsInput {
|
|
28
|
+
/** DocID is the ID from the document URL. */
|
|
29
|
+
"docId": string;
|
|
30
|
+
/** TableID is the stable table ID, such as grid-abc. */
|
|
31
|
+
"tableId": string;
|
|
32
|
+
/** Limit caps rows at 500; zero uses Coda's default. */
|
|
33
|
+
"limit"?: number | undefined;
|
|
34
|
+
/** PageToken is the opaque nextPageToken from a prior page. */
|
|
35
|
+
"pageToken"?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
/** ListRowsOutput preserves the Coda row page. */
|
|
38
|
+
interface ListRowsOutput {
|
|
39
|
+
/** Data contains items and a possible nextPageToken. */
|
|
40
|
+
"data": unknown | null;
|
|
41
|
+
}
|
|
42
|
+
/** GetRowInput selects one Coda row. */
|
|
43
|
+
interface GetRowInput {
|
|
44
|
+
/** DocID is the document ID. */
|
|
45
|
+
"docId": string;
|
|
46
|
+
/** TableID is the stable table ID. */
|
|
47
|
+
"tableId": string;
|
|
48
|
+
/** RowID is the stable row ID, such as i-abc. */
|
|
49
|
+
"rowId": string;
|
|
50
|
+
}
|
|
51
|
+
/** GetRowOutput preserves one Coda row. */
|
|
52
|
+
interface GetRowOutput {
|
|
53
|
+
/** Data is the row JSON object. */
|
|
54
|
+
"data": unknown | null;
|
|
55
|
+
}
|
|
56
|
+
/** Runtime validator for ListRowsInput. */
|
|
57
|
+
declare const ListRowsInputSchema: z.ZodObject<{
|
|
58
|
+
docId: z.ZodString;
|
|
59
|
+
tableId: z.ZodString;
|
|
60
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
pageToken: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
/** Runtime validator for ListRowsOutput. */
|
|
64
|
+
declare const ListRowsOutputSchema: z.ZodObject<{
|
|
65
|
+
data: z.ZodNullable<z.ZodUnknown>;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
/** Runtime validator for GetRowInput. */
|
|
68
|
+
declare const GetRowInputSchema: z.ZodObject<{
|
|
69
|
+
docId: z.ZodString;
|
|
70
|
+
tableId: z.ZodString;
|
|
71
|
+
rowId: z.ZodString;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
/** Runtime validator for GetRowOutput. */
|
|
74
|
+
declare const GetRowOutputSchema: z.ZodObject<{
|
|
75
|
+
data: z.ZodNullable<z.ZodUnknown>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
|
|
78
|
+
/** Typed operations supplied by a client or mock. */
|
|
79
|
+
interface Operations {
|
|
80
|
+
/** Invoke listRows through this connection. */
|
|
81
|
+
listRows(): Query<ListRowsInput, ListRowsOutput>;
|
|
82
|
+
/** Invoke getRow through this connection. */
|
|
83
|
+
getRow(): Query<GetRowInput, GetRowOutput>;
|
|
84
|
+
}
|
|
85
|
+
/** Named connector connection kept outside Flow state. */
|
|
86
|
+
declare class Connection<BoundOperations = Operations> {
|
|
87
|
+
/** Stable provider and connection name. */
|
|
88
|
+
readonly reference: ConnectionRef;
|
|
89
|
+
/** Bound provider operations. */
|
|
90
|
+
readonly operations: BoundOperations;
|
|
91
|
+
/** Validate a reference and bind operations. */
|
|
92
|
+
constructor(reference: ConnectionRef, operations: BoundOperations);
|
|
93
|
+
}
|
|
94
|
+
/** Bind a client to a named connection. */
|
|
95
|
+
declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
|
|
96
|
+
/** Bind scripted operations to a named connection. */
|
|
97
|
+
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
98
|
+
|
|
99
|
+
export { Connection as C, type GetRowInput as G, type ListRowsInput as L, type Operations as O, type GetRowOutput as a, type ListRowsOutput as b, type Config as c, type Credentials as d, ConfigSchema as e, type CredentialSource as f, GetRowInputSchema as g, GetRowOutputSchema as h, ListRowsInputSchema as i, ListRowsOutputSchema as j, newConnectionWithOperations as k, newConnection as n };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { G as GetRowInput, a as GetRowOutput, C as Connection, L as ListRowsInput, b as ListRowsOutput, c as Config, d as Credentials, O as Operations } from './connection-Bh8uZ-8W.js';
|
|
2
|
+
export { e as ConfigSchema, f as CredentialSource, g as GetRowInputSchema, h as GetRowOutputSchema, i as ListRowsInputSchema, j as ListRowsOutputSchema, n as newConnection, k as newConnectionWithOperations } from './connection-Bh8uZ-8W.js';
|
|
3
|
+
import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
|
|
4
|
+
import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, Call, QueryAttempt, CredentialProvider, Failure } from '@superdurable/connectors-sdk';
|
|
5
|
+
import { StepTarget } from '@superdurable/dex';
|
|
6
|
+
import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
|
|
7
|
+
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
|
8
|
+
import 'zod';
|
|
9
|
+
|
|
10
|
+
/** Stable connector identity. */
|
|
11
|
+
declare const ConnectorID = "coda";
|
|
12
|
+
/** Provider identity for named connections. */
|
|
13
|
+
declare const ProviderID = "coda";
|
|
14
|
+
/** Branch IDs for listRows. */
|
|
15
|
+
declare const ListRowsBranch: {
|
|
16
|
+
readonly Listed: "listed";
|
|
17
|
+
readonly ProviderRejected: "providerRejected";
|
|
18
|
+
readonly InvalidResponse: "invalidResponse";
|
|
19
|
+
readonly Defect: "defect";
|
|
20
|
+
};
|
|
21
|
+
/** List one page of rows in a Coda table. */
|
|
22
|
+
declare const ListRowsBranchListed: "listed";
|
|
23
|
+
/** The provider conclusively rejected the request or credentials. */
|
|
24
|
+
declare const ListRowsBranchProviderRejected: "providerRejected";
|
|
25
|
+
/** The provider returned malformed or oversized JSON. */
|
|
26
|
+
declare const ListRowsBranchInvalidResponse: "invalidResponse";
|
|
27
|
+
/** Local input, configuration, or credentials are invalid. */
|
|
28
|
+
declare const ListRowsBranchDefect: "defect";
|
|
29
|
+
/** Manifest definition for listRows. */
|
|
30
|
+
declare const ListRowsDefinition: QueryDefinition;
|
|
31
|
+
/** Manifest metadata for listRows. */
|
|
32
|
+
declare const ListRowsMetadata: {
|
|
33
|
+
readonly kind: "query";
|
|
34
|
+
readonly idempotency: "none";
|
|
35
|
+
readonly authorization: "required";
|
|
36
|
+
};
|
|
37
|
+
/** Branch IDs for getRow. */
|
|
38
|
+
declare const GetRowBranch: {
|
|
39
|
+
readonly Found: "found";
|
|
40
|
+
readonly NotFound: "notFound";
|
|
41
|
+
readonly ProviderRejected: "providerRejected";
|
|
42
|
+
readonly InvalidResponse: "invalidResponse";
|
|
43
|
+
readonly Defect: "defect";
|
|
44
|
+
};
|
|
45
|
+
/** Get one row in a Coda table. */
|
|
46
|
+
declare const GetRowBranchFound: "found";
|
|
47
|
+
/** The requested provider resource does not exist or is not visible. */
|
|
48
|
+
declare const GetRowBranchNotFound: "notFound";
|
|
49
|
+
/** The provider conclusively rejected the request or credentials. */
|
|
50
|
+
declare const GetRowBranchProviderRejected: "providerRejected";
|
|
51
|
+
/** The provider returned malformed or oversized JSON. */
|
|
52
|
+
declare const GetRowBranchInvalidResponse: "invalidResponse";
|
|
53
|
+
/** Local input, configuration, or credentials are invalid. */
|
|
54
|
+
declare const GetRowBranchDefect: "defect";
|
|
55
|
+
/** Manifest definition for getRow. */
|
|
56
|
+
declare const GetRowDefinition: QueryDefinition;
|
|
57
|
+
/** Manifest metadata for getRow. */
|
|
58
|
+
declare const GetRowMetadata: {
|
|
59
|
+
readonly kind: "query";
|
|
60
|
+
readonly idempotency: "none";
|
|
61
|
+
readonly authorization: "required";
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Configuration for the listRows connector Step. */
|
|
65
|
+
interface ListRowsStepConfig<StepInput, OperationInput = ListRowsInput, OperationOutput = ListRowsOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
66
|
+
/** Named connection supplying this operation. */
|
|
67
|
+
connection: Connection<{
|
|
68
|
+
listRows(): Query<OperationInput, OperationOutput>;
|
|
69
|
+
}>;
|
|
70
|
+
/** Name matching the bound connection. */
|
|
71
|
+
connectionName: string;
|
|
72
|
+
/** List one page of rows in a Coda table. */
|
|
73
|
+
listed: StepTarget<QueryResult<OperationOutput>>;
|
|
74
|
+
/** The provider conclusively rejected the request or credentials. */
|
|
75
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
76
|
+
/** The provider returned malformed or oversized JSON. */
|
|
77
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
78
|
+
/** Local input, configuration, or credentials are invalid. */
|
|
79
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
80
|
+
}
|
|
81
|
+
/** Build the listRows Step from a named connection. */
|
|
82
|
+
declare function newListRowsStep<StepInput, OperationInput = ListRowsInput, OperationOutput = ListRowsOutput>(configuration: ListRowsStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
83
|
+
/** Configuration for the getRow connector Step. */
|
|
84
|
+
interface GetRowStepConfig<StepInput, OperationInput = GetRowInput, OperationOutput = GetRowOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
85
|
+
/** Named connection supplying this operation. */
|
|
86
|
+
connection: Connection<{
|
|
87
|
+
getRow(): Query<OperationInput, OperationOutput>;
|
|
88
|
+
}>;
|
|
89
|
+
/** Name matching the bound connection. */
|
|
90
|
+
connectionName: string;
|
|
91
|
+
/** Get one row in a Coda table. */
|
|
92
|
+
found: StepTarget<QueryResult<OperationOutput>>;
|
|
93
|
+
/** The requested provider resource does not exist or is not visible. */
|
|
94
|
+
notFound?: StepTarget<QueryResult<OperationOutput>>;
|
|
95
|
+
/** The provider conclusively rejected the request or credentials. */
|
|
96
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
97
|
+
/** The provider returned malformed or oversized JSON. */
|
|
98
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
99
|
+
/** Local input, configuration, or credentials are invalid. */
|
|
100
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
101
|
+
}
|
|
102
|
+
/** Build the getRow Step from a named connection. */
|
|
103
|
+
declare function newGetRowStep<StepInput, OperationInput = GetRowInput, OperationOutput = GetRowOutput>(configuration: GetRowStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
104
|
+
|
|
105
|
+
/** List one page of rows from a Coda table. */
|
|
106
|
+
declare class ListRowsOperation implements Query<ListRowsInput, ListRowsOutput> {
|
|
107
|
+
private readonly client;
|
|
108
|
+
/** Bind a validated Coda client. */ constructor(client: CodaClient);
|
|
109
|
+
/** Return the manifest operation definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
|
|
110
|
+
/** Validate and query one provider page. */
|
|
111
|
+
invoke(call: Call, input: ListRowsInput): Promise<QueryAttempt<ListRowsOutput>>;
|
|
112
|
+
}
|
|
113
|
+
/** Get one stable row from a Coda table. */
|
|
114
|
+
declare class GetRowOperation implements Query<GetRowInput, GetRowOutput> {
|
|
115
|
+
private readonly client;
|
|
116
|
+
/** Bind a validated Coda client. */ constructor(client: CodaClient);
|
|
117
|
+
/** Return the manifest operation definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
|
|
118
|
+
/** Validate and query one provider row. */
|
|
119
|
+
invoke(call: Call, input: GetRowInput): Promise<QueryAttempt<GetRowOutput>>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** HTTP sender injected by tests or supplied by the connector SDK. */
|
|
123
|
+
type CodaRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
124
|
+
/** Optional provider transport dependency. */
|
|
125
|
+
interface CodaClientOptions {
|
|
126
|
+
/** Override the bounded SDK HTTP sender for deterministic provider tests. */
|
|
127
|
+
send?: CodaRequestSender;
|
|
128
|
+
}
|
|
129
|
+
/** Classified response from one Coda exchange. */
|
|
130
|
+
interface CodaExchangeFailure {
|
|
131
|
+
/** Retry or terminal branch. */
|
|
132
|
+
branch: 'retry' | 'notFound' | 'providerRejected' | 'invalidResponse' | 'defect';
|
|
133
|
+
/** Secret-safe failure. */
|
|
134
|
+
failure: Failure;
|
|
135
|
+
/** Provider-directed retry delay in milliseconds. */
|
|
136
|
+
retryAfterMs: number;
|
|
137
|
+
}
|
|
138
|
+
/** A successful response or a classified exchange failure. */
|
|
139
|
+
type CodaExchangeResult = {
|
|
140
|
+
body: Uint8Array;
|
|
141
|
+
} | {
|
|
142
|
+
outcome: CodaExchangeFailure;
|
|
143
|
+
};
|
|
144
|
+
/** Validated Coda HTTP client with credentials resolved for each call. */
|
|
145
|
+
declare class CodaClient {
|
|
146
|
+
private readonly baseUrl;
|
|
147
|
+
private readonly maxResponseBytes;
|
|
148
|
+
private readonly timeoutMs;
|
|
149
|
+
private readonly credentials;
|
|
150
|
+
private readonly send;
|
|
151
|
+
/** Construct without sending a provider request. */
|
|
152
|
+
constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: CodaClientOptions);
|
|
153
|
+
/** Bind the list query. */
|
|
154
|
+
listRows(): ListRowsOperation;
|
|
155
|
+
/** Bind the single-row query. */
|
|
156
|
+
getRow(): GetRowOperation;
|
|
157
|
+
/** Send one authenticated GET request and classify its response. */
|
|
158
|
+
exchange(call: Call, operation: string, path: string, query: URLSearchParams, hasNotFound: boolean): Promise<CodaExchangeResult>;
|
|
159
|
+
private failure;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Bind one named Coda connection from a private Dex project configuration. */
|
|
163
|
+
declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
|
|
164
|
+
|
|
165
|
+
export { CodaClient, type CodaClientOptions, type CodaRequestSender, Config, Connection, ConnectorID, Credentials, GetRowBranch, GetRowBranchDefect, GetRowBranchFound, GetRowBranchInvalidResponse, GetRowBranchNotFound, GetRowBranchProviderRejected, GetRowDefinition, GetRowInput, GetRowMetadata, GetRowOperation, GetRowOutput, type GetRowStepConfig, ListRowsBranch, ListRowsBranchDefect, ListRowsBranchInvalidResponse, ListRowsBranchListed, ListRowsBranchProviderRejected, ListRowsDefinition, ListRowsInput, ListRowsMetadata, ListRowsOperation, ListRowsOutput, type ListRowsStepConfig, ProviderID, newGetRowStep, newListRowsStep, newProjectConnection };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigSchema,
|
|
3
|
+
Connection,
|
|
4
|
+
ConnectorID,
|
|
5
|
+
GetRowBranch,
|
|
6
|
+
GetRowBranchDefect,
|
|
7
|
+
GetRowBranchFound,
|
|
8
|
+
GetRowBranchInvalidResponse,
|
|
9
|
+
GetRowBranchNotFound,
|
|
10
|
+
GetRowBranchProviderRejected,
|
|
11
|
+
GetRowDefinition,
|
|
12
|
+
GetRowInputSchema,
|
|
13
|
+
GetRowMetadata,
|
|
14
|
+
GetRowOutputSchema,
|
|
15
|
+
ListRowsBranch,
|
|
16
|
+
ListRowsBranchDefect,
|
|
17
|
+
ListRowsBranchInvalidResponse,
|
|
18
|
+
ListRowsBranchListed,
|
|
19
|
+
ListRowsBranchProviderRejected,
|
|
20
|
+
ListRowsDefinition,
|
|
21
|
+
ListRowsInputSchema,
|
|
22
|
+
ListRowsMetadata,
|
|
23
|
+
ListRowsOutputSchema,
|
|
24
|
+
ProviderID,
|
|
25
|
+
newConnection,
|
|
26
|
+
newConnectionWithOperations,
|
|
27
|
+
newProjectConnection
|
|
28
|
+
} from "./chunk-ZY4WUCOW.js";
|
|
29
|
+
|
|
30
|
+
// src/generated/steps.ts
|
|
31
|
+
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
32
|
+
function newListRowsStep(configuration) {
|
|
33
|
+
const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
34
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
35
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listRows(), connection: connection.reference, branches: [
|
|
36
|
+
goToBranch("listed", listed),
|
|
37
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
38
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
39
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
40
|
+
] });
|
|
41
|
+
}
|
|
42
|
+
function newGetRowStep(configuration) {
|
|
43
|
+
const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
44
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
45
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getRow(), connection: connection.reference, branches: [
|
|
46
|
+
goToBranch("found", found),
|
|
47
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
48
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
49
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
50
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
51
|
+
] });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/client.ts
|
|
55
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
56
|
+
import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
57
|
+
|
|
58
|
+
// src/operations.ts
|
|
59
|
+
import { newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
60
|
+
var identifier = /^[A-Za-z0-9_-]+$/;
|
|
61
|
+
var emptyOutput = { data: null };
|
|
62
|
+
var ListRowsOperation = class {
|
|
63
|
+
/** Bind a validated Coda client. */
|
|
64
|
+
constructor(client) {
|
|
65
|
+
this.client = client;
|
|
66
|
+
}
|
|
67
|
+
client;
|
|
68
|
+
/** Return the manifest operation definition. */
|
|
69
|
+
definition() {
|
|
70
|
+
return ListRowsDefinition;
|
|
71
|
+
}
|
|
72
|
+
/** Validate and query one provider page. */
|
|
73
|
+
async invoke(call, input) {
|
|
74
|
+
if (!identifier.test(input.docId) || !identifier.test(input.tableId) || !Number.isInteger(input.limit ?? 0) || (input.limit ?? 0) < 0 || (input.limit ?? 0) > 500) {
|
|
75
|
+
return failedBranch("defect", "listRows", "VALIDATION", "invalid doc, table, or limit");
|
|
76
|
+
}
|
|
77
|
+
const query = new URLSearchParams();
|
|
78
|
+
if (input.limit) query.set("limit", String(input.limit));
|
|
79
|
+
if (input.pageToken) query.set("pageToken", input.pageToken);
|
|
80
|
+
const result = await this.client.exchange(call, "listRows", `/docs/${input.docId}/tables/${input.tableId}/rows`, query, false);
|
|
81
|
+
if ("outcome" in result) return classifyOutcome(result.outcome);
|
|
82
|
+
const decoded = decodeObject(result);
|
|
83
|
+
if (!decoded || !Array.isArray(decoded.items)) return failedBranch("invalidResponse", "listRows", "PROTOCOL", "provider returned an incomplete response");
|
|
84
|
+
return newQueryBranch("listed", { data: decoded });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var GetRowOperation = class {
|
|
88
|
+
/** Bind a validated Coda client. */
|
|
89
|
+
constructor(client) {
|
|
90
|
+
this.client = client;
|
|
91
|
+
}
|
|
92
|
+
client;
|
|
93
|
+
/** Return the manifest operation definition. */
|
|
94
|
+
definition() {
|
|
95
|
+
return GetRowDefinition;
|
|
96
|
+
}
|
|
97
|
+
/** Validate and query one provider row. */
|
|
98
|
+
async invoke(call, input) {
|
|
99
|
+
if (!identifier.test(input.docId) || !identifier.test(input.tableId) || !identifier.test(input.rowId)) {
|
|
100
|
+
return failedBranch("defect", "getRow", "VALIDATION", "doc, table, and row IDs are required");
|
|
101
|
+
}
|
|
102
|
+
const result = await this.client.exchange(call, "getRow", `/docs/${input.docId}/tables/${input.tableId}/rows/${input.rowId}`, new URLSearchParams(), true);
|
|
103
|
+
if ("outcome" in result) return classifyOutcome(result.outcome);
|
|
104
|
+
const decoded = decodeObject(result);
|
|
105
|
+
if (!decoded || typeof decoded.id !== "string" || !decoded.id) return failedBranch("invalidResponse", "getRow", "PROTOCOL", "provider returned an incomplete response");
|
|
106
|
+
return newQueryBranch("found", { data: decoded });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function decodeObject(result) {
|
|
110
|
+
if (!("body" in result)) return null;
|
|
111
|
+
try {
|
|
112
|
+
const jsonWithRawNumbers = JSON;
|
|
113
|
+
const decoded = jsonWithRawNumbers.parse(Buffer.from(result.body).toString("utf8"), (_key, value, context) => typeof value === "number" ? jsonWithRawNumbers.rawJSON(context.source) : value);
|
|
114
|
+
return decoded && typeof decoded === "object" && !Array.isArray(decoded) ? decoded : null;
|
|
115
|
+
} catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function classifyOutcome(outcome) {
|
|
120
|
+
if (outcome.branch === "retry") return newQueryRetry(outcome.failure, outcome.retryAfterMs);
|
|
121
|
+
return newQueryBranch(outcome.branch, emptyOutput, {}, outcome.failure);
|
|
122
|
+
}
|
|
123
|
+
function failedBranch(branch, operation, kind, message) {
|
|
124
|
+
return newQueryBranch(branch, emptyOutput, {}, { kind, provider: "coda", operation, message });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/client.ts
|
|
128
|
+
var defaultBaseUrl = "https://coda.io/apis/v1";
|
|
129
|
+
var defaultMaxResponseBytes = 2097152;
|
|
130
|
+
var defaultTimeoutMs = 15e3;
|
|
131
|
+
var CodaClient = class {
|
|
132
|
+
baseUrl;
|
|
133
|
+
maxResponseBytes;
|
|
134
|
+
timeoutMs;
|
|
135
|
+
credentials;
|
|
136
|
+
send;
|
|
137
|
+
/** Construct without sending a provider request. */
|
|
138
|
+
constructor(config, credentials, options = {}) {
|
|
139
|
+
if (!credentials) throw new TypeError("Coda credential source is required");
|
|
140
|
+
this.baseUrl = validateBaseURL(config.baseUrl || defaultBaseUrl);
|
|
141
|
+
this.maxResponseBytes = config.maxResponseBytes || defaultMaxResponseBytes;
|
|
142
|
+
this.timeoutMs = config.timeoutMs || defaultTimeoutMs;
|
|
143
|
+
if (!Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("Coda maxResponseBytes must be positive");
|
|
144
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0) throw new TypeError("Coda timeoutMs must be positive");
|
|
145
|
+
this.credentials = credentials;
|
|
146
|
+
this.send = options.send ?? sendProviderRequest;
|
|
147
|
+
}
|
|
148
|
+
/** Bind the list query. */
|
|
149
|
+
listRows() {
|
|
150
|
+
return new ListRowsOperation(this);
|
|
151
|
+
}
|
|
152
|
+
/** Bind the single-row query. */
|
|
153
|
+
getRow() {
|
|
154
|
+
return new GetRowOperation(this);
|
|
155
|
+
}
|
|
156
|
+
/** Send one authenticated GET request and classify its response. */
|
|
157
|
+
async exchange(call, operation, path, query, hasNotFound) {
|
|
158
|
+
let token;
|
|
159
|
+
try {
|
|
160
|
+
const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
161
|
+
if (!(resolved.apiToken instanceof SecretString)) throw new TypeError("invalid Coda token");
|
|
162
|
+
token = resolved.apiToken.reveal();
|
|
163
|
+
if (!token || !isHeaderSafeCredential(token)) throw new TypeError("invalid Coda token");
|
|
164
|
+
} catch {
|
|
165
|
+
return { outcome: this.failure("defect", operation, "AUTHENTICATION", "connection credentials are unavailable") };
|
|
166
|
+
}
|
|
167
|
+
const address = this.baseUrl + path + (query.size ? `?${query.toString()}` : "");
|
|
168
|
+
let response;
|
|
169
|
+
try {
|
|
170
|
+
response = await this.send({
|
|
171
|
+
url: address,
|
|
172
|
+
method: "GET",
|
|
173
|
+
headers: { Accept: "application/json", "User-Agent": "superdurable-coda/0.1", Authorization: `Bearer ${token}` },
|
|
174
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
175
|
+
addressPolicy: this.baseUrl === defaultBaseUrl ? "publicHTTPS" : "privateNetworkHTTP",
|
|
176
|
+
timeoutMs: this.timeoutMs,
|
|
177
|
+
signal: call.context.cancellationSignal
|
|
178
|
+
});
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error instanceof BodyTooLargeError) return { outcome: this.failure("invalidResponse", operation, "RESPONSE_TOO_LARGE", "provider response exceeded the configured limit") };
|
|
181
|
+
return { outcome: this.failure("retry", operation, "AVAILABILITY", "provider request failed") };
|
|
182
|
+
}
|
|
183
|
+
const status = response.status;
|
|
184
|
+
if (status === 429 || status === 408 || status === 409 || status >= 500) {
|
|
185
|
+
const kind = status === 429 ? "RATE_LIMIT" : "AVAILABILITY";
|
|
186
|
+
const retryAfter = response.headers["retry-after"];
|
|
187
|
+
return { outcome: this.failure("retry", operation, kind, "provider is temporarily unavailable", parseRetryAfter(Array.isArray(retryAfter) ? retryAfter[0] ?? "" : retryAfter ?? "")) };
|
|
188
|
+
}
|
|
189
|
+
if (status === 404 && hasNotFound) return { outcome: this.failure("notFound", operation, "NOT_FOUND", "resource was not found") };
|
|
190
|
+
if (status !== 200) {
|
|
191
|
+
const kind = status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : status === 400 || status === 422 ? "VALIDATION" : "PROVIDER_REJECTION";
|
|
192
|
+
return { outcome: this.failure("providerRejected", operation, kind, `provider rejected the request with HTTP ${status}`) };
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
JSON.parse(Buffer.from(response.body).toString("utf8"));
|
|
196
|
+
} catch {
|
|
197
|
+
return { outcome: this.failure("invalidResponse", operation, "PROTOCOL", "provider returned malformed JSON") };
|
|
198
|
+
}
|
|
199
|
+
return { body: response.body };
|
|
200
|
+
}
|
|
201
|
+
failure(branch, operation, kind, message, retryAfterMs = 0) {
|
|
202
|
+
return { branch, failure: { kind, provider: "coda", operation, message }, retryAfterMs };
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/project.ts
|
|
207
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
208
|
+
import { z } from "zod";
|
|
209
|
+
function newProjectConnection2(project, connectionName) {
|
|
210
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
211
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "coda" && entry.connectionName === name);
|
|
212
|
+
if (!selected) throw new TypeError("Coda project connection is not configured");
|
|
213
|
+
const fields = z.strictObject({
|
|
214
|
+
baseUrl: z.string().optional(),
|
|
215
|
+
timeout: z.union([z.string(), z.number().int()]).optional(),
|
|
216
|
+
maxResponseBytes: z.number().int().optional()
|
|
217
|
+
}).parse(selected.configuration);
|
|
218
|
+
const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
|
|
219
|
+
const config = {
|
|
220
|
+
...fields.baseUrl !== void 0 ? { baseUrl: fields.baseUrl } : {},
|
|
221
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
222
|
+
...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
|
|
223
|
+
};
|
|
224
|
+
const credentials = {
|
|
225
|
+
async resolve(call, signal) {
|
|
226
|
+
void call;
|
|
227
|
+
const fields2 = await loadedProject.resolveCredential("coda", name, signal);
|
|
228
|
+
const token = fields2.api_token;
|
|
229
|
+
if (typeof token !== "string" || !token) throw new TypeError("Coda API token is unavailable");
|
|
230
|
+
return { apiToken: new SecretString2(token) };
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
return new CodaClient(config, credentials);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function parseDurationMilliseconds(value) {
|
|
237
|
+
let remaining = value;
|
|
238
|
+
let totalMilliseconds = 0;
|
|
239
|
+
const unitMilliseconds = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
|
|
240
|
+
while (remaining) {
|
|
241
|
+
const component = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
242
|
+
if (!component) throw new TypeError("Coda timeout must be a positive Go duration");
|
|
243
|
+
totalMilliseconds += Number(component[1]) * (unitMilliseconds[component[2] ?? ""] ?? NaN);
|
|
244
|
+
remaining = remaining.slice(component[0].length);
|
|
245
|
+
}
|
|
246
|
+
if (!Number.isSafeInteger(totalMilliseconds) || totalMilliseconds <= 0) throw new TypeError("Coda timeout must resolve to positive whole milliseconds");
|
|
247
|
+
return totalMilliseconds;
|
|
248
|
+
}
|
|
249
|
+
export {
|
|
250
|
+
CodaClient,
|
|
251
|
+
ConfigSchema,
|
|
252
|
+
Connection,
|
|
253
|
+
ConnectorID,
|
|
254
|
+
GetRowBranch,
|
|
255
|
+
GetRowBranchDefect,
|
|
256
|
+
GetRowBranchFound,
|
|
257
|
+
GetRowBranchInvalidResponse,
|
|
258
|
+
GetRowBranchNotFound,
|
|
259
|
+
GetRowBranchProviderRejected,
|
|
260
|
+
GetRowDefinition,
|
|
261
|
+
GetRowInputSchema,
|
|
262
|
+
GetRowMetadata,
|
|
263
|
+
GetRowOperation,
|
|
264
|
+
GetRowOutputSchema,
|
|
265
|
+
ListRowsBranch,
|
|
266
|
+
ListRowsBranchDefect,
|
|
267
|
+
ListRowsBranchInvalidResponse,
|
|
268
|
+
ListRowsBranchListed,
|
|
269
|
+
ListRowsBranchProviderRejected,
|
|
270
|
+
ListRowsDefinition,
|
|
271
|
+
ListRowsInputSchema,
|
|
272
|
+
ListRowsMetadata,
|
|
273
|
+
ListRowsOperation,
|
|
274
|
+
ListRowsOutputSchema,
|
|
275
|
+
ProviderID,
|
|
276
|
+
newConnection,
|
|
277
|
+
newConnectionWithOperations,
|
|
278
|
+
newGetRowStep,
|
|
279
|
+
newListRowsStep,
|
|
280
|
+
newProjectConnection2 as newProjectConnection
|
|
281
|
+
};
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
|
+
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
+
import { O as Operations, C as Connection, L as ListRowsInput, b as ListRowsOutput, G as GetRowInput, a as GetRowOutput } from './connection-Bh8uZ-8W.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** Go zero value for ListRowsInput in scripted cases. */
|
|
7
|
+
declare const emptyListRowsInput: ListRowsInput;
|
|
8
|
+
/** Go zero value for ListRowsOutput in scripted cases. */
|
|
9
|
+
declare const emptyListRowsOutput: ListRowsOutput;
|
|
10
|
+
/** Go zero value for GetRowInput in scripted cases. */
|
|
11
|
+
declare const emptyGetRowInput: GetRowInput;
|
|
12
|
+
/** Go zero value for GetRowOutput in scripted cases. */
|
|
13
|
+
declare const emptyGetRowOutput: GetRowOutput;
|
|
14
|
+
/** Script the listed branch. */
|
|
15
|
+
declare function listRowsListed(value: ListRowsOutput, failure?: Failure): Case<ListRowsOutput>;
|
|
16
|
+
/** Script the providerRejected branch. */
|
|
17
|
+
declare function listRowsProviderRejected(value: ListRowsOutput, failure?: Failure): Case<ListRowsOutput>;
|
|
18
|
+
/** Script the invalidResponse branch. */
|
|
19
|
+
declare function listRowsInvalidResponse(value: ListRowsOutput, failure?: Failure): Case<ListRowsOutput>;
|
|
20
|
+
/** Script the defect branch. */
|
|
21
|
+
declare function listRowsDefect(value: ListRowsOutput, failure?: Failure): Case<ListRowsOutput>;
|
|
22
|
+
/** Script a safe retry of listRows. */
|
|
23
|
+
declare function listRowsRetry(failure: Failure, retryAfterMs?: number): Case<ListRowsOutput>;
|
|
24
|
+
/** Manifest scenario defaultListRows for listRows. */
|
|
25
|
+
declare function listRowsDefaultListRows(): Case<ListRowsOutput>;
|
|
26
|
+
/** Default listRows scenario. */
|
|
27
|
+
declare function listRowsDefault(): Case<ListRowsOutput>;
|
|
28
|
+
/** Script the found branch. */
|
|
29
|
+
declare function getRowFound(value: GetRowOutput, failure?: Failure): Case<GetRowOutput>;
|
|
30
|
+
/** Script the notFound branch. */
|
|
31
|
+
declare function getRowNotFound(value: GetRowOutput, failure?: Failure): Case<GetRowOutput>;
|
|
32
|
+
/** Script the providerRejected branch. */
|
|
33
|
+
declare function getRowProviderRejected(value: GetRowOutput, failure?: Failure): Case<GetRowOutput>;
|
|
34
|
+
/** Script the invalidResponse branch. */
|
|
35
|
+
declare function getRowInvalidResponse(value: GetRowOutput, failure?: Failure): Case<GetRowOutput>;
|
|
36
|
+
/** Script the defect branch. */
|
|
37
|
+
declare function getRowDefect(value: GetRowOutput, failure?: Failure): Case<GetRowOutput>;
|
|
38
|
+
/** Script a safe retry of getRow. */
|
|
39
|
+
declare function getRowRetry(failure: Failure, retryAfterMs?: number): Case<GetRowOutput>;
|
|
40
|
+
/** Manifest scenario defaultGetRow for getRow. */
|
|
41
|
+
declare function getRowDefaultGetRow(): Case<GetRowOutput>;
|
|
42
|
+
/** Default getRow scenario. */
|
|
43
|
+
declare function getRowDefault(): Case<GetRowOutput>;
|
|
44
|
+
/** Scripted operations and manifest defaults for this connector. */
|
|
45
|
+
declare class GeneratedMock implements Operations {
|
|
46
|
+
#private;
|
|
47
|
+
constructor(connectionName: string);
|
|
48
|
+
connection(): Connection;
|
|
49
|
+
listRows(): MockQuery<ListRowsInput, ListRowsOutput>;
|
|
50
|
+
getRow(): MockQuery<GetRowInput, GetRowOutput>;
|
|
51
|
+
assertNoFailures(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { GeneratedMock, emptyGetRowInput, emptyGetRowOutput, emptyListRowsInput, emptyListRowsOutput, getRowDefault, getRowDefaultGetRow, getRowDefect, getRowFound, getRowInvalidResponse, getRowNotFound, getRowProviderRejected, getRowRetry, listRowsDefault, listRowsDefaultListRows, listRowsDefect, listRowsInvalidResponse, listRowsListed, listRowsProviderRejected, listRowsRetry };
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetRowDefinition,
|
|
3
|
+
GetRowInputSchema,
|
|
4
|
+
GetRowOutputSchema,
|
|
5
|
+
ListRowsDefinition,
|
|
6
|
+
ListRowsInputSchema,
|
|
7
|
+
ListRowsOutputSchema,
|
|
8
|
+
ProviderID,
|
|
9
|
+
newConnectionWithOperations
|
|
10
|
+
} from "./chunk-ZY4WUCOW.js";
|
|
11
|
+
|
|
12
|
+
// src/generated/mock.ts
|
|
13
|
+
import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
|
14
|
+
var emptyListRowsInput = ListRowsInputSchema.parse({
|
|
15
|
+
"docId": "",
|
|
16
|
+
"tableId": ""
|
|
17
|
+
});
|
|
18
|
+
var emptyListRowsOutput = ListRowsOutputSchema.parse({
|
|
19
|
+
"data": null
|
|
20
|
+
});
|
|
21
|
+
var emptyGetRowInput = GetRowInputSchema.parse({
|
|
22
|
+
"docId": "",
|
|
23
|
+
"tableId": "",
|
|
24
|
+
"rowId": ""
|
|
25
|
+
});
|
|
26
|
+
var emptyGetRowOutput = GetRowOutputSchema.parse({
|
|
27
|
+
"data": null
|
|
28
|
+
});
|
|
29
|
+
function listRowsListed(value, failure) {
|
|
30
|
+
return branchCase("listed", value, failure);
|
|
31
|
+
}
|
|
32
|
+
function listRowsProviderRejected(value, failure) {
|
|
33
|
+
return branchCase("providerRejected", value, failure);
|
|
34
|
+
}
|
|
35
|
+
function listRowsInvalidResponse(value, failure) {
|
|
36
|
+
return branchCase("invalidResponse", value, failure);
|
|
37
|
+
}
|
|
38
|
+
function listRowsDefect(value, failure) {
|
|
39
|
+
return branchCase("defect", value, failure);
|
|
40
|
+
}
|
|
41
|
+
function listRowsRetry(failure, retryAfterMs = 0) {
|
|
42
|
+
return retryCase(failure, retryAfterMs);
|
|
43
|
+
}
|
|
44
|
+
function listRowsDefaultListRows() {
|
|
45
|
+
const value = ListRowsOutputSchema.parse({ "data": { "items": [{ "id": "i-Meridian", "name": "Meridian", "values": { "c-Name": "Meridian" } }], "nextPageToken": "" } });
|
|
46
|
+
return branchCase("listed", value);
|
|
47
|
+
}
|
|
48
|
+
function listRowsDefault() {
|
|
49
|
+
return listRowsDefaultListRows();
|
|
50
|
+
}
|
|
51
|
+
function getRowFound(value, failure) {
|
|
52
|
+
return branchCase("found", value, failure);
|
|
53
|
+
}
|
|
54
|
+
function getRowNotFound(value, failure) {
|
|
55
|
+
return branchCase("notFound", value, failure);
|
|
56
|
+
}
|
|
57
|
+
function getRowProviderRejected(value, failure) {
|
|
58
|
+
return branchCase("providerRejected", value, failure);
|
|
59
|
+
}
|
|
60
|
+
function getRowInvalidResponse(value, failure) {
|
|
61
|
+
return branchCase("invalidResponse", value, failure);
|
|
62
|
+
}
|
|
63
|
+
function getRowDefect(value, failure) {
|
|
64
|
+
return branchCase("defect", value, failure);
|
|
65
|
+
}
|
|
66
|
+
function getRowRetry(failure, retryAfterMs = 0) {
|
|
67
|
+
return retryCase(failure, retryAfterMs);
|
|
68
|
+
}
|
|
69
|
+
function getRowDefaultGetRow() {
|
|
70
|
+
const value = GetRowOutputSchema.parse({ "data": { "id": "i-Meridian", "name": "Meridian", "values": { "c-Name": "Meridian" } } });
|
|
71
|
+
return branchCase("found", value);
|
|
72
|
+
}
|
|
73
|
+
function getRowDefault() {
|
|
74
|
+
return getRowDefaultGetRow();
|
|
75
|
+
}
|
|
76
|
+
var GeneratedMock = class {
|
|
77
|
+
#listRows;
|
|
78
|
+
#getRow;
|
|
79
|
+
#connection;
|
|
80
|
+
constructor(connectionName) {
|
|
81
|
+
this.#listRows = newQuery(ListRowsDefinition).default(listRowsDefault());
|
|
82
|
+
this.#getRow = newQuery(GetRowDefinition).default(getRowDefault());
|
|
83
|
+
this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
|
|
84
|
+
}
|
|
85
|
+
connection() {
|
|
86
|
+
return this.#connection;
|
|
87
|
+
}
|
|
88
|
+
listRows() {
|
|
89
|
+
return this.#listRows;
|
|
90
|
+
}
|
|
91
|
+
getRow() {
|
|
92
|
+
return this.#getRow;
|
|
93
|
+
}
|
|
94
|
+
assertNoFailures() {
|
|
95
|
+
this.#listRows.assertNoFailures();
|
|
96
|
+
this.#getRow.assertNoFailures();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
export {
|
|
100
|
+
GeneratedMock,
|
|
101
|
+
emptyGetRowInput,
|
|
102
|
+
emptyGetRowOutput,
|
|
103
|
+
emptyListRowsInput,
|
|
104
|
+
emptyListRowsOutput,
|
|
105
|
+
getRowDefault,
|
|
106
|
+
getRowDefaultGetRow,
|
|
107
|
+
getRowDefect,
|
|
108
|
+
getRowFound,
|
|
109
|
+
getRowInvalidResponse,
|
|
110
|
+
getRowNotFound,
|
|
111
|
+
getRowProviderRejected,
|
|
112
|
+
getRowRetry,
|
|
113
|
+
listRowsDefault,
|
|
114
|
+
listRowsDefaultListRows,
|
|
115
|
+
listRowsDefect,
|
|
116
|
+
listRowsInvalidResponse,
|
|
117
|
+
listRowsListed,
|
|
118
|
+
listRowsProviderRejected,
|
|
119
|
+
listRowsRetry
|
|
120
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-coda",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Coda connector for Dex TypeScript applications",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/superdurable/dex-connectors-library.git",
|
|
9
|
+
"directory": "connectors/coda/typescript"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" },
|
|
13
|
+
"engines": { "node": "^22.0.0 || ^24.0.0" },
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
|
|
18
|
+
"./mock": { "types": "./dist/mock.d.ts", "import": "./dist/mock.js" }
|
|
19
|
+
},
|
|
20
|
+
"files": ["dist", "dex-connector.json", "README.md", "LICENSE"],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts src/mock.ts --format esm --dts --clean",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"lint": "eslint src test examples",
|
|
25
|
+
"test": "npm run build && vitest run --exclude 'test/integration/**'",
|
|
26
|
+
"test:integration": "npm run build && vitest run test/integration/*.integration.test.ts",
|
|
27
|
+
"check": "npm test && npm run typecheck && npm run lint",
|
|
28
|
+
"example:list": "npm run build && tsx examples/list-rows/main.ts",
|
|
29
|
+
"example:list:start": "npm run build && tsx examples/list-rows/start.ts"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@superdurable/connectors-sdk": "0.1.0",
|
|
33
|
+
"@superdurable/dex": ">=1.28.0",
|
|
34
|
+
"zod": "^4.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@eslint/js": "^9.0.0",
|
|
38
|
+
"@types/node": "^22.0.0",
|
|
39
|
+
"eslint": "^9.0.0",
|
|
40
|
+
"tsup": "^8.0.0",
|
|
41
|
+
"tsx": "^4.23.15",
|
|
42
|
+
"typescript": "^5.9.0",
|
|
43
|
+
"typescript-eslint": "^8.0.0",
|
|
44
|
+
"vitest": "^3.0.0",
|
|
45
|
+
"yaml": "^2.9.1"
|
|
46
|
+
}
|
|
47
|
+
}
|