@cn-quickotp/k3cloud-webapi-sdk 1.0.1 → 1.0.2
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/dist/index.js +88 -4
- package/package.json +1 -1
- package/types/index.d.ts +19 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var require$$0 = require('fs');
|
|
4
|
+
var require$$1 = require('path');
|
|
5
|
+
|
|
3
6
|
function getDefaultExportFromCjs (x) {
|
|
4
7
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5
8
|
}
|
|
@@ -15,7 +18,7 @@ function requireVersion () {
|
|
|
15
18
|
* SDK 版本号,与 package.json 的 version 保持一致。
|
|
16
19
|
* @type {string}
|
|
17
20
|
*/
|
|
18
|
-
const SDK_VERSION = '1.0.
|
|
21
|
+
const SDK_VERSION = '1.0.2';
|
|
19
22
|
|
|
20
23
|
version = { SDK_VERSION };
|
|
21
24
|
return version;
|
|
@@ -1730,6 +1733,73 @@ function requireClient () {
|
|
|
1730
1733
|
return client;
|
|
1731
1734
|
}
|
|
1732
1735
|
|
|
1736
|
+
var envLoader;
|
|
1737
|
+
var hasRequiredEnvLoader;
|
|
1738
|
+
|
|
1739
|
+
function requireEnvLoader () {
|
|
1740
|
+
if (hasRequiredEnvLoader) return envLoader;
|
|
1741
|
+
hasRequiredEnvLoader = 1;
|
|
1742
|
+
|
|
1743
|
+
const fs = require$$0;
|
|
1744
|
+
const path = require$$1;
|
|
1745
|
+
|
|
1746
|
+
const { fromEnvVars } = requireConfig();
|
|
1747
|
+
|
|
1748
|
+
/** `.env` 文件名 */
|
|
1749
|
+
const ENV_FILE_NAME = '.env';
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* 解析 `.env` 文本为键值对。
|
|
1753
|
+
*
|
|
1754
|
+
* 支持 `KEY=VALUE`、双引号包裹值、`#` 注释行与空行。
|
|
1755
|
+
* @param {string} text
|
|
1756
|
+
* @returns {Object<string, string>}
|
|
1757
|
+
*/
|
|
1758
|
+
function parseEnv(text) {
|
|
1759
|
+
const result = {};
|
|
1760
|
+
for (const rawLine of String(text).split(/\r?\n/)) {
|
|
1761
|
+
const line = rawLine.trim();
|
|
1762
|
+
if (line === '' || line.startsWith('#')) continue;
|
|
1763
|
+
const eq = line.indexOf('=');
|
|
1764
|
+
if (eq === -1) continue;
|
|
1765
|
+
const key = line.slice(0, eq).trim();
|
|
1766
|
+
if (key === '') continue;
|
|
1767
|
+
let value = line.slice(eq + 1).trim();
|
|
1768
|
+
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
|
1769
|
+
value = value.slice(1, -1);
|
|
1770
|
+
}
|
|
1771
|
+
result[key] = value;
|
|
1772
|
+
}
|
|
1773
|
+
return result;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/**
|
|
1777
|
+
* 读取目录下的 `.env` 并写入目标对象,默认不覆盖已存在的键。
|
|
1778
|
+
* @param {string} [dir] 默认为当前工作目录
|
|
1779
|
+
* @param {{ target?: Object<string, string>, override?: boolean }} [options]
|
|
1780
|
+
* @returns {Object<string, string>} 目标对象
|
|
1781
|
+
*/
|
|
1782
|
+
function loadEnvFile(dir = process.cwd(), options = {}) {
|
|
1783
|
+
const target = options.target === undefined ? process.env : options.target;
|
|
1784
|
+
const override = options.override === true;
|
|
1785
|
+
let text;
|
|
1786
|
+
try {
|
|
1787
|
+
text = fs.readFileSync(path.join(dir, ENV_FILE_NAME), 'utf8');
|
|
1788
|
+
} catch (err) {
|
|
1789
|
+
if (err && err.code === 'ENOENT') return target;
|
|
1790
|
+
throw err;
|
|
1791
|
+
}
|
|
1792
|
+
const parsed = parseEnv(text);
|
|
1793
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
1794
|
+
if (override || target[key] === undefined) target[key] = value;
|
|
1795
|
+
}
|
|
1796
|
+
return target;
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
envLoader = { ENV_FILE_NAME, parseEnv, loadEnvFile, fromEnvVars };
|
|
1800
|
+
return envLoader;
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1733
1803
|
var src;
|
|
1734
1804
|
var hasRequiredSrc;
|
|
1735
1805
|
|
|
@@ -1738,10 +1808,24 @@ function requireSrc () {
|
|
|
1738
1808
|
hasRequiredSrc = 1;
|
|
1739
1809
|
|
|
1740
1810
|
const { SDK_VERSION } = requireVersion();
|
|
1741
|
-
const { K3CloudError } = requireErrors();
|
|
1811
|
+
const { K3CloudError, ERROR_CODES } = requireErrors();
|
|
1742
1812
|
const { createClient, createClientFromEnv } = requireClient();
|
|
1743
|
-
|
|
1744
|
-
|
|
1813
|
+
const { ENV_FILE_NAME, parseEnv, loadEnvFile } = requireEnvLoader();
|
|
1814
|
+
const { LOG_LEVELS, nullLogger, createLogger } = requireLogger();
|
|
1815
|
+
|
|
1816
|
+
src = {
|
|
1817
|
+
SDK_VERSION,
|
|
1818
|
+
K3CloudError,
|
|
1819
|
+
ERROR_CODES,
|
|
1820
|
+
createClient,
|
|
1821
|
+
createClientFromEnv,
|
|
1822
|
+
ENV_FILE_NAME,
|
|
1823
|
+
parseEnv,
|
|
1824
|
+
loadEnvFile,
|
|
1825
|
+
LOG_LEVELS,
|
|
1826
|
+
nullLogger,
|
|
1827
|
+
createLogger,
|
|
1828
|
+
};
|
|
1745
1829
|
return src;
|
|
1746
1830
|
}
|
|
1747
1831
|
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -97,3 +97,22 @@ export declare class K3CloudError extends Error {
|
|
|
97
97
|
export declare function createClient(config?: ClientConfig): K3CloudClient;
|
|
98
98
|
|
|
99
99
|
export declare function createClientFromEnv(env?: Record<string, string>): K3CloudClient;
|
|
100
|
+
|
|
101
|
+
export declare const ENV_FILE_NAME: string;
|
|
102
|
+
|
|
103
|
+
export declare function parseEnv(text: string): Record<string, string>;
|
|
104
|
+
|
|
105
|
+
export declare function loadEnvFile(
|
|
106
|
+
dir?: string,
|
|
107
|
+
options?: { target?: Record<string, string>; override?: boolean },
|
|
108
|
+
): Record<string, string>;
|
|
109
|
+
|
|
110
|
+
export declare const ERROR_CODES: Readonly<Record<string, string>>;
|
|
111
|
+
|
|
112
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
113
|
+
|
|
114
|
+
export declare const LOG_LEVELS: readonly LogLevel[];
|
|
115
|
+
|
|
116
|
+
export declare const nullLogger: Readonly<Record<LogLevel, (record: Record<string, unknown>) => void>>;
|
|
117
|
+
|
|
118
|
+
export declare function createLogger(sink?: object): Readonly<Record<LogLevel, (record: Record<string, unknown>) => void>>;
|