Skip to content

Commit 7ed3f34

Browse files
committed
Revert "Route serialization to support Shopper SEO URL mapping integration (#2300)"
This reverts commit 52be6f3.
1 parent 9df31eb commit 7ed3f34

File tree

36 files changed

+8849
-618
lines changed

36 files changed

+8849
-618
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2021, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
module.exports = {
9+
extends: [require.resolve('@salesforce/pwa-kit-dev/configs/eslint')]
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage
2+
dist
3+
generator-assets
4+
docs
5+
vendor
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
printWidth: 100
2+
singleQuote: true
3+
semi: false
4+
bracketSpacing: false
5+
tabWidth: 4
6+
arrowParens: 'always'
7+
trailingComma: 'none'
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
:loudspeaker: Hey there, Salesforce Commerce Cloud community!
2+
3+
We’re excited to hear your thoughts on your developer experience with PWA Kit and the Composable Storefront generally! Your feedback is incredibly valuable in helping us guide our roadmap and improve our offering.
4+
5+
:clipboard: Take our quick survey here: [Survey](https://forms.gle/bUZNxQ3QKUcrjhV18)
6+
7+
Feel free to share this survey link with your colleagues, partners, or anyone who has experience with PWA Kit. Your input will help us shape the future of our development tools.
8+
9+
Thank you for being a part of our community and for your continuous support! :raised_hands:
10+
11+
# Description
12+
13+
This is a sample PWA-Kit Application Extension. The purpose of this application extensions is to show how
14+
the Application Extensions API can be used to enhance your PWA-Kit base project.
15+
16+
# Folder Structure
17+
18+
This directory contains the PWA Kit Application Extension base files and structure. It includes the following files:
19+
```
20+
├── src
21+
│ ├── setup-server.ts
22+
│ └── setup-client.ts
23+
└── dev
24+
```
25+
26+
1. `src/setup-server.ts`: The server-side setup function for the extension.
27+
2. `src/setup-client.ts`: The client-side setup function for the extension.
28+
3. `dev/`: PWA Kit App TypeScript template project used for developing the generated PWA Kit App Extension.
29+
30+
# Peer Dependencies
31+
32+
PWA-Kit Application Extensions are NPM packages at their most simplest form, and as such you can define
33+
what peer dependencies are required when using it. Because this sample application extension provides
34+
UI via a new "Sample" page, it requires that the below dependencies are installed at a minimum.
35+
36+
Depending on what features your application extensions provides it's recommended you include any third-party
37+
packages as peer dependencies so that your base application doesn't end up having multiple versions of a
38+
given package.
39+
40+
"react": "^18.2.0",
41+
"react-dom": "^18.2.0"
42+
43+
# Configuration
44+
45+
This section is optional and will depend on your application extensions implementation. If you have features
46+
that are configurable, then list those configurations here so that the PWA-Kit project implementor can configure
47+
the extension as they like.
48+
49+
```
50+
{
51+
path: '/sample-page'
52+
}
53+
```
54+
55+
# Installation
56+
57+
```
58+
> npm install @salesforce/extension-starter<br/>
59+
> Downloading npm package... <br/>
60+
> Installing extension... <br/>
61+
> Finished. <br/>
62+
> Congratulations! The Sample extension was successfully installed! Please visit https://www.npmjs.com/package/@salesforce/extension-starter for more information on how to use this extension.
63+
```
64+
65+
# State Management
66+
67+
By default all extensions are enhanced with state management using the `withApplicationExtensionStore` higher-order component. Under the hood
68+
the state is provided using [Zustand](https://www.npmjs.com/package/zustand) as a global store for the entire PWA-Kit application.
69+
Each Application Extension inserts a "slice" into this global store following the
70+
[slicing pattern](https://github.com/pmndrs/zustand/blob/37e1e3f193a5e5dec6fbd0f07514aec59a187e01/docs/guides/slices-pattern.md).
71+
This allows you to have data separation from one extension to the other, but also allows you to access state and associated actions of other extensions when needed.
72+
73+
You can access the state of other extensions via the global store. Below is an example of why you might want to access state and actions from another extensions. In the following snippet we use the global store to access actions from the store locator. You can then use these actions as you please.
74+
75+
This is how you would do something like this.
76+
77+
```
78+
// /base-project/app/components/my-component.jsx
79+
import {useApplicationExtensionsStore} from '@salesforce/pwa-kit-extension-sdk/react'
80+
81+
export MyComponent = () => {
82+
// Zustand V5 requires stable selector outputs. E.g. Do NOT return a new reference in your selectors return value. This will
83+
// cause infinite re-renders.
84+
const defaultState = {}
85+
86+
// Grab the slice of the extension state for "extension-a"
87+
const {toggleMapsModal} = useApplicationExtensionsStore(
88+
(state) =>
89+
state.state['@salesforce/extension-store-locator'] || defaultState
90+
)
91+
92+
return (
93+
<div>
94+
<button onClick={() => toggleMapsModal()}/>
95+
</div>
96+
)
97+
}
98+
```
99+
100+
# Advanced Usage
101+
102+
As an application extension developer you are responsible for documenting how your extension works including basic usage, its configuration, and advanced customization via overrides. Use this section to explain how your extension can use overrides to accomplish this. Make should to include what files are overridable as well as their expected inputs and outputs.
103+
104+
## Overridable Files
105+
106+
```
107+
/src/path/to/overridable/files.ts
108+
```
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Extension Configuration 🧩
2+
3+
In most cases it's beneficial to make your application extension configurable. This will allow your extension to meet the needs of different PWA-Kit developers whom have varying requirements. This can be as simple as configuring the url path to the page your extension adds, to more complex scenarios like configuring layouts to those same pages.
4+
5+
6+
## `Sample` vs `Default` Configurations
7+
8+
This folder is home to two configuration files, `default.json` and `sample.json`. Both of which have their type define in the `src/types/config` file. But these files are used differently. Below is a summary of how each file is used.
9+
10+
### `default.json`
11+
12+
This configuration is used during the project generation as well as the extensions loading phase when running your PWA-Kit application.
13+
14+
During your PWA-Kit project generation, you can select which extensions are configured for your app. This ultimately leads to your applications configuration being setup with the extensions selected during the project questionnaire phase. For example, if you were to choose to use `@salesforce/extension-chakra-storefront` in your PWA-Kit app, then you might see something along the lines of this in your app config, where `<user_defined_configuration>` is initially set to the contents of the `default.json` file:
15+
16+
```
17+
app: {
18+
extensions: [
19+
['@salesforce/extension-chakra-storefront', <user_defined_configuration>]
20+
]
21+
}
22+
```
23+
24+
Additionally, during the PWA-Kit application execution the default configuration is merged with the user define configuration to ensure that all configuration key have a value. This means that you do not have to worry about scattering default values in your extensions code, whether it's in a React component or the setup files.
25+
26+
It's worth noting that if your configuration file is expected to have values supplied by the PWA-Kit application developer, you can use placeholder values that will prompt the developer to replace them with real world values. Below is an example default config file with a placeholder:
27+
28+
```
29+
{
30+
"enabled": true,
31+
"activeDataEnabled": false,
32+
"categoryNav": {
33+
"defaultNavSsrDepth": 1,
34+
"defaultRootCategory": "root"
35+
},
36+
"commerceAPI": {
37+
"proxyPath": "/mobify/proxy/api",
38+
"parameters": {
39+
"clientId": "<CLIENT_ID>",
40+
"organizationId": "<ORGANIZATION_ID>",
41+
"shortCode": "<SHORT_CODE>",
42+
"siteId": "<SITE_ID>"
43+
}
44+
},
45+
...
46+
}
47+
```
48+
49+
### `sample.json`
50+
51+
This configuration is similar in many ways to the one above, with the primary difference being that you cannot use placeholder values in it. The configuration is expected to have all its properties defined with valid values.
52+
53+
This configuration file is used internally by the PWA-Kit create-app application whenever a project is generated using a preset. This allows us to create E2E tests on our CI environment where we know that a project generated can be run without further modification to the configuration file.
54+
55+
We also recommend that you reference this configuration file from your extensions root README so that developers know what a valid configuration looks like.
56+
57+
## How to use your extension configuration?
58+
59+
Your extensions configuration can be used in different ways depending on the context in which you want to use it. Your configuration will primarily be used in two places, your React components and your extension setup files.
60+
61+
### Setup Files
62+
63+
The exported extension classes in `setup-app.ts` and `setup-server.ts` are extended from the `ApplicationExtension` class. This class provide a method called `getConfig` which returns the configuration your extension was instantiated with. you can use this method to grab the configuration and use it however you want.
64+
65+
Please refer to the `src/setup-app.ts` file to see a sample of how `getConfig` is being used in the `getRoutes` implementation.
66+
67+
### React Components
68+
69+
Every application extension generated will have a convenience hook scaffolded for you located at `src/hooks/use-extension-config`. You can use this hook in any pages, components, or other hooks that you add to your extension. Below is an example component that uses this hook:
70+
71+
```
72+
// src/components/sample-component.tsx
73+
import React from 'react'
74+
import {useExtensionConfig} from '../hooks/use-extension-config'
75+
76+
export const Sample = (): JSX.Element => {
77+
const {path} = useExtensionConfig()
78+
79+
return (
80+
<span>{path}<span/>
81+
)
82+
}
83+
84+
export default Sample
85+
```
86+
87+
### Other Contexts
88+
89+
If you plan on using the extension configuration in other contexts such as utility files, we recommend that you use dependency injection whenever possible. Passing in the configuration to these utilities will not only be a simple solution, but it will also make testing these utilities easier if you choose to do that.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"enabled": true,
3+
"path": "/sample-page",
4+
"commerceAPI": {
5+
"proxyPath": "/mobify/proxy/api",
6+
"parameters": {
7+
"clientId": "c9c45bfd-0ed3-4aa2-9971-40f88962b836",
8+
"organizationId": "f_ecom_zzrf_001",
9+
"shortCode": "8o7m175y",
10+
"siteId": "RefArchGlobal"
11+
}
12+
},
13+
"commerceAPIAuth": {
14+
"propertyNameInLocals": "commerceAPIAuth"
15+
}
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"id": "@salesforce/extension-url-mapping"
3+
}

0 commit comments

Comments
 (0)