@atproto/api
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -28,3 +28,3 @@ import { ValidationResult } from '@atproto/lexicon'; | ||
action: ActionType; | ||
subject: RepoView | RecordView | { | ||
subject: RepoView | RepoViewNotFound | RecordView | RecordViewNotFound | { | ||
$type: string; | ||
@@ -84,3 +84,3 @@ [k: string]: unknown; | ||
reason?: string; | ||
subject: RepoView | RecordView | { | ||
subject: RepoView | RepoViewNotFound | RecordView | RecordViewNotFound | { | ||
$type: string; | ||
@@ -124,2 +124,8 @@ [k: string]: unknown; | ||
export declare function validateRepoViewDetail(v: unknown): ValidationResult; | ||
export interface RepoViewNotFound { | ||
did: string; | ||
[k: string]: unknown; | ||
} | ||
export declare function isRepoViewNotFound(v: unknown): v is RepoViewNotFound; | ||
export declare function validateRepoViewNotFound(v: unknown): ValidationResult; | ||
export interface RepoRef { | ||
@@ -156,2 +162,8 @@ did: string; | ||
export declare function validateRecordViewDetail(v: unknown): ValidationResult; | ||
export interface RecordViewNotFound { | ||
uri: string; | ||
[k: string]: unknown; | ||
} | ||
export declare function isRecordViewNotFound(v: unknown): v is RecordViewNotFound; | ||
export declare function validateRecordViewNotFound(v: unknown): ValidationResult; | ||
export interface Moderation { | ||
@@ -158,0 +170,0 @@ currentAction?: ActionViewCurrent; |
@@ -6,2 +6,3 @@ import { Headers } from '@atproto/xrpc'; | ||
resolved?: boolean; | ||
actionType?: 'com.atproto.admin.defs#takedown' | 'com.atproto.admin.defs#flag' | 'com.atproto.admin.defs#acknowledge' | 'com.atproto.admin.defs#escalate' | (string & {}); | ||
limit?: number; | ||
@@ -8,0 +9,0 @@ cursor?: string; |
@@ -1,2 +0,2 @@ | ||
import { Headers } from '@atproto/xrpc'; | ||
import { Headers, XRPCError } from '@atproto/xrpc'; | ||
import * as ComAtprotoAdminDefs from './defs'; | ||
@@ -17,2 +17,5 @@ export interface QueryParams { | ||
} | ||
export declare class RecordNotFoundError extends XRPCError { | ||
constructor(src: XRPCError); | ||
} | ||
export declare function toKnownErr(e: any): any; |
@@ -1,2 +0,2 @@ | ||
import { Headers } from '@atproto/xrpc'; | ||
import { Headers, XRPCError } from '@atproto/xrpc'; | ||
import * as ComAtprotoAdminDefs from './defs'; | ||
@@ -16,2 +16,5 @@ export interface QueryParams { | ||
} | ||
export declare class RepoNotFoundError extends XRPCError { | ||
constructor(src: XRPCError); | ||
} | ||
export declare function toKnownErr(e: any): any; |
@@ -7,2 +7,3 @@ import { Headers, XRPCError } from '@atproto/xrpc'; | ||
handle: string; | ||
did?: string; | ||
inviteCode?: string; | ||
@@ -45,2 +46,8 @@ password: string; | ||
} | ||
export declare class UnresolvableDidError extends XRPCError { | ||
constructor(src: XRPCError); | ||
} | ||
export declare class IncompatibleDidDocError extends XRPCError { | ||
constructor(src: XRPCError); | ||
} | ||
export declare function toKnownErr(e: any): any; |
{ | ||
"name": "@atproto/api", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"main": "dist/index.js", | ||
@@ -13,3 +13,5 @@ "scripts": { | ||
"postpublish": "npm run update-main-to-src", | ||
"test": "jest" | ||
"test": "jest", | ||
"bench": "jest --config jest.bench.config.js", | ||
"bench:profile": "node --inspect-brk ../../node_modules/.bin/jest --config jest.bench.config.js" | ||
}, | ||
@@ -16,0 +18,0 @@ "license": "MIT", |
@@ -46,3 +46,8 @@ /** | ||
action: ActionType | ||
subject: RepoView | RecordView | { $type: string; [k: string]: unknown } | ||
subject: | ||
| RepoView | ||
| RepoViewNotFound | ||
| RecordView | ||
| RecordViewNotFound | ||
| { $type: string; [k: string]: unknown } | ||
subjectBlobs: BlobView[] | ||
@@ -154,3 +159,8 @@ createLabelVals?: string[] | ||
reason?: string | ||
subject: RepoView | RecordView | { $type: string; [k: string]: unknown } | ||
subject: | ||
| RepoView | ||
| RepoViewNotFound | ||
| RecordView | ||
| RecordViewNotFound | ||
| { $type: string; [k: string]: unknown } | ||
reportedBy: string | ||
@@ -224,2 +234,19 @@ createdAt: string | ||
export interface RepoViewNotFound { | ||
did: string | ||
[k: string]: unknown | ||
} | ||
export function isRepoViewNotFound(v: unknown): v is RepoViewNotFound { | ||
return ( | ||
isObj(v) && | ||
hasProp(v, '$type') && | ||
v.$type === 'com.atproto.admin.defs#repoViewNotFound' | ||
) | ||
} | ||
export function validateRepoViewNotFound(v: unknown): ValidationResult { | ||
return lexicons.validate('com.atproto.admin.defs#repoViewNotFound', v) | ||
} | ||
export interface RepoRef { | ||
@@ -289,2 +316,19 @@ did: string | ||
export interface RecordViewNotFound { | ||
uri: string | ||
[k: string]: unknown | ||
} | ||
export function isRecordViewNotFound(v: unknown): v is RecordViewNotFound { | ||
return ( | ||
isObj(v) && | ||
hasProp(v, '$type') && | ||
v.$type === 'com.atproto.admin.defs#recordViewNotFound' | ||
) | ||
} | ||
export function validateRecordViewNotFound(v: unknown): ValidationResult { | ||
return lexicons.validate('com.atproto.admin.defs#recordViewNotFound', v) | ||
} | ||
export interface Moderation { | ||
@@ -291,0 +335,0 @@ currentAction?: ActionViewCurrent |
@@ -14,2 +14,8 @@ /** | ||
resolved?: boolean | ||
actionType?: | ||
| 'com.atproto.admin.defs#takedown' | ||
| 'com.atproto.admin.defs#flag' | ||
| 'com.atproto.admin.defs#acknowledge' | ||
| 'com.atproto.admin.defs#escalate' | ||
| (string & {}) | ||
limit?: number | ||
@@ -16,0 +22,0 @@ cursor?: string |
@@ -29,6 +29,13 @@ /** | ||
export class RecordNotFoundError extends XRPCError { | ||
constructor(src: XRPCError) { | ||
super(src.status, src.error, src.message) | ||
} | ||
} | ||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
if (e.error === 'RecordNotFound') return new RecordNotFoundError(e) | ||
} | ||
return e | ||
} |
@@ -28,6 +28,13 @@ /** | ||
export class RepoNotFoundError extends XRPCError { | ||
constructor(src: XRPCError) { | ||
super(src.status, src.error, src.message) | ||
} | ||
} | ||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
if (e.error === 'RepoNotFound') return new RepoNotFoundError(e) | ||
} | ||
return e | ||
} |
@@ -15,2 +15,3 @@ /** | ||
handle: string | ||
did?: string | ||
inviteCode?: string | ||
@@ -72,2 +73,14 @@ password: string | ||
export class UnresolvableDidError extends XRPCError { | ||
constructor(src: XRPCError) { | ||
super(src.status, src.error, src.message) | ||
} | ||
} | ||
export class IncompatibleDidDocError extends XRPCError { | ||
constructor(src: XRPCError) { | ||
super(src.status, src.error, src.message) | ||
} | ||
} | ||
export function toKnownErr(e: any) { | ||
@@ -80,4 +93,6 @@ if (e instanceof XRPCError) { | ||
if (e.error === 'UnsupportedDomain') return new UnsupportedDomainError(e) | ||
if (e.error === 'UnresolvableDid') return new UnresolvableDidError(e) | ||
if (e.error === 'IncompatibleDidDoc') return new IncompatibleDidDocError(e) | ||
} | ||
return e | ||
} |
@@ -401,2 +401,65 @@ import { defaultFetchHandler } from '@atproto/xrpc' | ||
}) | ||
describe('setPersistSessionHandler', () => { | ||
it('sets persist session handler', async () => { | ||
let originalHandlerCallCount = 0 | ||
let newHandlerCallCount = 0 | ||
const persistSession = () => { | ||
originalHandlerCallCount++ | ||
} | ||
const newPersistSession = () => { | ||
newHandlerCallCount++ | ||
} | ||
const agent = new AtpAgent({ service: server.url, persistSession }) | ||
await agent.createAccount({ | ||
handle: 'user7.test', | ||
email: 'user7@test.com', | ||
password: 'password', | ||
}) | ||
expect(originalHandlerCallCount).toEqual(1) | ||
agent.setPersistSessionHandler(newPersistSession) | ||
await agent.createAccount({ | ||
handle: 'user8.test', | ||
email: 'user8@test.com', | ||
password: 'password', | ||
}) | ||
expect(originalHandlerCallCount).toEqual(1) | ||
expect(newHandlerCallCount).toEqual(1) | ||
}) | ||
}) | ||
describe('createAccount', () => { | ||
it('persists an empty session on failure', async () => { | ||
const events: string[] = [] | ||
const sessions: (AtpSessionData | undefined)[] = [] | ||
const persistSession = (evt: AtpSessionEvent, sess?: AtpSessionData) => { | ||
events.push(evt) | ||
sessions.push(sess) | ||
} | ||
const agent = new AtpAgent({ service: server.url, persistSession }) | ||
await expect( | ||
agent.createAccount({ | ||
handle: '', | ||
email: '', | ||
password: 'password', | ||
}), | ||
).rejects.toThrow() | ||
expect(agent.hasSession).toEqual(false) | ||
expect(agent.session).toEqual(undefined) | ||
expect(events.length).toEqual(1) | ||
expect(events[0]).toEqual('create-failed') | ||
expect(sessions.length).toEqual(1) | ||
expect(sessions[0]).toEqual(undefined) | ||
}) | ||
}) | ||
}) |
@@ -140,2 +140,65 @@ import { | ||
}) | ||
describe('app', () => { | ||
it('should retrieve the api app', () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
expect(agent.app).toBe(agent.api.app) | ||
}) | ||
}) | ||
describe('post', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.post({ text: 'foo' })).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
describe('deletePost', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.deletePost('foo')).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
describe('like', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.like('foo', 'bar')).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
describe('deleteLike', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.deleteLike('foo')).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
describe('repost', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.repost('foo', 'bar')).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
describe('deleteRepost', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.deleteRepost('foo')).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
describe('follow', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.follow('foo')).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
describe('deleteFollow', () => { | ||
it('should throw if no session', async () => { | ||
const agent = new BskyAgent({ service: server.url }) | ||
await expect(agent.deleteFollow('foo')).rejects.toThrow('Not logged in') | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
3628395
257
51189
9