@oxyhq/contracts 0.4.0 → 0.6.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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/links.js +68 -0
- package/dist/cjs/userResponse.js +5 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/links.js +65 -0
- package/dist/esm/userResponse.js +5 -3
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/links.d.ts +96 -0
- package/dist/types/userResponse.d.ts +11 -6
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -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>;
|
|
@@ -37,7 +37,10 @@ import { z } from 'zod';
|
|
|
37
37
|
* - `first` / `last` default to `''` in Mongo, so they are optional on the wire.
|
|
38
38
|
* - `full` is a Mongoose virtual — absent unless the query materialised
|
|
39
39
|
* virtuals or the serializer composed it.
|
|
40
|
-
* - `displayName` is the
|
|
40
|
+
* - `displayName` is the canonical app-facing display string when present.
|
|
41
|
+
* It is OPTIONAL on the wire: the API still synthesizes a default today, but
|
|
42
|
+
* the contract no longer guarantees it, so consumers fall back to a handle
|
|
43
|
+
* (e.g. `getNormalizedUserHandle`) when it is absent.
|
|
41
44
|
*
|
|
42
45
|
* This is declared as an explicit `interface` rather than being inferred from
|
|
43
46
|
* the runtime schema via `z.infer<typeof userNameSchema>`. Inferring it produced
|
|
@@ -47,7 +50,7 @@ import { z } from 'zod';
|
|
|
47
50
|
* Under a consumer's `moduleResolution: "node"` (node10), that chain does not
|
|
48
51
|
* always resolve, so `name.displayName` silently widened to `{}` and broke the
|
|
49
52
|
* "render `name.displayName` directly" contract at the type level. An explicit
|
|
50
|
-
* interface emits `displayName
|
|
53
|
+
* interface emits `displayName?: string` literally and survives BOTH `node` and
|
|
51
54
|
* `bundler` resolution. The index signature preserves the passthrough behaviour
|
|
52
55
|
* (additive name fields are tolerated without a coordinated contract bump).
|
|
53
56
|
*/
|
|
@@ -55,16 +58,18 @@ export interface UserNameResponse {
|
|
|
55
58
|
first?: string;
|
|
56
59
|
last?: string;
|
|
57
60
|
full?: string;
|
|
58
|
-
/**
|
|
59
|
-
displayName
|
|
61
|
+
/** Canonical display string when present — render this directly. */
|
|
62
|
+
displayName?: string;
|
|
60
63
|
[key: string]: unknown;
|
|
61
64
|
}
|
|
62
65
|
export declare const userNameSchema: z.ZodType<UserNameResponse>;
|
|
63
66
|
/**
|
|
64
67
|
* The canonical user object emitted by `formatUserResponse`.
|
|
65
68
|
*
|
|
66
|
-
* `id`
|
|
67
|
-
*
|
|
69
|
+
* `id` is present on formatted user DTOs. `name.displayName` is OPTIONAL on the
|
|
70
|
+
* contract — the API still synthesizes a default today, but consumers must not
|
|
71
|
+
* assume it is present and should fall back to a handle when it is absent. The
|
|
72
|
+
* rest is forwarded from the user document and may be absent depending on the query's
|
|
68
73
|
* `.select(...)`/`.lean()` projection. Both `id` and `_id` are accepted because
|
|
69
74
|
* some raw-document responses carry `_id` instead of `id`; resolve the
|
|
70
75
|
* identifier with {@link resolveUserId}.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxyhq/contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|