@bcis/sdk 0.0.1 → 0.1.1

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