@oxyhq/contracts 0.4.0 → 0.5.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.
@@ -21,3 +21,5 @@ export { verificationMethodSchema, didServiceSchema, didDocumentSchema, signedRe
21
21
  export type { VerificationMethod, DidService, DidDocument, SignedRecordEnvelope, SignedRecordType, VerifiedDomain, DomainVerificationRequest, DomainVerificationInstructions, AuthMethodEntry, AuthMethodsResponse, ExportAttestation, ExportBundle, } from './identity';
22
22
  export { publicCardSchema, signedPublicCardSchema, realLifeAttestationRecordSchema, realLifeAttestationResultSchema, validationVerdictRecordSchema, validationOpenRequestSchema, validationOpenResultSchema, validationRequestSummarySchema, validationVoteResultSchema, personhoodVouchRecordSchema, personhoodBreakdownSchema, personhoodStatusResultSchema, vouchResultSchema, credentialRecordSchema, verifiableCredentialResponseSchema, credentialIssueResultSchema, credentialListResultSchema, credentialVerifyResultSchema, } from './civic';
23
23
  export type { CardTrustTier, PersonhoodStatus, PublicCard, SignedPublicCard, RealLifeAttestationRecord, RealLifeAttestationResult, ValidationVerdict, ValidationRequestStatus, ValidationVerdictRecord, ValidationOpenRequest, ValidationOpenResult, ValidationRequestSummary, ValidationVoteResult, PersonhoodVouchRecord, PersonhoodBreakdown, PersonhoodStatusResult, VouchResult, CredentialStatus, CredentialRecord, VerifiableCredentialResponse, CredentialIssueResult, CredentialListResult, CredentialVerifyResult, } from './civic';
24
+ export { linkPreviewSchema, linkPreviewBatchRequestSchema, linkPreviewBatchResponseSchema, linkPreviewResponseSchema, } from './links';
25
+ export type { LinkPreviewStatus, LinkPreview, LinkPreviewBatchRequest, LinkPreviewBatchResponse, } from './links';
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Link-preview / unfurl API contracts.
3
+ *
4
+ * SINGLE SOURCE OF TRUTH for the wire shape of Oxy's link-preview ("unfurl")
5
+ * resolution surface: the single `GET` lookup and the `POST` batch lookup that
6
+ * every app calls through the SDK so apps stop duplicating their own
7
+ * link-metadata fetching. The API validates its OUTPUT against these schemas;
8
+ * every consumer (`@oxyhq/core`'s link mixin and the apps that call it)
9
+ * validates its INPUT against the same definitions, so producer and consumers
10
+ * cannot drift.
11
+ *
12
+ * Design anchors:
13
+ * - Oxy owns resolution. The `image` (and `favicon`) URLs a preview carries are
14
+ * re-hosted on Oxy media (`cloud.oxy.so/<fileId>`), never raw remote URLs —
15
+ * apps render them directly with no per-app proxy.
16
+ * - Resolution is best-effort and asynchronous. A preview is `'resolved'` once
17
+ * metadata is materialised, `'pending'` while a first-seen URL is being
18
+ * fetched in the background, or `'empty'` when the target yielded no usable
19
+ * metadata. `resolvedAt` (ISO datetime) is present only once `'resolved'`.
20
+ * - The batch response is keyed by the REQUESTED url (the exact string the
21
+ * caller sent), not the canonical/final URL, so a caller can always look its
22
+ * own input back up; the canonical URL lives on `LinkPreview.url`.
23
+ *
24
+ * The `LinkPreview` / `LinkPreviewBatchResponse` exports are declared as explicit
25
+ * `interface`s (with their runtime schemas annotated `z.ZodType<Interface>`),
26
+ * following the same rationale as `UserNameResponse` in `./userResponse`: a
27
+ * `z.infer<>` of a nested-object schema can degrade to `{}` under a consumer's
28
+ * `moduleResolution: "node"` (node10) resolution. A literal interface emits the
29
+ * field types verbatim in the `.d.ts` and survives BOTH `node` and `bundler`
30
+ * resolution. The flat batch-request schema (no nested-object hazard) is inferred
31
+ * via `z.infer<>`.
32
+ *
33
+ * Platform-agnostic — zod only, no react/react-native/expo. ESM-safe (no
34
+ * `require()`).
35
+ */
36
+ import { z } from 'zod';
37
+ /**
38
+ * Resolution state of a {@link LinkPreview}.
39
+ *
40
+ * - `resolved` — metadata materialised; `resolvedAt` is present.
41
+ * - `pending` — a first-seen URL is being fetched in the background; metadata
42
+ * fields and `resolvedAt` may be absent. The caller may re-fetch shortly.
43
+ * - `empty` — the target yielded no usable metadata (e.g. a bare binary, a
44
+ * 404, or an opted-out host); the negative result is cached.
45
+ */
46
+ export type LinkPreviewStatus = 'resolved' | 'pending' | 'empty';
47
+ /**
48
+ * A single resolved (or in-flight) link preview.
49
+ *
50
+ * `url` is the canonical / final resolved URL (after redirects). The optional
51
+ * metadata fields are present on a best-effort basis once `status` is
52
+ * `'resolved'`. `image` and `favicon` are absolute Oxy-hosted
53
+ * (`cloud.oxy.so/<fileId>`) URLs — render them directly, never proxy them.
54
+ */
55
+ export interface LinkPreview {
56
+ /** Canonical / final resolved URL (after following redirects). */
57
+ url: string;
58
+ status: LinkPreviewStatus;
59
+ title?: string;
60
+ description?: string;
61
+ /** Absolute Oxy-hosted (`cloud.oxy.so`) image URL. */
62
+ image?: string;
63
+ siteName?: string;
64
+ /** Absolute Oxy-hosted (`cloud.oxy.so`) favicon URL. */
65
+ favicon?: string;
66
+ /** ISO 8601 datetime of resolution; absent while `status` is `'pending'`. */
67
+ resolvedAt?: string;
68
+ }
69
+ export declare const linkPreviewSchema: z.ZodType<LinkPreview>;
70
+ /**
71
+ * Request body for the batch unfurl endpoint. Between 1 and 50 URLs per call;
72
+ * the server resolves each (returning a `'pending'` placeholder for any URL it
73
+ * has not seen before and is fetching in the background).
74
+ */
75
+ export declare const linkPreviewBatchRequestSchema: z.ZodObject<{
76
+ urls: z.ZodArray<z.ZodString, "many">;
77
+ }, "strip", z.ZodTypeAny, {
78
+ urls: string[];
79
+ }, {
80
+ urls: string[];
81
+ }>;
82
+ export type LinkPreviewBatchRequest = z.infer<typeof linkPreviewBatchRequestSchema>;
83
+ /**
84
+ * Batch unfurl response. `data` is keyed by the REQUESTED url (the exact string
85
+ * the caller sent in `urls`), so a caller can always look its own input back up;
86
+ * the canonical/final URL is on each {@link LinkPreview}'s `url` field.
87
+ */
88
+ export interface LinkPreviewBatchResponse {
89
+ data: Record<string, LinkPreview>;
90
+ }
91
+ export declare const linkPreviewBatchResponseSchema: z.ZodType<LinkPreviewBatchResponse>;
92
+ /**
93
+ * Wire shape of the single-URL unfurl lookup (`GET`) — a bare
94
+ * {@link LinkPreview}.
95
+ */
96
+ export declare const linkPreviewResponseSchema: z.ZodType<LinkPreview, z.ZodTypeDef, LinkPreview>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/contracts",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "OxyHQ API contracts — single source of truth for request/response Zod schemas and inferred types, shared by the backend and the client SDKs",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",