diff --git a/src/api-client.ts b/src/api-client.ts index de07238..e6a5de1 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -35,12 +35,13 @@ export interface PluginApiClientOptions { /** * PluginApiClient provides typed methods for common Paca API calls. - * Plugin route calls are automatically prefixed with - * `/plugins/{pluginId}/projects/{projectId}/`. + * Plugin route calls are prefixed with `/plugins/{pluginId}/`. + * Use the `projectId` property to include project context in paths when needed: + * `pluginGet(id, \`/projects/${api.projectId}/my-resource\`)` */ export class PluginApiClient { private readonly baseUrl: string; - private readonly projectId: string; + public readonly projectId: string; private readonly _fetch: PluginApiClientOptions["fetch"]; constructor(opts: PluginApiClientOptions) { @@ -96,8 +97,9 @@ export class PluginApiClient { /** * Call a GET route registered by this plugin. - * The URL is built as: - * `{baseUrl}/plugins/{pluginId}/projects/{projectId}/{path}` + * The URL is built as `{baseUrl}/plugins/{pluginId}{path}`. + * For project-scoped routes, include the project prefix in `path`: + * `pluginGet(id, \`/projects/${api.projectId}/resource\`)` */ async pluginGet(pluginId: string, path: string): Promise { return this._get(this._pluginUrl(pluginId, path)); @@ -140,7 +142,7 @@ export class PluginApiClient { private _pluginUrl(pluginId: string, path: string): string { const p = path.startsWith("/") ? path : `/${path}`; - return `${this.baseUrl}/plugins/${pluginId}/projects/${this.projectId}${p}`; + return `${this.baseUrl}/plugins/${pluginId}${p}`; } private async _get(url: string): Promise {