terrascale 0.3.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 +202 -0
- package/README.md +143 -0
- package/package.json +159 -0
- package/sdk-current-contract.json +27 -0
- package/sdk-route-manifest.json +67 -0
- package/src/admin.js +9 -0
- package/src/better-auth.js +14 -0
- package/src/config.js +121 -0
- package/src/database-codec.js +845 -0
- package/src/database-types.js +237 -0
- package/src/database-view.js +422 -0
- package/src/database.js +420 -0
- package/src/discovery.js +374 -0
- package/src/http.js +887 -0
- package/src/index.js +79 -0
- package/src/local/authentication.js +47 -0
- package/src/local/better-auth.js +517 -0
- package/src/local/cli.js +51 -0
- package/src/local/context.js +23 -0
- package/src/local/environment.js +109 -0
- package/src/local/index.js +204 -0
- package/src/local/router.js +999 -0
- package/src/local/server.js +664 -0
- package/src/local/store.js +530 -0
- package/src/local/test-environment.js +74 -0
- package/src/management-contracts.js +72 -0
- package/src/management.js +12 -0
- package/src/native-origin.js +75 -0
- package/src/postgres.js +494 -0
- package/src/react/core.js +743 -0
- package/src/react/index.js +99 -0
- package/src/result.js +251 -0
- package/src/schema.js +366 -0
- package/src/sql.js +996 -0
- package/src/svelte/index.js +129 -0
- package/src/tanstack/index.js +511 -0
- package/src/ts-auth-discovery.js +190 -0
- package/src/ts-auth.js +3497 -0
- package/types/admin.d.ts +6 -0
- package/types/better-auth.d.ts +8 -0
- package/types/config.d.ts +58 -0
- package/types/database-codec.d.ts +111 -0
- package/types/database-types.d.ts +213 -0
- package/types/database-view.d.ts +183 -0
- package/types/database.d.ts +98 -0
- package/types/discovery.d.ts +114 -0
- package/types/http.d.ts +46 -0
- package/types/index.d.ts +52 -0
- package/types/local/authentication.d.ts +11 -0
- package/types/local/better-auth.d.ts +33 -0
- package/types/local/cli.d.ts +2 -0
- package/types/local/context.d.ts +14 -0
- package/types/local/environment.d.ts +23 -0
- package/types/local/index.d.ts +94 -0
- package/types/local/router.d.ts +66 -0
- package/types/local/server.d.ts +54 -0
- package/types/local/store.d.ts +106 -0
- package/types/local/test-environment.d.ts +25 -0
- package/types/management-contracts.d.ts +44 -0
- package/types/management.d.ts +6 -0
- package/types/native-origin.d.ts +23 -0
- package/types/postgres.d.ts +123 -0
- package/types/react/core.d.ts +366 -0
- package/types/react/index.d.ts +54 -0
- package/types/result.d.ts +161 -0
- package/types/schema.d.ts +145 -0
- package/types/sql.d.ts +288 -0
- package/types/svelte/index.d.ts +81 -0
- package/types/tanstack/index.d.ts +165 -0
- package/types/ts-auth-discovery.d.ts +11 -0
- package/types/ts-auth.d.ts +1826 -0
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
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# terrascale
|
|
2
|
+
|
|
3
|
+
The JavaScript SDK for native TerraBase documents and hosted TerraScale identity.
|
|
4
|
+
The package targets Node.js 22 and 24 and current Chrome, Firefox, Safari, and Edge.
|
|
5
|
+
Release qualification installs the exact packed artifact into a separate consumer.
|
|
6
|
+
|
|
7
|
+
The source is plain ES modules typed with JSDoc and published as written; there
|
|
8
|
+
is no transpile step. `npm run build` generates the `.d.ts` declarations in
|
|
9
|
+
`types/`, so TypeScript and editor consumers get the same types the source is
|
|
10
|
+
checked against.
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import { createTerraBaseClient } from "terrascale";
|
|
14
|
+
|
|
15
|
+
const database = createTerraBaseClient({
|
|
16
|
+
tenant: process.env.TERRABASE_TENANT,
|
|
17
|
+
database: process.env.TERRABASE_DATABASE,
|
|
18
|
+
shard: BigInt(process.env.TERRABASE_SHARD),
|
|
19
|
+
apiKey: process.env.TERRABASE_API_KEY,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const result = await database.read(collectionUuid, documentUuid);
|
|
23
|
+
if (!result.ok) throw new Error(result.error.code);
|
|
24
|
+
console.log(result.value.state);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Entity IDs are canonical UUIDs. Shard, generation, sequence, and signed integer
|
|
28
|
+
values remain bigint; bytes remain Uint8Array. Preserve every conflict sibling
|
|
29
|
+
and the complete causal context. Missing fields are omitted; `{ type: "null" }`
|
|
30
|
+
is an explicit null. Use the actual provisioned collection's numeric field IDs,
|
|
31
|
+
schema generation, and digest. Schema helpers describe local declarations and
|
|
32
|
+
SQL builders produce parameterized descriptors; neither provisions a catalog.
|
|
33
|
+
|
|
34
|
+
Native methods are `read`, `query`, `subscription`, `prepareCommit`, `commit`,
|
|
35
|
+
and `transactionStatus`. Queries use bounded typed predicates and opaque cursors.
|
|
36
|
+
Subscriptions first consume a complete paginated snapshot, then finite poll
|
|
37
|
+
groups. SQL execution requires the separate PostgreSQL listener contract.
|
|
38
|
+
|
|
39
|
+
`createDatabaseQuery(client, options)` delivers complete native snapshot and poll
|
|
40
|
+
cuts to `useQuery` from `terrascale/react` or `createQuery` from
|
|
41
|
+
`terrascale/svelte`. TanStack DB 0.9.2 integration is available through
|
|
42
|
+
`terrascaleCollectionOptions` from `terrascale/tanstack`; map each complete
|
|
43
|
+
point explicitly and preserve conflicts. Publication is acknowledged before
|
|
44
|
+
advancing delivery, and cleanup cancels owned work. Mutations prepare and commit
|
|
45
|
+
through the same client; a presentation rollback does not establish a server abort.
|
|
46
|
+
|
|
47
|
+
Omitting `endpoint` uses authenticated, scope-bound routing at
|
|
48
|
+
`https://atlas.terrascale.tech` with the native `tbk1` database key. The client
|
|
49
|
+
selects an eligible canonical regional origin and checks its bounded lease again
|
|
50
|
+
before dispatch. `discoveryTimeoutMs` defaults to 3000 and accepts 1–30000 ms.
|
|
51
|
+
Each operation uses the receiver's highest-priority endpoint with the required
|
|
52
|
+
capabilities. Discovery denial, unavailability, invalid or expired leases, and
|
|
53
|
+
missing capabilities return a typed error before any native data request.
|
|
54
|
+
Set `endpoint` to use an independently provisioned direct HTTPS origin. HTTP is
|
|
55
|
+
allowed only on loopback for development, and the public test host is rejected.
|
|
56
|
+
Database keys and hosted identity management keys are separate credentials.
|
|
57
|
+
|
|
58
|
+
The admitted Atlas receiver advertises conditional mutations, atomic groups,
|
|
59
|
+
and security state as unavailable. Discovered clients refuse those operations
|
|
60
|
+
before native dispatch. Direct local native conditional semantics do not grant
|
|
61
|
+
those production capabilities.
|
|
62
|
+
|
|
63
|
+
For authentication/security conditional writes, use the provisioned single-writer authority, including
|
|
64
|
+
its generation and writer identity. An absent condition requires absence; a
|
|
65
|
+
version condition compares the complete point's state token. Copy the point's
|
|
66
|
+
full context into `observed` for replacement or deletion. Causal observation
|
|
67
|
+
alone does not establish compare-and-swap. Direct leaderless conditional commits
|
|
68
|
+
prove only the admitted local native exclusion semantics; they do not establish
|
|
69
|
+
distributed writer fencing. Leaderless storage is unsuitable for
|
|
70
|
+
security state and authentication invariants.
|
|
71
|
+
|
|
72
|
+
`prepareCommit` snapshots the request and computes its canonical SHA-256 effect
|
|
73
|
+
fingerprint. Reuse that prepared transaction on the same client for an exact
|
|
74
|
+
retry; a changed effect requires a new transaction identity. Mutations are not
|
|
75
|
+
automatically replayed. Resolve an uncertain mutation with transaction status;
|
|
76
|
+
unknown, pending, and expired status do not establish an abort. Persist the
|
|
77
|
+
transaction identity, authority, and fingerprint when recovery spans restarts.
|
|
78
|
+
`local_durable` and `object_durable` are distinct acknowledgement levels.
|
|
79
|
+
|
|
80
|
+
`terrascale/ts-auth` contains the separate hosted identity management and
|
|
81
|
+
OIDC client. Its private transport preserves form-encoded token operations,
|
|
82
|
+
bounded responses, deadlines, and a single changed-token refresh. Configure
|
|
83
|
+
its own origin, instance, and identity credentials.
|
|
84
|
+
|
|
85
|
+
`terrascale/local` is an explicitly enabled Node development runtime:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { createTerraScaleSqliteRuntime } from "terrascale/local";
|
|
89
|
+
|
|
90
|
+
const local = createTerraScaleSqliteRuntime({
|
|
91
|
+
sqlite: { enabled: true, databasePath: "/absolute/path/development.sqlite" },
|
|
92
|
+
});
|
|
93
|
+
await local.bindCollection({
|
|
94
|
+
collection: collectionUuid,
|
|
95
|
+
schema_generation: 1n,
|
|
96
|
+
schema_digest,
|
|
97
|
+
});
|
|
98
|
+
const client = local.createClient();
|
|
99
|
+
// Use local.authority for local conditional commits.
|
|
100
|
+
await local.close();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The local runtime refuses CI, production, qualification, staging, and deployment
|
|
104
|
+
environments. Its official Better Auth 1.7.2 adapter uses development SQLite
|
|
105
|
+
transactions and maintained adapter suites. These checks do not qualify
|
|
106
|
+
production security, regional replication, or the deployed customer application.
|
|
107
|
+
|
|
108
|
+
The management, administration, and production Better Auth entrypoints fail
|
|
109
|
+
with explicit capability errors until management/catalog provisioning and
|
|
110
|
+
credential lifecycle (C06/C07) and production Better Auth security persistence
|
|
111
|
+
are admitted.
|
|
112
|
+
|
|
113
|
+
Every push to `main` that passes CI publishes the `package.json` version to npm
|
|
114
|
+
when that version is not yet published. Bump the version to release.
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
npm ci
|
|
118
|
+
npm run typecheck
|
|
119
|
+
npm run build
|
|
120
|
+
npm test
|
|
121
|
+
npm run check:frameworks
|
|
122
|
+
npm run check:current-contract-inputs
|
|
123
|
+
npm run check:current-contract
|
|
124
|
+
npm run test:browser
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Source parity requires absolute `TERRASCALE_CURRENT_OPENAPI` and
|
|
128
|
+
`TERRASCALE_ATOMIC_VECTORS` paths matching `sdk-current-contract.json` exactly.
|
|
129
|
+
Run `npm run qualify:current-producer` with a supplied immutable tarball and a
|
|
130
|
+
real isolated allocation; see [qualification inputs](scripts/qualification/README.md).
|
|
131
|
+
Missing real-producer inputs fail the required gate. See [release requirements](docs/release.md).
|
|
132
|
+
|
|
133
|
+
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.
|
|
134
|
+
|
|
135
|
+
`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.
|
|
136
|
+
|
|
137
|
+
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.
|
|
138
|
+
|
|
139
|
+
Regional native database origins use `https://<region>.api.terrascale.tech`,
|
|
140
|
+
for example `https://gru.api.terrascale.tech`. The global API host and retired
|
|
141
|
+
root regional hosts cannot serve as native origins. Auth uses its separate
|
|
142
|
+
`.auth.terrascale.tech` namespace. Direct independent origins must use ASCII
|
|
143
|
+
hostnames; percent-encoded and Unicode hostname aliases are rejected.
|
package/package.json
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "terrascale",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "JavaScript SDK, typed with JSDoc, for native TerraBase documents 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-route-manifest.json",
|
|
81
|
+
"sdk-current-contract.json",
|
|
82
|
+
"README.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
|
+
"qualify:artifact": "node scripts/qualify-npm-artifact.js",
|
|
88
|
+
"qualify:current-producer": "node scripts/qualification/current-producer-consumer.js",
|
|
89
|
+
"check:route-manifest": "node scripts/generate-client-route-manifest.js --check",
|
|
90
|
+
"check:openapi-contract-descriptor": "node scripts/generate-openapi-contract-descriptor.js --check",
|
|
91
|
+
"check:public-contract-fixture": "vitest run test/public-contract-fixture.test.js",
|
|
92
|
+
"check:forbidden-surface": "vitest run test/forbidden-surface.test.js",
|
|
93
|
+
"check:sbom": "node scripts/check-sbom.js",
|
|
94
|
+
"check:vulnerabilities": "node scripts/check-vulnerabilities.js",
|
|
95
|
+
"generate:route-manifest": "npm run build && node scripts/generate-client-route-manifest.js",
|
|
96
|
+
"generate:openapi-contract-descriptor": "npm run build && node scripts/generate-openapi-contract-descriptor.js",
|
|
97
|
+
"local": "node src/local/cli.js",
|
|
98
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
99
|
+
"test": "vitest run",
|
|
100
|
+
"test:browser": "playwright test",
|
|
101
|
+
"check:current-contract": "vitest run test/current-producer-contract.test.js test/openapi-drift.test.js",
|
|
102
|
+
"qualify:auth-authority": "node scripts/qualify-auth-authority.js",
|
|
103
|
+
"qualify:release-e2e": "node scripts/run-packed-release-e2e.js",
|
|
104
|
+
"check:current-contract-inputs": "node scripts/openapi-contract-paths.js --check-inputs",
|
|
105
|
+
"check:frameworks": "vitest run src/database-view.test.js src/react/core.test.js src/svelte/index.test.js src/tanstack/index.test.js",
|
|
106
|
+
"check:local-better-auth": "vitest run src/better-auth-factory-conformance.test.js",
|
|
107
|
+
"qualify:current-postgres-producer": "node scripts/current-postgres-producer.js"
|
|
108
|
+
},
|
|
109
|
+
"peerDependencies": {
|
|
110
|
+
"@better-auth/core": "1.7.2",
|
|
111
|
+
"react": ">=18.2.0 <20.0.0",
|
|
112
|
+
"pg": "8.23.0",
|
|
113
|
+
"@tanstack/db": "0.9.2"
|
|
114
|
+
},
|
|
115
|
+
"peerDependenciesMeta": {
|
|
116
|
+
"@better-auth/core": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"react": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"pg": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"@tanstack/db": {
|
|
126
|
+
"optional": true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"devDependencies": {
|
|
130
|
+
"@better-auth/core": "1.7.2",
|
|
131
|
+
"@better-auth/test-utils": "1.7.2",
|
|
132
|
+
"@playwright/test": "^1.63.0",
|
|
133
|
+
"@types/node": "^26.0.0",
|
|
134
|
+
"better-auth": "1.7.2",
|
|
135
|
+
"typescript": "^5.9.3",
|
|
136
|
+
"vitest": "^4.1.11",
|
|
137
|
+
"@tanstack/db": "0.9.2",
|
|
138
|
+
"svelte": "5.55.1",
|
|
139
|
+
"react": "19.2.8",
|
|
140
|
+
"react-test-renderer": "19.2.8",
|
|
141
|
+
"@types/react": "19.2.14",
|
|
142
|
+
"@types/react-test-renderer": "19.1.0",
|
|
143
|
+
"pg": "8.23.0",
|
|
144
|
+
"@types/pg": "8.23.1"
|
|
145
|
+
},
|
|
146
|
+
"engines": {
|
|
147
|
+
"node": "22.x || 24.x",
|
|
148
|
+
"npm": ">=11.0.0"
|
|
149
|
+
},
|
|
150
|
+
"browserslist": {
|
|
151
|
+
"production": [
|
|
152
|
+
"last 1 Chrome major version",
|
|
153
|
+
"last 1 Firefox major version",
|
|
154
|
+
"last 1 Safari major version",
|
|
155
|
+
"last 1 Edge major version"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
"packageManager": "npm@11.18.0"
|
|
159
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"producer": "terrabase",
|
|
4
|
+
"sourceBase": "470d1f898897d4a0cefc7d638ce8eb72f0ca73b8",
|
|
5
|
+
"sourceOpenApiSha256": "2c8fc075bb2714de6f0ba10756f903e09e4d2a43ecaa63b2135ccb2042545a52",
|
|
6
|
+
"sourceAtomicVectorsSha256": "4ce4286b6e2eeae4ee15dec83f788f33cffdba7606a49021ec81afe0a4a9e816",
|
|
7
|
+
"sourceIdentityStatus": "accepted frozen atomic contract plus evolving uncommitted producer overlay; runtime qualification pending",
|
|
8
|
+
"atomicContractSha256": "f016ea7b0851a7f286a28a95c3d2186a1be57216105f1f13429160230e843e29",
|
|
9
|
+
"atlasAdmissionSha256": "8d1e39955e256851b4b89dedf52cdcc26d649ecd9ababa2164ccae021c0ba4b5",
|
|
10
|
+
"effectFingerprint": "SHA-256 over TB-DOC-EFFECT-v1 NUL domain and canonical native typed effect bytes; transaction identity excluded",
|
|
11
|
+
"routes": [
|
|
12
|
+
{ "method": "GET", "path": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/collections/{collection}/documents/{document}", "response": "PointResponse" },
|
|
13
|
+
{ "method": "POST", "path": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/collections/{collection}/documents/query", "request": "QueryRequest", "response": "QueryResponse" },
|
|
14
|
+
{ "method": "POST", "path": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/collections/{collection}/documents/subscriptions", "request": "SubscriptionRequest", "response": "SubscriptionResponse" },
|
|
15
|
+
{ "method": "POST", "path": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/transactions", "request": "CommitRequest", "response": "CommitResponse" },
|
|
16
|
+
{ "method": "POST", "path": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/transactions/status", "request": "TransactionStatusRequest", "response": "TransactionStatusResponse" }
|
|
17
|
+
],
|
|
18
|
+
"remainingReleaseGates": [
|
|
19
|
+
"exact producer source/artifact and OpenAPI digests",
|
|
20
|
+
"real packaged producer and independently installed SDK consumer",
|
|
21
|
+
"legacy public package cutover",
|
|
22
|
+
"scoped Atlas UUID/shard authority discovery",
|
|
23
|
+
"single-writer producer admission",
|
|
24
|
+
"public C06 catalog/schema/provisioning and C07 credentials",
|
|
25
|
+
"required deployed TypeScript account journey"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifestVersion": 2,
|
|
3
|
+
"contractVersion": "terrabase-client-v1",
|
|
4
|
+
"routeCount": 5,
|
|
5
|
+
"routes": [
|
|
6
|
+
{
|
|
7
|
+
"base": "native",
|
|
8
|
+
"producer": "terrabase",
|
|
9
|
+
"client": "TerraBaseClient",
|
|
10
|
+
"operation": "read",
|
|
11
|
+
"operationId": "readDocument",
|
|
12
|
+
"routeName": "database.read",
|
|
13
|
+
"method": "GET",
|
|
14
|
+
"pathTemplate": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/collections/{collection}/documents/{document}",
|
|
15
|
+
"requestType": "void",
|
|
16
|
+
"responseType": "PointResponse"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"base": "native",
|
|
20
|
+
"producer": "terrabase",
|
|
21
|
+
"client": "TerraBaseClient",
|
|
22
|
+
"operation": "query",
|
|
23
|
+
"operationId": "queryDocuments",
|
|
24
|
+
"routeName": "database.query",
|
|
25
|
+
"method": "POST",
|
|
26
|
+
"pathTemplate": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/collections/{collection}/documents/query",
|
|
27
|
+
"requestType": "QueryRequest",
|
|
28
|
+
"responseType": "QueryResponse"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"base": "native",
|
|
32
|
+
"producer": "terrabase",
|
|
33
|
+
"client": "TerraBaseClient",
|
|
34
|
+
"operation": "subscription",
|
|
35
|
+
"operationId": "subscribeDocuments",
|
|
36
|
+
"routeName": "database.subscription",
|
|
37
|
+
"method": "POST",
|
|
38
|
+
"pathTemplate": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/collections/{collection}/documents/subscriptions",
|
|
39
|
+
"requestType": "SubscriptionRequest",
|
|
40
|
+
"responseType": "SubscriptionResponse"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"base": "native",
|
|
44
|
+
"producer": "terrabase",
|
|
45
|
+
"client": "TerraBaseClient",
|
|
46
|
+
"operation": "commit",
|
|
47
|
+
"operationId": "commitDocuments",
|
|
48
|
+
"routeName": "database.commit",
|
|
49
|
+
"method": "POST",
|
|
50
|
+
"pathTemplate": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/transactions",
|
|
51
|
+
"requestType": "CommitRequest",
|
|
52
|
+
"responseType": "CommitResponse"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"base": "native",
|
|
56
|
+
"producer": "terrabase",
|
|
57
|
+
"client": "TerraBaseClient",
|
|
58
|
+
"operation": "transactionStatus",
|
|
59
|
+
"operationId": "transactionStatus",
|
|
60
|
+
"routeName": "database.transactionStatus",
|
|
61
|
+
"method": "POST",
|
|
62
|
+
"pathTemplate": "/v1/tenants/{tenant}/databases/{database}/shards/{shard}/transactions/status",
|
|
63
|
+
"requestType": "TransactionStatusRequest",
|
|
64
|
+
"responseType": "TransactionStatusResponse"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
package/src/admin.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { TerraScaleCapabilityUnavailableError } from "./management-contracts.js";
|
|
2
|
+
import { requireTerraScaleCapability } from "./management-contracts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Administrative operations require the admitted regional management contract.
|
|
5
|
+
* @returns {never}
|
|
6
|
+
*/
|
|
7
|
+
export function requireTerraScaleAdministration() {
|
|
8
|
+
return requireTerraScaleCapability("management");
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {
|
|
2
|
+
terraScaleReleaseBlockers,
|
|
3
|
+
TerraScaleCapabilityUnavailableError,
|
|
4
|
+
} from "./management-contracts.js";
|
|
5
|
+
import { requireTerraScaleCapability } from "./management-contracts.js";
|
|
6
|
+
/**
|
|
7
|
+
* Production Better Auth persistence is required but blocked by security authority
|
|
8
|
+
* and catalog/credential admission. Local development uses the explicit ./local
|
|
9
|
+
* SQLite factory pinned to Better Auth 1.7.2.
|
|
10
|
+
* @returns {never}
|
|
11
|
+
*/
|
|
12
|
+
export function requireTerraScaleBetterAuth() {
|
|
13
|
+
return requireTerraScaleCapability("betterAuth");
|
|
14
|
+
}
|