@cloudpdf/contract 3.0.0-next.5 → 3.0.0-next.7

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,10 +1,9 @@
1
1
  // src/openapi.ts
2
- import { zodToJsonSchema } from "zod-to-json-schema";
3
- import { z as z2 } from "zod";
4
2
  import { EngineErrorPayloadSchema as EngineErrorPayloadSchema2 } from "@embedpdf/engine-core/wire";
3
+ import { z as z2 } from "zod";
4
+ import { zodToJsonSchema } from "zod-to-json-schema";
5
5
 
6
6
  // src/index.ts
7
- import { z } from "zod";
8
7
  import {
9
8
  AnnotationListPageSnapshotSchema,
10
9
  DocumentHeadSchema,
@@ -16,6 +15,7 @@ import {
16
15
  PageTextSnapshotSchema,
17
16
  wireTemplates
18
17
  } from "@embedpdf/engine-core/wire";
18
+ import { z } from "zod";
19
19
  var sha256Hex = /^[0-9a-f]{64}$/i;
20
20
  var docIdPattern = /^[A-Za-z0-9_-]+$/;
21
21
  var tenantIdPattern = /^[A-Za-z0-9_-]+$/;
@@ -32,6 +32,7 @@ var adminWirePaths = {
32
32
  tenant: (tenantId) => `/v1/tenants/${encodeURIComponent(tenantId)}`,
33
33
  documents: (tenantId) => `/v1/tenants/${encodeURIComponent(tenantId)}/documents`,
34
34
  documentsInit: (tenantId) => `/v1/tenants/${encodeURIComponent(tenantId)}/documents/init`,
35
+ documentsImport: (tenantId) => `/v1/tenants/${encodeURIComponent(tenantId)}/documents/import`,
35
36
  document: (tenantId, docId) => `/v1/tenants/${encodeURIComponent(tenantId)}/documents/${encodeURIComponent(docId)}`,
36
37
  documentCommit: (tenantId, docId) => `/v1/tenants/${encodeURIComponent(tenantId)}/documents/${encodeURIComponent(docId)}/commit`,
37
38
  documentUploadProxy: (tenantId, docId) => `/v1/tenants/${encodeURIComponent(tenantId)}/documents/${encodeURIComponent(docId)}/upload-proxy`,
@@ -54,7 +55,9 @@ var adminWirePaths = {
54
55
  /** Deployment-global singletons: API-token only, no tenant context. */
55
56
  deploymentLicenseStatus: "/v1/deployment/license/status"
56
57
  };
57
- var DedupModeSchema = z.enum(["always-create", "reuse-existing"]);
58
+ var DedupModeSchema = z.enum(["always-create", "reuse-existing"]).describe(
59
+ "always-create (default) creates a new document every time. reuse-existing returns a document that already holds the same content instead of storing it twice."
60
+ );
58
61
  var UploadPreferenceSchema = z.enum(["auto", "presigned", "proxy"]);
59
62
  var DocumentStateSchema = z.enum(["pending", "ready", "failed", "deleting"]);
60
63
  var AdminDocumentRecordSchema = z.object({
@@ -123,6 +126,79 @@ var AdminDocumentCommitRequestSchema = z.object({
123
126
  var AdminDocumentCommitResponseSchema = z.object({
124
127
  document: AdminDocumentRecordSchema
125
128
  });
129
+ var utf8ByteLength = (s) => new TextEncoder().encode(s).length;
130
+ var AdminImportSourceSchema = z.discriminatedUnion("kind", [
131
+ z.object({
132
+ kind: z.literal("url"),
133
+ url: z.string().url().max(8192).describe(
134
+ "The URL to fetch. Must be allowed by the deployment import policy (scheme, network range, size) and must declare a length."
135
+ )
136
+ }).describe(
137
+ "The caller supplies the authority: a presigned S3/GCS/Azure/R2/MinIO GET, or any HTTPS endpoint the deployment import policy allows. The URL is a capability \u2014 treat it as a secret. CloudPDF never echoes its query string back in errors, logs, or stored failure reasons."
138
+ ),
139
+ z.object({
140
+ kind: z.literal("connection"),
141
+ connectionId: z.string().min(1).max(128).describe("The operator-registered storage connection to read from."),
142
+ key: z.string().min(1).refine((k) => !k.includes("\0"), "key must not contain NUL").refine((k) => utf8ByteLength(k) <= 1024, "key must be at most 1024 UTF-8 bytes").describe(
143
+ "The object key to read, inside the connection's configured scope. At most 1024 UTF-8 bytes."
144
+ ),
145
+ revision: z.string().min(1).max(1024).optional().describe(
146
+ "Pins a specific version of the object. Provider-interpreted (S3 VersionId, GCS generation, Azure version id); providers without versioning reject it."
147
+ )
148
+ }).describe(
149
+ "The operator pre-registered the authority: the request names a connection and a key inside it. Which provider backs the connection (S3, GCS, Azure Blob, filesystem, ...) is deployment configuration, never wire surface."
150
+ )
151
+ ]).describe(
152
+ "Where CloudPDF pulls the bytes from. The two shapes differ in WHO supplies the authority to read, not in which storage vendor holds the file."
153
+ );
154
+ var AdminDocumentImportRequestSchema = z.object({
155
+ source: AdminImportSourceSchema,
156
+ /**
157
+ * Optional integrity pins, enforced when present: `sizeBytes`
158
+ * against the source's declared Content-Length before the transfer,
159
+ * `sha256` against the server-observed digest after it. When absent
160
+ * the server-observed values become authoritative.
161
+ * `dedupMode=reuse-existing` REQUIRES `sha256` — without a declared
162
+ * hash the server cannot know what content to reuse.
163
+ */
164
+ expected: z.object({
165
+ sizeBytes: z.number().int().min(1).optional().describe("Checked against the source's declared Content-Length before the transfer."),
166
+ sha256: z.string().regex(sha256Hex).optional().describe(
167
+ "Checked against the server-observed digest after the transfer. Required when dedupMode is reuse-existing."
168
+ )
169
+ }).optional().describe(
170
+ "Integrity pins, enforced when present. When absent, the server-observed values become authoritative."
171
+ ),
172
+ metadata: z.record(z.string(), z.unknown()).optional(),
173
+ idempotencyKey: z.string().optional().describe(
174
+ "Retrying with the same key resumes the same document rather than importing a second copy \u2014 including after a 502."
175
+ ),
176
+ dedupMode: DedupModeSchema.optional(),
177
+ docId: z.string().regex(docIdPattern).optional(),
178
+ /**
179
+ * `sync` (default) holds the response open for the whole transfer.
180
+ * `async` accepts the request (202, document `pending`), transfers
181
+ * in the background, and the caller polls the document. Async
182
+ * requires a `connection` source (URLs are secrets and expire, so
183
+ * they cannot sit in a durable job); filesystem connections
184
+ * additionally require `expected.sha256`, since they have no
185
+ * revisions to pin retries to.
186
+ */
187
+ mode: z.enum(["sync", "async"]).optional().describe(
188
+ "sync (default) holds the response open for the whole transfer. async answers 202 with the document pending and transfers in the background; it requires a connection source, and filesystem connections additionally require expected.sha256."
189
+ )
190
+ });
191
+ var AdminDocumentImportResponseSchema = z.object({
192
+ /**
193
+ * `imported` — bytes were pulled, verified, and committed (sync).
194
+ * `deduped` — an existing document satisfied the request without a
195
+ * transfer (content dedup or idempotent replay).
196
+ * `accepted` — async: the job is queued (HTTP 202); poll the
197
+ * document until `ready` or `failed`.
198
+ */
199
+ tag: z.enum(["imported", "deduped", "accepted"]),
200
+ document: AdminDocumentRecordSchema
201
+ });
126
202
  var AdminDocumentResponseSchema = z.object({
127
203
  document: AdminDocumentRecordSchema
128
204
  });
@@ -480,6 +556,25 @@ var adminOperations = {
480
556
  },
481
557
  notes: "This bounded origin-mediated fallback must only be used after documents.init returns upload.kind=proxy. Auto mode prefers a presigned object-store PUT whenever available."
482
558
  },
559
+ "documents.importFrom": {
560
+ operationId: "documents.importFrom",
561
+ title: "Import document",
562
+ summary: "Server-side pull: fetch a PDF from a caller-supplied URL (e.g. a presigned object-store GET) or an operator-registered storage connection into CloudPDF-owned storage, verify it, and commit it.",
563
+ method: "POST",
564
+ path: "/v1/tenants/:tenantId/documents/import",
565
+ credentials: ["api-token", "tenant-jwt"],
566
+ scope: ["docs.create"],
567
+ params: AdminTenantParamsSchema,
568
+ body: { contentType: "application/json", schema: AdminDocumentImportRequestSchema },
569
+ responses: {
570
+ 200: { contentType: "application/json", schema: AdminDocumentImportResponseSchema },
571
+ 202: { contentType: "application/json", schema: AdminDocumentImportResponseSchema },
572
+ 400: { contentType: "application/json", schema: AdminErrorPayloadSchema },
573
+ 403: { contentType: "application/json", schema: AdminErrorPayloadSchema },
574
+ 502: { contentType: "application/json", schema: AdminErrorPayloadSchema }
575
+ },
576
+ notes: "Default mode is synchronous and bounded: the response returns only after the transfer verified and committed (or failed). mode=async (connection sources only) answers 202 immediately and an in-process worker performs the transfer with leased, fenced retries; poll the document until ready/failed. The deployment import policy gates scheme, network range, and size; sources must declare a length. CloudPDF copies and owns the bytes \u2014 the source is never referenced in place. A 502 marks a retryable upstream failure: retry with the same idempotencyKey to resume the same document. URL sources are capabilities and never echoed back. Connection sources name operator-registered storage (bucket/prefix scope, allowed credential classes, and tenant bindings are deployment configuration); `revision` is provider-interpreted (S3 VersionId, GCS generation, Azure version id)."
577
+ },
483
578
  "documents.list": {
484
579
  operationId: "documents.list",
485
580
  title: "List documents",
@@ -1231,12 +1326,54 @@ function operationObject(op, schemas) {
1231
1326
  };
1232
1327
  return out;
1233
1328
  }
1329
+ var RESERVED_SDK_SEGMENTS = [
1330
+ [
1331
+ "Java",
1332
+ /* @__PURE__ */ new Set([
1333
+ ...["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class"],
1334
+ ...["const", "continue", "default", "do", "double", "else", "enum", "extends", "final"],
1335
+ ...["finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int"],
1336
+ ...["interface", "long", "native", "new", "package", "private", "protected", "public"],
1337
+ ...["return", "short", "static", "strictfp", "super", "switch", "synchronized", "this"],
1338
+ ...["throw", "throws", "transient", "try", "void", "volatile", "while"],
1339
+ ...["true", "false", "null"]
1340
+ ])
1341
+ ],
1342
+ [
1343
+ "Python",
1344
+ /* @__PURE__ */ new Set([
1345
+ ...["False", "None", "True", "and", "as", "assert", "async", "await", "break", "class"],
1346
+ ...["continue", "def", "del", "elif", "else", "except", "finally", "for", "from"],
1347
+ ...["global", "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass"],
1348
+ ...["raise", "return", "try", "while", "with", "yield"]
1349
+ ])
1350
+ ],
1351
+ [
1352
+ "Ruby",
1353
+ /* @__PURE__ */ new Set([
1354
+ ...["alias", "and", "begin", "break", "case", "class", "def", "do", "else", "elsif"],
1355
+ ...["end", "ensure", "false", "for", "if", "in", "module", "next", "nil", "not", "or"],
1356
+ ...["redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef"],
1357
+ ...["unless", "until", "when", "while", "yield"]
1358
+ ])
1359
+ ]
1360
+ ];
1234
1361
  function sdkOperationName(operationId) {
1235
1362
  const parts = operationId.split(".");
1236
1363
  const method = parts.pop();
1237
1364
  if (!method || parts.length === 0) {
1238
1365
  throw new Error(`Operation ID must use resource.method form: ${operationId}`);
1239
1366
  }
1367
+ for (const segment of [...parts, method]) {
1368
+ const collisions = RESERVED_SDK_SEGMENTS.filter(([, words]) => words.has(segment)).map(
1369
+ ([language]) => language
1370
+ );
1371
+ if (collisions.length > 0) {
1372
+ throw new Error(
1373
+ `Operation "${operationId}" cannot use "${segment}" as an SDK name segment: it is a reserved word in ${collisions.join(" and ")}, so SDK generators would rename or reject it. Pick a compound name instead (e.g. importFrom rather than import).`
1374
+ );
1375
+ }
1376
+ }
1240
1377
  return { groups: parts, method };
1241
1378
  }
1242
1379
  function headerParameters(op) {
@@ -1376,6 +1513,7 @@ function sortKeys(obj) {
1376
1513
  return Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
1377
1514
  }
1378
1515
  export {
1379
- buildAdminOpenApiDocument
1516
+ buildAdminOpenApiDocument,
1517
+ sdkOperationName
1380
1518
  };
1381
1519
  //# sourceMappingURL=openapi.js.map