talizen 0.0.8 → 0.0.10
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/core.d.ts +3 -0
- package/core.js +8 -7
- package/package.json +1 -1
package/core.d.ts
CHANGED
|
@@ -21,5 +21,8 @@ export interface TalizenRequestOptions extends TalizenClientConfig {
|
|
|
21
21
|
}
|
|
22
22
|
export declare function setTalizenConfig(config: TalizenClientConfig): void;
|
|
23
23
|
export declare function getTalizenConfig(): TalizenClientConfig;
|
|
24
|
+
declare global {
|
|
25
|
+
var TalizenConfig: TalizenClientConfig | undefined;
|
|
26
|
+
}
|
|
24
27
|
export declare function resolveTalizenConfig(config?: TalizenRequestOptions): Required<Pick<TalizenClientConfig, "baseUrl" | "fetch">> & TalizenRequestOptions;
|
|
25
28
|
export declare function requestJson<T>(path: string, init?: RequestInit, config?: TalizenRequestOptions): Promise<T>;
|
package/core.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
let
|
|
1
|
+
let talizenConfig = {};
|
|
2
2
|
export function setTalizenConfig(config) {
|
|
3
|
-
|
|
4
|
-
...
|
|
3
|
+
talizenConfig = {
|
|
4
|
+
...talizenConfig,
|
|
5
5
|
...config,
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
8
|
export function getTalizenConfig() {
|
|
9
|
-
return
|
|
10
|
-
...globalTalizenConfig,
|
|
11
|
-
};
|
|
9
|
+
return talizenConfig;
|
|
12
10
|
}
|
|
13
11
|
export function resolveTalizenConfig(config) {
|
|
12
|
+
// globalThis is the global object in the browser and node.js
|
|
13
|
+
const globalTalizenConfig = typeof globalThis !== "undefined" ? globalThis.TalizenConfig : {};
|
|
14
14
|
const merged = {
|
|
15
15
|
...globalTalizenConfig,
|
|
16
|
+
...talizenConfig,
|
|
16
17
|
...config,
|
|
17
18
|
};
|
|
18
19
|
const baseUrl = merged.baseUrl ?? getDefaultBaseUrl();
|
|
@@ -62,7 +63,7 @@ function getDefaultBaseUrl() {
|
|
|
62
63
|
if (typeof window !== "undefined" && window.location?.origin) {
|
|
63
64
|
return window.location.origin;
|
|
64
65
|
}
|
|
65
|
-
throw new Error("Talizen baseUrl is required.
|
|
66
|
+
throw new Error("Talizen baseUrl is required. set window.TalizenConfig = { baseUrl: 'https://example.com' } first.");
|
|
66
67
|
}
|
|
67
68
|
function getDefaultFetch() {
|
|
68
69
|
if (typeof fetch === "function") {
|