{"_id":"@eduardoilha/email-client","_rev":"2-ec1db9eaf280287844d02ea8c31c19e0","name":"@eduardoilha/email-client","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@eduardoilha/email-client","version":"0.1.0","keywords":["email","client","transactional","marketing","fetch","typescript"],"license":"UNLICENSED","_id":"@eduardoilha/email-client@0.1.0","maintainers":[{"name":"eduardodesouzailha","email":"eduardoilhasouza@gmail.com"}],"homepage":"https://github.com/Armigliato-Ilha-Tecnologia/emailService/tree/main/packages/email-client","bugs":{"url":"https://github.com/Armigliato-Ilha-Tecnologia/emailService/issues"},"dist":{"shasum":"3e585cee9ea319cf669a9df4bfc1abf14a4ab1c7","tarball":"https://registry.npmjs.org/@eduardoilha/email-client/-/email-client-0.1.0.tgz","fileCount":6,"integrity":"sha512-AwMIfWKErRXRXvoFElxq6+1cnmlm860phURqzDieuUv/IR0DT2HOFvlZl5FWARhNIcJt+m+ss37tVCq7JcHRxg==","signatures":[{"sig":"MEUCIEn8Eif9JeSD6ohXGpkS6fuvycbM2cqgh/XTLiQUxExzAiEAw7hEsO2kqOiHH8Jcy817XlE0thy2hLELe/eiStjyWIg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":29403},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"6012a31025f0f626550e206d15b06005e89e3684","private":false,"scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","build":"tsup src/index.ts --format cjs,esm --dts --clean","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"_npmUser":{"name":"eduardodesouzailha","email":"eduardoilhasouza@gmail.com"},"repository":{"url":"git+https://github.com/Armigliato-Ilha-Tecnologia/emailService.git","type":"git","directory":"packages/email-client"},"_npmVersion":"10.9.4","description":"Typed HTTP client for the Acesse Email Service","directories":{},"_nodeVersion":"22.21.1","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","typescript":"^5.6.3"},"_npmOperationalInternal":{"tmp":"tmp/email-client_0.1.0_1779250665887_0.08294434973794518","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@eduardoilha/email-client","version":"0.1.1","description":"Typed HTTP client for the Acesse Email Service","license":"UNLICENSED","private":false,"main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --clean","dev":"tsup src/index.ts --format cjs,esm --dts --watch","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"},"repository":{"type":"git","url":"git+https://github.com/Armigliato-Ilha-Tecnologia/emailService.git","directory":"packages/email-client"},"homepage":"https://github.com/Armigliato-Ilha-Tecnologia/emailService/tree/main/packages/email-client","bugs":{"url":"https://github.com/Armigliato-Ilha-Tecnologia/emailService/issues"},"keywords":["email","client","transactional","marketing","fetch","typescript"],"devDependencies":{"tsup":"^8.3.5","typescript":"^5.6.3"},"engines":{"node":">=18"},"_id":"@eduardoilha/email-client@0.1.1","gitHead":"6012a31025f0f626550e206d15b06005e89e3684","_nodeVersion":"22.21.1","_npmVersion":"10.9.4","dist":{"integrity":"sha512-azNydLtsbnj4fPOVZX92XxP1xctTeb8oVNleNHLnXxTPtd9PKv1AsHinizBPvUCAr0/uhc3yH6rsiYDmw724+w==","shasum":"1a2c00b4737d8b44c08301af6593433bbc540efc","tarball":"https://registry.npmjs.org/@eduardoilha/email-client/-/email-client-0.1.1.tgz","fileCount":6,"unpackedSize":29535,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIApgM+eT3CTu3FLgxIKaXZTFzcgZ9oIgd1oWjdPpZvGjAiB5m1weT0cDPDM24HRS0Qn05RHiJ2NBV/bqL+AM+H1xuQ=="}]},"_npmUser":{"name":"eduardodesouzailha","email":"eduardoilhasouza@gmail.com"},"directories":{},"maintainers":[{"name":"eduardodesouzailha","email":"eduardoilhasouza@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/email-client_0.1.1_1779251212736_0.7842329574404288"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-20T04:17:45.761Z","modified":"2026-05-20T04:26:53.081Z","0.1.0":"2026-05-20T04:17:46.020Z","0.1.1":"2026-05-20T04:26:52.954Z"},"bugs":{"url":"https://github.com/Armigliato-Ilha-Tecnologia/emailService/issues"},"license":"UNLICENSED","homepage":"https://github.com/Armigliato-Ilha-Tecnologia/emailService/tree/main/packages/email-client","keywords":["email","client","transactional","marketing","fetch","typescript"],"repository":{"type":"git","url":"git+https://github.com/Armigliato-Ilha-Tecnologia/emailService.git","directory":"packages/email-client"},"description":"Typed HTTP client for the Acesse Email Service","maintainers":[{"name":"eduardodesouzailha","email":"eduardoilhasouza@gmail.com"}],"readme":"# @acesse/email-client\n\nTyped HTTP client for the Acesse Email Service. Use it from any Node 18+ project that needs to send transactional or marketing emails through your service.\n\n## Install\n\nPublished to **GitHub Packages**. Configure `.npmrc` in the consuming repo:\n\n```\n@acesse:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}\n```\n\nExport the token before installing:\n\n```bash\nexport GITHUB_PACKAGES_TOKEN=ghp_xxx   # needs read:packages scope\nnpm install @acesse/email-client\n```\n\nRequires Node 18+ (uses global `fetch`).\n\n## Usage\n\n```ts\nimport { EmailClient } from '@acesse/email-client'\n\nconst email = new EmailClient({\n  baseUrl: process.env.EMAIL_URL!,    // e.g. http://emailservice-app:3000\n  apiKey: process.env.EMAIL_API_KEY!,\n  timeoutMs: 10_000,                  // optional, default 10s\n})\n```\n\n### Transactional templates (seeded by the service)\n\nThe service ships with these slugs: `welcome`, `password-reset`, `order-confirmed`, `payment-failed`, `email-verification`.\n\n```ts\nawait email.sendSystem('account-created', user.email, {\n  name: user.name,\n  ctaUrl: `${process.env.APP_URL}/verify/${token}`,\n})\n```\n\n### Custom templates (DB-backed, built via the admin UI)\n\n```ts\nawait email.sendCustom({\n  templateSlug: 'campanha-mensal',\n  to: 'cliente@x.com',\n  data: { firstName: 'Ana', month: 'Maio' },\n})\n```\n\nPin a specific version (for reproducible sends):\n\n```ts\nawait email.sendCustom({\n  templateSlug: 'campanha-mensal',\n  to: 'cliente@x.com',\n  data: { firstName: 'Ana' },\n  version: 3,\n  locale: 'pt-BR',\n})\n```\n\n### Batch enqueue\n\n```ts\nconst { batchId, queued, skipped } = await email.sendBatch({\n  templateSlug: 'campanha-mensal',\n  recipients: [\n    { to: 'a@x.com', data: { firstName: 'A' } },\n    { to: 'b@x.com', data: { firstName: 'B' } },\n  ],\n})\n```\n\n### Follow batch progress\n\n```ts\nconst status = await email.getBatch(batchId, { errors: true })\n// { status: 'completed', sent, failed, skipped, pending, errors? }\n```\n\n### Templates CRUD\n\n```ts\nconst list = await email.listTemplates()\n\nconst { template, version } = await email.createTemplate({\n  slug: 'promo-black-friday',\n  name: 'Promo Black Friday',\n  category: 'marketing',\n  subject: 'Olá {{name}}, oferta especial!',\n  source: '<h1>Oi {{name}}</h1><p>Use cupom {{promoCode}}</p>',\n  variablesSchema: {\n    type: 'object',\n    required: ['name', 'promoCode'],\n    properties: {\n      name: { type: 'string' },\n      promoCode: { type: 'string' },\n    },\n  },\n})\n\nawait email.addVersion(template.id, {\n  subject: 'Última chance!',\n  source: '<h1>Última chance, {{name}}</h1>',\n  variablesSchema: { /* ... */ },\n  activate: true,\n})\n\nawait email.preview(template.id, { name: 'Test', promoCode: 'X' })\nawait email.deleteTemplate(template.id)   // blocked on system templates\n```\n\n## Idempotency\n\nPass `idempotencyKey` to dedupe retries on single sends:\n\n```ts\nawait email.sendCustom(\n  { templateSlug: 'welcome', to: 'a@x.com', data: { name: 'Ana' } },\n  { idempotencyKey: 'signup-user-123' },\n)\n```\n\nA second call with the same key returns the previous `messageId` and never hits the provider again.\n\n## Error handling\n\n```ts\nimport { EmailServiceError, EmailServiceNetworkError } from '@acesse/email-client'\n\ntry {\n  await email.sendCustom({ templateSlug: 'welcome', to: 'a@x.com' })\n} catch (err) {\n  if (err instanceof EmailServiceError) {\n    console.error(err.status, err.message, err.payload)\n  } else if (err instanceof EmailServiceNetworkError) {\n    console.error('network', err.message)\n  } else {\n    throw err\n  }\n}\n```\n\n## Examples\n\n### Next.js (App Router)\n\n```ts\n// app/api/signup/route.ts\nimport { EmailClient } from '@acesse/email-client'\n\nconst email = new EmailClient({\n  baseUrl: process.env.EMAIL_URL!,\n  apiKey: process.env.EMAIL_API_KEY!,\n})\n\nexport async function POST(req: Request) {\n  const { email: addr, name } = await req.json()\n  await email.sendSystem('account-created', addr, {\n    name,\n    ctaUrl: `${process.env.APP_URL}/verify/${generateToken()}`,\n  })\n  return Response.json({ ok: true })\n}\n```\n\n### Payment service — purchase confirmation\n\n```ts\nasync function onPaymentSuccess(payment: Payment) {\n  await email.sendSystem('order-confirmed', payment.customerEmail, {\n    name: payment.customerName,\n    orderId: payment.orderId,\n    orderUrl: `${process.env.APP_URL}/orders/${payment.orderId}`,\n    totalAmount: formatBRL(payment.total),\n    itemsLabel: payment.items.map((i) => i.name).join(', '),\n  })\n}\n```\n\n## Versioning\n\nSemver. Patches are safe, minors add fields, majors change the API surface.\n\n## Publishing\n\nWorkflow `.github/workflows/publish-client.yml` runs on tags `email-client-v*`:\n\n```bash\ncd packages/email-client\nnpm version patch          # bumps version + creates tag email-client-v0.1.1\ngit push --follow-tags\n```\n\nCI builds and pushes to GitHub Packages.\n","readmeFilename":"README.md"}