Skip to content

Commit 4f24813

Browse files
committed
fix: cjs compat
1 parent 2f42033 commit 4f24813

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/keys/get-management-token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ export const createGetManagementToken = (
149149
* ~~~
150150
* @category Keys
151151
*/
152-
export const getManagementToken = (privateKey: string, opts: GetManagementTokenOptions) => {
152+
export const getManagementToken = async (privateKey: string, opts: GetManagementTokenOptions) => {
153153
if ((opts.reuseToken || opts.reuseToken === undefined) && !defaultCache) {
154154
defaultCache = new LRUCache({ max: 10 })
155155
}
156156
const httpClientOpts = typeof opts.host !== 'undefined' ? { prefixUrl: opts.host } : {}
157157

158158
return createGetManagementToken(
159159
createLogger({ filename: __filename }),
160-
createHttpClient(httpClientOpts),
160+
await createHttpClient(httpClientOpts),
161161
defaultCache!,
162162
)(privateKey, opts)
163163
}

src/utils/http.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ky, {
1+
import {
22
Options,
33
KyInstance,
44
HTTPError,
@@ -13,7 +13,8 @@ const config = {
1313
retry: { limit: 3 },
1414
}
1515

16-
export const createHttpClient = (configOverride: Options = {}) => {
16+
export const createHttpClient = async (configOverride: Options = {}) => {
17+
const { default: ky } = await import('ky')
1718
return ky.extend({ ...config, ...configOverride })
1819
}
1920

test/integration/keys.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('Keys Utilities', () => {
3232
environmentId,
3333
})
3434

35-
await assert.doesNotReject(() => {
36-
const http = createHttpClient()
35+
await assert.doesNotReject(async () => {
36+
const http = await createHttpClient()
3737

3838
return http.get(`spaces/${spaceId}/entries`, {
3939
headers: {

test/utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import base64url from 'base64url'
44

55
import { createHttpClient, createValidateStatusCode } from '../src/utils'
66

7-
const http = createHttpClient({
8-
headers: {
9-
Authorization: `Bearer ${process.env.PERSONAL_ACCESS_TOKEN}`,
10-
},
11-
})
7+
const httpFactory = async () =>
8+
await createHttpClient({
9+
headers: {
10+
Authorization: `Bearer ${process.env.PERSONAL_ACCESS_TOKEN}`,
11+
},
12+
})
1213

1314
export const cleanOldKeys = async () => {
1415
const organizationId = process.env.ORGANIZATION_ID
1516
const appDefinitionId = process.env.APP_ID
1617

18+
const http = await httpFactory()
1719
const { items } = await http
1820
.get(`organizations/${organizationId}/app_definitions/${appDefinitionId}/keys`)
1921
.json<{ items: { jwk: { x5t: string } }[] }>()
@@ -33,6 +35,7 @@ export const setPublicKey = async (publicKey: Buffer) => {
3335
const appDefinitionId = process.env.APP_ID
3436
const keyId = base64url(crypto.createHash('sha256').update(publicKey).digest())
3537

38+
const http = await httpFactory()
3639
return http.post(`organizations/${organizationId}/app_definitions/${appDefinitionId}/keys`, {
3740
json: {
3841
jwk: {

0 commit comments

Comments
 (0)