|
| 1 | +// Taken from https://github.com/Kong/insomnia/blob/aeb12e0/packages/insomnia/src/main/importers/importers/curl.ts |
| 2 | +// Used under MIT license, see repo for details, see git history for modifications. |
| 3 | + |
| 4 | +import type * as Har from 'har-format'; |
| 5 | + |
| 6 | +export interface Comment { |
| 7 | + comment?: string; |
| 8 | +} |
| 9 | + |
| 10 | +export type Variable = `{{ ${string} }}`; |
| 11 | + |
| 12 | +export interface Authentication extends Comment { |
| 13 | + authorizationUrl?: string; |
| 14 | + accessTokenUrl?: string; |
| 15 | + clientId?: string; |
| 16 | + clientSecret?: Variable; |
| 17 | + scope?: string; |
| 18 | + type?: 'basic' | 'oauth2'; |
| 19 | + grantType?: 'authorization_code' | 'password' | 'client_credentials'; |
| 20 | + disabled?: boolean; |
| 21 | + username?: string; |
| 22 | + password?: string; |
| 23 | +} |
| 24 | + |
| 25 | +export interface Parameter extends Comment { |
| 26 | + name: string; |
| 27 | + value?: string; |
| 28 | + filename?: string; |
| 29 | + fileName?: string; |
| 30 | + disabled?: boolean; |
| 31 | + type?: 'file' | string; |
| 32 | +} |
| 33 | + |
| 34 | +export interface PathParameters { |
| 35 | + name: string; |
| 36 | + value?: string; |
| 37 | +} |
| 38 | + |
| 39 | +export type Body = |
| 40 | + | string |
| 41 | + | { |
| 42 | + mimeType?: string; |
| 43 | + text?: string; |
| 44 | + params?: Parameter[]; |
| 45 | + }; |
| 46 | + |
| 47 | +export interface Cookie { |
| 48 | + name: string; |
| 49 | + value: string; |
| 50 | +} |
| 51 | + |
| 52 | +export interface Header extends Comment { |
| 53 | + name: 'Cookie' | 'Content-Type' | string; |
| 54 | + disabled?: boolean; |
| 55 | + value: any; |
| 56 | +} |
| 57 | + |
| 58 | +export interface QueryString extends Comment { |
| 59 | + name: string; |
| 60 | +} |
| 61 | + |
| 62 | +export type ImportRequestType = 'environment' | 'request' | 'request_group' | 'workspace'; |
| 63 | + |
| 64 | +export interface ImportRequest extends Comment { |
| 65 | + _id?: string; |
| 66 | + // @TODO Fix me |
| 67 | + _type?: string; |
| 68 | + authentication?: Authentication; |
| 69 | + body?: Body; |
| 70 | + cookies?: Cookie[]; |
| 71 | + environment?: {}; |
| 72 | + headers?: Header[]; |
| 73 | + httpVersion?: string; |
| 74 | + method?: string; |
| 75 | + name?: string; |
| 76 | + data?: object; |
| 77 | + description?: string; |
| 78 | + parameters?: Parameter[]; |
| 79 | + pathParameters?: PathParameters[]; |
| 80 | + parentId?: string | null; |
| 81 | + postData?: Har.PostData; |
| 82 | + variable?: any; |
| 83 | + queryString?: QueryString[]; |
| 84 | + url?: string; |
| 85 | + preRequestScript?: string; |
| 86 | + afterResponseScript?: string; |
| 87 | + metaSortKey?: number; |
| 88 | + scope?: string; |
| 89 | +} |
| 90 | + |
| 91 | +interface ConvertErrorResult { |
| 92 | + convertErrorMessage: string; |
| 93 | +} |
| 94 | + |
| 95 | +type ConvertResult = ImportRequest[] | ConvertErrorResult | null; |
| 96 | + |
| 97 | +export type Converter = (rawData: string) => ConvertResult | Promise<ConvertResult>; |
| 98 | + |
| 99 | +export type FilePathConverter = (importEntry: ImportEntry) => ConvertResult | Promise<ConvertResult>; |
| 100 | + |
| 101 | +interface BaseImporter { |
| 102 | + id: string; |
| 103 | + name: string; |
| 104 | + description: string; |
| 105 | +} |
| 106 | + |
| 107 | +interface ContentStrImporter extends BaseImporter { |
| 108 | + acceptFilePath?: false; |
| 109 | + convert: Converter; |
| 110 | +} |
| 111 | + |
| 112 | +interface FilePathImporter extends BaseImporter { |
| 113 | + acceptFilePath: true; |
| 114 | + convert: FilePathConverter; |
| 115 | +} |
| 116 | + |
| 117 | +export type Importer = ContentStrImporter | FilePathImporter; |
| 118 | + |
| 119 | +export interface ImportEntry { |
| 120 | + contentStr: string; |
| 121 | + oriFileName?: string; |
| 122 | + oriFilePath?: string; |
| 123 | +} |
| 124 | + |
0 commit comments