@foir/sdk 0.7.0 → 0.8.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/CHANGELOG.md +805 -4
- package/README.md +46 -15
- package/dist/auth/auth.d.ts +104 -1
- package/dist/auth/index.d.ts +12 -6
- package/dist/auth/operations.d.ts +85 -64
- package/dist/auth/ops.d.ts +99 -0
- package/dist/auth.js +775 -106
- package/dist/chunk-IGNLWT3H.js +35 -0
- package/dist/chunk-OHYVKTGB.js +45 -0
- package/dist/chunk-TAL5H6VA.js +39 -0
- package/dist/client.js +25 -31
- package/dist/codegen/block-registry.d.ts +13 -19
- package/dist/codegen/block-registry.js +3 -31
- package/dist/codegen/block-scaffold.d.ts +12 -21
- package/dist/codegen/block-scaffold.js +3 -41
- package/dist/codegen/index.d.ts +9 -4
- package/dist/codegen/index.js +7 -11
- package/dist/codegen/item-registry.d.ts +28 -0
- package/dist/codegen/item-registry.js +7 -0
- package/dist/codegen/item-scaffold.d.ts +29 -0
- package/dist/codegen/item-scaffold.js +7 -0
- package/dist/codegen/preset.d.ts +14 -7
- package/dist/codegen/shared.d.ts +20 -9
- package/dist/content/content-renderer.d.ts +90 -24
- package/dist/content/index.d.ts +13 -7
- package/dist/content/richtext.d.ts +66 -18
- package/dist/content.js +227 -80
- package/dist/data/builtins.d.ts +302 -92
- package/dist/data/client.d.ts +97 -25
- package/dist/data/document.d.ts +251 -0
- package/dist/data/index.d.ts +38 -19
- package/dist/data/manifest.d.ts +266 -3
- package/dist/data/schema.d.ts +78 -8
- package/dist/data/selection.d.ts +231 -37
- package/dist/data/subjects.d.ts +221 -0
- package/dist/data/subscription-document.d.ts +75 -0
- package/dist/data/subscriptions.d.ts +181 -0
- package/dist/data/transport.d.ts +255 -37
- package/dist/data/ws-transport.d.ts +197 -0
- package/dist/data.js +1419 -45
- package/dist/graphql/cdn-route.d.ts +12 -28
- package/dist/media/index.d.ts +6 -2
- package/dist/media/media.d.ts +2 -2
- package/dist/media/screen-capture.d.ts +81 -0
- package/dist/media.js +97 -0
- package/dist/next.js +663 -182
- package/dist/push.js +700 -90
- package/dist/react/FoirFeedback.d.ts +62 -0
- package/dist/react/feedback-notes.d.ts +101 -0
- package/dist/react/index.d.ts +7 -1
- package/dist/react.js +1272 -194
- package/dist/realtime.js +1 -1
- package/dist/server/events-client.d.ts +279 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server.js +298 -0
- package/dist/transport/foir-http.d.ts +23 -6
- package/dist/transport/persisted-query.d.ts +68 -0
- package/dist/transport/retry.d.ts +1 -1
- package/package.json +13 -1
- package/dist/chunk-ADO5FJNM.js +0 -30
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { FoirCustomerNote, FoirSubject, FoirSubjectRegistry } from '../data';
|
|
2
|
+
import { type FoirFeedbackClient } from './feedback-notes';
|
|
3
|
+
export type { FoirFeedbackClient } from './feedback-notes';
|
|
4
|
+
export interface FoirFeedbackProps {
|
|
5
|
+
/**
|
|
6
|
+
* The data client the page reads through — the one you passed the subject
|
|
7
|
+
* registry to. Its `notes` namespace is what a submission goes to, and its
|
|
8
|
+
* `files` namespace is what a screenshot is uploaded through.
|
|
9
|
+
*/
|
|
10
|
+
client: FoirFeedbackClient;
|
|
11
|
+
/**
|
|
12
|
+
* The registry from `createFoirSubjectRegistry()`, the same object you passed
|
|
13
|
+
* to `createFoirClient({ subjects })`.
|
|
14
|
+
*
|
|
15
|
+
* Passed rather than discovered, because the registry is deliberately an
|
|
16
|
+
* object the host owns and not a flag the client turns on — see the registry's
|
|
17
|
+
* own header for why a list of what a page fetched is not the SDK's to hand
|
|
18
|
+
* out. Omit it and the widget has no subject unless you pass one.
|
|
19
|
+
*/
|
|
20
|
+
subjects?: FoirSubjectRegistry;
|
|
21
|
+
/**
|
|
22
|
+
* Pin what the feedback is about, overriding the registry.
|
|
23
|
+
*
|
|
24
|
+
* `null` states there is nothing to comment on, which is a different claim
|
|
25
|
+
* from omitting the prop and worth being able to make: a checkout step or a
|
|
26
|
+
* dashboard renders no record and should say so rather than inherit whatever
|
|
27
|
+
* the previous page fetched.
|
|
28
|
+
*/
|
|
29
|
+
subject?: FoirSubject | null;
|
|
30
|
+
/**
|
|
31
|
+
* What to call the subject on screen, overriding the label the registry
|
|
32
|
+
* resolved. Omit both and the widget shows no name at all.
|
|
33
|
+
*/
|
|
34
|
+
label?: string;
|
|
35
|
+
/** The disclosure button's text. Default `Feedback`. */
|
|
36
|
+
triggerLabel?: string;
|
|
37
|
+
/** The panel's heading. Default `Send feedback`. */
|
|
38
|
+
title?: string;
|
|
39
|
+
/** The composer's placeholder. Default `What would you like to tell us?`. */
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
/** Start with the panel open. Default false. */
|
|
42
|
+
defaultOpen?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Called when the visitor has to sign in first. Given a handler, the widget
|
|
45
|
+
* renders a button that calls it; given none, it says so and stops.
|
|
46
|
+
*/
|
|
47
|
+
onSignIn?: () => void;
|
|
48
|
+
/** Called with the note once it is written. */
|
|
49
|
+
onSubmitted?: (note: FoirCustomerNote) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Called with anything that failed. The widget also logs it — this is for
|
|
52
|
+
* routing it into your own error reporting, not for making it visible.
|
|
53
|
+
*/
|
|
54
|
+
onError?: (error: unknown) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Style it yourself. Passing a class turns OFF the built-in inline styles
|
|
57
|
+
* entirely, so the `data-foir-feedback-*` attributes below are yours to target
|
|
58
|
+
* without fighting anything.
|
|
59
|
+
*/
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
export declare function FoirFeedback({ client, subjects, subject, label, triggerLabel, title, placeholder, defaultOpen, onSignIn, onSubmitted, onError, className, }: FoirFeedbackProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The non-visual half of `<FoirFeedback>`: reading the notes surface, uploading
|
|
3
|
+
* an attachment, and telling one refusal from another.
|
|
4
|
+
*
|
|
5
|
+
* Separate from the component because none of it is React. A namespace op
|
|
6
|
+
* answers `unknown` — the manifest publishes root field NAMES and no result
|
|
7
|
+
* shape (see `data/selection.ts`) — so every response here has to be read rather
|
|
8
|
+
* than cast, and reading is the part worth testing on its own.
|
|
9
|
+
*/
|
|
10
|
+
import type { FoirCustomerNote, FoirNoteConfig, FoirSubject } from '../data';
|
|
11
|
+
import type { FoirScreenCapture } from '../media/screen-capture';
|
|
12
|
+
/**
|
|
13
|
+
* The client the widget needs, and no more of it.
|
|
14
|
+
*
|
|
15
|
+
* Structural rather than `FoirClient<S>`, for two reasons. `FoirClient` is
|
|
16
|
+
* generic in the caller's generated schema, so naming it here would force the
|
|
17
|
+
* component's props to be generic in a parameter nothing else reads. And what
|
|
18
|
+
* the widget actually depends on is three root fields — narrowing to them means
|
|
19
|
+
* a client whose key cannot reach `files` still satisfies this type, which is
|
|
20
|
+
* the honest shape: a project with screenshots off never uploads anything.
|
|
21
|
+
*
|
|
22
|
+
* The signatures are the ones `foir types` emits for every namespace op —
|
|
23
|
+
* `Record<string, unknown>` in, `unknown` out — so a real generated client
|
|
24
|
+
* assigns to this without a cast. `react/__tests__/feedback.test-d.ts` pins that.
|
|
25
|
+
*/
|
|
26
|
+
export interface FoirFeedbackClient {
|
|
27
|
+
readonly ns: {
|
|
28
|
+
readonly notes: {
|
|
29
|
+
noteConfig(args?: Record<string, unknown>): Promise<unknown>;
|
|
30
|
+
createMyNote(args?: Record<string, unknown>): Promise<unknown>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Absent on a credential without the files scopes, which is why it is
|
|
34
|
+
* optional. Screenshot capture is the only thing that reaches it.
|
|
35
|
+
*/
|
|
36
|
+
readonly files?: {
|
|
37
|
+
createFileUpload(args?: Record<string, unknown>): Promise<unknown>;
|
|
38
|
+
confirmFileUpload(args?: Record<string, unknown>): Promise<unknown>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Why a call to the notes surface was refused, when the refusal is one the
|
|
44
|
+
* widget can name.
|
|
45
|
+
*
|
|
46
|
+
* The distinction earns its place because the three have different audiences.
|
|
47
|
+
* `signIn` is the visitor's to fix. `scope` is the OPERATOR's — a role that does
|
|
48
|
+
* not grant `notes:write` produces `missing required scope: notes:write`, which
|
|
49
|
+
* reads like a bad API key and is not one; the key is fine and the customer's
|
|
50
|
+
* role is short a capability. `other` is everything the widget will not pretend
|
|
51
|
+
* to understand.
|
|
52
|
+
*/
|
|
53
|
+
export type FoirFeedbackFault = {
|
|
54
|
+
kind: 'signIn';
|
|
55
|
+
} | {
|
|
56
|
+
kind: 'scope';
|
|
57
|
+
scope: string;
|
|
58
|
+
} | {
|
|
59
|
+
kind: 'other';
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Read the refusal, if it is one of the two the widget can act on.
|
|
63
|
+
*
|
|
64
|
+
* Matched on the platform's own sentences rather than on an error code, because
|
|
65
|
+
* these two arrive as plain GraphQL errors with no `extensions.code` to read.
|
|
66
|
+
* Both the wrapper's message and every individual GraphQL error are scanned: the
|
|
67
|
+
* transport joins them into one string on the way out, but a partial-error
|
|
68
|
+
* envelope keeps them apart, and only one of the two forms is guaranteed.
|
|
69
|
+
*/
|
|
70
|
+
export declare function classifyNotesFault(err: unknown): FoirFeedbackFault;
|
|
71
|
+
/**
|
|
72
|
+
* `noteConfig`, read.
|
|
73
|
+
*
|
|
74
|
+
* Throws on a shape it does not recognise rather than defaulting
|
|
75
|
+
* `screenshotsEnabled` to false. Defaulting would be the quiet version of a
|
|
76
|
+
* project's setting being ignored: the offer would disappear from every surface
|
|
77
|
+
* at once and the only symptom would be a missing button.
|
|
78
|
+
*/
|
|
79
|
+
export declare function readNoteConfig(client: FoirFeedbackClient): Promise<FoirNoteConfig>;
|
|
80
|
+
/** What one submission carries. */
|
|
81
|
+
export interface FoirFeedbackSubmission {
|
|
82
|
+
/**
|
|
83
|
+
* What the note is about. Always a RECORD subject: the registry only ever
|
|
84
|
+
* names records, and a host pinning one names a record too.
|
|
85
|
+
*/
|
|
86
|
+
subject: FoirSubject;
|
|
87
|
+
body: string;
|
|
88
|
+
/** The still the visitor chose to attach, or null. */
|
|
89
|
+
screenshot: FoirScreenCapture | null;
|
|
90
|
+
/** Injectable for the presigned PUT. Defaults to `globalThis.fetch`. */
|
|
91
|
+
fetch?: typeof globalThis.fetch;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Upload the attachment (if there is one), then write the note.
|
|
95
|
+
*
|
|
96
|
+
* In that order, and with the upload failing the whole submission rather than
|
|
97
|
+
* being skipped. A note that arrived without the picture the visitor attached is
|
|
98
|
+
* worse than one that did not arrive: they have no way to tell, and the thing
|
|
99
|
+
* they wrote ("as you can see in the screenshot") stops making sense.
|
|
100
|
+
*/
|
|
101
|
+
export declare function submitFeedbackNote(client: FoirFeedbackClient, submission: FoirFeedbackSubmission): Promise<FoirCustomerNote>;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@foir/sdk/react` —
|
|
2
|
+
* `@foir/sdk/react` — drop-in React components for Foir customers.
|
|
3
3
|
*
|
|
4
4
|
* Wrap your app in `<FoirProvider>`, then read the session with
|
|
5
5
|
* `useFoirSession` / `useFoirUser` and drive it with `useFoirAuth` — or drop in
|
|
6
6
|
* the `<SignIn>`, `<OAuthButtons>`, and `<UserButton>` components. Built entirely
|
|
7
7
|
* on `@foir/sdk/auth`; `react` is the only peer dependency.
|
|
8
|
+
*
|
|
9
|
+
* `<FoirFeedback>` is the annotation half: a feedback widget that anchors to the
|
|
10
|
+
* RECORD the page was rendered from rather than to its URL. It takes the data
|
|
11
|
+
* client from `@foir/sdk/data` and the subject registry you built for it.
|
|
8
12
|
*/
|
|
9
13
|
export { FoirProvider, useFoirSession, useFoirUser, useFoirAuth, } from './FoirProvider';
|
|
10
14
|
export type { FoirProviderProps, FoirContextValue, FoirSession, FoirStatus, } from './FoirProvider';
|
|
@@ -14,6 +18,8 @@ export { OAuthButtons } from './OAuthButtons';
|
|
|
14
18
|
export type { OAuthButtonsProps } from './OAuthButtons';
|
|
15
19
|
export { UserButton } from './UserButton';
|
|
16
20
|
export type { UserButtonProps } from './UserButton';
|
|
21
|
+
export { FoirFeedback } from './FoirFeedback';
|
|
22
|
+
export type { FoirFeedbackProps, FoirFeedbackClient } from './FoirFeedback';
|
|
17
23
|
export { createLocalStorageAdapter } from './localStorageAdapter';
|
|
18
24
|
export type { FoirCustomer, SessionAdapter, AuthProviderPublic } from '../auth';
|
|
19
25
|
export type { FoirEnv } from '../graphql/foir-request';
|