mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-19 21:57:13 -04:00
typescript improvements (#9067)
* export types and sort order * clean up auth types * fix tests * fix type check
This commit is contained in:
@@ -7,7 +7,6 @@ import * as models from '../../models';
|
||||
import type { Cookie } from '../../models/cookie-jar';
|
||||
import type { Request } from '../../models/request';
|
||||
import type { Response } from '../../models/response';
|
||||
import { AUTH_BASIC } from '../constants';
|
||||
import { exportHar, exportHarResponse, exportHarWithRequest } from '../har';
|
||||
import { getRenderedRequestAndContext } from '../render';
|
||||
|
||||
@@ -439,7 +438,7 @@ describe('export', () => {
|
||||
},
|
||||
url: 'http://google.com',
|
||||
authentication: {
|
||||
type: AUTH_BASIC,
|
||||
type: 'basic',
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
},
|
||||
|
||||
@@ -9,13 +9,6 @@ import {
|
||||
METHOD_PATCH,
|
||||
METHOD_POST,
|
||||
METHOD_PUT,
|
||||
SORT_CREATED_ASC,
|
||||
SORT_CREATED_DESC,
|
||||
SORT_HTTP_METHOD,
|
||||
SORT_NAME_ASC,
|
||||
SORT_NAME_DESC,
|
||||
SORT_TYPE_ASC,
|
||||
SORT_TYPE_DESC,
|
||||
} from '../constants';
|
||||
import {
|
||||
ascendingFirstIndexStringSort,
|
||||
@@ -44,7 +37,7 @@ describe('Sorting methods', () => {
|
||||
]);
|
||||
});
|
||||
it('sorts by name', () => {
|
||||
const ascendingNameSort = sortMethodMap[SORT_NAME_ASC];
|
||||
const ascendingNameSort = sortMethodMap['name-asc'];
|
||||
expect(
|
||||
ascendingNameSort(
|
||||
{
|
||||
@@ -155,7 +148,7 @@ describe('Sorting methods', () => {
|
||||
},
|
||||
),
|
||||
).toBe(0);
|
||||
const descendingNameSort = sortMethodMap[SORT_NAME_DESC];
|
||||
const descendingNameSort = sortMethodMap['name-desc'];
|
||||
expect(
|
||||
descendingNameSort(
|
||||
{
|
||||
@@ -269,7 +262,7 @@ describe('Sorting methods', () => {
|
||||
});
|
||||
|
||||
it('sorts by timestamp', () => {
|
||||
const createdFirstSort = sortMethodMap[SORT_CREATED_ASC];
|
||||
const createdFirstSort = sortMethodMap['created-asc'];
|
||||
expect(
|
||||
createdFirstSort(
|
||||
{
|
||||
@@ -320,7 +313,7 @@ describe('Sorting methods', () => {
|
||||
},
|
||||
),
|
||||
).toBe(0);
|
||||
const createdLastSort = sortMethodMap[SORT_CREATED_DESC];
|
||||
const createdLastSort = sortMethodMap['created-desc'];
|
||||
expect(
|
||||
createdLastSort(
|
||||
{
|
||||
@@ -374,7 +367,7 @@ describe('Sorting methods', () => {
|
||||
});
|
||||
|
||||
it('sorts by type', () => {
|
||||
const ascendingTypeSort = sortMethodMap[SORT_TYPE_ASC];
|
||||
const ascendingTypeSort = sortMethodMap['type-asc'];
|
||||
expect(
|
||||
ascendingTypeSort(
|
||||
{
|
||||
@@ -519,7 +512,7 @@ describe('Sorting methods', () => {
|
||||
},
|
||||
),
|
||||
).toBe(1);
|
||||
const descendingTypeSort = sortMethodMap[SORT_TYPE_DESC];
|
||||
const descendingTypeSort = sortMethodMap['type-desc'];
|
||||
expect(
|
||||
descendingTypeSort(
|
||||
{
|
||||
@@ -667,7 +660,7 @@ describe('Sorting methods', () => {
|
||||
});
|
||||
|
||||
it('sorts by HTTP method', () => {
|
||||
const httpMethodSort = sortMethodMap[SORT_HTTP_METHOD];
|
||||
const httpMethodSort = sortMethodMap['http-method'];
|
||||
expect(
|
||||
httpMethodSort(
|
||||
{
|
||||
|
||||
@@ -282,19 +282,20 @@ export const contentTypesMap: Record<string, string[]> = {
|
||||
[CONTENT_TYPE_YAML]: ['YAML', 'YAML'],
|
||||
};
|
||||
|
||||
// Auth Types
|
||||
export const AUTH_NONE = 'none';
|
||||
export const AUTH_API_KEY = 'apikey';
|
||||
export const AUTH_OAUTH_2 = 'oauth2';
|
||||
export const AUTH_OAUTH_1 = 'oauth1';
|
||||
export const AUTH_BASIC = 'basic';
|
||||
export const AUTH_DIGEST = 'digest';
|
||||
export const AUTH_BEARER = 'bearer';
|
||||
export const AUTH_NTLM = 'ntlm';
|
||||
export const AUTH_HAWK = 'hawk';
|
||||
export const AUTH_AWS_IAM = 'iam';
|
||||
export const AUTH_NETRC = 'netrc';
|
||||
export const AUTH_ASAP = 'asap';
|
||||
export type AuthTypes =
|
||||
| 'none'
|
||||
| 'apikey'
|
||||
| 'oauth2'
|
||||
| 'oauth1'
|
||||
| 'basic'
|
||||
| 'digest'
|
||||
| 'bearer'
|
||||
| 'ntlm'
|
||||
| 'hawk'
|
||||
| 'iam'
|
||||
| 'netrc'
|
||||
| 'asap';
|
||||
|
||||
export const HAWK_ALGORITHM_SHA256 = 'sha256';
|
||||
export const HAWK_ALGORITHM_SHA1 = 'sha1';
|
||||
|
||||
@@ -302,21 +303,6 @@ export const HAWK_ALGORITHM_SHA1 = 'sha1';
|
||||
export const JSON_ORDER_PREFIX = '&';
|
||||
export const JSON_ORDER_SEPARATOR = '~|';
|
||||
|
||||
const authTypesMap: Record<string, string[]> = {
|
||||
[AUTH_API_KEY]: ['API Key', 'API Key Auth'],
|
||||
[AUTH_BASIC]: ['Basic', 'Basic Auth'],
|
||||
[AUTH_DIGEST]: ['Digest', 'Digest Auth'],
|
||||
[AUTH_NTLM]: ['NTLM', 'Microsoft NTLM'],
|
||||
[AUTH_BEARER]: ['Bearer', 'Bearer Token'],
|
||||
[AUTH_OAUTH_1]: ['OAuth 1', 'OAuth 1.0'],
|
||||
[AUTH_OAUTH_2]: ['OAuth 2', 'OAuth 2.0'],
|
||||
[AUTH_HAWK]: ['Hawk', 'Hawk'],
|
||||
[AUTH_AWS_IAM]: ['AWS', 'AWS IAM v4'],
|
||||
[AUTH_ASAP]: ['ASAP', 'Atlassian ASAP'],
|
||||
[AUTH_NETRC]: ['Netrc', 'Netrc File'],
|
||||
[AUTH_NONE]: ['None', 'No Auth'],
|
||||
};
|
||||
|
||||
// Sort Orders
|
||||
export type SortOrder =
|
||||
| 'name-asc'
|
||||
@@ -327,35 +313,26 @@ export type SortOrder =
|
||||
| 'type-desc'
|
||||
| 'type-asc'
|
||||
| 'type-manual';
|
||||
export const SORT_NAME_ASC = 'name-asc';
|
||||
export const SORT_NAME_DESC = 'name-desc';
|
||||
export const SORT_CREATED_ASC = 'created-asc';
|
||||
export const SORT_CREATED_DESC = 'created-desc';
|
||||
export const SORT_MODIFIED_ASC = 'modified-asc';
|
||||
export const SORT_MODIFIED_DESC = 'modified-desc';
|
||||
export const SORT_HTTP_METHOD = 'http-method';
|
||||
export const SORT_TYPE_DESC = 'type-desc';
|
||||
export const SORT_TYPE_ASC = 'type-asc';
|
||||
export const SORT_TYPE_MANUAL = 'type-manual';
|
||||
|
||||
export const SORT_ORDERS = [
|
||||
SORT_TYPE_MANUAL,
|
||||
SORT_NAME_ASC,
|
||||
SORT_NAME_DESC,
|
||||
SORT_CREATED_ASC,
|
||||
SORT_CREATED_DESC,
|
||||
SORT_HTTP_METHOD,
|
||||
SORT_TYPE_DESC,
|
||||
SORT_TYPE_ASC,
|
||||
'type-manual',
|
||||
'name-asc',
|
||||
'name-desc',
|
||||
'created-asc',
|
||||
'created-desc',
|
||||
'http-method',
|
||||
'type-desc',
|
||||
'type-asc',
|
||||
] as const;
|
||||
export const sortOrderName: Record<SortOrder, string> = {
|
||||
[SORT_TYPE_MANUAL]: 'Manual',
|
||||
[SORT_NAME_ASC]: 'Name Ascending (A-Z)',
|
||||
[SORT_NAME_DESC]: 'Name Descending (Z-A)',
|
||||
[SORT_CREATED_ASC]: 'Oldest First',
|
||||
[SORT_CREATED_DESC]: 'Newest First',
|
||||
[SORT_HTTP_METHOD]: 'HTTP Method',
|
||||
[SORT_TYPE_DESC]: 'Folders First',
|
||||
[SORT_TYPE_ASC]: 'Requests First',
|
||||
'type-manual': 'Manual',
|
||||
'name-asc': 'Name Ascending (A-Z)',
|
||||
'name-desc': 'Name Descending (Z-A)',
|
||||
'created-asc': 'Oldest First',
|
||||
'created-desc': 'Newest First',
|
||||
'http-method': 'HTTP Method',
|
||||
'type-desc': 'Folders First',
|
||||
'type-asc': 'Requests First',
|
||||
};
|
||||
|
||||
export const EXTERNAL_VAULT_PLUGIN_NAME = getAppBundlePlugins()[0].name;
|
||||
@@ -363,19 +340,19 @@ export const EXTERNAL_VAULT_PLUGIN_NAME = getAppBundlePlugins()[0].name;
|
||||
export type DashboardSortOrder = 'name-asc' | 'name-desc' | 'created-asc' | 'created-desc' | 'modified-desc';
|
||||
|
||||
export const DASHBOARD_SORT_ORDERS: DashboardSortOrder[] = [
|
||||
SORT_MODIFIED_DESC,
|
||||
SORT_NAME_ASC,
|
||||
SORT_NAME_DESC,
|
||||
SORT_CREATED_ASC,
|
||||
SORT_CREATED_DESC,
|
||||
'modified-desc',
|
||||
'name-asc',
|
||||
'name-desc',
|
||||
'created-asc',
|
||||
'created-desc',
|
||||
];
|
||||
|
||||
export const dashboardSortOrderName: Record<DashboardSortOrder, string> = {
|
||||
[SORT_NAME_ASC]: 'Name Ascending (A-Z)',
|
||||
[SORT_NAME_DESC]: 'Name Descending (Z-A)',
|
||||
[SORT_CREATED_ASC]: 'Oldest First',
|
||||
[SORT_CREATED_DESC]: 'Newest First',
|
||||
[SORT_MODIFIED_DESC]: 'Last Modified',
|
||||
'name-asc': 'Name Ascending (A-Z)',
|
||||
'name-desc': 'Name Descending (Z-A)',
|
||||
'created-asc': 'Oldest First',
|
||||
'created-desc': 'Newest First',
|
||||
'modified-desc': 'Last Modified',
|
||||
};
|
||||
|
||||
export type PreviewMode = 'friendly' | 'source' | 'raw';
|
||||
@@ -413,13 +390,6 @@ export function getContentTypeName(contentType?: string | null, useLong = false)
|
||||
return useLong ? contentTypesMap[CONTENT_TYPE_OTHER][1] : contentTypesMap[CONTENT_TYPE_OTHER][0];
|
||||
}
|
||||
|
||||
export function getAuthTypeName(authType?: string, useLong = false) {
|
||||
if (authType && authType in authTypesMap) {
|
||||
return useLong ? authTypesMap[authType][1] : authTypesMap[authType][0];
|
||||
}
|
||||
return 'Auth';
|
||||
}
|
||||
|
||||
export function getContentTypeFromHeaders(headers: any[], defaultValue: string | null = null) {
|
||||
if (!Array.isArray(headers)) {
|
||||
return null;
|
||||
@@ -577,43 +547,5 @@ export const RESPONSE_CODE_REASONS: Record<number, string> = {
|
||||
599: 'Network Connect Timeout Error',
|
||||
};
|
||||
|
||||
export const WORKSPACE_ID_KEY = '__WORKSPACE_ID__';
|
||||
export const BASE_ENVIRONMENT_ID_KEY = '__BASE_ENVIRONMENT_ID__';
|
||||
export const EXPORT_TYPE_REQUEST = 'request';
|
||||
export const EXPORT_TYPE_GRPC_REQUEST = 'grpc_request';
|
||||
export const EXPORT_TYPE_WEBSOCKET_REQUEST = 'websocket_request';
|
||||
export const EXPORT_TYPE_WEBSOCKET_PAYLOAD = 'websocket_payload';
|
||||
export const EXPORT_TYPE_SOCKETIO_REQUEST = 'socketio_request';
|
||||
export const EXPORT_TYPE_SOCKETIO_PAYLOAD = 'socketio_payload';
|
||||
export const EXPORT_TYPE_MOCK_SERVER = 'mock';
|
||||
export const EXPORT_TYPE_MOCK_ROUTE = 'mock_route';
|
||||
export const EXPORT_TYPE_REQUEST_GROUP = 'request_group';
|
||||
export const EXPORT_TYPE_UNIT_TEST_SUITE = 'unit_test_suite';
|
||||
export const EXPORT_TYPE_UNIT_TEST = 'unit_test';
|
||||
export const EXPORT_TYPE_WORKSPACE = 'workspace';
|
||||
export const EXPORT_TYPE_COOKIE_JAR = 'cookie_jar';
|
||||
export const EXPORT_TYPE_ENVIRONMENT = 'environment';
|
||||
export const EXPORT_TYPE_API_SPEC = 'api_spec';
|
||||
export const EXPORT_TYPE_PROTO_FILE = 'proto_file';
|
||||
export const EXPORT_TYPE_PROTO_DIRECTORY = 'proto_directory';
|
||||
export type AllExportTypes =
|
||||
| 'request'
|
||||
| 'grpc_request'
|
||||
| 'websocket_request'
|
||||
| 'websocket_payload'
|
||||
| 'socketio_request'
|
||||
| 'socketio_payload'
|
||||
| 'mock'
|
||||
| 'mock_route'
|
||||
| 'request_group'
|
||||
| 'unit_test_suite'
|
||||
| 'unit_test'
|
||||
| 'workspace'
|
||||
| 'cookie_jar'
|
||||
| 'environment'
|
||||
| 'api_spec'
|
||||
| 'proto_file'
|
||||
| 'proto_directory';
|
||||
|
||||
// (ms) curently server timeout is 30s
|
||||
export const INSOMNIA_FETCH_TIME_OUT = 30_000;
|
||||
|
||||
@@ -2,14 +2,13 @@ import { readFile } from 'node:fs/promises';
|
||||
|
||||
import { z, type ZodError } from 'zod/v4';
|
||||
|
||||
import type { AllExportTypes } from '~/common/constants';
|
||||
import type { CurrentPlan } from '~/models/organization';
|
||||
|
||||
import { type ApiSpec, isApiSpec } from '../models/api-spec';
|
||||
import { type CookieJar, isCookieJar } from '../models/cookie-jar';
|
||||
import { type BaseEnvironment, type Environment, isEnvironment } from '../models/environment';
|
||||
import { type GrpcRequest, isGrpcRequest } from '../models/grpc-request';
|
||||
import { type BaseModel, getModel, userSession } from '../models/index';
|
||||
import { type AllTypes, type BaseModel, getModel, userSession } from '../models/index';
|
||||
import * as models from '../models/index';
|
||||
import { isMockRoute, type MockRoute } from '../models/mock-route';
|
||||
import { isGitProject } from '../models/project';
|
||||
@@ -28,6 +27,24 @@ import { database as db } from './database';
|
||||
import { tryImportV5Data } from './insomnia-v5';
|
||||
import { generateId } from './misc';
|
||||
|
||||
export type AllExportTypes =
|
||||
| 'request'
|
||||
| 'grpc_request'
|
||||
| 'websocket_request'
|
||||
| 'websocket_payload'
|
||||
| 'socketio_request'
|
||||
| 'socketio_payload'
|
||||
| 'mock'
|
||||
| 'mock_route'
|
||||
| 'request_group'
|
||||
| 'unit_test_suite'
|
||||
| 'unit_test'
|
||||
| 'workspace'
|
||||
| 'cookie_jar'
|
||||
| 'environment'
|
||||
| 'api_spec'
|
||||
| 'proto_file'
|
||||
| 'proto_directory';
|
||||
export interface ExportedModel extends BaseModel {
|
||||
_type: AllExportTypes;
|
||||
}
|
||||
@@ -116,6 +133,26 @@ interface ResourceCacheType {
|
||||
|
||||
let resourceCacheList: ResourceCacheType[] = [];
|
||||
|
||||
export const MODELS_BY_EXPORT_TYPE: Record<AllExportTypes, AllTypes> = {
|
||||
request: 'Request',
|
||||
websocket_payload: 'WebSocketPayload',
|
||||
websocket_request: 'WebSocketRequest',
|
||||
socketio_payload: 'SocketIOPayload',
|
||||
socketio_request: 'SocketIORequest',
|
||||
mock: 'MockServer',
|
||||
mock_route: 'MockRoute',
|
||||
grpc_request: 'GrpcRequest',
|
||||
request_group: 'RequestGroup',
|
||||
unit_test_suite: 'UnitTestSuite',
|
||||
unit_test: 'UnitTest',
|
||||
workspace: 'Workspace',
|
||||
cookie_jar: 'CookieJar',
|
||||
environment: 'Environment',
|
||||
api_spec: 'ApiSpec',
|
||||
proto_file: 'ProtoFile',
|
||||
proto_directory: 'ProtoDirectory',
|
||||
};
|
||||
|
||||
export async function scanResources(importEntries: ImportEntry[]): Promise<ScanResult[]> {
|
||||
resourceCacheList = [];
|
||||
const results = await Promise.allSettled(
|
||||
@@ -176,7 +213,7 @@ export async function scanResources(importEntries: ImportEntry[]): Promise<ScanR
|
||||
.filter(r => r._type)
|
||||
.map(r => {
|
||||
const { _type, ...model } = r;
|
||||
return { ...model, type: models.MODELS_BY_EXPORT_TYPE[_type] };
|
||||
return { ...model, type: MODELS_BY_EXPORT_TYPE[_type] };
|
||||
});
|
||||
|
||||
resourceCacheList.push({
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { parse, stringify } from 'yaml';
|
||||
|
||||
import { type AllExportTypes, MODELS_BY_EXPORT_TYPE } from '~/common/import';
|
||||
|
||||
import * as models from '../models';
|
||||
import type { ApiSpec } from '../models/api-spec';
|
||||
import type { CookieJar } from '../models/cookie-jar';
|
||||
@@ -14,21 +16,6 @@ import type { UnitTest } from '../models/unit-test';
|
||||
import type { UnitTestSuite } from '../models/unit-test-suite';
|
||||
import type { WebSocketRequest } from '../models/websocket-request';
|
||||
import type { Workspace, WorkspaceScope } from '../models/workspace';
|
||||
import {
|
||||
EXPORT_TYPE_API_SPEC,
|
||||
EXPORT_TYPE_COOKIE_JAR,
|
||||
EXPORT_TYPE_ENVIRONMENT,
|
||||
EXPORT_TYPE_GRPC_REQUEST,
|
||||
EXPORT_TYPE_MOCK_ROUTE,
|
||||
EXPORT_TYPE_MOCK_SERVER,
|
||||
EXPORT_TYPE_REQUEST,
|
||||
EXPORT_TYPE_REQUEST_GROUP,
|
||||
EXPORT_TYPE_SOCKETIO_REQUEST,
|
||||
EXPORT_TYPE_UNIT_TEST,
|
||||
EXPORT_TYPE_UNIT_TEST_SUITE,
|
||||
EXPORT_TYPE_WEBSOCKET_REQUEST,
|
||||
EXPORT_TYPE_WORKSPACE,
|
||||
} from './constants';
|
||||
import { database } from './database';
|
||||
import {
|
||||
type Insomnia_GRPCRequest,
|
||||
@@ -43,7 +30,7 @@ import {
|
||||
WebsocketRequestSchema,
|
||||
} from './import-v5-parser';
|
||||
|
||||
type WithExportType<T extends models.BaseModel> = T & { _type: string };
|
||||
type WithExportType<T extends models.BaseModel> = T & { _type: AllExportTypes };
|
||||
|
||||
function filterEmptyValue(value: string | number | boolean | null | undefined) {
|
||||
return value !== null && value !== undefined && !(typeof value === 'object' && Object.keys(value).length === 0);
|
||||
@@ -103,7 +90,7 @@ function getWorkspace(file: InsomniaFile): WithExportType<Workspace> {
|
||||
},
|
||||
),
|
||||
type: 'Workspace',
|
||||
_type: EXPORT_TYPE_WORKSPACE,
|
||||
_type: 'workspace',
|
||||
name: file.name || 'Imported Collection',
|
||||
parentId: '',
|
||||
scope: insomniaSchemaTypeToScope(file.type),
|
||||
@@ -119,7 +106,7 @@ function getEnvironments(file: InsomniaFile): Environment[] {
|
||||
},
|
||||
),
|
||||
type: 'Environment',
|
||||
_type: EXPORT_TYPE_ENVIRONMENT,
|
||||
_type: 'environment',
|
||||
parentId: file.meta?.id || '__WORKSPACE_ID__',
|
||||
color: file.environments.color || null,
|
||||
data: (file.environments.data as Record<string, any>) || {},
|
||||
@@ -135,7 +122,7 @@ function getEnvironments(file: InsomniaFile): Environment[] {
|
||||
},
|
||||
),
|
||||
type: 'Environment',
|
||||
_type: EXPORT_TYPE_ENVIRONMENT,
|
||||
_type: 'environment',
|
||||
color: environment.color || null,
|
||||
data: (environment.data as Record<string, any>) || {},
|
||||
dataPropertyOrder: (environment.dataPropertyOrder as Record<string, any>) || undefined,
|
||||
@@ -158,7 +145,7 @@ function getCookieJar(file: InsomniaFile): [CookieJar] | [] {
|
||||
},
|
||||
),
|
||||
type: 'CookieJar',
|
||||
_type: EXPORT_TYPE_COOKIE_JAR,
|
||||
_type: 'cookie_jar',
|
||||
name: file.cookieJar.name || 'Imported Cookie Jar',
|
||||
parentId: file.meta?.id || '__WORKSPACE_ID__',
|
||||
cookies: file.cookieJar.cookies || [],
|
||||
@@ -181,7 +168,7 @@ function getApiSpec(file: InsomniaFile): [WithExportType<ApiSpec>] | [] {
|
||||
),
|
||||
type: 'ApiSpec',
|
||||
name: file.name || 'Api Spec',
|
||||
_type: EXPORT_TYPE_API_SPEC,
|
||||
_type: 'api_spec',
|
||||
fileName: 'file' in file.spec ? file.spec.file : '',
|
||||
contentType: 'json',
|
||||
contents: 'contents' in file.spec && file.spec.contents ? stringify(file.spec.contents) : '',
|
||||
@@ -202,7 +189,7 @@ function getMockServer(file: InsomniaFile): WithExportType<MockServer> {
|
||||
},
|
||||
),
|
||||
type: 'MockServer',
|
||||
_type: EXPORT_TYPE_MOCK_SERVER,
|
||||
_type: 'mock',
|
||||
name: file.name || 'Imported Mock Server',
|
||||
parentId: file.meta?.id || '__WORKSPACE_ID__',
|
||||
url: file.server?.url || '',
|
||||
@@ -223,7 +210,7 @@ function getMockRoutes(file: InsomniaFile): WithExportType<MockRoute>[] {
|
||||
},
|
||||
),
|
||||
type: 'MockRoute',
|
||||
_type: EXPORT_TYPE_MOCK_ROUTE,
|
||||
_type: 'mock_route',
|
||||
name: mock.name || 'Imported Mock Route',
|
||||
parentId: file.server?.meta?.id || '__MOCK_SERVER_ID__',
|
||||
body: mock.body || '',
|
||||
@@ -251,7 +238,7 @@ function getTestSuites(file: InsomniaFile): (UnitTestSuite | UnitTest)[] {
|
||||
},
|
||||
),
|
||||
type: 'UnitTestSuite',
|
||||
_type: EXPORT_TYPE_UNIT_TEST_SUITE,
|
||||
_type: 'unit_test_suite',
|
||||
name: testSuite.name || 'Imported Test Suite',
|
||||
parentId: file.meta?.id || '__WORKSPACE_ID__',
|
||||
metaSortKey: testSuite.meta?.sortKey ?? index,
|
||||
@@ -267,7 +254,7 @@ function getTestSuites(file: InsomniaFile): (UnitTestSuite | UnitTest)[] {
|
||||
},
|
||||
),
|
||||
type: 'UnitTest',
|
||||
_type: EXPORT_TYPE_UNIT_TEST,
|
||||
_type: 'unit_test',
|
||||
name: test.name || 'Imported Test',
|
||||
parentId: suite._id,
|
||||
requestId: test.requestId,
|
||||
@@ -303,7 +290,7 @@ function getCollection(
|
||||
},
|
||||
),
|
||||
type: 'RequestGroup',
|
||||
_type: EXPORT_TYPE_REQUEST_GROUP,
|
||||
_type: 'request_group',
|
||||
name: item.name || 'Imported Folder',
|
||||
parentId,
|
||||
headers: item.headers?.map(({ name, value }) => ({ name: name || '', value: value || '' })) || [],
|
||||
@@ -326,7 +313,7 @@ function getCollection(
|
||||
},
|
||||
),
|
||||
type: 'Request',
|
||||
_type: EXPORT_TYPE_REQUEST,
|
||||
_type: 'request',
|
||||
name: item.name || 'Imported Request',
|
||||
parentId,
|
||||
url: item.url,
|
||||
@@ -356,7 +343,7 @@ function getCollection(
|
||||
},
|
||||
),
|
||||
type: 'GrpcRequest',
|
||||
_type: EXPORT_TYPE_GRPC_REQUEST,
|
||||
_type: 'grpc_request',
|
||||
name: item.name || 'Imported gRPC Request',
|
||||
parentId,
|
||||
url: item.url,
|
||||
@@ -385,7 +372,7 @@ function getCollection(
|
||||
},
|
||||
),
|
||||
type: 'WebSocketRequest',
|
||||
_type: EXPORT_TYPE_WEBSOCKET_REQUEST,
|
||||
_type: 'websocket_request',
|
||||
name: item.name || 'Imported WebSocket Request',
|
||||
parentId,
|
||||
url: data.url,
|
||||
@@ -412,7 +399,7 @@ function getCollection(
|
||||
},
|
||||
),
|
||||
type: 'SocketIORequest',
|
||||
_type: EXPORT_TYPE_SOCKETIO_REQUEST,
|
||||
_type: 'socketio_request',
|
||||
name: item.name || 'Imported Socket.IO Request',
|
||||
parentId,
|
||||
url: data.url,
|
||||
@@ -499,11 +486,11 @@ export async function getInsomniaV5DataExport({
|
||||
if (!workspace) {
|
||||
throw new Error('Workspace not found');
|
||||
}
|
||||
|
||||
const workspaceDescendants = await database.getWithDescendants(workspace, models.EXPORTABLE_TYPES);
|
||||
const exportableTypes = Object.values(MODELS_BY_EXPORT_TYPE);
|
||||
const workspaceDescendants = await database.getWithDescendants(workspace, exportableTypes);
|
||||
|
||||
const exportableResources = workspaceDescendants.filter(resource => {
|
||||
if (models.EXPORTABLE_TYPES.includes(resource.type)) {
|
||||
if (exportableTypes.includes(resource.type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
import { type GrpcRequest, isGrpcRequest } from '../models/grpc-request';
|
||||
import { isRequest, type Request } from '../models/request';
|
||||
import { isRequestGroup, type RequestGroup } from '../models/request-group';
|
||||
import {
|
||||
HTTP_METHODS,
|
||||
SORT_CREATED_ASC,
|
||||
SORT_CREATED_DESC,
|
||||
SORT_HTTP_METHOD,
|
||||
SORT_MODIFIED_ASC,
|
||||
SORT_MODIFIED_DESC,
|
||||
SORT_NAME_ASC,
|
||||
SORT_NAME_DESC,
|
||||
SORT_TYPE_ASC,
|
||||
SORT_TYPE_DESC,
|
||||
SORT_TYPE_MANUAL,
|
||||
} from './constants';
|
||||
import { type DashboardSortOrder, HTTP_METHODS, type SortOrder } from './constants';
|
||||
|
||||
type SortableModel = Request | RequestGroup | GrpcRequest;
|
||||
type SortFunction<SortableType> = (a: SortableType, b: SortableType) => number;
|
||||
@@ -42,14 +30,6 @@ export const createdLastSort: SortFunction<{ created: number }> = (a, b) => {
|
||||
return a.created > b.created ? -1 : 1;
|
||||
};
|
||||
|
||||
export const ascendingModifiedSort: SortFunction<{ lastModifiedTimestamp: number }> = (a, b) => {
|
||||
if (a.lastModifiedTimestamp === b.lastModifiedTimestamp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return a.lastModifiedTimestamp < b.lastModifiedTimestamp ? -1 : 1;
|
||||
};
|
||||
|
||||
export const descendingModifiedSort: SortFunction<{ lastModifiedTimestamp: number }> = (a, b) => {
|
||||
if (a.lastModifiedTimestamp === b.lastModifiedTimestamp) {
|
||||
return 0;
|
||||
@@ -127,15 +107,14 @@ export const descendingNumberSort: SortFunction<number> = (a, b) => {
|
||||
|
||||
export const ascendingFirstIndexStringSort: SortFunction<string[]> = (a, b) => a[0].localeCompare(b[0]);
|
||||
|
||||
export const sortMethodMap = {
|
||||
[SORT_NAME_ASC]: ascendingNameSort,
|
||||
[SORT_NAME_DESC]: descendingNameSort,
|
||||
[SORT_CREATED_ASC]: createdFirstSort,
|
||||
[SORT_CREATED_DESC]: createdLastSort,
|
||||
[SORT_MODIFIED_ASC]: ascendingModifiedSort,
|
||||
[SORT_MODIFIED_DESC]: descendingModifiedSort,
|
||||
[SORT_HTTP_METHOD]: httpMethodSort,
|
||||
[SORT_TYPE_DESC]: descendingTypeSort,
|
||||
[SORT_TYPE_ASC]: ascendingTypeSort,
|
||||
[SORT_TYPE_MANUAL]: metaSortKeySort,
|
||||
export const sortMethodMap: Record<DashboardSortOrder | SortOrder, SortFunction<any>> = {
|
||||
'name-asc': ascendingNameSort,
|
||||
'name-desc': descendingNameSort,
|
||||
'created-asc': createdFirstSort,
|
||||
'created-desc': createdLastSort,
|
||||
'modified-desc': descendingModifiedSort,
|
||||
'http-method': httpMethodSort,
|
||||
'type-desc': descendingTypeSort,
|
||||
'type-asc': ascendingTypeSort,
|
||||
'type-manual': metaSortKeySort,
|
||||
};
|
||||
|
||||
@@ -23,14 +23,7 @@ import electron from 'electron';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { version } from '../../../package.json';
|
||||
import {
|
||||
AUTH_AWS_IAM,
|
||||
AUTH_DIGEST,
|
||||
AUTH_NETRC,
|
||||
AUTH_NTLM,
|
||||
CONTENT_TYPE_FORM_DATA,
|
||||
CONTENT_TYPE_FORM_URLENCODED,
|
||||
} from '../../common/constants';
|
||||
import { type AuthTypes, CONTENT_TYPE_FORM_DATA, CONTENT_TYPE_FORM_URLENCODED } from '../../common/constants';
|
||||
import { describeByteSize, hasAuthHeader } from '../../common/misc';
|
||||
import type { ClientCertificate } from '../../models/client-certificate';
|
||||
import type { RequestHeader } from '../../models/request';
|
||||
@@ -53,7 +46,7 @@ interface RequestUsedHere {
|
||||
headers: any;
|
||||
method: string;
|
||||
body: { mimeType?: string | null };
|
||||
authentication: Record<string, any>;
|
||||
authentication: {} | { type: AuthTypes; disabled?: boolean; username?: string; password?: string };
|
||||
settingFollowRedirects: 'global' | 'on' | 'off';
|
||||
settingRebuildPath: boolean;
|
||||
settingSendCookies: boolean;
|
||||
@@ -165,7 +158,8 @@ export const curlRequest = (options: CurlRequestOptions) =>
|
||||
const { authentication } = req;
|
||||
if (requestBodyPath) {
|
||||
// AWS IAM file upload not supported
|
||||
invariant(authentication.type !== AUTH_AWS_IAM, 'AWS authentication not supported for provided body type');
|
||||
const isAWSIAM = 'type' in authentication && authentication.type === 'iam';
|
||||
invariant(!isAWSIAM, 'AWS authentication not supported for provided body type');
|
||||
const { size: contentLength } = fs.statSync(requestBodyPath);
|
||||
curl.setOpt(Curl.option.INFILESIZE_LARGE, contentLength);
|
||||
curl.setOpt(Curl.option.UPLOAD, 1);
|
||||
@@ -449,21 +443,21 @@ export const createConfiguredCurlInstance = ({
|
||||
if (req.suppressUserAgent) {
|
||||
curl.setOpt(Curl.option.USERAGENT, '');
|
||||
}
|
||||
|
||||
const { username, password, disabled } = authentication;
|
||||
const isDigest = authentication.type === AUTH_DIGEST;
|
||||
const isNLTM = authentication.type === AUTH_NTLM;
|
||||
const isDigestOrNLTM = isDigest || isNLTM;
|
||||
if (!hasAuthHeader(headers) && !disabled && isDigestOrNLTM) {
|
||||
isDigest && curl.setOpt(Curl.option.HTTPAUTH, CurlAuth.Digest);
|
||||
isNLTM && curl.setOpt(Curl.option.HTTPAUTH, CurlAuth.Ntlm);
|
||||
curl.setOpt(Curl.option.USERNAME, username || '');
|
||||
curl.setOpt(Curl.option.PASSWORD, password || '');
|
||||
if (authentication && 'type' in authentication) {
|
||||
const { username, password, disabled } = authentication;
|
||||
const isDigest = authentication.type === 'digest';
|
||||
const isNLTM = authentication.type === 'ntlm';
|
||||
const isDigestOrNLTM = isDigest || isNLTM;
|
||||
if (!hasAuthHeader(headers) && !disabled && isDigestOrNLTM) {
|
||||
isDigest && curl.setOpt(Curl.option.HTTPAUTH, CurlAuth.Digest);
|
||||
isNLTM && curl.setOpt(Curl.option.HTTPAUTH, CurlAuth.Ntlm);
|
||||
curl.setOpt(Curl.option.USERNAME, username || '');
|
||||
curl.setOpt(Curl.option.PASSWORD, password || '');
|
||||
}
|
||||
if (authentication.type === 'netrc') {
|
||||
curl.setOpt(Curl.option.NETRC, CurlNetrc.Required);
|
||||
}
|
||||
}
|
||||
if (authentication.type === AUTH_NETRC) {
|
||||
curl.setOpt(Curl.option.NETRC, CurlNetrc.Required);
|
||||
}
|
||||
|
||||
return { curl, debugTimeline };
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ import { parse as urlParse } from 'node:url';
|
||||
import aws4 from 'aws4';
|
||||
import clone from 'clone';
|
||||
|
||||
import { AUTH_AWS_IAM, AUTH_DIGEST, AUTH_NTLM, CONTENT_TYPE_FORM_DATA } from '../../common/constants';
|
||||
import type { RequestAuthentication } from '~/models/request';
|
||||
|
||||
import { CONTENT_TYPE_FORM_DATA } from '../../common/constants';
|
||||
import {
|
||||
getContentTypeHeader,
|
||||
getHostHeader,
|
||||
@@ -27,7 +29,7 @@ interface Req {
|
||||
headers: any;
|
||||
method: string;
|
||||
body: { mimeType?: string | null };
|
||||
authentication: Record<string, any>;
|
||||
authentication: {} | RequestAuthentication;
|
||||
}
|
||||
export const parseHeaderStrings = ({ req, finalUrl, requestBody, requestBodyPath, authHeader }: Input) => {
|
||||
const headers = clone(req.headers);
|
||||
@@ -39,25 +41,27 @@ export const parseHeaderStrings = ({ req, finalUrl, requestBody, requestBodyPath
|
||||
headers.push({ name: 'Transfer-Encoding', value: DISABLE_HEADER_VALUE });
|
||||
}
|
||||
const { authentication, method } = req;
|
||||
const isDigest = authentication.type === AUTH_DIGEST;
|
||||
const isNTLM = authentication.type === AUTH_NTLM;
|
||||
const isAWSIAM = authentication.type === AUTH_AWS_IAM;
|
||||
const hasNoAuthorisationAndNotDisabledAWSBasicOrDigest =
|
||||
!hasAuthHeader(headers) && !authentication.disabled && !isAWSIAM && !isDigest && !isNTLM;
|
||||
if (hasNoAuthorisationAndNotDisabledAWSBasicOrDigest && authHeader) {
|
||||
headers.push(authHeader);
|
||||
}
|
||||
if (isAWSIAM) {
|
||||
const hostHeader = getHostHeader(headers)?.value;
|
||||
const contentTypeHeader = getContentTypeHeader(headers)?.value;
|
||||
_getAwsAuthHeaders({
|
||||
authentication,
|
||||
url: finalUrl,
|
||||
hostHeader,
|
||||
contentTypeHeader,
|
||||
body: requestBody,
|
||||
method,
|
||||
}).forEach(header => headers.push(header));
|
||||
if (authentication && 'type' in authentication) {
|
||||
const isDigest = authentication.type === 'digest';
|
||||
const isNTLM = authentication.type === 'ntlm';
|
||||
const isAWSIAM = authentication.type === 'iam';
|
||||
const hasNoAuthorisationAndNotDisabledAWSBasicOrDigest =
|
||||
!hasAuthHeader(headers) && !authentication.disabled && !isAWSIAM && !isDigest && !isNTLM;
|
||||
if (hasNoAuthorisationAndNotDisabledAWSBasicOrDigest && authHeader) {
|
||||
headers.push(authHeader);
|
||||
}
|
||||
if (isAWSIAM) {
|
||||
const hostHeader = getHostHeader(headers)?.value;
|
||||
const contentTypeHeader = getContentTypeHeader(headers)?.value;
|
||||
_getAwsAuthHeaders({
|
||||
authentication,
|
||||
url: finalUrl,
|
||||
hostHeader,
|
||||
contentTypeHeader,
|
||||
body: requestBody,
|
||||
method,
|
||||
}).forEach(header => headers.push(header));
|
||||
}
|
||||
}
|
||||
const isMultipartForm = req.body.mimeType === CONTENT_TYPE_FORM_DATA;
|
||||
if (isMultipartForm && requestBodyPath) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import { type CloseEvent, type ErrorEvent, type Event, type MessageEvent, WebSoc
|
||||
|
||||
import { database } from '~/common/database';
|
||||
|
||||
import { AUTH_API_KEY, AUTH_BASIC, AUTH_BEARER } from '../../common/constants';
|
||||
import { jarFromCookies } from '../../common/cookies';
|
||||
import { generateId, getSetCookieHeaders } from '../../common/misc';
|
||||
import { webSocketRequest } from '../../models';
|
||||
@@ -159,12 +158,12 @@ const openWebSocketConnection = async (
|
||||
let url = options.url;
|
||||
let authCookie = null;
|
||||
if (!options.authentication.disabled) {
|
||||
if (options.authentication.type === AUTH_BASIC) {
|
||||
if (options.authentication.type === 'basic') {
|
||||
const { username, password, useISO88591 } = options.authentication;
|
||||
const encoding = useISO88591 ? 'latin1' : 'utf8';
|
||||
headers.push(getBasicAuthHeader(username, password, encoding));
|
||||
}
|
||||
if (options.authentication.type === AUTH_API_KEY) {
|
||||
if (options.authentication.type === 'apikey') {
|
||||
const { key = '', value = '', addTo } = options.authentication; // Ensure key is not undefined
|
||||
if (addTo === HEADER) {
|
||||
headers.push({ name: key, value: value });
|
||||
@@ -179,7 +178,7 @@ const openWebSocketConnection = async (
|
||||
url = joinUrlAndQueryString(options.url, qs);
|
||||
}
|
||||
}
|
||||
if (options.authentication.type === AUTH_BEARER && options.authentication.token) {
|
||||
if (options.authentication.type === 'bearer' && options.authentication.token) {
|
||||
const { token, prefix } = options.authentication;
|
||||
headers.push(getBearerAuthHeader(token, prefix));
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ const pluginToMainAPI: Record<PluginToMainAPIPaths, (...args: any[]) => Promise<
|
||||
const response = await curlRequest({
|
||||
requestId: `no-sideEffects-request-${requestId}`,
|
||||
req: {
|
||||
authentication: {},
|
||||
authentication: { type: 'none' },
|
||||
body: {},
|
||||
cookieJar: {
|
||||
cookies: [],
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
import {
|
||||
type AllExportTypes,
|
||||
EXPORT_TYPE_API_SPEC,
|
||||
EXPORT_TYPE_COOKIE_JAR,
|
||||
EXPORT_TYPE_ENVIRONMENT,
|
||||
EXPORT_TYPE_GRPC_REQUEST,
|
||||
EXPORT_TYPE_MOCK_ROUTE,
|
||||
EXPORT_TYPE_MOCK_SERVER,
|
||||
EXPORT_TYPE_PROTO_DIRECTORY,
|
||||
EXPORT_TYPE_PROTO_FILE,
|
||||
EXPORT_TYPE_REQUEST,
|
||||
EXPORT_TYPE_REQUEST_GROUP,
|
||||
EXPORT_TYPE_SOCKETIO_PAYLOAD,
|
||||
EXPORT_TYPE_SOCKETIO_REQUEST,
|
||||
EXPORT_TYPE_UNIT_TEST,
|
||||
EXPORT_TYPE_UNIT_TEST_SUITE,
|
||||
EXPORT_TYPE_WEBSOCKET_PAYLOAD,
|
||||
EXPORT_TYPE_WEBSOCKET_REQUEST,
|
||||
EXPORT_TYPE_WORKSPACE,
|
||||
} from '../common/constants';
|
||||
import { generateId } from '../common/misc';
|
||||
import { typedKeys } from '../utils';
|
||||
import * as _apiSpec from './api-spec';
|
||||
@@ -282,28 +262,6 @@ export async function initModel<T extends BaseModel>(type: string, ...sources: R
|
||||
return migratedDoc as T;
|
||||
}
|
||||
|
||||
export const MODELS_BY_EXPORT_TYPE: Record<AllExportTypes, AllTypes> = {
|
||||
[EXPORT_TYPE_REQUEST]: 'Request',
|
||||
[EXPORT_TYPE_WEBSOCKET_PAYLOAD]: 'WebSocketPayload',
|
||||
[EXPORT_TYPE_WEBSOCKET_REQUEST]: 'WebSocketRequest',
|
||||
[EXPORT_TYPE_SOCKETIO_PAYLOAD]: 'SocketIOPayload',
|
||||
[EXPORT_TYPE_SOCKETIO_REQUEST]: 'SocketIORequest',
|
||||
[EXPORT_TYPE_MOCK_SERVER]: 'MockServer',
|
||||
[EXPORT_TYPE_MOCK_ROUTE]: 'MockRoute',
|
||||
[EXPORT_TYPE_GRPC_REQUEST]: 'GrpcRequest',
|
||||
[EXPORT_TYPE_REQUEST_GROUP]: 'RequestGroup',
|
||||
[EXPORT_TYPE_UNIT_TEST_SUITE]: 'UnitTestSuite',
|
||||
[EXPORT_TYPE_UNIT_TEST]: 'UnitTest',
|
||||
[EXPORT_TYPE_WORKSPACE]: 'Workspace',
|
||||
[EXPORT_TYPE_COOKIE_JAR]: 'CookieJar',
|
||||
[EXPORT_TYPE_ENVIRONMENT]: 'Environment',
|
||||
[EXPORT_TYPE_API_SPEC]: 'ApiSpec',
|
||||
[EXPORT_TYPE_PROTO_FILE]: 'ProtoFile',
|
||||
[EXPORT_TYPE_PROTO_DIRECTORY]: 'ProtoDirectory',
|
||||
};
|
||||
|
||||
export const EXPORTABLE_TYPES = Object.values(MODELS_BY_EXPORT_TYPE);
|
||||
|
||||
// Use function instead of object to avoid issues with circular dependencies
|
||||
export const getAllDescendantMap = (): Partial<Record<AllTypes, AllTypes[]>> => {
|
||||
return {
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
import { OperationTypeNode } from 'graphql';
|
||||
|
||||
import type {
|
||||
AUTH_API_KEY,
|
||||
AUTH_ASAP,
|
||||
AUTH_AWS_IAM,
|
||||
AUTH_BEARER,
|
||||
AUTH_DIGEST,
|
||||
AUTH_HAWK,
|
||||
AUTH_NETRC,
|
||||
AUTH_NONE,
|
||||
AUTH_NTLM,
|
||||
AUTH_OAUTH_1,
|
||||
HAWK_ALGORITHM_SHA1,
|
||||
HAWK_ALGORITHM_SHA256,
|
||||
} from '../common/constants';
|
||||
import { AUTH_BASIC, CONTENT_TYPE_FORM_URLENCODED, getContentTypeFromHeaders, METHOD_GET } from '../common/constants';
|
||||
import { CONTENT_TYPE_FORM_URLENCODED, getContentTypeFromHeaders, METHOD_GET } from '../common/constants';
|
||||
import { database as db } from '../common/database';
|
||||
import type { OAuth1SignatureMethod } from '../network/o-auth-1/constants';
|
||||
import { getOperationType } from '../utils/graph-ql';
|
||||
@@ -30,29 +16,16 @@ export const prefix = 'req';
|
||||
export const canDuplicate = true;
|
||||
|
||||
export const canSync = true;
|
||||
export type AuthTypes =
|
||||
| 'none'
|
||||
| 'apikey'
|
||||
| 'oauth2'
|
||||
| 'oauth1'
|
||||
| 'basic'
|
||||
| 'digest'
|
||||
| 'bearer'
|
||||
| 'ntlm'
|
||||
| 'hawk'
|
||||
| 'iam'
|
||||
| 'netrc'
|
||||
| 'asap';
|
||||
|
||||
export interface AuthTypeBasic {
|
||||
type: typeof AUTH_BASIC;
|
||||
type: 'basic';
|
||||
useISO88591?: boolean;
|
||||
disabled?: boolean;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
export interface AuthTypeAPIKey {
|
||||
type: typeof AUTH_API_KEY;
|
||||
type: 'apikey';
|
||||
disabled?: boolean;
|
||||
key?: string;
|
||||
value?: string;
|
||||
@@ -85,16 +58,16 @@ export interface AuthTypeOAuth2 {
|
||||
origin?: string;
|
||||
}
|
||||
export interface AuthTypeHawk {
|
||||
type: typeof AUTH_HAWK;
|
||||
type: 'hawk';
|
||||
disabled?: boolean;
|
||||
algorithm: typeof HAWK_ALGORITHM_SHA256 | typeof HAWK_ALGORITHM_SHA1;
|
||||
algorithm: 'sha1' | 'sha256';
|
||||
id: string;
|
||||
key: string;
|
||||
ext?: string;
|
||||
validatePayload?: boolean;
|
||||
}
|
||||
export interface AuthTypeOAuth1 {
|
||||
type: typeof AUTH_OAUTH_1;
|
||||
type: 'oauth1';
|
||||
disabled?: boolean;
|
||||
signatureMethod?: OAuth1SignatureMethod;
|
||||
consumerKey?: string;
|
||||
@@ -111,25 +84,25 @@ export interface AuthTypeOAuth1 {
|
||||
includeBodyHash?: boolean;
|
||||
}
|
||||
export interface AuthTypeDigest {
|
||||
type: typeof AUTH_DIGEST;
|
||||
type: 'digest';
|
||||
disabled?: boolean;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
export interface AuthTypeNTLM {
|
||||
type: typeof AUTH_NTLM;
|
||||
type: 'ntlm';
|
||||
disabled?: boolean;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
export interface AuthTypeBearer {
|
||||
type: typeof AUTH_BEARER;
|
||||
type: 'bearer';
|
||||
disabled?: boolean;
|
||||
token?: string;
|
||||
prefix?: string;
|
||||
}
|
||||
export interface AuthTypeAwsIam {
|
||||
type: typeof AUTH_AWS_IAM;
|
||||
type: 'iam';
|
||||
disabled?: boolean;
|
||||
accessKeyId?: string;
|
||||
secretAccessKey?: string;
|
||||
@@ -138,11 +111,11 @@ export interface AuthTypeAwsIam {
|
||||
service?: string;
|
||||
}
|
||||
export interface AuthTypeNetrc {
|
||||
type: typeof AUTH_NETRC;
|
||||
type: 'netrc';
|
||||
disabled?: boolean;
|
||||
}
|
||||
export interface AuthTypeAsap {
|
||||
type: typeof AUTH_ASAP;
|
||||
type: 'asap';
|
||||
disabled?: boolean;
|
||||
issuer: string;
|
||||
subject?: string;
|
||||
@@ -152,7 +125,7 @@ export interface AuthTypeAsap {
|
||||
privateKey: string;
|
||||
}
|
||||
export interface AuthTypeNone {
|
||||
type: typeof AUTH_NONE;
|
||||
type: 'none';
|
||||
disabled?: boolean;
|
||||
}
|
||||
export type RequestAuthentication =
|
||||
@@ -454,7 +427,7 @@ function migrateAuthType(request: Request) {
|
||||
// @ts-expect-error -- old model
|
||||
if (isAuthSet && !request.authentication.type) {
|
||||
// @ts-expect-error -- old model
|
||||
request.authentication.type = AUTH_BASIC;
|
||||
request.authentication.type = 'basic';
|
||||
}
|
||||
|
||||
return request;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { AUTH_API_KEY, AUTH_OAUTH_1 } from '../../common/constants';
|
||||
import { _buildBearerHeader, getAuthHeader, getAuthObjectOrNull, getAuthQueryParams } from '../authentication';
|
||||
|
||||
describe('OAuth 1.0', () => {
|
||||
it('Does OAuth 1.0', async () => {
|
||||
const authentication = {
|
||||
type: AUTH_OAUTH_1,
|
||||
type: 'oauth1',
|
||||
consumerKey: 'consumerKey',
|
||||
consumerSecret: 'consumerSecret',
|
||||
callback: 'https://insomnia.rest/callback/',
|
||||
@@ -39,7 +38,7 @@ describe('OAuth 1.0', () => {
|
||||
|
||||
it('Does OAuth 1.0 with RSA-SHA1', async () => {
|
||||
const authentication = {
|
||||
type: AUTH_OAUTH_1,
|
||||
type: 'oauth1',
|
||||
consumerKey: 'consumerKey',
|
||||
consumerSecret: 'consumerSecret',
|
||||
callback: 'https://insomnia.rest/callback/',
|
||||
@@ -88,7 +87,7 @@ describe('OAuth 1.0', () => {
|
||||
|
||||
it('Does OAuth 1.0 with defaults', async () => {
|
||||
const authentication = {
|
||||
type: AUTH_OAUTH_1,
|
||||
type: 'oauth1',
|
||||
consumerKey: 'consumerKey',
|
||||
consumerSecret: 'consumerSecret',
|
||||
signatureMethod: 'HMAC-SHA1',
|
||||
@@ -148,7 +147,7 @@ describe('API Key', () => {
|
||||
describe('getAuthHeader', () => {
|
||||
it('Creates header with key as header name and value as header value, when addTo is "header"', async () => {
|
||||
const authentication = {
|
||||
type: AUTH_API_KEY,
|
||||
type: 'apikey',
|
||||
key: 'x-api-key',
|
||||
value: 'test',
|
||||
addTo: 'header',
|
||||
@@ -167,7 +166,7 @@ describe('API Key', () => {
|
||||
|
||||
it('Creates cookie with key as name and value as value, when addTo is "cookie"', async () => {
|
||||
const authentication = {
|
||||
type: AUTH_API_KEY,
|
||||
type: 'apikey',
|
||||
key: 'x-api-key',
|
||||
value: 'test',
|
||||
addTo: 'cookie',
|
||||
@@ -188,7 +187,7 @@ describe('API Key', () => {
|
||||
describe('getAuthQueryParams', () => {
|
||||
it('Creates a query param with key as parameter name and value as parameter value, when addTo is "queryParams"', async () => {
|
||||
const authentication = {
|
||||
type: AUTH_API_KEY,
|
||||
type: 'apikey',
|
||||
key: 'x-api-key',
|
||||
value: 'test',
|
||||
addTo: 'queryParams',
|
||||
|
||||
@@ -4,14 +4,7 @@ import { join as pathJoin, resolve as pathResolve } from 'node:path';
|
||||
import { CurlHttpVersion, CurlNetrc } from '@getinsomnia/node-libcurl';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
AUTH_AWS_IAM,
|
||||
AUTH_BASIC,
|
||||
AUTH_NETRC,
|
||||
CONTENT_TYPE_FILE,
|
||||
CONTENT_TYPE_FORM_DATA,
|
||||
CONTENT_TYPE_FORM_URLENCODED,
|
||||
} from '../../common/constants';
|
||||
import { CONTENT_TYPE_FILE, CONTENT_TYPE_FORM_DATA, CONTENT_TYPE_FORM_URLENCODED } from '../../common/constants';
|
||||
import { filterHeaders } from '../../common/misc';
|
||||
import { getRenderedRequestAndContext } from '../../common/render';
|
||||
import { HttpVersions } from '../../common/settings';
|
||||
@@ -91,7 +84,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
},
|
||||
url: 'http://localhost',
|
||||
authentication: {
|
||||
type: AUTH_BASIC,
|
||||
type: 'basic',
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
},
|
||||
@@ -272,7 +265,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
},
|
||||
url: 'http://localhost',
|
||||
authentication: {
|
||||
type: AUTH_BASIC,
|
||||
type: 'basic',
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
},
|
||||
@@ -620,7 +613,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
_id: 'req_123',
|
||||
parentId: workspace._id,
|
||||
authentication: {
|
||||
type: AUTH_NETRC,
|
||||
type: 'netrc',
|
||||
},
|
||||
});
|
||||
const renderedRequest = await getRenderedRequest({ request });
|
||||
@@ -723,7 +716,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
},
|
||||
url: 'http://localhost',
|
||||
authentication: {
|
||||
type: AUTH_BASIC,
|
||||
type: 'basic',
|
||||
username: 'user',
|
||||
password: 'pass',
|
||||
},
|
||||
@@ -810,7 +803,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
describe('_getAwsAuthHeaders', () => {
|
||||
it('should generate expected headers', () => {
|
||||
const authentication = {
|
||||
type: AUTH_AWS_IAM,
|
||||
type: 'iam',
|
||||
accessKeyId: 'AKIA99999999',
|
||||
secretAccessKey: 'SAK9999999999999',
|
||||
sessionToken: 'ST99999999999999',
|
||||
@@ -836,7 +829,7 @@ describe('_getAwsAuthHeaders', () => {
|
||||
|
||||
it('should handle sparse request', () => {
|
||||
const authentication = {
|
||||
type: AUTH_AWS_IAM,
|
||||
type: 'iam',
|
||||
accessKeyId: 'AKIA99999999',
|
||||
secretAccessKey: 'SAK9999999999999',
|
||||
sessionToken: 'ST99999999999999',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { AUTH_AWS_IAM, CONTENT_TYPE_FORM_DATA } from '../../common/constants';
|
||||
import { CONTENT_TYPE_FORM_DATA } from '../../common/constants';
|
||||
import { parseHeaderStrings } from '../../main/network/parse-header-strings';
|
||||
|
||||
describe('parseHeaderStrings', () => {
|
||||
@@ -35,7 +35,7 @@ describe('parseHeaderStrings', () => {
|
||||
const req = {
|
||||
authentication: {
|
||||
sessionToken: 'someTokenSomethingSomething',
|
||||
type: AUTH_AWS_IAM,
|
||||
type: 'iam',
|
||||
},
|
||||
body: {},
|
||||
headers: [],
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
import * as Hawk from 'hawk';
|
||||
|
||||
import {
|
||||
AUTH_API_KEY,
|
||||
AUTH_ASAP,
|
||||
AUTH_BASIC,
|
||||
AUTH_BEARER,
|
||||
AUTH_HAWK,
|
||||
AUTH_OAUTH_1,
|
||||
AUTH_OAUTH_2,
|
||||
} from '../common/constants';
|
||||
import type { AuthTypeOAuth2, RequestAuthentication, RequestParameter } from '../models/request';
|
||||
import type { RenderedRequest } from '../templating/types';
|
||||
import { COOKIE, HEADER, QUERY_PARAMS } from './api-key/constants';
|
||||
@@ -32,7 +23,7 @@ export async function getAuthHeader(renderedRequest: RenderedRequest, url: strin
|
||||
return;
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_API_KEY && authentication.addTo === HEADER) {
|
||||
if (authentication.type === 'apikey' && authentication.addTo === HEADER) {
|
||||
const { key, value } = authentication;
|
||||
return {
|
||||
name: key,
|
||||
@@ -40,7 +31,7 @@ export async function getAuthHeader(renderedRequest: RenderedRequest, url: strin
|
||||
} as Header;
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_API_KEY && authentication.addTo === COOKIE) {
|
||||
if (authentication.type === 'apikey' && authentication.addTo === COOKIE) {
|
||||
const { key, value } = authentication;
|
||||
return {
|
||||
name: 'Cookie',
|
||||
@@ -48,18 +39,18 @@ export async function getAuthHeader(renderedRequest: RenderedRequest, url: strin
|
||||
} as Header;
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_BASIC) {
|
||||
if (authentication.type === 'basic') {
|
||||
const { username, password, useISO88591 } = authentication;
|
||||
const encoding = useISO88591 ? 'latin1' : 'utf8';
|
||||
return getBasicAuthHeader(username, password, encoding);
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_BEARER && authentication.token) {
|
||||
if (authentication.type === 'bearer' && authentication.token) {
|
||||
const { token, prefix } = authentication;
|
||||
return getBearerAuthHeader(token, prefix);
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_OAUTH_2) {
|
||||
if (authentication.type === 'oauth2') {
|
||||
// HACK: GraphQL requests use a child request to fetch the schema with an
|
||||
// ID of "{{request_id}}.graphql". Here we are removing the .graphql suffix and
|
||||
// pretending we are fetching a token for the original request. This makes sure
|
||||
@@ -80,7 +71,7 @@ export async function getAuthHeader(renderedRequest: RenderedRequest, url: strin
|
||||
}
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_OAUTH_1) {
|
||||
if (authentication.type === 'oauth1') {
|
||||
const oAuth1Token = await getOAuth1Token(url, method, authentication, body);
|
||||
|
||||
if (oAuth1Token) {
|
||||
@@ -92,7 +83,7 @@ export async function getAuthHeader(renderedRequest: RenderedRequest, url: strin
|
||||
return;
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_HAWK) {
|
||||
if (authentication.type === 'hawk') {
|
||||
const { id, key, algorithm, ext, validatePayload } = authentication;
|
||||
let headerOptions = {
|
||||
credentials: {
|
||||
@@ -118,7 +109,7 @@ export async function getAuthHeader(renderedRequest: RenderedRequest, url: strin
|
||||
};
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_ASAP) {
|
||||
if (authentication.type === 'asap') {
|
||||
const { issuer, subject, audience, keyId, additionalClaims, privateKey } = authentication;
|
||||
|
||||
let parsedAdditionalClaims;
|
||||
@@ -157,7 +148,7 @@ export function getAuthQueryParams(authentication: RequestAuthentication) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (authentication.type === AUTH_API_KEY && authentication.addTo === QUERY_PARAMS) {
|
||||
if (authentication.type === 'apikey' && authentication.addTo === QUERY_PARAMS) {
|
||||
const { key, value } = authentication;
|
||||
return {
|
||||
name: key,
|
||||
|
||||
@@ -6,7 +6,6 @@ import crypto from 'node:crypto';
|
||||
|
||||
import OAuth1 from 'oauth-1.0a';
|
||||
|
||||
import type { AUTH_OAUTH_1 } from '../../common/constants';
|
||||
import { CONTENT_TYPE_FORM_URLENCODED } from '../../common/constants';
|
||||
import type { RequestAuthentication, RequestBody } from '../../models/request';
|
||||
import type { OAuth1SignatureMethod } from './constants';
|
||||
@@ -48,7 +47,7 @@ function hashFunction(signatureMethod: OAuth1SignatureMethod) {
|
||||
export default async function (
|
||||
url: string,
|
||||
method: string,
|
||||
authentication: Extract<RequestAuthentication, { type: typeof AUTH_OAUTH_1 }>,
|
||||
authentication: Extract<RequestAuthentication, { type: 'oauth1' }>,
|
||||
body: RequestBody | null = null,
|
||||
) {
|
||||
const oauth = new OAuth1({
|
||||
|
||||
@@ -13,13 +13,12 @@ import {
|
||||
} from 'react-aria-components';
|
||||
import { useParams } from 'react-router';
|
||||
|
||||
import { HAWK_ALGORITHM_SHA256 } from '../../../common/constants';
|
||||
import { type AuthTypes, HAWK_ALGORITHM_SHA256 } from '../../../common/constants';
|
||||
import type {
|
||||
AuthTypeAPIKey,
|
||||
AuthTypeAwsIam,
|
||||
AuthTypeBasic,
|
||||
AuthTypeNTLM,
|
||||
AuthTypes,
|
||||
RequestAuthentication,
|
||||
} from '../../../models/request';
|
||||
import { getAuthObjectOrNull } from '../../../network/authentication';
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
import React, { type FC, type ReactNode } from 'react';
|
||||
import { Toolbar } from 'react-aria-components';
|
||||
|
||||
import {
|
||||
AUTH_API_KEY,
|
||||
AUTH_ASAP,
|
||||
AUTH_AWS_IAM,
|
||||
AUTH_BASIC,
|
||||
AUTH_BEARER,
|
||||
AUTH_DIGEST,
|
||||
AUTH_HAWK,
|
||||
AUTH_NETRC,
|
||||
AUTH_NTLM,
|
||||
AUTH_OAUTH_1,
|
||||
AUTH_OAUTH_2,
|
||||
} from '../../../../common/constants';
|
||||
import type { AuthTypes, RequestAuthentication } from '../../../../models/request';
|
||||
import type { AuthTypes } from '~/common/constants';
|
||||
|
||||
import type { RequestAuthentication } from '../../../../models/request';
|
||||
import { getAuthObjectOrNull } from '../../../../network/authentication';
|
||||
import { AuthDropdown } from '../../dropdowns/auth-dropdown';
|
||||
import { ApiKeyAuth } from './api-key-auth';
|
||||
@@ -37,27 +26,27 @@ export const AuthWrapper: FC<{
|
||||
const type = getAuthObjectOrNull(authentication)?.type || '';
|
||||
let authBody: ReactNode = null;
|
||||
|
||||
if (type === AUTH_BASIC) {
|
||||
if (type === 'basic') {
|
||||
authBody = <BasicAuth disabled={disabled} />;
|
||||
} else if (type === AUTH_API_KEY) {
|
||||
} else if (type === 'apikey') {
|
||||
authBody = <ApiKeyAuth disabled={disabled} />;
|
||||
} else if (type === AUTH_OAUTH_2) {
|
||||
} else if (type === 'oauth2') {
|
||||
authBody = <OAuth2Auth />;
|
||||
} else if (type === AUTH_HAWK) {
|
||||
} else if (type === 'hawk') {
|
||||
authBody = <HawkAuth />;
|
||||
} else if (type === AUTH_OAUTH_1) {
|
||||
} else if (type === 'oauth1') {
|
||||
authBody = <OAuth1Auth />;
|
||||
} else if (type === AUTH_DIGEST) {
|
||||
} else if (type === 'digest') {
|
||||
authBody = <DigestAuth disabled={disabled} />;
|
||||
} else if (type === AUTH_NTLM) {
|
||||
} else if (type === 'ntlm') {
|
||||
authBody = <NTLMAuth />;
|
||||
} else if (type === AUTH_BEARER) {
|
||||
} else if (type === 'bearer') {
|
||||
authBody = <BearerAuth disabled={disabled} />;
|
||||
} else if (type === AUTH_AWS_IAM) {
|
||||
} else if (type === 'iam') {
|
||||
authBody = <AWSAuth />;
|
||||
} else if (type === AUTH_NETRC) {
|
||||
} else if (type === 'netrc') {
|
||||
authBody = <NetrcAuth />;
|
||||
} else if (type === AUTH_ASAP) {
|
||||
} else if (type === 'asap') {
|
||||
authBody = <AsapAuth />;
|
||||
} else {
|
||||
authBody = (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { type ChangeEvent, type FC, type ReactNode, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { type AUTH_OAUTH_2, getOauthRedirectUrl } from '../../../../common/constants';
|
||||
import { getOauthRedirectUrl } from '../../../../common/constants';
|
||||
import { toKebabCase } from '../../../../common/misc';
|
||||
import accessTokenUrls from '../../../../datasets/access-token-urls';
|
||||
import authorizationUrls from '../../../../datasets/authorization-urls';
|
||||
@@ -95,7 +95,7 @@ const credentialsInBodyOptions = [
|
||||
},
|
||||
];
|
||||
|
||||
const getFields = (authentication: Extract<RequestAuthentication, { type: typeof AUTH_OAUTH_2 }>) => {
|
||||
const getFields = (authentication: Extract<RequestAuthentication, { type: 'oauth2' }>) => {
|
||||
const clientId = <AuthInputRow label="Client ID" property="clientId" key="clientId" />;
|
||||
const clientSecret = <AuthInputRow label="Client Secret" property="clientSecret" key="clientSecret" mask />;
|
||||
const usePkce = (
|
||||
@@ -218,7 +218,7 @@ const getFields = (authentication: Extract<RequestAuthentication, { type: typeof
|
||||
};
|
||||
};
|
||||
|
||||
const getFieldsForGrantType = (authentication: Extract<RequestAuthentication, { type: typeof AUTH_OAUTH_2 }>) => {
|
||||
const getFieldsForGrantType = (authentication: Extract<RequestAuthentication, { type: 'oauth2' }>) => {
|
||||
const {
|
||||
clientId,
|
||||
clientSecret,
|
||||
|
||||
@@ -9,10 +9,10 @@ import { useWorkspaceLoaderData } from '~/routes/organization.$organizationId.pr
|
||||
import { CodeEditor, type CodeEditorHandle } from '~/ui/components/.client/codemirror/code-editor';
|
||||
import { OneLineEditor } from '~/ui/components/.client/codemirror/one-line-editor';
|
||||
|
||||
import { CONTENT_TYPE_JSON } from '../../../common/constants';
|
||||
import { type AuthTypes, CONTENT_TYPE_JSON } from '../../../common/constants';
|
||||
import * as models from '../../../models';
|
||||
import type { Environment } from '../../../models/environment';
|
||||
import { type AuthTypes, getCombinedPathParametersFromUrl, type RequestPathParameter } from '../../../models/request';
|
||||
import { getCombinedPathParametersFromUrl, type RequestPathParameter } from '../../../models/request';
|
||||
import type { WebSocketRequest } from '../../../models/websocket-request';
|
||||
import { getAuthObjectOrNull } from '../../../network/authentication';
|
||||
import {
|
||||
|
||||
Reference in New Issue
Block a user