@seaverse/auth-sdk 0.4.1 → 0.4.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 +674 -688
- package/dist/auth-modal.css +1 -1
- package/dist/index.cjs +10 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +10 -120
- package/dist/index.js.map +1 -1
- package/dist/toast.css +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -88,12 +88,16 @@ declare class AuthFactory {
|
|
|
88
88
|
static fromEnv(): AuthProvider;
|
|
89
89
|
/**
|
|
90
90
|
* 从配置文件创建认证提供者
|
|
91
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
92
|
+
* Use AuthFactory.create() with a config object instead.
|
|
91
93
|
*/
|
|
92
|
-
static fromFile(
|
|
94
|
+
static fromFile(_path: string): Promise<AuthProvider>;
|
|
93
95
|
/**
|
|
94
96
|
* 从profile创建认证提供者
|
|
97
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
98
|
+
* Use AuthFactory.create() with a config object instead.
|
|
95
99
|
*/
|
|
96
|
-
static fromProfile(
|
|
100
|
+
static fromProfile(_profileName?: string): Promise<AuthProvider>;
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
type HookType = 'beforeRequest' | 'afterResponse' | 'onError' | 'onRetry';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import * as fs from 'fs/promises';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import * as os from 'os';
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* 生成UUID的跨平台函数
|
|
@@ -748,113 +745,6 @@ class CustomAuthProvider extends AuthProvider {
|
|
|
748
745
|
}
|
|
749
746
|
}
|
|
750
747
|
|
|
751
|
-
/**
|
|
752
|
-
* 配置管理器
|
|
753
|
-
*/
|
|
754
|
-
class ConfigManager {
|
|
755
|
-
constructor(configDir) {
|
|
756
|
-
this.configDir = configDir || path.join(os.homedir(), '.openapi-sdk');
|
|
757
|
-
this.configPath = path.join(this.configDir, 'config.json');
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* 保存认证配置
|
|
761
|
-
*/
|
|
762
|
-
async saveAuth(profileName, authConfig) {
|
|
763
|
-
await this.ensureConfigDir();
|
|
764
|
-
const config = await this.loadConfig();
|
|
765
|
-
config.profiles[profileName] = authConfig;
|
|
766
|
-
await fs.writeFile(this.configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* 加载认证配置
|
|
770
|
-
*/
|
|
771
|
-
async loadAuth(profileName) {
|
|
772
|
-
const config = await this.loadConfig();
|
|
773
|
-
const authConfig = config.profiles[profileName];
|
|
774
|
-
if (!authConfig) {
|
|
775
|
-
throw new Error(`Profile '${profileName}' not found`);
|
|
776
|
-
}
|
|
777
|
-
return authConfig;
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* 列出所有profile
|
|
781
|
-
*/
|
|
782
|
-
async listProfiles() {
|
|
783
|
-
const config = await this.loadConfig();
|
|
784
|
-
return Object.keys(config.profiles);
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* 删除profile
|
|
788
|
-
*/
|
|
789
|
-
async removeProfile(profileName) {
|
|
790
|
-
const config = await this.loadConfig();
|
|
791
|
-
delete config.profiles[profileName];
|
|
792
|
-
await fs.writeFile(this.configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* 从文件加载配置
|
|
796
|
-
*/
|
|
797
|
-
async loadFromFile(filePath) {
|
|
798
|
-
try {
|
|
799
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
800
|
-
return JSON.parse(content);
|
|
801
|
-
}
|
|
802
|
-
catch (error) {
|
|
803
|
-
throw new Error(`Failed to load config from ${filePath}: ${error}`);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* 保存配置到文件
|
|
808
|
-
*/
|
|
809
|
-
async saveToFile(filePath, authConfig) {
|
|
810
|
-
try {
|
|
811
|
-
await fs.writeFile(filePath, JSON.stringify(authConfig, null, 2), 'utf-8');
|
|
812
|
-
}
|
|
813
|
-
catch (error) {
|
|
814
|
-
throw new Error(`Failed to save config to ${filePath}: ${error}`);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* 加载完整配置文件
|
|
819
|
-
*/
|
|
820
|
-
async loadConfig() {
|
|
821
|
-
try {
|
|
822
|
-
const content = await fs.readFile(this.configPath, 'utf-8');
|
|
823
|
-
return JSON.parse(content);
|
|
824
|
-
}
|
|
825
|
-
catch (error) {
|
|
826
|
-
if (error.code === 'ENOENT') {
|
|
827
|
-
// 文件不存在,返回默认配置
|
|
828
|
-
return { profiles: {} };
|
|
829
|
-
}
|
|
830
|
-
throw error;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* 确保配置目录存在
|
|
835
|
-
*/
|
|
836
|
-
async ensureConfigDir() {
|
|
837
|
-
try {
|
|
838
|
-
await fs.mkdir(this.configDir, { recursive: true });
|
|
839
|
-
}
|
|
840
|
-
catch (error) {
|
|
841
|
-
// 忽略错误,可能目录已存在
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
/**
|
|
845
|
-
* 获取配置目录路径
|
|
846
|
-
*/
|
|
847
|
-
getConfigDir() {
|
|
848
|
-
return this.configDir;
|
|
849
|
-
}
|
|
850
|
-
/**
|
|
851
|
-
* 获取配置文件路径
|
|
852
|
-
*/
|
|
853
|
-
getConfigPath() {
|
|
854
|
-
return this.configPath;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
|
|
858
748
|
/**
|
|
859
749
|
* 跨平台环境配置工具
|
|
860
750
|
* 支持 Node.js 和浏览器环境
|
|
@@ -987,19 +877,19 @@ class AuthFactory {
|
|
|
987
877
|
}
|
|
988
878
|
/**
|
|
989
879
|
* 从配置文件创建认证提供者
|
|
880
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
881
|
+
* Use AuthFactory.create() with a config object instead.
|
|
990
882
|
*/
|
|
991
|
-
static async fromFile(
|
|
992
|
-
|
|
993
|
-
const config = await configManager.loadFromFile(path);
|
|
994
|
-
return this.create(config);
|
|
883
|
+
static async fromFile(_path) {
|
|
884
|
+
throw new Error('AuthFactory.fromFile() is not available in browser environments. Please use AuthFactory.create() instead.');
|
|
995
885
|
}
|
|
996
886
|
/**
|
|
997
887
|
* 从profile创建认证提供者
|
|
888
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
889
|
+
* Use AuthFactory.create() with a config object instead.
|
|
998
890
|
*/
|
|
999
|
-
static async fromProfile(
|
|
1000
|
-
|
|
1001
|
-
const config = await configManager.loadAuth(profileName);
|
|
1002
|
-
return this.create(config);
|
|
891
|
+
static async fromProfile(_profileName = 'default') {
|
|
892
|
+
throw new Error('AuthFactory.fromProfile() is not available in browser environments. Please use AuthFactory.create() instead.');
|
|
1003
893
|
}
|
|
1004
894
|
}
|
|
1005
895
|
|
|
@@ -1031,8 +921,8 @@ const ENVIRONMENT_CONFIGS = {
|
|
|
1031
921
|
},
|
|
1032
922
|
development: {
|
|
1033
923
|
name: 'development',
|
|
1034
|
-
baseURL: 'https://
|
|
1035
|
-
wsURL: 'wss://
|
|
924
|
+
baseURL: 'https://account-hub.sg.seaverse.dev',
|
|
925
|
+
wsURL: 'wss://account-hub.sg.seaverse.dev',
|
|
1036
926
|
isProduction: false,
|
|
1037
927
|
},
|
|
1038
928
|
local: {
|