@cloudpdf/contract 3.0.0-next.10 → 3.0.0-next.12

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/openapi.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/openapi.ts
2
- import { EngineErrorPayloadSchema as EngineErrorPayloadSchema2 } from "@embedpdf/engine-core/wire";
2
+ import { EngineErrorPayloadSchema as EngineErrorPayloadSchema2, PdfActionWireComponents } from "@embedpdf/engine-core/wire";
3
3
  import { z as z2 } from "zod";
4
- import { zodToJsonSchema } from "zod-to-json-schema";
4
+ import { ignoreOverride, zodToJsonSchema } from "zod-to-json-schema";
5
5
 
6
6
  // src/index.ts
7
7
  import {
@@ -1040,6 +1040,42 @@ var docOperations = {
1040
1040
  404: { contentType: "application/json", schema: EngineErrorPayloadSchema }
1041
1041
  }
1042
1042
  },
1043
+ "doc.annotations.flatten": {
1044
+ operationId: "doc.annotations.flatten",
1045
+ title: "Flatten annotations",
1046
+ summary: "Flatten a chosen set of one page's annotations into its content \u2014 pages.flatten for a selection. Painted annotations are removed; ineligible ones report skipped.",
1047
+ method: "POST",
1048
+ path: wireTemplates.layerAnnotationItemsFlatten,
1049
+ credentials: docCredentials,
1050
+ scope: [],
1051
+ docCapabilities: ["doc.pages.modify", "doc.annotate.modify"],
1052
+ requestHeaders: [documentPasswordHeader],
1053
+ params: DocPageParamsSchema,
1054
+ body: { contentType: "application/json", schema: looseJson },
1055
+ responses: {
1056
+ 200: { contentType: "application/json", schema: MutationResponseSchema },
1057
+ 400: { contentType: "application/json", schema: EngineErrorPayloadSchema },
1058
+ 404: { contentType: "application/json", schema: EngineErrorPayloadSchema }
1059
+ }
1060
+ },
1061
+ "doc.annotations.exportAppearance": {
1062
+ operationId: "doc.annotations.exportAppearance",
1063
+ title: "Export annotation appearances",
1064
+ summary: "The chosen annotations' appearances as one single-page PDF sized to their union rect \u2014 vector, positions preserved. A read; the source is untouched.",
1065
+ method: "POST",
1066
+ path: wireTemplates.layerAnnotationItemsAppearance,
1067
+ credentials: docCredentials,
1068
+ scope: [],
1069
+ docCapabilities: ["doc.download"],
1070
+ requestHeaders: [documentPasswordHeader],
1071
+ params: DocPageParamsSchema,
1072
+ body: { contentType: "application/json", schema: looseJson },
1073
+ responses: {
1074
+ 200: { contentType: "application/pdf" },
1075
+ 400: { contentType: "application/json", schema: EngineErrorPayloadSchema },
1076
+ 404: { contentType: "application/json", schema: EngineErrorPayloadSchema }
1077
+ }
1078
+ },
1043
1079
  "doc.forms.get": {
1044
1080
  operationId: "doc.forms.get",
1045
1081
  title: "Get form snapshot",
@@ -1179,6 +1215,42 @@ var docOperations = {
1179
1215
  404: { contentType: "application/json", schema: EngineErrorPayloadSchema }
1180
1216
  }
1181
1217
  },
1218
+ "doc.pages.setName": {
1219
+ operationId: "doc.pages.setName",
1220
+ title: "Set page name",
1221
+ summary: "Register or rename a /Names /Pages entry (a named page). A page-structure mutation: the layout version advances.",
1222
+ method: "POST",
1223
+ path: wireTemplates.layerPagesNames,
1224
+ credentials: docCredentials,
1225
+ scope: [],
1226
+ docCapabilities: ["doc.pages.assemble"],
1227
+ requestHeaders: [documentPasswordHeader],
1228
+ params: DocLayerParamsSchema,
1229
+ body: { contentType: "application/json", schema: looseJson },
1230
+ responses: {
1231
+ 200: { contentType: "application/json", schema: MutationResponseSchema },
1232
+ 400: { contentType: "application/json", schema: EngineErrorPayloadSchema },
1233
+ 404: { contentType: "application/json", schema: EngineErrorPayloadSchema }
1234
+ }
1235
+ },
1236
+ "doc.pages.removeName": {
1237
+ operationId: "doc.pages.removeName",
1238
+ title: "Remove page name",
1239
+ summary: "Remove a /Names /Pages entry; the page itself stays.",
1240
+ method: "POST",
1241
+ path: wireTemplates.layerPagesNamesDelete,
1242
+ credentials: docCredentials,
1243
+ scope: [],
1244
+ docCapabilities: ["doc.pages.assemble"],
1245
+ requestHeaders: [documentPasswordHeader],
1246
+ params: DocLayerParamsSchema,
1247
+ body: { contentType: "application/json", schema: looseJson },
1248
+ responses: {
1249
+ 200: { contentType: "application/json", schema: MutationResponseSchema },
1250
+ 400: { contentType: "application/json", schema: EngineErrorPayloadSchema },
1251
+ 404: { contentType: "application/json", schema: EngineErrorPayloadSchema }
1252
+ }
1253
+ },
1182
1254
  "doc.pages.flatten": {
1183
1255
  operationId: "doc.pages.flatten",
1184
1256
  title: "Flatten pages",
@@ -1325,11 +1397,21 @@ var SECURITY_SCHEME = {
1325
1397
  };
1326
1398
  var ADMIN_ERROR_REF = "#/components/schemas/AdminErrorPayload";
1327
1399
  var ENGINE_ERROR_REF = "#/components/schemas/EngineErrorPayload";
1400
+ var SHARED_COMPONENT_SCHEMAS = PdfActionWireComponents;
1401
+ var SHARED_COMPONENT_BY_DEFINITION = new Map(
1402
+ Object.entries(SHARED_COMPONENT_SCHEMAS).map(([name, schema]) => [schema._def, name])
1403
+ );
1404
+ var SHARED_COMPONENT_REFS = new Set(
1405
+ Object.keys(SHARED_COMPONENT_SCHEMAS).map((name) => `#/components/schemas/${name}`)
1406
+ );
1328
1407
  function buildAdminOpenApiDocument(opts) {
1329
1408
  const paths = {};
1330
1409
  const schemas = {};
1331
1410
  registerSchema(schemas, "AdminErrorPayload", AdminErrorPayloadSchema);
1332
1411
  registerSchema(schemas, "EngineErrorPayload", EngineErrorPayloadSchema2);
1412
+ for (const [name, schema] of Object.entries(SHARED_COMPONENT_SCHEMAS)) {
1413
+ registerSchema(schemas, name, schema);
1414
+ }
1333
1415
  for (const op of Object.values(allOperations)) {
1334
1416
  assertDocsGroupsCover(op);
1335
1417
  const openApiPath = toOpenApiPath(op.path);
@@ -1545,11 +1627,50 @@ function registerSchema(schemas, name, schema) {
1545
1627
  const referenced = zodToJsonSchema(schema, {
1546
1628
  target: "openApi3",
1547
1629
  $refStrategy: "root",
1548
- basePath: ["#", ...componentPath]
1630
+ basePath: ["#", ...componentPath],
1631
+ override: (definition) => {
1632
+ const sharedName = SHARED_COMPONENT_BY_DEFINITION.get(definition);
1633
+ if (!sharedName || sharedName === name) return ignoreOverride;
1634
+ return { $ref: `#/components/schemas/${sharedName}` };
1635
+ }
1549
1636
  });
1550
- schemas[name] = breakAncestorReferences(referenced, componentPath);
1637
+ const canonical = collapseSharedReferenceAliases(referenced, referenced, componentPath);
1638
+ schemas[name] = breakAncestorReferences(canonical, componentPath);
1551
1639
  return { $ref: `#/components/schemas/${name}` };
1552
1640
  }
1641
+ function collapseSharedReferenceAliases(value, component, componentPath) {
1642
+ if (Array.isArray(value)) {
1643
+ return value.map((child) => collapseSharedReferenceAliases(child, component, componentPath));
1644
+ }
1645
+ if (!value || typeof value !== "object") return value;
1646
+ const record = value;
1647
+ if (Object.keys(record).length === 1 && typeof record.$ref === "string") {
1648
+ const target = resolveComponentReference(component, record.$ref, componentPath);
1649
+ if (target && typeof target === "object" && !Array.isArray(target)) {
1650
+ const targetRecord = target;
1651
+ if (Object.keys(targetRecord).length === 1 && typeof targetRecord.$ref === "string" && SHARED_COMPONENT_REFS.has(targetRecord.$ref)) {
1652
+ return { $ref: targetRecord.$ref };
1653
+ }
1654
+ }
1655
+ }
1656
+ return Object.fromEntries(
1657
+ Object.entries(record).map(([key, child]) => [
1658
+ key,
1659
+ collapseSharedReferenceAliases(child, component, componentPath)
1660
+ ])
1661
+ );
1662
+ }
1663
+ function resolveComponentReference(component, reference, componentPath) {
1664
+ if (!reference.startsWith("#/")) return void 0;
1665
+ const target = reference.slice(2).split("/").map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
1666
+ if (target.length < componentPath.length || !componentPath.every((segment, index) => target[index] === segment)) {
1667
+ return void 0;
1668
+ }
1669
+ return target.slice(componentPath.length).reduce((current, segment) => {
1670
+ if (!current || typeof current !== "object") return void 0;
1671
+ return current[segment];
1672
+ }, component);
1673
+ }
1553
1674
  function breakAncestorReferences(value, path) {
1554
1675
  if (Array.isArray(value)) {
1555
1676
  return value.map((child, index) => breakAncestorReferences(child, [...path, String(index)]));