Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 507bc3a

Browse files
committed
readme, release please, lint
1 parent 46cf903 commit 507bc3a

File tree

8 files changed

+123
-23
lines changed

8 files changed

+123
-23
lines changed

.github/workflows/release-please.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,14 @@ jobs:
218218
fi
219219
env:
220220
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
221+
- if:
222+
${{ steps.release.outputs['packages/ai-gateway--release_created'] || github.event_name == 'workflow_dispatch'
223+
}}
224+
run: |
225+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
226+
npm publish packages/ai-gateway/ --provenance --access=public || true
227+
else
228+
npm publish packages/ai-gateway/ --provenance --access=public
229+
fi
230+
env:
231+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ npm run dev
2929

3030
| Name | Description | Version |
3131
| --------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
32+
| 🤖 [@netlify/ai-gateway](packages/ai-gateway) | Netlify AI Gateway integration for local development | [![npm version](https://img.shields.io/npm/v/@netlify/ai-gateway.svg)](https://www.npmjs.com/package/@netlify/ai-gateway) |
3233
| 🗄️ [@netlify/blobs](packages/blobs) | TypeScript client for Netlify Blobs | [![npm version](https://img.shields.io/npm/v/@netlify/blobs.svg)](https://www.npmjs.com/package/@netlify/blobs) |
3334
| 💾 [@netlify/cache](packages/cache) | TypeScript utilities for interacting with the Netlify cache | [![npm version](https://img.shields.io/npm/v/@netlify/cache.svg)](https://www.npmjs.com/package/@netlify/cache) |
3435
| 🛠️ [@netlify/dev](packages/dev) | Emulation of the Netlify environment for local development | [![npm version](https://img.shields.io/npm/v/@netlify/dev.svg)](https://www.npmjs.com/package/@netlify/dev) |

package-lock.json

Lines changed: 102 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ai-gateway/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

packages/ai-gateway/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"publint": "npx -y publint --strict"
4343
},
4444
"dependencies": {
45-
"@netlify/api": "workspace:*"
45+
"@netlify/api": "^14.0.4"
4646
},
4747
"devDependencies": {
4848
"@types/node": "20.14.15",
@@ -54,4 +54,4 @@
5454
"peerDependencies": {
5555
"@netlify/api": ">=14.0.0"
5656
}
57-
}
57+
}

packages/ai-gateway/src/main.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import type { NetlifyAPI } from '@netlify/api'
55
const mockFetch = vi.fn()
66
vi.stubGlobal('fetch', mockFetch)
77

8-
vi.stubGlobal('Buffer', {
9-
from: (str: string, encoding?: string) => {
10-
if (encoding === 'base64') {
11-
return { toString: () => atob(str) }
12-
}
13-
return { toString: (encoding?: string) => (encoding === 'base64' ? btoa(str) : str) }
14-
},
15-
})
8+
// Node.js environment has Buffer available, no need to mock it
169

1710
describe('fetchAIGatewayToken', () => {
1811
const mockApi: NetlifyAPI = {
@@ -142,7 +135,7 @@ describe('setupAIGateway', () => {
142135
await setupAIGateway(config)
143136

144137
expect(env).toHaveProperty('AI_GATEWAY')
145-
expect((env as any).AI_GATEWAY.sources).toEqual(['internal'])
138+
expect((env as { AI_GATEWAY: { sources: string[] } }).AI_GATEWAY.sources).toEqual(['internal'])
146139
expect(process.env.AI_GATEWAY).toBeDefined()
147140
})
148141

@@ -202,7 +195,7 @@ describe('parseAIGatewayContext', () => {
202195

203196
test('parses valid AI Gateway context', () => {
204197
const contextData = { token: 'test-token', url: 'https://example.com/.netlify/ai' }
205-
const base64Data = btoa(JSON.stringify(contextData))
198+
const base64Data = Buffer.from(JSON.stringify(contextData)).toString('base64')
206199
process.env.AI_GATEWAY = base64Data
207200

208201
const result = parseAIGatewayContext()
@@ -225,7 +218,7 @@ describe('parseAIGatewayContext', () => {
225218
})
226219

227220
test('returns undefined when AI_GATEWAY contains invalid JSON', () => {
228-
process.env.AI_GATEWAY = btoa('invalid-json')
221+
process.env.AI_GATEWAY = Buffer.from('invalid-json').toString('base64')
229222

230223
const result = parseAIGatewayContext()
231224

packages/ai-gateway/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const setupAIGateway = async (config: AIGatewayConfig): Promise<void> =>
8484
env.AI_GATEWAY = { sources: ['internal'], value: base64Payload }
8585

8686
// Also set process env for compatibility
87-
if (typeof process !== 'undefined' && process.env) {
87+
if (typeof process !== 'undefined') {
8888
process.env.AI_GATEWAY = base64Payload
8989
}
9090
}

packages/ai-gateway/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default defineConfig({
88
include: ['src/**/*.test.ts'],
99
testTimeout: 30_000,
1010
},
11-
})
11+
})

0 commit comments

Comments
 (0)