@superdurable/connector-navinfo 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
+ # NavInfo 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-navinfo` 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 `lookupIPLocation` resolves credentials for each call. Local conformance tests replay the Go provider scenarios; live provider authorization has not been verified.
@@ -0,0 +1,60 @@
1
+ {
2
+ "connectorId": "navinfo",
3
+ "releaseTag": "connectors/navinfo/go/v0.1.0",
4
+ "package": {
5
+ "ecosystem": "npm",
6
+ "name": "@superdurable/connector-navinfo",
7
+ "version": "0.1.0"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "newLookupIPLocationStep",
12
+ "kind": "query",
13
+ "operationId": "lookupIPLocation",
14
+ "inputType": "LookupIPLocationInput",
15
+ "description": "Resolve one IP address to coarse province, city, and administrative code.",
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": "LookupIPLocationInput identifies one IPv4 address.",
47
+ "properties": {
48
+ "ipAddress": {
49
+ "description": "IPAddress is a literal address, not a hostname or CIDR range.",
50
+ "type": "string"
51
+ }
52
+ },
53
+ "required": [
54
+ "ipAddress"
55
+ ],
56
+ "type": "object"
57
+ }
58
+ }
59
+ ]
60
+ }
@@ -0,0 +1,117 @@
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(["ak"]);
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["ak"] != null && !(typeof fields["ak"] === "string")) throw new CredentialMaterialError("credential ak has an invalid type");
28
+ const credentials = {};
29
+ if (!fields["ak"]) throw new CredentialMaterialError("credential ak is required");
30
+ credentials.ak = new SecretString(fields["ak"] ?? "");
31
+ return credentials;
32
+ }
33
+ var LookupIPLocationInputSchema = z.strictObject({
34
+ "ipAddress": z.string()
35
+ });
36
+ var LookupIPLocationOutputSchema = z.strictObject({
37
+ "province": z.string(),
38
+ "city": z.string(),
39
+ "adcode": z.string()
40
+ });
41
+
42
+ // src/generated/definitions.ts
43
+ var ConnectorID = "navinfo";
44
+ var ProviderID = "navinfo";
45
+ var LookupIPLocationBranch = {
46
+ Found: "found",
47
+ ProviderRejected: "providerRejected",
48
+ InvalidResponse: "invalidResponse",
49
+ Defect: "defect"
50
+ };
51
+ var LookupIPLocationBranchFound = LookupIPLocationBranch.Found;
52
+ var LookupIPLocationBranchProviderRejected = LookupIPLocationBranch.ProviderRejected;
53
+ var LookupIPLocationBranchInvalidResponse = LookupIPLocationBranch.InvalidResponse;
54
+ var LookupIPLocationBranchDefect = LookupIPLocationBranch.Defect;
55
+ var LookupIPLocationDefinition = {
56
+ operation: { connectorId: ConnectorID, operationId: "lookupIPLocation" },
57
+ branches: [
58
+ { id: "found", description: "NavInfo returned coarse city location." },
59
+ { id: "providerRejected", description: "NavInfo rejected the AK, IP, quota, or permission.", optional: true },
60
+ { id: "invalidResponse", description: "NavInfo returned malformed or oversized location data.", optional: true },
61
+ { id: "defect", description: "The local AK or IP address is invalid.", optional: true }
62
+ ],
63
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async", executeRetry: { initialIntervalMs: 2e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 3, totalDurationMs: 3e5 } }
64
+ };
65
+ var LookupIPLocationMetadata = { 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
+ LookupIPLocationInputSchema,
103
+ LookupIPLocationOutputSchema,
104
+ ConnectorID,
105
+ ProviderID,
106
+ LookupIPLocationBranch,
107
+ LookupIPLocationBranchFound,
108
+ LookupIPLocationBranchProviderRejected,
109
+ LookupIPLocationBranchInvalidResponse,
110
+ LookupIPLocationBranchDefect,
111
+ LookupIPLocationDefinition,
112
+ LookupIPLocationMetadata,
113
+ Connection,
114
+ newConnection,
115
+ newConnectionWithOperations,
116
+ newProjectConnection
117
+ };
@@ -0,0 +1,75 @@
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 IP location 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 location response size in bytes as a positive integer. Blank uses the displayed default; increase only if NavInfo adds verified location fields. */
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 NavInfo REST API AK from https://lbs.navinfo.com/docs/webapi/ipcity.html > AK > 点击申请. Create a REST API key, copy its opaque AK, and paste here; blank prevents requests. */
19
+ ak: 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
+ /** LookupIPLocationInput identifies one IPv4 address. */
32
+ interface LookupIPLocationInput {
33
+ /** IPAddress is a literal address, not a hostname or CIDR range. */
34
+ "ipAddress": string;
35
+ }
36
+ /** LookupIPLocationOutput contains only coarse NavInfo location fields. */
37
+ interface LookupIPLocationOutput {
38
+ /** Province is the province or municipality name. */
39
+ "province": string;
40
+ /** City is the city name. */
41
+ "city": string;
42
+ /** Adcode is the city administrative code. */
43
+ "adcode": string;
44
+ }
45
+ /** Runtime validator for LookupIPLocationInput. */
46
+ declare const LookupIPLocationInputSchema: z.ZodObject<{
47
+ ipAddress: z.ZodString;
48
+ }, z.core.$strict>;
49
+ /** Runtime validator for LookupIPLocationOutput. */
50
+ declare const LookupIPLocationOutputSchema: z.ZodObject<{
51
+ province: z.ZodString;
52
+ city: z.ZodString;
53
+ adcode: z.ZodString;
54
+ }, z.core.$strict>;
55
+
56
+ /** Typed operations supplied by a client or mock. */
57
+ interface Operations {
58
+ /** Invoke lookupIPLocation through this connection. */
59
+ lookupIPLocation(): Query<LookupIPLocationInput, LookupIPLocationOutput>;
60
+ }
61
+ /** Named connector connection kept outside Flow state. */
62
+ declare class Connection<BoundOperations = Operations> {
63
+ /** Stable provider and connection name. */
64
+ readonly reference: ConnectionRef;
65
+ /** Bound provider operations. */
66
+ readonly operations: BoundOperations;
67
+ /** Validate a reference and bind operations. */
68
+ constructor(reference: ConnectionRef, operations: BoundOperations);
69
+ }
70
+ /** Bind a client to a named connection. */
71
+ declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
72
+ /** Bind scripted operations to a named connection. */
73
+ declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
74
+
75
+ export { Connection as C, type LookupIPLocationInput as L, type Operations as O, type LookupIPLocationOutput as a, type Config as b, type Credentials as c, ConfigSchema as d, CredentialMaterialError as e, type CredentialSource as f, LookupIPLocationInputSchema as g, LookupIPLocationOutputSchema as h, decodeCredentials as i, isCredentialMaterialError as j, newConnectionWithOperations as k, newConnection as n };
@@ -0,0 +1,90 @@
1
+ import { L as LookupIPLocationInput, a as LookupIPLocationOutput, C as Connection, O as Operations, b as Config, c as Credentials } from './connection-BLBWTMcE.js';
2
+ export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, g as LookupIPLocationInputSchema, h as LookupIPLocationOutputSchema, i as decodeCredentials, j as isCredentialMaterialError, n as newConnection, k as newConnectionWithOperations } from './connection-BLBWTMcE.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 = "navinfo";
11
+ /** Provider identity for named connections. */
12
+ declare const ProviderID = "navinfo";
13
+ /** Branch IDs for lookupIPLocation. */
14
+ declare const LookupIPLocationBranch: {
15
+ readonly Found: "found";
16
+ readonly ProviderRejected: "providerRejected";
17
+ readonly InvalidResponse: "invalidResponse";
18
+ readonly Defect: "defect";
19
+ };
20
+ /** NavInfo returned coarse city location. */
21
+ declare const LookupIPLocationBranchFound: "found";
22
+ /** NavInfo rejected the AK, IP, quota, or permission. */
23
+ declare const LookupIPLocationBranchProviderRejected: "providerRejected";
24
+ /** NavInfo returned malformed or oversized location data. */
25
+ declare const LookupIPLocationBranchInvalidResponse: "invalidResponse";
26
+ /** The local AK or IP address is invalid. */
27
+ declare const LookupIPLocationBranchDefect: "defect";
28
+ /** Manifest definition for lookupIPLocation. */
29
+ declare const LookupIPLocationDefinition: QueryDefinition;
30
+ /** Manifest metadata for lookupIPLocation. */
31
+ declare const LookupIPLocationMetadata: {
32
+ readonly kind: "query";
33
+ readonly idempotency: "none";
34
+ readonly authorization: "required";
35
+ };
36
+
37
+ /** Configuration for the lookupIPLocation connector Step. */
38
+ interface LookupIPLocationStepConfig<StepInput, OperationInput = LookupIPLocationInput, OperationOutput = LookupIPLocationOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
39
+ /** Named connection supplying this operation. */
40
+ connection: Connection<{
41
+ lookupIPLocation(): Query<OperationInput, OperationOutput>;
42
+ }>;
43
+ /** Name matching the bound connection. */
44
+ connectionName: string;
45
+ /** NavInfo returned coarse city location. */
46
+ found: StepTarget<QueryResult<OperationOutput>>;
47
+ /** NavInfo rejected the AK, IP, quota, or permission. */
48
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
49
+ /** NavInfo returned malformed or oversized location data. */
50
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
51
+ /** The local AK or IP address is invalid. */
52
+ defect?: StepTarget<QueryResult<OperationOutput>>;
53
+ }
54
+ /** Build the lookupIPLocation Step from a named connection. */
55
+ declare function newLookupIPLocationStep<StepInput, OperationInput = LookupIPLocationInput, OperationOutput = LookupIPLocationOutput>(configuration: LookupIPLocationStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
56
+
57
+ /** Open one named NavInfo 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 NavInfoClientOptions {
62
+ send?: (request: ProviderRequest) => Promise<ProviderResponse>;
63
+ }
64
+ /** Resolve NavInfo credentials for each city-level IP query. */
65
+ declare class NavInfoClient {
66
+ private readonly credentials;
67
+ private readonly timeoutMs;
68
+ private readonly maxResponseBytes;
69
+ private readonly send;
70
+ /** Validate settings without contacting NavInfo. */
71
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: NavInfoClientOptions);
72
+ /** Bind the city-level location Query. */ lookupIPLocation(): LookupIPLocationOperation;
73
+ /** Send one bounded request without exposing the query-string credential. */
74
+ request(call: Call, ipAddress: string): Promise<{
75
+ response?: ProviderResponse;
76
+ error?: 'credential' | 'transport' | 'tooLarge';
77
+ retryAfterMs: number;
78
+ ak?: string;
79
+ }>;
80
+ }
81
+ /** Look up coarse location for one IPv4 address. */
82
+ declare class LookupIPLocationOperation implements Query<LookupIPLocationInput, LookupIPLocationOutput> {
83
+ private readonly client;
84
+ /** Bind the provider client. */ constructor(client: NavInfoClient);
85
+ /** Return the generated Query definition. */ definition(): QueryDefinition;
86
+ /** Classify the provider response using the Go contract. */
87
+ invoke(call: Call, input: LookupIPLocationInput): Promise<QueryAttempt<LookupIPLocationOutput>>;
88
+ }
89
+
90
+ export { Config, Connection, ConnectorID, Credentials, LookupIPLocationBranch, LookupIPLocationBranchDefect, LookupIPLocationBranchFound, LookupIPLocationBranchInvalidResponse, LookupIPLocationBranchProviderRejected, LookupIPLocationDefinition, LookupIPLocationInput, LookupIPLocationMetadata, LookupIPLocationOutput, type LookupIPLocationStepConfig, NavInfoClient, type NavInfoClientOptions, ProviderID, newLookupIPLocationStep, newProjectConnection };
package/dist/index.js ADDED
@@ -0,0 +1,192 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ CredentialMaterialError,
6
+ LookupIPLocationBranch,
7
+ LookupIPLocationBranchDefect,
8
+ LookupIPLocationBranchFound,
9
+ LookupIPLocationBranchInvalidResponse,
10
+ LookupIPLocationBranchProviderRejected,
11
+ LookupIPLocationDefinition,
12
+ LookupIPLocationInputSchema,
13
+ LookupIPLocationMetadata,
14
+ LookupIPLocationOutputSchema,
15
+ ProviderID,
16
+ decodeCredentials,
17
+ isCredentialMaterialError,
18
+ newConnection,
19
+ newConnectionWithOperations,
20
+ newProjectConnection
21
+ } from "./chunk-4BVUWYSK.js";
22
+
23
+ // src/generated/steps.ts
24
+ import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
25
+ function newLookupIPLocationStep(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.lookupIPLocation(), 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 empty = { province: "", city: "", adcode: "" };
40
+ var NavInfoClient = class {
41
+ /** Validate settings without contacting NavInfo. */
42
+ constructor(config, credentials, options = {}) {
43
+ this.credentials = credentials;
44
+ if (!config || !credentials) throw new TypeError("NavInfo settings and credentials are required");
45
+ this.timeoutMs = config.timeoutMs || 1e4;
46
+ this.maxResponseBytes = config.maxResponseBytes || 1048576;
47
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0 || this.maxResponseBytes > 16 * 1024 * 1024) throw new TypeError("NavInfo limits are invalid");
48
+ this.send = options.send ?? sendProviderRequest;
49
+ }
50
+ credentials;
51
+ timeoutMs;
52
+ maxResponseBytes;
53
+ send;
54
+ /** Bind the city-level location Query. */
55
+ lookupIPLocation() {
56
+ return new LookupIPLocationOperation(this);
57
+ }
58
+ /** Send one bounded request without exposing the query-string credential. */
59
+ async request(call, ipAddress) {
60
+ let ak = "";
61
+ try {
62
+ const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
63
+ ak = resolved.ak instanceof SecretString ? resolved.ak.reveal() : "";
64
+ } catch {
65
+ return { error: "credential", retryAfterMs: 0 };
66
+ }
67
+ if (!ak || ak.length > 1024 || /[^\x21-\x7e]/.test(ak)) return { error: "credential", retryAfterMs: 0 };
68
+ const url = new URL("https://lbs.navinfo.com/open-api/position/v1/ip");
69
+ url.searchParams.set("ak", ak);
70
+ url.searchParams.set("ip", ipAddress);
71
+ const request = { url: url.toString(), method: "GET", headers: { Accept: "application/json" }, timeoutMs: this.timeoutMs, maxResponseBytes: this.maxResponseBytes, addressPolicy: "publicHTTPS", signal: call.context.cancellationSignal };
72
+ let response;
73
+ try {
74
+ response = await this.send(request);
75
+ } catch (error) {
76
+ if (error instanceof BodyTooLargeError && error.status !== void 0) return { response: { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() }, error: "tooLarge", retryAfterMs: 0, ak };
77
+ return { error: "transport", retryAfterMs: 0 };
78
+ }
79
+ return { response, error: response.body.length > this.maxResponseBytes ? "tooLarge" : void 0, retryAfterMs: parseRetryAfter(header(response.headers, "retry-after")), ak };
80
+ }
81
+ };
82
+ var LookupIPLocationOperation = class {
83
+ /** Bind the provider client. */
84
+ constructor(client) {
85
+ this.client = client;
86
+ }
87
+ client;
88
+ /** Return the generated Query definition. */
89
+ definition() {
90
+ return LookupIPLocationDefinition;
91
+ }
92
+ /** Classify the provider response using the Go contract. */
93
+ async invoke(call, input) {
94
+ const address = input?.ipAddress;
95
+ if (typeof address !== "string" || !isIPv4(address)) return branch("defect", "VALIDATION");
96
+ const exchange = await this.client.request(call, address);
97
+ if (exchange.error === "credential") return branch("defect", "AUTHENTICATION");
98
+ if (exchange.error === "transport" || !exchange.response) return retry("AVAILABILITY");
99
+ const { status, body } = exchange.response;
100
+ if (status === 429) return retry("RATE_LIMIT", exchange.retryAfterMs);
101
+ if (status === 408 || status >= 500) return retry("AVAILABILITY", exchange.retryAfterMs);
102
+ if (status !== 200) return branch("providerRejected", status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : "PROVIDER_REJECTION");
103
+ if (exchange.error === "tooLarge") return branch("invalidResponse", "RESPONSE_TOO_LARGE");
104
+ let wire;
105
+ try {
106
+ wire = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
107
+ } catch {
108
+ return branch("invalidResponse", "PROTOCOL");
109
+ }
110
+ if (!wire || typeof wire !== "object" || Array.isArray(wire)) return branch("invalidResponse", "PROTOCOL");
111
+ const record = wire;
112
+ if (!Number.isInteger(record.status)) return branch("invalidResponse", "PROTOCOL");
113
+ if (record.status === 1008 || record.status === 1010) return retry("RATE_LIMIT");
114
+ if (record.status !== 200) return branch("providerRejected", "PROVIDER_REJECTION");
115
+ if (!record.data || typeof record.data !== "object" || Array.isArray(record.data)) return branch("invalidResponse", "PROTOCOL");
116
+ const data = record.data;
117
+ const output = { province: data.prov, city: data.city, adcode: data.adcode };
118
+ if (Object.values(output).some((value) => typeof value !== "string") || String(output.province).length > 128 || String(output.city).length > 128 || String(output.adcode).length > 16 || Object.values(output).join("").split("").some((character) => character.charCodeAt(0) < 32) || Object.values(output).join("").includes(exchange.ak ?? "")) return branch("invalidResponse", "PROTOCOL");
119
+ return newQueryBranch("found", output);
120
+ }
121
+ };
122
+ function isIPv4(value) {
123
+ const octets = value.split(".");
124
+ return octets.length === 4 && octets.every((octet) => /^(0|[1-9]\d{0,2})$/.test(octet) && Number(octet) <= 255);
125
+ }
126
+ function header(headers, name) {
127
+ const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
128
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
129
+ }
130
+ function failure(kind) {
131
+ return { provider: "navinfo", operation: "lookupIPLocation", kind, message: "NavInfo IP location query failed" };
132
+ }
133
+ function branch(name, kind) {
134
+ return newQueryBranch(name, empty, {}, failure(kind));
135
+ }
136
+ function retry(kind, delay = 0) {
137
+ return newQueryRetry(failure(kind), delay);
138
+ }
139
+
140
+ // src/project.ts
141
+ function newProjectConnection2(project, connectionName) {
142
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
143
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "navinfo" && entry.connectionName === name);
144
+ if (!selected) throw new TypeError("NavInfo project connection is not configured");
145
+ const fields = selected.configuration;
146
+ const config = ConfigSchema.parse({ ...fields, ...fields.timeout !== void 0 ? { timeoutMs: parseDurationMilliseconds(fields.timeout) } : {} });
147
+ const credentials = {
148
+ async resolve(_call, signal) {
149
+ return decodeCredentials(await loadedProject.resolveCredential("navinfo", name, signal));
150
+ }
151
+ };
152
+ return new NavInfoClient(config, credentials);
153
+ });
154
+ }
155
+ function parseDurationMilliseconds(value) {
156
+ if (typeof value === "number") return Math.ceil(value / 1e6);
157
+ if (typeof value !== "string") throw new TypeError("timeout must be a duration");
158
+ let remaining = value;
159
+ let milliseconds = 0;
160
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
161
+ while (remaining) {
162
+ const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
163
+ if (!part) throw new TypeError("timeout must be a positive Go duration");
164
+ milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
165
+ remaining = remaining.slice(part[0].length);
166
+ }
167
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("timeout must resolve to positive whole milliseconds");
168
+ return milliseconds;
169
+ }
170
+ export {
171
+ ConfigSchema,
172
+ Connection,
173
+ ConnectorID,
174
+ CredentialMaterialError,
175
+ LookupIPLocationBranch,
176
+ LookupIPLocationBranchDefect,
177
+ LookupIPLocationBranchFound,
178
+ LookupIPLocationBranchInvalidResponse,
179
+ LookupIPLocationBranchProviderRejected,
180
+ LookupIPLocationDefinition,
181
+ LookupIPLocationInputSchema,
182
+ LookupIPLocationMetadata,
183
+ LookupIPLocationOutputSchema,
184
+ NavInfoClient,
185
+ ProviderID,
186
+ decodeCredentials,
187
+ isCredentialMaterialError,
188
+ newConnection,
189
+ newConnectionWithOperations,
190
+ newLookupIPLocationStep,
191
+ newProjectConnection2 as newProjectConnection
192
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,33 @@
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 LookupIPLocationInput, a as LookupIPLocationOutput } from './connection-BLBWTMcE.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for LookupIPLocationInput in scripted cases. */
7
+ declare const emptyLookupIPLocationInput: LookupIPLocationInput;
8
+ /** Go zero value for LookupIPLocationOutput in scripted cases. */
9
+ declare const emptyLookupIPLocationOutput: LookupIPLocationOutput;
10
+ /** Script the found branch. */
11
+ declare function lookupIPLocationFound(value: LookupIPLocationOutput, failure?: Failure): Case<LookupIPLocationOutput>;
12
+ /** Script the providerRejected branch. */
13
+ declare function lookupIPLocationProviderRejected(value: LookupIPLocationOutput, failure?: Failure): Case<LookupIPLocationOutput>;
14
+ /** Script the invalidResponse branch. */
15
+ declare function lookupIPLocationInvalidResponse(value: LookupIPLocationOutput, failure?: Failure): Case<LookupIPLocationOutput>;
16
+ /** Script the defect branch. */
17
+ declare function lookupIPLocationDefect(value: LookupIPLocationOutput, failure?: Failure): Case<LookupIPLocationOutput>;
18
+ /** Script a safe retry of lookupIPLocation. */
19
+ declare function lookupIPLocationRetry(failure: Failure, retryAfterMs?: number): Case<LookupIPLocationOutput>;
20
+ /** Manifest scenario beijing for lookupIPLocation. */
21
+ declare function lookupIPLocationBeijing(): Case<LookupIPLocationOutput>;
22
+ /** Default lookupIPLocation scenario. */
23
+ declare function lookupIPLocationDefault(): Case<LookupIPLocationOutput>;
24
+ /** Scripted operations and manifest defaults for this connector. */
25
+ declare class GeneratedMock implements Operations {
26
+ #private;
27
+ constructor(connectionName: string);
28
+ connection(): Connection;
29
+ lookupIPLocation(): MockQuery<LookupIPLocationInput, LookupIPLocationOutput>;
30
+ assertNoFailures(): void;
31
+ }
32
+
33
+ export { GeneratedMock, emptyLookupIPLocationInput, emptyLookupIPLocationOutput, lookupIPLocationBeijing, lookupIPLocationDefault, lookupIPLocationDefect, lookupIPLocationFound, lookupIPLocationInvalidResponse, lookupIPLocationProviderRejected, lookupIPLocationRetry };
package/dist/mock.js ADDED
@@ -0,0 +1,69 @@
1
+ import {
2
+ LookupIPLocationDefinition,
3
+ LookupIPLocationInputSchema,
4
+ LookupIPLocationOutputSchema,
5
+ ProviderID,
6
+ newConnectionWithOperations
7
+ } from "./chunk-4BVUWYSK.js";
8
+
9
+ // src/generated/mock.ts
10
+ import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
11
+ var emptyLookupIPLocationInput = LookupIPLocationInputSchema.parse({
12
+ "ipAddress": ""
13
+ });
14
+ var emptyLookupIPLocationOutput = LookupIPLocationOutputSchema.parse({
15
+ "province": "",
16
+ "city": "",
17
+ "adcode": ""
18
+ });
19
+ function lookupIPLocationFound(value, failure) {
20
+ return branchCase("found", value, failure);
21
+ }
22
+ function lookupIPLocationProviderRejected(value, failure) {
23
+ return branchCase("providerRejected", value, failure);
24
+ }
25
+ function lookupIPLocationInvalidResponse(value, failure) {
26
+ return branchCase("invalidResponse", value, failure);
27
+ }
28
+ function lookupIPLocationDefect(value, failure) {
29
+ return branchCase("defect", value, failure);
30
+ }
31
+ function lookupIPLocationRetry(failure, retryAfterMs = 0) {
32
+ return retryCase(failure, retryAfterMs);
33
+ }
34
+ function lookupIPLocationBeijing() {
35
+ const value = LookupIPLocationOutputSchema.parse({ "adcode": "110000", "city": "\u5317\u4EAC\u5E02", "province": "\u5317\u4EAC\u5E02" });
36
+ return branchCase("found", value);
37
+ }
38
+ function lookupIPLocationDefault() {
39
+ return lookupIPLocationBeijing();
40
+ }
41
+ var GeneratedMock = class {
42
+ #lookupIPLocation;
43
+ #connection;
44
+ constructor(connectionName) {
45
+ this.#lookupIPLocation = newQuery(LookupIPLocationDefinition).default(lookupIPLocationDefault());
46
+ this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
47
+ }
48
+ connection() {
49
+ return this.#connection;
50
+ }
51
+ lookupIPLocation() {
52
+ return this.#lookupIPLocation;
53
+ }
54
+ assertNoFailures() {
55
+ this.#lookupIPLocation.assertNoFailures();
56
+ }
57
+ };
58
+ export {
59
+ GeneratedMock,
60
+ emptyLookupIPLocationInput,
61
+ emptyLookupIPLocationOutput,
62
+ lookupIPLocationBeijing,
63
+ lookupIPLocationDefault,
64
+ lookupIPLocationDefect,
65
+ lookupIPLocationFound,
66
+ lookupIPLocationInvalidResponse,
67
+ lookupIPLocationProviderRejected,
68
+ lookupIPLocationRetry
69
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@superdurable/connector-navinfo",
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": "navinfo connector for Dex TypeScript applications",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/superdurable/dex-connectors-library.git",
9
+ "directory": "connectors/navinfo/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
+ }