mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
fix export interface stuff
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
export class Origin {
|
||||
constructor(readonly protocol: string | null, readonly host: string) {}
|
||||
|
||||
withAuth(
|
||||
origin?:
|
||||
| {
|
||||
password: null | string
|
||||
username: string
|
||||
}
|
||||
| null
|
||||
| undefined,
|
||||
) {
|
||||
build({ basic, path, search }: BuildOptions) {
|
||||
// prettier-ignore
|
||||
const urlAuth = !!(origin) ? `${origin.username}${origin.password != null ?`:${origin.password}`:''}@` :
|
||||
const urlAuth = !!(basic) ? `${basic.username}${basic.password != null ?`:${basic.password}`:''}@` :
|
||||
'';
|
||||
const protocolSection = this.protocol != null ? `${this.protocol}://` : ""
|
||||
return `${protocolSection}${urlAuth}${this.host}`
|
||||
|
||||
const qpEntries = Object.entries(search)
|
||||
.map(
|
||||
([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`,
|
||||
)
|
||||
.join("&")
|
||||
|
||||
const qp = qpEntries.length ? `?${qpEntries}` : ""
|
||||
|
||||
return `${protocolSection}${urlAuth}${this.host}${path}${qp}`
|
||||
}
|
||||
}
|
||||
|
||||
type BuildOptions = {
|
||||
basic: { username: string; password: string | null } | null
|
||||
path: string
|
||||
search: Record<string, string>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user