@foir/sdk 0.7.0 → 0.9.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +857 -4
  2. package/README.md +46 -15
  3. package/dist/auth/auth.d.ts +104 -1
  4. package/dist/auth/hosted.d.ts +22 -0
  5. package/dist/auth/index.d.ts +13 -7
  6. package/dist/auth/operations.d.ts +85 -64
  7. package/dist/auth/ops.d.ts +99 -0
  8. package/dist/auth.js +786 -106
  9. package/dist/chunk-IGNLWT3H.js +35 -0
  10. package/dist/chunk-OHYVKTGB.js +45 -0
  11. package/dist/chunk-TAL5H6VA.js +39 -0
  12. package/dist/client.js +25 -31
  13. package/dist/codegen/block-registry.d.ts +13 -19
  14. package/dist/codegen/block-registry.js +3 -31
  15. package/dist/codegen/block-scaffold.d.ts +12 -21
  16. package/dist/codegen/block-scaffold.js +3 -41
  17. package/dist/codegen/index.d.ts +9 -4
  18. package/dist/codegen/index.js +7 -11
  19. package/dist/codegen/item-registry.d.ts +28 -0
  20. package/dist/codegen/item-registry.js +7 -0
  21. package/dist/codegen/item-scaffold.d.ts +29 -0
  22. package/dist/codegen/item-scaffold.js +7 -0
  23. package/dist/codegen/preset.d.ts +14 -7
  24. package/dist/codegen/shared.d.ts +20 -9
  25. package/dist/content/content-renderer.d.ts +90 -24
  26. package/dist/content/index.d.ts +13 -7
  27. package/dist/content/richtext.d.ts +66 -18
  28. package/dist/content.js +227 -80
  29. package/dist/data/builtins.d.ts +369 -92
  30. package/dist/data/client.d.ts +97 -25
  31. package/dist/data/document.d.ts +251 -0
  32. package/dist/data/index.d.ts +38 -19
  33. package/dist/data/manifest.d.ts +290 -8
  34. package/dist/data/schema.d.ts +78 -8
  35. package/dist/data/selection.d.ts +231 -37
  36. package/dist/data/subjects.d.ts +221 -0
  37. package/dist/data/subscription-document.d.ts +75 -0
  38. package/dist/data/subscriptions.d.ts +181 -0
  39. package/dist/data/transport.d.ts +255 -37
  40. package/dist/data/ws-transport.d.ts +197 -0
  41. package/dist/data.js +1419 -45
  42. package/dist/graphql/cdn-route.d.ts +12 -28
  43. package/dist/media/index.d.ts +6 -2
  44. package/dist/media/media.d.ts +2 -2
  45. package/dist/media/screen-capture.d.ts +81 -0
  46. package/dist/media.js +97 -0
  47. package/dist/next.js +663 -182
  48. package/dist/push.js +700 -90
  49. package/dist/react/FoirFeedback.d.ts +62 -0
  50. package/dist/react/feedback-notes.d.ts +101 -0
  51. package/dist/react/index.d.ts +7 -1
  52. package/dist/react.js +1272 -194
  53. package/dist/realtime.js +1 -1
  54. package/dist/server/events-client.d.ts +279 -0
  55. package/dist/server/index.d.ts +4 -0
  56. package/dist/server.js +298 -0
  57. package/dist/transport/foir-http.d.ts +23 -6
  58. package/dist/transport/persisted-query.d.ts +68 -0
  59. package/dist/transport/retry.d.ts +1 -1
  60. package/package.json +13 -1
  61. package/dist/chunk-ADO5FJNM.js +0 -30
@@ -1,47 +1,113 @@
1
1
  /**
2
2
  * createContentRenderer — the generic content-dispatch primitive.
3
3
  *
4
- * It does NOT know any concrete block types. Given a registry that maps each
5
- * block `__typename` to a component, it renders a `flexible` field's block
6
- * array: looks each block up by `__typename`, renders unknown types as null,
7
- * keys by the block `_id`, assigns LCP `priority` to the first block that
8
- * actually renders, and threads a consumer-defined `Ctx` to every component.
4
+ * It does NOT know any concrete item types. Given a registry that maps each
5
+ * entry `__typename` to a component, it renders a prose flow's entries (or a
6
+ * plain item array): looks each entry up by `__typename`, renders unknown
7
+ * types as null, keys by the entry `_key`/`_id` where one is present, assigns
8
+ * LCP `priority` to the first entry that actually renders, and threads a
9
+ * consumer-defined `Ctx` to every component.
10
+ *
11
+ * Passage entries — the flow's text — are not registry-dispatched: a run of
12
+ * consecutive passages renders as ONE unit through `options.passageRun` (or
13
+ * the SDK's `PassageList` with provider tokens when none is supplied), so
14
+ * prose reads as a single body with shared list structure.
9
15
  *
10
16
  * The "switch" is a typed object lookup. Exhaustiveness is enforced where the
11
- * registry is BUILT — against the exhaustive `BlockRegistry` type the codegen
12
- * plugin (EID-92) generates per project, so omitting a block type is a compile
17
+ * registry is BUILT — against the exhaustive `ItemRegistry` type the codegen
18
+ * plugin (EID-92) generates per project, so omitting an item type is a compile
13
19
  * error there, not a runtime surprise here. The consumer can supply different
14
20
  * registries per surface (e.g. web vs email).
21
+ *
22
+ * # On the word
23
+ *
24
+ * A prose field holds ENTRIES. A modeller may name the field `blocks`,
25
+ * `sections`, `modules` or anything else, and this renderer must not care:
26
+ * dispatch is on `__typename` and never on a field name. The `Block*` spellings
27
+ * below are deprecated aliases kept so existing consumers compile — see
28
+ * TTS-1391.
15
29
  */
16
30
  import { type ReactNode } from 'react';
17
- /** Minimal shape every block in a `flexible` field carries. */
18
- export interface BlockLike {
31
+ import { type PassageLike } from './richtext';
32
+ /** Minimal shape every entry in a prose flow carries. */
33
+ export interface ItemLike {
19
34
  __typename: string;
20
35
  _id?: string | null;
36
+ _key?: string | null;
21
37
  }
22
- /** Props a block component receives from the content renderer. */
23
- export interface BlockComponentProps<TBlock, TCtx = unknown> {
24
- block: TBlock;
38
+ /** Props an item component receives from the content renderer. */
39
+ export interface ItemComponentProps<TItem, TCtx = unknown> {
40
+ item: TItem;
41
+ /**
42
+ * The same value as `item`.
43
+ *
44
+ * @deprecated Use `item`. Kept so components scaffolded before TTS-1391
45
+ * keep compiling; it is passed on every render and will be removed in a
46
+ * future major.
47
+ */
48
+ block: TItem;
25
49
  /** Consumer-defined render context (host product, locale, etc.). */
26
50
  ctx: TCtx;
27
- /** True only for the first block that renders — the LCP candidate. */
51
+ /** True only for the first item that renders — the LCP candidate. */
28
52
  priority: boolean;
29
53
  }
30
- /** A component that renders one block type. */
31
- export type BlockComponent<TBlock, TCtx = unknown> = (props: BlockComponentProps<TBlock, TCtx>) => ReactNode;
54
+ /** A component that renders one item type. */
55
+ export type ItemComponent<TItem, TCtx = unknown> = (props: ItemComponentProps<TItem, TCtx>) => ReactNode;
32
56
  /**
33
- * A registry mapping `__typename` → block component. In practice this is the
34
- * exhaustive `BlockRegistry` type the codegen plugin emits for the project;
57
+ * A registry mapping `__typename` → item component. In practice this is the
58
+ * exhaustive `ItemRegistry` type the codegen plugin emits for the project;
35
59
  * here it's the structural lower bound the renderer needs.
36
60
  */
37
- export type BlockRegistry<TCtx = unknown> = Record<string, BlockComponent<any, TCtx>>;
38
- export interface ContentRendererProps<TCtx> {
39
- blocks: readonly BlockLike[] | null | undefined;
40
- /** Consumer-defined context passed to every block component. */
61
+ export type ItemRegistry<TCtx = unknown> = Record<string, ItemComponent<any, TCtx>>;
62
+ /** A prose flow's projection wrapper: the field value carrying `entries`. */
63
+ export interface EntriesLike {
64
+ entries?: readonly (ItemLike | null | undefined)[] | null;
65
+ }
66
+ /**
67
+ * The prose field's entries — the projection wrapper (`{ entries }`), or a
68
+ * plain array — plus the context threaded to every component.
69
+ *
70
+ * `items` is canonical. `blocks` is the pre-TTS-1391 spelling and still
71
+ * accepted; passing both is a type error rather than a silent precedence rule,
72
+ * because a caller who set both cannot be told which one this honoured.
73
+ */
74
+ export type ContentRendererProps<TCtx> = {
75
+ /** Consumer-defined context passed to every item component. */
76
+ ctx: TCtx;
77
+ } & ({
78
+ items: readonly (ItemLike | null | undefined)[] | EntriesLike | null | undefined;
79
+ blocks?: never;
80
+ } | {
81
+ /** @deprecated Use `items`. */
82
+ blocks: readonly (ItemLike | null | undefined)[] | EntriesLike | null | undefined;
83
+ items?: never;
84
+ });
85
+ /** Props the passage-run component receives. */
86
+ export interface PassageRunProps<TCtx = unknown> {
87
+ /** The consecutive passage entries of this run, in document order. */
88
+ passages: PassageLike[];
89
+ /** Consumer-defined render context. */
41
90
  ctx: TCtx;
91
+ /** True only when the run is the flow's first rendered unit. */
92
+ priority: boolean;
93
+ }
94
+ export interface ContentRendererOptions<TCtx = unknown> {
95
+ /**
96
+ * Renders a run of consecutive passage entries. Defaults to the SDK's
97
+ * `PassageList` (typography tokens via `RichTextTypographyProvider`).
98
+ */
99
+ passageRun?: (props: PassageRunProps<TCtx>) => ReactNode;
42
100
  }
43
101
  /**
44
- * Build a `<ContentRenderer>` bound to a block registry. Returns a component
45
- * that takes the `flexible` field's `blocks` array plus a `ctx`.
102
+ * Build a `<ContentRenderer>` bound to an item registry. Returns a component
103
+ * that takes the prose field's value (or a plain entry array) plus a `ctx`.
46
104
  */
47
- export declare function createContentRenderer<TCtx = unknown>(registry: BlockRegistry<TCtx>): (props: ContentRendererProps<TCtx>) => ReactNode;
105
+ export declare function createContentRenderer<TCtx = unknown>(registry: ItemRegistry<TCtx>, options?: ContentRendererOptions<TCtx>): (props: ContentRendererProps<TCtx>) => ReactNode;
106
+ /** @deprecated Renamed to {@link ItemLike}. */
107
+ export type BlockLike = ItemLike;
108
+ /** @deprecated Renamed to {@link ItemComponentProps}. */
109
+ export type BlockComponentProps<TBlock, TCtx = unknown> = ItemComponentProps<TBlock, TCtx>;
110
+ /** @deprecated Renamed to {@link ItemComponent}. */
111
+ export type BlockComponent<TBlock, TCtx = unknown> = ItemComponent<TBlock, TCtx>;
112
+ /** @deprecated Renamed to {@link ItemRegistry}. */
113
+ export type BlockRegistry<TCtx = unknown> = ItemRegistry<TCtx>;
@@ -1,12 +1,18 @@
1
1
  /**
2
2
  * `@foir/sdk/content` — generic content-rendering primitives.
3
3
  *
4
- * Ships ONLY the framework-agnostic primitives: the block-dispatch renderer
5
- * and a Lexical richtext renderer with injected typography tokens. Concrete
6
- * block components, host/Shopify context, and layout systems stay app-side.
7
- * `react` is a peer dependency.
4
+ * Ships ONLY the framework-agnostic primitives: the entry-dispatch renderer
5
+ * and a prose renderer (passages with spans, marks and markDefs) with
6
+ * injected typography tokens. Concrete item components, host/Shopify
7
+ * context, and layout systems stay app-side. `react` is a peer dependency.
8
8
  */
9
9
  export { createContentRenderer } from './content-renderer';
10
- export type { BlockLike, BlockComponent, BlockComponentProps, BlockRegistry, ContentRendererProps, } from './content-renderer';
11
- export { RichTextRenderer, RichTextTypographyProvider, useRichTextTypography, } from './richtext';
12
- export type { RichTextRendererProps, TypographyToken, } from './richtext';
10
+ export type { ItemLike, EntriesLike, ItemComponent, ItemComponentProps, ItemRegistry, ContentRendererProps, ContentRendererOptions, PassageRunProps, } from './content-renderer';
11
+ /**
12
+ * Pre-TTS-1391 spellings. `Block` was one project's name for a flexible field,
13
+ * never a platform concept; these are kept so existing consumers compile and
14
+ * will be removed in a future major.
15
+ */
16
+ export type { BlockLike, BlockComponent, BlockComponentProps, BlockRegistry, } from './content-renderer';
17
+ export { RichTextRenderer, RichTextTypographyProvider, useRichTextTypography, PassageList, passagesOf, isPassageEntry, safeHref, } from './richtext';
18
+ export type { RichTextRendererProps, PassageListProps, TypographyToken, ProseValueLike, PassageLike, ProseSpanLike, } from './richtext';
@@ -1,23 +1,30 @@
1
1
  /**
2
- * RichTextRenderer — render a Foir richtext field (a Lexical EditorState) with
3
- * per-paragraph typography tokens applied as inline styles.
2
+ * RichTextRenderer — render a Foir prose value (a flow of passages) with
3
+ * per-passage typography tokens applied as inline styles.
4
4
  *
5
5
  * The design-token dependency is INJECTED, not imported from an app: pass the
6
6
  * resolved `typography` token array as a prop, or provide it once via
7
7
  * `<RichTextTypographyProvider>`. With no tokens the structure still renders
8
- * (fallback tag, no inline typography), and a doc-less value falls back to its
9
- * `html` projection. No `@foir`-app imports.
8
+ * (fallback tag, no inline typography), and a value without a typed `entries`
9
+ * projection falls back to its stored flow (`json`) and then its `html`
10
+ * projection. No `@foir`-app imports.
10
11
  *
11
- * Token semantics:
12
- * - `token.tag` (paragraph / h1–h6 / blockquote) controls the rendered HTML
13
- * element and wins over the Lexical heading `tag` when both are present.
14
- * - Paragraph `format` ('left'|'center'|'right'|'justify') → text-align.
15
- * - Text-node `format` bits → inline emphasis: bold(1) italic(2)
16
- * strikethrough(4) underline(8) code(16).
12
+ * Passage semantics:
13
+ * - `kind` (paragraph / h1–h6 / quote / code) picks the HTML element.
14
+ * - `token` names a typography token; its resolved CSS is inlined and the
15
+ * token's `tag` wins over the kind's element when both are present.
16
+ * - `align` maps to text-align on the rendered element.
17
+ * - `list` + `level` flatten list membership onto the passage; consecutive
18
+ * list passages regroup into <ul>/<ol> with nesting rebuilt from `level`.
19
+ * - Span marks are the eight decorations (bold, italic, underline,
20
+ * strikethrough, code, subscript, superscript, highlight) or the `_key`
21
+ * of a markDef on the same passage (links, scheme-checked through
22
+ * `safeHref`).
23
+ * - A soft line break is `"\n"` inside a span's text.
17
24
  */
18
25
  import { type ReactNode, type JSX } from 'react';
19
26
  /**
20
- * safeHref allow-lists link schemes so stored richtext can't smuggle a
27
+ * safeHref allow-lists link schemes so stored prose can't smuggle a
21
28
  * `javascript:` (or `data:`/`vbscript:`) URL that executes on click (EID-207).
22
29
  * Relative URLs, anchors, and the http(s)/mailto/tel schemes pass; anything
23
30
  * else collapses to '#'. Editors are not fully trusted, so this runs on the
@@ -26,7 +33,7 @@ import { type ReactNode, type JSX } from 'react';
26
33
  export declare function safeHref(url: string | undefined): string;
27
34
  /** A resolved typography token from the project's design tokens. */
28
35
  export interface TypographyToken {
29
- /** Token key referenced by a Lexical node's `style`. */
36
+ /** Token key referenced by a passage's `token`. */
30
37
  name: string;
31
38
  /** Rendered HTML element (paragraph / h1–h6 / blockquote). */
32
39
  tag?: string;
@@ -41,8 +48,8 @@ export interface TypographyToken {
41
48
  }
42
49
  /**
43
50
  * Provide the project's resolved typography tokens to every nested
44
- * `<RichTextRenderer>` so callers don't thread them through each usage. A
45
- * `tokens` prop on the renderer still takes precedence.
51
+ * `<RichTextRenderer>` / `<PassageList>` so callers don't thread them through
52
+ * each usage. A `tokens` prop on the renderer still takes precedence.
46
53
  */
47
54
  export declare function RichTextTypographyProvider({ tokens, children, }: {
48
55
  tokens: TypographyToken[];
@@ -50,12 +57,40 @@ export declare function RichTextTypographyProvider({ tokens, children, }: {
50
57
  }): import("react/jsx-runtime").JSX.Element;
51
58
  /** Read the injected typography tokens (null when no provider is mounted). */
52
59
  export declare function useRichTextTypography(): TypographyToken[] | null;
53
- interface RichtextValueLike {
60
+ export interface ProseSpanLike {
61
+ text?: string | null;
62
+ marks?: ReadonlyArray<string | null> | null;
63
+ }
64
+ export interface PassageLike {
65
+ __typename?: string;
66
+ _type?: string;
67
+ _key?: string | null;
68
+ kind?: string | null;
69
+ token?: string | null;
70
+ align?: string | null;
71
+ list?: string | null;
72
+ level?: number | null;
73
+ language?: string | null;
74
+ markDefs?: unknown;
75
+ spans?: ReadonlyArray<ProseSpanLike | null> | null;
76
+ }
77
+ export interface ProseValueLike {
54
78
  html?: string | null;
55
79
  json?: unknown;
80
+ entries?: ReadonlyArray<PassageLike | null> | null;
56
81
  }
82
+ /** True for a passage entry from either the typed projection
83
+ * (`__typename: "Passage"`) or the stored flow (`_type: "passage"`). */
84
+ export declare function isPassageEntry(entry: unknown): entry is PassageLike;
85
+ /**
86
+ * Extract the renderable passages from a prose value. Prefers the typed
87
+ * `entries` projection; falls back to walking the stored flow (`json`).
88
+ * Embed entries are skipped — a prose *value* position renders text; embeds
89
+ * in list positions render through the consumer's content renderer instead.
90
+ */
91
+ export declare function passagesOf(value: ProseValueLike | null | undefined): PassageLike[];
57
92
  export interface RichTextRendererProps {
58
- value: RichtextValueLike | null | undefined;
93
+ value: ProseValueLike | null | undefined;
59
94
  className?: string;
60
95
  /**
61
96
  * Resolved typography tokens. Overrides any provided via
@@ -63,8 +98,21 @@ export interface RichTextRendererProps {
63
98
  * with `fallbackTag` and no inline typography.
64
99
  */
65
100
  tokens?: TypographyToken[];
66
- /** Tag used for any paragraph with no token style and no Lexical tag. */
101
+ /** Tag used for a paragraph passage with no token tag. */
67
102
  fallbackTag?: keyof JSX.IntrinsicElements;
68
103
  }
69
104
  export declare function RichTextRenderer({ value, className, tokens, fallbackTag, }: RichTextRendererProps): import("react/jsx-runtime").JSX.Element | null;
70
- export {};
105
+ export interface PassageListProps {
106
+ passages: ReadonlyArray<PassageLike>;
107
+ /** Resolved typography tokens; falls back to the provider's. */
108
+ tokens?: TypographyToken[];
109
+ /** Tag used for a paragraph passage with no token tag. */
110
+ fallbackTag?: keyof JSX.IntrinsicElements;
111
+ }
112
+ /**
113
+ * Render a run of passages: consecutive list passages regroup into (nested)
114
+ * <ul>/<ol>, everything else renders as its own element. Used by
115
+ * `RichTextRenderer` for prose field values and by `createContentRenderer`
116
+ * for passage runs inside a flow's entries.
117
+ */
118
+ export declare function PassageList({ passages, tokens, fallbackTag, }: PassageListProps): import("react/jsx-runtime").JSX.Element;