@superdurable/connector-apispace 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 +21 -0
- package/README.md +6 -2
- package/dex-connector.json +60 -0
- package/dist/chunk-QFOWL4LT.js +120 -0
- package/dist/connection-BCwHhHO-.d.ts +84 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +237 -0
- package/dist/mock.d.ts +33 -0
- package/dist/mock.js +72 -0
- package/package.json +59 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# APISpace TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-apispace` provides the read-only `getCurrentWeather` Dex Step. It reads one city's current observations from the [APISpace Weather Forecast Query API](https://www.apispace.com/eolink/api/456456/apiDocument).
|
|
4
|
+
|
|
5
|
+
Use the [runnable Flow and Worker](examples/current-weather/) with a static `apispace` connection. In Dex Web Connections, subscribe to Weather Forecast Query (product 456456), then open Console > Access Control and enter the API key in the protected `api_token` field. The city `areaCode` comes from the product's Domestic Cities attachment. The endpoint, timeout, and response limit have manifest defaults.
|
|
6
|
+
|
|
7
|
+
The checked-in conformance scenarios replay Go-recorded requests and outcomes. The integration test exercises a real Dex Worker and Client with a local provider that returns 503 before succeeding. Real APISpace authorization and current weather remain unverified without a user-controlled subscription and API key.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "apispace",
|
|
3
|
+
"releaseTag": "connectors/apispace/go/v0.1.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-apispace",
|
|
7
|
+
"version": "0.1.1"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newGetCurrentWeatherStep",
|
|
12
|
+
"kind": "query",
|
|
13
|
+
"operationId": "getCurrentWeather",
|
|
14
|
+
"inputType": "GetCurrentWeatherInput",
|
|
15
|
+
"description": "Read current conditions and provider update time for one city ID.",
|
|
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": "GetCurrentWeatherInput selects one city by the provider's documented area code.",
|
|
47
|
+
"properties": {
|
|
48
|
+
"areaCode": {
|
|
49
|
+
"description": "AreaCode is a city ID from the APISpace weather product's city list.",
|
|
50
|
+
"type": "string"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"required": [
|
|
54
|
+
"areaCode"
|
|
55
|
+
],
|
|
56
|
+
"type": "object"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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(["api_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["api_token"] != null && !(typeof fields["api_token"] === "string")) throw new CredentialMaterialError("credential api_token has an invalid type");
|
|
29
|
+
const credentials = {};
|
|
30
|
+
if (!fields["api_token"]) throw new CredentialMaterialError("credential api_token is required");
|
|
31
|
+
credentials.apiToken = new SecretString(fields["api_token"] ?? "");
|
|
32
|
+
return credentials;
|
|
33
|
+
}
|
|
34
|
+
var GetCurrentWeatherInputSchema = z.strictObject({
|
|
35
|
+
"areaCode": z.string()
|
|
36
|
+
});
|
|
37
|
+
var CurrentWeatherSchema = z.strictObject({
|
|
38
|
+
"city": z.string(),
|
|
39
|
+
"condition": z.string(),
|
|
40
|
+
"temperatureCelsius": z.number(),
|
|
41
|
+
"humidityPercent": z.number().int(),
|
|
42
|
+
"updatedAtBeijing": z.string()
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// src/generated/definitions.ts
|
|
46
|
+
var ConnectorID = "apispace";
|
|
47
|
+
var ProviderID = "apispace";
|
|
48
|
+
var GetCurrentWeatherBranch = {
|
|
49
|
+
Found: "found",
|
|
50
|
+
ProviderRejected: "providerRejected",
|
|
51
|
+
InvalidResponse: "invalidResponse",
|
|
52
|
+
Defect: "defect"
|
|
53
|
+
};
|
|
54
|
+
var GetCurrentWeatherBranchFound = GetCurrentWeatherBranch.Found;
|
|
55
|
+
var GetCurrentWeatherBranchProviderRejected = GetCurrentWeatherBranch.ProviderRejected;
|
|
56
|
+
var GetCurrentWeatherBranchInvalidResponse = GetCurrentWeatherBranch.InvalidResponse;
|
|
57
|
+
var GetCurrentWeatherBranchDefect = GetCurrentWeatherBranch.Defect;
|
|
58
|
+
var GetCurrentWeatherDefinition = {
|
|
59
|
+
operation: { connectorId: ConnectorID, operationId: "getCurrentWeather" },
|
|
60
|
+
branches: [
|
|
61
|
+
{ id: "found", description: "APISpace returned current conditions for the city." },
|
|
62
|
+
{ id: "providerRejected", description: "APISpace rejected the key, plan, quota, or city.", optional: true },
|
|
63
|
+
{ id: "invalidResponse", description: "APISpace returned malformed or oversized weather data.", optional: true },
|
|
64
|
+
{ id: "defect", description: "Local connection configuration, token, or city ID is invalid.", optional: true }
|
|
65
|
+
],
|
|
66
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
67
|
+
};
|
|
68
|
+
var GetCurrentWeatherMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
69
|
+
|
|
70
|
+
// src/generated/connection.ts
|
|
71
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
72
|
+
var Connection = class {
|
|
73
|
+
/** Stable provider and connection name. */
|
|
74
|
+
reference;
|
|
75
|
+
/** Bound provider operations. */
|
|
76
|
+
operations;
|
|
77
|
+
/** Validate a reference and bind operations. */
|
|
78
|
+
constructor(reference, operations) {
|
|
79
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
80
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
81
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
82
|
+
this.operations = operations;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function newConnection(client, reference) {
|
|
86
|
+
if (!client) throw new TypeError("connector client is required");
|
|
87
|
+
return new Connection(reference, client);
|
|
88
|
+
}
|
|
89
|
+
function newConnectionWithOperations(operations, reference) {
|
|
90
|
+
return new Connection(reference, operations);
|
|
91
|
+
}
|
|
92
|
+
function newProjectConnection(project, connectionName, createClient) {
|
|
93
|
+
if (!project) throw new TypeError("loaded project is required");
|
|
94
|
+
const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
95
|
+
const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
|
|
96
|
+
if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
|
|
97
|
+
return newConnection(createClient(project, connectionName), reference);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
ConfigSchema,
|
|
102
|
+
CredentialMaterialError,
|
|
103
|
+
isCredentialMaterialError,
|
|
104
|
+
decodeCredentials,
|
|
105
|
+
GetCurrentWeatherInputSchema,
|
|
106
|
+
CurrentWeatherSchema,
|
|
107
|
+
ConnectorID,
|
|
108
|
+
ProviderID,
|
|
109
|
+
GetCurrentWeatherBranch,
|
|
110
|
+
GetCurrentWeatherBranchFound,
|
|
111
|
+
GetCurrentWeatherBranchProviderRejected,
|
|
112
|
+
GetCurrentWeatherBranchInvalidResponse,
|
|
113
|
+
GetCurrentWeatherBranchDefect,
|
|
114
|
+
GetCurrentWeatherDefinition,
|
|
115
|
+
GetCurrentWeatherMetadata,
|
|
116
|
+
Connection,
|
|
117
|
+
newConnection,
|
|
118
|
+
newConnectionWithOperations,
|
|
119
|
+
newProjectConnection
|
|
120
|
+
};
|
|
@@ -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 APISpace gateway. Leave blank for the displayed production endpoint; override only for a trusted test server or provider-approved proxy. */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Maximum duration of one weather request as a positive Go duration such as 30s or 1m. Leave blank for the displayed default; raise it only when the provider responds slowly from your network. Runtime value in milliseconds. */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** Maximum weather response size in bytes as a positive integer. Leave blank for the displayed default; raise only for a documented larger provider response. */
|
|
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 API key from https://www.apispace.com/ > Console > Access Control. Copy the exact token without a prefix; blank prevents requests. The key is sent only in X-APISpace-Token and must be updated after rotation. */
|
|
22
|
+
apiToken: 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
|
+
/** GetCurrentWeatherInput selects one city by the provider's documented area code. */
|
|
35
|
+
interface GetCurrentWeatherInput {
|
|
36
|
+
/** AreaCode is a city ID from the APISpace weather product's city list. */
|
|
37
|
+
"areaCode": string;
|
|
38
|
+
}
|
|
39
|
+
/** CurrentWeather contains selected public observations for one city. */
|
|
40
|
+
interface CurrentWeather {
|
|
41
|
+
/** City is the provider's city display name. */
|
|
42
|
+
"city": string;
|
|
43
|
+
/** Condition is the current weather description. */
|
|
44
|
+
"condition": string;
|
|
45
|
+
/** TemperatureCelsius is the current air temperature in degrees Celsius. */
|
|
46
|
+
"temperatureCelsius": number;
|
|
47
|
+
/** HumidityPercent is the relative humidity from 0 to 100 percent. */
|
|
48
|
+
"humidityPercent": number;
|
|
49
|
+
/** UpdatedAtBeijing is the provider update time in Beijing local time. */
|
|
50
|
+
"updatedAtBeijing": string;
|
|
51
|
+
}
|
|
52
|
+
/** Runtime validator for GetCurrentWeatherInput. */
|
|
53
|
+
declare const GetCurrentWeatherInputSchema: z.ZodObject<{
|
|
54
|
+
areaCode: z.ZodString;
|
|
55
|
+
}, z.core.$strict>;
|
|
56
|
+
/** Runtime validator for CurrentWeather. */
|
|
57
|
+
declare const CurrentWeatherSchema: z.ZodObject<{
|
|
58
|
+
city: z.ZodString;
|
|
59
|
+
condition: z.ZodString;
|
|
60
|
+
temperatureCelsius: z.ZodNumber;
|
|
61
|
+
humidityPercent: z.ZodNumber;
|
|
62
|
+
updatedAtBeijing: z.ZodString;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
|
|
65
|
+
/** Typed operations supplied by a client or mock. */
|
|
66
|
+
interface Operations {
|
|
67
|
+
/** Invoke getCurrentWeather through this connection. */
|
|
68
|
+
getCurrentWeather(): Query<GetCurrentWeatherInput, CurrentWeather>;
|
|
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 { type CurrentWeather as C, type GetCurrentWeatherInput as G, type Operations as O, Connection as a, type Credentials as b, type Config as c, ConfigSchema as d, CredentialMaterialError as e, type CredentialSource as f, CurrentWeatherSchema as g, GetCurrentWeatherInputSchema as h, decodeCredentials as i, isCredentialMaterialError as j, newConnectionWithOperations as k, newConnection as n };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { G as GetCurrentWeatherInput, C as CurrentWeather, a as Connection, O as Operations, b as Credentials, c as Config } from './connection-BCwHhHO-.js';
|
|
2
|
+
export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, g as CurrentWeatherSchema, h as GetCurrentWeatherInputSchema, i as decodeCredentials, j as isCredentialMaterialError, n as newConnection, k as newConnectionWithOperations } from './connection-BCwHhHO-.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 = "apispace";
|
|
11
|
+
/** Provider identity for named connections. */
|
|
12
|
+
declare const ProviderID = "apispace";
|
|
13
|
+
/** Branch IDs for getCurrentWeather. */
|
|
14
|
+
declare const GetCurrentWeatherBranch: {
|
|
15
|
+
readonly Found: "found";
|
|
16
|
+
readonly ProviderRejected: "providerRejected";
|
|
17
|
+
readonly InvalidResponse: "invalidResponse";
|
|
18
|
+
readonly Defect: "defect";
|
|
19
|
+
};
|
|
20
|
+
/** APISpace returned current conditions for the city. */
|
|
21
|
+
declare const GetCurrentWeatherBranchFound: "found";
|
|
22
|
+
/** APISpace rejected the key, plan, quota, or city. */
|
|
23
|
+
declare const GetCurrentWeatherBranchProviderRejected: "providerRejected";
|
|
24
|
+
/** APISpace returned malformed or oversized weather data. */
|
|
25
|
+
declare const GetCurrentWeatherBranchInvalidResponse: "invalidResponse";
|
|
26
|
+
/** Local connection configuration, token, or city ID is invalid. */
|
|
27
|
+
declare const GetCurrentWeatherBranchDefect: "defect";
|
|
28
|
+
/** Manifest definition for getCurrentWeather. */
|
|
29
|
+
declare const GetCurrentWeatherDefinition: QueryDefinition;
|
|
30
|
+
/** Manifest metadata for getCurrentWeather. */
|
|
31
|
+
declare const GetCurrentWeatherMetadata: {
|
|
32
|
+
readonly kind: "query";
|
|
33
|
+
readonly idempotency: "none";
|
|
34
|
+
readonly authorization: "required";
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Configuration for the getCurrentWeather connector Step. */
|
|
38
|
+
interface GetCurrentWeatherStepConfig<StepInput, OperationInput = GetCurrentWeatherInput, OperationOutput = CurrentWeather> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
39
|
+
/** Named connection supplying this operation. */
|
|
40
|
+
connection: Connection<{
|
|
41
|
+
getCurrentWeather(): Query<OperationInput, OperationOutput>;
|
|
42
|
+
}>;
|
|
43
|
+
/** Name matching the bound connection. */
|
|
44
|
+
connectionName: string;
|
|
45
|
+
/** APISpace returned current conditions for the city. */
|
|
46
|
+
found: StepTarget<QueryResult<OperationOutput>>;
|
|
47
|
+
/** APISpace rejected the key, plan, quota, or city. */
|
|
48
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
49
|
+
/** APISpace returned malformed or oversized weather data. */
|
|
50
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
51
|
+
/** Local connection configuration, token, or city ID is invalid. */
|
|
52
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
53
|
+
}
|
|
54
|
+
/** Build the getCurrentWeather Step from a named connection. */
|
|
55
|
+
declare function newGetCurrentWeatherStep<StepInput, OperationInput = GetCurrentWeatherInput, OperationOutput = CurrentWeather>(configuration: GetCurrentWeatherStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
56
|
+
|
|
57
|
+
/** Open one named APISpace connection from Dex project configuration. */
|
|
58
|
+
declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
|
|
59
|
+
|
|
60
|
+
/** Send one weather request through a caller-owned transport. */
|
|
61
|
+
type WeatherRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
62
|
+
/** Optional transport dependency for provider tests. */
|
|
63
|
+
interface APISpaceClientOptions {
|
|
64
|
+
/** Request sender; production uses the Connector SDK transport. */
|
|
65
|
+
send?: WeatherRequestSender;
|
|
66
|
+
}
|
|
67
|
+
/** Resolve APISpace credentials for each weather query. */
|
|
68
|
+
declare class APISpaceClient {
|
|
69
|
+
readonly baseUrl: string;
|
|
70
|
+
readonly timeoutMs: number;
|
|
71
|
+
readonly maxResponseBytes: number;
|
|
72
|
+
readonly credentials: CredentialProvider<Credentials>;
|
|
73
|
+
readonly send: WeatherRequestSender;
|
|
74
|
+
/** Validate configuration without contacting APISpace. */
|
|
75
|
+
constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: APISpaceClientOptions);
|
|
76
|
+
/** Bind the current-weather Query. */
|
|
77
|
+
getCurrentWeather(): GetCurrentWeatherOperation;
|
|
78
|
+
}
|
|
79
|
+
/** Read current weather for one APISpace city area code. */
|
|
80
|
+
declare class GetCurrentWeatherOperation implements Query<GetCurrentWeatherInput, CurrentWeather> {
|
|
81
|
+
private readonly client;
|
|
82
|
+
/** Bind an authenticated APISpace client. */
|
|
83
|
+
constructor(client: APISpaceClient);
|
|
84
|
+
/** Return the stable generated Query contract. */
|
|
85
|
+
definition(): QueryDefinition;
|
|
86
|
+
/** Send and classify one current-weather request. */
|
|
87
|
+
invoke(call: Call, input: GetCurrentWeatherInput): Promise<QueryAttempt<CurrentWeather>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { APISpaceClient, type APISpaceClientOptions, Config, Connection, ConnectorID, Credentials, CurrentWeather, GetCurrentWeatherBranch, GetCurrentWeatherBranchDefect, GetCurrentWeatherBranchFound, GetCurrentWeatherBranchInvalidResponse, GetCurrentWeatherBranchProviderRejected, GetCurrentWeatherDefinition, GetCurrentWeatherInput, GetCurrentWeatherMetadata, GetCurrentWeatherOperation, type GetCurrentWeatherStepConfig, ProviderID, type WeatherRequestSender, newGetCurrentWeatherStep, newProjectConnection };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigSchema,
|
|
3
|
+
Connection,
|
|
4
|
+
ConnectorID,
|
|
5
|
+
CredentialMaterialError,
|
|
6
|
+
CurrentWeatherSchema,
|
|
7
|
+
GetCurrentWeatherBranch,
|
|
8
|
+
GetCurrentWeatherBranchDefect,
|
|
9
|
+
GetCurrentWeatherBranchFound,
|
|
10
|
+
GetCurrentWeatherBranchInvalidResponse,
|
|
11
|
+
GetCurrentWeatherBranchProviderRejected,
|
|
12
|
+
GetCurrentWeatherDefinition,
|
|
13
|
+
GetCurrentWeatherInputSchema,
|
|
14
|
+
GetCurrentWeatherMetadata,
|
|
15
|
+
ProviderID,
|
|
16
|
+
decodeCredentials,
|
|
17
|
+
isCredentialMaterialError,
|
|
18
|
+
newConnection,
|
|
19
|
+
newConnectionWithOperations,
|
|
20
|
+
newProjectConnection
|
|
21
|
+
} from "./chunk-QFOWL4LT.js";
|
|
22
|
+
|
|
23
|
+
// src/generated/steps.ts
|
|
24
|
+
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
25
|
+
function newGetCurrentWeatherStep(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.getCurrentWeather(), 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/project.ts
|
|
37
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
38
|
+
import { z } from "zod";
|
|
39
|
+
|
|
40
|
+
// src/client.ts
|
|
41
|
+
import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
42
|
+
import { BodyTooLargeError, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
43
|
+
var emptyWeather = { city: "", condition: "", temperatureCelsius: 0, humidityPercent: 0, updatedAtBeijing: "" };
|
|
44
|
+
var APISpaceClient = class {
|
|
45
|
+
baseUrl;
|
|
46
|
+
timeoutMs;
|
|
47
|
+
maxResponseBytes;
|
|
48
|
+
credentials;
|
|
49
|
+
send;
|
|
50
|
+
/** Validate configuration without contacting APISpace. */
|
|
51
|
+
constructor(config, credentials, options = {}) {
|
|
52
|
+
if (!config || !credentials) throw new TypeError("APISpace configuration and credential source are required");
|
|
53
|
+
const baseUrl = validateBaseURL(config.baseUrl || "https://eolink.o.apispace.com");
|
|
54
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
55
|
+
this.timeoutMs = config.timeoutMs ?? 15e3;
|
|
56
|
+
this.maxResponseBytes = config.maxResponseBytes ?? 1048576;
|
|
57
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("APISpace timeout and response limit must be positive");
|
|
58
|
+
this.credentials = credentials;
|
|
59
|
+
this.send = options.send ?? sendProviderRequest;
|
|
60
|
+
}
|
|
61
|
+
/** Bind the current-weather Query. */
|
|
62
|
+
getCurrentWeather() {
|
|
63
|
+
return new GetCurrentWeatherOperation(this);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var GetCurrentWeatherOperation = class {
|
|
67
|
+
/** Bind an authenticated APISpace client. */
|
|
68
|
+
constructor(client) {
|
|
69
|
+
this.client = client;
|
|
70
|
+
}
|
|
71
|
+
client;
|
|
72
|
+
/** Return the stable generated Query contract. */
|
|
73
|
+
definition() {
|
|
74
|
+
return GetCurrentWeatherDefinition;
|
|
75
|
+
}
|
|
76
|
+
/** Send and classify one current-weather request. */
|
|
77
|
+
async invoke(call, input) {
|
|
78
|
+
if (!/^[A-Za-z0-9]{1,32}$/.test(input.areaCode ?? "")) return branch("defect", "VALIDATION", "APISpace area code must be 1 to 32 ASCII letters or digits");
|
|
79
|
+
let credentials;
|
|
80
|
+
try {
|
|
81
|
+
credentials = await this.client.credentials.resolve(call, call.context.cancellationSignal);
|
|
82
|
+
} catch {
|
|
83
|
+
return branch("defect", "AUTHENTICATION", "APISpace API token is unavailable or invalid");
|
|
84
|
+
}
|
|
85
|
+
const token = credentials.apiToken instanceof SecretString ? credentials.apiToken.reveal() : "";
|
|
86
|
+
if (!isValidAPIToken(token)) return branch("defect", "AUTHENTICATION", "APISpace API token is unavailable or invalid");
|
|
87
|
+
let response;
|
|
88
|
+
try {
|
|
89
|
+
response = await this.client.send({
|
|
90
|
+
url: `${this.client.baseUrl}/456456/weather/v001/now?areacode=${encodeURIComponent(input.areaCode)}`,
|
|
91
|
+
method: "GET",
|
|
92
|
+
headers: { Accept: "application/json", "Content-Type": "application/json", "Authorization-Type": "apikey", "X-APISpace-Token": token },
|
|
93
|
+
timeoutMs: this.client.timeoutMs,
|
|
94
|
+
maxResponseBytes: this.client.maxResponseBytes,
|
|
95
|
+
addressPolicy: this.client.baseUrl === "https://eolink.o.apispace.com" ? "publicHTTPS" : "privateNetworkHTTP",
|
|
96
|
+
signal: call.context.cancellationSignal
|
|
97
|
+
});
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0) {
|
|
100
|
+
if (error.status === 429 || error.status === 413 || error.status === 408 || error.status >= 500) {
|
|
101
|
+
const early2 = classifyEarlyStatus(error.status, error.headers ?? {});
|
|
102
|
+
if (early2) return early2;
|
|
103
|
+
}
|
|
104
|
+
return branch("invalidResponse", "RESPONSE_TOO_LARGE", "APISpace response exceeded the configured limit");
|
|
105
|
+
}
|
|
106
|
+
return retry("AVAILABILITY", "APISpace weather request failed");
|
|
107
|
+
}
|
|
108
|
+
const early = classifyEarlyStatus(response.status, response.headers);
|
|
109
|
+
if (early) return early;
|
|
110
|
+
if (response.body.length > this.client.maxResponseBytes) return branch("invalidResponse", "RESPONSE_TOO_LARGE", "APISpace response exceeded the configured limit");
|
|
111
|
+
if (response.status !== 200) {
|
|
112
|
+
const kind = response.status === 401 ? "AUTHENTICATION" : response.status === 403 || response.status === 416 ? "AUTHORIZATION" : response.status === 400 || response.status === 404 ? "VALIDATION" : "PROVIDER_REJECTION";
|
|
113
|
+
return branch("providerRejected", kind, `APISpace rejected weather query with HTTP ${response.status}`);
|
|
114
|
+
}
|
|
115
|
+
let wire;
|
|
116
|
+
try {
|
|
117
|
+
wire = fieldsByName(JSON.parse(new TextDecoder().decode(response.body), readProviderNumber));
|
|
118
|
+
} catch {
|
|
119
|
+
return invalidWeather();
|
|
120
|
+
}
|
|
121
|
+
if (!wire || typeof wire.status !== "bigint") return invalidWeather();
|
|
122
|
+
const result = wire.result == null ? {} : fieldsByName(wire.result);
|
|
123
|
+
if (!result) return invalidWeather();
|
|
124
|
+
const location = result.location == null ? {} : fieldsByName(result.location);
|
|
125
|
+
const observation = result.realtime == null ? {} : fieldsByName(result.realtime);
|
|
126
|
+
if (!location || !observation) return invalidWeather();
|
|
127
|
+
const { name: city } = location;
|
|
128
|
+
const { text: condition, temp: temperature, rh: humidity } = observation;
|
|
129
|
+
const updated = result.last_update;
|
|
130
|
+
if ([city, condition, updated].some((value) => value != null && typeof value !== "string") || temperature != null && (typeof temperature !== "number" || !Number.isFinite(temperature)) || humidity != null && typeof humidity !== "bigint") return invalidWeather();
|
|
131
|
+
if (wire.status !== 0n) {
|
|
132
|
+
return branch("providerRejected", "PROVIDER_REJECTION", `APISpace rejected weather query with status ${wire.status}`);
|
|
133
|
+
}
|
|
134
|
+
if (typeof city !== "string" || !city || typeof condition !== "string" || !condition || typeof temperature !== "number" || typeof humidity !== "bigint" || humidity < 0n || humidity > 100n || typeof updated !== "string" || !updated) return invalidWeather();
|
|
135
|
+
return newQueryBranch("found", {
|
|
136
|
+
city,
|
|
137
|
+
condition,
|
|
138
|
+
temperatureCelsius: temperature,
|
|
139
|
+
humidityPercent: Number(humidity),
|
|
140
|
+
updatedAtBeijing: updated
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
function classifyEarlyStatus(status, headers) {
|
|
145
|
+
const retryAfterHeader = Object.entries(headers).find(([name]) => name.toLowerCase() === "retry-after")?.[1];
|
|
146
|
+
const retryAfterMs = parseRetryAfter(Array.isArray(retryAfterHeader) ? retryAfterHeader[0] ?? "" : retryAfterHeader ?? "");
|
|
147
|
+
if (status === 429 || status === 413) return retry("RATE_LIMIT", "APISpace rate limited weather requests", retryAfterMs);
|
|
148
|
+
if (status === 408 || status >= 500) return retry("AVAILABILITY", "APISpace weather is temporarily unavailable", retryAfterMs);
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
function invalidWeather() {
|
|
152
|
+
return branch("invalidResponse", "PROTOCOL", "APISpace returned an invalid weather response");
|
|
153
|
+
}
|
|
154
|
+
function fieldsByName(value) {
|
|
155
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
156
|
+
return Object.fromEntries(Object.entries(value).map(([name, field]) => [name.toLowerCase(), field]));
|
|
157
|
+
}
|
|
158
|
+
function readProviderNumber(key, value, context) {
|
|
159
|
+
if (!["status", "rh"].includes(key.toLowerCase()) || typeof value !== "number") return value;
|
|
160
|
+
const source = context?.source;
|
|
161
|
+
if (source === void 0) return Number.isSafeInteger(value) ? BigInt(value) : false;
|
|
162
|
+
if (!/^-?\d+$/.test(source) || source.length > 20) return false;
|
|
163
|
+
const integer = BigInt(source);
|
|
164
|
+
return integer >= -(1n << 63n) && integer < 1n << 63n ? integer : false;
|
|
165
|
+
}
|
|
166
|
+
function isValidAPIToken(value) {
|
|
167
|
+
return value.length > 0 && value.length <= 2048 && /^[!-~]+$/.test(value);
|
|
168
|
+
}
|
|
169
|
+
function failure(kind, message) {
|
|
170
|
+
return { provider: "apispace", operation: "getCurrentWeather", kind, message };
|
|
171
|
+
}
|
|
172
|
+
function branch(id, kind, message) {
|
|
173
|
+
return newQueryBranch(id, emptyWeather, {}, failure(kind, message));
|
|
174
|
+
}
|
|
175
|
+
function retry(kind, message, delayMs = 0) {
|
|
176
|
+
return newQueryRetry(failure(kind, message), delayMs);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/project.ts
|
|
180
|
+
function newProjectConnection2(project, connectionName) {
|
|
181
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
182
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "apispace" && entry.connectionName === name);
|
|
183
|
+
if (!selected) throw new TypeError("APISpace project connection is not configured");
|
|
184
|
+
const fields = z.strictObject({ baseUrl: z.string().optional(), timeout: z.union([z.string(), z.number().int()]).optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
|
|
185
|
+
const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
|
|
186
|
+
const config = {
|
|
187
|
+
...fields.baseUrl !== void 0 ? { baseUrl: fields.baseUrl } : {},
|
|
188
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
189
|
+
...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
|
|
190
|
+
};
|
|
191
|
+
const credentials = {
|
|
192
|
+
async resolve(_call, signal) {
|
|
193
|
+
const privateFields = await loadedProject.resolveCredential("apispace", name, signal);
|
|
194
|
+
if (typeof privateFields.api_token !== "string") throw new TypeError("APISpace API token is unavailable");
|
|
195
|
+
return { apiToken: new SecretString2(privateFields.api_token) };
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return new APISpaceClient(config, credentials);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function parseDurationMilliseconds(value) {
|
|
202
|
+
let remaining = value;
|
|
203
|
+
let milliseconds = 0;
|
|
204
|
+
const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
|
|
205
|
+
while (remaining) {
|
|
206
|
+
const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
207
|
+
if (!part) throw new TypeError("APISpace timeout must be a positive Go duration");
|
|
208
|
+
milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
|
|
209
|
+
remaining = remaining.slice(part[0].length);
|
|
210
|
+
}
|
|
211
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("APISpace timeout must resolve to positive whole milliseconds");
|
|
212
|
+
return milliseconds;
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
APISpaceClient,
|
|
216
|
+
ConfigSchema,
|
|
217
|
+
Connection,
|
|
218
|
+
ConnectorID,
|
|
219
|
+
CredentialMaterialError,
|
|
220
|
+
CurrentWeatherSchema,
|
|
221
|
+
GetCurrentWeatherBranch,
|
|
222
|
+
GetCurrentWeatherBranchDefect,
|
|
223
|
+
GetCurrentWeatherBranchFound,
|
|
224
|
+
GetCurrentWeatherBranchInvalidResponse,
|
|
225
|
+
GetCurrentWeatherBranchProviderRejected,
|
|
226
|
+
GetCurrentWeatherDefinition,
|
|
227
|
+
GetCurrentWeatherInputSchema,
|
|
228
|
+
GetCurrentWeatherMetadata,
|
|
229
|
+
GetCurrentWeatherOperation,
|
|
230
|
+
ProviderID,
|
|
231
|
+
decodeCredentials,
|
|
232
|
+
isCredentialMaterialError,
|
|
233
|
+
newConnection,
|
|
234
|
+
newConnectionWithOperations,
|
|
235
|
+
newGetCurrentWeatherStep,
|
|
236
|
+
newProjectConnection2 as newProjectConnection
|
|
237
|
+
};
|
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, a as Connection, G as GetCurrentWeatherInput, C as CurrentWeather } from './connection-BCwHhHO-.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** Go zero value for GetCurrentWeatherInput in scripted cases. */
|
|
7
|
+
declare const emptyGetCurrentWeatherInput: GetCurrentWeatherInput;
|
|
8
|
+
/** Go zero value for CurrentWeather in scripted cases. */
|
|
9
|
+
declare const emptyCurrentWeather: CurrentWeather;
|
|
10
|
+
/** Script the found branch. */
|
|
11
|
+
declare function getCurrentWeatherFound(value: CurrentWeather, failure?: Failure): Case<CurrentWeather>;
|
|
12
|
+
/** Script the providerRejected branch. */
|
|
13
|
+
declare function getCurrentWeatherProviderRejected(value: CurrentWeather, failure?: Failure): Case<CurrentWeather>;
|
|
14
|
+
/** Script the invalidResponse branch. */
|
|
15
|
+
declare function getCurrentWeatherInvalidResponse(value: CurrentWeather, failure?: Failure): Case<CurrentWeather>;
|
|
16
|
+
/** Script the defect branch. */
|
|
17
|
+
declare function getCurrentWeatherDefect(value: CurrentWeather, failure?: Failure): Case<CurrentWeather>;
|
|
18
|
+
/** Script a safe retry of getCurrentWeather. */
|
|
19
|
+
declare function getCurrentWeatherRetry(failure: Failure, retryAfterMs?: number): Case<CurrentWeather>;
|
|
20
|
+
/** Manifest scenario currentWeather for getCurrentWeather. */
|
|
21
|
+
declare function getCurrentWeatherCurrentWeather(): Case<CurrentWeather>;
|
|
22
|
+
/** Default getCurrentWeather scenario. */
|
|
23
|
+
declare function getCurrentWeatherDefault(): Case<CurrentWeather>;
|
|
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
|
+
getCurrentWeather(): MockQuery<GetCurrentWeatherInput, CurrentWeather>;
|
|
30
|
+
assertNoFailures(): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { GeneratedMock, GeneratedMock as Mock, emptyCurrentWeather, emptyGetCurrentWeatherInput, getCurrentWeatherCurrentWeather, getCurrentWeatherDefault, getCurrentWeatherDefect, getCurrentWeatherFound, getCurrentWeatherInvalidResponse, getCurrentWeatherProviderRejected, getCurrentWeatherRetry };
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CurrentWeatherSchema,
|
|
3
|
+
GetCurrentWeatherDefinition,
|
|
4
|
+
GetCurrentWeatherInputSchema,
|
|
5
|
+
ProviderID,
|
|
6
|
+
newConnectionWithOperations
|
|
7
|
+
} from "./chunk-QFOWL4LT.js";
|
|
8
|
+
|
|
9
|
+
// src/generated/mock.ts
|
|
10
|
+
import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
|
11
|
+
var emptyGetCurrentWeatherInput = GetCurrentWeatherInputSchema.parse({
|
|
12
|
+
"areaCode": ""
|
|
13
|
+
});
|
|
14
|
+
var emptyCurrentWeather = CurrentWeatherSchema.parse({
|
|
15
|
+
"city": "",
|
|
16
|
+
"condition": "",
|
|
17
|
+
"temperatureCelsius": 0,
|
|
18
|
+
"humidityPercent": 0,
|
|
19
|
+
"updatedAtBeijing": ""
|
|
20
|
+
});
|
|
21
|
+
function getCurrentWeatherFound(value, failure) {
|
|
22
|
+
return branchCase("found", value, failure);
|
|
23
|
+
}
|
|
24
|
+
function getCurrentWeatherProviderRejected(value, failure) {
|
|
25
|
+
return branchCase("providerRejected", value, failure);
|
|
26
|
+
}
|
|
27
|
+
function getCurrentWeatherInvalidResponse(value, failure) {
|
|
28
|
+
return branchCase("invalidResponse", value, failure);
|
|
29
|
+
}
|
|
30
|
+
function getCurrentWeatherDefect(value, failure) {
|
|
31
|
+
return branchCase("defect", value, failure);
|
|
32
|
+
}
|
|
33
|
+
function getCurrentWeatherRetry(failure, retryAfterMs = 0) {
|
|
34
|
+
return retryCase(failure, retryAfterMs);
|
|
35
|
+
}
|
|
36
|
+
function getCurrentWeatherCurrentWeather() {
|
|
37
|
+
const value = CurrentWeatherSchema.parse({ "city": "Beijing", "condition": "Cloudy", "humidityPercent": 38, "temperatureCelsius": 18.5, "updatedAtBeijing": "2026-11-13 12:00:00" });
|
|
38
|
+
return branchCase("found", value);
|
|
39
|
+
}
|
|
40
|
+
function getCurrentWeatherDefault() {
|
|
41
|
+
return getCurrentWeatherCurrentWeather();
|
|
42
|
+
}
|
|
43
|
+
var GeneratedMock = class {
|
|
44
|
+
#getCurrentWeather;
|
|
45
|
+
#connection;
|
|
46
|
+
constructor(connectionName) {
|
|
47
|
+
this.#getCurrentWeather = newQuery(GetCurrentWeatherDefinition).default(getCurrentWeatherDefault());
|
|
48
|
+
this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
|
|
49
|
+
}
|
|
50
|
+
connection() {
|
|
51
|
+
return this.#connection;
|
|
52
|
+
}
|
|
53
|
+
getCurrentWeather() {
|
|
54
|
+
return this.#getCurrentWeather;
|
|
55
|
+
}
|
|
56
|
+
assertNoFailures() {
|
|
57
|
+
this.#getCurrentWeather.assertNoFailures();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
GeneratedMock,
|
|
62
|
+
GeneratedMock as Mock,
|
|
63
|
+
emptyCurrentWeather,
|
|
64
|
+
emptyGetCurrentWeatherInput,
|
|
65
|
+
getCurrentWeatherCurrentWeather,
|
|
66
|
+
getCurrentWeatherDefault,
|
|
67
|
+
getCurrentWeatherDefect,
|
|
68
|
+
getCurrentWeatherFound,
|
|
69
|
+
getCurrentWeatherInvalidResponse,
|
|
70
|
+
getCurrentWeatherProviderRejected,
|
|
71
|
+
getCurrentWeatherRetry
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-apispace",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "APISpace current weather connector for Dex TypeScript applications",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/superdurable/dex-connectors-library.git",
|
|
9
|
+
"directory": "connectors/apispace/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
|
+
"check": "npm run typecheck && npm run lint && npm test && npm run build",
|
|
42
|
+
"example:worker": "tsx examples/current-weather/worker.ts",
|
|
43
|
+
"example:start": "tsx examples/current-weather/start.ts"
|
|
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
|
+
}
|