@somewhere-cloud/sdk 0.0.0-stage → 0.13.1

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 (149) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -2
  3. package/dist/cjs/auth/client.js +1142 -0
  4. package/dist/cjs/auth/client.js.map +1 -0
  5. package/dist/cjs/auth/continuation.js +27 -0
  6. package/dist/cjs/auth/continuation.js.map +1 -0
  7. package/dist/cjs/auth/index.js +21 -0
  8. package/dist/cjs/auth/index.js.map +1 -0
  9. package/dist/cjs/auth/react.js +295 -0
  10. package/dist/cjs/auth/react.js.map +1 -0
  11. package/dist/cjs/auth/server.js +368 -0
  12. package/dist/cjs/auth/server.js.map +1 -0
  13. package/dist/cjs/client.js +392 -0
  14. package/dist/cjs/client.js.map +1 -0
  15. package/dist/cjs/errors.js +16 -0
  16. package/dist/cjs/errors.js.map +1 -0
  17. package/dist/cjs/index.cjs +215 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/package.json +1 -0
  20. package/dist/cjs/query-cache.js +91 -0
  21. package/dist/cjs/query-cache.js.map +1 -0
  22. package/dist/cjs/resources/auth.js +875 -0
  23. package/dist/cjs/resources/auth.js.map +1 -0
  24. package/dist/cjs/resources/calls.js +42 -0
  25. package/dist/cjs/resources/calls.js.map +1 -0
  26. package/dist/cjs/resources/chat.js +82 -0
  27. package/dist/cjs/resources/chat.js.map +1 -0
  28. package/dist/cjs/resources/db.js +124 -0
  29. package/dist/cjs/resources/db.js.map +1 -0
  30. package/dist/cjs/resources/emails.js +39 -0
  31. package/dist/cjs/resources/emails.js.map +1 -0
  32. package/dist/cjs/resources/fs.js +141 -0
  33. package/dist/cjs/resources/fs.js.map +1 -0
  34. package/dist/cjs/resources/functions.js +145 -0
  35. package/dist/cjs/resources/functions.js.map +1 -0
  36. package/dist/cjs/resources/inbox.js +76 -0
  37. package/dist/cjs/resources/inbox.js.map +1 -0
  38. package/dist/cjs/resources/payments.js +68 -0
  39. package/dist/cjs/resources/payments.js.map +1 -0
  40. package/dist/cjs/resources/postgrest.js +391 -0
  41. package/dist/cjs/resources/postgrest.js.map +1 -0
  42. package/dist/cjs/resources/projects.js +71 -0
  43. package/dist/cjs/resources/projects.js.map +1 -0
  44. package/dist/cjs/resources/storage.js +191 -0
  45. package/dist/cjs/resources/storage.js.map +1 -0
  46. package/dist/cjs/resources/tasks.js +99 -0
  47. package/dist/cjs/resources/tasks.js.map +1 -0
  48. package/dist/cjs/resources/video.js +50 -0
  49. package/dist/cjs/resources/video.js.map +1 -0
  50. package/dist/cjs/types.js +3 -0
  51. package/dist/cjs/types.js.map +1 -0
  52. package/dist/esm/auth/client.js +1137 -0
  53. package/dist/esm/auth/client.js.map +1 -0
  54. package/dist/esm/auth/continuation.js +22 -0
  55. package/dist/esm/auth/continuation.js.map +1 -0
  56. package/dist/esm/auth/index.js +5 -0
  57. package/dist/esm/auth/index.js.map +1 -0
  58. package/dist/esm/auth/react.js +279 -0
  59. package/dist/esm/auth/react.js.map +1 -0
  60. package/dist/esm/auth/server.js +365 -0
  61. package/dist/esm/auth/server.js.map +1 -0
  62. package/dist/esm/client.js +388 -0
  63. package/dist/esm/client.js.map +1 -0
  64. package/dist/esm/errors.js +12 -0
  65. package/dist/esm/errors.js.map +1 -0
  66. package/dist/esm/index.js +188 -0
  67. package/dist/esm/index.js.map +1 -0
  68. package/dist/esm/package.json +1 -0
  69. package/dist/esm/query-cache.js +87 -0
  70. package/dist/esm/query-cache.js.map +1 -0
  71. package/dist/esm/resources/auth.js +871 -0
  72. package/dist/esm/resources/auth.js.map +1 -0
  73. package/dist/esm/resources/calls.js +38 -0
  74. package/dist/esm/resources/calls.js.map +1 -0
  75. package/dist/esm/resources/chat.js +77 -0
  76. package/dist/esm/resources/chat.js.map +1 -0
  77. package/dist/esm/resources/db.js +120 -0
  78. package/dist/esm/resources/db.js.map +1 -0
  79. package/dist/esm/resources/emails.js +35 -0
  80. package/dist/esm/resources/emails.js.map +1 -0
  81. package/dist/esm/resources/fs.js +137 -0
  82. package/dist/esm/resources/fs.js.map +1 -0
  83. package/dist/esm/resources/functions.js +141 -0
  84. package/dist/esm/resources/functions.js.map +1 -0
  85. package/dist/esm/resources/inbox.js +70 -0
  86. package/dist/esm/resources/inbox.js.map +1 -0
  87. package/dist/esm/resources/payments.js +64 -0
  88. package/dist/esm/resources/payments.js.map +1 -0
  89. package/dist/esm/resources/postgrest.js +386 -0
  90. package/dist/esm/resources/postgrest.js.map +1 -0
  91. package/dist/esm/resources/projects.js +67 -0
  92. package/dist/esm/resources/projects.js.map +1 -0
  93. package/dist/esm/resources/storage.js +186 -0
  94. package/dist/esm/resources/storage.js.map +1 -0
  95. package/dist/esm/resources/tasks.js +95 -0
  96. package/dist/esm/resources/tasks.js.map +1 -0
  97. package/dist/esm/resources/video.js +46 -0
  98. package/dist/esm/resources/video.js.map +1 -0
  99. package/dist/esm/types.js +2 -0
  100. package/dist/esm/types.js.map +1 -0
  101. package/dist/types/auth/client.d.ts +272 -0
  102. package/dist/types/auth/client.d.ts.map +1 -0
  103. package/dist/types/auth/continuation.d.ts +10 -0
  104. package/dist/types/auth/continuation.d.ts.map +1 -0
  105. package/dist/types/auth/index.d.ts +2 -0
  106. package/dist/types/auth/index.d.ts.map +1 -0
  107. package/dist/types/auth/react.d.ts +140 -0
  108. package/dist/types/auth/react.d.ts.map +1 -0
  109. package/dist/types/auth/server.d.ts +124 -0
  110. package/dist/types/auth/server.d.ts.map +1 -0
  111. package/dist/types/client.d.ts +128 -0
  112. package/dist/types/client.d.ts.map +1 -0
  113. package/dist/types/errors.d.ts +17 -0
  114. package/dist/types/errors.d.ts.map +1 -0
  115. package/dist/types/index.d.ts +145 -0
  116. package/dist/types/index.d.ts.map +1 -0
  117. package/dist/types/query-cache.d.ts +59 -0
  118. package/dist/types/query-cache.d.ts.map +1 -0
  119. package/dist/types/resources/auth.d.ts +188 -0
  120. package/dist/types/resources/auth.d.ts.map +1 -0
  121. package/dist/types/resources/calls.d.ts +27 -0
  122. package/dist/types/resources/calls.d.ts.map +1 -0
  123. package/dist/types/resources/chat.d.ts +24 -0
  124. package/dist/types/resources/chat.d.ts.map +1 -0
  125. package/dist/types/resources/db.d.ts +81 -0
  126. package/dist/types/resources/db.d.ts.map +1 -0
  127. package/dist/types/resources/emails.d.ts +20 -0
  128. package/dist/types/resources/emails.d.ts.map +1 -0
  129. package/dist/types/resources/fs.d.ts +68 -0
  130. package/dist/types/resources/fs.d.ts.map +1 -0
  131. package/dist/types/resources/functions.d.ts +30 -0
  132. package/dist/types/resources/functions.d.ts.map +1 -0
  133. package/dist/types/resources/inbox.d.ts +52 -0
  134. package/dist/types/resources/inbox.d.ts.map +1 -0
  135. package/dist/types/resources/payments.d.ts +31 -0
  136. package/dist/types/resources/payments.d.ts.map +1 -0
  137. package/dist/types/resources/postgrest.d.ts +121 -0
  138. package/dist/types/resources/postgrest.d.ts.map +1 -0
  139. package/dist/types/resources/projects.d.ts +79 -0
  140. package/dist/types/resources/projects.d.ts.map +1 -0
  141. package/dist/types/resources/storage.d.ts +63 -0
  142. package/dist/types/resources/storage.d.ts.map +1 -0
  143. package/dist/types/resources/tasks.d.ts +87 -0
  144. package/dist/types/resources/tasks.d.ts.map +1 -0
  145. package/dist/types/resources/video.d.ts +30 -0
  146. package/dist/types/resources/video.d.ts.map +1 -0
  147. package/dist/types/types.d.ts +379 -0
  148. package/dist/types/types.d.ts.map +1 -0
  149. 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
- # Temporary Holding Version
1
+ # @somewhere-cloud/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
+ 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