Skip to content

Commit d11c245

Browse files
authored
Merge pull request #20 from cloudflare/prettify
Ran prettier over whole project to reduce merge noise later
2 parents 96fb975 + a9b5776 commit d11c245

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2186
-2104
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.md
2+
*.yaml

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
import { init } from './init'
33
import { config, log } from './utils/helpers'
44
import { main } from './main'
5-
import { getAuthTokens, isAccessTokenExpired, LocalState, refreshToken, ensureWranglerAuthentication } from './utils/wrangler'
5+
import {
6+
getAuthTokens,
7+
isAccessTokenExpired,
8+
LocalState,
9+
refreshToken,
10+
ensureWranglerAuthentication,
11+
} from './utils/wrangler'
612

713
// Handle process events
814
process.on('uncaughtException', (error) => {
@@ -37,7 +43,7 @@ if (cmd === 'init') {
3743
if (!isAuthenticated) {
3844
throw new Error('Failed to authenticate with Wrangler. Please run `npx wrangler login` manually and try again.')
3945
}
40-
46+
4147
// Set the API token from the authenticated state
4248
config.apiToken = LocalState.accessToken?.value
4349
}

src/init.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
// Shell out to `npx wrangler@latest whoami`
22
import { exec } from 'child_process'
33
import { promisify } from 'util'
4-
import {
5-
AccountInfo,
6-
ensureWranglerAuthentication,
7-
fetchInternal,
8-
FetchResult,
9-
isDirectory,
10-
} from './utils/wrangler'
4+
import { AccountInfo, ensureWranglerAuthentication, fetchInternal, FetchResult, isDirectory } from './utils/wrangler'
115
import chalk from 'chalk'
126
import os from 'node:os'
137
import path from 'node:path'
@@ -37,7 +31,9 @@ export async function init(accountTag: string | undefined) {
3731

3832
const authenticated = await ensureWranglerAuthentication()
3933
if (!authenticated) {
40-
throw new Error('Failed to authenticate with Wrangler. Please try running npx wrangler@latest login manually and then retry.')
34+
throw new Error(
35+
'Failed to authenticate with Wrangler. Please try running npx wrangler@latest login manually and then retry.',
36+
)
4137
}
4238

4339
updateStatus(`Wrangler auth info loaded!`)

src/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import { WRANGLER_HANDLERS, WRANGLER_TOOLS } from './tools/wrangler'
2626
// Combine all tools
2727

2828
const ALL_TOOLS = [
29-
...KV_TOOLS,
30-
...WORKER_TOOLS,
31-
...ANALYTICS_TOOLS,
32-
...R2_TOOLS,
29+
...KV_TOOLS,
30+
...WORKER_TOOLS,
31+
...ANALYTICS_TOOLS,
32+
...R2_TOOLS,
3333
...D1_TOOLS,
3434
...DURABLE_OBJECTS_TOOLS,
3535
...QUEUES_TOOLS,
@@ -43,7 +43,7 @@ const ALL_TOOLS = [
4343
...ZONES_TOOLS,
4444
...SECRETS_TOOLS,
4545
...VERSIONS_TOOLS,
46-
...WRANGLER_TOOLS
46+
...WRANGLER_TOOLS,
4747
]
4848

4949
// Create server

src/tools/analytics.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const WORKERS_ANALYTICS_SEARCH_TOOL: Tool = {
5555
status: {
5656
type: 'string',
5757
description: 'Filter by status (e.g., "success", "error")',
58-
}
58+
},
5959
},
6060
required: ['accountId'],
6161
},
@@ -64,16 +64,16 @@ const WORKERS_ANALYTICS_SEARCH_TOOL: Tool = {
6464
export const ANALYTICS_TOOLS = [ANALYTICS_GET_TOOL, WORKERS_ANALYTICS_SEARCH_TOOL]
6565

6666
interface GraphQLResponse {
67-
data?: any;
67+
data?: any
6868
errors?: Array<{
69-
message: string;
69+
message: string
7070
locations?: Array<{
71-
line: number;
72-
column: number;
73-
}>;
74-
path?: string[];
75-
extensions?: Record<string, any>;
76-
}>;
71+
line: number
72+
column: number
73+
}>
74+
path?: string[]
75+
extensions?: Record<string, any>
76+
}>
7777
}
7878

7979
export const ANALYTICS_HANDLERS: ToolHandlers = {
@@ -125,24 +125,24 @@ export const ANALYTICS_HANDLERS: ToolHandlers = {
125125
throw new Error(`Analytics API error: ${await analyticsResponse.text()}`)
126126
}
127127

128-
const analyticsData = await analyticsResponse.json() as GraphQLResponse
129-
128+
const analyticsData = (await analyticsResponse.json()) as GraphQLResponse
129+
130130
// Check for GraphQL errors
131131
if (analyticsData.errors) {
132132
throw new Error(`GraphQL error: ${JSON.stringify(analyticsData.errors)}`)
133133
}
134-
134+
135135
return {
136136
content: [
137137
{
138138
type: 'text',
139139
text: JSON.stringify(analyticsData, null, 2),
140140
},
141141
],
142-
metadata: {}
142+
metadata: {},
143143
}
144144
},
145-
145+
146146
workers_analytics_search: async (request) => {
147147
const { accountId, scriptName, startTime, endTime, limit, status } = request.params.arguments as {
148148
accountId: string
@@ -152,31 +152,31 @@ export const ANALYTICS_HANDLERS: ToolHandlers = {
152152
limit?: number
153153
status?: string
154154
}
155-
155+
156156
// Set default time range if not provided (last 24 hours)
157157
const now = new Date()
158158
const defaultEndTime = now.toISOString()
159159
const defaultStartTime = new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString()
160-
160+
161161
const datetimeStart = startTime || defaultStartTime
162162
const datetimeEnd = endTime || defaultEndTime
163163
const resultLimit = limit || 100
164-
164+
165165
// Build filter object for the GraphQL query
166166
const filter: Record<string, any> = {
167167
datetime_geq: datetimeStart,
168-
datetime_leq: datetimeEnd
168+
datetime_leq: datetimeEnd,
169169
}
170-
170+
171171
// Add optional filters if provided
172172
if (scriptName) {
173173
filter.scriptName = scriptName
174174
}
175-
175+
176176
if (status) {
177177
filter.status = status
178178
}
179-
179+
180180
// Construct the GraphQL query
181181
const graphqlQuery = {
182182
query: `
@@ -206,8 +206,8 @@ export const ANALYTICS_HANDLERS: ToolHandlers = {
206206
variables: {
207207
accountTag: accountId,
208208
limit: resultLimit,
209-
filter: filter
210-
}
209+
filter: filter,
210+
},
211211
}
212212

213213
try {
@@ -224,13 +224,13 @@ export const ANALYTICS_HANDLERS: ToolHandlers = {
224224
throw new Error(`Workers Analytics API error: ${await analyticsResponse.text()}`)
225225
}
226226

227-
const analyticsData = await analyticsResponse.json() as GraphQLResponse
228-
227+
const analyticsData = (await analyticsResponse.json()) as GraphQLResponse
228+
229229
// Check for GraphQL errors
230230
if (analyticsData.errors) {
231231
throw new Error(`GraphQL error: ${JSON.stringify(analyticsData.errors)}`)
232232
}
233-
233+
234234
return {
235235
toolResult: {
236236
content: [

0 commit comments

Comments
 (0)