@terrascale/sdk 0.0.0-stage → 0.0.2

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 (89) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +202 -0
  3. package/README.md +202 -2
  4. package/package.json +152 -4
  5. package/sdk-v1-route-manifest.json +2330 -0
  6. package/src/admin.js +9 -0
  7. package/src/better-auth.js +14 -0
  8. package/src/config.js +121 -0
  9. package/src/database-codec.js +845 -0
  10. package/src/database-types.js +237 -0
  11. package/src/database-view.js +423 -0
  12. package/src/database.js +2 -0
  13. package/src/http.js +898 -0
  14. package/src/index.js +62 -0
  15. package/src/local/authentication.js +47 -0
  16. package/src/local/better-auth.js +517 -0
  17. package/src/local/cli.js +51 -0
  18. package/src/local/context.js +23 -0
  19. package/src/local/environment.js +109 -0
  20. package/src/local/index.js +206 -0
  21. package/src/local/legacy-client.js +411 -0
  22. package/src/local/router.js +999 -0
  23. package/src/local/server.js +664 -0
  24. package/src/local/store.js +530 -0
  25. package/src/local/test-environment.js +74 -0
  26. package/src/management-contracts.js +72 -0
  27. package/src/management.js +12 -0
  28. package/src/native-origin.js +75 -0
  29. package/src/postgres.js +496 -0
  30. package/src/react/core.js +743 -0
  31. package/src/react/index.js +99 -0
  32. package/src/result.js +251 -0
  33. package/src/schema.js +366 -0
  34. package/src/sql.js +996 -0
  35. package/src/svelte/index.js +129 -0
  36. package/src/tanstack/index.js +512 -0
  37. package/src/ts-auth-discovery.js +207 -0
  38. package/src/ts-auth.js +3498 -0
  39. package/src/v1/decode.js +118 -0
  40. package/src/v1/errors.js +185 -0
  41. package/src/v1/filter.js +230 -0
  42. package/src/v1/ids.js +119 -0
  43. package/src/v1/json.js +335 -0
  44. package/src/v1/routes.js +57 -0
  45. package/src/v1/shapes.js +145 -0
  46. package/src/v1/terrabase-v1.js +722 -0
  47. package/src/v1/transport.js +324 -0
  48. package/types/admin.d.ts +6 -0
  49. package/types/better-auth.d.ts +8 -0
  50. package/types/config.d.ts +58 -0
  51. package/types/database-codec.d.ts +111 -0
  52. package/types/database-types.d.ts +213 -0
  53. package/types/database-view.d.ts +184 -0
  54. package/types/database.d.ts +2 -0
  55. package/types/http.d.ts +47 -0
  56. package/types/index.d.ts +43 -0
  57. package/types/local/authentication.d.ts +11 -0
  58. package/types/local/better-auth.d.ts +33 -0
  59. package/types/local/cli.d.ts +2 -0
  60. package/types/local/context.d.ts +14 -0
  61. package/types/local/environment.d.ts +23 -0
  62. package/types/local/index.d.ts +96 -0
  63. package/types/local/legacy-client.d.ts +94 -0
  64. package/types/local/router.d.ts +66 -0
  65. package/types/local/server.d.ts +54 -0
  66. package/types/local/store.d.ts +106 -0
  67. package/types/local/test-environment.d.ts +25 -0
  68. package/types/management-contracts.d.ts +44 -0
  69. package/types/management.d.ts +6 -0
  70. package/types/native-origin.d.ts +23 -0
  71. package/types/postgres.d.ts +124 -0
  72. package/types/react/core.d.ts +366 -0
  73. package/types/react/index.d.ts +54 -0
  74. package/types/result.d.ts +161 -0
  75. package/types/schema.d.ts +145 -0
  76. package/types/sql.d.ts +288 -0
  77. package/types/svelte/index.d.ts +81 -0
  78. package/types/tanstack/index.d.ts +166 -0
  79. package/types/ts-auth-discovery.d.ts +19 -0
  80. package/types/ts-auth.d.ts +1826 -0
  81. package/types/v1/decode.d.ts +119 -0
  82. package/types/v1/errors.d.ts +107 -0
  83. package/types/v1/filter.d.ts +148 -0
  84. package/types/v1/ids.d.ts +44 -0
  85. package/types/v1/json.d.ts +92 -0
  86. package/types/v1/routes.d.ts +26 -0
  87. package/types/v1/shapes.d.ts +78 -0
  88. package/types/v1/terrabase-v1.d.ts +374 -0
  89. package/types/v1/transport.d.ts +117 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,62 @@
1
+ # Changelog
2
+
3
+ ## 0.0.2 — TS-650
4
+
5
+ TerraBase version tokens are opaque: `tbv1-<32 hex>` and the coming `tbv2-…`
6
+ format are both accepted (any 1-256 visible ASCII characters without quotes, so
7
+ they stay safe in `If-Match`). Responses with new members no longer throw:
8
+ `durability` passes through any label, and documents pass through any `state`,
9
+ including a causal read's `"conflict"` with its `siblings` (the LWW winner stays
10
+ in `document`). Conditional writes and error handling are unchanged.
11
+
12
+ ## 0.0.1 — TS-498
13
+
14
+ The package moves from the unscoped `terrascale` npm name, which the owner has
15
+ deleted, to `@terrascale/sdk` (TS-537). Install `@terrascale/sdk` and import
16
+ from `@terrascale/sdk` and its subpaths, for example `@terrascale/sdk/admin`.
17
+ Per the owner's 2026-10-05 decision (TS-528), 0.0.1 is the first `latest`
18
+ release and `@terrascale/sdk` stays on 0.0.x until the owner lifts this policy.
19
+
20
+ ### Breaking changes
21
+
22
+ 1. The root entrypoint exposes only the C# TerraBase v1 client API.
23
+ `createTerraBaseClient` now aliases `createTerraBaseV1Client`; the retired
24
+ tenant/shard client, Rust discovery, schema/SQL and reactive-view
25
+ exports are removed from the root. Named legacy entrypoints remain separate.
26
+ 2. Client configuration requires `project`, a Bearer `tb_` token and exactly one
27
+ of `baseUrl` or `endpointResolver`. Tenant, shard, `apiKey`, `endpoint` and
28
+ `tbk1` routing assumptions no longer apply. Database operations use
29
+ `/v1/projects/{project}/databases/{db}` paths.
30
+ 3. Mutations follow the C# producer: `Idempotency-Key` is unsupported and writes
31
+ cannot be automatically replayed. Queries do not support `lower` or `explain`;
32
+ server numeric comparison and bounded-count semantics replace Rust assumptions.
33
+ 4. Shapes use `GET …/collections/{collection}/shape` with `shapes:read`.
34
+ The retired shape gatekeeper, SSE, edge tokens and projection are unavailable.
35
+ 5. `@terrascale/sdk/local`, `terrascale-local` and `@terrascale/sdk/postgres` are deprecated
36
+ legacy surfaces. SDK SQLite is no longer the required Dashboard backend;
37
+ real C# release binaries replace frozen Rust/fake-server qualification.
38
+
39
+ ### Migration
40
+
41
+ Configure a provisioned project and `tb_` API key with `documents:read` and/or
42
+ `documents:write`, then obtain `client.database(name).collection(name)` handles.
43
+ Use `get`, `put`, `create`, `patch`, `delete` and bounded `query`/`pages`/`items`
44
+ operations; conditional writes carry `ifMatch` or `ifNoneMatchAny`.
45
+ Do not replay uncertain mutations without a producer deduplication contract.
46
+
47
+ `staticBaseUrlResolver(baseUrl)` supplies an explicit override; a custom resolver
48
+ receives `{ project, database }` and is resolved once per database session.
49
+ Atlas discovery is deferred to TS-507; no regional hostname is hardcoded.
50
+ Ouroboros qualification uses the real immutable C# TerraBase release binary,
51
+ pinned by version and SHA-256, rather than an SDK-local substitute.
52
+ `provision:terrabase` acquires the verified binary; `test:integration` runs it
53
+ with isolated TLS, real tenant provisioning and runtime OpenAPI parity.
54
+ The pinned official producer release is a draft after failed fast checks
55
+ (terrabase #110). Its verified release asset can run SDK integration without
56
+ publication; those results do not establish that producer source checks passed.
57
+
58
+ The package and lockfile must use version 0.0.1. `lint` reuses the
59
+ existing strict TypeScript/JSDoc check; dependencies are unchanged.
60
+
61
+ Fresh shape bootstrap requires a server runtime; browser manual redirects hide
62
+ the bootstrap handle and offset. Browser continuation needs those server-issued positions.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,203 @@
1
- # Temporary Holding Version
1
+ # @terrascale/sdk
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 JavaScript/JSDoc SDK for the project-scoped C#/.NET TerraBase server
4
+ (`terrabase`, `origin/main`). Version 0.0.1 replaces the retired Rust client.
5
+ The package targets Node.js 22 and 24 and current Chrome, Firefox, Safari, and Edge.
6
+ Plain ES modules ship as written; `nice -n 19 npm run build` generates the
7
+ TypeScript declarations in `types/`.
8
+
9
+ ```sh
10
+ npm install @terrascale/sdk
11
+ ```
12
+
13
+ ```js
14
+ import { createTerraBaseV1Client, documentIdFor, v1Filter } from "@terrascale/sdk";
15
+
16
+ const client = createTerraBaseV1Client({
17
+ project: process.env.TERRABASE_PROJECT,
18
+ token: process.env.TERRABASE_API_KEY,
19
+ baseUrl: process.env.TERRABASE_BASE_URL,
20
+ });
21
+ const db = client.database("app");
22
+ const todos = db.collection("todos");
23
+
24
+ const id = await documentIdFor("todos", "first-task");
25
+ await todos.put(id, { title: "Use TerraBase", done: false }, { ifNoneMatchAny: true });
26
+ const doc = await todos.get(id);
27
+ await todos.patch(id, { merge: { done: true } }, { ifMatch: doc.version });
28
+
29
+ for await (const page of todos.pages({ filter: v1Filter.eq("/done", true), limit: 50 })) {
30
+ console.log(page.items);
31
+ }
32
+ ```
33
+
34
+ Provision the project, database and collection before using their handles.
35
+ API keys begin with `tb_` and travel as `Authorization: Bearer <key>`.
36
+ Reads and queries require `documents:read`; writes and transactions require
37
+ `documents:write`. Transaction assertions additionally require `documents:read`.
38
+ Keep keys private and out of logs and browser bundles. `createTerraBaseClient`
39
+ is an alias of `createTerraBaseV1Client`; it no longer accepts tenant/shard options.
40
+
41
+ ## Atlas and endpoint selection
42
+
43
+ Supply exactly one of `baseUrl` or `endpointResolver`. A resolver receives
44
+ `{ project, database }` and returns the service URL, synchronously or asynchronously.
45
+ The URL is resolved once per database session and reused by its operations.
46
+ Shared resolution expires after 30 seconds and supplies a cancellation signal
47
+ to the resolver; a later operation can retry an expired or failed resolution.
48
+ Cancelling one operation leaves other callers' shared resolution running.
49
+ HTTPS is required except for loopback HTTP in local development; no regional
50
+ host is hardcoded and no implicit production endpoint is selected.
51
+
52
+ ```js
53
+ import { createTerraBaseV1Client, staticBaseUrlResolver } from "@terrascale/sdk";
54
+
55
+ const client = createTerraBaseV1Client({
56
+ project: process.env.TERRABASE_PROJECT,
57
+ token: process.env.TERRABASE_API_KEY,
58
+ endpointResolver: staticBaseUrlResolver(process.env.TERRABASE_BASE_URL),
59
+ });
60
+ const db = client.database("app");
61
+ ```
62
+
63
+ Atlas (`ts-atlas`, a TypeScript Cloudflare Worker) discovers the closest eligible
64
+ region and the location of a project/database. The resolver seam allows that
65
+ choice to stay pinned for the session. Atlas discovery integration is deferred
66
+ to TS-507; this release requires an explicit URL or caller-supplied resolver.
67
+
68
+ ## Documents, queries, transactions and shapes
69
+
70
+ The C# producer owns these routes:
71
+
72
+ | Operation | Method and path |
73
+ | --- | --- |
74
+ | Documents | `GET/PUT/PATCH/DELETE /v1/projects/{project}/databases/{db}/collections/{c}/documents/{id}`; `POST …/documents` |
75
+ | Query | `POST /v1/projects/{project}/databases/{db}/collections/{c}/query` |
76
+ | Transaction | `POST /v1/projects/{project}/databases/{db}/transactions` |
77
+ | Shape | `GET /v1/projects/{project}/databases/{db}/collections/{c}/shape` |
78
+
79
+ Collection methods are `get`, `put`, `create`, `patch`, `delete`, `query`,
80
+ `pages` and `items`. New document IDs are canonical UUIDs; `documentIdFor`
81
+ generates a stable UUIDv5 from a natural key. Documents return
82
+ `{ id, version, state: "value", document }`; a causal read can answer
83
+ `state: "conflict"` with `siblings`, and unknown states pass through. Versions
84
+ (`tbv1-…`, `tbv2-…`) are opaque tokens. Writes return the version and a
85
+ decimal-string commit `offset`; preserve those opaque positions and use
86
+ `ifMatch` or `ifNoneMatchAny` for conditional writes.
87
+
88
+ Queries support typed filters, sorting, projection and bounded cursor pages.
89
+ `query` returns one page; `pages` and `items` follow `nextCursor`.
90
+ `count.exact: false` means the count is a lower bound. The current C# producer
91
+ does not support `lower` paths or `explain`; query number comparisons use its
92
+ 64-bit integer/double arithmetic, even when the SDK preserves exact JSON numbers.
93
+ `ExactDecimal` and bigint serialization require Node.js 22+ or a current browser.
94
+
95
+ `db.transaction()` builds one bounded atomic group across collections in that
96
+ database. It supports document operations, `assert`, `assertAbsent` and
97
+ `assertCount`; assertions examine the state before the group's writes.
98
+ The C# producer rejects `Idempotency-Key`. Do not enable automatic idempotency
99
+ or replay mutations after an uncertain result; this release does not promise
100
+ mutation deduplication. Validation, authentication, authorization and
101
+ precondition failures are not automatically retried.
102
+
103
+ Shapes require `shapes:read` and use the collection's GET route with a `where`
104
+ filter, handle, offset and live cursor. Snapshot bootstrap and checkpoint resume
105
+ provide correctness; `must_refetch` requires discarding local state and starting
106
+ a fresh snapshot. The C# producer has no shape gatekeeper, SSE route, edge shape
107
+ token or projection support. Origin responses require private cache revalidation. Fresh shape bootstrap is
108
+ server-only in this release: browsers hide the initial 307 redirect metadata.
109
+ Browser callers need a handle and snapshot offset obtained on their server.
110
+
111
+ The same public SDK supplies this metadata on the server. Pass the position to
112
+ the browser and repeat that immutable snapshot page with the identical filter
113
+ and collection:
114
+
115
+ ```js
116
+ // Server: use the public client with the caller's shapes:read key.
117
+ const snapshot = await serverCollection.shape({ where });
118
+ const position = { handle: snapshot.handle, offset: snapshot.offset };
119
+ // Browser: resume using position supplied by your application server.
120
+ const page = await browserCollection.shape({ where, ...position });
121
+ ```
122
+
123
+ Failures throw `TerraBaseV1Error` with the HTTP status and producer error code;
124
+ transaction failures may also identify the failing `op`. Request cancellation
125
+ uses `AbortSignal`.
126
+
127
+ ## Ouroboros and qualification
128
+
129
+ Ouroboros means TerraScale services store their data in the same production
130
+ TerraBase that customers use. SDK boundary tests must run the real C# TerraBase
131
+ release binary, pinned by immutable version and SHA-256, with an isolated
132
+ allocation. A fixture, mocked transport, SQLite SDK runtime, frozen Rust
133
+ contract archive or typed build cannot establish producer compatibility.
134
+
135
+ The v1 route manifest and producer contract evidence must agree with the C#
136
+ release under test. Keep live tests environment-gated; report missing local
137
+ configuration as skipped, never as successful integration evidence. Required
138
+ release qualification must supply the verified binary and real producer inputs.
139
+ Never commit keys, cookies, environment files or real tenant data.
140
+
141
+ The immutable release pin is
142
+ [`scripts/ci/terrabase-release.json`](scripts/ci/terrabase-release.json): C#
143
+ TerraBase 0.1.0, release `ci-0248ad3ac6fb82ac900e38005840a619e5d0beac-run-13267`,
144
+ with binary SHA-256
145
+ `8abcedaa6b8487f08ecafe4485862f1f9309154e58ac1a74eda2278b78500968`.
146
+ This official release is currently a draft: the producer's fast checks failed
147
+ and publication was skipped (terrabase #110). The SDK integration harness may
148
+ consume its official asset read-only when the version, source revision, size and
149
+ SHA-256 are verified; publication is not required. Draft status does not establish
150
+ that the producer's source qualification passed.
151
+ The acquisition script verifies the official release, revision, asset size and
152
+ digest. Private downloads require `FORGEJO_TOKEN`. Missing or mismatched official
153
+ assets block qualification rather than selecting older bytes.
154
+
155
+ ```sh
156
+ nice -n 19 npm run provision:terrabase
157
+ export TERRABASE_BINARY=/absolute/path/printed/by/the/provisioner
158
+ nice -n 19 npm run test:integration
159
+ ```
160
+
161
+ The integration runner rechecks the binary digest, starts an isolated TLS server,
162
+ verifies its version and runtime OpenAPI digest, and provisions a disposable
163
+ organization, project, database, collections and scoped keys. It supplies the
164
+ `TB_V1_*` environment and trusted local certificate to the real-server tests and
165
+ cleans up the process and allocation afterwards. No TLS validation is disabled.
166
+ Direct live test configuration uses `TB_V1_URL`, `TB_V1_PROJECT`,
167
+ `TB_V1_DATA_KEY` and optionally `TB_V1_DATABASE` (default `app`);
168
+ `TB_V1_REQUIRED=1` makes absent integration inputs fail rather than skip.
169
+
170
+ Local checks run at low CPU priority:
171
+
172
+ ```sh
173
+ nice -n 19 npm ci
174
+ nice -n 19 npm run typecheck
175
+ nice -n 19 npm run lint
176
+ nice -n 19 npm run build
177
+ nice -n 19 npm test
178
+ ```
179
+
180
+ `lint` reuses the strict TypeScript/JSDoc check, including unused-code checks,
181
+ without adding a linter dependency. CI runs these commands at normal priority.
182
+ See [CHANGELOG.md](CHANGELOG.md) for the 0.0.1 migration and breaking changes.
183
+
184
+ ## Separate and deprecated entrypoints
185
+
186
+ `@terrascale/sdk/ts-auth` retains its separate hosted identity management and OIDC
187
+ client, with its own origin, instance and credentials. Management,
188
+ administration and production Better Auth capabilities remain subject to their
189
+ explicit admission errors; they are not a shortcut into the database transport.
190
+
191
+ `@terrascale/sdk/local` (including `terrascale-local`) and `@terrascale/sdk/postgres` are
192
+ **deprecated legacy entrypoints**. SQLite stays opt-in for development only and
193
+ refuses CI, production, staging, qualification and deployment environments.
194
+ It is no longer the required Dashboard backend and does not qualify the C# API.
195
+ The PostgreSQL listener and retired tenant/shard client are outside the default
196
+ v1 API. Existing framework, schema and SQL entrypoints are separate legacy
197
+ surfaces; the root entrypoint exposes the C# v1 client API.
198
+
199
+ Hosted OAuth resource requests use one exact registered HTTPS `resource`. `oidc.authorizationUrl`, `oidc.deviceAuthorization`, and the code, device, refresh, and client-credentials token grants retain its bytes, including path and query. Omission on a browser code or refresh flow preserves the stored no-resource binding; it never repairs a rejected audience or falls back to browser login. Refresh requests can ask for narrower scopes. Client credentials require explicit resource and scope values. Token and originating-client introspection methods use `client_secret_post`; public-client and originating-client Basic token authentication are not currently exposed by this SDK.
200
+
201
+ `oauthClients` and `oauthResources` provide the producer's snake_case policy records and named management operations. Resource PATCH requires `expected_auth_epoch`; client PATCH accepts it. JSON epochs outside JavaScript's exact integer range are rejected. Client PATCH returns a bare client view unless `rotate_secret` is true, when it returns the client and its one-time secret. Resource create/PATCH always return the resource and nullable one-time introspection secret.
202
+
203
+ Use `oidc.introspectResource` with independently configured `issuer`, exact `audience`, `introspection_client_id`, and `introspection_secret`. It uses resource Basic authentication only, with each credential component form encoded before Base64. An active result requires the exact configured issuer/audience, `Bearer`, integer timestamps valid at the local clock with no default skew, and the required user/service session shape. Inactive results contain only `active: false`. Resource results expose no internal epochs, refresh family, or token-use fields. The provider checks current durable token/session/resource state; an active principal or scope does not grant project ownership or management authority. Product authorization remains at the caller's existing authorization boundary. Behind the Atlas proxy `apiBaseUrl` `https://auth.terrascale.tech`, ts-auth's issuer is regional, `https://<region>.auth.terrascale.tech/<slug>` (for example `https://gru.auth.terrascale.tech/<slug>`); configure that issuer, not the proxy host. Resource introspection then calls the issuer's regional host directly, because Atlas could rank another region, which is another issuer; `useReverseProxy` keeps it on the proxy.
package/package.json CHANGED
@@ -1,6 +1,154 @@
1
1
  {
2
2
  "name": "@terrascale/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.2",
4
+ "description": "JavaScript SDK, typed with JSDoc, for project-scoped C# TerraBase v1 and hosted TerraScale identity.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "private": false,
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "registry": "https://registry.npmjs.org/"
11
+ },
12
+ "sideEffects": false,
13
+ "main": "./src/index.js",
14
+ "types": "./types/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./types/index.d.ts",
18
+ "import": "./src/index.js"
19
+ },
20
+ "./admin": {
21
+ "types": "./types/admin.d.ts",
22
+ "import": "./src/admin.js"
23
+ },
24
+ "./schema": {
25
+ "types": "./types/schema.d.ts",
26
+ "import": "./src/schema.js"
27
+ },
28
+ "./sql": {
29
+ "types": "./types/sql.d.ts",
30
+ "import": "./src/sql.js"
31
+ },
32
+ "./management": {
33
+ "types": "./types/management.d.ts",
34
+ "import": "./src/management.js"
35
+ },
36
+ "./ts-auth": {
37
+ "types": "./types/ts-auth.d.ts",
38
+ "import": "./src/ts-auth.js"
39
+ },
40
+ "./react": {
41
+ "types": "./types/react/index.d.ts",
42
+ "import": "./src/react/index.js"
43
+ },
44
+ "./svelte": {
45
+ "types": "./types/svelte/index.d.ts",
46
+ "import": "./src/svelte/index.js"
47
+ },
48
+ "./tanstack": {
49
+ "types": "./types/tanstack/index.d.ts",
50
+ "import": "./src/tanstack/index.js"
51
+ },
52
+ "./better-auth": {
53
+ "types": "./types/better-auth.d.ts",
54
+ "workerd": "./src/better-auth.js",
55
+ "browser": null,
56
+ "node": "./src/better-auth.js"
57
+ },
58
+ "./local": {
59
+ "types": "./types/local/index.d.ts",
60
+ "workerd": null,
61
+ "browser": null,
62
+ "node": "./src/local/index.js"
63
+ },
64
+ "./postgres": {
65
+ "types": "./types/postgres.d.ts",
66
+ "workerd": null,
67
+ "browser": null,
68
+ "node": "./src/postgres.js"
69
+ }
70
+ },
71
+ "bin": {
72
+ "terrascale-local": "./src/local/cli.js"
73
+ },
74
+ "files": [
75
+ "src",
76
+ "!src/integration",
77
+ "!src/**/*.test.js",
78
+ "types",
79
+ "!types/integration",
80
+ "sdk-v1-route-manifest.json",
81
+ "README.md",
82
+ "CHANGELOG.md",
83
+ "LICENSE"
84
+ ],
85
+ "scripts": {
86
+ "build": "node -e \"require('node:fs').rmSync('types', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
87
+ "prepack": "npm run build",
88
+ "check:v1-route-manifest": "node scripts/generate-v1-route-manifest.js --check",
89
+ "check:forbidden-surface": "vitest run test/forbidden-surface.test.js",
90
+ "check:sbom": "node scripts/check-sbom.js",
91
+ "check:vulnerabilities": "node scripts/check-vulnerabilities.js",
92
+ "generate:v1-route-manifest": "node scripts/generate-v1-route-manifest.js",
93
+ "local": "node src/local/cli.js",
94
+ "typecheck": "tsc -p tsconfig.json --noEmit",
95
+ "lint": "npm run typecheck",
96
+ "test": "vitest run",
97
+ "provision:terrabase": "node scripts/ci/provision-terrabase.mjs",
98
+ "test:integration": "node scripts/ci/run-terrabase-integration.mjs",
99
+ "test:browser": "playwright test",
100
+ "qualify:auth-authority": "node scripts/qualify-auth-authority.js",
101
+ "check:frameworks": "vitest run src/database-view.test.js src/react/core.test.js src/svelte/index.test.js src/tanstack/index.test.js",
102
+ "check:local-better-auth": "vitest run src/better-auth-factory-conformance.test.js"
103
+ },
104
+ "peerDependencies": {
105
+ "@better-auth/core": "1.7.2",
106
+ "react": ">=18.2.0 <20.0.0",
107
+ "pg": "8.23.0",
108
+ "@tanstack/db": "0.9.2"
109
+ },
110
+ "peerDependenciesMeta": {
111
+ "@better-auth/core": {
112
+ "optional": true
113
+ },
114
+ "react": {
115
+ "optional": true
116
+ },
117
+ "pg": {
118
+ "optional": true
119
+ },
120
+ "@tanstack/db": {
121
+ "optional": true
122
+ }
123
+ },
124
+ "devDependencies": {
125
+ "@better-auth/core": "1.7.2",
126
+ "@better-auth/test-utils": "1.7.2",
127
+ "@playwright/test": "^1.63.0",
128
+ "@types/node": "^26.0.0",
129
+ "better-auth": "1.7.2",
130
+ "typescript": "^5.9.3",
131
+ "vitest": "^4.1.11",
132
+ "@tanstack/db": "0.9.2",
133
+ "svelte": "5.55.1",
134
+ "react": "19.2.8",
135
+ "react-test-renderer": "19.2.8",
136
+ "@types/react": "19.2.14",
137
+ "@types/react-test-renderer": "19.1.0",
138
+ "pg": "8.23.0",
139
+ "@types/pg": "8.23.1"
140
+ },
141
+ "engines": {
142
+ "node": "22.x || 24.x",
143
+ "npm": ">=11.0.0"
144
+ },
145
+ "browserslist": {
146
+ "production": [
147
+ "last 1 Chrome major version",
148
+ "last 1 Firefox major version",
149
+ "last 1 Safari major version",
150
+ "last 1 Edge major version"
151
+ ]
152
+ },
153
+ "packageManager": "npm@11.18.0"
154
+ }