Skip to content

Commit 77369f1

Browse files
committed
fix: update PluginApiClient URL construction for project context
1 parent d949650 commit 77369f1

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/api-client.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ export interface PluginApiClientOptions {
3535

3636
/**
3737
* PluginApiClient provides typed methods for common Paca API calls.
38-
* Plugin route calls are automatically prefixed with
39-
* `/plugins/{pluginId}/projects/{projectId}/`.
38+
* Plugin route calls are prefixed with `/plugins/{pluginId}/`.
39+
* Use the `projectId` property to include project context in paths when needed:
40+
* `pluginGet(id, \`/projects/${api.projectId}/my-resource\`)`
4041
*/
4142
export class PluginApiClient {
4243
private readonly baseUrl: string;
43-
private readonly projectId: string;
44+
public readonly projectId: string;
4445
private readonly _fetch: PluginApiClientOptions["fetch"];
4546

4647
constructor(opts: PluginApiClientOptions) {
@@ -96,8 +97,9 @@ export class PluginApiClient {
9697

9798
/**
9899
* Call a GET route registered by this plugin.
99-
* The URL is built as:
100-
* `{baseUrl}/plugins/{pluginId}/projects/{projectId}/{path}`
100+
* The URL is built as `{baseUrl}/plugins/{pluginId}{path}`.
101+
* For project-scoped routes, include the project prefix in `path`:
102+
* `pluginGet(id, \`/projects/${api.projectId}/resource\`)`
101103
*/
102104
async pluginGet<T>(pluginId: string, path: string): Promise<T> {
103105
return this._get<T>(this._pluginUrl(pluginId, path));
@@ -140,7 +142,7 @@ export class PluginApiClient {
140142

141143
private _pluginUrl(pluginId: string, path: string): string {
142144
const p = path.startsWith("/") ? path : `/${path}`;
143-
return `${this.baseUrl}/plugins/${pluginId}/projects/${this.projectId}${p}`;
145+
return `${this.baseUrl}/plugins/${pluginId}${p}`;
144146
}
145147

146148
private async _get<T>(url: string): Promise<T> {

0 commit comments

Comments
 (0)