Skip to content

Commit

Permalink
PDS contact email address (#2313)
Browse files Browse the repository at this point in the history
* lexicon: add pds server contact email

* pds: configuration for contact email address
  • Loading branch information
devinivy authored Mar 13, 2024
1 parent 2194807 commit 722d417
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lexicons/com/atproto/server/describeServer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"description": "URLs of service policy documents.",
"ref": "#links"
},
"contact": {
"type": "ref",
"description": "Contact information",
"ref": "#contact"
},
"did": {
"type": "string",
"format": "did"
Expand All @@ -43,6 +48,12 @@
"privacyPolicy": { "type": "string" },
"termsOfService": { "type": "string" }
}
},
"contact": {
"type": "object",
"properties": {
"email": { "type": "string" }
}
}
}
}
13 changes: 13 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,11 @@ export const schemaDict = {
description: 'URLs of service policy documents.',
ref: 'lex:com.atproto.server.describeServer#links',
},
contact: {
type: 'ref',
description: 'Contact information',
ref: 'lex:com.atproto.server.describeServer#contact',
},
did: {
type: 'string',
format: 'did',
Expand All @@ -2439,6 +2444,14 @@ export const schemaDict = {
},
},
},
contact: {
type: 'object',
properties: {
email: {
type: 'string',
},
},
},
},
},
ComAtprotoServerGetAccountInviteCodes: {
Expand Down
18 changes: 18 additions & 0 deletions packages/api/src/client/types/com/atproto/server/describeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface OutputSchema {
/** List of domain suffixes that can be used in account handles. */
availableUserDomains: string[]
links?: Links
contact?: Contact
did: string
[k: string]: unknown
}
Expand Down Expand Up @@ -56,3 +57,20 @@ export function isLinks(v: unknown): v is Links {
export function validateLinks(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#links', v)
}

export interface Contact {
email?: string
[k: string]: unknown
}

export function isContact(v: unknown): v is Contact {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'com.atproto.server.describeServer#contact'
)
}

export function validateContact(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#contact', v)
}
13 changes: 13 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,11 @@ export const schemaDict = {
description: 'URLs of service policy documents.',
ref: 'lex:com.atproto.server.describeServer#links',
},
contact: {
type: 'ref',
description: 'Contact information',
ref: 'lex:com.atproto.server.describeServer#contact',
},
did: {
type: 'string',
format: 'did',
Expand All @@ -2439,6 +2444,14 @@ export const schemaDict = {
},
},
},
contact: {
type: 'object',
properties: {
email: {
type: 'string',
},
},
},
},
},
ComAtprotoServerGetAccountInviteCodes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface OutputSchema {
/** List of domain suffixes that can be used in account handles. */
availableUserDomains: string[]
links?: Links
contact?: Contact
did: string
[k: string]: unknown
}
Expand Down Expand Up @@ -66,3 +67,20 @@ export function isLinks(v: unknown): v is Links {
export function validateLinks(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#links', v)
}

export interface Contact {
email?: string
[k: string]: unknown
}

export function isContact(v: unknown): v is Contact {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'com.atproto.server.describeServer#contact'
)
}

export function validateContact(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#contact', v)
}
13 changes: 13 additions & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,11 @@ export const schemaDict = {
description: 'URLs of service policy documents.',
ref: 'lex:com.atproto.server.describeServer#links',
},
contact: {
type: 'ref',
description: 'Contact information',
ref: 'lex:com.atproto.server.describeServer#contact',
},
did: {
type: 'string',
format: 'did',
Expand All @@ -2439,6 +2444,14 @@ export const schemaDict = {
},
},
},
contact: {
type: 'object',
properties: {
email: {
type: 'string',
},
},
},
},
},
ComAtprotoServerGetAccountInviteCodes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface OutputSchema {
/** List of domain suffixes that can be used in account handles. */
availableUserDomains: string[]
links?: Links
contact?: Contact
did: string
[k: string]: unknown
}
Expand Down Expand Up @@ -66,3 +67,20 @@ export function isLinks(v: unknown): v is Links {
export function validateLinks(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#links', v)
}

export interface Contact {
email?: string
[k: string]: unknown
}

export function isContact(v: unknown): v is Contact {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'com.atproto.server.describeServer#contact'
)
}

export function validateContact(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#contact', v)
}
4 changes: 4 additions & 0 deletions packages/pds/src/api/com/atproto/server/describeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function (server: Server, ctx: AppContext) {
const inviteCodeRequired = ctx.cfg.invites.required
const privacyPolicy = ctx.cfg.service.privacyPolicyUrl
const termsOfService = ctx.cfg.service.termsOfServiceUrl
const contactEmailAddress = ctx.cfg.service.contactEmailAddress

return {
encoding: 'application/json',
Expand All @@ -15,6 +16,9 @@ export default function (server: Server, ctx: AppContext) {
availableUserDomains,
inviteCodeRequired,
links: { privacyPolicy, termsOfService },
contact: {
email: contactEmailAddress,
},
},
}
})
Expand Down
2 changes: 2 additions & 0 deletions packages/pds/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const envToCfg = (env: ServerEnvironment): ServerConfig => {
version: env.version, // default?
privacyPolicyUrl: env.privacyPolicyUrl,
termsOfServiceUrl: env.termsOfServiceUrl,
contactEmailAddress: env.contactEmailAddress,
acceptingImports: env.acceptingImports ?? true,
blobUploadLimit: env.blobUploadLimit ?? 5 * 1024 * 1024, // 5mb
devMode: env.devMode ?? false,
Expand Down Expand Up @@ -281,6 +282,7 @@ export type ServiceConfig = {
termsOfServiceUrl?: string
acceptingImports: boolean
blobUploadLimit: number
contactEmailAddress?: string
devMode: boolean
}

Expand Down
2 changes: 2 additions & 0 deletions packages/pds/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const readEnv = (): ServerEnvironment => {
version: envStr('PDS_VERSION'),
privacyPolicyUrl: envStr('PDS_PRIVACY_POLICY_URL'),
termsOfServiceUrl: envStr('PDS_TERMS_OF_SERVICE_URL'),
contactEmailAddress: envStr('PDS_CONTACT_EMAIL_ADDRESS'),
acceptingImports: envBool('PDS_ACCEPTING_REPO_IMPORTS'),
blobUploadLimit: envInt('PDS_BLOB_UPLOAD_LIMIT'),
devMode: envBool('PDS_DEV_MODE'),
Expand Down Expand Up @@ -115,6 +116,7 @@ export type ServerEnvironment = {
version?: string
privacyPolicyUrl?: string
termsOfServiceUrl?: string
contactEmailAddress?: string
acceptingImports?: boolean
blobUploadLimit?: number
devMode?: boolean
Expand Down
13 changes: 13 additions & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,11 @@ export const schemaDict = {
description: 'URLs of service policy documents.',
ref: 'lex:com.atproto.server.describeServer#links',
},
contact: {
type: 'ref',
description: 'Contact information',
ref: 'lex:com.atproto.server.describeServer#contact',
},
did: {
type: 'string',
format: 'did',
Expand All @@ -2439,6 +2444,14 @@ export const schemaDict = {
},
},
},
contact: {
type: 'object',
properties: {
email: {
type: 'string',
},
},
},
},
},
ComAtprotoServerGetAccountInviteCodes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface OutputSchema {
/** List of domain suffixes that can be used in account handles. */
availableUserDomains: string[]
links?: Links
contact?: Contact
did: string
[k: string]: unknown
}
Expand Down Expand Up @@ -66,3 +67,20 @@ export function isLinks(v: unknown): v is Links {
export function validateLinks(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#links', v)
}

export interface Contact {
email?: string
[k: string]: unknown
}

export function isContact(v: unknown): v is Contact {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'com.atproto.server.describeServer#contact'
)
}

export function validateContact(v: unknown): ValidationResult {
return lexicons.validate('com.atproto.server.describeServer#contact', v)
}
2 changes: 2 additions & 0 deletions packages/pds/tests/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('account', () => {
network = await TestNetworkNoAppView.create({
dbPostgresSchema: 'account',
pds: {
contactEmailAddress: 'abuse@example.com',
termsOfServiceUrl: 'https://example.com/tos',
privacyPolicyUrl: 'https://example.com/privacy-policy',
},
Expand Down Expand Up @@ -58,6 +59,7 @@ describe('account', () => {
'https://example.com/privacy-policy',
)
expect(res.data.links?.termsOfService).toBe('https://example.com/tos')
expect(res.data.contact?.email).toBe('abuse@example.com')
})

it('fails on invalid handles', async () => {
Expand Down

0 comments on commit 722d417

Please sign in to comment.