@se-studio/hubspot 1.0.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 (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +92 -0
  3. package/dist/external/createHubspotFormExternalRenderer.d.ts +23 -0
  4. package/dist/external/createHubspotFormExternalRenderer.d.ts.map +1 -0
  5. package/dist/external/createHubspotFormExternalRenderer.js +26 -0
  6. package/dist/external/createHubspotFormExternalRenderer.js.map +1 -0
  7. package/dist/forms/client/HubspotDynamicForm.d.ts +13 -0
  8. package/dist/forms/client/HubspotDynamicForm.d.ts.map +1 -0
  9. package/dist/forms/client/HubspotDynamicForm.js +101 -0
  10. package/dist/forms/client/HubspotDynamicForm.js.map +1 -0
  11. package/dist/forms/client/dependentFields.d.ts +11 -0
  12. package/dist/forms/client/dependentFields.d.ts.map +1 -0
  13. package/dist/forms/client/dependentFields.js +39 -0
  14. package/dist/forms/client/dependentFields.js.map +1 -0
  15. package/dist/forms/client/getCookieValue.d.ts +2 -0
  16. package/dist/forms/client/getCookieValue.d.ts.map +1 -0
  17. package/dist/forms/client/getCookieValue.js +8 -0
  18. package/dist/forms/client/getCookieValue.js.map +1 -0
  19. package/dist/forms/client/renderHubspotField.d.ts +11 -0
  20. package/dist/forms/client/renderHubspotField.d.ts.map +1 -0
  21. package/dist/forms/client/renderHubspotField.js +61 -0
  22. package/dist/forms/client/renderHubspotField.js.map +1 -0
  23. package/dist/forms/client/useHubspotSubmit.d.ts +15 -0
  24. package/dist/forms/client/useHubspotSubmit.d.ts.map +1 -0
  25. package/dist/forms/client/useHubspotSubmit.js +93 -0
  26. package/dist/forms/client/useHubspotSubmit.js.map +1 -0
  27. package/dist/forms/server/getFormDefinition.d.ts +7 -0
  28. package/dist/forms/server/getFormDefinition.d.ts.map +1 -0
  29. package/dist/forms/server/getFormDefinition.js +24 -0
  30. package/dist/forms/server/getFormDefinition.js.map +1 -0
  31. package/dist/forms/server/hubspotFormTag.d.ts +3 -0
  32. package/dist/forms/server/hubspotFormTag.d.ts.map +1 -0
  33. package/dist/forms/server/hubspotFormTag.js +5 -0
  34. package/dist/forms/server/hubspotFormTag.js.map +1 -0
  35. package/dist/forms/server/mapApiResponse.d.ts +4 -0
  36. package/dist/forms/server/mapApiResponse.d.ts.map +1 -0
  37. package/dist/forms/server/mapApiResponse.js +91 -0
  38. package/dist/forms/server/mapApiResponse.js.map +1 -0
  39. package/dist/forms/server/submitForm.d.ts +8 -0
  40. package/dist/forms/server/submitForm.d.ts.map +1 -0
  41. package/dist/forms/server/submitForm.js +32 -0
  42. package/dist/forms/server/submitForm.js.map +1 -0
  43. package/dist/forms/types.d.ts +102 -0
  44. package/dist/forms/types.d.ts.map +1 -0
  45. package/dist/forms/types.js +2 -0
  46. package/dist/forms/types.js.map +1 -0
  47. package/dist/index.d.ts +9 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +5 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/server.d.ts +7 -0
  52. package/dist/server.d.ts.map +1 -0
  53. package/dist/server.js +6 -0
  54. package/dist/server.js.map +1 -0
  55. package/dist/tracking/HubSpotAnalyticsAdapter.d.ts +23 -0
  56. package/dist/tracking/HubSpotAnalyticsAdapter.d.ts.map +1 -0
  57. package/dist/tracking/HubSpotAnalyticsAdapter.js +84 -0
  58. package/dist/tracking/HubSpotAnalyticsAdapter.js.map +1 -0
  59. package/dist/tracking/createHubSpotBootstrapScript.d.ts +6 -0
  60. package/dist/tracking/createHubSpotBootstrapScript.d.ts.map +1 -0
  61. package/dist/tracking/createHubSpotBootstrapScript.js +10 -0
  62. package/dist/tracking/createHubSpotBootstrapScript.js.map +1 -0
  63. package/docs/llms.md +24 -0
  64. package/package.json +76 -0
@@ -0,0 +1,24 @@
1
+ import 'server-only';
2
+ import { Client } from '@hubspot/api-client';
3
+ import { unstable_cache } from 'next/cache';
4
+ import { hubspotFormTag } from './hubspotFormTag';
5
+ import { mapApiResponseToFormDefinition } from './mapApiResponse';
6
+ async function fetchFormDefinition(formId) {
7
+ const accessToken = process.env.HUBSPOT_PAT;
8
+ if (!accessToken) {
9
+ throw new Error('Missing HUBSPOT_PAT environment variable');
10
+ }
11
+ const client = new Client({ accessToken });
12
+ const response = await client.marketing.forms.formsApi.getById(formId);
13
+ return mapApiResponseToFormDefinition(response);
14
+ }
15
+ /**
16
+ * Fetch a single HubSpot form definition by ID (cached per form).
17
+ */
18
+ export async function getHubspotFormDefinition(formId) {
19
+ return unstable_cache(async () => fetchFormDefinition(formId), ['hubspot-form', formId], {
20
+ revalidate: 3600,
21
+ tags: [hubspotFormTag(formId)],
22
+ })();
23
+ }
24
+ //# sourceMappingURL=getFormDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFormDefinition.js","sourceRoot":"","sources":["../../../src/forms/server/getFormDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAElE,KAAK,UAAU,mBAAmB,CAAC,MAAc;IAC/C,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAC5C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,OAAO,8BAA8B,CAAC,QAA8C,CAAC,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,MAAc;IAEd,OAAO,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE;QACvF,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;KAC/B,CAAC,EAAE,CAAC;AACP,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const HUBSPOT_FORMS_CACHE_TAG_PREFIX = "hubspot-form";
2
+ export declare function hubspotFormTag(formId: string): string;
3
+ //# sourceMappingURL=hubspotFormTag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hubspotFormTag.d.ts","sourceRoot":"","sources":["../../../src/forms/server/hubspotFormTag.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,iBAAiB,CAAC;AAE7D,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -0,0 +1,5 @@
1
+ export const HUBSPOT_FORMS_CACHE_TAG_PREFIX = 'hubspot-form';
2
+ export function hubspotFormTag(formId) {
3
+ return `${HUBSPOT_FORMS_CACHE_TAG_PREFIX}#${formId}`;
4
+ }
5
+ //# sourceMappingURL=hubspotFormTag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hubspotFormTag.js","sourceRoot":"","sources":["../../../src/forms/server/hubspotFormTag.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,8BAA8B,GAAG,cAAc,CAAC;AAE7D,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,GAAG,8BAA8B,IAAI,MAAM,EAAE,CAAC;AACvD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { HubspotFormDefinition } from '../types';
2
+ /** Map a HubSpot Marketing Forms API response to the package's internal definition type. */
3
+ export declare function mapApiResponseToFormDefinition(raw: Record<string, unknown>): HubspotFormDefinition;
4
+ //# sourceMappingURL=mapApiResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapApiResponse.d.ts","sourceRoot":"","sources":["../../../src/forms/server/mapApiResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,qBAAqB,EAGtB,MAAM,UAAU,CAAC;AA4ElB,4FAA4F;AAC5F,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,qBAAqB,CAsBvB"}
@@ -0,0 +1,91 @@
1
+ function mapField(raw) {
2
+ const dependentFields = Array.isArray(raw.dependentFields)
3
+ ? raw.dependentFields.map((dep) => ({
4
+ dependentCondition: dep.dependentCondition,
5
+ dependentField: mapField(dep.dependentField),
6
+ }))
7
+ : undefined;
8
+ return {
9
+ name: String(raw.name ?? ''),
10
+ label: String(raw.label ?? ''),
11
+ description: raw.description ? String(raw.description) : undefined,
12
+ fieldType: String(raw.fieldType ?? ''),
13
+ objectTypeId: String(raw.objectTypeId ?? '0-1'),
14
+ required: Boolean(raw.required),
15
+ hidden: Boolean(raw.hidden),
16
+ options: Array.isArray(raw.options)
17
+ ? raw.options.map((option) => ({
18
+ label: String(option.label ?? ''),
19
+ value: String(option.value ?? ''),
20
+ }))
21
+ : undefined,
22
+ defaultValue: raw.defaultValue ? String(raw.defaultValue) : undefined,
23
+ defaultValues: Array.isArray(raw.defaultValues)
24
+ ? raw.defaultValues.map(String)
25
+ : undefined,
26
+ dependentFields,
27
+ };
28
+ }
29
+ function mapFieldGroup(raw) {
30
+ return {
31
+ groupType: String(raw.groupType ?? 'default_group'),
32
+ richText: raw.richText ? String(raw.richText) : undefined,
33
+ richTextType: raw.richTextType ? String(raw.richTextType) : undefined,
34
+ fields: Array.isArray(raw.fields)
35
+ ? raw.fields.map(mapField)
36
+ : [],
37
+ };
38
+ }
39
+ function mapLegalConsent(raw) {
40
+ if (!raw || typeof raw !== 'object') {
41
+ return null;
42
+ }
43
+ const consent = raw;
44
+ const type = String(consent.type ?? 'none');
45
+ if (type === 'none') {
46
+ return null;
47
+ }
48
+ return {
49
+ type,
50
+ privacyText: consent.privacyText ? String(consent.privacyText) : undefined,
51
+ consentToProcessText: consent.consentToProcessText
52
+ ? String(consent.consentToProcessText)
53
+ : undefined,
54
+ consentToProcessCheckboxLabel: consent.consentToProcessCheckboxLabel
55
+ ? String(consent.consentToProcessCheckboxLabel)
56
+ : undefined,
57
+ communicationsCheckboxes: Array.isArray(consent.communicationsCheckboxes)
58
+ ? consent.communicationsCheckboxes.map((checkbox) => ({
59
+ label: String(checkbox.label ?? ''),
60
+ required: Boolean(checkbox.required),
61
+ subscriptionTypeId: typeof checkbox.subscriptionTypeId === 'number'
62
+ ? checkbox.subscriptionTypeId
63
+ : undefined,
64
+ }))
65
+ : undefined,
66
+ };
67
+ }
68
+ /** Map a HubSpot Marketing Forms API response to the package's internal definition type. */
69
+ export function mapApiResponseToFormDefinition(raw) {
70
+ const configuration = (raw.configuration ?? {});
71
+ const displayOptions = (raw.displayOptions ?? {});
72
+ const postSubmitAction = (configuration.postSubmitAction ?? {
73
+ type: 'thank_you',
74
+ value: 'Thank you for submitting the form.',
75
+ });
76
+ return {
77
+ id: String(raw.id ?? ''),
78
+ name: String(raw.name ?? ''),
79
+ fieldGroups: Array.isArray(raw.fieldGroups)
80
+ ? raw.fieldGroups.map(mapFieldGroup)
81
+ : [],
82
+ legalConsentOptions: mapLegalConsent(raw.legalConsentOptions),
83
+ submitButtonText: String(displayOptions.submitButtonText ?? 'Submit'),
84
+ postSubmitAction: {
85
+ type: postSubmitAction.type ?? 'thank_you',
86
+ value: String(postSubmitAction.value ?? ''),
87
+ },
88
+ recaptchaEnabled: Boolean(configuration.recaptchaEnabled),
89
+ };
90
+ }
91
+ //# sourceMappingURL=mapApiResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapApiResponse.js","sourceRoot":"","sources":["../../../src/forms/server/mapApiResponse.ts"],"names":[],"mappings":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AAW,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;YACzC,CAAC,CAAE,GAAG,CAAC,WAAyC,CAAC,GAAG,CAAC,aAAa,CAAC;YACnE,CAAC,CAAC,EAAE;QACN,mBAAmB,EAAE,eAAe,CAAC,GAAG,CAAC,mBAAmB,CAAC;QAC7D,gBAAgB,EAAE,MAAM,CAAC,cAAc,CAAC,gBAAgB,IAAI,QAAQ,CAAC;QACrE,gBAAgB,EAAE;YAChB,IAAI,EAAG,gBAAgB,CAAC,IAAqC,IAAI,WAAW;YAC5E,KAAK,EAAE,MAAM,CAAC,gBAAgB,CAAC,KAAK,IAAI,EAAE,CAAC;SAC5C;QACD,gBAAgB,EAAE,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC;KAC1D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { HubspotFieldResponse, HubspotFormContext, HubspotFormSubmissionResponse } from '../types';
2
+ export interface SubmitHubspotFormResult {
3
+ success?: boolean;
4
+ failure?: string;
5
+ data?: HubspotFormSubmissionResponse;
6
+ }
7
+ export declare function submitHubspotForm(portalId: string, formId: string, fields: HubspotFieldResponse[], context: HubspotFormContext, formStartTime: number, formEndTime: number): Promise<SubmitHubspotFormResult>;
8
+ //# sourceMappingURL=submitForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submitForm.d.ts","sourceRoot":"","sources":["../../../src/forms/server/submitForm.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,6BAA6B,EAC9B,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,6BAA6B,CAAC;CACtC;AAED,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,oBAAoB,EAAE,EAC9B,OAAO,EAAE,kBAAkB,EAC3B,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,uBAAuB,CAAC,CAiClC"}
@@ -0,0 +1,32 @@
1
+ 'use server';
2
+ export async function submitHubspotForm(portalId, formId, fields, context, formStartTime, formEndTime) {
3
+ if (!portalId) {
4
+ return { failure: 'no portal ID' };
5
+ }
6
+ if (formStartTime === 0) {
7
+ return { success: true };
8
+ }
9
+ if (formStartTime > formEndTime) {
10
+ return { success: true };
11
+ }
12
+ if (formEndTime - formStartTime < 3000) {
13
+ return { success: true };
14
+ }
15
+ try {
16
+ const response = await fetch(`https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formId}`, {
17
+ method: 'POST',
18
+ headers: { 'Content-Type': 'application/json' },
19
+ body: JSON.stringify({ fields, context }),
20
+ });
21
+ const data = (await response.json());
22
+ if (data.redirectUri) {
23
+ const uri = new URL(data.redirectUri);
24
+ data.redirectUri = uri.pathname + uri.search;
25
+ }
26
+ return { data };
27
+ }
28
+ catch {
29
+ return { failure: 'error submitting form' };
30
+ }
31
+ }
32
+ //# sourceMappingURL=submitForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submitForm.js","sourceRoot":"","sources":["../../../src/forms/server/submitForm.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAcb,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAgB,EAChB,MAAc,EACd,MAA8B,EAC9B,OAA2B,EAC3B,aAAqB,EACrB,WAAmB;IAEnB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IACD,IAAI,aAAa,GAAG,WAAW,EAAE,CAAC;QAChC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IACD,IAAI,WAAW,GAAG,aAAa,GAAG,IAAI,EAAE,CAAC;QACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,6DAA6D,QAAQ,IAAI,MAAM,EAAE,EACjF;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;SAC1C,CACF,CAAC;QACF,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAkC,CAAC;QACtE,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACtC,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC;QAC/C,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;IAC9C,CAAC;AACH,CAAC"}
@@ -0,0 +1,102 @@
1
+ export interface HubspotFieldOption {
2
+ label: string;
3
+ value: string;
4
+ }
5
+ export interface HubspotDependentCondition {
6
+ operator: string;
7
+ values: string[];
8
+ }
9
+ export interface HubspotDependentField {
10
+ dependentCondition: HubspotDependentCondition;
11
+ dependentField: HubspotFormField;
12
+ }
13
+ export interface HubspotFormField {
14
+ name: string;
15
+ label: string;
16
+ description?: string;
17
+ fieldType: string;
18
+ objectTypeId: string;
19
+ required: boolean;
20
+ hidden: boolean;
21
+ options?: HubspotFieldOption[];
22
+ defaultValue?: string;
23
+ defaultValues?: string[];
24
+ dependentFields?: HubspotDependentField[];
25
+ }
26
+ export interface HubspotFieldGroup {
27
+ groupType: string;
28
+ richText?: string;
29
+ richTextType?: string;
30
+ fields: HubspotFormField[];
31
+ }
32
+ export interface HubspotLegalConsentCheckbox {
33
+ label: string;
34
+ required: boolean;
35
+ subscriptionTypeId?: number;
36
+ }
37
+ export interface HubspotLegalConsent {
38
+ type: string;
39
+ privacyText?: string;
40
+ consentToProcessText?: string;
41
+ consentToProcessCheckboxLabel?: string;
42
+ communicationsCheckboxes?: HubspotLegalConsentCheckbox[];
43
+ }
44
+ export interface HubspotPostSubmitAction {
45
+ type: 'redirect_url' | 'thank_you';
46
+ value: string;
47
+ }
48
+ export interface HubspotFormDefinition {
49
+ id: string;
50
+ name: string;
51
+ fieldGroups: HubspotFieldGroup[];
52
+ legalConsentOptions: HubspotLegalConsent | null;
53
+ submitButtonText: string;
54
+ postSubmitAction: HubspotPostSubmitAction;
55
+ recaptchaEnabled: boolean;
56
+ }
57
+ export interface HubspotFieldResponse {
58
+ objectTypeId: string;
59
+ name: string;
60
+ value: string | string[];
61
+ }
62
+ export interface HubspotFormContext {
63
+ hutk?: string;
64
+ ipAddress?: string;
65
+ pageName: string;
66
+ pageUri: string;
67
+ }
68
+ export interface HubspotFormSubmissionResponse {
69
+ redirectUri?: string;
70
+ inlineMessage?: string;
71
+ errors?: {
72
+ message: string;
73
+ errorType: string;
74
+ }[];
75
+ }
76
+ export interface HubspotFormExternalData {
77
+ formId: string;
78
+ portalId?: string;
79
+ submitButtonText?: string;
80
+ widthPercentage?: number;
81
+ hiddenFields?: Record<string, string>;
82
+ initialValues?: Record<string, string>;
83
+ }
84
+ export interface HubspotFormClassNames {
85
+ form?: string;
86
+ fieldGroup?: string;
87
+ field?: string;
88
+ label?: string;
89
+ description?: string;
90
+ input?: string;
91
+ textarea?: string;
92
+ select?: string;
93
+ checkboxGroup?: string;
94
+ checkboxLabel?: string;
95
+ radioGroup?: string;
96
+ radioLabel?: string;
97
+ submitButton?: string;
98
+ message?: string;
99
+ legalConsent?: string;
100
+ richText?: string;
101
+ }
102
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,EAAE,yBAAyB,CAAC;IAC9C,cAAc,EAAE,gBAAgB,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,eAAe,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,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AAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export type { HubspotDynamicFormProps } from './forms/client/HubspotDynamicForm';
2
+ export { HubspotDynamicForm } from './forms/client/HubspotDynamicForm';
3
+ export type { UseHubspotSubmitOptions } from './forms/client/useHubspotSubmit';
4
+ export { useHubspotSubmit } from './forms/client/useHubspotSubmit';
5
+ export type { HubspotFieldResponse, HubspotFormClassNames, HubspotFormContext, HubspotFormDefinition, HubspotFormExternalData, HubspotFormSubmissionResponse, } from './forms/types';
6
+ export { createHubSpotBootstrapScript } from './tracking/createHubSpotBootstrapScript';
7
+ export type { HubSpotAnalyticsAdapterConfig } from './tracking/HubSpotAnalyticsAdapter';
8
+ export { HubSpotAnalyticsAdapter } from './tracking/HubSpotAnalyticsAdapter';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,YAAY,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,YAAY,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { HubspotDynamicForm } from './forms/client/HubspotDynamicForm';
2
+ export { useHubspotSubmit } from './forms/client/useHubspotSubmit';
3
+ export { createHubSpotBootstrapScript } from './tracking/createHubSpotBootstrapScript';
4
+ export { HubSpotAnalyticsAdapter } from './tracking/HubSpotAnalyticsAdapter';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAEvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import 'server-only';
2
+ export { getHubspotFormDefinition } from './forms/server/getFormDefinition';
3
+ export { HUBSPOT_FORMS_CACHE_TAG_PREFIX, hubspotFormTag } from './forms/server/hubspotFormTag';
4
+ export { mapApiResponseToFormDefinition } from './forms/server/mapApiResponse';
5
+ export type { SubmitHubspotFormResult } from './forms/server/submitForm';
6
+ export { submitHubspotForm } from './forms/server/submitForm';
7
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAC/E,YAAY,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/server.js ADDED
@@ -0,0 +1,6 @@
1
+ import 'server-only';
2
+ export { getHubspotFormDefinition } from './forms/server/getFormDefinition';
3
+ export { HUBSPOT_FORMS_CACHE_TAG_PREFIX, hubspotFormTag } from './forms/server/hubspotFormTag';
4
+ export { mapApiResponseToFormDefinition } from './forms/server/mapApiResponse';
5
+ export { submitHubspotForm } from './forms/server/submitForm';
6
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { AnalyticsAdapter, ClickTrackingProperties, PageTrackingProperties } from '@se-studio/core-ui';
2
+ declare global {
3
+ interface Window {
4
+ _hsq?: unknown[][];
5
+ }
6
+ }
7
+ export interface HubSpotAnalyticsAdapterConfig {
8
+ portalId: string;
9
+ /** Map analytics event names to HubSpot behavioural event names. */
10
+ eventNameMap?: Record<string, string>;
11
+ /** Default behavioural event for trackClick when trackingInfo has no event name. */
12
+ defaultClickEventName?: string;
13
+ }
14
+ export declare class HubSpotAnalyticsAdapter implements AnalyticsAdapter {
15
+ private initialized;
16
+ private readonly config;
17
+ constructor(config: HubSpotAnalyticsAdapterConfig);
18
+ initialize(): void;
19
+ trackPage(_url: string, properties: PageTrackingProperties): void;
20
+ trackEvent(event: string, properties: Record<string, unknown>): void;
21
+ trackClick(properties: ClickTrackingProperties): void;
22
+ }
23
+ //# sourceMappingURL=HubSpotAnalyticsAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HubSpotAnalyticsAdapter.d.ts","sourceRoot":"","sources":["../../src/tracking/HubSpotAnalyticsAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;KACpB;CACF;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,oFAAoF;IACpF,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AA8BD,qBAAa,uBAAwB,YAAW,gBAAgB;IAC9D,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;gBAE3C,MAAM,EAAE,6BAA6B;IAIjD,UAAU,IAAI,IAAI;IAwBlB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,sBAAsB,GAAG,IAAI;IAKjE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAepE,UAAU,CAAC,UAAU,EAAE,uBAAuB,GAAG,IAAI;CAsBtD"}
@@ -0,0 +1,84 @@
1
+ 'use client';
2
+ function pushHsq(args) {
3
+ if (typeof window === 'undefined') {
4
+ return;
5
+ }
6
+ window._hsq = window._hsq || [];
7
+ window._hsq.push(args);
8
+ }
9
+ function getHubspotEventName(event, properties, eventNameMap) {
10
+ const fromProps = properties.hubspotEvent ||
11
+ properties.hubspot_event;
12
+ if (fromProps) {
13
+ return fromProps;
14
+ }
15
+ const trackingInfo = properties.trackingInfo;
16
+ if (trackingInfo?.trackingEventName) {
17
+ return trackingInfo.trackingEventName;
18
+ }
19
+ return eventNameMap?.[event];
20
+ }
21
+ export class HubSpotAnalyticsAdapter {
22
+ initialized = false;
23
+ config;
24
+ constructor(config) {
25
+ this.config = config;
26
+ }
27
+ initialize() {
28
+ if (typeof window === 'undefined' || this.initialized) {
29
+ return;
30
+ }
31
+ const { portalId } = this.config;
32
+ if (!portalId) {
33
+ return;
34
+ }
35
+ const scriptId = 'hs-script-loader';
36
+ if (!document.getElementById(scriptId)) {
37
+ const script = document.createElement('script');
38
+ script.id = scriptId;
39
+ script.type = 'text/javascript';
40
+ script.async = true;
41
+ script.defer = true;
42
+ script.src = `https://js.hs-scripts.com/${portalId}.js`;
43
+ document.head.appendChild(script);
44
+ }
45
+ this.initialized = true;
46
+ }
47
+ trackPage(_url, properties) {
48
+ pushHsq(['setPath', properties.pathname]);
49
+ pushHsq(['trackPageView']);
50
+ }
51
+ trackEvent(event, properties) {
52
+ const hubspotEventName = getHubspotEventName(event, properties, this.config.eventNameMap);
53
+ if (!hubspotEventName) {
54
+ return;
55
+ }
56
+ pushHsq([
57
+ 'trackCustomBehavioralEvent',
58
+ {
59
+ name: hubspotEventName,
60
+ properties,
61
+ },
62
+ ]);
63
+ }
64
+ trackClick(properties) {
65
+ const hubspotEventName = properties.trackingInfo?.trackingEventName?.trim() || this.config.defaultClickEventName;
66
+ if (!hubspotEventName) {
67
+ return;
68
+ }
69
+ pushHsq([
70
+ 'trackCustomBehavioralEvent',
71
+ {
72
+ name: hubspotEventName,
73
+ properties: {
74
+ componentType: properties.componentType,
75
+ linkText: properties.linkText,
76
+ url: properties.url,
77
+ targetUrl: properties.targetUrl,
78
+ location: properties.location,
79
+ },
80
+ },
81
+ ]);
82
+ }
83
+ }
84
+ //# sourceMappingURL=HubSpotAnalyticsAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HubSpotAnalyticsAdapter.js","sourceRoot":"","sources":["../../src/tracking/HubSpotAnalyticsAdapter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAsBb,SAAS,OAAO,CAAC,IAAe;IAC9B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO;IACT,CAAC;IACD,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,mBAAmB,CAC1B,KAAa,EACb,UAAmC,EACnC,YAAqC;IAErC,MAAM,SAAS,GACZ,UAAU,CAAC,YAAmC;QAC9C,UAAU,CAAC,aAAoC,CAAC;IACnD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,YAAY,GAAG,UAAU,CAAC,YAAiE,CAAC;IAClG,IAAI,YAAY,EAAE,iBAAiB,EAAE,CAAC;QACpC,OAAO,YAAY,CAAC,iBAAiB,C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C,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC1F,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,OAAO,CAAC;YACN,4BAA4B;YAC5B;gBACE,IAAI,EAAE,gBAAgB;gBACtB,UAAU;aACX;SACF,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,UAAmC;QAC5C,MAAM,gBAAgB,GACpB,UAAU,CAAC,YAAY,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC;QAE1F,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,OAAO,CAAC;YACN,4BAA4B;YAC5B;gBACE,IAAI,EAAE,gBAAgB;gBACtB,UAAU,EAAE;oBACV,aAAa,EAAE,UAAU,CAAC,aAAa;oBACvC,QAAQ,EAAE,UAAU,CAAC,QAAQ;oBAC7B,GAAG,EAAE,UAAU,CAAC,GAAG;oBACnB,SAAS,EAAE,UAAU,CAAC,SAAS;oBAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ;iBAC9B;aACF;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Inline script for beforeInteractive: initialises _hsq and sets the path
3
+ * before the HubSpot tracking script loads (SPA Mode B).
4
+ */
5
+ export declare function createHubSpotBootstrapScript(pathname: string): string;
6
+ //# sourceMappingURL=createHubSpotBootstrapScript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHubSpotBootstrapScript.d.ts","sourceRoot":"","sources":["../../src/tracking/createHubSpotBootstrapScript.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIrE"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Inline script for beforeInteractive: initialises _hsq and sets the path
3
+ * before the HubSpot tracking script loads (SPA Mode B).
4
+ */
5
+ export function createHubSpotBootstrapScript(pathname) {
6
+ const safePath = pathname.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
7
+ return `var _hsq = window._hsq = window._hsq || [];
8
+ _hsq.push(['setPath', '${safePath}']);`;
9
+ }
10
+ //# sourceMappingURL=createHubSpotBootstrapScript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHubSpotBootstrapScript.js","sourceRoot":"","sources":["../../src/tracking/createHubSpotBootstrapScript.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAAC,QAAgB;IAC3D,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtE,OAAO;yBACgB,QAAQ,MAAM,CAAC;AACxC,CAAC"}
package/docs/llms.md ADDED
@@ -0,0 +1,24 @@
1
+ # @se-studio/hubspot — LLM reference
2
+
3
+ ## Exports
4
+
5
+ | Import | Contents |
6
+ |--------|----------|
7
+ | `@se-studio/hubspot` | `HubSpotAnalyticsAdapter`, `createHubSpotBootstrapScript`, `HubspotDynamicForm`, types |
8
+ | `@se-studio/hubspot/server` | `getHubspotFormDefinition`, `submitHubspotForm`, `hubspotFormTag` |
9
+ | `@se-studio/hubspot/external` | `createHubspotFormExternalRenderer` |
10
+
11
+ ## CMS external component
12
+
13
+ - `externalComponentType`: `"Hubspot form"`
14
+ - `data.formId` (required): HubSpot form GUID
15
+ - `data.portalId` (optional): defaults to `HUBSPOT_PORTAL_ID`
16
+
17
+ ## Analytics
18
+
19
+ Use with `CompositeAnalyticsAdapter` + `AnalyticsPageTracker` from `@se-studio/core-ui`. HubSpot SPA Mode B: bootstrap `setPath` before script load; `AnalyticsPageTracker` skips first mount.
20
+
21
+ ## Env
22
+
23
+ - `HUBSPOT_PORTAL_ID` — tracking + submit URL
24
+ - `HUBSPOT_PAT` — Marketing Forms API (server only)
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@se-studio/hubspot",
3
+ "version": "1.0.0",
4
+ "description": "HubSpot tracking and API-driven form rendering for Next.js marketing sites",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/Something-Else-Studio/se-core-product",
8
+ "directory": "packages/hubspot"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./server": {
20
+ "types": "./dist/server.d.ts",
21
+ "import": "./dist/server.js"
22
+ },
23
+ "./external": {
24
+ "types": "./dist/external/createHubspotFormExternalRenderer.d.ts",
25
+ "import": "./dist/external/createHubspotFormExternalRenderer.js"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "*.md",
31
+ "docs"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsc --project tsconfig.build.json",
35
+ "dev": "tsc --project tsconfig.build.json --watch",
36
+ "type-check": "tsc --noEmit",
37
+ "lint": "biome lint .",
38
+ "test": "vitest run",
39
+ "clean": "rm -rf dist .turbo *.tsbuildinfo"
40
+ },
41
+ "keywords": [
42
+ "hubspot",
43
+ "forms",
44
+ "analytics",
45
+ "nextjs",
46
+ "contentful",
47
+ "typescript",
48
+ "react"
49
+ ],
50
+ "peerDependencies": {
51
+ "@se-studio/core-data-types": "workspace:*",
52
+ "@se-studio/core-ui": "workspace:*",
53
+ "next": ">=15.5.0 <16",
54
+ "react": "^19.0.0",
55
+ "react-dom": "^19.0.0"
56
+ },
57
+ "dependencies": {
58
+ "@hubspot/api-client": "^12.0.0",
59
+ "html-entities": "^2.6.0",
60
+ "server-only": "0.0.1"
61
+ },
62
+ "devDependencies": {
63
+ "@biomejs/biome": "^2.5.0",
64
+ "@se-studio/core-data-types": "workspace:*",
65
+ "@se-studio/core-ui": "workspace:*",
66
+ "@types/node": "^24.13.2",
67
+ "@types/react": "^19.2.17",
68
+ "@types/react-dom": "^19.2.3",
69
+ "jsdom": "^29.1.1",
70
+ "next": "^15.5.19",
71
+ "react": "^19.2.0",
72
+ "react-dom": "^19.2.0",
73
+ "typescript": "^6.0.3",
74
+ "vitest": "^4.1.9"
75
+ }
76
+ }