import { PlainClient, uiComponent } from '@team-plain/typescript-sdk';
const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });
const res = await client.createCustomerEvent({
  title: 'API key generated',
  customerIdentifier: {
    // You can use the email:
    emailAddress: 'jane@acme.com',
    // ...or if you set external id on customers:
    // externalId: 'YOUR_ID',
    // ...or you can use the customer's id in Plain:
    // customerId: 'c_01H14DFQ4PDYBH398J1E99TWSS'
  },
  components: [
    uiComponent.text({
      text: 'New API key was added with the fingerprint **3b7896975ee9fd15eeb7** with 4 associated roles.',
    }),
    uiComponent.spacer({
      size: 'M',
    }),
    uiComponent.linkButton({
      label: 'View in admin',
      url: 'https://admin.your-app.com',
    }),
  ],
  // Optional - if provided, this will ensure that this event can only
  // be created once and fail on the second time. This external id acts
  // as an idempotency key while also letting you correlate an event to
  // something your systems.
  externalId: 'XXX',
});
if (res.error) {
  console.error(res.error);
} else {
  console.log(res.data);
}