{"_id":"@aimearn/webhook-sdk","_rev":"3-c7664acd7fb9c6866462c51856b86981","name":"@aimearn/webhook-sdk","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"@aimearn/webhook-sdk","version":"0.1.0","keywords":["aimearn","webhook","affiliate","commission","sdk","hmac","ecommerce"],"license":"MIT","_id":"@aimearn/webhook-sdk@0.1.0","maintainers":[{"name":"iprach","email":"prach.hormanee@gmail.com"}],"homepage":"https://github.com/sangium47/aim-earn/tree/master/packages/webhook-sdk#readme","bugs":{"url":"https://github.com/sangium47/aim-earn/issues"},"dist":{"shasum":"5e18068182b76b53e44d5ad6f04f8ce296b7d320","tarball":"https://registry.npmjs.org/@aimearn/webhook-sdk/-/webhook-sdk-0.1.0.tgz","fileCount":13,"integrity":"sha512-v7zOjv4meK4he4n24NPIUJju6o5LLRAIgQisrSPhxdaya+TXlcj2v45AyIT0FcpIe7ZdAy5LlXF20LwvyyzXew==","signatures":[{"sig":"MEYCIQC9iP+2sYcmW5lOzly0xa2ias6npGiPyl4tsXRCyn3RAgIhALtFIqZG8yDoNUEVC9IHXv+FCS6ZiGCbHz/RMoCN9fQN","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":111977},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./browser":{"types":"./dist/browser/index.d.ts","import":"./dist/browser/index.js"}},"gitHead":"f56d69955b9841735d0c465f1c16a30925de112f","scripts":{"test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","build:watch":"tsup --watch","prepublishOnly":"npm run typecheck && npm test && npm run build"},"_npmUser":{"name":"iprach","email":"prach.hormanee@gmail.com"},"repository":{"url":"git+https://github.com/sangium47/aim-earn.git","type":"git","directory":"packages/webhook-sdk"},"_npmVersion":"11.6.2","description":"Brand SDK for the Aim Earn webhook ingest API — HMAC signing, response verification, retries, idempotency.","directories":{},"_nodeVersion":"24.13.0","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5"},"_npmOperationalInternal":{"tmp":"tmp/webhook-sdk_0.1.0_1777548196175_0.42609722038560816","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@aimearn/webhook-sdk","version":"0.1.1","keywords":["aimearn","webhook","affiliate","commission","sdk","hmac","ecommerce"],"license":"MIT","_id":"@aimearn/webhook-sdk@0.1.1","maintainers":[{"name":"iprach","email":"prach.hormanee@gmail.com"}],"homepage":"https://github.com/aimearn/webhook-sdk#readme","bugs":{"url":"https://github.com/aimearn/webhook-sdk/issues"},"dist":{"shasum":"2c3477485ff21edd3e23fc6de0ea67e2cc1fb6e2","tarball":"https://registry.npmjs.org/@aimearn/webhook-sdk/-/webhook-sdk-0.1.1.tgz","fileCount":13,"integrity":"sha512-1FsLurrz4ymC5wduc1dxtaLJhmxfRhf6I/HTAGhGEfpXRgnBMnZOt2AHPP3RhVdd7LV4ZWF2aRMG7BY2UVOJNQ==","signatures":[{"sig":"MEQCIDL0icbit1DImdjj7BelYGNtfAnSMJNuoEgy/jPRE7xxAiBBezZLUsGg5kr9ZjZs1QG7pCyidCKUN2DdGnqo4k+dpw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":111947},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./browser":{"types":"./dist/browser/index.d.ts","import":"./dist/browser/index.js"}},"gitHead":"f56d69955b9841735d0c465f1c16a30925de112f","scripts":{"test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","build:watch":"tsup --watch","prepublishOnly":"npm run typecheck && npm test && npm run build"},"_npmUser":{"name":"iprach","email":"prach.hormanee@gmail.com"},"repository":{"url":"git+https://github.com/aimearn/webhook-sdk.git","type":"git","directory":"packages/webhook-sdk"},"_npmVersion":"11.6.2","description":"Brand SDK for the Aim Earn webhook ingest API — HMAC signing, response verification, retries, idempotency.","directories":{},"_nodeVersion":"24.13.0","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5"},"_npmOperationalInternal":{"tmp":"tmp/webhook-sdk_0.1.1_1777550446046_0.8453649038166733","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"@aimearn/webhook-sdk","version":"1.0.0","description":"Brand SDK for the Aim Earn webhook ingest API — HMAC signing, response verification, retries, idempotency.","license":"MIT","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./browser":{"types":"./dist/browser/index.d.ts","import":"./dist/browser/index.js"}},"keywords":["aimearn","webhook","affiliate","commission","sdk","hmac","ecommerce"],"homepage":"https://github.com/aimearn/webhook-sdk#readme","repository":{"type":"git","url":"git+https://github.com/aimearn/webhook-sdk.git","directory":"packages/webhook-sdk"},"bugs":{"url":"https://github.com/aimearn/webhook-sdk/issues"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"scripts":{"build":"tsup","build:watch":"tsup --watch","test":"vitest run","typecheck":"tsc --noEmit","prepublishOnly":"npm run typecheck && npm test && npm run build"},"engines":{"node":">=20"},"devDependencies":{"tsup":"^8.3.5"},"gitHead":"411de5699e688d05b70047d6115edd1698256b46","_id":"@aimearn/webhook-sdk@1.0.0","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-xBXmxqyOLo/0QNY3ymnm0ddbWyj78Zdw9HNQ/N7ntO4RTCzq+pFQiSp7MrHypYXW1IwLUPZuJAFIFXKBN8Helg==","shasum":"35a4367366941270bd3187f7dcb69b2f9bdcac53","tarball":"https://registry.npmjs.org/@aimearn/webhook-sdk/-/webhook-sdk-1.0.0.tgz","fileCount":13,"unpackedSize":115836,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCJvbgDsOJAI3H1GWC+wYqSf7ZGoh2bb7i8I8oPCAzSqgIhAMpIvcUs38460C4x1Q51nu8nxx2m15dwvZDdpmXnrrjJ"}]},"_npmUser":{"name":"iprach","email":"prach.hormanee@gmail.com"},"directories":{},"maintainers":[{"name":"iprach","email":"prach.hormanee@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/webhook-sdk_1.0.0_1782062066001_0.6119332919273153"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-30T11:23:16.108Z","modified":"2026-06-21T17:14:26.260Z","0.1.0":"2026-04-30T11:23:16.308Z","0.1.1":"2026-04-30T12:00:46.206Z","1.0.0":"2026-06-21T17:14:26.134Z"},"bugs":{"url":"https://github.com/aimearn/webhook-sdk/issues"},"license":"MIT","homepage":"https://github.com/aimearn/webhook-sdk#readme","keywords":["aimearn","webhook","affiliate","commission","sdk","hmac","ecommerce"],"repository":{"type":"git","url":"git+https://github.com/aimearn/webhook-sdk.git","directory":"packages/webhook-sdk"},"description":"Brand SDK for the Aim Earn webhook ingest API — HMAC signing, response verification, retries, idempotency.","maintainers":[{"name":"iprach","email":"prach.hormanee@gmail.com"}],"readme":"# @aimearn/webhook-sdk\n\nBrand SDK for the Aim Earn webhook ingest API.\n\nWraps:\n\n- HMAC-SHA256 request signing + response-signature verification\n- Exponential-backoff retries on 5xx / 429 / network errors\n- ULID-shaped `eventId` auto-generation for idempotent retries\n- Typed error hierarchy keyed on `WebhookDelivery.result`\n- Browser entry for the affiliate-link `?aimearn=…` capture flow\n\n## Install\n\n```bash\nnpm install @aimearn/webhook-sdk\n```\n\n(or via the workspace symlink in this monorepo).\n\n## Server-side usage\n\n```ts\nimport { AimearnClient } from \"@aimearn/webhook-sdk\";\n\nconst client = new AimearnClient({\n  keyId: process.env.AIMEARN_KEY_ID!,\n  secret: process.env.AIMEARN_WEBHOOK_SECRET!,\n  endpoint: \"https://webhooks.aimearn.platform.com\",\n});\n\nconst result = await client.orderCompleted({\n  orderId: \"ord_12345\",\n  data: {\n    items: [\n      {\n        productId: \"shopwave-sku-789\",\n        quantity: 1,\n        unitPriceCents: 19900,\n        commissionCents: 1990, // required — brand-computed, post-discount\n      },\n    ],\n    subtotalCents: 19900,\n    totalCommissionCents: 1990, // required — must equal Σ item.commissionCents\n    currency: \"SGD\",\n    country: \"SG\",\n    referralCode: \"XX0025\",\n    customer: { name: \"Jane Doe\", email: \"jane@example.com\" },\n  },\n});\n// → { status: \"accepted\", orderId: \"shopwave#ord_12345\", matchedItems: 1 }\n```\n\nMethods: `orderCompleted`, `orderShipped`, `orderRefunded`, `orderCancelled`.\n\n### Commission (required as of 1.0.0)\n\n`commissionCents` (per item) and `totalCommissionCents` (order total) are\n**required**. Compute them on your side — apply any discounts/promotions\nfirst — because the platform treats `commissionCents` as authoritative and\nsplits it across the affiliate chain using your configured `ProductCountry`\npercentages as ratios. It never derives commission from `subtotalCents`. A\npayload missing either field is rejected with `parse_error` (HTTP 400); a\n`Σ item.commissionCents !== totalCommissionCents` mismatch is accepted with a\n`commission_mismatch` warning.\n\n## Browser usage (affiliate-link capture)\n\n```ts\n// On every page load\nimport { captureReferralFromUrl } from \"@aimearn/webhook-sdk/browser\";\ncaptureReferralFromUrl();\n\n// At checkout\nimport { getStoredReferralCode } from \"@aimearn/webhook-sdk/browser\";\nconst referralCode = getStoredReferralCode(); // \"XX0025\" or null\n```\n\nESM-only, ~1KB gzipped, no external deps.\n\n## Documentation\n\nFull docs live in the host Next.js app under `/docs/sdk`:\n\n```bash\nnpm run dev\n# → http://localhost:3000/docs/sdk\n```\n\nOr browse the source: [`docs/sdk/*.mdx`](https://github.com/aimearn/aim-earn/tree/features/order-pipeline/app/docs/sdk).\n\n## Build\n\n```bash\n# From the monorepo root:\nnpm run build:sdk\n\n# Or inside this package:\nnpm run build\n```\n\nProduces:\n\n| Path                      | Use                 |\n| ------------------------- | ------------------- |\n| `dist/index.js`           | Server entry, ESM   |\n| `dist/index.cjs`          | Server entry, CJS   |\n| `dist/index.d.ts`         | Server entry types  |\n| `dist/browser/index.js`   | Browser entry, ESM  |\n| `dist/browser/index.d.ts` | Browser entry types |\n\n## Engines\n\nRequires Node.js 20+ (Node 24 LTS preferred). Node 18 is EOL.\n\n## Tests\n\n```bash\nnpm test\n```\n\n54 unit tests covering signing, retry, eventId, errors, client, and\nbrowser cookies (Vitest + jsdom).\n\n## License\n\nMIT — see [LICENSE](./LICENSE).\n","readmeFilename":"README.md"}