@atproto/api
Advanced tools
Comparing version 0.6.11 to 0.6.12
import { AtpAgent } from './agent'; | ||
import { AppBskyFeedPost, AppBskyActorProfile } from './client'; | ||
import { BskyPreferences, BskyLabelPreference } from './types'; | ||
declare global { | ||
interface Array<T> { | ||
findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T; | ||
} | ||
} | ||
export declare class BskyAgent extends AtpAgent { | ||
@@ -70,2 +75,5 @@ get app(): import("./client").AppNS; | ||
setContentLabelPref(key: string, value: BskyLabelPreference): Promise<void>; | ||
setPersonalDetails({ birthDate, }: { | ||
birthDate: string | Date | undefined; | ||
}): Promise<void>; | ||
} |
@@ -43,3 +43,4 @@ import { LabelPreference } from './moderation/types'; | ||
contentLabels: Record<string, BskyLabelPreference>; | ||
birthDate: Date | undefined; | ||
} | ||
export {}; |
{ | ||
"name": "@atproto/api", | ||
"version": "0.6.11", | ||
"version": "0.6.12", | ||
"main": "dist/index.js", | ||
@@ -16,4 +16,4 @@ "license": "MIT", | ||
"@atproto/common-web": "^0.2.0", | ||
"@atproto/syntax": "^0.1.0", | ||
"@atproto/lexicon": "^0.2.0", | ||
"@atproto/syntax": "^0.1.0", | ||
"@atproto/xrpc": "^0.3.0" | ||
@@ -23,4 +23,4 @@ }, | ||
"common-tags": "^1.8.2", | ||
"@atproto/lex-cli": "^0.2.0", | ||
"@atproto/pds": "^0.1.12" | ||
"@atproto/pds": "^0.1.12", | ||
"@atproto/lex-cli": "^0.2.0" | ||
}, | ||
@@ -27,0 +27,0 @@ "scripts": { |
@@ -11,2 +11,11 @@ import { AtUri } from '@atproto/syntax' | ||
declare global { | ||
interface Array<T> { | ||
findLast( | ||
predicate: (value: T, index: number, obj: T[]) => unknown, | ||
thisArg?: any, | ||
): T | ||
} | ||
} | ||
export class BskyAgent extends AtpAgent { | ||
@@ -251,2 +260,3 @@ get app() { | ||
contentLabels: {}, | ||
birthDate: undefined, | ||
} | ||
@@ -277,2 +287,9 @@ const res = await this.app.bsky.actor.getPreferences({}) | ||
prefs.feeds.pinned = pref.pinned | ||
} else if ( | ||
AppBskyActorDefs.isPersonalDetailsPref(pref) && | ||
AppBskyActorDefs.validatePersonalDetailsPref(pref).success | ||
) { | ||
if (pref.birthDate) { | ||
prefs.birthDate = new Date(pref.birthDate) | ||
} | ||
} | ||
@@ -320,3 +337,3 @@ } | ||
await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => { | ||
const existing = prefs.find( | ||
let adultContentPref = prefs.findLast( | ||
(pref) => | ||
@@ -326,11 +343,13 @@ AppBskyActorDefs.isAdultContentPref(pref) && | ||
) | ||
if (existing) { | ||
existing.enabled = v | ||
if (adultContentPref) { | ||
adultContentPref.enabled = v | ||
} else { | ||
prefs.push({ | ||
adultContentPref = { | ||
$type: 'app.bsky.actor.defs#adultContentPref', | ||
enabled: v, | ||
}) | ||
} | ||
} | ||
return prefs | ||
.filter((pref) => !AppBskyActorDefs.isAdultContentPref(pref)) | ||
.concat([adultContentPref]) | ||
}) | ||
@@ -346,3 +365,3 @@ } | ||
await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => { | ||
const existing = prefs.find( | ||
let labelPref = prefs.findLast( | ||
(pref) => | ||
@@ -353,14 +372,45 @@ AppBskyActorDefs.isContentLabelPref(pref) && | ||
) | ||
if (existing) { | ||
existing.visibility = value | ||
if (labelPref) { | ||
labelPref.visibility = value | ||
} else { | ||
prefs.push({ | ||
labelPref = { | ||
$type: 'app.bsky.actor.defs#contentLabelPref', | ||
label: key, | ||
visibility: value, | ||
}) | ||
} | ||
} | ||
return prefs | ||
.filter( | ||
(pref) => | ||
!AppBskyActorDefs.isContentLabelPref(pref) || pref.label !== key, | ||
) | ||
.concat([labelPref]) | ||
}) | ||
} | ||
async setPersonalDetails({ | ||
birthDate, | ||
}: { | ||
birthDate: string | Date | undefined | ||
}) { | ||
birthDate = birthDate instanceof Date ? birthDate.toISOString() : birthDate | ||
await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => { | ||
let personalDetailsPref = prefs.findLast( | ||
(pref) => | ||
AppBskyActorDefs.isPersonalDetailsPref(pref) && | ||
AppBskyActorDefs.validatePersonalDetailsPref(pref).success, | ||
) | ||
if (personalDetailsPref) { | ||
personalDetailsPref.birthDate = birthDate | ||
} else { | ||
personalDetailsPref = { | ||
$type: 'app.bsky.actor.defs#personalDetailsPref', | ||
birthDate, | ||
} | ||
} | ||
return prefs | ||
.filter((pref) => !AppBskyActorDefs.isPersonalDetailsPref(pref)) | ||
.concat([personalDetailsPref]) | ||
}) | ||
} | ||
} | ||
@@ -404,3 +454,3 @@ | ||
await updatePreferences(agent, (prefs: AppBskyActorDefs.Preferences) => { | ||
let feedsPref = prefs.find( | ||
let feedsPref = prefs.findLast( | ||
(pref) => | ||
@@ -407,0 +457,0 @@ AppBskyActorDefs.isSavedFeedsPref(pref) && |
@@ -92,2 +92,3 @@ import { LabelPreference } from './moderation/types' | ||
contentLabels: Record<string, BskyLabelPreference> | ||
birthDate: Date | undefined | ||
} |
@@ -218,2 +218,3 @@ import { | ||
contentLabels: {}, | ||
birthDate: undefined, | ||
}) | ||
@@ -226,2 +227,3 @@ | ||
contentLabels: {}, | ||
birthDate: undefined, | ||
}) | ||
@@ -234,2 +236,3 @@ | ||
contentLabels: {}, | ||
birthDate: undefined, | ||
}) | ||
@@ -244,2 +247,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -256,2 +260,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -270,2 +275,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -284,2 +290,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -298,2 +305,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -312,2 +320,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -326,2 +335,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -346,2 +356,3 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
@@ -360,5 +371,176 @@ | ||
}, | ||
birthDate: undefined, | ||
}) | ||
await agent.setPersonalDetails({ birthDate: '2023-09-11T18:05:42.556Z' }) | ||
await expect(agent.getPreferences()).resolves.toStrictEqual({ | ||
feeds: { | ||
pinned: ['at://bob.com/app.bsky.feed.generator/fake2'], | ||
saved: ['at://bob.com/app.bsky.feed.generator/fake2'], | ||
}, | ||
adultContentEnabled: false, | ||
contentLabels: { | ||
impersonation: 'hide', | ||
spam: 'ignore', | ||
}, | ||
birthDate: new Date('2023-09-11T18:05:42.556Z'), | ||
}) | ||
}) | ||
it('resolves duplicates correctly', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await agent.createAccount({ | ||
handle: 'user6.test', | ||
email: 'user6@test.com', | ||
password: 'password', | ||
}) | ||
await agent.app.bsky.actor.putPreferences({ | ||
preferences: [ | ||
{ | ||
$type: 'app.bsky.actor.defs#contentLabelPref', | ||
label: 'nsfw', | ||
visibility: 'show', | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#contentLabelPref', | ||
label: 'nsfw', | ||
visibility: 'hide', | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#contentLabelPref', | ||
label: 'nsfw', | ||
visibility: 'show', | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#contentLabelPref', | ||
label: 'nsfw', | ||
visibility: 'warn', | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#adultContentPref', | ||
enabled: true, | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#adultContentPref', | ||
enabled: false, | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#adultContentPref', | ||
enabled: true, | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#savedFeedsPref', | ||
pinned: [ | ||
'at://bob.com/app.bsky.feed.generator/fake', | ||
'at://bob.com/app.bsky.feed.generator/fake2', | ||
], | ||
saved: [ | ||
'at://bob.com/app.bsky.feed.generator/fake', | ||
'at://bob.com/app.bsky.feed.generator/fake2', | ||
], | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#savedFeedsPref', | ||
pinned: [], | ||
saved: [], | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#personalDetailsPref', | ||
birthDate: '2023-09-11T18:05:42.556Z', | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#personalDetailsPref', | ||
birthDate: '2021-09-11T18:05:42.556Z', | ||
}, | ||
], | ||
}) | ||
await expect(agent.getPreferences()).resolves.toStrictEqual({ | ||
feeds: { | ||
pinned: [], | ||
saved: [], | ||
}, | ||
adultContentEnabled: true, | ||
contentLabels: { | ||
nsfw: 'warn', | ||
}, | ||
birthDate: new Date('2021-09-11T18:05:42.556Z'), | ||
}) | ||
await agent.setAdultContentEnabled(false) | ||
await expect(agent.getPreferences()).resolves.toStrictEqual({ | ||
feeds: { | ||
pinned: [], | ||
saved: [], | ||
}, | ||
adultContentEnabled: false, | ||
contentLabels: { | ||
nsfw: 'warn', | ||
}, | ||
birthDate: new Date('2021-09-11T18:05:42.556Z'), | ||
}) | ||
await agent.setContentLabelPref('nsfw', 'hide') | ||
await expect(agent.getPreferences()).resolves.toStrictEqual({ | ||
feeds: { | ||
pinned: [], | ||
saved: [], | ||
}, | ||
adultContentEnabled: false, | ||
contentLabels: { | ||
nsfw: 'hide', | ||
}, | ||
birthDate: new Date('2021-09-11T18:05:42.556Z'), | ||
}) | ||
await agent.addPinnedFeed('at://bob.com/app.bsky.feed.generator/fake') | ||
await expect(agent.getPreferences()).resolves.toStrictEqual({ | ||
feeds: { | ||
pinned: ['at://bob.com/app.bsky.feed.generator/fake'], | ||
saved: ['at://bob.com/app.bsky.feed.generator/fake'], | ||
}, | ||
adultContentEnabled: false, | ||
contentLabels: { | ||
nsfw: 'hide', | ||
}, | ||
birthDate: new Date('2021-09-11T18:05:42.556Z'), | ||
}) | ||
await agent.setPersonalDetails({ birthDate: '2023-09-11T18:05:42.556Z' }) | ||
await expect(agent.getPreferences()).resolves.toStrictEqual({ | ||
feeds: { | ||
pinned: ['at://bob.com/app.bsky.feed.generator/fake'], | ||
saved: ['at://bob.com/app.bsky.feed.generator/fake'], | ||
}, | ||
adultContentEnabled: false, | ||
contentLabels: { | ||
nsfw: 'hide', | ||
}, | ||
birthDate: new Date('2023-09-11T18:05:42.556Z'), | ||
}) | ||
const res = await agent.app.bsky.actor.getPreferences() | ||
await expect(res.data.preferences).toStrictEqual([ | ||
{ | ||
$type: 'app.bsky.actor.defs#adultContentPref', | ||
enabled: false, | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#contentLabelPref', | ||
label: 'nsfw', | ||
visibility: 'hide', | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#savedFeedsPref', | ||
pinned: ['at://bob.com/app.bsky.feed.generator/fake'], | ||
saved: ['at://bob.com/app.bsky.feed.generator/fake'], | ||
}, | ||
{ | ||
$type: 'app.bsky.actor.defs#personalDetailsPref', | ||
birthDate: '2023-09-11T18:05:42.556Z', | ||
}, | ||
]) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4189067
64895