@seaverse/auth-sdk 0.4.4 → 0.4.5
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.cjs +8 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +8 -118
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var axios = require('axios');
|
|
4
|
-
var fs = require('fs/promises');
|
|
5
|
-
var path = require('path');
|
|
6
|
-
var os = require('os');
|
|
7
|
-
|
|
8
|
-
function _interopNamespaceDefault(e) {
|
|
9
|
-
var n = Object.create(null);
|
|
10
|
-
if (e) {
|
|
11
|
-
Object.keys(e).forEach(function (k) {
|
|
12
|
-
if (k !== 'default') {
|
|
13
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return e[k]; }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
n.default = e;
|
|
22
|
-
return Object.freeze(n);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
26
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
27
|
-
var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
|
|
28
4
|
|
|
29
5
|
/**
|
|
30
6
|
* 生成UUID的跨平台函数
|
|
@@ -771,113 +747,6 @@ class CustomAuthProvider extends AuthProvider {
|
|
|
771
747
|
}
|
|
772
748
|
}
|
|
773
749
|
|
|
774
|
-
/**
|
|
775
|
-
* 配置管理器
|
|
776
|
-
*/
|
|
777
|
-
class ConfigManager {
|
|
778
|
-
constructor(configDir) {
|
|
779
|
-
this.configDir = configDir || path__namespace.join(os__namespace.homedir(), '.openapi-sdk');
|
|
780
|
-
this.configPath = path__namespace.join(this.configDir, 'config.json');
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* 保存认证配置
|
|
784
|
-
*/
|
|
785
|
-
async saveAuth(profileName, authConfig) {
|
|
786
|
-
await this.ensureConfigDir();
|
|
787
|
-
const config = await this.loadConfig();
|
|
788
|
-
config.profiles[profileName] = authConfig;
|
|
789
|
-
await fs__namespace.writeFile(this.configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* 加载认证配置
|
|
793
|
-
*/
|
|
794
|
-
async loadAuth(profileName) {
|
|
795
|
-
const config = await this.loadConfig();
|
|
796
|
-
const authConfig = config.profiles[profileName];
|
|
797
|
-
if (!authConfig) {
|
|
798
|
-
throw new Error(`Profile '${profileName}' not found`);
|
|
799
|
-
}
|
|
800
|
-
return authConfig;
|
|
801
|
-
}
|
|
802
|
-
/**
|
|
803
|
-
* 列出所有profile
|
|
804
|
-
*/
|
|
805
|
-
async listProfiles() {
|
|
806
|
-
const config = await this.loadConfig();
|
|
807
|
-
return Object.keys(config.profiles);
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* 删除profile
|
|
811
|
-
*/
|
|
812
|
-
async removeProfile(profileName) {
|
|
813
|
-
const config = await this.loadConfig();
|
|
814
|
-
delete config.profiles[profileName];
|
|
815
|
-
await fs__namespace.writeFile(this.configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* 从文件加载配置
|
|
819
|
-
*/
|
|
820
|
-
async loadFromFile(filePath) {
|
|
821
|
-
try {
|
|
822
|
-
const content = await fs__namespace.readFile(filePath, 'utf-8');
|
|
823
|
-
return JSON.parse(content);
|
|
824
|
-
}
|
|
825
|
-
catch (error) {
|
|
826
|
-
throw new Error(`Failed to load config from ${filePath}: ${error}`);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* 保存配置到文件
|
|
831
|
-
*/
|
|
832
|
-
async saveToFile(filePath, authConfig) {
|
|
833
|
-
try {
|
|
834
|
-
await fs__namespace.writeFile(filePath, JSON.stringify(authConfig, null, 2), 'utf-8');
|
|
835
|
-
}
|
|
836
|
-
catch (error) {
|
|
837
|
-
throw new Error(`Failed to save config to ${filePath}: ${error}`);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* 加载完整配置文件
|
|
842
|
-
*/
|
|
843
|
-
async loadConfig() {
|
|
844
|
-
try {
|
|
845
|
-
const content = await fs__namespace.readFile(this.configPath, 'utf-8');
|
|
846
|
-
return JSON.parse(content);
|
|
847
|
-
}
|
|
848
|
-
catch (error) {
|
|
849
|
-
if (error.code === 'ENOENT') {
|
|
850
|
-
// 文件不存在,返回默认配置
|
|
851
|
-
return { profiles: {} };
|
|
852
|
-
}
|
|
853
|
-
throw error;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* 确保配置目录存在
|
|
858
|
-
*/
|
|
859
|
-
async ensureConfigDir() {
|
|
860
|
-
try {
|
|
861
|
-
await fs__namespace.mkdir(this.configDir, { recursive: true });
|
|
862
|
-
}
|
|
863
|
-
catch (error) {
|
|
864
|
-
// 忽略错误,可能目录已存在
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
/**
|
|
868
|
-
* 获取配置目录路径
|
|
869
|
-
*/
|
|
870
|
-
getConfigDir() {
|
|
871
|
-
return this.configDir;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* 获取配置文件路径
|
|
875
|
-
*/
|
|
876
|
-
getConfigPath() {
|
|
877
|
-
return this.configPath;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
|
|
881
750
|
/**
|
|
882
751
|
* 跨平台环境配置工具
|
|
883
752
|
* 支持 Node.js 和浏览器环境
|
|
@@ -1010,19 +879,19 @@ class AuthFactory {
|
|
|
1010
879
|
}
|
|
1011
880
|
/**
|
|
1012
881
|
* 从配置文件创建认证提供者
|
|
882
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
883
|
+
* Use AuthFactory.create() with a config object instead.
|
|
1013
884
|
*/
|
|
1014
|
-
static async fromFile(
|
|
1015
|
-
|
|
1016
|
-
const config = await configManager.loadFromFile(path);
|
|
1017
|
-
return this.create(config);
|
|
885
|
+
static async fromFile(_path) {
|
|
886
|
+
throw new Error('AuthFactory.fromFile() is not available in browser environments. Please use AuthFactory.create() instead.');
|
|
1018
887
|
}
|
|
1019
888
|
/**
|
|
1020
889
|
* 从profile创建认证提供者
|
|
890
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
891
|
+
* Use AuthFactory.create() with a config object instead.
|
|
1021
892
|
*/
|
|
1022
|
-
static async fromProfile(
|
|
1023
|
-
|
|
1024
|
-
const config = await configManager.loadAuth(profileName);
|
|
1025
|
-
return this.create(config);
|
|
893
|
+
static async fromProfile(_profileName = 'default') {
|
|
894
|
+
throw new Error('AuthFactory.fromProfile() is not available in browser environments. Please use AuthFactory.create() instead.');
|
|
1026
895
|
}
|
|
1027
896
|
}
|
|
1028
897
|
|