Skip to content

Export parameter keys (@W-15676813@) #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@
"bundlesize": [
{
"path": "lib/**/*.js",
"maxSize": "46 kB"
"maxSize": "48 kB"
},
{
"path": "commerce-sdk-isomorphic-with-deps.tgz",
"maxSize": "400 kB"
"maxSize": "410 kB"
Comment on lines +180 to +184
Copy link
Contributor Author

@vmarta vmarta Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest sizes.. they're a slight increase from before.
iTerm2 2024-06-06 at 12 35 15

}
],
"proxy": "https://SHORTCODE.api.commercecloud.salesforce.com"
Expand Down
4 changes: 4 additions & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
'operationsPartial',
path.join(TEMPLATE_DIRECTORY, 'operations.ts.hbs')
);
registerPartial(
'paramKeysPartial',
path.join(TEMPLATE_DIRECTORY, 'paramKeys.ts.hbs')
);
}

function addTemplates(apis: ApiMetadata, outputBasePath: string): ApiMetadata {
Expand Down Expand Up @@ -136,7 +140,7 @@
deployment: RegExp,
rootPath: string
): Promise<void> {
console.warn('updateApis is deprecated. Use downloadLatestApis instead.');

Check warning on line 143 in scripts/utils.ts

View workflow job for this annotation

GitHub Actions / linux-tests (10)

Unexpected console statement

Check warning on line 143 in scripts/utils.ts

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Unexpected console statement

Check warning on line 143 in scripts/utils.ts

View workflow job for this annotation

GitHub Actions / linux-tests (14)

Unexpected console statement

Check warning on line 143 in scripts/utils.ts

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Unexpected console statement

Check warning on line 143 in scripts/utils.ts

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Unexpected console statement

Check warning on line 143 in scripts/utils.ts

View workflow job for this annotation

GitHub Actions / linux-tests (20)

Unexpected console statement

const matchedApis = await download.search(`"${name}"`, deployment);
if (!(matchedApis?.length > 0)) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ describe('Parameters', () => {
.reply(200, MOCK_RESPONSE)
);

it('has a list of parameter keys (and the required ones)', () => {
// eslint-disable-next-line
expect(ShopperSearch.paramKeys?.productSearch).toBeDefined();
// eslint-disable-next-line
expect(ShopperSearch.paramKeys?.productSearchRequired).toBeDefined();
});

it('can all be specified in config (no method parameters object)', async () => {
const searchClient = new ShopperSearch({
parameters: {
Expand Down
11 changes: 5 additions & 6 deletions templates/client.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ export type {{name.upperCamelCase}}Parameters = {{name.upperCamelCase}}PathParam
*
* <span style="font-size:.7em; display:block; text-align: right">
* API Version: {{metadata.version}}<br />
* Last Updated: {{metadata.updatedDate}}<br />
* Last Updated: {{metadata.updatedDate}}<br />
* </span>
{{#if (eq (lowercase metadata.categories.[CC Version Status].[0]) "beta")}}
* @beta
* {{#if (eq (lowercase metadata.categories.[CC Version Status].[0]) "beta")}}
* @beta
* {{/if}}
*

*
*/
export class {{name.upperCamelCase}}<ConfigParameters extends {{{name.upperCamelCase}}}Parameters & Record<string, unknown>> {
// baseUri is not required on ClientConfig, but we know that we provide one in the class constructor
Expand All @@ -101,6 +100,6 @@ export class {{name.upperCamelCase}}<ConfigParameters extends {{{name.upperCamel
this.clientConfig = new ClientConfig(cfg) as ClientConfig<ConfigParameters> & { baseUri: string };
}

{{> paramKeysPartial model}}
{{> operationsPartial model}}

}
3 changes: 2 additions & 1 deletion templates/operations.ts.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{#each encodes.endPoints}}
{{#each operations}}

/**
* {{{formatForTsDoc description}}}
*
Expand Down Expand Up @@ -193,7 +194,7 @@
method: "{{loud method}}",
headers,
{{#if (isRequestWithPayload request)}}body: this.clientConfig.transformRequest(options.body, headers){{/if}}
},
},
this.clientConfig,
rawResponse
)
Expand Down
24 changes: 24 additions & 0 deletions templates/paramKeys.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
static readonly paramKeys = {
{{#each encodes.endPoints}}
{{#each operations}}
{{{name}}}: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way to also include the endpoint names

{{#each ../parameters}}
'{{{name}}}',
{{/each}}
{{#each request.queryParameters}}
'{{{name}}}',
{{/each}}
],
{{{name}}}Required: [
{{#each ../parameters}}
'{{{name}}}',
{{/each}}
{{#each request.queryParameters}}
{{#if (is required "true")}}
'{{{name}}}',
{{/if}}
{{/each}}
],
{{/each}}
{{/each}}
} as const;
Loading