@k9o/core 0.0.0-stage → 1.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +4 -0
  4. package/README.md +253 -2
  5. package/dist/chunk-2NDFTHUB.js +93 -0
  6. package/dist/chunk-2NDFTHUB.js.map +1 -0
  7. package/dist/chunk-LJZ45UA2.js +33 -0
  8. package/dist/chunk-LJZ45UA2.js.map +1 -0
  9. package/dist/chunk-O2ZTV6YN.js +234 -0
  10. package/dist/chunk-O2ZTV6YN.js.map +1 -0
  11. package/dist/chunk-YEYRP6PG.js +1 -0
  12. package/dist/chunk-YEYRP6PG.js.map +1 -0
  13. package/dist/envelope.d.ts +94 -0
  14. package/dist/envelope.js +2 -0
  15. package/dist/envelope.js.map +1 -0
  16. package/dist/http.d.ts +86 -0
  17. package/dist/http.js +12 -0
  18. package/dist/http.js.map +1 -0
  19. package/dist/index.d.ts +2127 -0
  20. package/dist/index.js +1907 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/kerror.d.ts +73 -0
  23. package/dist/kerror.js +9 -0
  24. package/dist/kerror.js.map +1 -0
  25. package/dist/types.d.ts +62 -0
  26. package/dist/types.js +1 -0
  27. package/dist/types.js.map +1 -0
  28. package/dist/url-grammar.d.ts +75 -0
  29. package/dist/url-grammar.js +18 -0
  30. package/dist/url-grammar.js.map +1 -0
  31. package/package.json +69 -4
  32. package/src/ai.ts +56 -0
  33. package/src/audit.ts +100 -0
  34. package/src/byos.ts +192 -0
  35. package/src/compute/llms.ts +154 -0
  36. package/src/data/from.ts +346 -0
  37. package/src/envelope.ts +101 -0
  38. package/src/extensions-bridge.ts +33 -0
  39. package/src/functions.ts +114 -0
  40. package/src/gate-bridge.ts +65 -0
  41. package/src/http.ts +286 -0
  42. package/src/index.ts +304 -0
  43. package/src/internal/sse.ts +91 -0
  44. package/src/kerror.ts +92 -0
  45. package/src/me.ts +161 -0
  46. package/src/metadata.ts +130 -0
  47. package/src/migrations.ts +265 -0
  48. package/src/org.ts +347 -0
  49. package/src/orgs.ts +74 -0
  50. package/src/policies.ts +138 -0
  51. package/src/projects.ts +107 -0
  52. package/src/provider-region.ts +54 -0
  53. package/src/realtime.ts +350 -0
  54. package/src/region.ts +5 -0
  55. package/src/retry.ts +110 -0
  56. package/src/storage-buckets.ts +248 -0
  57. package/src/storage-locations.ts +177 -0
  58. package/src/studio/dashboards.ts +178 -0
  59. package/src/studio/index.ts +18 -0
  60. package/src/studio/workflows.ts +268 -0
  61. package/src/types.ts +74 -0
  62. package/src/url-grammar.ts +168 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog — @k9o/core
2
+
3
+ ## 1.1.0 — 2026-10-25
4
+
5
+ - Documentation rewritten with runnable examples and expected output; internal cross-references removed from the published sources. No change to the public API.
6
+ - Error text for `update()` / `delete()` without an `id` filter no longer mentions a version or a roadmap.
7
+
8
+ ## 1.0.0 — 2026-10-23
9
+
10
+ First public release. See the README for the full API overview.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Kilimanjaro SDK
2
+ Copyright 2026 Formelo Inc.
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
package/README.md CHANGED
@@ -1,3 +1,254 @@
1
- # Temporary Holding Version
1
+ # @k9o/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Kilimanjaro platform SDK for TypeScript and JavaScript. One client for your data, projects, functions, audit log and more.
4
+
5
+ ## Contents
6
+
7
+ - [Install](#install)
8
+ - [Quick start](#quick-start)
9
+ - [Authentication and project context](#authentication-and-project-context)
10
+ - [Running queries](#running-queries)
11
+ - [Handling errors](#handling-errors)
12
+ - [Regional hosts](#regional-hosts)
13
+ - [Appendix](#appendix)
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install @k9o/core
19
+ ```
20
+
21
+ ```bash
22
+ bun add @k9o/core
23
+ ```
24
+
25
+ ```bash
26
+ pnpm add @k9o/core
27
+ ```
28
+
29
+ Requires Node.js 18+, Bun 1.1+ or a browser with a global `fetch`. TypeScript 5.6+ is optional. See [Requirements](#requirements).
30
+
31
+ ## Quick start
32
+
33
+ The examples on this page use a `tasks` collection with a `title` and a `done` field.
34
+
35
+ ```ts
36
+ import { createClient } from "@k9o/core";
37
+
38
+ const client = createClient({
39
+ apiKey: process.env.K9O_API_KEY,
40
+ orgSlug: "acme",
41
+ projectSlug: "member-portal",
42
+ });
43
+
44
+ type Task = { id: string; title: string; done: boolean };
45
+
46
+ const created = await client.from("tasks").insert<Task>({ title: "Write the README", done: false });
47
+ const task = created.data;
48
+
49
+ console.log(task.title);
50
+ ```
51
+
52
+ ```text
53
+ Write the README
54
+ ```
55
+
56
+ Every method resolves to `{ data, meta }`. `data` is the typed result and `meta` holds response metadata.
57
+
58
+ ## Authentication and project context
59
+
60
+ Three options select who you are and where you work. See [Client options](#client-options) for the full list.
61
+
62
+ | Option | What it does |
63
+ | --- | --- |
64
+ | `apiKey` | Bearer token sent on every request. |
65
+ | `orgSlug` | Selects your organization. |
66
+ | `projectSlug` | Selects the project. Required by project-scoped calls. |
67
+
68
+ - On the default host, pass `orgSlug` and leave `baseUrl` out.
69
+ - On a self-hosted or custom host, pass `baseUrl` and leave `orgSlug` out.
70
+
71
+ ```ts
72
+ const client = createClient({
73
+ baseUrl: "https://acme.example.com",
74
+ apiKey: process.env.K9O_API_KEY,
75
+ projectSlug: "member-portal",
76
+ });
77
+ ```
78
+
79
+ To retry transient failures, add `retryConfig`. See [Retry settings](#retry-settings).
80
+
81
+ ## Running queries
82
+
83
+ `client.from(collection)` reads and writes records. Chain filters and paging, then await the result.
84
+
85
+ ```ts
86
+ const response = await client.from("tasks").select<Task>().eq("done", false).limit(10);
87
+
88
+ for (const openTask of response.data) {
89
+ console.log(openTask.title);
90
+ }
91
+ ```
92
+
93
+ Update or delete one record by id:
94
+
95
+ ```ts
96
+ const updated = await client.from("tasks").update<Task>({ done: true }).eq("id", task.id);
97
+
98
+ console.log(updated.data.done);
99
+ ```
100
+
101
+ ```text
102
+ true
103
+ ```
104
+
105
+ - `update` and `delete` need an `eq("id", ...)` filter. They never change many rows at once.
106
+ - See [Data methods](#data-methods) for filters and paging.
107
+ - Other namespaces such as projects, migrations and audit are listed in [Methods by namespace](#methods-by-namespace).
108
+
109
+ ## Handling errors
110
+
111
+ Every method throws `KError` when a request fails or the SDK rejects your input. Switch on `code`.
112
+
113
+ ```ts
114
+ import { KError } from "@k9o/core";
115
+
116
+ try {
117
+ await client.from("tasks").insert<Task>({ title: "One more task", done: false });
118
+ } catch (error) {
119
+ if (error instanceof KError && error.code === "K9O_TIER_CAP_HIT") {
120
+ console.warn(error.message, error.recommendation);
121
+ } else {
122
+ throw error;
123
+ }
124
+ }
125
+ ```
126
+
127
+ - `KError` also carries `context`, `status` and `requestId`. See [Error fields](#error-fields).
128
+ - The gateway can send many codes. See [Error codes](#error-codes) for the ones the SDK raises itself.
129
+
130
+ ## Regional hosts
131
+
132
+ - On an organization host such as `https://acme.api.k9o.io`, the client sends one `HEAD` request first.
133
+ - The request carries no credentials. It finds the regional host for your organization.
134
+ - All later requests go to that host. The answer is cached for the life of the client.
135
+ - Any other `baseUrl` is used as given. If the lookup fails, the configured host is used.
136
+
137
+ ## Appendix
138
+
139
+ ### Requirements
140
+
141
+ | Requirement | Version |
142
+ | --- | --- |
143
+ | Node.js | 18 or newer |
144
+ | Bun | 1.1 or newer |
145
+ | TypeScript (optional) | 5.6 or newer |
146
+ | Browser | Any with a global `fetch` |
147
+
148
+ ### Client options
149
+
150
+ | Option | What it does |
151
+ | --- | --- |
152
+ | `apiKey` | Bearer token sent on every request. |
153
+ | `orgSlug` | Selects your organization. On the default host it builds `https://<orgSlug>.api.k9o.io`. |
154
+ | `projectSlug` | Selects the project. Required by project-scoped calls. |
155
+ | `baseUrl` | Gateway host, no path. Defaults to `https://api.k9o.io`. |
156
+ | `fetch` | Custom `fetch` implementation. |
157
+ | `defaultHeaders` | Headers added to every request. |
158
+ | `retryConfig` | Retry policy. See [Retry settings](#retry-settings). |
159
+
160
+ - A `baseUrl` with a path, query or fragment throws `K9O_INVALID_BASE_URL`.
161
+ - Slugs use 2 to 63 lowercase letters, digits and hyphens. They start with a letter and do not end with a hyphen.
162
+
163
+ ### Retry settings
164
+
165
+ | Field | Meaning |
166
+ | --- | --- |
167
+ | `maxRetries` | How many times to retry. |
168
+ | `backoff` | `"exponential"`, `"linear"` or `"none"`. |
169
+ | `initialDelayMs` | First delay. Optional. |
170
+ | `maxDelayMs` | Delay cap. Optional. |
171
+
172
+ - Only GET, HEAD, OPTIONS and DELETE are retried.
173
+ - Retries happen on network failure and on HTTP 429, 502, 503 and 504.
174
+
175
+ ### Methods by namespace
176
+
177
+ | Namespace | Methods |
178
+ | --- | --- |
179
+ | `client.from(collection)` | See [Data methods](#data-methods). |
180
+ | `client.projects` | `list`, `create`, `get`, `update` |
181
+ | `client.migrations` | `apply`, `list`, `get`, `queue`, `listPending`, `applyPending`, `rejectPending`, `deletePending` |
182
+ | `client.functions` | `deploy`, `list`, `get`, `delete` |
183
+ | `client.audit` | `query`, `tail` (needs `projectSlug`) |
184
+ | `client.policies` | Policy bundle lifecycle |
185
+ | `client.storage` | Storage locations and buckets |
186
+ | `client.metadata` | Metadata queries across surfaces |
187
+ | `client.orgs` | `list`, `get`, `restore`, `current` |
188
+ | `client.org` | Members, groups, SMTP settings, audit log, identity providers |
189
+ | `client.me` | Your profile, sessions, API tokens, notifications |
190
+ | `client.studio` | `workflows` and `dashboards` |
191
+ | `client.compute.llms` | `list`, `read`, `invoke` |
192
+ | `client.ai` | `embed` |
193
+ | `client.realtime` | `subscribe`, `replay` |
194
+ | `client.gate` | End-user sign-in from `@k9o/gate` (needs `projectSlug`) |
195
+ | `client.kibo` | Vault and key operations from `@k9o/kibo` |
196
+ | `client.extensions` | `extension(slug)` from `@k9o/extensions` |
197
+
198
+ ### Data methods
199
+
200
+ | Method | What it does |
201
+ | --- | --- |
202
+ | `select<T>()` | Starts a query. Await it to get the rows. |
203
+ | `insert<T>(record)` | Creates one record. |
204
+ | `update<T>(patch)` | Updates one record by id. |
205
+ | `delete<T>()` | Deletes one record by id. |
206
+ | `eq`, `neq` | Equal, not equal. |
207
+ | `gt`, `gte`, `lt`, `lte` | Comparisons. |
208
+ | `in`, `notIn` | Value is in, or not in, a list. |
209
+ | `like`, `ilike` | Pattern match, case-sensitive or not. |
210
+ | `is` | Compare with `"null"`, `"true"` or `"false"`. |
211
+ | `filter(column, op, value)` | Generic form of the filters above. |
212
+ | `limit(n)` | Maximum rows to return. |
213
+ | `cursor(token)` | Continue from a cursor. |
214
+ | `count(mode)` | `"none"`, `"exact"` or `"estimated"`. |
215
+
216
+ Filters combine with AND.
217
+
218
+ ### Error fields
219
+
220
+ | Field | Meaning |
221
+ | --- | --- |
222
+ | `code` | Stable string such as `K9O_PROJECT_NOT_FOUND`. Switch on this. |
223
+ | `message` | Human-readable explanation. |
224
+ | `context` | Read-only per-code details. |
225
+ | `recommendation` | Suggested next step, or `null`. |
226
+ | `status` | HTTP status, or `null` if no request was sent. |
227
+ | `requestId` | Gateway trace id for support, or `null`. |
228
+
229
+ ### Error codes
230
+
231
+ The gateway can send other codes. The SDK passes them through unchanged.
232
+
233
+ | Code | When |
234
+ | --- | --- |
235
+ | `K9O_INVALID_BASE_URL` | `baseUrl` is not a plain http or https host. |
236
+ | `K9O_INVALID_FIELD_VALUE` | An argument or slug failed validation. |
237
+ | `K9O_INVALID_FILTER` | A realtime subscription filter was malformed. |
238
+ | `K9O_MISSING_PROJECT_CONTEXT` | A project-scoped call was made without `projectSlug`. |
239
+ | `K9O_UPSTREAM_UNAVAILABLE` | The gateway could not be reached. |
240
+ | `K9O_INTERNAL_ERROR` | No `fetch` is available, or the response was unexpected. |
241
+
242
+ ### Related packages
243
+
244
+ | Package | What it does |
245
+ | --- | --- |
246
+ | `@k9o/gate` | End-user sign-up, sign-in, sessions and JWT verification. |
247
+ | `@k9o/extensions` | Typed bindings for platform extensions. |
248
+ | `@k9o/kibo` | Vault and key operations. |
249
+
250
+ Platform apex: https://api.k9o.io. Documentation: https://kilimanjaro.dev.
251
+
252
+ ## License
253
+
254
+ Apache-2.0 © Formelo Inc. See `LICENSE` and `NOTICE`.
@@ -0,0 +1,93 @@
1
+ import {
2
+ KError
3
+ } from "./chunk-LJZ45UA2.js";
4
+
5
+ // src/url-grammar.ts
6
+ function validateBaseUrl(baseUrl) {
7
+ let parsed;
8
+ try {
9
+ parsed = new URL(baseUrl);
10
+ } catch {
11
+ throw new KError({
12
+ code: "K9O_INVALID_BASE_URL",
13
+ message: `baseUrl "${baseUrl}" is not a valid URL`,
14
+ context: { baseUrl },
15
+ recommendation: "Pass a scheme + host like `https://api.k9o.io` or `https://<orgSlug>.api.k9o.io`",
16
+ status: null
17
+ });
18
+ }
19
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
20
+ throw new KError({
21
+ code: "K9O_INVALID_BASE_URL",
22
+ message: `baseUrl "${baseUrl}" uses unsupported scheme "${parsed.protocol}"; expected http: or https:`,
23
+ context: { baseUrl, scheme: parsed.protocol },
24
+ recommendation: "Use http:// or https://. WebSocket subscriptions are wired internally over SSE on the same host.",
25
+ status: null
26
+ });
27
+ }
28
+ if (parsed.pathname !== "/" && parsed.pathname !== "") {
29
+ throw new KError({
30
+ code: "K9O_INVALID_BASE_URL",
31
+ message: `baseUrl "${baseUrl}" must not contain a path segment; got "${parsed.pathname}"`,
32
+ context: { baseUrl, path: parsed.pathname },
33
+ recommendation: "Strip the path segment \u2014 pass host only. URL paths are composed by the SDK.",
34
+ status: null
35
+ });
36
+ }
37
+ if (parsed.search.length > 0 || parsed.hash.length > 0) {
38
+ throw new KError({
39
+ code: "K9O_INVALID_BASE_URL",
40
+ message: `baseUrl "${baseUrl}" must not contain query or fragment`,
41
+ context: { baseUrl, query: parsed.search, fragment: parsed.hash },
42
+ recommendation: "Pass host only.",
43
+ status: null
44
+ });
45
+ }
46
+ const normalised = `${parsed.protocol}//${parsed.host}`;
47
+ return normalised;
48
+ }
49
+ var K9O_ORG_DERIVABLE_APEXES = /* @__PURE__ */ new Set(["api.k9o.io", "api-staging.k9o.io"]);
50
+ function resolveBaseUrl(baseUrl, orgSlug) {
51
+ const validated = validateBaseUrl(baseUrl ?? "https://api.k9o.io");
52
+ const parsed = new URL(validated);
53
+ if (K9O_ORG_DERIVABLE_APEXES.has(parsed.hostname) && orgSlug) {
54
+ validateSlug(orgSlug, "org");
55
+ return `${parsed.protocol}//${orgSlug}.${parsed.hostname}`;
56
+ }
57
+ return validated;
58
+ }
59
+ var SLUG_RE = /^[a-z][a-z0-9-]{1,62}$/;
60
+ function validateSlug(slug, kind) {
61
+ if (!SLUG_RE.test(slug) || slug.endsWith("-")) {
62
+ throw new KError({
63
+ code: "K9O_INVALID_FIELD_VALUE",
64
+ message: `${kind}Slug "${slug}" does not match required format ^[a-z][a-z0-9-]{1,62}$ (must not end with '-')`,
65
+ context: { slug, kind },
66
+ recommendation: `Pass a slug matching the format \u2014 lowercase letters / digits / hyphens; 2-63 chars; starts with a letter; does not end with hyphen.`,
67
+ status: null
68
+ });
69
+ }
70
+ }
71
+ function projectPath(projectSlug, subResource) {
72
+ validateSlug(projectSlug, "project");
73
+ const cleaned = subResource.startsWith("/") ? subResource.slice(1) : subResource;
74
+ return `/@${projectSlug}/${cleaned}`;
75
+ }
76
+ function orgPath(resource) {
77
+ const cleaned = resource.startsWith("/") ? resource.slice(1) : resource;
78
+ return `/${cleaned}`;
79
+ }
80
+ function platformPath(resource) {
81
+ const cleaned = resource.startsWith("/") ? resource.slice(1) : resource;
82
+ return `/${cleaned}`;
83
+ }
84
+
85
+ export {
86
+ validateBaseUrl,
87
+ resolveBaseUrl,
88
+ validateSlug,
89
+ projectPath,
90
+ orgPath,
91
+ platformPath
92
+ };
93
+ //# sourceMappingURL=chunk-2NDFTHUB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/url-grammar.ts"],"sourcesContent":["/**\n * URL grammar.\n *\n * Canonical URL shapes:\n * - Member-plane (project-scoped): `<orgSlug>.api.k9o.io/@<projectSlug>/<sub-resource>/...`\n * - Org-plane (org-scoped): `<orgSlug>.api.k9o.io/<resource>/...`\n * - Platform-plane (cross-org): `api.k9o.io/discovery/...` + `api.k9o.io/auth/...` etc.\n *\n * The `baseUrl` passed to `createClient` is the gateway host root —\n * scheme + host (+ optional port). Path-bearing baseUrls\n * are rejected with `K9O_INVALID_BASE_URL`.\n *\n * The SDK constructs URLs by composing `baseUrl + path-from-builder`.\n * Per-resource SDK methods use the builders below to assemble their\n * `path` argument before handing to the HTTP client.\n */\n\nimport { KError } from \"./kerror.ts\";\n\n/**\n * Validate a `baseUrl`. Returns the normalised form\n * (trailing-slash stripped) on success; throws `K9O_INVALID_BASE_URL`\n * on any violation.\n *\n * Accepted shapes:\n * - `https://api.k9o.io`\n * - `https://acme.api.k9o.io`\n * - `http://localhost:8080`\n * - `https://api.k9o.io:443`\n *\n * Rejected shapes:\n * - path segments (`https://api.k9o.io/v2`)\n * - missing scheme (`api.k9o.io`)\n * - non-http(s) scheme (`wss://api.k9o.io`)\n * - query / fragment (`https://api.k9o.io?x=1`)\n */\nexport function validateBaseUrl(baseUrl: string): string {\n let parsed: URL;\n try {\n parsed = new URL(baseUrl);\n } catch {\n throw new KError({\n code: \"K9O_INVALID_BASE_URL\",\n message: `baseUrl \"${baseUrl}\" is not a valid URL`,\n context: { baseUrl },\n recommendation: \"Pass a scheme + host like `https://api.k9o.io` or `https://<orgSlug>.api.k9o.io`\",\n status: null,\n });\n }\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n throw new KError({\n code: \"K9O_INVALID_BASE_URL\",\n message: `baseUrl \"${baseUrl}\" uses unsupported scheme \"${parsed.protocol}\"; expected http: or https:`,\n context: { baseUrl, scheme: parsed.protocol },\n recommendation: \"Use http:// or https://. WebSocket subscriptions are wired internally over SSE on the same host.\",\n status: null,\n });\n }\n if (parsed.pathname !== \"/\" && parsed.pathname !== \"\") {\n throw new KError({\n code: \"K9O_INVALID_BASE_URL\",\n message: `baseUrl \"${baseUrl}\" must not contain a path segment; got \"${parsed.pathname}\"`,\n context: { baseUrl, path: parsed.pathname },\n recommendation: \"Strip the path segment — pass host only. URL paths are composed by the SDK.\",\n status: null,\n });\n }\n if (parsed.search.length > 0 || parsed.hash.length > 0) {\n throw new KError({\n code: \"K9O_INVALID_BASE_URL\",\n message: `baseUrl \"${baseUrl}\" must not contain query or fragment`,\n context: { baseUrl, query: parsed.search, fragment: parsed.hash },\n recommendation: \"Pass host only.\",\n status: null,\n });\n }\n // Normalise — strip trailing slash so concatenation is predictable.\n const normalised = `${parsed.protocol}//${parsed.host}`;\n return normalised;\n}\n\n/**\n * The bare platform apex hosts org-subdomain derivation applies to. `api.k9o.io`\n * (production) and `api-staging.k9o.io` (staging) share the same\n * `<orgSlug>.<apex>` wire-routing scheme — confirmed live (conformance,\n * `k9o login` examples, staging demo configs all address orgs this way on\n * both). A THIRD apex here needs the same confirmation before joining this\n * set — never inferred from a hostname merely looking apex-shaped.\n */\nconst K9O_ORG_DERIVABLE_APEXES = new Set([\"api.k9o.io\", \"api-staging.k9o.io\"]);\n\n/**\n * Resolve the effective baseUrl. `baseUrl` is\n * OPTIONAL — it defaults to the platform apex `https://api.k9o.io`. When the\n * (validated) host is a bare apex in `K9O_ORG_DERIVABLE_APEXES` and `orgSlug`\n * is supplied, the SDK composes the canonical org-subdomain wire root\n * `https://<orgSlug>.<apex>`. An explicit `<orgSlug>` subdomain, a\n * self-hosted / Sovereign host, or a dev host (anything not in that set)\n * passes through unchanged — `orgSlug` is intentionally NOT validated or\n * composed onto a non-apex host (fixed 2026-08-30: this used to silently\n * ignore `orgSlug` for `api-staging.k9o.io` too, not just genuine\n * self-hosted/custom hosts, since only the literal production apex string\n * was checked).\n */\nexport function resolveBaseUrl(baseUrl: string | undefined, orgSlug?: string): string {\n const validated = validateBaseUrl(baseUrl ?? \"https://api.k9o.io\");\n const parsed = new URL(validated);\n if (K9O_ORG_DERIVABLE_APEXES.has(parsed.hostname) && orgSlug) {\n validateSlug(orgSlug, \"org\");\n return `${parsed.protocol}//${orgSlug}.${parsed.hostname}`;\n }\n return validated;\n}\n\n/**\n * Slug format validator:\n * `[a-z][a-z0-9-]{1,62}` and must not end with `-`.\n */\nconst SLUG_RE = /^[a-z][a-z0-9-]{1,62}$/;\n\nexport function validateSlug(slug: string, kind: \"org\" | \"project\"): void {\n if (!SLUG_RE.test(slug) || slug.endsWith(\"-\")) {\n throw new KError({\n code: \"K9O_INVALID_FIELD_VALUE\",\n message: `${kind}Slug \"${slug}\" does not match required format ^[a-z][a-z0-9-]{1,62}$ (must not end with '-')`,\n context: { slug, kind },\n recommendation: `Pass a slug matching the format — lowercase letters / digits / hyphens; 2-63 chars; starts with a letter; does not end with hyphen.`,\n status: null,\n });\n }\n}\n\n/**\n * Build a project-scoped (member-plane) URL path per the URL grammar\n * E.g. `projectPath('member-portal', 'collections/posts/documents')`\n * → `/@member-portal/collections/posts/documents`.\n *\n * The caller is responsible for normalising sub-resource components\n * (URL-encoding goes through the caller's path construction; this\n * helper handles only the prefix + slug shape).\n */\nexport function projectPath(projectSlug: string, subResource: string): string {\n validateSlug(projectSlug, \"project\");\n const cleaned = subResource.startsWith(\"/\") ? subResource.slice(1) : subResource;\n return `/@${projectSlug}/${cleaned}`;\n}\n\n/**\n * Build an org-plane path. E.g. `orgPath('org')` → `/org`,\n * `orgPath('projects')` → `/projects`.\n */\nexport function orgPath(resource: string): string {\n const cleaned = resource.startsWith(\"/\") ? resource.slice(1) : resource;\n return `/${cleaned}`;\n}\n\n/**\n * Build a platform-plane path (cross-org). E.g.\n * `platformPath('discovery/projects')` → `/discovery/projects`,\n * `platformPath('auth/sign-in')` → `/auth/sign-in`.\n *\n * Composes with the platform baseUrl (`https://api.k9o.io`) — not the\n * org-subdomain baseUrl.\n */\nexport function platformPath(resource: string): string {\n const cleaned = resource.startsWith(\"/\") ? resource.slice(1) : resource;\n return `/${cleaned}`;\n}\n"],"mappings":";;;;;AAoCO,SAAS,gBAAgB,SAAyB;AACvD,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,OAAO;AAAA,EAC1B,QAAQ;AACN,UAAM,IAAI,OAAO;AAAA,MACf,MAAM;AAAA,MACN,SAAS,YAAY,OAAO;AAAA,MAC5B,SAAS,EAAE,QAAQ;AAAA,MACnB,gBAAgB;AAAA,MAChB,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACA,MAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UAAU;AAC/D,UAAM,IAAI,OAAO;AAAA,MACf,MAAM;AAAA,MACN,SAAS,YAAY,OAAO,8BAA8B,OAAO,QAAQ;AAAA,MACzE,SAAS,EAAE,SAAS,QAAQ,OAAO,SAAS;AAAA,MAC5C,gBAAgB;AAAA,MAChB,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACA,MAAI,OAAO,aAAa,OAAO,OAAO,aAAa,IAAI;AACrD,UAAM,IAAI,OAAO;AAAA,MACf,MAAM;AAAA,MACN,SAAS,YAAY,OAAO,2CAA2C,OAAO,QAAQ;AAAA,MACtF,SAAS,EAAE,SAAS,MAAM,OAAO,SAAS;AAAA,MAC1C,gBAAgB;AAAA,MAChB,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACA,MAAI,OAAO,OAAO,SAAS,KAAK,OAAO,KAAK,SAAS,GAAG;AACtD,UAAM,IAAI,OAAO;AAAA,MACf,MAAM;AAAA,MACN,SAAS,YAAY,OAAO;AAAA,MAC5B,SAAS,EAAE,SAAS,OAAO,OAAO,QAAQ,UAAU,OAAO,KAAK;AAAA,MAChE,gBAAgB;AAAA,MAChB,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAEA,QAAM,aAAa,GAAG,OAAO,QAAQ,KAAK,OAAO,IAAI;AACrD,SAAO;AACT;AAUA,IAAM,2BAA2B,oBAAI,IAAI,CAAC,cAAc,oBAAoB,CAAC;AAetE,SAAS,eAAe,SAA6B,SAA0B;AACpF,QAAM,YAAY,gBAAgB,WAAW,oBAAoB;AACjE,QAAM,SAAS,IAAI,IAAI,SAAS;AAChC,MAAI,yBAAyB,IAAI,OAAO,QAAQ,KAAK,SAAS;AAC5D,iBAAa,SAAS,KAAK;AAC3B,WAAO,GAAG,OAAO,QAAQ,KAAK,OAAO,IAAI,OAAO,QAAQ;AAAA,EAC1D;AACA,SAAO;AACT;AAMA,IAAM,UAAU;AAET,SAAS,aAAa,MAAc,MAA+B;AACxE,MAAI,CAAC,QAAQ,KAAK,IAAI,KAAK,KAAK,SAAS,GAAG,GAAG;AAC7C,UAAM,IAAI,OAAO;AAAA,MACf,MAAM;AAAA,MACN,SAAS,GAAG,IAAI,SAAS,IAAI;AAAA,MAC7B,SAAS,EAAE,MAAM,KAAK;AAAA,MACtB,gBAAgB;AAAA,MAChB,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;AAWO,SAAS,YAAY,aAAqB,aAA6B;AAC5E,eAAa,aAAa,SAAS;AACnC,QAAM,UAAU,YAAY,WAAW,GAAG,IAAI,YAAY,MAAM,CAAC,IAAI;AACrE,SAAO,KAAK,WAAW,IAAI,OAAO;AACpC;AAMO,SAAS,QAAQ,UAA0B;AAChD,QAAM,UAAU,SAAS,WAAW,GAAG,IAAI,SAAS,MAAM,CAAC,IAAI;AAC/D,SAAO,IAAI,OAAO;AACpB;AAUO,SAAS,aAAa,UAA0B;AACrD,QAAM,UAAU,SAAS,WAAW,GAAG,IAAI,SAAS,MAAM,CAAC,IAAI;AAC/D,SAAO,IAAI,OAAO;AACpB;","names":[]}
@@ -0,0 +1,33 @@
1
+ // src/kerror.ts
2
+ var KError = class extends Error {
3
+ code;
4
+ context;
5
+ recommendation;
6
+ status;
7
+ requestId;
8
+ constructor(init) {
9
+ super(init.message);
10
+ this.name = "KError";
11
+ this.code = init.code;
12
+ this.context = Object.freeze({ ...init.context ?? {} });
13
+ this.recommendation = init.recommendation ?? null;
14
+ this.status = init.status ?? null;
15
+ this.requestId = init.requestId ?? null;
16
+ }
17
+ };
18
+ function kerrorFromWire(wire, status) {
19
+ return new KError({
20
+ code: wire.code,
21
+ message: wire.message,
22
+ context: wire.context ?? {},
23
+ recommendation: wire.recommendation ?? null,
24
+ status,
25
+ requestId: wire.requestId ?? null
26
+ });
27
+ }
28
+
29
+ export {
30
+ KError,
31
+ kerrorFromWire
32
+ };
33
+ //# sourceMappingURL=chunk-LJZ45UA2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/kerror.ts"],"sourcesContent":["/**\n * `KError` — the closed-taxonomy error class returned by every `@k9o/core`\n * surface on non-2xx gateway responses or SDK-side validation failures.\n *\n * TypeScript / JavaScript throw on error; the per-language SDKs deliver this same payload\n * via their idiomatic mechanism (Go tuple-return; Rust Result; Python\n * raise; etc.) without changing the field shape.\n *\n * Fields:\n * - `code` — closed-taxonomy string (e.g. `K9O_TIER_CAP_HIT`,\n * `K9O_PROJECT_NOT_FOUND`); unknown codes pass through\n * with `code` preserved + `INTERNAL_ERROR` family\n * classification recorded in `context.originalCode`.\n * - `message` — human-readable explanation.\n * - `context` — structured per-code payload (immutable; frozen).\n * - `recommendation` — actionable next step (may be null when the\n * gateway didn't return one).\n * - `status` — HTTP status the gateway returned (or null for\n * SDK-side construct-time errors like\n * `K9O_INVALID_BASE_URL`).\n * - `requestId` — gateway-emitted trace ID for downstream correlation.\n *\n * Standalone `@k9o/gate` ships its own `GateError` for the Auth0-parity\n * deployment shape; when `@k9o/gate` is composed inside `@k9o/core`,\n * `GateError` semantics align with `KError extends KError` (alignment still open).\n * Until then `KError` is the canonical error type returned by `@k9o/core` surfaces; `GateError` thrown by\n * `@k9o/gate`-delegated surfaces remain `KError`-shape-compatible\n * (both expose the same `code` / `message` / `context` / `recommendation`\n * fields) so caller code that narrows on `code` works against either.\n */\n\n/**\n * Wire-shape sentinel matching the gateway's `KError` JSON payload. The HTTP client recognises this on non-2xx responses\n * and rehydrates it into a `KError` instance.\n */\nexport type KErrorWire = {\n code: string;\n message: string;\n context?: Record<string, unknown>;\n recommendation?: string | null;\n requestId?: string;\n};\n\n/**\n * The customer-facing error type. Every `@k9o/core` surface throws this\n * on non-2xx upstream responses, transport failures, or SDK-side\n * validation failures.\n */\nexport class KError extends Error {\n readonly code: string;\n readonly context: Readonly<Record<string, unknown>>;\n readonly recommendation: string | null;\n readonly status: number | null;\n readonly requestId: string | null;\n\n constructor(init: {\n code: string;\n message: string;\n context?: Record<string, unknown>;\n recommendation?: string | null;\n status?: number | null;\n requestId?: string | null;\n }) {\n super(init.message);\n this.name = \"KError\";\n this.code = init.code;\n this.context = Object.freeze({ ...(init.context ?? {}) });\n this.recommendation = init.recommendation ?? null;\n this.status = init.status ?? null;\n this.requestId = init.requestId ?? null;\n }\n}\n\n/**\n * Rehydrate a wire `KError` payload into a typed `KError` instance.\n * Unlike `@k9o/gate.gateErrorFromWire`, `@k9o/core` does not maintain\n * a hand-curated allow-list of known codes — the gateway's KError\n * code-space is open-ended and curated centrally; the SDK\n * preserves whatever code the gateway sends. Code-narrowing in caller\n * code uses string-literal comparison against the well-known codes\n * (e.g. `if (e.code === 'K9O_TIER_CAP_HIT')`).\n */\nexport function kerrorFromWire(wire: KErrorWire, status: number): KError {\n return new KError({\n code: wire.code,\n message: wire.message,\n context: wire.context ?? {},\n recommendation: wire.recommendation ?? null,\n status,\n requestId: wire.requestId ?? null,\n });\n}\n"],"mappings":";AAgDO,IAAM,SAAN,cAAqB,MAAM;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAOT;AACD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,UAAU,OAAO,OAAO,EAAE,GAAI,KAAK,WAAW,CAAC,EAAG,CAAC;AACxD,SAAK,iBAAiB,KAAK,kBAAkB;AAC7C,SAAK,SAAS,KAAK,UAAU;AAC7B,SAAK,YAAY,KAAK,aAAa;AAAA,EACrC;AACF;AAWO,SAAS,eAAe,MAAkB,QAAwB;AACvE,SAAO,IAAI,OAAO;AAAA,IAChB,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,IACd,SAAS,KAAK,WAAW,CAAC;AAAA,IAC1B,gBAAgB,KAAK,kBAAkB;AAAA,IACvC;AAAA,IACA,WAAW,KAAK,aAAa;AAAA,EAC/B,CAAC;AACH;","names":[]}