Node reference

Import from @cusuai/node. Integrators usually need only identifySign.

identifySign

import { identifySign } from "@cusuai/node";

const identity = identifySign({
	isk: process.env.CUSU_IDENTIFY_SECRET,
	visitorId,
	externalId: customer.id,
	traits: {
		name: customer.name,
		email: customer.email,
		phone: customer.phone,
		gender: customer.gender
	}
});
FieldRequiredDescription
iskyesIdentify secret, isk_…
visitorIdyesFrom the browser cookie cusu_vid
externalIdyesYour customer id, from the session
traitsnoname, email, phone, gender
signedAtnoUnix milliseconds. Defaults to now. Omit it in production.

Empty isk, visitorId, or externalId throws. signedAt must be a safe integer. The return value always includes externalId, signedAt, and signature, plus any trait you passed.

gender on the signed payload is male, female, or other. The helper forwards the string you pass. Cusu accepts those three values.

Other exports

ExportWhat it does
signIdentify(secret, payload)Hex HMAC for a payload you already built.
verifyIdentify(secret, payload, signature, signedAt, now?)true when the signature matches and signedAt is within five minutes of now.
buildCanonicalIdentifyPayload(payload)The exact text that is signed. See Identify.
generateIdentifySecret()A new isk_… value. The app can create one for you. Prefer that.
IDENTIFY_SIGNATURE_MAX_AGE_MSFive minutes. It matches the Cusu service. It is not an environment variable and not an argument of identifySign.