Skip to content

Commit 0049a06

Browse files
authored
feat: expose fetch utils (#1217)
## 🧰 Changes exposes a handful of utils in a new `rdme/utils` export. figured this would be a good spot to add more as we think of them. ## 🧬 QA & Testing do tests pass?
1 parent 9638f3a commit 0049a06

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

knip.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { KnipConfig } from 'knip';
22

33
const config: KnipConfig = {
4-
entry: ['src/index.ts', 'src/types.ts', 'src/lib/help.ts', 'bin/*.js'],
4+
entry: ['src/index.ts', 'src/types.ts', 'src/utils.ts', 'src/lib/help.ts', 'bin/*.js'],
55
ignore: ['dist-gha/**'],
66
// we're choosing not to include semantic release deps in our main dev-deps
77
// since we're only using it in CI

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
"swagger"
3434
],
3535
"exports": {
36-
"./types": "./dist/types.js"
36+
".": "./dist/index.js",
37+
"./types": "./dist/types.js",
38+
"./utils": "./dist/utils.js"
3739
},
3840
"repository": {
3941
"type": "git",

src/lib/readmeAPIFetch.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { SpecFileType } from './prepareOas.js';
22
import type { CommandClass } from '../index.js';
33
import type { CommandsThatSyncMarkdown } from './syncPagePath.js';
4+
import type { Hook } from '@oclif/core';
45
import type { SchemaObject } from 'oas/types';
56

67
import path from 'node:path';
@@ -227,7 +228,7 @@ export async function readmeAPIv1Fetch(
227228
* Wrapper for the `fetch` API so we can add rdme-specific headers to all ReadMe API v2 requests.
228229
*/
229230
export async function readmeAPIv2Fetch(
230-
this: CommandClass['prototype'],
231+
this: CommandClass['prototype'] | Hook.Context,
231232
/** The pathname to make the request to. Must have a leading slash. */
232233
pathname: string,
233234
options: RequestInit = { headers: new Headers() },
@@ -367,7 +368,7 @@ export async function handleAPIv1Res(
367368
* If we receive non-JSON responses, we consider them errors and throw them.
368369
*/
369370
export async function handleAPIv2Res(
370-
this: CommandClass['prototype'],
371+
this: CommandClass['prototype'] | Hook.Context,
371372
res: Response,
372373
/**
373374
* If we're making a request where we don't care about the body (e.g. a HEAD or DELETE request),

src/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { readmeAPIv2Fetch, handleAPIv2Res } from './lib/readmeAPIFetch.js';

0 commit comments

Comments
 (0)