@factorialco/fcode-react-forms 3.4.0 → 3.5.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/dist/components/fcode-form/fcode-form.d.ts +25 -10
- package/dist/components/fcode-form/fcode-form.default-requests.test.d.ts +1 -0
- package/dist/components/fcode-form/fcode-form.transport.test.d.ts +1 -0
- package/dist/components/json-schema-form/oauth/resolve-oauth-value.d.ts +2 -1
- package/dist/components/json-schema-form/oauth/types.d.ts +12 -1
- package/dist/fcode-form.cjs.js +72 -72
- package/dist/fcode-form.cjs.js.map +1 -1
- package/dist/fcode-form.es.js +9116 -8913
- package/dist/fcode-form.es.js.map +1 -1
- package/dist/fcode-form.umd.js +81 -81
- package/dist/fcode-form.umd.js.map +1 -1
- package/dist/hooks/use-form-specs.d.ts +21 -3
- package/dist/hooks/use-submit-form.d.ts +13 -2
- package/dist/index.d.ts +2 -1
- package/dist/services/fcode.d.ts +10 -1
- package/dist/services/transport.d.ts +25 -0
- package/dist/services/transport.test.d.ts +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/utils/oauth-popup.d.ts +54 -4
- package/dist/utils/oauth-relay.d.ts +1 -0
- package/dist/utils/oauth-relay.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import { FormOptions, FormSpecs } from '../types';
|
|
2
|
-
|
|
1
|
+
import { FormOptions, FormSpecs, TransportFormOptions, UploadGrant } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* With a `transport`, the schema comes from it instead of the platform, and
|
|
4
|
+
* `hostUrl`, `team`, `headers` and `processVersion` do not apply. The
|
|
5
|
+
* transport is read when a fetch starts, so a new transport object alone does
|
|
6
|
+
* not refetch; a new `processId`, `locale` or `params` does.
|
|
7
|
+
*/
|
|
8
|
+
declare const useFormSpecs: (options: FormOptions | TransportFormOptions) => {
|
|
3
9
|
loading: boolean;
|
|
4
10
|
/** A `reload()` is in flight; the previous specs stay available meanwhile. */
|
|
5
11
|
reloading: boolean;
|
|
6
12
|
formSpecs: FormSpecs | undefined;
|
|
13
|
+
/** The upload grants the transport returned with the specs. */
|
|
14
|
+
uploads: UploadGrant[] | undefined;
|
|
7
15
|
error: unknown;
|
|
8
16
|
/**
|
|
9
17
|
* Refetches the specs bypassing the cache, keeping the current form on
|
|
10
18
|
* screen. A failed reload keeps the current specs too and sets no `error`.
|
|
19
|
+
* `silent: true` also skips `reloading` (no overlay): a background refresh
|
|
20
|
+
* the user should not notice, e.g. while an OAuth field is still waiting
|
|
21
|
+
* for a severed popup's completion.
|
|
11
22
|
*/
|
|
12
|
-
reload: (
|
|
23
|
+
reload: (options?: {
|
|
24
|
+
silent?: boolean;
|
|
25
|
+
}) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Refetches the specs through the transport for fresh upload grants and
|
|
28
|
+
* resolves with them; `undefined` without a transport.
|
|
29
|
+
*/
|
|
30
|
+
reloadUploads: () => Promise<UploadGrant[] | undefined>;
|
|
13
31
|
};
|
|
14
32
|
export default useFormSpecs;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import { FormOptions, SubmitFormResults, FormData } from '../types';
|
|
2
|
-
|
|
1
|
+
import { FormOptions, SubmitFormResults, FormData, TransportFormOptions, UploadGrant } from '../types';
|
|
2
|
+
export type SubmitFormOptions = FormOptions | (TransportFormOptions & {
|
|
3
|
+
/** The grants `useFormSpecs` returned with the specs. */
|
|
4
|
+
uploads?: UploadGrant[];
|
|
5
|
+
/** `useFormSpecs().reloadUploads`, used once when a grant has expired. */
|
|
6
|
+
reloadUploads?: () => Promise<UploadGrant[] | undefined>;
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* With a `transport`, submits through it (uploading files to their grants
|
|
10
|
+
* first) instead of posting to the platform; `hostUrl`, `team`, `headers` and
|
|
11
|
+
* `processVersion` do not apply.
|
|
12
|
+
*/
|
|
13
|
+
declare const useSubmitForm: (options: SubmitFormOptions) => [(data: FormData) => Promise<any>, {
|
|
3
14
|
loading: boolean;
|
|
4
15
|
results: SubmitFormResults | undefined;
|
|
5
16
|
error: string | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { processFormSpecs } from './utils/process-form-specs';
|
|
|
4
4
|
import { buildId } from './utils';
|
|
5
5
|
import { resolveErrorMessage } from './components/fcode-form/fcode-form.utils';
|
|
6
6
|
export { FcodeForm, FcodeJsonSchemaForm, processFormSpecs, buildId, resolveErrorMessage, };
|
|
7
|
-
export type { RedirectConfig } from './types';
|
|
7
|
+
export type { FormTransport, RedirectConfig, SubmitFormResponse, TransportFetchSchemaParams, TransportFetchSchemaResult, TransportSubmitParams, UploadGrant, } from './types';
|
|
8
|
+
export type { FcodeFormProps } from './components/fcode-form/fcode-form';
|
|
8
9
|
export type { FcodeRjsfTheme, MultistepThemeComponents, StepBackButtonProps, StepsNavigationItem, StepsNavigationProps, } from './components/json-schema-form/multistep';
|
|
9
10
|
export type { FcodeFormContext, OauthCompletionMessage, OauthConnectControlProps, OauthConnectStatus, OauthOnComplete, OauthThemeComponents, } from './components/json-schema-form/oauth';
|
|
10
11
|
export default FcodeForm;
|
package/dist/services/fcode.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import { SubmitFormParams, SubmitFormResponse, FetchFormSpecsParams } from '../types';
|
|
1
|
+
import { SubmitFormParams, SubmitFormResponse, FetchFormSpecsParams, FormData as YepFormData } from '../types';
|
|
2
2
|
export declare const fetchFormSpecs: ({ hostUrl, headers, team, processId, processVersion, locale, cache, }: FetchFormSpecsParams) => Promise<any>;
|
|
3
|
+
type ExtractedFile = {
|
|
4
|
+
key: string;
|
|
5
|
+
file: File;
|
|
6
|
+
};
|
|
7
|
+
export declare const extractFilesFromFormData: (formData: YepFormData) => {
|
|
8
|
+
sanitized: YepFormData;
|
|
9
|
+
files: ExtractedFile[];
|
|
10
|
+
};
|
|
3
11
|
export declare const submitForm: ({ hostUrl, headers, team, processId, processVersion, async, locale, formData, }: SubmitFormParams) => Promise<SubmitFormResponse>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FormData as YepFormData, FormOptions, FormTransport, SubmitFormResponse, TransportFormOptions, UploadGrant } from '../types';
|
|
2
|
+
export declare const isTransportOptions: (options: FormOptions | TransportFormOptions) => options is TransportFormOptions;
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when a grant's URL refuses the upload twice: the grants were reloaded
|
|
5
|
+
* once already, so another attempt would only repeat the refusal.
|
|
6
|
+
*/
|
|
7
|
+
export declare class UploadGrantExpiredError extends Error {
|
|
8
|
+
constructor(field: string);
|
|
9
|
+
}
|
|
10
|
+
export interface SubmitThroughTransportParams {
|
|
11
|
+
transport: FormTransport;
|
|
12
|
+
processId: string;
|
|
13
|
+
locale?: string;
|
|
14
|
+
async?: boolean;
|
|
15
|
+
formData: YepFormData;
|
|
16
|
+
uploads?: UploadGrant[];
|
|
17
|
+
/** Fetches the schema again for fresh grants, when the current ones have expired. */
|
|
18
|
+
reloadUploads?: () => Promise<UploadGrant[] | undefined>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Submits through a transport. With grants, each file is sent to its grant's
|
|
22
|
+
* URL first and the submit carries the storage paths instead, as plain JSON;
|
|
23
|
+
* without grants the form data goes to the transport as it is.
|
|
24
|
+
*/
|
|
25
|
+
export declare const submitThroughTransport: ({ transport, processId, locale, async, formData, uploads, reloadUploads, }: SubmitThroughTransportParams) => Promise<SubmitFormResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -102,3 +102,62 @@ export interface SubmitFormParams {
|
|
|
102
102
|
locale?: string;
|
|
103
103
|
formData: FormData;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* A presigned write for one file field, handed out with the schema by a
|
|
107
|
+
* transport. The SDK sends the file there itself and submits `path` as the
|
|
108
|
+
* field's value, so the submit carries no file bytes.
|
|
109
|
+
*/
|
|
110
|
+
export interface UploadGrant {
|
|
111
|
+
/** The form field the file belongs to. */
|
|
112
|
+
field: string;
|
|
113
|
+
/** The `fcode.storage://` reference submitted as the field's value. */
|
|
114
|
+
path: string;
|
|
115
|
+
uploadUrl: string;
|
|
116
|
+
/** Defaults to `PUT`. */
|
|
117
|
+
method?: string;
|
|
118
|
+
/** Sent with the upload as they are; presigned URLs usually sign some. */
|
|
119
|
+
headers?: Record<string, string>;
|
|
120
|
+
expiresAt?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface TransportFetchSchemaParams {
|
|
123
|
+
/**
|
|
124
|
+
* Whatever id the transport understands — a process slug, an opaque action
|
|
125
|
+
* id. The SDK passes it through, including a step's `nextProcessId`.
|
|
126
|
+
*/
|
|
127
|
+
processId: string;
|
|
128
|
+
locale?: string;
|
|
129
|
+
/** The form's variables: the embedder's `options.variables` plus what earlier steps returned. */
|
|
130
|
+
params?: GenericObjectType;
|
|
131
|
+
/** Always `no-store`: the schema is per user and must not be shared through a cache. */
|
|
132
|
+
cache: RequestCache;
|
|
133
|
+
}
|
|
134
|
+
export interface TransportFetchSchemaResult {
|
|
135
|
+
/** The form specs, the same body the platform's forms endpoint returns. */
|
|
136
|
+
schema: FormSpecs;
|
|
137
|
+
/** One grant per file field. Absent, the transport receives the files inside `formData`. */
|
|
138
|
+
uploads?: UploadGrant[];
|
|
139
|
+
}
|
|
140
|
+
export interface TransportSubmitParams {
|
|
141
|
+
processId: string;
|
|
142
|
+
/** Plain JSON: file fields with a grant already hold their storage path. */
|
|
143
|
+
formData: FormData;
|
|
144
|
+
locale?: string;
|
|
145
|
+
async?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A caller-supplied channel for fetching the schema and submitting the form,
|
|
149
|
+
* used instead of the SDK's own requests to the platform. A submit that fails
|
|
150
|
+
* rejects with the error body, as the platform's does (`formErrors`,
|
|
151
|
+
* `errorMessage`).
|
|
152
|
+
*/
|
|
153
|
+
export interface FormTransport {
|
|
154
|
+
fetchSchema: (params: TransportFetchSchemaParams) => Promise<TransportFetchSchemaResult>;
|
|
155
|
+
submit: (params: TransportSubmitParams) => Promise<SubmitFormResponse>;
|
|
156
|
+
}
|
|
157
|
+
export interface TransportFormOptions {
|
|
158
|
+
transport: FormTransport;
|
|
159
|
+
processId: string;
|
|
160
|
+
async?: boolean;
|
|
161
|
+
locale?: string;
|
|
162
|
+
params?: GenericObjectType;
|
|
163
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OauthCompletionMessage, OauthResult } from '../components/json-schema-form/oauth/types';
|
|
1
|
+
import { OauthCompletionMessage, OauthOutcome, OauthResult } from '../components/json-schema-form/oauth/types';
|
|
2
2
|
export interface OpenOauthPopupOptions {
|
|
3
3
|
url: string;
|
|
4
4
|
/** The window name; re-opening with the same name reuses the popup. */
|
|
@@ -16,14 +16,64 @@ export interface OauthPopupHandle {
|
|
|
16
16
|
/** Stops listening without closing the popup (component unmount). */
|
|
17
17
|
dispose: () => void;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* How long a "closed" popup may still deliver its completion. A provider that
|
|
21
|
+
* sends `Cross-Origin-Opener-Policy` (DATEV does) swaps the popup into another
|
|
22
|
+
* browsing context group the moment it navigates there: the opener's window
|
|
23
|
+
* proxy starts reporting `closed: true` while the user is still logging in.
|
|
24
|
+
* The completion then arrives over the BroadcastChannel instead, so a closed
|
|
25
|
+
* popup only counts as cancelled once this grace period passes in silence.
|
|
26
|
+
*/
|
|
27
|
+
export declare const CLOSED_GRACE_MS = 1500;
|
|
28
|
+
/**
|
|
29
|
+
* A popup that reports closed within this window of being opened is most
|
|
30
|
+
* likely not closed at all but COOP-severed — the swap happens the moment the
|
|
31
|
+
* provider's page commits, seconds in, while a user genuinely closing the
|
|
32
|
+
* window takes longer. Such a cancel is flagged `possiblySevered` so the
|
|
33
|
+
* control can keep its waiting state for the late completion.
|
|
34
|
+
*/
|
|
35
|
+
export declare const SEVERANCE_WINDOW_MS = 8000;
|
|
36
|
+
/**
|
|
37
|
+
* The same-origin channel `oauth-callback.html` broadcasts its completion on,
|
|
38
|
+
* for openers a `Cross-Origin-Opener-Policy` header disconnected. The name is
|
|
39
|
+
* a contract with that page.
|
|
40
|
+
*/
|
|
41
|
+
export declare const OAUTH_CHANNEL_NAME = "fcode-forms:oauth";
|
|
42
|
+
/** A channel to listen for completions on, or null where unsupported (jsdom). */
|
|
43
|
+
export declare const openOauthChannel: () => BroadcastChannel | null;
|
|
44
|
+
/**
|
|
45
|
+
* The OAuth `state` an authorization URL carries, or null. The SDK never mints
|
|
46
|
+
* the state (the author's pre-render process does), but it can read it — and
|
|
47
|
+
* when the callback webhook echoes it back to `oauth-callback.html`, a
|
|
48
|
+
* completion can be bound to the very flow that opened the popup.
|
|
49
|
+
*/
|
|
50
|
+
export declare const oauthStateOf: (url: string) => string | null;
|
|
51
|
+
/**
|
|
52
|
+
* State binding for channel-delivered completions, where no sender identity
|
|
53
|
+
* exists: whenever this side knows the states it opened popups for, the
|
|
54
|
+
* payload MUST echo one of them — the callback contract requires echoing the
|
|
55
|
+
* `state` back to `oauth-callback.html`. A merely-optional echo would be no
|
|
56
|
+
* binding at all (a forger could just omit it). Only a flow whose
|
|
57
|
+
* authorization URL carried no `state` cannot be bound and stays accept-any.
|
|
58
|
+
*/
|
|
59
|
+
export declare const completionMatchesState: (data: OauthCompletionMessage, knownStates: ReadonlySet<string>) => boolean;
|
|
19
60
|
/** Whether `data` is the payload `oauth-callback.html` posts. */
|
|
20
61
|
export declare const isOauthCompletionMessage: (data: unknown) => data is OauthCompletionMessage;
|
|
62
|
+
/** The outcome a completion payload describes, with params sanitised. */
|
|
63
|
+
export declare const completionToResult: (data: OauthCompletionMessage) => OauthOutcome;
|
|
21
64
|
/**
|
|
22
65
|
* Opens the authorization URL in a popup and reports how it ended, once:
|
|
23
|
-
* `success`/`error` when the callback page
|
|
66
|
+
* `success`/`error` when the callback page delivers its completion message,
|
|
24
67
|
* `cancelled` when the popup closes without one, `blocked` when the browser
|
|
25
|
-
* refused to open it.
|
|
26
|
-
*
|
|
68
|
+
* refused to open it. After a completion the popup is closed once `closeDelay`
|
|
69
|
+
* elapses.
|
|
70
|
+
*
|
|
71
|
+
* The completion arrives on two redundant paths: a `postMessage` from the
|
|
72
|
+
* popup (accepted only when `event.source` is that very window) and the
|
|
73
|
+
* same-origin `BroadcastChannel` — the fallback for providers whose
|
|
74
|
+
* `Cross-Origin-Opener-Policy` severs the opener link mid-flow. A channel is
|
|
75
|
+
* same-origin by construction, and the payload travelled in a URL anyway; the
|
|
76
|
+
* submit-side process must verify the connection regardless.
|
|
27
77
|
*
|
|
28
78
|
* Must be called synchronously from a user gesture, or popup blockers step in.
|
|
29
79
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ensureOauthRelay: (sdkOrigin: string) => (() => void);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorialco/fcode-react-forms",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Factorial Code allows start process executions from any webpage embedding process input parameters forms. This allows each form submission to start one execution with the information filled in the form, and also allows to manage the execution result into that webpage.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://code.factorialhr.com/docs/forms/",
|