@atproto/bsky 0.0.82 → 0.0.84
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/CHANGELOG.md +28 -0
- package/dist/api/app/bsky/feed/getAuthorFeed.d.ts.map +1 -1
- package/dist/api/app/bsky/feed/getAuthorFeed.js +27 -7
- package/dist/api/app/bsky/feed/getAuthorFeed.js.map +1 -1
- package/dist/api/app/bsky/graph/getSuggestedFollowsByActor.js +4 -4
- package/dist/api/app/bsky/graph/getSuggestedFollowsByActor.js.map +1 -1
- package/dist/auth-verifier.d.ts +6 -0
- package/dist/auth-verifier.d.ts.map +1 -1
- package/dist/auth-verifier.js +80 -1
- package/dist/auth-verifier.js.map +1 -1
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -1
- package/dist/data-plane/server/db/migrations/20240831T134810923Z-pinned-posts.d.ts +4 -0
- package/dist/data-plane/server/db/migrations/20240831T134810923Z-pinned-posts.d.ts.map +1 -0
- package/dist/data-plane/server/db/migrations/20240831T134810923Z-pinned-posts.js +20 -0
- package/dist/data-plane/server/db/migrations/20240831T134810923Z-pinned-posts.js.map +1 -0
- package/dist/data-plane/server/db/migrations/index.d.ts +1 -0
- package/dist/data-plane/server/db/migrations/index.d.ts.map +1 -1
- package/dist/data-plane/server/db/migrations/index.js +2 -1
- package/dist/data-plane/server/db/migrations/index.js.map +1 -1
- package/dist/data-plane/server/db/tables/profile.d.ts +2 -0
- package/dist/data-plane/server/db/tables/profile.d.ts.map +1 -1
- package/dist/feature-gates.d.ts +5 -1
- package/dist/feature-gates.d.ts.map +1 -1
- package/dist/feature-gates.js +5 -1
- package/dist/feature-gates.js.map +1 -1
- package/dist/hydration/feed.d.ts +5 -0
- package/dist/hydration/feed.d.ts.map +1 -1
- package/dist/hydration/feed.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lexicon/lexicons.d.ts +68 -0
- package/dist/lexicon/lexicons.d.ts.map +1 -1
- package/dist/lexicon/lexicons.js +77 -3
- package/dist/lexicon/lexicons.js.map +1 -1
- package/dist/lexicon/types/app/bsky/actor/defs.d.ts +16 -0
- package/dist/lexicon/types/app/bsky/actor/defs.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/actor/defs.js +9 -1
- package/dist/lexicon/types/app/bsky/actor/defs.js.map +1 -1
- package/dist/lexicon/types/app/bsky/actor/profile.d.ts +1 -0
- package/dist/lexicon/types/app/bsky/actor/profile.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/actor/profile.js.map +1 -1
- package/dist/lexicon/types/app/bsky/feed/defs.d.ts +13 -2
- package/dist/lexicon/types/app/bsky/feed/defs.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/feed/defs.js +21 -1
- package/dist/lexicon/types/app/bsky/feed/defs.js.map +1 -1
- package/dist/lexicon/types/app/bsky/feed/getAuthorFeed.d.ts +1 -0
- package/dist/lexicon/types/app/bsky/feed/getAuthorFeed.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/graph/getSuggestedFollowsByActor.d.ts +2 -0
- package/dist/lexicon/types/app/bsky/graph/getSuggestedFollowsByActor.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestionsSkeleton.d.ts +2 -0
- package/dist/lexicon/types/app/bsky/unspecced/getSuggestionsSkeleton.d.ts.map +1 -1
- package/dist/views/index.d.ts +4 -0
- package/dist/views/index.d.ts.map +1 -1
- package/dist/views/index.js +22 -1
- package/dist/views/index.js.map +1 -1
- package/package.json +13 -12
- package/src/api/app/bsky/feed/getAuthorFeed.ts +32 -7
- package/src/api/app/bsky/graph/getSuggestedFollowsByActor.ts +5 -9
- package/src/auth-verifier.ts +77 -0
- package/src/config.ts +8 -0
- package/src/data-plane/server/db/migrations/20240831T134810923Z-pinned-posts.ts +17 -0
- package/src/data-plane/server/db/migrations/index.ts +1 -0
- package/src/data-plane/server/db/tables/profile.ts +2 -0
- package/src/feature-gates.ts +5 -1
- package/src/hydration/feed.ts +9 -1
- package/src/index.ts +5 -1
- package/src/lexicon/lexicons.ts +81 -3
- package/src/lexicon/types/app/bsky/actor/defs.ts +25 -0
- package/src/lexicon/types/app/bsky/actor/profile.ts +1 -0
- package/src/lexicon/types/app/bsky/feed/defs.ts +38 -2
- package/src/lexicon/types/app/bsky/feed/getAuthorFeed.ts +1 -0
- package/src/lexicon/types/app/bsky/graph/getSuggestedFollowsByActor.ts +2 -0
- package/src/lexicon/types/app/bsky/unspecced/getSuggestionsSkeleton.ts +2 -0
- package/src/views/index.ts +22 -2
- package/tests/entryway-auth.test.ts +174 -0
- package/tests/views/__snapshots__/author-feed.test.ts.snap +1795 -0
- package/tests/views/author-feed.test.ts +132 -1
package/src/lexicon/lexicons.ts
CHANGED
|
@@ -4190,6 +4190,10 @@ export const schemaDict = {
|
|
|
4190
4190
|
ref: 'lex:com.atproto.label.defs#label',
|
|
4191
4191
|
},
|
|
4192
4192
|
},
|
|
4193
|
+
pinnedPost: {
|
|
4194
|
+
type: 'ref',
|
|
4195
|
+
ref: 'lex:com.atproto.repo.strongRef',
|
|
4196
|
+
},
|
|
4193
4197
|
},
|
|
4194
4198
|
},
|
|
4195
4199
|
profileAssociated: {
|
|
@@ -4572,6 +4576,15 @@ export const schemaDict = {
|
|
|
4572
4576
|
maxLength: 100,
|
|
4573
4577
|
},
|
|
4574
4578
|
},
|
|
4579
|
+
nuxs: {
|
|
4580
|
+
description: 'Storage for NUXs the user has encountered.',
|
|
4581
|
+
type: 'array',
|
|
4582
|
+
maxLength: 100,
|
|
4583
|
+
items: {
|
|
4584
|
+
type: 'ref',
|
|
4585
|
+
ref: 'lex:app.bsky.actor.defs#nux',
|
|
4586
|
+
},
|
|
4587
|
+
},
|
|
4575
4588
|
},
|
|
4576
4589
|
},
|
|
4577
4590
|
bskyAppProgressGuide: {
|
|
@@ -4586,6 +4599,34 @@ export const schemaDict = {
|
|
|
4586
4599
|
},
|
|
4587
4600
|
},
|
|
4588
4601
|
},
|
|
4602
|
+
nux: {
|
|
4603
|
+
type: 'object',
|
|
4604
|
+
description: 'A new user experiences (NUX) storage object',
|
|
4605
|
+
required: ['id', 'completed'],
|
|
4606
|
+
properties: {
|
|
4607
|
+
id: {
|
|
4608
|
+
type: 'string',
|
|
4609
|
+
maxLength: 100,
|
|
4610
|
+
},
|
|
4611
|
+
completed: {
|
|
4612
|
+
type: 'boolean',
|
|
4613
|
+
default: false,
|
|
4614
|
+
},
|
|
4615
|
+
data: {
|
|
4616
|
+
description:
|
|
4617
|
+
'Arbitrary data for the NUX. The structure is defined by the NUX itself. Limited to 300 characters.',
|
|
4618
|
+
type: 'string',
|
|
4619
|
+
maxLength: 3000,
|
|
4620
|
+
maxGraphemes: 300,
|
|
4621
|
+
},
|
|
4622
|
+
expiresAt: {
|
|
4623
|
+
type: 'string',
|
|
4624
|
+
format: 'datetime',
|
|
4625
|
+
description:
|
|
4626
|
+
'The date and time at which the NUX will expire and should be considered completed.',
|
|
4627
|
+
},
|
|
4628
|
+
},
|
|
4629
|
+
},
|
|
4589
4630
|
},
|
|
4590
4631
|
},
|
|
4591
4632
|
AppBskyActorGetPreferences: {
|
|
@@ -4775,6 +4816,10 @@ export const schemaDict = {
|
|
|
4775
4816
|
type: 'ref',
|
|
4776
4817
|
ref: 'lex:com.atproto.repo.strongRef',
|
|
4777
4818
|
},
|
|
4819
|
+
pinnedPost: {
|
|
4820
|
+
type: 'ref',
|
|
4821
|
+
ref: 'lex:com.atproto.repo.strongRef',
|
|
4822
|
+
},
|
|
4778
4823
|
createdAt: {
|
|
4779
4824
|
type: 'string',
|
|
4780
4825
|
format: 'datetime',
|
|
@@ -5431,6 +5476,9 @@ export const schemaDict = {
|
|
|
5431
5476
|
embeddingDisabled: {
|
|
5432
5477
|
type: 'boolean',
|
|
5433
5478
|
},
|
|
5479
|
+
pinned: {
|
|
5480
|
+
type: 'boolean',
|
|
5481
|
+
},
|
|
5434
5482
|
},
|
|
5435
5483
|
},
|
|
5436
5484
|
feedViewPost: {
|
|
@@ -5447,7 +5495,10 @@ export const schemaDict = {
|
|
|
5447
5495
|
},
|
|
5448
5496
|
reason: {
|
|
5449
5497
|
type: 'union',
|
|
5450
|
-
refs: [
|
|
5498
|
+
refs: [
|
|
5499
|
+
'lex:app.bsky.feed.defs#reasonRepost',
|
|
5500
|
+
'lex:app.bsky.feed.defs#reasonPin',
|
|
5501
|
+
],
|
|
5451
5502
|
},
|
|
5452
5503
|
feedContext: {
|
|
5453
5504
|
type: 'string',
|
|
@@ -5499,6 +5550,10 @@ export const schemaDict = {
|
|
|
5499
5550
|
},
|
|
5500
5551
|
},
|
|
5501
5552
|
},
|
|
5553
|
+
reasonPin: {
|
|
5554
|
+
type: 'object',
|
|
5555
|
+
properties: {},
|
|
5556
|
+
},
|
|
5502
5557
|
threadViewPost: {
|
|
5503
5558
|
type: 'object',
|
|
5504
5559
|
required: ['post'],
|
|
@@ -5656,7 +5711,10 @@ export const schemaDict = {
|
|
|
5656
5711
|
},
|
|
5657
5712
|
reason: {
|
|
5658
5713
|
type: 'union',
|
|
5659
|
-
refs: [
|
|
5714
|
+
refs: [
|
|
5715
|
+
'lex:app.bsky.feed.defs#skeletonReasonRepost',
|
|
5716
|
+
'lex:app.bsky.feed.defs#skeletonReasonPin',
|
|
5717
|
+
],
|
|
5660
5718
|
},
|
|
5661
5719
|
feedContext: {
|
|
5662
5720
|
type: 'string',
|
|
@@ -5676,6 +5734,10 @@ export const schemaDict = {
|
|
|
5676
5734
|
},
|
|
5677
5735
|
},
|
|
5678
5736
|
},
|
|
5737
|
+
skeletonReasonPin: {
|
|
5738
|
+
type: 'object',
|
|
5739
|
+
properties: {},
|
|
5740
|
+
},
|
|
5679
5741
|
threadgateView: {
|
|
5680
5742
|
type: 'object',
|
|
5681
5743
|
properties: {
|
|
@@ -6041,6 +6103,10 @@ export const schemaDict = {
|
|
|
6041
6103
|
],
|
|
6042
6104
|
default: 'posts_with_replies',
|
|
6043
6105
|
},
|
|
6106
|
+
includePins: {
|
|
6107
|
+
type: 'boolean',
|
|
6108
|
+
default: false,
|
|
6109
|
+
},
|
|
6044
6110
|
},
|
|
6045
6111
|
},
|
|
6046
6112
|
output: {
|
|
@@ -7125,7 +7191,7 @@ export const schemaDict = {
|
|
|
7125
7191
|
type: 'record',
|
|
7126
7192
|
key: 'tid',
|
|
7127
7193
|
description:
|
|
7128
|
-
"Record defining interaction gating rules for a thread (aka, reply controls). The record key (rkey) of the threadgate record must match the record key of the thread's root post, and that record must be in the same repository
|
|
7194
|
+
"Record defining interaction gating rules for a thread (aka, reply controls). The record key (rkey) of the threadgate record must match the record key of the thread's root post, and that record must be in the same repository.",
|
|
7129
7195
|
record: {
|
|
7130
7196
|
type: 'object',
|
|
7131
7197
|
required: ['post', 'createdAt'],
|
|
@@ -8199,6 +8265,12 @@ export const schemaDict = {
|
|
|
8199
8265
|
ref: 'lex:app.bsky.actor.defs#profileView',
|
|
8200
8266
|
},
|
|
8201
8267
|
},
|
|
8268
|
+
isFallback: {
|
|
8269
|
+
type: 'boolean',
|
|
8270
|
+
description:
|
|
8271
|
+
'If true, response has fallen-back to generic results, and is not scoped using relativeToDid',
|
|
8272
|
+
default: false,
|
|
8273
|
+
},
|
|
8202
8274
|
},
|
|
8203
8275
|
},
|
|
8204
8276
|
},
|
|
@@ -9155,6 +9227,12 @@ export const schemaDict = {
|
|
|
9155
9227
|
ref: 'lex:app.bsky.unspecced.defs#skeletonSearchActor',
|
|
9156
9228
|
},
|
|
9157
9229
|
},
|
|
9230
|
+
relativeToDid: {
|
|
9231
|
+
type: 'string',
|
|
9232
|
+
format: 'did',
|
|
9233
|
+
description:
|
|
9234
|
+
'DID of the account these suggestions are relative to. If this is returned undefined, suggestions are based on the viewer.',
|
|
9235
|
+
},
|
|
9158
9236
|
},
|
|
9159
9237
|
},
|
|
9160
9238
|
},
|
|
@@ -7,6 +7,7 @@ import { isObj, hasProp } from '../../../../util'
|
|
|
7
7
|
import { CID } from 'multiformats/cid'
|
|
8
8
|
import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs'
|
|
9
9
|
import * as AppBskyGraphDefs from '../graph/defs'
|
|
10
|
+
import * as ComAtprotoRepoStrongRef from '../../../com/atproto/repo/strongRef'
|
|
10
11
|
|
|
11
12
|
export interface ProfileViewBasic {
|
|
12
13
|
did: string
|
|
@@ -74,6 +75,7 @@ export interface ProfileViewDetailed {
|
|
|
74
75
|
createdAt?: string
|
|
75
76
|
viewer?: ViewerState
|
|
76
77
|
labels?: ComAtprotoLabelDefs.Label[]
|
|
78
|
+
pinnedPost?: ComAtprotoRepoStrongRef.Main
|
|
77
79
|
[k: string]: unknown
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -469,6 +471,8 @@ export interface BskyAppStatePref {
|
|
|
469
471
|
activeProgressGuide?: BskyAppProgressGuide
|
|
470
472
|
/** An array of tokens which identify nudges (modals, popups, tours, highlight dots) that should be shown to the user. */
|
|
471
473
|
queuedNudges?: string[]
|
|
474
|
+
/** Storage for NUXs the user has encountered. */
|
|
475
|
+
nuxs?: Nux[]
|
|
472
476
|
[k: string]: unknown
|
|
473
477
|
}
|
|
474
478
|
|
|
@@ -501,3 +505,24 @@ export function isBskyAppProgressGuide(v: unknown): v is BskyAppProgressGuide {
|
|
|
501
505
|
export function validateBskyAppProgressGuide(v: unknown): ValidationResult {
|
|
502
506
|
return lexicons.validate('app.bsky.actor.defs#bskyAppProgressGuide', v)
|
|
503
507
|
}
|
|
508
|
+
|
|
509
|
+
/** A new user experiences (NUX) storage object */
|
|
510
|
+
export interface Nux {
|
|
511
|
+
id: string
|
|
512
|
+
completed: boolean
|
|
513
|
+
/** Arbitrary data for the NUX. The structure is defined by the NUX itself. Limited to 300 characters. */
|
|
514
|
+
data?: string
|
|
515
|
+
/** The date and time at which the NUX will expire and should be considered completed. */
|
|
516
|
+
expiresAt?: string
|
|
517
|
+
[k: string]: unknown
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export function isNux(v: unknown): v is Nux {
|
|
521
|
+
return (
|
|
522
|
+
isObj(v) && hasProp(v, '$type') && v.$type === 'app.bsky.actor.defs#nux'
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export function validateNux(v: unknown): ValidationResult {
|
|
527
|
+
return lexicons.validate('app.bsky.actor.defs#nux', v)
|
|
528
|
+
}
|
|
@@ -55,6 +55,7 @@ export interface ViewerState {
|
|
|
55
55
|
threadMuted?: boolean
|
|
56
56
|
replyDisabled?: boolean
|
|
57
57
|
embeddingDisabled?: boolean
|
|
58
|
+
pinned?: boolean
|
|
58
59
|
[k: string]: unknown
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -73,7 +74,7 @@ export function validateViewerState(v: unknown): ValidationResult {
|
|
|
73
74
|
export interface FeedViewPost {
|
|
74
75
|
post: PostView
|
|
75
76
|
reply?: ReplyRef
|
|
76
|
-
reason?: ReasonRepost | { $type: string; [k: string]: unknown }
|
|
77
|
+
reason?: ReasonRepost | ReasonPin | { $type: string; [k: string]: unknown }
|
|
77
78
|
/** Context provided by feed generator that may be passed back alongside interactions. */
|
|
78
79
|
feedContext?: string
|
|
79
80
|
[k: string]: unknown
|
|
@@ -134,6 +135,22 @@ export function validateReasonRepost(v: unknown): ValidationResult {
|
|
|
134
135
|
return lexicons.validate('app.bsky.feed.defs#reasonRepost', v)
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
export interface ReasonPin {
|
|
139
|
+
[k: string]: unknown
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function isReasonPin(v: unknown): v is ReasonPin {
|
|
143
|
+
return (
|
|
144
|
+
isObj(v) &&
|
|
145
|
+
hasProp(v, '$type') &&
|
|
146
|
+
v.$type === 'app.bsky.feed.defs#reasonPin'
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function validateReasonPin(v: unknown): ValidationResult {
|
|
151
|
+
return lexicons.validate('app.bsky.feed.defs#reasonPin', v)
|
|
152
|
+
}
|
|
153
|
+
|
|
137
154
|
export interface ThreadViewPost {
|
|
138
155
|
post: PostView
|
|
139
156
|
parent?:
|
|
@@ -265,7 +282,10 @@ export function validateGeneratorViewerState(v: unknown): ValidationResult {
|
|
|
265
282
|
|
|
266
283
|
export interface SkeletonFeedPost {
|
|
267
284
|
post: string
|
|
268
|
-
reason?:
|
|
285
|
+
reason?:
|
|
286
|
+
| SkeletonReasonRepost
|
|
287
|
+
| SkeletonReasonPin
|
|
288
|
+
| { $type: string; [k: string]: unknown }
|
|
269
289
|
/** Context that will be passed through to client and may be passed to feed generator back alongside interactions. */
|
|
270
290
|
feedContext?: string
|
|
271
291
|
[k: string]: unknown
|
|
@@ -300,6 +320,22 @@ export function validateSkeletonReasonRepost(v: unknown): ValidationResult {
|
|
|
300
320
|
return lexicons.validate('app.bsky.feed.defs#skeletonReasonRepost', v)
|
|
301
321
|
}
|
|
302
322
|
|
|
323
|
+
export interface SkeletonReasonPin {
|
|
324
|
+
[k: string]: unknown
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export function isSkeletonReasonPin(v: unknown): v is SkeletonReasonPin {
|
|
328
|
+
return (
|
|
329
|
+
isObj(v) &&
|
|
330
|
+
hasProp(v, '$type') &&
|
|
331
|
+
v.$type === 'app.bsky.feed.defs#skeletonReasonPin'
|
|
332
|
+
)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function validateSkeletonReasonPin(v: unknown): ValidationResult {
|
|
336
|
+
return lexicons.validate('app.bsky.feed.defs#skeletonReasonPin', v)
|
|
337
|
+
}
|
|
338
|
+
|
|
303
339
|
export interface ThreadgateView {
|
|
304
340
|
uri?: string
|
|
305
341
|
cid?: string
|
|
@@ -17,6 +17,8 @@ export type InputSchema = undefined
|
|
|
17
17
|
|
|
18
18
|
export interface OutputSchema {
|
|
19
19
|
suggestions: AppBskyActorDefs.ProfileView[]
|
|
20
|
+
/** If true, response has fallen-back to generic results, and is not scoped using relativeToDid */
|
|
21
|
+
isFallback?: boolean
|
|
20
22
|
[k: string]: unknown
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -23,6 +23,8 @@ export type InputSchema = undefined
|
|
|
23
23
|
export interface OutputSchema {
|
|
24
24
|
cursor?: string
|
|
25
25
|
actors: AppBskyUnspeccedDefs.SkeletonSearchActor[]
|
|
26
|
+
/** DID of the account these suggestions are relative to. If this is returned undefined, suggestions are based on the viewer. */
|
|
27
|
+
relativeToDid?: string
|
|
26
28
|
[k: string]: unknown
|
|
27
29
|
}
|
|
28
30
|
|
package/src/views/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
NotFoundPost,
|
|
17
17
|
PostView,
|
|
18
18
|
ReasonRepost,
|
|
19
|
+
ReasonPin,
|
|
19
20
|
ReplyRef,
|
|
20
21
|
ThreadViewPost,
|
|
21
22
|
ThreadgateView,
|
|
@@ -169,6 +170,7 @@ export class Views {
|
|
|
169
170
|
joinedViaStarterPack: actor.profile?.joinedViaStarterPack
|
|
170
171
|
? this.starterPackBasic(actor.profile.joinedViaStarterPack.uri, state)
|
|
171
172
|
: undefined,
|
|
173
|
+
pinnedPost: actor.profile?.pinnedPost,
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
|
|
@@ -606,6 +608,7 @@ export class Views {
|
|
|
606
608
|
threadMuted: viewer.threadMuted,
|
|
607
609
|
replyDisabled: this.userReplyDisabled(uri, state),
|
|
608
610
|
embeddingDisabled: this.userPostEmbeddingDisabled(uri, state),
|
|
611
|
+
pinned: this.viewerPinned(uri, state, authorDid),
|
|
609
612
|
}
|
|
610
613
|
: undefined,
|
|
611
614
|
labels,
|
|
@@ -620,8 +623,10 @@ export class Views {
|
|
|
620
623
|
state: HydrationState,
|
|
621
624
|
): FeedViewPost | undefined {
|
|
622
625
|
const postInfo = state.posts?.get(item.post.uri)
|
|
623
|
-
let reason: ReasonRepost | undefined
|
|
624
|
-
if (item.
|
|
626
|
+
let reason: ReasonRepost | ReasonPin | undefined
|
|
627
|
+
if (item.authorPinned) {
|
|
628
|
+
reason = this.reasonPin()
|
|
629
|
+
} else if (item.repost) {
|
|
625
630
|
const repost = state.reposts?.get(item.repost.uri)
|
|
626
631
|
if (!repost) return
|
|
627
632
|
if (repost.record.subject.uri !== item.post.uri) return
|
|
@@ -723,6 +728,12 @@ export class Views {
|
|
|
723
728
|
}
|
|
724
729
|
}
|
|
725
730
|
|
|
731
|
+
reasonPin() {
|
|
732
|
+
return {
|
|
733
|
+
$type: 'app.bsky.feed.defs#reasonPin',
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
726
737
|
// Threads
|
|
727
738
|
// ------------
|
|
728
739
|
|
|
@@ -1128,6 +1139,15 @@ export class Views {
|
|
|
1128
1139
|
return true
|
|
1129
1140
|
}
|
|
1130
1141
|
|
|
1142
|
+
viewerPinned(uri: string, state: HydrationState, authorDid: string) {
|
|
1143
|
+
if (!state.ctx?.viewer || state.ctx.viewer !== authorDid) return
|
|
1144
|
+
const actor = state.actors?.get(authorDid)
|
|
1145
|
+
if (!actor) return
|
|
1146
|
+
const pinnedPost = actor.profile?.pinnedPost
|
|
1147
|
+
if (!pinnedPost) return undefined
|
|
1148
|
+
return pinnedPost.uri === uri
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1131
1151
|
notification(
|
|
1132
1152
|
notif: Notification,
|
|
1133
1153
|
lastSeenAt: string | undefined,
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import * as nodeCrypto from 'node:crypto'
|
|
2
|
+
import KeyEncoder from 'key-encoder'
|
|
3
|
+
import * as ui8 from 'uint8arrays'
|
|
4
|
+
import * as jose from 'jose'
|
|
5
|
+
import * as crypto from '@atproto/crypto'
|
|
6
|
+
import { AtpAgent, AtUri } from '@atproto/api'
|
|
7
|
+
import { basicSeed, SeedClient, TestNetwork } from '@atproto/dev-env'
|
|
8
|
+
import assert from 'node:assert'
|
|
9
|
+
import { MINUTE } from '@atproto/common'
|
|
10
|
+
|
|
11
|
+
const keyEncoder = new KeyEncoder('secp256k1')
|
|
12
|
+
|
|
13
|
+
const derivePrivKey = async (
|
|
14
|
+
keypair: crypto.ExportableKeypair,
|
|
15
|
+
): Promise<nodeCrypto.KeyObject> => {
|
|
16
|
+
const privKeyRaw = await keypair.export()
|
|
17
|
+
const privKeyEncoded = keyEncoder.encodePrivate(
|
|
18
|
+
ui8.toString(privKeyRaw, 'hex'),
|
|
19
|
+
'raw',
|
|
20
|
+
'pem',
|
|
21
|
+
)
|
|
22
|
+
return nodeCrypto.createPrivateKey(privKeyEncoded)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// @NOTE temporary measure, see note on entrywaySession in bsky/src/auth-verifier.ts
|
|
26
|
+
describe('entryway auth', () => {
|
|
27
|
+
let network: TestNetwork
|
|
28
|
+
let agent: AtpAgent
|
|
29
|
+
let sc: SeedClient
|
|
30
|
+
let alice: string
|
|
31
|
+
let jwtPrivKey: nodeCrypto.KeyObject
|
|
32
|
+
|
|
33
|
+
beforeAll(async () => {
|
|
34
|
+
const keypair = await crypto.Secp256k1Keypair.create({ exportable: true })
|
|
35
|
+
jwtPrivKey = await derivePrivKey(keypair)
|
|
36
|
+
const entrywayJwtPublicKeyHex = ui8.toString(
|
|
37
|
+
keypair.publicKeyBytes(),
|
|
38
|
+
'hex',
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
network = await TestNetwork.create({
|
|
42
|
+
dbPostgresSchema: 'bsky_entryway_auth',
|
|
43
|
+
bsky: {
|
|
44
|
+
entrywayJwtPublicKeyHex,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
agent = network.bsky.getClient()
|
|
48
|
+
sc = network.getSeedClient()
|
|
49
|
+
await basicSeed(sc)
|
|
50
|
+
await network.processAll()
|
|
51
|
+
alice = sc.dids.alice
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
afterAll(async () => {
|
|
55
|
+
await network.close()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('works', async () => {
|
|
59
|
+
const signer = new jose.SignJWT({ scope: 'com.atproto.access' })
|
|
60
|
+
.setSubject(alice)
|
|
61
|
+
.setIssuedAt()
|
|
62
|
+
.setExpirationTime('60mins')
|
|
63
|
+
.setAudience('did:web:fake.server.bsky.network')
|
|
64
|
+
.setProtectedHeader({
|
|
65
|
+
typ: 'at+jwt', // https://www.rfc-editor.org/rfc/rfc9068.html
|
|
66
|
+
alg: 'ES256K',
|
|
67
|
+
})
|
|
68
|
+
const token = await signer.sign(jwtPrivKey)
|
|
69
|
+
const res = await agent.app.bsky.actor.getProfile(
|
|
70
|
+
{ actor: sc.dids.bob },
|
|
71
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
72
|
+
)
|
|
73
|
+
expect(res.data.did).toEqual(sc.dids.bob)
|
|
74
|
+
// ensure this request is personalized for alice
|
|
75
|
+
const followingUri = res.data.viewer?.following
|
|
76
|
+
assert(followingUri)
|
|
77
|
+
const parsed = new AtUri(followingUri)
|
|
78
|
+
expect(parsed.hostname).toEqual(alice)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('does not work on bad scopes', async () => {
|
|
82
|
+
const signer = new jose.SignJWT({ scope: 'com.atproto.refresh' })
|
|
83
|
+
.setSubject(alice)
|
|
84
|
+
.setIssuedAt()
|
|
85
|
+
.setExpirationTime('60mins')
|
|
86
|
+
.setAudience('did:web:fake.server.bsky.network')
|
|
87
|
+
.setProtectedHeader({
|
|
88
|
+
typ: 'at+jwt', // https://www.rfc-editor.org/rfc/rfc9068.html
|
|
89
|
+
alg: 'ES256K',
|
|
90
|
+
})
|
|
91
|
+
const token = await signer.sign(jwtPrivKey)
|
|
92
|
+
const attempt = agent.app.bsky.actor.getProfile(
|
|
93
|
+
{ actor: sc.dids.bob },
|
|
94
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
95
|
+
)
|
|
96
|
+
await expect(attempt).rejects.toThrow('Bad token scope')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('does not work on expired tokens', async () => {
|
|
100
|
+
const time = Math.floor((Date.now() - 5 * MINUTE) / 1000)
|
|
101
|
+
const signer = new jose.SignJWT({ scope: 'com.atproto.access' })
|
|
102
|
+
.setSubject(alice)
|
|
103
|
+
.setIssuedAt()
|
|
104
|
+
.setExpirationTime(time)
|
|
105
|
+
.setAudience('did:web:fake.server.bsky.network')
|
|
106
|
+
.setProtectedHeader({
|
|
107
|
+
typ: 'at+jwt', // https://www.rfc-editor.org/rfc/rfc9068.html
|
|
108
|
+
alg: 'ES256K',
|
|
109
|
+
})
|
|
110
|
+
const token = await signer.sign(jwtPrivKey)
|
|
111
|
+
const attempt = agent.app.bsky.actor.getProfile(
|
|
112
|
+
{ actor: sc.dids.bob },
|
|
113
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
114
|
+
)
|
|
115
|
+
await expect(attempt).rejects.toThrow('Token has expired')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('does not work on bad auds', async () => {
|
|
119
|
+
const signer = new jose.SignJWT({ scope: 'com.atproto.access' })
|
|
120
|
+
.setSubject(alice)
|
|
121
|
+
.setIssuedAt()
|
|
122
|
+
.setExpirationTime('60mins')
|
|
123
|
+
.setAudience('did:web:my.personal.pds.com')
|
|
124
|
+
.setProtectedHeader({
|
|
125
|
+
typ: 'at+jwt', // https://www.rfc-editor.org/rfc/rfc9068.html
|
|
126
|
+
alg: 'ES256K',
|
|
127
|
+
})
|
|
128
|
+
const token = await signer.sign(jwtPrivKey)
|
|
129
|
+
const attempt = agent.app.bsky.actor.getProfile(
|
|
130
|
+
{ actor: sc.dids.bob },
|
|
131
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
132
|
+
)
|
|
133
|
+
await expect(attempt).rejects.toThrow('Bad token aud')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('does not work with bad signatures', async () => {
|
|
137
|
+
const fakeKey = await crypto.Secp256k1Keypair.create({ exportable: true })
|
|
138
|
+
const fakeJwtKey = await derivePrivKey(fakeKey)
|
|
139
|
+
const signer = new jose.SignJWT({ scope: 'com.atproto.access' })
|
|
140
|
+
.setSubject(alice)
|
|
141
|
+
.setIssuedAt()
|
|
142
|
+
.setExpirationTime('60mins')
|
|
143
|
+
.setAudience('did:web:my.personal.pds.com')
|
|
144
|
+
.setProtectedHeader({
|
|
145
|
+
typ: 'at+jwt', // https://www.rfc-editor.org/rfc/rfc9068.html
|
|
146
|
+
alg: 'ES256K',
|
|
147
|
+
})
|
|
148
|
+
const token = await signer.sign(fakeJwtKey)
|
|
149
|
+
const attempt = agent.app.bsky.actor.getProfile(
|
|
150
|
+
{ actor: sc.dids.bob },
|
|
151
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
152
|
+
)
|
|
153
|
+
await expect(attempt).rejects.toThrow('Token could not be verified')
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('does not work on flexible aud routes', async () => {
|
|
157
|
+
const signer = new jose.SignJWT({ scope: 'com.atproto.access' })
|
|
158
|
+
.setSubject(alice)
|
|
159
|
+
.setIssuedAt()
|
|
160
|
+
.setExpirationTime('60mins')
|
|
161
|
+
.setAudience('did:web:fake.server.bsky.network')
|
|
162
|
+
.setProtectedHeader({
|
|
163
|
+
typ: 'at+jwt', // https://www.rfc-editor.org/rfc/rfc9068.html
|
|
164
|
+
alg: 'ES256K',
|
|
165
|
+
})
|
|
166
|
+
const token = await signer.sign(jwtPrivKey)
|
|
167
|
+
const feedUri = AtUri.make(alice, 'app.bsky.feed.generator', 'fake-feed')
|
|
168
|
+
const attempt = agent.app.bsky.feed.getFeed(
|
|
169
|
+
{ feed: feedUri.toString() },
|
|
170
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
171
|
+
)
|
|
172
|
+
await expect(attempt).rejects.toThrow('Malformed token')
|
|
173
|
+
})
|
|
174
|
+
})
|