- {PLAN_OPTIONS.map(({ plan, name, price, perks, highlight }) => (
-
-
- {name}
-
- {price}
-
-
-
- {perks.map((perk, i) => (
-
-
- {perk}
-
- ))}
-
-
-
- ))}
+
+
+ Compare plans, review limits, and complete checkout securely from Billing.
+
+
+
+ Not now
+
+
+ View plans
+
+
diff --git a/apps/web/src/lib/constants/payments.ts b/apps/web/src/lib/constants/payments.ts
index 4e417c0..ee1e5cf 100644
--- a/apps/web/src/lib/constants/payments.ts
+++ b/apps/web/src/lib/constants/payments.ts
@@ -5,6 +5,11 @@ function fmt(n: number): string {
return n.toLocaleString();
}
+function formatOverageRate(rate: number): string {
+ if (!isFinite(rate) || rate <= 0) return "N/A";
+ return `CA$${(rate * 1000).toFixed(2)}/1,000`;
+}
+
function buildPerks(plan: (typeof PLANS)[keyof typeof PLANS]): string[] {
const l = plan.limits;
const perks: string[] = [];
@@ -13,7 +18,6 @@ function buildPerks(plan: (typeof PLANS)[keyof typeof PLANS]): string[] {
if (!isFinite(l.monthlyEmailLimit)) {
perks.push("Unlimited emails — no overage charges");
} else {
- const isHardCap = !plan.usageMetering && plan.plan !== "FREE";
const suffix = plan.plan === "FREE" ? " (hard cap)" : " included";
perks.push(`${fmt(l.monthlyEmailLimit)} emails / month${suffix}`);
@@ -29,11 +33,11 @@ function buildPerks(plan: (typeof PLANS)[keyof typeof PLANS]): string[] {
if (!l.marketingEmailsIncluded) {
perks.push("Marketing emails not available");
} else if (plan.usageMetering) {
- const rate = plan.usageMetering.marketing.toFixed(2);
- perks.push(`Marketing CA$${rate}/ea (overage)`);
+ perks.push(`Marketing ${formatOverageRate(plan.usageMetering.marketing)} (overage)`);
if (plan.usageMetering.transactional !== plan.usageMetering.marketing) {
- const txRate = plan.usageMetering.transactional.toFixed(2);
- perks.push(`Transactional CA$${txRate}/ea (overage)`);
+ perks.push(
+ `Transactional ${formatOverageRate(plan.usageMetering.transactional)} (overage)`,
+ );
}
} else {
perks.push("Marketing & transactional included");
@@ -50,7 +54,11 @@ function buildPerks(plan: (typeof PLANS)[keyof typeof PLANS]): string[] {
if (!isFinite(l.maxTeamMembers)) {
perks.push("Unlimited team members");
} else {
- perks.push(`Up to ${l.maxTeamMembers} team members`);
+ const memberAddonSuffix =
+ l.extraMemberRateCents > 0
+ ? ` + CA$${(l.extraMemberRateCents / 100).toFixed(2)}/extra member`
+ : "";
+ perks.push(`Up to ${l.maxTeamMembers} team members${memberAddonSuffix}`);
}
// Support
diff --git a/apps/web/src/lib/constants/plans.ts b/apps/web/src/lib/constants/plans.ts
index 673e385..403c65c 100644
--- a/apps/web/src/lib/constants/plans.ts
+++ b/apps/web/src/lib/constants/plans.ts
@@ -5,6 +5,7 @@ export enum LimitReason {
DOMAIN = "DOMAIN",
CONTACT_BOOK = "CONTACT_BOOK",
CONTACTS = "CONTACTS",
+ CAMPAIGN = "CAMPAIGN",
TEAM_MEMBER = "TEAM_MEMBER",
WEBHOOK = "WEBHOOK",
EMAIL_BLOCKED = "EMAIL_BLOCKED",
@@ -23,6 +24,7 @@ export const PLAN_LIMITS: Record<
contacts: number;
teamMembers: number;
webhooks: number;
+ campaigns: number;
/** Whether marketing/campaign emails are available on this plan. */
marketingEmailsIncluded: boolean;
}
@@ -33,26 +35,29 @@ export const PLAN_LIMITS: Record<
domains: PLANS.FREE.limits.maxDomains,
contactBooks: PLANS.FREE.limits.maxContactBooks,
contacts: PLANS.FREE.limits.contactsLimit, // Hard cap across all contact books
+ campaigns: PLANS.FREE.limits.campaignsLimit,
teamMembers: PLANS.FREE.limits.maxTeamMembers, // Hard cap — upgrade required
webhooks: PLANS.FREE.limits.maxWebhooks,
- marketingEmailsIncluded: PLANS.FREE.limits.marketingEmailsIncluded, // Marketing emails blocked on free plan
+ marketingEmailsIncluded: PLANS.FREE.limits.marketingEmailsIncluded,
},
HOBBY: {
- emailsPerMonth: PLANS.HOBBY.limits.monthlyEmailLimit, // Included; overage billed at CA$0.05 marketing / CA$0.03 transactional
- emailsPerDay: PLANS.HOBBY.limits.dailyEmailLimit,
+ emailsPerMonth: PLANS.HOBBY.limits.monthlyEmailLimit, // Included; overage billed monthly
+ emailsPerDay: -1, // Unlimited daily on paid plans
domains: PLANS.HOBBY.limits.maxDomains,
contactBooks: PLANS.HOBBY.limits.maxContactBooks,
contacts: PLANS.HOBBY.limits.contactsLimit,
+ campaigns: PLANS.HOBBY.limits.campaignsLimit,
teamMembers: PLANS.HOBBY.limits.maxTeamMembers, // Hard cap — upgrade required
webhooks: PLANS.HOBBY.limits.maxWebhooks,
marketingEmailsIncluded: PLANS.HOBBY.limits.marketingEmailsIncluded,
},
LITE: {
- emailsPerMonth: PLANS.LITE.limits.monthlyEmailLimit, // Included; overage billed at CA$0.02/ea
- emailsPerDay: PLANS.LITE.limits.dailyEmailLimit,
+ emailsPerMonth: PLANS.LITE.limits.monthlyEmailLimit, // Included; overage billed monthly
+ emailsPerDay: -1, // Unlimited daily on paid plans
domains: PLANS.LITE.limits.maxDomains,
contactBooks: PLANS.LITE.limits.maxContactBooks,
contacts: PLANS.LITE.limits.contactsLimit,
+ campaigns: PLANS.LITE.limits.campaignsLimit,
teamMembers: PLANS.LITE.limits.maxTeamMembers, // Hard cap — upgrade required
webhooks: PLANS.LITE.limits.maxWebhooks,
marketingEmailsIncluded: PLANS.LITE.limits.marketingEmailsIncluded,
@@ -63,6 +68,7 @@ export const PLAN_LIMITS: Record<
domains: PLANS.BASIC.limits.maxDomains,
contactBooks: PLANS.BASIC.limits.maxContactBooks,
contacts: -1, // Unlimited
+ campaigns: PLANS.BASIC.limits.campaignsLimit,
teamMembers: -1, // Unlimited
webhooks: PLANS.BASIC.limits.maxWebhooks,
marketingEmailsIncluded: PLANS.BASIC.limits.marketingEmailsIncluded,
@@ -73,6 +79,7 @@ export const PLAN_LIMITS: Record<
domains: PLANS.LIFETIME.limits.maxDomains,
contactBooks: PLANS.LIFETIME.limits.maxContactBooks,
contacts: -1, // Unlimited
+ campaigns: PLANS.LIFETIME.limits.campaignsLimit,
teamMembers: -1, // Unlimited
webhooks: PLANS.LIFETIME.limits.maxWebhooks,
marketingEmailsIncluded: PLANS.LIFETIME.limits.marketingEmailsIncluded,
diff --git a/apps/web/src/server/api/root.ts b/apps/web/src/server/api/root.ts
index adfe7a5..cf1ac6e 100644
--- a/apps/web/src/server/api/root.ts
+++ b/apps/web/src/server/api/root.ts
@@ -16,6 +16,7 @@ import { feedbackRouter } from "./routers/feedback";
import { webhookRouter } from "./routers/webhook";
import { userRouter } from "./routers/user";
import { notificationProviderRouter } from "./routers/notification-provider";
+import { logsRouter } from "./routers/logs";
/**
* This is the primary router for your server.
@@ -40,6 +41,7 @@ export const appRouter = createTRPCRouter({
webhook: webhookRouter,
user: userRouter,
notificationProvider: notificationProviderRouter,
+ logs: logsRouter,
});
// export type definition of API
diff --git a/apps/web/src/server/api/routers/admin.ts b/apps/web/src/server/api/routers/admin.ts
index 1756046..c44df3c 100644
--- a/apps/web/src/server/api/routers/admin.ts
+++ b/apps/web/src/server/api/routers/admin.ts
@@ -299,11 +299,11 @@ export const adminRouter = createTRPCRouter({
const where: Prisma.UserWhereInput = query
? {
- OR: [
- { email: { contains: query, mode: "insensitive" } },
- { name: { contains: query, mode: "insensitive" } },
- ],
- }
+ OR: [
+ { email: { contains: query, mode: "insensitive" } },
+ { name: { contains: query, mode: "insensitive" } },
+ ],
+ }
: {};
const [users, total] = await Promise.all([
@@ -339,9 +339,9 @@ export const adminRouter = createTRPCRouter({
let team = numericId
? await db.team.findUnique({
- where: { id: numericId },
- select: teamAdminSelection,
- })
+ where: { id: numericId },
+ select: teamAdminSelection,
+ })
: null;
if (!team) {
@@ -396,18 +396,18 @@ export const adminRouter = createTRPCRouter({
const where: Prisma.TeamWhereInput = query
? {
- OR: [
- { name: { contains: query, mode: "insensitive" } },
- { billingEmail: { contains: query, mode: "insensitive" } },
- {
- teamUsers: {
- some: {
- user: { email: { contains: query, mode: "insensitive" } },
- },
+ OR: [
+ { name: { contains: query, mode: "insensitive" } },
+ { billingEmail: { contains: query, mode: "insensitive" } },
+ {
+ teamUsers: {
+ some: {
+ user: { email: { contains: query, mode: "insensitive" } },
},
},
- ],
- }
+ },
+ ],
+ }
: {};
const [teams, total] = await Promise.all([
@@ -436,9 +436,27 @@ export const adminRouter = createTRPCRouter({
plan: z.enum(["FREE", "HOBBY", "LITE", "BASIC", "LIFETIME"]),
}),
)
- .mutation(async ({ input }) => {
+ .mutation(async ({ ctx, input }) => {
const { teamId, ...data } = input;
+ if (isCloud()) {
+ const existingTeam = await db.team.findUnique({
+ where: { id: teamId },
+ select: { plan: true },
+ });
+
+ if (!existingTeam) {
+ throw new TRPCError({ code: "NOT_FOUND", message: "Team not found" });
+ }
+
+ if (existingTeam.plan !== data.plan && !ctx.session.user.isEnvAdmin) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "Only founder/admin env accounts can change team plans.",
+ });
+ }
+ }
+
const updatedTeam = await db.team.update({
where: { id: teamId },
data,
@@ -462,7 +480,7 @@ export const adminRouter = createTRPCRouter({
method: z.enum(["complimentary", "checkout_link"]),
}),
)
- .mutation(async ({ input }) => {
+ .mutation(async ({ ctx, input }) => {
const { teamId, plan, method } = input;
if (!isCloud()) {
@@ -472,12 +490,23 @@ export const adminRouter = createTRPCRouter({
});
}
+ if (!ctx.session.user.isEnvAdmin) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "Only founder/admin env accounts can assign plans or generate payment links.",
+ });
+ }
+
if (method === "complimentary") {
const updatedTeam = await db.team.update({
where: { id: teamId },
data: {
plan,
isActive: plan !== "FREE",
+ customPlanEnabled: false,
+ customMarketingEmailLimit: null,
+ customTransactionalEmailLimit: null,
+ customMonthlyPriceCents: null,
},
select: teamAdminSelection,
});
@@ -518,12 +547,12 @@ export const adminRouter = createTRPCRouter({
const where: Prisma.DomainWhereInput = query
? {
- OR: [
- { name: { contains: query, mode: "insensitive" } },
- { region: { contains: query, mode: "insensitive" } },
- { team: { name: { contains: query, mode: "insensitive" } } },
- ],
- }
+ OR: [
+ { name: { contains: query, mode: "insensitive" } },
+ { region: { contains: query, mode: "insensitive" } },
+ { team: { name: { contains: query, mode: "insensitive" } } },
+ ],
+ }
: {};
const [domains, total] = await Promise.all([
@@ -554,12 +583,12 @@ export const adminRouter = createTRPCRouter({
const where: Prisma.WebhookWhereInput = query
? {
- OR: [
- { url: { contains: query, mode: "insensitive" } },
- { team: { name: { contains: query, mode: "insensitive" } } },
- { createdBy: { email: { contains: query, mode: "insensitive" } } },
- ],
- }
+ OR: [
+ { url: { contains: query, mode: "insensitive" } },
+ { team: { name: { contains: query, mode: "insensitive" } } },
+ { createdBy: { email: { contains: query, mode: "insensitive" } } },
+ ],
+ }
: {};
const [webhooks, total] = await Promise.all([
@@ -590,19 +619,19 @@ export const adminRouter = createTRPCRouter({
const where: Prisma.TeamWhereInput = query
? {
- OR: [
- { name: { contains: query, mode: "insensitive" } },
- { billingEmail: { contains: query, mode: "insensitive" } },
- { stripeCustomerId: { contains: query, mode: "insensitive" } },
- {
- subscription: {
- some: {
- id: { contains: query, mode: "insensitive" },
- },
+ OR: [
+ { name: { contains: query, mode: "insensitive" } },
+ { billingEmail: { contains: query, mode: "insensitive" } },
+ { stripeCustomerId: { contains: query, mode: "insensitive" } },
+ {
+ subscription: {
+ some: {
+ id: { contains: query, mode: "insensitive" },
},
},
- ],
- }
+ },
+ ],
+ }
: {};
const [teams, total] = await Promise.all([
@@ -686,10 +715,9 @@ export const adminRouter = createTRPCRouter({
FROM "DailyEmailUsage" d
INNER JOIN "Team" t ON t.id = d."teamId"
WHERE 1 = 1
- ${
- timeframe === "today"
- ? Prisma.sql`AND d."date" = ${today}`
- : Prisma.sql`AND d."date" >= ${monthStart}`
+ ${timeframe === "today"
+ ? Prisma.sql`AND d."date" = ${today}`
+ : Prisma.sql`AND d."date" >= ${monthStart}`
}
${paidOnly ? Prisma.sql`AND t."plan" = 'BASIC'` : Prisma.sql``}
GROUP BY d."teamId", t."name", t."plan"
diff --git a/apps/web/src/server/api/routers/billing.ts b/apps/web/src/server/api/routers/billing.ts
index d8d29db..134dd36 100644
--- a/apps/web/src/server/api/routers/billing.ts
+++ b/apps/web/src/server/api/routers/billing.ts
@@ -12,10 +12,12 @@ import {
} from "~/server/api/trpc";
import {
createCheckoutSessionForTeam,
+ createCustomCheckoutSessionForTeam,
createAddonCheckoutSession,
getManageSessionUrl,
syncStripeData,
type CheckoutPlan,
+ type CustomBasePlan,
} from "~/server/billing/payments";
import { db } from "~/server/db";
import { TeamService } from "~/server/service/team-service";
@@ -39,6 +41,25 @@ export const billingRouter = createTRPCRouter({
).url;
}),
+ createCustomCheckoutSession: teamAdminProcedure
+ .input(
+ z.object({
+ plan: z.enum(["LITE", "HOBBY", "BASIC"]),
+ marketingEmailLimit: z.number().int().min(1000).max(3000000),
+ transactionalEmailLimit: z.number().int().min(1000).max(3000000),
+ monthlyPriceCents: z.number().int().min(100).max(50000000),
+ }),
+ )
+ .mutation(async ({ ctx, input }) => {
+ const session = await createCustomCheckoutSessionForTeam(ctx.team.id, {
+ basePlan: input.plan as CustomBasePlan,
+ marketingEmailLimit: input.marketingEmailLimit,
+ transactionalEmailLimit: input.transactionalEmailLimit,
+ monthlyPriceCents: input.monthlyPriceCents,
+ });
+ return session.url;
+ }),
+
/**
* Purchase extra domain slots at CA$1/domain/month.
* Available on all plans including FREE.
@@ -51,7 +72,7 @@ export const billingRouter = createTRPCRouter({
}),
/**
- * Purchase extra team member slots at CA$5/member/month.
+ * Purchase extra team member slots at CA$2/member/month.
* Available on all plans including FREE.
*/
purchaseAddonMemberSlots: teamAdminProcedure
@@ -78,6 +99,20 @@ export const billingRouter = createTRPCRouter({
return subscription;
}),
+ getCustomPlanContract: teamProcedure.query(async ({ ctx }) => {
+ const team = await db.team.findUnique({
+ where: { id: ctx.team.id },
+ select: {
+ customPlanEnabled: true,
+ customMarketingEmailLimit: true,
+ customTransactionalEmailLimit: true,
+ customMonthlyPriceCents: true,
+ },
+ });
+
+ return team;
+ }),
+
updateBillingEmail: teamAdminProcedure
.input(
z.object({
diff --git a/apps/web/src/server/api/routers/campaign-security.trpc.test.ts b/apps/web/src/server/api/routers/campaign-security.trpc.test.ts
index dcf9357..f5bba62 100644
--- a/apps/web/src/server/api/routers/campaign-security.trpc.test.ts
+++ b/apps/web/src/server/api/routers/campaign-security.trpc.test.ts
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
-const { mockDb, mockValidateDomainFromEmail, mockCheckMarketingAccess } = vi.hoisted(() => ({
+const { mockDb, mockValidateDomainFromEmail, mockCheckCampaignLimit } = vi.hoisted(() => ({
mockDb: {
teamUser: {
findFirst: vi.fn(),
@@ -15,7 +15,7 @@ const { mockDb, mockValidateDomainFromEmail, mockCheckMarketingAccess } = vi.hoi
},
},
mockValidateDomainFromEmail: vi.fn(),
- mockCheckMarketingAccess: vi.fn(),
+ mockCheckCampaignLimit: vi.fn(),
}));
vi.mock("~/server/db", () => ({
@@ -34,7 +34,7 @@ vi.mock("~/server/service/domain-service", () => ({
vi.mock("~/server/service/limit-service", () => ({
LimitService: {
- checkMarketingAccess: mockCheckMarketingAccess,
+ checkCampaignLimit: mockCheckCampaignLimit,
},
}));
@@ -66,8 +66,12 @@ describe("campaignRouter.updateCampaign authorization", () => {
mockDb.campaign.update.mockReset();
mockDb.campaign.create.mockReset();
mockDb.contactBook.findUnique.mockReset();
- mockCheckMarketingAccess.mockReset();
- mockCheckMarketingAccess.mockResolvedValue(true);
+ mockCheckCampaignLimit.mockReset();
+ mockCheckCampaignLimit.mockResolvedValue({
+ isLimitReached: false,
+ limit: 3,
+ currentCount: 0,
+ });
mockDb.teamUser.findFirst.mockResolvedValue({
teamId: 10,
@@ -124,8 +128,12 @@ describe("campaignRouter.duplicateCampaign", () => {
mockDb.teamUser.findFirst.mockReset();
mockDb.campaign.findUnique.mockReset();
mockDb.campaign.create.mockReset();
- mockCheckMarketingAccess.mockReset();
- mockCheckMarketingAccess.mockResolvedValue(true);
+ mockCheckCampaignLimit.mockReset();
+ mockCheckCampaignLimit.mockResolvedValue({
+ isLimitReached: false,
+ limit: 3,
+ currentCount: 0,
+ });
mockDb.teamUser.findFirst.mockResolvedValue({
teamId: 10,
diff --git a/apps/web/src/server/api/routers/campaign.ts b/apps/web/src/server/api/routers/campaign.ts
index e2ee29d..1c72106 100644
--- a/apps/web/src/server/api/routers/campaign.ts
+++ b/apps/web/src/server/api/routers/campaign.ts
@@ -20,6 +20,7 @@ import {
import { LimitService } from "~/server/service/limit-service";
const statuses = Object.values(CampaignStatus) as [CampaignStatus];
+const intents = ["CAMPAIGN", "BROADCAST"] as const;
export const campaignRouter = createTRPCRouter({
getCampaigns: teamProcedure
@@ -28,6 +29,7 @@ export const campaignRouter = createTRPCRouter({
page: z.number().optional(),
status: z.enum(statuses).optional().nullable(),
search: z.string().optional().nullable(),
+ intent: z.enum(intents).optional(),
}),
)
.query(async ({ ctx: { db, team }, input }) => {
@@ -43,6 +45,10 @@ export const campaignRouter = createTRPCRouter({
whereConditions.status = input.status;
}
+ if (input.intent) {
+ whereConditions.intent = input.intent;
+ }
+
if (input.search) {
whereConditions.OR = [
{
@@ -77,6 +83,7 @@ export const campaignRouter = createTRPCRouter({
sent: true,
delivered: true,
unsubscribed: true,
+ intent: true,
},
orderBy: {
createdAt: "desc",
@@ -96,14 +103,15 @@ export const campaignRouter = createTRPCRouter({
name: z.string(),
from: z.string(),
subject: z.string(),
+ intent: z.enum(intents).optional(),
}),
)
.mutation(async ({ ctx: { db, team }, input }) => {
- const allowed = await LimitService.checkMarketingAccess(team.id);
- if (!allowed) {
+ const limitCheck = await LimitService.checkCampaignLimit(team.id);
+ if (limitCheck.isLimitReached) {
throw new TRPCError({
code: "FORBIDDEN",
- message: "Marketing campaigns are not available on the Free plan. Upgrade to a paid plan to access this feature.",
+ message: `You have reached the campaign limit (${limitCheck.currentCount}/${limitCheck.limit}) for your current plan. Upgrade to create more campaigns.`,
});
}
@@ -112,6 +120,7 @@ export const campaignRouter = createTRPCRouter({
const campaign = await db.campaign.create({
data: {
...input,
+ intent: input.intent ?? "CAMPAIGN",
teamId: team.id,
domainId: domain.id,
},
@@ -248,11 +257,11 @@ export const campaignRouter = createTRPCRouter({
duplicateCampaign: campaignProcedure.mutation(
async ({ ctx: { db, team, campaign } }) => {
- const allowed = await LimitService.checkMarketingAccess(team.id);
- if (!allowed) {
+ const limitCheck = await LimitService.checkCampaignLimit(team.id);
+ if (limitCheck.isLimitReached) {
throw new TRPCError({
code: "FORBIDDEN",
- message: "Marketing campaigns are not available on the Free plan. Upgrade to a paid plan to access this feature.",
+ message: `You have reached the campaign limit (${limitCheck.currentCount}/${limitCheck.limit}) for your current plan. Upgrade to duplicate more campaigns.`,
});
}
@@ -270,6 +279,7 @@ export const campaignRouter = createTRPCRouter({
teamId: team.id,
domainId: campaign.domainId,
contactBookId: campaign.contactBookId,
+ intent: campaign.intent,
},
});
diff --git a/apps/web/src/server/api/routers/limits.ts b/apps/web/src/server/api/routers/limits.ts
index 26d609f..3752b50 100644
--- a/apps/web/src/server/api/routers/limits.ts
+++ b/apps/web/src/server/api/routers/limits.ts
@@ -16,6 +16,8 @@ export const limitsRouter = createTRPCRouter({
return LimitService.checkContactBookLimit(ctx.team.id);
case LimitReason.CONTACTS:
return LimitService.checkContactsLimit(ctx.team.id);
+ case LimitReason.CAMPAIGN:
+ return LimitService.checkCampaignLimit(ctx.team.id);
case LimitReason.DOMAIN:
return LimitService.checkDomainLimit(ctx.team.id);
case LimitReason.TEAM_MEMBER:
diff --git a/apps/web/src/server/api/routers/logs.ts b/apps/web/src/server/api/routers/logs.ts
new file mode 100644
index 0000000..7eb6b29
--- /dev/null
+++ b/apps/web/src/server/api/routers/logs.ts
@@ -0,0 +1,129 @@
+import { z } from "zod";
+import { createTRPCRouter, teamProcedure } from "~/server/api/trpc";
+
+const LOG_SOURCES = ["EMAIL", "WEBHOOK", "NOTIFICATION"] as const;
+
+export const logsRouter = createTRPCRouter({
+ list: teamProcedure
+ .input(
+ z
+ .object({
+ limit: z.number().int().min(10).max(300).default(120),
+ source: z.enum(LOG_SOURCES).optional(),
+ })
+ .optional(),
+ )
+ .query(async ({ ctx, input }) => {
+ const limit = input?.limit ?? 120;
+ const source = input?.source;
+
+ const includeEmail = !source || source === "EMAIL";
+ const includeWebhook = !source || source === "WEBHOOK";
+ const includeNotification = !source || source === "NOTIFICATION";
+
+ const [emailEvents, webhookCalls, notificationLogs] = await Promise.all([
+ includeEmail
+ ? ctx.db.emailEvent.findMany({
+ where: { teamId: ctx.team.id },
+ orderBy: { createdAt: "desc" },
+ take: limit,
+ select: {
+ id: true,
+ createdAt: true,
+ status: true,
+ emailId: true,
+ email: {
+ select: {
+ subject: true,
+ from: true,
+ to: true,
+ },
+ },
+ },
+ })
+ : Promise.resolve([]),
+ includeWebhook
+ ? ctx.db.webhookCall.findMany({
+ where: { teamId: ctx.team.id },
+ orderBy: { createdAt: "desc" },
+ take: limit,
+ select: {
+ id: true,
+ createdAt: true,
+ type: true,
+ status: true,
+ responseStatus: true,
+ lastError: true,
+ webhook: {
+ select: {
+ url: true,
+ },
+ },
+ },
+ })
+ : Promise.resolve([]),
+ includeNotification
+ ? ctx.db.notificationLog.findMany({
+ where: { teamId: ctx.team.id },
+ orderBy: { createdAt: "desc" },
+ take: limit,
+ select: {
+ id: true,
+ createdAt: true,
+ status: true,
+ eventType: true,
+ providerId: true,
+ responseStatus: true,
+ lastError: true,
+ },
+ })
+ : Promise.resolve([]),
+ ]);
+
+ const entries = [
+ ...emailEvents.map((event) => ({
+ id: event.id,
+ source: "EMAIL" as const,
+ createdAt: event.createdAt,
+ status: event.status,
+ kind: event.status,
+ title: event.email?.subject || "Email event",
+ target: event.email?.to?.[0] || event.emailId,
+ metadata: {
+ emailId: event.emailId,
+ from: event.email?.from,
+ },
+ })),
+ ...webhookCalls.map((call) => ({
+ id: call.id,
+ source: "WEBHOOK" as const,
+ createdAt: call.createdAt,
+ status: call.status,
+ kind: call.type,
+ title: call.type,
+ target: call.webhook?.url || "Webhook endpoint",
+ metadata: {
+ responseStatus: call.responseStatus,
+ lastError: call.lastError,
+ },
+ })),
+ ...notificationLogs.map((log) => ({
+ id: log.id,
+ source: "NOTIFICATION" as const,
+ createdAt: log.createdAt,
+ status: log.status,
+ kind: log.eventType,
+ title: log.eventType,
+ target: `Provider ${log.providerId}`,
+ metadata: {
+ responseStatus: log.responseStatus,
+ lastError: log.lastError,
+ },
+ })),
+ ]
+ .sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
+ .slice(0, limit);
+
+ return entries;
+ }),
+});
diff --git a/apps/web/src/server/auth.ts b/apps/web/src/server/auth.ts
index 5bf13d0..500b385 100644
--- a/apps/web/src/server/auth.ts
+++ b/apps/web/src/server/auth.ts
@@ -31,6 +31,7 @@ declare module "next-auth" {
isBetaUser: boolean;
isAdmin: boolean;
isFounder: boolean;
+ isEnvAdmin?: boolean;
// ...other properties
// role: UserRole;
} & DefaultSession["user"];
@@ -42,10 +43,15 @@ declare module "next-auth" {
isBetaUser: boolean;
isAdmin: boolean;
isFounder: boolean;
+ isEnvAdmin?: boolean;
image?: string | null;
}
}
+function normalizeEmail(email?: string | null) {
+ return email?.trim().toLowerCase();
+}
+
/**
* Auth providers
*/
@@ -168,10 +174,16 @@ export const authOptions: NextAuthOptions = {
return true;
},
session: ({ session, user }) => {
- const isFounder = !!env.FOUNDER_EMAIL && user.email === env.FOUNDER_EMAIL;
- const isAdmin =
+ const userEmail = normalizeEmail(user.email);
+ const founderEmail = normalizeEmail(env.FOUNDER_EMAIL);
+ const adminEmail = normalizeEmail(env.ADMIN_EMAIL);
+
+ const isFounder = !!founderEmail && userEmail === founderEmail;
+ const isEnvAdmin =
isFounder ||
- (!!env.ADMIN_EMAIL && user.email === env.ADMIN_EMAIL) ||
+ (!!adminEmail && userEmail === adminEmail);
+ const isAdmin =
+ isEnvAdmin ||
user.isAdmin;
return {
...session,
@@ -181,6 +193,7 @@ export const authOptions: NextAuthOptions = {
isBetaUser: user.isBetaUser,
isAdmin,
isFounder,
+ isEnvAdmin,
// Explicitly forward the DB image so it always reaches the client,
// even when session.user was built before the image update above.
image: user.image ?? session.user.image,
diff --git a/apps/web/src/server/billing/payments.ts b/apps/web/src/server/billing/payments.ts
index 9c15aa0..d9be1c8 100644
--- a/apps/web/src/server/billing/payments.ts
+++ b/apps/web/src/server/billing/payments.ts
@@ -15,6 +15,14 @@ import {
} from "./stripe-config";
export type CheckoutPlan = Extract
;
+export type CustomBasePlan = Extract;
+
+export type CustomPlanContract = {
+ basePlan: CustomBasePlan;
+ marketingEmailLimit: number;
+ transactionalEmailLimit: number;
+ monthlyPriceCents: number;
+};
export function getStripe() {
if (!env.STRIPE_SECRET_KEY) {
@@ -35,6 +43,30 @@ async function createCustomerForTeam(teamId: number) {
return customer;
}
+async function ensureTeamCustomerId(teamId: number, existingCustomerId?: string | null) {
+ const stripe = getStripe();
+ let customerId = existingCustomerId;
+
+ if (!customerId) {
+ const customer = await createCustomerForTeam(teamId);
+ customerId = customer.id;
+ return customerId;
+ }
+
+ try {
+ await stripe.customers.retrieve(customerId);
+ } catch (err) {
+ if (err instanceof Stripe.errors.StripeError && err.code === "resource_missing") {
+ const customer = await createCustomerForTeam(teamId);
+ customerId = customer.id;
+ } else {
+ throw err;
+ }
+ }
+
+ return customerId;
+}
+
export async function createCheckoutSessionForTeam(
teamId: number,
plan: CheckoutPlan = "BASIC",
@@ -44,24 +76,7 @@ export async function createCheckoutSessionForTeam(
if (team.isActive && team.plan !== "FREE") throw new Error("Team is already active");
const stripe = getStripe();
-
- let customerId = team.stripeCustomerId;
- if (!customerId) {
- const customer = await createCustomerForTeam(teamId);
- customerId = customer.id;
- } else {
- // Verify the stored customer still exists in Stripe (handles DB resets / key switches)
- try {
- await stripe.customers.retrieve(customerId);
- } catch (err) {
- if (err instanceof Stripe.errors.StripeError && err.code === "resource_missing") {
- const customer = await createCustomerForTeam(teamId);
- customerId = customer.id;
- } else {
- throw err;
- }
- }
- }
+ const customerId = await ensureTeamCustomerId(teamId, team.stripeCustomerId);
const priceIds = await getPlanPriceIds(plan);
@@ -90,7 +105,7 @@ export async function createCheckoutSessionForTeam(
customer: customerId,
line_items: [
{ price: priceIds.monthly, quantity: 1 },
- ...(priceIds.marketingUsage ? [{ price: priceIds.marketingUsage }] : []),
+ ...(priceIds.marketingUsage ? [{ price: priceIds.marketingUsage }] : []),
...(priceIds.transactionalUsage ? [{ price: priceIds.transactionalUsage }] : []),
],
success_url: `${env.NEXTAUTH_URL}/payments?success=true&session_id={CHECKOUT_SESSION_ID}`,
@@ -100,6 +115,56 @@ export async function createCheckoutSessionForTeam(
});
}
+/**
+ * Creates a Stripe Checkout session for purchasing additional domain slots.
+ */
+export async function createCustomCheckoutSessionForTeam(
+ teamId: number,
+ contract: CustomPlanContract,
+) {
+ const team = await db.team.findUnique({ where: { id: teamId } });
+ if (!team) throw new Error("Team not found");
+ if (team.isActive && team.plan !== "FREE") throw new Error("Team is already active");
+
+ const customerId = await ensureTeamCustomerId(teamId, team.stripeCustomerId);
+ const stripe = getStripe();
+
+ const metadata = {
+ teamId: teamId.toString(),
+ customPlanEnabled: "true",
+ plan: contract.basePlan,
+ customMarketingEmailLimit: contract.marketingEmailLimit.toString(),
+ customTransactionalEmailLimit: contract.transactionalEmailLimit.toString(),
+ customMonthlyPriceCents: contract.monthlyPriceCents.toString(),
+ };
+
+ return stripe.checkout.sessions.create({
+ mode: "subscription",
+ customer: customerId,
+ line_items: [
+ {
+ price_data: {
+ currency: "cad",
+ recurring: { interval: "month" },
+ unit_amount: contract.monthlyPriceCents,
+ product_data: {
+ name: `ByteSend Custom ${contract.basePlan}`,
+ description: `${contract.marketingEmailLimit.toLocaleString()} marketing + ${contract.transactionalEmailLimit.toLocaleString()} transactional emails per month`,
+ },
+ },
+ quantity: 1,
+ },
+ ],
+ success_url: `${env.NEXTAUTH_URL}/payments?success=true&custom=true&session_id={CHECKOUT_SESSION_ID}`,
+ cancel_url: `${env.NEXTAUTH_URL}/settings/billing`,
+ metadata,
+ subscription_data: {
+ metadata,
+ },
+ client_reference_id: teamId.toString(),
+ });
+}
+
/**
* Creates a Stripe Checkout session for purchasing additional domain slots.
*/
@@ -149,6 +214,20 @@ async function getPlanFromPriceIds(priceIds: string[]): Promise {
return "FREE";
}
+function parsePositiveInt(value: string | undefined): number | null {
+ if (!value) return null;
+ const parsed = Number.parseInt(value, 10);
+ if (!Number.isFinite(parsed) || parsed <= 0) return null;
+ return parsed;
+}
+
+function parseCustomBasePlan(value: string | undefined): CustomBasePlan | null {
+ if (value === "HOBBY" || value === "LITE" || value === "BASIC") {
+ return value;
+ }
+ return null;
+}
+
export async function getManageSessionUrl(teamId: number) {
const team = await db.team.findUnique({ where: { id: teamId } });
if (!team) throw new Error("Team not found");
@@ -202,9 +281,9 @@ export async function syncStripeData(customerId: string) {
}
}
- await db.team.update({
- where: { id: team.id },
- data: { extraDomainSlots, extraMemberSlots }
+ await db.team.update({
+ where: { id: team.id },
+ data: { extraDomainSlots, extraMemberSlots }
});
await TeamService.invalidateTeamCache(team.id);
@@ -215,11 +294,19 @@ export async function syncStripeData(customerId: string) {
.map((item) => item.price?.id)
.filter((id): id is string => Boolean(id));
- const nextPlan = await getPlanFromPriceIds(priceIds);
+ const customPlanEnabled = subscription.metadata?.customPlanEnabled === "true";
+ const customBasePlan = parseCustomBasePlan(subscription.metadata?.plan);
+ const customMarketingEmailLimit = parsePositiveInt(subscription.metadata?.customMarketingEmailLimit);
+ const customTransactionalEmailLimit = parsePositiveInt(subscription.metadata?.customTransactionalEmailLimit);
+ const customMonthlyPriceCents = parsePositiveInt(subscription.metadata?.customMonthlyPriceCents);
+
+ const nextPlan = customPlanEnabled
+ ? (customBasePlan ?? team.plan)
+ : await getPlanFromPriceIds(priceIds);
const isNowPaid = subscription.status === "active" && nextPlan !== "FREE";
const shouldSendSubscriptionConfirmation = !wasPaid && isNowPaid;
- const periodEnd = subscription.items.data[0]?.current_period_end;
+ const periodEnd = subscription.items.data[0]?.current_period_end;
const periodStart = subscription.items.data[0]?.current_period_start;
await db.subscription.upsert({
@@ -228,7 +315,7 @@ export async function syncStripeData(customerId: string) {
status: subscription.status,
priceId: subscription.items.data[0]?.price?.id ?? "",
priceIds,
- currentPeriodEnd: periodEnd ? new Date(periodEnd * 1000) : null,
+ currentPeriodEnd: periodEnd ? new Date(periodEnd * 1000) : null,
currentPeriodStart: periodStart ? new Date(periodStart * 1000) : null,
cancelAtPeriodEnd: subscription.cancel_at ? new Date(subscription.cancel_at * 1000) : null,
paymentMethod: JSON.stringify(subscription.default_payment_method),
@@ -239,7 +326,7 @@ export async function syncStripeData(customerId: string) {
status: subscription.status,
priceId: subscription.items.data[0]?.price?.id ?? "",
priceIds,
- currentPeriodEnd: periodEnd ? new Date(periodEnd * 1000) : null,
+ currentPeriodEnd: periodEnd ? new Date(periodEnd * 1000) : null,
currentPeriodStart: periodStart ? new Date(periodStart * 1000) : null,
cancelAtPeriodEnd: subscription.cancel_at ? new Date(subscription.cancel_at * 1000) : null,
paymentMethod: JSON.stringify(subscription.default_payment_method),
@@ -250,6 +337,22 @@ export async function syncStripeData(customerId: string) {
await TeamService.updateTeam(team.id, {
plan: subscription.status === "canceled" ? "FREE" : nextPlan,
isActive: subscription.status === "active",
+ customPlanEnabled:
+ subscription.status === "active" &&
+ customPlanEnabled &&
+ Boolean(customBasePlan && customMarketingEmailLimit && customTransactionalEmailLimit && customMonthlyPriceCents),
+ customMarketingEmailLimit:
+ subscription.status === "active" && customPlanEnabled
+ ? customMarketingEmailLimit
+ : null,
+ customTransactionalEmailLimit:
+ subscription.status === "active" && customPlanEnabled
+ ? customTransactionalEmailLimit
+ : null,
+ customMonthlyPriceCents:
+ subscription.status === "active" && customPlanEnabled
+ ? customMonthlyPriceCents
+ : null,
});
logger.info(
@@ -286,7 +389,14 @@ export async function syncLifetimePayment(customerId: string) {
if (team.plan === "LIFETIME") return;
- await TeamService.updateTeam(team.id, { plan: "LIFETIME", isActive: true });
+ await TeamService.updateTeam(team.id, {
+ plan: "LIFETIME",
+ isActive: true,
+ customPlanEnabled: false,
+ customMarketingEmailLimit: null,
+ customTransactionalEmailLimit: null,
+ customMonthlyPriceCents: null,
+ });
try {
const teamUsers = await TeamService.getTeamUsers(team.id);
diff --git a/apps/web/src/server/jobs/usage-job.ts b/apps/web/src/server/jobs/usage-job.ts
index f4c03b1..56f7384 100644
--- a/apps/web/src/server/jobs/usage-job.ts
+++ b/apps/web/src/server/jobs/usage-job.ts
@@ -80,7 +80,10 @@ const worker = new Worker(
// Period total before yesterday (subtract yesterday from period-through-yesterday)
const priorTotal = Math.max(0, periodTotal - totalYesterday);
- // The plan's included monthly email limit
+ // The plan's included monthly email limit.
+ // Custom slider contracts are fixed-price + fixed limits, so no Stripe metered overage.
+ if (team.customPlanEnabled) continue;
+
const includedLimit = PLAN_LIMITS[team.plan as Plan].emailsPerMonth;
if (includedLimit === -1) continue; // Unlimited plan, nothing to meter
diff --git a/apps/web/src/server/service/campaign-service.ts b/apps/web/src/server/service/campaign-service.ts
index fa12f0f..d168ad2 100644
--- a/apps/web/src/server/service/campaign-service.ts
+++ b/apps/web/src/server/service/campaign-service.ts
@@ -298,11 +298,11 @@ export async function createCampaignFromApi({
bcc?: string | string[];
batchSize?: number;
}) {
- const marketingAllowed = await LimitService.checkMarketingAccess(teamId);
- if (!marketingAllowed) {
+ const campaignLimit = await LimitService.checkCampaignLimit(teamId);
+ if (campaignLimit.isLimitReached) {
throw new ByteSendApiError({
code: "FORBIDDEN",
- message: "Marketing campaigns are not available on the Free plan. Upgrade to a paid plan to access this feature.",
+ message: `You have reached the campaign limit (${campaignLimit.currentCount}/${campaignLimit.limit}) for your current plan. Upgrade to create more campaigns.`,
});
}
@@ -519,14 +519,6 @@ export async function scheduleCampaign({
});
}
- const marketingAllowed = await LimitService.checkMarketingAccess(teamId);
- if (!marketingAllowed) {
- throw new ByteSendApiError({
- code: "FORBIDDEN",
- message: "Marketing campaigns are not available on the Free plan. Upgrade to a paid plan to access this feature.",
- });
- }
-
let html: string;
try {
const prepared = await prepareCampaignHtml(campaign);
diff --git a/apps/web/src/server/service/limit-service.ts b/apps/web/src/server/service/limit-service.ts
index d96d208..39c53be 100644
--- a/apps/web/src/server/service/limit-service.ts
+++ b/apps/web/src/server/service/limit-service.ts
@@ -5,7 +5,7 @@ import { TeamService } from "./team-service";
import { withCache } from "../redis";
import { db } from "../db";
import { logger } from "../logger/log";
-import { Plan } from "@prisma/client";
+import { Plan, Team } from "@prisma/client";
function isLimitExceeded(current: number, limit: number): boolean {
if (limit === -1) return false; // unlimited
@@ -16,18 +16,45 @@ function getActivePlan(team: { plan: Plan; isActive: boolean }): Plan {
return team.isActive ? team.plan : "FREE";
}
+function hasCustomPlan(team: Team): boolean {
+ return Boolean(
+ team.customPlanEnabled &&
+ team.customMarketingEmailLimit &&
+ team.customTransactionalEmailLimit,
+ );
+}
+
+function getCustomMonthlyTotalLimit(team: Team): number | null {
+ if (!hasCustomPlan(team)) return null;
+ return (team.customMarketingEmailLimit ?? 0) + (team.customTransactionalEmailLimit ?? 0);
+}
+
+function getEffectiveDailyEmailLimit(team: Team): number {
+ if (hasCustomPlan(team)) return -1;
+ return PLAN_LIMITS[getActivePlan(team)].emailsPerDay;
+}
+
+function hasMarketingEnabled(team: Team): boolean {
+ if (hasCustomPlan(team)) {
+ return (team.customMarketingEmailLimit ?? 0) > 0;
+ }
+ return PLAN_LIMITS[getActivePlan(team)].marketingEmailsIncluded;
+}
+
export class LimitService {
/**
* Returns true if the team has the admin or founder as a member.
* These teams are exempt from all limits.
*/
private static async isAdminOrFounderTeam(teamId: number): Promise {
- const adminEmails = [env.ADMIN_EMAIL, env.FOUNDER_EMAIL].filter(Boolean) as string[];
+ const adminEmails = [env.ADMIN_EMAIL, env.FOUNDER_EMAIL]
+ .filter(Boolean)
+ .map((email) => email!.trim().toLowerCase()) as string[];
if (adminEmails.length === 0) return false;
const count = await db.teamUser.count({
where: {
teamId,
- user: { email: { in: adminEmails } },
+ user: { email: { in: adminEmails, mode: "insensitive" } },
},
});
return count > 0;
@@ -157,6 +184,36 @@ export class LimitService {
};
}
+ static async checkCampaignLimit(teamId: number): Promise<{
+ isLimitReached: boolean;
+ limit: number;
+ currentCount: number;
+ reason?: LimitReason;
+ }> {
+ if (!env.NEXT_PUBLIC_IS_CLOUD) {
+ return { isLimitReached: false, limit: -1, currentCount: 0 };
+ }
+
+ const team = await TeamService.getTeamCached(teamId);
+ const currentCount = await db.campaign.count({ where: { teamId } });
+ const limit = PLAN_LIMITS[getActivePlan(team)].campaigns;
+
+ if (isLimitExceeded(currentCount, limit)) {
+ return {
+ isLimitReached: true,
+ limit,
+ currentCount,
+ reason: LimitReason.CAMPAIGN,
+ };
+ }
+
+ return {
+ isLimitReached: false,
+ limit,
+ currentCount,
+ };
+ }
+
static async checkWebhookLimit(teamId: number): Promise<{
isLimitReached: boolean;
limit: number;
@@ -228,10 +285,7 @@ export class LimitService {
const activePlan = getActivePlan(team);
// Block marketing emails on plans where they are not available (e.g. FREE)
- if (
- emailType === "MARKETING" &&
- !PLAN_LIMITS[activePlan].marketingEmailsIncluded
- ) {
+ if (emailType === "MARKETING" && !hasMarketingEnabled(team)) {
return {
isLimitReached: true,
limit: 0,
@@ -247,10 +301,7 @@ export class LimitService {
);
const dailyUsage = usage.day.reduce((acc, curr) => acc + curr.sent, 0);
- const dailyLimit =
- activePlan !== "FREE"
- ? team.dailyEmailLimit
- : PLAN_LIMITS.FREE.emailsPerDay;
+ const dailyLimit = getEffectiveDailyEmailLimit(team);
logger.info(
{ dailyUsage, dailyLimit, team },
@@ -280,6 +331,53 @@ export class LimitService {
};
}
+ const monthlyMarketingUsage =
+ usage.month.find((u) => u.type === "MARKETING")?.sent ?? 0;
+ const monthlyTransactionalUsage =
+ usage.month.find((u) => u.type === "TRANSACTIONAL")?.sent ?? 0;
+
+ if (hasCustomPlan(team)) {
+ const marketingLimit = team.customMarketingEmailLimit ?? -1;
+ const transactionalLimit = team.customTransactionalEmailLimit ?? -1;
+ const totalLimit = getCustomMonthlyTotalLimit(team) ?? -1;
+
+ if (
+ emailType === "MARKETING" &&
+ isLimitExceeded(monthlyMarketingUsage, marketingLimit)
+ ) {
+ return {
+ isLimitReached: true,
+ limit: marketingLimit,
+ reason: LimitReason.EMAIL_FREE_PLAN_MONTHLY_LIMIT_REACHED,
+ available: marketingLimit - monthlyMarketingUsage,
+ };
+ }
+
+ if (
+ emailType === "TRANSACTIONAL" &&
+ isLimitExceeded(monthlyTransactionalUsage, transactionalLimit)
+ ) {
+ return {
+ isLimitReached: true,
+ limit: transactionalLimit,
+ reason: LimitReason.EMAIL_FREE_PLAN_MONTHLY_LIMIT_REACHED,
+ available: transactionalLimit - monthlyTransactionalUsage,
+ };
+ }
+
+ if (!emailType) {
+ const totalUsage = monthlyMarketingUsage + monthlyTransactionalUsage;
+ if (isLimitExceeded(totalUsage, totalLimit)) {
+ return {
+ isLimitReached: true,
+ limit: totalLimit,
+ reason: LimitReason.EMAIL_FREE_PLAN_MONTHLY_LIMIT_REACHED,
+ available: totalLimit - totalUsage,
+ };
+ }
+ }
+ }
+
// Apply monthly limit logic for FREE plan or inactive subscriptions
if (getActivePlan(team) === "FREE") {
const monthlyUsage = usage.month.reduce(
@@ -367,7 +465,7 @@ export class LimitService {
if (!env.NEXT_PUBLIC_IS_CLOUD) return true;
if (await LimitService.isAdminOrFounderTeam(teamId)) return true;
const team = await TeamService.getTeamCached(teamId);
- return PLAN_LIMITS[getActivePlan(team)].marketingEmailsIncluded;
+ return hasMarketingEnabled(team);
}
}
diff --git a/packages/go-sdk/.gitignore b/packages/go-sdk/.gitignore
new file mode 100644
index 0000000..38b8aab
--- /dev/null
+++ b/packages/go-sdk/.gitignore
@@ -0,0 +1 @@
+.gocache
\ No newline at end of file
diff --git a/packages/go-sdk/LICENSE b/packages/go-sdk/LICENSE
new file mode 100644
index 0000000..f53cd9d
--- /dev/null
+++ b/packages/go-sdk/LICENSE
@@ -0,0 +1,660 @@
+GNU AFFERO GENERAL PUBLIC LICENSE
+ Version 3, 19 November 2007
+
+Copyright (C) 2007 Free Software Foundation, Inc.
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+
+ Preamble
+
+The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate. Many developers of free software are heartened and
+encouraged by the resulting cooperation. However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community. It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server. Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals. This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+0. Definitions.
+
+"This License" refers to version 3 of the GNU Affero General Public License.
+
+"Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+"The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+1. Source Code.
+
+The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+The Corresponding Source for a work in source code form is that
+same work.
+
+2. Basic Permissions.
+
+All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+4. Conveying Verbatim Copies.
+
+You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+5. Conveying Modified Source Versions.
+
+You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+a) The work must carry prominent notices stating that you modified
+it, and giving a relevant date.
+
+b) The work must carry prominent notices stating that it is
+released under this License and any conditions added under section
+7. This requirement modifies the requirement in section 4 to
+"keep intact all notices".
+
+c) You must license the entire work, as a whole, under this
+License to anyone who comes into possession of a copy. This
+License will therefore apply, along with any applicable section 7
+additional terms, to the whole of the work, and all its parts,
+regardless of how they are packaged. This License gives no
+permission to license the work in any other way, but it does not
+invalidate such permission if you have separately received it.
+
+d) If the work has interactive user interfaces, each must display
+Appropriate Legal Notices; however, if the Program has interactive
+interfaces that do not display Appropriate Legal Notices, your
+work need not make them do so.
+
+A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+6. Conveying Non-Source Forms.
+
+You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+a) Convey the object code in, or embodied in, a physical product
+(including a physical distribution medium), accompanied by the
+Corresponding Source fixed on a durable physical medium
+customarily used for software interchange.
+
+b) Convey the object code in, or embodied in, a physical product
+(including a physical distribution medium), accompanied by a
+written offer, valid for at least three years and valid for as
+long as you offer spare parts or customer support for that product
+model, to give anyone who possesses the object code either (1) a
+copy of the Corresponding Source for all the software in the
+product that is covered by this License, on a durable physical
+medium customarily used for software interchange, for a price no
+more than your reasonable cost of physically performing this
+conveying of source, or (2) access to copy the
+Corresponding Source from a network server at no charge.
+
+c) Convey individual copies of the object code with a copy of the
+written offer to provide the Corresponding Source. This
+alternative is allowed only occasionally and noncommercially, and
+only if you received the object code with such an offer, in accord
+with subsection 6b.
+
+d) Convey the object code by offering access from a designated
+place (gratis or for a charge), and offer equivalent access to the
+Corresponding Source in the same way through the same place at no
+further charge. You need not require recipients to copy the
+Corresponding Source along with the object code. If the place to
+copy the object code is a network server, the Corresponding Source
+may be on a different server (operated by you or a third party)
+that supports equivalent copying facilities, provided you maintain
+clear directions next to the object code saying where to find the
+Corresponding Source. Regardless of what server hosts the
+Corresponding Source, you remain obligated to ensure that it is
+available for as long as needed to satisfy these requirements.
+
+e) Convey the object code using peer-to-peer transmission, provided
+you inform other peers where the object code and Corresponding
+Source of the work are being offered to the general public at no
+charge under subsection 6d.
+
+A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+"Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+7. Additional Terms.
+
+"Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+a) Disclaiming warranty or limiting liability differently from the
+terms of sections 15 and 16 of this License; or
+
+b) Requiring preservation of specified reasonable legal notices or
+author attributions in that material or in the Appropriate Legal
+Notices displayed by works containing it; or
+
+c) Prohibiting misrepresentation of the origin of that material, or
+requiring that modified versions of such material be marked in
+reasonable ways as different from the original version; or
+
+d) Limiting the use for publicity purposes of names of licensors or
+authors of the material; or
+
+e) Declining to grant rights under trademark law for use of some
+trade names, trademarks, or service marks; or
+
+f) Requiring indemnification of licensors and authors of that
+material by anyone who conveys the material (or modified versions of
+it) with contractual assumptions of liability to the recipient, for
+any liability that these contractual assumptions directly impose on
+those licensors and authors.
+
+All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+8. Termination.
+
+You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+9. Acceptance Not Required for Having Copies.
+
+You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+10. Automatic Licensing of Downstream Recipients.
+
+Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+11. Patents.
+
+A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+12. No Surrender of Others' Freedom.
+
+If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+13. Remote Network Interaction; Use with the GNU General Public License.
+
+Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software. This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+14. Revised Versions of this License.
+
+The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+15. Disclaimer of Warranty.
+
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+16. Limitation of Liability.
+
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+17. Interpretation of Sections 15 and 16.
+
+If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+How to Apply These Terms to Your New Programs
+
+If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+Copyright (C) 2026 NodeByte LTD
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published
+by the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source. For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code. There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+ .
\ No newline at end of file
diff --git a/packages/go-sdk/README.md b/packages/go-sdk/README.md
new file mode 100644
index 0000000..81f3bf7
--- /dev/null
+++ b/packages/go-sdk/README.md
@@ -0,0 +1,492 @@
+# bytesend-go
+
+The official Go SDK for [ByteSend](https://bytesend.cloud) — a transactional email and campaign platform.
+
+## Table of Contents
+
+- [Installation](#installation)
+- [Quick Start](#quick-start)
+- [Configuration](#configuration)
+- [Error Handling](#error-handling)
+- [Services](#services)
+ - [Emails](#emails)
+ - [Contacts](#contacts)
+ - [Contact Books](#contact-books)
+ - [Domains](#domains)
+ - [Campaigns](#campaigns)
+ - [Analytics](#analytics)
+
+## Installation
+
+```sh
+go get github.com/nodebyteltd/bytesend-go
+```
+
+Requires Go 1.21+.
+
+## Quick Start
+
+```go
+package main
+
+import (
+ "context"
+ "fmt"
+ "log"
+
+ bytesend "github.com/nodebyteltd/bytesend-go"
+)
+
+func main() {
+ client, err := bytesend.NewClient("bs_your_api_key")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ resp, err := client.Emails.Create(context.Background(), bytesend.SendEmailPayload{
+ From: "Acme ",
+ To: []string{"user@example.com"},
+ Subject: "Welcome!",
+ HTML: "Hello! ",
+ })
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Println("Sent:", resp.EmailID)
+}
+```
+
+## Configuration
+
+### API Key
+
+The API key can be passed directly or read automatically from the `BYTESEND_API_KEY` environment variable:
+
+```go
+// Explicit key
+client, err := bytesend.NewClient("bs_your_api_key")
+
+// From environment variable (pass empty string)
+client, err := bytesend.NewClient("")
+```
+
+### Client Options
+
+```go
+import (
+ "net/http"
+ "time"
+)
+
+client, err := bytesend.NewClient("bs_your_api_key",
+ // Override the base URL (useful for testing/proxying)
+ bytesend.WithBaseURL("https://your-proxy.example.com/api/v1"),
+
+ // Supply your own HTTP client (custom timeouts, transport, etc.)
+ bytesend.WithHTTPClient(&http.Client{Timeout: 60 * time.Second}),
+)
+```
+
+## Error Handling
+
+All service methods return a single `error`. API errors are returned as `*ErrorResponse`, which implements the `error` interface. Use `errors.As` to inspect the API error code:
+
+```go
+import "errors"
+
+resp, err := client.Emails.Create(ctx, payload)
+if err != nil {
+ var apiErr *bytesend.ErrorResponse
+ if errors.As(err, &apiErr) {
+ fmt.Println("API error code:", apiErr.Code)
+ fmt.Println("API error message:", apiErr.Message)
+ } else {
+ // Network or encoding error
+ log.Fatal(err)
+ }
+}
+```
+
+## Services
+
+### Emails
+
+#### Send an email
+
+```go
+resp, err := client.Emails.Create(ctx, bytesend.SendEmailPayload{
+ From: "Acme ",
+ To: []string{"user@example.com"},
+ Subject: "Hello!",
+ HTML: "Hello! ",
+ Text: "Hello!",
+})
+// resp.EmailID
+```
+
+#### Send with idempotency key
+
+Passing an idempotency key prevents duplicate sends on retry. The same key + same body returns the original `emailId` without re-sending. The same key + a different body returns an error with code `NOT_UNIQUE`. Keys expire after 24 hours.
+
+```go
+resp, err := client.Emails.Create(ctx, payload, "order-12345")
+```
+
+#### Send with attachments
+
+```go
+content, _ := os.ReadFile("invoice.pdf")
+
+resp, err := client.Emails.Create(ctx, bytesend.SendEmailPayload{
+ From: "Acme ",
+ To: []string{"user@example.com"},
+ Subject: "Your invoice",
+ HTML: "Please find your invoice attached.
",
+ Attachments: []bytesend.Attachment{
+ {Filename: "invoice.pdf", Content: content},
+ },
+})
+```
+
+#### Send with a template
+
+```go
+resp, err := client.Emails.Create(ctx, bytesend.SendEmailPayload{
+ From: "Acme ",
+ To: []string{"user@example.com"},
+ TemplateID: "tmpl_abc123",
+ Variables: map[string]string{"name": "Jane", "plan": "Pro"},
+})
+```
+
+#### Batch send (up to 100 emails)
+
+```go
+resp, err := client.Emails.Batch(ctx, []bytesend.SendEmailPayload{
+ {From: "hello@acme.com", To: []string{"a@example.com"}, Subject: "Hi A", HTML: "Hi A
"},
+ {From: "hello@acme.com", To: []string{"b@example.com"}, Subject: "Hi B", HTML: "Hi B
"},
+}, "batch-idempotency-key") // idempotency key is optional
+// resp.Data — []CreateEmailResponse
+```
+
+#### List emails
+
+```go
+resp, err := client.Emails.List(ctx, bytesend.ListEmailsParams{
+ Page: "1",
+ Limit: "50",
+ StartDate: "2026-01-01T00:00:00Z",
+ EndDate: "2026-01-31T23:59:59Z",
+ DomainID: "123",
+})
+// resp.Data — []EmailSummary
+// resp.Count — total number of emails
+```
+
+#### Get a single email
+
+```go
+email, err := client.Emails.Get(ctx, "em_abc123")
+// email.EmailEvents — full delivery event history
+```
+
+#### Reschedule a scheduled email
+
+```go
+resp, err := client.Emails.Update(ctx, "em_abc123", bytesend.UpdateEmailPayload{
+ ScheduledAt: "2026-06-01T09:00:00Z",
+})
+```
+
+#### Cancel a scheduled email
+
+```go
+resp, err := client.Emails.Cancel(ctx, "em_abc123")
+```
+
+---
+
+### Contacts
+
+#### Create a contact
+
+```go
+subscribed := true
+resp, err := client.Contacts.Create(ctx, "cb_bookid", bytesend.CreateContactPayload{
+ Email: "user@example.com",
+ FirstName: "Jane",
+ LastName: "Doe",
+ Subscribed: &subscribed,
+ Properties: map[string]string{"plan": "pro"},
+})
+// resp.ContactID
+```
+
+#### List contacts
+
+```go
+contacts, err := client.Contacts.List(ctx, "cb_bookid", bytesend.ListContactsParams{
+ Page: "1",
+ Limit: "100",
+ // Emails: "a@example.com,b@example.com" — filter by email addresses
+ // IDs: "ct_1,ct_2" — filter by contact IDs
+})
+```
+
+#### Get a contact
+
+```go
+contact, err := client.Contacts.Get(ctx, "cb_bookid", "ct_contactid")
+```
+
+#### Update a contact
+
+```go
+resp, err := client.Contacts.Update(ctx, "cb_bookid", "ct_contactid", bytesend.UpdateContactPayload{
+ FirstName: "Jane",
+})
+```
+
+#### Upsert a contact
+
+Creates the contact if it doesn't exist, updates it if it does.
+
+```go
+resp, err := client.Contacts.Upsert(ctx, "cb_bookid", "ct_contactid", bytesend.CreateContactPayload{
+ Email: "user@example.com",
+})
+```
+
+#### Delete a contact
+
+```go
+resp, err := client.Contacts.Delete(ctx, "cb_bookid", "ct_contactid")
+// resp.Success
+```
+
+#### Bulk create contacts (up to 1,000)
+
+```go
+resp, err := client.Contacts.BulkCreate(ctx, "cb_bookid", []bytesend.CreateContactPayload{
+ {Email: "a@example.com", FirstName: "Alice"},
+ {Email: "b@example.com", FirstName: "Bob"},
+})
+// resp.Count — number of contacts created
+```
+
+#### Bulk delete contacts (up to 1,000)
+
+```go
+resp, err := client.Contacts.BulkDelete(ctx, "cb_bookid", bytesend.BulkDeleteContactsPayload{
+ ContactIDs: []string{"ct_1", "ct_2"},
+})
+// resp.Count — number of contacts deleted
+```
+
+---
+
+### Contact Books
+
+#### List contact books
+
+```go
+books, err := client.ContactBooks.List(ctx)
+// books — []ContactBook, each with books[i].Count.Contacts
+```
+
+#### Create a contact book
+
+```go
+book, err := client.ContactBooks.Create(ctx, bytesend.CreateContactBookPayload{
+ Name: "Newsletter",
+ Emoji: "📬",
+ Variables: []string{"firstName", "company"},
+})
+```
+
+#### Get a contact book
+
+```go
+book, err := client.ContactBooks.Get(ctx, "cb_bookid")
+// book.Count.Contacts — total contact count
+```
+
+#### Update a contact book
+
+```go
+book, err := client.ContactBooks.Update(ctx, "cb_bookid", bytesend.UpdateContactBookPayload{
+ Name: "Weekly Newsletter",
+})
+```
+
+#### Enable double opt-in
+
+```go
+enabled := true
+book, err := client.ContactBooks.Update(ctx, "cb_bookid", bytesend.UpdateContactBookPayload{
+ DoubleOptInEnabled: &enabled,
+ DoubleOptInFrom: "Newsletter ",
+ DoubleOptInSubject: "Please confirm your subscription",
+})
+```
+
+#### Delete a contact book
+
+```go
+resp, err := client.ContactBooks.Delete(ctx, "cb_bookid")
+// resp.Success
+```
+
+---
+
+### Domains
+
+#### List domains
+
+```go
+domains, err := client.Domains.List(ctx)
+```
+
+#### Create a domain
+
+```go
+domain, err := client.Domains.Create(ctx, bytesend.CreateDomainPayload{
+ Name: "mail.acme.com",
+ Region: "us-east-1",
+})
+// domain.DNSRecords — DNS records to add at your DNS provider
+```
+
+#### Get a domain
+
+```go
+domain, err := client.Domains.Get(ctx, "1")
+// domain.Status — NOT_STARTED | PENDING | SUCCESS | FAILED | TEMPORARY_FAILURE
+```
+
+#### Verify a domain
+
+Triggers a DNS verification check.
+
+```go
+resp, err := client.Domains.Verify(ctx, "1")
+// resp.Message
+```
+
+#### Delete a domain
+
+```go
+resp, err := client.Domains.Delete(ctx, "1")
+// resp.Success
+```
+
+---
+
+### Campaigns
+
+#### Create a campaign
+
+```go
+campaign, err := client.Campaigns.Create(ctx, bytesend.CreateCampaignPayload{
+ Name: "May Newsletter",
+ From: "Acme ",
+ Subject: "What's new in May",
+ ContactBookID: "cb_bookid",
+ HTML: "Hello from Acme! ",
+ PreviewText: "Here's what's new this month",
+})
+```
+
+#### Create and send immediately
+
+```go
+campaign, err := client.Campaigns.Create(ctx, bytesend.CreateCampaignPayload{
+ Name: "Flash Sale",
+ From: "Acme ",
+ Subject: "Flash sale — 24 hours only",
+ ContactBookID: "cb_bookid",
+ HTML: "Sale is live!
",
+ SendNow: true,
+})
+```
+
+#### List campaigns
+
+```go
+resp, err := client.Campaigns.List(ctx, bytesend.ListCampaignsParams{
+ Page: "1",
+ Status: "DRAFT", // DRAFT | SCHEDULED | RUNNING | PAUSED | SENT
+ Search: "newsletter",
+})
+// resp.Campaigns — []CampaignSummary
+// resp.TotalPage
+```
+
+#### Get a campaign
+
+```go
+campaign, err := client.Campaigns.Get(ctx, "cmp_123")
+// campaign.Sent, campaign.Delivered, campaign.Opened, campaign.Clicked, ...
+```
+
+#### Schedule a campaign
+
+```go
+resp, err := client.Campaigns.Schedule(ctx, "cmp_123", bytesend.ScheduleCampaignPayload{
+ ScheduledAt: "2026-06-01T09:00:00Z",
+ BatchSize: 500, // emails per batch window
+})
+```
+
+#### Pause a campaign
+
+```go
+resp, err := client.Campaigns.Pause(ctx, "cmp_123")
+// resp.Success
+```
+
+#### Resume a campaign
+
+```go
+resp, err := client.Campaigns.Resume(ctx, "cmp_123")
+// resp.Success
+```
+
+#### Delete a campaign
+
+```go
+campaign, err := client.Campaigns.Delete(ctx, "cmp_123")
+```
+
+---
+
+### Analytics
+
+#### Email time series
+
+Returns per-day send, delivery, and engagement counts for the last 7 or 30 days.
+
+```go
+resp, err := client.Analytics.EmailTimeSeries(ctx, bytesend.EmailTimeSeriesParams{
+ Days: "30", // "7" or "30"
+ DomainID: "123",
+})
+// resp.Result — []EmailTimeSeriesEntry{Date, Sent, Delivered, Opened, Clicked, Bounced, Complained}
+// resp.TotalCounts — EmailTotals (aggregate over the period)
+```
+
+#### Reputation metrics
+
+```go
+resp, err := client.Analytics.ReputationMetrics(ctx, bytesend.ReputationMetricsParams{
+ DomainID: "123",
+})
+// resp.BounceRate float64
+// resp.ComplaintRate float64
+// resp.HardBounced int
+```
+
+## License
+
+[AGPL-3.0](LICENSE) © [NodeByte LTD](https://nodebyte.co.uk)
diff --git a/packages/go-sdk/analytics.go b/packages/go-sdk/analytics.go
new file mode 100644
index 0000000..f63a593
--- /dev/null
+++ b/packages/go-sdk/analytics.go
@@ -0,0 +1,67 @@
+package bytesend
+
+import "context"
+
+type EmailTimeSeriesParams struct {
+ Days string
+ DomainID string
+}
+
+type EmailTimeSeriesEntry struct {
+ Date string `json:"date"`
+ Sent int `json:"sent"`
+ Delivered int `json:"delivered"`
+ Opened int `json:"opened"`
+ Clicked int `json:"clicked"`
+ Bounced int `json:"bounced"`
+ Complained int `json:"complained"`
+}
+
+type EmailTotals struct {
+ Sent int `json:"sent"`
+ Delivered int `json:"delivered"`
+ Opened int `json:"opened"`
+ Clicked int `json:"clicked"`
+ Bounced int `json:"bounced"`
+ Complained int `json:"complained"`
+}
+
+type EmailTimeSeriesResponse struct {
+ Result []EmailTimeSeriesEntry `json:"result"`
+ TotalCounts EmailTotals `json:"totalCounts"`
+}
+
+type ReputationMetricsParams struct {
+ DomainID string
+}
+
+type ReputationMetricsResponse struct {
+ Delivered int `json:"delivered"`
+ HardBounced int `json:"hardBounced"`
+ Complained int `json:"complained"`
+ BounceRate float64 `json:"bounceRate"`
+ ComplaintRate float64 `json:"complaintRate"`
+}
+
+type AnalyticsService struct {
+ client *Client
+}
+
+func (s *AnalyticsService) EmailTimeSeries(ctx context.Context, params EmailTimeSeriesParams) (EmailTimeSeriesResponse, error) {
+ path := s.client.buildPath("/analytics/email-time-series", map[string]string{
+ "days": params.Days,
+ "domainId": params.DomainID,
+ })
+ var resp EmailTimeSeriesResponse
+ err := s.client.get(ctx, path, &resp)
+ return resp, err
+}
+
+func (s *AnalyticsService) ReputationMetrics(ctx context.Context, params ReputationMetricsParams) (ReputationMetricsResponse, error) {
+ path := s.client.buildPath("/analytics/reputation-metrics", map[string]string{
+ "domainId": params.DomainID,
+ })
+ var resp ReputationMetricsResponse
+ err := s.client.get(ctx, path, &resp)
+ return resp, err
+}
diff --git a/packages/go-sdk/campaigns.go b/packages/go-sdk/campaigns.go
new file mode 100644
index 0000000..581cbce
--- /dev/null
+++ b/packages/go-sdk/campaigns.go
@@ -0,0 +1,134 @@
+package bytesend
+
+import "context"
+
+type Campaign struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ From string `json:"from"`
+ Subject string `json:"subject"`
+ PreviewText string `json:"previewText"`
+ ContactBookID string `json:"contactBookId"`
+ HTML string `json:"html"`
+ Content string `json:"content"`
+ Status string `json:"status"`
+ ScheduledAt string `json:"scheduledAt"`
+ BatchSize int `json:"batchSize"`
+ BatchWindowMinutes int `json:"batchWindowMinutes"`
+ Total int `json:"total"`
+ Sent int `json:"sent"`
+ Delivered int `json:"delivered"`
+ Opened int `json:"opened"`
+ Clicked int `json:"clicked"`
+ Unsubscribed int `json:"unsubscribed"`
+ Bounced int `json:"bounced"`
+ HardBounced int `json:"hardBounced"`
+ Complained int `json:"complained"`
+ ReplyTo []string `json:"replyTo"`
+ CC []string `json:"cc"`
+ BCC []string `json:"bcc"`
+ CreatedAt string `json:"createdAt"`
+ UpdatedAt string `json:"updatedAt"`
+}
+
+type CampaignSummary struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ From string `json:"from"`
+ Subject string `json:"subject"`
+ Status string `json:"status"`
+ ScheduledAt string `json:"scheduledAt"`
+ Total int `json:"total"`
+ Sent int `json:"sent"`
+ Delivered int `json:"delivered"`
+ Unsubscribed int `json:"unsubscribed"`
+ CreatedAt string `json:"createdAt"`
+ UpdatedAt string `json:"updatedAt"`
+}
+
+type CreateCampaignPayload struct {
+ Name string `json:"name"`
+ From string `json:"from"`
+ Subject string `json:"subject"`
+ ContactBookID string `json:"contactBookId"`
+ PreviewText string `json:"previewText,omitempty"`
+ Content string `json:"content,omitempty"`
+ HTML string `json:"html,omitempty"`
+ ReplyTo StringSlice `json:"replyTo,omitempty"`
+ CC StringSlice `json:"cc,omitempty"`
+ BCC StringSlice `json:"bcc,omitempty"`
+ SendNow bool `json:"sendNow,omitempty"`
+ ScheduledAt string `json:"scheduledAt,omitempty"`
+ BatchSize int `json:"batchSize,omitempty"`
+}
+
+type ListCampaignsParams struct {
+ Page string
+ Status string
+ Search string
+}
+
+type ListCampaignsResponse struct {
+ Campaigns []CampaignSummary `json:"campaigns"`
+ TotalPage int `json:"totalPage"`
+}
+
+type ScheduleCampaignPayload struct {
+ ScheduledAt string `json:"scheduledAt,omitempty"`
+ BatchSize int `json:"batchSize,omitempty"`
+}
+
+type CampaignActionResponse struct {
+ Success bool `json:"success"`
+}
+
+type CampaignsService struct {
+ client *Client
+}
+
+func (s *CampaignsService) Create(ctx context.Context, payload CreateCampaignPayload) (Campaign, error) {
+ var resp Campaign
+ err := s.client.post(ctx, "/campaigns", payload, &resp)
+ return resp, err
+}
+
+func (s *CampaignsService) List(ctx context.Context, params ListCampaignsParams) (ListCampaignsResponse, error) {
+ path := s.client.buildPath("/campaigns", map[string]string{
+ "page": params.Page,
+ "status": params.Status,
+ "search": params.Search,
+ })
+ var resp ListCampaignsResponse
+ err := s.client.get(ctx, path, &resp)
+ return resp, err
+}
+
+func (s *CampaignsService) Get(ctx context.Context, campaignID string) (Campaign, error) {
+ var resp Campaign
+ err := s.client.get(ctx, "/campaigns/"+campaignID, &resp)
+ return resp, err
+}
+
+func (s *CampaignsService) Delete(ctx context.Context, campaignID string) (Campaign, error) {
+ var resp Campaign
+ err := s.client.delete(ctx, "/campaigns/"+campaignID, nil, &resp)
+ return resp, err
+}
+
+func (s *CampaignsService) Schedule(ctx context.Context, campaignID string, payload ScheduleCampaignPayload) (CampaignActionResponse, error) {
+ var resp CampaignActionResponse
+ err := s.client.post(ctx, "/campaigns/"+campaignID+"/schedule", payload, &resp)
+ return resp, err
+}
+
+func (s *CampaignsService) Pause(ctx context.Context, campaignID string) (CampaignActionResponse, error) {
+ var resp CampaignActionResponse
+ err := s.client.post(ctx, "/campaigns/"+campaignID+"/pause", nil, &resp)
+ return resp, err
+}
+
+func (s *CampaignsService) Resume(ctx context.Context, campaignID string) (CampaignActionResponse, error) {
+ var resp CampaignActionResponse
+ err := s.client.post(ctx, "/campaigns/"+campaignID+"/resume", nil, &resp)
+ return resp, err
+}
diff --git a/packages/go-sdk/client.go b/packages/go-sdk/client.go
new file mode 100644
index 0000000..5ca8f82
--- /dev/null
+++ b/packages/go-sdk/client.go
@@ -0,0 +1,153 @@
+package bytesend
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "errors"
+ "io"
+ "net/http"
+ "net/url"
+ "os"
+ "time"
+)
+
+const defaultBaseURL = "https://bytesend.cloud/api/v1"
+const userAgent = "bytesend-go/0.1.0"
+const maxResponseBodyBytes int64 = 10 * 1024 * 1024 // 10 MB
+
+type Client struct {
+ apiKey string
+ baseURL string
+ httpClient *http.Client
+
+ Emails *EmailsService
+ Contacts *ContactsService
+ ContactBooks *ContactBooksService
+ Domains *DomainsService
+ Campaigns *CampaignsService
+ Analytics *AnalyticsService
+}
+
+type ClientOption func(*Client)
+
+func WithBaseURL(url string) ClientOption {
+ return func(c *Client) {
+ c.baseURL = url
+ }
+}
+
+func WithHTTPClient(h *http.Client) ClientOption {
+ return func(c *Client) {
+ c.httpClient = h
+ }
+}
+
+func NewClient(apiKey string, opts ...ClientOption) (*Client, error) {
+ if apiKey == "" {
+ apiKey = os.Getenv("BYTESEND_API_KEY")
+ if apiKey == "" {
+ return nil, errors.New("missing API key")
+ }
+ }
+
+ c := &Client{
+ apiKey: apiKey,
+ baseURL: defaultBaseURL,
+ httpClient: &http.Client{Timeout: 30 * time.Second},
+ }
+
+ for _, opt := range opts {
+ opt(c)
+ }
+
+ c.Emails = &EmailsService{client: c}
+ c.Contacts = &ContactsService{client: c}
+ c.ContactBooks = &ContactBooksService{client: c}
+ c.Domains = &DomainsService{client: c}
+ c.Campaigns = &CampaignsService{client: c}
+ c.Analytics = &AnalyticsService{client: c}
+
+ return c, nil
+}
+
+func (c *Client) buildPath(path string, params map[string]string) string {
+ v := url.Values{}
+ for k, val := range params {
+ if val != "" {
+ v.Set(k, val)
+ }
+ }
+ if len(v) == 0 {
+ return path
+ }
+ return path + "?" + v.Encode()
+}
+
+func (c *Client) doRequest(ctx context.Context, method, path string, body any, v any, extraHeaders map[string]string) error {
+ var buf io.Reader
+ if body != nil {
+ b := &bytes.Buffer{}
+ if err := json.NewEncoder(b).Encode(body); err != nil {
+ return err
+ }
+ buf = b
+ }
+
+ req, err := http.NewRequestWithContext(ctx, method, c.baseURL+path, buf)
+ if err != nil {
+ return err
+ }
+ req.Header.Set("Authorization", "Bearer "+c.apiKey)
+ req.Header.Set("Content-Type", "application/json")
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("User-Agent", userAgent)
+ for k, val := range extraHeaders {
+ req.Header.Set(k, val)
+ }
+
+ resp, err := c.httpClient.Do(req)
+ if err != nil {
+ return err
+ }
+ defer resp.Body.Close()
+
+ limited := io.LimitReader(resp.Body, maxResponseBodyBytes)
+
+ if resp.StatusCode >= 200 && resp.StatusCode < 300 {
+ if v != nil {
+ if err := json.NewDecoder(limited).Decode(v); err != nil && err != io.EOF {
+ return err
+ }
+ }
+ return nil
+ }
+
+ errResp := &ErrorResponse{Message: resp.Status, Code: "INTERNAL_SERVER_ERROR"}
+ _ = json.NewDecoder(limited).Decode(errResp)
+ return errResp
+}
+
+func (c *Client) get(ctx context.Context, path string, out any) error {
+ return c.doRequest(ctx, http.MethodGet, path, nil, out, nil)
+}
+
+func (c *Client) post(ctx context.Context, path string, body any, out any) error {
+ return c.doRequest(ctx, http.MethodPost, path, body, out, nil)
+}
+
+func (c *Client) postWithHeaders(ctx context.Context, path string, body any, out any, headers map[string]string) error {
+ return c.doRequest(ctx, http.MethodPost, path, body, out, headers)
+}
+
+func (c *Client) put(ctx context.Context, path string, body any, out any) error {
+ return c.doRequest(ctx, http.MethodPut, path, body, out, nil)
+}
+
+func (c *Client) patch(ctx context.Context, path string, body any, out any) error {
+ return c.doRequest(ctx, http.MethodPatch, path, body, out, nil)
+}
+
+func (c *Client) delete(ctx context.Context, path string, body any, out any) error {
+ return c.doRequest(ctx, http.MethodDelete, path, body, out, nil)
+}
diff --git a/packages/go-sdk/contact_books.go b/packages/go-sdk/contact_books.go
new file mode 100644
index 0000000..79ca52e
--- /dev/null
+++ b/packages/go-sdk/contact_books.go
@@ -0,0 +1,85 @@
+package bytesend
+
+import "context"
+
+type ContactBookCount struct {
+ Contacts int `json:"contacts"`
+}
+
+type ContactBook struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ TeamID int `json:"teamId"`
+ Properties map[string]string `json:"properties"`
+ Variables []string `json:"variables"`
+ Emoji string `json:"emoji"`
+ DoubleOptInEnabled bool `json:"doubleOptInEnabled,omitempty"`
+ DoubleOptInFrom string `json:"doubleOptInFrom,omitempty"`
+ DoubleOptInSubject string `json:"doubleOptInSubject,omitempty"`
+ DoubleOptInContent string `json:"doubleOptInContent,omitempty"`
+ CreatedAt string `json:"createdAt"`
+ UpdatedAt string `json:"updatedAt"`
+ Count *ContactBookCount `json:"_count,omitempty"`
+}
+
+type CreateContactBookPayload struct {
+ Name string `json:"name"`
+ Emoji string `json:"emoji,omitempty"`
+ Properties map[string]string `json:"properties,omitempty"`
+ Variables []string `json:"variables,omitempty"`
+ DoubleOptInEnabled *bool `json:"doubleOptInEnabled,omitempty"`
+ DoubleOptInFrom string `json:"doubleOptInFrom,omitempty"`
+ DoubleOptInSubject string `json:"doubleOptInSubject,omitempty"`
+ DoubleOptInContent string `json:"doubleOptInContent,omitempty"`
+}
+
+type UpdateContactBookPayload struct {
+ Name string `json:"name,omitempty"`
+ Emoji string `json:"emoji,omitempty"`
+ Properties map[string]string `json:"properties,omitempty"`
+ Variables []string `json:"variables,omitempty"`
+ DoubleOptInEnabled *bool `json:"doubleOptInEnabled,omitempty"`
+ DoubleOptInFrom string `json:"doubleOptInFrom,omitempty"`
+ DoubleOptInSubject string `json:"doubleOptInSubject,omitempty"`
+ DoubleOptInContent string `json:"doubleOptInContent,omitempty"`
+}
+
+type DeleteContactBookResponse struct {
+ ID string `json:"id"`
+ Success bool `json:"success"`
+ Message string `json:"message"`
+}
+
+type ContactBooksService struct {
+ client *Client
+}
+
+func (s *ContactBooksService) List(ctx context.Context) ([]ContactBook, error) {
+ var resp []ContactBook
+ err := s.client.get(ctx, "/contactBooks", &resp)
+ return resp, err
+}
+
+func (s *ContactBooksService) Create(ctx context.Context, payload CreateContactBookPayload) (ContactBook, error) {
+ var resp ContactBook
+ err := s.client.post(ctx, "/contactBooks", payload, &resp)
+ return resp, err
+}
+
+func (s *ContactBooksService) Get(ctx context.Context, contactBookID string) (ContactBook, error) {
+ var resp ContactBook
+ err := s.client.get(ctx, "/contactBooks/"+contactBookID, &resp)
+ return resp, err
+}
+
+func (s *ContactBooksService) Update(ctx context.Context, contactBookID string, payload UpdateContactBookPayload) (ContactBook, error) {
+ var resp ContactBook
+ err := s.client.patch(ctx, "/contactBooks/"+contactBookID, payload, &resp)
+ return resp, err
+}
+
+func (s *ContactBooksService) Delete(ctx context.Context, contactBookID string) (DeleteContactBookResponse, error) {
+ var resp DeleteContactBookResponse
+ err := s.client.delete(ctx, "/contactBooks/"+contactBookID, nil, &resp)
+ return resp, err
+}
diff --git a/packages/go-sdk/contacts.go b/packages/go-sdk/contacts.go
new file mode 100644
index 0000000..30c67a8
--- /dev/null
+++ b/packages/go-sdk/contacts.go
@@ -0,0 +1,117 @@
+package bytesend
+
+import "context"
+
+type Contact struct {
+ ID string `json:"id"`
+ FirstName string `json:"firstName,omitempty"`
+ LastName string `json:"lastName,omitempty"`
+ Email string `json:"email"`
+ Subscribed bool `json:"subscribed"`
+ Properties map[string]string `json:"properties"`
+ ContactBookID string `json:"contactBookId"`
+ CreatedAt string `json:"createdAt"`
+ UpdatedAt string `json:"updatedAt"`
+}
+
+type CreateContactPayload struct {
+ Email string `json:"email"`
+ FirstName string `json:"firstName,omitempty"`
+ LastName string `json:"lastName,omitempty"`
+ Properties map[string]string `json:"properties,omitempty"`
+ Subscribed *bool `json:"subscribed,omitempty"`
+}
+
+type UpdateContactPayload struct {
+ FirstName string `json:"firstName,omitempty"`
+ LastName string `json:"lastName,omitempty"`
+ Properties map[string]string `json:"properties,omitempty"`
+ Subscribed *bool `json:"subscribed,omitempty"`
+}
+
+type CreateContactResponse struct {
+ ContactID string `json:"contactId"`
+}
+
+type DeleteContactResponse struct {
+ Success bool `json:"success"`
+}
+
+type ListContactsParams struct {
+ Emails string
+ Page string
+ Limit string
+ IDs string
+}
+
+type BulkCreateContactsResponse struct {
+ Message string `json:"message"`
+ Count int `json:"count"`
+}
+
+type BulkDeleteContactsPayload struct {
+ ContactIDs []string `json:"contactIds"`
+}
+
+type BulkDeleteContactsResponse struct {
+ Success bool `json:"success"`
+ Count int `json:"count"`
+}
+
+type ContactsService struct {
+ client *Client
+}
+
+func (c *ContactsService) Create(ctx context.Context, contactBookID string, payload CreateContactPayload) (CreateContactResponse, error) {
+ var resp CreateContactResponse
+ err := c.client.post(ctx, "/contactBooks/"+contactBookID+"/contacts", payload, &resp)
+ return resp, err
+}
+
+func (c *ContactsService) Get(ctx context.Context, contactBookID, contactID string) (Contact, error) {
+ var resp Contact
+ err := c.client.get(ctx, "/contactBooks/"+contactBookID+"/contacts/"+contactID, &resp)
+ return resp, err
+}
+
+func (c *ContactsService) Update(ctx context.Context, contactBookID, contactID string, payload UpdateContactPayload) (CreateContactResponse, error) {
+ var resp CreateContactResponse
+ err := c.client.patch(ctx, "/contactBooks/"+contactBookID+"/contacts/"+contactID, payload, &resp)
+ return resp, err
+}
+
+func (c *ContactsService) Upsert(ctx context.Context, contactBookID, contactID string, payload CreateContactPayload) (CreateContactResponse, error) {
+ var resp CreateContactResponse
+ err := c.client.put(ctx, "/contactBooks/"+contactBookID+"/contacts/"+contactID, payload, &resp)
+ return resp, err
+}
+
+func (c *ContactsService) List(ctx context.Context, contactBookID string, params ListContactsParams) ([]Contact, error) {
+ path := c.client.buildPath("/contactBooks/"+contactBookID+"/contacts", map[string]string{
+ "emails": params.Emails,
+ "page": params.Page,
+ "limit": params.Limit,
+ "ids": params.IDs,
+ })
+ var resp []Contact
+ err := c.client.get(ctx, path, &resp)
+ return resp, err
+}
+
+func (c *ContactsService) BulkCreate(ctx context.Context, contactBookID string, payload []CreateContactPayload) (BulkCreateContactsResponse, error) {
+ var resp BulkCreateContactsResponse
+ err := c.client.post(ctx, "/contactBooks/"+contactBookID+"/contacts/bulk", payload, &resp)
+ return resp, err
+}
+
+func (c *ContactsService) BulkDelete(ctx context.Context, contactBookID string, payload BulkDeleteContactsPayload) (BulkDeleteContactsResponse, error) {
+ var resp BulkDeleteContactsResponse
+ err := c.client.delete(ctx, "/contactBooks/"+contactBookID+"/contacts/bulk", payload, &resp)
+ return resp, err
+}
+
+func (c *ContactsService) Delete(ctx context.Context, contactBookID, contactID string) (DeleteContactResponse, error) {
+ var resp DeleteContactResponse
+ err := c.client.delete(ctx, "/contactBooks/"+contactBookID+"/contacts/"+contactID, nil, &resp)
+ return resp, err
+}
diff --git a/packages/go-sdk/domains.go b/packages/go-sdk/domains.go
new file mode 100644
index 0000000..7c318d6
--- /dev/null
+++ b/packages/go-sdk/domains.go
@@ -0,0 +1,84 @@
+package bytesend
+
+import "context"
+
+type DNSRecord struct {
+ Type string `json:"type"`
+ Name string `json:"name"`
+ Value string `json:"value"`
+ TTL string `json:"ttl"`
+ Priority string `json:"priority,omitempty"`
+ Status string `json:"status"`
+ Recommended bool `json:"recommended,omitempty"`
+}
+
+type Domain struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ TeamID int `json:"teamId"`
+ Status string `json:"status"`
+ Region string `json:"region"`
+ ClickTracking bool `json:"clickTracking"`
+ OpenTracking bool `json:"openTracking"`
+ PublicKey string `json:"publicKey"`
+ DKIMStatus string `json:"dkimStatus,omitempty"`
+ SPFDetails string `json:"spfDetails,omitempty"`
+ CreatedAt string `json:"createdAt"`
+ UpdatedAt string `json:"updatedAt"`
+ DMARCAdded bool `json:"dmarcAdded"`
+ IsVerifying bool `json:"isVerifying"`
+ ErrorMessage string `json:"errorMessage,omitempty"`
+ Subdomain string `json:"subdomain,omitempty"`
+ VerificationError string `json:"verificationError,omitempty"`
+ LastCheckedTime string `json:"lastCheckedTime,omitempty"`
+ DNSRecords []DNSRecord `json:"dnsRecords"`
+}
+
+type CreateDomainPayload struct {
+ Name string `json:"name"`
+ Region string `json:"region"`
+}
+
+type DeleteDomainResponse struct {
+ ID int `json:"id"`
+ Success bool `json:"success"`
+ Message string `json:"message"`
+}
+
+type VerifyDomainResponse struct {
+ Message string `json:"message"`
+}
+
+type DomainsService struct {
+ client *Client
+}
+
+func (s *DomainsService) List(ctx context.Context) ([]Domain, error) {
+ var resp []Domain
+ err := s.client.get(ctx, "/domains", &resp)
+ return resp, err
+}
+
+func (s *DomainsService) Create(ctx context.Context, payload CreateDomainPayload) (Domain, error) {
+ var resp Domain
+ err := s.client.post(ctx, "/domains", payload, &resp)
+ return resp, err
+}
+
+func (s *DomainsService) Get(ctx context.Context, id string) (Domain, error) {
+ var resp Domain
+ err := s.client.get(ctx, "/domains/"+id, &resp)
+ return resp, err
+}
+
+func (s *DomainsService) Verify(ctx context.Context, id string) (VerifyDomainResponse, error) {
+ var resp VerifyDomainResponse
+ err := s.client.put(ctx, "/domains/"+id+"/verify", nil, &resp)
+ return resp, err
+}
+
+func (s *DomainsService) Delete(ctx context.Context, id string) (DeleteDomainResponse, error) {
+ var resp DeleteDomainResponse
+ err := s.client.delete(ctx, "/domains/"+id, nil, &resp)
+ return resp, err
+}
diff --git a/packages/go-sdk/emails.go b/packages/go-sdk/emails.go
new file mode 100644
index 0000000..c3d35df
--- /dev/null
+++ b/packages/go-sdk/emails.go
@@ -0,0 +1,151 @@
+package bytesend
+
+import "context"
+
+type Attachment struct {
+ Filename string `json:"filename"`
+ Content []byte `json:"content"`
+}
+
+type SendEmailPayload struct {
+ To []string `json:"to"`
+ From string `json:"from"`
+ Subject string `json:"subject,omitempty"`
+ TemplateID string `json:"templateId,omitempty"`
+ Variables map[string]string `json:"variables,omitempty"`
+ ReplyTo []string `json:"replyTo,omitempty"`
+ CC []string `json:"cc,omitempty"`
+ BCC []string `json:"bcc,omitempty"`
+ Text string `json:"text,omitempty"`
+ HTML string `json:"html,omitempty"`
+ Headers map[string]string `json:"headers,omitempty"`
+ Attachments []Attachment `json:"attachments,omitempty"`
+ ScheduledAt string `json:"scheduledAt,omitempty"`
+ InReplyToID string `json:"inReplyToId,omitempty"`
+}
+
+type CreateEmailResponse struct {
+ EmailID string `json:"emailId"`
+}
+
+type Email struct {
+ ID string `json:"id"`
+ TeamID int `json:"teamId"`
+ To StringSlice `json:"to"`
+ ReplyTo StringSlice `json:"replyTo,omitempty"`
+ CC StringSlice `json:"cc,omitempty"`
+ BCC StringSlice `json:"bcc,omitempty"`
+ From string `json:"from"`
+ Subject string `json:"subject"`
+ HTML string `json:"html"`
+ Text string `json:"text"`
+ CreatedAt string `json:"createdAt"`
+ UpdatedAt string `json:"updatedAt"`
+ EmailEvents []EmailEvent `json:"emailEvents"`
+}
+
+type EmailEvent struct {
+ EmailID string `json:"emailId"`
+ Status string `json:"status"`
+ CreatedAt string `json:"createdAt"`
+ Data any `json:"data,omitempty"`
+}
+
+type UpdateEmailPayload struct {
+ ScheduledAt string `json:"scheduledAt"`
+}
+
+type BatchEmailResponse struct {
+ Data []CreateEmailResponse `json:"data"`
+}
+
+type EmailSummary struct {
+ ID string `json:"id"`
+ To StringSlice `json:"to"`
+ ReplyTo StringSlice `json:"replyTo,omitempty"`
+ CC StringSlice `json:"cc,omitempty"`
+ BCC StringSlice `json:"bcc,omitempty"`
+ From string `json:"from"`
+ Subject string `json:"subject"`
+ HTML string `json:"html"`
+ Text string `json:"text"`
+ CreatedAt string `json:"createdAt"`
+ UpdatedAt string `json:"updatedAt"`
+ LatestStatus string `json:"latestStatus"`
+ ScheduledAt string `json:"scheduledAt"`
+ DomainID *int `json:"domainId"`
+}
+
+type ListEmailsParams struct {
+ Page string
+ Limit string
+ StartDate string
+ EndDate string
+ DomainID string
+}
+
+type ListEmailsResponse struct {
+ Data []EmailSummary `json:"data"`
+ Count int `json:"count"`
+}
+
+type EmailsService struct {
+ client *Client
+}
+
+func (e *EmailsService) Create(ctx context.Context, payload SendEmailPayload, idempotencyKey ...string) (CreateEmailResponse, error) {
+ var resp CreateEmailResponse
+ var err error
+ if len(idempotencyKey) > 0 && idempotencyKey[0] != "" {
+ err = e.client.postWithHeaders(ctx, "/emails", payload, &resp, map[string]string{
+ "Idempotency-Key": idempotencyKey[0],
+ })
+ } else {
+ err = e.client.post(ctx, "/emails", payload, &resp)
+ }
+ return resp, err
+}
+
+func (e *EmailsService) Batch(ctx context.Context, payload []SendEmailPayload, idempotencyKey ...string) (BatchEmailResponse, error) {
+ var resp BatchEmailResponse
+ var err error
+ if len(idempotencyKey) > 0 && idempotencyKey[0] != "" {
+ err = e.client.postWithHeaders(ctx, "/emails/batch", payload, &resp, map[string]string{
+ "Idempotency-Key": idempotencyKey[0],
+ })
+ } else {
+ err = e.client.post(ctx, "/emails/batch", payload, &resp)
+ }
+ return resp, err
+}
+
+func (e *EmailsService) List(ctx context.Context, params ListEmailsParams) (ListEmailsResponse, error) {
+ path := e.client.buildPath("/emails", map[string]string{
+ "page": params.Page,
+ "limit": params.Limit,
+ "startDate": params.StartDate,
+ "endDate": params.EndDate,
+ "domainId": params.DomainID,
+ })
+ var resp ListEmailsResponse
+ err := e.client.get(ctx, path, &resp)
+ return resp, err
+}
+
+func (e *EmailsService) Get(ctx context.Context, id string) (Email, error) {
+ var resp Email
+ err := e.client.get(ctx, "/emails/"+id, &resp)
+ return resp, err
+}
+
+func (e *EmailsService) Update(ctx context.Context, id string, payload UpdateEmailPayload) (CreateEmailResponse, error) {
+ var resp CreateEmailResponse
+ err := e.client.patch(ctx, "/emails/"+id, payload, &resp)
+ return resp, err
+}
+
+func (e *EmailsService) Cancel(ctx context.Context, id string) (CreateEmailResponse, error) {
+ var resp CreateEmailResponse
+ err := e.client.post(ctx, "/emails/"+id+"/cancel", nil, &resp)
+ return resp, err
+}
diff --git a/packages/go-sdk/go.mod b/packages/go-sdk/go.mod
new file mode 100644
index 0000000..3f9e885
--- /dev/null
+++ b/packages/go-sdk/go.mod
@@ -0,0 +1,3 @@
+module github.com/nodebyteltd/bytesend-go
+
+go 1.21
diff --git a/packages/go-sdk/types.go b/packages/go-sdk/types.go
new file mode 100644
index 0000000..ddb42c4
--- /dev/null
+++ b/packages/go-sdk/types.go
@@ -0,0 +1,45 @@
+package bytesend
+
+import (
+ "encoding/json"
+ "fmt"
+)
+
+type ErrorResponse struct {
+ Message string `json:"message"`
+ Code string `json:"code"`
+}
+
+func (e *ErrorResponse) Error() string {
+ return fmt.Sprintf("%s: %s", e.Code, e.Message)
+}
+
+// StringSlice unmarshals a JSON value that can be either a string or an array of strings
+// into a Go []string. This accommodates API responses that may return a single string
+// or multiple values interchangeably.
+type StringSlice []string
+
+func (s *StringSlice) UnmarshalJSON(b []byte) error {
+ // Try to unmarshal as an array of strings first
+ var arr []string
+ if err := json.Unmarshal(b, &arr); err == nil {
+ *s = arr
+ return nil
+ }
+
+ // Try to unmarshal as a single string
+ var single string
+ if err := json.Unmarshal(b, &single); err == nil {
+ *s = []string{single}
+ return nil
+ }
+
+ // Accept null as nil slice
+ if string(b) == "null" {
+ *s = nil
+ return nil
+ }
+
+ // Fallback: return original error by attempting array once more
+ return json.Unmarshal(b, &arr)
+}
diff --git a/packages/lib/src/stripe/plans.ts b/packages/lib/src/stripe/plans.ts
index 9a9fe4d..44367cd 100644
--- a/packages/lib/src/stripe/plans.ts
+++ b/packages/lib/src/stripe/plans.ts
@@ -22,14 +22,14 @@ export const PLANS: Record = {
maxTeamMembers: 5,
maxWebhooks: 3,
contactsLimit: 100,
- campaignsLimit: 0, // Marketing emails not available on free plan
+ campaignsLimit: 3, // Limited marketing access on free plan
prioritySupport: false,
customBranding: false,
advancedAnalytics: false,
apiAccessLevel: "basic",
concurrentConnections: 1,
- marketingEmailsIncluded: false,
- extraMemberRateCents: 0, // Hard cap — upgrade required
+ marketingEmailsIncluded: true,
+ extraMemberRateCents: 200, // CA$2/member add-on
additionalDomainRateCents: 100, // CA$1/domain add-on
},
},
@@ -42,12 +42,12 @@ export const PLANS: Record = {
isLimited: true,
monthlyPrice: 500, // CA$5/month in cents
usageMetering: {
- marketing: 0.05, // CA$0.05 per marketing email (overage after 25,000 included)
- transactional: 0.03, // CA$0.03 per transactional email (overage after 25,000 included)
+ marketing: 0.0009, // CA$0.90 per 1,000 marketing emails (overage)
+ transactional: 0.0004, // CA$0.40 per 1,000 transactional emails (overage)
},
limits: {
monthlyEmailLimit: 25_000,
- dailyEmailLimit: 12_500,
+ dailyEmailLimit: Number.POSITIVE_INFINITY, // unlimited daily
maxDomains: 4,
maxContactBooks: 10,
maxTeamMembers: 10,
@@ -60,7 +60,7 @@ export const PLANS: Record = {
apiAccessLevel: "basic",
concurrentConnections: 2,
marketingEmailsIncluded: true,
- extraMemberRateCents: 0, // Hard cap — upgrade required
+ extraMemberRateCents: 200, // CA$2/member add-on
additionalDomainRateCents: 100, // CA$1/domain add-on
},
},
@@ -73,12 +73,12 @@ export const PLANS: Record = {
isLimited: true,
monthlyPrice: 1000, // CA$10/month in cents
usageMetering: {
- marketing: 0.02, // CA$0.02 per marketing email (overage after 50,000 included)
- transactional: 0.02, // CA$0.02 per transactional email (overage after 50,000 included)
+ marketing: 0.0008, // CA$0.80 per 1,000 marketing emails (overage)
+ transactional: 0.00035, // CA$0.35 per 1,000 transactional emails (overage)
},
limits: {
monthlyEmailLimit: 50_000,
- dailyEmailLimit: 25_000,
+ dailyEmailLimit: Number.POSITIVE_INFINITY, // unlimited daily
maxDomains: 6,
maxContactBooks: 25,
maxTeamMembers: 15,
@@ -91,21 +91,21 @@ export const PLANS: Record = {
apiAccessLevel: "full",
concurrentConnections: 5,
marketingEmailsIncluded: true,
- extraMemberRateCents: 0, // Hard cap — upgrade required
+ extraMemberRateCents: 200, // CA$2/member add-on
additionalDomainRateCents: 100, // CA$1/domain add-on
},
},
BASIC: {
plan: "BASIC",
- displayName: "Professional",
+ displayName: "Pro",
description: "For professionals and growing businesses",
order: 4,
isLimited: true,
monthlyPrice: 2000, // CA$20/month in cents
usageMetering: {
- marketing: 0.01, // CA$0.01 per marketing email (overage after 100,000 included)
- transactional: 0.01, // CA$0.01 per transactional email (overage after 100,000 included)
+ marketing: 0.0007, // CA$0.70 per 1,000 marketing emails (overage)
+ transactional: 0.00025, // CA$0.25 per 1,000 transactional emails (overage)
},
limits: {
monthlyEmailLimit: 100_000,
@@ -122,7 +122,7 @@ export const PLANS: Record = {
apiAccessLevel: "full",
concurrentConnections: 10,
marketingEmailsIncluded: true,
- extraMemberRateCents: 0, // Hard cap — upgrade required
+ extraMemberRateCents: 200, // CA$2/member add-on
additionalDomainRateCents: 100, // CA$1/domain add-on
},
},
@@ -151,7 +151,7 @@ export const PLANS: Record = {
apiAccessLevel: "full",
concurrentConnections: 20,
marketingEmailsIncluded: true,
- extraMemberRateCents: 0,
+ extraMemberRateCents: 200, // CA$2/member add-on
additionalDomainRateCents: 100, // CA$1/domain add-on
},
},
diff --git a/packages/lib/src/stripe/products.ts b/packages/lib/src/stripe/products.ts
index 5b1cc9d..a420c50 100644
--- a/packages/lib/src/stripe/products.ts
+++ b/packages/lib/src/stripe/products.ts
@@ -24,7 +24,8 @@ export const STRIPE_PRODUCTS: Record = {
"For hobbyists and side projects. " +
"25,000 emails/month included. " +
"Transactional and marketing emails included. " +
- "Overage billed at CA$0.05/marketing email and CA$0.03/transactional email. " +
+ "Overage billed at CA$0.90/1,000 marketing emails and CA$0.40/1,000 transactional emails. " +
+ "No daily send cap on paid plans. " +
"Extra domains available at CA$1/domain/month.",
priceMonthly: 500, // CA$5/month
},
@@ -36,18 +37,19 @@ export const STRIPE_PRODUCTS: Record = {
"For small teams and growing projects. " +
"50,000 emails/month included. " +
"Transactional and marketing emails included. " +
- "Overage billed at CA$0.02/email (marketing and transactional). " +
+ "Overage billed at CA$0.80/1,000 marketing emails and CA$0.35/1,000 transactional emails. " +
+ "No daily send cap on paid plans. " +
"Extra domains available at CA$1/domain/month.",
priceMonthly: 1000, // CA$10/month in cents
},
BASIC: {
plan: "BASIC",
- name: "ByteSend Professional",
+ name: "ByteSend Pro",
description:
- "For professionals and growing businesses. " +
+ "For teams with higher volume and tighter delivery requirements. " +
"100,000 emails/month included with unlimited daily sending. " +
- "Overage billed at CA$0.01/email (marketing and transactional). " +
+ "Overage billed at CA$0.70/1,000 marketing emails and CA$0.25/1,000 transactional emails. " +
"Up to 12 domains, 30 team members, 1,000 contacts.",
priceMonthly: 2000, // CA$20/month
},
@@ -71,12 +73,9 @@ export const STRIPE_ADDON_PRODUCTS = {
EXTRA_MEMBER: {
name: "ByteSend Extra Team Member",
description:
- "Metered add-on for team members beyond the included plan limit. " +
- "Billed at CA$0.25 per additional member per month.",
- meteringConfig: {
- eventName: "bytesend_extra_team_members",
- rateCents: 25, // CA$0.25 per extra member
- },
+ "Add-on for team members beyond the included plan limit. " +
+ "Billed at CA$2.00 per additional member per month.",
+ priceMonthly: 200, // CA$2.00/month per member
},
ADDITIONAL_DOMAIN: {
name: "ByteSend Additional Domain",
@@ -134,7 +133,7 @@ export const STRIPE_ENV_KEYS = {
// Add-on products
EXTRA_MEMBER: {
productId: "STRIPE_EXTRA_MEMBER_PRODUCT_ID",
- usagePrice: "STRIPE_EXTRA_MEMBER_USAGE_PRICE_ID",
+ monthlyPrice: "STRIPE_EXTRA_MEMBER_PRICE_ID",
},
ADDITIONAL_DOMAIN: {
productId: "STRIPE_ADDITIONAL_DOMAIN_PRODUCT_ID",
diff --git a/packages/lib/src/stripe/seed.ts b/packages/lib/src/stripe/seed.ts
index 35a0a9f..6f90a89 100644
--- a/packages/lib/src/stripe/seed.ts
+++ b/packages/lib/src/stripe/seed.ts
@@ -82,10 +82,12 @@ async function ensureMeter(
*/
export async function syncPlansToStripe(
stripe: Stripe,
- environment: string = "dev"
+ environment: string = "dev",
+ options?: { forceRecreateProducts?: boolean },
): Promise {
const products: StripeProductMapping[] = [];
const errors: string[] = [];
+ const forceRecreateProducts = options?.forceRecreateProducts === true;
try {
// ── Step 1: Ensure Billing Meters exist ──
@@ -115,15 +117,15 @@ export async function syncPlansToStripe(
console.log(`Syncing plan: ${plan}`);
- // Search for existing product
+ // Search active products only (archived products are ignored)
const existingProducts = await stripe.products.search({
- query: `name:"${productName}"`,
- limit: 1,
+ query: `name:"${productName}" AND active:'true'`,
+ limit: 100,
});
let product: Stripe.Product;
- if (existingProducts.data.length > 0) {
+ if (existingProducts.data.length > 0 && !forceRecreateProducts) {
product = existingProducts.data[0];
await stripe.products.update(product.id, {
name: productName,
@@ -136,6 +138,13 @@ export async function syncPlansToStripe(
});
console.log(` ✓ Updated product: ${product.id}`);
} else {
+ if (forceRecreateProducts) {
+ for (const existing of existingProducts.data) {
+ await stripe.products.update(existing.id, { active: false });
+ console.log(` ✓ Archived existing product: ${existing.id}`);
+ }
+ }
+
product = await stripe.products.create({
name: productName,
description: config.description,
@@ -365,25 +374,29 @@ async function createOrUpdateMeterPrice(
*/
export const DB_CONFIG_KEYS = {
price: {
- hobby: { monthly: "stripe.price.hobby.monthly", marketingUsage: "stripe.price.hobby.marketing_usage", transactionalUsage: "stripe.price.hobby.transactional_usage" },
- lite: { monthly: "stripe.price.lite.monthly", marketingUsage: "stripe.price.lite.marketing_usage", transactionalUsage: "stripe.price.lite.transactional_usage" },
- basic: { monthly: "stripe.price.basic.monthly", marketingUsage: "stripe.price.basic.marketing_usage", transactionalUsage: "stripe.price.basic.transactional_usage" },
+ hobby: { monthly: "stripe.price.hobby.monthly", marketingUsage: "stripe.price.hobby.marketing_usage", transactionalUsage: "stripe.price.hobby.transactional_usage" },
+ lite: { monthly: "stripe.price.lite.monthly", marketingUsage: "stripe.price.lite.marketing_usage", transactionalUsage: "stripe.price.lite.transactional_usage" },
+ basic: { monthly: "stripe.price.basic.monthly", marketingUsage: "stripe.price.basic.marketing_usage", transactionalUsage: "stripe.price.basic.transactional_usage" },
lifetime: { oneTime: "stripe.price.lifetime.one_time" },
- addon: { domainMonthly: "stripe.price.addon.domain_monthly" },
+ addon: {
+ domainMonthly: "stripe.price.addon.domain_monthly",
+ memberMonthly: "stripe.price.addon.member_monthly",
+ },
},
product: {
free: "stripe.product.free", hobby: "stripe.product.hobby", lite: "stripe.product.lite",
basic: "stripe.product.basic", lifetime: "stripe.product.lifetime",
addonDomain: "stripe.product.addon.domain",
+ addonMember: "stripe.product.addon.member",
},
meter: {
- marketing: "stripe.meter.marketing",
+ marketing: "stripe.meter.marketing",
transactional: "stripe.meter.transactional",
- extraMember: "stripe.meter.extra_member",
+ extraMember: "stripe.meter.extra_member",
},
webhook: {
endpointId: "stripe.webhook.endpoint_id",
- secret: "stripe.webhook.secret",
+ secret: "stripe.webhook.secret",
},
} as const;
@@ -394,6 +407,8 @@ export function generateDbConfig(
result: SyncResult,
addonDomainProductId?: string,
addonDomainPriceId?: string,
+ addonMemberProductId?: string,
+ addonMemberPriceId?: string,
): Record {
const out: Record = {};
@@ -405,18 +420,20 @@ export function generateDbConfig(
const priceKeys = DB_CONFIG_KEYS.price[planKey as keyof typeof DB_CONFIG_KEYS.price];
if (!priceKeys) continue;
const r = priceKeys as Record;
- if (p.priceIds.monthly && r.monthly) out[r.monthly] = p.priceIds.monthly;
+ if (p.priceIds.monthly && r.monthly) out[r.monthly] = p.priceIds.monthly;
if (p.priceIds.marketingUsage && r.marketingUsage) out[r.marketingUsage] = p.priceIds.marketingUsage;
if (p.priceIds.transactionalUsage && r.transactionalUsage) out[r.transactionalUsage] = p.priceIds.transactionalUsage;
- if (p.priceIds.oneTime && r.oneTime) out[r.oneTime] = p.priceIds.oneTime;
+ if (p.priceIds.oneTime && r.oneTime) out[r.oneTime] = p.priceIds.oneTime;
}
if (addonDomainProductId) out[DB_CONFIG_KEYS.product.addonDomain] = addonDomainProductId;
- if (addonDomainPriceId) out[DB_CONFIG_KEYS.price.addon.domainMonthly] = addonDomainPriceId;
+ if (addonDomainPriceId) out[DB_CONFIG_KEYS.price.addon.domainMonthly] = addonDomainPriceId;
+ if (addonMemberProductId) out[DB_CONFIG_KEYS.product.addonMember] = addonMemberProductId;
+ if (addonMemberPriceId) out[DB_CONFIG_KEYS.price.addon.memberMonthly] = addonMemberPriceId;
- if (result.meters.marketing) out[DB_CONFIG_KEYS.meter.marketing] = result.meters.marketing;
+ if (result.meters.marketing) out[DB_CONFIG_KEYS.meter.marketing] = result.meters.marketing;
if (result.meters.transactional) out[DB_CONFIG_KEYS.meter.transactional] = result.meters.transactional;
- if (result.meters.extraMember) out[DB_CONFIG_KEYS.meter.extraMember] = result.meters.extraMember;
+ if (result.meters.extraMember) out[DB_CONFIG_KEYS.meter.extraMember] = result.meters.extraMember;
return out;
}
diff --git a/packages/sdk/README.md b/packages/sdk/README.md
index 489f57b..99ea430 100644
--- a/packages/sdk/README.md
+++ b/packages/sdk/README.md
@@ -2,7 +2,7 @@
## Prerequisites
-- [ByteSend API key](https://bytesend.cloud/dev-settings/api-keys)
+- [ByteSend API key](https://bytesend.cloud/settings/api-keys)
- [Verified domain](https://bytesend.cloud/domains)
## Installation
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b769544..98895ae 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -117,7 +117,7 @@ importers:
version: 6.6.0(prisma@6.6.0(typescript@5.8.3))(typescript@5.8.3)
'@t3-oss/env-nextjs':
specifier: ^0.13.0
- version: 0.13.0(arktype@2.1.28)(typescript@5.8.3)(zod@3.24.3)
+ version: 0.13.0(arktype@2.1.28)(typescript@5.8.3)(valibot@0.42.1(typescript@5.8.3))(zod@3.24.3)
'@tanstack/react-query':
specifier: ^5.74.4
version: 5.74.4(react@19.1.0)
@@ -177,7 +177,7 @@ importers:
version: 15.5.9(@babel/core@7.26.10)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
next-auth:
specifier: ^4.24.11
- version: 4.24.11(next@15.5.9(@babel/core@7.26.10)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(nodemailer@7.0.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
+ version: 4.24.11(@auth/core@0.39.0(nodemailer@7.0.3))(next@15.5.9(@babel/core@7.26.10)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(nodemailer@7.0.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
nodemailer:
specifier: ^7.0.3
version: 7.0.3
@@ -205,6 +205,9 @@ importers:
react-hook-form:
specifier: ^7.56.1
version: 7.56.1(react@19.1.0)
+ react-icons:
+ specifier: 5.6.0
+ version: 5.6.0(react@19.1.0)
recharts:
specifier: ^2.15.3
version: 2.15.3(react-dom@19.1.0(react@19.1.0))(react@19.1.0)
@@ -8693,6 +8696,11 @@ packages:
peerDependencies:
react: ^16.8.0 || ^17 || ^18 || ^19
+ react-icons@5.6.0:
+ resolution: {integrity: sha512-RH93p5ki6LfOiIt0UtDyNg/cee+HLVR6cHHtW3wALfo+eOHTp8RnU2kRkI6E+H19zMIs03DyxUG/GfZMOGvmiA==}
+ peerDependencies:
+ react: '*'
+
react-is@16.13.1:
resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==}
@@ -14674,18 +14682,20 @@ snapshots:
dependencies:
defer-to-connect: 2.0.1
- '@t3-oss/env-core@0.13.0(arktype@2.1.28)(typescript@5.8.3)(zod@3.24.3)':
+ '@t3-oss/env-core@0.13.0(arktype@2.1.28)(typescript@5.8.3)(valibot@0.42.1(typescript@5.8.3))(zod@3.24.3)':
dependencies:
arktype: 2.1.28
optionalDependencies:
typescript: 5.8.3
+ valibot: 0.42.1(typescript@5.8.3)
zod: 3.24.3
- '@t3-oss/env-nextjs@0.13.0(arktype@2.1.28)(typescript@5.8.3)(zod@3.24.3)':
+ '@t3-oss/env-nextjs@0.13.0(arktype@2.1.28)(typescript@5.8.3)(valibot@0.42.1(typescript@5.8.3))(zod@3.24.3)':
dependencies:
- '@t3-oss/env-core': 0.13.0(arktype@2.1.28)(typescript@5.8.3)(zod@3.24.3)
+ '@t3-oss/env-core': 0.13.0(arktype@2.1.28)(typescript@5.8.3)(valibot@0.42.1(typescript@5.8.3))(zod@3.24.3)
optionalDependencies:
typescript: 5.8.3
+ valibot: 0.42.1(typescript@5.8.3)
zod: 3.24.3
transitivePeerDependencies:
- arktype
@@ -15496,7 +15506,7 @@ snapshots:
'@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.8.3))(eslint@8.57.1)(typescript@5.8.3)
'@typescript-eslint/parser': 7.18.0(eslint@8.57.1)(typescript@5.8.3)
eslint-config-prettier: 9.1.0(eslint@8.57.1)
- eslint-import-resolver-alias: 1.1.2(eslint-plugin-import@2.31.0)
+ eslint-import-resolver-alias: 1.1.2(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1))
eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.31.0)(eslint@8.57.1)
eslint-plugin-eslint-comments: 3.2.0(eslint@8.57.1)
eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.31.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1)
@@ -16908,7 +16918,7 @@ snapshots:
eslint-plugin-turbo: 2.5.2(eslint@8.57.1)(turbo@2.5.8)
turbo: 2.5.8
- eslint-import-resolver-alias@1.1.2(eslint-plugin-import@2.31.0):
+ eslint-import-resolver-alias@1.1.2(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1)):
dependencies:
eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.31.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1)
@@ -16935,7 +16945,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
- eslint-module-utils@2.12.0(@typescript-eslint/parser@8.31.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1):
+ eslint-module-utils@2.12.0(@typescript-eslint/parser@8.31.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.31.0)(eslint@8.57.1))(eslint@8.57.1):
dependencies:
debug: 3.2.7
optionalDependencies:
@@ -16963,7 +16973,7 @@ snapshots:
doctrine: 2.1.0
eslint: 8.57.1
eslint-import-resolver-node: 0.3.9
- eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.31.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1)
+ eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.31.0(eslint@8.57.1)(typescript@5.8.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.31.0)(eslint@8.57.1))(eslint@8.57.1)
hasown: 2.0.2
is-core-module: 2.16.1
is-glob: 4.0.3
@@ -19351,7 +19361,7 @@ snapshots:
netmask@2.0.2: {}
- next-auth@4.24.11(next@15.5.9(@babel/core@7.26.10)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(nodemailer@7.0.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0):
+ next-auth@4.24.11(@auth/core@0.39.0(nodemailer@7.0.3))(next@15.5.9(@babel/core@7.26.10)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(nodemailer@7.0.3)(react-dom@19.1.0(react@19.1.0))(react@19.1.0):
dependencies:
'@babel/runtime': 7.27.0
'@panva/hkdf': 1.2.1
@@ -19366,6 +19376,7 @@ snapshots:
react-dom: 19.1.0(react@19.1.0)
uuid: 8.3.2
optionalDependencies:
+ '@auth/core': 0.39.0(nodemailer@7.0.3)
nodemailer: 7.0.3
next-mdx-remote-client@1.1.0(@types/react@19.1.14)(acorn@8.11.2)(react-dom@19.1.0(react@19.2.3))(react@19.2.3):
@@ -20200,6 +20211,10 @@ snapshots:
dependencies:
react: 19.1.0
+ react-icons@5.6.0(react@19.1.0):
+ dependencies:
+ react: 19.1.0
+
react-is@16.13.1: {}
react-is@18.3.1: {}