diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index b7a89789a..786d61c73 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -1,11 +1,11 @@ -/* eslint-disable */ -/* prettier-ignore */ -// @ts-nocheck -// Generated by unplugin-vue-components +// generated by unplugin-vue-components +// We suggest you to commit this file into source control // Read more: https://github.com/vuejs/core/pull/3399 +import '@vue/runtime-core' + export {} -declare module 'vue' { +declare module '@vue/runtime-core' { export interface GlobalComponents { AppActionHandler: typeof import('./components/app/ActionHandler.vue')['default'] AppAnnouncement: typeof import('./components/app/Announcement.vue')['default'] @@ -59,7 +59,6 @@ declare module 'vue' { CollectionsSaveRequest: typeof import('./components/collections/SaveRequest.vue')['default'] CollectionsTeamCollections: typeof import('./components/collections/TeamCollections.vue')['default'] CookiesAllModal: typeof import('./components/cookies/AllModal.vue')['default'] - CookiesCookieJarModal: typeof import('./components/cookies/CookieJarModal.vue')['default'] CookiesEditCookie: typeof import('./components/cookies/EditCookie.vue')['default'] Environments: typeof import('./components/environments/index.vue')['default'] EnvironmentsAdd: typeof import('./components/environments/Add.vue')['default'] @@ -219,4 +218,5 @@ declare module 'vue' { WorkspaceCurrent: typeof import('./components/workspace/Current.vue')['default'] WorkspaceSelector: typeof import('./components/workspace/Selector.vue')['default'] } + } diff --git a/packages/hoppscotch-selfhost-desktop/package.json b/packages/hoppscotch-selfhost-desktop/package.json index 6d7649d1f..f8e5223a1 100644 --- a/packages/hoppscotch-selfhost-desktop/package.json +++ b/packages/hoppscotch-selfhost-desktop/package.json @@ -10,6 +10,7 @@ "tauri": "tauri" }, "dependencies": { + "dioc": "workspace:^", "@hoppscotch/common": "workspace:^", "@platform/auth": "^0.1.106", "@tauri-apps/api": "^1.3.0", diff --git a/packages/hoppscotch-selfhost-desktop/src/main.ts b/packages/hoppscotch-selfhost-desktop/src/main.ts index 7d653f3b8..3c43b6a21 100644 --- a/packages/hoppscotch-selfhost-desktop/src/main.ts +++ b/packages/hoppscotch-selfhost-desktop/src/main.ts @@ -5,9 +5,9 @@ import { def as collectionsDef } from "./platform/collections/collections.platfo import { def as settingsDef } from "./platform/settings/settings.platform" import { def as historyDef } from "./platform/history/history.platform" import { def as tabStateDef } from "./platform/tabState/tabState.platform" -import { nativeInterceptor } from "./platform/interceptors/native" import { proxyInterceptor } from "@hoppscotch/common/platform/std/interceptors/proxy" import { ExtensionInspectorService } from "@hoppscotch/common/platform/std/inspections/extension.inspector" +import { NativeInterceptorService } from "./platform/interceptors/native" import { nextTick, ref, watch } from "vue" import { emit, listen } from "@tauri-apps/api/event" import { type } from "@tauri-apps/api/os" @@ -40,7 +40,7 @@ createHoppApp("#app", { interceptors: { default: "native", interceptors: [ - { type: "standalone", interceptor: nativeInterceptor }, + { type: "service", service: NativeInterceptorService }, { type: "standalone", interceptor: proxyInterceptor }, ], }, diff --git a/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native.ts b/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native.ts index 751cd49f9..716c57436 100644 --- a/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native.ts +++ b/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native.ts @@ -4,9 +4,11 @@ import { InterceptorError, RequestRunResult, } from "@hoppscotch/common/services/interceptor.service" +import { CookieJarService } from "@hoppscotch/common/services/cookie-jar.service" import axios, { AxiosRequestConfig, CancelToken } from "axios" import { cloneDeep } from "lodash-es" -import { Body, HttpVerb, ResponseType, getClient } from '@tauri-apps/api/http' +import { Body, HttpVerb, ResponseType, getClient } from "@tauri-apps/api/http" +import { Service } from "dioc" export const preProcessRequest = ( req: AxiosRequestConfig @@ -55,19 +57,19 @@ async function runRequest( if (processedReq.data instanceof FormData) { let body_data = {} for (const entry of processedReq.data.entries()) { - const [name, value] = entry; + const [name, value] = entry if (value instanceof File) { let file_data = await value.arrayBuffer() body_data[name] = { - file: new Uint8Array(file_data), - fileName: value.name + file: new Uint8Array(file_data), + fileName: value.name, } } } - body = Body.form(body_data); + body = Body.form(body_data) } const res = await client.request({ @@ -75,15 +77,15 @@ async function runRequest( url: processedReq.url ?? "", responseType: ResponseType.Binary, headers: processedReq.headers, - body: body - }); + body: body, + }) if (cancelled()) { client.drop() return E.left("cancellation") } - res.data = new Uint8Array(res.data as number[]).buffer; + res.data = new Uint8Array(res.data as number[]).buffer const timeEnd = Date.now() @@ -123,20 +125,45 @@ async function runRequest( } } -export const nativeInterceptor: Interceptor = { - interceptorID: "native", - name: () => "Native", - selectable: { type: "selectable" }, - runRequest(req) { +export class NativeInterceptorService extends Service implements Interceptor { + public static readonly ID = "NATIVE_INTERCEPTOR_SERVICE" + + public interceptorID = "native" // TODO: i18n this + + public name = () => "Native" + + public selectable = { type: "selectable" as const } + + public supportsCookies = true + + public cookieJarService = this.bind(CookieJarService) + + constructor() { + super() + } + + public runRequest(req: any) { const processedReq = preProcessRequest(req) + const relevantCookies = this.cookieJarService.getCookiesForURL( + new URL(processedReq.url!) + ) + + processedReq.headers["Cookie"] = relevantCookies + .map((cookie) => `${cookie.name!}=${cookie.value!}`) + .join(";") + let cancelled = false - const checkCancelled = () => { return cancelled } + const checkCancelled = () => { + return cancelled + } return { - cancel: () => { cancelled = true }, + cancel: () => { + cancelled = true + }, response: runRequest(processedReq, checkCancelled), } - }, + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 461fcb48e..a604c564e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -901,6 +901,9 @@ importers: buffer: specifier: ^6.0.3 version: 6.0.3 + dioc: + specifier: workspace:^ + version: link:../dioc environments.api: specifier: link:@platform/environments/environments.api version: link:@platform/environments/environments.api