@superdurable/connector-baishancloud 0.0.0-stage → 0.1.1

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
+ # BaishanCloud 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
+ Read one CDN domain's status, type, and CNAME without exposing origin configuration.
4
+
5
+ Install `@superdurable/connector-baishancloud` 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 `describeDomain` resolves credentials for each call. Local conformance tests replay the Go provider scenarios; live provider authorization has not been verified.
@@ -0,0 +1,65 @@
1
+ {
2
+ "connectorId": "baishancloud",
3
+ "releaseTag": "connectors/baishancloud/go/v0.1.0",
4
+ "package": {
5
+ "ecosystem": "npm",
6
+ "name": "@superdurable/connector-baishancloud",
7
+ "version": "0.1.1"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "newDescribeDomainStep",
12
+ "kind": "query",
13
+ "operationId": "describeDomain",
14
+ "inputType": "DescribeDomainInput",
15
+ "description": "Describe one CDN domain by name, returning only ID, name, type, status, and CNAME.",
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": "notFound",
30
+ "field": "notFound",
31
+ "optional": true
32
+ },
33
+ {
34
+ "id": "providerRejected",
35
+ "field": "providerRejected",
36
+ "optional": true
37
+ },
38
+ {
39
+ "id": "invalidResponse",
40
+ "field": "invalidResponse",
41
+ "optional": true
42
+ },
43
+ {
44
+ "id": "defect",
45
+ "field": "defect",
46
+ "optional": true
47
+ }
48
+ ],
49
+ "inputSchema": {
50
+ "additionalProperties": false,
51
+ "description": "DescribeDomainInput identifies one CDN domain by name.",
52
+ "properties": {
53
+ "domain": {
54
+ "description": "Domain is an ASCII DNS name, without protocol or path.",
55
+ "type": "string"
56
+ }
57
+ },
58
+ "required": [
59
+ "domain"
60
+ ],
61
+ "type": "object"
62
+ }
63
+ }
64
+ ]
65
+ }
@@ -0,0 +1,124 @@
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(["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["token"] != null && !(typeof fields["token"] === "string")) throw new CredentialMaterialError("credential token has an invalid type");
29
+ const credentials = {};
30
+ if (!fields["token"]) throw new CredentialMaterialError("credential token is required");
31
+ credentials.token = new SecretString(fields["token"] ?? "");
32
+ return credentials;
33
+ }
34
+ var DescribeDomainInputSchema = z.strictObject({
35
+ "domain": z.string()
36
+ });
37
+ var DomainDetailSchema = z.strictObject({
38
+ "id": z.string(),
39
+ "domain": z.string(),
40
+ "type": z.string(),
41
+ "status": z.string(),
42
+ "cname": z.string()
43
+ });
44
+
45
+ // src/generated/definitions.ts
46
+ var ConnectorID = "baishancloud";
47
+ var ProviderID = "baishancloud";
48
+ var DescribeDomainBranch = {
49
+ Found: "found",
50
+ NotFound: "notFound",
51
+ ProviderRejected: "providerRejected",
52
+ InvalidResponse: "invalidResponse",
53
+ Defect: "defect"
54
+ };
55
+ var DescribeDomainBranchFound = DescribeDomainBranch.Found;
56
+ var DescribeDomainBranchNotFound = DescribeDomainBranch.NotFound;
57
+ var DescribeDomainBranchProviderRejected = DescribeDomainBranch.ProviderRejected;
58
+ var DescribeDomainBranchInvalidResponse = DescribeDomainBranch.InvalidResponse;
59
+ var DescribeDomainBranchDefect = DescribeDomainBranch.Defect;
60
+ var DescribeDomainDefinition = {
61
+ operation: { connectorId: ConnectorID, operationId: "describeDomain" },
62
+ branches: [
63
+ { id: "found", description: "BaishanCloud returned the requested CDN domain." },
64
+ { id: "notFound", description: "The authorized response has no matching domain.", optional: true },
65
+ { id: "providerRejected", description: "BaishanCloud rejected the token, access, or domain.", optional: true },
66
+ { id: "invalidResponse", description: "BaishanCloud returned malformed or oversized data.", optional: true },
67
+ { id: "defect", description: "Local connection configuration or input is invalid.", optional: true }
68
+ ],
69
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
70
+ };
71
+ var DescribeDomainMetadata = { kind: "query", idempotency: "none", authorization: "required" };
72
+
73
+ // src/generated/connection.ts
74
+ import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
75
+ var Connection = class {
76
+ /** Stable provider and connection name. */
77
+ reference;
78
+ /** Bound provider operations. */
79
+ operations;
80
+ /** Validate a reference and bind operations. */
81
+ constructor(reference, operations) {
82
+ this.reference = ConnectionRefSchema.parse(reference);
83
+ if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
84
+ if (!operations) throw new TypeError("connector operations are required");
85
+ this.operations = operations;
86
+ }
87
+ };
88
+ function newConnection(client, reference) {
89
+ if (!client) throw new TypeError("connector client is required");
90
+ return new Connection(reference, client);
91
+ }
92
+ function newConnectionWithOperations(operations, reference) {
93
+ return new Connection(reference, operations);
94
+ }
95
+ function newProjectConnection(project, connectionName, createClient) {
96
+ if (!project) throw new TypeError("loaded project is required");
97
+ const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
98
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
99
+ if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
100
+ return newConnection(createClient(project, connectionName), reference);
101
+ }
102
+
103
+ export {
104
+ ConfigSchema,
105
+ CredentialMaterialError,
106
+ isCredentialMaterialError,
107
+ decodeCredentials,
108
+ DescribeDomainInputSchema,
109
+ DomainDetailSchema,
110
+ ConnectorID,
111
+ ProviderID,
112
+ DescribeDomainBranch,
113
+ DescribeDomainBranchFound,
114
+ DescribeDomainBranchNotFound,
115
+ DescribeDomainBranchProviderRejected,
116
+ DescribeDomainBranchInvalidResponse,
117
+ DescribeDomainBranchDefect,
118
+ DescribeDomainDefinition,
119
+ DescribeDomainMetadata,
120
+ Connection,
121
+ newConnection,
122
+ newConnectionWithOperations,
123
+ newProjectConnection
124
+ };
@@ -0,0 +1,84 @@
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
+ /** HTTPS origin of the BaishanCloud CDN API. Leave blank for the displayed public endpoint; override only for a trusted test server or approved proxy. */
7
+ baseUrl?: string;
8
+ /** Maximum duration of one domain query 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 domain-detail response size in bytes as a positive integer. Leave blank for the displayed default; raise only when provider configuration data makes the response unusually large. */
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 CDN API token requested from your BaishanCloud account team via https://cdn.portal.baishan.com/track/document/api/1/1139. Copy the exact token without a token= prefix; blank prevents requests. The provider requires it in an HTTPS query parameter. */
22
+ token: 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
+ /** DescribeDomainInput identifies one CDN domain by name. */
35
+ interface DescribeDomainInput {
36
+ /** Domain is an ASCII DNS name, without protocol or path. */
37
+ "domain": string;
38
+ }
39
+ /** DomainDetail is a CDN domain without its origin or cache configuration. */
40
+ interface DomainDetail {
41
+ /** ID is the BaishanCloud domain identifier. */
42
+ "id": string;
43
+ /** Domain is the CDN domain name. */
44
+ "domain": string;
45
+ /** Type is the acceleration service type. */
46
+ "type": string;
47
+ /** Status is the provider's service status. */
48
+ "status": string;
49
+ /** CNAME is the DNS alias assigned by BaishanCloud. */
50
+ "cname": string;
51
+ }
52
+ /** Runtime validator for DescribeDomainInput. */
53
+ declare const DescribeDomainInputSchema: z.ZodObject<{
54
+ domain: z.ZodString;
55
+ }, z.core.$strict>;
56
+ /** Runtime validator for DomainDetail. */
57
+ declare const DomainDetailSchema: z.ZodObject<{
58
+ id: z.ZodString;
59
+ domain: z.ZodString;
60
+ type: z.ZodString;
61
+ status: z.ZodString;
62
+ cname: z.ZodString;
63
+ }, z.core.$strict>;
64
+
65
+ /** Typed operations supplied by a client or mock. */
66
+ interface Operations {
67
+ /** Invoke describeDomain through this connection. */
68
+ describeDomain(): Query<DescribeDomainInput, DomainDetail>;
69
+ }
70
+ /** Named connector connection kept outside Flow state. */
71
+ declare class Connection<BoundOperations = Operations> {
72
+ /** Stable provider and connection name. */
73
+ readonly reference: ConnectionRef;
74
+ /** Bound provider operations. */
75
+ readonly operations: BoundOperations;
76
+ /** Validate a reference and bind operations. */
77
+ constructor(reference: ConnectionRef, operations: BoundOperations);
78
+ }
79
+ /** Bind a client to a named connection. */
80
+ declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
81
+ /** Bind scripted operations to a named connection. */
82
+ declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
83
+
84
+ export { Connection as C, type DescribeDomainInput as D, type Operations as O, type DomainDetail as a, type Config as b, type Credentials as c, ConfigSchema as d, CredentialMaterialError as e, type CredentialSource as f, DescribeDomainInputSchema as g, DomainDetailSchema as h, decodeCredentials as i, isCredentialMaterialError as j, newConnectionWithOperations as k, newConnection as n };
@@ -0,0 +1,95 @@
1
+ import { D as DescribeDomainInput, a as DomainDetail, C as Connection, O as Operations, b as Config, c as Credentials } from './connection-CI25PuSh.js';
2
+ export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, g as DescribeDomainInputSchema, h as DomainDetailSchema, i as decodeCredentials, j as isCredentialMaterialError, n as newConnection, k as newConnectionWithOperations } from './connection-CI25PuSh.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 = "baishancloud";
11
+ /** Provider identity for named connections. */
12
+ declare const ProviderID = "baishancloud";
13
+ /** Branch IDs for describeDomain. */
14
+ declare const DescribeDomainBranch: {
15
+ readonly Found: "found";
16
+ readonly NotFound: "notFound";
17
+ readonly ProviderRejected: "providerRejected";
18
+ readonly InvalidResponse: "invalidResponse";
19
+ readonly Defect: "defect";
20
+ };
21
+ /** BaishanCloud returned the requested CDN domain. */
22
+ declare const DescribeDomainBranchFound: "found";
23
+ /** The authorized response has no matching domain. */
24
+ declare const DescribeDomainBranchNotFound: "notFound";
25
+ /** BaishanCloud rejected the token, access, or domain. */
26
+ declare const DescribeDomainBranchProviderRejected: "providerRejected";
27
+ /** BaishanCloud returned malformed or oversized data. */
28
+ declare const DescribeDomainBranchInvalidResponse: "invalidResponse";
29
+ /** Local connection configuration or input is invalid. */
30
+ declare const DescribeDomainBranchDefect: "defect";
31
+ /** Manifest definition for describeDomain. */
32
+ declare const DescribeDomainDefinition: QueryDefinition;
33
+ /** Manifest metadata for describeDomain. */
34
+ declare const DescribeDomainMetadata: {
35
+ readonly kind: "query";
36
+ readonly idempotency: "none";
37
+ readonly authorization: "required";
38
+ };
39
+
40
+ /** Configuration for the describeDomain connector Step. */
41
+ interface DescribeDomainStepConfig<StepInput, OperationInput = DescribeDomainInput, OperationOutput = DomainDetail> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
42
+ /** Named connection supplying this operation. */
43
+ connection: Connection<{
44
+ describeDomain(): Query<OperationInput, OperationOutput>;
45
+ }>;
46
+ /** Name matching the bound connection. */
47
+ connectionName: string;
48
+ /** BaishanCloud returned the requested CDN domain. */
49
+ found: StepTarget<QueryResult<OperationOutput>>;
50
+ /** The authorized response has no matching domain. */
51
+ notFound?: StepTarget<QueryResult<OperationOutput>>;
52
+ /** BaishanCloud rejected the token, access, or domain. */
53
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
54
+ /** BaishanCloud returned malformed or oversized data. */
55
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
56
+ /** Local connection configuration or input is invalid. */
57
+ defect?: StepTarget<QueryResult<OperationOutput>>;
58
+ }
59
+ /** Build the describeDomain Step from a named connection. */
60
+ declare function newDescribeDomainStep<StepInput, OperationInput = DescribeDomainInput, OperationOutput = DomainDetail>(configuration: DescribeDomainStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
61
+
62
+ /** Open one named BaishanCloud connection from Dex project configuration. */
63
+ declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
64
+
65
+ /** Optional HTTP transport for local provider tests. */
66
+ interface BaishanCloudClientOptions {
67
+ send?: (request: ProviderRequest) => Promise<ProviderResponse>;
68
+ }
69
+ /** Resolve BaishanCloud credentials for each CDN domain query. */
70
+ declare class BaishanCloudClient {
71
+ private readonly credentials;
72
+ private readonly baseURL;
73
+ private readonly timeoutMs;
74
+ private readonly maxResponseBytes;
75
+ private readonly send;
76
+ /** Validate connection settings without contacting BaishanCloud. */
77
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: BaishanCloudClientOptions);
78
+ /** Bind the CDN domain detail Query. */ describeDomain(): DescribeDomainOperation;
79
+ /** Send one bounded CDN domain request. */
80
+ getDomain(call: Call, domain: string): Promise<{
81
+ response?: ProviderResponse;
82
+ error?: 'credential' | 'transport' | 'tooLarge';
83
+ retryAfterMs: number;
84
+ }>;
85
+ }
86
+ /** Describe one CDN domain without origin or cache configuration. */
87
+ declare class DescribeDomainOperation implements Query<DescribeDomainInput, DomainDetail> {
88
+ private readonly client;
89
+ /** Bind the provider client. */ constructor(client: BaishanCloudClient);
90
+ /** Return the generated Query definition. */ definition(): QueryDefinition;
91
+ /** Classify one provider response using the Go connector contract. */
92
+ invoke(call: Call, input: DescribeDomainInput): Promise<QueryAttempt<DomainDetail>>;
93
+ }
94
+
95
+ export { BaishanCloudClient, type BaishanCloudClientOptions, Config, Connection, ConnectorID, Credentials, DescribeDomainBranch, DescribeDomainBranchDefect, DescribeDomainBranchFound, DescribeDomainBranchInvalidResponse, DescribeDomainBranchNotFound, DescribeDomainBranchProviderRejected, DescribeDomainDefinition, DescribeDomainInput, DescribeDomainMetadata, type DescribeDomainStepConfig, DomainDetail, ProviderID, newDescribeDomainStep, newProjectConnection };
package/dist/index.js ADDED
@@ -0,0 +1,220 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ CredentialMaterialError,
6
+ DescribeDomainBranch,
7
+ DescribeDomainBranchDefect,
8
+ DescribeDomainBranchFound,
9
+ DescribeDomainBranchInvalidResponse,
10
+ DescribeDomainBranchNotFound,
11
+ DescribeDomainBranchProviderRejected,
12
+ DescribeDomainDefinition,
13
+ DescribeDomainInputSchema,
14
+ DescribeDomainMetadata,
15
+ DomainDetailSchema,
16
+ ProviderID,
17
+ decodeCredentials,
18
+ isCredentialMaterialError,
19
+ newConnection,
20
+ newConnectionWithOperations,
21
+ newProjectConnection
22
+ } from "./chunk-ZTMAXOOR.js";
23
+
24
+ // src/generated/steps.ts
25
+ import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
26
+ function newDescribeDomainStep(configuration) {
27
+ const { connection, connectionName, found, notFound, 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.describeDomain(), connection: connection.reference, branches: [
30
+ goToBranch("found", found),
31
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
32
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
33
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
34
+ ...defect ? [goToBranch("defect", defect)] : []
35
+ ] });
36
+ }
37
+
38
+ // src/client.ts
39
+ import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
40
+ import { BodyTooLargeError, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
41
+ var BaishanCloudClient = class {
42
+ /** Validate connection settings without contacting BaishanCloud. */
43
+ constructor(config, credentials, options = {}) {
44
+ this.credentials = credentials;
45
+ if (!config || !credentials) throw new TypeError("BaishanCloud configuration and credentials are required");
46
+ this.baseURL = validateBaseURL(config.baseUrl || "https://cdn.api.baishan.com");
47
+ this.timeoutMs = config.timeoutMs || 15e3;
48
+ this.maxResponseBytes = config.maxResponseBytes || 1048576;
49
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("BaishanCloud request limits are invalid");
50
+ this.send = options.send ?? sendProviderRequest;
51
+ }
52
+ credentials;
53
+ baseURL;
54
+ timeoutMs;
55
+ maxResponseBytes;
56
+ send;
57
+ /** Bind the CDN domain detail Query. */
58
+ describeDomain() {
59
+ return new DescribeDomainOperation(this);
60
+ }
61
+ /** Send one bounded CDN domain request. */
62
+ async getDomain(call, domain) {
63
+ let token = "";
64
+ try {
65
+ const credential = await this.credentials.resolve(call, call.context.cancellationSignal);
66
+ token = credential.token instanceof SecretString ? credential.token.reveal() : "";
67
+ } catch {
68
+ return { error: "credential", retryAfterMs: 0 };
69
+ }
70
+ if (!token || token.length > 512 || /[^\x21-\x7e]/.test(token)) return { error: "credential", retryAfterMs: 0 };
71
+ const query = new URLSearchParams({ domains: domain, token });
72
+ const request = { url: this.baseURL + "/v2/domain?" + query.toString(), method: "GET", headers: { Accept: "application/json" }, timeoutMs: this.timeoutMs, maxResponseBytes: this.maxResponseBytes, addressPolicy: this.baseURL.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP", signal: call.context.cancellationSignal };
73
+ let response;
74
+ try {
75
+ response = await this.send(request);
76
+ } catch (error) {
77
+ if (error instanceof BodyTooLargeError && error.status !== void 0) {
78
+ const headers = error.headers ?? {};
79
+ return { response: { status: error.status, headers, body: new Uint8Array() }, error: "tooLarge", retryAfterMs: retryDelay(headers) };
80
+ }
81
+ return { error: "transport", retryAfterMs: 0 };
82
+ }
83
+ return { response, error: response.body.length > this.maxResponseBytes ? "tooLarge" : void 0, retryAfterMs: retryDelay(response.headers) };
84
+ }
85
+ };
86
+ var DescribeDomainOperation = class {
87
+ /** Bind the provider client. */
88
+ constructor(client) {
89
+ this.client = client;
90
+ }
91
+ client;
92
+ /** Return the generated Query definition. */
93
+ definition() {
94
+ return DescribeDomainDefinition;
95
+ }
96
+ /** Classify one provider response using the Go connector contract. */
97
+ async invoke(call, input) {
98
+ if (!input || typeof input.domain !== "string") return branch("defect", "VALIDATION");
99
+ const domain = input.domain.replace(/^\p{White_Space}+|\p{White_Space}+$/gu, "").toLowerCase();
100
+ if (domain.length > 253 || !/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/.test(domain)) return branch("defect", "VALIDATION");
101
+ const exchange = await this.client.getDomain(call, domain);
102
+ if (exchange.error === "credential") return branch("defect", "AUTHENTICATION");
103
+ if (exchange.error === "transport" || !exchange.response) return retry("AVAILABILITY");
104
+ const { status, body } = exchange.response;
105
+ if (status === 429) return retry("RATE_LIMIT", exchange.retryAfterMs);
106
+ if (status === 408 || status >= 500) return retry("AVAILABILITY", exchange.retryAfterMs);
107
+ if (exchange.error === "tooLarge") return branch("invalidResponse", "RESPONSE_TOO_LARGE");
108
+ if (status !== 200) return branch("providerRejected", status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : status === 400 || status === 404 ? "VALIDATION" : "PROVIDER_REJECTION");
109
+ try {
110
+ return decodeDomain(body, domain);
111
+ } catch {
112
+ return branch("invalidResponse", "PROTOCOL");
113
+ }
114
+ }
115
+ };
116
+ function isRecord(value) {
117
+ return value !== null && typeof value === "object" && !Array.isArray(value);
118
+ }
119
+ function decodeDomain(body, domain) {
120
+ const wire = JSON.parse(
121
+ new TextDecoder("utf-8", { ignoreBOM: true }).decode(body),
122
+ (_key, value, context) => {
123
+ if (isRecord(value)) return Object.fromEntries(Object.entries(value).map(([name, item]) => [name.toLowerCase().replace(/ſ/g, "s"), item]));
124
+ if (typeof value !== "number" || !context?.source) return value;
125
+ if (!/^-?\d+$/.test(context.source)) return NaN;
126
+ const exact = BigInt(context.source);
127
+ return exact < -(1n << 63n) || exact >= 1n << 63n ? NaN : value;
128
+ }
129
+ );
130
+ if (!isRecord(wire) || typeof wire.code !== "number" || !Number.isInteger(wire.code)) throw new TypeError("Invalid domain response code");
131
+ if (wire.data != null && !Array.isArray(wire.data)) throw new TypeError("Invalid domain list");
132
+ const details = (wire.data ?? []).map(readDetail);
133
+ if (wire.code !== 0) return branch("providerRejected", "PROVIDER_REJECTION");
134
+ if (wire.data == null || details.length > 1) throw new TypeError("Invalid domain list");
135
+ if (details.length === 0) return branch("notFound", "NOT_FOUND");
136
+ const detail = details[0];
137
+ if (!detail.id || detail.domain.toLowerCase().replace(/ſ/g, "s") !== domain || !detail.type || !detail.status || !detail.cname) throw new TypeError("Invalid domain detail");
138
+ return newQueryBranch("found", detail);
139
+ }
140
+ function readDetail(row) {
141
+ const item = row ?? {};
142
+ if (!isRecord(item)) throw new TypeError("Invalid domain detail");
143
+ function field(name) {
144
+ const value = item[name] ?? "";
145
+ if (typeof value !== "string") throw new TypeError("Invalid domain field");
146
+ return value;
147
+ }
148
+ return { id: field("id"), domain: field("domain"), type: field("type"), status: field("status"), cname: field("cname") };
149
+ }
150
+ function retryDelay(headers) {
151
+ return parseRetryAfter(header(headers, "retry-after")) || parseRetryAfter(header(headers, "x-retry-after"));
152
+ }
153
+ function header(headers, name) {
154
+ const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
155
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
156
+ }
157
+ function failure(kind) {
158
+ return { provider: "baishancloud", operation: "describeDomain", kind, message: "BaishanCloud domain query failed" };
159
+ }
160
+ function branch(name, kind) {
161
+ return newQueryBranch(name, { id: "", domain: "", type: "", status: "", cname: "" }, {}, failure(kind));
162
+ }
163
+ function retry(kind, delay = 0) {
164
+ return newQueryRetry(failure(kind), delay);
165
+ }
166
+
167
+ // src/project.ts
168
+ function newProjectConnection2(project, connectionName) {
169
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
170
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "baishancloud" && entry.connectionName === name);
171
+ if (!selected) throw new TypeError("BaishanCloud project connection is not configured");
172
+ const fields = selected.configuration;
173
+ const config = ConfigSchema.parse({ ...fields, ...fields.timeout !== void 0 ? { timeoutMs: parseDurationMilliseconds(fields.timeout) } : {} });
174
+ const credentials = {
175
+ async resolve(_call, signal) {
176
+ return decodeCredentials(await loadedProject.resolveCredential("baishancloud", name, signal));
177
+ }
178
+ };
179
+ return new BaishanCloudClient(config, credentials);
180
+ });
181
+ }
182
+ function parseDurationMilliseconds(value) {
183
+ if (typeof value === "number") return Math.ceil(value / 1e6);
184
+ if (typeof value !== "string") throw new TypeError("timeout must be a duration");
185
+ let remaining = value;
186
+ let milliseconds = 0;
187
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
188
+ while (remaining) {
189
+ const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
190
+ if (!part) throw new TypeError("timeout must be a positive Go duration");
191
+ milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
192
+ remaining = remaining.slice(part[0].length);
193
+ }
194
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("timeout must resolve to positive whole milliseconds");
195
+ return milliseconds;
196
+ }
197
+ export {
198
+ BaishanCloudClient,
199
+ ConfigSchema,
200
+ Connection,
201
+ ConnectorID,
202
+ CredentialMaterialError,
203
+ DescribeDomainBranch,
204
+ DescribeDomainBranchDefect,
205
+ DescribeDomainBranchFound,
206
+ DescribeDomainBranchInvalidResponse,
207
+ DescribeDomainBranchNotFound,
208
+ DescribeDomainBranchProviderRejected,
209
+ DescribeDomainDefinition,
210
+ DescribeDomainInputSchema,
211
+ DescribeDomainMetadata,
212
+ DomainDetailSchema,
213
+ ProviderID,
214
+ decodeCredentials,
215
+ isCredentialMaterialError,
216
+ newConnection,
217
+ newConnectionWithOperations,
218
+ newDescribeDomainStep,
219
+ newProjectConnection2 as newProjectConnection
220
+ };
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, D as DescribeDomainInput, a as DomainDetail } from './connection-CI25PuSh.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for DescribeDomainInput in scripted cases. */
7
+ declare const emptyDescribeDomainInput: DescribeDomainInput;
8
+ /** Go zero value for DomainDetail in scripted cases. */
9
+ declare const emptyDomainDetail: DomainDetail;
10
+ /** Script the found branch. */
11
+ declare function describeDomainFound(value: DomainDetail, failure?: Failure): Case<DomainDetail>;
12
+ /** Script the notFound branch. */
13
+ declare function describeDomainNotFound(value: DomainDetail, failure?: Failure): Case<DomainDetail>;
14
+ /** Script the providerRejected branch. */
15
+ declare function describeDomainProviderRejected(value: DomainDetail, failure?: Failure): Case<DomainDetail>;
16
+ /** Script the invalidResponse branch. */
17
+ declare function describeDomainInvalidResponse(value: DomainDetail, failure?: Failure): Case<DomainDetail>;
18
+ /** Script the defect branch. */
19
+ declare function describeDomainDefect(value: DomainDetail, failure?: Failure): Case<DomainDetail>;
20
+ /** Script a safe retry of describeDomain. */
21
+ declare function describeDomainRetry(failure: Failure, retryAfterMs?: number): Case<DomainDetail>;
22
+ /** Manifest scenario foundDomain for describeDomain. */
23
+ declare function describeDomainFoundDomain(): Case<DomainDetail>;
24
+ /** Default describeDomain scenario. */
25
+ declare function describeDomainDefault(): Case<DomainDetail>;
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
+ describeDomain(): MockQuery<DescribeDomainInput, DomainDetail>;
32
+ assertNoFailures(): void;
33
+ }
34
+
35
+ export { GeneratedMock, describeDomainDefault, describeDomainDefect, describeDomainFound, describeDomainFoundDomain, describeDomainInvalidResponse, describeDomainNotFound, describeDomainProviderRejected, describeDomainRetry, emptyDescribeDomainInput, emptyDomainDetail };
package/dist/mock.js ADDED
@@ -0,0 +1,75 @@
1
+ import {
2
+ DescribeDomainDefinition,
3
+ DescribeDomainInputSchema,
4
+ DomainDetailSchema,
5
+ ProviderID,
6
+ newConnectionWithOperations
7
+ } from "./chunk-ZTMAXOOR.js";
8
+
9
+ // src/generated/mock.ts
10
+ import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
11
+ var emptyDescribeDomainInput = DescribeDomainInputSchema.parse({
12
+ "domain": ""
13
+ });
14
+ var emptyDomainDetail = DomainDetailSchema.parse({
15
+ "id": "",
16
+ "domain": "",
17
+ "type": "",
18
+ "status": "",
19
+ "cname": ""
20
+ });
21
+ function describeDomainFound(value, failure) {
22
+ return branchCase("found", value, failure);
23
+ }
24
+ function describeDomainNotFound(value, failure) {
25
+ return branchCase("notFound", value, failure);
26
+ }
27
+ function describeDomainProviderRejected(value, failure) {
28
+ return branchCase("providerRejected", value, failure);
29
+ }
30
+ function describeDomainInvalidResponse(value, failure) {
31
+ return branchCase("invalidResponse", value, failure);
32
+ }
33
+ function describeDomainDefect(value, failure) {
34
+ return branchCase("defect", value, failure);
35
+ }
36
+ function describeDomainRetry(failure, retryAfterMs = 0) {
37
+ return retryCase(failure, retryAfterMs);
38
+ }
39
+ function describeDomainFoundDomain() {
40
+ const value = DomainDetailSchema.parse({ "cname": "cdn.example.com.qingcdn.com.", "domain": "cdn.example.com", "id": "31335", "status": "serving", "type": "download" });
41
+ return branchCase("found", value);
42
+ }
43
+ function describeDomainDefault() {
44
+ return describeDomainFoundDomain();
45
+ }
46
+ var GeneratedMock = class {
47
+ #describeDomain;
48
+ #connection;
49
+ constructor(connectionName) {
50
+ this.#describeDomain = newQuery(DescribeDomainDefinition).default(describeDomainDefault());
51
+ this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
52
+ }
53
+ connection() {
54
+ return this.#connection;
55
+ }
56
+ describeDomain() {
57
+ return this.#describeDomain;
58
+ }
59
+ assertNoFailures() {
60
+ this.#describeDomain.assertNoFailures();
61
+ }
62
+ };
63
+ export {
64
+ GeneratedMock,
65
+ describeDomainDefault,
66
+ describeDomainDefect,
67
+ describeDomainFound,
68
+ describeDomainFoundDomain,
69
+ describeDomainInvalidResponse,
70
+ describeDomainNotFound,
71
+ describeDomainProviderRejected,
72
+ describeDomainRetry,
73
+ emptyDescribeDomainInput,
74
+ emptyDomainDetail
75
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@superdurable/connector-baishancloud",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "license": "MIT",
5
+ "description": "baishancloud connector for Dex TypeScript applications",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/superdurable/dex-connectors-library.git",
9
+ "directory": "connectors/baishancloud/typescript"
10
+ },
11
+ "type": "module",
12
+ "engines": {
13
+ "node": "^22.0.0 || ^24.0.0"
14
+ },
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ },
22
+ "./mock": {
23
+ "types": "./dist/mock.d.ts",
24
+ "import": "./dist/mock.js"
25
+ },
26
+ "./dex-connector.json": "./dex-connector.json"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE",
32
+ "dex-connector.json"
33
+ ],
34
+ "scripts": {
35
+ "prepack": "npm run build",
36
+ "build": "tsup src/index.ts src/mock.ts --format esm --dts --clean",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint src test examples",
39
+ "test": "vitest run --exclude test/integration/**",
40
+ "test:integration": "vitest run test/integration/*.integration.test.ts",
41
+ "example:worker": "tsx examples/basic/worker.ts",
42
+ "example:start": "tsx examples/basic/start.ts",
43
+ "check": "npm run typecheck && npm run lint && npm test && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@superdurable/connectors-sdk": "0.1.1",
47
+ "@superdurable/dex": ">=1.28.0",
48
+ "zod": "^4.1.0"
49
+ },
50
+ "devDependencies": {
51
+ "@eslint/js": "^9.0.0",
52
+ "@types/node": "^22.0.0",
53
+ "eslint": "^9.0.0",
54
+ "tsup": "^8.0.0",
55
+ "tsx": "^4.23.15",
56
+ "typescript": "^5.9.0",
57
+ "typescript-eslint": "^8.0.0",
58
+ "vitest": "^3.0.0",
59
+ "yaml": "^2.9.1"
60
+ }
61
+ }