@adobe-commerce/recaptcha 1.2.2 → 1.3.0-alpha-20260818101543

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @adobe-commerce/recaptcha
2
2
 
3
+ ## 1.3.0-alpha-20260818101543
4
+
5
+ ### Minor Changes
6
+
7
+ - 383aafe: reCAPTCHA form types are now configurable via feature flag. COMPANY_CREATE is no
8
+ longer in the default form-type map. B2B storefronts pass `{ b2bEnabled: true }`
9
+ to `setConfig()` to include it in the configuration query.
10
+
3
11
  ## 1.2.2
4
12
 
5
13
  ### Patch Changes
@@ -19,6 +27,7 @@
19
27
  ## What changed
20
28
 
21
29
  ### TypeScript 4.7 → 6.0
30
+
22
31
  - `tsconfig-base.json` updated with correct TS 6 defaults. Two new-default opt-outs are deferred as tech debt: `exactOptionalPropertyTypes` and `verbatimModuleSyntax`.
23
32
  - `moduleResolution` changed from `"nodenext"` to `"bundler"` across all packages — the correct pairing for `module: "esnext"` in a Vite monorepo. Only `packages/elsie` keeps `"NodeNext"` (paired with `module: "NodeNext"` for its dual CJS/ESM output).
24
33
  - `baseUrl` removed from all tsconfigs (deprecated in TS 6; `paths` resolves relative to the tsconfig file directly).
@@ -28,6 +37,7 @@
28
37
  - `noUncheckedIndexedAccess` enabled — violations were few enough to fix in source.
29
38
 
30
39
  ### ESLint 8 → 9 (flat config)
40
+
31
41
  - `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` (v5) removed; replaced by the unified `typescript-eslint` v8 package.
32
42
  - `eslint-config-preact` bumped to `^2.0.0` (ESLint 9 support).
33
43
  - `eslint-config-prettier` bumped to `^10.0.0`.
@@ -88,6 +98,7 @@
88
98
  ## What changed
89
99
 
90
100
  ### TypeScript 4.7 → 6.0
101
+
91
102
  - `tsconfig-base.json` updated with correct TS 6 defaults. Two new-default opt-outs are deferred as tech debt: `exactOptionalPropertyTypes` and `verbatimModuleSyntax`.
92
103
  - `moduleResolution` changed from `"nodenext"` to `"bundler"` across all packages — the correct pairing for `module: "esnext"` in a Vite monorepo. Only `packages/elsie` keeps `"NodeNext"` (paired with `module: "NodeNext"` for its dual CJS/ESM output).
93
104
  - `baseUrl` removed from all tsconfigs (deprecated in TS 6; `paths` resolves relative to the tsconfig file directly).
@@ -97,6 +108,7 @@
97
108
  - `noUncheckedIndexedAccess` enabled — violations were few enough to fix in source.
98
109
 
99
110
  ### ESLint 8 → 9 (flat config)
111
+
100
112
  - `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` (v5) removed; replaced by the unified `typescript-eslint` v8 package.
101
113
  - `eslint-config-preact` bumped to `^2.0.0` (ESLint 9 support).
102
114
  - `eslint-config-prettier` bumped to `^10.0.0`.
package/README.md CHANGED
@@ -36,21 +36,24 @@ const token = await verifyReCaptcha();
36
36
 
37
37
  Sets the GraphQL endpoint URL used to fetch reCAPTCHA configuration.
38
38
 
39
- ### `setConfig(configList: PropsFormTypes[])`
39
+ ### `setConfig(configList: PropsFormTypes[], options?: { b2bEnabled?: boolean })`
40
40
 
41
41
  Fetches reCAPTCHA configuration from the backend via `recaptchaFormConfig` and stores it in session storage.
42
42
 
43
- - Queries all known form types and determines which are enabled
43
+ - Queries all default form types and determines which are enabled
44
+ - When `options.b2bEnabled` is `true`, includes `COMPANY_CREATE` in the query —
45
+ this form type is **not** included by default
44
46
  - Normalizes the response into a unified config shape
45
47
  - Detects the reCAPTCHA type (v3 or Enterprise) from the `re_captcha_type` field
46
48
  - Skips forms with empty `website_key`
47
49
  - Warns and disables reCAPTCHA if mixed types (both v3 and Enterprise) are detected across forms
48
50
 
49
51
  ```typescript
50
- await setConfig([
51
- { badgeId: 'generateCustomerToken' },
52
- { badgeId: 'contactUs' },
53
- ]);
52
+ // B2C storefront (default)
53
+ await setConfig([{ badgeId: 'generateCustomerToken' }]);
54
+
55
+ // B2B storefront
56
+ await setConfig([], { b2bEnabled: true });
54
57
  ```
55
58
 
56
59
  ### `initReCaptcha(lazyLoadTimeout?: number)`
@@ -79,22 +82,33 @@ Enables or disables debug logging. When enabled, logs are prefixed with `[ReCapt
79
82
  - Token generation attempts
80
83
  - Warnings for skipped forms (missing keys) or mixed type configurations
81
84
 
82
- ## Supported Form Types
83
-
84
- The module queries these form types from the backend:
85
-
86
- | Form Type | Badge ID |
87
- |---|---|
88
- | `PLACE_ORDER` | `placeOrder` |
89
- | `CONTACT` | `contactUs` |
90
- | `CUSTOMER_LOGIN` | `generateCustomerToken` |
91
- | `CUSTOMER_FORGOT_PASSWORD` | `requestPasswordResetEmail` |
92
- | `CUSTOMER_CREATE` | `createCustomerV2` |
93
- | `CUSTOMER_EDIT` | `updateCustomerV2` |
94
- | `NEWSLETTER` | `subscribeEmailToNewsletter` |
95
- | `PRODUCT_REVIEW` | `createProductReview` |
96
- | `SENDFRIEND` | `SENDFRIEND` |
97
- | `BRAINTREE` | `BRAINTREE` |
85
+ ## Default Form Types
86
+
87
+ These form types are queried by default (no additional configuration needed):
88
+
89
+ | Form Type | Badge ID |
90
+ | -------------------------- | ---------------------------- |
91
+ | `PLACE_ORDER` | `placeOrder` |
92
+ | `CONTACT` | `contactUs` |
93
+ | `CUSTOMER_LOGIN` | `generateCustomerToken` |
94
+ | `CUSTOMER_FORGOT_PASSWORD` | `requestPasswordResetEmail` |
95
+ | `CUSTOMER_CREATE` | `createCustomerV2` |
96
+ | `CUSTOMER_EDIT` | `updateCustomerV2` |
97
+ | `NEWSLETTER` | `subscribeEmailToNewsletter` |
98
+ | `PRODUCT_REVIEW` | `createProductReview` |
99
+ | `SENDFRIEND` | `SENDFRIEND` |
100
+ | `BRAINTREE` | `BRAINTREE` |
101
+
102
+ ## B2B Form Types
103
+
104
+ B2B storefronts should pass `{ b2bEnabled: true }` to include `COMPANY_CREATE`
105
+ in the reCAPTCHA query:
106
+
107
+ ```typescript
108
+ await setConfig([], { b2bEnabled: true });
109
+ ```
110
+
111
+ This requires the backend to expose `COMPANY_CREATE` in `ReCaptchaFormEnum`.
98
112
 
99
113
  ## Mixed Type Configuration
100
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe-commerce/recaptcha",
3
- "version": "1.2.2",
3
+ "version": "1.3.0-alpha-20260818101543",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "description": "Module allows to efficiently verify that users are humans, not bots or spammers",
6
6
  "type": "module",
@@ -7,7 +7,12 @@
7
7
  * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
- export const typeDefaultForm: Record<string, string> = {
10
+ /**
11
+ * All known reCAPTCHA form types and their associated GraphQL mutation names.
12
+ * Keys = form type identifiers (matching ReCaptchaFormEnum on the backend).
13
+ * Values = mutation names used for badge mapping.
14
+ */
15
+ export const RECAPTCHA_FORMS = {
11
16
  PLACE_ORDER: 'placeOrder',
12
17
  CONTACT: 'contactUs',
13
18
  CUSTOMER_LOGIN: 'generateCustomerToken',
@@ -18,4 +23,23 @@ export const typeDefaultForm: Record<string, string> = {
18
23
  PRODUCT_REVIEW: 'createProductReview',
19
24
  SENDFRIEND: 'SENDFRIEND',
20
25
  BRAINTREE: 'BRAINTREE',
26
+ COMPANY_CREATE: 'createCompany',
27
+ } as const;
28
+
29
+ /**
30
+ * Default form-type → mutation mapping.
31
+ * Only base (non-B2B) forms live here. B2B forms are included conditionally
32
+ * via the `b2bEnabled` option in `setConfig()`.
33
+ */
34
+ export const typeDefaultForm: Record<string, string> = {
35
+ PLACE_ORDER: RECAPTCHA_FORMS.PLACE_ORDER,
36
+ CONTACT: RECAPTCHA_FORMS.CONTACT,
37
+ CUSTOMER_LOGIN: RECAPTCHA_FORMS.CUSTOMER_LOGIN,
38
+ CUSTOMER_FORGOT_PASSWORD: RECAPTCHA_FORMS.CUSTOMER_FORGOT_PASSWORD,
39
+ CUSTOMER_CREATE: RECAPTCHA_FORMS.CUSTOMER_CREATE,
40
+ CUSTOMER_EDIT: RECAPTCHA_FORMS.CUSTOMER_EDIT,
41
+ NEWSLETTER: RECAPTCHA_FORMS.NEWSLETTER,
42
+ PRODUCT_REVIEW: RECAPTCHA_FORMS.PRODUCT_REVIEW,
43
+ SENDFRIEND: RECAPTCHA_FORMS.SENDFRIEND,
44
+ BRAINTREE: RECAPTCHA_FORMS.BRAINTREE,
21
45
  };
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  recaptchaMessage,
18
18
  recaptchaBadgeSelector,
19
19
  typeDefaultForm,
20
+ RECAPTCHA_FORMS,
20
21
  } from './configs';
21
22
  import {
22
23
  extendConfig,
@@ -203,9 +204,16 @@ export class RecaptchaModule {
203
204
  }
204
205
  }
205
206
 
206
- async _fetchStoreConfig(): Promise<ReCaptchaResponse | undefined> {
207
+ async _fetchStoreConfig(options?: {
208
+ b2bEnabled?: boolean;
209
+ }): Promise<ReCaptchaResponse | undefined> {
207
210
  try {
208
- const formTypes = Object.keys(typeDefaultForm);
211
+ const formTypes = Object.keys({
212
+ ...typeDefaultForm,
213
+ ...(options?.b2bEnabled
214
+ ? { COMPANY_CREATE: RECAPTCHA_FORMS.COMPANY_CREATE }
215
+ : {}),
216
+ });
209
217
  const query = buildRecaptchaFormConfigQuery(formTypes);
210
218
 
211
219
  this._log(`Fetching config for forms: ${formTypes.join(', ')}`);
@@ -248,9 +256,12 @@ export class RecaptchaModule {
248
256
  recaptchaFetchApi.setEndpoint(url);
249
257
  }
250
258
 
251
- async setConfig(configList: PropsFormTypes[]) {
259
+ async setConfig(
260
+ configList: PropsFormTypes[],
261
+ options?: { b2bEnabled?: boolean },
262
+ ) {
252
263
  try {
253
- const config = await this._fetchStoreConfig();
264
+ const config = await this._fetchStoreConfig(options);
254
265
 
255
266
  if (!config?.data?.recaptchaConfig) {
256
267
  this._log('No reCAPTCHA config returned, clearing storage');
@@ -367,3 +378,4 @@ const { initReCaptcha, verifyReCaptcha, setEndpoint, setConfig, enableLogger } =
367
378
  recaptcha.getMethods();
368
379
 
369
380
  export { setEndpoint, setConfig, initReCaptcha, verifyReCaptcha, enableLogger };
381
+ export { RECAPTCHA_FORMS };
@@ -8,7 +8,7 @@
8
8
  *******************************************************************/
9
9
 
10
10
  import { ReCaptchaModel } from '../types/recaptcha.types';
11
- import { typeDefaultForm } from '../configs/typeForms.config';
11
+ import { typeDefaultForm, RECAPTCHA_FORMS } from '../configs/typeForms.config';
12
12
 
13
13
  export const extendConfig = (
14
14
  config: ReCaptchaModel,
@@ -19,7 +19,9 @@ export const extendConfig = (
19
19
  if (typeof el !== 'string') return { ...el, enabledBadgePlace: false };
20
20
 
21
21
  return {
22
- badgeId: typeDefaultForm[el],
22
+ badgeId:
23
+ typeDefaultForm[el] ??
24
+ RECAPTCHA_FORMS[el as keyof typeof RECAPTCHA_FORMS],
23
25
  enabledBadgePlace: false,
24
26
  };
25
27
  });