@ebitex/forms-sdk 0.6.158 → 0.7.190
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 +46 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/react/EbitexForm.d.ts +21 -2
- package/dist/react/EbitexForm.d.ts.map +1 -1
- package/dist/react/EbitexForm.js +16 -5
- package/dist/react/EbitexForm.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/types.d.ts +44 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -4
- package/dist/types.js.map +1 -1
- package/dist/visitor.d.ts +61 -0
- package/dist/visitor.d.ts.map +1 -0
- package/dist/visitor.js +152 -0
- package/dist/visitor.js.map +1 -0
- package/package.json +1 -1
- package/dist/react/visitorId.d.ts +0 -19
- package/dist/react/visitorId.d.ts.map +0 -1
- package/dist/react/visitorId.js +0 -41
- package/dist/react/visitorId.js.map +0 -1
package/README.md
CHANGED
|
@@ -163,6 +163,52 @@ const errors = validateSubmission(form, submittedData, { requireAll: true })
|
|
|
163
163
|
`<EbitexForm>` calls this itself for inline feedback before every request; the server is always the
|
|
164
164
|
final authority regardless — a client-side pass is for a good respondent experience, not enforcement.
|
|
165
165
|
|
|
166
|
+
## Consent and the visitor token
|
|
167
|
+
|
|
168
|
+
A multi-step form keeps its progress against a visitor token that the API issues. The package holds that token
|
|
169
|
+
**in memory only**. It never writes to `localStorage`, `sessionStorage`, a cookie or IndexedDB, so by default a
|
|
170
|
+
page load is a new visitor and nothing is remembered across visits.
|
|
171
|
+
|
|
172
|
+
Recognising a respondent across visits needs their consent. Tell the form what they chose, and, if you want the
|
|
173
|
+
token to survive between visits, give it somewhere to keep it:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
import { EbitexForm } from '@ebitex/forms-sdk/react'
|
|
177
|
+
|
|
178
|
+
<EbitexForm
|
|
179
|
+
form={form}
|
|
180
|
+
consent={{ cmp: 'granted' }} // from your consent banner; 'denied' is a withdrawal
|
|
181
|
+
storage={{
|
|
182
|
+
get: () => localStorage.getItem('visitor'),
|
|
183
|
+
set: (token) => localStorage.setItem('visitor', token),
|
|
184
|
+
remove: () => localStorage.removeItem('visitor'),
|
|
185
|
+
}}
|
|
186
|
+
/>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- `set` is called **only** when the API reports that recognising the respondent is granted, and only when the
|
|
190
|
+
token has changed. `remove` is called when it is not, when the respondent withdraws consent, when you call
|
|
191
|
+
`forget`, and when a response says nothing about consent (an older server).
|
|
192
|
+
- Without a `consent` option the organization's default applies. That default is *denied* until an Owner changes
|
|
193
|
+
it or you pass a signal from your banner, so out of the box nothing is recognised across visits.
|
|
194
|
+
- `gpc` and `dnt` default to the browser's Global Privacy Control and Do Not Track settings. Pass them to
|
|
195
|
+
override. Either one set means "do not recognise me" unless your banner records an explicit choice.
|
|
196
|
+
- If you keep the token anywhere other than through `storage`, the same rule applies to you: store it only while
|
|
197
|
+
recognition is granted, and remove it as soon as it is not.
|
|
198
|
+
|
|
199
|
+
To change consent after the form has mounted, update the `consent` prop, or share one session across forms and
|
|
200
|
+
call `setConsent` yourself. `forget` asks the API to forget the browser and clears the token:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import { createVisitorSession } from '@ebitex/forms-sdk'
|
|
204
|
+
|
|
205
|
+
const visitor = createVisitorSession({ storage, consent: { cmp: 'granted' } })
|
|
206
|
+
// <EbitexForm visitor={visitor} ... />
|
|
207
|
+
visitor.setConsent({ cmp: 'denied' }) // drops the token and calls storage.remove()
|
|
208
|
+
await visitor.forget(form) // resolves with the organization's confirmation message
|
|
209
|
+
visitor.consent?.messages.recognitionDeclined // wording to show where something needs recognition
|
|
210
|
+
```
|
|
211
|
+
|
|
166
212
|
## Versioning
|
|
167
213
|
|
|
168
214
|
This package's public wire shape mirrors ebitex's own Forms API responses directly (see
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ export { validateSubmission, type ValidateOptions } from './validators.js';
|
|
|
12
12
|
export { isAllOfSatisfied, isFieldComparisonSatisfied, isSatisfied } from './predicates.js';
|
|
13
13
|
export { deriveDarkVariant } from './theme.js';
|
|
14
14
|
export { adjacentVisibleStepSlot, collectDataFields, defaultChoiceValues, isDataField, collectSubmissionKeys, isFormField, resolveSteps, resolveVariant, resolveVisibleStepSlot, } from './nodes.js';
|
|
15
|
-
export { type AllOfPredicate, type ButtonField, type ButtonType, type ChoiceField, type ChoiceOption, type ChoiceType, type FieldComparisonOperator, type FieldComparisonPredicate, type FieldsetNode, type FormField, type FormNode, type FormStep, type InputField, type InputVariant, type LookupSource, type NumberField, type RowNode, type SdkForm, type SubmissionData, type TextareaField, type ValidationErrors, type VariantBranch, type VariantNode, type VariantPredicate, } from './types.js';
|
|
15
|
+
export { type AllOfPredicate, type ButtonField, type ButtonType, type ChoiceField, type ChoiceOption, type ChoiceType, type ConsentMessages, type ConsentOptions, type ConsentState, type FieldComparisonOperator, type FieldComparisonPredicate, type FieldsetNode, type FormField, type FormNode, type FormStep, type InputField, type InputVariant, type LookupSource, type NumberField, type RowNode, type SdkForm, type SubmissionData, type TextareaField, type ValidationErrors, type VariantBranch, type VariantNode, type VariantPredicate, type VisitorStorage, } from './types.js';
|
|
16
16
|
export { LOOKUP_COMPANION_SUFFIX, MAX_LOOKUP_VALUE_LENGTH } from './types.js';
|
|
17
17
|
export { createPublicLookupSource, lookupUrlFromSubmissionUrl } from './lookup.js';
|
|
18
|
+
export { createVisitorSession, forgetUrlFromSubmissionUrl, type VisitorSession, type VisitorSessionOptions, } from './visitor.js';
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,GACvB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,GACvB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAE7E,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAElF,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -15,4 +15,5 @@ export { adjacentVisibleStepSlot, collectDataFields, defaultChoiceValues, isData
|
|
|
15
15
|
export {} from './types.js';
|
|
16
16
|
export { LOOKUP_COMPANION_SUFFIX, MAX_LOOKUP_VALUE_LENGTH } from './types.js';
|
|
17
17
|
export { createPublicLookupSource, lookupUrlFromSubmissionUrl } from './lookup.js';
|
|
18
|
+
export { createVisitorSession, forgetUrlFromSubmissionUrl, } from './visitor.js';
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,iBAAiB,EACjB,aAAa,GAGd,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAwB,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,GACvB,MAAM,YAAY,CAAA;AAEnB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,iBAAiB,EACjB,aAAa,GAGd,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAwB,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,GACvB,MAAM,YAAY,CAAA;AAEnB,OAAO,EA6BN,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAE7E,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAElF,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAG3B,MAAM,cAAc,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CSSProperties } from 'react';
|
|
2
|
-
import type { LookupSource, SdkForm, SubmissionData } from '../types.js';
|
|
2
|
+
import type { ConsentOptions, LookupSource, SdkForm, SubmissionData, VisitorStorage } from '../types.js';
|
|
3
|
+
import { type VisitorSession } from '../visitor.js';
|
|
3
4
|
import type { FieldComponents } from './fields.js';
|
|
4
5
|
export interface EbitexFormProps {
|
|
5
6
|
/** A form definition from `createFormsClient(...).getForm(...)`, fetched on your server. */
|
|
@@ -22,6 +23,24 @@ export interface EbitexFormProps {
|
|
|
22
23
|
* through your own server or to fake them in a test.
|
|
23
24
|
*/
|
|
24
25
|
lookup?: LookupSource;
|
|
26
|
+
/**
|
|
27
|
+
* Signals from your consent banner (and, by default, the browser's Global Privacy Control and Do Not
|
|
28
|
+
* Track settings). Without any, the organization's default applies, which is *denied* until an Owner
|
|
29
|
+
* changes it: the respondent is not recognised across visits. Update it as the respondent chooses; a
|
|
30
|
+
* change to `cmp: 'denied'` drops the token at once.
|
|
31
|
+
*/
|
|
32
|
+
consent?: ConsentOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Where to keep the visitor token between visits. Optional, and the component never persists anything
|
|
35
|
+
* itself: your adapter's `set` is called only when the API reports that recognising the respondent is
|
|
36
|
+
* granted, and `remove` whenever it is not. If you keep the token anywhere else, the same rule applies.
|
|
37
|
+
*/
|
|
38
|
+
storage?: VisitorStorage;
|
|
39
|
+
/**
|
|
40
|
+
* An existing session from `createVisitorSession`, to share one token across several forms on a page or to
|
|
41
|
+
* call `forget` from your own UI. When given, `consent` and `storage` here are ignored.
|
|
42
|
+
*/
|
|
43
|
+
visitor?: VisitorSession;
|
|
25
44
|
/** Injectable for tests and non-standard runtimes. */
|
|
26
45
|
fetch?: typeof globalThis.fetch;
|
|
27
46
|
}
|
|
@@ -38,5 +57,5 @@ export interface EbitexFormProps {
|
|
|
38
57
|
* isn't lost — matching the behaviour of ebitex's own renderer rather than a simplified
|
|
39
58
|
* client-only notion of steps.
|
|
40
59
|
*/
|
|
41
|
-
export declare function EbitexForm({ form, onSubmitted, onError, className, style, fieldComponents, lookup, fetch: injectedFetch, }: EbitexFormProps): import("react").JSX.Element | null;
|
|
60
|
+
export declare function EbitexForm({ form, onSubmitted, onError, className, style, fieldComponents, lookup, consent, storage, visitor: injectedVisitor, fetch: injectedFetch, }: EbitexFormProps): import("react").JSX.Element | null;
|
|
42
61
|
//# sourceMappingURL=EbitexForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EbitexForm.d.ts","sourceRoot":"","sources":["../../src/react/EbitexForm.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"EbitexForm.d.ts","sourceRoot":"","sources":["../../src/react/EbitexForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAG/E,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAoB,cAAc,EAAE,MAAM,aAAa,CAAA;AAC1H,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AAEzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAGlD,MAAM,WAAW,eAAe;IAC9B,4FAA4F;IAC5F,IAAI,EAAE,OAAO,CAAA;IAEb,kDAAkD;IAClD,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAA;IAE5C,wGAAwG;IACxG,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAElC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;IAErB;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAA;IAEjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,YAAY,CAAA;IAErB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IAExB;;;;OAIG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IAExB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IAExB,sDAAsD;IACtD,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAChC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,WAAW,EACX,OAAO,EACP,SAAS,EACT,KAAK,EACL,eAAe,EACf,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,GACrB,EAAE,eAAe,sCAyOjB"}
|
package/dist/react/EbitexForm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useId, useMemo, useState } from 'react';
|
|
2
|
+
import { useEffect, useId, useMemo, useState } from 'react';
|
|
3
3
|
import { adjacentVisibleStepSlot, collectSubmissionKeys, defaultChoiceValues, resolveSteps, resolveVisibleStepSlot } from '../nodes.js';
|
|
4
4
|
import { createPublicLookupSource, lookupUrlFromSubmissionUrl } from '../lookup.js';
|
|
5
|
+
import { createVisitorSession } from '../visitor.js';
|
|
5
6
|
import { validateSubmission } from '../validators.js';
|
|
6
7
|
import { ActionButtons, NodeList, joinClassNames } from './NodeList.js';
|
|
7
|
-
import { getOrCreateVisitorId } from './visitorId.js';
|
|
8
8
|
/**
|
|
9
9
|
* Renders an ebitex Form and submits it.
|
|
10
10
|
*
|
|
@@ -18,7 +18,7 @@ import { getOrCreateVisitorId } from './visitorId.js';
|
|
|
18
18
|
* isn't lost — matching the behaviour of ebitex's own renderer rather than a simplified
|
|
19
19
|
* client-only notion of steps.
|
|
20
20
|
*/
|
|
21
|
-
export function EbitexForm({ form, onSubmitted, onError, className, style, fieldComponents, lookup, fetch: injectedFetch, }) {
|
|
21
|
+
export function EbitexForm({ form, onSubmitted, onError, className, style, fieldComponents, lookup, consent, storage, visitor: injectedVisitor, fetch: injectedFetch, }) {
|
|
22
22
|
const baseId = useId();
|
|
23
23
|
const doFetch = injectedFetch ?? globalThis.fetch;
|
|
24
24
|
const lookupSource = useMemo(() => {
|
|
@@ -46,7 +46,16 @@ export function EbitexForm({ form, onSubmitted, onError, className, style, field
|
|
|
46
46
|
const isLastStep = step === undefined || adjacentVisibleStepSlot(steps, data, currentSlot, 1) < 0;
|
|
47
47
|
const hasPreviousStep = step !== undefined && adjacentVisibleStepSlot(steps, data, currentSlot, -1) >= 0;
|
|
48
48
|
const visibleStepPosition = step ? visibleSteps.indexOf(step) : -1;
|
|
49
|
-
|
|
49
|
+
// Held in memory for the life of the component. Nothing is written to the browser by this package.
|
|
50
|
+
const session = useMemo(() => injectedVisitor ?? createVisitorSession({ storage, consent }),
|
|
51
|
+
// The session is created once; later `consent` changes are applied by the effect below, and a
|
|
52
|
+
// different adapter is a different session only if the host remounts the form.
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
[injectedVisitor]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!injectedVisitor && consent)
|
|
57
|
+
session.setConsent(consent);
|
|
58
|
+
}, [session, injectedVisitor, consent?.cmp, consent?.cmpString, consent?.gpc, consent?.dnt]);
|
|
50
59
|
if (completed) {
|
|
51
60
|
return (_jsx("div", { className: joinClassNames('ebitex-forms', className), style: style, children: _jsx("p", { className: "ebitex-forms__complete", role: "status", children: "Thanks \u2014 your response has been submitted." }) }));
|
|
52
61
|
}
|
|
@@ -90,7 +99,7 @@ export function EbitexForm({ form, onSubmitted, onError, className, style, field
|
|
|
90
99
|
const response = await doFetch(form.submissionUrl, {
|
|
91
100
|
method: 'POST',
|
|
92
101
|
headers: { 'Content-Type': 'application/json' },
|
|
93
|
-
body: JSON.stringify({
|
|
102
|
+
body: JSON.stringify({ ...(await session.requestFields()), data: visiblePayload(), complete }),
|
|
94
103
|
});
|
|
95
104
|
if (!response.ok) {
|
|
96
105
|
// The server is authoritative: a field-level rejection is surfaced inline rather than
|
|
@@ -103,6 +112,8 @@ export function EbitexForm({ form, onSubmitted, onError, className, style, field
|
|
|
103
112
|
onError?.(new Error(`Submission failed with status ${response.status}`));
|
|
104
113
|
return false;
|
|
105
114
|
}
|
|
115
|
+
// The response carries the token to use from now on and what the API decided about consent.
|
|
116
|
+
session.receive(await response.clone().json().catch(() => null));
|
|
106
117
|
return true;
|
|
107
118
|
}
|
|
108
119
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EbitexForm.js","sourceRoot":"","sources":["../../src/react/EbitexForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"EbitexForm.js","sourceRoot":"","sources":["../../src/react/EbitexForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAA;AAC/E,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACvI,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAEnF,OAAO,EAAE,oBAAoB,EAAuB,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,E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AAE,GAAG,EAAE;oCACZ,MAAM,QAAQ,GAAG,uBAAuB,CAAC,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAA;oCACtE,IAAI,QAAQ,IAAI,CAAC;wCAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;gCAC1C,CAAC,qBAGM,CACV,CAAC,CAAC,CAAC,IAAI,EAEP,UAAU,CAAC,CAAC,CAAC,CACZ,KAAC,aAAa,IAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAC3D,CAAC,CAAC,CAAC,CACF,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,sBAAsB,EAAC,QAAQ,EAAE,QAAQ,qBAEhE,CACV,IACG,IACD,IACH,CACP,CAAA;AACH,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export { LookupFieldControl } from './LookupField.js';
|
|
|
16
16
|
* spec 77-public-form-progressive-enhancement.
|
|
17
17
|
*/
|
|
18
18
|
export { ActionButtons, NodeList } from './NodeList.js';
|
|
19
|
-
export {
|
|
19
|
+
export { createVisitorSession, type VisitorSession, type VisitorSessionOptions } from '../visitor.js';
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAElE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACxB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD;;;;;;GAMG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAElE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACxB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD;;;;;;GAMG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,oBAAoB,EAAE,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/react/index.js
CHANGED
|
@@ -16,5 +16,5 @@ export { LookupFieldControl } from './LookupField.js';
|
|
|
16
16
|
* spec 77-public-form-progressive-enhancement.
|
|
17
17
|
*/
|
|
18
18
|
export { ActionButtons, NodeList } from './NodeList.js';
|
|
19
|
-
export {
|
|
19
|
+
export { createVisitorSession } from '../visitor.js';
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAA;AAElE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,GAIrB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD;;;;;;GAMG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAA;AAElE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,GAIrB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD;;;;;;GAMG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,oBAAoB,EAAmD,MAAM,eAAe,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -186,5 +186,49 @@ export interface SdkForm {
|
|
|
186
186
|
export type SubmissionData = Record<string, string | string[] | number | null>;
|
|
187
187
|
/** Field-level validation messages, keyed by `submissionKey`. Empty means valid. */
|
|
188
188
|
export type ValidationErrors = Record<string, string>;
|
|
189
|
+
/**
|
|
190
|
+
* The signals from a consent banner and the respondent's browser, sent as they are for the API to resolve.
|
|
191
|
+
* Every member is optional. `gpc` and `dnt` default to the browser's Global Privacy Control and Do Not Track
|
|
192
|
+
* settings when running in a browser; pass a value to override.
|
|
193
|
+
*/
|
|
194
|
+
export interface ConsentOptions {
|
|
195
|
+
/** The respondent's explicit choice about being recognised across visits, from your consent banner. */
|
|
196
|
+
cmp?: 'granted' | 'denied';
|
|
197
|
+
/** Your banner's own consent string (a TCF string, for instance), kept as the organization's evidence. Up to 4096 characters. */
|
|
198
|
+
cmpString?: string;
|
|
199
|
+
/** Global Privacy Control. Defaults to `navigator.globalPrivacyControl`. */
|
|
200
|
+
gpc?: boolean;
|
|
201
|
+
/** Do Not Track. Defaults to `navigator.doNotTrack === '1'`. */
|
|
202
|
+
dnt?: boolean;
|
|
203
|
+
}
|
|
204
|
+
/** Wording the organization has set for the respondent, already resolved to the respondent's language. */
|
|
205
|
+
export interface ConsentMessages {
|
|
206
|
+
/** Shown where something is unavailable because the respondent is not being recognised across visits. */
|
|
207
|
+
recognitionDeclined: string;
|
|
208
|
+
forgetConfirm: string;
|
|
209
|
+
forgetDone: string;
|
|
210
|
+
}
|
|
211
|
+
/** What the API decided about recognising this respondent, and why. */
|
|
212
|
+
export interface ConsentState {
|
|
213
|
+
recognition: 'granted' | 'denied';
|
|
214
|
+
/** What decided it: your banner (`cmp`), the browser (`globalPrivacyControl`, `doNotTrack`) or the organization's default. */
|
|
215
|
+
source: string;
|
|
216
|
+
policyVersion: number;
|
|
217
|
+
/** `recognition` tokens may outlive a visit; `session` tokens are short-lived and for the form in progress only. */
|
|
218
|
+
tokenKind: 'recognition' | 'session';
|
|
219
|
+
tokenLifetimeSeconds: number;
|
|
220
|
+
messages: ConsentMessages;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Where a consumer persists the visitor token across visits, if at all. The package never touches browser
|
|
224
|
+
* storage itself. See {@link VisitorSession} in `./visitor.js` for exactly when each method is called.
|
|
225
|
+
*/
|
|
226
|
+
export interface VisitorStorage {
|
|
227
|
+
get(): string | null | undefined | Promise<string | null | undefined>;
|
|
228
|
+
/** Called only when the API reports recognition as granted, and only when the token changed. */
|
|
229
|
+
set(token: string): void | Promise<void>;
|
|
230
|
+
/** Called when recognition is denied or withdrawn, on forget, and when the API says nothing about consent. */
|
|
231
|
+
remove(): void | Promise<void>;
|
|
232
|
+
}
|
|
189
233
|
export {};
|
|
190
234
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU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AA;IACxC,8GAA8G;IAC9G,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/B"}
|
package/dist/types.js
CHANGED
|
@@ -13,8 +13,4 @@ export const MAX_LOOKUP_VALUE_LENGTH = 200;
|
|
|
13
13
|
* is how extra questions appear only for an answer that is not in the list.
|
|
14
14
|
*/
|
|
15
15
|
export const LOOKUP_COMPANION_SUFFIX = '-existing';
|
|
16
|
-
// `isFormField`/`isDataField`/`collectDataFields`/`resolveVariant` live in `./nodes.js`, not here —
|
|
17
|
-
// `resolveVariant` needs `isFieldComparisonSatisfied` from `./predicates.js`, which itself imports
|
|
18
|
-
// types from this file, so keeping tree-walking logic out of `types.ts` avoids a circular import
|
|
19
|
-
// between the two.
|
|
20
16
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAyFH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAAA
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAyFH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ConsentOptions, ConsentState, SdkForm, VisitorStorage } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a respondent's browser holds between the steps of one form, and, only with consent, between visits.
|
|
4
|
+
*
|
|
5
|
+
* **The token lives in memory.** This package never writes to `localStorage`, `sessionStorage`, a cookie or
|
|
6
|
+
* IndexedDB itself. Putting an identifier on a respondent's device is "storage" under the ePrivacy rules and
|
|
7
|
+
* needs their consent first, so persistence goes through the optional {@link VisitorStorage} adapter you pass,
|
|
8
|
+
* and the session calls its `set` **only** when the API reports that recognising the respondent is granted.
|
|
9
|
+
* On a denial, a withdrawal, a forget, or a response that says nothing about consent (an older server), it
|
|
10
|
+
* calls `remove`.
|
|
11
|
+
*
|
|
12
|
+
* If you keep the token anywhere yourself, the same rule applies to you: persist it only while recognition is
|
|
13
|
+
* granted and remove it as soon as it is not.
|
|
14
|
+
*
|
|
15
|
+
* Without a `consent` option the organization's default applies. That default is *denied* until an Owner
|
|
16
|
+
* changes it or you pass a signal from your consent banner, so out of the box nothing is recognised across
|
|
17
|
+
* visits and each page load is a new visitor.
|
|
18
|
+
*/
|
|
19
|
+
export interface VisitorSession {
|
|
20
|
+
/** The current token, held in memory. `null` before the first response of a visit. */
|
|
21
|
+
readonly token: string | null;
|
|
22
|
+
/** The consent state the API reported on the last response, or `null` before one (or from an older server). */
|
|
23
|
+
readonly consent: ConsentState | null;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves once the adapter's stored token, if any, has been read into memory. Awaited by {@link requestFields},
|
|
26
|
+
* so you rarely need it.
|
|
27
|
+
*/
|
|
28
|
+
readonly ready: Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Replaces the consent signals, for a consent banner's callback. `cmp: 'denied'` is a withdrawal: the
|
|
31
|
+
* in-memory token is dropped and the adapter's `remove` is called at once.
|
|
32
|
+
*/
|
|
33
|
+
setConsent(options: ConsentOptions): void;
|
|
34
|
+
/** The `visitor` and `consent` members to merge into a render or submission request body. */
|
|
35
|
+
requestFields(): Promise<{
|
|
36
|
+
visitor: string;
|
|
37
|
+
consent: {
|
|
38
|
+
cmp: 'granted' | 'denied' | null;
|
|
39
|
+
gpc: boolean;
|
|
40
|
+
dnt: boolean;
|
|
41
|
+
cmpString: string | null;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
/** Reads `visitor` and `consent` from a render or submission response and applies the storage rules. */
|
|
45
|
+
receive(responseBody: unknown): void;
|
|
46
|
+
/**
|
|
47
|
+
* Asks the API to forget this browser (rotating its id and removing links to details held about it), then
|
|
48
|
+
* clears the token from memory and calls the adapter's `remove`. Resolves with the message to show.
|
|
49
|
+
*/
|
|
50
|
+
forget(form: Pick<SdkForm, 'submissionUrl'>, doFetch?: typeof globalThis.fetch): Promise<string | null>;
|
|
51
|
+
}
|
|
52
|
+
export interface VisitorSessionOptions {
|
|
53
|
+
/** Where to persist the token across visits. Called only as described on {@link VisitorSession}. Optional. */
|
|
54
|
+
storage?: VisitorStorage;
|
|
55
|
+
/** Signals from your consent banner and the respondent's browser settings. See {@link ConsentOptions}. */
|
|
56
|
+
consent?: ConsentOptions;
|
|
57
|
+
}
|
|
58
|
+
export declare function createVisitorSession(options?: VisitorSessionOptions): VisitorSession;
|
|
59
|
+
/** The forget endpoint that sits beside a form's public submission endpoint, or `undefined` for an address of another shape. */
|
|
60
|
+
export declare function forgetUrlFromSubmissionUrl(submissionUrl: string): string | undefined;
|
|
61
|
+
//# sourceMappingURL=visitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor.d.ts","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,OAAO,EACP,cAAc,EACf,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,cAAc;IAC7B,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAE7B,+GAA+G;IAC/G,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAA;IAErC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7B;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAA;IAEzC,6FAA6F;IAC7F,aAAa,IAAI,OAAO,CAAC;QACvB,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE;YAAE,GAAG,EAAE,SAAS,GAAG,QAAQ,GAAG,IAAI,CAAC;YAAC,GAAG,EAAE,OAAO,CAAC;YAAC,GAAG,EAAE,OAAO,CAAC;YAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAA;KACpG,CAAC,CAAA;IAEF,wGAAwG;IACxG,OAAO,CAAC,YAAY,EAAE,OAAO,GAAG,IAAI,CAAA;IAEpC;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CACxG;AAED,MAAM,WAAW,qBAAqB;IACpC,8GAA8G;IAC9G,OAAO,CAAC,EAAE,cAAc,CAAA;IAExB,0GAA0G;IAC1G,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,cAAc,CAqHxF;AAED,gIAAgI;AAChI,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGpF"}
|
package/dist/visitor.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
export function createVisitorSession(options = {}) {
|
|
2
|
+
const { storage } = options;
|
|
3
|
+
let consentOptions = { ...options.consent };
|
|
4
|
+
let token = null;
|
|
5
|
+
let persisted = null;
|
|
6
|
+
let consent = null;
|
|
7
|
+
// Only used when the API has not issued a token yet (the first request of a visit). It is never stored, and a
|
|
8
|
+
// server that issues its own tokens ignores it once its transition window for unsigned ids has ended.
|
|
9
|
+
let provisional = null;
|
|
10
|
+
const ready = (async () => {
|
|
11
|
+
if (!storage)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
const stored = await storage.get();
|
|
15
|
+
if (stored && token === null) {
|
|
16
|
+
token = stored;
|
|
17
|
+
persisted = stored;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// A broken adapter must not stop a form rendering.
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
async function removeStored() {
|
|
25
|
+
persisted = null;
|
|
26
|
+
if (!storage)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
await storage.remove();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Same: never fail the form over storage.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
get token() {
|
|
37
|
+
return token;
|
|
38
|
+
},
|
|
39
|
+
get consent() {
|
|
40
|
+
return consent;
|
|
41
|
+
},
|
|
42
|
+
ready,
|
|
43
|
+
setConsent(next) {
|
|
44
|
+
consentOptions = { ...next };
|
|
45
|
+
if (next.cmp === 'denied') {
|
|
46
|
+
token = null;
|
|
47
|
+
consent = null;
|
|
48
|
+
void removeStored();
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
async requestFields() {
|
|
52
|
+
await ready;
|
|
53
|
+
provisional ??= newProvisionalId();
|
|
54
|
+
return {
|
|
55
|
+
visitor: token ?? provisional,
|
|
56
|
+
consent: {
|
|
57
|
+
cmp: consentOptions.cmp ?? null,
|
|
58
|
+
gpc: consentOptions.gpc ?? detectGlobalPrivacyControl(),
|
|
59
|
+
dnt: consentOptions.dnt ?? detectDoNotTrack(),
|
|
60
|
+
cmpString: consentOptions.cmpString ?? null,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
receive(responseBody) {
|
|
65
|
+
const body = isRecord(responseBody) ? responseBody : {};
|
|
66
|
+
if (typeof body.visitor === 'string' && body.visitor) {
|
|
67
|
+
token = body.visitor;
|
|
68
|
+
}
|
|
69
|
+
const reported = readConsent(body.consent);
|
|
70
|
+
consent = reported;
|
|
71
|
+
if (reported?.recognition === 'granted' && token) {
|
|
72
|
+
if (token !== persisted) {
|
|
73
|
+
const toPersist = token;
|
|
74
|
+
persisted = toPersist;
|
|
75
|
+
if (storage) {
|
|
76
|
+
void Promise.resolve()
|
|
77
|
+
.then(() => storage.set(toPersist))
|
|
78
|
+
.catch(() => { });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Denied, or no consent member at all (an older server): nothing is persisted, anything stored is removed.
|
|
84
|
+
void removeStored();
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
async forget(form, doFetch = globalThis.fetch) {
|
|
88
|
+
await ready;
|
|
89
|
+
const url = forgetUrlFromSubmissionUrl(form.submissionUrl);
|
|
90
|
+
let message = null;
|
|
91
|
+
if (url !== undefined && token !== null) {
|
|
92
|
+
try {
|
|
93
|
+
const response = await doFetch(url, {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: { 'Content-Type': 'application/json' },
|
|
96
|
+
body: JSON.stringify({ visitor: token }),
|
|
97
|
+
});
|
|
98
|
+
if (response.ok) {
|
|
99
|
+
const body = (await response.json().catch(() => null));
|
|
100
|
+
message = typeof body?.message === 'string' ? body.message : null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Forgetting locally still happens below: the respondent asked for it.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
token = null;
|
|
108
|
+
provisional = null;
|
|
109
|
+
consent = null;
|
|
110
|
+
await removeStored();
|
|
111
|
+
return message;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** The forget endpoint that sits beside a form's public submission endpoint, or `undefined` for an address of another shape. */
|
|
116
|
+
export function forgetUrlFromSubmissionUrl(submissionUrl) {
|
|
117
|
+
const suffix = '/submissions';
|
|
118
|
+
return submissionUrl.endsWith(suffix) ? `${submissionUrl.slice(0, -suffix.length)}/forget` : undefined;
|
|
119
|
+
}
|
|
120
|
+
function detectGlobalPrivacyControl() {
|
|
121
|
+
return typeof navigator !== 'undefined' && navigator.globalPrivacyControl === true;
|
|
122
|
+
}
|
|
123
|
+
function detectDoNotTrack() {
|
|
124
|
+
return typeof navigator !== 'undefined' && navigator.doNotTrack === '1';
|
|
125
|
+
}
|
|
126
|
+
function newProvisionalId() {
|
|
127
|
+
return globalThis.crypto.randomUUID();
|
|
128
|
+
}
|
|
129
|
+
function isRecord(value) {
|
|
130
|
+
return typeof value === 'object' && value !== null;
|
|
131
|
+
}
|
|
132
|
+
function readConsent(value) {
|
|
133
|
+
if (!isRecord(value))
|
|
134
|
+
return null;
|
|
135
|
+
const recognition = value.recognition;
|
|
136
|
+
if (recognition !== 'granted' && recognition !== 'denied')
|
|
137
|
+
return null;
|
|
138
|
+
const messages = isRecord(value.messages) ? value.messages : {};
|
|
139
|
+
return {
|
|
140
|
+
recognition,
|
|
141
|
+
source: typeof value.source === 'string' ? value.source : '',
|
|
142
|
+
policyVersion: typeof value.policyVersion === 'number' ? value.policyVersion : 0,
|
|
143
|
+
tokenKind: value.tokenKind === 'session' ? 'session' : 'recognition',
|
|
144
|
+
tokenLifetimeSeconds: typeof value.tokenLifetimeSeconds === 'number' ? value.tokenLifetimeSeconds : 0,
|
|
145
|
+
messages: {
|
|
146
|
+
recognitionDeclined: typeof messages.recognitionDeclined === 'string' ? messages.recognitionDeclined : '',
|
|
147
|
+
forgetConfirm: typeof messages.forgetConfirm === 'string' ? messages.forgetConfirm : '',
|
|
148
|
+
forgetDone: typeof messages.forgetDone === 'string' ? messages.forgetDone : '',
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitor.js","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":"AAmEA,MAAM,UAAU,oBAAoB,CAAC,UAAiC,EAAE;IACtE,MAAM,EAAE,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AS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa;QACpE,oBAAoB,EAAE,OAAO,KAAK,CAAC,oBAAoB,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;QACrG,QAAQ,EAAE;YACR,mBAAmB,EAAE,OAAO,QAAQ,CAAC,mBAAmB,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE;YACzG,aAAa,EAAE,OAAO,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE;YACvF,UAAU,EAAE,OAAO,QAAQ,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;SAC/E;KACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The persistent visitor id the public submission endpoint uses to reconcile a respondent's
|
|
3
|
-
* progress across steps.
|
|
4
|
-
*
|
|
5
|
-
* It serves the same purpose as the visitor id ebitex's own hosted form page keeps, implemented here
|
|
6
|
-
* so this package depends on nothing but React: its consumers are arbitrary external apps with their
|
|
7
|
-
* own bundlers and design systems.
|
|
8
|
-
*
|
|
9
|
-
* Note the id is scoped to *your* site's origin, not ebitex's, because nothing here loads in an
|
|
10
|
-
* iframe. A respondent who fills the same form on two different sites is therefore two visitors.
|
|
11
|
-
*
|
|
12
|
-
* Never throws. Storage access can fail outright under some privacy settings, and a form that
|
|
13
|
-
* refuses to render because it couldn't save an id would be a far worse outcome than one that
|
|
14
|
-
* simply can't reconcile progress.
|
|
15
|
-
*/
|
|
16
|
-
export declare function getOrCreateVisitorId(): string;
|
|
17
|
-
/** Test seam — resets the in-memory fallback between cases. */
|
|
18
|
-
export declare function resetVisitorIdFallbackForTests(): void;
|
|
19
|
-
//# sourceMappingURL=visitorId.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visitorId.d.ts","sourceRoot":"","sources":["../../src/react/visitorId.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAY7C;AAED,+DAA+D;AAC/D,wBAAgB,8BAA8B,IAAI,IAAI,CAErD"}
|
package/dist/react/visitorId.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const STORAGE_KEY = 'ebitex.visitor-id';
|
|
2
|
-
/**
|
|
3
|
-
* Held for the life of the page when storage is unavailable, so a respondent in a privacy-mode
|
|
4
|
-
* browser still gets consistent behaviour *within* one visit (a multi-step form keeps accumulating
|
|
5
|
-
* into one submission) even though nothing persists across visits.
|
|
6
|
-
*/
|
|
7
|
-
let inMemoryFallback = null;
|
|
8
|
-
/**
|
|
9
|
-
* The persistent visitor id the public submission endpoint uses to reconcile a respondent's
|
|
10
|
-
* progress across steps.
|
|
11
|
-
*
|
|
12
|
-
* It serves the same purpose as the visitor id ebitex's own hosted form page keeps, implemented here
|
|
13
|
-
* so this package depends on nothing but React: its consumers are arbitrary external apps with their
|
|
14
|
-
* own bundlers and design systems.
|
|
15
|
-
*
|
|
16
|
-
* Note the id is scoped to *your* site's origin, not ebitex's, because nothing here loads in an
|
|
17
|
-
* iframe. A respondent who fills the same form on two different sites is therefore two visitors.
|
|
18
|
-
*
|
|
19
|
-
* Never throws. Storage access can fail outright under some privacy settings, and a form that
|
|
20
|
-
* refuses to render because it couldn't save an id would be a far worse outcome than one that
|
|
21
|
-
* simply can't reconcile progress.
|
|
22
|
-
*/
|
|
23
|
-
export function getOrCreateVisitorId() {
|
|
24
|
-
try {
|
|
25
|
-
const existing = window.localStorage.getItem(STORAGE_KEY);
|
|
26
|
-
if (existing)
|
|
27
|
-
return existing;
|
|
28
|
-
const created = crypto.randomUUID();
|
|
29
|
-
window.localStorage.setItem(STORAGE_KEY, created);
|
|
30
|
-
return created;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
inMemoryFallback ??= crypto.randomUUID();
|
|
34
|
-
return inMemoryFallback;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/** Test seam — resets the in-memory fallback between cases. */
|
|
38
|
-
export function resetVisitorIdFallbackForTests() {
|
|
39
|
-
inMemoryFallback = null;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=visitorId.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visitorId.js","sourceRoot":"","sources":["../../src/react/visitorId.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,mBAAmB,CAAA;AAEvC;;;;GAIG;AACH,IAAI,gBAAgB,GAAkB,IAAI,CAAA;AAE1C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,oBAAoB;IAClC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QACzD,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAA;QAE7B,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAA;QACnC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;QACjD,OAAO,OAAO,CAAA;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,gBAAgB,KAAK,MAAM,CAAC,UAAU,EAAE,CAAA;QACxC,OAAO,gBAAgB,CAAA;IACzB,CAAC;AACH,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,8BAA8B;IAC5C,gBAAgB,GAAG,IAAI,CAAA;AACzB,CAAC"}
|