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