@wearejh/m2-pwa-engine 0.33.1 → 0.35.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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.35.0](https://github.com/WeareJH/mage-mono/compare/v0.34.0...v0.35.0) (2025-09-08)
7
+
8
+ **Note:** Version bump only for package @wearejh/m2-pwa-engine
9
+
10
+
11
+
12
+
13
+
14
+ # [0.34.0](https://github.com/WeareJH/mage-mono/compare/v0.33.1...v0.34.0) (2025-09-08)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **WOOD-2710:** ensure service work uses hashed directory ([88f67d0](https://github.com/WeareJH/mage-mono/commit/88f67d06e7caeb2e4b4406bdf878999ec774ca2d))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.33.1](https://github.com/WeareJH/mage-mono/compare/v0.33.0...v0.33.1) (2025-07-01)
7
26
 
8
27
  **Note:** Version bump only for package @wearejh/m2-pwa-engine
package/README.md CHANGED
@@ -1 +1,100 @@
1
- @wearejh/m2-pwa-user
1
+ # @wearejh/m2-pwa-engine
2
+
3
+ The core Progressive Web Application (PWA) engine for Magento 2, providing the foundational infrastructure and services needed to build modern, performant e-commerce experiences.
4
+
5
+ ## Overview
6
+
7
+ The `m2-pwa-engine` package serves as the backbone of the Magento 2 PWA ecosystem, offering essential utilities, state management, routing, and integration capabilities that power e-commerce applications. It provides a standardized foundation that other PWA packages can build upon.
8
+
9
+ ## Key Features
10
+
11
+ - **Redux Store Management**: Lazy access to the Redux store with proper typing
12
+ - **Apollo GraphQL Integration**: Client configuration and provider setup for Magento GraphQL API
13
+ - **Routing Infrastructure**: Core routing utilities and components
14
+ - **Environment Configuration**: Multi-environment support (development, staging, production)
15
+ - **Service Worker Support**: PWA capabilities and offline functionality
16
+ - **TypeScript Support**: Full TypeScript definitions and type safety
17
+
18
+ ## Architecture
19
+
20
+ ```mermaid
21
+ graph TD
22
+ A[m2-pwa-engine] --> B[Redux Store]
23
+ A --> C[Apollo Client]
24
+ A --> D[Router]
25
+ A --> E[Environment Config]
26
+
27
+ B --> F[State Management]
28
+ C --> G[GraphQL API]
29
+ D --> H[Navigation]
30
+ E --> I[Multi-env Support]
31
+
32
+ F --> J[Cart Module]
33
+ F --> K[User Module]
34
+ F --> L[Checkout Module]
35
+
36
+ G --> M[Magento GraphQL]
37
+ H --> N[Page Components]
38
+ I --> O[staging/staging3/production]
39
+
40
+ style A fill:#e1f5fe
41
+ style B fill:#f3e5f5
42
+ style C fill:#e8f5e8
43
+ style D fill:#fff3e0
44
+ style E fill:#fce4ec
45
+ ```
46
+
47
+ ## Core Concepts
48
+
49
+ ### State Management
50
+ The engine provides a centralized Redux store with lazy initialization, allowing modules to register their reducers and access shared application state efficiently.
51
+
52
+ ### GraphQL Integration
53
+ Built-in Apollo Client configuration enables seamless communication with Magento's GraphQL API, handling authentication, caching, and error management.
54
+
55
+ ### Environment Support
56
+ The package includes configuration for multiple deployment environments:
57
+ - Development
58
+ - Staging (staging3 support added in v0.31.2)
59
+ - Production
60
+
61
+ ### Modular Architecture
62
+ Designed to work with companion packages:
63
+ - [`m2-pwa-cart`](../m2-pwa-cart) - Shopping cart functionality
64
+ - [`m2-pwa-user`](../m2-pwa-user) - User authentication and management
65
+ - [`m2-pwa-checkout`](../m2-pwa-checkout) - Checkout process
66
+ - [`m2-pwa-adyen`](../m2-pwa-adyen) - Adyen payment integration
67
+ - [`m2-pwa-tools`](../m2-pwa-tools) - Development and build tools
68
+ - [`m2-pwa-webpack`](../m2-pwa-webpack) - Webpack configuration
69
+
70
+ ## Installation
71
+
72
+ ```bash
73
+ npm install @wearejh/m2-pwa-engine
74
+ ```
75
+
76
+ ## Usage
77
+
78
+ The engine is typically initialized early in your application lifecycle:
79
+
80
+ ```typescript
81
+ import { initializeEngine } from '@wearejh/m2-pwa-engine';
82
+
83
+ // Initialize the PWA engine with your configuration
84
+ const engine = initializeEngine({
85
+ apiUrl: 'https://your-magento-instance.com/graphql',
86
+ environment: 'production'
87
+ });
88
+ ```
89
+
90
+ ## Dependencies
91
+
92
+ This package works in conjunction with the broader Magento 2 PWA ecosystem and requires:
93
+ - React for UI components
94
+ - Redux for state management
95
+ - Apollo Client for GraphQL communication
96
+ - Compatible Magento 2 backend with GraphQL support
97
+
98
+ ## Contributing
99
+
100
+ This package is part of the larger mage-mono repository. Changes should be made following the established patterns and with consideration for backward compatibility across the PWA
@@ -2,7 +2,7 @@ import { EMPTY, Observable, of } from 'rxjs';
2
2
  import { ignoreElements, share, tap, mergeMap, withLatestFrom } from 'rxjs/operators';
3
3
  import { Action } from 'redux';
4
4
 
5
- import { RuntimeActions, RuntimeMsg } from '../runtime.register';
5
+ import { RuntimeActions, RuntimeMsg, RuntimeEnv } from '../runtime.register';
6
6
  import { createDebug } from '../../utils/runtimeDebug';
7
7
 
8
8
  const debug = createDebug(`serviceWorkers.ts`);
@@ -16,13 +16,21 @@ const debug = createDebug(`serviceWorkers.ts`);
16
16
  export function registerServiceWorker(
17
17
  version = '__development__',
18
18
  path = '/sw.js',
19
+ env?: RuntimeEnv,
19
20
  ): Observable<ServiceWorkerRegistration> {
20
- debug('Trying to register ', path);
21
+ // Use dynamic path based on asset prefix if available
22
+ let swPath = path;
23
+ if (env?.ASSET_PREFIX) {
24
+ swPath = `/${env.ASSET_PREFIX}/sw.js`;
25
+ debug('Using dynamic SW path with asset prefix:', swPath);
26
+ }
27
+
28
+ debug('Trying to register ', swPath);
21
29
  debug('Version', version);
22
30
 
23
31
  return Observable.create((observer) => {
24
32
  navigator.serviceWorker
25
- .register(path)
33
+ .register(swPath)
26
34
  .then((registration) => {
27
35
  debug('SW registered: ', registration);
28
36
  observer.next(registration);
@@ -104,10 +112,17 @@ export function handleVersionUpdates(
104
112
  * Register the killswitch
105
113
  * @param path
106
114
  */
107
- export function registerKillSwitchServiceWorker(path = '/sw-killswitch.js') {
108
- debug('Trying to register killswitch ', path);
115
+ export function registerKillSwitchServiceWorker(path = '/sw-killswitch.js', env?: RuntimeEnv) {
116
+ // Use dynamic path based on asset prefix if available
117
+ let swPath = path;
118
+ if (env?.ASSET_PREFIX) {
119
+ swPath = `/${env.ASSET_PREFIX}/sw-killswitch.js`;
120
+ debug('Using dynamic killswitch path with asset prefix:', swPath);
121
+ }
122
+
123
+ debug('Trying to register killswitch ', swPath);
109
124
  navigator.serviceWorker
110
- .register(path)
125
+ .register(swPath)
111
126
  .then(() => {
112
127
  debug('SW Killswitch registered');
113
128
  })
@@ -34,7 +34,7 @@ export function serviceWorkerEpic(
34
34
  * and register as normal
35
35
  */
36
36
  case true:
37
- const sw$ = registerServiceWorker(env.VERSION);
37
+ const sw$ = registerServiceWorker(env.VERSION, '/sw.js', env);
38
38
  /**
39
39
  * Message stream coming out of the service worker
40
40
  */
@@ -52,7 +52,7 @@ export function serviceWorkerEpic(
52
52
  );
53
53
  return merge(msgHandlers$, updates);
54
54
  case false:
55
- return registerKillSwitchServiceWorker();
55
+ return registerKillSwitchServiceWorker('/sw-killswitch.js', env);
56
56
  default:
57
57
  return assertUnreachable();
58
58
  }
@@ -25,6 +25,7 @@ export type RuntimeEnv = {
25
25
  RELEASE_STAGE: 'local' | 'develop' | 'staging' | 'staging2' | 'staging3' | 'production';
26
26
  VERSION: string;
27
27
  DOMAIN: string;
28
+ ASSET_PREFIX?: string;
28
29
  };
29
30
 
30
31
  export type RuntimeState = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wearejh/m2-pwa-engine",
3
- "version": "0.33.1",
3
+ "version": "0.35.0",
4
4
  "description": "> TODO: description",
5
5
  "author": "Shane Osbourne <shane.osbourne8@gmail.com>",
6
6
  "homepage": "",
@@ -18,10 +18,10 @@
18
18
  ],
19
19
  "scripts": {},
20
20
  "dependencies": {
21
- "@wearejh/m2-pwa-vars": "^0.33.1",
22
- "@wearejh/swagger-rxjs": "^0.33.1",
21
+ "@wearejh/m2-pwa-vars": "^0.35.0",
22
+ "@wearejh/swagger-rxjs": "^0.35.0",
23
23
  "history": "^4.10.1",
24
24
  "loadcss": "^0.0.2"
25
25
  },
26
- "gitHead": "57494895c65f690d46cb4881888cc4cefa4bccbd"
26
+ "gitHead": "c28fc34b4cd0b85fafe885cfdcd364f4c576e11b"
27
27
  }