@singi-labs/sifa-sdk 0.9.11 → 0.9.13

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.
@@ -0,0 +1,253 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Zod schemas mirroring the canonical Standard.site lexicons that Sifa
5
+ * consumes when rendering publication embeds.
6
+ *
7
+ * Canonical lexicons live at:
8
+ * DID: did:plc:re3ebnp5v7ffagz6rb6xfei4
9
+ * PDS: https://auriporia.us-west.host.bsky.network
10
+ * Collection: com.atproto.lexicon.schema
11
+ *
12
+ * Sifa does NOT own these lexicons; we vendor the validation shapes so
13
+ * clients can parse augmented embeds and (in Phase 4) write subscription
14
+ * records to viewers' PDSes. Re-check against the canonical PDS on each
15
+ * SDK release to detect schema drift.
16
+ */
17
+ declare const rgbColorSchema: z.ZodObject<{
18
+ r: z.ZodNumber;
19
+ g: z.ZodNumber;
20
+ b: z.ZodNumber;
21
+ }, z.core.$strip>;
22
+ type RgbColor = z.infer<typeof rgbColorSchema>;
23
+ /** site.standard.theme.basic */
24
+ declare const BasicThemeSchema: z.ZodObject<{
25
+ background: z.ZodObject<{
26
+ r: z.ZodNumber;
27
+ g: z.ZodNumber;
28
+ b: z.ZodNumber;
29
+ }, z.core.$strip>;
30
+ foreground: z.ZodObject<{
31
+ r: z.ZodNumber;
32
+ g: z.ZodNumber;
33
+ b: z.ZodNumber;
34
+ }, z.core.$strip>;
35
+ accent: z.ZodObject<{
36
+ r: z.ZodNumber;
37
+ g: z.ZodNumber;
38
+ b: z.ZodNumber;
39
+ }, z.core.$strip>;
40
+ accentForeground: z.ZodObject<{
41
+ r: z.ZodNumber;
42
+ g: z.ZodNumber;
43
+ b: z.ZodNumber;
44
+ }, z.core.$strip>;
45
+ }, z.core.$strip>;
46
+ type BasicTheme = z.infer<typeof BasicThemeSchema>;
47
+ /** site.standard.publication */
48
+ declare const StandardSitePublicationRecordSchema: z.ZodObject<{
49
+ url: z.ZodString;
50
+ name: z.ZodString;
51
+ description: z.ZodOptional<z.ZodString>;
52
+ icon: z.ZodOptional<z.ZodObject<{
53
+ $type: z.ZodOptional<z.ZodString>;
54
+ ref: z.ZodUnknown;
55
+ mimeType: z.ZodOptional<z.ZodString>;
56
+ size: z.ZodOptional<z.ZodNumber>;
57
+ }, z.core.$loose>>;
58
+ basicTheme: z.ZodOptional<z.ZodObject<{
59
+ background: z.ZodObject<{
60
+ r: z.ZodNumber;
61
+ g: z.ZodNumber;
62
+ b: z.ZodNumber;
63
+ }, z.core.$strip>;
64
+ foreground: z.ZodObject<{
65
+ r: z.ZodNumber;
66
+ g: z.ZodNumber;
67
+ b: z.ZodNumber;
68
+ }, z.core.$strip>;
69
+ accent: z.ZodObject<{
70
+ r: z.ZodNumber;
71
+ g: z.ZodNumber;
72
+ b: z.ZodNumber;
73
+ }, z.core.$strip>;
74
+ accentForeground: z.ZodObject<{
75
+ r: z.ZodNumber;
76
+ g: z.ZodNumber;
77
+ b: z.ZodNumber;
78
+ }, z.core.$strip>;
79
+ }, z.core.$strip>>;
80
+ labels: z.ZodOptional<z.ZodObject<{
81
+ $type: z.ZodOptional<z.ZodLiteral<"com.atproto.label.defs#selfLabels">>;
82
+ values: z.ZodArray<z.ZodObject<{
83
+ val: z.ZodString;
84
+ }, z.core.$strip>>;
85
+ }, z.core.$strip>>;
86
+ preferences: z.ZodOptional<z.ZodObject<{
87
+ showInDiscover: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
88
+ }, z.core.$strip>>;
89
+ }, z.core.$loose>;
90
+ type StandardSitePublicationRecord = z.infer<typeof StandardSitePublicationRecordSchema>;
91
+ /** site.standard.document */
92
+ declare const StandardSiteDocumentRecordSchema: z.ZodObject<{
93
+ site: z.ZodString;
94
+ title: z.ZodString;
95
+ path: z.ZodOptional<z.ZodString>;
96
+ publishedAt: z.ZodString;
97
+ updatedAt: z.ZodOptional<z.ZodString>;
98
+ description: z.ZodOptional<z.ZodString>;
99
+ textContent: z.ZodOptional<z.ZodString>;
100
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
101
+ coverImage: z.ZodOptional<z.ZodObject<{
102
+ $type: z.ZodOptional<z.ZodString>;
103
+ ref: z.ZodUnknown;
104
+ mimeType: z.ZodOptional<z.ZodString>;
105
+ size: z.ZodOptional<z.ZodNumber>;
106
+ }, z.core.$loose>>;
107
+ contributors: z.ZodOptional<z.ZodArray<z.ZodObject<{
108
+ did: z.ZodString;
109
+ role: z.ZodOptional<z.ZodString>;
110
+ displayName: z.ZodOptional<z.ZodString>;
111
+ }, z.core.$loose>>>;
112
+ bskyPostRef: z.ZodOptional<z.ZodObject<{
113
+ uri: z.ZodString;
114
+ cid: z.ZodString;
115
+ }, z.core.$strip>>;
116
+ labels: z.ZodOptional<z.ZodObject<{
117
+ $type: z.ZodOptional<z.ZodLiteral<"com.atproto.label.defs#selfLabels">>;
118
+ values: z.ZodArray<z.ZodObject<{
119
+ val: z.ZodString;
120
+ }, z.core.$strip>>;
121
+ }, z.core.$strip>>;
122
+ }, z.core.$loose>;
123
+ type StandardSiteDocumentRecord = z.infer<typeof StandardSiteDocumentRecordSchema>;
124
+ /**
125
+ * site.standard.graph.subscription
126
+ *
127
+ * Authored by a viewer to declare a subscription to a publication. Used
128
+ * by Phase 4 inline-subscribe path. Record key is a TID; the AT-URI
129
+ * shape is `at://<viewer-did>/site.standard.graph.subscription/<rkey>`.
130
+ */
131
+ declare const StandardSiteSubscriptionRecordSchema: z.ZodObject<{
132
+ publication: z.ZodString;
133
+ createdAt: z.ZodOptional<z.ZodString>;
134
+ }, z.core.$strip>;
135
+ type StandardSiteSubscriptionRecord = z.infer<typeof StandardSiteSubscriptionRecordSchema>;
136
+ /**
137
+ * site.standard.graph.recommend
138
+ *
139
+ * Document-level "like" record. Same scope as subscription via the
140
+ * site.standard.authSocial OAuth permission-set, so Phase 4 unlocks
141
+ * inline likes alongside inline subscribes.
142
+ */
143
+ declare const StandardSiteRecommendRecordSchema: z.ZodObject<{
144
+ document: z.ZodString;
145
+ createdAt: z.ZodString;
146
+ }, z.core.$strip>;
147
+ type StandardSiteRecommendRecord = z.infer<typeof StandardSiteRecommendRecordSchema>;
148
+
149
+ /**
150
+ * Publisher allowlist for the Standard.site rich embed.
151
+ *
152
+ * Mirrors `bluesky-social/social-app`
153
+ * `src/components/Post/Embed/StandardSiteEmbed/publishers.ts`. The only
154
+ * gate this provides is which publishers get the highlighted
155
+ * "Subscribe on {Publisher}" CTA with a publisher icon vs the plain
156
+ * "View publication" fallback — any Standard.site embed renders
157
+ * regardless of allowlist membership.
158
+ *
159
+ * Sync policy: review additions against the upstream bsky list weekly;
160
+ * Singi Labs reviews before merge.
161
+ */
162
+ interface Publisher {
163
+ /** Lowercase host. Subdomains are matched via `hostMatches`. */
164
+ host: string;
165
+ /** Human-facing publisher name shown in CTA copy. */
166
+ name: string;
167
+ /**
168
+ * Stable identifier used by clients to look up brand icons. The SDK
169
+ * does not ship icon assets — sifa-web maintains them keyed by this
170
+ * id so React Native vs web rendering can diverge.
171
+ */
172
+ iconKey: 'leaflet' | 'pckt' | 'offprint';
173
+ }
174
+ declare const STANDARD_SITE_PUBLISHERS: readonly Publisher[];
175
+ /**
176
+ * Returns true when `host` exactly matches `target` or is a subdomain of
177
+ * it. Hosts are expected to be lowercase already.
178
+ */
179
+ declare function hostMatches(host: string, target: string): boolean;
180
+ /**
181
+ * Match a publisher by host. Returns the publisher when `host` is on the
182
+ * allowlist (exact or subdomain match), null otherwise. Host should be
183
+ * lowercase.
184
+ */
185
+ declare function matchPublisherByHost(host: string | null | undefined): Publisher | null;
186
+ /**
187
+ * Match a publisher by URI. Convenience wrapper around
188
+ * `matchPublisherByHost` for callers that have a publication URL handy.
189
+ */
190
+ declare function matchPublisherByUri(uri: string | undefined | null): Publisher | null;
191
+
192
+ /**
193
+ * Publication metadata embedded in the augmented activity view by
194
+ * sifa-api when an external link card matches an indexed publication.
195
+ *
196
+ * `uri` is the publication's AT-URI (e.g.
197
+ * `at://did:plc:abc/site.standard.publication/xyz`). `theme` carries
198
+ * the publication's own colors when supplied — clients should apply a
199
+ * WCAG min-contrast fallback before honoring them.
200
+ *
201
+ * `icon` is left as `unknown` here because its representation depends
202
+ * on the surface: blob ref on the wire, CDN URL after resolution.
203
+ */
204
+ interface PublicationSource {
205
+ uri: string;
206
+ title: string;
207
+ icon?: unknown;
208
+ theme?: BasicTheme;
209
+ }
210
+ /**
211
+ * Shape attached to activity items whose external link card URL matches
212
+ * a Standard.site record. Mirrors the relevant fields of bsky's
213
+ * `StandardSiteEmbed` view so a sifa-web renderer can be near-1:1.
214
+ *
215
+ * `associatedRefs` carries AT-URIs the client may use in Phase 4 to
216
+ * query subscription state for the viewer.
217
+ */
218
+ interface StandardSiteEmbedView {
219
+ uri: string;
220
+ source: PublicationSource;
221
+ associatedRefs: {
222
+ uri: string;
223
+ }[];
224
+ createdAt?: string;
225
+ readingTime?: number;
226
+ }
227
+ declare const STANDARD_SITE_PUBLICATION_NSID: "site.standard.publication";
228
+ declare const STANDARD_SITE_DOCUMENT_NSID: "site.standard.document";
229
+ declare const STANDARD_SITE_SUBSCRIPTION_NSID: "site.standard.graph.subscription";
230
+ declare const STANDARD_SITE_RECOMMEND_NSID: "site.standard.graph.recommend";
231
+ /**
232
+ * Pre-defined OAuth permission-set the consumer apps request to write
233
+ * subscription + recommend records on behalf of the viewer. The actual
234
+ * permission-set is published under
235
+ * `at://did:plc:re3ebnp5v7ffagz6rb6xfei4/com.atproto.lexicon.schema/site.standard.authSocial`.
236
+ */
237
+ declare const STANDARD_SITE_AUTH_SOCIAL_NSID: "site.standard.authSocial";
238
+ /**
239
+ * True when the AT-URI's collection segment is a Standard.site
240
+ * collection. Useful for detecting Standard.site embed augmentation on
241
+ * arbitrary activity items.
242
+ */
243
+ declare function isStandardSiteAtUri(uri: string): boolean;
244
+ /**
245
+ * True when any `associatedRefs[].uri` is a Standard.site collection
246
+ * AT-URI. The bsky client uses the same check to gate the
247
+ * `StandardSiteEmbed` renderer.
248
+ */
249
+ declare function hasStandardSiteAssociatedRef(refs: {
250
+ uri: string;
251
+ }[] | undefined): boolean;
252
+
253
+ export { type BasicTheme, BasicThemeSchema, type PublicationSource, type Publisher, type RgbColor, STANDARD_SITE_AUTH_SOCIAL_NSID, STANDARD_SITE_DOCUMENT_NSID, STANDARD_SITE_PUBLICATION_NSID, STANDARD_SITE_PUBLISHERS, STANDARD_SITE_RECOMMEND_NSID, STANDARD_SITE_SUBSCRIPTION_NSID, type StandardSiteDocumentRecord, StandardSiteDocumentRecordSchema, type StandardSiteEmbedView, type StandardSitePublicationRecord, StandardSitePublicationRecordSchema, type StandardSiteRecommendRecord, StandardSiteRecommendRecordSchema, type StandardSiteSubscriptionRecord, StandardSiteSubscriptionRecordSchema, hasStandardSiteAssociatedRef, hostMatches, isStandardSiteAtUri, matchPublisherByHost, matchPublisherByUri };
@@ -0,0 +1,138 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/publishing/schemas.ts
4
+ function maxGraphemes(max) {
5
+ return (value) => {
6
+ const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
7
+ let count = 0;
8
+ for (const _ of segmenter.segment(value)) {
9
+ count++;
10
+ if (count > max) return false;
11
+ }
12
+ return true;
13
+ };
14
+ }
15
+ var didSchema = z.string().regex(/^did:[a-z]+:[a-zA-Z0-9._:%-]+$/, "Invalid DID");
16
+ var datetimeSchema = z.string().datetime({ offset: true });
17
+ var atUriSchema = z.string().regex(/^at:\/\/[^\s]+$/, "Invalid AT-URI");
18
+ var cidSchema = z.string().regex(/^(Qm[1-9A-HJ-NP-Za-km-z]{44}|b[A-Za-z0-9+/=]+)$/, "Invalid CID");
19
+ z.string().regex(/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/, "Invalid BCP 47 language tag");
20
+ var uriSchema = z.string().url();
21
+ var strongRefSchema = z.object({
22
+ uri: atUriSchema,
23
+ cid: cidSchema
24
+ });
25
+ var selfLabelsSchema = z.object({
26
+ $type: z.literal("com.atproto.label.defs#selfLabels").optional(),
27
+ values: z.array(z.object({ val: z.string() }))
28
+ });
29
+
30
+ // src/publishing/schemas.ts
31
+ var rgbColorSchema = z.object({
32
+ r: z.number().int().min(0).max(255),
33
+ g: z.number().int().min(0).max(255),
34
+ b: z.number().int().min(0).max(255)
35
+ });
36
+ var BasicThemeSchema = z.object({
37
+ background: rgbColorSchema,
38
+ foreground: rgbColorSchema,
39
+ accent: rgbColorSchema,
40
+ accentForeground: rgbColorSchema
41
+ });
42
+ var blobRefSchema = z.object({
43
+ $type: z.string().optional(),
44
+ ref: z.unknown(),
45
+ mimeType: z.string().optional(),
46
+ size: z.number().optional()
47
+ }).passthrough();
48
+ var StandardSitePublicationRecordSchema = z.object({
49
+ url: uriSchema,
50
+ name: z.string().min(1).refine(maxGraphemes(500)).max(5e3),
51
+ description: z.string().refine(maxGraphemes(3e3)).max(3e4).optional(),
52
+ icon: blobRefSchema.optional(),
53
+ basicTheme: BasicThemeSchema.optional(),
54
+ labels: selfLabelsSchema.optional(),
55
+ preferences: z.object({
56
+ showInDiscover: z.boolean().optional()
57
+ }).partial().optional()
58
+ }).passthrough();
59
+ var contributorSchema = z.object({
60
+ did: didSchema,
61
+ role: z.string().refine(maxGraphemes(100)).max(1e3).optional(),
62
+ displayName: z.string().refine(maxGraphemes(100)).max(1e3).optional()
63
+ }).passthrough();
64
+ var StandardSiteDocumentRecordSchema = z.object({
65
+ site: z.string().min(1),
66
+ title: z.string().min(1).refine(maxGraphemes(500)).max(5e3),
67
+ path: z.string().optional(),
68
+ publishedAt: datetimeSchema,
69
+ updatedAt: datetimeSchema.optional(),
70
+ description: z.string().refine(maxGraphemes(3e3)).max(3e4).optional(),
71
+ textContent: z.string().optional(),
72
+ tags: z.array(z.string().refine(maxGraphemes(128)).max(1280)).optional(),
73
+ coverImage: blobRefSchema.optional(),
74
+ contributors: z.array(contributorSchema).optional(),
75
+ bskyPostRef: strongRefSchema.optional(),
76
+ labels: selfLabelsSchema.optional()
77
+ }).passthrough();
78
+ var StandardSiteSubscriptionRecordSchema = z.object({
79
+ publication: atUriSchema,
80
+ createdAt: datetimeSchema.optional()
81
+ });
82
+ var StandardSiteRecommendRecordSchema = z.object({
83
+ document: atUriSchema,
84
+ createdAt: datetimeSchema
85
+ });
86
+
87
+ // src/publishing/registry.ts
88
+ var STANDARD_SITE_PUBLISHERS = Object.freeze([
89
+ { host: "leaflet.pub", name: "Leaflet", iconKey: "leaflet" },
90
+ { host: "pckt.blog", name: "pckt", iconKey: "pckt" },
91
+ { host: "offprint.app", name: "Offprint", iconKey: "offprint" }
92
+ ]);
93
+ function hostMatches(host, target) {
94
+ return host === target || host.endsWith("." + target);
95
+ }
96
+ function hostFromUri(uri) {
97
+ if (!uri) return null;
98
+ try {
99
+ return new URL(uri).host.toLowerCase();
100
+ } catch {
101
+ return null;
102
+ }
103
+ }
104
+ function matchPublisherByHost(host) {
105
+ if (!host) return null;
106
+ const lower = host.toLowerCase();
107
+ return STANDARD_SITE_PUBLISHERS.find((p) => hostMatches(lower, p.host)) ?? null;
108
+ }
109
+ function matchPublisherByUri(uri) {
110
+ return matchPublisherByHost(hostFromUri(uri));
111
+ }
112
+
113
+ // src/publishing/types.ts
114
+ var STANDARD_SITE_PUBLICATION_NSID = "site.standard.publication";
115
+ var STANDARD_SITE_DOCUMENT_NSID = "site.standard.document";
116
+ var STANDARD_SITE_SUBSCRIPTION_NSID = "site.standard.graph.subscription";
117
+ var STANDARD_SITE_RECOMMEND_NSID = "site.standard.graph.recommend";
118
+ var STANDARD_SITE_AUTH_SOCIAL_NSID = "site.standard.authSocial";
119
+ var COLLECTION_SET = /* @__PURE__ */ new Set([
120
+ STANDARD_SITE_PUBLICATION_NSID,
121
+ STANDARD_SITE_DOCUMENT_NSID,
122
+ STANDARD_SITE_SUBSCRIPTION_NSID,
123
+ STANDARD_SITE_RECOMMEND_NSID
124
+ ]);
125
+ function isStandardSiteAtUri(uri) {
126
+ if (!uri.startsWith("at://")) return false;
127
+ const segments = uri.slice("at://".length).split("/");
128
+ const collection = segments[1];
129
+ return collection !== void 0 && COLLECTION_SET.has(collection);
130
+ }
131
+ function hasStandardSiteAssociatedRef(refs) {
132
+ if (!refs) return false;
133
+ return refs.some((r) => isStandardSiteAtUri(r.uri));
134
+ }
135
+
136
+ export { BasicThemeSchema, STANDARD_SITE_AUTH_SOCIAL_NSID, STANDARD_SITE_DOCUMENT_NSID, STANDARD_SITE_PUBLICATION_NSID, STANDARD_SITE_PUBLISHERS, STANDARD_SITE_RECOMMEND_NSID, STANDARD_SITE_SUBSCRIPTION_NSID, StandardSiteDocumentRecordSchema, StandardSitePublicationRecordSchema, StandardSiteRecommendRecordSchema, StandardSiteSubscriptionRecordSchema, hasStandardSiteAssociatedRef, hostMatches, isStandardSiteAtUri, matchPublisherByHost, matchPublisherByUri };
137
+ //# sourceMappingURL=index.js.map
138
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/schemas/shared.ts","../../src/publishing/schemas.ts","../../src/publishing/registry.ts","../../src/publishing/types.ts"],"names":["z"],"mappings":";;;AASO,SAAS,aAAa,GAAA,EAAa;AACxC,EAAA,OAAO,CAAC,KAAA,KAA2B;AACjC,IAAA,MAAM,SAAA,GAAY,IAAI,IAAA,CAAK,SAAA,CAAU,QAAW,EAAE,WAAA,EAAa,YAAY,CAAA;AAC3E,IAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,IAAA,KAAA,MAAW,CAAA,IAAK,SAAA,CAAU,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxC,MAAA,KAAA,EAAA;AACA,MAAA,IAAI,KAAA,GAAQ,KAAK,OAAO,KAAA;AAAA,IAC1B;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AACF;AAGO,IAAM,YAAY,CAAA,CAAE,MAAA,EAAO,CAAE,KAAA,CAAM,kCAAkC,aAAa,CAAA;AAGlF,IAAM,cAAA,GAAiB,EAAE,MAAA,EAAO,CAAE,SAAS,E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ACpF,EAAA,OAAO,oBAAA,CAAqB,WAAA,CAAY,GAAG,CAAC,CAAA;AAC9C;;;AC9BO,IAAM,8BAAA,GAAiC;AACvC,IAAM,2BAAA,GAA8B;AACpC,IAAM,+BAAA,GAAkC;AACxC,IAAM,4BAAA,GAA+B;AAQrC,IAAM,8BAAA,GAAiC;AAE9C,IAAM,cAAA,uBAAqB,GAAA,CAAY;AAAA,EACrC,8BAAA;AAAA,EACA,2BAAA;AAAA,EACA,+BAAA;AAAA,EACA;AACF,CAAC,CAAA;AAOM,SAAS,oBAAoB,GAAA,EAAsB;AACxD,EAAA,IAAI,CAAC,GAAA,CAAI,UAAA,CAAW,OAAO,GAAG,OAAO,KAAA;AACrC,EAAA,MAAM,WAAW,GAAA,CAAI,KAAA,CAAM,QAAQ,MAAM,CAAA,CAAE,MAAM,GAAG,CAAA;AACpD,EAAA,MAAM,UAAA,GAAa,SAAS,CAAC,CAAA;AAC7B,EAAA,OAAO,UAAA,KAAe,MAAA,IAAa,cAAA,CAAe,GAAA,CAAI,UAAU,CAAA;AAClE;AAOO,SAAS,6BAA6B,IAAA,EAA8C;AACzF,EAAA,IAAI,CAAC,MAAM,OAAO,KAAA;AAClB,EAAA,OAAO,KAAK,IAAA,CAAK,CAAC,MAAM,mBAAA,CAAoB,CAAA,CAAE,GAAG,CAAC,CAAA;AACpD","file":"index.js","sourcesContent":["import { z } from 'zod';\n\n/**\n * Grapheme-aware refinement matching the AT Protocol lexicon `maxGraphemes`\n * constraint. JS strings are sequences of UTF-16 code units, but lexicon\n * `maxGraphemes` counts user-perceived characters (grapheme clusters), so\n * emoji sequences, regional indicators, ZWJ joins, and combining marks all\n * count as one unit each. We use `Intl.Segmenter` to enforce this correctly.\n */\nexport function maxGraphemes(max: number) {\n return (value: string): boolean => {\n const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });\n let count = 0;\n for (const _ of segmenter.segment(value)) {\n count++;\n if (count > max) return false;\n }\n return true;\n };\n}\n\n/** Decentralized identifier, AT Protocol `format: did`. */\nexport const didSchema = z.string().regex(/^did:[a-z]+:[a-zA-Z0-9._:%-]+$/, 'Invalid DID');\n\n/** RFC 3339 datetime with timezone offset, AT Protocol `format: datetime`. */\nexport const datetimeSchema = z.string().datetime({ offset: true });\n\n/** Generic AT-URI, AT Protocol `format: at-uri`. */\nexport const atUriSchema = z.string().regex(/^at:\\/\\/[^\\s]+$/, 'Invalid AT-URI');\n\n/** Content identifier, AT Protocol `format: cid`. Loose validation -- accepts CIDv0 and CIDv1. */\nexport const cidSchema = z\n .string()\n .regex(/^(Qm[1-9A-HJ-NP-Za-km-z]{44}|b[A-Za-z0-9+/=]+)$/, 'Invalid CID');\n\n/** BCP 47 language tag, AT Protocol `format: language`. */\nexport const languageTagSchema = z\n .string()\n .regex(/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/, 'Invalid BCP 47 language tag');\n\n/** Generic URI, AT Protocol `format: uri`. */\nexport const uriSchema = z.string().url();\n\n/**\n * StrongRef shape from `com.atproto.repo.strongRef` -- pins a record by both\n * AT-URI (identity) and CID (version).\n */\nexport const strongRefSchema = z.object({\n uri: atUriSchema,\n cid: cidSchema,\n});\n\n/**\n * Self-labels shape from `com.atproto.label.defs#selfLabels`. Modelled\n * permissively because clients rarely construct this directly; the AppView\n * handles label validation.\n */\nexport const selfLabelsSchema = z.object({\n $type: z.literal('com.atproto.label.defs#selfLabels').optional(),\n values: z.array(z.object({ val: z.string() })),\n});\n","import { z } from 'zod';\n\nimport {\n atUriSchema,\n datetimeSchema,\n didSchema,\n maxGraphemes,\n selfLabelsSchema,\n strongRefSchema,\n uriSchema,\n} from '../schemas/shared.js';\n\n/**\n * Zod schemas mirroring the canonical Standard.site lexicons that Sifa\n * consumes when rendering publication embeds.\n *\n * Canonical lexicons live at:\n * DID: did:plc:re3ebnp5v7ffagz6rb6xfei4\n * PDS: https://auriporia.us-west.host.bsky.network\n * Collection: com.atproto.lexicon.schema\n *\n * Sifa does NOT own these lexicons; we vendor the validation shapes so\n * clients can parse augmented embeds and (in Phase 4) write subscription\n * records to viewers' PDSes. Re-check against the canonical PDS on each\n * SDK release to detect schema drift.\n */\n\nconst rgbColorSchema = z.object({\n r: z.number().int().min(0).max(255),\n g: z.number().int().min(0).max(255),\n b: z.number().int().min(0).max(255),\n});\n\nexport type RgbColor = z.infer<typeof rgbColorSchema>;\n\n/** site.standard.theme.basic */\nexport const BasicThemeSchema = z.object({\n background: rgbColorSchema,\n foreground: rgbColorSchema,\n accent: rgbColorSchema,\n accentForeground: rgbColorSchema,\n});\n\nexport type BasicTheme = z.infer<typeof BasicThemeSchema>;\n\nconst blobRefSchema = z\n .object({\n $type: z.string().optional(),\n ref: z.unknown(),\n mimeType: z.string().optional(),\n size: z.number().optional(),\n })\n .passthrough();\n\n/** site.standard.publication */\nexport const StandardSitePublicationRecordSchema = z\n .object({\n url: uriSchema,\n name: z.string().min(1).refine(maxGraphemes(500)).max(5000),\n description: z.string().refine(maxGraphemes(3000)).max(30000).optional(),\n icon: blobRefSchema.optional(),\n basicTheme: BasicThemeSchema.optional(),\n labels: selfLabelsSchema.optional(),\n preferences: z\n .object({\n showInDiscover: z.boolean().optional(),\n })\n .partial()\n .optional(),\n })\n .passthrough();\n\nexport type StandardSitePublicationRecord = z.infer<typeof StandardSitePublicationRecordSchema>;\n\nconst contributorSchema = z\n .object({\n did: didSchema,\n role: z.string().refine(maxGraphemes(100)).max(1000).optional(),\n displayName: z.string().refine(maxGraphemes(100)).max(1000).optional(),\n })\n .passthrough();\n\n/** site.standard.document */\nexport const StandardSiteDocumentRecordSchema = z\n .object({\n site: z.string().min(1),\n title: z.string().min(1).refine(maxGraphemes(500)).max(5000),\n path: z.string().optional(),\n publishedAt: datetimeSchema,\n updatedAt: datetimeSchema.optional(),\n description: z.string().refine(maxGraphemes(3000)).max(30000).optional(),\n textContent: z.string().optional(),\n tags: z.array(z.string().refine(maxGraphemes(128)).max(1280)).optional(),\n coverImage: blobRefSchema.optional(),\n contributors: z.array(contributorSchema).optional(),\n bskyPostRef: strongRefSchema.optional(),\n labels: selfLabelsSchema.optional(),\n })\n .passthrough();\n\nexport type StandardSiteDocumentRecord = z.infer<typeof StandardSiteDocumentRecordSchema>;\n\n/**\n * site.standard.graph.subscription\n *\n * Authored by a viewer to declare a subscription to a publication. Used\n * by Phase 4 inline-subscribe path. Record key is a TID; the AT-URI\n * shape is `at://<viewer-did>/site.standard.graph.subscription/<rkey>`.\n */\nexport const StandardSiteSubscriptionRecordSchema = z.object({\n publication: atUriSchema,\n createdAt: datetimeSchema.optional(),\n});\n\nexport type StandardSiteSubscriptionRecord = z.infer<typeof StandardSiteSubscriptionRecordSchema>;\n\n/**\n * site.standard.graph.recommend\n *\n * Document-level \"like\" record. Same scope as subscription via the\n * site.standard.authSocial OAuth permission-set, so Phase 4 unlocks\n * inline likes alongside inline subscribes.\n */\nexport const StandardSiteRecommendRecordSchema = z.object({\n document: atUriSchema,\n createdAt: datetimeSchema,\n});\n\nexport type StandardSiteRecommendRecord = z.infer<typeof StandardSiteRecommendRecordSchema>;\n","/**\n * Publisher allowlist for the Standard.site rich embed.\n *\n * Mirrors `bluesky-social/social-app`\n * `src/components/Post/Embed/StandardSiteEmbed/publishers.ts`. The only\n * gate this provides is which publishers get the highlighted\n * \"Subscribe on {Publisher}\" CTA with a publisher icon vs the plain\n * \"View publication\" fallback — any Standard.site embed renders\n * regardless of allowlist membership.\n *\n * Sync policy: review additions against the upstream bsky list weekly;\n * Singi Labs reviews before merge.\n */\n\nexport interface Publisher {\n /** Lowercase host. Subdomains are matched via `hostMatches`. */\n host: string;\n /** Human-facing publisher name shown in CTA copy. */\n name: string;\n /**\n * Stable identifier used by clients to look up brand icons. The SDK\n * does not ship icon assets — sifa-web maintains them keyed by this\n * id so React Native vs web rendering can diverge.\n */\n iconKey: 'leaflet' | 'pckt' | 'offprint';\n}\n\nexport const STANDARD_SITE_PUBLISHERS: readonly Publisher[] = Object.freeze([\n { host: 'leaflet.pub', name: 'Leaflet', iconKey: 'leaflet' },\n { host: 'pckt.blog', name: 'pckt', iconKey: 'pckt' },\n { host: 'offprint.app', name: 'Offprint', iconKey: 'offprint' },\n]);\n\n/**\n * Returns true when `host` exactly matches `target` or is a subdomain of\n * it. Hosts are expected to be lowercase already.\n */\nexport function hostMatches(host: string, target: string): boolean {\n return host === target || host.endsWith('.' + target);\n}\n\nfunction hostFromUri(uri: string | undefined | null): string | null {\n if (!uri) return null;\n try {\n return new URL(uri).host.toLowerCase();\n } catch {\n return null;\n }\n}\n\n/**\n * Match a publisher by host. Returns the publisher when `host` is on the\n * allowlist (exact or subdomain match), null otherwise. Host should be\n * lowercase.\n */\nexport function matchPublisherByHost(host: string | null | undefined): Publisher | null {\n if (!host) return null;\n const lower = host.toLowerCase();\n return STANDARD_SITE_PUBLISHERS.find((p) => hostMatches(lower, p.host)) ?? null;\n}\n\n/**\n * Match a publisher by URI. Convenience wrapper around\n * `matchPublisherByHost` for callers that have a publication URL handy.\n */\nexport function matchPublisherByUri(uri: string | undefined | null): Publisher | null {\n return matchPublisherByHost(hostFromUri(uri));\n}\n","import type { BasicTheme } from './schemas.js';\n\n/**\n * Publication metadata embedded in the augmented activity view by\n * sifa-api when an external link card matches an indexed publication.\n *\n * `uri` is the publication's AT-URI (e.g.\n * `at://did:plc:abc/site.standard.publication/xyz`). `theme` carries\n * the publication's own colors when supplied — clients should apply a\n * WCAG min-contrast fallback before honoring them.\n *\n * `icon` is left as `unknown` here because its representation depends\n * on the surface: blob ref on the wire, CDN URL after resolution.\n */\nexport interface PublicationSource {\n uri: string;\n title: string;\n icon?: unknown;\n theme?: BasicTheme;\n}\n\n/**\n * Shape attached to activity items whose external link card URL matches\n * a Standard.site record. Mirrors the relevant fields of bsky's\n * `StandardSiteEmbed` view so a sifa-web renderer can be near-1:1.\n *\n * `associatedRefs` carries AT-URIs the client may use in Phase 4 to\n * query subscription state for the viewer.\n */\nexport interface StandardSiteEmbedView {\n uri: string;\n source: PublicationSource;\n associatedRefs: { uri: string }[];\n createdAt?: string;\n readingTime?: number;\n}\n\nexport const STANDARD_SITE_PUBLICATION_NSID = 'site.standard.publication' as const;\nexport const STANDARD_SITE_DOCUMENT_NSID = 'site.standard.document' as const;\nexport const STANDARD_SITE_SUBSCRIPTION_NSID = 'site.standard.graph.subscription' as const;\nexport const STANDARD_SITE_RECOMMEND_NSID = 'site.standard.graph.recommend' as const;\n\n/**\n * Pre-defined OAuth permission-set the consumer apps request to write\n * subscription + recommend records on behalf of the viewer. The actual\n * permission-set is published under\n * `at://did:plc:re3ebnp5v7ffagz6rb6xfei4/com.atproto.lexicon.schema/site.standard.authSocial`.\n */\nexport const STANDARD_SITE_AUTH_SOCIAL_NSID = 'site.standard.authSocial' as const;\n\nconst COLLECTION_SET = new Set<string>([\n STANDARD_SITE_PUBLICATION_NSID,\n STANDARD_SITE_DOCUMENT_NSID,\n STANDARD_SITE_SUBSCRIPTION_NSID,\n STANDARD_SITE_RECOMMEND_NSID,\n]);\n\n/**\n * True when the AT-URI's collection segment is a Standard.site\n * collection. Useful for detecting Standard.site embed augmentation on\n * arbitrary activity items.\n */\nexport function isStandardSiteAtUri(uri: string): boolean {\n if (!uri.startsWith('at://')) return false;\n const segments = uri.slice('at://'.length).split('/');\n const collection = segments[1];\n return collection !== undefined && COLLECTION_SET.has(collection);\n}\n\n/**\n * True when any `associatedRefs[].uri` is a Standard.site collection\n * AT-URI. The bsky client uses the same check to gate the\n * `StandardSiteEmbed` renderer.\n */\nexport function hasStandardSiteAssociatedRef(refs: { uri: string }[] | undefined): boolean {\n if (!refs) return false;\n return refs.some((r) => isStandardSiteAtUri(r.uri));\n}\n"]}