@superdurable/connector-easyapi 0.1.0 → 0.2.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/README.md +2 -0
- package/dex-connector.json +2 -2
- package/dist/{chunk-H7EQZD4H.js → chunk-AC3VW4YR.js} +55 -2
- package/dist/{connection-CoZSCCwQ.d.ts → connection-CmwaCEu5.d.ts} +22 -5
- package/dist/index.d.ts +3 -2
- package/dist/index.js +84 -37
- package/dist/mock.d.ts +2 -1
- package/dist/mock.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,3 +5,5 @@
|
|
|
5
5
|
In the [EasyAPI E-Invoice console](https://fapiao.easyapi.com/console/), open **服务认证**, create or select a key pair associated with the company, and save its Key and Secret as Dex secret credentials. Use the company's 15, 17, 18, 19, or 20 character tax number as Query input. Blank credentials prevent requests. Leave baseUrl, timeout and maxResponseBytes blank for their displayed production defaults.
|
|
6
6
|
|
|
7
7
|
The [runnable Flow](examples/basic/) uses static connection name `easyapi`. `npm run check` replays all Go-recorded provider scenarios, including rejection, retry, and secret-safe output. Live provider authorization remains unverified without a user-controlled connection.
|
|
8
|
+
|
|
9
|
+
In v0.2, `ShopResult.shopId` uses `SignedInteger`. Safe IDs remain numbers. Larger IDs retain their decimal digits in a raw JSON token. Use `exactIntegerJSONCodec<ShopResult>()` for Blob, Attribute and Flow result decoding. The [Flow](examples/basic/flow.ts) and [starter](examples/basic/start.ts) demonstrate both sides.
|
package/dex-connector.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"connectorId": "easyapi",
|
|
3
|
-
"releaseTag": "connectors/easyapi/go/v0.1.
|
|
3
|
+
"releaseTag": "connectors/easyapi/go/v0.1.1",
|
|
4
4
|
"package": {
|
|
5
5
|
"ecosystem": "npm",
|
|
6
6
|
"name": "@superdurable/connector-easyapi",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.2.0"
|
|
8
8
|
},
|
|
9
9
|
"factories": [
|
|
10
10
|
{
|
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
// src/generated/models.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { SecretString } from "@superdurable/connectors-sdk";
|
|
4
|
+
var nativeJSON = JSON;
|
|
5
|
+
var signedIntegerToken = /^-?(?:0|[1-9][0-9]*)$/;
|
|
6
|
+
var minimumSignedInteger = -(1n << 63n);
|
|
7
|
+
var maximumSignedInteger = (1n << 63n) - 1n;
|
|
8
|
+
function decodeSignedInteger(value) {
|
|
9
|
+
if (typeof value === "number" && Number.isSafeInteger(value)) return value === 0 ? 0 : value;
|
|
10
|
+
if (!nativeJSON.isRawJSON(value) || value.rawJSON.length > 20 || !signedIntegerToken.test(value.rawJSON)) {
|
|
11
|
+
throw new TypeError("expected a signed 64-bit integer");
|
|
12
|
+
}
|
|
13
|
+
const integer = BigInt(value.rawJSON);
|
|
14
|
+
if (integer < minimumSignedInteger || integer > maximumSignedInteger) throw new RangeError("signed 64-bit integer out of range");
|
|
15
|
+
const number = Number(integer);
|
|
16
|
+
return Number.isSafeInteger(number) ? number : value;
|
|
17
|
+
}
|
|
18
|
+
var signedIntegerSchema = z.unknown().transform((value, context) => {
|
|
19
|
+
try {
|
|
20
|
+
return decodeSignedInteger(value);
|
|
21
|
+
} catch {
|
|
22
|
+
context.addIssue({ code: "custom", message: "expected a signed 64-bit integer" });
|
|
23
|
+
return z.NEVER;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
function parseJSONNumberTokens(text) {
|
|
27
|
+
return JSON.parse(text, (_key, value, context) => typeof value === "number" && context?.source !== void 0 ? nativeJSON.rawJSON(context.source) : value);
|
|
28
|
+
}
|
|
29
|
+
function parseExactIntegerJSON(text) {
|
|
30
|
+
return JSON.parse(text, (_key, field, context) => typeof field === "number" && !Number.isSafeInteger(field) && context?.source && signedIntegerToken.test(context.source) ? nativeJSON.rawJSON(context.source) : field);
|
|
31
|
+
}
|
|
32
|
+
function exactIntegerJSONCodec(decode) {
|
|
33
|
+
return {
|
|
34
|
+
typeName: "json",
|
|
35
|
+
wireKind: "json",
|
|
36
|
+
encode(value) {
|
|
37
|
+
const data = JSON.stringify(value, (_key, field) => {
|
|
38
|
+
if (typeof field === "number" && Number.isInteger(field) && !Number.isSafeInteger(field)) {
|
|
39
|
+
throw new RangeError("use a raw JSON token for integers outside the safe number range");
|
|
40
|
+
}
|
|
41
|
+
return field;
|
|
42
|
+
});
|
|
43
|
+
if (data === void 0) throw new TypeError("value cannot be encoded as JSON");
|
|
44
|
+
return { kind: "json", data };
|
|
45
|
+
},
|
|
46
|
+
decode(wire) {
|
|
47
|
+
if (wire.kind !== "json" || typeof wire.data !== "string") throw new TypeError("expected Dex JSON wire data");
|
|
48
|
+
const value = parseExactIntegerJSON(wire.data);
|
|
49
|
+
return decode ? decode(value) : value;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
4
53
|
var ConfigSchema = z.object({
|
|
5
54
|
"baseUrl": z.string().optional(),
|
|
6
55
|
"timeoutMs": z.number().int().optional(),
|
|
@@ -38,9 +87,9 @@ var QueryShopInputSchema = z.strictObject({
|
|
|
38
87
|
"taxNumber": z.string()
|
|
39
88
|
});
|
|
40
89
|
var ShopResultSchema = z.strictObject({
|
|
41
|
-
"shopId":
|
|
90
|
+
"shopId": signedIntegerSchema,
|
|
42
91
|
"name": z.string(),
|
|
43
|
-
"apiState":
|
|
92
|
+
"apiState": signedIntegerSchema,
|
|
44
93
|
"endTime": z.string()
|
|
45
94
|
});
|
|
46
95
|
|
|
@@ -100,6 +149,10 @@ function newProjectConnection(project, connectionName, createClient) {
|
|
|
100
149
|
}
|
|
101
150
|
|
|
102
151
|
export {
|
|
152
|
+
decodeSignedInteger,
|
|
153
|
+
parseJSONNumberTokens,
|
|
154
|
+
parseExactIntegerJSON,
|
|
155
|
+
exactIntegerJSONCodec,
|
|
103
156
|
ConfigSchema,
|
|
104
157
|
CredentialMaterialError,
|
|
105
158
|
isCredentialMaterialError,
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { CredentialProvider, SecretString, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { Codec } from '@superdurable/dex';
|
|
3
4
|
|
|
5
|
+
/** A signed 64-bit JSON integer. Values outside the safe number range retain their decimal token. */
|
|
6
|
+
type SignedInteger = number | Readonly<{
|
|
7
|
+
rawJSON: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Decode one signed Go integer from a safe number or a native raw JSON number token. */
|
|
10
|
+
declare function decodeSignedInteger(value: unknown): SignedInteger;
|
|
11
|
+
/** Read provider JSON with the original syntax of every numeric token for typed field validation. */
|
|
12
|
+
declare function parseJSONNumberTokens(text: string): unknown;
|
|
13
|
+
/** Decode JSON while retaining exact decimal tokens for integers outside JavaScript's safe range. */
|
|
14
|
+
declare function parseExactIntegerJSON(text: string): unknown;
|
|
15
|
+
/** JSON-wire codec for records with signed integer fields. An optional decoder validates the application type. */
|
|
16
|
+
declare function exactIntegerJSONCodec<T>(decode?: (value: unknown) => T): Codec<T>;
|
|
4
17
|
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
18
|
interface Config {
|
|
6
19
|
/** HTTPS origin of the EasyAPI E-Invoice API. Leave blank for the displayed production endpoint; override only for a trusted provider-issued HTTPS endpoint. */
|
|
@@ -41,11 +54,11 @@ interface QueryShopInput {
|
|
|
41
54
|
/** ShopResult contains only non-sensitive invoicing service configuration. */
|
|
42
55
|
interface ShopResult {
|
|
43
56
|
/** ShopID is EasyAPI's company ID. */
|
|
44
|
-
"shopId":
|
|
57
|
+
"shopId": SignedInteger;
|
|
45
58
|
/** Name is the company's registered name. */
|
|
46
59
|
"name": string;
|
|
47
60
|
/** APIState is 1 normal, 0 expired, or -1 not activated. */
|
|
48
|
-
"apiState":
|
|
61
|
+
"apiState": SignedInteger;
|
|
49
62
|
/** EndTime is the service expiry time in provider local time, or blank if absent. */
|
|
50
63
|
"endTime": string;
|
|
51
64
|
}
|
|
@@ -55,9 +68,13 @@ declare const QueryShopInputSchema: z.ZodObject<{
|
|
|
55
68
|
}, z.core.$strict>;
|
|
56
69
|
/** Runtime validator for ShopResult. */
|
|
57
70
|
declare const ShopResultSchema: z.ZodObject<{
|
|
58
|
-
shopId: z.
|
|
71
|
+
shopId: z.ZodPipe<z.ZodUnknown, z.ZodTransform<number | Readonly<{
|
|
72
|
+
rawJSON: string;
|
|
73
|
+
}>, unknown>>;
|
|
59
74
|
name: z.ZodString;
|
|
60
|
-
apiState: z.
|
|
75
|
+
apiState: z.ZodPipe<z.ZodUnknown, z.ZodTransform<number | Readonly<{
|
|
76
|
+
rawJSON: string;
|
|
77
|
+
}>, unknown>>;
|
|
61
78
|
endTime: z.ZodString;
|
|
62
79
|
}, z.core.$strict>;
|
|
63
80
|
|
|
@@ -80,4 +97,4 @@ declare function newConnection(client: Operations, reference: ConnectionRef): Co
|
|
|
80
97
|
/** Bind scripted operations to a named connection. */
|
|
81
98
|
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
82
99
|
|
|
83
|
-
export { Connection as C, type Operations as O, type QueryShopInput as Q, type ShopResult as S, type Config as a, type Credentials as b, ConfigSchema as c, CredentialMaterialError as d, type CredentialSource as e, QueryShopInputSchema as f, ShopResultSchema as g,
|
|
100
|
+
export { Connection as C, type Operations as O, type QueryShopInput as Q, type ShopResult as S, type Config as a, type Credentials as b, ConfigSchema as c, CredentialMaterialError as d, type CredentialSource as e, QueryShopInputSchema as f, ShopResultSchema as g, type SignedInteger as h, decodeCredentials as i, decodeSignedInteger as j, exactIntegerJSONCodec as k, isCredentialMaterialError as l, newConnectionWithOperations as m, newConnection as n, parseJSONNumberTokens as o, parseExactIntegerJSON as p };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q as QueryShopInput, S as ShopResult, C as Connection, O as Operations, a as Config, b as Credentials } from './connection-
|
|
2
|
-
export { c as ConfigSchema, d as CredentialMaterialError, e as CredentialSource, f as QueryShopInputSchema, g as ShopResultSchema, h as
|
|
1
|
+
import { Q as QueryShopInput, S as ShopResult, C as Connection, O as Operations, a as Config, b as Credentials } from './connection-CmwaCEu5.js';
|
|
2
|
+
export { c as ConfigSchema, d as CredentialMaterialError, e as CredentialSource, f as QueryShopInputSchema, g as ShopResultSchema, h as SignedInteger, i as decodeCredentials, j as decodeSignedInteger, k as exactIntegerJSONCodec, l as isCredentialMaterialError, n as newConnection, m as newConnectionWithOperations, p as parseExactIntegerJSON, o as parseJSONNumberTokens } from './connection-CmwaCEu5.js';
|
|
3
3
|
import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, CredentialProvider, Call, QueryAttempt } from '@superdurable/connectors-sdk';
|
|
4
4
|
import { StepTarget } from '@superdurable/dex';
|
|
5
5
|
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
|
@@ -76,6 +76,7 @@ declare class EasyapiClient {
|
|
|
76
76
|
response?: ProviderResponse;
|
|
77
77
|
error?: 'credential' | 'transport' | 'tooLarge';
|
|
78
78
|
retryAfterMs: number;
|
|
79
|
+
outcome?: QueryAttempt<ShopResult>;
|
|
79
80
|
}>;
|
|
80
81
|
}
|
|
81
82
|
/** Read one company's non-sensitive service configuration. */
|
package/dist/index.js
CHANGED
|
@@ -14,11 +14,15 @@ import {
|
|
|
14
14
|
QueryShopMetadata,
|
|
15
15
|
ShopResultSchema,
|
|
16
16
|
decodeCredentials,
|
|
17
|
+
decodeSignedInteger,
|
|
18
|
+
exactIntegerJSONCodec,
|
|
17
19
|
isCredentialMaterialError,
|
|
18
20
|
newConnection,
|
|
19
21
|
newConnectionWithOperations,
|
|
20
|
-
newProjectConnection
|
|
21
|
-
|
|
22
|
+
newProjectConnection,
|
|
23
|
+
parseExactIntegerJSON,
|
|
24
|
+
parseJSONNumberTokens
|
|
25
|
+
} from "./chunk-AC3VW4YR.js";
|
|
22
26
|
|
|
23
27
|
// src/generated/steps.ts
|
|
24
28
|
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
@@ -34,26 +38,28 @@ function newQueryShopStep(configuration) {
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
// src/client.ts
|
|
37
|
-
import {
|
|
38
|
-
|
|
41
|
+
import {
|
|
42
|
+
SecretString,
|
|
43
|
+
newQueryBranch,
|
|
44
|
+
newQueryRetry
|
|
45
|
+
} from "@superdurable/connectors-sdk";
|
|
46
|
+
import {
|
|
47
|
+
BodyTooLargeError,
|
|
48
|
+
parseRetryAfter,
|
|
49
|
+
sendProviderRequest,
|
|
50
|
+
validateBaseURL
|
|
51
|
+
} from "@superdurable/connectors-sdk/providerhttp";
|
|
39
52
|
var emptyResult = { shopId: 0, name: "", apiState: 0, endTime: "" };
|
|
40
53
|
var EasyapiClient = class {
|
|
41
54
|
/** Validate local settings without contacting EasyAPI. */
|
|
42
55
|
constructor(config, credentials, options = {}) {
|
|
43
56
|
this.credentials = credentials;
|
|
44
57
|
if (!config || !credentials) throw new TypeError("EasyAPI configuration and credentials are required");
|
|
45
|
-
|
|
46
|
-
let parsed;
|
|
47
|
-
try {
|
|
48
|
-
parsed = new URL(selectedBaseUrl);
|
|
49
|
-
} catch {
|
|
50
|
-
throw new TypeError("EasyAPI base URL is invalid");
|
|
51
|
-
}
|
|
52
|
-
if (!["https:", "http:"].includes(parsed.protocol) || parsed.protocol === "http:" && !["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname) || !parsed.hostname || parsed.username || parsed.password || parsed.search || parsed.hash || selectedBaseUrl.endsWith("/")) throw new TypeError("EasyAPI base URL is invalid");
|
|
53
|
-
this.baseUrl = selectedBaseUrl;
|
|
58
|
+
this.baseUrl = validateBaseURL(config.baseUrl || "https://fapiao-api.easyapi.com");
|
|
54
59
|
this.timeoutMs = config.timeoutMs || 15e3;
|
|
55
60
|
this.maxResponseBytes = config.maxResponseBytes || 262144;
|
|
56
|
-
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0
|
|
61
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0)
|
|
62
|
+
throw new TypeError("EasyAPI request limits are invalid");
|
|
57
63
|
this.send = options.send ?? sendProviderRequest;
|
|
58
64
|
}
|
|
59
65
|
credentials;
|
|
@@ -75,17 +81,37 @@ var EasyapiClient = class {
|
|
|
75
81
|
} catch {
|
|
76
82
|
return { error: "credential", retryAfterMs: 0 };
|
|
77
83
|
}
|
|
78
|
-
if (!validCredential(appKey) || !validCredential(appSecret))
|
|
84
|
+
if (!validCredential(appKey) || !validCredential(appSecret))
|
|
85
|
+
return { error: "credential", retryAfterMs: 0 };
|
|
79
86
|
const query = new URLSearchParams({ appKey, appSecret, taxNumber });
|
|
80
|
-
const request = {
|
|
87
|
+
const request = {
|
|
88
|
+
url: this.baseUrl + "/shop/query?" + query.toString(),
|
|
89
|
+
method: "GET",
|
|
90
|
+
headers: { Accept: "application/json" },
|
|
91
|
+
timeoutMs: this.timeoutMs,
|
|
92
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
93
|
+
addressPolicy: "publicHTTPS",
|
|
94
|
+
signal: call.context.cancellationSignal
|
|
95
|
+
};
|
|
81
96
|
let response;
|
|
82
97
|
try {
|
|
83
98
|
response = await this.send(request);
|
|
84
99
|
} catch (error) {
|
|
85
|
-
if (error instanceof BodyTooLargeError && error.status !== void 0)
|
|
100
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0)
|
|
101
|
+
return {
|
|
102
|
+
response: { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() },
|
|
103
|
+
error: "tooLarge",
|
|
104
|
+
retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"))
|
|
105
|
+
};
|
|
86
106
|
return { error: "transport", retryAfterMs: 0 };
|
|
87
107
|
}
|
|
88
|
-
|
|
108
|
+
const outcome = response.status === 200 && response.body.length <= this.maxResponseBytes ? decodeShop(response.body, [appKey, appSecret, taxNumber]) : void 0;
|
|
109
|
+
return {
|
|
110
|
+
response,
|
|
111
|
+
outcome,
|
|
112
|
+
error: response.body.length > this.maxResponseBytes ? "tooLarge" : void 0,
|
|
113
|
+
retryAfterMs: parseRetryAfter(header(response.headers, "retry-after"))
|
|
114
|
+
};
|
|
89
115
|
}
|
|
90
116
|
};
|
|
91
117
|
var QueryShopOperation = class {
|
|
@@ -101,33 +127,50 @@ var QueryShopOperation = class {
|
|
|
101
127
|
/** Classify one company read according to the Go connector contract. */
|
|
102
128
|
async invoke(call, input) {
|
|
103
129
|
const taxNumber = input?.taxNumber;
|
|
104
|
-
if (typeof taxNumber !== "string" || ![15, 17, 18, 19, 20].includes(taxNumber.length) ||
|
|
130
|
+
if (typeof taxNumber !== "string" || ![15, 17, 18, 19, 20].includes(taxNumber.length) || /[^0-9A-Z]/.test(taxNumber))
|
|
131
|
+
return branch("defect", "VALIDATION");
|
|
105
132
|
const exchange = await this.client.readShop(call, taxNumber);
|
|
106
133
|
if (exchange.error === "credential") return branch("defect", "AUTHENTICATION");
|
|
107
134
|
if (exchange.error === "transport" || !exchange.response) return retry("AVAILABILITY");
|
|
108
|
-
const { status
|
|
135
|
+
const { status } = exchange.response;
|
|
109
136
|
if (status === 429) return retry("RATE_LIMIT", exchange.retryAfterMs);
|
|
110
137
|
if (status === 408 || status >= 500) return retry("AVAILABILITY", exchange.retryAfterMs);
|
|
111
138
|
if (exchange.error === "tooLarge") return branch("invalidResponse", "RESPONSE_TOO_LARGE");
|
|
112
|
-
if (status !== 200)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
if (!isRecord(wire) || !Number.isInteger(wire.code)) return branch("invalidResponse", "PROTOCOL");
|
|
120
|
-
if (wire.code !== 1) return branch("providerRejected", "PROVIDER_REJECTION");
|
|
121
|
-
const content = wire.content;
|
|
122
|
-
if (!isRecord(content) || !Number.isSafeInteger(content.shopId) || content.shopId <= 0 || typeof content.name !== "string" || !content.name || content.name.length > 256 || ![-1, 0, 1].includes(content.apiState) || !Number.isInteger(content.apiState) || content.endTime !== void 0 && (typeof content.endTime !== "string" || content.endTime.length > 32)) return branch("invalidResponse", "PROTOCOL");
|
|
123
|
-
return newQueryBranch("found", { shopId: content.shopId, name: content.name, apiState: content.apiState, endTime: content.endTime ?? "" }, {});
|
|
139
|
+
if (status !== 200)
|
|
140
|
+
return branch(
|
|
141
|
+
"providerRejected",
|
|
142
|
+
status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : [400, 404, 412].includes(status) ? "VALIDATION" : "PROVIDER_REJECTION"
|
|
143
|
+
);
|
|
144
|
+
return exchange.outcome ?? branch("invalidResponse", "PROTOCOL");
|
|
124
145
|
}
|
|
125
146
|
};
|
|
126
|
-
function
|
|
127
|
-
|
|
147
|
+
function decodeShop(body, privateValues) {
|
|
148
|
+
try {
|
|
149
|
+
const envelope = record(
|
|
150
|
+
parseJSONNumberTokens(new TextDecoder("utf-8", { ignoreBOM: true }).decode(body))
|
|
151
|
+
);
|
|
152
|
+
const code = decodeSignedInteger(envelope.code);
|
|
153
|
+
const content = record(envelope.content ?? {});
|
|
154
|
+
const id = decodeSignedInteger(content.shopid ?? 0);
|
|
155
|
+
const state = decodeSignedInteger(content.apistate ?? 0);
|
|
156
|
+
const name = content.name ?? "", endTime = content.endtime ?? "";
|
|
157
|
+
if (typeof name !== "string" || typeof endTime !== "string") throw new Error("invalid company fields");
|
|
158
|
+
if (code !== 1) return branch("providerRejected", "PROVIDER_REJECTION");
|
|
159
|
+
const positiveId = typeof id === "number" ? id > 0 : BigInt(id.rawJSON) > 0n;
|
|
160
|
+
if (!positiveId || !name || Buffer.byteLength(name) > 256 || Buffer.byteLength(endTime) > 32 || content.apistate == null || state !== -1 && state !== 0 && state !== 1 || privateValues.some((value) => name.includes(value) || endTime.includes(value)))
|
|
161
|
+
throw new Error("invalid company fields");
|
|
162
|
+
return newQueryBranch("found", { shopId: id, name, apiState: state, endTime }, {});
|
|
163
|
+
} catch {
|
|
164
|
+
return branch("invalidResponse", "PROTOCOL");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function record(value) {
|
|
168
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || JSON.isRawJSON(value))
|
|
169
|
+
throw new Error("invalid response object");
|
|
170
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key.toLowerCase(), item]));
|
|
128
171
|
}
|
|
129
|
-
function
|
|
130
|
-
return value
|
|
172
|
+
function validCredential(value) {
|
|
173
|
+
return !!value && Buffer.byteLength(value) <= 2048 && !/^\p{White_Space}|\p{White_Space}$/u.test(value);
|
|
131
174
|
}
|
|
132
175
|
function header(headers, name) {
|
|
133
176
|
const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
|
|
@@ -190,9 +233,13 @@ export {
|
|
|
190
233
|
QueryShopMetadata,
|
|
191
234
|
ShopResultSchema,
|
|
192
235
|
decodeCredentials,
|
|
236
|
+
decodeSignedInteger,
|
|
237
|
+
exactIntegerJSONCodec,
|
|
193
238
|
isCredentialMaterialError,
|
|
194
239
|
newConnection,
|
|
195
240
|
newConnectionWithOperations,
|
|
196
241
|
newProjectConnection2 as newProjectConnection,
|
|
197
|
-
newQueryShopStep
|
|
242
|
+
newQueryShopStep,
|
|
243
|
+
parseExactIntegerJSON,
|
|
244
|
+
parseJSONNumberTokens
|
|
198
245
|
};
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
2
|
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
-
import { O as Operations, C as Connection, Q as QueryShopInput, S as ShopResult } from './connection-
|
|
3
|
+
import { O as Operations, C as Connection, Q as QueryShopInput, S as ShopResult } from './connection-CmwaCEu5.js';
|
|
4
4
|
import 'zod';
|
|
5
|
+
import '@superdurable/dex';
|
|
5
6
|
|
|
6
7
|
/** Go zero value for QueryShopInput in scripted cases. */
|
|
7
8
|
declare const emptyQueryShopInput: QueryShopInput;
|
package/dist/mock.js
CHANGED
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
QueryShopDefinition,
|
|
4
4
|
QueryShopInputSchema,
|
|
5
5
|
ShopResultSchema,
|
|
6
|
-
newConnectionWithOperations
|
|
7
|
-
|
|
6
|
+
newConnectionWithOperations,
|
|
7
|
+
parseExactIntegerJSON
|
|
8
|
+
} from "./chunk-AC3VW4YR.js";
|
|
8
9
|
|
|
9
10
|
// src/generated/mock.ts
|
|
10
11
|
import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
|
@@ -33,7 +34,7 @@ function queryShopRetry(failure, retryAfterMs = 0) {
|
|
|
33
34
|
return retryCase(failure, retryAfterMs);
|
|
34
35
|
}
|
|
35
36
|
function queryShopFoundShop() {
|
|
36
|
-
const value = ShopResultSchema.parse({
|
|
37
|
+
const value = ShopResultSchema.parse(parseExactIntegerJSON('{"apiState":1,"endTime":"2027-01-01 00:00:00","name":"Example Company","shopId":1001}'));
|
|
37
38
|
return branchCase("found", value);
|
|
38
39
|
}
|
|
39
40
|
function queryShopDefault() {
|