@enonic/nextjs-adapter 5.0.0-beta.2 → 6.0.0-beta.1

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.
Files changed (86) hide show
  1. package/README.md +155 -129
  2. package/dist/common/UrlProcessor.d.ts +2 -8
  3. package/dist/common/UrlProcessor.js +33 -90
  4. package/dist/common/UrlProcessor.js.map +1 -1
  5. package/dist/common/constants.d.ts +2 -1
  6. package/dist/common/constants.js +26 -25
  7. package/dist/common/constants.js.map +1 -1
  8. package/dist/guillotine/buildErrorResponse.d.ts +1 -1
  9. package/dist/guillotine/buildErrorResponse.js +4 -2
  10. package/dist/guillotine/buildErrorResponse.js.map +1 -1
  11. package/dist/guillotine/collectComponentDescriptors.d.ts +5 -3
  12. package/dist/guillotine/collectComponentDescriptors.js +5 -3
  13. package/dist/guillotine/collectComponentDescriptors.js.map +1 -1
  14. package/dist/guillotine/combineMultipleQueries.js +22 -13
  15. package/dist/guillotine/combineMultipleQueries.js.map +1 -1
  16. package/dist/guillotine/createMetaData.d.ts +4 -2
  17. package/dist/guillotine/createMetaData.js +4 -2
  18. package/dist/guillotine/createMetaData.js.map +1 -1
  19. package/dist/guillotine/fetchContent.js +27 -17
  20. package/dist/guillotine/fetchContent.js.map +1 -1
  21. package/dist/guillotine/fetchContentData.d.ts +1 -1
  22. package/dist/guillotine/fetchContentData.js +12 -4
  23. package/dist/guillotine/fetchContentData.js.map +1 -1
  24. package/dist/guillotine/fetchContentPathsForAllLocales.d.ts +1 -1
  25. package/dist/guillotine/fetchContentPathsForAllLocales.js +3 -3
  26. package/dist/guillotine/fetchContentPathsForAllLocales.js.map +1 -1
  27. package/dist/guillotine/fetchContentPathsForLocale.d.ts +1 -1
  28. package/dist/guillotine/fetchContentPathsForLocale.js +13 -13
  29. package/dist/guillotine/fetchContentPathsForLocale.js.map +1 -1
  30. package/dist/guillotine/fetchFromApi.d.ts +2 -2
  31. package/dist/guillotine/fetchFromApi.js +3 -5
  32. package/dist/guillotine/fetchFromApi.js.map +1 -1
  33. package/dist/guillotine/fetchGuillotine.d.ts +2 -2
  34. package/dist/guillotine/fetchGuillotine.js +2 -2
  35. package/dist/guillotine/fetchGuillotine.js.map +1 -1
  36. package/dist/guillotine/fetchMetaData.d.ts +1 -1
  37. package/dist/guillotine/fetchMetaData.js +6 -3
  38. package/dist/guillotine/fetchMetaData.js.map +1 -1
  39. package/dist/guillotine/getMetaData.d.ts +2 -0
  40. package/dist/guillotine/getMetaData.js +17 -10
  41. package/dist/guillotine/getMetaData.js.map +1 -1
  42. package/dist/guillotine/getQueryAndVariables.d.ts +2 -2
  43. package/dist/guillotine/getQueryAndVariables.js +12 -5
  44. package/dist/guillotine/getQueryAndVariables.js.map +1 -1
  45. package/dist/guillotine/{getCleanContentPathArrayOrThrow400.d.ts → getSiteRelativePathOrThrow.d.ts} +1 -1
  46. package/dist/guillotine/{getCleanContentPathArrayOrThrow400.js → getSiteRelativePathOrThrow.js} +2 -2
  47. package/dist/guillotine/getSiteRelativePathOrThrow.js.map +1 -0
  48. package/dist/guillotine/metadata/richTextQuery.js +1 -0
  49. package/dist/guillotine/metadata/richTextQuery.js.map +1 -1
  50. package/dist/guillotine/validateShortcut.js +3 -3
  51. package/dist/guillotine/validateShortcut.js.map +1 -1
  52. package/dist/index.d.ts +4 -2
  53. package/dist/index.js +4 -2
  54. package/dist/index.js.map +1 -1
  55. package/dist/query/Shortcut.d.ts +1 -1
  56. package/dist/query/Shortcut.js +11 -15
  57. package/dist/query/Shortcut.js.map +1 -1
  58. package/dist/types/component.d.ts +9 -6
  59. package/dist/types/componentProps.d.ts +4 -4
  60. package/dist/types/guillotine.d.ts +0 -1
  61. package/dist/utils/decryptParams.d.ts +1 -0
  62. package/dist/utils/decryptParams.js +20 -0
  63. package/dist/utils/decryptParams.js.map +1 -0
  64. package/dist/utils/encryptParams.d.ts +1 -0
  65. package/dist/utils/encryptParams.js +12 -0
  66. package/dist/utils/encryptParams.js.map +1 -0
  67. package/dist/utils/fixDoubleSlashes.d.ts +3 -0
  68. package/dist/utils/fixDoubleSlashes.js +9 -0
  69. package/dist/utils/fixDoubleSlashes.js.map +1 -1
  70. package/dist/utils/getContentBranch.d.ts +2 -0
  71. package/dist/utils/getContentBranch.js +11 -0
  72. package/dist/utils/getContentBranch.js.map +1 -0
  73. package/dist/utils/getRenderMode.d.ts +1 -1
  74. package/dist/utils/getRenderMode.js +1 -1
  75. package/dist/utils/getRenderMode.js.map +1 -1
  76. package/dist/views/BaseMacro.jsx +1 -30
  77. package/dist/views/BaseMacro.jsx.map +1 -1
  78. package/dist/views/RichTextView.jsx +8 -8
  79. package/dist/views/RichTextView.jsx.map +1 -1
  80. package/dist/views/Text.jsx +1 -1
  81. package/dist/views/Text.jsx.map +1 -1
  82. package/package.json +14 -14
  83. package/dist/guillotine/getCleanContentPathArrayOrThrow400.js.map +0 -1
  84. package/dist/utils/getContentApiUrl.d.ts +0 -2
  85. package/dist/utils/getContentApiUrl.js +0 -15
  86. package/dist/utils/getContentApiUrl.js.map +0 -1
package/README.md CHANGED
@@ -27,7 +27,7 @@ import {fetchContent} from "@enonic/nextjs-adapter/server";
27
27
  import MainView from "@enonic/nextjs-adapter/views/MainView"
28
28
 
29
29
  // ...
30
- const props = await fetchContent(path, {
30
+ const props = await fetchContent({
31
31
  contentPath: '/content/path',
32
32
  locale: 'en',
33
33
  });
@@ -44,13 +44,13 @@ They are available at `@enonic/nextjs-adapter/server`
44
44
 
45
45
  <br/>
46
46
 
47
- #### <a id="fetch-content"></a>`fetchContent(contentPath: string | string[], context: Context) => Promise<FetchContentResult>`
47
+ #### <a id="fetch-content"></a>`fetchContent(context: Context) => Promise<FetchContentResult>`
48
48
 
49
49
  Fetches the content/component by path with component queries optimization, page structure as well as runtime info calculation. This is the
50
50
  main method for querying content.
51
51
 
52
- | Argument | Description |
53
- |----------|-------------------|
52
+ | Argument | Description |
53
+ |-----------|-------------------|
54
54
  | `context` | Execution context |
55
55
 
56
56
  Usage:
@@ -85,28 +85,22 @@ type FetchContentResult = {
85
85
 
86
86
  <br/>
87
87
 
88
- #### <a id="fetch-guillotine"></a>`fetchGuillotine(apiUrl: string, mapping: LocaleMapping, options?: FetchOptions) => Promise<GuillotineResult>`
88
+ #### <a id="fetch-guillotine"></a>`fetchGuillotine(contentApiUrl: string, options?: FetchOptions) => Promise<GuillotineResult>`
89
89
 
90
90
  Makes a custom request to Guillotine. Used by [fetchContent()](#fetch-content) method.
91
91
 
92
- | Argument | Description |
93
- |-----------|---------------------------------------------------|
94
- | `apiUrl` | Guillotine API URL |
95
- | `mapping` | [Mapping](#locale-mapping-type) locale to project |
96
- | `options` | Request and Next.js config options _(Optional)_ |
92
+ | Argument | Description |
93
+ |-----------------|-------------------------------------------------|
94
+ | `contentApiUrl` | Guillotine API URL |
95
+ | `options` | Request and Next.js config options _(Optional)_ |
97
96
 
98
97
  Usage:
99
98
 
100
99
  ```tsx
101
100
  import {fetchGuillotine} from '@enonic/nextjs-adapter/server';
102
- import {getLocaleMapping} from '@enonic/nextjs-adapter';
103
101
 
104
102
  const apiUrl = 'http://domain:8000/graphql/api';
105
103
 
106
- const mapping = getLocaleMapping({
107
- contentPath: '/current/content/path',
108
- });
109
-
110
104
  const body = {
111
105
  query: 'qraphql query as string',
112
106
  variables: {
@@ -128,7 +122,7 @@ const opts = {
128
122
  }
129
123
  };
130
124
 
131
- const result = fetchGuillotine(apiUrl, mapping, opts);
125
+ const result = fetchGuillotine(apiUrl, opts);
132
126
  ```
133
127
 
134
128
  Response type:
@@ -145,28 +139,22 @@ type GuillotineResult = {
145
139
 
146
140
  <br/>
147
141
 
148
- #### `fetchFromApi(apiUrl: string, mapping: LocaleMapping, options?: FetchOptions) => Promise<GuillotineResponseJson>`
142
+ #### `fetchFromApi(apiUrl: string, options?: FetchOptions) => Promise<GuillotineResponseJson>`
149
143
 
150
144
  Makes custom third-party service request. Used by the [fetchGuillotine()](#fetch-guillotine) method.
151
145
 
152
- | Argument | Description |
153
- |-----------|---------------------------------------------------|
154
- | `apiUrl` | Service API URL |
155
- | `mapping` | [Mapping](#locale-mapping-type) locale to project |
156
- | `options` | Request and Next.js config options _(Optional)_ |
146
+ | Argument | Description |
147
+ |-----------|-------------------------------------------------|
148
+ | `apiUrl` | Service API URL |
149
+ | `options` | Request and Next.js config options _(Optional)_ |
157
150
 
158
151
  Usage:
159
152
 
160
153
  ```tsx
161
154
  import {fetchFromApi} from '@enonic/nextjs-adapter/server';
162
- import {getLocaleMapping} from '@enonic/nextjs-adapter';
163
155
 
164
156
  const apiUrl = 'http://domain:8000/graphql/api';
165
157
 
166
- const mapping = getLocaleMapping({
167
- contentPath: '/current/content/path',
168
- });
169
-
170
158
  const body = {
171
159
  query: 'qraphql query as string',
172
160
  variables: {
@@ -188,22 +176,22 @@ const opts = {
188
176
  }
189
177
  };
190
178
 
191
- const result = fetchFromApi(apiUrl, mapping, opts);
179
+ const result = fetchFromApi(apiUrl, opts);
192
180
  ```
193
181
 
194
182
  <br/>
195
183
 
196
- #### <a id="fetch-paths-for-all-locales"></a>`fetchContentPathsForAllLocales(path: string, query?: string, count?: number) => Promise<ContentPathItem[]>`
184
+ #### <a id="fetch-paths-for-all-locales"></a>
185
+ `fetchContentPathsForAllLocales(query?: string, countPerLocale?: number) => Promise<ContentPathItem[]>`
197
186
 
198
187
  Loads all content paths for all locales. Generally used for static site generation.
199
188
 
200
- | Argument | Description |
201
- |----------|---------------------------------------------------|
202
- | `path` | Root content path |
203
- | `query` | Request and Next.js config options _(Optional)_ * |
204
- | `count` | Max result count _(Optional, defaults to 999)_ |
189
+ | Argument | Description |
190
+ |------------------|-----------------------------------------------------------|
191
+ | `query` | Custom GraphQL query _(Optional)_ * |
192
+ | `countPerLocale` | Max result count per locale _(Optional, defaults to 999)_ |
205
193
 
206
- &ast; Default query gets up to `count` results, sorts them by `modifiedTime` and excludes following content types:
194
+ &ast; Default query gets up to `countPerLocale` results, sorts them by `modifiedTime` and excludes following content types:
207
195
 
208
196
  ```
209
197
  "base:shortcut",
@@ -218,22 +206,21 @@ Usage:
218
206
  ```tsx
219
207
  import {fetchContentPathsForAllLocales} from '@enonic/nextjs-adapter/server';
220
208
 
221
- const contentPaths = fetchContentPathsForLocale('/site-name', 'custom graphql query', 1001);
209
+ const contentPaths = fetchContentPathsForAllLocales('custom graphql query', 1001);
222
210
  ```
223
211
 
224
212
  <br/>
225
213
 
226
- #### `fetchContentPathsForLocale(path: string, mapping: LocaleMapping, query?: string, count?: number) => Promise<ContentPathItem[]>`
214
+ #### `fetchContentPathsForLocale(mapping: LocaleMapping, query?: string, count?: number) => Promise<ContentPathItem[]>`
227
215
 
228
216
  Loads all content paths for the current locale. Generally used for static site generation.
229
217
  Used by [fetchContentPathsForAllLocales()](#fetch-paths-for-all-locales)
230
218
 
231
- | Argument | Description |
232
- |-----------|-----------------------------------------------------------------------------------------------------|
233
- | `path` | Root content path |
234
- | `mapping` | [Mapping](#locale-mapping-type) locale to project |
235
- | `query` | Request and Next.js config options _(Optional, [default value here](#fetch-paths-for-all-locales))_ |
236
- | `count` | Max result count _(Optional, defaults to 999)_ |
219
+ | Argument | Description |
220
+ |-----------|---------------------------------------------------------------------------------------|
221
+ | `mapping` | [Mapping](#locale-mapping-type) locale to project |
222
+ | `query` | Custom GraphQL query _(Optional, [default value here](#fetch-paths-for-all-locales))_ |
223
+ | `count` | Max result count _(Optional, defaults to 999)_ |
237
224
 
238
225
  Usage:
239
226
 
@@ -245,7 +232,7 @@ const mapping = getLocaleMapping({
245
232
  contentPath: '/current/content/path',
246
233
  });
247
234
 
248
- const contentPaths = fetchContentPathsForLocale('/', mapping, 'custom graphql query', 1001);
235
+ const contentPaths = fetchContentPathsForLocale(mapping, 'custom graphql query', 1001);
249
236
  ```
250
237
 
251
238
  <br/>
@@ -339,29 +326,6 @@ const urlRelativeToViewer = getUrl('/some/content/url', meta);
339
326
 
340
327
  <br/>
341
328
 
342
- #### <a id="get-asset"></a>`getAsset(url: string, meta: MetaData) => string`
343
-
344
- Converts a local asset URL to relative one for current viewer (Next.js/Enonic XP). It doesn't append locales unlike the [getUrl()](#get-url).
345
-
346
- > **INFO:** For your URLs to work both in Enonic XP and Next.js you need to:
347
- > 1. Use relative URL to local asset
348
- > 2. Wrap them with `getAsset()` function in the views
349
-
350
- | Argument | Description |
351
- |----------|---------------------------------------------------------|
352
- | `url` | asset URL you want to transform |
353
- | `meta` | Runtime data returned by [fetchContent](#fetch-content) |
354
-
355
- Usage:
356
-
357
- ```tsx
358
- import {getAsset} from '@enonic/nextjs-adapter';
359
-
360
- const urlRelativeToViewer = getAsset('/some/asset/url', meta);
361
- ```
362
-
363
- <br/>
364
-
365
329
  #### <a id="rich-text-query"></a>`richTextQuery(fieldName: string) => string`
366
330
 
367
331
  This is a utility function for querying for `RichTextData` needed for [RichTextView](#rich-text-view). It creates a graphql query string for
@@ -391,7 +355,8 @@ const query = `query($path:ID!){
391
355
 
392
356
  #### `validateData(props: FetchContentResult) => void`
393
357
 
394
- Utility method to validate data returned by [fetchContent()](#fetch-content) method. Throws an error or notFound() if data is invalid. Also prevents shortcut content types from being rendered in preview/edit modes.
358
+ Utility method to validate data returned by [fetchContent()](#fetch-content) method. Throws an error or calls Next.js `notFound()` if data
359
+ is invalid. Also prevents shortcut content types from being rendered in preview/edit modes.
395
360
 
396
361
  | Argument | Description |
397
362
  |----------|-----------------------------|
@@ -403,7 +368,7 @@ Usage:
403
368
  import {fetchContent} from '@enonic/nextjs-adapter/server';
404
369
  import {validateData} from '@enonic/nextjs-adapter';
405
370
 
406
- const data = fetchContent({
371
+ const data = await fetchContent({
407
372
  contentPath: '/path/to/content',
408
373
  locale: 'en',
409
374
  });
@@ -413,6 +378,71 @@ validateData(data);
413
378
 
414
379
  <br/>
415
380
 
381
+ #### <a id="get-content-branch"></a>`getContentBranch(context?: Context) => string`
382
+
383
+ Resolves the Enonic XP branch (`master` or `draft`) for the current request based on its render mode.
384
+ Returns `master` for `LIVE` and `NEXT` render modes, and `draft` otherwise (e.g. `EDIT`, `PREVIEW`, `INLINE`).
385
+
386
+ | Argument | Description |
387
+ |-----------|-------------------------------|
388
+ | `context` | `Context` object _(Optional)_ |
389
+
390
+ Usage:
391
+
392
+ ```tsx
393
+ import {getContentBranch} from '@enonic/nextjs-adapter';
394
+
395
+ const branch = getContentBranch({
396
+ contentPath: '/current/content/path',
397
+ locale: 'en',
398
+ });
399
+ ```
400
+
401
+ <br/>
402
+
403
+ #### <a id="encrypt-params"></a>`encryptParams(params: Record<string, any>, secret: string) => string`
404
+
405
+ Symmetrically encrypts a params object into a base64url string using AES-256-GCM. The `secret` is hashed with SHA-256
406
+ to derive the key, so any string length works. Pair with [decryptParams()](#decrypt-params) to read the value back.
407
+
408
+ | Argument | Description |
409
+ |----------|-------------------------------------------------|
410
+ | `params` | Plain object to encrypt |
411
+ | `secret` | Secret string used to derive the encryption key |
412
+
413
+ Usage:
414
+
415
+ ```tsx
416
+ import {encryptParams} from '@enonic/nextjs-adapter';
417
+
418
+ const blob = encryptParams({userId: '123', role: 'editor'}, process.env.ENONIC_API_TOKEN);
419
+ ```
420
+
421
+ <br/>
422
+
423
+ #### <a id="decrypt-params"></a>`decryptParams(blob: string, secret: string) => Record<string, any> | null`
424
+
425
+ Decrypts a base64url string produced by [encryptParams()](#encrypt-params). Returns `null` if the input is malformed,
426
+ tampered with, or was encrypted with a different secret.
427
+
428
+ | Argument | Description |
429
+ |----------|----------------------------------------------|
430
+ | `blob` | Base64url string produced by `encryptParams` |
431
+ | `secret` | Same secret used during encryption |
432
+
433
+ Usage:
434
+
435
+ ```tsx
436
+ import {decryptParams} from '@enonic/nextjs-adapter';
437
+
438
+ const params = decryptParams(blob, process.env.ENONIC_API_TOKEN);
439
+ if (params) {
440
+ // use params.userId, params.role, ...
441
+ }
442
+ ```
443
+
444
+ <br/>
445
+
416
446
  ### `ComponentRegistry`
417
447
 
418
448
  Registry containing definitions of all components (i.e. pages, parts, layouts, macros, etc. ). It is used in the runtime by `nextjs-adapter`
@@ -435,9 +465,12 @@ import {ComponentRegistry} from '@enonic/nextjs-adapter';
435
465
 
436
466
  const query = {
437
467
  query: 'graphql query',
438
- variables: (path, context, config) => {
468
+ variables: ({path, siteKey, branch, project}, context, config) => {
439
469
  return {
440
- path: path + '/some/processing'
470
+ path: path + '/some/processing',
471
+ siteKey,
472
+ branch,
473
+ project,
441
474
  };
442
475
  }
443
476
  }
@@ -454,6 +487,17 @@ Gets the common query definition.
454
487
  <a id="query-def"></a>Response type:
455
488
 
456
489
  ```tsx
490
+ interface GlobalVariables {
491
+ path: string;
492
+ siteKey: string;
493
+ branch: string;
494
+ project: string;
495
+ }
496
+
497
+ type QueryGetter = (vars: GlobalVariables, context?: Context, config?: any) => string;
498
+
499
+ type VariablesGetter = (vars: GlobalVariables, context?: Context, config?: any) => GlobalVariables & Record<string, any>;
500
+
457
501
  type SelectedQueryMaybeVariablesFunc =
458
502
  string |
459
503
  QueryGetter |
@@ -504,17 +548,17 @@ interface ComponentDefinition {
504
548
 
505
549
  <br/>
506
550
 
507
- #### `static addMacro(name: string, obj: ComponentDefinition): void`
551
+ #### `static addMacro(name: string, obj: ComponentDefinitionParams): void`
508
552
 
509
- #### `static addPart(name: string, obj: ComponentDefinition): void`
553
+ #### `static addPart(name: string, obj: ComponentDefinitionParams): void`
510
554
 
511
- #### `static addLayout(name: string, obj: ComponentDefinition): void`
555
+ #### `static addLayout(name: string, obj: ComponentDefinitionParams): void`
512
556
 
513
- #### `static addCPage(name: string, obj: ComponentDefinition): void`
557
+ #### `static addPage(name: string, obj: ComponentDefinitionParams): void`
514
558
 
515
- #### `static addContentType(name: string, obj: ComponentDefinition): void`
559
+ #### `static addContentType(name: string, obj: ComponentDefinitionParams): void`
516
560
 
517
- #### `static addComponent(name: string, obj: ComponentDefinition): void`
561
+ #### `static addComponent(name: string, obj: ComponentDefinitionParams): void`
518
562
 
519
563
  Saves the component definition in ComponentRegistry by name.
520
564
 
@@ -570,19 +614,19 @@ Response type: [component definition](#comp-def)
570
614
 
571
615
  <br/>
572
616
 
573
- #### `static getMacros(): ComponentDefinition[]`
617
+ #### `static getMacros(): [string, ComponentDefinition][]`
574
618
 
575
- #### `static getParts(): ComponentDefinition[]`
619
+ #### `static getParts(): [string, ComponentDefinition][]`
576
620
 
577
- #### `static getLayouts(): ComponentDefinition[]`
621
+ #### `static getLayouts(): [string, ComponentDefinition][]`
578
622
 
579
- #### `static getPages(): ComponentDefinition[]`
623
+ #### `static getPages(): [string, ComponentDefinition][]`
580
624
 
581
- #### `static getContentTypes(): ComponentDefinition[]`
625
+ #### `static getContentTypes(): [string, ComponentDefinition][]`
582
626
 
583
- #### `static getComponents(): ComponentDefinition[]`
627
+ #### `static getComponents(): [string, ComponentDefinition][]`
584
628
 
585
- Gets all component definitions stored in ComponentRegistry.
629
+ Gets all component entries (`[name, definition]` tuples) stored in ComponentRegistry.
586
630
 
587
631
  > **NOTE:** Read [addComponent](#add-comp) note before using `getComponents`.
588
632
 
@@ -594,7 +638,7 @@ import {ComponentRegistry} from '@enonic/nextjs-adapter';
594
638
  const macros = ComponentRegistry.getMacros();
595
639
  ```
596
640
 
597
- Response type: List of [component definitions](#comp-def)
641
+ Response type: list of `[name, ComponentDefinition]` tuples — see [component definition](#comp-def).
598
642
 
599
643
  <br/>
600
644
 
@@ -609,7 +653,7 @@ Helper singleton for processing URLs.
609
653
  Processes the absolute URL to become relative for the current viewer, while keeping in mind Next.js assets and Enonic XP binary content
610
654
  links
611
655
 
612
- > **NOTE:** There are convenience aliases to this function called [getUrl()](#get-url) and [getAsset()](#get-asset)
656
+ > **NOTE:** There is a convenience alias to this function called [getUrl()](#get-url)
613
657
 
614
658
  | Argument | Description |
615
659
  |--------------|------------------------------------------------------------------------------|
@@ -647,26 +691,6 @@ const url = UrlProcessor.processSrcSet('<srcset value>', meta);
647
691
 
648
692
  <br/>
649
693
 
650
- #### `static setSiteKey(key: string): void`
651
-
652
- > **DEPRECATED:** It is automatically done by `nextjs-adapter` now and have no effect.
653
-
654
- Sets the site key value that is needed for correct absolute URL processing.
655
-
656
- | Argument | Description |
657
- |----------|-------------|
658
- | `key` | Site key |
659
-
660
- Usage:
661
-
662
- ```tsx
663
- import {UrlProcessor} from '@enonic/nextjs-adapter';
664
-
665
- UrlProcessor.setSiteKey('<site key>');
666
- ```
667
-
668
- <br/>
669
-
670
694
  #### `static isMediaLink(ref: string, linkData: LinkData[]): boolean`
671
695
 
672
696
  Checks if link data array contains link with provided ref. Positive result means that this is a link to Enonic XP content.
@@ -784,7 +808,7 @@ const mapping = getLocaleMappingByLocale('en', true);
784
808
 
785
809
  <br/>
786
810
 
787
- #### `getRequestLocaleInfo(context: Context): LocaleMapping`
811
+ #### `getRequestLocaleInfo(context: Context): LocaleInfo`
788
812
 
789
813
  Attempts to get the locale info from the request. Along with that it also returns the default locale and all configured locales.
790
814
 
@@ -903,9 +927,9 @@ There is also a number of utility constants and functions available at `@enonic/
903
927
 
904
928
  <br/>
905
929
 
906
- ```tsx
907
- import {CATCH_ALL} from './constants';
930
+ All of the following are exported from `@enonic/nextjs-adapter`:
908
931
 
932
+ ```tsx
909
933
  IS_DEV_MODE; // True if current mode == development
910
934
 
911
935
  APP_NAME; // Name of the app defined in .env files
@@ -953,11 +977,10 @@ enum XP_COMPONENT_TYPE { // Enum for XP component types
953
977
 
954
978
  // Sanitizes text according to graphql naming spec http://spec.graphql.org/October2021/#sec-Names
955
979
  const sanitizeGraphqlName = (text: string) => string;
956
-
957
- // Returns full content api URL with current project and branch appended
958
- const getContentApiUrl = (context: Context) => string;
959
980
  ```
960
981
 
982
+ See also: [getContentBranch](#get-content-branch), [encryptParams](#encrypt-params), [decryptParams](#decrypt-params).
983
+
961
984
  ### Views
962
985
 
963
986
  They are located in `@enonic/nextjs-adapter/views` folder. Each view is a default export in the corresponding file.
@@ -979,10 +1002,13 @@ Usage:
979
1002
 
980
1003
  ```tsx
981
1004
  import MainView from '@enonic/nextjs-adapter/views/MainView';
982
- import fetchContent from '@enonic/nextjs-adapter';
1005
+ import {fetchContent} from '@enonic/nextjs-adapter/server';
983
1006
 
984
1007
  export async function getServerSideProps(context: Context) {
985
- const props = fetchContent('/content/path', context);
1008
+ const props = await fetchContent({
1009
+ contentPath: '/content/path',
1010
+ locale: 'en',
1011
+ });
986
1012
  return {
987
1013
  props
988
1014
  }
@@ -993,37 +1019,37 @@ export default MainView;
993
1019
 
994
1020
  <br/>
995
1021
 
996
- #### `<StaticContent condition="true" tag="div">`
1022
+ #### `<StaticContent condition={true} element="div">`
997
1023
 
998
1024
  Tag for disabling client side hydration if the condition is true. This will remove interactivity from children.
999
1025
 
1000
1026
  | Argument | Type | Description |
1001
1027
  |--------------------|-----------|------------------------------------|
1002
1028
  | `condition = true` | `Boolean` | Condition to trigger static output |
1003
- | `tag = 'div'` | `String` | Html tag to use for static output |
1029
+ | `element = 'div'` | `String` | Html tag to use for static output |
1004
1030
 
1005
1031
  Usage:
1006
1032
 
1007
1033
  ```tsx
1008
1034
  import StaticContent from '@enonic/nextjs-adapter/views/StaticContent';
1009
1035
 
1010
- <StaticContent condition={true} tag="div"> ...child elements... </StaticContent>
1036
+ <StaticContent condition={true} element="div"> ...child elements... </StaticContent>
1011
1037
  ```
1012
1038
 
1013
1039
  <br/>
1014
1040
 
1015
- #### <a id="rich-text-view"></a>`<RichTextView className="css-class" tag="section" data={data} meta={meta}, renderMacroInEditMode="true", customReplacer={customReplacerFn}>`
1041
+ #### <a id="rich-text-view"></a>
1042
+ `<RichTextView className="css-class" tag="section" data={data} meta={meta} customReplacer={customReplacerFn}>`
1016
1043
 
1017
1044
  Tag for displaying contents of html area input types. Takes care of processing macros, URLs and images inside.
1018
1045
 
1019
- | Argument | Type | Description |
1020
- |--------------------------------|----------------|---------------------------------------------------------------------------------------------------|
1021
- | `data` | `RichTextData` | Rich text data |
1022
- | `meta` | `MetaData` | Runtime data returned by fetchContent method. |
1023
- | `customReplacer` | `Replacer` | Function to do custom element processing. Not invoked for image, link and macro nodes. _Optional_ |
1024
- | `className` | `String` | Class name to add to the root html element. _Optional_ |
1025
- | `renderMacroInEditMode = true` | `boolean` | Flag passed to macros telling if they should render themselves in edit mode |
1026
- | `tag = 'div'` | `String` | Html tag to use as a root |
1046
+ | Argument | Type | Description |
1047
+ |------------------|----------------|---------------------------------------------------------------------------------------------------|
1048
+ | `data` | `RichTextData` | Rich text data |
1049
+ | `meta` | `MetaData` | Runtime data returned by fetchContent method. |
1050
+ | `customReplacer` | `Replacer` | Function to do custom element processing. Not invoked for image, link and macro nodes. _Optional_ |
1051
+ | `className` | `String` | Class name to add to the root html element. _Optional_ |
1052
+ | `tag = 'div'` | `String` | Html tag to use as a root |
1027
1053
 
1028
1054
  > **TIP!** There is a utility function [richTextQuery(fieldName)](#rich-text-query) generating part of the graphql query to
1029
1055
  > obtain `RichTextData` for html area input types.
@@ -1033,7 +1059,7 @@ Usage:
1033
1059
  ```tsx
1034
1060
  import RichTextView from '@enonic/nextjs-adapter/views/RichTextView';
1035
1061
 
1036
- <RichTextView data={richTextData} meta={meta} tag="section" className="rich-text-view" renderMacroInEditMode="false"></RichTextView>
1062
+ <RichTextView data={richTextData} meta={meta} tag="section" className="rich-text-view"></RichTextView>
1037
1063
  ```
1038
1064
 
1039
1065
  <br/>
@@ -1053,7 +1079,7 @@ All necessary data can be acquired by running [fetchContent()](#fetch-content)
1053
1079
  Usage:
1054
1080
 
1055
1081
  ```tsx
1056
- import StaticContent from '@enonic/nextjs-adapter/views/StaticContent';
1082
+ import Regions from '@enonic/nextjs-adapter/views/Region';
1057
1083
 
1058
- <StaticContent condition={true} tag="div"> ...child elements... </StaticContent>
1084
+ <Regions page={page} meta={meta} name="main" common={common}/>
1059
1085
  ```
@@ -7,19 +7,13 @@ export declare class UrlProcessor {
7
7
  static LINK_ATTR: string;
8
8
  static MACRO_ATTR: string;
9
9
  private static IMG_ATMT_REGEXP;
10
- private static endSlashPattern;
11
- private static startSlashPattern;
12
- private static localhostPattern;
13
10
  static process(url: string, meta: MetaData, serverSide?: boolean, isResource?: boolean): string;
14
- static setSiteKey(key: string): void;
11
+ private static normalizeBaseUrl;
15
12
  static isMediaLink(ref: string, linkData: LinkData[]): boolean;
16
13
  static isContentImage(ref: string, imageData: ImageData[]): boolean;
17
14
  static processSrcSet(srcset: string, meta: MetaData): string;
18
- private static stripApiUrl;
19
15
  private static isAttachmentUrl;
20
16
  private static startsWithHash;
21
- private static isRelative;
22
- private static getApiUrl;
17
+ private static isAbsolute;
23
18
  }
24
19
  export declare function getUrl(url: string, meta: MetaData): string;
25
- export declare function getAsset(url: string, meta: MetaData): string;