@alteran/astro 0.8.3 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -3,10 +3,14 @@ import { isAbsolute, relative } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
 
5
5
  const CORE_ROUTES = [
6
- { pattern: '/.well-known/atproto-did', entrypoint: './src/pages/.well-known/atproto-did.ts' },
7
- { pattern: '/.well-known/did.json', entrypoint: './src/pages/.well-known/did.json.ts' },
8
- { pattern: '/.well-known/oauth-authorization-server', entrypoint: './src/pages/.well-known/oauth-authorization-server.ts' },
9
- { pattern: '/.well-known/oauth-protected-resource', entrypoint: './src/pages/.well-known/oauth-protected-resource.ts' },
6
+ { pattern: '/.well-known/atproto-did', entrypoint: './src/entrypoints/well-known/atproto-did.ts' },
7
+ { pattern: '/.well-known/did.json', entrypoint: './src/entrypoints/well-known/did.json.ts' },
8
+ { pattern: '/.well-known/oauth-authorization-server', entrypoint: './src/entrypoints/well-known/oauth-authorization-server.ts' },
9
+ { pattern: '/.well-known/oauth-protected-resource', entrypoint: './src/entrypoints/well-known/oauth-protected-resource.ts' },
10
+ { pattern: '/well-known/atproto-did', entrypoint: './src/pages/well-known/atproto-did.ts' },
11
+ { pattern: '/well-known/did.json', entrypoint: './src/pages/well-known/did.json.ts' },
12
+ { pattern: '/well-known/oauth-authorization-server', entrypoint: './src/pages/well-known/oauth-authorization-server.ts' },
13
+ { pattern: '/well-known/oauth-protected-resource', entrypoint: './src/pages/well-known/oauth-protected-resource.ts' },
10
14
  { pattern: '/health', entrypoint: './src/pages/health.ts' },
11
15
  { pattern: '/oauth/authorize', entrypoint: './src/pages/oauth/authorize.ts' },
12
16
  { pattern: '/oauth/consent', entrypoint: './src/pages/oauth/consent.ts' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alteran/astro",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Astro integration for running a Cloudflare-hosted Bluesky PDS with Alteran.",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,5 +1,8 @@
1
- import type { APIContext } from 'astro';
2
- import { configuredDid, requestMatchesConfiguredHandle } from '../../lib/public-host';
1
+ import type { APIContext } from "astro";
2
+ import {
3
+ configuredDid,
4
+ requestMatchesConfiguredHandle,
5
+ } from "../../lib/public-host";
3
6
 
4
7
  export const prerender = false;
5
8
 
@@ -7,13 +10,13 @@ export async function GET({ locals, request }: APIContext) {
7
10
  const { env } = locals.runtime;
8
11
 
9
12
  if (!await requestMatchesConfiguredHandle(request, env)) {
10
- return new Response('NotFound', {
13
+ return new Response("NotFound", {
11
14
  status: 404,
12
- headers: { 'Content-Type': 'text/plain' },
15
+ headers: { "Content-Type": "text/plain" },
13
16
  });
14
17
  }
15
18
 
16
19
  return new Response(await configuredDid(env), {
17
- headers: { 'Content-Type': 'text/plain' },
20
+ headers: { "Content-Type": "text/plain" },
18
21
  });
19
22
  }
@@ -1,14 +1,14 @@
1
- import type { APIContext } from 'astro';
2
- import { errorMessage } from '../../lib/errors';
3
- import { withCache, CACHE_CONFIGS } from '../../lib/cache';
4
- import { resolveSecret } from '../../lib/secrets';
5
- import { Secp256k1Keypair, formatMultikey } from '@atproto/crypto';
1
+ import type { APIContext } from "astro";
2
+ import { errorMessage } from "../../lib/errors";
3
+ import { CACHE_CONFIGS, withCache } from "../../lib/cache";
4
+ import { resolveSecret } from "../../lib/secrets";
5
+ import { formatMultikey, Secp256k1Keypair } from "@atproto/crypto";
6
6
  import {
7
7
  canonicalPdsOrigin,
8
8
  configuredDid,
9
9
  configuredHandle,
10
10
  validAtprotoHandle,
11
- } from '../../lib/public-host';
11
+ } from "../../lib/public-host";
12
12
 
13
13
  export const prerender = false;
14
14
 
@@ -28,15 +28,15 @@ export async function GET({ locals, request }: APIContext) {
28
28
  try {
29
29
  const signingKey = await resolveSecret((env as any).REPO_SIGNING_KEY);
30
30
  if (!signingKey) {
31
- signingKeyError = 'REPO_SIGNING_KEY not configured';
32
- console.warn('did.json: REPO_SIGNING_KEY not configured');
31
+ signingKeyError = "REPO_SIGNING_KEY not configured";
32
+ console.warn("did.json: REPO_SIGNING_KEY not configured");
33
33
  } else {
34
34
  const cleaned = signingKey.trim();
35
35
  let kp: Secp256k1Keypair;
36
36
  if (/^[0-9a-fA-F]{64}$/.test(cleaned)) {
37
37
  kp = await Secp256k1Keypair.import(cleaned);
38
38
  } else {
39
- const bin = atob(cleaned.replace(/\s+/g, ''));
39
+ const bin = atob(cleaned.replace(/\s+/g, ""));
40
40
  const bytes = new Uint8Array(bin.length);
41
41
  for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
42
42
  kp = await Secp256k1Keypair.import(bytes);
@@ -44,25 +44,27 @@ export async function GET({ locals, request }: APIContext) {
44
44
  publicKeyMultibase = formatMultikey(kp.jwtAlg, kp.publicKeyBytes());
45
45
  }
46
46
  } catch (error) {
47
- signingKeyError = `Failed to process REPO_SIGNING_KEY: ${errorMessage(error) || error}`;
48
- console.error('did.json: Failed to process REPO_SIGNING_KEY:', error);
47
+ signingKeyError = `Failed to process REPO_SIGNING_KEY: ${
48
+ errorMessage(error) || error
49
+ }`;
50
+ console.error("did.json: Failed to process REPO_SIGNING_KEY:", error);
49
51
  }
50
52
 
51
53
  const verificationMethods = publicKeyMultibase
52
54
  ? [
53
- {
54
- id: `${did}#atproto`,
55
- type: 'Multikey',
56
- controller: did,
57
- publicKeyMultibase,
58
- },
59
- ]
55
+ {
56
+ id: `${did}#atproto`,
57
+ type: "Multikey",
58
+ controller: did,
59
+ publicKeyMultibase,
60
+ },
61
+ ]
60
62
  : [];
61
63
 
62
64
  const didDocument: Record<string, unknown> = {
63
- '@context': [
64
- 'https://www.w3.org/ns/did/v1',
65
- 'https://w3id.org/security/multikey/v1',
65
+ "@context": [
66
+ "https://www.w3.org/ns/did/v1",
67
+ "https://w3id.org/security/multikey/v1",
66
68
  ],
67
69
  id: did,
68
70
  alsoKnownAs: claimedHandle ? [`at://${claimedHandle}`] : [],
@@ -70,20 +72,20 @@ export async function GET({ locals, request }: APIContext) {
70
72
  service: [
71
73
  {
72
74
  id: `${did}#atproto_pds`,
73
- type: 'AtprotoPersonalDataServer',
75
+ type: "AtprotoPersonalDataServer",
74
76
  serviceEndpoint,
75
77
  },
76
78
  ],
77
79
  };
78
80
 
79
81
  // Add debug info if signing key has issues (only visible in dev/debug)
80
- if (signingKeyError && (env as any).ENVIRONMENT !== 'production') {
82
+ if (signingKeyError && (env as any).ENVIRONMENT !== "production") {
81
83
  didDocument._debug = { signingKeyError };
82
84
  }
83
85
 
84
86
  return new Response(JSON.stringify(didDocument, null, 2), {
85
87
  headers: {
86
- 'Content-Type': 'application/json',
88
+ "Content-Type": "application/json",
87
89
  },
88
90
  });
89
91
  },
@@ -1,6 +1,6 @@
1
- import type { APIContext } from 'astro';
2
- import { withCache, CACHE_CONFIGS } from '../../lib/cache';
3
- import { publicPdsOrigin } from '../../lib/oauth/consent';
1
+ import type { APIContext } from "astro";
2
+ import { CACHE_CONFIGS, withCache } from "../../lib/cache";
3
+ import { publicPdsOrigin } from "../../lib/oauth/consent";
4
4
 
5
5
  export const prerender = false;
6
6
 
@@ -17,16 +17,16 @@ export async function GET({ locals, request }: APIContext) {
17
17
  token_endpoint: `${origin}/oauth/token`,
18
18
  jwks_uri: `${origin}/oauth/jwks`,
19
19
  revocation_endpoint: `${origin}/oauth/revoke`,
20
- scopes_supported: ['atproto', 'transition:generic'],
21
- response_types_supported: ['code'],
22
- response_modes_supported: ['query'],
23
- grant_types_supported: ['authorization_code', 'refresh_token'],
24
- code_challenge_methods_supported: ['S256'],
25
- token_endpoint_auth_methods_supported: ['none', 'private_key_jwt'],
26
- token_endpoint_auth_signing_alg_values_supported: ['ES256'],
27
- dpop_signing_alg_values_supported: ['ES256'],
28
- subject_types_supported: ['public'],
29
- prompt_values_supported: ['none', 'consent', 'login'],
20
+ scopes_supported: ["atproto", "transition:generic"],
21
+ response_types_supported: ["code"],
22
+ response_modes_supported: ["query"],
23
+ grant_types_supported: ["authorization_code", "refresh_token"],
24
+ code_challenge_methods_supported: ["S256"],
25
+ token_endpoint_auth_methods_supported: ["none", "private_key_jwt"],
26
+ token_endpoint_auth_signing_alg_values_supported: ["ES256"],
27
+ dpop_signing_alg_values_supported: ["ES256"],
28
+ subject_types_supported: ["public"],
29
+ prompt_values_supported: ["none", "consent", "login"],
30
30
  require_pushed_authorization_requests: true,
31
31
  request_parameter_supported: false,
32
32
  request_uri_parameter_supported: true,
@@ -35,7 +35,7 @@ export async function GET({ locals, request }: APIContext) {
35
35
  protected_resources: [origin],
36
36
  };
37
37
  return new Response(JSON.stringify(json, null, 2), {
38
- headers: { 'Content-Type': 'application/json' },
38
+ headers: { "Content-Type": "application/json" },
39
39
  });
40
40
  },
41
41
  CACHE_CONFIGS.WELL_KNOWN,
@@ -1,6 +1,6 @@
1
- import type { APIContext } from 'astro';
2
- import { withCache, CACHE_CONFIGS } from '../../lib/cache';
3
- import { publicPdsOrigin } from '../../lib/oauth/consent';
1
+ import type { APIContext } from "astro";
2
+ import { CACHE_CONFIGS, withCache } from "../../lib/cache";
3
+ import { publicPdsOrigin } from "../../lib/oauth/consent";
4
4
 
5
5
  export const prerender = false;
6
6
 
@@ -13,12 +13,13 @@ export async function GET({ locals, request }: APIContext) {
13
13
  const json = {
14
14
  resource: origin,
15
15
  authorization_servers: [origin],
16
- bearer_methods_supported: ['header'],
17
- scopes_supported: ['atproto', 'transition:generic'],
18
- resource_documentation: `${origin}/.well-known/oauth-protected-resource`,
16
+ bearer_methods_supported: ["header"],
17
+ scopes_supported: ["atproto", "transition:generic"],
18
+ resource_documentation:
19
+ `${origin}/.well-known/oauth-protected-resource`,
19
20
  };
20
21
  return new Response(JSON.stringify(json, null, 2), {
21
- headers: { 'Content-Type': 'application/json' },
22
+ headers: { "Content-Type": "application/json" },
22
23
  });
23
24
  },
24
25
  CACHE_CONFIGS.WELL_KNOWN,
@@ -0,0 +1,9 @@
1
+ export function redirectWellKnownAlias(request: Request): Response | null {
2
+ const url = new URL(request.url);
3
+ if (!url.pathname.startsWith("/well-known/")) {
4
+ return null;
5
+ }
6
+
7
+ url.pathname = `/.${url.pathname.slice(1)}`;
8
+ return Response.redirect(url, 308);
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { APIContext } from "astro";
2
+ import { redirectWellKnownAlias } from "../../lib/well-known-redirect";
3
+
4
+ export const prerender = false;
5
+
6
+ export function GET({ request }: APIContext) {
7
+ return redirectWellKnownAlias(request) ??
8
+ new Response("NotFound", { status: 404 });
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { APIContext } from "astro";
2
+ import { redirectWellKnownAlias } from "../../lib/well-known-redirect";
3
+
4
+ export const prerender = false;
5
+
6
+ export function GET({ request }: APIContext) {
7
+ return redirectWellKnownAlias(request) ??
8
+ new Response("NotFound", { status: 404 });
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { APIContext } from "astro";
2
+ import { redirectWellKnownAlias } from "../../lib/well-known-redirect";
3
+
4
+ export const prerender = false;
5
+
6
+ export function GET({ request }: APIContext) {
7
+ return redirectWellKnownAlias(request) ??
8
+ new Response("NotFound", { status: 404 });
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { APIContext } from "astro";
2
+ import { redirectWellKnownAlias } from "../../lib/well-known-redirect";
3
+
4
+ export const prerender = false;
5
+
6
+ export function GET({ request }: APIContext) {
7
+ return redirectWellKnownAlias(request) ??
8
+ new Response("NotFound", { status: 404 });
9
+ }