@waywake/wdt-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # @waywake/wdt-sdk
2
+
3
+ TypeScript SDK for 旺店通旗舰版 OpenAPI, built with Bun.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @waywake/wdt-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { WdtClient } from "@waywake/wdt-sdk";
15
+
16
+ const client = new WdtClient({
17
+ sid: process.env.WDT_SID!,
18
+ appKey: process.env.WDT_APP_KEY!,
19
+ appSecret: process.env.WDT_APP_SECRET!,
20
+ baseUrl: process.env.WDT_BASE_URL,
21
+ });
22
+
23
+ const response = await client.call(
24
+ "setting.Warehouse.queryWarehouse",
25
+ {
26
+ startTime: "2020-01-01 00:00:00",
27
+ endTime: "2020-01-20 00:00:00",
28
+ },
29
+ {
30
+ pager: { pageNo: 0, pageSize: 100, calcTotal: true },
31
+ },
32
+ );
33
+
34
+ console.log(response.data?.totalCount);
35
+ ```
36
+
37
+ Every public API method from the API list is available as a typed method string and as an `api` helper:
38
+
39
+ ```ts
40
+ await client.api.settingWarehouseQueryWarehouse(
41
+ { startTime: "2020-01-01 00:00:00", endTime: "2020-01-20 00:00:00" },
42
+ { pager: { pageNo: 0, pageSize: 100, calcTotal: true } },
43
+ );
44
+ ```
45
+
46
+ Request and response objects use `camelCase` in TypeScript. The SDK converts request keys to `snake_case` before sending and converts response keys back to `camelCase`.
47
+
48
+ For positional body APIs, pass an array:
49
+
50
+ ```ts
51
+ await client.call("wms.stockout.Sales.weighingExt", [
52
+ "xc109393939393939",
53
+ "",
54
+ 1.2,
55
+ 0,
56
+ false,
57
+ ]);
58
+ ```
59
+
60
+ ## Docs
61
+
62
+ - 接口规范: <https://open.wangdian.cn/qjb/open/guide?path=qjbguide_jkgf>
63
+ - Sign算法: <https://open.wangdian.cn/qjb/open/guide?path=qjbguide_signsf>
64
+ - API列表: <https://open.wangdian.cn/qjb/open/apidoc>
65
+
66
+ ## Development
67
+
68
+ ```bash
69
+ bun install
70
+ bun run generate:endpoints
71
+ bun test
72
+ bun run build
73
+ ```
74
+
75
+ Live integration tests are disabled by default. To run them:
76
+
77
+ ```bash
78
+ WDT_INTEGRATION=1 \
79
+ WDT_BASE_URL='https://example.com/openapi' \
80
+ WDT_SID='your-sid' \
81
+ WDT_APP_KEY='your-app-key' \
82
+ WDT_APP_SECRET='...' \
83
+ bun test
84
+ ```
package/dist/body.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { WdtRequestBody } from "./types";
2
+ export declare function createRequestBody(input: WdtRequestBody): string;
3
+ //# sourceMappingURL=body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAS/D"}
package/dist/case.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { DeepCamel, DeepSnake, JsonObject, JsonValue } from "./types";
2
+ export declare function toSnakeCase(key: string): string;
3
+ export declare function toCamelCase(key: string): string;
4
+ export declare function isPlainObject(value: unknown): value is JsonObject;
5
+ export declare function keysToSnakeCase<T extends JsonValue | undefined>(value: T): DeepSnake<T>;
6
+ export declare function keysToCamelCase<T extends JsonValue | undefined>(value: T): DeepCamel<T>;
7
+ //# sourceMappingURL=case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../src/case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAa,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAItF,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEjE;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEvF;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEvF"}
@@ -0,0 +1,34 @@
1
+ import { type WdtEndpointMap, type WdtMethod } from "./endpoints";
2
+ import { type WdtSignedRequest } from "./sign";
3
+ import type { DeepCamel, WdtApiResponse, WdtCallOptions, WdtClientOptions, WdtEndpointMeta, WdtRequestBody } from "./types";
4
+ type PascalSegment<S extends string> = Capitalize<Uncapitalize<S>>;
5
+ type PascalDotted<S extends string> = S extends `${infer Head}.${infer Tail}` ? `${PascalSegment<Head>}${PascalDotted<Tail>}` : PascalSegment<S>;
6
+ export type WdtMethodAlias<S extends string> = S extends `${infer Head}.${infer Tail}` ? `${Uncapitalize<Head>}${PascalDotted<Tail>}` : Uncapitalize<S>;
7
+ export type WdtApiHelpers = {
8
+ [M in WdtMethod as WdtMethodAlias<M>]: (request?: WdtEndpointMap[M]["request"], options?: WdtCallOptions) => Promise<DeepCamel<WdtEndpointMap[M]["response"]>>;
9
+ };
10
+ export interface PreparedWdtRequest {
11
+ url: string;
12
+ init: RequestInit;
13
+ signed: WdtSignedRequest;
14
+ }
15
+ export declare class WdtClient {
16
+ readonly sid: string;
17
+ readonly appKey: string;
18
+ readonly appSecret: string;
19
+ readonly baseUrl: string;
20
+ readonly version: string;
21
+ readonly api: WdtApiHelpers;
22
+ private readonly fetchImpl;
23
+ private readonly defaultThrowOnApiError;
24
+ private readonly timestampProvider?;
25
+ constructor(options: WdtClientOptions);
26
+ call<M extends WdtMethod>(method: M, request?: WdtEndpointMap[M]["request"], options?: WdtCallOptions): Promise<DeepCamel<WdtEndpointMap[M]["response"]>>;
27
+ call(method: string, request?: WdtRequestBody, options?: WdtCallOptions): Promise<WdtApiResponse>;
28
+ prepareRequest(method: string, request?: WdtRequestBody, options?: WdtCallOptions): PreparedWdtRequest;
29
+ getEndpoint(method: WdtMethod): WdtEndpointMeta;
30
+ }
31
+ export declare function createWdtClient(options: WdtClientOptions): WdtClient;
32
+ export declare function aliasForMethod(method: string): string;
33
+ export {};
34
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,KAAK,EACV,SAAS,EAET,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EAEf,cAAc,EACf,MAAM,SAAS,CAAC;AAIjB,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AACnE,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GACzE,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,GAC7C,aAAa,CAAC,CAAC,CAAC,CAAC;AAErB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GAClF,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,GAC5C,YAAY,CAAC,CAAC,CAAC,CAAC;AAEpB,MAAM,MAAM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