@salesforce/templates 66.13.6 → 66.13.7

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 (101) hide show
  1. package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/package-lock.json +436 -184
  2. package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/package-lock.json +439 -187
  3. package/lib/templates/project/reactexternalapp/CHANGELOG.md +96 -0
  4. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/package-lock.json +410 -132
  5. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/package.json +4 -4
  6. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/_ls_/LanguageSwitcher.tsx +116 -0
  7. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/_ls_/__examples__/language-switcher-example.tsx +36 -0
  8. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/_ls_/__examples__/vite-config-site-example.ts +44 -0
  9. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/_ls_/buildLanguageUrl.ts +158 -0
  10. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/_ls_/index.ts +28 -0
  11. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/_ls_/languages.ts +46 -0
  12. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/README.md +246 -0
  13. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/api/apiUtils.ts +56 -0
  14. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/api/orgApiVersionService.ts +37 -0
  15. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/api/searchableContentTypesService.ts +116 -0
  16. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/channelResolver.ts +40 -0
  17. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/cmsQueryFragment.ts +97 -0
  18. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/contentTypeSessionCache.ts +134 -0
  19. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/contentTypeUtils.ts +38 -0
  20. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/hooks/useSearchableContentTypes.ts +128 -0
  21. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/index.ts +54 -0
  22. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/parseResponse.ts +65 -0
  23. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/searchChannel.ts +15 -0
  24. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/types.ts +66 -0
  25. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/registry.ts +38 -0
  26. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/sobject/index.ts +19 -0
  27. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/sobject/parseResponse.ts +56 -0
  28. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/sobject/queryFragment.ts +141 -0
  29. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/types.ts +101 -0
  30. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/api/searchService.ts +110 -45
  31. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/GlobalSearchBox.tsx +98 -0
  32. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/MergedSearchResults.tsx +34 -17
  33. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/Search.tsx +31 -13
  34. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/SearchResults.tsx +22 -11
  35. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/SourceSection.tsx +9 -4
  36. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/controls/ScopeSelector.tsx +58 -6
  37. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/results/CmsResultRow.tsx +101 -0
  38. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/results/resolveResultRenderer.ts +49 -0
  39. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/config.json +7 -2
  40. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/constants.ts +8 -0
  41. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/hooks/useSearch.ts +313 -50
  42. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/index.ts +26 -1
  43. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/queryBuilder.ts +62 -118
  44. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/_f_/search/types.ts +74 -5
  45. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/index.ts +5 -3
  46. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/pages/AccountObjectDetailPage.tsx +4 -2
  47. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/pages/Home.tsx +3 -42
  48. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/routes.tsx +12 -5
  49. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/types/globals.d.ts +23 -0
  50. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/tsconfig.tsbuildinfo +1 -1
  51. package/lib/templates/project/reactexternalapp/package.json +1 -1
  52. package/lib/templates/project/reactinternalapp/CHANGELOG.md +96 -0
  53. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/package-lock.json +421 -143
  54. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/package.json +5 -5
  55. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/README.md +246 -0
  56. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/api/apiUtils.ts +56 -0
  57. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/api/orgApiVersionService.ts +37 -0
  58. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/api/searchableContentTypesService.ts +116 -0
  59. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/channelResolver.ts +40 -0
  60. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/cmsQueryFragment.ts +97 -0
  61. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/contentTypeSessionCache.ts +134 -0
  62. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/contentTypeUtils.ts +38 -0
  63. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/hooks/useSearchableContentTypes.ts +128 -0
  64. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/index.ts +54 -0
  65. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/parseResponse.ts +65 -0
  66. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/searchChannel.ts +15 -0
  67. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/cms/types.ts +66 -0
  68. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/registry.ts +38 -0
  69. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/sobject/index.ts +19 -0
  70. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/sobject/parseResponse.ts +56 -0
  71. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/sobject/queryFragment.ts +141 -0
  72. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/adapters/types.ts +101 -0
  73. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/api/searchService.ts +110 -45
  74. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/GlobalSearchBox.tsx +98 -0
  75. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/MergedSearchResults.tsx +34 -17
  76. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/Search.tsx +31 -13
  77. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/SearchResults.tsx +22 -11
  78. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/SourceSection.tsx +9 -4
  79. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/controls/ScopeSelector.tsx +58 -6
  80. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/results/CmsResultRow.tsx +101 -0
  81. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/components/results/resolveResultRenderer.ts +49 -0
  82. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/config.json +7 -2
  83. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/constants.ts +8 -0
  84. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/hooks/useSearch.ts +313 -50
  85. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/index.ts +26 -1
  86. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/queryBuilder.ts +62 -118
  87. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/_f_/search/types.ts +74 -5
  88. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/pages/Home.tsx +3 -42
  89. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/routes.tsx +12 -5
  90. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/tsconfig.tsbuildinfo +1 -1
  91. package/lib/templates/project/reactinternalapp/package.json +1 -1
  92. package/lib/templates/uiBundles/angularbasic/package-lock.json +436 -184
  93. package/lib/templates/uiBundles/reactbasic/package-lock.json +384 -106
  94. package/lib/utils/template-placeholders.js +7 -0
  95. package/lib/utils/template-placeholders.js.map +1 -1
  96. package/lib/utils/uiBundleTemplateUtils.d.ts +3 -1
  97. package/lib/utils/uiBundleTemplateUtils.js +4 -1
  98. package/lib/utils/uiBundleTemplateUtils.js.map +1 -1
  99. package/package.json +3 -3
  100. package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/src/pages/AccountSearch.tsx +0 -25
  101. package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/src/pages/AccountSearch.tsx +0 -25
@@ -0,0 +1,246 @@
1
+ # Search feature
2
+
3
+ Explains how this search feature is structured and how to customize it — which
4
+ files own configuration, how sObject and CMS sources differ, how CMS search is
5
+ wired end to end, and how to mount the UI. Read it before changing anything
6
+ under this directory.
7
+
8
+ ## 1. What this feature is / where sources live
9
+
10
+ - `config.json` (co-located here) declares `sources: SourceConfig[]` — a
11
+ discriminated union on `kind` — plus an optional `pagination` block. The
12
+ shipped default has 3 `"sobject"` sources (`accounts`, `contacts`,
13
+ `opportunities`) and one `"cms"` source (`key: "content"`).
14
+ - `loadConfig.ts` re-exports `config.json`, typed as `SearchConfig`. For a
15
+ pure config change (add/remove a source, tweak fields), **edit
16
+ `config.json` directly — no code changes required.**
17
+ - `types.ts` is the source of truth for `SourceConfig` (`SObjectSourceConfig |
18
+ CmsSourceConfig`) and `SearchConfig`.
19
+
20
+ ## 2. Choosing sObject vs CMS per source
21
+
22
+ - **sObject source** (`kind: "sobject"`): requires `objectName`, `label`,
23
+ `searchableFields`, `displayFields`. Optional: `labelSingular`, `idField`
24
+ (defaults `"Id"`), `routePattern`, `filterBy`, `sortBy`, `defaultSort`,
25
+ `whereTypeName`/`orderByTypeName`. Queried via the `uiapi` GraphQL bridge
26
+ (`adapters/sobject`).
27
+ - **CMS source** (`kind: "cms"`): deliberately minimal — only `kind`, `key`,
28
+ `label`, and optionally `labelSingular`/`routePattern`
29
+ (`adapters/cms/types.ts`, `CmsSourceConfig`). No `channelId`, no content
30
+ types, no `displayFields` — all of that is resolved at runtime. Routed via
31
+ `adapters/registry.ts` to `cmsAdapter` (`adapters/cms/index.ts`).
32
+ - `adapters/registry.ts` maps `kind` → adapter (`sobject → sObjectAdapter`,
33
+ `cms → cmsAdapter`). Adding a new backend `kind` means registering an
34
+ adapter here plus extending the `SourceConfig` union in `types.ts` — out of
35
+ scope for typical customization; most tasks only touch `config.json`.
36
+
37
+ ## 3. Enabling sObject search
38
+
39
+ sObject sources work out of the box — no runtime id resolution and no gating.
40
+ They query the org's `uiapi` GraphQL bridge through `adapters/sobject`.
41
+
42
+ - **Declare the source** in `config.json`: `kind: "sobject"`, `objectName` (the
43
+ API name, e.g. `"Account"`), `label`, `searchableFields` (the fields the
44
+ free-text term matches against), and `displayFields` (what each result row
45
+ shows). A `displayFields` entry is a plain field name (`"Name"`), a
46
+ `{ name, raw }` (use the raw value, skip display formatting), or a
47
+ `{ name, subfields }` for a parent relationship
48
+ (`{ "name": "Owner", "subfields": ["Name"] }`).
49
+ - **Optional per-source knobs:** `labelSingular`, `idField` (defaults `"Id"`),
50
+ `filterBy` (facets — `picklist` / `numeric` / `daterange`), `sortBy` +
51
+ `defaultSort`, and `routePattern` (see §6). `whereTypeName` / `orderByTypeName`
52
+ override the generated GraphQL input type names for objects whose where/orderBy
53
+ types don't follow the default `<Object>` naming.
54
+ - **Query construction:** `buildSearchQuery` (`api/buildSearchQuery.ts`)
55
+ assembles the GraphQL from the source config, `buildOrderBy` builds the sort
56
+ clause, and picklist filter values come from `useDistinctValues` /
57
+ `fetchDistinctValues`. The whole path runs through the platform data SDK — no
58
+ enablement step beyond declaring the source.
59
+ - **FLS caveat:** a field the running user can't read is silently dropped by the
60
+ platform, so an sObject source that "returns nothing" usually means the app's
61
+ permission set is missing field access, not a config error.
62
+
63
+ ## 4. Enabling CMS search
64
+
65
+ This is the part most likely to be missed — read all of it before assuming
66
+ CMS search "just works" after adding a `cms` source to `config.json`.
67
+
68
+ - **API version requirement.** Search on CMS content is supported only when the
69
+ bundle is built against **API version 68.0 or greater**. The build-time
70
+ version (`__SF_API_VERSION__`, injected from the resolved org's API version)
71
+ is the version every SDK request is actually issued at, so it is the gate.
72
+ - **No static id in config.** The UIBundle id is resolved at runtime by
73
+ `adapters/cms/searchChannel.ts::getUIBundleId()`, which calls
74
+ `@salesforce/platform-sdk`'s `getCurrentApp()` and reads
75
+ `identity.bundleId` — the UIBundle **record id** (a `9YE...` id). This is
76
+ only populated when running on the WebApp surface (the runtime injects
77
+ `SFDC_ENV`, per `packages/sdk/platform-sdk/src/core/app.ts`). Locally, or on
78
+ any non-WebApp surface, `bundleId` is `undefined`/`""`, and the CMS source
79
+ is skipped with no error — by design.
80
+ - **The gate:** `hooks/useSearch.ts` resolves `getUIBundleId()` **and**
81
+ `getOrgSupportsCmsSearch()` once per fetch and, for the CMS source, includes
82
+ the CMS request only when BOTH pass: `isConfiguredUIBundleId(uiBundleId)`
83
+ (`adapters/cms/searchChannel.ts`) and the build API-version check (above).
84
+ `isConfiguredUIBundleId` validates the `9YE` shape
85
+ (`UI_BUNDLE_ID_PATTERN = /^9YE[a-zA-Z0-9]{12,15}$/`) — an empty or malformed
86
+ id, or a build below v68, causes the CMS source to be silently dropped from
87
+ the request (no per-source error banner), not sent to the server.
88
+ - **CMS UI surfaces hide on a gated build too.** When CMS search is skipped for
89
+ the build-version reason, its scope entry and result section would only ever
90
+ be empty, so both are hidden using the SAME gate as the fetch skip —
91
+ `isCmsSearchSupported()` (the synchronous core of `getOrgSupportsCmsSearch()`,
92
+ in `adapters/cms/api/orgApiVersionService.ts`). Two minimal guards read it:
93
+ `ScopeSelector` skips the CMS `<SelectItem>` ("Content") and `SearchResults`
94
+ skips the CMS `SourceSection` ("Content" heading + empty state). Both are safe
95
+ during render because the gate reads only the build-time API version. (The
96
+ runtime `bundleId` gate above is _not_ build-constant — it can differ per
97
+ surface — so it stays a per-fetch skip and does not hide the UI; a CMS source
98
+ skipped only for a missing `bundleId` still shows its section, empty.)
99
+ - **The query field:** `adapters/cms/cmsQueryFragment.ts` sends the resolved
100
+ `$UIBundleId` into `searchIdentifiers.uibundleIds` (NOT `channelIds`) on
101
+ `managed_content.search.searchContentInChannels`. Content-type filtering
102
+ (`$cmsContentTypeFQNs`) is omitted on the bootstrap call and supplied once
103
+ discovery completes.
104
+ - **Why `uibundleIds` (evidence from core).** `ContentSearchIdentifiersInput`
105
+ has three id-space fields — `channelIds` (`0ap` Managed Content channel ids),
106
+ `siteIds`, and `uibundleIds` — and the `9YE` UIBundle **record id** belongs
107
+ only in `uibundleIds`. In core (`core-2206/core-266-public`): the schema
108
+ `ui-services-private/.../graphql-schemas/mcontent-search.graphqls` documents
109
+ `uibundleIds` as _"Each UI bundle ID is resolved to its associated Managed
110
+ Content channel(s)"_; the resolver
111
+ `mcontent-impl/.../ManagedContentGraphQLSearchServiceImpl.resolveChannelIdsFromSitesAndUiBundles()`
112
+ resolves each id via `getManagedContentChannelsByTarget(uibundleId)` (the id
113
+ is the channel's **TargetEntityId**, i.e. a UIBundle record id); the UDD
114
+ `lwr-udd/.../UIBundle.entity.xml` sets `keyPrefix="9YE"`; and the unit test
115
+ `ManagedContentGraphQLSearchServiceImplTest.testUiBundleId_resolvesToChannelIds_andIsSearched()`
116
+ passes a `9YE…` id into `uibundleIds` and asserts it resolves (W-23364628).
117
+ `channelIds` values are validated as channel/site ids and never run through
118
+ the target-entity resolver, so a `9YE` id sent there fails with
119
+ `"9YE… isn't a valid managed content channel ID or a site ID"` — the exact
120
+ error this wiring fixes. (Server-side, resolution of `uibundleIds`/`siteIds`
121
+ is gated by the core feature flag `isAllowTargetEntityIdsEnabled()`.)
122
+ - **Content-type discovery:** after the first CMS result returns,
123
+ `adapters/cms/channelResolver.ts::resolveChannelId()` extracts the `0ap`
124
+ managed-content-channel id from
125
+ `nodes[0].managedContentChannelDeliveryDetails[0].managedContentChannelDetails.id`.
126
+ `adapters/cms/hooks/useSearchableContentTypes.ts` (session-cached) then
127
+ fetches `GET /connect/cms/channels/{channelId}/searchable-content-types` to
128
+ populate the scope dropdown's per-content-type entries. Note: this `0ap` id
129
+ is a _different_ id space from the `9YE` UIBundle id above — don't confuse
130
+ the two when debugging.
131
+ - **Seeding content:** the resolved `bundleId` only surfaces content published
132
+ to the UIBundle's own channel (WebApp type), so CMS content must be published
133
+ there — not to the Experience Site COMMUNITY channel. Content published to
134
+ the wrong channel returns zero results even when the id/gate/query wiring is
135
+ correct, so empty CMS results with everything else in place usually points at
136
+ the publishing target rather than the code.
137
+ - **Mounting:** add a `{ "kind": "cms", "key": "...", "label": "..." }` entry
138
+ to `config.sources` (in `config.json`, or a custom `SearchConfig` object at
139
+ runtime), then render `<Search config={config} />` somewhere routed — see
140
+ the next section.
141
+
142
+ ## 5. Mounting `<Search>` — the routing caveat
143
+
144
+ - `GlobalSearchBox` (`components/GlobalSearchBox.tsx`) is a **pure
145
+ launcher** — a text input + button that calls `navigate('/search?q=...')`
146
+ on submit. **It renders no results itself.**
147
+ - **`GlobalSearchBox` only routes to `/search`; you must mount `<Search>` at
148
+ that route for results to render.** In this template, `routes.tsx` does
149
+ exactly that: `path: "search"` renders `<GlobalSearch config={config} .../>`
150
+ (`GlobalSearch` is `Search` aliased on import). If an app drops in
151
+ `GlobalSearchBox` without also mounting `<Search>` (or a custom results UI
152
+ built on `useSearch`) at the route it navigates to, searches will appear to
153
+ do nothing.
154
+ - `<Search>` itself (`components/Search.tsx`) is the batteries-included
155
+ drop-in. For narrower customizations (e.g. a single-object search page),
156
+ see its prop JSDoc for `restrictTo` (lock to one source), `renderResult` /
157
+ `renderFilters` (per-source overrides), and `showScopeSelector`.
158
+
159
+ ## 6. Adding a detail page (object detail / CMS content detail)
160
+
161
+ **By default, result cards are NOT clickable** — the feature renders each row as
162
+ plain (non-linked) text (see the final `return <div>…` branch in
163
+ `DefaultResultRow.tsx` / `CmsResultRow.tsx`). Making a card clickable is a
164
+ two-part change, and **both parts are required** — one without the other either
165
+ does nothing or 404s:
166
+
167
+ 1. **In this feature** (`config.json`): give the source a `routePattern`. This is
168
+ the _only_ thing that turns the row into a `<Link>`. Without it the row stays
169
+ non-clickable no matter what routes the app defines.
170
+ 2. **In the app** (`src/routes.tsx`): the detail page must actually exist and be
171
+ registered at a matching dynamic route. The feature only builds the href
172
+ (e.g. `/accounts/001…`); it does not own any route. If that route isn't in the
173
+ app's `routes.tsx`, the (now-clickable) card navigates to a dead URL and 404s.
174
+
175
+ So: `routePattern` present **and** a matching detail route/page in the app →
176
+ clickable card that opens a detail page. `routePattern` absent → non-clickable
177
+ card (the default). `routePattern` present but no app route → clickable card that
178
+ 404s.
179
+
180
+ - **How the link is built:** `routePattern` is a path template with `:token`
181
+ placeholders resolved per result.
182
+ - **sObject rows** (`components/results/DefaultResultRow.tsx`,
183
+ `resolveRoute(routePattern, node, idField)`): `:fieldName` tokens are
184
+ substituted from the record's field values, and a bare `:id` maps to the
185
+ source's `idField` (default `Id`). The shipped `accounts` source uses
186
+ `"/accounts/:id"`.
187
+ - **CMS rows** (`components/results/CmsResultRow.tsx`): tokens are `:id`
188
+ (the `managedContentId`) and `:key`; when no `routePattern` is set it falls
189
+ back to `/content/:contentType/:id`.
190
+ - **Authoring the app-side route + page** (part 2 above): register the matching
191
+ dynamic route in the app's `routes.tsx` (e.g. `path: "accounts/:id"` /
192
+ `path: "content/:contentType/:id"`). That route's component reads the route
193
+ param (`useParams`) and fetches the single record/content item — sObject
194
+ detail: fetch the one record by id via the platform data SDK (see the
195
+ `experience-ui-bundle-salesforce-data-access` skill — do not hand-roll
196
+ `fetch`); CMS detail: fetch the content item by `managedContentId` through the
197
+ CMS delivery API.
198
+ - **Generating the page:** whichever kind of detail page you need, nothing inside
199
+ this search feature changes beyond setting `routePattern` — the page and route
200
+ live in the app, not in this directory. Pick the skill by source type:
201
+ - **sObject object-detail page** — a normal routed page; generate it with the
202
+ `experience-ui-bundle-frontend-generate` skill (its page types include "detail
203
+ view"; record data is fetched via the platform Data SDK per the
204
+ `experience-ui-bundle-salesforce-data-access` skill).
205
+ - **CMS content-detail page** — generate it with the
206
+ `experience-cms-content-render` skill. That skill owns CMS content _fetch +
207
+ render_ (the delivery API, `contentKey`/`contentType`, RichText, and image
208
+ resolution) and **takes precedence** over `experience-ui-bundle-frontend-generate`
209
+ for the rendering portion — the UI skill owns only the page/layout shell. Its
210
+ Detail Page branch writes `src/pages/<type>/<PageName>.tsx` and inserts the
211
+ route, so the app gets both the page and the matching route wired for you. (It
212
+ is scoped to _rendering existing_ content — use this search feature, not that
213
+ skill, for the search itself.)
214
+
215
+ ## 7. Config knobs reference
216
+
217
+ | Knob | Values / notes |
218
+ | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
219
+ | `pagination.mode` | `"per-source"` (default; one section per source) vs `"merged"` (one combined grid, single global pager) — `types.ts` |
220
+ | `pagination.mergeOrder` | `"sequential" \| "interleaved" \| "proportional"` — merged mode only |
221
+ | `pagination.pageSize` / `pageSizeOptions` | shared across every source, every scope |
222
+ | Per-sobject-source | `objectName`, `label`/`labelSingular`, `idField`, `routePattern`, `searchableFields`, `displayFields` (`string \| {name,raw} \| {name,subfields}`), `filterBy`, `sortBy`, `defaultSort`, `whereTypeName`/`orderByTypeName` |
223
+ | Per-cms-source | `key`, `label`, `labelSingular?`, `routePattern?` — nothing else, by design |
224
+ | `MIN_QUERY_LENGTH` | `constants.ts`, currently `3`. Both backends reject shorter terms server-side; gated client-side in `useSearch.ts` and `GlobalSearchBox.tsx` so the UI never shows a spurious failure for a too-short query |
225
+
226
+ ## 8. Public API pointers
227
+
228
+ Import from the barrel (`index.ts`) rather than reaching into internals. The
229
+ main extension points, grouped by concern:
230
+
231
+ - **Core (both source types):** `useSearch` — the hook (state, fetch,
232
+ pagination) behind `<Search>`; `runSearch` — the underlying fetch;
233
+ `buildSearchQuery` — assembles the query payload; `getAdapter` — resolves a
234
+ source `kind` to its adapter; `config` — the loaded `SearchConfig`.
235
+ - **sObject sources:** `useDistinctValues` / `fetchDistinctValues` — picklist
236
+ filter values; `buildOrderBy` — sort clause construction; the filter inputs
237
+ (`TextFilter`, `SelectFilter`, `MultiSelectFilter`, `NumericRangeFilter`,
238
+ `BooleanFilter`, `DateRangeFilter`) and `DefaultResultRow` for rendering.
239
+ - **CMS source:** `cmsAdapter`; `useSearchableContentTypes` — content-type
240
+ discovery; `isValidCmsFqn` / `formatContentTypeLabel` — content-type FQN
241
+ helpers; `CmsResultRow` for rendering.
242
+ - **Types:** `SearchConfig`, `SourceConfig`, `SObjectSourceConfig`,
243
+ `CmsSourceConfig`, `SourceAdapter`, `SearchHandle`, and related runtime types.
244
+
245
+ See `index.ts` for the full exported surface (all components, filter inputs,
246
+ utils) — this list is intentionally short.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Self-contained CMS Connect REST helpers (URL builder + authenticated GET).
3
+ */
4
+
5
+ import { createDataSDK } from "@salesforce/platform-sdk";
6
+
7
+ // The build injects the org's API version via `__SF_API_VERSION__`; the literal
8
+ // is only a fallback for environments (e.g. unit tests) where it is undefined.
9
+ declare const __SF_API_VERSION__: string;
10
+
11
+ /** Project-standard API version, mirroring `@salesforce/ui-bundle/api`'s clients. */
12
+ const API_VERSION: string = typeof __SF_API_VERSION__ !== "undefined" ? __SF_API_VERSION__ : "65.0";
13
+
14
+ /**
15
+ * The bundle's build-time API version as a number (e.g. `68.0`), i.e. the
16
+ * version the SDK's GraphQL/REST requests are actually issued at. `0` when it
17
+ * cannot be parsed. Distinct from the org's advertised max version.
18
+ */
19
+ export function getBuildApiVersion(): number {
20
+ const v = Number.parseFloat(API_VERSION);
21
+ return Number.isFinite(v) ? v : 0;
22
+ }
23
+
24
+ /**
25
+ * Percent-encodes a single path segment (SSRF / path-injection guard). Mirrors
26
+ * the reference `safeEncodePath`.
27
+ */
28
+ export function safeEncodePath(segment: string): string {
29
+ return encodeURIComponent(segment);
30
+ }
31
+
32
+ /** Builds an absolute Connect REST URL from a version-relative sub-path. */
33
+ export function connectUrl(subPath: string): string {
34
+ const normalized = subPath.startsWith("/") ? subPath : `/${subPath}`;
35
+ return `/services/data/v${API_VERSION}/connect${normalized}`;
36
+ }
37
+
38
+ /**
39
+ * GETs a Connect JSON resource via the platform SDK's authenticated `fetch`
40
+ * and returns the parsed body. Throws on SDK-init failure or a non-OK response
41
+ * (the caller decides how a whole-request failure surfaces).
42
+ */
43
+ export async function connectGetJson<T = unknown>(url: string): Promise<T> {
44
+ const sdk = await createDataSDK();
45
+ if (!sdk?.fetch) {
46
+ throw new Error("Failed to initialize data SDK for CMS REST call");
47
+ }
48
+ const response = await sdk.fetch(url, {
49
+ method: "GET",
50
+ headers: { Accept: "application/json" },
51
+ });
52
+ if (!response.ok) {
53
+ throw new Error(`CMS REST request failed: ${response.status} ${response.statusText}`);
54
+ }
55
+ return (await response.json()) as T;
56
+ }
@@ -0,0 +1,37 @@
1
+ /** Service to gate CMS search on the bundle's build-time API version. */
2
+
3
+ import { getBuildApiVersion } from "./apiUtils";
4
+
5
+ /** Minimum API version that supports CMS search. */
6
+ export const MIN_CMS_API_VERSION = 68;
7
+
8
+ /**
9
+ * Whether CMS search can run — the synchronous core of the gate. Gated on the
10
+ * bundle's build-time API version (`__SF_API_VERSION__`, injected from the
11
+ * resolved org's API version at build time) being >= {@link MIN_CMS_API_VERSION}.
12
+ *
13
+ * The build version is the version every SDK GraphQL/REST request is actually
14
+ * issued at, so it already reflects a concrete, org-supported API version: a
15
+ * bundle built against an org resolves that org's max version, and a bundle
16
+ * built below v68 sends its CMS query to `/services/data/v67.0/graphql` where
17
+ * the v68 CMS backend is unavailable. Gating on the build version alone is
18
+ * therefore both necessary and sufficient — and, unlike a runtime probe of the
19
+ * bare `/services/data/` version-listing endpoint (which is not routed on guest
20
+ * Experience Sites and would fail-close there), it works on every surface.
21
+ *
22
+ * Because it reads only the baked build version, it is safe to call during
23
+ * render — e.g. to hide the CMS source's scope entry and result section when
24
+ * the backend isn't available (see `ScopeSelector` and `SearchResults`).
25
+ */
26
+ export function isCmsSearchSupported(): boolean {
27
+ return getBuildApiVersion() >= MIN_CMS_API_VERSION;
28
+ }
29
+
30
+ /**
31
+ * Resolves whether CMS search can run. Thin async wrapper over
32
+ * {@link isCmsSearchSupported} that preserves the existing fetch-path call-site
33
+ * contract (the fetch effect awaits it alongside the async UIBundle-id lookup).
34
+ */
35
+ export function getOrgSupportsCmsSearch(): Promise<boolean> {
36
+ return Promise.resolve(isCmsSearchSupported());
37
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Connect REST caller for a CMS channel's searchable content types:
3
+ * GET /connect/cms/channels/{channelId}/searchable-content-types?page=N&pageSize=25
4
+ * Returns the validated content types (FQN + server label) that populate the
5
+ * content-type scope entries.
6
+ */
7
+
8
+ import { connectGetJson, connectUrl, safeEncodePath } from "./apiUtils";
9
+ import {
10
+ isValidCmsFqn,
11
+ formatContentTypeLabel,
12
+ type DiscoveredContentType,
13
+ } from "../contentTypeUtils";
14
+
15
+ /** Hard-coded REST page size. NEVER user input. */
16
+ const REST_PAGE_SIZE = 25;
17
+
18
+ /** Safety cap so a misbehaving backend cannot spin an unbounded loop. */
19
+ const MAX_PAGES = 100;
20
+
21
+ /** Channel id shape guard — `0ap` + 12–15 alphanumerics — validates the discovery channel id before the searchable-content-types REST call. */
22
+ export const CHANNEL_ID_PATTERN = /^0ap[a-zA-Z0-9]{12,15}$/;
23
+
24
+ /** One raw entry from the Connect response. */
25
+ interface RawContentTypeEntry {
26
+ /** FQN with the `sfdc_cms__` prefix (e.g. "sfdc_cms__news"). */
27
+ id?: string;
28
+ /** Server-provided display name (e.g. "News"). */
29
+ label?: string;
30
+ /** Bare developer name without the prefix (e.g. "news"). */
31
+ name?: string;
32
+ // Legacy/alternate FQN field names kept as fallbacks.
33
+ contentType?: string;
34
+ fqn?: string;
35
+ developerName?: string;
36
+ isSearchable?: boolean;
37
+ searchable?: boolean;
38
+ }
39
+
40
+ /** Loose shape of one page of the Connect response. */
41
+ interface RawContentTypesPage {
42
+ items?: RawContentTypeEntry[];
43
+ contentTypes?: RawContentTypeEntry[];
44
+ }
45
+
46
+ /** Reads the entries array from a page payload (array or object form). */
47
+ function pageItems(payload: unknown): RawContentTypeEntry[] {
48
+ if (Array.isArray(payload)) return payload as RawContentTypeEntry[];
49
+ const obj = payload as RawContentTypesPage | null;
50
+ if (obj?.items && Array.isArray(obj.items)) return obj.items;
51
+ if (obj?.contentTypes && Array.isArray(obj.contentTypes)) return obj.contentTypes;
52
+ return [];
53
+ }
54
+
55
+ /** True when the entry is not explicitly marked non-searchable. */
56
+ function isSearchable(entry: RawContentTypeEntry): boolean {
57
+ if (typeof entry.isSearchable === "boolean") return entry.isSearchable;
58
+ if (typeof entry.searchable === "boolean") return entry.searchable;
59
+ // No flag present → do not exclude on searchability (FQN validity still gates).
60
+ return true;
61
+ }
62
+
63
+ /**
64
+ * Extracts the prefixed FQN from an entry. `id` is the current field; the
65
+ * others are fallbacks for alternate/legacy payloads. `name` is intentionally
66
+ * NOT read here — it is the bare (unprefixed) developer name and would fail
67
+ * `isValidCmsFqn`.
68
+ */
69
+ function entryFqn(entry: RawContentTypeEntry): string | undefined {
70
+ return entry.id ?? entry.contentType ?? entry.fqn ?? entry.developerName;
71
+ }
72
+
73
+ /**
74
+ * Fetches every searchable content type for `channelId`, paginating the
75
+ * Connect endpoint until a short page is returned, then filtering to searchable
76
+ * entries whose FQN passes `isValidCmsFqn`. Each result carries the FQN and the
77
+ * server-provided display `label` (falling back to a derived label only when
78
+ * the response omits one). De-duplicates by FQN, preserving first-seen order.
79
+ *
80
+ * @throws when `channelId` fails the shape guard (before any network call).
81
+ */
82
+ export async function fetchSearchableContentTypes(
83
+ channelId: string,
84
+ ): Promise<DiscoveredContentType[]> {
85
+ if (!CHANNEL_ID_PATTERN.test(channelId)) {
86
+ throw new Error(`Invalid CMS channel id "${channelId}".`);
87
+ }
88
+
89
+ const encoded = safeEncodePath(channelId);
90
+ const collected: DiscoveredContentType[] = [];
91
+ const seen = new Set<string>();
92
+
93
+ for (let page = 0; page < MAX_PAGES; page++) {
94
+ const url = connectUrl(
95
+ `/cms/channels/${encoded}/searchable-content-types?page=${page}&pageSize=${REST_PAGE_SIZE}`,
96
+ );
97
+ const payload = await connectGetJson(url);
98
+ const items = pageItems(payload);
99
+
100
+ for (const entry of items) {
101
+ const fqn = entryFqn(entry);
102
+ if (!fqn || !isSearchable(entry) || !isValidCmsFqn(fqn) || seen.has(fqn)) {
103
+ continue;
104
+ }
105
+ seen.add(fqn);
106
+ // Prefer the server label; fall back to a label derived from the FQN.
107
+ const label = entry.label?.trim() || formatContentTypeLabel(fqn);
108
+ collected.push({ fqn, label });
109
+ }
110
+
111
+ // Last page reached when fewer than a full page came back.
112
+ if (items.length < REST_PAGE_SIZE) break;
113
+ }
114
+
115
+ return collected;
116
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Extracts the CMS channel id from a search result so it can feed the
3
+ * searchable-content-types Connect endpoint. There is one CMS channel for the
4
+ * app, so any result carries it:
5
+ *
6
+ * nodes[0].managedContentChannelDeliveryDetails[0].managedContentChannelDetails.id
7
+ *
8
+ * Returns `null` when any hop is missing (empty nodes, missing delivery
9
+ * details, missing channel details / id) — the caller simply skips discovery.
10
+ */
11
+
12
+ import type { SourceResult } from "../../types";
13
+ import type { CmsSearchResponse, CmsSearchItem } from "./types";
14
+
15
+ /** Accepts either a normalised `SourceResult` or a raw `CmsSearchResponse`. */
16
+ type ChannelSource = SourceResult | CmsSearchResponse | null | undefined;
17
+
18
+ function getNodes(result: ChannelSource): unknown[] {
19
+ if (!result) return [];
20
+ // SourceResult carries `nodes`; CmsSearchResponse carries `items`.
21
+ if ("nodes" in result && Array.isArray(result.nodes)) return result.nodes;
22
+ if ("items" in result && Array.isArray(result.items)) return result.items;
23
+ return [];
24
+ }
25
+
26
+ /**
27
+ * Returns the channel id derived from the first result's delivery details, or
28
+ * `null` when any level is absent. Validate the returned id's shape before it
29
+ * enters a REST path (the discovery service does this).
30
+ */
31
+ export function resolveChannelId(result: ChannelSource): string | null {
32
+ const nodes = getNodes(result);
33
+ const first = nodes[0] as Partial<CmsSearchItem> | undefined;
34
+ if (!first) return null;
35
+
36
+ const delivery = first.managedContentChannelDeliveryDetails?.[0];
37
+ const id = delivery?.managedContentChannelDetails?.id;
38
+
39
+ return typeof id === "string" && id.length > 0 ? id : null;
40
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Builds the CMS `managed_content { search { searchContentInChannels … } }`
3
+ * fragment as a {@link QueryFragmentContribution} with `placement: "root"` — a
4
+ * sibling of the `uiapi` block in the combined document.
5
+ *
6
+ * The `$cmsContentTypeFQNs` declaration, its `contentTypeFQNs:` argument, and
7
+ * its variable value are all emitted only when a non-empty content-type list is
8
+ * passed; on the bootstrap call (no types known) they are omitted entirely.
9
+ */
10
+
11
+ import type { QueryFragmentContribution } from "../types";
12
+
13
+ export interface BuildCmsFragmentParams {
14
+ /** Search keyword → `$cmsKeyword`. */
15
+ keyword: string;
16
+ /** UIBundle Id fed into the query → `$UIBundleId` (from `getUIBundleId()`). */
17
+ uiBundleId: string;
18
+ /** Pagination offset → `$cmsOffset` (already clamped `>= 0` by the caller). */
19
+ offset: number;
20
+ /** Page size → `$cmsLimit` (validated against `pageSizeOptions` upstream). */
21
+ limit: number;
22
+ /**
23
+ * Discovered/selected content-type FQNs → the schema's `contentTypeFQNs`
24
+ * argument (via `$cmsContentTypeFQNs`). When absent, null, or empty, those
25
+ * pieces are omitted entirely (bootstrap call). Callers pass ONLY
26
+ * `isValidCmsFqn`-validated values.
27
+ */
28
+ contentTypes?: string[] | null;
29
+ }
30
+
31
+ /**
32
+ * Builds the CMS fragment contribution. The content-type filter pieces are
33
+ * included only when `params.contentTypes` is a non-empty array.
34
+ */
35
+ export function buildCmsQueryFragment(params: BuildCmsFragmentParams): QueryFragmentContribution {
36
+ const { keyword, uiBundleId, offset, limit, contentTypes } = params;
37
+
38
+ const hasContentTypes = Array.isArray(contentTypes) && contentTypes.length > 0;
39
+
40
+ const variableDeclarations = [
41
+ "$cmsKeyword: String!",
42
+ "$UIBundleId: ID!",
43
+ "$cmsOffset: Int!",
44
+ "$cmsLimit: Int!",
45
+ ];
46
+
47
+ const variables: Record<string, unknown> = {
48
+ cmsKeyword: keyword,
49
+ UIBundleId: uiBundleId,
50
+ cmsOffset: offset,
51
+ cmsLimit: limit,
52
+ };
53
+
54
+ // CONDITIONAL: declare + pass + supply the content-type filter only when a
55
+ // non-empty list is provided. Otherwise these three pieces are all absent.
56
+ // The schema argument is `contentTypeFQNs` (a list of content-type FQNs) —
57
+ // NOT `contentTypes`; the latter is rejected as an unknown field argument.
58
+ const contentTypesArg = hasContentTypes ? "\n contentTypeFQNs: $cmsContentTypeFQNs" : "";
59
+ if (hasContentTypes) {
60
+ variableDeclarations.push("$cmsContentTypeFQNs: [String!]");
61
+ variables.cmsContentTypeFQNs = contentTypes;
62
+ }
63
+
64
+ const fragment = `managed_content {
65
+ search {
66
+ searchContentInChannels(
67
+ searchIdentifiers: { uibundleIds: [$UIBundleId] }
68
+ keyword: $cmsKeyword
69
+ pagination: { limit: $cmsLimit, offset: $cmsOffset }${contentTypesArg}
70
+ ) {
71
+ total
72
+ offset
73
+ pageSize
74
+ items {
75
+ managedContentId
76
+ managedContentKey
77
+ title
78
+ contentType
79
+ language
80
+ highlightedSnippet
81
+ managedContentChannelDeliveryDetails {
82
+ contentUrl
83
+ publishedDate
84
+ managedContentChannelDetails { id name type }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }`;
90
+
91
+ return {
92
+ variableDeclarations,
93
+ variables,
94
+ placement: "root",
95
+ fragment,
96
+ };
97
+ }