@oxy.so/contracts 4.2.0 → 4.3.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 +1 -0
- package/dist/cjs/stickers.js +151 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/stickers.js +148 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stickers.d.ts +1049 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stickers — the wire shape of Oxy's shared sticker catalogue.
|
|
3
|
+
*
|
|
4
|
+
* One catalogue serves every app: Allo sends a sticker in a chat, Mention draws
|
|
5
|
+
* one in an empty state, and both resolve the same id to the same animation.
|
|
6
|
+
* The API validates its output against these schemas and `@oxy.so/stickers`
|
|
7
|
+
* validates its input against the same ones.
|
|
8
|
+
*
|
|
9
|
+
* A sticker is a Lottie animation plus a static fallback image, both served
|
|
10
|
+
* from Oxy's CDN at content-addressed, immutable URLs. The fallback is what a
|
|
11
|
+
* surface that cannot animate shows — a push notification, a federated copy of
|
|
12
|
+
* a post, a person who asked for reduced motion.
|
|
13
|
+
*
|
|
14
|
+
* Platform-agnostic — zod only. ESM-safe (no `require()`).
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
/* -------------------------------------------------------------------------- */
|
|
18
|
+
/* Limits */
|
|
19
|
+
/* -------------------------------------------------------------------------- */
|
|
20
|
+
/**
|
|
21
|
+
* The square canvases a sticker may be authored at. Lottie is vectors, so the
|
|
22
|
+
* canvas is a coordinate space rather than a resolution: a 1024 file draws as
|
|
23
|
+
* sharply in a 128-point bubble as a 512 one.
|
|
24
|
+
*/
|
|
25
|
+
export const STICKER_CANVAS_SIZES = [512, 1024];
|
|
26
|
+
/** Size of the static fallback image every sticker gets. */
|
|
27
|
+
export const STICKER_FALLBACK_SIZE = 512;
|
|
28
|
+
/** Longest loop a sticker may have. */
|
|
29
|
+
export const STICKER_MAX_DURATION_MS = 10000;
|
|
30
|
+
/** Highest frame rate a sticker may declare. */
|
|
31
|
+
export const STICKER_MAX_FRAME_RATE = 60;
|
|
32
|
+
/**
|
|
33
|
+
* Largest Lottie JSON accepted on upload, before the API normalizes it.
|
|
34
|
+
* Exported animations carry pretty-printing and full float precision, so the
|
|
35
|
+
* raw file is routinely many times the size of what is stored.
|
|
36
|
+
*/
|
|
37
|
+
export const STICKER_MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
|
|
38
|
+
/**
|
|
39
|
+
* Largest animation STORED, after normalization (minified, floats rounded,
|
|
40
|
+
* expressions removed). The CDN compresses JSON in transit, which takes a
|
|
41
|
+
* typical sticker to a few tens of kilobytes on the wire.
|
|
42
|
+
*/
|
|
43
|
+
export const STICKER_MAX_ANIMATION_BYTES = 1024 * 1024;
|
|
44
|
+
/** Largest static fallback accepted on upload, when one is supplied. */
|
|
45
|
+
export const STICKER_MAX_FALLBACK_BYTES = 256 * 1024;
|
|
46
|
+
/** How many stickers one pack may hold. */
|
|
47
|
+
export const STICKER_PACK_MAX_STICKERS = 120;
|
|
48
|
+
/** How many packs one person may have installed. */
|
|
49
|
+
export const STICKER_MAX_INSTALLED_PACKS = 200;
|
|
50
|
+
/** How many ids one resolve call may ask about. */
|
|
51
|
+
export const STICKER_RESOLVE_MAX_IDS = 100;
|
|
52
|
+
/* -------------------------------------------------------------------------- */
|
|
53
|
+
/* Primitives */
|
|
54
|
+
/* -------------------------------------------------------------------------- */
|
|
55
|
+
/** Lowercase-hex SHA-256 of a file's bytes. */
|
|
56
|
+
export const stickerSha256Schema = z
|
|
57
|
+
.string()
|
|
58
|
+
.regex(/^[a-f0-9]{64}$/, 'sha256 must be 64 lowercase hex characters');
|
|
59
|
+
/** A pack's public URL segment. */
|
|
60
|
+
export const stickerPackSlugSchema = z
|
|
61
|
+
.string()
|
|
62
|
+
.min(2)
|
|
63
|
+
.max(64)
|
|
64
|
+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'slug must be lowercase words joined by hyphens');
|
|
65
|
+
export const stickerIdSchema = z.string().min(1).max(64);
|
|
66
|
+
export const stickerPackStatusSchema = z.enum(['draft', 'published', 'archived']);
|
|
67
|
+
/** One stored file: where to fetch it and the hash its bytes must have. */
|
|
68
|
+
export const stickerFileSchema = z.object({
|
|
69
|
+
url: z.string().url(),
|
|
70
|
+
sha256: stickerSha256Schema,
|
|
71
|
+
mime: z.string(),
|
|
72
|
+
bytes: z.number().int().nonnegative(),
|
|
73
|
+
});
|
|
74
|
+
/* -------------------------------------------------------------------------- */
|
|
75
|
+
/* Catalogue */
|
|
76
|
+
/* -------------------------------------------------------------------------- */
|
|
77
|
+
export const stickerSchema = z.object({
|
|
78
|
+
id: stickerIdSchema,
|
|
79
|
+
packId: z.string(),
|
|
80
|
+
emoji: z.array(z.string()).min(1),
|
|
81
|
+
keywords: z.array(z.string()),
|
|
82
|
+
size: z.number().int().positive(),
|
|
83
|
+
durationMs: z.number().int().positive(),
|
|
84
|
+
/** The Lottie JSON. */
|
|
85
|
+
animation: stickerFileSchema,
|
|
86
|
+
/** A static image of the same sticker. */
|
|
87
|
+
fallback: stickerFileSchema,
|
|
88
|
+
});
|
|
89
|
+
/** What a shop card needs. */
|
|
90
|
+
export const stickerPackSummarySchema = z.object({
|
|
91
|
+
id: z.string(),
|
|
92
|
+
slug: stickerPackSlugSchema,
|
|
93
|
+
title: z.string(),
|
|
94
|
+
description: z.string().nullable(),
|
|
95
|
+
author: z.string().nullable(),
|
|
96
|
+
status: stickerPackStatusSchema,
|
|
97
|
+
publishedAt: z.string().nullable(),
|
|
98
|
+
stickerCount: z.number().int().nonnegative(),
|
|
99
|
+
/** The first sticker, drawn as the pack's cover. Null for an empty draft. */
|
|
100
|
+
cover: stickerSchema.nullable(),
|
|
101
|
+
});
|
|
102
|
+
export const stickerPackSchema = stickerPackSummarySchema.extend({
|
|
103
|
+
stickers: z.array(stickerSchema),
|
|
104
|
+
});
|
|
105
|
+
/** A pack in someone's picker. */
|
|
106
|
+
export const installedStickerPackSchema = stickerPackSchema.extend({
|
|
107
|
+
installedAt: z.string(),
|
|
108
|
+
});
|
|
109
|
+
/* -------------------------------------------------------------------------- */
|
|
110
|
+
/* References */
|
|
111
|
+
/* -------------------------------------------------------------------------- */
|
|
112
|
+
/**
|
|
113
|
+
* How an app stores or sends a sticker: its id, the pack it came from, and the
|
|
114
|
+
* hash of the animation it showed. The hash lets a receiver verify the bytes it
|
|
115
|
+
* fetched are the ones the sender saw — which matters in an end-to-end
|
|
116
|
+
* encrypted chat, where the server relaying the message never sees it.
|
|
117
|
+
*/
|
|
118
|
+
export const stickerRefSchema = z.object({
|
|
119
|
+
stickerId: stickerIdSchema,
|
|
120
|
+
packId: z.string().min(1).max(64),
|
|
121
|
+
sha256: stickerSha256Schema,
|
|
122
|
+
});
|
|
123
|
+
/* -------------------------------------------------------------------------- */
|
|
124
|
+
/* Requests */
|
|
125
|
+
/* -------------------------------------------------------------------------- */
|
|
126
|
+
/** POST /stickers/resolve */
|
|
127
|
+
export const resolveStickersRequestSchema = z.object({
|
|
128
|
+
ids: z.array(stickerIdSchema).min(1).max(STICKER_RESOLVE_MAX_IDS),
|
|
129
|
+
});
|
|
130
|
+
/** Unknown ids are absent, not errors: a caller checks what came back. */
|
|
131
|
+
export const resolveStickersResponseSchema = z.object({
|
|
132
|
+
stickers: z.array(stickerSchema),
|
|
133
|
+
});
|
|
134
|
+
/** PATCH /stickers/me/packs/order — the installed pack ids, first to last. */
|
|
135
|
+
export const reorderStickerPacksRequestSchema = z.object({
|
|
136
|
+
packIds: z.array(z.string().min(1).max(64)).max(STICKER_MAX_INSTALLED_PACKS),
|
|
137
|
+
});
|
|
138
|
+
/** POST /stickers/admin/packs */
|
|
139
|
+
export const createStickerPackRequestSchema = z.object({
|
|
140
|
+
slug: stickerPackSlugSchema,
|
|
141
|
+
title: z.string().trim().min(1).max(64),
|
|
142
|
+
description: z.string().trim().max(500).nullish(),
|
|
143
|
+
author: z.string().trim().max(64).nullish(),
|
|
144
|
+
});
|
|
145
|
+
/** PATCH /stickers/admin/packs/:packId */
|
|
146
|
+
export const updateStickerPackRequestSchema = createStickerPackRequestSchema
|
|
147
|
+
.omit({ slug: true })
|
|
148
|
+
.partial();
|