@superdurable/connector-moxin 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,5 @@
1
- # Temporary Holding Version
1
+ # Moxin 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
+ Look up country, province, city, district, and network operator for one public IPv4 address.
4
+
5
+ Install `@superdurable/connector-moxin` and use `newProjectConnection` with the static connection name in the runnable [`examples/basic`](examples/basic) Flow. Configure the connection and provider credentials in Dex Web Connections. The operation `listModels` resolves credentials for each call. Local conformance tests replay the Go provider scenarios; live provider authorization has not been verified.
@@ -0,0 +1,52 @@
1
+ {
2
+ "connectorId": "moxin",
3
+ "releaseTag": "connectors/moxin/go/v0.1.0",
4
+ "package": {
5
+ "ecosystem": "npm",
6
+ "name": "@superdurable/connector-moxin",
7
+ "version": "0.1.0"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "newListModelsStep",
12
+ "kind": "query",
13
+ "operationId": "listModels",
14
+ "inputType": "ListModelsInput",
15
+ "description": "List current model IDs available to the configured token and group.",
16
+ "fields": {
17
+ "stepType": "stepType",
18
+ "annotations": "annotations",
19
+ "connectionName": "connectionName",
20
+ "resultAttribute": "resultAttribute"
21
+ },
22
+ "branches": [
23
+ {
24
+ "id": "listed",
25
+ "field": "listed",
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": "ListModelsInput requires no selector; the token and group define visibility.",
47
+ "properties": {},
48
+ "type": "object"
49
+ }
50
+ }
51
+ ]
52
+ }
@@ -0,0 +1,118 @@
1
+ // src/generated/models.ts
2
+ import { z } from "zod";
3
+ import { SecretString } from "@superdurable/connectors-sdk";
4
+ var ConfigSchema = z.object({
5
+ "baseUrl": z.string().optional(),
6
+ "timeoutMs": z.number().int().optional(),
7
+ "maxResponseBytes": z.number().int().optional()
8
+ });
9
+ var CredentialMaterialError = class extends TypeError {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = "CredentialMaterialError";
13
+ }
14
+ };
15
+ var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
16
+ "project credential decoding failed",
17
+ "shared project credential decoding failed",
18
+ "project credential decoding failed: this connector version does not support shared credentials"
19
+ ]);
20
+ function isCredentialMaterialError(error) {
21
+ return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
22
+ }
23
+ function decodeCredentials(value) {
24
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
25
+ const fields = value;
26
+ const allowed = /* @__PURE__ */ new Set(["platform_token"]);
27
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
28
+ if (fields["platform_token"] != null && !(typeof fields["platform_token"] === "string")) throw new CredentialMaterialError("credential platform_token has an invalid type");
29
+ const credentials = {};
30
+ if (!fields["platform_token"]) throw new CredentialMaterialError("credential platform_token is required");
31
+ credentials.platformToken = new SecretString(fields["platform_token"] ?? "");
32
+ return credentials;
33
+ }
34
+ var ListModelsInputSchema = z.strictObject({});
35
+ var ModelSchema = z.strictObject({
36
+ "id": z.string()
37
+ });
38
+ var ModelPageSchema = z.strictObject({
39
+ "models": z.array(ModelSchema).nullable()
40
+ });
41
+
42
+ // src/generated/definitions.ts
43
+ var ConnectorID = "moxin";
44
+ var ProviderID = "moxin";
45
+ var ListModelsBranch = {
46
+ Listed: "listed",
47
+ ProviderRejected: "providerRejected",
48
+ InvalidResponse: "invalidResponse",
49
+ Defect: "defect"
50
+ };
51
+ var ListModelsBranchListed = ListModelsBranch.Listed;
52
+ var ListModelsBranchProviderRejected = ListModelsBranch.ProviderRejected;
53
+ var ListModelsBranchInvalidResponse = ListModelsBranch.InvalidResponse;
54
+ var ListModelsBranchDefect = ListModelsBranch.Defect;
55
+ var ListModelsDefinition = {
56
+ operation: { connectorId: ConnectorID, operationId: "listModels" },
57
+ branches: [
58
+ { id: "listed", description: "Moxin returned the authorized model list, possibly empty." },
59
+ { id: "providerRejected", description: "Moxin rejected the token or model-list request.", optional: true },
60
+ { id: "invalidResponse", description: "Moxin returned malformed or oversized model data.", optional: true },
61
+ { id: "defect", description: "Local connection configuration or credentials are invalid.", optional: true }
62
+ ],
63
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
64
+ };
65
+ var ListModelsMetadata = { kind: "query", idempotency: "none", authorization: "required" };
66
+
67
+ // src/generated/connection.ts
68
+ import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
69
+ var Connection = class {
70
+ /** Stable provider and connection name. */
71
+ reference;
72
+ /** Bound provider operations. */
73
+ operations;
74
+ /** Validate a reference and bind operations. */
75
+ constructor(reference, operations) {
76
+ this.reference = ConnectionRefSchema.parse(reference);
77
+ if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
78
+ if (!operations) throw new TypeError("connector operations are required");
79
+ this.operations = operations;
80
+ }
81
+ };
82
+ function newConnection(client, reference) {
83
+ if (!client) throw new TypeError("connector client is required");
84
+ return new Connection(reference, client);
85
+ }
86
+ function newConnectionWithOperations(operations, reference) {
87
+ return new Connection(reference, operations);
88
+ }
89
+ function newProjectConnection(project, connectionName, createClient) {
90
+ if (!project) throw new TypeError("loaded project is required");
91
+ const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
92
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
93
+ if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
94
+ return newConnection(createClient(project, connectionName), reference);
95
+ }
96
+
97
+ export {
98
+ ConfigSchema,
99
+ CredentialMaterialError,
100
+ isCredentialMaterialError,
101
+ decodeCredentials,
102
+ ListModelsInputSchema,
103
+ ModelSchema,
104
+ ModelPageSchema,
105
+ ConnectorID,
106
+ ProviderID,
107
+ ListModelsBranch,
108
+ ListModelsBranchListed,
109
+ ListModelsBranchProviderRejected,
110
+ ListModelsBranchInvalidResponse,
111
+ ListModelsBranchDefect,
112
+ ListModelsDefinition,
113
+ ListModelsMetadata,
114
+ Connection,
115
+ newConnection,
116
+ newConnectionWithOperations,
117
+ newProjectConnection
118
+ };
@@ -0,0 +1,79 @@
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
+ /** HTTPS origin of the Moxin platform API. Leave blank for the displayed public endpoint; override only when your platform administrator assigns another trusted HTTPS address or for a local test server. */
7
+ baseUrl?: string;
8
+ /** Maximum duration of one model-list request as a positive Go duration such as 30s or 1m. Leave blank for the displayed default; raise only for a slow approved network. Runtime value in milliseconds. */
9
+ timeoutMs?: number;
10
+ /** Maximum model-list response size in bytes as a positive integer. Leave blank for the displayed default; raise only if your token sees unusually many models. */
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 sk-prefixed token created after sign-in at https://api.kokoniworld.com/ > Console > Token Management > New Token. Your administrator must first open an account and assign a group. Copy the token without Bearer; blank prevents requests. Dex sends it only in the Authorization header. */
22
+ platformToken: SecretString;
23
+ }
24
+ /** Stored credential material that fails the connector credential checks, so no retry can succeed. */
25
+ declare class CredentialMaterialError extends TypeError {
26
+ constructor(message: string);
27
+ }
28
+ /** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
29
+ declare function isCredentialMaterialError(error: unknown): boolean;
30
+ /** Decode private credential fields for the connector. */
31
+ declare function decodeCredentials(value: unknown): Credentials;
32
+ /** Host-owned source of private connector credentials. */
33
+ type CredentialSource = CredentialProvider<Credentials>;
34
+ /** ListModelsInput requires no selector; the token and group define visibility. */
35
+ interface ListModelsInput {
36
+ }
37
+ /** Model identifies a model currently available to the configured token. */
38
+ interface Model {
39
+ /** ID is the model identifier accepted by Moxin generation APIs. */
40
+ "id": string;
41
+ }
42
+ /** ModelPage contains the current authorized model IDs. */
43
+ interface ModelPage {
44
+ /** Models may be empty when no model is assigned to the token's group. */
45
+ "models": Array<Model> | null;
46
+ }
47
+ /** Runtime validator for ListModelsInput. */
48
+ declare const ListModelsInputSchema: z.ZodObject<{}, z.core.$strict>;
49
+ /** Runtime validator for Model. */
50
+ declare const ModelSchema: z.ZodObject<{
51
+ id: z.ZodString;
52
+ }, z.core.$strict>;
53
+ /** Runtime validator for ModelPage. */
54
+ declare const ModelPageSchema: z.ZodObject<{
55
+ models: z.ZodNullable<z.ZodArray<z.ZodObject<{
56
+ id: z.ZodString;
57
+ }, z.core.$strict>>>;
58
+ }, z.core.$strict>;
59
+
60
+ /** Typed operations supplied by a client or mock. */
61
+ interface Operations {
62
+ /** Invoke listModels through this connection. */
63
+ listModels(): Query<ListModelsInput, ModelPage>;
64
+ }
65
+ /** Named connector connection kept outside Flow state. */
66
+ declare class Connection<BoundOperations = Operations> {
67
+ /** Stable provider and connection name. */
68
+ readonly reference: ConnectionRef;
69
+ /** Bound provider operations. */
70
+ readonly operations: BoundOperations;
71
+ /** Validate a reference and bind operations. */
72
+ constructor(reference: ConnectionRef, operations: BoundOperations);
73
+ }
74
+ /** Bind a client to a named connection. */
75
+ declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
76
+ /** Bind scripted operations to a named connection. */
77
+ declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
78
+
79
+ export { Connection as C, type ListModelsInput as L, type ModelPage as M, type Operations as O, type Config as a, type Credentials as b, ConfigSchema as c, CredentialMaterialError as d, type CredentialSource as e, ListModelsInputSchema as f, type Model as g, ModelPageSchema as h, ModelSchema as i, decodeCredentials as j, isCredentialMaterialError as k, newConnectionWithOperations as l, newConnection as n };
@@ -0,0 +1,90 @@
1
+ import { L as ListModelsInput, M as ModelPage, C as Connection, O as Operations, a as Config, b as Credentials } from './connection-CXdoxBtX.js';
2
+ export { c as ConfigSchema, d as CredentialMaterialError, e as CredentialSource, f as ListModelsInputSchema, g as Model, h as ModelPageSchema, i as ModelSchema, j as decodeCredentials, k as isCredentialMaterialError, n as newConnection, l as newConnectionWithOperations } from './connection-CXdoxBtX.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 = "moxin";
11
+ /** Provider identity for named connections. */
12
+ declare const ProviderID = "moxin";
13
+ /** Branch IDs for listModels. */
14
+ declare const ListModelsBranch: {
15
+ readonly Listed: "listed";
16
+ readonly ProviderRejected: "providerRejected";
17
+ readonly InvalidResponse: "invalidResponse";
18
+ readonly Defect: "defect";
19
+ };
20
+ /** Moxin returned the authorized model list, possibly empty. */
21
+ declare const ListModelsBranchListed: "listed";
22
+ /** Moxin rejected the token or model-list request. */
23
+ declare const ListModelsBranchProviderRejected: "providerRejected";
24
+ /** Moxin returned malformed or oversized model data. */
25
+ declare const ListModelsBranchInvalidResponse: "invalidResponse";
26
+ /** Local connection configuration or credentials are invalid. */
27
+ declare const ListModelsBranchDefect: "defect";
28
+ /** Manifest definition for listModels. */
29
+ declare const ListModelsDefinition: QueryDefinition;
30
+ /** Manifest metadata for listModels. */
31
+ declare const ListModelsMetadata: {
32
+ readonly kind: "query";
33
+ readonly idempotency: "none";
34
+ readonly authorization: "required";
35
+ };
36
+
37
+ /** Configuration for the listModels connector Step. */
38
+ interface ListModelsStepConfig<StepInput, OperationInput = ListModelsInput, OperationOutput = ModelPage> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
39
+ /** Named connection supplying this operation. */
40
+ connection: Connection<{
41
+ listModels(): Query<OperationInput, OperationOutput>;
42
+ }>;
43
+ /** Name matching the bound connection. */
44
+ connectionName: string;
45
+ /** Moxin returned the authorized model list, possibly empty. */
46
+ listed: StepTarget<QueryResult<OperationOutput>>;
47
+ /** Moxin rejected the token or model-list request. */
48
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
49
+ /** Moxin returned malformed or oversized model data. */
50
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
51
+ /** Local connection configuration or credentials are invalid. */
52
+ defect?: StepTarget<QueryResult<OperationOutput>>;
53
+ }
54
+ /** Build the listModels Step from a named connection. */
55
+ declare function newListModelsStep<StepInput, OperationInput = ListModelsInput, OperationOutput = ModelPage>(configuration: ListModelsStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
56
+
57
+ /** Open one named Moxin connection from Dex project configuration. */
58
+ declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
59
+
60
+ /** Optional HTTP transport for provider tests. */
61
+ interface MoxinClientOptions {
62
+ send?: (request: ProviderRequest) => Promise<ProviderResponse>;
63
+ }
64
+ /** Resolve Moxin credentials for each model-list query. */
65
+ declare class MoxinClient {
66
+ private readonly credentials;
67
+ private readonly baseUrl;
68
+ private readonly timeoutMs;
69
+ private readonly maxResponseBytes;
70
+ private readonly send;
71
+ /** Validate settings without contacting Moxin. */
72
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: MoxinClientOptions);
73
+ /** Bind the model-list Query. */ listModels(): ListModelsOperation;
74
+ /** Send one bounded request. */
75
+ request(call: Call): Promise<{
76
+ response?: ProviderResponse;
77
+ error?: 'credential' | 'transport' | 'tooLarge';
78
+ retryAfterMs: number;
79
+ }>;
80
+ }
81
+ /** List authorized model identifiers. */
82
+ declare class ListModelsOperation implements Query<ListModelsInput, ModelPage> {
83
+ private readonly client;
84
+ /** Bind the provider client. */ constructor(client: MoxinClient);
85
+ /** Return the generated Query definition. */ definition(): QueryDefinition;
86
+ /** Classify the provider response using the Go contract. */
87
+ invoke(call: Call, _input: ListModelsInput): Promise<QueryAttempt<ModelPage>>;
88
+ }
89
+
90
+ export { Config, Connection, ConnectorID, Credentials, ListModelsBranch, ListModelsBranchDefect, ListModelsBranchInvalidResponse, ListModelsBranchListed, ListModelsBranchProviderRejected, ListModelsDefinition, ListModelsInput, ListModelsMetadata, type ListModelsStepConfig, ModelPage, MoxinClient, type MoxinClientOptions, ProviderID, newListModelsStep, newProjectConnection };
package/dist/index.js ADDED
@@ -0,0 +1,189 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ CredentialMaterialError,
6
+ ListModelsBranch,
7
+ ListModelsBranchDefect,
8
+ ListModelsBranchInvalidResponse,
9
+ ListModelsBranchListed,
10
+ ListModelsBranchProviderRejected,
11
+ ListModelsDefinition,
12
+ ListModelsInputSchema,
13
+ ListModelsMetadata,
14
+ ModelPageSchema,
15
+ ModelSchema,
16
+ ProviderID,
17
+ decodeCredentials,
18
+ isCredentialMaterialError,
19
+ newConnection,
20
+ newConnectionWithOperations,
21
+ newProjectConnection
22
+ } from "./chunk-4LDUHHTO.js";
23
+
24
+ // src/generated/steps.ts
25
+ import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
26
+ function newListModelsStep(configuration) {
27
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
28
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
29
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listModels(), connection: connection.reference, branches: [
30
+ goToBranch("listed", listed),
31
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
32
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
33
+ ...defect ? [goToBranch("defect", defect)] : []
34
+ ] });
35
+ }
36
+
37
+ // src/client.ts
38
+ import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
39
+ import { BodyTooLargeError, parseRetryAfter, sendProviderRequest } from "@superdurable/connectors-sdk/providerhttp";
40
+ var empty = { models: [] };
41
+ var MoxinClient = class {
42
+ /** Validate settings without contacting Moxin. */
43
+ constructor(config, credentials, options = {}) {
44
+ this.credentials = credentials;
45
+ if (!config || !credentials) throw new TypeError("Moxin settings and credentials are required");
46
+ this.baseUrl = config.baseUrl || "https://api.kokoniworld.com";
47
+ this.timeoutMs = config.timeoutMs || 15e3;
48
+ this.maxResponseBytes = config.maxResponseBytes || 1048576;
49
+ const url = new URL(this.baseUrl);
50
+ if (url.protocol !== "https:" || url.pathname !== "/" && url.pathname !== "" || url.search || url.hash || !Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0 || this.maxResponseBytes > 16 * 1024 * 1024) throw new TypeError("Moxin settings are invalid");
51
+ this.baseUrl = url.origin;
52
+ this.send = options.send ?? sendProviderRequest;
53
+ }
54
+ credentials;
55
+ baseUrl;
56
+ timeoutMs;
57
+ maxResponseBytes;
58
+ send;
59
+ /** Bind the model-list Query. */
60
+ listModels() {
61
+ return new ListModelsOperation(this);
62
+ }
63
+ /** Send one bounded request. */
64
+ async request(call) {
65
+ let token = "";
66
+ try {
67
+ const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
68
+ token = resolved.platformToken instanceof SecretString ? resolved.platformToken.reveal() : "";
69
+ } catch {
70
+ return { error: "credential", retryAfterMs: 0 };
71
+ }
72
+ if (!token || token.length > 2048 || /[^\x21-\x7e]/.test(token) || /^bearer /i.test(token)) return { error: "credential", retryAfterMs: 0 };
73
+ const request = { url: `${this.baseUrl}/v1/models`, method: "GET", headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: `Bearer ${token}` }, timeoutMs: this.timeoutMs, maxResponseBytes: this.maxResponseBytes, addressPolicy: "publicHTTPS", signal: call.context.cancellationSignal };
74
+ let response;
75
+ try {
76
+ response = await this.send(request);
77
+ } catch (error) {
78
+ if (error instanceof BodyTooLargeError && error.status !== void 0) return { response: { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() }, error: "tooLarge", retryAfterMs: 0 };
79
+ return { error: "transport", retryAfterMs: 0 };
80
+ }
81
+ return { response, error: response.body.length > this.maxResponseBytes ? "tooLarge" : void 0, retryAfterMs: parseRetryAfter(header(response.headers, "retry-after")) };
82
+ }
83
+ };
84
+ var ListModelsOperation = class {
85
+ /** Bind the provider client. */
86
+ constructor(client) {
87
+ this.client = client;
88
+ }
89
+ client;
90
+ /** Return the generated Query definition. */
91
+ definition() {
92
+ return ListModelsDefinition;
93
+ }
94
+ /** Classify the provider response using the Go contract. */
95
+ async invoke(call, _input) {
96
+ void _input;
97
+ const exchange = await this.client.request(call);
98
+ if (exchange.error === "credential") return branch("defect", "AUTHENTICATION");
99
+ if (exchange.error === "transport" || !exchange.response) return retry("AVAILABILITY");
100
+ const { status, body } = exchange.response;
101
+ if (status === 429) return retry("RATE_LIMIT", exchange.retryAfterMs);
102
+ if (status === 408 || status >= 500) return retry("AVAILABILITY", exchange.retryAfterMs);
103
+ if (exchange.error === "tooLarge") return branch("invalidResponse", "RESPONSE_TOO_LARGE");
104
+ if (status !== 200) return branch("providerRejected", status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : status === 400 || status === 404 ? "VALIDATION" : "PROVIDER_REJECTION");
105
+ let wire;
106
+ try {
107
+ wire = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
108
+ } catch {
109
+ return branch("invalidResponse", "PROTOCOL");
110
+ }
111
+ if (!wire || typeof wire !== "object" || Array.isArray(wire)) return branch("invalidResponse", "PROTOCOL");
112
+ const record = wire;
113
+ if (record.object !== "list" || !Array.isArray(record.data) || record.data.length > 1e3) return branch("invalidResponse", "PROTOCOL");
114
+ const models = [];
115
+ for (const item of record.data) {
116
+ if (!item || typeof item !== "object" || Array.isArray(item) || typeof item.id !== "string" || !item.id || item.object !== "model") return branch("invalidResponse", "PROTOCOL");
117
+ models.push({ id: item.id });
118
+ }
119
+ return newQueryBranch("listed", { models });
120
+ }
121
+ };
122
+ function header(headers, name) {
123
+ const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
124
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
125
+ }
126
+ function failure(kind) {
127
+ return { provider: "moxin", operation: "listModels", kind, message: "Moxin model-list query failed" };
128
+ }
129
+ function branch(name, kind) {
130
+ return newQueryBranch(name, empty, {}, failure(kind));
131
+ }
132
+ function retry(kind, delay = 0) {
133
+ return newQueryRetry(failure(kind), delay);
134
+ }
135
+
136
+ // src/project.ts
137
+ function newProjectConnection2(project, connectionName) {
138
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
139
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "moxin" && entry.connectionName === name);
140
+ if (!selected) throw new TypeError("Moxin project connection is not configured");
141
+ const fields = selected.configuration;
142
+ const config = ConfigSchema.parse({ ...fields, ...fields.timeout !== void 0 ? { timeoutMs: parseDurationMilliseconds(fields.timeout) } : {} });
143
+ const credentials = {
144
+ async resolve(_call, signal) {
145
+ return decodeCredentials(await loadedProject.resolveCredential("moxin", name, signal));
146
+ }
147
+ };
148
+ return new MoxinClient(config, credentials);
149
+ });
150
+ }
151
+ function parseDurationMilliseconds(value) {
152
+ if (typeof value === "number") return Math.ceil(value / 1e6);
153
+ if (typeof value !== "string") throw new TypeError("timeout must be a duration");
154
+ let remaining = value;
155
+ let milliseconds = 0;
156
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
157
+ while (remaining) {
158
+ const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
159
+ if (!part) throw new TypeError("timeout must be a positive Go duration");
160
+ milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
161
+ remaining = remaining.slice(part[0].length);
162
+ }
163
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("timeout must resolve to positive whole milliseconds");
164
+ return milliseconds;
165
+ }
166
+ export {
167
+ ConfigSchema,
168
+ Connection,
169
+ ConnectorID,
170
+ CredentialMaterialError,
171
+ ListModelsBranch,
172
+ ListModelsBranchDefect,
173
+ ListModelsBranchInvalidResponse,
174
+ ListModelsBranchListed,
175
+ ListModelsBranchProviderRejected,
176
+ ListModelsDefinition,
177
+ ListModelsInputSchema,
178
+ ListModelsMetadata,
179
+ ModelPageSchema,
180
+ ModelSchema,
181
+ MoxinClient,
182
+ ProviderID,
183
+ decodeCredentials,
184
+ isCredentialMaterialError,
185
+ newConnection,
186
+ newConnectionWithOperations,
187
+ newListModelsStep,
188
+ newProjectConnection2 as newProjectConnection
189
+ };
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, L as ListModelsInput, M as ModelPage, g as Model } from './connection-CXdoxBtX.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for ListModelsInput in scripted cases. */
7
+ declare const emptyListModelsInput: ListModelsInput;
8
+ /** Go zero value for Model in scripted cases. */
9
+ declare const emptyModel: Model;
10
+ /** Go zero value for ModelPage in scripted cases. */
11
+ declare const emptyModelPage: ModelPage;
12
+ /** Script the listed branch. */
13
+ declare function listModelsListed(value: ModelPage, failure?: Failure): Case<ModelPage>;
14
+ /** Script the providerRejected branch. */
15
+ declare function listModelsProviderRejected(value: ModelPage, failure?: Failure): Case<ModelPage>;
16
+ /** Script the invalidResponse branch. */
17
+ declare function listModelsInvalidResponse(value: ModelPage, failure?: Failure): Case<ModelPage>;
18
+ /** Script the defect branch. */
19
+ declare function listModelsDefect(value: ModelPage, failure?: Failure): Case<ModelPage>;
20
+ /** Script a safe retry of listModels. */
21
+ declare function listModelsRetry(failure: Failure, retryAfterMs?: number): Case<ModelPage>;
22
+ /** Manifest scenario listedModel for listModels. */
23
+ declare function listModelsListedModel(): Case<ModelPage>;
24
+ /** Default listModels scenario. */
25
+ declare function listModelsDefault(): Case<ModelPage>;
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
+ listModels(): MockQuery<ListModelsInput, ModelPage>;
32
+ assertNoFailures(): void;
33
+ }
34
+
35
+ export { GeneratedMock, emptyListModelsInput, emptyModel, emptyModelPage, listModelsDefault, listModelsDefect, listModelsInvalidResponse, listModelsListed, listModelsListedModel, listModelsProviderRejected, listModelsRetry };
package/dist/mock.js ADDED
@@ -0,0 +1,70 @@
1
+ import {
2
+ ListModelsDefinition,
3
+ ListModelsInputSchema,
4
+ ModelPageSchema,
5
+ ModelSchema,
6
+ ProviderID,
7
+ newConnectionWithOperations
8
+ } from "./chunk-4LDUHHTO.js";
9
+
10
+ // src/generated/mock.ts
11
+ import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
12
+ var emptyListModelsInput = ListModelsInputSchema.parse({});
13
+ var emptyModel = ModelSchema.parse({
14
+ "id": ""
15
+ });
16
+ var emptyModelPage = ModelPageSchema.parse({
17
+ "models": []
18
+ });
19
+ function listModelsListed(value, failure) {
20
+ return branchCase("listed", value, failure);
21
+ }
22
+ function listModelsProviderRejected(value, failure) {
23
+ return branchCase("providerRejected", value, failure);
24
+ }
25
+ function listModelsInvalidResponse(value, failure) {
26
+ return branchCase("invalidResponse", value, failure);
27
+ }
28
+ function listModelsDefect(value, failure) {
29
+ return branchCase("defect", value, failure);
30
+ }
31
+ function listModelsRetry(failure, retryAfterMs = 0) {
32
+ return retryCase(failure, retryAfterMs);
33
+ }
34
+ function listModelsListedModel() {
35
+ const value = ModelPageSchema.parse({ "models": [{ "id": "example-model" }] });
36
+ return branchCase("listed", value);
37
+ }
38
+ function listModelsDefault() {
39
+ return listModelsListedModel();
40
+ }
41
+ var GeneratedMock = class {
42
+ #listModels;
43
+ #connection;
44
+ constructor(connectionName) {
45
+ this.#listModels = newQuery(ListModelsDefinition).default(listModelsDefault());
46
+ this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
47
+ }
48
+ connection() {
49
+ return this.#connection;
50
+ }
51
+ listModels() {
52
+ return this.#listModels;
53
+ }
54
+ assertNoFailures() {
55
+ this.#listModels.assertNoFailures();
56
+ }
57
+ };
58
+ export {
59
+ GeneratedMock,
60
+ emptyListModelsInput,
61
+ emptyModel,
62
+ emptyModelPage,
63
+ listModelsDefault,
64
+ listModelsDefect,
65
+ listModelsInvalidResponse,
66
+ listModelsListed,
67
+ listModelsListedModel,
68
+ listModelsProviderRejected,
69
+ listModelsRetry
70
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@superdurable/connector-moxin",
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": "moxin connector for Dex TypeScript applications",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/superdurable/dex-connectors-library.git",
9
+ "directory": "connectors/moxin/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.11.0",
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
+ }