Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit"
},
"typescript.tsdk": "node_modules/typescript/lib",
"explorer.fileNesting.enabled": true
}
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
"$schema": "https://biomejs.dev/schemas/2.2.0/schema.json",
"assist": { "actions": { "source": { "organizeImports": "on" } } },
"formatter": {
"enabled": true,
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Brand, BrandResponse } from '../../brand/interfaces'
import type { Domain, DomainResponse } from '../../domains/interfaces'

export interface Project {
Expand All @@ -11,6 +12,7 @@ export interface Project {
timezone: string
subdomain: string
primaryDomain: string | null | Domain
brand: string | null | Brand
published: boolean
processed: boolean
createdAt: number
Expand All @@ -29,6 +31,7 @@ export interface ProjectResponse {
timezone: string
subdomain: string
primary_domain: string | null | DomainResponse
brand: string | null | BrandResponse
published: boolean
processed: boolean
created_at: number
Expand Down
14 changes: 14 additions & 0 deletions src/resources/agency/projects/projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ describe('Project', () => {
object: 'list',
})
})

it('can retrieve a list of projects with an expandable brand', async () => {
fetchOnce(projectListFixture)
const projects = await blutui
.agency('foo')
.projects.list({ expand: ['brand'] })

expect(fetchURL()).toBe(
encodeURI(`${blutui.baseURL}/v1/agencies/foo/projects?expand[]=brand`)
)
expect(projects).toMatchObject({
object: 'list',
})
})
})

describe('get', () => {
Expand Down
46 changes: 22 additions & 24 deletions src/resources/agency/projects/projects.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
deserializeProject,
deserializeProjectList,
serializeCreateProjectOptions,
serializeUpdateProjectOptions,
} from './serializers'
import { deserializeDomainList } from '../domains/serializers'

import type { Agency } from '@/agency'
import type {
DeletedResponse,
Expandable,
List,
ListResponse,
PaginationOptions,
} from '@/types'
import type { Cassette, CassetteResponse } from '../cassettes/interfaces'
import { deserializeCassetteList } from '../cassettes/serializers'
import type { Domain, DomainResponse } from '../domains/interfaces'
import { deserializeDomainList } from '../domains/serializers'
import type {
CreateProjectOptions,
Project,
Expand All @@ -17,16 +20,14 @@ import type {
SerializedUpdateProjectOptions,
UpdateProjectOptions,
} from './interfaces'
import type { Domain, DomainResponse } from '../domains/interfaces'
import type { Cassette, CassetteResponse } from '../cassettes/interfaces'
import type {
DeletedResponse,
Expandable,
List,
ListResponse,
PaginationOptions,
} from '@/types'
import { deserializeCassetteList } from '../cassettes/serializers'
import {
deserializeProject,
deserializeProjectList,
serializeCreateProjectOptions,
serializeUpdateProjectOptions,
} from './serializers'

export type ProjectExpandable = Expandable<'primary_domain' | 'brand'>

export class Projects {
constructor(private readonly agency: Agency) {}
Expand All @@ -35,7 +36,7 @@ export class Projects {
* Get the projects list for the current agency.
*/
async list(
options?: PaginationOptions & Expandable<'primary_domain'>
options?: PaginationOptions & ProjectExpandable
): Promise<List<Project>> {
const { data } = await this.agency.get<ListResponse<ProjectResponse>>(
'projects',
Expand All @@ -50,10 +51,7 @@ export class Projects {
/**
* Get a project's information by ID.
*/
async get(
id: string,
options?: Expandable<'primary_domain'>
): Promise<Project> {
async get(id: string, options?: ProjectExpandable): Promise<Project> {
const { data } = await this.agency.get<ProjectResponse>(`projects/${id}`, {
query: options,
})
Expand Down Expand Up @@ -152,7 +150,7 @@ export class Projects {
*/
async search(
payload: SearchProjectOptions,
options?: PaginationOptions & Expandable<'primary_domain'>
options?: PaginationOptions & ProjectExpandable
): Promise<List<Project>> {
const { data } = await this.agency.post<
ListResponse<ProjectResponse>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { List, ListResponse } from '@/types'
import { deserializePaginationMeta } from '@/utils/serializers'
import { deserializeBrand } from '../../brand/serializers'
import { deserializeDomain } from '../../domains/serializers'

import type { Project, ProjectResponse } from '../interfaces'
import type { List, ListResponse } from '@/types'

export const deserializeProject = (project: ProjectResponse): Project => ({
id: project.id,
Expand All @@ -18,6 +18,10 @@ export const deserializeProject = (project: ProjectResponse): Project => ({
project.primary_domain instanceof Object
? deserializeDomain(project.primary_domain)
: project.primary_domain,
brand:
project.brand instanceof Object
? deserializeBrand(project.brand)
: project.brand,
published: project.published,
processed: project.processed,
createdAt: project.created_at,
Expand Down
24 changes: 13 additions & 11 deletions src/resources/project/menus/fixtures/menu-with-items.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"id": "9bfdb42b-1bf0-4510-978e-46aa329f8efa",
"object": "menu",
"name": "Primary Menu",
"items": [{
"id": "99bc147e-966c-4dd0-8def-de817c63cf41",
"object": "menu_item",
"label": "Contact",
"url": "/contact",
"active": true,
"is_new_tab": false,
"order": 1,
"created_at": 1720758022,
"updated_at": 1720758046
}],
"items": [
{
"id": "99bc147e-966c-4dd0-8def-de817c63cf41",
"object": "menu_item",
"label": "Contact",
"url": "/contact",
"active": true,
"is_new_tab": false,
"order": 1,
"created_at": 1720758022,
"updated_at": 1720758046
}
],
"created_at": 1716170007,
"updated_at": 1716170007
}
13 changes: 9 additions & 4 deletions src/resources/project/redirect/redirect.admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ export class Redirects {
* Get a redirect's information by ID.
*/
async get(id: string, options?: Expandable<'items'>): Promise<Redirect> {
const { data } = await this.project.get<RedirectResponse>(`redirects/${id}`, {
query: options,
})
const { data } = await this.project.get<RedirectResponse>(
`redirects/${id}`,
{
query: options,
}
)

return deserializeRedirect(data)
}
Expand Down Expand Up @@ -80,7 +83,9 @@ export class Redirects {
* Remove the redirect for the current project.
*/
async remove(id: string): Promise<DeletedResponse> {
const { data } = await this.project.delete<DeletedResponse>(`redirects/${id}`)
const { data } = await this.project.delete<DeletedResponse>(
`redirects/${id}`
)

return data
}
Expand Down