@cookiemunch/sdk 0.4.0 → 0.5.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.
package/dist/index.d.cts CHANGED
@@ -390,6 +390,20 @@ interface VerifyWebhookInput {
390
390
  */
391
391
  declare function verifyWebhookSignature(input: VerifyWebhookInput): boolean;
392
392
 
393
+ interface MintConsentSyncTokenInput {
394
+ /** The site's consent-sync secret (`cmss_…`). */
395
+ secret: string;
396
+ /** The site the token is for. A token for one site is refused by every other. */
397
+ cbid: string;
398
+ /** Who is signed in: 1–128 of `A-Z a-z 0-9 . _ : @ + / = ~ -`. Use an opaque id. */
399
+ subject: string;
400
+ /** Lifetime in seconds. Default 3600; at most 86400 (Cookie Munch refuses longer). */
401
+ ttlSeconds?: number;
402
+ /** Current time in ms (injectable for tests). */
403
+ now?: number;
404
+ }
405
+ declare function mintConsentSyncToken(input: MintConsentSyncTokenInput): string;
406
+
393
407
  /**
394
408
  * @cookiemunch/sdk — a small, typed REST client for the Cookie Munch Developer API
395
409
  * (the /v1 surface). Construct it with an API key; the org is derived server-side
@@ -400,6 +414,11 @@ declare function verifyWebhookSignature(input: VerifyWebhookInput): boolean;
400
414
  * const sites = await fc.sites.list();
401
415
  */
402
416
 
417
+ /**
418
+ * This package's version, sent in the default User-Agent. Cloudflare answers a request with
419
+ * no recognisable User-Agent with `403 error code: 1010`; a test pins this to package.json.
420
+ */
421
+ declare const SDK_VERSION = "0.5.0";
403
422
  interface CookieMunchOptions {
404
423
  apiKey: string;
405
424
  /** "https://api.cookiemunch.net" — the /v1 prefix is appended automatically. */
@@ -411,12 +430,14 @@ interface CookieMunchOptions {
411
430
  * declare is refused (`400 unknown_field`, with `field`) instead of ignored. Catches typos.
412
431
  */
413
432
  strictUnknownFields?: boolean;
433
+ /** The `User-Agent` sent on every request. Default `cookiemunch-js/<version>`. */
434
+ userAgent?: string;
414
435
  }
415
436
  /**
416
437
  * Thrown for any non-2xx response. `message` is the server's `error` field when present;
417
438
  * `code` is populated from the server's `code` field whenever the error body carries one
418
- * (e.g. banner-library conflicts, docs-admin checks) — not only for scoped-key
419
- * (`insufficient_scope`) responses. It's `undefined` when the body has no `code`.
439
+ * (e.g. `forbidden` on a scope failure, whose `message` is `insufficient_scope`,
440
+ * or `banner_in_use` on a banner-library conflict). It's `undefined` when the body has no `code`.
420
441
  */
421
442
  declare class CookieMunchApiError extends Error {
422
443
  readonly status: number;
@@ -448,9 +469,12 @@ interface CategorizedCookie {
448
469
  /**
449
470
  * Why a person should look at it. Visitors see unclassified and category ones under
450
471
  * "Unclassified"; `retired_but_seen` = retired, but a crawl or a visit saw it since, so the
451
- * site still sets it and it is listed again.
472
+ * site still sets it and it is listed again. `awaiting_corroboration` / `suspicious_report` =
473
+ * only visitors reported it (not enough of them yet, or in one injection-shaped report), owner
474
+ * views only; `foreign_cmp` = another consent platform's cookie, filed unclassified;
475
+ * `not_seen_recently` = unseen for the site's `staleAfterDays`, owner views only.
452
476
  */
453
- review?: 'unclassified' | 'category_disabled' | 'category_unknown' | 'retired_but_seen';
477
+ review?: 'unclassified' | 'category_disabled' | 'category_unknown' | 'retired_but_seen' | 'awaiting_corroboration' | 'suspicious_report' | 'foreign_cmp' | 'not_seen_recently';
454
478
  /** Epoch-ms a crawl or a real visit last saw it. Absent on older rows. */
455
479
  lastSeenAt?: number;
456
480
  /** Owner views only: the site owner retired this cookie (see `sites.retireCookie`). */
@@ -529,7 +553,7 @@ interface DeclaredCookie extends DeclaredCookieInput {
529
553
  vendor?: string;
530
554
  }
531
555
  /** A platform whose cookies and storage a preset declares. */
532
- type CookiePresetVendor = 'atlas' | 'forumulate' | 'chatly' | 'cookiemunch';
556
+ type CookiePresetVendor = 'atlas' | 'forumulate' | 'chatly' | 'cookiemunch' | 'referally';
533
557
  /** Where a vendor's live manifest will come from, and whether it exists yet. */
534
558
  interface CookiePresetManifest {
535
559
  status: 'builtin' | 'waiting_on_vendor';
@@ -537,13 +561,15 @@ interface CookiePresetManifest {
537
561
  item?: string;
538
562
  contract?: string;
539
563
  }
540
- /** Preset parameters: Atlas `frontendApiHost`/`crossSubdomainCookies`; Chatly `publicId`/`dragging`/`category`. */
564
+ /** Preset parameters: Atlas `frontendApiHost`/`crossSubdomainCookies`; Chatly `publicId`/`dragging`/`category`; Referally `cookieDomain`/`cookieDays`/`category`. */
541
565
  interface CookiePresetParams {
542
566
  frontendApiHost?: string;
543
567
  crossSubdomainCookies?: boolean;
544
568
  publicId?: string;
545
569
  dragging?: boolean;
546
570
  category?: string;
571
+ cookieDomain?: string;
572
+ cookieDays?: number;
547
573
  }
548
574
  /** One preset in GET /v1/sites/:cbid/cookies/presets. */
549
575
  interface CookiePreset {
@@ -1315,6 +1341,38 @@ type RightsCaptchaProvider = 'turnstile' | 'hcaptcha' | 'recaptcha_v2' | 'recapt
1315
1341
  * The rights page's captcha in force: your own keys (`own`, recommended) or none (`off`, the default).
1316
1342
  * Cookie Munch's own captcha is never used on rights pages. The secret is never returned.
1317
1343
  */
1344
+ /** Whether hosted consent sync is set up for a site. The secret itself is never read back. */
1345
+ interface ConsentSyncSecret {
1346
+ cbid: string;
1347
+ configured: boolean;
1348
+ secretLast4: string | null;
1349
+ /** Epoch ms the current secret was minted. */
1350
+ createdAt: number | null;
1351
+ }
1352
+ /**
1353
+ * Who a preference-centre token is for: a site of your organisation and exactly one of `email`
1354
+ * (resolved as the emailed preference link resolves it) or `subjectId`.
1355
+ */
1356
+ type CenterTokenInput = {
1357
+ cbid: string;
1358
+ ttlSeconds?: number;
1359
+ } & ({
1360
+ email: string;
1361
+ subjectId?: never;
1362
+ } | {
1363
+ subjectId: string;
1364
+ email?: never;
1365
+ });
1366
+ /** A preference-centre token. A credential: hand it to `CookieMunch.setSubjectToken`, never put it in a shared URL or a log. */
1367
+ interface CenterToken {
1368
+ token: string;
1369
+ /** ISO 8601. */
1370
+ expiresAt: string;
1371
+ }
1372
+ /** A freshly minted or rotated consent-sync secret: `secret` is shown this once. */
1373
+ interface ConsentSyncSecretMinted extends ConsentSyncSecret {
1374
+ secret: string;
1375
+ }
1318
1376
  interface RightsCaptcha {
1319
1377
  /** `site`: the site's own setting; `org`: the organisation default; `default`: neither (off). */
1320
1378
  source: 'site' | 'org' | 'default';
@@ -1395,6 +1453,24 @@ interface RightsIdentityInput {
1395
1453
  */
1396
1454
  trustEmailClaim?: boolean;
1397
1455
  }
1456
+ /** The organisation's own data-controller identity (GET /v1/org/controller). */
1457
+ interface OrgControllerIdentity {
1458
+ /** False when none is set; then only `updatedAt` (null) is present. */
1459
+ set: boolean;
1460
+ legalName?: string;
1461
+ contactEmail?: string;
1462
+ address?: string;
1463
+ /** The Data Protection Officer: a name, an email address, or both. */
1464
+ dpoContact?: string;
1465
+ updatedAt: number | null;
1466
+ }
1467
+ /** Replaces the identity: a field left out is removed. `legalName` is required. */
1468
+ interface OrgControllerInput {
1469
+ legalName: string;
1470
+ contactEmail?: string;
1471
+ address?: string;
1472
+ dpoContact?: string;
1473
+ }
1398
1474
  interface MailProviderTestResult {
1399
1475
  ok: boolean;
1400
1476
  sentTo: string;
@@ -2250,7 +2326,7 @@ interface CookieMunchClient {
2250
2326
  dryRun: true;
2251
2327
  retired: RetiredCookie[];
2252
2328
  }>;
2253
- /** Every declaration preset (atlas, forumulate, chatly, cookiemunch): params, what it declared here, manifest status. */
2329
+ /** Every declaration preset (atlas, forumulate, chatly, cookiemunch, referally): params, what it declared here, manifest status. */
2254
2330
  cookiePresets(cbid: string): Promise<{
2255
2331
  presets: CookiePreset[];
2256
2332
  }>;
@@ -2705,6 +2781,16 @@ interface CookieMunchClient {
2705
2781
  /** One subject's record. A subject with none has empty `purposes`. */
2706
2782
  get(subjectId: string): Promise<PreferenceRecord>;
2707
2783
  };
2784
+ /** The hosted preference centre, opened for a visitor your server has signed in. */
2785
+ preferenceCenter: {
2786
+ /**
2787
+ * Mint a preference-centre token (POST /v1/preference-center/tokens) for the page to pass to
2788
+ * `CookieMunch.setSubjectToken`. Server-side only: the token opens that subject's subscriptions
2789
+ * and profile until `expiresAt`. `ttlSeconds` defaults to 3600, at most 86400. Needs
2790
+ * subscriptions:write and profile:write, plus identity:read when minting by email.
2791
+ */
2792
+ mintToken(input: CenterTokenInput): Promise<CenterToken>;
2793
+ };
2708
2794
  members: {
2709
2795
  list(): Promise<Member[]>;
2710
2796
  invite(email: string, role: string): Promise<{
@@ -2773,6 +2859,17 @@ interface CookieMunchClient {
2773
2859
  /** Send a test through your provider. `to` defaults to the reply-to, else the from address. */
2774
2860
  test(to?: string): Promise<MailProviderTestResult>;
2775
2861
  };
2862
+ /**
2863
+ * Your organisation's own data-controller identity: who every rights notice names, before any site config
2864
+ * `controller` block. Needed for a notice on a request filed without a cbid when you have several sites.
2865
+ * An unscoped key, or `rights:write`.
2866
+ */
2867
+ controller: {
2868
+ get(): Promise<OrgControllerIdentity>;
2869
+ /** Replace it: a field left out is removed. */
2870
+ set(input: OrgControllerInput): Promise<OrgControllerIdentity>;
2871
+ remove(): Promise<void>;
2872
+ };
2776
2873
  /**
2777
2874
  * The default captcha for your rights pages, for every site without its own (`rightsCaptcha`): your own
2778
2875
  * keys (recommended) or off. Without one, rights pages have no captcha.
@@ -2854,6 +2951,18 @@ interface CookieMunchClient {
2854
2951
  rightsLinks: {
2855
2952
  create(cbid: string, input: RightsLinkInput): Promise<RightsLink>;
2856
2953
  };
2954
+ /**
2955
+ * A site's consent-sync signing secret: your server signs consent-sync tokens with it
2956
+ * (`mintConsentSyncToken`) so a visitor's decision syncs across their browsers. `rotate` mints the
2957
+ * first one or replaces it (the old one stops at once) and is the only time the secret is returned.
2958
+ * Reading needs sites:read; rotate and remove need sites:write and consent:write.
2959
+ */
2960
+ consentSyncSecret: {
2961
+ get(cbid: string): Promise<ConsentSyncSecret>;
2962
+ rotate(cbid: string): Promise<ConsentSyncSecretMinted>;
2963
+ /** Turn hosted consent sync off for the site. */
2964
+ remove(cbid: string): Promise<ConsentSyncSecret>;
2965
+ };
2857
2966
  /**
2858
2967
  * A site's rights-page captcha: your own Turnstile, hCaptcha or reCAPTCHA keys (recommended), or off. A site
2859
2968
  * without its own setting uses the organisation default (`org.rightsCaptcha`), else off. Requires sites:read / sites:write.
@@ -2910,4 +3019,4 @@ interface CookieMunchClient {
2910
3019
  }
2911
3020
  declare function createCookieMunch(opts: CookieMunchOptions): CookieMunchClient;
2912
3021
 
2913
- export { type AbResult, type AccountOrg, type AccountOrgs, type AdPersonalizationInput, type AiInspectInput, type AiInspectResult, type ApiKey, type ApiKeyIssueInput, type ApiKeyIssued, type ApiKeyPrefix, type ApiKeyReport, type ApiKeyUpdate, type AppliedImport, type AssetUpload, type AuditEntry, type BannerRecord, type BannerSummary, type BlockedReport, type BrandExtractionResult, type BrandKit, type BrandKitCreate, type BrandSuggestion, type BulkSiteInput, type BulkSiteResult, type ButtonParityFinding, type ButtonParityLint, type ButtonParityScan, type CategorizedCookie, type ChildKeyInput, type ConfigChange, type ConfigDryRun, type ConfigWarning, type ConsentDay, type ConsentDecisionInput, type ConsentIngestInput, type ConsentLogRow, type CookieDeclaration, CookieMunchApiError, type CookieMunchClient, type CookieMunchOptions, type CookiePreset, type CookiePresetManifest, type CookiePresetParams, type CookiePresetResult, type CookiePresetVendor, type CspSources, type DeclarationDiff, type DeclarationDryRun, type DeclarationWarning, type DeclaredCookie, type DeclaredCookieInput, type DnsRecordInstruction, type DsarCreate, type DsarEraseResult, type DsarExecutor, type DsarExecutorCreated, type DsarExecutorDryRun, type DsarExecutorInput, type DsarExecutorPatch, type DsarExecutorPresetInput, type DsarExportResult, type DsarRequest, type DsarStatus, type DsarTask, type DsarTaskEvent, type DsarTaskExport, type DsarTaskLogEntry, type DsarTaskOutcome, type DsarType, type EnforcementRuleInput, type ExecutorHealth, type ExecutorPresetName, type ExecutorPresetUpgrade, type ExecutorPresets, type ExecutorProfile, type ExecutorTestInput, type ExecutorTestResult, type ExecutorWebhookDelivery, type ExecutorWebhookTestResult, type FlowIssue, type FlowOp, type FlowOpResponse, type FulfillmentOp, type HealthRow, type Identifier, type Identity, type ImportedCookie, type ImportedDeclaration, type InstallSnippet, type IntegrationHealthReport, type LegalBasis, type LogQuery, type MailProvider, type MailProviderInput, type MailProviderKind, type MailProviderTestResult, type Member, type ObservedPurgeResult, type OptInMethod, type Org, type OrgUpdate, type ParityControlSummary, type PartnerCatalogEntry, type PartnerId, type PartnerLink, type PartnerLinkCreate, type PlanSource, type PolicyOptions, type PreferenceItem, type PreferenceRecord, type PreviewToken, type PreviewTokenOptions, type ProfileAttributeInput, type ProvisionRequest, type ProvisionResult, type ProvisionStep, type PublicDsarFiled, type PublicDsarPending, type PublicVerification, type PutConfigOptions, type RangeQuery, type Regulation, type RegulationSummary, type RegulatoryFeedResult, type ResellerChild, type ResellerChildCreate, type ResellerChildList, type ResellerChildPatch, type RetiredCookie, type RightKind, type RightsCaptcha, type RightsCaptchaInput, type RightsCaptchaProvider, type RightsIdentity, type RightsIdentityInput, type RightsIdentityType, type RightsLink, type RightsLinkInput, type RightsPageDocument, type RightsPageDomain, type RightsPageDomainList, type RightsPageDraft, type RightsPageDraftConflict, type RightsPageDryRun, type RightsPageIssue, type RightsPagePublishResult, type RightsPagePublished, type RightsPagePublisher, type RightsPageVersions, type RightsPageWriteOptions, type RiskScore, type RopaEntry, type RopaInput, type ScanResult, type ScanStatus, type ScoredVendor, type ScrollbarTheme, type SessionAnalysisInput, type SignedReceipt, type Site, type SiteConfig, type SiteCookie, type SiteCreate, type SiteFlow, type SiteUpdate, type SiteUpdateResult, type SnippetOptions, type StorageType, type SubscriptionTopicInput, type SuggestedRejectStyle, type SupportedLanguage, type Usage, type VendorInput, type VendorRecord, type VerifyResult, type VerifyWebhookInput, type WebhookCreate, type WebhookDeadLetter, type WebhookKeyForm, type WebhookStage, type WebhookSubscription, type WebhookTestResult, type WebhookUpdate, createCookieMunch, verifyWebhookSignature };
3022
+ export { type AbResult, type AccountOrg, type AccountOrgs, type AdPersonalizationInput, type AiInspectInput, type AiInspectResult, type ApiKey, type ApiKeyIssueInput, type ApiKeyIssued, type ApiKeyPrefix, type ApiKeyReport, type ApiKeyUpdate, type AppliedImport, type AssetUpload, type AuditEntry, type BannerRecord, type BannerSummary, type BlockedReport, type BrandExtractionResult, type BrandKit, type BrandKitCreate, type BrandSuggestion, type BulkSiteInput, type BulkSiteResult, type ButtonParityFinding, type ButtonParityLint, type ButtonParityScan, type CategorizedCookie, type CenterToken, type CenterTokenInput, type ChildKeyInput, type ConfigChange, type ConfigDryRun, type ConfigWarning, type ConsentDay, type ConsentDecisionInput, type ConsentIngestInput, type ConsentLogRow, type ConsentSyncSecret, type ConsentSyncSecretMinted, type CookieDeclaration, CookieMunchApiError, type CookieMunchClient, type CookieMunchOptions, type CookiePreset, type CookiePresetManifest, type CookiePresetParams, type CookiePresetResult, type CookiePresetVendor, type CspSources, type DeclarationDiff, type DeclarationDryRun, type DeclarationWarning, type DeclaredCookie, type DeclaredCookieInput, type DnsRecordInstruction, type DsarCreate, type DsarEraseResult, type DsarExecutor, type DsarExecutorCreated, type DsarExecutorDryRun, type DsarExecutorInput, type DsarExecutorPatch, type DsarExecutorPresetInput, type DsarExportResult, type DsarRequest, type DsarStatus, type DsarTask, type DsarTaskEvent, type DsarTaskExport, type DsarTaskLogEntry, type DsarTaskOutcome, type DsarType, type EnforcementRuleInput, type ExecutorHealth, type ExecutorPresetName, type ExecutorPresetUpgrade, type ExecutorPresets, type ExecutorProfile, type ExecutorTestInput, type ExecutorTestResult, type ExecutorWebhookDelivery, type ExecutorWebhookTestResult, type FlowIssue, type FlowOp, type FlowOpResponse, type FulfillmentOp, type HealthRow, type Identifier, type Identity, type ImportedCookie, type ImportedDeclaration, type InstallSnippet, type IntegrationHealthReport, type LegalBasis, type LogQuery, type MailProvider, type MailProviderInput, type MailProviderKind, type MailProviderTestResult, type Member, type MintConsentSyncTokenInput, type ObservedPurgeResult, type OptInMethod, type Org, type OrgControllerIdentity, type OrgControllerInput, type OrgUpdate, type ParityControlSummary, type PartnerCatalogEntry, type PartnerId, type PartnerLink, type PartnerLinkCreate, type PlanSource, type PolicyOptions, type PreferenceItem, type PreferenceRecord, type PreviewToken, type PreviewTokenOptions, type ProfileAttributeInput, type ProvisionRequest, type ProvisionResult, type ProvisionStep, type PublicDsarFiled, type PublicDsarPending, type PublicVerification, type PutConfigOptions, type RangeQuery, type Regulation, type RegulationSummary, type RegulatoryFeedResult, type ResellerChild, type ResellerChildCreate, type ResellerChildList, type ResellerChildPatch, type RetiredCookie, type RightKind, type RightsCaptcha, type RightsCaptchaInput, type RightsCaptchaProvider, type RightsIdentity, type RightsIdentityInput, type RightsIdentityType, type RightsLink, type RightsLinkInput, type RightsPageDocument, type RightsPageDomain, type RightsPageDomainList, type RightsPageDraft, type RightsPageDraftConflict, type RightsPageDryRun, type RightsPageIssue, type RightsPagePublishResult, type RightsPagePublished, type RightsPagePublisher, type RightsPageVersions, type RightsPageWriteOptions, type RiskScore, type RopaEntry, type RopaInput, SDK_VERSION, type ScanResult, type ScanStatus, type ScoredVendor, type ScrollbarTheme, type SessionAnalysisInput, type SignedReceipt, type Site, type SiteConfig, type SiteCookie, type SiteCreate, type SiteFlow, type SiteUpdate, type SiteUpdateResult, type SnippetOptions, type StorageType, type SubscriptionTopicInput, type SuggestedRejectStyle, type SupportedLanguage, type Usage, type VendorInput, type VendorRecord, type VerifyResult, type VerifyWebhookInput, type WebhookCreate, type WebhookDeadLetter, type WebhookKeyForm, type WebhookStage, type WebhookSubscription, type WebhookTestResult, type WebhookUpdate, createCookieMunch, mintConsentSyncToken, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -390,6 +390,20 @@ interface VerifyWebhookInput {
390
390
  */
391
391
  declare function verifyWebhookSignature(input: VerifyWebhookInput): boolean;
392
392
 
393
+ interface MintConsentSyncTokenInput {
394
+ /** The site's consent-sync secret (`cmss_…`). */
395
+ secret: string;
396
+ /** The site the token is for. A token for one site is refused by every other. */
397
+ cbid: string;
398
+ /** Who is signed in: 1–128 of `A-Z a-z 0-9 . _ : @ + / = ~ -`. Use an opaque id. */
399
+ subject: string;
400
+ /** Lifetime in seconds. Default 3600; at most 86400 (Cookie Munch refuses longer). */
401
+ ttlSeconds?: number;
402
+ /** Current time in ms (injectable for tests). */
403
+ now?: number;
404
+ }
405
+ declare function mintConsentSyncToken(input: MintConsentSyncTokenInput): string;
406
+
393
407
  /**
394
408
  * @cookiemunch/sdk — a small, typed REST client for the Cookie Munch Developer API
395
409
  * (the /v1 surface). Construct it with an API key; the org is derived server-side
@@ -400,6 +414,11 @@ declare function verifyWebhookSignature(input: VerifyWebhookInput): boolean;
400
414
  * const sites = await fc.sites.list();
401
415
  */
402
416
 
417
+ /**
418
+ * This package's version, sent in the default User-Agent. Cloudflare answers a request with
419
+ * no recognisable User-Agent with `403 error code: 1010`; a test pins this to package.json.
420
+ */
421
+ declare const SDK_VERSION = "0.5.0";
403
422
  interface CookieMunchOptions {
404
423
  apiKey: string;
405
424
  /** "https://api.cookiemunch.net" — the /v1 prefix is appended automatically. */
@@ -411,12 +430,14 @@ interface CookieMunchOptions {
411
430
  * declare is refused (`400 unknown_field`, with `field`) instead of ignored. Catches typos.
412
431
  */
413
432
  strictUnknownFields?: boolean;
433
+ /** The `User-Agent` sent on every request. Default `cookiemunch-js/<version>`. */
434
+ userAgent?: string;
414
435
  }
415
436
  /**
416
437
  * Thrown for any non-2xx response. `message` is the server's `error` field when present;
417
438
  * `code` is populated from the server's `code` field whenever the error body carries one
418
- * (e.g. banner-library conflicts, docs-admin checks) — not only for scoped-key
419
- * (`insufficient_scope`) responses. It's `undefined` when the body has no `code`.
439
+ * (e.g. `forbidden` on a scope failure, whose `message` is `insufficient_scope`,
440
+ * or `banner_in_use` on a banner-library conflict). It's `undefined` when the body has no `code`.
420
441
  */
421
442
  declare class CookieMunchApiError extends Error {
422
443
  readonly status: number;
@@ -448,9 +469,12 @@ interface CategorizedCookie {
448
469
  /**
449
470
  * Why a person should look at it. Visitors see unclassified and category ones under
450
471
  * "Unclassified"; `retired_but_seen` = retired, but a crawl or a visit saw it since, so the
451
- * site still sets it and it is listed again.
472
+ * site still sets it and it is listed again. `awaiting_corroboration` / `suspicious_report` =
473
+ * only visitors reported it (not enough of them yet, or in one injection-shaped report), owner
474
+ * views only; `foreign_cmp` = another consent platform's cookie, filed unclassified;
475
+ * `not_seen_recently` = unseen for the site's `staleAfterDays`, owner views only.
452
476
  */
453
- review?: 'unclassified' | 'category_disabled' | 'category_unknown' | 'retired_but_seen';
477
+ review?: 'unclassified' | 'category_disabled' | 'category_unknown' | 'retired_but_seen' | 'awaiting_corroboration' | 'suspicious_report' | 'foreign_cmp' | 'not_seen_recently';
454
478
  /** Epoch-ms a crawl or a real visit last saw it. Absent on older rows. */
455
479
  lastSeenAt?: number;
456
480
  /** Owner views only: the site owner retired this cookie (see `sites.retireCookie`). */
@@ -529,7 +553,7 @@ interface DeclaredCookie extends DeclaredCookieInput {
529
553
  vendor?: string;
530
554
  }
531
555
  /** A platform whose cookies and storage a preset declares. */
532
- type CookiePresetVendor = 'atlas' | 'forumulate' | 'chatly' | 'cookiemunch';
556
+ type CookiePresetVendor = 'atlas' | 'forumulate' | 'chatly' | 'cookiemunch' | 'referally';
533
557
  /** Where a vendor's live manifest will come from, and whether it exists yet. */
534
558
  interface CookiePresetManifest {
535
559
  status: 'builtin' | 'waiting_on_vendor';
@@ -537,13 +561,15 @@ interface CookiePresetManifest {
537
561
  item?: string;
538
562
  contract?: string;
539
563
  }
540
- /** Preset parameters: Atlas `frontendApiHost`/`crossSubdomainCookies`; Chatly `publicId`/`dragging`/`category`. */
564
+ /** Preset parameters: Atlas `frontendApiHost`/`crossSubdomainCookies`; Chatly `publicId`/`dragging`/`category`; Referally `cookieDomain`/`cookieDays`/`category`. */
541
565
  interface CookiePresetParams {
542
566
  frontendApiHost?: string;
543
567
  crossSubdomainCookies?: boolean;
544
568
  publicId?: string;
545
569
  dragging?: boolean;
546
570
  category?: string;
571
+ cookieDomain?: string;
572
+ cookieDays?: number;
547
573
  }
548
574
  /** One preset in GET /v1/sites/:cbid/cookies/presets. */
549
575
  interface CookiePreset {
@@ -1315,6 +1341,38 @@ type RightsCaptchaProvider = 'turnstile' | 'hcaptcha' | 'recaptcha_v2' | 'recapt
1315
1341
  * The rights page's captcha in force: your own keys (`own`, recommended) or none (`off`, the default).
1316
1342
  * Cookie Munch's own captcha is never used on rights pages. The secret is never returned.
1317
1343
  */
1344
+ /** Whether hosted consent sync is set up for a site. The secret itself is never read back. */
1345
+ interface ConsentSyncSecret {
1346
+ cbid: string;
1347
+ configured: boolean;
1348
+ secretLast4: string | null;
1349
+ /** Epoch ms the current secret was minted. */
1350
+ createdAt: number | null;
1351
+ }
1352
+ /**
1353
+ * Who a preference-centre token is for: a site of your organisation and exactly one of `email`
1354
+ * (resolved as the emailed preference link resolves it) or `subjectId`.
1355
+ */
1356
+ type CenterTokenInput = {
1357
+ cbid: string;
1358
+ ttlSeconds?: number;
1359
+ } & ({
1360
+ email: string;
1361
+ subjectId?: never;
1362
+ } | {
1363
+ subjectId: string;
1364
+ email?: never;
1365
+ });
1366
+ /** A preference-centre token. A credential: hand it to `CookieMunch.setSubjectToken`, never put it in a shared URL or a log. */
1367
+ interface CenterToken {
1368
+ token: string;
1369
+ /** ISO 8601. */
1370
+ expiresAt: string;
1371
+ }
1372
+ /** A freshly minted or rotated consent-sync secret: `secret` is shown this once. */
1373
+ interface ConsentSyncSecretMinted extends ConsentSyncSecret {
1374
+ secret: string;
1375
+ }
1318
1376
  interface RightsCaptcha {
1319
1377
  /** `site`: the site's own setting; `org`: the organisation default; `default`: neither (off). */
1320
1378
  source: 'site' | 'org' | 'default';
@@ -1395,6 +1453,24 @@ interface RightsIdentityInput {
1395
1453
  */
1396
1454
  trustEmailClaim?: boolean;
1397
1455
  }
1456
+ /** The organisation's own data-controller identity (GET /v1/org/controller). */
1457
+ interface OrgControllerIdentity {
1458
+ /** False when none is set; then only `updatedAt` (null) is present. */
1459
+ set: boolean;
1460
+ legalName?: string;
1461
+ contactEmail?: string;
1462
+ address?: string;
1463
+ /** The Data Protection Officer: a name, an email address, or both. */
1464
+ dpoContact?: string;
1465
+ updatedAt: number | null;
1466
+ }
1467
+ /** Replaces the identity: a field left out is removed. `legalName` is required. */
1468
+ interface OrgControllerInput {
1469
+ legalName: string;
1470
+ contactEmail?: string;
1471
+ address?: string;
1472
+ dpoContact?: string;
1473
+ }
1398
1474
  interface MailProviderTestResult {
1399
1475
  ok: boolean;
1400
1476
  sentTo: string;
@@ -2250,7 +2326,7 @@ interface CookieMunchClient {
2250
2326
  dryRun: true;
2251
2327
  retired: RetiredCookie[];
2252
2328
  }>;
2253
- /** Every declaration preset (atlas, forumulate, chatly, cookiemunch): params, what it declared here, manifest status. */
2329
+ /** Every declaration preset (atlas, forumulate, chatly, cookiemunch, referally): params, what it declared here, manifest status. */
2254
2330
  cookiePresets(cbid: string): Promise<{
2255
2331
  presets: CookiePreset[];
2256
2332
  }>;
@@ -2705,6 +2781,16 @@ interface CookieMunchClient {
2705
2781
  /** One subject's record. A subject with none has empty `purposes`. */
2706
2782
  get(subjectId: string): Promise<PreferenceRecord>;
2707
2783
  };
2784
+ /** The hosted preference centre, opened for a visitor your server has signed in. */
2785
+ preferenceCenter: {
2786
+ /**
2787
+ * Mint a preference-centre token (POST /v1/preference-center/tokens) for the page to pass to
2788
+ * `CookieMunch.setSubjectToken`. Server-side only: the token opens that subject's subscriptions
2789
+ * and profile until `expiresAt`. `ttlSeconds` defaults to 3600, at most 86400. Needs
2790
+ * subscriptions:write and profile:write, plus identity:read when minting by email.
2791
+ */
2792
+ mintToken(input: CenterTokenInput): Promise<CenterToken>;
2793
+ };
2708
2794
  members: {
2709
2795
  list(): Promise<Member[]>;
2710
2796
  invite(email: string, role: string): Promise<{
@@ -2773,6 +2859,17 @@ interface CookieMunchClient {
2773
2859
  /** Send a test through your provider. `to` defaults to the reply-to, else the from address. */
2774
2860
  test(to?: string): Promise<MailProviderTestResult>;
2775
2861
  };
2862
+ /**
2863
+ * Your organisation's own data-controller identity: who every rights notice names, before any site config
2864
+ * `controller` block. Needed for a notice on a request filed without a cbid when you have several sites.
2865
+ * An unscoped key, or `rights:write`.
2866
+ */
2867
+ controller: {
2868
+ get(): Promise<OrgControllerIdentity>;
2869
+ /** Replace it: a field left out is removed. */
2870
+ set(input: OrgControllerInput): Promise<OrgControllerIdentity>;
2871
+ remove(): Promise<void>;
2872
+ };
2776
2873
  /**
2777
2874
  * The default captcha for your rights pages, for every site without its own (`rightsCaptcha`): your own
2778
2875
  * keys (recommended) or off. Without one, rights pages have no captcha.
@@ -2854,6 +2951,18 @@ interface CookieMunchClient {
2854
2951
  rightsLinks: {
2855
2952
  create(cbid: string, input: RightsLinkInput): Promise<RightsLink>;
2856
2953
  };
2954
+ /**
2955
+ * A site's consent-sync signing secret: your server signs consent-sync tokens with it
2956
+ * (`mintConsentSyncToken`) so a visitor's decision syncs across their browsers. `rotate` mints the
2957
+ * first one or replaces it (the old one stops at once) and is the only time the secret is returned.
2958
+ * Reading needs sites:read; rotate and remove need sites:write and consent:write.
2959
+ */
2960
+ consentSyncSecret: {
2961
+ get(cbid: string): Promise<ConsentSyncSecret>;
2962
+ rotate(cbid: string): Promise<ConsentSyncSecretMinted>;
2963
+ /** Turn hosted consent sync off for the site. */
2964
+ remove(cbid: string): Promise<ConsentSyncSecret>;
2965
+ };
2857
2966
  /**
2858
2967
  * A site's rights-page captcha: your own Turnstile, hCaptcha or reCAPTCHA keys (recommended), or off. A site
2859
2968
  * without its own setting uses the organisation default (`org.rightsCaptcha`), else off. Requires sites:read / sites:write.
@@ -2910,4 +3019,4 @@ interface CookieMunchClient {
2910
3019
  }
2911
3020
  declare function createCookieMunch(opts: CookieMunchOptions): CookieMunchClient;
2912
3021
 
2913
- export { type AbResult, type AccountOrg, type AccountOrgs, type AdPersonalizationInput, type AiInspectInput, type AiInspectResult, type ApiKey, type ApiKeyIssueInput, type ApiKeyIssued, type ApiKeyPrefix, type ApiKeyReport, type ApiKeyUpdate, type AppliedImport, type AssetUpload, type AuditEntry, type BannerRecord, type BannerSummary, type BlockedReport, type BrandExtractionResult, type BrandKit, type BrandKitCreate, type BrandSuggestion, type BulkSiteInput, type BulkSiteResult, type ButtonParityFinding, type ButtonParityLint, type ButtonParityScan, type CategorizedCookie, type ChildKeyInput, type ConfigChange, type ConfigDryRun, type ConfigWarning, type ConsentDay, type ConsentDecisionInput, type ConsentIngestInput, type ConsentLogRow, type CookieDeclaration, CookieMunchApiError, type CookieMunchClient, type CookieMunchOptions, type CookiePreset, type CookiePresetManifest, type CookiePresetParams, type CookiePresetResult, type CookiePresetVendor, type CspSources, type DeclarationDiff, type DeclarationDryRun, type DeclarationWarning, type DeclaredCookie, type DeclaredCookieInput, type DnsRecordInstruction, type DsarCreate, type DsarEraseResult, type DsarExecutor, type DsarExecutorCreated, type DsarExecutorDryRun, type DsarExecutorInput, type DsarExecutorPatch, type DsarExecutorPresetInput, type DsarExportResult, type DsarRequest, type DsarStatus, type DsarTask, type DsarTaskEvent, type DsarTaskExport, type DsarTaskLogEntry, type DsarTaskOutcome, type DsarType, type EnforcementRuleInput, type ExecutorHealth, type ExecutorPresetName, type ExecutorPresetUpgrade, type ExecutorPresets, type ExecutorProfile, type ExecutorTestInput, type ExecutorTestResult, type ExecutorWebhookDelivery, type ExecutorWebhookTestResult, type FlowIssue, type FlowOp, type FlowOpResponse, type FulfillmentOp, type HealthRow, type Identifier, type Identity, type ImportedCookie, type ImportedDeclaration, type InstallSnippet, type IntegrationHealthReport, type LegalBasis, type LogQuery, type MailProvider, type MailProviderInput, type MailProviderKind, type MailProviderTestResult, type Member, type ObservedPurgeResult, type OptInMethod, type Org, type OrgUpdate, type ParityControlSummary, type PartnerCatalogEntry, type PartnerId, type PartnerLink, type PartnerLinkCreate, type PlanSource, type PolicyOptions, type PreferenceItem, type PreferenceRecord, type PreviewToken, type PreviewTokenOptions, type ProfileAttributeInput, type ProvisionRequest, type ProvisionResult, type ProvisionStep, type PublicDsarFiled, type PublicDsarPending, type PublicVerification, type PutConfigOptions, type RangeQuery, type Regulation, type RegulationSummary, type RegulatoryFeedResult, type ResellerChild, type ResellerChildCreate, type ResellerChildList, type ResellerChildPatch, type RetiredCookie, type RightKind, type RightsCaptcha, type RightsCaptchaInput, type RightsCaptchaProvider, type RightsIdentity, type RightsIdentityInput, type RightsIdentityType, type RightsLink, type RightsLinkInput, type RightsPageDocument, type RightsPageDomain, type RightsPageDomainList, type RightsPageDraft, type RightsPageDraftConflict, type RightsPageDryRun, type RightsPageIssue, type RightsPagePublishResult, type RightsPagePublished, type RightsPagePublisher, type RightsPageVersions, type RightsPageWriteOptions, type RiskScore, type RopaEntry, type RopaInput, type ScanResult, type ScanStatus, type ScoredVendor, type ScrollbarTheme, type SessionAnalysisInput, type SignedReceipt, type Site, type SiteConfig, type SiteCookie, type SiteCreate, type SiteFlow, type SiteUpdate, type SiteUpdateResult, type SnippetOptions, type StorageType, type SubscriptionTopicInput, type SuggestedRejectStyle, type SupportedLanguage, type Usage, type VendorInput, type VendorRecord, type VerifyResult, type VerifyWebhookInput, type WebhookCreate, type WebhookDeadLetter, type WebhookKeyForm, type WebhookStage, type WebhookSubscription, type WebhookTestResult, type WebhookUpdate, createCookieMunch, verifyWebhookSignature };
3022
+ export { type AbResult, type AccountOrg, type AccountOrgs, type AdPersonalizationInput, type AiInspectInput, type AiInspectResult, type ApiKey, type ApiKeyIssueInput, type ApiKeyIssued, type ApiKeyPrefix, type ApiKeyReport, type ApiKeyUpdate, type AppliedImport, type AssetUpload, type AuditEntry, type BannerRecord, type BannerSummary, type BlockedReport, type BrandExtractionResult, type BrandKit, type BrandKitCreate, type BrandSuggestion, type BulkSiteInput, type BulkSiteResult, type ButtonParityFinding, type ButtonParityLint, type ButtonParityScan, type CategorizedCookie, type CenterToken, type CenterTokenInput, type ChildKeyInput, type ConfigChange, type ConfigDryRun, type ConfigWarning, type ConsentDay, type ConsentDecisionInput, type ConsentIngestInput, type ConsentLogRow, type ConsentSyncSecret, type ConsentSyncSecretMinted, type CookieDeclaration, CookieMunchApiError, type CookieMunchClient, type CookieMunchOptions, type CookiePreset, type CookiePresetManifest, type CookiePresetParams, type CookiePresetResult, type CookiePresetVendor, type CspSources, type DeclarationDiff, type DeclarationDryRun, type DeclarationWarning, type DeclaredCookie, type DeclaredCookieInput, type DnsRecordInstruction, type DsarCreate, type DsarEraseResult, type DsarExecutor, type DsarExecutorCreated, type DsarExecutorDryRun, type DsarExecutorInput, type DsarExecutorPatch, type DsarExecutorPresetInput, type DsarExportResult, type DsarRequest, type DsarStatus, type DsarTask, type DsarTaskEvent, type DsarTaskExport, type DsarTaskLogEntry, type DsarTaskOutcome, type DsarType, type EnforcementRuleInput, type ExecutorHealth, type ExecutorPresetName, type ExecutorPresetUpgrade, type ExecutorPresets, type ExecutorProfile, type ExecutorTestInput, type ExecutorTestResult, type ExecutorWebhookDelivery, type ExecutorWebhookTestResult, type FlowIssue, type FlowOp, type FlowOpResponse, type FulfillmentOp, type HealthRow, type Identifier, type Identity, type ImportedCookie, type ImportedDeclaration, type InstallSnippet, type IntegrationHealthReport, type LegalBasis, type LogQuery, type MailProvider, type MailProviderInput, type MailProviderKind, type MailProviderTestResult, type Member, type MintConsentSyncTokenInput, type ObservedPurgeResult, type OptInMethod, type Org, type OrgControllerIdentity, type OrgControllerInput, type OrgUpdate, type ParityControlSummary, type PartnerCatalogEntry, type PartnerId, type PartnerLink, type PartnerLinkCreate, type PlanSource, type PolicyOptions, type PreferenceItem, type PreferenceRecord, type PreviewToken, type PreviewTokenOptions, type ProfileAttributeInput, type ProvisionRequest, type ProvisionResult, type ProvisionStep, type PublicDsarFiled, type PublicDsarPending, type PublicVerification, type PutConfigOptions, type RangeQuery, type Regulation, type RegulationSummary, type RegulatoryFeedResult, type ResellerChild, type ResellerChildCreate, type ResellerChildList, type ResellerChildPatch, type RetiredCookie, type RightKind, type RightsCaptcha, type RightsCaptchaInput, type RightsCaptchaProvider, type RightsIdentity, type RightsIdentityInput, type RightsIdentityType, type RightsLink, type RightsLinkInput, type RightsPageDocument, type RightsPageDomain, type RightsPageDomainList, type RightsPageDraft, type RightsPageDraftConflict, type RightsPageDryRun, type RightsPageIssue, type RightsPagePublishResult, type RightsPagePublished, type RightsPagePublisher, type RightsPageVersions, type RightsPageWriteOptions, type RiskScore, type RopaEntry, type RopaInput, SDK_VERSION, type ScanResult, type ScanStatus, type ScoredVendor, type ScrollbarTheme, type SessionAnalysisInput, type SignedReceipt, type Site, type SiteConfig, type SiteCookie, type SiteCreate, type SiteFlow, type SiteUpdate, type SiteUpdateResult, type SnippetOptions, type StorageType, type SubscriptionTopicInput, type SuggestedRejectStyle, type SupportedLanguage, type Usage, type VendorInput, type VendorRecord, type VerifyResult, type VerifyWebhookInput, type WebhookCreate, type WebhookDeadLetter, type WebhookKeyForm, type WebhookStage, type WebhookSubscription, type WebhookTestResult, type WebhookUpdate, createCookieMunch, mintConsentSyncToken, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -26,7 +26,23 @@ function verifyWebhookSignature(input) {
26
26
  return timingSafeEqual(got, want);
27
27
  }
28
28
 
29
+ // src/consent-sync.ts
30
+ import { createHmac as createHmac2 } from "crypto";
31
+ var SUBJECT_RE = /^[A-Za-z0-9._:@+/=~-]{1,128}$/;
32
+ function mintConsentSyncToken(input) {
33
+ if (!input.secret) throw new Error("mintConsentSyncToken: secret is required");
34
+ if (!input.cbid) throw new Error("mintConsentSyncToken: cbid is required");
35
+ if (!SUBJECT_RE.test(input.subject)) throw new Error("mintConsentSyncToken: subject must be 1\u2013128 characters of A-Z a-z 0-9 . _ : @ + / = ~ -");
36
+ const ttl = Math.floor(input.ttlSeconds ?? 3600);
37
+ if (!(ttl >= 1 && ttl <= 86400)) throw new Error("mintConsentSyncToken: ttlSeconds must be between 1 and 86400");
38
+ const iat = Math.floor((input.now ?? Date.now()) / 1e3);
39
+ const payload = Buffer.from(JSON.stringify({ c: input.cbid, s: input.subject, iat, exp: iat + ttl })).toString("base64url");
40
+ const sig = createHmac2("sha256", input.secret).update(`cms1.${payload}`).digest("base64url");
41
+ return `cms1.${payload}.${sig}`;
42
+ }
43
+
29
44
  // src/index.ts
45
+ var SDK_VERSION = "0.5.0";
30
46
  var CookieMunchApiError = class extends Error {
31
47
  constructor(status, message, code, body) {
32
48
  super(message);
@@ -53,7 +69,7 @@ function createCookieMunch(opts) {
53
69
  const doFetch = opts.fetch ?? globalThis.fetch;
54
70
  if (!doFetch) throw new Error("No fetch available; pass { fetch } in CookieMunchOptions.");
55
71
  async function request(method, path, body, raw = false) {
56
- const headers = { Authorization: `Bearer ${opts.apiKey}` };
72
+ const headers = { Authorization: `Bearer ${opts.apiKey}`, "User-Agent": opts.userAgent ?? `cookiemunch-js/${SDK_VERSION}` };
57
73
  if (opts.strictUnknownFields && method !== "GET") headers["Prefer"] = "strict-unknown-fields";
58
74
  const init = { method, headers };
59
75
  if (body !== void 0) {
@@ -328,6 +344,9 @@ function createCookieMunch(opts) {
328
344
  save: (subjectId, purposes) => request("POST", "/preferences", { subjectId, purposes }),
329
345
  get: (subjectId) => get(`/preferences/${enc(subjectId)}`)
330
346
  },
347
+ preferenceCenter: {
348
+ mintToken: (input) => request("POST", "/preference-center/tokens", input)
349
+ },
331
350
  members: {
332
351
  list: () => get("/members"),
333
352
  invite: (email, role) => request("POST", "/members", { email, role }),
@@ -358,6 +377,13 @@ function createCookieMunch(opts) {
358
377
  },
359
378
  test: (to) => request("POST", "/org/mail-provider/test", to ? { to } : {})
360
379
  },
380
+ controller: {
381
+ get: () => get("/org/controller"),
382
+ set: (input) => request("PUT", "/org/controller", input),
383
+ remove: async () => {
384
+ await request("DELETE", "/org/controller");
385
+ }
386
+ },
361
387
  rightsCaptcha: {
362
388
  get: () => get("/org/rights-captcha"),
363
389
  set: (input) => request("PUT", "/org/rights-captcha", input),
@@ -406,6 +432,11 @@ function createCookieMunch(opts) {
406
432
  rightsLinks: {
407
433
  create: (cbid, input) => request("POST", `/sites/${enc(cbid)}/rights-links`, input)
408
434
  },
435
+ consentSyncSecret: {
436
+ get: (cbid) => get(`/sites/${enc(cbid)}/consent-sync-secret`),
437
+ rotate: (cbid) => request("POST", `/sites/${enc(cbid)}/consent-sync-secret`),
438
+ remove: (cbid) => request("DELETE", `/sites/${enc(cbid)}/consent-sync-secret`)
439
+ },
409
440
  rightsCaptcha: {
410
441
  get: (cbid) => get(`/sites/${enc(cbid)}/rights-captcha`),
411
442
  set: (cbid, input) => request("PUT", `/sites/${enc(cbid)}/rights-captcha`, input),
@@ -436,9 +467,11 @@ function createCookieMunch(opts) {
436
467
  export {
437
468
  CONSENT_COOKIE_NAME,
438
469
  CookieMunchApiError,
470
+ SDK_VERSION,
439
471
  createCookieMunch,
440
472
  getConsent,
441
473
  isAllowed,
474
+ mintConsentSyncToken,
442
475
  parseConsentValue,
443
476
  readConsent,
444
477
  verifyWebhookSignature