-
Notifications
You must be signed in to change notification settings - Fork 218
create identity client interface #6634
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
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| let _identityClient: IdentityBaseClient | undefined | ||
|
|
||
| export function getIdentityClient() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wanted this to live in IdentityBaseClient under a getInstance method like we do for our other clients, but combining that with an abstract class leads to circular dependencies. I see we use this singleton pattern in other modules, so looking for feedback on this especially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is OK to have this here 👌
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success3364 tests passing in 1378 suites. Report generated by 🧪jest coverage report action from ec62db8 |
MitchDickinson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick drive by interface feedback 😅
packages/cli-kit/src/private/node/clients/identity/identity-base-client.ts
Outdated
Show resolved
Hide resolved
packages/cli-kit/src/private/node/clients/identity/identity-base-client.ts
Outdated
Show resolved
Hide resolved
packages/cli-kit/src/private/node/clients/identity/identity-base-client.ts
Outdated
Show resolved
Hide resolved
| if (!_identityClient) { | ||
| const isLocal = serviceEnvironment() === Environment.Local | ||
| const identityServiceRunning = isRunning2024('identity') | ||
| const client = isLocal && !identityServiceRunning ? new IdentityMockClient() : new IdentityServiceClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just return client and get rid of the mutable variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just lends itself to the singleton pattern better. Saves re-instantiating on every call, but the clients are deterministic so we could do this too. Follows existing patterns, I don't feel too strongly about this. LMK what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion is that the tradeoff isn't worth it -- it introduces sequencing where the variable can be undefined, which has to be accounted for in the type as well as in all processes it's called from. The perf gains on compute will be near-zero, and may never actually become concrete unless you're calling identity multiple times in the same command lifecycle but different execution context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you ever access the undefined variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mutable variable is private, only the getIdentityClient is public and will return a valid client always, regardless of using a singleton or instantiating a new client every time.
I think is ok, to have a singleton here. Is safe and I think there is any con about it.
If eventually we decide that this client will have logic to prevent multiple refresh tokens operations from running at the same time, then we need to ensure everyone is using the same instance. (is an example, this is controlled somewhere else now)
6ec2d7e to
bd49456
Compare
bd49456 to
ec62db8
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationspackages/cli-kit/dist/private/node/clients/identity/identity-client.d.tsimport { ApplicationToken, IdentityToken } from '../../session/schema.js';
import { ExchangeScopes } from '../../session/exchange.js';
import { API } from '../../api.js';
export declare abstract class IdentityClient {
abstract requestAccessToken(scopes: string[]): Promise<IdentityToken>;
abstract exchangeAccessForApplicationTokens(identityToken: IdentityToken, scopes: ExchangeScopes, store?: string): Promise<{
[x: string]: ApplicationToken;
}>;
abstract refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken>;
clientId(): string;
applicationId(_api: API): string;
}
packages/cli-kit/dist/private/node/clients/identity/identity-mock-client.d.tsimport { IdentityClient } from './identity-client.js';
import { ApplicationToken, IdentityToken } from '../../session/schema.js';
import { ExchangeScopes } from '../../session/exchange.js';
export declare class IdentityMockClient extends IdentityClient {
requestAccessToken(_scopes: string[]): Promise<IdentityToken>;
exchangeAccessForApplicationTokens(_identityToken: IdentityToken, _scopes: ExchangeScopes, _store?: string): Promise<{
[x: string]: ApplicationToken;
}>;
refreshAccessToken(_currentToken: IdentityToken): Promise<IdentityToken>;
}
packages/cli-kit/dist/private/node/clients/identity/identity-service-client.d.tsimport { IdentityClient } from './identity-client.js';
import { ApplicationToken, IdentityToken } from '../../session/schema.js';
import { ExchangeScopes } from '../../session/exchange.js';
export declare class IdentityServiceClient extends IdentityClient {
requestAccessToken(_scopes: string[]): Promise<IdentityToken>;
exchangeAccessForApplicationTokens(_identityToken: IdentityToken, _scopes: ExchangeScopes, _store?: string): Promise<{
[x: string]: ApplicationToken;
}>;
refreshAccessToken(_currentToken: IdentityToken): Promise<IdentityToken>;
}
packages/cli-kit/dist/private/node/clients/identity/instance.d.tsimport { IdentityClient } from './identity-client.js';
export declare function getIdentityClient(): IdentityClient;
Existing type declarationspackages/cli-kit/dist/public/node/vendor/dev_server/dev-server-2024.d.ts@@ -4,6 +4,7 @@ export declare function createServer(projectName: string): {
url: (options?: HostOptions) => string;
};
declare function assertRunning2024(projectName: string): void;
+export declare function isRunning2024(projectName: string): boolean;
declare let assertRunningOverride: typeof assertRunning2024 | undefined;
export declare function setAssertRunning(override: typeof assertRunningOverride): void;
export {};
\ No newline at end of file
|
|
We detected some changes at Caution DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release. |

WHY are these changes introduced?
Part of: https://github.com/shop/issues-develop/issues/21594
WHAT is this pull request doing?
How to test your changes?