Skip to content

Commit

Permalink
[Nextjs] [Context] Context's getSDK is non-enumerable (#1662)
Browse files Browse the repository at this point in the history
* [Nextjs] [Context] Context's getSDK is non-enumerable

* Updated CHANGELOG
  • Loading branch information
illiakovalenko committed Nov 13, 2023
1 parent db032a6 commit 2d79c08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Our versioning strategy is as follows:

* `[templates/react]` `[templates/angular]` `[templates/vue]` `[templates/node-headless-ssr-proxy]` `[templates/node-headless-ssr-experience-edge]` ([#1647](https://github.com/Sitecore/jss/pull/1647)) Switch from using JSS_APP_NAME to SITE_NAME - environment and config variables in React, Vue, Angular templates as well as ssr node proxy apps templates have been renamed.
* `[sitecore-jss]` Support for both 'published' and 'staged' revisions of FEAAS stylesheets/themes ([#1644](https://github.com/Sitecore/jss/pull/1644))
* `[templates/nextjs]` `[sitecore-jss-nextjs]` `[sitecore-jss]` ([#1640](https://github.com/Sitecore/jss/pull/1640)) Sitecore Edge Platform and Context support:
* `[templates/nextjs]` `[sitecore-jss-nextjs]` `[sitecore-jss]` ([#1640](https://github.com/Sitecore/jss/pull/1640)) ([#1662](https://github.com/Sitecore/jss/pull/1662))([#1661](https://github.com/Sitecore/jss/pull/1661)) Sitecore Edge Platform and Context support:
* Introducing the _clientFactory_ property. This property can be utilized by GraphQL-based services, the previously used _endpoint_ and _apiKey_ properties are deprecated. The _clientFactory_ serves as the central hub for executing GraphQL requests within the application.
* New SITECORE_EDGE_CONTEXT_ID environment variable has been added.
* The JSS_APP_NAME environment variable has been updated and is now referred to as SITE_NAME.
Expand Down
12 changes: 12 additions & 0 deletions packages/sitecore-jss-nextjs/src/context/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ describe('Context', () => {
expect(context.sitecoreEdgeContextId).to.equal(props.sitecoreEdgeContextId);
expect(context.siteName).to.equal(props.siteName);
});

it('should provide all the properties when context instance is merged as an object', () => {
const context = new Context<typeof sdks>(props);

const merged = { ...context };

expect(merged.sitecoreEdgeUrl).to.equal(props.sitecoreEdgeUrl);
expect(merged.sitecoreEdgeContextId).to.equal(props.sitecoreEdgeContextId);
expect(merged.siteName).to.equal(props.siteName);
expect(merged.getSDK).to.equal(context.getSDK);
expect(merged.isInitialized).to.equal(context.isInitialized);
});
});

describe('init', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/sitecore-jss-nextjs/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ export class Context<SDKModules extends SDKModulesType> {
* @param {string} name SDK name
* @returns initialized SDK
*/
public getSDK<T extends keyof SDKModules>(name: T): Promise<SDKModules[T]['sdk']> | undefined {
public getSDK = <T extends keyof SDKModules>(
name: T
): Promise<SDKModules[T]['sdk']> | undefined => {
return this.sdkPromises[name];
}
};

/**
* Initializes the Software Development Kit (SDK)
Expand Down

0 comments on commit 2d79c08

Please sign in to comment.