-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove calling payments server for subscriptions if using thir…
…d party api hosts
- Loading branch information
1 parent
970238a
commit bd898b5
Showing
24 changed files
with
233 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/services/src/Domain/UseCase/IsApplicationUsingThirdPartyHost.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Result } from '@standardnotes/domain-core' | ||
|
||
import { GetHost } from '../..' | ||
import { IsApplicationUsingThirdPartyHost } from './IsApplicationUsingThirdPartyHost' | ||
|
||
describe('IsApplicationUsingThirdPartyHost', () => { | ||
let getHostUseCase: GetHost | ||
|
||
const createUseCase = () => new IsApplicationUsingThirdPartyHost(getHostUseCase) | ||
|
||
beforeEach(() => { | ||
getHostUseCase = {} as jest.Mocked<GetHost> | ||
getHostUseCase.execute = jest.fn().mockReturnValue(Result.ok('https://api.standardnotes.com')) | ||
}) | ||
|
||
it('returns true if host is localhost', () => { | ||
getHostUseCase.execute = jest.fn().mockReturnValue(Result.ok('http://localhost:3000')) | ||
|
||
const useCase = createUseCase() | ||
const result = useCase.execute() | ||
|
||
expect(result.getValue()).toBe(true) | ||
}) | ||
|
||
it('returns false if host is api.standardnotes.com', () => { | ||
getHostUseCase.execute = jest.fn().mockReturnValue(Result.ok('https://api.standardnotes.com')) | ||
|
||
const useCase = createUseCase() | ||
const result = useCase.execute() | ||
|
||
expect(result.getValue()).toBe(false) | ||
}) | ||
|
||
it('returns false if host is sync.standardnotes.org', () => { | ||
getHostUseCase.execute = jest.fn().mockReturnValue(Result.ok('https://sync.standardnotes.org')) | ||
|
||
const useCase = createUseCase() | ||
const result = useCase.execute() | ||
|
||
expect(result.getValue()).toBe(false) | ||
}) | ||
|
||
it('returns false if host is files.standardnotes.com', () => { | ||
getHostUseCase.execute = jest.fn().mockReturnValue(Result.ok('https://files.standardnotes.com')) | ||
|
||
const useCase = createUseCase() | ||
const result = useCase.execute() | ||
|
||
expect(result.getValue()).toBe(false) | ||
}) | ||
|
||
it('returns true if host is not first party', () => { | ||
getHostUseCase.execute = jest.fn().mockReturnValue(Result.ok('https://example.com')) | ||
|
||
const useCase = createUseCase() | ||
const result = useCase.execute() | ||
|
||
expect(result.getValue()).toBe(true) | ||
}) | ||
}) |
31 changes: 31 additions & 0 deletions
31
packages/services/src/Domain/UseCase/IsApplicationUsingThirdPartyHost.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core' | ||
|
||
import { GetHost } from './GetHost' | ||
|
||
export class IsApplicationUsingThirdPartyHost implements SyncUseCaseInterface<boolean> { | ||
private readonly APPLICATION_DEFAULT_HOSTS = ['api.standardnotes.com', 'sync.standardnotes.org'] | ||
|
||
private readonly FILES_DEFAULT_HOSTS = ['files.standardnotes.com'] | ||
|
||
constructor(private getHostUseCase: GetHost) {} | ||
|
||
execute(): Result<boolean> { | ||
const result = this.getHostUseCase.execute() | ||
if (result.isFailed()) { | ||
return Result.fail(result.getError()) | ||
} | ||
|
||
const host = result.getValue() | ||
|
||
return Result.ok(!this.isUrlFirstParty(host)) | ||
} | ||
|
||
private isUrlFirstParty(url: string): boolean { | ||
try { | ||
const { host } = new URL(url) | ||
return this.APPLICATION_DEFAULT_HOSTS.includes(host) || this.FILES_DEFAULT_HOSTS.includes(host) | ||
} catch (error) { | ||
return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.