You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Docstrings generation was requested by @Mkassabov.
* #1073 (comment)
The following files were modified:
* `alchemy/src/cloudflare/snippet-rule.ts`
* `alchemy/src/cloudflare/snippet.ts`
* Removes a snippet rule identified by its ruleId from the specified zone.
296
+
*
297
+
* If the rule is the only snippet rule remaining, all snippet rules for the zone are deleted; otherwise the rule is removed and the remaining rules are updated.
298
+
*
299
+
* @param api - Cloudflare API client used to list and modify snippet rules
300
+
* @param zoneId - Zone identifier containing the snippet rule
301
+
* @param ruleId - Identifier of the snippet rule to remove
302
+
* @throws Errors encountered while listing, updating, or deleting rules are logged and rethrown
296
303
* @internal
297
304
*/
298
305
asyncfunctiondeleteSnippetRuleById(
@@ -343,8 +350,10 @@ async function deleteSnippetRuleById(
343
350
}
344
351
345
352
/**
346
-
* List all snippet rules in a zone
353
+
* Retrieve the snippet rules configured for the given zone.
354
+
*
347
355
* @internal
356
+
* @returns An array of `SnippetRuleResponse` objects representing the zone's snippet rules.
348
357
*/
349
358
exportasyncfunctionlistSnippetRules(
350
359
api: CloudflareApi,
@@ -357,7 +366,11 @@ export async function listSnippetRules(
357
366
}
358
367
359
368
/**
360
-
* Update snippet rules in a zone (replaces all rules)
369
+
* Replace all snippet rules for a Cloudflare zone with the provided set of rules.
370
+
*
371
+
* @param zoneId - The target zone identifier
372
+
* @param rules - Array of snippet rule inputs; each item should include `expression`, `snippetName`, optional `description`, and optional `enabled` (defaults to `true`)
373
+
* @returns The updated list of snippet rules as returned by the Cloudflare API
361
374
* @internal
362
375
*/
363
376
exportasyncfunctionupdateSnippetRules(
@@ -381,7 +394,10 @@ export async function updateSnippetRules(
381
394
}
382
395
383
396
/**
384
-
* Delete all snippet rules in a zone
397
+
* Remove all snippet rules for the given zone.
398
+
*
399
+
* Treats a missing resource (HTTP 404) as a successful no-op; throws an error for any other non-OK response.
400
+
*
385
401
* @internal
386
402
*/
387
403
exportasyncfunctiondeleteSnippetRules(
@@ -393,4 +409,4 @@ export async function deleteSnippetRules(
393
409
if(!response.ok&&response.status!==404){
394
410
thrownewError(`Failed to delete snippet rules: ${response.statusText}`);
* Uploads a JavaScript snippet to a Cloudflare zone, creating or replacing the named snippet.
272
+
*
268
273
* @internal
274
+
* @param zoneId - The Cloudflare zone identifier where the snippet will be stored
275
+
* @param snippetName - The unique name of the snippet within the zone
276
+
* @param content - The JavaScript source to upload as the snippet
277
+
* @throws If the Cloudflare API returns an error while creating or updating the snippet
269
278
*/
270
279
exportasyncfunctioncreateOrUpdateSnippet(
271
280
api: CloudflareApi,
@@ -302,8 +311,10 @@ export async function createOrUpdateSnippet(
302
311
}
303
312
304
313
/**
305
-
* Check if a snippet exists
314
+
* Determine whether a Cloudflare snippet with the given name exists in the specified zone.
315
+
*
306
316
* @internal
317
+
* @returns `true` if the snippet exists, `false` otherwise.
307
318
*/
308
319
exportasyncfunctionsnippetExists(
309
320
api: CloudflareApi,
@@ -315,8 +326,13 @@ export async function snippetExists(
315
326
}
316
327
317
328
/**
318
-
* Get a snippet by name
329
+
* Retrieve metadata for a Cloudflare snippet by name.
330
+
*
319
331
* @internal
332
+
* @param api - Cloudflare API client used to perform the request
333
+
* @param zoneId - Identifier of the Cloudflare zone containing the snippet
334
+
* @param snippetName - The name of the snippet to retrieve
335
+
* @returns The snippet metadata (`SnippetResponse`)
320
336
*/
321
337
exportasyncfunctiongetSnippet(
322
338
api: CloudflareApi,
@@ -330,8 +346,11 @@ export async function getSnippet(
330
346
}
331
347
332
348
/**
333
-
* Get the content of a snippet
349
+
* Retrieve the raw content of a Cloudflare snippet.
350
+
*
334
351
* @internal
352
+
* @returns The snippet's raw JavaScript content as a string.
353
+
* @throws When the Cloudflare API responds with an error for the snippet content request.
335
354
*/
336
355
exportasyncfunctiongetSnippetContent(
337
356
api: CloudflareApi,
@@ -350,8 +369,10 @@ export async function getSnippetContent(
350
369
}
351
370
352
371
/**
353
-
* List all snippets in a zone
372
+
* List all snippets for the given zone.
373
+
*
354
374
* @internal
375
+
* @returns An array of snippet metadata objects for the zone.
355
376
*/
356
377
exportasyncfunctionlistSnippets(
357
378
api: CloudflareApi,
@@ -364,8 +385,15 @@ export async function listSnippets(
364
385
}
365
386
366
387
/**
367
-
* Delete a snippet from Cloudflare
388
+
* Remove a named snippet from a Cloudflare zone.
389
+
*
390
+
* Deletes the snippet identified by `snippetName` in the given `zoneId`. Treats a 404 response
391
+
* and the Cloudflare 400 message "requested snippet not found" as successful deletions; other
392
+
* non-OK responses are propagated via API error handling.
393
+
*
368
394
* @internal
395
+
* @param zoneId - The Cloudflare zone identifier containing the snippet
396
+
* @param snippetName - The name of the snippet to delete
369
397
*/
370
398
exportasyncfunctiondeleteSnippet(
371
399
api: CloudflareApi,
@@ -388,10 +416,10 @@ export async function deleteSnippet(
388
416
}
389
417
390
418
/**
391
-
* Validates that a snippet name meets Cloudflare requirements due to strong restrictions on the name.
392
-
* Cloudflare Snippets only allow lowercase letters (a-z), numbers (0-9), and underscores (_)
419
+
* Ensures a snippet name conforms to Cloudflare's naming rules.
393
420
*
394
-
* @throws Error if the name does not meet Cloudflare snippet requirements
421
+
* @returns `true` if the name is valid.
422
+
* @throws Error if the name is empty, longer than 255 characters, or contains characters other than lowercase letters (a-z), numbers (0-9), or underscores (_).
0 commit comments