diff --git a/.changeset/young-gifts-learn.md b/.changeset/young-gifts-learn.md new file mode 100644 index 0000000000..4847266237 --- /dev/null +++ b/.changeset/young-gifts-learn.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli-hydrogen': patch +--- + +Added an `--auth-bypass-token-duration` flag to the `deploy` command to allow for specified token duration between 1 to 12 hours. diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index c2d504cf56..1fc4f9ba6e 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -373,11 +373,24 @@ }, "auth-bypass-token": { "description": "Generate an authentication bypass token, which can be used to perform end-to-end tests against the deployment.", + "env": "AUTH_BYPASS_TOKEN", "name": "auth-bypass-token", "required": false, "allowNo": false, "type": "boolean" }, + "auth-bypass-token-duration": { + "dependsOn": [ + "auth-bypass-token" + ], + "description": "Specify the duration (in hours) up to 12 hours for the authentication bypass token. Defaults to `2`", + "env": "AUTH_BYPASS_TOKEN_DURATION", + "name": "auth-bypass-token-duration", + "required": false, + "hasDynamicHelp": false, + "multiple": false, + "type": "option" + }, "build-command": { "description": "Specify a build command to run before deploying. If not specified, `shopify hydrogen build` will be used.", "name": "build-command", diff --git a/packages/cli/src/commands/hydrogen/deploy.test.ts b/packages/cli/src/commands/hydrogen/deploy.test.ts index 6c1a97c0e7..720204edd8 100644 --- a/packages/cli/src/commands/hydrogen/deploy.test.ts +++ b/packages/cli/src/commands/hydrogen/deploy.test.ts @@ -220,6 +220,26 @@ describe('deploy', () => { }); }); + it('supports valid authBypassTokenDuration when generateAuthBypassToken is true', async () => { + const params = { + ...deployParams, + generateAuthBypassToken: true, + authBypassTokenDuration: '2', + }; + + await expect(runDeploy(params)).resolves.not.toThrow(); + + expect(vi.mocked(createDeploy)).toHaveBeenCalledWith( + expect.objectContaining({ + config: expect.objectContaining({ + generateAuthBypassToken: true, + authBypassTokenDuration: '2', + }), + }), + ); + expect(vi.mocked(renderSuccess)).toHaveBeenCalled(); + }); + it('calls createDeploy against a environment selected by env', async () => { vi.mocked(getOxygenDeploymentData).mockResolvedValue({ oxygenDeploymentToken: 'some-encoded-token', diff --git a/packages/cli/src/commands/hydrogen/deploy.ts b/packages/cli/src/commands/hydrogen/deploy.ts index c27d2f2cdb..055a328b4c 100644 --- a/packages/cli/src/commands/hydrogen/deploy.ts +++ b/packages/cli/src/commands/hydrogen/deploy.ts @@ -98,6 +98,14 @@ export default class Deploy extends Command { 'Generate an authentication bypass token, which can be used to perform end-to-end tests against the deployment.', required: false, default: false, + env: 'AUTH_BYPASS_TOKEN', + }), + 'auth-bypass-token-duration': Flags.string({ + description: + 'Specify the duration (in hours) up to 12 hours for the authentication bypass token. Defaults to `2`', + required: false, + env: 'AUTH_BYPASS_TOKEN_DURATION', + dependsOn: ['auth-bypass-token'], }), 'build-command': Flags.string({ description: @@ -178,6 +186,7 @@ export default class Deploy extends Command { } interface OxygenDeploymentOptions { + authBypassTokenDuration?: string; authBypassToken: boolean; buildCommand?: string; defaultEnvironment: boolean; @@ -226,6 +235,7 @@ export async function runDeploy( options: OxygenDeploymentOptions, ): Promise { const { + authBypassTokenDuration, authBypassToken: generateAuthBypassToken, buildCommand, defaultEnvironment, @@ -458,6 +468,7 @@ export async function runDeploy( userChosenEnvironmentTag || fallbackEnvironmentTag, generateAuthBypassToken, + authBypassTokenDuration, verificationMaxDuration: 180, metadata: { ...(metadataDescription ? {description: metadataDescription} : {}),