@zerosls/clm-sdk 1.1.0 → 1.1.1
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/config/config.js +15 -6
- package/package.json +1 -1
- package/src/config/config.ts +17 -8
package/dist/config/config.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
+
function normalizeUrl(url) {
|
|
2
|
+
return url.trim().replace(/\/+$/, "");
|
|
3
|
+
}
|
|
4
|
+
function resolveDefaultBaseUrl() {
|
|
5
|
+
var _a;
|
|
6
|
+
const fromWindow = (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.SDK_CONFIG) === null || _a === void 0 ? void 0 : _a.API_BASE_URL;
|
|
7
|
+
if (fromWindow)
|
|
8
|
+
return normalizeUrl(String(fromWindow));
|
|
9
|
+
return "https://api.clm-app.com/api";
|
|
10
|
+
}
|
|
1
11
|
export const DEFAULT_CONFIG = {
|
|
2
|
-
baseUrl:
|
|
12
|
+
baseUrl: resolveDefaultBaseUrl(),
|
|
3
13
|
organization: "default-org",
|
|
4
|
-
cache: {
|
|
5
|
-
enabled: true,
|
|
6
|
-
ttl: 60000,
|
|
7
|
-
},
|
|
14
|
+
cache: { enabled: true, ttl: 60000 },
|
|
8
15
|
debug: true,
|
|
9
|
-
credentials:
|
|
16
|
+
credentials: "include",
|
|
10
17
|
};
|
|
11
18
|
export function mergeWithDefaultConfig(config) {
|
|
19
|
+
var _a;
|
|
12
20
|
return {
|
|
13
21
|
...DEFAULT_CONFIG,
|
|
14
22
|
...config,
|
|
23
|
+
baseUrl: normalizeUrl(String((_a = config.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.baseUrl)),
|
|
15
24
|
cache: {
|
|
16
25
|
...DEFAULT_CONFIG.cache,
|
|
17
26
|
...(config.cache || {}),
|
package/package.json
CHANGED
package/src/config/config.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
import { SdkConfig } from "../types/sdk";
|
|
2
2
|
|
|
3
|
+
function normalizeUrl(url: string) {
|
|
4
|
+
return url.trim().replace(/\/+$/, "");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function resolveDefaultBaseUrl(): string {
|
|
8
|
+
const fromWindow = (globalThis as any)?.SDK_CONFIG?.API_BASE_URL;
|
|
9
|
+
if (fromWindow) return normalizeUrl(String(fromWindow));
|
|
10
|
+
return "https://api.clm-app.com/api";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
export const DEFAULT_CONFIG: Partial<SdkConfig> = {
|
|
4
|
-
baseUrl:
|
|
15
|
+
baseUrl: resolveDefaultBaseUrl(),
|
|
5
16
|
organization: "default-org",
|
|
6
|
-
cache: {
|
|
7
|
-
enabled: true,
|
|
8
|
-
ttl: 60000,
|
|
9
|
-
},
|
|
17
|
+
cache: { enabled: true, ttl: 60000 },
|
|
10
18
|
debug: true,
|
|
11
|
-
credentials:
|
|
19
|
+
credentials: "include",
|
|
12
20
|
};
|
|
13
21
|
|
|
14
22
|
export function mergeWithDefaultConfig(config: Partial<SdkConfig>): SdkConfig {
|
|
15
23
|
return {
|
|
16
24
|
...DEFAULT_CONFIG,
|
|
17
25
|
...config,
|
|
26
|
+
baseUrl: normalizeUrl(String(config.baseUrl ?? DEFAULT_CONFIG.baseUrl)),
|
|
18
27
|
cache: {
|
|
19
28
|
...DEFAULT_CONFIG.cache,
|
|
20
29
|
...(config.cache || {}),
|
|
21
30
|
},
|
|
22
|
-
credentials: config.credentials || DEFAULT_CONFIG.credentials,
|
|
31
|
+
credentials: config.credentials || DEFAULT_CONFIG.credentials,
|
|
23
32
|
} as SdkConfig;
|
|
24
|
-
}
|
|
33
|
+
}
|