@kard-financial/sdk 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Normalize an email address for Hashed Email (HEM) generation.
3
+ *
4
+ * Follows UID2/LiveRamp industry standards:
5
+ * - Remove all whitespace
6
+ * - Lowercase
7
+ * - Gmail/Googlemail only: remove dots from local-part, strip '+' suffix
8
+ * - Canonicalize googlemail.com → gmail.com
9
+ */
10
+ export declare function normalizeEmail(raw: string): string;
11
+ /**
12
+ * Generate a Hashed Email (HEM) from a raw email address.
13
+ * Returns the lowercase hex SHA-256 digest of the normalized, UTF-8-encoded email.
14
+ */
15
+ export declare function generateHEM(raw: string): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeEmail = normalizeEmail;
4
+ exports.generateHEM = generateHEM;
5
+ const crypto_1 = require("crypto");
6
+ const GMAIL_DOMAINS = new Set(["gmail.com", "googlemail.com"]);
7
+ /**
8
+ * Normalize an email address for Hashed Email (HEM) generation.
9
+ *
10
+ * Follows UID2/LiveRamp industry standards:
11
+ * - Remove all whitespace
12
+ * - Lowercase
13
+ * - Gmail/Googlemail only: remove dots from local-part, strip '+' suffix
14
+ * - Canonicalize googlemail.com → gmail.com
15
+ */
16
+ function normalizeEmail(raw) {
17
+ const email = raw.replace(/\s/g, "").toLowerCase();
18
+ const atIndex = email.indexOf("@");
19
+ if (atIndex < 1 || atIndex !== email.lastIndexOf("@") || atIndex === email.length - 1) {
20
+ throw new TypeError(`Invalid email address: ${JSON.stringify(raw)}`);
21
+ }
22
+ const localPart = email.slice(0, atIndex);
23
+ const domain = email.slice(atIndex + 1);
24
+ if (GMAIL_DOMAINS.has(domain)) {
25
+ const base = localPart.split("+")[0].replace(/\./g, "");
26
+ return `${base}@gmail.com`;
27
+ }
28
+ return `${localPart}@${domain}`;
29
+ }
30
+ /**
31
+ * Generate a Hashed Email (HEM) from a raw email address.
32
+ * Returns the lowercase hex SHA-256 digest of the normalized, UTF-8-encoded email.
33
+ */
34
+ function generateHEM(raw) {
35
+ return (0, crypto_1.createHash)("sha256").update(normalizeEmail(raw), "utf8").digest("hex");
36
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Normalize an email address for Hashed Email (HEM) generation.
3
+ *
4
+ * Follows UID2/LiveRamp industry standards:
5
+ * - Remove all whitespace
6
+ * - Lowercase
7
+ * - Gmail/Googlemail only: remove dots from local-part, strip '+' suffix
8
+ * - Canonicalize googlemail.com → gmail.com
9
+ */
10
+ export declare function normalizeEmail(raw: string): string;
11
+ /**
12
+ * Generate a Hashed Email (HEM) from a raw email address.
13
+ * Returns the lowercase hex SHA-256 digest of the normalized, UTF-8-encoded email.
14
+ */
15
+ export declare function generateHEM(raw: string): string;
@@ -0,0 +1,32 @@
1
+ import { createHash } from "crypto";
2
+ const GMAIL_DOMAINS = new Set(["gmail.com", "googlemail.com"]);
3
+ /**
4
+ * Normalize an email address for Hashed Email (HEM) generation.
5
+ *
6
+ * Follows UID2/LiveRamp industry standards:
7
+ * - Remove all whitespace
8
+ * - Lowercase
9
+ * - Gmail/Googlemail only: remove dots from local-part, strip '+' suffix
10
+ * - Canonicalize googlemail.com → gmail.com
11
+ */
12
+ export function normalizeEmail(raw) {
13
+ const email = raw.replace(/\s/g, "").toLowerCase();
14
+ const atIndex = email.indexOf("@");
15
+ if (atIndex < 1 || atIndex !== email.lastIndexOf("@") || atIndex === email.length - 1) {
16
+ throw new TypeError(`Invalid email address: ${JSON.stringify(raw)}`);
17
+ }
18
+ const localPart = email.slice(0, atIndex);
19
+ const domain = email.slice(atIndex + 1);
20
+ if (GMAIL_DOMAINS.has(domain)) {
21
+ const base = localPart.split("+")[0].replace(/\./g, "");
22
+ return `${base}@gmail.com`;
23
+ }
24
+ return `${localPart}@${domain}`;
25
+ }
26
+ /**
27
+ * Generate a Hashed Email (HEM) from a raw email address.
28
+ * Returns the lowercase hex SHA-256 digest of the normalized, UTF-8-encoded email.
29
+ */
30
+ export function generateHEM(raw) {
31
+ return createHash("sha256").update(normalizeEmail(raw), "utf8").digest("hex");
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kard-financial/sdk",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "private": false,
5
5
  "repository": "github:KardFinancial/kard-node-sdk",
6
6
  "type": "commonjs",