opacacms 0.3.15 → 0.3.16
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.
|
@@ -31,7 +31,7 @@ function createClient(configOrOptions) {
|
|
|
31
31
|
};
|
|
32
32
|
if (options.token) {
|
|
33
33
|
headers.Authorization = `Bearer ${options.token}`;
|
|
34
|
-
}
|
|
34
|
+
} else if (typeof window !== "undefined") {}
|
|
35
35
|
return headers;
|
|
36
36
|
};
|
|
37
37
|
const fetcher = async (path, init) => {
|
|
@@ -50,19 +50,35 @@ function createClient(configOrOptions) {
|
|
|
50
50
|
return res.json();
|
|
51
51
|
};
|
|
52
52
|
const initConfig = async () => {
|
|
53
|
-
if (
|
|
53
|
+
if (metadataCache && engineConfig)
|
|
54
54
|
return;
|
|
55
55
|
try {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
const setupRes = await fetcher("/api/__admin/setup").catch(() => null);
|
|
57
|
+
if (setupRes?.api) {
|
|
58
|
+
engineConfig = {
|
|
59
|
+
...engineConfig || {},
|
|
60
|
+
...setupRes.api,
|
|
61
|
+
rest: setupRes.api.rest !== undefined ? setupRes.api.rest : engineConfig?.rest,
|
|
62
|
+
graphql: {
|
|
63
|
+
...engineConfig?.graphql || {},
|
|
64
|
+
...setupRes.api.graphql || {}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
engineConfig = engineConfig || { rest: { enabled: true }, graphql: { enabled: false } };
|
|
69
|
+
}
|
|
70
|
+
const metadataRes = await fetcher("/api/__admin/collections").catch(() => null);
|
|
71
|
+
if (metadataRes && metadataRes.collections) {
|
|
72
|
+
metadataCache = metadataRes;
|
|
73
|
+
} else {
|
|
74
|
+
const localCols = configOrOptions.collections || [];
|
|
75
|
+
const localGlobals = configOrOptions.globals || [];
|
|
76
|
+
metadataCache = { collections: localCols, globals: localGlobals };
|
|
77
|
+
}
|
|
62
78
|
} catch (e) {
|
|
63
79
|
const localCols = configOrOptions.collections || [];
|
|
64
80
|
const localGlobals = configOrOptions.globals || [];
|
|
65
|
-
engineConfig = engineConfig || { rest: true, graphql: { enabled: false
|
|
81
|
+
engineConfig = engineConfig || { rest: { enabled: true }, graphql: { enabled: false } };
|
|
66
82
|
metadataCache = { collections: localCols, globals: localGlobals };
|
|
67
83
|
}
|
|
68
84
|
};
|
package/dist/client.js
CHANGED
package/dist/index.js
CHANGED