@remkoj/optimizely-cms-nextjs 5.3.1 → 5.3.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 +7 -7
- package/dist/client.js +24 -15
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +5 -5
package/dist/client.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
-
import { type IOptiGraphClient, type OptimizelyGraphConfig } from '@remkoj/optimizely-graph-client';
|
|
2
|
+
import { type IOptiGraphClient, type OptimizelyGraphConfig, type IOptiGraphClientFlags } from '@remkoj/optimizely-graph-client';
|
|
3
|
+
import type { ClientFactory } from './types.js';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
* exported from `@remkoj/optimizely-graph-client`.
|
|
5
|
+
* Default implementation of the `ClientFactory` interface
|
|
6
6
|
*
|
|
7
7
|
* @returns The newly created GraphQL Client
|
|
8
8
|
*/
|
|
9
|
-
export declare
|
|
9
|
+
export declare const createClient: ClientFactory;
|
|
10
10
|
/**
|
|
11
11
|
* Create a new client instance, with the needed configuration to access restricted content. This
|
|
12
12
|
* wraps the `createClient` function from `@remkoj/optimizely-graph-client` and applies some
|
|
@@ -14,7 +14,7 @@ export declare function createClient(): IOptiGraphClient;
|
|
|
14
14
|
*
|
|
15
15
|
* @returns The newly created GraphQL Client
|
|
16
16
|
*/
|
|
17
|
-
export declare function createAuthorizedClient(token?: string, config?: OptimizelyGraphConfig): IOptiGraphClient;
|
|
17
|
+
export declare function createAuthorizedClient(token?: string, config?: OptimizelyGraphConfig, flags?: Partial<IOptiGraphClientFlags>): IOptiGraphClient;
|
|
18
18
|
/**
|
|
19
19
|
* Create a new client instance, with the needed configuration to access restricted content. This
|
|
20
20
|
* wraps the `createClient` function from `@remkoj/optimizely-graph-client` and applies some
|
|
@@ -28,8 +28,8 @@ export declare const getAuthorizedServerClient: typeof createAuthorizedClient;
|
|
|
28
28
|
* Create a new client instance. This is a direct wrapper for the `createClient` function
|
|
29
29
|
* exported from `@remkoj/optimizely-graph-client`.
|
|
30
30
|
*
|
|
31
|
-
* @deprecated use
|
|
31
|
+
* @deprecated use createAuthorizedClient
|
|
32
32
|
* @returns The newly created GraphQL Client
|
|
33
33
|
*/
|
|
34
|
-
export declare const getServerClient:
|
|
34
|
+
export declare const getServerClient: ClientFactory;
|
|
35
35
|
export default createClient;
|
package/dist/client.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
-
import {
|
|
2
|
+
import { draftMode } from 'next/headers.js';
|
|
3
|
+
import { createClient as createBaseClient, AuthMode, } from '@remkoj/optimizely-graph-client';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
* exported from `@remkoj/optimizely-graph-client`.
|
|
5
|
+
* Default implementation of the `ClientFactory` interface
|
|
6
6
|
*
|
|
7
7
|
* @returns The newly created GraphQL Client
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export const createClient = (token, mode) => {
|
|
10
|
+
const client = createAuthorizedClient(token || undefined);
|
|
11
|
+
if (mode === 'request') {
|
|
12
|
+
const { isEnabled } = draftMode();
|
|
13
|
+
if (isEnabled && client.currentAuthMode === AuthMode.Public) {
|
|
14
|
+
client.updateAuthentication(AuthMode.HMAC);
|
|
15
|
+
client.enablePreview();
|
|
16
|
+
console.info('🔐 [ContentGraph Client] Switching to common drafts');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
console.warn(`⚠️ [ContentGraph Client] DraftMode ignored for authorized requests, current mode ${client.currentAuthMode}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return client;
|
|
23
|
+
};
|
|
12
24
|
/**
|
|
13
25
|
* Create a new client instance, with the needed configuration to access restricted content. This
|
|
14
26
|
* wraps the `createClient` function from `@remkoj/optimizely-graph-client` and applies some
|
|
@@ -16,10 +28,9 @@ export function createClient() {
|
|
|
16
28
|
*
|
|
17
29
|
* @returns The newly created GraphQL Client
|
|
18
30
|
*/
|
|
19
|
-
export function createAuthorizedClient(token, config) {
|
|
20
|
-
const client = createBaseClient(config);
|
|
21
|
-
|
|
22
|
-
console.log('⚪ [ContentGraph Client] Created new Optimizely Graph client');
|
|
31
|
+
export function createAuthorizedClient(token, config, flags) {
|
|
32
|
+
const client = createBaseClient(config, undefined, { nextJsFetchDirectives: true, ...flags });
|
|
33
|
+
console.info('⚪ [ContentGraph Client] Created new Optimizely Graph client');
|
|
23
34
|
// Apply token if needed
|
|
24
35
|
if (typeof (token) == 'string' && token.length > 0) {
|
|
25
36
|
if (token == client.siteInfo.publishToken) {
|
|
@@ -29,10 +40,8 @@ export function createAuthorizedClient(token, config) {
|
|
|
29
40
|
else {
|
|
30
41
|
client.updateAuthentication(token);
|
|
31
42
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.log('⚪ [ContentGraph Client] Setting disable cache feature flags');
|
|
35
|
-
}
|
|
43
|
+
console.warn(`🔐 [ContentGraph Client] Updated authentication, current mode: ${client.currentAuthMode}`);
|
|
44
|
+
console.debug('⚪ [ContentGraph Client] Setting disable cache feature flags');
|
|
36
45
|
client.updateFlags({ cache: false, cache_uniq: false, queryCache: false }, false);
|
|
37
46
|
}
|
|
38
47
|
return client;
|
|
@@ -50,7 +59,7 @@ export const getAuthorizedServerClient = createAuthorizedClient;
|
|
|
50
59
|
* Create a new client instance. This is a direct wrapper for the `createClient` function
|
|
51
60
|
* exported from `@remkoj/optimizely-graph-client`.
|
|
52
61
|
*
|
|
53
|
-
* @deprecated use
|
|
62
|
+
* @deprecated use createAuthorizedClient
|
|
54
63
|
* @returns The newly created GraphQL Client
|
|
55
64
|
*/
|
|
56
65
|
export const getServerClient = createClient;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names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,OAAO,CAAC,KAAK,CAAC,IAAI,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnD,IAAI,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1C,OAAO,CAAC,IAAI,CAAC,2FAA2F,CAAC,CAAA;YACzG,MAAM,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAA;QACpC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,kEAAkE,MAAM,CAAC,eAAe,EAAE,CAAC,CAAA;QACxG,OAAO,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAA;QAC5E,MAAM,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,CAAA;IACnF,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAA;AAE/D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAA;AAE3C,eAAe,YAAY,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ import type { Metadata } from 'next';
|
|
|
4
4
|
export type OptimizelyNextPage<T = {}> = CmsComponent<T> & {
|
|
5
5
|
getMetaData?: (contentLink: ContentLink, locale: string | null | undefined, client: IOptiGraphClient) => Promise<Metadata>;
|
|
6
6
|
};
|
|
7
|
+
export type ClientFactory = (token?: string, scope?: 'request' | 'metadata') => IOptiGraphClient;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@remkoj/optimizely-cms-nextjs",
|
|
3
3
|
"description": "Next.JS integration for Optimizely SaaS CMS",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "5.3.
|
|
5
|
+
"version": "5.3.2",
|
|
6
6
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
7
7
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
8
8
|
"homepage": "https://github.com/remkoj/optimizely-dxp-clients",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@remkoj/optimizely-cms-react": "5.3.
|
|
48
|
-
"@remkoj/optimizely-graph-client": "5.3.
|
|
47
|
+
"@remkoj/optimizely-cms-react": "5.3.2",
|
|
48
|
+
"@remkoj/optimizely-graph-client": "5.3.2",
|
|
49
49
|
"@types/negotiator": "^0.6.4",
|
|
50
50
|
"@types/node": "^22.19.3",
|
|
51
51
|
"@types/react": "^18.3.27",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"negotiator": "^1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@remkoj/optimizely-cms-react": "^5.3.
|
|
69
|
-
"@remkoj/optimizely-graph-client": "^5.3.
|
|
68
|
+
"@remkoj/optimizely-cms-react": "^5.3.2",
|
|
69
|
+
"@remkoj/optimizely-graph-client": "^5.3.2",
|
|
70
70
|
"graphql": "^16",
|
|
71
71
|
"graphql-request": "^6",
|
|
72
72
|
"next": "^14",
|