@adobedjangir/commerce-admin-management 0.0.13 → 0.0.15

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/README.md CHANGED
@@ -40,6 +40,7 @@ and an extension point for host apps to add their own pages and actions.
40
40
  | App Builder Database (ABDB) auto-provisioning on deploy | `ext.config.yaml` |
41
41
  | Host-extensible nav and pages | `configureWeb({ extraNav, extraPages })` |
42
42
  | Auto-scaffolded host scaffold on `npm install` | `scripts/setup.js` (postinstall hook) |
43
+ | Auto-bump host React/Spectrum/Adobe deps to React-18 floor | `scripts/setup.js` mutates host `package.json` |
43
44
 
44
45
  ---
45
46
 
@@ -50,14 +51,15 @@ and an extension point for host apps to add their own pages and actions.
50
51
  aio app init my-commerce-admin
51
52
  cd my-commerce-admin
52
53
 
53
- # 2. Install the package postinstall scaffolds everything
54
+ # 2. Install. The postinstall bumps the host's package.json to the
55
+ # React 18 / Spectrum 4 floor and re-runs `npm install` automatically.
54
56
  npm install @adobedjangir/commerce-admin-management
55
57
 
56
58
  # 3. Fill in .env (see required values below)
57
59
  cp env.dist .env
58
60
  $EDITOR .env
59
61
 
60
- # 4. Deploy. ABDB is auto-provisioned; 11 actions + web assets ship to CDN.
62
+ # 4. Deploy. ABDB is auto-provisioned; actions + web assets ship to CDN.
61
63
  aio app deploy
62
64
  ```
63
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobedjangir/commerce-admin-management",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Schema-driven system configuration for Adobe Commerce App Builder sync apps. Magento-style scoped config in Adobe App Builder Database (ABDB) with encryption, Commerce REST helpers, and React Admin UI.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Adobe Inc.",
@@ -53,26 +53,20 @@
53
53
  "@adobe/aio-lib-core-auth": ">=1.1.0",
54
54
  "@adobe/aio-lib-db": ">=1.0.0",
55
55
  "@adobe/aio-lib-ims": ">=7.0.0",
56
- "@adobe/aio-sdk": ">=5.0.0",
57
- "@adobe/exc-app": ">=1.0.0",
58
- "@adobe/react-spectrum": ">=3.30.0",
59
- "@adobe/uix-guest": ">=0.8.0",
60
- "@spectrum-icons/workflow": ">=3.0.0 <5.0.0",
61
- "dotenv": ">=16.0.0",
62
- "react": ">=18.0.0",
63
- "react-dom": ">=18.0.0",
64
- "react-error-boundary": ">=3.1.0",
65
- "react-router-dom": ">=6.0.0"
56
+ "dotenv": ">=16.0.0"
66
57
  },
67
58
  "peerDependenciesMeta": {
68
59
  "@adobe/aio-lib-core-auth": {
69
- "optional": false
60
+ "optional": true
70
61
  },
71
62
  "@adobe/aio-lib-db": {
72
- "optional": false
63
+ "optional": true
73
64
  },
74
65
  "@adobe/aio-lib-ims": {
75
- "optional": false
66
+ "optional": true
67
+ },
68
+ "dotenv": {
69
+ "optional": true
76
70
  }
77
71
  },
78
72
  "dependencies": {
package/scripts/setup.js CHANGED
@@ -496,6 +496,122 @@ function stripExcshellSourceDir (projectRoot) {
496
496
  return { changed, reason: changed ? 'removed' : 'absent' }
497
497
  }
498
498
 
499
+ /**
500
+ * Bump the host's package.json so the React 18 / Spectrum 4 stack we
501
+ * depend on is satisfied without the consumer running a long
502
+ * `npm install --save react@^18 …` chant. We declare these as peers (to
503
+ * avoid shipping duplicate React copies) but a fresh `aio app init` host
504
+ * still pins React 16 — so we patch the host's declared versions here.
505
+ *
506
+ * Strategy:
507
+ * - Only touch entries that are MISSING or pin a version below our floor.
508
+ * - Leave entries already satisfying the floor alone (don't downgrade).
509
+ * - We mutate package.json only; the next `npm install` actually applies
510
+ * the upgrade. We don't re-shell-out to npm from a postinstall — that
511
+ * causes recursive installs and is fragile in workspaces / monorepos.
512
+ */
513
+ const REQUIRED_HOST_DEPS = {
514
+ // React + DOM — package code uses createRoot/react-dom/client (React 18+).
515
+ 'react': '^18.3.1',
516
+ 'react-dom': '^18.3.1',
517
+ // React-error-boundary v4 dropped the default export the older versions
518
+ // shipped; we use named imports so v4 is the floor.
519
+ 'react-error-boundary': '^4.0.0',
520
+ 'react-router-dom': '^6.26.2',
521
+ // Adobe Spectrum trio — must be React-18 compatible.
522
+ '@adobe/react-spectrum': '^3.47.0',
523
+ '@spectrum-icons/workflow': '^4.2.4',
524
+ '@spectrum-icons/ui': '^3.7.1',
525
+ // Adobe app runtime + helpers used by the bootstrap and actions.
526
+ '@adobe/exc-app': '^1.6.0',
527
+ '@adobe/uix-guest': '^0.8.3',
528
+ '@adobe/aio-sdk': '^6.0.0'
529
+ }
530
+
531
+ // Parse a semver-ish version specifier ("^18.3.1", ">=3.0.0", "16.14.0",
532
+ // "16.14.0 || >=18") and return the lowest concrete major.minor.patch it
533
+ // could resolve to. Returns null for non-numeric specs we can't reason
534
+ // about (workspace:*, file:..., git URLs) — those we leave alone.
535
+ function lowestVersion (spec) {
536
+ if (!spec || typeof spec !== 'string') return null
537
+ const s = spec.split('||')[0].trim() // take the first range in an OR list
538
+ const m = s.match(/(\d+)\.(\d+)\.(\d+)/)
539
+ if (!m) return null
540
+ return { major: +m[1], minor: +m[2], patch: +m[3] }
541
+ }
542
+
543
+ function compareVersions (a, b) {
544
+ if (a.major !== b.major) return a.major - b.major
545
+ if (a.minor !== b.minor) return a.minor - b.minor
546
+ return a.patch - b.patch
547
+ }
548
+
549
+ function satisfiesFloor (currentSpec, floorSpec) {
550
+ const cur = lowestVersion(currentSpec)
551
+ const min = lowestVersion(floorSpec)
552
+ if (!cur || !min) return false
553
+ return compareVersions(cur, min) >= 0
554
+ }
555
+
556
+ /**
557
+ * Re-run `npm install` after bumping host package.json so the upgraded
558
+ * versions actually land in node_modules. Without this, the consumer
559
+ * would have to run `npm install` manually after our postinstall.
560
+ *
561
+ * Recursion is prevented by setting COMMERCE_ADMIN_MANAGEMENT_SKIP_SETUP=1
562
+ * in the child npm's env — main() bails immediately when it sees that
563
+ * flag, so the inner install doesn't loop back through this code.
564
+ *
565
+ * Failures here don't throw — we print a fallback hint and let the
566
+ * outer install report success. The consumer can re-run `npm install`
567
+ * manually if our auto-invocation can't reach the network.
568
+ */
569
+ function autoRunNpmInstall (projectRoot) {
570
+ const { execSync } = require('child_process')
571
+ console.log('[@adobedjangir/commerce-admin-management] running `npm install` to apply the bumped versions…')
572
+ try {
573
+ execSync('npm install --no-audit --no-fund --silent --legacy-peer-deps', {
574
+ cwd: projectRoot,
575
+ stdio: 'inherit',
576
+ env: { ...process.env, COMMERCE_ADMIN_MANAGEMENT_SKIP_SETUP: '1' }
577
+ })
578
+ console.log('[@adobedjangir/commerce-admin-management] dependency upgrade complete ✓')
579
+ } catch (e) {
580
+ console.warn('[@adobedjangir/commerce-admin-management] auto-install failed. Run `npm install` manually.')
581
+ console.warn(` reason: ${e.message}`)
582
+ }
583
+ }
584
+
585
+ function ensureHostDeps (projectRoot) {
586
+ const pkgPath = path.join(projectRoot, 'package.json')
587
+ if (!fs.existsSync(pkgPath)) {
588
+ return { changed: false, reason: 'no-package-json' }
589
+ }
590
+ let pkg
591
+ try { pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) } catch (_) {
592
+ return { changed: false, reason: 'unreadable-package-json' }
593
+ }
594
+ pkg.dependencies = pkg.dependencies || {}
595
+
596
+ const bumped = []
597
+ for (const [name, floor] of Object.entries(REQUIRED_HOST_DEPS)) {
598
+ const declared = pkg.dependencies[name] || (pkg.devDependencies && pkg.devDependencies[name])
599
+ if (declared && satisfiesFloor(declared, floor)) continue
600
+ // Move it to dependencies (out of devDependencies if it was there) and
601
+ // set to the floor.
602
+ pkg.dependencies[name] = floor
603
+ if (pkg.devDependencies && pkg.devDependencies[name]) {
604
+ delete pkg.devDependencies[name]
605
+ }
606
+ bumped.push({ name, was: declared || '(missing)', now: floor })
607
+ }
608
+
609
+ if (bumped.length === 0) return { changed: false, reason: 'already-satisfies' }
610
+
611
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8')
612
+ return { changed: true, bumped }
613
+ }
614
+
499
615
  function setupAppConfig (projectRoot) {
500
616
  const appConfigPath = path.join(projectRoot, 'app.config.yaml')
501
617
  if (!fs.existsSync(appConfigPath)) {
@@ -519,9 +635,12 @@ function setupAppConfig (projectRoot) {
519
635
  }
520
636
 
521
637
  function main () {
522
- if (process.env.CONFIGURATION_MANAGEMENT_SKIP_SETUP === '1') {
523
- return
524
- }
638
+ // Two opt-outs:
639
+ // - CONFIGURATION_MANAGEMENT_SKIP_SETUP: legacy name kept for compat.
640
+ // - COMMERCE_ADMIN_MANAGEMENT_SKIP_SETUP: set by autoRunNpmInstall to
641
+ // prevent the recursive postinstall from re-running this code.
642
+ if (process.env.CONFIGURATION_MANAGEMENT_SKIP_SETUP === '1') return
643
+ if (process.env.COMMERCE_ADMIN_MANAGEMENT_SKIP_SETUP === '1') return
525
644
 
526
645
  const projectRoot = resolveProjectRoot()
527
646
  if (!projectRoot) {
@@ -539,6 +658,24 @@ function main () {
539
658
  console.log('[@adobedjangir/commerce-admin-management] removed src/dx-excshell-1/ (replaced by commerce/backend-ui/1)')
540
659
  }
541
660
 
661
+ // Bump host package.json so React-18 + Spectrum-4 peers are satisfied
662
+ // without the consumer running a long `npm install --save react@^18 ...`
663
+ // chant. If anything was bumped, automatically re-run npm install so the
664
+ // new versions actually land in node_modules. A guard env var prevents
665
+ // the recursive postinstall from re-running this step.
666
+ const deps = ensureHostDeps(projectRoot)
667
+ if (deps.changed) {
668
+ console.log('[@adobedjangir/commerce-admin-management] bumped host package.json:')
669
+ for (const b of deps.bumped) {
670
+ console.log(` • ${b.name}: ${b.was} → ${b.now}`)
671
+ }
672
+ if (process.env.COMMERCE_ADMIN_MANAGEMENT_NO_AUTO_INSTALL === '1') {
673
+ console.log('[@adobedjangir/commerce-admin-management] auto-install disabled; run `npm install` to apply.')
674
+ } else {
675
+ autoRunNpmInstall(projectRoot)
676
+ }
677
+ }
678
+
542
679
  const app = setupAppConfig(projectRoot)
543
680
  if (app.changed) {
544
681
  console.log(