@bcis/sdk 0.0.1 → 0.1.0
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/README.md +270 -1
- package/dist/index.d.mts +604 -0
- package/dist/index.d.ts +604 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -15
- package/.github/workflows/npm-publish.yml +0 -31
- package/.github/workflows/release.yml +0 -30
- package/.github/workflows/tag.yml +0 -17
- package/LICENSE +0 -201
- package/index.js +0 -5
package/README.md
CHANGED
|
@@ -1 +1,270 @@
|
|
|
1
|
-
# sdk
|
|
1
|
+
# @bcis/sdk
|
|
2
|
+
|
|
3
|
+
> **Auto-generated** — re-run `npm run generate` in the `sdk-generator` project to update this file.
|
|
4
|
+
|
|
5
|
+
Type-safe TypeScript SDK for the [BCIS (Building Cost Information Service)](https://bcis.co.uk) APIs.
|
|
6
|
+
Supports both **ESM** and **CommonJS** environments with full TypeScript declarations.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @bcis/sdk
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Authentication
|
|
19
|
+
|
|
20
|
+
All BCIS APIs require a Bearer JWT obtained via OAuth2.
|
|
21
|
+
The `AuthManager` class handles token acquisition, caching, and renewal automatically.
|
|
22
|
+
|
|
23
|
+
### Client Credentials (server-to-server)
|
|
24
|
+
|
|
25
|
+
Use this flow for back-end or machine-to-machine integrations.
|
|
26
|
+
Tokens are fetched and renewed automatically — no user interaction required.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { AuthManager, CoreApiClient, ResidentialRebuildClient, ScheduleOfRatesClient } from '@bcis/sdk';
|
|
30
|
+
|
|
31
|
+
const auth = new AuthManager({
|
|
32
|
+
flow: 'client-credentials',
|
|
33
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
34
|
+
clientSecret: 'YOUR_CLIENT_SECRET',
|
|
35
|
+
tokenUrl: 'https://auth.bcis.co.uk/oauth/token',
|
|
36
|
+
scopes: ['openid'], // optional
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Authorization Code + PKCE (user-facing applications)
|
|
41
|
+
|
|
42
|
+
Use this flow when your application acts on behalf of a logged-in user.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { AuthManager } from '@bcis/sdk';
|
|
46
|
+
|
|
47
|
+
const auth = new AuthManager({
|
|
48
|
+
flow: 'authorization-code',
|
|
49
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
50
|
+
tokenUrl: 'https://auth.bcis.co.uk/oauth/token',
|
|
51
|
+
authorizationUrl: 'https://auth.bcis.co.uk/authorize',
|
|
52
|
+
redirectUri: 'https://yourapp.com/callback',
|
|
53
|
+
scopes: ['openid', 'profile'],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Step 1 — redirect the user
|
|
57
|
+
const { url, codeVerifier } = await auth.getAuthorizationUrl();
|
|
58
|
+
// persist codeVerifier (e.g. in session), then redirect browser to url
|
|
59
|
+
|
|
60
|
+
// Step 2 — handle the callback (after user authenticates)
|
|
61
|
+
await auth.handleCallback(code, codeVerifier);
|
|
62
|
+
|
|
63
|
+
// Step 3 — the SDK will now attach the token to every request automatically
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Available Clients
|
|
69
|
+
|
|
70
|
+
### `CoreApiClient`
|
|
71
|
+
|
|
72
|
+
**Base URL:** `https://api.bcis.co.uk/core-apis`
|
|
73
|
+
|
|
74
|
+
Core APIs Documentation
|
|
75
|
+
|
|
76
|
+
**Instantiation:**
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { AuthManager, CoreApiClient } from '@bcis/sdk';
|
|
80
|
+
|
|
81
|
+
const client = new CoreApiClient(auth);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Methods:**
|
|
85
|
+
|
|
86
|
+
#### `abpRetrieve(params: AbpRetrieveParams): Promise<AbpResponseDto>`
|
|
87
|
+
|
|
88
|
+
Returns results from one of the BCIS Average prices studies
|
|
89
|
+
|
|
90
|
+
| Parameter | Type | Required | Description |
|
|
91
|
+
|-----------|------|:--------:|-------------|
|
|
92
|
+
| `include-data-for-graph` | boolean | | When true, returns additional data for graph plotting. Default false. |
|
|
93
|
+
| `include-subclasses` | boolean | | When true, includes sub-divided categories (e.g., size bands) in results. Default false. |
|
|
94
|
+
| `building-function` | string[] | ✓ | A comma-separated list of building function codes used to filter study results. [See the Codes Update API](/docs/bcis-gr |
|
|
95
|
+
| `type-of-work` | string[] | ✓ | A list of type of work codes to filter the results by, the example contains all valid codes. |
|
|
96
|
+
| `abp-study` | `'ABPBUI'` \| `'ABPFUN'` \| `'ABPGRP'` \| `'ABPEM2'` \| `'ABPEUR'` \| `'ABPEXT'` | ✓ | A six-character code identifying the BCIS study |
|
|
97
|
+
|
|
98
|
+
#### `indicesRetrieve(params: IndicesRetrieveParams): Promise<IndicesResponseDto>`
|
|
99
|
+
|
|
100
|
+
Returns index figures from one or more index series
|
|
101
|
+
|
|
102
|
+
| Parameter | Type | Required | Description |
|
|
103
|
+
|-----------|------|:--------:|-------------|
|
|
104
|
+
| `base-of-series` | string | | Restricts the index series by year e.g. `1985` or description `1985 mean = 100`. Ignored if a series number is provided. |
|
|
105
|
+
| `regularity` | string[] | | Restricts index series by `regularity` (`monthly`, `quarterly`, `annual`). Ignored if a series number is used. Defaults |
|
|
106
|
+
| `end-date` | string | | Restricts index figures up to a specific month `yyyy-mm`, or leave blank for latest available. |
|
|
107
|
+
| `start-date` | string | | Restricts index figures to a specific month `yyyy-mm`, or leave blank for earliest available. |
|
|
108
|
+
| `series-identification` | string[] | ✓ | Comma-delimited list of short names (e.g. `BCISTPI:AllIn`) or series numbers. [See the Codes Update API](/docs/bcis-grac |
|
|
109
|
+
|
|
110
|
+
#### `tpsRetrieve(params: TpsRetrieveParams): Promise<TpsResponseDto>`
|
|
111
|
+
|
|
112
|
+
Returns results from one of the BCIS Average prices studies
|
|
113
|
+
|
|
114
|
+
| Parameter | Type | Required | Description |
|
|
115
|
+
|-----------|------|:--------:|-------------|
|
|
116
|
+
| `short-tps-name` | string | ✓ | Supports suffixes to filter or refine the study data: - Level Filters: - `:region`, `:county`, `:district` |
|
|
117
|
+
|
|
118
|
+
#### `codesUpdate(params: CodesUpdateParams): Promise<CodesResponseDto>`
|
|
119
|
+
|
|
120
|
+
Returns codes lists or other supporting data
|
|
121
|
+
|
|
122
|
+
| Parameter | Type | Required | Description |
|
|
123
|
+
|-----------|------|:--------:|-------------|
|
|
124
|
+
| `if-changed-since` | string | | A date in `yyyy-mm-dd` format. Returns only codes added or modified since this date. Not supported for all code types. L |
|
|
125
|
+
| `version` | string | | A version string to select relevant code tables. |
|
|
126
|
+
| `code-type` | `'shortTPSName'` \| `'ABPStudy'` \| `'BuildingFunction'` \| `'BuildingFunction:Categories'` \| `'BuildingFunction:[1-9]'` \| `'BuildingFunction:Duration'` \| `'BuildingFunction:Duration:Categories'` \| `'BuildingFunction:Duration:[1-9]'` \| `'BuildingFunction:ABP'` \| `'SimplifiedTypeOfWork'` | ✓ | A string to select the code list required. The supported values are: - `seriesIdentification`: All regularity name |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### `ResidentialRebuildClient`
|
|
131
|
+
|
|
132
|
+
**Base URL:** `https://api.bcis.co.uk/residential-rebuild-calculator`
|
|
133
|
+
|
|
134
|
+
The BCIS Rebuild Lookup Service calculates the reinstatement cost of a house or flat using minimal information.
|
|
135
|
+
The target audience includes insurance companies and brokers that require rebuilding costs when quoting a policy on a website or using software.
|
|
136
|
+
|
|
137
|
+
**Instantiation:**
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { AuthManager, ResidentialRebuildClient } from '@bcis/sdk';
|
|
141
|
+
|
|
142
|
+
const client = new ResidentialRebuildClient(auth);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Methods:**
|
|
146
|
+
|
|
147
|
+
#### `calculate(params: CalculateParams): Promise<CalculationResponse>`
|
|
148
|
+
|
|
149
|
+
Calculate the reinstatement cost of a house or flat
|
|
150
|
+
|
|
151
|
+
| Parameter | Type | Required | Description |
|
|
152
|
+
|-----------|------|:--------:|-------------|
|
|
153
|
+
| `postCode` | string | ✓ | Postcode of the property |
|
|
154
|
+
| `type` | string | ✓ | Type of the property |
|
|
155
|
+
| `storeys` | string | ✓ | Number of storeys in the property |
|
|
156
|
+
| `style` | string | ✓ | Style of the property: detached, terraced, etc |
|
|
157
|
+
| `wallType` | string | ✓ | Type of the walls of the property |
|
|
158
|
+
| `roofType` | string | | Type of the roof of the property |
|
|
159
|
+
| `yearBuilt` | number | ✓ | Year the property was built |
|
|
160
|
+
| `noOfFlats` | number | | Number of flats |
|
|
161
|
+
| `area` | number | | Area of the property in sq.m. |
|
|
162
|
+
| `noOfRooms` | number | | Number of rooms in the property |
|
|
163
|
+
| `noOfBedrooms` | number | | Number of bedrooms in the property |
|
|
164
|
+
| `noOfGarageSpaces` | number | | Number of garage spaces in the property |
|
|
165
|
+
| `noOfBathrooms` | number | | Number of bathrooms in the property |
|
|
166
|
+
| `specialFeatures` | string | | Special features of the property, Must be blank, or a comma delimited list containing one or more of 'cellar' or 'noexte |
|
|
167
|
+
|
|
168
|
+
#### `reportUsage(params: ReportUsageParams): Promise<UsageResponse>`
|
|
169
|
+
|
|
170
|
+
Usage of the calculations endpoint within a specified date range
|
|
171
|
+
|
|
172
|
+
| Parameter | Type | Required | Description |
|
|
173
|
+
|-----------|------|:--------:|-------------|
|
|
174
|
+
| `startMonth` | string | | First month of the usage report |
|
|
175
|
+
| `endMonth` | string | | Last month of the usage report |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### `ScheduleOfRatesClient`
|
|
180
|
+
|
|
181
|
+
**Base URL:** `https://api.bcis.co.uk/schedule-of-rates`
|
|
182
|
+
|
|
183
|
+
The BCIS Schedule of Rates API is designed for integration with your applications and workflows, the API enables you to retrieve and analyse comprehensive pricing information to support accurate project estimation and cost management.
|
|
184
|
+
|
|
185
|
+
**Instantiation:**
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { AuthManager, ScheduleOfRatesClient } from '@bcis/sdk';
|
|
189
|
+
|
|
190
|
+
const client = new ScheduleOfRatesClient(auth);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Methods:**
|
|
194
|
+
|
|
195
|
+
#### `getBooksEdition(): Promise<EditionsDto>`
|
|
196
|
+
|
|
197
|
+
Lists books and editions available to user
|
|
198
|
+
|
|
199
|
+
#### `getRates(params: GetRatesParams): Promise<GetRateResponseDto>`
|
|
200
|
+
|
|
201
|
+
Lists matching rates
|
|
202
|
+
|
|
203
|
+
| Parameter | Type | Required | Description |
|
|
204
|
+
|-----------|------|:--------:|-------------|
|
|
205
|
+
| `selected-node-id` | string | | node id, returned data are for the selected node |
|
|
206
|
+
| `filter-text` | string | | filter term, returned nodes contain the text somewhere in that branch |
|
|
207
|
+
| `edition-id` | string | ✓ | id obtained from get-books-edition |
|
|
208
|
+
|
|
209
|
+
#### `getResources(params: GetResourcesParams): Promise<GetResourceResponseDto>`
|
|
210
|
+
|
|
211
|
+
Lists matching resources
|
|
212
|
+
|
|
213
|
+
| Parameter | Type | Required | Description |
|
|
214
|
+
|-----------|------|:--------:|-------------|
|
|
215
|
+
| `selected-node-id` | string | | node id, returned data are for the selected node |
|
|
216
|
+
| `filter-text` | string | | filter term, returned nodes contain the text somewhere in that branch |
|
|
217
|
+
| `edition-id` | string | ✓ | id obtained from get-books-edition |
|
|
218
|
+
|
|
219
|
+
#### `getBuildUp(params: GetBuildUpParams): Promise<GetBuildUpResponseDto>`
|
|
220
|
+
|
|
221
|
+
Lists components of a rate or buildUp
|
|
222
|
+
|
|
223
|
+
| Parameter | Type | Required | Description |
|
|
224
|
+
|-----------|------|:--------:|-------------|
|
|
225
|
+
| `entity-id` | string | ✓ | Id as returned from GetRates or GetResources |
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Error Handling
|
|
231
|
+
|
|
232
|
+
`BcisApiError` is thrown for any non-2xx HTTP response.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { BcisApiError, CoreApiClient } from '@bcis/sdk';
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
const result = await coreApi.abpRetrieve({ ... });
|
|
239
|
+
} catch (err) {
|
|
240
|
+
if (err instanceof BcisApiError) {
|
|
241
|
+
console.error(err.status, err.statusText, err.body);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## TypeScript
|
|
249
|
+
|
|
250
|
+
All parameter and response types are exported from the package root:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import type {
|
|
254
|
+
// Auth
|
|
255
|
+
AuthConfig,
|
|
256
|
+
ClientCredentialsConfig,
|
|
257
|
+
AuthorizationCodeConfig,
|
|
258
|
+
// Response types (one per API)
|
|
259
|
+
AbpResponseDto,
|
|
260
|
+
IndicesResponseDto,
|
|
261
|
+
TpsResponseDto,
|
|
262
|
+
CodesResponseDto,
|
|
263
|
+
CalculationResponse,
|
|
264
|
+
UsageResponse,
|
|
265
|
+
EditionsDto,
|
|
266
|
+
GetRateResponseDto,
|
|
267
|
+
GetResourceResponseDto,
|
|
268
|
+
GetBuildUpResponseDto,
|
|
269
|
+
} from '@bcis/sdk';
|
|
270
|
+
```
|