@knapsack/adapter-core 4.89.8--canary.7199.f5d8aa8.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/.eslintrc.cjs ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ extends: ['@knapsack/eslint-config-starter'],
3
+ parserOptions: { tsconfigRootDir: __dirname },
4
+ };
package/dist/fs.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Filesystem utilities for parsers.
3
+ */
4
+ /**
5
+ * Write a file, creating parent directories if needed
6
+ */
7
+ export declare function writeFile({ path, content, }: {
8
+ path: string;
9
+ content: string;
10
+ }): void;
11
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;GAEG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,OAAO,GACR,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CAGP"}
package/dist/fs.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Filesystem utilities for parsers.
3
+ */
4
+ import { writeFileSync, mkdirSync } from 'node:fs';
5
+ import { dirname } from 'node:path';
6
+ /**
7
+ * Write a file, creating parent directories if needed
8
+ */
9
+ export function writeFile({ path, content, }) {
10
+ mkdirSync(dirname(path), { recursive: true });
11
+ writeFileSync(path, content);
12
+ }
13
+ //# sourceMappingURL=fs.js.map
package/dist/fs.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,EACxB,IAAI,EACJ,OAAO,GAIR;IACC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @knapsack/ingest-core
3
+ *
4
+ * Core types, interfaces, and utilities for PCIF ingestion.
5
+ * All ingestion pipelines depend on this package for shared infrastructure.
6
+ */
7
+ export type { SourceType, EntityKind, IngestSourceType, ContextEntity, Manifest, ManifestItem, ValidationResult, PipelineStage, StageInfo, MdxConfig, StorybookConfig, KnapsackConfig, FigmaConfig, ParserConfig, AdapterMessage, } from './types.js';
8
+ export { SOURCE_TYPE_TO_EVT } from './types.js';
9
+ export type { Validator, Parser, Transformer, ContextSrcAdapter, } from './interface.js';
10
+ export type { RuntimeDeps } from './runtime-deps.js';
11
+ export type { Logger, IngestEvt, LogContext } from './log.js';
12
+ export { buildLogContext } from './log.js';
13
+ export { writeFile } from './fs.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EAEV,UAAU,EACV,UAAU,EACV,gBAAgB,EAEhB,aAAa,EAEb,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAEhB,aAAa,EACb,SAAS,EAET,SAAS,EACT,eAAe,EACf,cAAc,EACd,WAAW,EACX,YAAY,EAEZ,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,YAAY,EACV,SAAS,EACT,MAAM,EACN,WAAW,EACX,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @knapsack/ingest-core
3
+ *
4
+ * Core types, interfaces, and utilities for PCIF ingestion.
5
+ * All ingestion pipelines depend on this package for shared infrastructure.
6
+ */
7
+ export { SOURCE_TYPE_TO_EVT } from './types.js';
8
+ export { buildLogContext } from './log.js';
9
+ // Filesystem utilities
10
+ export { writeFile } from './fs.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0BH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAehD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,uBAAuB;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * ContextSrcAdapter interfaces — contextSrc contract
3
+ *
4
+ * A ContextSrcAdapter<TConfig> is the implementation for handling one ContextSrcType.
5
+ * It contains everything needed to ingest a single source type.
6
+ *
7
+ * - Validator: config-level checks (UI) + full source validation (pipeline)
8
+ * - Parser: handles connecting to and extracting from a source
9
+ * - Transformer: handles transforming the extracted data into Context entities
10
+ * - ... other pipeline stages and hooks can be added in by following patterns here
11
+ */
12
+ import type { ValidationResult, SourceType } from './types.js';
13
+ import type { RuntimeDeps } from './runtime-deps.js';
14
+ /**
15
+ * Validator — two-phase validation
16
+ *
17
+ * validateConfig runs in GraphQL/UI (sync, no I/O).
18
+ * validateFull runs in the pipeline with real source access.
19
+ */
20
+ export interface Validator<TConfig> {
21
+ /** Sync check on config fields only — no file I/O, no network. */
22
+ validateConfig(config: Partial<TConfig>): ValidationResult;
23
+ /** Full validation with source access (fs, network). May be async. */
24
+ validateFull(config: TConfig): ValidationResult | Promise<ValidationResult>;
25
+ }
26
+ /**
27
+ * Parser — handles connecting to and extracting from a source
28
+ */
29
+ export interface Parser<TConfig> {
30
+ parse(config: TConfig, deps: RuntimeDeps): void | Promise<void>;
31
+ }
32
+ /**
33
+ * Transformer — handles transforming the extracted data into Context entities
34
+ *
35
+ * Symmetric with Parser: takes the same TConfig. The transformer reads
36
+ * manifest.yml + raw extractions from deps.outputPath.
37
+ */
38
+ export interface Transformer<TConfig> {
39
+ transform(config: TConfig, deps: RuntimeDeps): void | Promise<void>;
40
+ }
41
+ /**
42
+ * ContextSrcAdapter — composition of validator, parser, transformer
43
+ *
44
+ * All three stages take (config: TConfig, deps: RuntimeDeps).
45
+ * The controller populates config and wires deps.
46
+ */
47
+ export interface ContextSrcAdapter<TConfig> {
48
+ readonly sourceType: SourceType;
49
+ /** Derive the sourceKey from an adapter's config */
50
+ readonly sourceKey: (config: TConfig) => string;
51
+ readonly validator: Validator<TConfig>;
52
+ readonly parser: Parser<TConfig>;
53
+ readonly transformer: Transformer<TConfig>;
54
+ }
55
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,WAAW,SAAS,CAAC,OAAO;IAChC,kEAAkE;IAClE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC;IAE3D,sEAAsE;IACtE,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC7E;AAED;;GAEG;AACH,MAAM,WAAW,MAAM,CAAC,OAAO;IAC7B,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO;IAClC,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAAC,OAAO;IACxC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,oDAAoD;IACpD,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC;IAChD,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * ContextSrcAdapter interfaces — contextSrc contract
3
+ *
4
+ * A ContextSrcAdapter<TConfig> is the implementation for handling one ContextSrcType.
5
+ * It contains everything needed to ingest a single source type.
6
+ *
7
+ * - Validator: config-level checks (UI) + full source validation (pipeline)
8
+ * - Parser: handles connecting to and extracting from a source
9
+ * - Transformer: handles transforming the extracted data into Context entities
10
+ * - ... other pipeline stages and hooks can be added in by following patterns here
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
package/dist/log.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Adapter Logger
3
+ *
4
+ * Structured logging with Datadog integration (following the MCP server pattern.)
5
+ * Uses a context object to track operations across the parsing pipeline.
6
+ *
7
+ * This is the shared logging infrastructure for all ContextSrcAdapters.
8
+ * The default logger is configured to log to Datadog and stdout, but can be overridden and passed a
9
+ * runtime dependency.
10
+ */
11
+ import { type LogMetadata } from '@knapsack/logger';
12
+ import type { SourceType } from './types.js';
13
+ /** Ingest event types derived from the logger's LogMetadata.evt union */
14
+ type Evt = NonNullable<LogMetadata['evt']>;
15
+ export type IngestEvt = Extract<Evt, {
16
+ name: `ingest.${string}`;
17
+ }>;
18
+ /**
19
+ * Context for a log operation - tracks state across the parsing pipeline
20
+ */
21
+ export interface LogContext {
22
+ /** Source type (storybook, figma, knapsack, etc.) */
23
+ sourceType: SourceType;
24
+ /** Target identifier */
25
+ sourceKey: string;
26
+ /** KS Site identifier */
27
+ siteId: string;
28
+ }
29
+ /**
30
+ * Narrow logger interface — the contract adapters and RuntimeDeps depend on.
31
+ * The concrete createLogger return satisfies this via structural typing.
32
+ */
33
+ export interface Logger {
34
+ info(message: string, metadata?: Record<string, unknown>): void;
35
+ warn(message: string, metadata?: Record<string, unknown>): void;
36
+ debug(message: string, metadata?: Record<string, unknown>): void;
37
+ error(message: string, metadata?: Record<string, unknown>): void;
38
+ }
39
+ /**
40
+ * Create the logger instance with Datadog integration
41
+ */
42
+ export declare const log: {
43
+ info(message: string, metadata?: LogMetadata): void;
44
+ warn(message: string, metadata?: LogMetadata): void;
45
+ debug(message: string, metadata?: LogMetadata): void;
46
+ error(message: string, metadata?: LogMetadata): void;
47
+ };
48
+ /**
49
+ * Build structured log metadata following the LogMetadata.evt convention.
50
+ * Event data goes in `evt`, standard context (siteId) in `knapsackMeta`, adapter context in `metadata`.
51
+ */
52
+ export declare function buildLogContext({ context, evt, error, }: {
53
+ context: LogContext;
54
+ evt: IngestEvt;
55
+ error?: Error;
56
+ }): LogMetadata;
57
+ export {};
58
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.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pB,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GAAG,WAAW,CAOd"}
package/dist/log.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Adapter Logger
3
+ *
4
+ * Structured logging with Datadog integration (following the MCP server pattern.)
5
+ * Uses a context object to track operations across the parsing pipeline.
6
+ *
7
+ * This is the shared logging infrastructure for all ContextSrcAdapters.
8
+ * The default logger is configured to log to Datadog and stdout, but can be overridden and passed a
9
+ * runtime dependency.
10
+ */
11
+ import { createLogger } from '@knapsack/logger';
12
+ // Environment configuration
13
+ const SERVICE_NAME = 'context-src-runner';
14
+ const ENVIRONMENT = process.env.NODE_ENV || 'development';
15
+ const { DATADOG_API_KEY } = process.env;
16
+ const KS_DD_LOGGER_ENABLED = process.env.KS_DD_LOGGER_ENABLED === 'true';
17
+ /**
18
+ * Create the logger instance with Datadog integration
19
+ */
20
+ export const log = createLogger({
21
+ defaultMeta: {
22
+ service: SERVICE_NAME,
23
+ env: ENVIRONMENT,
24
+ },
25
+ dataDogApiKey: DATADOG_API_KEY,
26
+ enableDataDogLogger: ENVIRONMENT === 'production' || KS_DD_LOGGER_ENABLED,
27
+ });
28
+ /**
29
+ * Build structured log metadata following the LogMetadata.evt convention.
30
+ * Event data goes in `evt`, standard context (siteId) in `knapsackMeta`, adapter context in `metadata`.
31
+ */
32
+ export function buildLogContext({ context, evt, error, }) {
33
+ return {
34
+ knapsackMeta: { siteId: context.siteId },
35
+ metadata: { sourceKey: context.sourceKey },
36
+ evt,
37
+ ...(error && { error }),
38
+ };
39
+ }
40
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAoB,MAAM,kBAAkB,CAAC;AAGlE,4BAA4B;AAC5B,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAC1C,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAC1D,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AACxC,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,MAAM,CAAC;AA6BzE;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,YAAY,CAAC;IAC9B,WAAW,EAAE;QACX,OAAO,EAAE,YAAY;QACrB,GAAG,EAAE,WAAW;KACjB;IACD,aAAa,EAAE,eAAe;IAC9B,mBAAmB,EAAE,WAAW,KAAK,YAAY,IAAI,oBAAoB;CAC1E,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,OAAO,EACP,GAAG,EACH,KAAK,GAKN;IACC,OAAO;QACL,YAAY,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;QACxC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE;QAC1C,GAAG;QACH,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC;KACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Runtime Dependencies — injected by the handler, not owned by parsers
3
+ *
4
+ * Currently provides methods to handle different channels:
5
+ * - logger: observability (goes to stdout/Datadog/CloudWatch/console)
6
+ * - emit: application messaging (goes to SQS/handler callbacks)
7
+ * - writeFile: filesystem output
8
+ */
9
+ import type { Logger } from './log.js';
10
+ import type { AdapterMessage } from './types.js';
11
+ /**
12
+ * Runtime dependencies injected into parser.parse() and transformer.transform()
13
+ */
14
+ export interface RuntimeDeps {
15
+ /** Observability - consumed by ops/devs for debugging */
16
+ logger: Logger;
17
+ /** Application messaging - consumed by app/queues for DB/UI */
18
+ emit: (message: AdapterMessage) => void;
19
+ /** File system - used by parsers to write any data */
20
+ writeFile: (params: {
21
+ path: string;
22
+ content: string;
23
+ }) => void;
24
+ /** Working directory for stage output (manifests, raw extractions, entities) */
25
+ outputPath: string;
26
+ /** Error escalation - handler decides how to handle (DLQ, alert, etc.) */
27
+ onError?: (error: Error) => void;
28
+ }
29
+ //# sourceMappingURL=runtime-deps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-deps.d.ts","sourceRoot":"","sources":["../src/runtime-deps.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IAEf,+DAA+D;IAC/D,IAAI,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAExC,sDAAsD;IACtD,SAAS,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAE/D,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;IAEnB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Runtime Dependencies — injected by the handler, not owned by parsers
3
+ *
4
+ * Currently provides methods to handle different channels:
5
+ * - logger: observability (goes to stdout/Datadog/CloudWatch/console)
6
+ * - emit: application messaging (goes to SQS/handler callbacks)
7
+ * - writeFile: filesystem output
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=runtime-deps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-deps.js","sourceRoot":"","sources":["../src/runtime-deps.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Core types for ContextSrcAdapters
3
+ *
4
+ * These types define the contract that all ContextSrcAdapters.
5
+ */
6
+ /**
7
+ * Supported source types for PCIF parsers
8
+ */
9
+ export type SourceType = 'STORYBOOK' | 'KNAPSACK' | 'FIGMA' | 'MDX';
10
+ /**
11
+ * Maps internal SourceType to the lowercase sourceType used in LogMetadata.evt.
12
+ * Maps internal SourceType values to lowercase event strings.
13
+ */
14
+ export declare const SOURCE_TYPE_TO_EVT: {
15
+ readonly STORYBOOK: "storybook";
16
+ readonly KNAPSACK: "knapsack";
17
+ readonly FIGMA: "figma";
18
+ readonly MDX: "mdx";
19
+ };
20
+ export type IngestSourceType = (typeof SOURCE_TYPE_TO_EVT)[SourceType];
21
+ /**
22
+ * Context Entity types - the processed types
23
+ *
24
+ * These are the canonical content types for schema content at rest.
25
+ * Interim Source-specific types (e.g., StorybookContentType) are defined in each ContextSrcAdapter.
26
+ */
27
+ export type EntityKind = 'COMPONENT' | 'DOCUMENT' | 'TOKEN_SET';
28
+ /**
29
+ * A Context Entity - the final output of the ingest pipeline
30
+ */
31
+ export interface ContextEntity {
32
+ /** Unique key, e.g., "component/button" or "document/getting-started" */
33
+ canonicalKey: string;
34
+ /** Entity kind */
35
+ entityKind: EntityKind;
36
+ /** Source key */
37
+ sourceKey: string;
38
+ }
39
+ /**
40
+ * Pipeline stages — the ordered lifecycle stages an adapter runs through
41
+ */
42
+ export type PipelineStage = 'parse' | 'transform' | 'validate';
43
+ /**
44
+ * Metadata recorded when a stage completes
45
+ */
46
+ export interface StageInfo {
47
+ /** Number of items processed in this stage */
48
+ itemCount: number;
49
+ /** Number of errors in this stage */
50
+ errors: number;
51
+ /** Duration of this stage in milliseconds */
52
+ durationMs: number;
53
+ /** ISO-8601 timestamp when this stage completed */
54
+ completedAt: string;
55
+ /** Number of items discovered in source (parse stage only) */
56
+ discoveredItemCount?: number;
57
+ }
58
+ /**
59
+ * A single item in the manifest
60
+ */
61
+ export interface ManifestItem {
62
+ /** Reference ID from source (e.g., storybook story id) */
63
+ ref: string;
64
+ /** Source-specific content type (e.g., "story", "docs" for Storybook) */
65
+ refType: string;
66
+ stage: PipelineStage;
67
+ /** Error message if extraction failed */
68
+ error?: string;
69
+ }
70
+ /**
71
+ * Manifest - tracks pipeline progress
72
+ *
73
+ * Single manifest that grows through the pipeline:
74
+ * - Parse stage: populates items[], sets stages.parse
75
+ * - Transform stage: adds entities[], sets stages.transform
76
+ */
77
+ export interface Manifest {
78
+ /** Site identifier */
79
+ siteId: string;
80
+ /** Source key */
81
+ sourceKey: string;
82
+ /** Source type */
83
+ sourceType: SourceType;
84
+ /** Items in pipeline */
85
+ items: ManifestItem[];
86
+ /** manifest version */
87
+ manifestVersion: string;
88
+ /** Per-stage completion metadata, populated as each stage runs */
89
+ stages: Partial<Record<PipelineStage, StageInfo>>;
90
+ /** Entity references for transformed items (added by transform stage) */
91
+ entities?: ContextEntity[];
92
+ }
93
+ /**
94
+ * Result from a parse run (discover + extract)
95
+ */
96
+ export interface PipelineResult {
97
+ /** Which parser produced this result */
98
+ sourceType: SourceType;
99
+ /** Site identifier (auto-detected or explicit) */
100
+ siteId: string;
101
+ stage: PipelineStage;
102
+ /** Path where manifest and raw extractions were written */
103
+ outputPath: string;
104
+ adapterVersion: string;
105
+ durationMs: number;
106
+ }
107
+ /**
108
+ * Result of config validation - discriminated union for type safety
109
+ */
110
+ export type ValidationResult = {
111
+ valid: true;
112
+ } | {
113
+ valid: false;
114
+ errors: string[];
115
+ };
116
+ /**
117
+ * MDX parser configuration
118
+ */
119
+ export interface MdxConfig {
120
+ /** Stable identifier for this source (e.g. "mdx--intro") — must be filename-friendly */
121
+ sourceKey: string;
122
+ /** Original filename from the upload */
123
+ filename: string;
124
+ /** File size in bytes */
125
+ size: number;
126
+ /** Path to MDX file on disk */
127
+ path: string;
128
+ /** Optional explicit site ID */
129
+ siteId?: string;
130
+ }
131
+ /**
132
+ * Storybook parser configuration
133
+ */
134
+ export interface StorybookConfig {
135
+ /** Stable identifier for this source */
136
+ sourceKey: string;
137
+ /** Storybook URL */
138
+ url: string;
139
+ /** Max items to extract (for testing) */
140
+ limit?: number;
141
+ }
142
+ /**
143
+ * TBD: Knapsack parser configuration
144
+ */
145
+ export interface KnapsackConfig {
146
+ /** Stable identifier for this source */
147
+ sourceKey: string;
148
+ /** Branch name */
149
+ branchName: string;
150
+ /** Input path to raw sitemeta schema.json */
151
+ inputPath: string;
152
+ /** Optional explicit site ID (defaults to auto-detection from filename) */
153
+ siteId?: string;
154
+ }
155
+ /**
156
+ * TBD: Figma parser configuration
157
+ */
158
+ export interface FigmaConfig {
159
+ /** Stable identifier for this source */
160
+ sourceKey: string;
161
+ /** Figma file key */
162
+ fileKey: string;
163
+ /** Figma API token */
164
+ token: string;
165
+ /** Optional explicit site ID */
166
+ siteId?: string;
167
+ }
168
+ /**
169
+ * Parser configuration - discriminated union for runtime dispatch
170
+ */
171
+ export type ParserConfig = ({
172
+ type: 'mdx';
173
+ } & MdxConfig) | ({
174
+ type: 'storybook';
175
+ } & StorybookConfig) | ({
176
+ type: 'knapsack';
177
+ } & KnapsackConfig) | ({
178
+ type: 'figma';
179
+ } & FigmaConfig);
180
+ /**
181
+ * Structured messages the parser sends to the application layer.
182
+ * The handler wires these to SQS, webhooks, or direct callbacks.
183
+ * These are all TBD, we need to define them later.
184
+ * TODO: needs input from what the ui and db WANT from parsers
185
+ */
186
+ export type AdapterMessage = {
187
+ stage: 'parse';
188
+ type: 'progress';
189
+ itemsComplete: number;
190
+ itemsTotal: number;
191
+ } | {
192
+ stage: 'parse';
193
+ type: 'item.extracted';
194
+ ref: string;
195
+ } | {
196
+ stage: 'parse';
197
+ type: 'item.failed';
198
+ ref: string;
199
+ error: string;
200
+ } | {
201
+ stage: 'transform';
202
+ type: 'progress';
203
+ itemsComplete: number;
204
+ itemsTotal: number;
205
+ } | {
206
+ stage: 'transform';
207
+ type: 'item.extracted';
208
+ ref: string;
209
+ } | {
210
+ stage: 'transform';
211
+ type: 'item.failed';
212
+ ref: string;
213
+ error: string;
214
+ };
215
+ //# sour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IACnB,IAAI,EAAE,UAAU,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB,GACD;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,aAAa,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Core types for ContextSrcAdapters
3
+ *
4
+ * These types define the contract that all ContextSrcAdapters.
5
+ */
6
+ /**
7
+ * Maps internal SourceType to the lowercase sourceType used in LogMetadata.evt.
8
+ * Maps internal SourceType values to lowercase event strings.
9
+ */
10
+ export const SOURCE_TYPE_TO_EVT = {
11
+ STORYBOOK: 'storybook',
12
+ KNAPSACK: 'knapsack',
13
+ FIGMA: 'figma',
14
+ MDX: 'mdx',
15
+ };
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;CACmC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@knapsack/adapter-core",
3
+ "description": "Core types, interfaces, and logging for ContextSrcAdapters",
4
+ "version": "4.89.8--canary.7199.f5d8aa8.0",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./package": "./package.json",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "sideEffects": false,
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "clean": "rm -rf dist",
20
+ "dev": "tsc --watch",
21
+ "lint": "eslint ./src --quiet"
22
+ },
23
+ "author": "Knapsack (https://www.knapsack.cloud)",
24
+ "dependencies": {
25
+ "@knapsack/logger": "4.89.8--canary.7199.f5d8aa8.0"
26
+ },
27
+ "devDependencies": {
28
+ "@knapsack/eslint-config-starter": "4.89.8--canary.7199.f5d8aa8.0",
29
+ "@knapsack/typescript-config-starter": "4.89.8--canary.7199.f5d8aa8.0",
30
+ "@types/node": "^20.19.25",
31
+ "eslint": "^9.20.0",
32
+ "typescript": "^5.9.3"
33
+ },
34
+ "license": "GPL-2.0-or-later",
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "repository": {
39
+ "url": "https://github.com/knapsack-labs/app-monorepo",
40
+ "directory": "libs/ingest-pipeline/adapters/core",
41
+ "type": "git"
42
+ },
43
+ "gitHead": "f5d8aa87c6ce664d3e72ca892982b0765bcec20e"
44
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }