@hyperse-hub/hps-plugin-subscribe
Vendure plugin for marketing subscriptions: collect email or phone opt-ins per sales channel, optional subscribe topics, shop-side reCAPTCHA on signup, and double opt-in for email addresses created from the storefront.
Requirements
- Vendure
>= 3.6 (plugin compatibility >= 3.0.0)
- Node
>= 16
- Runtime companions (the plugin imports these modules):
@hyperse-hub/hps-plugin-core — defines RecaptchaInput and GoogleRecaptchaService used by createSubscribe on the shop API.
@hyperse-hub/hps-plugin-email — registers verification and confirmation email handlers.
@hyperse-hub/hps-plugin-admin — admin UI extensions and related entities (e.g. Module) when the dashboard is used.
Installation
Add the package to your Vendure server and satisfy peer dependencies (@vendure/core, Nest, GraphQL, TypeORM, etc.) like your other plugins.
Registering the plugin
Register HpsPluginCore so the shop schema includes RecaptchaInput and verification can run. For storefront email signups you must provide buildEmailVerificationUrl so verification emails contain a correct link.
Minimal example:
Local dev server: config/dev-server.ts in this package.
Configuration
Options for HpsPluginSubscribe.init({ ... }) (see src/types.ts — HpsPluginSubscribeOptions):
| Option | Type | Description |
|---|
initialSubscribeTopics | InitialSubscribeTopicInput[] or (ctx: { channelId: string }) => ... | Promise<...> | If set, topics are upserted on bootstrap for the default channel (matched by code). |
buildEmailVerificationUrl | (args: { token, channelCode, languageCode }) => string | Promise<string> | Required for shop createSubscribe with type: email. Builds the URL opened from the verification email. |
Behaviour
Shop API
subscribeTopics — public list of opt-in topics for the active channel (for building signup UIs).
createSubscribe — requires recaptcha; channel comes from the request context. New email subscriptions are unverified until verifySubscribeEmail succeeds; phone subscriptions are treated as verified for the emailVerified flag.
verifySubscribeEmail — completes double opt-in using the token from the verification email; publishes SubscribeEmailVerifiedEvent.
Admin API
- CRUD-style queries and mutations:
subscribes, subscribe, createSubscribe, updateSubscribe, deleteSubscribe (no reCAPTCHA; Subscribe permissions apply).
- Subscribe topics are managed per channel (
subscribeTopic / subscribeTopics / create / update / delete).
The same channel + normalized value (email or E.164 phone) maps to a single row; a new signup merges topic IDs with any existing subscription.
Events
| Event | When |
|---|
SubscribeEvent | Subscribe created, updated, or deleted. Shop email signups do not emit created until verified (verification email is sent instead). |
SubscribeVerificationEmailEvent | Shop email signup needs a verification message (internal; used by email handlers). |
SubscribeEmailVerifiedEvent | Shop email double opt-in completed via verifySubscribeEmail. Use this to sync to ESP (e.g. EmailMarketingService.subscribeToList), not a generic SubscribeEvent updated. |
Admin-created or phone subscriptions still emit SubscribeEvent created with emailVerifiedAt already set.
Example (sync to Klaviyo after verification):
End-to-end tests
From this package:
Layout:
e2e/plugin-subscribe.e2e.spec.ts — main flows: shop listing, invalid email, email signup + DB-backed token + verifySubscribeEmail, phone signup, admin list/create. Uses HpsPluginCore.init({ devMode: true }) so reCAPTCHA is skipped (same pattern as other Hyperse plugin e2e suites).
e2e/plugin-subscribe-recaptcha.e2e.spec.ts — asserts failed verification for an empty token with devMode: false (calls Google siteverify; needs outbound network).
- Helpers under
e2e/data/ (subscribe-shop, subscribe-admin, subscribe-db).
The test server also registers HpsPluginAdmin.init({ ... }) so admin-extension bootstrap and the module table match a full integration setup.
If you change entities or plugins and see stale SQL.js errors, delete the generated __data__ directory under this package and re-run tests.
GraphQL codegen
With the dev server running (yarn serve or equivalent), refresh admin/shop TypeScript types: