Skip to content

Commit

Permalink
feat(klaviyo): channel aware apikey
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvdbrug committed Dec 12, 2024
1 parent 17cc8ab commit 06e0179
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/vendure-plugin-klaviyo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.0 (2024-12-12)

- Allow setting an apiKey per channel

# 1.2.1 (2024-12-04)

- Add support for DiscountCode on Placed Order event
Expand Down
2 changes: 1 addition & 1 deletion packages/vendure-plugin-klaviyo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pinelab/vendure-plugin-klaviyo",
"version": "1.2.1",
"version": "1.3.0",
"description": "An extensible plugin for sending placed orders to the Klaviyo marketing platform.",
"author": "Martijn van de Brug <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down
8 changes: 6 additions & 2 deletions packages/vendure-plugin-klaviyo/src/klaviyo.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PluginCommonModule, VendurePlugin } from '@vendure/core';
import {
PluginCommonModule,
RequestContext,
VendurePlugin,
} from '@vendure/core';
import { PLUGIN_INIT_OPTIONS } from './constants';
import { defaultOrderPlacedEventHandler } from './event-handler/default-order-placed-event-handler';
import {
Expand All @@ -11,7 +15,7 @@ interface KlaviyoPluginOptionsInput {
/**
* Private API key from your Klaviyo dashboard
*/
apiKey: string;
apiKey: string | ((ctx: RequestContext) => string);
/**
* Map a Vendure event to a Klaviyo event.
*/
Expand Down
6 changes: 5 additions & 1 deletion packages/vendure-plugin-klaviyo/src/klaviyo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ export class KlaviyoService implements OnApplicationBootstrap {

// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars -- In future implementation we can make this channel aware, where the API key is stored in the DB per channel
async getKlaviyoApi(ctx: RequestContext): Promise<EventsApi> {
const session = new ApiKeySession(this.options.apiKey);
const apiKey =
typeof this.options.apiKey === 'function'
? this.options.apiKey(ctx)
: this.options.apiKey;
const session = new ApiKeySession(apiKey);
return new EventsApi(session);
}

Expand Down

0 comments on commit 06e0179

Please sign in to comment.