@somewhere-cloud/sdk 0.0.0-stage → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +191 -2
- package/dist/cjs/auth/client.js +1059 -0
- package/dist/cjs/auth/client.js.map +1 -0
- package/dist/cjs/auth/continuation.js +27 -0
- package/dist/cjs/auth/continuation.js.map +1 -0
- package/dist/cjs/auth/index.js +21 -0
- package/dist/cjs/auth/index.js.map +1 -0
- package/dist/cjs/auth/react.js +295 -0
- package/dist/cjs/auth/react.js.map +1 -0
- package/dist/cjs/auth/server.js +368 -0
- package/dist/cjs/auth/server.js.map +1 -0
- package/dist/cjs/client.js +392 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors.js +16 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.cjs +215 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/query-cache.js +91 -0
- package/dist/cjs/query-cache.js.map +1 -0
- package/dist/cjs/resources/auth.js +875 -0
- package/dist/cjs/resources/auth.js.map +1 -0
- package/dist/cjs/resources/calls.js +42 -0
- package/dist/cjs/resources/calls.js.map +1 -0
- package/dist/cjs/resources/chat.js +82 -0
- package/dist/cjs/resources/chat.js.map +1 -0
- package/dist/cjs/resources/db.js +124 -0
- package/dist/cjs/resources/db.js.map +1 -0
- package/dist/cjs/resources/emails.js +39 -0
- package/dist/cjs/resources/emails.js.map +1 -0
- package/dist/cjs/resources/fs.js +141 -0
- package/dist/cjs/resources/fs.js.map +1 -0
- package/dist/cjs/resources/functions.js +145 -0
- package/dist/cjs/resources/functions.js.map +1 -0
- package/dist/cjs/resources/inbox.js +76 -0
- package/dist/cjs/resources/inbox.js.map +1 -0
- package/dist/cjs/resources/payments.js +68 -0
- package/dist/cjs/resources/payments.js.map +1 -0
- package/dist/cjs/resources/postgrest.js +391 -0
- package/dist/cjs/resources/postgrest.js.map +1 -0
- package/dist/cjs/resources/projects.js +71 -0
- package/dist/cjs/resources/projects.js.map +1 -0
- package/dist/cjs/resources/storage.js +191 -0
- package/dist/cjs/resources/storage.js.map +1 -0
- package/dist/cjs/resources/tasks.js +99 -0
- package/dist/cjs/resources/tasks.js.map +1 -0
- package/dist/cjs/resources/video.js +50 -0
- package/dist/cjs/resources/video.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/auth/client.js +1054 -0
- package/dist/esm/auth/client.js.map +1 -0
- package/dist/esm/auth/continuation.js +22 -0
- package/dist/esm/auth/continuation.js.map +1 -0
- package/dist/esm/auth/index.js +5 -0
- package/dist/esm/auth/index.js.map +1 -0
- package/dist/esm/auth/react.js +279 -0
- package/dist/esm/auth/react.js.map +1 -0
- package/dist/esm/auth/server.js +365 -0
- package/dist/esm/auth/server.js.map +1 -0
- package/dist/esm/client.js +388 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.js +12 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +188 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/query-cache.js +87 -0
- package/dist/esm/query-cache.js.map +1 -0
- package/dist/esm/resources/auth.js +871 -0
- package/dist/esm/resources/auth.js.map +1 -0
- package/dist/esm/resources/calls.js +38 -0
- package/dist/esm/resources/calls.js.map +1 -0
- package/dist/esm/resources/chat.js +77 -0
- package/dist/esm/resources/chat.js.map +1 -0
- package/dist/esm/resources/db.js +120 -0
- package/dist/esm/resources/db.js.map +1 -0
- package/dist/esm/resources/emails.js +35 -0
- package/dist/esm/resources/emails.js.map +1 -0
- package/dist/esm/resources/fs.js +137 -0
- package/dist/esm/resources/fs.js.map +1 -0
- package/dist/esm/resources/functions.js +141 -0
- package/dist/esm/resources/functions.js.map +1 -0
- package/dist/esm/resources/inbox.js +70 -0
- package/dist/esm/resources/inbox.js.map +1 -0
- package/dist/esm/resources/payments.js +64 -0
- package/dist/esm/resources/payments.js.map +1 -0
- package/dist/esm/resources/postgrest.js +386 -0
- package/dist/esm/resources/postgrest.js.map +1 -0
- package/dist/esm/resources/projects.js +67 -0
- package/dist/esm/resources/projects.js.map +1 -0
- package/dist/esm/resources/storage.js +186 -0
- package/dist/esm/resources/storage.js.map +1 -0
- package/dist/esm/resources/tasks.js +95 -0
- package/dist/esm/resources/tasks.js.map +1 -0
- package/dist/esm/resources/video.js +46 -0
- package/dist/esm/resources/video.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/auth/client.d.ts +272 -0
- package/dist/types/auth/client.d.ts.map +1 -0
- package/dist/types/auth/continuation.d.ts +10 -0
- package/dist/types/auth/continuation.d.ts.map +1 -0
- package/dist/types/auth/index.d.ts +2 -0
- package/dist/types/auth/index.d.ts.map +1 -0
- package/dist/types/auth/react.d.ts +140 -0
- package/dist/types/auth/react.d.ts.map +1 -0
- package/dist/types/auth/server.d.ts +124 -0
- package/dist/types/auth/server.d.ts.map +1 -0
- package/dist/types/client.d.ts +128 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/errors.d.ts +17 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +145 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/query-cache.d.ts +59 -0
- package/dist/types/query-cache.d.ts.map +1 -0
- package/dist/types/resources/auth.d.ts +188 -0
- package/dist/types/resources/auth.d.ts.map +1 -0
- package/dist/types/resources/calls.d.ts +27 -0
- package/dist/types/resources/calls.d.ts.map +1 -0
- package/dist/types/resources/chat.d.ts +24 -0
- package/dist/types/resources/chat.d.ts.map +1 -0
- package/dist/types/resources/db.d.ts +81 -0
- package/dist/types/resources/db.d.ts.map +1 -0
- package/dist/types/resources/emails.d.ts +20 -0
- package/dist/types/resources/emails.d.ts.map +1 -0
- package/dist/types/resources/fs.d.ts +68 -0
- package/dist/types/resources/fs.d.ts.map +1 -0
- package/dist/types/resources/functions.d.ts +30 -0
- package/dist/types/resources/functions.d.ts.map +1 -0
- package/dist/types/resources/inbox.d.ts +52 -0
- package/dist/types/resources/inbox.d.ts.map +1 -0
- package/dist/types/resources/payments.d.ts +31 -0
- package/dist/types/resources/payments.d.ts.map +1 -0
- package/dist/types/resources/postgrest.d.ts +121 -0
- package/dist/types/resources/postgrest.d.ts.map +1 -0
- package/dist/types/resources/projects.d.ts +79 -0
- package/dist/types/resources/projects.d.ts.map +1 -0
- package/dist/types/resources/storage.d.ts +63 -0
- package/dist/types/resources/storage.d.ts.map +1 -0
- package/dist/types/resources/tasks.d.ts +87 -0
- package/dist/types/resources/tasks.d.ts.map +1 -0
- package/dist/types/resources/video.d.ts +30 -0
- package/dist/types/resources/video.d.ts.map +1 -0
- package/dist/types/types.d.ts +379 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +86 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 somewhere.tech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,192 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @somewhere-cloud/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official JavaScript and TypeScript client for [Somewhere Cloud](https://somewhere.cloud).
|
|
4
|
+
|
|
5
|
+
This package was published as `@somewhere-cloud/sdk` through 0.12.10; those versions stay installable.
|
|
6
|
+
|
|
7
|
+
For a browser application's database, start with the schema-generated client that the platform builds from `db/schema.ts`:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { data } from 'somewhere:data'
|
|
11
|
+
|
|
12
|
+
const page = await data.notes.list({ limit: 20 })
|
|
13
|
+
await data.notes.create({ title: 'First note' })
|
|
14
|
+
await data.notes.update(noteId, { done: true })
|
|
15
|
+
await data.notes.remove(noteId)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The generated client exposes only the operations and fields declared in each
|
|
19
|
+
table's `client` grant. A readable declared relation is available through a
|
|
20
|
+
generated `relations.<name>.list(...)` method only when both participating
|
|
21
|
+
tables grant browser reads; hidden linking fields remain internal. Put product
|
|
22
|
+
authorization and trusted database work in server functions with the runtime
|
|
23
|
+
`sw.db` API.
|
|
24
|
+
|
|
25
|
+
Use `@somewhere-cloud/sdk` when application code needs the maintained auth adapters, function invocation, or an explicit server/non-browser client for platform resources. The package keeps its established root exports and result shapes for existing applications, but it is not a replacement for the generated browser data client.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @somewhere-cloud/sdk
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The package provides a root client and focused auth entry points:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { createClient, Somewhere } from '@somewhere-cloud/sdk'
|
|
37
|
+
import { createSomewhereAuth } from '@somewhere-cloud/sdk/auth'
|
|
38
|
+
import { SomewhereAuthProvider, useAuth, SignedIn, SignedOut } from '@somewhere-cloud/sdk/react'
|
|
39
|
+
import { somewhereAuth } from '@somewhere-cloud/sdk/server'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Browser auth and functions
|
|
43
|
+
|
|
44
|
+
Browser sessions use same-origin httpOnly cookies. Page JavaScript holds no developer key or session token. Mount the standard auth handler in your application at `/api/auth`, then create a credential-free browser client:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createClient } from '@somewhere-cloud/sdk'
|
|
48
|
+
|
|
49
|
+
const client = createClient('https://booking-app.somewhere.site', undefined, {
|
|
50
|
+
projectId: 'booking-app',
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const { data, error } = await client.auth.signInWithPassword({
|
|
54
|
+
email: 'person@example.com',
|
|
55
|
+
password,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const result = await client.functions.invoke('checkout', {
|
|
59
|
+
body: { plan: 'pro' },
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`functions.invoke(name, options)` calls `/api/<name>` on the application URL,
|
|
64
|
+
includes browser cookies, and returns `{ data, error }`. Current
|
|
65
|
+
`.somewhere.site` and custom-domain URLs require an explicit `projectId` for
|
|
66
|
+
project-resource calls. Automatic project-id inference is retained only for
|
|
67
|
+
legacy `*.somewhere.tech` application URLs.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const client = createClient('https://app.example.com', undefined, {
|
|
71
|
+
projectId: 'booking-app',
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The auth client also provides signup, magic-link, OAuth, sign-out, password reset, user lookup, session lookup, and auth-state subscriptions. Cookie mode is the browser default. Non-browser clients can select `{ authMode: 'header' }` and manage bearer-session rotation explicitly.
|
|
76
|
+
|
|
77
|
+
## Server and non-browser client
|
|
78
|
+
|
|
79
|
+
Trusted server scripts can construct an explicit client with a developer key:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { Somewhere } from '@somewhere-cloud/sdk'
|
|
83
|
+
|
|
84
|
+
const client = new Somewhere({
|
|
85
|
+
key: process.env.SOMEWHERE_API_KEY,
|
|
86
|
+
projectId: 'booking-app',
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const rows = await client.db.query(
|
|
90
|
+
'SELECT id, total FROM orders WHERE status = ?',
|
|
91
|
+
['pending'],
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Never expose an `smt_` developer key in browser code. Inside a deployed Somewhere Cloud function, use the supplied runtime instead of constructing an SDK client:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
export default async function (request, sw) {
|
|
99
|
+
const result = await sw.db.from('orders', {
|
|
100
|
+
where: { status: 'pending' },
|
|
101
|
+
limit: 20,
|
|
102
|
+
})
|
|
103
|
+
return Response.json(result.data)
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The explicit client retains these established namespaces:
|
|
108
|
+
|
|
109
|
+
- `db` and `from(table)` for server/non-browser database access
|
|
110
|
+
- `fs` and `storage.from(prefix)` for server/non-browser files
|
|
111
|
+
- `auth` for user sessions and account actions
|
|
112
|
+
- `functions.invoke(name, options)` for application functions
|
|
113
|
+
- `emails`, `inbox`, `chat`, `payments`, `video`, `calls`, `tasks`, and `projects`
|
|
114
|
+
|
|
115
|
+
## Fluent database client
|
|
116
|
+
|
|
117
|
+
`client.from(table)` is a thenable fluent query builder for existing server and non-browser integrations. It supports filters such as `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `like`, `ilike`, `in`, `is`, `match`, and `or`, plus `order`, `limit`, `range`, `single`, and `maybeSingle`.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const { data, error } = await client
|
|
121
|
+
.from('orders')
|
|
122
|
+
.select('id, total, status')
|
|
123
|
+
.eq('status', 'pending')
|
|
124
|
+
.order('created_at', { ascending: false })
|
|
125
|
+
.limit(20)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Writes return the same `{ data, error, count?, status? }` result envelope:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
await client.from('orders').insert({ id: 'order-1', status: 'pending' })
|
|
132
|
+
await client.from('orders').update({ status: 'paid' }).eq('id', 'order-1')
|
|
133
|
+
await client.from('orders').delete().eq('id', 'order-1')
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`from().select()` uses a short per-client cache with request deduplication and write invalidation. Disable it with `{ cache: false }`, tune it with `{ cache: { staleTime: 2000 } }`, force one fresh read with `.fresh()`, or invalidate a table with `client.invalidate(table)`.
|
|
137
|
+
|
|
138
|
+
Direct database and private-file calls from a cookie-only browser client do not have a bearer credential. Use `somewhere:data` for declared browser database operations and same-origin functions for trusted logic.
|
|
139
|
+
|
|
140
|
+
## Files
|
|
141
|
+
|
|
142
|
+
The explicit client offers direct file operations through `client.fs` and a prefix-oriented interface through `client.storage.from(prefix)`:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
const avatars = client.storage.from('avatars')
|
|
146
|
+
await avatars.upload('user-42.png', bytes, { contentType: 'image/png' })
|
|
147
|
+
const downloaded = await avatars.download('user-42.png')
|
|
148
|
+
const listed = await avatars.list('team/')
|
|
149
|
+
const publicUrl = avatars.getPublicUrl('user-42.png')
|
|
150
|
+
const signed = await avatars.createSignedUrl('user-42.png', 3600)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Use a server/non-browser credential for private file reads and writes. Public and signed URLs can be consumed by browsers.
|
|
154
|
+
|
|
155
|
+
For browser uploads where each user (or team) sees only their own files, declare a file collection in `db/schema.ts` and use the generated `somewhere:files` client instead of this SDK: see `docs({ topic: 'declared-files' })`.
|
|
156
|
+
|
|
157
|
+
## Browser live views
|
|
158
|
+
|
|
159
|
+
For live browser interfaces, declare a named `sw.db.live` view and use the
|
|
160
|
+
browser subscription helper. That surface is a platform capability, not an SDK
|
|
161
|
+
one; see `docs({ topic: 'live' })` for its scope limits:
|
|
162
|
+
member and policy scopes are not subscribable, and relation-filtered live views
|
|
163
|
+
are refused.
|
|
164
|
+
|
|
165
|
+
## Error handling
|
|
166
|
+
|
|
167
|
+
Most client calls return `{ data, error }`. Check `error` before using `data`:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
const { data, error } = await client.functions.invoke('checkout', {
|
|
171
|
+
body: { plan: 'pro' },
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
if (error) {
|
|
175
|
+
console.error(error.code, error.message)
|
|
176
|
+
if (error.retry && error.retryAfterMs) {
|
|
177
|
+
// Retry only when the operation itself is safe to repeat.
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`client.chat.completions.create(...)` throws on failure and can be handled with `SomewhereError`.
|
|
183
|
+
|
|
184
|
+
## Test
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npm test
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
MIT © somewhere.tech
|