@unchainedshop/cockpit-api 2.4.0 → 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.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/core/config.d.ts +18 -0
- package/dist/core/config.js +2 -0
- package/dist/methods/graphql.d.ts +1 -1
- package/dist/methods/graphql.js +8 -3
- package/dist/schema/executor.d.ts +1 -0
- package/dist/schema/executor.js +2 -2
- package/package.json +9 -9
package/dist/client.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { type LocalizeOptions } from "./methods/localize.ts";
|
|
|
14
14
|
* Cockpit API Client interface
|
|
15
15
|
*/
|
|
16
16
|
export interface CockpitAPIClient {
|
|
17
|
-
graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown
|
|
17
|
+
graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown>, operationName?: string): Promise<T | null>;
|
|
18
18
|
getContentItem<T = unknown>(options: ContentItemQueryOptions): Promise<T | null>;
|
|
19
19
|
getContentItems<T = CockpitContentItem>(model: string, options?: ContentListQueryOptions): Promise<CockpitListResponse<T> | null>;
|
|
20
20
|
/**
|
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
|
}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
import { type DocumentNode } from "graphql";
|
|
5
5
|
import type { MethodContext } from "./content.ts";
|
|
6
6
|
export interface GraphQLMethods {
|
|
7
|
-
graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown
|
|
7
|
+
graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown>, operationName?: string): Promise<T | null>;
|
|
8
8
|
}
|
|
9
9
|
export declare function createGraphQLMethods(ctx: MethodContext): GraphQLMethods;
|
package/dist/methods/graphql.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* GraphQL API method
|
|
3
3
|
*/
|
|
4
|
-
import { print } from "graphql";
|
|
4
|
+
import { print, getOperationAST } from "graphql";
|
|
5
5
|
export function createGraphQLMethods(ctx) {
|
|
6
6
|
return {
|
|
7
|
-
async graphQL(document, variables) {
|
|
7
|
+
async graphQL(document, variables, operationName) {
|
|
8
8
|
const query = print(document);
|
|
9
|
+
const resolvedOperationName = operationName ?? getOperationAST(document)?.name?.value;
|
|
9
10
|
const endpoint = ctx.url.graphqlEndpoint();
|
|
10
|
-
return ctx.http.post(endpoint, {
|
|
11
|
+
return ctx.http.post(endpoint, {
|
|
12
|
+
query,
|
|
13
|
+
variables,
|
|
14
|
+
operationName: resolvedOperationName,
|
|
15
|
+
});
|
|
11
16
|
},
|
|
12
17
|
};
|
|
13
18
|
}
|
package/dist/schema/executor.js
CHANGED
|
@@ -72,7 +72,7 @@ export function createRemoteExecutor(options = {}) {
|
|
|
72
72
|
pendingClients.delete(key);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
return async ({ document, variables, context }) => {
|
|
75
|
+
return async ({ document, variables, operationName, context, }) => {
|
|
76
76
|
// Extract tenant from context
|
|
77
77
|
const tenant = extractTenant
|
|
78
78
|
? extractTenant(context)
|
|
@@ -80,6 +80,6 @@ export function createRemoteExecutor(options = {}) {
|
|
|
80
80
|
// Get or create pooled client
|
|
81
81
|
const cockpit = await getOrCreateClient(tenant);
|
|
82
82
|
// Execute GraphQL query
|
|
83
|
-
return cockpit.graphQL(document, variables);
|
|
83
|
+
return cockpit.graphQL(document, variables, operationName);
|
|
84
84
|
};
|
|
85
85
|
}
|
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,11 +47,11 @@
|
|
|
47
47
|
],
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": ">=25"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@unchainedshop/logger": "^4.6.
|
|
54
|
-
"lru-cache": "^11.2.
|
|
53
|
+
"@unchainedshop/logger": "^4.6.2",
|
|
54
|
+
"lru-cache": "^11.2.6"
|
|
55
55
|
},
|
|
56
56
|
"types": "dist/index.d.ts",
|
|
57
57
|
"peerDependencies": {
|
|
@@ -68,13 +68,13 @@
|
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@eslint/js": "^9.39.2",
|
|
71
|
-
"@types/node": "^
|
|
71
|
+
"@types/node": "^25.3.1",
|
|
72
72
|
"eslint": "^9.39.2",
|
|
73
73
|
"eslint-config-prettier": "^10.1.8",
|
|
74
|
-
"eslint-plugin-prettier": "^5.5.
|
|
75
|
-
"graphql": "^16.
|
|
76
|
-
"prettier": "^3.
|
|
74
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
75
|
+
"graphql": "^16.13.0",
|
|
76
|
+
"prettier": "^3.8.1",
|
|
77
77
|
"typescript": "^5.9.3",
|
|
78
|
-
"typescript-eslint": "^8.
|
|
78
|
+
"typescript-eslint": "^8.56.1"
|
|
79
79
|
}
|
|
80
80
|
}
|