@classcad/client 0.0.0-stage → 3.0.0-beta.20261119100608

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 (108) hide show
  1. package/README.md +20 -2
  2. package/bin/buerli-classcad.cjs +23 -0
  3. package/build/cjs/BuerliCadFacade.js +718 -0
  4. package/build/cjs/cclass/utils/assembly.js +687 -0
  5. package/build/cjs/cclass/utils/base.js +136 -0
  6. package/build/cjs/cclass/utils/index.js +99 -0
  7. package/build/cjs/cclass/utils/part.js +153 -0
  8. package/build/cjs/classcadEngine.js +33 -0
  9. package/build/cjs/createApi.js +71 -0
  10. package/build/cjs/createUnwrappedApi.js +43 -0
  11. package/build/cjs/facade.js +103 -0
  12. package/build/cjs/globals.js +157 -0
  13. package/build/cjs/index.js +102 -0
  14. package/build/cjs/io/AwvNodeClient.js +290 -0
  15. package/build/cjs/io/SocketIOClient.js +339 -0
  16. package/build/cjs/io/Transaction.js +134 -0
  17. package/build/cjs/io/WASMClient.js +433 -0
  18. package/build/cjs/io/WSClient.js +646 -0
  19. package/build/cjs/io/engineKey.js +202 -0
  20. package/build/cjs/re-export.js +35 -0
  21. package/build/cjs/session/host.js +479 -0
  22. package/build/cjs/session/identity.js +38 -0
  23. package/build/cjs/session/selection.js +283 -0
  24. package/build/cjs/session/share.js +229 -0
  25. package/build/cjs/session/types.js +23 -0
  26. package/build/cjs/test/SocketIOClient.spec.js +178 -0
  27. package/build/cjs/types/ComClient.js +10 -0
  28. package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
  29. package/build/cjs/utils/createRecursiveScene.js +140 -0
  30. package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
  31. package/build/cjs/utils/index.js +20 -0
  32. package/build/cjs/utils/polyline.js +65 -0
  33. package/build/cjs/utils/waitForSelect.js +29 -0
  34. package/build/esm/BuerliCadFacade.js +714 -0
  35. package/build/esm/cclass/utils/assembly.js +665 -0
  36. package/build/esm/cclass/utils/base.js +127 -0
  37. package/build/esm/cclass/utils/index.js +62 -0
  38. package/build/esm/cclass/utils/part.js +144 -0
  39. package/build/esm/classcadEngine.js +30 -0
  40. package/build/esm/createApi.js +66 -0
  41. package/build/esm/createUnwrappedApi.js +39 -0
  42. package/build/esm/facade.js +98 -0
  43. package/build/esm/globals.js +150 -0
  44. package/build/esm/index.js +80 -0
  45. package/build/esm/io/AwvNodeClient.js +286 -0
  46. package/build/esm/io/SocketIOClient.js +332 -0
  47. package/build/esm/io/Transaction.js +130 -0
  48. package/build/esm/io/WASMClient.js +429 -0
  49. package/build/esm/io/WSClient.js +642 -0
  50. package/build/esm/io/engineKey.js +196 -0
  51. package/build/esm/re-export.js +3 -0
  52. package/build/esm/session/host.js +474 -0
  53. package/build/esm/session/identity.js +34 -0
  54. package/build/esm/session/selection.js +277 -0
  55. package/build/esm/session/share.js +221 -0
  56. package/build/esm/session/types.js +20 -0
  57. package/build/esm/test/SocketIOClient.spec.js +178 -0
  58. package/build/esm/types/ComClient.js +7 -0
  59. package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
  60. package/build/esm/utils/createRecursiveScene.js +136 -0
  61. package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
  62. package/build/esm/utils/index.js +4 -0
  63. package/build/esm/utils/polyline.js +60 -0
  64. package/build/esm/utils/waitForSelect.js +23 -0
  65. package/build/types/BuerliCadFacade.d.ts +410 -0
  66. package/build/types/cclass/utils/assembly.d.ts +180 -0
  67. package/build/types/cclass/utils/base.d.ts +55 -0
  68. package/build/types/cclass/utils/index.d.ts +46 -0
  69. package/build/types/cclass/utils/part.d.ts +46 -0
  70. package/build/types/classcadEngine.d.ts +40 -0
  71. package/build/types/createApi.d.ts +65 -0
  72. package/build/types/createUnwrappedApi.d.ts +36 -0
  73. package/build/types/facade.d.ts +9 -0
  74. package/build/types/globals.d.ts +79 -0
  75. package/build/types/index.d.ts +82 -0
  76. package/build/types/io/AwvNodeClient.d.ts +182 -0
  77. package/build/types/io/SocketIOClient.d.ts +84 -0
  78. package/build/types/io/Transaction.d.ts +56 -0
  79. package/build/types/io/WASMClient.d.ts +239 -0
  80. package/build/types/io/WSClient.d.ts +242 -0
  81. package/build/types/io/engineKey.d.ts +137 -0
  82. package/build/types/re-export.d.ts +6 -0
  83. package/build/types/session/host.d.ts +108 -0
  84. package/build/types/session/identity.d.ts +46 -0
  85. package/build/types/session/selection.d.ts +164 -0
  86. package/build/types/session/share.d.ts +131 -0
  87. package/build/types/session/types.d.ts +113 -0
  88. package/build/types/test/SocketIOClient.spec.d.ts +0 -0
  89. package/build/types/types/ComClient.d.ts +307 -0
  90. package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
  91. package/build/types/utils/createRecursiveScene.d.ts +24 -0
  92. package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
  93. package/build/types/utils/index.d.ts +4 -0
  94. package/build/types/utils/polyline.d.ts +43 -0
  95. package/build/types/utils/waitForSelect.d.ts +4 -0
  96. package/doc/api/advanced/connection.md +488 -0
  97. package/doc/api/clients.md +2045 -0
  98. package/doc/api/engine-keys.md +230 -0
  99. package/doc/api/index.md +58 -0
  100. package/doc/api/modeling.md +682 -0
  101. package/doc/api/other.md +33 -0
  102. package/doc/api/session-sharing.md +706 -0
  103. package/package.json +60 -4
  104. package/test/classcadEngine.test.cjs +44 -0
  105. package/test/connect.test.cjs +81 -0
  106. package/test/engineKey.test.cjs +80 -0
  107. package/test/onClient.test.cjs +82 -0
  108. package/typedoc.json +8 -0
@@ -0,0 +1,230 @@
1
+ # Engine Keys
2
+
3
+ The key an engine starts with. A public access token on the `WASMClient` is all most apps need; the rest is for
4
+ apps with a sign-in of their own, and for servers.
5
+
6
+ ## Functions
7
+
8
+ ### resolveEngineKey() {#resolveenginekey}
9
+
10
+ ```ts
11
+ function resolveEngineKey(source): Promise<string>;
12
+ ```
13
+
14
+ The key for an engine start: the given key, the app's own, or one for the access token.
15
+
16
+ Throws EngineKeyError when there is none, with the service's reason (an unregistered
17
+ domain, a revoked token, a plan without the native engine).
18
+
19
+ A key for a token is cached in `localStorage` (where there is one), per token, page origin and key service. It is
20
+ used until a minute before it expires and renewed in the background once less than a quarter of its life, or less
21
+ than a day, is left. When the service cannot be reached, a cached key that has not expired is used; a refusal
22
+ (an HTTP 4xx) is final. [WASMClient](clients.md#wasmclient) calls it on `connect`.
23
+
24
+ #### Parameters
25
+
26
+ | Parameter | Type | Description |
27
+ | :------ | :------ | :------ |
28
+ | `source` | [`EngineKeySource`](#enginekeysource) | The key, the app's `getKey`, or the access token to get one with. |
29
+
30
+ #### Returns
31
+
32
+ `Promise`&lt;`string`&gt;
33
+
34
+ The key.
35
+
36
+ #### Example
37
+
38
+ ```ts
39
+ import { resolveEngineKey } from '@classcad/client'
40
+
41
+ // A server that starts a native engine of its own, with a secret access token
42
+ const key = await resolveEngineKey({
43
+ token: process.env.CLASSCAD_SECRET_TOKEN,
44
+ appType: 'native',
45
+ client: 'render farm',
46
+ })
47
+ await startEngine(key)
48
+ ```
49
+
50
+ ## Classes
51
+
52
+ ### EngineKeyError {#enginekeyerror}
53
+
54
+ The error when there is no key for an engine: no token, the key service cannot be reached, or it refused.
55
+
56
+ [WASMClient.connect](clients.md#connect) rejects with it.
57
+
58
+ #### Example
59
+
60
+ ```ts
61
+ import { EngineKeyError, resolveEngineKey } from '@classcad/client'
62
+
63
+ // Checks a page's token before the app starts, and says why it fails
64
+ try {
65
+ await resolveEngineKey({ token: 'ccpk_…' })
66
+ } catch (error) {
67
+ if (error instanceof EngineKeyError && error.status && error.status < 500) {
68
+ showError(`ClassCAD refused the key: ${error.message}`) // e.g. a domain the account has not registered
69
+ } else {
70
+ showError('The ClassCAD key service cannot be reached')
71
+ }
72
+ }
73
+ ```
74
+
75
+ #### Extends
76
+
77
+ - `Error`
78
+
79
+ #### Constructors
80
+
81
+ ##### Constructor
82
+
83
+ ```ts
84
+ new EngineKeyError(
85
+ message,
86
+ status?,
87
+ code?
88
+ ): EngineKeyError;
89
+ ```
90
+
91
+ ###### Parameters
92
+
93
+ | Parameter | Type | Description |
94
+ | :------ | :------ | :------ |
95
+ | `message` | `string` | What went wrong; the key service's own words when it refused. |
96
+ | `status?` | `number` | The HTTP status of the key service's answer, when it answered. |
97
+ | `code?` | `string` | The key service's error code, when it gave one. |
98
+
99
+ ###### Returns
100
+
101
+ [`EngineKeyError`](#enginekeyerror)
102
+
103
+ ###### Overrides
104
+
105
+ ```ts
106
+ Error.constructor
107
+ ```
108
+
109
+ #### Properties
110
+
111
+ | Property | Modifier | Type | Description |
112
+ | :------ | :------ | :------ | :------ |
113
+ | <a id="property-code"></a> `code?` | `public` | `string` | The key service's error code, when it gave one. |
114
+ | <a id="property-status"></a> `status?` | `public` | `number` | The HTTP status of the key service's answer, when it answered. |
115
+
116
+ ## Types
117
+
118
+ ### EngineKey {#enginekey}
119
+
120
+ ```ts
121
+ type EngineKey = {
122
+ exp: number;
123
+ key: string;
124
+ };
125
+ ```
126
+
127
+ An engine key, and when it expires.
128
+
129
+ What a WASMClient's `getKey` may resolve to: see the examples of [WASMClient](clients.md#wasmclient) and [requestEngineKey](#requestenginekey).
130
+
131
+ #### Properties
132
+
133
+ | Property | Type | Description |
134
+ | :------ | :------ | :------ |
135
+ | <a id="property-exp"></a> `exp` | `number` | When the key expires, in milliseconds since 1970 (as `Date.now()`). |
136
+ | <a id="property-key"></a> `key` | `string` | The key the engine starts with. |
137
+
138
+ ***
139
+
140
+ ### EngineKeySource {#enginekeysource}
141
+
142
+ ```ts
143
+ type EngineKeySource = {
144
+ appType?: "wasm" | "native";
145
+ classcadKey?: string;
146
+ client?: string;
147
+ getKey?: () => Promise<string | EngineKey>;
148
+ keyUrl?: string;
149
+ token?: string;
150
+ };
151
+ ```
152
+
153
+ Where an engine's key comes from: a key, a ClassCAD access token, or a function of the app's own.
154
+
155
+ The first one given is used, in this order: `classcadKey`, `getKey`, `token`.
156
+
157
+ #### Example
158
+
159
+ ```ts
160
+ import { resolveEngineKey } from '@classcad/client'
161
+ import type { EngineKeySource } from '@classcad/client'
162
+
163
+ // A key from a token exchange of one's own (a self-hosted backend), named for the account's records
164
+ const source: EngineKeySource = {
165
+ token: 'ccpk_…',
166
+ keyUrl: 'https://keys.example.com/api/v1/key',
167
+ client: 'configurator 2.1',
168
+ }
169
+ const key = await resolveEngineKey(source)
170
+ ```
171
+
172
+ #### Properties
173
+
174
+ | Property | Type | Description |
175
+ | :------ | :------ | :------ |
176
+ | <a id="property-apptype"></a> `appType?` | `"wasm"` \| `"native"` | The engine the key is for: `'wasm'` (default) or `'native'`. |
177
+ | <a id="property-classcadkey"></a> `classcadKey?` | `string` | An engine key itself; when given, nothing is fetched. |
178
+ | <a id="property-client"></a> `client?` | `string` | Who asks, for the account's records. |
179
+ | <a id="property-getkey"></a> `getKey?` | () => `Promise`&lt;`string` \| [`EngineKey`](#enginekey)&gt; | Or the app supplies keys itself, for example from its own sign-in (POST /key with a Firebase ID token). |
180
+ | <a id="property-keyurl"></a> `keyUrl?` | `string` | The token exchange, DEFAULT_KEY_URL unless given. |
181
+ | <a id="property-token"></a> `token?` | `string` | A ClassCAD access token: `ccpk_…` in web pages, `ccsk_…` on servers. |
182
+
183
+ ## Advanced
184
+
185
+ Most apps do not need these directly: types they meet through the exports above, and what is there for special cases or for building on the SDK itself.
186
+
187
+ ### DEFAULT\_KEY\_URL {#default_key_url}
188
+
189
+ ```ts
190
+ const DEFAULT_KEY_URL: "https://europe-west1-classcad-app.cloudfunctions.net/api/v1/key" = 'https://europe-west1-classcad-app.cloudfunctions.net/api/v1/key';
191
+ ```
192
+
193
+ The token exchange of the ClassCAD backend.
194
+
195
+ ***
196
+
197
+ ### requestEngineKey() {#requestenginekey}
198
+
199
+ ```ts
200
+ function requestEngineKey(source): Promise<EngineKey>;
201
+ ```
202
+
203
+ Asks the token exchange for a key.
204
+
205
+ Sends `source.token` to `source.keyUrl` (default [DEFAULT\_KEY\_URL](#default_key_url)) every time; [resolveEngineKey](#resolveenginekey)
206
+ caches the key. Throws an [EngineKeyError](#enginekeyerror) without a token, when the service cannot be reached, and with
207
+ its reason when it refuses.
208
+
209
+ #### Parameters
210
+
211
+ | Parameter | Type | Description |
212
+ | :------ | :------ | :------ |
213
+ | `source` | [`EngineKeySource`](#enginekeysource) | The access token, and optionally `keyUrl`, `appType` and `client`. |
214
+
215
+ #### Returns
216
+
217
+ `Promise`&lt;[`EngineKey`](#enginekey)&gt;
218
+
219
+ #### Example
220
+
221
+ ```ts
222
+ import { requestEngineKey } from '@classcad/client'
223
+
224
+ // The app's server: hands its signed-in users engine keys, with the secret token only it knows
225
+ export async function engineKeyRoute(request: Request): Promise<Response> {
226
+ if (!(await isSignedIn(request))) return new Response('Sign in first', { status: 401 })
227
+ const key = await requestEngineKey({ token: process.env.CLASSCAD_SECRET_TOKEN, client: 'my-app server' })
228
+ return Response.json(key) // { key, exp }, what a WASMClient's getKey returns
229
+ }
230
+ ```
@@ -0,0 +1,58 @@
1
+ # @classcad/client
2
+
3
+ Connects an app to ClassCAD, the CAD engine, and runs the ClassCAD API on its drawings: the package every sdkjs
4
+ app starts with. The engine runs in the browser as WebAssembly, or natively behind a server; a session can be
5
+ shared with other apps and with AI agents.
6
+
7
+ ## What it exposes
8
+
9
+ - [init](clients.md#init): sets the SDK up with a factory that makes the client of each drawing.
10
+ - [WASMClient](clients.md#wasmclient): runs the engine in the browser, with a public access token (`ccpk_…`).
11
+ - [WSClient](clients.md#wsclient): connects to a native engine's own WebSocket server (`classcad-cli worker`).
12
+ - [SocketIOClient](clients.md#socketioclient): connects to the ClassCAD server (`classcad-socketio`).
13
+ - [onClient](clients.md#onclient): prepares each client a host makes, before it connects.
14
+ - [BuerliCadFacade](modeling.md#buerlicadfacade): connects a drawing, holds its ClassCAD API (`api.v1.*`) and makes three.js geometry of
15
+ the model.
16
+ - [resolveEngineKey](engine-keys.md#resolveenginekey): an engine key from an access token, for engines an app starts itself.
17
+ - [classcadEngine](clients.md#classcadengine): the ClassCAD engine this package is built against, and where its bundle is.
18
+ - Session sharing: [createInvite](clients.md#createinvite-1) on a client, [buildShareUrl](session-sharing.md#buildshareurl) and
19
+ [getShareTokenFromUrl](session-sharing.md#getsharetokenfromurl), [getSessionShareState](session-sharing.md#getsessionsharestate), [syncSelection](session-sharing.md#syncselection), and the participants'
20
+ [ClientIdentity](session-sharing.md#clientidentity).
21
+
22
+ ## Example
23
+
24
+ ```ts
25
+ import * as THREE from 'three'
26
+ import { init, BuerliCadFacade, WASMClient } from '@classcad/client'
27
+
28
+ // The engine in the browser; a public access token from classcad.ch/account
29
+ init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
30
+
31
+ const facade = new BuerliCadFacade()
32
+ await facade.connect()
33
+ const part = (await facade.api.v1.part.create({ name: 'Part' }))!
34
+ await facade.api.v1.part.box({ id: part, length: 100, width: 60, height: 20 })
35
+ await facade.api.v1.part.cylinder({ id: part, diameter: 30, height: 50 })
36
+
37
+ // The model as three.js geometry
38
+ const geometries = await facade.createBufferGeometry(part)
39
+ const meshes = geometries?.map(geometry => new THREE.Mesh(geometry, new THREE.MeshStandardMaterial()))
40
+ ```
41
+
42
+ ## API
43
+
44
+ | Name | Description |
45
+ | :------ | :------ |
46
+ | [Clients](clients.md) | Start here: `init` takes a factory that makes the client of each drawing, which connects it to ClassCAD: the engine in the page (`WASMClient`), a native engine (`WSClient`) or the ClassCAD server (`SocketIOClient`). |
47
+ | [Modeling](modeling.md) | `BuerliCadFacade` connects a drawing, runs the ClassCAD API on it (`api.v1.*`) and turns the model into three.js geometry. |
48
+ | [Engine Keys](engine-keys.md) | The key an engine starts with. A public access token on the `WASMClient` is all most apps need; the rest is for apps with a sign-in of their own, and for servers. |
49
+ | [Session Sharing](session-sharing.md) | Shares a drawing's session with other apps and AI agents: invites and share links, who is in the session, what they publish, and what they have selected. |
50
+ | [Other](other.md) | - |
51
+
52
+ ## Advanced
53
+
54
+ Most apps do not need these directly: types they meet through the exports above, and what is there for special cases or for building on the SDK itself.
55
+
56
+ | Name | Description |
57
+ | :------ | :------ |
58
+ | [Connection](advanced/connection.md) | The protocol between a client and its engine: requests, replies, and what the engine sends back after a command (`EmissionConfig`). For apps that talk to the engine directly. |