-
Notifications
You must be signed in to change notification settings - Fork 6
feat(dns): manage Scriptable DNS scripts with ambient runtime types #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
46f4aa2
feat(dns): manage Scriptable DNS scripts with ambient runtime types
jamie-at-bunny 9171b92
updates
jamie-at-bunny 57e43e4
link dns script
jamie-at-bunny 6464333
static-vs-scriptable
jamie-at-bunny a8f6bd1
fixes
jamie-at-bunny 916564c
update dns attach
jamie-at-bunny d775ff3
add comment about publish script
jamie-at-bunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@bunny.net/cli": patch | ||
| "@bunny.net/scriptable-dns-types": patch | ||
| --- | ||
|
|
||
| feat(dns): manage Scriptable DNS scripts (`bunny dns scripts` init/create/deploy/attach/link/list) with ambient runtime types in `@bunny.net/scriptable-dns-types`; `dns records add` offers a static or script-computed answer for A/AAAA/CNAME/TXT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| import { defineNamespace } from "../../core/define-namespace.ts"; | ||
| import { dnsRecordNamespace } from "./record/index.ts"; | ||
| import { dnsScriptsNamespace } from "./scripts/index.ts"; | ||
| import { dnsZoneHiddenAliases, dnsZoneNamespace } from "./zone/index.ts"; | ||
|
|
||
| // Hidden from help while experimental, matching the apps and registries namespaces. | ||
| export const dnsNamespace = defineNamespace("dns", false, [ | ||
| dnsRecordNamespace, | ||
| dnsZoneNamespace, | ||
| dnsScriptsNamespace, | ||
| ...dnsZoneHiddenAliases, | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import type { createComputeClient } from "@bunny.net/openapi-client"; | ||
| import type { components } from "@bunny.net/openapi-client/generated/compute.d.ts"; | ||
| import { UserError } from "../../../core/errors.ts"; | ||
| import { SCRIPT_TYPE_DNS } from "./constants.ts"; | ||
|
|
||
| export type ComputeClient = ReturnType<typeof createComputeClient>; | ||
| export type EdgeScript = components["schemas"]["EdgeScriptModel"]; | ||
|
|
||
| /** | ||
| * Fetch a single script by ID, throwing a UserError if it doesn't exist or is | ||
| * not a Scriptable DNS script. Guards callers from treating a CDN or Middleware | ||
| * Edge Script as a DNS script (linking it, deploying DNS code, or attaching it). | ||
| */ | ||
| export async function fetchDnsScript( | ||
| client: ComputeClient, | ||
| id: number, | ||
| ): Promise<EdgeScript> { | ||
| const { data } = await client.GET("/compute/script/{id}", { | ||
| params: { path: { id } }, | ||
| }); | ||
| if (!data) throw new UserError(`DNS script ${id} not found.`); | ||
| if (data.ScriptType !== SCRIPT_TYPE_DNS) { | ||
| throw new UserError( | ||
| `Script ${id} is not a Scriptable DNS script.`, | ||
| "Pass the ID of a DNS script, or create one with `bunny dns scripts create`.", | ||
| ); | ||
| } | ||
| return data; | ||
| } | ||
|
|
||
| /** Fetch all DNS scripts on the account, paginated and sorted by name. */ | ||
| export async function fetchDnsScripts( | ||
| client: ComputeClient, | ||
| ): Promise<EdgeScript[]> { | ||
| const scripts: EdgeScript[] = []; | ||
| let page = 1; | ||
| for (;;) { | ||
| const { data } = await client.GET("/compute/script", { | ||
| params: { query: { type: [SCRIPT_TYPE_DNS], page, perPage: 1000 } }, | ||
| }); | ||
| scripts.push(...(data?.Items ?? [])); | ||
| if (!data?.HasMoreItems) break; | ||
| page++; | ||
| } | ||
|
|
||
| return scripts.sort((a, b) => (a.Name ?? "").localeCompare(b.Name ?? "")); | ||
| } | ||
|
|
||
| /** Create a DNS script (no linked pull zone), returning its ID and name. */ | ||
| export async function createDnsScript( | ||
| client: ComputeClient, | ||
| name: string, | ||
| ): Promise<{ id: number; name: string }> { | ||
| const { data } = await client.POST("/compute/script", { | ||
| body: { | ||
| Name: name, | ||
| ScriptType: SCRIPT_TYPE_DNS, | ||
| CreateLinkedPullZone: false, | ||
| }, | ||
| }); | ||
|
|
||
| if (!data || data.Id == null) { | ||
| throw new UserError("Failed to create DNS script."); | ||
| } | ||
| return { id: data.Id, name: data.Name ?? name }; | ||
| } | ||
|
|
||
| /** Upload code to a DNS script, creating an unpublished deployment. */ | ||
| export async function uploadCode( | ||
| client: ComputeClient, | ||
| id: number, | ||
| code: string, | ||
| ): Promise<void> { | ||
| await client.POST("/compute/script/{id}/code", { | ||
| params: { path: { id } }, | ||
| body: { Code: code }, | ||
| }); | ||
| } | ||
|
|
||
| /** Publish the latest uploaded code as the live release. */ | ||
| export async function publishScript( | ||
| client: ComputeClient, | ||
| id: number, | ||
| ): Promise<void> { | ||
| // The {id}/publish path has no {uuid} token (and null is skipped anyway), so this publishes the latest release. | ||
| await client.POST("/compute/script/{id}/publish", { | ||
| params: { path: { id, uuid: null } }, | ||
| body: {}, | ||
| }); | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.