-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
150 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@k-phoen/backstage-plugin-announcements-backend': minor | ||
'@k-phoen/backstage-plugin-announcements-common': minor | ||
'@k-phoen/backstage-plugin-announcements': minor | ||
--- | ||
|
||
Correctly index announcements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,54 @@ | ||
import fetch from 'node-fetch'; | ||
import { DiscoveryApi } from '@backstage/core-plugin-api'; | ||
import { ResponseError } from '@backstage/errors'; | ||
|
||
export type Announcement = { | ||
id: string; | ||
publisher: string; | ||
title: string; | ||
excerpt: string; | ||
body: string; | ||
created_at: string; | ||
}; | ||
import { TokenManager } from '@backstage/backend-common'; | ||
import { | ||
Announcement, | ||
AnnouncementsList, | ||
} from '@k-phoen/backstage-plugin-announcements-common'; | ||
|
||
export class AnnouncementsClient { | ||
private readonly discoveryApi: DiscoveryApi; | ||
private readonly tokenManager?: TokenManager; | ||
|
||
constructor(opts: { discoveryApi: DiscoveryApi }) { | ||
constructor(opts: { | ||
discoveryApi: DiscoveryApi; | ||
tokenManager?: TokenManager; | ||
}) { | ||
this.discoveryApi = opts.discoveryApi; | ||
} | ||
|
||
private async fetch<T = any>(input: string): Promise<T> { | ||
const baseApiUrl = await this.discoveryApi.getBaseUrl('announcements'); | ||
|
||
const response = await fetch(`${baseApiUrl}${input}`); | ||
let headers = {}; | ||
|
||
if (this.tokenManager) { | ||
const { token } = await this.tokenManager.getToken(); | ||
headers = { | ||
Authorization: `Bearer ${token}`, | ||
}; | ||
} | ||
|
||
const response = await fetch(`${baseApiUrl}${input}`, headers); | ||
if (!response.ok) { | ||
throw await ResponseError.fromResponse(response); | ||
} | ||
|
||
return response.json() as Promise<T>; | ||
} | ||
|
||
async announcements(): Promise<Announcement[]> { | ||
return await this.fetch<Announcement[]>('/'); | ||
async announcements({ | ||
page, | ||
maxPerPage, | ||
}: { | ||
page: number; | ||
maxPerPage: number; | ||
}): Promise<Announcement[]> { | ||
return this.fetch<AnnouncementsList>( | ||
`/announcements?page=${page}&max=${maxPerPage}`, | ||
).then(response => { | ||
return response.results || []; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './permissions'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { IndexableDocument } from '@backstage/plugin-search-common'; | ||
|
||
export type Category = { | ||
slug: string; | ||
title: string; | ||
}; | ||
|
||
export type Announcement = { | ||
id: string; | ||
category?: Category; | ||
publisher: string; | ||
title: string; | ||
excerpt: string; | ||
body: string; | ||
created_at: string; | ||
}; | ||
|
||
export type AnnouncementsList = { | ||
count: number; | ||
results: Announcement[]; | ||
}; | ||
|
||
export type IndexableAnnouncement = IndexableDocument & { | ||
excerpt: string; | ||
createdAt: string; | ||
}; | ||
|
||
export type CreateAnnouncementRequest = Omit< | ||
Announcement, | ||
'id' | 'category' | 'created_at' | ||
> & { | ||
category?: string; | ||
}; | ||
|
||
export type UpdateAnnouncementRequest = CreateAnnouncementRequest; | ||
|
||
export type CreateCategoryRequest = { | ||
title: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.