MCPcopy Index your code
hub / github.com/massCodeIO/massCode / parseAuth

Function parseAuth

src/main/http/import/postman.ts:95–124  ·  view source on GitHub ↗
(
  rawAuth: unknown,
  source: string,
  warnings: HttpImportWarning[],
)

Source from the content-addressed store, hash-verified

93}
94
95function parseAuth(
96 rawAuth: unknown,
97 source: string,
98 warnings: HttpImportWarning[],
99): HttpAuth | null {
100 if (!isRecord(rawAuth)) {
101 return null
102 }
103
104 const type = asString(rawAuth.type).toLowerCase()
105 if (!type || type === 'noauth') {
106 return { type: 'none' }
107 }
108
109 if (type === 'bearer') {
110 const token = getKeyValueArrayValue(rawAuth.bearer, 'token') ?? ''
111 return { token, type: 'bearer' }
112 }
113
114 if (type === 'basic') {
115 return {
116 password: getKeyValueArrayValue(rawAuth.basic, 'password') ?? '',
117 type: 'basic',
118 username: getKeyValueArrayValue(rawAuth.basic, 'username') ?? '',
119 }
120 }
121
122 addWarning(warnings, source, `Unsupported auth type "${type}" skipped`)
123 return { type: 'none' }
124}
125
126function parseHeaders(rawHeaders: unknown): HttpHeaderEntry[] {
127 return asArray(rawHeaders)

Callers 3

parseRequestFunction · 0.70
walkItemsFunction · 0.70
parseCollectionFunction · 0.70

Calls 4

addWarningFunction · 0.90
getKeyValueArrayValueFunction · 0.85
isRecordFunction · 0.70
asStringFunction · 0.70

Tested by

no test coverage detected