From 99f4d1e4c79979754c9b03fa6dae59f79c95b9d9 Mon Sep 17 00:00:00 2001 From: Alex Antsiferov Date: Wed, 18 Dec 2024 16:30:12 +0100 Subject: [PATCH] Add missing membership details (#195) - Added `phone`, `address` and `plan` fields --- CHANGELOG.md | 16 +++++----- package.json | 2 +- ...rMembershipCancellationDateReached.test.ts | 28 ++++++++++++++++- .../triggerMembershipCancelled.test.ts | 28 ++++++++++++++++- .../triggerMembershipConfirmed.test.ts | 30 +++++++++++++++++-- src/test/utils/mockBundle.ts | 1 + src/types/api-responses.d.ts | 11 +++++++ src/types/outputs.d.ts | 16 ++++++++++ src/utils/api-to-output.ts | 16 ++++++++++ src/utils/samples.ts | 16 ++++++++++ 10 files changed, 152 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be81cb..bd409c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,24 +7,26 @@ Minor changes to associated `membership` to the invoice on trigger/created_invoi ## 2.2.4 -Added associated `contact` to the invoice on trigger/created_invoice. - +- Added associated `contact` to the invoice on trigger/created_invoice. - Added `contact email` and `contact name` fields to the Invoice creation trigger. ## 2.3.0 -Added trigger/cancelled_membership +- Added trigger/cancelled_membership ## 2.3.1 -Added `canceled_to` field to trigger on trigger/cancelled_membership which gives the date of cancellation +- Added `canceled_to` field to trigger on trigger/cancelled_membership which gives the date of cancellation ## 2.4.0 -Added trigger/membership_cancellation_date_reached - +- Added trigger/membership_cancellation_date_reached - This trigger fires on the day a membership cancellation applies ## 2.4.1 -Added `accounting_code` field to trigger/created_booking +- Added `accounting_code` field to trigger/created_booking + +## 2.4.2 + +- Added membership `phone`, `address`, and `plan` fields diff --git a/package.json b/package.json index cf7e1b4..2a29f74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cobot-zapier", - "version": "2.4.1", + "version": "2.4.2", "description": "", "main": "index.js", "scripts": { diff --git a/src/test/triggers/triggerMembershipCancellationDateReached.test.ts b/src/test/triggers/triggerMembershipCancellationDateReached.test.ts index e832e83..517ee3f 100644 --- a/src/test/triggers/triggerMembershipCancellationDateReached.test.ts +++ b/src/test/triggers/triggerMembershipCancellationDateReached.test.ts @@ -23,13 +23,23 @@ const membershipResponse: MembershipApiResponse = { address: { company: "Acme inc", name: "Sam Duncan", - full_address: "982 Ruguw Terrace", + full_address: "982 Ruguw Terrace\n55112 Bellona", + address: "982 Ruguw Terrace", + city: "Bellona", + post_code: "55112", + state: "AK", + country: "US", }, payment_method: { name: "Credit Card", }, plan: { name: "Full Time", + description: "Enjoy the stability of a Full Time membership", + total_price_per_cycle: "100.0", + currency: "USD", + cycle_duration: 1, + cancellation_period: 14, }, customer_number: "123", confirmed_at: "2012/04/12 12:00:00 +0000", @@ -40,9 +50,25 @@ const membershipOutput: MembershipOutput = { id: "003b37a3-f205-5d9e-9caf-c4ca612075d4", name: "Sam Duncan", company: "Acme inc", + address: { + full_address: "982 Ruguw Terrace\n55112 Bellona", + address: "982 Ruguw Terrace", + city: "Bellona", + post_code: "55112", + state: "AK", + country: "US", + }, email: "sig@rauwekug.kr", + phone: null, customer_number: "123", plan_name: "Full Time", + plan: { + description: "Enjoy the stability of a Full Time membership", + total_price_per_cycle: "100.0", + currency: "USD", + cycle_duration: 1, + cancellation_period: 14, + }, payment_method_name: "Credit Card", confirmed_at: "2012-04-12", canceled_to: "2012-04-14", diff --git a/src/test/triggers/triggerMembershipCancelled.test.ts b/src/test/triggers/triggerMembershipCancelled.test.ts index 88b4474..cab96a0 100644 --- a/src/test/triggers/triggerMembershipCancelled.test.ts +++ b/src/test/triggers/triggerMembershipCancelled.test.ts @@ -23,13 +23,23 @@ const membershipResponse: MembershipApiResponse = { address: { company: "Acme inc", name: "Sam Duncan", - full_address: "982 Ruguw Terrace", + full_address: "982 Ruguw Terrace\n55112 Bellona", + address: "982 Ruguw Terrace", + city: "Bellona", + post_code: "55112", + state: "AK", + country: "US", }, payment_method: { name: "Credit Card", }, plan: { name: "Full Time", + description: "Enjoy the stability of a Full Time membership", + total_price_per_cycle: "100.0", + currency: "USD", + cycle_duration: 1, + cancellation_period: 14, }, customer_number: "123", confirmed_at: "2012/04/12 12:00:00 +0000", @@ -40,9 +50,25 @@ const membershipOutput: MembershipOutput = { id: "003b37a3-f205-5d9e-9caf-c4ca612075d4", name: "Sam Duncan", company: "Acme inc", + address: { + full_address: "982 Ruguw Terrace\n55112 Bellona", + address: "982 Ruguw Terrace", + city: "Bellona", + post_code: "55112", + state: "AK", + country: "US", + }, email: "sig@rauwekug.kr", + phone: null, customer_number: "123", plan_name: "Full Time", + plan: { + description: "Enjoy the stability of a Full Time membership", + total_price_per_cycle: "100.0", + currency: "USD", + cycle_duration: 1, + cancellation_period: 14, + }, payment_method_name: "Credit Card", confirmed_at: "2012-04-12", canceled_to: "2012-04-14", diff --git a/src/test/triggers/triggerMembershipConfirmed.test.ts b/src/test/triggers/triggerMembershipConfirmed.test.ts index bc75ca6..0001f73 100644 --- a/src/test/triggers/triggerMembershipConfirmed.test.ts +++ b/src/test/triggers/triggerMembershipConfirmed.test.ts @@ -18,17 +18,27 @@ const membershipResponse: MembershipApiResponse = { id: "003b37a3-f205-5d9e-9caf-c4ca612075d4", name: "Sam Duncan", email: "sig@rauwekug.kr", - phone: null, + phone: "+1 555 683 4463", address: { company: "Acme inc", name: "Sam Duncan", - full_address: "982 Ruguw Terrace", + full_address: "982 Ruguw Terrace\n55112 Bellona", + address: "982 Ruguw Terrace", + city: "Bellona", + post_code: "55112", + state: "AK", + country: "US", }, payment_method: { name: "Credit Card", }, plan: { name: "Full Time", + description: "Enjoy the stability of a Full Time membership", + total_price_per_cycle: "100.0", + currency: "USD", + cycle_duration: 1, + cancellation_period: 14, }, customer_number: "123", confirmed_at: "2012/04/12 12:00:00 +0000", @@ -38,9 +48,25 @@ const membershipOutput: MembershipOutput = { id: "003b37a3-f205-5d9e-9caf-c4ca612075d4", name: "Sam Duncan", company: "Acme inc", + address: { + full_address: "982 Ruguw Terrace\n55112 Bellona", + address: "982 Ruguw Terrace", + city: "Bellona", + post_code: "55112", + state: "AK", + country: "US", + }, email: "sig@rauwekug.kr", + phone: "+1 555 683 4463", customer_number: "123", plan_name: "Full Time", + plan: { + description: "Enjoy the stability of a Full Time membership", + total_price_per_cycle: "100.0", + currency: "USD", + cycle_duration: 1, + cancellation_period: 14, + }, payment_method_name: "Credit Card", confirmed_at: "2012-04-12", }; diff --git a/src/test/utils/mockBundle.ts b/src/test/utils/mockBundle.ts index f7d019f..20b048a 100644 --- a/src/test/utils/mockBundle.ts +++ b/src/test/utils/mockBundle.ts @@ -13,6 +13,7 @@ export const mockBundle: KontentBundle<{}> = { }, inputData: {}, inputDataRaw: {}, + // https://docs.zapier.com/platform/build-cli/core#bundle-meta meta: { isBulkRead: false, page: 0, diff --git a/src/types/api-responses.d.ts b/src/types/api-responses.d.ts index fec307f..d21892e 100644 --- a/src/types/api-responses.d.ts +++ b/src/types/api-responses.d.ts @@ -72,6 +72,7 @@ export type EventApiResponse = { }; }; +// Note: APIv2 address type Address = { company: string | null; name: string | null; @@ -172,10 +173,20 @@ export type MembershipApiResponse = { company: string | null; name: string | null; full_address: string | null; + address: string | null; + post_code: string | null; + city: string | null; + state: string | null; + country: string | null; }; customer_number: string | null; plan: { name: string; + description: string | null; + total_price_per_cycle: string; + currency: string | null; + cycle_duration: number; + cancellation_period: number | null; }; payment_method: { name: string; diff --git a/src/types/outputs.d.ts b/src/types/outputs.d.ts index 9dba080..41d9a59 100644 --- a/src/types/outputs.d.ts +++ b/src/types/outputs.d.ts @@ -52,10 +52,26 @@ export type ExternalBookingOutput = { export type MembershipOutput = { id: string; name: string | null; + phone: string | null; company: string | null; + address: { + full_address: string | null; + address: string | null; + city: string | null; + post_code: string | null; + state: string | null; + country: string | null; + }; email: string | null; customer_number: string | null; plan_name: string; + plan: { + description: string | null; + total_price_per_cycle: string; + cycle_duration: number; + currency: string | null; + cancellation_period: number | null; + }; payment_method_name: string | null; confirmed_at: string | null; canceled_to?: string; diff --git a/src/utils/api-to-output.ts b/src/utils/api-to-output.ts index 7aad8a5..a0d4b65 100644 --- a/src/utils/api-to-output.ts +++ b/src/utils/api-to-output.ts @@ -23,9 +23,25 @@ export function apiResponseToMembershipOutput( id: membership.id, name: membership.name, email: membership.email, + phone: membership.phone, company: membership.address.company, + address: { + full_address: membership.address.full_address, + address: membership.address.address, + city: membership.address.city, + post_code: membership.address.post_code, + state: membership.address.state, + country: membership.address.country, + }, customer_number: membership.customer_number, plan_name: membership.plan.name, + plan: { + description: membership.plan.description, + total_price_per_cycle: membership.plan.total_price_per_cycle, + cycle_duration: membership.plan.cycle_duration, + currency: membership.plan.currency, + cancellation_period: membership.plan.cancellation_period, + }, payment_method_name: membership.payment_method?.name ?? null, confirmed_at: membership.confirmed_at?.replaceAll("/", "-").substring(0, 10) ?? null, diff --git a/src/utils/samples.ts b/src/utils/samples.ts index 12907ed..1bc4d59 100644 --- a/src/utils/samples.ts +++ b/src/utils/samples.ts @@ -59,9 +59,25 @@ export const membershipSample: MembershipOutput = { id: "003b37a3-f205-5d9e-9caf-c4ca612075d4", name: "Sam Duncan", company: "", + address: { + full_address: "982 Ruguw Terrace\n55112 Bellona", + address: "982 Ruguw Terrace", + city: "Bellona", + post_code: "55112", + state: "AK", + country: "US", + }, email: "sig@rauwekug.kr", + phone: "+1 555 683 4463", customer_number: "123", plan_name: "Full Time", + plan: { + description: "Enjoy the stability of a Full Time membership", + total_price_per_cycle: "100.0", + currency: "USD", + cycle_duration: 1, + cancellation_period: 14, + }, payment_method_name: "Credit Card", confirmed_at: "2012-04-12", canceled_to: "2012-04-12",