@pacp/spec 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PACP contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # pacp
2
+
3
+ Schema, profiles e validador do [PACP](https://pacp-org.github.io/pacp/) (Padrão Aberto de Catálogo e Precificação) como pacote npm.
4
+
5
+ ## Instalação
6
+
7
+ ```bash
8
+ npm install pacp
9
+ ```
10
+
11
+ Para usar a função `validate()`, instale também as peer dependencies:
12
+
13
+ ```bash
14
+ npm install pacp ajv ajv-formats
15
+ ```
16
+
17
+ ## Uso
18
+
19
+ ### Schema e profiles (sem dependências extras)
20
+
21
+ ```typescript
22
+ import { schema, profiles, profileIds, SPEC_VERSION } from 'pacp';
23
+
24
+ // JSON Schema completo do PACP v1.0.0
25
+ console.log(schema.$id); // "https://pacp.dev/spec/1.0.0/pacp.schema.json"
26
+
27
+ // Versão da spec
28
+ console.log(SPEC_VERSION); // "1.0.0"
29
+
30
+ // Extension profiles disponíveis
31
+ console.log(profileIds); // ["moveis", "iluminacao", "pisos-revestimentos", "fiscal-br"]
32
+
33
+ // Acessar profile específico
34
+ console.log(profiles.moveis.title); // "PACP Profile: Moveis e Alta Decoracao"
35
+ ```
36
+
37
+ ### Validação de documentos
38
+
39
+ ```typescript
40
+ import { validate } from 'pacp';
41
+
42
+ const catalogDocument = {
43
+ spec: '1.0.0',
44
+ document_type: 'CATALOG',
45
+ catalog: { id: 'meu_catalogo' },
46
+ rulesets: [
47
+ {
48
+ id: 'rs_base',
49
+ target: 'BASE',
50
+ rules: [{ id: 'rule_setup', operation: 'ADD', value: 10 }],
51
+ },
52
+ ],
53
+ };
54
+
55
+ const result = validate(catalogDocument);
56
+
57
+ if (result.valid) {
58
+ console.log('Documento PACP válido!');
59
+ } else {
60
+ for (const issue of result.issues) {
61
+ console.error(`[${issue.code}] ${issue.path}: ${issue.message}`);
62
+ }
63
+ }
64
+ ```
65
+
66
+ ### Tipos TypeScript
67
+
68
+ Todos os tipos do PACP estão disponíveis:
69
+
70
+ ```typescript
71
+ import type {
72
+ CatalogDocument,
73
+ ProductDocument,
74
+ PacpDocument,
75
+ Product,
76
+ Ruleset,
77
+ Rule,
78
+ Table,
79
+ Constraint,
80
+ Dependency,
81
+ Context,
82
+ Option,
83
+ ImageRef,
84
+ Measure,
85
+ DimensionsObj,
86
+ ValidationResult,
87
+ } from 'pacp';
88
+
89
+ const product: Product = {
90
+ id: 'prod_mesa',
91
+ name: 'Mesa de Jantar',
92
+ sku: 'MES-001',
93
+ manufacturer: 'Moveis Artisan',
94
+ brand: 'Artisan Home',
95
+ base_price: 2500,
96
+ weight: { value: 45, unit: 'kg' },
97
+ dimensions: { width: 160, height: 78, depth: 90, unit: 'cm' },
98
+ options: [
99
+ { id: 'opt_madeira', attributeId: 'material', value: 'CARVALHO' },
100
+ ],
101
+ 'x-finish': 'Natural envernizado',
102
+ 'x-warranty_months': 24,
103
+ };
104
+ ```
105
+
106
+ ### Acesso direto aos JSONs
107
+
108
+ Se preferir usar os JSONs diretamente (sem TypeScript):
109
+
110
+ ```javascript
111
+ // Schema principal
112
+ const schema = require('pacp/schema.json');
113
+
114
+ // Profiles
115
+ const moveis = require('pacp/profiles/moveis.json');
116
+ const iluminacao = require('pacp/profiles/iluminacao.json');
117
+ const pisos = require('pacp/profiles/pisos-revestimentos.json');
118
+ const fiscal = require('pacp/profiles/fiscal-br.json');
119
+ ```
120
+
121
+ ## O que está incluído
122
+
123
+ | Export | Descrição |
124
+ |--------|-----------|
125
+ | `schema` | JSON Schema completo do PACP v1.0.0 |
126
+ | `profiles` | Objeto com todos os profiles oficiais |
127
+ | `profileIds` | Array com IDs dos profiles: `moveis`, `iluminacao`, `pisos-revestimentos`, `fiscal-br` |
128
+ | `validate()` | Função de validação (requer `ajv` + `ajv-formats`) |
129
+ | `SPEC_VERSION` | Constante `"1.0.0"` |
130
+ | Tipos TS | `CatalogDocument`, `ProductDocument`, `Product`, `Rule`, `Table`, etc. |
131
+
132
+ ## Extension Profiles
133
+
134
+ | Profile | Vertical | Campos |
135
+ |---------|----------|--------|
136
+ | `moveis` | Móveis e Alta Decoração | `x-assembly_required`, `x-load_capacity`, `x-finish`, `x-warranty_months`, ... |
137
+ | `iluminacao` | Iluminação | `x-lumens`, `x-color_temp_k`, `x-voltage`, `x-dimmable`, ... |
138
+ | `pisos-revestimentos` | Pisos e Revestimentos | `x-pei`, `x-slip_resistance`, `x-rectified`, `x-usage`, ... |
139
+ | `fiscal-br` | Fiscal Brasil | `x-ncm`, `x-origem`, `x-cest`, `x-cfop`, ... |
140
+
141
+ ## Links
142
+
143
+ - [Spec v1.0.0](https://github.com/pacp-org/pacp/blob/main/spec/1.0.0/pacp.md)
144
+ - [Guia de integração](https://github.com/pacp-org/pacp/blob/main/docs/integration-guide.md)
145
+ - [Site](https://pacp-org.github.io/pacp/)
146
+ - [GitHub](https://github.com/pacp-org/pacp)
147
+
148
+ ## Licença
149
+
150
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ SPEC_VERSION: () => SPEC_VERSION,
24
+ profileIds: () => profileIds,
25
+ profiles: () => profiles,
26
+ schema: () => schema,
27
+ validate: () => validate
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/schema.ts
32
+ var import_node_fs = require("fs");
33
+ var import_node_path = require("path");
34
+ function loadJson(relativePath) {
35
+ const fullPath = (0, import_node_path.join)(__dirname, relativePath);
36
+ return JSON.parse((0, import_node_fs.readFileSync)(fullPath, "utf8"));
37
+ }
38
+ var schema = loadJson("./pacp.schema.json");
39
+ var profiles = {
40
+ moveis: loadJson("./profiles/moveis.schema.json"),
41
+ iluminacao: loadJson("./profiles/iluminacao.schema.json"),
42
+ "pisos-revestimentos": loadJson("./profiles/pisos-revestimentos.schema.json"),
43
+ "fiscal-br": loadJson("./profiles/fiscal-br.schema.json")
44
+ };
45
+ var profileIds = Object.keys(profiles);
46
+
47
+ // src/validate.ts
48
+ function validate(document) {
49
+ let Ajv2020;
50
+ let addFormats;
51
+ try {
52
+ Ajv2020 = require("ajv/dist/2020");
53
+ addFormats = require("ajv-formats");
54
+ } catch {
55
+ throw new Error(
56
+ "Para usar validate(), instale ajv e ajv-formats: npm install ajv ajv-formats"
57
+ );
58
+ }
59
+ const ajv = new Ajv2020({ allErrors: true, strict: false });
60
+ addFormats(ajv);
61
+ const issues = [];
62
+ const validateSchema = ajv.compile(schema);
63
+ const valid = validateSchema(document);
64
+ if (!valid && validateSchema.errors) {
65
+ for (const error of validateSchema.errors) {
66
+ issues.push({
67
+ code: "SCHEMA",
68
+ path: error.instancePath || "/",
69
+ message: error.message ?? "Erro de validacao de schema"
70
+ });
71
+ }
72
+ }
73
+ if (document && typeof document === "object" && !Array.isArray(document)) {
74
+ const doc = document;
75
+ const declaredProfiles = Array.isArray(doc.profiles) ? doc.profiles : [];
76
+ for (const profileId of declaredProfiles) {
77
+ if (typeof profileId !== "string") continue;
78
+ const profileSchema = profiles[profileId];
79
+ if (!profileSchema) {
80
+ issues.push({
81
+ code: "UNKNOWN_PROFILE",
82
+ path: "/profiles",
83
+ message: `Profile "${profileId}" nao e um profile oficial PACP`
84
+ });
85
+ continue;
86
+ }
87
+ const products = extractProducts(doc);
88
+ const validateProfile = ajv.compile(profileSchema);
89
+ for (let i = 0; i < products.length; i++) {
90
+ const xFields = extractXFields(products[i]);
91
+ if (Object.keys(xFields).length === 0) continue;
92
+ const profileValid = validateProfile(xFields);
93
+ if (!profileValid && validateProfile.errors) {
94
+ for (const error of validateProfile.errors) {
95
+ issues.push({
96
+ code: "PROFILE_VALIDATION",
97
+ path: `products[${i}]${error.instancePath || "/"}`,
98
+ message: `Profile "${profileId}": ${error.message ?? "erro de validacao"}`
99
+ });
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ return { valid: issues.length === 0, issues };
106
+ }
107
+ function extractProducts(doc) {
108
+ if (doc.document_type === "PRODUCT" && doc.product && typeof doc.product === "object") {
109
+ return [doc.product];
110
+ }
111
+ return [];
112
+ }
113
+ function extractXFields(obj) {
114
+ const result = {};
115
+ for (const [key, value] of Object.entries(obj)) {
116
+ if (key.startsWith("x-")) {
117
+ result[key] = value;
118
+ }
119
+ }
120
+ return result;
121
+ }
122
+
123
+ // src/index.ts
124
+ var SPEC_VERSION = "1.0.0";
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ SPEC_VERSION,
128
+ profileIds,
129
+ profiles,
130
+ schema,
131
+ validate
132
+ });
133
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/schema.ts","../src/validate.ts"],"sourcesContent":["export { schema, profiles, profileIds } from \"./schema.js\";\r\nexport { validate } from \"./validate.js\";\r\nexport type {\r\n ScalarValue,\r\n ImageType,\r\n ImageRef,\r\n Measure,\r\n DimensionsObj,\r\n AttributeRef,\r\n AttributeValue,\r\n Option,\r\n LotPolicy,\r\n SalesUnit,\r\n Product,\r\n Predicate,\r\n Condition,\r\n Component,\r\n RuleOperation,\r\n Rule,\r\n Ruleset,\r\n Dimension,\r\n TableRow,\r\n Table,\r\n Dependency,\r\n Constraint,\r\n PriceList,\r\n Catalog,\r\n ProductRef,\r\n Context,\r\n Pricing,\r\n CatalogDocument,\r\n ProductDocument,\r\n PacpDocument,\r\n ProfileId,\r\n ValidationIssue,\r\n ValidationResult,\r\n} from \"./types.js\";\r\n\r\nexport const SPEC_VERSION = \"1.0.0\" as const;\r\n","import { readFileSync } from \"node:fs\";\r\nimport { join } from \"node:path\";\r\n\r\nfunction loadJson(relativePath: string): Record<string, unknown> {\r\n const fullPath = join(__dirname, relativePath);\r\n return JSON.parse(readFileSync(fullPath, \"utf8\"));\r\n}\r\n\r\nexport const schema = loadJson(\"./pacp.schema.json\") as Record<string, unknown>;\r\n\r\nexport const profiles = {\r\n moveis: loadJson(\"./profiles/moveis.schema.json\") as Record<string, unknown>,\r\n iluminacao: loadJson(\"./profiles/iluminacao.schema.json\") as Record<string, unknown>,\r\n \"pisos-revestimentos\": loadJson(\"./profiles/pisos-revestimentos.schema.json\") as Record<string, unknown>,\r\n \"fiscal-br\": loadJson(\"./profiles/fiscal-br.schema.json\") as Record<string, unknown>,\r\n} as const;\r\n\r\nexport type ProfileId = keyof typeof profiles;\r\n\r\nexport const profileIds = Object.keys(profiles) as ProfileId[];\r\n","import type { ValidationResult, ValidationIssue, PacpDocument } from \"./types.js\";\r\nimport { schema, profiles, type ProfileId } from \"./schema.js\";\r\n\r\nexport function validate(document: unknown): ValidationResult {\r\n let Ajv2020: typeof import(\"ajv/dist/2020\").default;\r\n let addFormats: typeof import(\"ajv-formats\").default;\r\n\r\n try {\r\n Ajv2020 = require(\"ajv/dist/2020\") as typeof import(\"ajv/dist/2020\").default;\r\n addFormats = require(\"ajv-formats\") as typeof import(\"ajv-formats\").default;\r\n } catch {\r\n throw new Error(\r\n 'Para usar validate(), instale ajv e ajv-formats: npm install ajv ajv-formats'\r\n );\r\n }\r\n\r\n const ajv = new Ajv2020({ allErrors: true, strict: false });\r\n addFormats(ajv);\r\n\r\n const issues: ValidationIssue[] = [];\r\n\r\n const validateSchema = ajv.compile(schema);\r\n const valid = validateSchema(document);\r\n\r\n if (!valid && validateSchema.errors) {\r\n for (const error of validateSchema.errors) {\r\n issues.push({\r\n code: \"SCHEMA\",\r\n path: error.instancePath || \"/\",\r\n message: error.message ?? \"Erro de validacao de schema\",\r\n });\r\n }\r\n }\r\n\r\n if (document && typeof document === \"object\" && !Array.isArray(document)) {\r\n const doc = document as Record<string, unknown>;\r\n const declaredProfiles = Array.isArray(doc.profiles) ? doc.profiles : [];\r\n\r\n for (const profileId of declaredProfiles) {\r\n if (typeof profileId !== \"string\") continue;\r\n\r\n const profileSchema = profiles[profileId as ProfileId];\r\n if (!profileSchema) {\r\n issues.push({\r\n code: \"UNKNOWN_PROFILE\",\r\n path: \"/profiles\",\r\n message: `Profile \"${profileId}\" nao e um profile oficial PACP`,\r\n });\r\n continue;\r\n }\r\n\r\n const products = extractProducts(doc);\r\n const validateProfile = ajv.compile(profileSchema);\r\n\r\n for (let i = 0; i < products.length; i++) {\r\n const xFields = extractXFields(products[i]);\r\n if (Object.keys(xFields).length === 0) continue;\r\n\r\n const profileValid = validateProfile(xFields);\r\n if (!profileValid && validateProfile.errors) {\r\n for (const error of validateProfile.errors) {\r\n issues.push({\r\n code: \"PROFILE_VALIDATION\",\r\n path: `products[${i}]${error.instancePath || \"/\"}`,\r\n message: `Profile \"${profileId}\": ${error.message ?? \"erro de validacao\"}`,\r\n });\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n return { valid: issues.length === 0, issues };\r\n}\r\n\r\nfunction extractProducts(doc: Record<string, unknown>): Record<string, unknown>[] {\r\n if (doc.document_type === \"PRODUCT\" && doc.product && typeof doc.product === \"object\") {\r\n return [doc.product as Record<string, unknown>];\r\n }\r\n return [];\r\n}\r\n\r\nfunction extractXFields(obj: Record<string, unknown>): Record<string, unknown> {\r\n const result: Record<string, unknown> = {};\r\n for (const [key, value] of Object.entries(obj)) {\r\n if (key.startsWith(\"x-\")) {\r\n result[key] = value;\r\n }\r\n }\r\n return result;\r\n}\r\n"],"mappings":"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","names":[]}
@@ -0,0 +1,223 @@
1
+ export { profileIds, profiles, schema } from './schema.cjs';
2
+
3
+ type ScalarValue = string | number | boolean;
4
+ type ImageType = "MAIN" | "DETAIL" | "AMBIANCE" | "TECHNICAL" | "OTHER";
5
+ interface ImageRef {
6
+ url: string;
7
+ label?: string;
8
+ type?: ImageType;
9
+ }
10
+ interface Measure {
11
+ value: number;
12
+ unit: string;
13
+ }
14
+ interface DimensionsObj {
15
+ width?: number;
16
+ height?: number;
17
+ depth?: number;
18
+ unit: string;
19
+ }
20
+ interface AttributeRef {
21
+ id: string;
22
+ label?: string;
23
+ }
24
+ interface AttributeValue {
25
+ attributeId: string;
26
+ value: ScalarValue;
27
+ label?: string;
28
+ }
29
+ interface Option {
30
+ id: string;
31
+ attributeId: string;
32
+ value: ScalarValue;
33
+ label?: string;
34
+ }
35
+ interface LotPolicy {
36
+ required: boolean;
37
+ source: "CONTEXT" | "ATTRIBUTE";
38
+ contextKey?: string;
39
+ attributeId?: string;
40
+ }
41
+ interface SalesUnit {
42
+ requested_unit: string;
43
+ sell_unit: string;
44
+ quantity_per_sell_unit: number;
45
+ rounding: "CEIL";
46
+ min_sell_units?: number;
47
+ }
48
+ interface Product {
49
+ id: string;
50
+ name?: string;
51
+ sku?: string;
52
+ manufacturer?: string;
53
+ brand?: string;
54
+ description?: string;
55
+ category?: string;
56
+ gtin?: string;
57
+ base_price?: number;
58
+ images?: ImageRef[];
59
+ tags?: string[];
60
+ weight?: Measure;
61
+ dimensions?: DimensionsObj;
62
+ lot_policy?: LotPolicy;
63
+ sales_unit?: SalesUnit;
64
+ attributes?: AttributeRef[];
65
+ attribute_values?: AttributeValue[];
66
+ options: Option[];
67
+ rulesetIds?: string[];
68
+ [key: `x-${string}`]: unknown;
69
+ }
70
+ interface Predicate {
71
+ fact: string;
72
+ operator: "EQ" | "NEQ" | "IN" | "NOT_IN" | "GT" | "GTE" | "LT" | "LTE" | "EXISTS";
73
+ value?: ScalarValue;
74
+ values?: ScalarValue[];
75
+ }
76
+ interface Condition {
77
+ all?: Predicate[];
78
+ any?: Predicate[];
79
+ }
80
+ interface Component {
81
+ label?: string;
82
+ value?: number;
83
+ tableId?: string;
84
+ optionId?: string;
85
+ }
86
+ type RuleOperation = "ADD" | "PERCENT_OF" | "OVERRIDE" | "LOOKUP" | "MAX_OF" | "MIN_OF" | "PICK" | "ROUND" | "CAP" | "FLOOR";
87
+ interface Rule {
88
+ id: string;
89
+ operation: RuleOperation;
90
+ priority?: number;
91
+ enabled?: boolean;
92
+ when?: Condition;
93
+ value?: number;
94
+ percent?: number;
95
+ tableId?: string;
96
+ components?: Component[];
97
+ precision?: number;
98
+ max?: number;
99
+ min?: number;
100
+ fallback?: number;
101
+ optionId?: string;
102
+ optionIds?: string[];
103
+ [key: `x-${string}`]: unknown;
104
+ }
105
+ interface Ruleset {
106
+ id: string;
107
+ target: "BASE" | "SUBTOTAL" | "TOTAL";
108
+ rules: Rule[];
109
+ [key: `x-${string}`]: unknown;
110
+ }
111
+ interface Dimension {
112
+ key: string;
113
+ source: "ATTRIBUTE" | "CONTEXT" | "LITERAL";
114
+ attributeId?: string;
115
+ contextKey?: string;
116
+ literal?: ScalarValue;
117
+ }
118
+ interface TableRow {
119
+ key: Record<string, ScalarValue>;
120
+ value: number;
121
+ }
122
+ interface Table {
123
+ id: string;
124
+ type: "LOOKUP";
125
+ dimensions: Dimension[];
126
+ rows: TableRow[];
127
+ keys?: (string | {
128
+ optionId?: string;
129
+ id?: string;
130
+ name?: string;
131
+ })[];
132
+ }
133
+ interface Dependency {
134
+ id: string;
135
+ type: "REQUIRES" | "IMPLIES" | "AVAILABLE_OPTIONS_WHEN";
136
+ productId?: string;
137
+ optionId?: string;
138
+ requiresOptionIds?: string[];
139
+ allowedOptionIds?: string[];
140
+ when?: Condition;
141
+ }
142
+ interface Constraint {
143
+ id: string;
144
+ type: "DENY";
145
+ when: Condition;
146
+ message: string;
147
+ productId?: string;
148
+ optionIds?: string[];
149
+ }
150
+ interface PriceList {
151
+ id: string;
152
+ currency: string;
153
+ label?: string;
154
+ context_match?: Record<string, ScalarValue>;
155
+ }
156
+ interface Catalog {
157
+ id: string;
158
+ name?: string;
159
+ default_price_list_id?: string;
160
+ price_lists?: PriceList[];
161
+ [key: `x-${string}`]: unknown;
162
+ }
163
+ interface ProductRef {
164
+ id: string;
165
+ path: string;
166
+ }
167
+ interface Context {
168
+ price_list_id?: string;
169
+ region?: string;
170
+ channel?: string;
171
+ customer?: string;
172
+ lot_id?: string;
173
+ requested_quantity?: number;
174
+ requested_unit?: string;
175
+ [key: `x-${string}`]: unknown;
176
+ }
177
+ interface Pricing {
178
+ calculation_mode?: "CASCADE" | "TABLE_LOOKUP" | "OVERRIDE_BY_VARIANT" | "COST_PLUS";
179
+ }
180
+ interface CatalogDocument {
181
+ spec: "1.0.0";
182
+ document_type: "CATALOG";
183
+ catalog: Catalog;
184
+ rulesets: Ruleset[];
185
+ product_refs?: ProductRef[];
186
+ context?: Context;
187
+ pricing?: Pricing;
188
+ dictionaries?: Record<string, unknown>;
189
+ tables?: Table[];
190
+ dependencies?: Dependency[];
191
+ constraints?: Constraint[];
192
+ profiles?: string[];
193
+ [key: `x-${string}`]: unknown;
194
+ }
195
+ interface ProductDocument {
196
+ spec: "1.0.0";
197
+ document_type: "PRODUCT";
198
+ catalog_id: string;
199
+ product: Product;
200
+ rulesets?: Ruleset[];
201
+ tables?: Table[];
202
+ constraints?: Constraint[];
203
+ dependencies?: Dependency[];
204
+ profiles?: string[];
205
+ [key: `x-${string}`]: unknown;
206
+ }
207
+ type PacpDocument = CatalogDocument | ProductDocument;
208
+ type ProfileId = "moveis" | "iluminacao" | "pisos-revestimentos" | "fiscal-br";
209
+ interface ValidationIssue {
210
+ code: string;
211
+ path: string;
212
+ message: string;
213
+ }
214
+ interface ValidationResult {
215
+ valid: boolean;
216
+ issues: ValidationIssue[];
217
+ }
218
+
219
+ declare function validate(document: unknown): ValidationResult;
220
+
221
+ declare const SPEC_VERSION: "1.0.0";
222
+
223
+ export { type AttributeRef, type AttributeValue, type Catalog, type CatalogDocument, type Component, type Condition, type Constraint, type Context, type Dependency, type Dimension, type DimensionsObj, type ImageRef, type ImageType, type LotPolicy, type Measure, type Option, type PacpDocument, type Predicate, type PriceList, type Pricing, type Product, type ProductDocument, type ProductRef, type ProfileId, type Rule, type RuleOperation, type Ruleset, SPEC_VERSION, type SalesUnit, type ScalarValue, type Table, type TableRow, type ValidationIssue, type ValidationResult, validate };