@unchainedshop/cockpit-api 2.4.1 → 2.4.2
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/client.js +1 -1
- package/dist/core/config.d.ts +18 -0
- package/dist/core/config.js +2 -0
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -79,7 +79,7 @@ export async function CockpitAPI(options = {}) {
|
|
|
79
79
|
: {};
|
|
80
80
|
// Create response transformer
|
|
81
81
|
const transformerConfig = {
|
|
82
|
-
baseUrl: config.endpoint.origin,
|
|
82
|
+
baseUrl: config.publicUrl ?? config.endpoint.origin,
|
|
83
83
|
replacements: routeReplacements,
|
|
84
84
|
};
|
|
85
85
|
if (options.tenant)
|
package/dist/core/config.d.ts
CHANGED
|
@@ -71,6 +71,23 @@ export interface CockpitAPIOptions {
|
|
|
71
71
|
* ```
|
|
72
72
|
*/
|
|
73
73
|
cache?: false | CacheOptions;
|
|
74
|
+
/**
|
|
75
|
+
* Public URL for asset path rewriting.
|
|
76
|
+
* When using an internal/Docker endpoint (e.g. http://cms:80/api/gql), asset paths
|
|
77
|
+
* would contain the internal hostname. Set this to the public-facing URL so that
|
|
78
|
+
* asset paths use the correct origin in responses.
|
|
79
|
+
*
|
|
80
|
+
* Falls back to COCKPIT_PUBLIC_URL env var. When omitted, uses endpoint.origin.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const client = await CockpitAPI({
|
|
85
|
+
* endpoint: 'http://cms-internal:80/api/gql', // internal
|
|
86
|
+
* publicUrl: 'https://cms.example.com', // public-facing
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
publicUrl?: string;
|
|
74
91
|
/**
|
|
75
92
|
* Preload route replacements during client initialization.
|
|
76
93
|
* When true, fetches page routes to enable `pages://id` link resolution in responses.
|
|
@@ -85,6 +102,7 @@ export interface CockpitConfig {
|
|
|
85
102
|
readonly apiKey?: string;
|
|
86
103
|
readonly useAdminAccess: boolean;
|
|
87
104
|
readonly defaultLanguage: string | null;
|
|
105
|
+
readonly publicUrl?: string;
|
|
88
106
|
readonly cachePrefix: string;
|
|
89
107
|
}
|
|
90
108
|
/**
|
package/dist/core/config.js
CHANGED
|
@@ -22,6 +22,7 @@ export function createConfig(options = {}) {
|
|
|
22
22
|
}
|
|
23
23
|
const endpoint = new URL(endpointStr);
|
|
24
24
|
const apiKey = resolveApiKey(tenant, options);
|
|
25
|
+
const publicUrl = options.publicUrl ?? process.env["COCKPIT_PUBLIC_URL"] ?? undefined;
|
|
25
26
|
// Build config object with all properties before freezing
|
|
26
27
|
const config = Object.freeze({
|
|
27
28
|
endpoint,
|
|
@@ -30,6 +31,7 @@ export function createConfig(options = {}) {
|
|
|
30
31
|
cachePrefix: `${endpointStr}:${tenant ?? "default"}:`,
|
|
31
32
|
...(tenant && { tenant }),
|
|
32
33
|
...(apiKey !== undefined && { apiKey }),
|
|
34
|
+
...(publicUrl !== undefined && { publicUrl }),
|
|
33
35
|
});
|
|
34
36
|
return config;
|
|
35
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/cockpit-api",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "A package to interact with the Cockpit CMS API, including functionalities to handle GraphQL requests and various CMS content manipulations.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"homepage": "https://unchained.shop",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": ">=25"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@unchainedshop/logger": "^4.6.2",
|