@backstage/plugin-bitbucket-cloud-common 0.3.4-next.0 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @backstage/plugin-bitbucket-cloud-common
|
|
2
2
|
|
|
3
|
+
## 0.3.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fa255f5: Support for Bitbucket Cloud's API token was added as `appPassword` is deprecated (no new creation from September 9, 2025) and will be removed on June 9, 2026.
|
|
8
|
+
|
|
9
|
+
API token usage example:
|
|
10
|
+
|
|
11
|
+
```yaml
|
|
12
|
+
integrations:
|
|
13
|
+
bitbucketCloud:
|
|
14
|
+
- username: user@domain.com
|
|
15
|
+
token: my-token
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- 05f60e1: Refactored constructor parameter properties to explicit property declarations for compatibility with TypeScript's `erasableSyntaxOnly` setting. This internal refactoring maintains all existing functionality while ensuring TypeScript compilation compatibility.
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @backstage/integration@1.18.2
|
|
21
|
+
|
|
3
22
|
## 0.3.4-next.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -96,14 +96,12 @@ class BitbucketCloudClient {
|
|
|
96
96
|
}
|
|
97
97
|
getAuthHeaders() {
|
|
98
98
|
const headers = {};
|
|
99
|
-
if (this.config.username) {
|
|
99
|
+
if (this.config.username && (this.config.token ?? this.config.appPassword)) {
|
|
100
100
|
const buffer = Buffer.from(
|
|
101
|
-
`${this.config.username}:${this.config.appPassword}`,
|
|
101
|
+
`${this.config.username}:${this.config.token ?? this.config.appPassword}`,
|
|
102
102
|
"utf8"
|
|
103
103
|
);
|
|
104
104
|
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
105
|
-
} else if (this.config.token) {
|
|
106
|
-
headers.Authorization = `Bearer ${this.config.token}`;
|
|
107
105
|
}
|
|
108
106
|
return headers;
|
|
109
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitbucketCloudClient.cjs.js","sources":["../src/BitbucketCloudClient.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BitbucketCloudIntegrationConfig } from '@backstage/integration';\nimport fetch, { Request } from 'cross-fetch';\nimport { Models } from './models';\nimport { WithPagination } from './pagination';\nimport {\n FilterAndSortOptions,\n PartialResponseOptions,\n RequestOptions,\n} from './types';\n\n/** @public */\nexport class BitbucketCloudClient {\n static fromConfig(\n config: BitbucketCloudIntegrationConfig,\n ): BitbucketCloudClient {\n return new BitbucketCloudClient(config);\n }\n\n private constructor(\n private readonly config: BitbucketCloudIntegrationConfig,\n ) {}\n\n searchCode(\n workspace: string,\n query: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n pagelen?: number,\n ): WithPagination<Models.SearchResultPage, Models.SearchCodeSearchResult> {\n const workspaceEnc = encodeURIComponent(workspace);\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/search/code`, {\n ...paginationOptions,\n ...options,\n search_query: query,\n }),\n url => this.getTypeMapped(url),\n pagelen,\n );\n }\n\n listRepositoriesByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedRepositories, Models.Repository> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/repositories/${workspaceEnc}`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listProjectsByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedProjects, Models.Project> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/projects`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listWorkspaces(\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedWorkspaces, Models.Workspace> {\n return new WithPagination(\n paginationOptions =>\n this.createUrl('/workspaces', { ...paginationOptions, ...options }),\n url => this.getTypeMapped(url),\n );\n }\n\n listBranchesByRepository(\n repository: string,\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedBranches, Models.Branch> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(\n `/repositories/${workspaceEnc}/${repository}/refs/branches`,\n {\n ...paginationOptions,\n ...options,\n },\n ),\n url => this.getTypeMapped(url),\n );\n }\n\n private createUrl(endpoint: string, options?: RequestOptions): URL {\n const request = new URL(this.config.apiBaseUrl + endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n\n return request;\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then(\n (response: Response) => response.json() as Promise<T>,\n );\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, { headers: this.getAuthHeaders() }).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n\n return response;\n },\n );\n }\n\n private getAuthHeaders(): Record<string, string> {\n const headers: Record<string, string> = {};\n\n if (this.config.username) {\n const buffer = Buffer.from(\n `${this.config.username}:${this.config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }
|
|
1
|
+
{"version":3,"file":"BitbucketCloudClient.cjs.js","sources":["../src/BitbucketCloudClient.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BitbucketCloudIntegrationConfig } from '@backstage/integration';\nimport fetch, { Request } from 'cross-fetch';\nimport { Models } from './models';\nimport { WithPagination } from './pagination';\nimport {\n FilterAndSortOptions,\n PartialResponseOptions,\n RequestOptions,\n} from './types';\n\n/** @public */\nexport class BitbucketCloudClient {\n static fromConfig(\n config: BitbucketCloudIntegrationConfig,\n ): BitbucketCloudClient {\n return new BitbucketCloudClient(config);\n }\n\n private constructor(\n private readonly config: BitbucketCloudIntegrationConfig,\n ) {}\n\n searchCode(\n workspace: string,\n query: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n pagelen?: number,\n ): WithPagination<Models.SearchResultPage, Models.SearchCodeSearchResult> {\n const workspaceEnc = encodeURIComponent(workspace);\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/search/code`, {\n ...paginationOptions,\n ...options,\n search_query: query,\n }),\n url => this.getTypeMapped(url),\n pagelen,\n );\n }\n\n listRepositoriesByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedRepositories, Models.Repository> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/repositories/${workspaceEnc}`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listProjectsByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedProjects, Models.Project> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/projects`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listWorkspaces(\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedWorkspaces, Models.Workspace> {\n return new WithPagination(\n paginationOptions =>\n this.createUrl('/workspaces', { ...paginationOptions, ...options }),\n url => this.getTypeMapped(url),\n );\n }\n\n listBranchesByRepository(\n repository: string,\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedBranches, Models.Branch> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(\n `/repositories/${workspaceEnc}/${repository}/refs/branches`,\n {\n ...paginationOptions,\n ...options,\n },\n ),\n url => this.getTypeMapped(url),\n );\n }\n\n private createUrl(endpoint: string, options?: RequestOptions): URL {\n const request = new URL(this.config.apiBaseUrl + endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n\n return request;\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then(\n (response: Response) => response.json() as Promise<T>,\n );\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, { headers: this.getAuthHeaders() }).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n\n return response;\n },\n );\n }\n\n private getAuthHeaders(): Record<string, string> {\n const headers: Record<string, string> = {};\n\n if (\n this.config.username &&\n (this.config.token ?? this.config.appPassword)\n ) {\n const buffer = Buffer.from(\n `${this.config.username}:${\n this.config.token ?? this.config.appPassword\n }`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return headers;\n }\n}\n"],"names":["WithPagination","Request","fetch"],"mappings":";;;;;;;;;AA2BO,MAAM,oBAAA,CAAqB;AAAA,EAOxB,YACW,MAAA,EACjB;AADiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAChB;AAAA,EARH,OAAO,WACL,MAAA,EACsB;AACtB,IAAA,OAAO,IAAI,qBAAqB,MAAM,CAAA;AAAA,EACxC;AAAA,EAMA,UAAA,CACE,SAAA,EACA,KAAA,EACA,OAAA,EACA,OAAA,EACwE;AACxE,IAAA,MAAM,YAAA,GAAe,mBAAmB,SAAS,CAAA;AACjD,IAAA,OAAO,IAAIA,yBAAA;AAAA,MACT,CAAA,iBAAA,KACE,IAAA,CAAK,SAAA,CAAU,CAAA,YAAA,EAAe,YAAY,CAAA,YAAA,CAAA,EAAgB;AAAA,QACxD,GAAG,iBAAA;AAAA,QACH,GAAG,OAAA;AAAA,QACH,YAAA,EAAc;AAAA,OACf,CAAA;AAAA,MACH,CAAA,GAAA,KAAO,IAAA,CAAK,aAAA,CAAc,GAAG,CAAA;AAAA,MAC7B;AAAA,KACF;AAAA,EACF;AAAA,EAEA,2BAAA,CACE,WACA,OAAA,EACiE;AACjE,IAAA,MAAM,YAAA,GAAe,mBAAmB,SAAS,CAAA;AAEjD,IAAA,OAAO,IAAIA,yBAAA;AAAA,MACT,CAAA,iBAAA,KACE,IAAA,CAAK,SAAA,CAAU,CAAA,cAAA,EAAiB,YAAY,CAAA,CAAA,EAAI;AAAA,QAC9C,GAAG,iBAAA;AAAA,QACH,GAAG;AAAA,OACJ,CAAA;AAAA,MACH,CAAA,GAAA,KAAO,IAAA,CAAK,aAAA,CAAc,GAAG;AAAA,K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AM,SAAS,MAAA,CAAO,IAAA;AAAA,QACpB,CAAA,EAAG,IAAA,CAAK,MAAA,CAAO,QAAQ,CAAA,CAAA,EACrB,KAAK,MAAA,CAAO,KAAA,IAAS,IAAA,CAAK,MAAA,CAAO,WACnC,CAAA,CAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,OAAA,CAAQ,aAAA,GAAgB,CAAA,MAAA,EAAS,MAAA,CAAO,QAAA,CAAS,QAAQ,CAAC,CAAA,CAAA;AAAA,IAC5D;AAEA,IAAA,OAAO,OAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -90,14 +90,12 @@ class BitbucketCloudClient {
|
|
|
90
90
|
}
|
|
91
91
|
getAuthHeaders() {
|
|
92
92
|
const headers = {};
|
|
93
|
-
if (this.config.username) {
|
|
93
|
+
if (this.config.username && (this.config.token ?? this.config.appPassword)) {
|
|
94
94
|
const buffer = Buffer.from(
|
|
95
|
-
`${this.config.username}:${this.config.appPassword}`,
|
|
95
|
+
`${this.config.username}:${this.config.token ?? this.config.appPassword}`,
|
|
96
96
|
"utf8"
|
|
97
97
|
);
|
|
98
98
|
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
99
|
-
} else if (this.config.token) {
|
|
100
|
-
headers.Authorization = `Bearer ${this.config.token}`;
|
|
101
99
|
}
|
|
102
100
|
return headers;
|
|
103
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitbucketCloudClient.esm.js","sources":["../src/BitbucketCloudClient.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BitbucketCloudIntegrationConfig } from '@backstage/integration';\nimport fetch, { Request } from 'cross-fetch';\nimport { Models } from './models';\nimport { WithPagination } from './pagination';\nimport {\n FilterAndSortOptions,\n PartialResponseOptions,\n RequestOptions,\n} from './types';\n\n/** @public */\nexport class BitbucketCloudClient {\n static fromConfig(\n config: BitbucketCloudIntegrationConfig,\n ): BitbucketCloudClient {\n return new BitbucketCloudClient(config);\n }\n\n private constructor(\n private readonly config: BitbucketCloudIntegrationConfig,\n ) {}\n\n searchCode(\n workspace: string,\n query: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n pagelen?: number,\n ): WithPagination<Models.SearchResultPage, Models.SearchCodeSearchResult> {\n const workspaceEnc = encodeURIComponent(workspace);\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/search/code`, {\n ...paginationOptions,\n ...options,\n search_query: query,\n }),\n url => this.getTypeMapped(url),\n pagelen,\n );\n }\n\n listRepositoriesByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedRepositories, Models.Repository> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/repositories/${workspaceEnc}`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listProjectsByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedProjects, Models.Project> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/projects`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listWorkspaces(\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedWorkspaces, Models.Workspace> {\n return new WithPagination(\n paginationOptions =>\n this.createUrl('/workspaces', { ...paginationOptions, ...options }),\n url => this.getTypeMapped(url),\n );\n }\n\n listBranchesByRepository(\n repository: string,\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedBranches, Models.Branch> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(\n `/repositories/${workspaceEnc}/${repository}/refs/branches`,\n {\n ...paginationOptions,\n ...options,\n },\n ),\n url => this.getTypeMapped(url),\n );\n }\n\n private createUrl(endpoint: string, options?: RequestOptions): URL {\n const request = new URL(this.config.apiBaseUrl + endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n\n return request;\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then(\n (response: Response) => response.json() as Promise<T>,\n );\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, { headers: this.getAuthHeaders() }).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n\n return response;\n },\n );\n }\n\n private getAuthHeaders(): Record<string, string> {\n const headers: Record<string, string> = {};\n\n if (this.config.username) {\n const buffer = Buffer.from(\n `${this.config.username}:${this.config.appPassword}`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }
|
|
1
|
+
{"version":3,"file":"BitbucketCloudClient.esm.js","sources":["../src/BitbucketCloudClient.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BitbucketCloudIntegrationConfig } from '@backstage/integration';\nimport fetch, { Request } from 'cross-fetch';\nimport { Models } from './models';\nimport { WithPagination } from './pagination';\nimport {\n FilterAndSortOptions,\n PartialResponseOptions,\n RequestOptions,\n} from './types';\n\n/** @public */\nexport class BitbucketCloudClient {\n static fromConfig(\n config: BitbucketCloudIntegrationConfig,\n ): BitbucketCloudClient {\n return new BitbucketCloudClient(config);\n }\n\n private constructor(\n private readonly config: BitbucketCloudIntegrationConfig,\n ) {}\n\n searchCode(\n workspace: string,\n query: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n pagelen?: number,\n ): WithPagination<Models.SearchResultPage, Models.SearchCodeSearchResult> {\n const workspaceEnc = encodeURIComponent(workspace);\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/search/code`, {\n ...paginationOptions,\n ...options,\n search_query: query,\n }),\n url => this.getTypeMapped(url),\n pagelen,\n );\n }\n\n listRepositoriesByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedRepositories, Models.Repository> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/repositories/${workspaceEnc}`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listProjectsByWorkspace(\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedProjects, Models.Project> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(`/workspaces/${workspaceEnc}/projects`, {\n ...paginationOptions,\n ...options,\n }),\n url => this.getTypeMapped(url),\n );\n }\n\n listWorkspaces(\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedWorkspaces, Models.Workspace> {\n return new WithPagination(\n paginationOptions =>\n this.createUrl('/workspaces', { ...paginationOptions, ...options }),\n url => this.getTypeMapped(url),\n );\n }\n\n listBranchesByRepository(\n repository: string,\n workspace: string,\n options?: FilterAndSortOptions & PartialResponseOptions,\n ): WithPagination<Models.PaginatedBranches, Models.Branch> {\n const workspaceEnc = encodeURIComponent(workspace);\n\n return new WithPagination(\n paginationOptions =>\n this.createUrl(\n `/repositories/${workspaceEnc}/${repository}/refs/branches`,\n {\n ...paginationOptions,\n ...options,\n },\n ),\n url => this.getTypeMapped(url),\n );\n }\n\n private createUrl(endpoint: string, options?: RequestOptions): URL {\n const request = new URL(this.config.apiBaseUrl + endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n\n return request;\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then(\n (response: Response) => response.json() as Promise<T>,\n );\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, { headers: this.getAuthHeaders() }).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n\n return response;\n },\n );\n }\n\n private getAuthHeaders(): Record<string, string> {\n const headers: Record<string, string> = {};\n\n if (\n this.config.username &&\n (this.config.token ?? this.config.appPassword)\n ) {\n const buffer = Buffer.from(\n `${this.config.username}:${\n this.config.token ?? this.config.appPassword\n }`,\n 'utf8',\n );\n headers.Authorization = `Basic ${buffer.toString('base64')}`;\n }\n\n return headers;\n }\n}\n"],"names":[],"mappings":";;;AA2BO,MAAM,oBAAA,CAAqB;AAAA,EAOxB,YACW,MAAA,EACjB;AADiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAChB;AAAA,EARH,OAAO,WACL,MAAA,EACsB;AACtB,IAAA,OAAO,IAAI,qBAAqB,MAAM,CAAA;AAAA,EACxC;AAAA,EAMA,UAAA,CACE,SAAA,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3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Common functionalities for bitbucket-cloud plugins",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "common-library",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"update-models": "yarn refresh-schema && yarn generate-models && yarn reduce-models"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@backstage/integration": "1.18.2
|
|
44
|
+
"@backstage/integration": "^1.18.2",
|
|
45
45
|
"cross-fetch": "^4.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@backstage/cli": "0.34.5
|
|
48
|
+
"@backstage/cli": "^0.34.5",
|
|
49
49
|
"@openapitools/openapi-generator-cli": "^2.4.26",
|
|
50
50
|
"msw": "^1.0.0",
|
|
51
51
|
"ts-morph": "^24.0.0"
|