Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Jan 27, 2025
1 parent c1deda4 commit 7c8793b
Show file tree
Hide file tree
Showing 33 changed files with 95 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .changeset/olive-teachers-yawn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@atproto/oauth-types": patch
---

Support environemnts not providing URL.canParse
Support environments not providing URL.canParse
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
],
"settings": {
"node": { "version": ">=18.7.0" },
"import/internal-regex": "^@atproto/",
"import/internal-regex": "^@atproto(?:-labs)?/",
"import/parsers": { "@typescript-eslint/parser": [".ts", ".tsx"] },
"import/resolver": {
"typescript": {
Expand Down
3 changes: 2 additions & 1 deletion packages/bsky/src/api/blob-dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isUnicastIp, unicastLookup } from '@atproto-labs/fetch-node'
import { Agent, Dispatcher, Pool, RetryAgent } from 'undici'

import { isUnicastIp, unicastLookup } from '@atproto-labs/fetch-node'

import { ServerConfig } from '../config'
import { RETRYABLE_HTTP_STATUS_CODES } from '../util/retry'

Expand Down
12 changes: 6 additions & 6 deletions packages/bsky/src/api/blob-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { Duplex, Transform, Writable } from 'node:stream'
import { pipeline } from 'node:stream/promises'

import {
ACCEPT_ENCODING_COMPRESSED,
ACCEPT_ENCODING_UNCOMPRESSED,
buildProxiedContentEncoding,
formatAcceptHeader,
} from '@atproto-labs/xrpc-utils'
import createError, { isHttpError } from 'http-errors'
import { CID } from 'multiformats/cid'
import { Dispatcher } from 'undici'
Expand All @@ -17,6 +11,12 @@ import {
createDecoders,
} from '@atproto/common'
import { AtprotoDid, isAtprotoDid } from '@atproto/did'
import {
ACCEPT_ENCODING_COMPRESSED,
ACCEPT_ENCODING_UNCOMPRESSED,
buildProxiedContentEncoding,
formatAcceptHeader,
} from '@atproto-labs/xrpc-utils'

import { ServerConfig } from '../config'
import { AppContext } from '../context'
Expand Down
3 changes: 1 addition & 2 deletions packages/internal/did-resolver/src/did-cache-memory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Did, DidDocument } from '@atproto/did'
import {
SimpleStoreMemory,
SimpleStoreMemoryOptions,
} from '@atproto-labs/simple-store-memory'

import { Did, DidDocument } from '@atproto/did'

import { DidCache } from './did-cache.js'

const DEFAULT_TTL = 3600 * 1000 // 1 hour
Expand Down
3 changes: 1 addition & 2 deletions packages/internal/did-resolver/src/did-cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CachedGetter, SimpleStore } from '@atproto-labs/simple-store'

import { Did, DidDocument } from '@atproto/did'
import { CachedGetter, SimpleStore } from '@atproto-labs/simple-store'

import { DidCacheMemory } from './did-cache-memory.js'
import { DidMethod, ResolveDidOptions } from './did-method.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/did-resolver/src/did-resolver-base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FetchError, FetchResponseError } from '@atproto-labs/fetch'
import { ZodError } from 'zod'

import { Did, DidError, extractDidMethod } from '@atproto/did'
import { FetchError, FetchResponseError } from '@atproto-labs/fetch'

import { DidMethod, DidMethods, ResolveDidOptions } from './did-method.js'
import { DidResolver, ResolvedDocument } from './did-resolver.js'
Expand Down
3 changes: 1 addition & 2 deletions packages/internal/did-resolver/src/methods/plc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Did, assertDidPlc, didDocumentValidator } from '@atproto/did'
import {
Fetch,
bindFetch,
Expand All @@ -7,8 +8,6 @@ import {
} from '@atproto-labs/fetch'
import { pipe } from '@atproto-labs/pipe'

import { Did, assertDidPlc, didDocumentValidator } from '@atproto/did'

import { DidMethod, ResolveDidOptions } from '../did-method.js'

const fetchSuccessHandler = pipe(
Expand Down
3 changes: 1 addition & 2 deletions packages/internal/did-resolver/src/methods/web.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Did, DidError, didDocumentValidator, didWebToUrl } from '@atproto/did'
import {
Fetch,
bindFetch,
Expand All @@ -7,8 +8,6 @@ import {
} from '@atproto-labs/fetch'
import { pipe } from '@atproto-labs/pipe'

import { Did, DidError, didDocumentValidator, didWebToUrl } from '@atproto/did'

import { DidMethod, ResolveDidOptions } from '../did-method.js'

const fetchSuccessHandler = pipe(
Expand Down
7 changes: 4 additions & 3 deletions packages/internal/fetch-node/src/unicast.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import dns, { LookupAddress } from 'node:dns'
import { LookupFunction } from 'node:net'

import ipaddr from 'ipaddr.js'
import { parse as pslParse } from 'psl'
import { Agent, Client } from 'undici'

import {
Fetch,
FetchContext,
FetchRequestError,
asRequest,
extractUrl,
} from '@atproto-labs/fetch'
import ipaddr from 'ipaddr.js'
import { parse as pslParse } from 'psl'
import { Agent, Client } from 'undici'

import { isUnicastIp } from './util.js'

Expand Down
3 changes: 2 additions & 1 deletion packages/internal/fetch/src/fetch-response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Transformer, pipe } from '@atproto-labs/pipe'
import type { ParseParams, TypeOf, ZodTypeAny } from 'zod'

import { Transformer, pipe } from '@atproto-labs/pipe'

import { FetchError } from './fetch-error.js'
import { TransformedResponse } from './transformed-response.js'
import {
Expand Down
3 changes: 1 addition & 2 deletions packages/internal/identity-resolver/src/identity-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { normalizeAndEnsureValidHandle } from '@atproto/syntax'
import {
Did,
DidDocument,
Expand All @@ -13,8 +14,6 @@ import {
isResolvedHandle,
} from '@atproto-labs/handle-resolver'

import { normalizeAndEnsureValidHandle } from '@atproto/syntax'

export type ResolvedIdentity = {
did: NonNullable<ResolvedHandle>
pds: URL
Expand Down
3 changes: 2 additions & 1 deletion packages/internal/simple-store-memory/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Key, SimpleStore, Value } from '@atproto-labs/simple-store'
import { LRUCache } from 'lru-cache'

import { Key, SimpleStore, Value } from '@atproto-labs/simple-store'

import { roughSizeOfObject } from './util.js'

export type SimpleStoreMemoryOptions<K extends Key, V extends Value> = {
Expand Down
7 changes: 4 additions & 3 deletions packages/oauth/oauth-client-browser-example/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* eslint-env node */

const {
default: manifest,
} = require('@atproto-labs/rollup-plugin-bundle-manifest')
const { default: commonjs } = require('@rollup/plugin-commonjs')
const { default: html, makeHtmlAttributes } = require('@rollup/plugin-html')
const { default: json } = require('@rollup/plugin-json')
Expand All @@ -11,6 +8,10 @@ const { default: replace } = require('@rollup/plugin-replace')
const { default: terser } = require('@rollup/plugin-terser')
const { default: typescript } = require('@rollup/plugin-typescript')
const { defineConfig } = require('rollup')

const {
default: manifest,
} = require('@atproto-labs/rollup-plugin-bundle-manifest')
const postcss = ((m) => m.default || m)(require('rollup-plugin-postcss'))
const serve = ((m) => m.default || m)(require('rollup-plugin-serve'))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { ResolvedHandle } from '@atproto-labs/handle-resolver'
import { SimpleStore, Value } from '@atproto-labs/simple-store'

import { DidDocument } from '@atproto/did'
import { Key } from '@atproto/jwk'
import { WebcryptoKey } from '@atproto/jwk-webcrypto'
Expand All @@ -9,6 +6,8 @@ import {
OAuthAuthorizationServerMetadata,
OAuthProtectedResourceMetadata,
} from '@atproto/oauth-types'
import { ResolvedHandle } from '@atproto-labs/handle-resolver'
import { SimpleStore, Value } from '@atproto-labs/simple-store'

import { DB, DBObjectStore } from './indexed-db/index.js'
import { TupleUnion } from './util.js'
Expand Down
3 changes: 1 addition & 2 deletions packages/oauth/oauth-client-node/src/node-dpop-store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { SimpleStore } from '@atproto-labs/simple-store'

import { Jwk, Key } from '@atproto/jwk'
import { JoseKey } from '@atproto/jwk-jose'
import { InternalStateData, Session } from '@atproto/oauth-client'
import { SimpleStore } from '@atproto-labs/simple-store'

type ToDpopJwkValue<V extends { dpopKey: Key }> = Omit<V, 'dpopKey'> & {
dpopJwk: Jwk
Expand Down
9 changes: 4 additions & 5 deletions packages/oauth/oauth-client-node/src/node-oauth-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { createHash, randomBytes } from 'node:crypto'

import {
AtprotoHandleResolverNode,
AtprotoHandleResolverNodeOptions,
} from '@atproto-labs/handle-resolver-node'

import { JoseKey } from '@atproto/jwk-jose'
import {
OAuthClient,
Expand All @@ -13,6 +8,10 @@ import {
RuntimeLock,
} from '@atproto/oauth-client'
import { OAuthResponseMode } from '@atproto/oauth-types'
import {
AtprotoHandleResolverNode,
AtprotoHandleResolverNodeOptions,
} from '@atproto-labs/handle-resolver-node'

import {
NodeSavedSessionStore,
Expand Down
4 changes: 2 additions & 2 deletions packages/oauth/oauth-client/src/fetch-dpop.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Fetch, FetchContext, cancelBody, peekJson } from '@atproto-labs/fetch'
import { SimpleStore } from '@atproto-labs/simple-store'
import { base64url } from 'multiformats/bases/base64'

import { Key } from '@atproto/jwk'
import { Fetch, FetchContext, cancelBody, peekJson } from '@atproto-labs/fetch'
import { SimpleStore } from '@atproto-labs/simple-store'

// "undefined" in non https environments or environments without crypto
const subtle = globalThis.crypto?.subtle as SubtleCrypto | undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
OAuthAuthorizationServerMetadata,
oauthAuthorizationServerMetadataValidator,
oauthIssuerIdentifierSchema,
} from '@atproto/oauth-types'
import {
Fetch,
FetchResponseError,
Expand All @@ -10,12 +15,6 @@ import {
SimpleStore,
} from '@atproto-labs/simple-store'

import {
OAuthAuthorizationServerMetadata,
oauthAuthorizationServerMetadataValidator,
oauthIssuerIdentifierSchema,
} from '@atproto/oauth-types'

import { contentMime } from './util.js'

export type { GetCachedOptions, OAuthAuthorizationServerMetadata }
Expand Down
19 changes: 9 additions & 10 deletions packages/oauth/oauth-client/src/oauth-client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { Key, Keyset } from '@atproto/jwk'
import {
OAuthAuthorizationRequestParameters,
OAuthClientIdDiscoverable,
OAuthClientMetadata,
OAuthClientMetadataInput,
OAuthResponseMode,
oauthClientMetadataSchema,
} from '@atproto/oauth-types'
import {
AtprotoDid,
DidCache,
Expand All @@ -17,16 +26,6 @@ import {
import { IdentityResolver } from '@atproto-labs/identity-resolver'
import { SimpleStoreMemory } from '@atproto-labs/simple-store-memory'

import { Key, Keyset } from '@atproto/jwk'
import {
OAuthAuthorizationRequestParameters,
OAuthClientIdDiscoverable,
OAuthClientMetadata,
OAuthClientMetadataInput,
OAuthResponseMode,
oauthClientMetadataSchema,
} from '@atproto/oauth-types'

import { FALLBACK_ALG } from './constants.js'
import { TokenRevokedError } from './errors/token-revoked-error.js'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
OAuthProtectedResourceMetadata,
oauthProtectedResourceMetadataSchema,
} from '@atproto/oauth-types'
import {
Fetch,
FetchResponseError,
Expand All @@ -10,11 +14,6 @@ import {
SimpleStore,
} from '@atproto-labs/simple-store'

import {
OAuthProtectedResourceMetadata,
oauthProtectedResourceMetadataSchema,
} from '@atproto/oauth-types'

import { contentMime } from './util.js'

export type { GetCachedOptions, OAuthProtectedResourceMetadata }
Expand Down
9 changes: 4 additions & 5 deletions packages/oauth/oauth-client/src/oauth-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
OAuthAuthorizationServerMetadata,
oauthIssuerIdentifierSchema,
} from '@atproto/oauth-types'
import {
IdentityResolver,
ResolveIdentityOptions,
ResolvedIdentity,
} from '@atproto-labs/identity-resolver'

import {
OAuthAuthorizationServerMetadata,
oauthIssuerIdentifierSchema,
} from '@atproto/oauth-types'

import {
GetCachedOptions,
OAuthAuthorizationServerMetadataResolver,
Expand Down
5 changes: 2 additions & 3 deletions packages/oauth/oauth-client/src/oauth-server-agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { Fetch, Json, bindFetch, fetchJsonProcessor } from '@atproto-labs/fetch'
import { SimpleStore } from '@atproto-labs/simple-store'

import { AtprotoDid } from '@atproto/did'
import { Key, Keyset } from '@atproto/jwk'
import {
Expand All @@ -13,6 +10,8 @@ import {
OAuthTokenRequest,
oauthParResponseSchema,
} from '@atproto/oauth-types'
import { Fetch, Json, bindFetch, fetchJsonProcessor } from '@atproto-labs/fetch'
import { SimpleStore } from '@atproto-labs/simple-store'

import {
AtprotoScope,
Expand Down
3 changes: 1 addition & 2 deletions packages/oauth/oauth-client/src/oauth-server-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Fetch } from '@atproto-labs/fetch'

import { Key, Keyset } from '@atproto/jwk'
import { OAuthAuthorizationServerMetadata } from '@atproto/oauth-types'
import { Fetch } from '@atproto-labs/fetch'

import { GetCachedOptions } from './oauth-authorization-server-metadata-resolver.js'
import { OAuthResolver } from './oauth-resolver.js'
Expand Down
3 changes: 1 addition & 2 deletions packages/oauth/oauth-client/src/oauth-session.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Fetch, bindFetch } from '@atproto-labs/fetch'

import { AtprotoDid } from '@atproto/did'
import { OAuthAuthorizationServerMetadata } from '@atproto/oauth-types'
import { Fetch, bindFetch } from '@atproto-labs/fetch'

import { AtprotoScope } from './atproto-token-response.js'
import { TokenInvalidError } from './errors/token-invalid-error.js'
Expand Down
5 changes: 2 additions & 3 deletions packages/oauth/oauth-client/src/session-getter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { AtprotoDid } from '@atproto/did'
import { Key } from '@atproto/jwk'
import {
CachedGetter,
GetCachedOptions,
SimpleStore,
} from '@atproto-labs/simple-store'

import { AtprotoDid } from '@atproto/did'
import { Key } from '@atproto/jwk'

import { TokenInvalidError } from './errors/token-invalid-error.js'
import { TokenRefreshError } from './errors/token-refresh-error.js'
import { TokenRevokedError } from './errors/token-revoked-error.js'
Expand Down
3 changes: 1 addition & 2 deletions packages/oauth/oauth-client/src/state-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SimpleStore } from '@atproto-labs/simple-store'

import { Key } from '@atproto/jwk'
import { SimpleStore } from '@atproto-labs/simple-store'

export type InternalStateData = {
iss: string
Expand Down
Loading

0 comments on commit 7c8793b

Please sign in to comment.