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 (engineConfig && engineConfig.graphql && metadataCache)
53
+ if (metadataCache && engineConfig)
54
54
  return;
55
55
  try {
56
- const [setupRes, metadataRes] = await Promise.all([
57
- fetcher("/api/__admin/setup"),
58
- fetcher("/api/__admin/collections")
59
- ]);
60
- engineConfig = setupRes.api || engineConfig || { rest: true, graphql: { enabled: false, path: "/graphql" } };
61
- metadataCache = metadataRes;
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, path: "/graphql" } };
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
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpacaError,
3
3
  createClient
4
- } from "./chunk-nv91gc63.js";
4
+ } from "./chunk-dz94msss.js";
5
5
  import"./chunk-2vbfc4q8.js";
6
6
  import"./chunk-8sqjbsgt.js";
7
7
  export {
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpacaError,
3
3
  createClient
4
- } from "./chunk-nv91gc63.js";
4
+ } from "./chunk-dz94msss.js";
5
5
  import {
6
6
  defineCollection,
7
7
  defineGlobal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opacacms",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "license": "MIT",
5
5
  "description": "OpacaCMS: A lightweight, type-safe, and developer-first Headless CMS for the edge and beyond.",
6
6
  "keywords": [