@brandwork/hs-utils
v1.23.1
Published
Generic utils for HubSpot applications
Readme
@brandwork/hs-utils
Generic utility components and helpers for HubSpot applications.
Features
- AutoForm: Dynamic form generation based on Zod schemas
- FormHeader: Reusable form header component
- FormValidator: Schema-based form validation
- API Client: Generic webhook submission utilities
- TypeScript: Full type safety and IntelliSense support
Installation
npm install @brandwork/hs-utilsUsage
Basic AutoForm
import { AutoForm, FormHeader } from '@brandwork/hs-utils';
import { z } from 'zod';
const schema = z.object({
name: z.string().min(1).meta({
fieldMeta: { label: "Name", fieldType: "text", hsId: "firstname" }
}),
email: z.string().email().meta({
fieldMeta: { label: "Email", fieldType: "text", hsId: "email" }
})
});
function MyForm() {
const handleSubmit = (data, validationResult, processedData) => {
console.log('Form submitted:', data);
};
return (
<AutoForm
schema={schema}
onSubmit={handleSubmit}
submitLabel="Submit"
/>
);
}Webhook Submission
import { submitToWebhook } from '@brandwork/hs-utils';
const response = await submitToWebhook(
'https://your-webhook-url.com',
'form-type',
formData,
noteOnlyFields,
fieldLabels,
objectId,
email
);Components
- AutoForm: Dynamic form component
- FormHeader: Form header with back button
- FormValidator: Validation utility class
Utilities
- submitToWebhook: Generic webhook submission
- createFormValidator: Form validator factory
- separateFormData: Data separation utility
License
MIT
