Skip to content
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

Upgrade API, implement XRPC rework #4857

Merged
merged 32 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
be26e9b
use Blob's with uploadBlob
matthieusieben May 2, 2024
e3e1a5c
use xrpc dispatcher
matthieusieben May 2, 2024
3476d28
clean merge conflict
matthieusieben Jul 14, 2024
a053710
work with packages from atproto repo
matthieusieben Jul 14, 2024
3485da2
bump api
haileyok Jul 31, 2024
5fbfaff
Merge remote-tracking branch 'origin' into xrpc-rework
haileyok Jul 31, 2024
755f4a5
Merge branch 'xrpc-rework' into hailey/upgrade-api
haileyok Jul 31, 2024
a8cde82
tweaks
haileyok Jul 31, 2024
62e0253
rm comment
haileyok Jul 31, 2024
b7b59b0
remove `SignupQueued` screen
haileyok Jul 31, 2024
731d659
Merge branch 'hailey/rm-signup-queued' into hailey/upgrade-api
haileyok Jul 31, 2024
5939c07
fix did type problems
haileyok Jul 31, 2024
98fc3ac
add back `else`
haileyok Jul 31, 2024
4321e34
revert metro changes
haileyok Aug 6, 2024
86367cf
merge main
haileyok Aug 6, 2024
61c282a
Revert "tweaks"
haileyok Aug 6, 2024
a80399a
revert a change
haileyok Aug 6, 2024
8c04c82
maintain previous behavior
haileyok Aug 6, 2024
1e87164
oops
haileyok Aug 6, 2024
ddc6e60
update session test
haileyok Aug 6, 2024
206dbc6
bump
haileyok Aug 7, 2024
bfd0fff
Discard changes to src/lib/moderation.ts
haileyok Aug 7, 2024
1703b03
Discard changes to src/state/queries/preferences/moderation.ts
haileyok Aug 7, 2024
eddcf9c
Merge remote-tracking branch 'origin/main' into hailey/upgrade-api
haileyok Aug 12, 2024
d821901
upgrade package, rm await
haileyok Aug 12, 2024
0385274
Merge remote-tracking branch 'origin/main' into hailey/upgrade-api
haileyok Aug 12, 2024
942aab6
rm todo
haileyok Aug 12, 2024
13a0fb4
Revert "remove `SignupQueued` screen"
haileyok Aug 12, 2024
9519006
revert removal of signup queue
haileyok Aug 12, 2024
7b7b3e8
bump packages
haileyok Aug 12, 2024
97badf3
Merge remote-tracking branch 'origin/main' into hailey/upgrade-api
haileyok Aug 12, 2024
c0c1df7
📌
haileyok Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import 'react-native-gesture-handler' // must be first
import {LogBox} from 'react-native'

import '#/platform/polyfills'
import {IS_TEST} from '#/env'

import {LogBox} from 'react-native'
import {registerRootComponent} from 'expo'
import {doPolyfill} from '#/lib/api/api-polyfill'

import App from '#/App'

doPolyfill()
import {IS_TEST} from '#/env'

if (IS_TEST) {
LogBox.ignoreAllLogs() // suppress all logs in tests
Expand Down
5 changes: 2 additions & 3 deletions index.web.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import '#/platform/markBundleStartTime'

import '#/platform/polyfills'

import {registerRootComponent} from 'expo'
import {doPolyfill} from '#/lib/api/api-polyfill'

import App from '#/App'

doPolyfill()
registerRootComponent(App)
4 changes: 2 additions & 2 deletions jest/test-pds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Mocker {
}

async createUser(name: string) {
const agent = new BskyAgent({service: this.agent.service})
const agent = new BskyAgent({service: this.service})

const inviteRes = await agent.api.com.atproto.server.createInviteCode(
{useCount: 1},
Expand Down Expand Up @@ -332,7 +332,7 @@ class Mocker {
}

async createInvite(forAccount: string) {
const agent = new BskyAgent({service: this.agent.service})
const agent = new BskyAgent({service: this.service})
await agent.api.com.atproto.server.createInviteCode(
{useCount: 1, forAccount},
{
Expand Down
66 changes: 65 additions & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const {resolve} = require('node:path')
const {getDefaultConfig} = require('expo/metro-config')
const cfg = getDefaultConfig(__dirname)

const projectRoot = __dirname
const atprotoRoot = resolve(projectRoot, '../atproto')

const cfg = getDefaultConfig(projectRoot)

const atprotoPackagesDirs = [
'packages/api',
'packages/aws',
'packages/bsky',
'packages/bsync',
'packages/common',
'packages/common-web',
'packages/crypto',
'packages/dev-env',
'packages/dev-infra',
'packages/did',
'packages/identity',
'packages/lex-cli',
'packages/lexicon',
'packages/ozone',
'packages/pds',
'packages/repo',
'packages/syntax',
'packages/xrpc',
'packages/xrpc-server',
'packages/oauth/jwk',
'packages/oauth/jwk-jose',
'packages/oauth/jwk-webcrypto',
'packages/oauth/oauth-client',
'packages/oauth/oauth-client-browser',
'packages/oauth/oauth-client-node',
'packages/oauth/oauth-provider',
'packages/oauth/oauth-types',
'packages/internal/did-resolver',
'packages/internal/fetch',
'packages/internal/fetch-node',
'packages/internal/handle-resolver',
'packages/internal/handle-resolver-node',
'packages/internal/identity-resolver',
'packages/internal/pipe',
'packages/internal/rollup-plugin-bundle-manifest',
'packages/internal/simple-store',
'packages/internal/simple-store-memory',
]

cfg.resolver.extraNodeModules = Object.fromEntries(
atprotoPackagesDirs.map(dir => {
const namespace = dir.includes('internal') ? '@atproto-labs' : '@atproto'
const name = dir.split('/').pop()
return [`${namespace}/${name}`, resolve(atprotoRoot, dir)]
}),
)

cfg.watchFolders = [
projectRoot,
atprotoRoot,
...Object.values(cfg.resolver.extraNodeModules),
]

cfg.resolver.nodeModulesPaths = [
resolve(projectRoot, 'node_modules'),
resolve(atprotoRoot, 'node_modules'),
]

cfg.resolver.sourceExts = process.env.RN_SRC_EXT
? process.env.RN_SRC_EXT.split(',').concat(cfg.resolver.sourceExts)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web"
},
"dependencies": {
"@atproto/api": "0.12.25",
"@atproto/api": "0.13.0-rc.0",
"@bam.tech/react-native-image-resizer": "^3.0.4",
"@braintree/sanitize-url": "^6.0.2",
"@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet",
Expand Down
85 changes: 0 additions & 85 deletions src/lib/api/api-polyfill.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/lib/api/api-polyfill.web.ts

This file was deleted.

25 changes: 11 additions & 14 deletions src/lib/api/feed/custom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
AppBskyFeedDefs,
AppBskyFeedGetFeed as GetCustomFeed,
AtpAgent,
BskyAgent,
} from '@atproto/api'

Expand Down Expand Up @@ -51,7 +50,7 @@ export class CustomFeedAPI implements FeedAPI {
const agent = this.agent
const isBlueskyOwned = isBlueskyOwnedFeed(this.params.feed)

const res = agent.session
const res = agent.did
? await this.agent.app.bsky.feed.getFeed(
{
...this.params,
Expand Down Expand Up @@ -106,34 +105,32 @@ async function loggedOutFetch({
let contentLangs = getContentLanguages().join(',')

// manually construct fetch call so we can add the `lang` cache-busting param
let res = await AtpAgent.fetch!(
let res = await fetch(
`https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=${feed}${
cursor ? `&cursor=${cursor}` : ''
}&limit=${limit}&lang=${contentLangs}`,
'GET',
{'Accept-Language': contentLangs},
undefined,
{method: 'GET', headers: {'Accept-Language': contentLangs}},
)
if (res.body?.feed?.length) {
let data = res.ok ? await res.json() : null
if (data?.feed?.length) {
return {
success: true,
data: res.body,
data,
}
}

// no data, try again with language headers removed
res = await AtpAgent.fetch!(
res = await fetch(
`https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=${feed}${
cursor ? `&cursor=${cursor}` : ''
}&limit=${limit}`,
'GET',
{'Accept-Language': ''},
undefined,
{method: 'GET', headers: {'Accept-Language': ''}},
)
if (res.body?.feed?.length) {
data = res.ok ? await res.json() : null
if (data?.feed?.length) {
return {
success: true,
data: res.body,
data,
}
}

Expand Down
39 changes: 5 additions & 34 deletions src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
AppBskyFeedThreadgate,
BskyAgent,
ComAtprotoLabelDefs,
ComAtprotoRepoUploadBlob,
RichText,
} from '@atproto/api'
import {AtUri} from '@atproto/api'
Expand All @@ -15,10 +14,13 @@ import {logger} from '#/logger'
import {ThreadgateSetting} from '#/state/queries/threadgate'
import {isNetworkError} from 'lib/strings/errors'
import {shortenLinks, stripInvalidMentions} from 'lib/strings/rich-text-manip'
import {isNative, isWeb} from 'platform/detection'
import {isNative} from 'platform/detection'
import {ImageModel} from 'state/models/media/image'
import {LinkMeta} from '../link-meta/link-meta'
import {safeDeleteAsync} from '../media/manip'
import {uploadBlob} from './upload-blob'

export {uploadBlob}

export interface ExternalEmbedDraft {
uri: string
Expand All @@ -28,25 +30,6 @@ export interface ExternalEmbedDraft {
localThumb?: ImageModel
}

export async function uploadBlob(
agent: BskyAgent,
blob: string,
encoding: string,
): Promise<ComAtprotoRepoUploadBlob.Response> {
if (isWeb) {
// `blob` should be a data uri
return agent.uploadBlob(convertDataURIToUint8Array(blob), {
encoding,
})
} else {
// `blob` should be a path to a file in the local FS
return agent.uploadBlob(
blob, // this will be special-cased by the fetch monkeypatch in /src/state/lib/api.ts
{encoding},
)
}
}

interface PostOpts {
rawText: string
replyTo?: string
Expand Down Expand Up @@ -301,7 +284,7 @@ export async function createThreadgate(

const postUrip = new AtUri(postUri)
await agent.api.com.atproto.repo.putRecord({
repo: agent.session!.did,
repo: agent.accountDid,
collection: 'app.bsky.feed.threadgate',
rkey: postUrip.rkey,
record: {
Expand All @@ -312,15 +295,3 @@ export async function createThreadgate(
},
})
}

// helpers
// =

function convertDataURIToUint8Array(uri: string): Uint8Array {
var raw = window.atob(uri.substring(uri.indexOf(';base64,') + 8))
var binary = new Uint8Array(new ArrayBuffer(raw.length))
for (let i = 0; i < raw.length; i++) {
binary[i] = raw.charCodeAt(i)
}
return binary
}
Loading
Loading