@easecation/ecapi-sdk 0.1.2 → 0.1.3

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 CHANGED
@@ -17,7 +17,6 @@ npm install @easecation/ecapi-sdk
17
17
  import { ECAPIClient } from "@easecation/ecapi-sdk";
18
18
 
19
19
  const client = new ECAPIClient({
20
- baseUrl: "https://your-ecapi-host",
21
20
  auth: { type: "apiKey", apiKey: process.env.EC_API_KEY! },
22
21
  });
23
22
 
@@ -33,6 +32,7 @@ client.setAppSessionToken(process.env.EC_APP_SESSION_TOKEN!);
33
32
 
34
33
  ## 客户端能力
35
34
 
35
+ - 默认 `baseUrl`:`https://console.easecation.net/apiv2`
36
36
  - 统一请求入口:`client.request(method, path, options)`
37
37
  - 默认超时:15s(可在构造时 `timeoutMs` 覆盖)
38
38
  - 支持 per-request 覆盖鉴权:`options.auth`
package/dist/http.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ECAPIHttpClient = exports.ECAPIError = void 0;
4
+ const DEFAULT_BASE_URL = "https://console.easecation.net/apiv2";
4
5
  function normalizeBaseUrl(baseUrl) {
5
6
  return baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
6
7
  }
@@ -101,7 +102,7 @@ class ECAPIError extends Error {
101
102
  exports.ECAPIError = ECAPIError;
102
103
  class ECAPIHttpClient {
103
104
  constructor(options) {
104
- this.baseUrl = normalizeBaseUrl(options.baseUrl);
105
+ this.baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_BASE_URL);
105
106
  this.defaultHeaders = { ...(options.defaultHeaders || {}) };
106
107
  this.timeoutMs = options.timeoutMs ?? 15000;
107
108
  this.auth = options.auth;
package/dist/types.d.ts CHANGED
@@ -111,8 +111,8 @@ export type AuthCredentials = {
111
111
  };
112
112
  /** Top-level options used when creating `ECAPIClient`. */
113
113
  export interface ClientOptions {
114
- /** API base URL, e.g. https://console.easecation.net/apiv2 */
115
- baseUrl: string;
114
+ /** API base URL. Defaults to https://console.easecation.net/apiv2 */
115
+ baseUrl?: string;
116
116
  /** Default auth used by all requests unless overridden. */
117
117
  auth?: AuthCredentials;
118
118
  /** Request timeout in milliseconds. Default is 15000. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easecation/ecapi-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "ECAPI SDK for JavaScript and TypeScript",
5
5
  "homepage": "https://github.com/easecation/easecation-api/tree/main/sdk/npm/ecapi-sdk#readme",
6
6
  "repository": {