@izak0s/spacebring-api 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/LICENSE +21 -0
- package/README.md +116 -0
- package/dist/index.cjs +2098 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27384 -0
- package/dist/index.d.ts +27384 -0
- package/dist/index.js +2070 -0
- package/dist/index.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 izak.amsterdam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# spacebring-api
|
|
2
|
+
|
|
3
|
+
[](https://github.com/izak0s/spacebring-api/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@izak0s/spacebring-api)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
A fully-typed TypeScript client for the [Spacebring](https://www.spacebring.com) coworking space management API, auto-generated from the official OpenAPI spec.
|
|
8
|
+
|
|
9
|
+
> **Community package** — This is not an official Spacebring package. It is independently developed and maintained by the community. Use at your own risk. For the official API documentation, see [spacebring.com/docs/api](https://www.spacebring.com/docs/api).
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **<!-- coverage -->162 operations across 20 resource groups<!-- /coverage -->** — the full Spacebring API surface
|
|
16
|
+
- **Auto-generated** from the official OpenAPI spec — types and facade regenerate anytime the spec changes
|
|
17
|
+
- **Nested, discoverable API** — `sb.billing.invoices.pay(id)`, `sb.visitors.visits.checkIn(body)`
|
|
18
|
+
- **Auto-pagination** — every paginated list endpoint has an `iterate()` async generator that walks `nextPageToken` for you
|
|
19
|
+
- **Ergonomic returns** — single-property response envelopes are unwrapped: entities and plain arrays come back directly
|
|
20
|
+
- **Rich error handling** — non-2xx responses throw a typed `SpacebringError`; malformed 2xx bodies and stuck pagination tokens throw instead of failing silently
|
|
21
|
+
- **Zero runtime dependencies** — Node ≥ 20, `fetch`-based
|
|
22
|
+
- **Dual module** — ships both ESM and CommonJS builds with type declarations for each
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm install @izak0s/spacebring-api
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
No runtime dependencies — HTTP uses the built-in `fetch`.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { Spacebring } from "@izak0s/spacebring-api";
|
|
40
|
+
|
|
41
|
+
const sb = new Spacebring({
|
|
42
|
+
clientId: process.env.SPACEBRING_CLIENT_ID!,
|
|
43
|
+
clientSecret: process.env.SPACEBRING_CLIENT_SECRET!,
|
|
44
|
+
networkId: "your-network-id", // optional, sent as spacebring-network-id header
|
|
45
|
+
// baseUrl: "https://api.spacebring.com", // default
|
|
46
|
+
// fetch: customFetch, // inject your own fetch (tests, proxies)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Single-property envelopes are unwrapped: entities and plain arrays come back directly
|
|
50
|
+
const invoice = await sb.billing.invoices.get(invoiceId);
|
|
51
|
+
const locations = await sb.locations.list();
|
|
52
|
+
await sb.visitors.visits.checkIn({ locationRef, visitRef });
|
|
53
|
+
|
|
54
|
+
// Paginated lists return the page envelope, so nextPageToken stays available
|
|
55
|
+
const { benefits, nextPageToken } = await sb.benefits.list({ locationRef });
|
|
56
|
+
|
|
57
|
+
// ...or let iterate() walk nextPageToken for you; breaking early stops fetching
|
|
58
|
+
for await (const booking of sb.resources.bookings.iterate({ locationRef })) {
|
|
59
|
+
console.log(booking.id);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Endpoints returning multiple payloads keep the envelope
|
|
63
|
+
const { invoice: paid, payment } = await sb.billing.invoices.pay(invoiceId, {
|
|
64
|
+
paymentMethod: { type: "stripe" },
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
TypeScript helpers are exported too: `SpacebringConfig`, `SpacebringResources`, and the raw spec types `paths` / `components` / `operations` (e.g. `components["schemas"]["invoice"]`).
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Authentication
|
|
73
|
+
|
|
74
|
+
HTTP Basic with your **Client ID** and **Client Secret** from **Spacebring → [Network] → Network Settings → Developers**. The client builds the `Authorization: Basic …` header for you. The API's OAuth2 flow is not currently supported.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Error handling
|
|
79
|
+
|
|
80
|
+
Non-2xx responses throw `SpacebringError`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { SpacebringError } from "@izak0s/spacebring-api";
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
await sb.benefits.get(id);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof SpacebringError) {
|
|
89
|
+
console.error(error.status, error.body?.message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Malformed successes are covered too: a 2xx with an empty or incomplete body throws a `SpacebringError` (never a bare `TypeError`), and `iterate()` throws instead of looping forever if the API repeats a page token.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Escape hatch
|
|
99
|
+
|
|
100
|
+
`sb.raw` is a typed [openapi-fetch](https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-fetch) client for anything the facade doesn't expose (custom headers, response inspection):
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const { data, error, response } = await sb.raw.GET("/networks/v1", {});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Keeping up with API changes
|
|
109
|
+
|
|
110
|
+
The whole client (types + methods) is generated from Spacebring's OpenAPI spec; a nightly GitHub Action picks up spec changes and publishes a new version automatically. Details in [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
[MIT](LICENSE)
|