Skip to content

Commit 893df14

Browse files
author
Mohammod Al Amin Ashik
committed
apply namechanges
1 parent f9313f0 commit 893df14

File tree

4 files changed

+122
-56
lines changed

4 files changed

+122
-56
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@sitecore-marketplace-sdk/core': patch
3+
---
4+
5+
Deprecate `resources` and `touchpoints` properties in favor of `resourceAccess` and `extensionsPoints`
6+
7+
**BREAKING CHANGE (Deprecation):**
8+
9+
- The `resources` property in `ApplicationContext` and `ApplicationRuntimeContext` interfaces is now deprecated. Use `resourceAccess` instead.
10+
- The `touchpoints` property in `ApplicationContext` and `ApplicationRuntimeContext` interfaces is now deprecated. Use `extensionsPoints` instead.
11+
12+
**What changed:**
13+
14+
- Added deprecation JSDoc comments to `resources` and `touchpoints` properties in both interfaces
15+
- Added new `resourceAccess` and `extensionsPoints` properties to `ApplicationContext` and `ApplicationRuntimeContext` interfaces
16+
- Maintained backward compatibility - deprecated properties still work but will show deprecation warnings in IDEs
17+
18+
**Migration guide:**
19+
20+
Replace usage of deprecated properties with their new equivalents:
21+
22+
- `applicationContext.resources``applicationContext.resourceAccess`
23+
- `applicationContext.touchpoints``applicationContext.extensionsPoints`
24+
- `runtimeContext.resources``runtimeContext.resourceAccess`
25+
- `runtimeContext.touchpoints``runtimeContext.extensionsPoints`
26+
27+
The deprecated properties will be removed in a future major version.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@sitecore-marketplace-sdk/client': patch
3+
---
4+
5+
Update README documentation to use new `resourceAccess` property name
6+
7+
**What changed:**
8+
9+
- Updated README.md examples to use `resourceAccess` instead of the deprecated `resources` property
10+
- Updated descriptive text to refer to "resource access" instead of "resources" for consistency with new property naming
11+
- Improved code examples and documentation to reflect the current recommended API usage
12+
- Enhanced initialization examples with comprehensive React hooks and error handling patterns
13+
14+
**Migration guide:**
15+
16+
When following the README examples, use:
17+
18+
- `applicationContext.resourceAccess` instead of `applicationContext.resources` in your code
19+
- The examples now demonstrate best practices for SDK initialization and usage
20+
21+
This change ensures developers following the documentation will use the recommended property names from the start.

packages/client/README.md

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
The `client` package provides secure, bidirectional communication between a Marketplace application (the client) and Sitecore (the host). Sitecore loads the Marketplace app inside a sandboxed [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe). The iframe and its parent window securely communicate using the web browser's [PostMessage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage).
44

55
This package lets you:
6+
67
- Make queries. Queries support one-off data requests and subscriptions for live updates. The `client` package lets you query the host's state and environment, and the [context](#query-the-application-context) of your Marketplace app.
78
- Make mutations. Mutations trigger state changes or HTTP requests in Sitecore.
8-
- Interact with Sitecore APIs to perform actions on behalf of the resources it was granted access to during installation.
9+
- Interact with Sitecore APIs to perform actions on behalf of the resource access it was granted during installation.
910
> [!TIP]
1011
> Inspired by GraphQL and React Query, the query/mutation API manages internal state, loading status, and error handling.
1112
1213
The `client` package is required for all Marketplace apps.
1314

1415
## Prerequisites
16+
1517
- Node.js 16 or later. Check your installed version by using the `node --version` command.
1618
- npm 10 or later. Check your installed version by using the `npm --version` command.
1719
- Access to the Sitecore Cloud Portal.
@@ -31,8 +33,8 @@ Before you use queries or mutations, you must initialize the Client SDK.
3133
```typescript
3234
// utils/hooks/useMarketplaceClient.ts
3335

34-
import { ClientSDK } from "@sitecore-marketplace-sdk/client";
35-
import { useEffect, useState, useCallback, useMemo, useRef } from "react";
36+
import { ClientSDK } from '@sitecore-marketplace-sdk/client';
37+
import { useEffect, useState, useCallback, useMemo, useRef } from 'react';
3638

3739
export interface MarketplaceClientState {
3840
client: ClientSDK | null;
@@ -84,9 +86,7 @@ async function getMarketplaceClient() {
8486

8587
export function useMarketplaceClient(options: UseMarketplaceClientOptions = {}) {
8688
// Memoize the options to prevent unnecessary re-renders
87-
const opts = useMemo(() => ({ ...DEFAULT_OPTIONS, ...options }), [
88-
options,
89-
]);
89+
const opts = useMemo(() => ({ ...DEFAULT_OPTIONS, ...options }), [options]);
9090

9191
const [state, setState] = useState<MarketplaceClientState>({
9292
client: null,
@@ -98,44 +98,48 @@ export function useMarketplaceClient(options: UseMarketplaceClientOptions = {})
9898
// Use ref to track if we're currently initializing to prevent race conditions
9999
const isInitializingRef = useRef(false);
100100

101-
const initializeClient = useCallback(async (attempt = 1): Promise<void> => {
102-
// Use functional state update to check current state without dependencies
103-
let shouldProceed = false;
104-
setState(prev => {
105-
if (prev.isLoading || prev.isInitialized || isInitializingRef.current) {
106-
return prev;
107-
}
108-
shouldProceed = true;
109-
isInitializingRef.current = true;
110-
return { ...prev, isLoading: true, error: null };
111-
});
101+
const initializeClient = useCallback(
102+
async (attempt = 1): Promise<void> => {
103+
// Use functional state update to check current state without dependencies
104+
let shouldProceed = false;
105+
setState((prev) => {
106+
if (prev.isLoading || prev.isInitialized || isInitializingRef.current) {
107+
return prev;
108+
}
109+
shouldProceed = true;
110+
isInitializingRef.current = true;
111+
return { ...prev, isLoading: true, error: null };
112+
});
112113

113-
if (!shouldProceed) return;
114+
if (!shouldProceed) return;
114115

115-
try {
116-
const client = await getMarketplaceClient();
117-
setState({
118-
client,
119-
error: null,
120-
isLoading: false,
121-
isInitialized: true,
122-
});
123-
} catch (error) {
124-
if (attempt < opts.retryAttempts) {
125-
await new Promise(resolve => setTimeout(resolve, opts.retryDelay));
126-
return initializeClient(attempt + 1);
116+
try {
117+
const client = await getMarketplaceClient();
118+
setState({
119+
client,
120+
error: null,
121+
isLoading: false,
122+
isInitialized: true,
123+
});
124+
} catch (error) {
125+
if (attempt < opts.retryAttempts) {
126+
await new Promise((resolve) => setTimeout(resolve, opts.retryDelay));
127+
return initializeClient(attempt + 1);
128+
}
129+
130+
setState({
131+
client: null,
132+
error:
133+
error instanceof Error ? error : new Error('Failed to initialize MarketplaceClient'),
134+
isLoading: false,
135+
isInitialized: false,
136+
});
137+
} finally {
138+
isInitializingRef.current = false;
127139
}
128-
129-
setState({
130-
client: null,
131-
error: error instanceof Error ? error : new Error('Failed to initialize MarketplaceClient'),
132-
isLoading: false,
133-
isInitialized: false,
134-
});
135-
} finally {
136-
isInitializingRef.current = false;
137-
}
138-
}, [opts.retryAttempts, opts.retryDelay]); // Removed state dependencies
140+
},
141+
[opts.retryAttempts, opts.retryDelay],
142+
); // Removed state dependencies
139143

140144
useEffect(() => {
141145
if (opts.autoInit) {
@@ -154,14 +158,18 @@ export function useMarketplaceClient(options: UseMarketplaceClientOptions = {})
154158
}, [opts.autoInit, initializeClient]);
155159

156160
// Memoize the return value to prevent object recreation on every render
157-
return useMemo(() => ({
158-
...state,
159-
initialize: initializeClient,
160-
}), [state, initializeClient]);
161+
return useMemo(
162+
() => ({
163+
...state,
164+
initialize: initializeClient,
165+
}),
166+
[state, initializeClient],
167+
);
161168
}
162169
```
163170

164171
2. Initialize the SDK:
172+
165173
```typescript
166174
// src/pages/index.tsx
167175

@@ -201,7 +209,6 @@ function App() {
201209
export default App;
202210
```
203211

204-
205212
## Usage
206213

207214
### Make a query
@@ -211,17 +218,18 @@ Use the `query` method to make one-off data requests and live subscriptions. Pas
211218
For example, pass `'application.context'` to retrieve details about the Marketplace app and the Sitecore host, including, for example, your Context IDs:
212219

213220
```typescript
214-
client.query("application.context")
221+
client
222+
.query('application.context')
215223
.then((res) => {
216-
console.log("Success retrieving application.context:", res.data);
224+
console.log('Success retrieving application.context:', res.data);
217225
setAppContext(res.data);
218226
})
219227
.catch((error) => {
220-
console.error("Error retrieving application.context:", error);
221-
});
228+
console.error('Error retrieving application.context:', error);
229+
});
222230
```
223231

224-
The application context provides information about your Marketplace app, such as its ID, URL, name, type, icon URL, installation ID, and associated resources:
232+
The application context provides information about your Marketplace app, such as its ID, URL, name, type, icon URL, installation ID, and associated resource access:
225233

226234
```javascript
227235
{
@@ -231,13 +239,13 @@ The application context provides information about your Marketplace app, such as
231239
url: 'https://my-app.com/app',
232240
iconUrl: 'https://my-app.com/assets/icon.png',
233241
installationId: 'abc1234567890',
234-
resources: [
242+
resourceAccess: [
235243
{
236244
resourceId: 'resource-1',
237245
tenantId: 'tenant-1',
238246
tenantName: 'Example Tenant',
239247
context: {
240-
live: '1234567890',
248+
live: '1234567890',
241249
preview: '0987654321'
242250
}
243251
}
@@ -249,13 +257,13 @@ For an overview of all the possible values, refer to the [`QueryMap` interface](
249257

250258
### Make a mutation
251259

252-
Use the `mutate` method to trigger changes in Sitecore (the host). Pass a value to the method depending on the change you want to make.
260+
Use the `mutate` method to trigger changes in Sitecore (the host). Pass a value to the method depending on the change you want to make.
253261

254262
For example, pass `'pages.reloadCanvas'` to reload the XM Cloud page builder canvas:
255263

256264
```typescript
257265
const reloadCanvas = () => {
258-
client?.mutate("pages.reloadCanvas");
266+
client?.mutate('pages.reloadCanvas');
259267
};
260268
```
261269

@@ -268,8 +276,10 @@ For an overview of all the possible values, refer to the [`MutationMap` interfac
268276

269277
For more information, refer to the reference documentation in the `/docs` folder, and the official [Marketplace developer documentation](https://doc.sitecore.com/mp/en/developers/marketplace/introduction-to-sitecore-marketplace.html) and [Marketplace SDK documentation](https://doc.sitecore.com/mp/en/developers/sdk/latest/sitecore-marketplace-sdk/sitecore-marketplace-sdk-for-javascript.html).
270278

271-
## License
279+
## License
280+
272281
This package is part of the Sitecore Marketplace SDK, licensed under the Apache 2.0 License. Refer to the [LICENSE](../../LICENSE.md) file in the repository root.
273282

274283
## Status
284+
275285
The `client` package is actively maintained as part of the Sitecore Marketplace SDK.

packages/core/src/shared-types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ export interface ApplicationContext {
146146
iconUrl?: string;
147147
state?: string;
148148
installationId?: string;
149+
/** @deprecated Use resourceAccess instead */
149150
resources?: ApplicationResourceContext[];
151+
/** @deprecated Use extensionsPoints instead */
150152
touchpoints?: ApplicationTouchpointContext[];
153+
resourceAccess?: ApplicationResourceContext[];
154+
extensionsPoints?: ApplicationTouchpointContext[];
151155
[key: string]: any;
152156
}
153157

@@ -165,8 +169,12 @@ export interface ApplicationRuntimeContext {
165169
state: string;
166170
[key: string]: any;
167171
};
172+
/** @deprecated Use resourceAccess instead */
168173
resources: ApplicationResourceContext[];
174+
/** @deprecated Use extensionsPoints instead */
169175
touchpoints: ApplicationTouchpointContext[];
176+
resourceAccess?: ApplicationResourceContext[];
177+
extensionsPoints?: ApplicationTouchpointContext[];
170178
[key: string]: any;
171179
}
172180

0 commit comments

Comments
 (0)