@joai/sdk 8.0.0 → 9.0.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/README.md +115 -0
- package/dist/index.mjs +6 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# @joai/sdk
|
|
2
|
+
|
|
3
|
+
The React entry point contains reusable building blocks for editable content on client websites. The components stay domain-neutral: sites provide identifiers, copy, styling hooks, and rendered fields; the SDK owns session handoff and the editing lifecycle.
|
|
4
|
+
|
|
5
|
+
## Managed content editor
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { ManagedContentEditor } from '@joai/react'
|
|
9
|
+
|
|
10
|
+
<ManagedContentEditor
|
|
11
|
+
config={{
|
|
12
|
+
contentId: 'content-id',
|
|
13
|
+
publicSlug: 'website-content',
|
|
14
|
+
sessionStorageKey: 'website-content-session',
|
|
15
|
+
team: 'team-slug',
|
|
16
|
+
}}
|
|
17
|
+
initialContent={content}
|
|
18
|
+
title="Inhalte bearbeiten"
|
|
19
|
+
labels={{
|
|
20
|
+
edit: 'Bearbeiten',
|
|
21
|
+
save: 'Entwurf speichern',
|
|
22
|
+
saving: 'Wird gespeichert …',
|
|
23
|
+
publish: 'Veröffentlichen',
|
|
24
|
+
publishing: 'Wird veröffentlicht …',
|
|
25
|
+
cancel: 'Abbrechen',
|
|
26
|
+
toolbar: 'Inhaltseditor',
|
|
27
|
+
unsaved: 'Nicht gespeicherte Änderungen',
|
|
28
|
+
}}
|
|
29
|
+
messages={{
|
|
30
|
+
conflict: 'Der Inhalt wurde zwischenzeitlich geändert. Deine Eingaben bleiben erhalten. Bitte prüfe sie und versuche es erneut.',
|
|
31
|
+
loadError: 'Der Inhalt konnte nicht geladen werden.',
|
|
32
|
+
publishError: 'Die Änderungen konnten nicht veröffentlicht werden.',
|
|
33
|
+
published: 'Die Änderungen wurden veröffentlicht.',
|
|
34
|
+
saveError: 'Der Entwurf konnte nicht gespeichert werden.',
|
|
35
|
+
saved: 'Der Entwurf wurde gespeichert.',
|
|
36
|
+
sessionExpired: 'Deine Sitzung ist abgelaufen.',
|
|
37
|
+
unsavedNavigation: 'Du hast nicht gespeicherte Änderungen. Seite wirklich verlassen?',
|
|
38
|
+
}}
|
|
39
|
+
imagePickerLabels={{
|
|
40
|
+
applyCrop: 'Zuschnitt übernehmen',
|
|
41
|
+
back: 'Zurück',
|
|
42
|
+
choose: 'Bild auswählen',
|
|
43
|
+
close: 'Schließen',
|
|
44
|
+
cropDescription: 'Passe Bildausschnitt und Zoom vor dem Hochladen an.',
|
|
45
|
+
cropTitle: 'Bild zuschneiden',
|
|
46
|
+
dimensionsTooLarge: 'Die Bildabmessungen sind zu groß.',
|
|
47
|
+
dimensionsTooSmall: 'Die Bildabmessungen sind zu klein.',
|
|
48
|
+
drop: 'Bild hier ablegen',
|
|
49
|
+
empty: 'Noch keine Bilder vorhanden.',
|
|
50
|
+
field: 'Bearbeitbares Bild',
|
|
51
|
+
invalidType: 'Bitte wähle eine Bilddatei.',
|
|
52
|
+
libraryDescription: 'Wähle ein vorhandenes Bild oder lade ein neues hoch.',
|
|
53
|
+
libraryTitle: 'Bildmediathek',
|
|
54
|
+
loadError: 'Bilder konnten nicht geladen werden.',
|
|
55
|
+
loading: 'Bilder werden geladen …',
|
|
56
|
+
positionHorizontal: 'Horizontale Position',
|
|
57
|
+
positionVertical: 'Vertikale Position',
|
|
58
|
+
processing: 'Bild wird vorbereitet …',
|
|
59
|
+
retry: 'Erneut versuchen',
|
|
60
|
+
tooLarge: 'Das Bild ist zu groß.',
|
|
61
|
+
upload: 'Bild hochladen',
|
|
62
|
+
uploadError: 'Das Bild konnte nicht hochgeladen werden.',
|
|
63
|
+
uploading: 'Wird hochgeladen …',
|
|
64
|
+
zoom: 'Zoom',
|
|
65
|
+
}}
|
|
66
|
+
reauthenticateLabel="Anmeldung erneuern"
|
|
67
|
+
sessionExpiredMessage="Deine Sitzung ist abgelaufen. Deine lokalen Änderungen bleiben erhalten."
|
|
68
|
+
confirmCancel={() => window.confirm('Nicht gespeicherte Änderungen verwerfen?')}
|
|
69
|
+
confirmLeave={() => window.confirm('Du hast nicht gespeicherte Änderungen. Seite wirklich verlassen?')}
|
|
70
|
+
confirmPublish={() => window.confirm('Änderungen jetzt veröffentlichen?')}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</ManagedContentEditor>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Use `EditableContent`, `EditableImage`, and `useContentValue` from `@joai/react` inside the editor. Pass server-fetched public content as `initialContent` to avoid a client-side loading state for visitors.
|
|
77
|
+
|
|
78
|
+
Configure each image field as a reusable, domain-neutral building block. Images are compressed to WebP at up to 2560 × 2560 pixels by default, while animated GIF and SVG files retain their original format. Cropping is opt-in per field:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
<EditableImage
|
|
82
|
+
field="heroImage"
|
|
83
|
+
label="Titelbild"
|
|
84
|
+
maxSourceBytes={40 * 1024 * 1024}
|
|
85
|
+
maxUploadBytes={5 * 1024 * 1024}
|
|
86
|
+
processing={{
|
|
87
|
+
crop: { aspectRatio: 16 / 9, outputWidth: 1920 },
|
|
88
|
+
compression: { maxWidth: 1920, maxHeight: 1080, mimeType: 'image/webp', quality: 0.84 },
|
|
89
|
+
dimensions: { minWidth: 1280, minHeight: 720, maxPixels: 50_000_000 },
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Set `compression: false` or `dimensions: false` to disable only that stage, or `processing={false}` to upload the original image without client-side decoding, validation, cropping, or compression.
|
|
95
|
+
|
|
96
|
+
## Session storage
|
|
97
|
+
|
|
98
|
+
`useContentSession` and `createSessionTokenStore` are exported for custom shells. A custom `SessionTokenStore` can be injected when a host needs a different persistence mechanism. The URL fragment containing the one-time handoff token is removed before it is exchanged and persisted.
|
|
99
|
+
|
|
100
|
+
The managed editor automatically adds `platform=app` to its reauthentication return URL so JoAi returns a one-time handoff token. Override `reauthenticateUrl` only when a host has a dedicated login callback.
|
|
101
|
+
|
|
102
|
+
`createContentDraftStore` uses `sessionStorage` by default. `ManagedContentEditor` wires it automatically so unsaved values survive refreshes and expired-session reauthentication without being shared across browser sessions.
|
|
103
|
+
|
|
104
|
+
## Editing behavior
|
|
105
|
+
|
|
106
|
+
- Cancel restores the currently loaded version.
|
|
107
|
+
- Save is disabled when there are no local changes.
|
|
108
|
+
- A dirty publish saves and publishes with one request.
|
|
109
|
+
- Network failures keep local edits available for retry.
|
|
110
|
+
- Refresh, close, and link/navigation attempts warn while edits are unsaved.
|
|
111
|
+
- Editable text and image fields are visibly labelled in edit mode.
|
|
112
|
+
- The image library supports loading, empty, error, byte/dimension validation, cropping, compression, keyboard, focus, and drag-and-drop states.
|
|
113
|
+
- Expired authorization offers a sign-in action and restores locally persisted edits afterwards.
|
|
114
|
+
- Version conflicts load the latest version while preserving local edits.
|
|
115
|
+
- Public content cache entries are invalidated after authenticated mutations.
|
package/dist/index.mjs
CHANGED
|
@@ -3340,7 +3340,7 @@ var MemoryCache = class {
|
|
|
3340
3340
|
this.store.clear();
|
|
3341
3341
|
}
|
|
3342
3342
|
bust(prefix) {
|
|
3343
|
-
for (const key of this.store.keys()) if (key.startsWith(prefix)) this.store.delete(key);
|
|
3343
|
+
for (const key of this.store.keys()) if (key.startsWith(prefix) || key.startsWith(`/${prefix}`)) this.store.delete(key);
|
|
3344
3344
|
}
|
|
3345
3345
|
};
|
|
3346
3346
|
//#endregion
|
|
@@ -3364,6 +3364,10 @@ const DEFAULTS = {
|
|
|
3364
3364
|
agents: 1e4,
|
|
3365
3365
|
rooms: 1e4
|
|
3366
3366
|
};
|
|
3367
|
+
const RELATED_PREFIXES = {
|
|
3368
|
+
content: ["contents"],
|
|
3369
|
+
contents: ["content"]
|
|
3370
|
+
};
|
|
3367
3371
|
function getTtl(url, ttlMap, defaultTtl) {
|
|
3368
3372
|
for (const [prefix, ttl] of Object.entries(ttlMap)) if (url.startsWith(prefix) || url.startsWith(`/${prefix}`)) return ttl;
|
|
3369
3373
|
return defaultTtl;
|
|
@@ -3451,6 +3455,7 @@ var CachedHttpService = class {
|
|
|
3451
3455
|
bust(prefix) {
|
|
3452
3456
|
this.cacheVersion++;
|
|
3453
3457
|
this.cache.bust(prefix);
|
|
3458
|
+
for (const relatedPrefix of RELATED_PREFIXES[prefix] ?? []) this.cache.bust(relatedPrefix);
|
|
3454
3459
|
}
|
|
3455
3460
|
};
|
|
3456
3461
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joai/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "JoAi public API SDK — build with your AI agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"test": "jest --config jest.config.js"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@joai/core": "^
|
|
38
|
+
"@joai/core": "^5.0.0",
|
|
39
39
|
"@joai/warps": "*"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@joai/core": "^
|
|
42
|
+
"@joai/core": "^5.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsdown": "^0.21.0",
|