- Add consent to CORE_PACKAGE_GENERATORS in turbo/generators/config.ts so pnpm turbo gen core-package consent is a valid command (not hand-rollable) - Create turbo/generators/templates/core-package/consent/ mirroring the analytics template shape (AGENTS.md, package.json, tsconfig, turbo, vitest, eslint, src/index.ts scaffolds) - Regenerate packages/core-consent/ from the new template (replaces the previous hand-rolled attempt that violated the generator-first rule) - Add __consentChecked to withCapture PROPAGATED_BRANDS so the brand bubbles through the full withSpan→withCapture wrapper chain to the outermost binding that assertFeatureConformance reads Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import type { IConsent } from "./consent.interface";
|
|
import type { ConsentChecked } from "@repo/core-shared/conformance";
|
|
import { attachBrand } from "@repo/core-shared/conformance";
|
|
|
|
export type { ConsentChecked };
|
|
|
|
/**
|
|
* Use-case wrapper applied at DI bind time. Attaches the `__consentChecked`
|
|
* brand so the boot-time assertion can verify consent-gated use cases were
|
|
* bound through the consent-aware path.
|
|
*
|
|
* The forward closure keeps the brand on a fresh function so the original
|
|
* `fn` reference is not mutated — important when the same factory output is
|
|
* used elsewhere unwrapped (dev-seed paths, tests).
|
|
*
|
|
* Composition order (innermost to outermost):
|
|
* withSpan → withCapture → withAudit → withAnalytics → withConsent → factory(deps)
|
|
*/
|
|
export function withConsent<Args extends unknown[], R>(
|
|
consent: IConsent,
|
|
fn: (...args: Args) => Promise<R>,
|
|
): ConsentChecked<(...args: Args) => Promise<R>> {
|
|
void consent;
|
|
const wrapped: (...args: Args) => Promise<R> = (...args) => fn(...args);
|
|
attachBrand(wrapped, "__consentChecked");
|
|
return wrapped as ConsentChecked<(...args: Args) => Promise<R>>;
|
|
}
|