@salesforce/templates 66.11.1 → 66.13.0
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/lib/generators/projectGenerator.js +4 -1
- package/lib/generators/projectGenerator.js.map +1 -1
- package/lib/generators/uiEmbeddingGenerator.d.ts +6 -0
- package/lib/generators/{lightningEmbeddingGenerator.js → uiEmbeddingGenerator.js} +12 -12
- package/lib/generators/uiEmbeddingGenerator.js.map +1 -0
- package/lib/i18n/i18n.d.ts +6 -6
- package/lib/i18n/i18n.js +6 -6
- package/lib/i18n/i18n.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/templates/project/angularextapp/.forceignore +15 -0
- package/lib/templates/project/angularextapp/.husky/pre-commit +4 -0
- package/lib/templates/project/angularextapp/.prettierignore +11 -0
- package/lib/templates/project/angularextapp/.prettierrc +17 -0
- package/lib/templates/project/angularextapp/CHANGELOG.md +4086 -0
- package/lib/templates/project/angularextapp/README.md +77 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_d_/_s_/angularextapp1/angularextapp1.digitalExperience-meta.xml +11 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_d_/_s_/angularextapp1/sfdc_cms__site/angularextapp1/_meta.json +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_d_/_s_/angularextapp1/sfdc_cms__site/angularextapp1/content.json +10 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_dc_/angularextapp1.digitalExperienceConfig-meta.xml +8 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/.forceignore +15 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/.postcssrc.json +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/.prettierignore +8 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/.prettierrc +12 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/CHANGELOG.md +4 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/README.md +85 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/angular.json +101 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/angularextapp.uibundle-meta.xml +8 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/e2e/app.spec.ts +15 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/esbuild/api-version.mjs +17 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/eslint.config.js +60 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/middleware/html.mjs +3 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/middleware/proxy.mjs +12 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/package-lock.json +13600 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/package.json +56 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/playwright.config.ts +25 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/public/favicon.ico +0 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/scripts/rewrite-e2e-assets.mjs +30 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/account/account-search.service.ts +196 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/account/distinctAccountIndustries.ts +26 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/account/distinctAccountTypes.ts +26 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/account/getAccountDetail.ts +128 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/account/searchAccounts.ts +58 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/data-client.service.spec.ts +184 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/data-client.service.ts +74 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/api/user-profile.service.ts +126 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/app.config.ts +22 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/app.html +1 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/app.routes.ts +77 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/app.spec.ts +18 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/app.ts +15 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/layout/app-layout/app-layout.html +53 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/layout/app-layout/app-layout.spec.ts +89 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/layout/app-layout/app-layout.ts +81 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/_field-size.scss +42 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/alert/alert.html +31 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/alert/alert.ts +53 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/button/button.html +18 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/button/button.scss +112 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/button/button.ts +57 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/card/card.scss +34 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/card/card.ts +110 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/collapsible/collapsible.html +10 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/collapsible/collapsible.ts +26 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-picker/date-picker.html +25 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-picker/date-picker.scss +36 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-picker/date-picker.ts +41 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-range-picker/date-range-picker.html +34 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-range-picker/date-range-picker.scss +33 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-range-picker/date-range-picker.ts +66 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/dialog/dialog.html +37 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/dialog/dialog.ts +55 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/field/field.html +21 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/field/field.ts +36 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/field-size.ts +8 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/input/input.html +19 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/input/input.scss +35 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/input/input.ts +36 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/label/label.html +3 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/label/label.ts +17 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/paginator/paginator.html +10 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/paginator/paginator.ts +37 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/popover/popover.html +41 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/popover/popover.ts +40 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/select/select.html +24 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/select/select.scss +35 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/select/select.ts +72 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/separator/separator.html +1 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/separator/separator.scss +23 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/separator/separator.ts +56 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/skeleton/skeleton.html +1 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/skeleton/skeleton.scss +28 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/skeleton/skeleton.ts +24 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/components/ui/spinner/spinner.ts +35 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/auth/auth.guard.ts +50 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/auth/auth.service.ts +126 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/auth-form/auth-form.html +34 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/auth-form/auth-form.ts +94 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/auth-layout/auth-layout.html +2 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/auth-layout/auth-layout.ts +30 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/card-layout/card-layout.html +16 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/card-layout/card-layout.ts +40 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/config/authentication.config.ts +75 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/footer-link/footer-link.html +9 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/footer-link/footer-link.ts +26 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/menu/auth-menu/auth-menu.html +26 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/menu/auth-menu/auth-menu.ts +46 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/reactive-form-page.base.ts +50 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/session/session.html +55 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/session/session.ts +205 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/status-alert/status-alert.html +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/status-alert/status-alert.ts +52 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/submit-button/submit-button.html +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/submit-button/submit-button.scss +17 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/submit-button/submit-button.ts +35 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/utils/auth-helpers.ts +68 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/utils/auth-validators.ts +72 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/utils/helpers.ts +85 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/utils/session-time-servlet.ts +130 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/utils/session-timeout.config.ts +83 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/authentication/utils/session-timeout.service.ts +201 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/breadcrumb/breadcrumb.html +54 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/breadcrumb/breadcrumb.ts +40 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/active-filters.html +23 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/active-filters.ts +78 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-filter.html +18 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-filter.ts +137 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-range-filter.html +11 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-range-filter.ts +69 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/filter-field-wrapper.html +11 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/filter-field-wrapper.ts +36 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/multi-select-filter.html +10 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/multi-select-filter.ts +58 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/numeric-range-filter.html +22 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/numeric-range-filter.ts +146 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/search-filter.html +8 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/search-filter.ts +82 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/select-filter.html +12 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/select-filter.ts +65 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/text-filter.html +12 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/text-filter.ts +90 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/object-search-state.service.ts +232 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/pagination/pagination.html +8 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/pagination/pagination.ts +61 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/search-bar/search-bar.html +59 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/search-bar/search-bar.ts +108 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/sort-control/sort-control.html +50 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/sort-control/sort-control.ts +72 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/debounce.ts +31 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/field-utils.ts +54 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/filter-utils.ts +354 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/index.ts +12 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/sort-utils.ts +46 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/account-detail/account-detail-page.html +164 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/account-detail/account-detail-page.scss +7 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/account-detail/account-detail-page.ts +196 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/account-search/account-search-page.html +111 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/account-search/account-search-page.ts +217 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/change-password/change-password-page.html +68 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/change-password/change-password-page.ts +82 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/forgot-password/forgot-password-page.html +35 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/forgot-password/forgot-password-page.ts +87 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/home/home-page.html +18 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/home/home-page.ts +47 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/home/home.html +6 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/home/home.spec.ts +23 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/home/home.ts +13 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/login/login-page.html +47 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/login/login-page.ts +89 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/not-found/not-found.html +12 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/not-found/not-found.spec.ts +33 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/not-found/not-found.ts +15 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/profile/profile-page.html +116 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/profile/profile-page.ts +194 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/register/register-page.html +80 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/register/register-page.ts +93 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/reset-password/reset-password-page.html +60 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/pages/reset-password/reset-password-page.ts +96 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/app/utils/async-data.ts +99 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/index.html +14 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/main.ts +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/styles.scss +170 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/theme.scss +39 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/src/types/sf-globals.d.ts +9 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/tsconfig.app.json +11 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/tsconfig.json +33 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/tsconfig.spec.json +10 -0
- package/lib/templates/project/angularextapp/_p_/_m_/_w_/_a_/ui-bundle.json +7 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleAuthUtils.cls +68 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleAuthUtils.cls-meta.xml +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleChangePassword.cls +77 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleChangePassword.cls-meta.xml +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleForgotPassword.cls +71 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleForgotPassword.cls-meta.xml +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleLogin.cls +105 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleLogin.cls-meta.xml +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleRegistration.cls +162 -0
- package/lib/templates/project/angularextapp/_p_/_m_/classes/UIBundleRegistration.cls-meta.xml +5 -0
- package/lib/templates/project/angularextapp/_p_/_m_/networks/angularextapp.network-meta.xml +60 -0
- package/lib/templates/project/angularextapp/_p_/_m_/package.xml +24 -0
- package/lib/templates/project/angularextapp/_p_/_m_/permissionsets/angularextapp_Guest_User_Api_Access.permissionset-meta.xml +9 -0
- package/lib/templates/project/angularextapp/_p_/_m_/sites/angularextapp.site-meta.xml +31 -0
- package/lib/templates/project/angularextapp/config/project-scratch-def.json +13 -0
- package/lib/templates/project/angularextapp/eslint.config.js +7 -0
- package/lib/templates/project/angularextapp/jest.config.js +6 -0
- package/lib/templates/project/angularextapp/package.json +46 -0
- package/lib/templates/project/angularextapp/scripts/apex/hello.apex +10 -0
- package/lib/templates/project/angularextapp/scripts/gitignore-templates.json +4 -0
- package/lib/templates/project/angularextapp/scripts/graphql-search.sh +191 -0
- package/lib/templates/project/angularextapp/scripts/org-setup-config-schema.mjs +103 -0
- package/lib/templates/project/angularextapp/scripts/org-setup-dev.mjs +87 -0
- package/lib/templates/project/angularextapp/scripts/org-setup-utils.mjs +369 -0
- package/lib/templates/project/angularextapp/scripts/org-setup-xml.mjs +182 -0
- package/lib/templates/project/angularextapp/scripts/org-setup.config.json +9 -0
- package/lib/templates/project/angularextapp/scripts/org-setup.mjs +1702 -0
- package/lib/templates/project/angularextapp/scripts/sf-project-setup.mjs +103 -0
- package/lib/templates/project/angularextapp/scripts/soql/account.soql +6 -0
- package/lib/templates/project/angularextapp/scripts/validate-org-setup-config.mjs +38 -0
- package/lib/templates/project/angularextapp/sfdx-project.json +12 -0
- package/lib/templates/project/angularintapp/.forceignore +15 -0
- package/lib/templates/project/angularintapp/.husky/pre-commit +4 -0
- package/lib/templates/project/angularintapp/.prettierignore +11 -0
- package/lib/templates/project/angularintapp/.prettierrc +17 -0
- package/lib/templates/project/angularintapp/CHANGELOG.md +4086 -0
- package/lib/templates/project/angularintapp/README.md +77 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/.forceignore +15 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/.postcssrc.json +5 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/.prettierignore +8 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/.prettierrc +12 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/CHANGELOG.md +4 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/README.md +85 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/angular.json +101 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/angularintapp.uibundle-meta.xml +8 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/e2e/app.spec.ts +15 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/esbuild/api-version.mjs +17 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/eslint.config.js +60 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/middleware/html.mjs +3 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/middleware/proxy.mjs +12 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/package-lock.json +13619 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/package.json +57 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/playwright.config.ts +25 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/public/favicon.ico +0 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/scripts/rewrite-e2e-assets.mjs +30 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/api/account/account-search.service.ts +196 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/api/account/distinctAccountIndustries.ts +26 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/api/account/distinctAccountTypes.ts +26 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/api/account/getAccountDetail.ts +128 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/api/account/searchAccounts.ts +58 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/api/data-client.service.spec.ts +184 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/api/data-client.service.ts +74 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/app.config.ts +22 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/app.html +1 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/app.routes.ts +31 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/app.spec.ts +18 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/app.ts +15 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/layout/app-layout/app-layout.html +52 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/layout/app-layout/app-layout.spec.ts +90 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/layout/app-layout/app-layout.ts +67 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/_field-size.scss +42 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/alert/alert.html +31 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/alert/alert.ts +53 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/button/button.html +18 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/button/button.scss +112 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/button/button.ts +57 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/card/card.scss +34 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/card/card.ts +110 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/collapsible/collapsible.html +10 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/collapsible/collapsible.ts +26 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-picker/date-picker.html +25 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-picker/date-picker.scss +36 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-picker/date-picker.ts +41 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-range-picker/date-range-picker.html +34 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-range-picker/date-range-picker.scss +33 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/date-range-picker/date-range-picker.ts +66 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/dialog/dialog.html +37 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/dialog/dialog.ts +55 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/field/field.html +21 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/field/field.ts +36 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/field-size.ts +8 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/input/input.html +19 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/input/input.scss +35 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/input/input.ts +36 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/label/label.html +3 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/label/label.ts +17 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/paginator/paginator.html +10 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/paginator/paginator.ts +37 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/popover/popover.html +41 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/popover/popover.ts +40 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/select/select.html +24 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/select/select.scss +35 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/select/select.ts +72 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/separator/separator.html +1 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/separator/separator.scss +23 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/separator/separator.ts +56 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/skeleton/skeleton.html +1 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/skeleton/skeleton.scss +28 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/skeleton/skeleton.ts +24 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/components/ui/spinner/spinner.ts +35 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/agentforce/agentforce-embed.service.ts +177 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/agentforce/conversation.html +3 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/agentforce/conversation.ts +119 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/breadcrumb/breadcrumb.html +54 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/breadcrumb/breadcrumb.ts +40 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/active-filters.html +23 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/active-filters.ts +78 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-filter.html +18 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-filter.ts +137 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-range-filter.html +11 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/date-range-filter.ts +69 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/filter-field-wrapper.html +11 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/filter-field-wrapper.ts +36 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/multi-select-filter.html +10 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/multi-select-filter.ts +58 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/numeric-range-filter.html +22 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/numeric-range-filter.ts +146 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/search-filter.html +8 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/search-filter.ts +82 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/select-filter.html +12 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/select-filter.ts +65 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/text-filter.html +12 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/filters/text-filter.ts +90 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/object-search-state.service.ts +232 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/pagination/pagination.html +8 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/pagination/pagination.ts +61 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/search-bar/search-bar.html +59 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/search-bar/search-bar.ts +108 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/sort-control/sort-control.html +50 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/sort-control/sort-control.ts +72 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/debounce.ts +31 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/field-utils.ts +54 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/filter-utils.ts +354 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/index.ts +12 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/features/object-search/utils/sort-utils.ts +46 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/account-detail/account-detail-page.html +164 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/account-detail/account-detail-page.scss +7 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/account-detail/account-detail-page.ts +196 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/account-search/account-search-page.html +111 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/account-search/account-search-page.ts +217 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/home/home-page.html +18 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/home/home-page.ts +47 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/home/home.html +6 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/home/home.spec.ts +23 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/home/home.ts +13 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/not-found/not-found.html +12 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/not-found/not-found.spec.ts +33 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/pages/not-found/not-found.ts +15 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/types/conversation.ts +55 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/types/globals.d.ts +13 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/app/utils/async-data.ts +99 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/index.html +14 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/index.ts +15 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/main.ts +5 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/styles.scss +170 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/theme.scss +39 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/src/types/sf-globals.d.ts +9 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/tsconfig.app.json +11 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/tsconfig.json +33 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/tsconfig.spec.json +10 -0
- package/lib/templates/project/angularintapp/_p_/_m_/_w_/_a_/ui-bundle.json +7 -0
- package/lib/templates/project/angularintapp/_p_/_m_/applications/angularintapp.app-meta.xml +17 -0
- package/lib/templates/project/angularintapp/_p_/_m_/permissionsets/angularintapp_Access.permissionset-meta.xml +13 -0
- package/lib/templates/project/angularintapp/config/project-scratch-def.json +13 -0
- package/lib/templates/project/angularintapp/eslint.config.js +7 -0
- package/lib/templates/project/angularintapp/jest.config.js +6 -0
- package/lib/templates/project/angularintapp/package.json +46 -0
- package/lib/templates/project/angularintapp/scripts/apex/hello.apex +10 -0
- package/lib/templates/project/angularintapp/scripts/gitignore-templates.json +4 -0
- package/lib/templates/project/angularintapp/scripts/graphql-search.sh +191 -0
- package/lib/templates/project/angularintapp/scripts/org-setup-config-schema.mjs +103 -0
- package/lib/templates/project/angularintapp/scripts/org-setup-dev.mjs +87 -0
- package/lib/templates/project/angularintapp/scripts/org-setup-utils.mjs +369 -0
- package/lib/templates/project/angularintapp/scripts/org-setup-xml.mjs +182 -0
- package/lib/templates/project/angularintapp/scripts/org-setup.config.json +9 -0
- package/lib/templates/project/angularintapp/scripts/org-setup.mjs +1702 -0
- package/lib/templates/project/angularintapp/scripts/sf-project-setup.mjs +103 -0
- package/lib/templates/project/angularintapp/scripts/soql/account.soql +6 -0
- package/lib/templates/project/angularintapp/scripts/validate-org-setup-config.mjs +38 -0
- package/lib/templates/project/angularintapp/sfdx-project.json +12 -0
- package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/package-lock.json +601 -572
- package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/package-lock.json +601 -572
- package/lib/templates/uiBundles/angularbasic/package-lock.json +147 -168
- package/lib/templates/uiBundles/reactbasic/package-lock.json +601 -572
- package/lib/templates/{lightningembedding → uiembedding}/default/default.html +3 -3
- package/lib/templates/{lightningembedding → uiembedding}/default/default.js +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/types.d.ts +5 -5
- package/lib/utils/types.js +3 -3
- package/lib/utils/types.js.map +1 -1
- package/lib/utils/uiBundleTemplateUtils.js +10 -0
- package/lib/utils/uiBundleTemplateUtils.js.map +1 -1
- package/lib/utils/uiEmbedding.d.ts +12 -0
- package/lib/utils/{lightningEmbedding.js → uiEmbedding.js} +7 -7
- package/lib/utils/uiEmbedding.js.map +1 -0
- package/package.json +4 -2
- package/lib/generators/lightningEmbeddingGenerator.d.ts +0 -6
- package/lib/generators/lightningEmbeddingGenerator.js.map +0 -1
- package/lib/utils/lightningEmbedding.d.ts +0 -12
- package/lib/utils/lightningEmbedding.js.map +0 -1
- /package/lib/templates/{lightningembedding → uiembedding}/default/default.css +0 -0
- /package/lib/templates/{lightningembedding → uiembedding}/default/default.js-meta.xml +0 -0
|
@@ -0,0 +1,1702 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* One-command setup: login, deploy, optional permset/data, GraphQL schema/codegen, UI bundle build.
|
|
4
|
+
* Use this script to make setup easier for each app generated from this template.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* node scripts/org-setup.mjs --target-org <alias> # interactive step picker (all selected)
|
|
8
|
+
* node scripts/org-setup.mjs # prompt to pick an authenticated org
|
|
9
|
+
* node scripts/org-setup.mjs --target-org <alias> --yes # skip picker, run all steps
|
|
10
|
+
* node scripts/org-setup.mjs --target-org afv5 --skip-data --skip-ui-bundle-build
|
|
11
|
+
* node scripts/org-setup.mjs --target-org myorg --ui-bundle-name my-app
|
|
12
|
+
*
|
|
13
|
+
* Login is an unconditional precondition (not a toggleable step); the dev server
|
|
14
|
+
* is launched separately via `npm run dev:preview` (scripts/org-setup-dev.mjs).
|
|
15
|
+
*
|
|
16
|
+
* Steps (in order):
|
|
17
|
+
* login (precondition) — sf org login web only if org not already connected; always runs before deploy
|
|
18
|
+
* 1. uiBundle — (all UI bundles) npm install && npm run build so dist exists for deploy (skip with --skip-ui-bundle-build)
|
|
19
|
+
* 2. deploy — sf project deploy start --target-org <alias> (requires dist for entity deployment)
|
|
20
|
+
* 3. permset — assign permsets per org-setup.config.json (skip with --skip-permset; override via --permset-name)
|
|
21
|
+
* 4. data — prepare unique fields + sf data import tree (skipped if no data dir/plan)
|
|
22
|
+
* 5. graphql — (in UI bundle) npm run graphql:schema then npm run graphql:codegen
|
|
23
|
+
*
|
|
24
|
+
* Permset assignment config (scripts/org-setup.config.json):
|
|
25
|
+
* {
|
|
26
|
+
* "permsetAssignments": {
|
|
27
|
+
* "defaultAssignee": "skip",
|
|
28
|
+
* "assignments": {
|
|
29
|
+
* "My_Permset": { "assignee": "currentUser" },
|
|
30
|
+
* "Guest_Permset": { "assignee": "guestUser" },
|
|
31
|
+
* "Internal_Only": { "assignee": "skip" }
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* Assignee values: "currentUser", "guestUser", or "skip". For "guestUser" the
|
|
36
|
+
* site is derived from the single networks/<siteName>.network-meta.xml the app
|
|
37
|
+
* ships — it is not restated per assignment.
|
|
38
|
+
* Unlisted permsets resolve to "defaultAssignee" (default "skip").
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import { spawnSync, spawn as nodeSpawn } from 'node:child_process';
|
|
42
|
+
import { resolve, dirname, join } from 'node:path';
|
|
43
|
+
import { fileURLToPath } from 'node:url';
|
|
44
|
+
import {
|
|
45
|
+
readdirSync,
|
|
46
|
+
existsSync,
|
|
47
|
+
readFileSync,
|
|
48
|
+
writeFileSync,
|
|
49
|
+
mkdtempSync,
|
|
50
|
+
rmSync,
|
|
51
|
+
openSync,
|
|
52
|
+
closeSync,
|
|
53
|
+
} from 'node:fs';
|
|
54
|
+
import { tmpdir } from 'node:os';
|
|
55
|
+
|
|
56
|
+
import { validateConfig } from './org-setup-config-schema.mjs';
|
|
57
|
+
import {
|
|
58
|
+
addProfileToMemberGroups,
|
|
59
|
+
enableSelfRegInXml,
|
|
60
|
+
NetworkXmlError,
|
|
61
|
+
} from './org-setup-xml.mjs';
|
|
62
|
+
import {
|
|
63
|
+
discoverAllUIBundleDirs as discoverAllUIBundleDirsIn,
|
|
64
|
+
discoverUIBundleDir as discoverUIBundleDirIn,
|
|
65
|
+
resolveTargetOrg,
|
|
66
|
+
evaluateLicenseRows,
|
|
67
|
+
validateProfileNameForSoql,
|
|
68
|
+
} from './org-setup-utils.mjs';
|
|
69
|
+
|
|
70
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
71
|
+
const ROOT = resolve(__dirname, '..');
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Thrown by step runners (run/runAsync) when a subprocess fails. The per-step
|
|
75
|
+
* orchestration in main() catches it, records the failure in the result ledger,
|
|
76
|
+
* and either aborts (fail-fast steps) or continues (skippable steps).
|
|
77
|
+
*/
|
|
78
|
+
class StepError extends Error {}
|
|
79
|
+
|
|
80
|
+
const APEX_TMP_PREFIX = 'org-setup-';
|
|
81
|
+
// Legacy fixed-name temp files that older versions of this script wrote to ROOT
|
|
82
|
+
// and could leave behind on a hard kill. Swept at startup for backward cleanup.
|
|
83
|
+
const LEGACY_ROOT_TMP_FILES = ['.tmp-setup-selfreg.apex', '.tmp-setup-delete.apex'];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Remove leftover Apex temp artifacts from a prior hard-killed run (cleanup AT
|
|
87
|
+
* START). Two sources: per-run dirs under os.tmpdir() created by
|
|
88
|
+
* withApexTempDir, and legacy fixed-name files this script used to write to
|
|
89
|
+
* ROOT. Best-effort: a failure to remove one entry never blocks setup.
|
|
90
|
+
*
|
|
91
|
+
* Scoped to DIRECTORY entries only: the per-run artifacts are dirs created by
|
|
92
|
+
* withApexTempDir via mkdtempSync, whereas the per-org lock files share the same
|
|
93
|
+
* `org-setup-` prefix but are plain files (`org-setup-lock-<org>.lock`). Sweeping
|
|
94
|
+
* files too would delete a live run's lock before acquireOrgLock could see it,
|
|
95
|
+
* defeating the concurrency guard. The dir sweep is still intentionally broad
|
|
96
|
+
* across PIDs; the per-target-org lock acquired in main() is what makes that
|
|
97
|
+
* safe — only one live run per org.
|
|
98
|
+
*/
|
|
99
|
+
function sweepStaleApexTempDirs() {
|
|
100
|
+
const base = tmpdir();
|
|
101
|
+
let entries = [];
|
|
102
|
+
try {
|
|
103
|
+
entries = readdirSync(base, { withFileTypes: true });
|
|
104
|
+
} catch {
|
|
105
|
+
/* tmpdir unreadable — nothing to sweep */
|
|
106
|
+
}
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
if (entry.isDirectory() && entry.name.startsWith(APEX_TMP_PREFIX)) {
|
|
109
|
+
try {
|
|
110
|
+
rmSync(join(base, entry.name), { recursive: true, force: true });
|
|
111
|
+
} catch {
|
|
112
|
+
/* best effort */
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (const legacy of LEGACY_ROOT_TMP_FILES) {
|
|
117
|
+
const p = resolve(ROOT, legacy);
|
|
118
|
+
if (existsSync(p)) {
|
|
119
|
+
try {
|
|
120
|
+
rmSync(p, { force: true });
|
|
121
|
+
} catch {
|
|
122
|
+
/* best effort */
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Run `fn(writeApex)` with a private temp dir under os.tmpdir() that is ALWAYS
|
|
130
|
+
* removed afterwards (cleanup IN FINALLY), even when fn throws or
|
|
131
|
+
* the spawned Apex step fails. `writeApex(basename, contents)` writes a file in
|
|
132
|
+
* that dir and returns its absolute path. Replaces the old fixed-name
|
|
133
|
+
* `.tmp-setup-*.apex` files in ROOT, which collided across concurrent runs and
|
|
134
|
+
* leaked on throw.
|
|
135
|
+
*/
|
|
136
|
+
function withApexTempDir(fn) {
|
|
137
|
+
const dir = mkdtempSync(join(tmpdir(), APEX_TMP_PREFIX));
|
|
138
|
+
try {
|
|
139
|
+
return fn((basename, contents) => {
|
|
140
|
+
const p = join(dir, basename);
|
|
141
|
+
writeFileSync(p, contents);
|
|
142
|
+
return p;
|
|
143
|
+
});
|
|
144
|
+
} finally {
|
|
145
|
+
try {
|
|
146
|
+
rmSync(dir, { recursive: true, force: true });
|
|
147
|
+
} catch {
|
|
148
|
+
/* best effort */
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Filesystem-safe lock path for a target org. */
|
|
154
|
+
function orgLockPath(targetOrg) {
|
|
155
|
+
const safe = String(targetOrg).replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
156
|
+
return join(tmpdir(), `org-setup-lock-${safe}.lock`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Liveness probe: signal 0 throws ESRCH if the pid is gone, EPERM if it exists
|
|
161
|
+
* but we can't signal it (still alive, owned by another user).
|
|
162
|
+
*/
|
|
163
|
+
function isProcessAlive(pid) {
|
|
164
|
+
try {
|
|
165
|
+
process.kill(pid, 0);
|
|
166
|
+
return true;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return e.code === 'EPERM';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Acquire a single-host advisory per-target-org lock. If a LIVE
|
|
174
|
+
* run already holds it, exit early with a clear message rather than interleaving
|
|
175
|
+
* destructive Apex (deletes/imports) against the same org. A lock left by a
|
|
176
|
+
* hard-killed run (dead pid) is reclaimed. Different-org runs use different lock
|
|
177
|
+
* files and proceed in parallel.
|
|
178
|
+
*
|
|
179
|
+
* Released via process.on('exit') — NOT a finally block — because main() exits
|
|
180
|
+
* through process.exit() (the runStep fail-fast path, the end-of-run summary,
|
|
181
|
+
* and the top-level .catch), and process.exit() does not run finally blocks.
|
|
182
|
+
*/
|
|
183
|
+
function acquireOrgLock(targetOrg) {
|
|
184
|
+
const lockPath = orgLockPath(targetOrg);
|
|
185
|
+
if (existsSync(lockPath)) {
|
|
186
|
+
const holder = Number(readFileSync(lockPath, 'utf8').trim());
|
|
187
|
+
if (holder && isProcessAlive(holder)) {
|
|
188
|
+
console.error(
|
|
189
|
+
`\nAnother org-setup run (pid ${holder}) is already targeting "${targetOrg}".\n` +
|
|
190
|
+
`Wait for it to finish, or if it was killed, remove ${lockPath} and retry.`,
|
|
191
|
+
);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
// Stale lock (holder dead / hard-killed) — reclaim it.
|
|
195
|
+
rmSync(lockPath, { force: true });
|
|
196
|
+
}
|
|
197
|
+
// O_EXCL ('wx') create closes the check-then-write race between two
|
|
198
|
+
// near-simultaneous runs: the loser gets EEXIST.
|
|
199
|
+
let fd;
|
|
200
|
+
try {
|
|
201
|
+
fd = openSync(lockPath, 'wx');
|
|
202
|
+
} catch (e) {
|
|
203
|
+
if (e.code === 'EEXIST') {
|
|
204
|
+
console.error(
|
|
205
|
+
`\nAnother org-setup run just acquired the lock for "${targetOrg}". Retry shortly.`,
|
|
206
|
+
);
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
throw e;
|
|
210
|
+
}
|
|
211
|
+
writeFileSync(fd, String(process.pid));
|
|
212
|
+
closeSync(fd);
|
|
213
|
+
|
|
214
|
+
process.on('exit', () => {
|
|
215
|
+
try {
|
|
216
|
+
rmSync(lockPath, { force: true });
|
|
217
|
+
} catch {
|
|
218
|
+
/* best effort */
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* npm strips .gitignore from published packages — generate them on first run.
|
|
225
|
+
* Templates are stored in scripts/gitignore-templates.json (generated at build
|
|
226
|
+
* time from the actual .gitignore files) so the content lives in one place.
|
|
227
|
+
* The JSON may not exist in git-cloned distributions where .gitignore is
|
|
228
|
+
* already present, so loading is best-effort.
|
|
229
|
+
*/
|
|
230
|
+
function loadGitignoreTemplates() {
|
|
231
|
+
const templatesPath = resolve(__dirname, 'gitignore-templates.json');
|
|
232
|
+
if (!existsSync(templatesPath)) return null;
|
|
233
|
+
try {
|
|
234
|
+
return JSON.parse(readFileSync(templatesPath, 'utf8'));
|
|
235
|
+
} catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function ensureGitignore(dir, content) {
|
|
241
|
+
if (!content) return;
|
|
242
|
+
const gitignorePath = resolve(dir, '.gitignore');
|
|
243
|
+
if (!existsSync(gitignorePath)) {
|
|
244
|
+
writeFileSync(gitignorePath, content, 'utf8');
|
|
245
|
+
console.log(`Created .gitignore in ${dir}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function resolveSfdxSource() {
|
|
250
|
+
const sfdxPath = resolve(ROOT, 'sfdx-project.json');
|
|
251
|
+
if (!existsSync(sfdxPath)) {
|
|
252
|
+
console.error('Error: sfdx-project.json not found at project root.');
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
const sfdxProject = JSON.parse(readFileSync(sfdxPath, 'utf8'));
|
|
256
|
+
const pkgDir = sfdxProject?.packageDirectories?.[0]?.path;
|
|
257
|
+
if (!pkgDir) {
|
|
258
|
+
console.error('Error: No packageDirectories[].path found in sfdx-project.json.');
|
|
259
|
+
process.exit(1);
|
|
260
|
+
}
|
|
261
|
+
return resolve(ROOT, pkgDir, 'main', 'default');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const SFDX_SOURCE = resolveSfdxSource();
|
|
265
|
+
const UIBUNDLES_DIR = resolve(SFDX_SOURCE, 'uiBundles');
|
|
266
|
+
const DATA_DIR = resolve(SFDX_SOURCE, 'data');
|
|
267
|
+
const DATA_PLAN = resolve(SFDX_SOURCE, 'data/data-plan.json');
|
|
268
|
+
|
|
269
|
+
function parseArgs() {
|
|
270
|
+
const args = process.argv.slice(2);
|
|
271
|
+
let targetOrg = null;
|
|
272
|
+
let uiBundleName = null;
|
|
273
|
+
/** If non-empty, only these names are assigned; otherwise all discovered from the project. */
|
|
274
|
+
const permsetNamesExplicit = [];
|
|
275
|
+
let yes = false;
|
|
276
|
+
const flags = {
|
|
277
|
+
skipDeploy: false,
|
|
278
|
+
skipPermset: false,
|
|
279
|
+
skipRole: false,
|
|
280
|
+
skipData: false,
|
|
281
|
+
skipGraphql: false,
|
|
282
|
+
skipUIBundleBuild: false,
|
|
283
|
+
skipSelfReg: false,
|
|
284
|
+
};
|
|
285
|
+
for (let i = 0; i < args.length; i++) {
|
|
286
|
+
if (args[i] === '--target-org' && args[i + 1]) {
|
|
287
|
+
targetOrg = args[++i];
|
|
288
|
+
} else if (args[i] === '--ui-bundle-name' && args[i + 1]) {
|
|
289
|
+
uiBundleName = args[++i];
|
|
290
|
+
} else if (args[i] === '--permset-name' && args[i + 1]) {
|
|
291
|
+
permsetNamesExplicit.push(args[++i]);
|
|
292
|
+
} else if (args[i] === '--skip-deploy') flags.skipDeploy = true;
|
|
293
|
+
else if (args[i] === '--skip-permset') flags.skipPermset = true;
|
|
294
|
+
else if (args[i] === '--skip-role') flags.skipRole = true;
|
|
295
|
+
else if (args[i] === '--skip-data') flags.skipData = true;
|
|
296
|
+
else if (args[i] === '--skip-self-reg') flags.skipSelfReg = true;
|
|
297
|
+
else if (args[i] === '--skip-graphql') flags.skipGraphql = true;
|
|
298
|
+
else if (args[i] === '--skip-ui-bundle-build') flags.skipUIBundleBuild = true;
|
|
299
|
+
// --skip-login and --skip-dev are retired (spec §5.5/§5.6, AC-14): login is now
|
|
300
|
+
// an unconditional precondition and the dev step moved to `npm run dev:preview`.
|
|
301
|
+
// Accept them silently as no-ops so existing invocations don't hard-error.
|
|
302
|
+
else if (args[i] === '--skip-login' || args[i] === '--skip-dev') {
|
|
303
|
+
/* no-op (retired flag) */
|
|
304
|
+
} else if (args[i] === '--yes' || args[i] === '-y') yes = true;
|
|
305
|
+
else if (args[i] === '--help' || args[i] === '-h') {
|
|
306
|
+
console.log(`
|
|
307
|
+
Setup CLI — one-command setup for apps in this project
|
|
308
|
+
|
|
309
|
+
Usage:
|
|
310
|
+
node scripts/org-setup.mjs [--target-org <alias>] [options]
|
|
311
|
+
|
|
312
|
+
Options:
|
|
313
|
+
--target-org <alias> Target Salesforce org alias (e.g. myorg). If omitted, you
|
|
314
|
+
are prompted to pick from authenticated orgs (or the
|
|
315
|
+
default org is used when not running interactively).
|
|
316
|
+
--ui-bundle-name <name> UI bundle folder name under uiBundles/ (default: auto-detect)
|
|
317
|
+
--permset-name <name> Assign only this permission set (repeatable). Default: all sets under permissionsets/
|
|
318
|
+
--skip-deploy Do not deploy metadata
|
|
319
|
+
--skip-permset Do not assign permission set
|
|
320
|
+
--skip-data Do not prepare data or run data import
|
|
321
|
+
--skip-graphql Do not fetch schema or run GraphQL codegen
|
|
322
|
+
--skip-ui-bundle-build Do not npm install / build the UI bundle
|
|
323
|
+
-y, --yes Skip interactive step picker; run all enabled steps immediately
|
|
324
|
+
-h, --help Show this help
|
|
325
|
+
|
|
326
|
+
To launch the dev server after setup, run: npm run dev:preview
|
|
327
|
+
|
|
328
|
+
Permset config (scripts/org-setup.config.json):
|
|
329
|
+
Control per-permset assignment via a config file. Example:
|
|
330
|
+
{
|
|
331
|
+
"permsetAssignments": {
|
|
332
|
+
"defaultAssignee": "skip",
|
|
333
|
+
"assignments": {
|
|
334
|
+
"My_Permset": { "assignee": "currentUser" },
|
|
335
|
+
"Guest_Permset": { "assignee": "guestUser" },
|
|
336
|
+
"Internal_Only": { "assignee": "skip" }
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
Assignee values: "currentUser", "guestUser", or "skip". For "guestUser" the site
|
|
341
|
+
is derived from the single networks/<siteName>.network-meta.xml the app ships.
|
|
342
|
+
Unlisted permsets resolve to "defaultAssignee" (default "skip").
|
|
343
|
+
`);
|
|
344
|
+
process.exit(0);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// NOTE: no hard-exit on a missing --target-org here (spec §5.4). Resolution is
|
|
348
|
+
// deferred to resolveTargetOrg(), which either prompts (TTY) or falls back to
|
|
349
|
+
// the default org / exits with a clear message (non-TTY).
|
|
350
|
+
return { targetOrg, uiBundleName, permsetNamesExplicit, yes, ...flags };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Bundle discovery lives in org-setup-utils.mjs so org-setup-dev.mjs shares it verbatim.
|
|
354
|
+
// These thin wrappers bind the shared helpers to this script's UIBUNDLES_DIR and
|
|
355
|
+
// keep the existing call-site signatures. discoverUIBundleDir now carries the
|
|
356
|
+
// multi-bundle acknowledgment of spec §5.1 item 2 (TTY picker / non-TTY warning).
|
|
357
|
+
function discoverAllUIBundleDirs(uiBundleName) {
|
|
358
|
+
return discoverAllUIBundleDirsIn(UIBUNDLES_DIR, uiBundleName);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function discoverUIBundleDir(uiBundleName) {
|
|
362
|
+
return discoverUIBundleDirIn(UIBUNDLES_DIR, uiBundleName);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** API names from permissionsets/*.permissionset-meta.xml in the first package directory. */
|
|
366
|
+
function discoverPermissionSetNames() {
|
|
367
|
+
const dir = resolve(SFDX_SOURCE, 'permissionsets');
|
|
368
|
+
if (!existsSync(dir)) return [];
|
|
369
|
+
const names = [];
|
|
370
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
371
|
+
if (!entry.isFile()) continue;
|
|
372
|
+
const m = entry.name.match(/^(.+)\.permissionset-meta\.xml$/);
|
|
373
|
+
if (m) names.push(m[1]);
|
|
374
|
+
}
|
|
375
|
+
return names.sort();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const CONFIG_PATH = resolve(__dirname, 'org-setup.config.json');
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Read + validate org-setup.config.json ONCE, against the shared zod schema
|
|
382
|
+
* (the same `validateConfig` the build/CI gate uses). Exits non-zero with the
|
|
383
|
+
* precise zod issues if the config is invalid — before any step runs.
|
|
384
|
+
*
|
|
385
|
+
* Returns the validated config object (zod defaults applied), or an empty
|
|
386
|
+
* object when the file is absent (every section is optional).
|
|
387
|
+
*
|
|
388
|
+
* This is the single source of truth: loadPermsetConfig / loadRoleConfig /
|
|
389
|
+
* loadSelfRegConfig all read from the object it returns, so they no longer
|
|
390
|
+
* parse or defensively swallow errors.
|
|
391
|
+
*/
|
|
392
|
+
function loadValidatedConfig() {
|
|
393
|
+
if (!existsSync(CONFIG_PATH)) return {};
|
|
394
|
+
const result = validateConfig(readFileSync(CONFIG_PATH, 'utf8'), CONFIG_PATH);
|
|
395
|
+
if (!result.ok) {
|
|
396
|
+
console.error('Invalid org-setup.config.json:');
|
|
397
|
+
for (const err of result.errors) console.error(` - ${err}`);
|
|
398
|
+
process.exit(1);
|
|
399
|
+
}
|
|
400
|
+
return result.data;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Derive the site name from the single networks/<siteName>.network-meta.xml the
|
|
405
|
+
* app ships. An app ships exactly one site, so the site name is derivable from
|
|
406
|
+
* deployed metadata rather than restated per-assignment. Returns
|
|
407
|
+
* null when there is no networks dir or no .network-meta.xml file.
|
|
408
|
+
*/
|
|
409
|
+
function deriveSiteName() {
|
|
410
|
+
const networksDir = resolve(SFDX_SOURCE, 'networks');
|
|
411
|
+
if (!existsSync(networksDir)) return null;
|
|
412
|
+
const files = readdirSync(networksDir)
|
|
413
|
+
.filter((f) => f.endsWith('.network-meta.xml'))
|
|
414
|
+
.sort();
|
|
415
|
+
if (files.length === 0) return null;
|
|
416
|
+
// An app ships exactly one site; if a developer added a second, derivation is
|
|
417
|
+
// ambiguous — fail loudly rather than silently bind to an arbitrary site.
|
|
418
|
+
if (files.length > 1) {
|
|
419
|
+
throw new StepError(
|
|
420
|
+
`cannot derive guest site: multiple network metadata files found in ${networksDir} (${files.join(', ')}); guestUser assignment requires exactly one`,
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
return files[0].replace(/\.network-meta\.xml$/, '');
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Permset assignment configuration, read from the already-validated config.
|
|
428
|
+
*
|
|
429
|
+
* Config shape:
|
|
430
|
+
* {
|
|
431
|
+
* "permsetAssignments": {
|
|
432
|
+
* "defaultAssignee": "skip",
|
|
433
|
+
* "assignments": {
|
|
434
|
+
* "My_Permset": { "assignee": "currentUser" },
|
|
435
|
+
* "My_Guest_Permset": { "assignee": "guestUser" },
|
|
436
|
+
* "Internal_Only": { "assignee": "skip" }
|
|
437
|
+
* }
|
|
438
|
+
* }
|
|
439
|
+
* }
|
|
440
|
+
*
|
|
441
|
+
* Assignee values:
|
|
442
|
+
* "currentUser" — assign to the user running the script
|
|
443
|
+
* "skip" — do not assign this permset
|
|
444
|
+
* "guestUser" — resolve the site guest user automatically (site derived from
|
|
445
|
+
* the single networks/<siteName>.network-meta.xml the app ships)
|
|
446
|
+
*
|
|
447
|
+
* Unlisted permsets resolve to `defaultAssignee` (default "skip").
|
|
448
|
+
*
|
|
449
|
+
* Returns { defaultAssignee: string, assignments: Record<string, { assignee: string }> }
|
|
450
|
+
*/
|
|
451
|
+
function loadPermsetConfig(config) {
|
|
452
|
+
const section = config.permsetAssignments;
|
|
453
|
+
if (!section) return { defaultAssignee: 'skip', assignments: {} };
|
|
454
|
+
return {
|
|
455
|
+
defaultAssignee: section.defaultAssignee,
|
|
456
|
+
assignments: section.assignments,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** Resolve the effective assignment config for a given permset name. */
|
|
461
|
+
function resolveAssignment(permsetName, permsetConfig) {
|
|
462
|
+
const override = permsetConfig.assignments[permsetName];
|
|
463
|
+
if (!override) return { assignee: permsetConfig.defaultAssignee };
|
|
464
|
+
return { assignee: override.assignee };
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Role assignment config, read from the already-validated config.
|
|
469
|
+
*
|
|
470
|
+
* Config shape:
|
|
471
|
+
* { "role": { "assignee": "currentUser", "roleName": "Admin" } }
|
|
472
|
+
*
|
|
473
|
+
* Returns null if no "role" section exists in config (the step is hidden).
|
|
474
|
+
*/
|
|
475
|
+
function loadRoleConfig(config) {
|
|
476
|
+
const section = config.role;
|
|
477
|
+
if (!section) return null;
|
|
478
|
+
return {
|
|
479
|
+
assignee: section.assignee,
|
|
480
|
+
roleName: section.roleName,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Self-registration config, read from the already-validated config. The site is
|
|
486
|
+
* NOT stored here — it is derived from the single
|
|
487
|
+
* networks/<siteName>.network-meta.xml the app ships, exactly like
|
|
488
|
+
* the guestUser permset path. deriveSiteName() is called lazily inside the
|
|
489
|
+
* selfReg step body so its "multiple network files" StepError is recorded in
|
|
490
|
+
* the ledger rather than escaping config load.
|
|
491
|
+
*
|
|
492
|
+
* Config shape:
|
|
493
|
+
* {
|
|
494
|
+
* "selfRegistration": {
|
|
495
|
+
* "selfRegProfile": "myapp Profile",
|
|
496
|
+
* "accountName": "My Self-Reg Account"
|
|
497
|
+
* }
|
|
498
|
+
* }
|
|
499
|
+
*
|
|
500
|
+
* Returns null if no "selfRegistration" section exists in config (the step is hidden).
|
|
501
|
+
*/
|
|
502
|
+
function loadSelfRegConfig(config) {
|
|
503
|
+
const section = config.selfRegistration;
|
|
504
|
+
if (!section) return null;
|
|
505
|
+
return {
|
|
506
|
+
selfRegProfile: section.selfRegProfile,
|
|
507
|
+
accountName: section.accountName,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Ensure the self-registration profile is listed in networkMemberGroups.
|
|
513
|
+
* This must happen BEFORE the initial deploy so that the profile is a recognised
|
|
514
|
+
* site member when subsequent steps (selfRegProfile, selfRegistration=true) are deployed.
|
|
515
|
+
*/
|
|
516
|
+
function ensureNetworkMemberProfile(selfRegConfig, siteName) {
|
|
517
|
+
const { selfRegProfile } = selfRegConfig;
|
|
518
|
+
if (!siteName || !selfRegProfile) return;
|
|
519
|
+
|
|
520
|
+
const networkXmlPath = resolve(SFDX_SOURCE, 'networks', `${siteName}.network-meta.xml`);
|
|
521
|
+
if (!existsSync(networkXmlPath)) {
|
|
522
|
+
console.log(` Network metadata not found: ${networkXmlPath}; skipping member group update.`);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
const xml = readFileSync(networkXmlPath, 'utf8');
|
|
526
|
+
|
|
527
|
+
// Parse + assert the target node exists, then mutate via a targeted edit.
|
|
528
|
+
// This is the BEST-EFFORT pre-deploy prep (not inside runStep, see lines
|
|
529
|
+
// ~1050): on a missing <networkMemberGroups> node we surface a LOUD
|
|
530
|
+
// console.error but do NOT throw — a bare throw here aborts before deploy and
|
|
531
|
+
// bypasses the ledger. The authoritative failure is recorded later by the
|
|
532
|
+
// post-deploy selfReg step.
|
|
533
|
+
let result;
|
|
534
|
+
try {
|
|
535
|
+
result = addProfileToMemberGroups(xml, selfRegProfile);
|
|
536
|
+
} catch (e) {
|
|
537
|
+
if (e instanceof NetworkXmlError) {
|
|
538
|
+
console.error(
|
|
539
|
+
` ERROR: cannot add self-reg profile to ${siteName}.network-meta.xml — ${e.message}. ` +
|
|
540
|
+
`Continuing pre-deploy; the self-registration step will record the authoritative failure.`,
|
|
541
|
+
);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
throw e;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (!result.changed) {
|
|
548
|
+
console.log(` Profile "${selfRegProfile}" already in networkMemberGroups; no update needed.`);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
writeFileSync(networkXmlPath, result.xml);
|
|
552
|
+
console.log(` Added profile "${selfRegProfile}" to networkMemberGroups in ${siteName}.network-meta.xml`);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Enable self-registration for an Experience Cloud network.
|
|
557
|
+
*
|
|
558
|
+
* 1. Modify the network metadata XML to set selfRegistration=true and add selfRegProfile.
|
|
559
|
+
* 2. Re-deploy the modified network metadata.
|
|
560
|
+
* 3. Create an Account record (idempotent).
|
|
561
|
+
* 4. Create a NetworkSelfRegistration record linking the Account to the Network (idempotent).
|
|
562
|
+
*/
|
|
563
|
+
function enableSelfRegistration(selfRegConfig, siteName, targetOrg) {
|
|
564
|
+
const { selfRegProfile, accountName } = selfRegConfig;
|
|
565
|
+
|
|
566
|
+
// 1. Modify network metadata XML
|
|
567
|
+
const networkXmlPath = resolve(SFDX_SOURCE, 'networks', `${siteName}.network-meta.xml`);
|
|
568
|
+
if (!existsSync(networkXmlPath)) {
|
|
569
|
+
throw new StepError(`network metadata not found: ${networkXmlPath}`);
|
|
570
|
+
}
|
|
571
|
+
const xml = readFileSync(networkXmlPath, 'utf8');
|
|
572
|
+
|
|
573
|
+
// Parse + assert the <selfRegistration> node exists, then mutate via a
|
|
574
|
+
// targeted edit. This runs inside
|
|
575
|
+
// runStep(selfReg, failFast:false) (line ~1211), so a missing node must throw
|
|
576
|
+
// a StepError — caught, recorded `failed`, non-zero exit — rather than the
|
|
577
|
+
// old silent no-op. The helper's idempotency check
|
|
578
|
+
// (already true / selfRegProfile present) yields changed:false here.
|
|
579
|
+
let result;
|
|
580
|
+
try {
|
|
581
|
+
result = enableSelfRegInXml(xml, selfRegProfile);
|
|
582
|
+
} catch (e) {
|
|
583
|
+
if (e instanceof NetworkXmlError) {
|
|
584
|
+
throw new StepError(`${siteName}.network-meta.xml: ${e.message}`);
|
|
585
|
+
}
|
|
586
|
+
throw e;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (!result.changed) {
|
|
590
|
+
console.log(` Network "${siteName}" already has self-registration configured; skipping metadata update and deploy.`);
|
|
591
|
+
} else {
|
|
592
|
+
writeFileSync(networkXmlPath, result.xml);
|
|
593
|
+
console.log(` Updated ${siteName}.network-meta.xml: selfRegistration=true, selfRegProfile=${selfRegProfile}`);
|
|
594
|
+
|
|
595
|
+
// Re-deploy only the network file
|
|
596
|
+
const deployResult = spawnSync('sf', [
|
|
597
|
+
'project', 'deploy', 'start',
|
|
598
|
+
'--target-org', targetOrg,
|
|
599
|
+
'--source-dir', networkXmlPath,
|
|
600
|
+
], { cwd: ROOT, stdio: 'inherit', shell: true, timeout: 120000 });
|
|
601
|
+
if (deployResult.status !== 0) {
|
|
602
|
+
throw new StepError(`failed to deploy updated network metadata (exit ${deployResult.status ?? 1})`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// 3. Create Account (idempotent)
|
|
607
|
+
const acctQuery = `SELECT Id FROM Account WHERE Name = '${accountName.replace(/'/g, "\\'")}' LIMIT 1`;
|
|
608
|
+
const acctQueryResult = spawnSync('sf', [
|
|
609
|
+
'data', 'query',
|
|
610
|
+
'--query', acctQuery,
|
|
611
|
+
'--target-org', targetOrg,
|
|
612
|
+
'--json',
|
|
613
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
614
|
+
let accountId = null;
|
|
615
|
+
if (acctQueryResult.status === 0) {
|
|
616
|
+
try {
|
|
617
|
+
const json = JSON.parse(acctQueryResult.stdout);
|
|
618
|
+
accountId = json.result?.records?.[0]?.Id || null;
|
|
619
|
+
} catch { /* proceed to create */ }
|
|
620
|
+
}
|
|
621
|
+
if (accountId) {
|
|
622
|
+
console.log(` Account "${accountName}" already exists (${accountId}); skipping creation.`);
|
|
623
|
+
} else {
|
|
624
|
+
const createResult = spawnSync('sf', [
|
|
625
|
+
'data', 'create', 'record',
|
|
626
|
+
'--sobject', 'Account',
|
|
627
|
+
'--values', `Name='${accountName}'`,
|
|
628
|
+
'--target-org', targetOrg,
|
|
629
|
+
'--json',
|
|
630
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
631
|
+
if (createResult.status !== 0) {
|
|
632
|
+
if (createResult.stderr) console.error(createResult.stderr);
|
|
633
|
+
throw new StepError(`failed to create Account "${accountName}"`);
|
|
634
|
+
}
|
|
635
|
+
try {
|
|
636
|
+
const json = JSON.parse(createResult.stdout);
|
|
637
|
+
accountId = json.result?.id;
|
|
638
|
+
console.log(` Created Account "${accountName}" (${accountId}).`);
|
|
639
|
+
} catch {
|
|
640
|
+
throw new StepError('failed to parse Account creation result');
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// 4. Query Network Id
|
|
645
|
+
const netQuery = `SELECT Id FROM Network WHERE Name = '${siteName}'`;
|
|
646
|
+
const netResult = spawnSync('sf', [
|
|
647
|
+
'data', 'query',
|
|
648
|
+
'--query', netQuery,
|
|
649
|
+
'--target-org', targetOrg,
|
|
650
|
+
'--json',
|
|
651
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
652
|
+
let networkId = null;
|
|
653
|
+
if (netResult.status === 0) {
|
|
654
|
+
try {
|
|
655
|
+
const json = JSON.parse(netResult.stdout);
|
|
656
|
+
networkId = json.result?.records?.[0]?.Id || null;
|
|
657
|
+
} catch { /* fall through */ }
|
|
658
|
+
}
|
|
659
|
+
if (!networkId) {
|
|
660
|
+
throw new StepError(`could not find Network "${siteName}" in org`);
|
|
661
|
+
}
|
|
662
|
+
console.log(` Found Network "${siteName}" (${networkId}).`);
|
|
663
|
+
|
|
664
|
+
// 5. Create NetworkSelfRegistration (idempotent)
|
|
665
|
+
const nsrQuery = `SELECT Id FROM NetworkSelfRegistration WHERE NetworkId = '${networkId}'`;
|
|
666
|
+
const nsrResult = spawnSync('sf', [
|
|
667
|
+
'data', 'query',
|
|
668
|
+
'--query', nsrQuery,
|
|
669
|
+
'--target-org', targetOrg,
|
|
670
|
+
'--json',
|
|
671
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
672
|
+
let nsrExists = false;
|
|
673
|
+
if (nsrResult.status === 0) {
|
|
674
|
+
try {
|
|
675
|
+
const json = JSON.parse(nsrResult.stdout);
|
|
676
|
+
nsrExists = (json.result?.records?.length || 0) > 0;
|
|
677
|
+
} catch { /* proceed to create */ }
|
|
678
|
+
}
|
|
679
|
+
if (nsrExists) {
|
|
680
|
+
console.log(' NetworkSelfRegistration record already exists; skipping.');
|
|
681
|
+
} else {
|
|
682
|
+
const apex = [
|
|
683
|
+
`Account acct = [SELECT Id FROM Account WHERE Id = '${accountId}' LIMIT 1];`,
|
|
684
|
+
`NetworkSelfRegistration nsr = new NetworkSelfRegistration();`,
|
|
685
|
+
`nsr.AccountId = acct.Id;`,
|
|
686
|
+
`nsr.NetworkId = '${networkId}';`,
|
|
687
|
+
`insert nsr;`,
|
|
688
|
+
`System.debug('NSR_CREATED:' + nsr.Id);`,
|
|
689
|
+
].join('\n');
|
|
690
|
+
const apexOut = withApexTempDir((writeApex) => {
|
|
691
|
+
const tmpApex = writeApex('selfreg.apex', apex);
|
|
692
|
+
const apexResult = spawnSync('sf', [
|
|
693
|
+
'apex', 'run', '--target-org', targetOrg, '--file', tmpApex,
|
|
694
|
+
], { cwd: ROOT, stdio: 'pipe', shell: true, timeout: 60000 });
|
|
695
|
+
const out = apexResult.stdout?.toString() || '';
|
|
696
|
+
if (apexResult.status !== 0 && !out.includes('Compiled successfully')) {
|
|
697
|
+
process.stderr.write(apexResult.stderr?.toString() || out);
|
|
698
|
+
throw new StepError('failed to create NetworkSelfRegistration record');
|
|
699
|
+
}
|
|
700
|
+
return out;
|
|
701
|
+
});
|
|
702
|
+
const nsrMatch = apexOut.match(/NSR_CREATED:(\w+)/);
|
|
703
|
+
if (nsrMatch) {
|
|
704
|
+
console.log(` Created NetworkSelfRegistration (${nsrMatch[1]}).`);
|
|
705
|
+
} else {
|
|
706
|
+
console.log(' NetworkSelfRegistration creation executed.');
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Assign a role to the current user so that Experience Cloud self-registration
|
|
713
|
+
* works correctly.
|
|
714
|
+
*/
|
|
715
|
+
function assignRoleToCurrentUser(roleName, targetOrg) {
|
|
716
|
+
const roleQuery = `SELECT Id FROM UserRole WHERE Name = '${roleName}'`;
|
|
717
|
+
const roleResult = spawnSync('sf', [
|
|
718
|
+
'data', 'query',
|
|
719
|
+
'--query', roleQuery,
|
|
720
|
+
'--target-org', targetOrg,
|
|
721
|
+
'--json',
|
|
722
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
723
|
+
if (roleResult.status !== 0) {
|
|
724
|
+
if (roleResult.stderr) console.error(roleResult.stderr);
|
|
725
|
+
throw new StepError(`failed to query role "${roleName}" in org`);
|
|
726
|
+
}
|
|
727
|
+
let roleId;
|
|
728
|
+
try {
|
|
729
|
+
const json = JSON.parse(roleResult.stdout);
|
|
730
|
+
const records = json.result?.records;
|
|
731
|
+
if (!records || records.length === 0) {
|
|
732
|
+
throw new StepError(`role "${roleName}" not found in org`);
|
|
733
|
+
}
|
|
734
|
+
roleId = records[0].Id;
|
|
735
|
+
} catch (err) {
|
|
736
|
+
if (err instanceof StepError) throw err;
|
|
737
|
+
throw new StepError(`failed to parse role query result for "${roleName}"`);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
const orgResult = spawnSync('sf', [
|
|
741
|
+
'org', 'display',
|
|
742
|
+
'--target-org', targetOrg,
|
|
743
|
+
'--json',
|
|
744
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
745
|
+
if (orgResult.status !== 0) {
|
|
746
|
+
throw new StepError('failed to resolve current user from org');
|
|
747
|
+
}
|
|
748
|
+
let username;
|
|
749
|
+
try {
|
|
750
|
+
const json = JSON.parse(orgResult.stdout);
|
|
751
|
+
username = json.result?.username;
|
|
752
|
+
if (!username) {
|
|
753
|
+
throw new StepError('could not determine current username from org display');
|
|
754
|
+
}
|
|
755
|
+
} catch (err) {
|
|
756
|
+
if (err instanceof StepError) throw err;
|
|
757
|
+
throw new StepError('failed to parse org display result');
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
const userQuery = `SELECT Id, UserRoleId FROM User WHERE Username = '${username}'`;
|
|
761
|
+
const userResult = spawnSync('sf', [
|
|
762
|
+
'data', 'query',
|
|
763
|
+
'--query', userQuery,
|
|
764
|
+
'--target-org', targetOrg,
|
|
765
|
+
'--json',
|
|
766
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
767
|
+
if (userResult.status === 0) {
|
|
768
|
+
try {
|
|
769
|
+
const json = JSON.parse(userResult.stdout);
|
|
770
|
+
const userRecord = json.result?.records?.[0];
|
|
771
|
+
if (userRecord?.UserRoleId) {
|
|
772
|
+
console.log(` User ${username} already has a role assigned; skipping to avoid overriding.`);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
} catch { /* continue */ }
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
const updateResult = spawnSync('sf', [
|
|
779
|
+
'data', 'update', 'record',
|
|
780
|
+
'--sobject', 'User',
|
|
781
|
+
'--where', `Username='${username}'`,
|
|
782
|
+
'--values', `UserRoleId='${roleId}'`,
|
|
783
|
+
'--target-org', targetOrg,
|
|
784
|
+
'--json',
|
|
785
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
786
|
+
if (updateResult.status === 0) {
|
|
787
|
+
console.log(` Role "${roleName}" assigned to ${username}.`);
|
|
788
|
+
} else {
|
|
789
|
+
const out = (updateResult.stderr?.toString() || '') + (updateResult.stdout?.toString() || '');
|
|
790
|
+
if (out) console.error(out);
|
|
791
|
+
throw new StepError(`failed to assign role "${roleName}" to ${username}`);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Query the org for a guest user whose profile name matches the given site name.
|
|
797
|
+
*/
|
|
798
|
+
function resolveGuestUsername(siteName, targetOrg) {
|
|
799
|
+
const query = `SELECT Username FROM User WHERE Profile.Name LIKE '%${siteName}%' AND UserType = 'Guest'`;
|
|
800
|
+
const result = spawnSync('sf', [
|
|
801
|
+
'data', 'query',
|
|
802
|
+
'--query', query,
|
|
803
|
+
'--target-org', targetOrg,
|
|
804
|
+
'--json',
|
|
805
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
806
|
+
if (result.status !== 0) {
|
|
807
|
+
console.error(` Failed to query guest user for site "${siteName}".`);
|
|
808
|
+
if (result.stderr) console.error(result.stderr);
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
const json = JSON.parse(result.stdout);
|
|
813
|
+
const records = json.result?.records;
|
|
814
|
+
if (!records || records.length === 0) {
|
|
815
|
+
console.error(` No guest user found for site "${siteName}".`);
|
|
816
|
+
return null;
|
|
817
|
+
}
|
|
818
|
+
return records[0].Username;
|
|
819
|
+
} catch {
|
|
820
|
+
console.error(` Failed to parse guest user query result for site "${siteName}".`);
|
|
821
|
+
return null;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* M1 license pre-check (spec §5.3). Query the UserLicense that the selfRegProfile
|
|
827
|
+
* belongs to and decide whether self-registration can proceed. The profile name
|
|
828
|
+
* is validate-and-fail (Q10, AC-8): a SOQL-special character throws a config
|
|
829
|
+
* error rather than being escaped — profile names are developer-authored config,
|
|
830
|
+
* not user input, so a `'` / `\` / control char is a mistake to surface loudly.
|
|
831
|
+
*
|
|
832
|
+
* Selection is on the stable LicenseDefinitionKey; the seat math lives in JS
|
|
833
|
+
* (evaluateLicenseRows) because SOQL cannot compare two fields. A query failure
|
|
834
|
+
* or 0 rows is treated as "not satisfied" (soft skip), not a hard error.
|
|
835
|
+
*
|
|
836
|
+
* @returns {{ satisfied: boolean, reason: string|null }}
|
|
837
|
+
*/
|
|
838
|
+
function checkSelfRegLicense(selfRegConfig, targetOrg) {
|
|
839
|
+
const profileName = validateProfileNameForSoql(selfRegConfig.selfRegProfile);
|
|
840
|
+
const query =
|
|
841
|
+
`SELECT UserLicense.LicenseDefinitionKey, UserLicense.Name, UserLicense.Status, ` +
|
|
842
|
+
`UserLicense.TotalLicenses, UserLicense.UsedLicenses ` +
|
|
843
|
+
`FROM Profile WHERE Name = '${profileName}'`;
|
|
844
|
+
const result = spawnSync('sf', [
|
|
845
|
+
'data', 'query',
|
|
846
|
+
'--query', query,
|
|
847
|
+
'--target-org', targetOrg,
|
|
848
|
+
'--json',
|
|
849
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
850
|
+
|
|
851
|
+
if (result.status !== 0) {
|
|
852
|
+
if (result.stderr) console.error(result.stderr);
|
|
853
|
+
return {
|
|
854
|
+
satisfied: false,
|
|
855
|
+
reason: `could not query the UserLicense for profile "${profileName}" (sf data query failed)`,
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
let rows;
|
|
859
|
+
try {
|
|
860
|
+
rows = JSON.parse(result.stdout).result?.records ?? [];
|
|
861
|
+
} catch {
|
|
862
|
+
return {
|
|
863
|
+
satisfied: false,
|
|
864
|
+
reason: `could not parse the UserLicense query result for profile "${profileName}"`,
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
const { satisfied, reason } = evaluateLicenseRows(rows, profileName);
|
|
868
|
+
return { satisfied, reason };
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Read the UserLicense the selfRegProfile requires straight from the local
|
|
873
|
+
* profile metadata's <userLicense> element. The deploy pre-check runs BEFORE
|
|
874
|
+
* the profile is deployed, so querying the org's Profile table returns 0 rows
|
|
875
|
+
* and can only report "profile missing" — which never tells the user which
|
|
876
|
+
* license to add. The profile source we are about to deploy is the
|
|
877
|
+
* authoritative declaration of the required license.
|
|
878
|
+
*
|
|
879
|
+
* @returns {string|null} the license name, or null if the file / field is absent
|
|
880
|
+
*/
|
|
881
|
+
function readProfileUserLicense(selfRegProfile) {
|
|
882
|
+
const profilePath = resolve(SFDX_SOURCE, 'profiles', `${selfRegProfile}.profile-meta.xml`);
|
|
883
|
+
if (!existsSync(profilePath)) return null;
|
|
884
|
+
const xml = readFileSync(profilePath, 'utf8');
|
|
885
|
+
const m = xml.match(/<userLicense>\s*([^<]+?)\s*<\/userLicense>/);
|
|
886
|
+
return m ? m[1].trim() : null;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Deploy license pre-check (spec §5.3). `sf project deploy start` fails with a
|
|
891
|
+
* cryptic error when the org lacks the UserLicense the selfRegProfile's metadata
|
|
892
|
+
* declares. Resolve the required license NAME from the local profile source, then
|
|
893
|
+
* query the org's UserLicense by that name so a miss names the actual license the
|
|
894
|
+
* admin must add — not the not-yet-deployed profile. Seat/status math is shared
|
|
895
|
+
* with the self-reg gate via evaluateLicenseRows.
|
|
896
|
+
*
|
|
897
|
+
* @returns {{ satisfied: boolean, reason: string|null }}
|
|
898
|
+
*/
|
|
899
|
+
function checkDeployLicense(selfRegConfig, targetOrg) {
|
|
900
|
+
const licenseName = readProfileUserLicense(selfRegConfig.selfRegProfile);
|
|
901
|
+
// No <userLicense> in the profile source (or profile file absent) — nothing to
|
|
902
|
+
// gate on; let deploy proceed and surface any real error on its own.
|
|
903
|
+
if (!licenseName) return { satisfied: true, reason: null };
|
|
904
|
+
|
|
905
|
+
const escaped = licenseName.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
906
|
+
const query =
|
|
907
|
+
`SELECT LicenseDefinitionKey, Name, Status, TotalLicenses, UsedLicenses ` +
|
|
908
|
+
`FROM UserLicense WHERE Name = '${escaped}'`;
|
|
909
|
+
const result = spawnSync('sf', [
|
|
910
|
+
'data', 'query',
|
|
911
|
+
'--query', query,
|
|
912
|
+
'--target-org', targetOrg,
|
|
913
|
+
'--json',
|
|
914
|
+
], { cwd: ROOT, encoding: 'utf8' });
|
|
915
|
+
|
|
916
|
+
if (result.status !== 0) {
|
|
917
|
+
if (result.stderr) console.error(result.stderr);
|
|
918
|
+
return { satisfied: false, reason: `could not query UserLicense "${licenseName}" (sf data query failed)` };
|
|
919
|
+
}
|
|
920
|
+
let rows;
|
|
921
|
+
try {
|
|
922
|
+
rows = JSON.parse(result.stdout).result?.records ?? [];
|
|
923
|
+
} catch {
|
|
924
|
+
return { satisfied: false, reason: `could not parse the UserLicense query result for "${licenseName}"` };
|
|
925
|
+
}
|
|
926
|
+
if (rows.length === 0) {
|
|
927
|
+
return {
|
|
928
|
+
satisfied: false,
|
|
929
|
+
reason: `required license "${licenseName}" is not present in the org — add it before deploying`,
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
// evaluateLicenseRows expects the license nested under `.UserLicense` (its
|
|
933
|
+
// Profile-query shape); reshape the direct UserLicense rows to match so the
|
|
934
|
+
// seat/status logic — and its license-named messages — stay shared.
|
|
935
|
+
return evaluateLicenseRows(rows.map((r) => ({ UserLicense: r })), selfRegConfig.selfRegProfile);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
function isOrgConnected(targetOrg) {
|
|
939
|
+
const result = spawnSync('sf', ['org', 'display', '--target-org', targetOrg, '--json'], {
|
|
940
|
+
cwd: ROOT,
|
|
941
|
+
stdio: 'pipe',
|
|
942
|
+
shell: true,
|
|
943
|
+
});
|
|
944
|
+
return result.status === 0;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function apexLiteral(value) {
|
|
948
|
+
if (value === null || value === undefined) return 'null';
|
|
949
|
+
if (typeof value === 'boolean') return String(value);
|
|
950
|
+
if (typeof value === 'number') return String(value);
|
|
951
|
+
const s = String(value);
|
|
952
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return `Date.valueOf('${s}')`;
|
|
953
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(s)) {
|
|
954
|
+
const dt = s.replace('T', ' ').replace(/\.\d+/, '').replace('Z', '');
|
|
955
|
+
return `DateTime.valueOf('${dt}')`;
|
|
956
|
+
}
|
|
957
|
+
return "'" + s.replace(/\\/g, '\\\\').replace(/'/g, "\\'") + "'";
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function buildApexInsert(sobject, records, refIds) {
|
|
961
|
+
const lines = [
|
|
962
|
+
'Database.DMLOptions dmlOpts = new Database.DMLOptions();',
|
|
963
|
+
'dmlOpts.DuplicateRuleHeader.allowSave = true;',
|
|
964
|
+
`List<${sobject}> recs = new List<${sobject}>();`,
|
|
965
|
+
];
|
|
966
|
+
for (const rec of records) {
|
|
967
|
+
lines.push(`{ ${sobject} r = new ${sobject}();`);
|
|
968
|
+
for (const [key, val] of Object.entries(rec)) {
|
|
969
|
+
if (key === 'attributes') continue;
|
|
970
|
+
lines.push(`r.put('${key}', ${apexLiteral(val)});`);
|
|
971
|
+
}
|
|
972
|
+
lines.push('recs.add(r); }');
|
|
973
|
+
}
|
|
974
|
+
lines.push('Database.SaveResult[] results = Database.insert(recs, dmlOpts);');
|
|
975
|
+
const refArray = refIds.map((r) => `'${r}'`).join(',');
|
|
976
|
+
lines.push(`String[] refs = new String[]{${refArray}};`);
|
|
977
|
+
lines.push('for (Integer i = 0; i < results.size(); i++) {');
|
|
978
|
+
lines.push(" if (results[i].isSuccess()) System.debug('REF:' + refs[i] + ':' + results[i].getId());");
|
|
979
|
+
lines.push(" else System.debug('ERR:' + refs[i] + ':' + results[i].getErrors()[0].getMessage());");
|
|
980
|
+
lines.push('}');
|
|
981
|
+
return lines.join('\n');
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* Interactive multi-select: arrow keys navigate, space toggles, 'a' toggles all, enter confirms.
|
|
986
|
+
* Returns a boolean[] matching the input order. Falls through immediately when stdin is not a TTY.
|
|
987
|
+
*/
|
|
988
|
+
async function promptSteps(steps) {
|
|
989
|
+
if (!process.stdin.isTTY) return steps.map((s) => s.enabled);
|
|
990
|
+
|
|
991
|
+
// `selected` stays indexed by ORIGINAL step order (so the caller's
|
|
992
|
+
// selections[i] → stepDefs[i] mapping is unchanged); unavailable steps remain
|
|
993
|
+
// false. Only available steps are shown and navigable — unavailable steps are
|
|
994
|
+
// hidden entirely rather than rendered greyed-out.
|
|
995
|
+
const selected = steps.map((s) => s.enabled);
|
|
996
|
+
const visible = steps.map((s, i) => ({ step: s, index: i })).filter(({ step }) => step.available);
|
|
997
|
+
let cursor = 0;
|
|
998
|
+
const RST = '\x1B[0m';
|
|
999
|
+
const CYAN = '\x1B[36m';
|
|
1000
|
+
const GREEN = '\x1B[32m';
|
|
1001
|
+
|
|
1002
|
+
/** Strip ANSI escape sequences to get visible character count. */
|
|
1003
|
+
function visibleLength(str) {
|
|
1004
|
+
return str.replace(/\x1B\[[0-9;]*m/g, '').length;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/** Count how many terminal rows a set of lines occupies (accounting for wrapping). */
|
|
1008
|
+
function terminalRows(lines) {
|
|
1009
|
+
const cols = process.stdout.columns || 80;
|
|
1010
|
+
let rows = 0;
|
|
1011
|
+
for (const line of lines) {
|
|
1012
|
+
const len = visibleLength(line);
|
|
1013
|
+
rows += len === 0 ? 1 : Math.ceil(len / cols);
|
|
1014
|
+
}
|
|
1015
|
+
return rows;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function render() {
|
|
1019
|
+
return visible.map(({ step, index }, row) => {
|
|
1020
|
+
const ptr = row === cursor ? `${CYAN}❯${RST}` : ' ';
|
|
1021
|
+
const chk = selected[index] ? `${GREEN}●${RST}` : '○';
|
|
1022
|
+
return `${ptr} ${chk} ${step.label}`;
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
let prevRows = 0;
|
|
1027
|
+
|
|
1028
|
+
return new Promise((resolve) => {
|
|
1029
|
+
process.stdin.setRawMode(true);
|
|
1030
|
+
process.stdin.resume();
|
|
1031
|
+
process.stdin.setEncoding('utf8');
|
|
1032
|
+
process.stdout.write('\x1B[?25l');
|
|
1033
|
+
console.log('\nSelect steps (↑↓ move, space toggle, a all, enter confirm):\n');
|
|
1034
|
+
const initialLines = render();
|
|
1035
|
+
prevRows = terminalRows(initialLines);
|
|
1036
|
+
process.stdout.write(initialLines.join('\n') + '\n');
|
|
1037
|
+
|
|
1038
|
+
function redraw() {
|
|
1039
|
+
process.stdout.write(`\x1B[${prevRows}A`);
|
|
1040
|
+
const lines = render();
|
|
1041
|
+
for (const line of lines) process.stdout.write(`\x1B[2K${line}\n`);
|
|
1042
|
+
prevRows = terminalRows(lines);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
process.stdin.on('data', (key) => {
|
|
1046
|
+
if (key === '\x03') {
|
|
1047
|
+
process.stdout.write('\x1B[?25h\n');
|
|
1048
|
+
process.exit(0);
|
|
1049
|
+
}
|
|
1050
|
+
if (key === '\r' || key === '\n') {
|
|
1051
|
+
process.stdout.write('\x1B[?25h');
|
|
1052
|
+
process.stdin.setRawMode(false);
|
|
1053
|
+
process.stdin.pause();
|
|
1054
|
+
process.stdin.removeAllListeners('data');
|
|
1055
|
+
console.log();
|
|
1056
|
+
resolve(selected);
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
// Note: `cursor` indexes `visible`; `selected` is indexed by ORIGINAL step
|
|
1060
|
+
// order. Map through visible[cursor].index before touching `selected`.
|
|
1061
|
+
if (key === ' ') {
|
|
1062
|
+
const { index } = visible[cursor];
|
|
1063
|
+
selected[index] = !selected[index];
|
|
1064
|
+
redraw();
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
if (key === 'a') {
|
|
1068
|
+
const allOn = visible.every(({ index }) => selected[index]);
|
|
1069
|
+
for (const { index } of visible) selected[index] = !allOn;
|
|
1070
|
+
redraw();
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (key === '\x1B[A' || key === 'k') {
|
|
1074
|
+
cursor = Math.max(0, cursor - 1);
|
|
1075
|
+
redraw();
|
|
1076
|
+
} else if (key === '\x1B[B' || key === 'j') {
|
|
1077
|
+
cursor = Math.min(visible.length - 1, cursor + 1);
|
|
1078
|
+
redraw();
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
function run(name, cmd, args, opts = {}) {
|
|
1085
|
+
const { cwd = ROOT, optional = false } = opts;
|
|
1086
|
+
console.log('\n---', name, '---');
|
|
1087
|
+
const result = spawnSync(cmd, args, {
|
|
1088
|
+
cwd,
|
|
1089
|
+
stdio: 'inherit',
|
|
1090
|
+
shell: true,
|
|
1091
|
+
...(opts.env && { env: opts.env }),
|
|
1092
|
+
...(opts.timeout && { timeout: opts.timeout }),
|
|
1093
|
+
});
|
|
1094
|
+
if (result.status !== 0 && !optional) {
|
|
1095
|
+
throw new StepError(`${name} (exit ${result.status ?? 1})`);
|
|
1096
|
+
}
|
|
1097
|
+
return result;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/** Promise-based spawn for parallel execution. Always uses stdio: 'pipe'. */
|
|
1101
|
+
function spawnAsync(cmd, args, opts = {}) {
|
|
1102
|
+
return new Promise((resolve, reject) => {
|
|
1103
|
+
const proc = nodeSpawn(cmd, args, {
|
|
1104
|
+
cwd: opts.cwd || ROOT,
|
|
1105
|
+
stdio: 'pipe',
|
|
1106
|
+
shell: true,
|
|
1107
|
+
...(opts.timeout && { timeout: opts.timeout }),
|
|
1108
|
+
});
|
|
1109
|
+
let stdout = '';
|
|
1110
|
+
let stderr = '';
|
|
1111
|
+
proc.stdout.on('data', (d) => { stdout += d.toString(); });
|
|
1112
|
+
proc.stderr.on('data', (d) => { stderr += d.toString(); });
|
|
1113
|
+
proc.on('close', (code) => resolve({ status: code, stdout, stderr }));
|
|
1114
|
+
proc.on('error', reject);
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/** Async version of run() for parallel steps. Captures output and prints on failure. */
|
|
1119
|
+
async function runAsync(name, cmd, args, opts = {}) {
|
|
1120
|
+
const { cwd = ROOT, optional = false } = opts;
|
|
1121
|
+
const result = await spawnAsync(cmd, args, { cwd, ...(opts.timeout && { timeout: opts.timeout }) });
|
|
1122
|
+
if (result.status !== 0 && !optional) {
|
|
1123
|
+
if (result.stdout) process.stdout.write(result.stdout);
|
|
1124
|
+
if (result.stderr) process.stderr.write(result.stderr);
|
|
1125
|
+
throw new StepError(`${name} (exit ${result.status ?? 1})`);
|
|
1126
|
+
}
|
|
1127
|
+
return result;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* In-memory result ledger. Each selected step records exactly one outcome:
|
|
1132
|
+
* ok — the step ran and succeeded
|
|
1133
|
+
* skipped — the step was not selected, or had no config section (intentional)
|
|
1134
|
+
* failed — the step ran and failed (with a human-readable reason)
|
|
1135
|
+
* The end-of-run summary is rendered from this ledger and the process exits
|
|
1136
|
+
* non-zero whenever any step is `failed` (fail-fast or skippable alike).
|
|
1137
|
+
*
|
|
1138
|
+
* @typedef {{ key: string, label: string, status: 'ok'|'skipped'|'failed', reason?: string, failFast?: boolean }} StepResult
|
|
1139
|
+
*/
|
|
1140
|
+
const results = [];
|
|
1141
|
+
function recordOk(step) {
|
|
1142
|
+
results.push({ key: step.key, label: step.label, status: 'ok', failFast: step.failFast });
|
|
1143
|
+
}
|
|
1144
|
+
function recordSkipped(step, reason) {
|
|
1145
|
+
results.push({ key: step.key, label: step.label, status: 'skipped', reason, failFast: step.failFast });
|
|
1146
|
+
}
|
|
1147
|
+
function recordFailed(step, reason) {
|
|
1148
|
+
results.push({ key: step.key, label: step.label, status: 'failed', reason, failFast: step.failFast });
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/** True if any step in the ledger failed. */
|
|
1152
|
+
function finalExitCode() {
|
|
1153
|
+
return results.some((r) => r.status === 'failed') ? 1 : 0;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
const SUMMARY_GLYPH = { ok: '✔', skipped: '–', failed: '✖' };
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* Render the end-of-run summary. Always called — on success, on a fail-fast
|
|
1160
|
+
* abort (partial: only steps reached so far are present), and on a clean finish
|
|
1161
|
+
* that had skippable failures. Failed rows are listed last so the real problem
|
|
1162
|
+
* is the last thing the developer sees.
|
|
1163
|
+
*/
|
|
1164
|
+
function printSummary(targetOrg) {
|
|
1165
|
+
const ordered = [
|
|
1166
|
+
...results.filter((r) => r.status !== 'failed'),
|
|
1167
|
+
...results.filter((r) => r.status === 'failed'),
|
|
1168
|
+
];
|
|
1169
|
+
const pad = Math.max(0, ...ordered.map((r) => r.key.length));
|
|
1170
|
+
console.log(`\nSetup summary (target org: ${targetOrg})`);
|
|
1171
|
+
for (const r of ordered) {
|
|
1172
|
+
const glyph = SUMMARY_GLYPH[r.status] ?? ' ';
|
|
1173
|
+
const key = r.key.padEnd(pad);
|
|
1174
|
+
let line = ` ${glyph} ${key} ${r.status}`;
|
|
1175
|
+
if (r.reason) line += ` (${r.reason})`;
|
|
1176
|
+
if (r.status === 'failed') line += r.failFast ? ' [fail-fast — aborted]' : ' [skippable — continued]';
|
|
1177
|
+
console.log(line);
|
|
1178
|
+
}
|
|
1179
|
+
const failures = results.filter((r) => r.status === 'failed').length;
|
|
1180
|
+
if (failures > 0) {
|
|
1181
|
+
console.log(`Setup completed with ${failures} failure(s). Exiting 1.`);
|
|
1182
|
+
} else {
|
|
1183
|
+
console.log('Setup complete.');
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* Run one step body, recording its outcome in the ledger and honoring the
|
|
1189
|
+
* step's fixed `failFast` classification. The body either completes (→ ok),
|
|
1190
|
+
* throws a StepError (→ failed), or throws something unexpected (→ failed,
|
|
1191
|
+
* with the raw message). On a fail-fast failure this prints the partial
|
|
1192
|
+
* summary and exits non-zero immediately; on a skippable failure it records
|
|
1193
|
+
* and returns so the run continues.
|
|
1194
|
+
*/
|
|
1195
|
+
async function runStep(step, targetOrg, body) {
|
|
1196
|
+
try {
|
|
1197
|
+
await body();
|
|
1198
|
+
recordOk(step);
|
|
1199
|
+
} catch (err) {
|
|
1200
|
+
const reason = err instanceof StepError ? err.message : (err?.message ?? String(err));
|
|
1201
|
+
recordFailed(step, reason);
|
|
1202
|
+
console.error(`\nStep "${step.key}" failed: ${reason}`);
|
|
1203
|
+
if (step.failFast) {
|
|
1204
|
+
printSummary(targetOrg);
|
|
1205
|
+
process.exit(1);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
async function main() {
|
|
1211
|
+
// Cleanup AT START: remove Apex temp artifacts left by a prior hard-killed run.
|
|
1212
|
+
// Safe to run before the per-org lock is acquired because it only removes
|
|
1213
|
+
// org-setup-* temp DIRECTORIES and legacy ROOT temp files — never the
|
|
1214
|
+
// org-setup-lock-<org>.lock files (plain files), so it cannot clobber a
|
|
1215
|
+
// concurrent run's live lock.
|
|
1216
|
+
sweepStaleApexTempDirs();
|
|
1217
|
+
|
|
1218
|
+
// Ensure .gitignore files exist (npm strips them from published packages).
|
|
1219
|
+
const gitignoreTemplates = loadGitignoreTemplates();
|
|
1220
|
+
if (gitignoreTemplates) {
|
|
1221
|
+
ensureGitignore(ROOT, gitignoreTemplates.sfdx);
|
|
1222
|
+
if (existsSync(UIBUNDLES_DIR)) {
|
|
1223
|
+
for (const entry of readdirSync(UIBUNDLES_DIR, { withFileTypes: true })) {
|
|
1224
|
+
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
|
1225
|
+
ensureGitignore(resolve(UIBUNDLES_DIR, entry.name), gitignoreTemplates.webapp);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
const parsed = parseArgs();
|
|
1232
|
+
const {
|
|
1233
|
+
uiBundleName,
|
|
1234
|
+
permsetNamesExplicit,
|
|
1235
|
+
yes,
|
|
1236
|
+
skipDeploy: argSkipDeploy,
|
|
1237
|
+
skipPermset: argSkipPermset,
|
|
1238
|
+
skipRole: argSkipRole,
|
|
1239
|
+
skipSelfReg: argSkipSelfReg,
|
|
1240
|
+
skipData: argSkipData,
|
|
1241
|
+
skipGraphql: argSkipGraphql,
|
|
1242
|
+
skipUIBundleBuild: argSkipUIBundleBuild,
|
|
1243
|
+
} = parsed;
|
|
1244
|
+
|
|
1245
|
+
// Resolve the target org up front (spec §5.4): explicit --target-org is used
|
|
1246
|
+
// verbatim; otherwise prompt (TTY) or fall back to the default org / exit.
|
|
1247
|
+
const targetOrg = await resolveTargetOrg(parsed);
|
|
1248
|
+
|
|
1249
|
+
// Per-target-org lock: acquired right after the start-of-run
|
|
1250
|
+
// sweep and before any step runs, so two runs against the same org cannot
|
|
1251
|
+
// interleave destructive Apex. The startup sweep above deliberately skips lock
|
|
1252
|
+
// files, so it never races this. Released on process exit.
|
|
1253
|
+
acquireOrgLock(targetOrg);
|
|
1254
|
+
|
|
1255
|
+
const permsetNames =
|
|
1256
|
+
permsetNamesExplicit.length > 0 ? permsetNamesExplicit : discoverPermissionSetNames();
|
|
1257
|
+
const permsetStepLabel =
|
|
1258
|
+
permsetNames.length === 0
|
|
1259
|
+
? 'Permset — (none under permissionsets/)'
|
|
1260
|
+
: permsetNames.length <= 3
|
|
1261
|
+
? `Permset — assign ${permsetNames.join(', ')}`
|
|
1262
|
+
: `Permset — assign ${permsetNames.length} permission sets`;
|
|
1263
|
+
|
|
1264
|
+
// Validate org-setup.config.json ONCE, before any step runs. The three
|
|
1265
|
+
// load*Config helpers read from this already-validated object.
|
|
1266
|
+
const config = loadValidatedConfig();
|
|
1267
|
+
|
|
1268
|
+
const hasDataPlan = existsSync(DATA_PLAN) && existsSync(DATA_DIR);
|
|
1269
|
+
const roleConfig = loadRoleConfig(config);
|
|
1270
|
+
const hasRoleConfig = roleConfig !== null;
|
|
1271
|
+
const selfRegConfig = loadSelfRegConfig(config);
|
|
1272
|
+
const hasSelfRegConfig = selfRegConfig !== null;
|
|
1273
|
+
|
|
1274
|
+
// Validate the selfRegProfile name for SOQL-safety up front (spec §5.3, AC-8),
|
|
1275
|
+
// alongside the config validation and BEFORE any org mutation (login/deploy).
|
|
1276
|
+
// A quote / backslash / control char is a config mistake, not a runtime value
|
|
1277
|
+
// to escape — fail fast here with a clean, actionable message rather than
|
|
1278
|
+
// letting the M1 gate throw a raw stack trace deep in the run after deploy.
|
|
1279
|
+
if (hasSelfRegConfig) {
|
|
1280
|
+
try {
|
|
1281
|
+
validateProfileNameForSoql(selfRegConfig.selfRegProfile);
|
|
1282
|
+
} catch (err) {
|
|
1283
|
+
console.error(`Invalid org-setup.config.json:\n - ${err.message}`);
|
|
1284
|
+
process.exit(1);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// failFast is a fixed, implementer-owned classification (spec §5.2) — NOT
|
|
1289
|
+
// user-configurable. A fail-fast failure aborts the run immediately; a
|
|
1290
|
+
// skippable failure is recorded and the run continues. The exit code is
|
|
1291
|
+
// non-zero on any failure regardless of class.
|
|
1292
|
+
// Login is NOT in this picker (spec §5.6, AC-13): it is an unconditional
|
|
1293
|
+
// precondition run before deploy, not a toggleable step. The dev step is also
|
|
1294
|
+
// gone (spec §5.5): launching the dev server moved to `npm run dev:preview`, so
|
|
1295
|
+
// setup terminates cleanly after graphql (AC-11).
|
|
1296
|
+
const stepDefs = [
|
|
1297
|
+
{ key: 'uiBundleBuild', label: 'UI Bundle Build — npm install + build (pre-deploy)', enabled: !argSkipUIBundleBuild, available: true, failFast: true },
|
|
1298
|
+
{ key: 'deploy', label: 'Deploy — sf project deploy start', enabled: !argSkipDeploy, available: true, failFast: true },
|
|
1299
|
+
{ key: 'permset', label: permsetStepLabel, enabled: !argSkipPermset, available: true, failFast: false },
|
|
1300
|
+
{ key: 'role', label: `Role — assign "${roleConfig?.roleName ?? '?'}" to current user`, enabled: !argSkipRole && hasRoleConfig, available: hasRoleConfig, failFast: false },
|
|
1301
|
+
{ key: 'selfReg', label: 'Self-Registration — enable for site', enabled: !argSkipSelfReg && hasSelfRegConfig, available: hasSelfRegConfig, failFast: false },
|
|
1302
|
+
{ key: 'data', label: 'Data — delete + import records via Apex', enabled: !argSkipData && hasDataPlan, available: hasDataPlan, failFast: true },
|
|
1303
|
+
{ key: 'graphql', label: 'GraphQL — schema introspect + codegen', enabled: !argSkipGraphql, available: true, failFast: true },
|
|
1304
|
+
];
|
|
1305
|
+
|
|
1306
|
+
const selections = yes ? stepDefs.map((s) => s.enabled) : await promptSteps(stepDefs);
|
|
1307
|
+
const on = {};
|
|
1308
|
+
stepDefs.forEach((s, i) => {
|
|
1309
|
+
on[s.key] = selections[i];
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
const skipUIBundleBuild = !on.uiBundleBuild;
|
|
1313
|
+
const skipDeploy = !on.deploy;
|
|
1314
|
+
const skipPermset = !on.permset;
|
|
1315
|
+
const skipRole = !on.role;
|
|
1316
|
+
const skipSelfReg = !on.selfReg;
|
|
1317
|
+
const skipData = !on.data;
|
|
1318
|
+
const skipGraphql = !on.graphql;
|
|
1319
|
+
|
|
1320
|
+
const needsUIBundle = !skipUIBundleBuild || !skipGraphql;
|
|
1321
|
+
const uiBundleDir = needsUIBundle ? await discoverUIBundleDir(uiBundleName) : null;
|
|
1322
|
+
const doData = !skipData;
|
|
1323
|
+
|
|
1324
|
+
console.log('Setup — target org:', targetOrg, '| UI bundle:', uiBundleDir ?? '(none)');
|
|
1325
|
+
console.log(
|
|
1326
|
+
'Steps: login=always deploy=%s permset=%s role=%s selfReg=%s data=%s graphql=%s uiBundle=%s',
|
|
1327
|
+
!skipDeploy,
|
|
1328
|
+
!skipPermset,
|
|
1329
|
+
!skipRole,
|
|
1330
|
+
!skipSelfReg,
|
|
1331
|
+
doData,
|
|
1332
|
+
!skipGraphql,
|
|
1333
|
+
!skipUIBundleBuild
|
|
1334
|
+
);
|
|
1335
|
+
|
|
1336
|
+
// Login is an unconditional precondition (spec §5.6, AC-13): it is not part of
|
|
1337
|
+
// the step picker and cannot be skipped. It still no-ops when the org is already
|
|
1338
|
+
// connected, and stays fail-fast — a failed browser login aborts before deploy.
|
|
1339
|
+
const loginStep = { key: 'login', label: 'Login — org authentication', failFast: true };
|
|
1340
|
+
await runStep(loginStep, targetOrg, async () => {
|
|
1341
|
+
if (isOrgConnected(targetOrg)) {
|
|
1342
|
+
console.log('\n--- Login ---');
|
|
1343
|
+
console.log(`Org ${targetOrg} is already authenticated; skipping browser login.`);
|
|
1344
|
+
} else {
|
|
1345
|
+
run('Login (browser)', 'sf', ['org', 'login', 'web', '--alias', targetOrg]);
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1349
|
+
// Ensure the self-reg profile is in networkMemberGroups before deploy so that
|
|
1350
|
+
// subsequent selfRegProfile / selfRegistration updates don't fail. This is
|
|
1351
|
+
// best-effort prep: if the site can't be derived (no network file, or the
|
|
1352
|
+
// ambiguous multi-network case where deriveSiteName throws), skip the prep
|
|
1353
|
+
// silently here — the selfReg step records that derivation failure as a
|
|
1354
|
+
// skippable StepError, so it stays in the ledger instead of aborting pre-deploy.
|
|
1355
|
+
if (!skipDeploy && selfRegConfig) {
|
|
1356
|
+
let preDeploySiteName = null;
|
|
1357
|
+
try {
|
|
1358
|
+
preDeploySiteName = deriveSiteName();
|
|
1359
|
+
} catch {
|
|
1360
|
+
// ambiguous derivation — surfaced by the selfReg step below
|
|
1361
|
+
}
|
|
1362
|
+
if (preDeploySiteName) {
|
|
1363
|
+
console.log('\n--- Ensure network member profile (pre-deploy) ---');
|
|
1364
|
+
ensureNetworkMemberProfile(selfRegConfig, preDeploySiteName);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// Build all UI Bundles before deploy so dist exists for entity deployment
|
|
1369
|
+
const uiBundleBuildStep = stepDefs.find((s) => s.key === 'uiBundleBuild');
|
|
1370
|
+
let preDeployBundlesBuilt = false;
|
|
1371
|
+
if (!skipUIBundleBuild) {
|
|
1372
|
+
if (!skipDeploy) {
|
|
1373
|
+
await runStep(uiBundleBuildStep, targetOrg, () => {
|
|
1374
|
+
const allUIBundleDirs = discoverAllUIBundleDirs(uiBundleName);
|
|
1375
|
+
for (const dir of allUIBundleDirs) {
|
|
1376
|
+
const name = dir.split(/[/\\]/).pop();
|
|
1377
|
+
run(`UI Bundle install (${name})`, 'npm', ['install'], { cwd: dir });
|
|
1378
|
+
run(`UI Bundle build (${name})`, 'npm', ['run', 'build'], { cwd: dir });
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
preDeployBundlesBuilt = true;
|
|
1382
|
+
}
|
|
1383
|
+
// When skipDeploy, the bundle build happens in the GraphQL section below;
|
|
1384
|
+
// its outcome is recorded there.
|
|
1385
|
+
} else {
|
|
1386
|
+
recordSkipped(uiBundleBuildStep, 'not selected');
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
const deployStep = stepDefs.find((s) => s.key === 'deploy');
|
|
1390
|
+
if (!skipDeploy) {
|
|
1391
|
+
await runStep(deployStep, targetOrg, () => {
|
|
1392
|
+
// License pre-check (spec §5.3): deploy fails with a cryptic error when the
|
|
1393
|
+
// org lacks the UserLicense the selfRegProfile's metadata requires. Verify a
|
|
1394
|
+
// seat is available BEFORE `sf project deploy start` so the run aborts with a
|
|
1395
|
+
// clean message NAMING the missing license. The required license is read from
|
|
1396
|
+
// the local profile source (the profile isn't in the org yet pre-deploy, so
|
|
1397
|
+
// querying it would only report "profile missing"). Only gates when self-reg
|
|
1398
|
+
// is configured — that config names the profile the license is derived from.
|
|
1399
|
+
if (selfRegConfig) {
|
|
1400
|
+
const licenseGate = checkDeployLicense(selfRegConfig, targetOrg);
|
|
1401
|
+
if (!licenseGate.satisfied) {
|
|
1402
|
+
throw new StepError(`deploy blocked — ${licenseGate.reason}`);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
run('Deploy metadata', 'sf', ['project', 'deploy', 'start', '--target-org', targetOrg], {
|
|
1406
|
+
timeout: 180000,
|
|
1407
|
+
});
|
|
1408
|
+
});
|
|
1409
|
+
} else {
|
|
1410
|
+
recordSkipped(deployStep, 'not selected');
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
const permsetStep = stepDefs.find((s) => s.key === 'permset');
|
|
1414
|
+
if (!skipPermset) {
|
|
1415
|
+
await runStep(permsetStep, targetOrg, async () => {
|
|
1416
|
+
const permsetConfig = loadPermsetConfig(config);
|
|
1417
|
+
if (permsetNames.length === 0) {
|
|
1418
|
+
console.log('\n--- Assign permission sets ---');
|
|
1419
|
+
console.log('No permission sets found under permissionsets/ and none passed via --permset-name; skipping.');
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
console.log('\n--- Assign permission sets ---');
|
|
1423
|
+
|
|
1424
|
+
// Resolve assignments (guest user lookups etc.) then run all sf assign calls in parallel.
|
|
1425
|
+
//
|
|
1426
|
+
// A guest-user resolution failure (no derivable site, or no guest user yet)
|
|
1427
|
+
// is collected — NOT thrown mid-loop. Throwing here would unwind the whole
|
|
1428
|
+
// runStep body before Promise.all and silently drop every assignment already
|
|
1429
|
+
// queued (e.g. a currentUser permset that sorts ahead of a guestUser one and
|
|
1430
|
+
// never depended on the site at all). Resolvable assignments still run; the
|
|
1431
|
+
// combined failure is thrown at the end so the step is still recorded failed.
|
|
1432
|
+
const assignmentJobs = [];
|
|
1433
|
+
const resolutionFailures = [];
|
|
1434
|
+
for (const permsetName of permsetNames) {
|
|
1435
|
+
const assignment = resolveAssignment(permsetName, permsetConfig);
|
|
1436
|
+
if (assignment.assignee === 'skip') {
|
|
1437
|
+
console.log(`Permission set "${permsetName}" — skipped (config).`);
|
|
1438
|
+
continue;
|
|
1439
|
+
}
|
|
1440
|
+
let effectiveUsername = null;
|
|
1441
|
+
if (assignment.assignee === 'guestUser') {
|
|
1442
|
+
// Site name is derived from the single network metadata file the app
|
|
1443
|
+
// ships — never restated per-assignment.
|
|
1444
|
+
const siteName = deriveSiteName();
|
|
1445
|
+
if (!siteName) {
|
|
1446
|
+
console.error(`Permission set "${permsetName}" — assignee is "guestUser" but no networks/<siteName>.network-meta.xml was found to derive the site; skipping.`);
|
|
1447
|
+
resolutionFailures.push(`${permsetName} (no network metadata to derive site)`);
|
|
1448
|
+
continue;
|
|
1449
|
+
}
|
|
1450
|
+
effectiveUsername = resolveGuestUsername(siteName, targetOrg);
|
|
1451
|
+
if (!effectiveUsername) {
|
|
1452
|
+
console.error(`Permission set "${permsetName}" — could not resolve guest user for site "${siteName}"; skipping.`);
|
|
1453
|
+
resolutionFailures.push(`${permsetName} (could not resolve guest user for site "${siteName}")`);
|
|
1454
|
+
continue;
|
|
1455
|
+
}
|
|
1456
|
+
console.log(` Resolved guest user for site "${siteName}": ${effectiveUsername}`);
|
|
1457
|
+
}
|
|
1458
|
+
assignmentJobs.push({ permsetName, effectiveUsername });
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// Run all permset assignment calls in parallel.
|
|
1462
|
+
const assignResults = await Promise.all(assignmentJobs.map(async ({ permsetName, effectiveUsername }) => {
|
|
1463
|
+
const sfArgs = ['org', 'assign', 'permset', '--name', permsetName, '--target-org', targetOrg];
|
|
1464
|
+
if (effectiveUsername) {
|
|
1465
|
+
sfArgs.push('--on-behalf-of', effectiveUsername);
|
|
1466
|
+
}
|
|
1467
|
+
const assigneeLabel = effectiveUsername || 'current user';
|
|
1468
|
+
const result = await spawnAsync('sf', sfArgs);
|
|
1469
|
+
return { permsetName, assigneeLabel, result };
|
|
1470
|
+
}));
|
|
1471
|
+
|
|
1472
|
+
const failures = [];
|
|
1473
|
+
for (const { permsetName, assigneeLabel, result } of assignResults) {
|
|
1474
|
+
if (result.status === 0) {
|
|
1475
|
+
console.log(`Permission set "${permsetName}" assigned to ${assigneeLabel}.`);
|
|
1476
|
+
} else {
|
|
1477
|
+
const out = (result.stderr || '') + (result.stdout || '');
|
|
1478
|
+
if (out.includes('Duplicate') && out.includes('PermissionSet')) {
|
|
1479
|
+
console.log(`Permission set "${permsetName}" already assigned to ${assigneeLabel}; skipping.`);
|
|
1480
|
+
} else if (out.includes('not found') && out.includes('target org')) {
|
|
1481
|
+
console.log(`Permission set "${permsetName}" not in org; skipping.`);
|
|
1482
|
+
} else {
|
|
1483
|
+
if (result.stdout) process.stdout.write(result.stdout);
|
|
1484
|
+
if (result.stderr) process.stderr.write(result.stderr);
|
|
1485
|
+
failures.push(`${permsetName} (exit ${result.status ?? 1})`);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
const allFailures = [...resolutionFailures, ...failures];
|
|
1490
|
+
if (allFailures.length > 0) {
|
|
1491
|
+
throw new StepError(`failed to assign permission set(s): ${allFailures.join(', ')}`);
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
} else {
|
|
1495
|
+
recordSkipped(permsetStep, 'not selected');
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
const roleStep = stepDefs.find((s) => s.key === 'role');
|
|
1499
|
+
if (!skipRole) {
|
|
1500
|
+
console.log('\n--- Assign role ---');
|
|
1501
|
+
// Config shape (assignee === 'currentUser', non-empty roleName) is guaranteed
|
|
1502
|
+
// by the schema, so there is nothing to re-check here — the step either ran
|
|
1503
|
+
// (ok) or its assignment threw (failed). No manual recordSkipped inference.
|
|
1504
|
+
await runStep(roleStep, targetOrg, () => {
|
|
1505
|
+
assignRoleToCurrentUser(roleConfig.roleName, targetOrg);
|
|
1506
|
+
});
|
|
1507
|
+
} else {
|
|
1508
|
+
recordSkipped(roleStep, roleStep.available ? 'not selected' : 'no config');
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
const selfRegStep = stepDefs.find((s) => s.key === 'selfReg');
|
|
1512
|
+
if (!skipSelfReg) {
|
|
1513
|
+
// M1 license pre-check (spec §5.3): self-registration requires a seat on the
|
|
1514
|
+
// UserLicense the selfRegProfile belongs to. Verify it BEFORE running the step
|
|
1515
|
+
// — recordSkipped is only reachable here, ahead of runStep (mirroring the
|
|
1516
|
+
// not-selected branch); once inside a step body an unmet precondition could
|
|
1517
|
+
// only record `failed`. A missing / inactive / seatless license is a soft
|
|
1518
|
+
// precondition, not a setup failure, so warn + recordSkipped and move on.
|
|
1519
|
+
const licenseGate = checkSelfRegLicense(selfRegConfig, targetOrg);
|
|
1520
|
+
if (!licenseGate.satisfied) {
|
|
1521
|
+
console.warn(`\n--- Self-registration skipped ---\n ⚠ ${licenseGate.reason}`);
|
|
1522
|
+
recordSkipped(selfRegStep, licenseGate.reason);
|
|
1523
|
+
} else {
|
|
1524
|
+
console.log('\n--- Enable self-registration ---');
|
|
1525
|
+
// Config shape (selfRegProfile, accountName) is guaranteed by the schema.
|
|
1526
|
+
// The site is derived inside the step body so a "multiple network files"
|
|
1527
|
+
// StepError is recorded in the ledger rather than escaping. No manual
|
|
1528
|
+
// recordSkipped inference.
|
|
1529
|
+
await runStep(selfRegStep, targetOrg, () => {
|
|
1530
|
+
const siteName = deriveSiteName();
|
|
1531
|
+
if (!siteName) {
|
|
1532
|
+
throw new StepError(
|
|
1533
|
+
'self-registration is configured but no networks/<siteName>.network-meta.xml was found to derive the site',
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
enableSelfRegistration(selfRegConfig, siteName, targetOrg);
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
} else {
|
|
1540
|
+
recordSkipped(selfRegStep, selfRegStep.available ? 'not selected' : 'no config');
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
const dataStep = stepDefs.find((s) => s.key === 'data');
|
|
1544
|
+
if (doData) {
|
|
1545
|
+
await runStep(dataStep, targetOrg, () => {
|
|
1546
|
+
// Prepare data for uniqueness (run before import so repeat imports don't conflict).
|
|
1547
|
+
// Per-app data normalization (reference remapping, unique-field mangling) ships with
|
|
1548
|
+
// the app's seed data as data/prepare-import-unique-fields.js — this script stays
|
|
1549
|
+
// object-agnostic and simply runs it if present.
|
|
1550
|
+
const prepareScript = resolve(DATA_DIR, 'prepare-import-unique-fields.js');
|
|
1551
|
+
if (existsSync(prepareScript)) {
|
|
1552
|
+
run('Prepare data (unique fields)', 'node', [prepareScript, '--data-dir', DATA_DIR], {
|
|
1553
|
+
cwd: ROOT,
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
// Delete existing records so every run inserts the full dataset without duplicate conflicts.
|
|
1558
|
+
// Reverse plan order ensures children are removed before parents (FK safety).
|
|
1559
|
+
console.log('\n--- Clean existing data for fresh import ---');
|
|
1560
|
+
const planEntries = JSON.parse(readFileSync(DATA_PLAN, 'utf8'));
|
|
1561
|
+
const sobjectsReversed = [...planEntries.map((e) => e.sobject)].reverse();
|
|
1562
|
+
// One private temp dir for both the delete sweep and the import batches;
|
|
1563
|
+
// always removed in finally, even if a batch throws.
|
|
1564
|
+
withApexTempDir((writeApex) => {
|
|
1565
|
+
for (const sobject of sobjectsReversed) {
|
|
1566
|
+
const apexCode = [
|
|
1567
|
+
'try {',
|
|
1568
|
+
` List<SObject> recs = Database.query('SELECT Id FROM ${sobject} LIMIT 10000');`,
|
|
1569
|
+
' if (!recs.isEmpty()) {',
|
|
1570
|
+
' Database.delete(recs, false);',
|
|
1571
|
+
' Database.emptyRecycleBin(recs);',
|
|
1572
|
+
' }',
|
|
1573
|
+
'} catch (Exception e) {',
|
|
1574
|
+
' // non-deletable records (e.g. Contact linked to Case) are skipped via allOrNone=false',
|
|
1575
|
+
'}',
|
|
1576
|
+
].join('\n');
|
|
1577
|
+
const tmpApex = writeApex('data.apex', apexCode);
|
|
1578
|
+
spawnSync('sf', ['apex', 'run', '--target-org', targetOrg, '--file', tmpApex], {
|
|
1579
|
+
cwd: ROOT,
|
|
1580
|
+
stdio: 'pipe',
|
|
1581
|
+
shell: true,
|
|
1582
|
+
timeout: 60000,
|
|
1583
|
+
});
|
|
1584
|
+
console.log(` ${sobject}: cleaned`);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
// Import via Anonymous Apex with Database.DMLOptions.duplicateRuleHeader.allowSave = true.
|
|
1588
|
+
// This bypasses both duplicate-rule blocks AND matching-service timeouts that the REST
|
|
1589
|
+
// API headers (Sforce-Duplicate-Rule-Action) cannot override.
|
|
1590
|
+
console.log('\n--- Data import tree ---');
|
|
1591
|
+
const refMap = new Map();
|
|
1592
|
+
const APEX_CHAR_LIMIT = 25000;
|
|
1593
|
+
const APEX_MAX_BATCH = 200;
|
|
1594
|
+
|
|
1595
|
+
for (const entry of planEntries) {
|
|
1596
|
+
for (const file of entry.files) {
|
|
1597
|
+
const data = JSON.parse(readFileSync(resolve(DATA_DIR, file), 'utf8'));
|
|
1598
|
+
const records = data.records || [];
|
|
1599
|
+
|
|
1600
|
+
for (const rec of records) {
|
|
1601
|
+
for (const key of Object.keys(rec)) {
|
|
1602
|
+
if (key === 'attributes') continue;
|
|
1603
|
+
const val = rec[key];
|
|
1604
|
+
if (typeof val === 'string' && val.startsWith('@')) {
|
|
1605
|
+
const actual = refMap.get(val.slice(1));
|
|
1606
|
+
if (actual) {
|
|
1607
|
+
rec[key] = actual;
|
|
1608
|
+
} else if (refMap.size > 0) {
|
|
1609
|
+
console.warn(` Warning: unresolved ref ${val} in ${file}`);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
let imported = 0;
|
|
1616
|
+
const sampleRec = records[0] || {};
|
|
1617
|
+
const fieldsPerRec = Object.keys(sampleRec).filter((k) => k !== 'attributes').length;
|
|
1618
|
+
const estCharsPerRec = 40 + fieldsPerRec * 55;
|
|
1619
|
+
const batchSize = Math.min(APEX_MAX_BATCH, Math.max(5, Math.floor(APEX_CHAR_LIMIT / estCharsPerRec)));
|
|
1620
|
+
for (let i = 0; i < records.length; i += batchSize) {
|
|
1621
|
+
const batch = records.slice(i, i + batchSize);
|
|
1622
|
+
const refIds = batch.map((r) => r.attributes?.referenceId || `_idx${i}`);
|
|
1623
|
+
const apex = buildApexInsert(entry.sobject, batch, refIds);
|
|
1624
|
+
const tmpApex = writeApex('data.apex', apex);
|
|
1625
|
+
const apexResult = spawnSync(
|
|
1626
|
+
'sf',
|
|
1627
|
+
['apex', 'run', '--target-org', targetOrg, '--file', tmpApex],
|
|
1628
|
+
{ cwd: ROOT, stdio: 'pipe', shell: true, timeout: 120000 }
|
|
1629
|
+
);
|
|
1630
|
+
const apexOut = apexResult.stdout?.toString() || '';
|
|
1631
|
+
const apexErr = apexResult.stderr?.toString() || '';
|
|
1632
|
+
if (apexResult.status !== 0 && !apexOut.includes('Compiled successfully')) {
|
|
1633
|
+
process.stderr.write(apexErr || apexOut);
|
|
1634
|
+
throw new StepError(`${entry.sobject}: apex execution failed`);
|
|
1635
|
+
}
|
|
1636
|
+
const okMatches = [...apexOut.matchAll(/\|DEBUG\|REF:([^:\n]+):(\w+)/g)];
|
|
1637
|
+
const errMatches = [...apexOut.matchAll(/\|DEBUG\|ERR:([^:\n]+):([^\n]+)/g)];
|
|
1638
|
+
if (errMatches.length) {
|
|
1639
|
+
for (const m of errMatches.slice(0, 5)) {
|
|
1640
|
+
console.error(` ${m[1]}: ${m[2].trim()}`);
|
|
1641
|
+
}
|
|
1642
|
+
if (errMatches.length > 5) console.error(` ... and ${errMatches.length - 5} more`);
|
|
1643
|
+
throw new StepError(`data import tree (${entry.sobject}) — ${errMatches.length} record error(s)`);
|
|
1644
|
+
}
|
|
1645
|
+
if (entry.saveRefs) {
|
|
1646
|
+
for (const m of okMatches) refMap.set(m[1], m[2]);
|
|
1647
|
+
}
|
|
1648
|
+
imported += okMatches.length;
|
|
1649
|
+
}
|
|
1650
|
+
console.log(` ${entry.sobject}: imported ${imported} records`);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
});
|
|
1655
|
+
} else {
|
|
1656
|
+
recordSkipped(dataStep, dataStep.available ? 'not selected' : 'no data plan');
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
const graphqlStep = stepDefs.find((s) => s.key === 'graphql');
|
|
1660
|
+
if (!skipGraphql) {
|
|
1661
|
+
await runStep(graphqlStep, targetOrg, () => {
|
|
1662
|
+
run('UI Bundle npm install', 'npm', ['install'], { cwd: uiBundleDir });
|
|
1663
|
+
run('GraphQL schema (introspect)', 'npm', ['run', 'graphql:schema'], {
|
|
1664
|
+
cwd: uiBundleDir,
|
|
1665
|
+
env: { ...process.env, SF_TARGET_ORG: targetOrg },
|
|
1666
|
+
});
|
|
1667
|
+
run('GraphQL codegen', 'npm', ['run', 'graphql:codegen'], { cwd: uiBundleDir });
|
|
1668
|
+
run('UI Bundle build (post-codegen)', 'npm', ['run', 'build'], { cwd: uiBundleDir });
|
|
1669
|
+
});
|
|
1670
|
+
} else {
|
|
1671
|
+
recordSkipped(graphqlStep, 'not selected');
|
|
1672
|
+
if (!skipUIBundleBuild && skipDeploy && !preDeployBundlesBuilt) {
|
|
1673
|
+
// The pre-deploy build never ran (deploy was skipped); build here and
|
|
1674
|
+
// record the uiBundleBuild outcome that the pre-deploy branch would have.
|
|
1675
|
+
await runStep(uiBundleBuildStep, targetOrg, () => {
|
|
1676
|
+
run('UI Bundle npm install', 'npm', ['install'], { cwd: uiBundleDir });
|
|
1677
|
+
run('UI Bundle build', 'npm', ['run', 'build'], { cwd: uiBundleDir });
|
|
1678
|
+
});
|
|
1679
|
+
preDeployBundlesBuilt = true;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
// When uiBundleBuild was selected but the dedicated pre-deploy build never ran
|
|
1684
|
+
// (deploy skipped and graphql selected), the build happened inside the graphql
|
|
1685
|
+
// step — which is fail-fast, so reaching here means it succeeded. Record ok.
|
|
1686
|
+
if (!skipUIBundleBuild && !preDeployBundlesBuilt && !results.some((r) => r.key === 'uiBundleBuild')) {
|
|
1687
|
+
recordOk(uiBundleBuildStep);
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
// Setup terminates cleanly here (spec §5.5, AC-11). Launching the dev server is
|
|
1691
|
+
// no longer part of setup — run `npm run dev:preview` (scripts/org-setup-dev.mjs) for that.
|
|
1692
|
+
printSummary(targetOrg);
|
|
1693
|
+
if (finalExitCode() === 0) {
|
|
1694
|
+
console.log('\nTo launch the dev server, run: npm run dev:preview');
|
|
1695
|
+
}
|
|
1696
|
+
process.exit(finalExitCode());
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
main().catch((err) => {
|
|
1700
|
+
console.error(err);
|
|
1701
|
+
process.exit(1);
|
|
1702
|
+
});
|