@singi-labs/sifa-sdk 0.12.9 → 0.12.11

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/index.cjs CHANGED
@@ -2708,17 +2708,136 @@ var streamExternalLinkSchema = zod.z.object({
2708
2708
  title: zod.z.string().optional(),
2709
2709
  thumb: zod.z.string().optional()
2710
2710
  });
2711
+ var streamGeoSchema = zod.z.object({
2712
+ latitude: zod.z.number(),
2713
+ longitude: zod.z.number()
2714
+ });
2715
+ var streamAddressSchema = zod.z.object({
2716
+ name: zod.z.string().optional(),
2717
+ street: zod.z.string().optional(),
2718
+ locality: zod.z.string().optional(),
2719
+ region: zod.z.string().optional(),
2720
+ country: zod.z.string().optional(),
2721
+ postalCode: zod.z.string().optional()
2722
+ });
2723
+ var streamRichSegmentSchema = zod.z.object({
2724
+ text: zod.z.string(),
2725
+ link: zod.z.string().optional(),
2726
+ mention: zod.z.string().optional(),
2727
+ tag: zod.z.string().optional()
2728
+ });
2711
2729
  var streamCardBodySchema = zod.z.discriminatedUnion("kind", [
2712
- zod.z.object({ kind: zod.z.literal("text"), text: zod.z.string() }),
2713
- zod.z.object({ kind: zod.z.literal("media"), text: zod.z.string().optional() }),
2714
- zod.z.object({ kind: zod.z.literal("link"), text: zod.z.string().optional() }),
2730
+ zod.z.object({
2731
+ kind: zod.z.literal("text"),
2732
+ text: zod.z.string(),
2733
+ richSegments: zod.z.array(streamRichSegmentSchema).optional(),
2734
+ tags: zod.z.array(zod.z.string()).optional()
2735
+ }),
2736
+ zod.z.object({
2737
+ kind: zod.z.literal("media"),
2738
+ text: zod.z.string().optional(),
2739
+ tags: zod.z.array(zod.z.string()).optional()
2740
+ }),
2741
+ zod.z.object({
2742
+ kind: zod.z.literal("link"),
2743
+ text: zod.z.string().optional(),
2744
+ tags: zod.z.array(zod.z.string()).optional()
2745
+ }),
2715
2746
  zod.z.object({
2716
2747
  kind: zod.z.literal("track"),
2717
2748
  text: zod.z.string().optional(),
2718
2749
  trackTitle: zod.z.string().optional(),
2719
2750
  artist: zod.z.string().optional()
2720
2751
  }),
2721
- zod.z.object({ kind: zod.z.literal("generic"), text: zod.z.string().optional() })
2752
+ zod.z.object({
2753
+ kind: zod.z.literal("generic"),
2754
+ text: zod.z.string().optional(),
2755
+ tags: zod.z.array(zod.z.string()).optional()
2756
+ }),
2757
+ zod.z.object({
2758
+ kind: zod.z.literal("github-pr"),
2759
+ repoOwner: zod.z.string(),
2760
+ repoName: zod.z.string(),
2761
+ prNumber: zod.z.number(),
2762
+ title: zod.z.string(),
2763
+ url: zod.z.string().optional(),
2764
+ language: zod.z.string().optional(),
2765
+ additions: zod.z.number(),
2766
+ deletions: zod.z.number(),
2767
+ mergedAt: zod.z.string().optional()
2768
+ }),
2769
+ zod.z.object({
2770
+ kind: zod.z.literal("book"),
2771
+ title: zod.z.string(),
2772
+ authors: zod.z.array(zod.z.string()),
2773
+ stars: zod.z.number().optional(),
2774
+ status: zod.z.string().optional(),
2775
+ review: zod.z.string().optional()
2776
+ }),
2777
+ zod.z.object({
2778
+ kind: zod.z.literal("media-review"),
2779
+ reviewKind: zod.z.enum(["review", "post", "note", "other"]),
2780
+ title: zod.z.string().optional(),
2781
+ mediaType: zod.z.string().optional(),
2782
+ rating: zod.z.number().optional(),
2783
+ mainCredit: zod.z.string().optional(),
2784
+ reviewText: zod.z.string().optional(),
2785
+ isRevisit: zod.z.boolean()
2786
+ }),
2787
+ zod.z.object({
2788
+ kind: zod.z.literal("event-rsvp"),
2789
+ rsvpStatus: zod.z.enum(["going", "interested", "notgoing", "unknown"]),
2790
+ eventName: zod.z.string().optional(),
2791
+ startsAt: zod.z.string().optional(),
2792
+ endsAt: zod.z.string().optional(),
2793
+ mode: zod.z.enum(["inperson", "virtual", "hybrid"]).optional(),
2794
+ locationName: zod.z.string().optional(),
2795
+ locationLocality: zod.z.string().optional(),
2796
+ locationCountry: zod.z.string().optional()
2797
+ }),
2798
+ zod.z.object({
2799
+ kind: zod.z.literal("verification"),
2800
+ platform: zod.z.string(),
2801
+ verified: zod.z.boolean(),
2802
+ subjectLabel: zod.z.string().optional(),
2803
+ handle: zod.z.string().optional(),
2804
+ profileUrl: zod.z.string().optional()
2805
+ }),
2806
+ zod.z.object({
2807
+ kind: zod.z.literal("membership"),
2808
+ communityName: zod.z.string().optional(),
2809
+ description: zod.z.string().optional(),
2810
+ communityUri: zod.z.string().optional()
2811
+ }),
2812
+ zod.z.object({
2813
+ kind: zod.z.literal("location"),
2814
+ venueName: zod.z.string().optional(),
2815
+ shout: zod.z.string().optional(),
2816
+ address: streamAddressSchema.optional(),
2817
+ geo: streamGeoSchema.optional()
2818
+ }),
2819
+ zod.z.object({
2820
+ kind: zod.z.literal("travel"),
2821
+ origin: zod.z.string().optional(),
2822
+ destination: zod.z.string().optional(),
2823
+ transportation: zod.z.string().optional(),
2824
+ carrier: zod.z.string().optional(),
2825
+ carrierCode: zod.z.string().optional(),
2826
+ startDate: zod.z.string().optional(),
2827
+ endDate: zod.z.string().optional()
2828
+ }),
2829
+ zod.z.object({
2830
+ kind: zod.z.literal("standard-site"),
2831
+ title: zod.z.string().optional(),
2832
+ description: zod.z.string().optional(),
2833
+ siteUrl: zod.z.string().optional(),
2834
+ path: zod.z.string().optional(),
2835
+ publisherName: zod.z.string().optional(),
2836
+ icon: zod.z.string().optional(),
2837
+ coverImageUrl: zod.z.string().optional(),
2838
+ readingTime: zod.z.number().optional(),
2839
+ publishedAt: zod.z.string().optional()
2840
+ })
2722
2841
  ]);
2723
2842
  var streamCardSubjectSchema = zod.z.discriminatedUnion("kind", [
2724
2843
  zod.z.object({
@@ -2754,6 +2873,62 @@ var streamCardVMSchema = zod.z.lazy(
2754
2873
  subject: zod.z.lazy(() => streamCardSubjectSchema).optional()
2755
2874
  })
2756
2875
  );
2876
+ function maxGraphemes(max) {
2877
+ return (value) => {
2878
+ const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
2879
+ let count = 0;
2880
+ for (const _ of segmenter.segment(value)) {
2881
+ count++;
2882
+ if (count > max) return false;
2883
+ }
2884
+ return true;
2885
+ };
2886
+ }
2887
+ var didSchema = zod.z.string().regex(/^did:[a-z]+:[a-zA-Z0-9._:%-]+$/, "Invalid DID");
2888
+ var datetimeSchema = zod.z.string().datetime({ offset: true });
2889
+ var partialDateSchema = zod.z.string().regex(/^\d{4}(-\d{2}(-\d{2}(T.+)?)?)?$/, "Expected YYYY, YYYY-MM, YYYY-MM-DD, or a datetime");
2890
+ var atUriSchema = zod.z.string().regex(/^at:\/\/[^\s]+$/, "Invalid AT-URI");
2891
+ var cidSchema = zod.z.string().regex(/^(Qm[1-9A-HJ-NP-Za-km-z]{44}|b[A-Za-z0-9+/=]+)$/, "Invalid CID");
2892
+ var languageTagSchema = zod.z.string().regex(/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/, "Invalid BCP 47 language tag");
2893
+ var uriSchema = zod.z.string().url();
2894
+ var strongRefSchema = zod.z.object({
2895
+ uri: atUriSchema,
2896
+ cid: cidSchema
2897
+ });
2898
+ var externalRecordRefSchema = zod.z.object({
2899
+ uri: atUriSchema,
2900
+ cid: cidSchema.optional()
2901
+ });
2902
+ var selfLabelsSchema = zod.z.object({
2903
+ $type: zod.z.literal("com.atproto.label.defs#selfLabels").optional(),
2904
+ values: zod.z.array(zod.z.object({ val: zod.z.string() }))
2905
+ });
2906
+
2907
+ // src/publishing/registry.ts
2908
+ var STANDARD_SITE_PUBLISHERS = Object.freeze([
2909
+ { host: "leaflet.pub", name: "Leaflet", iconKey: "leaflet" },
2910
+ { host: "pckt.blog", name: "pckt", iconKey: "pckt" },
2911
+ { host: "offprint.app", name: "Offprint", iconKey: "offprint" }
2912
+ ]);
2913
+ function hostMatches(host, target) {
2914
+ return host === target || host.endsWith("." + target);
2915
+ }
2916
+ function hostFromUri(uri) {
2917
+ if (!uri) return null;
2918
+ try {
2919
+ return new URL(uri).host.toLowerCase();
2920
+ } catch {
2921
+ return null;
2922
+ }
2923
+ }
2924
+ function matchPublisherByHost(host) {
2925
+ if (!host) return null;
2926
+ const lower = host.toLowerCase();
2927
+ return STANDARD_SITE_PUBLISHERS.find((p) => hostMatches(lower, p.host)) ?? null;
2928
+ }
2929
+ function matchPublisherByUri(uri) {
2930
+ return matchPublisherByHost(hostFromUri(uri));
2931
+ }
2757
2932
 
2758
2933
  // src/stream/to-stream-card-vm.ts
2759
2934
  var DEFAULT_SOURCE_COLOR = "slate";
@@ -2782,6 +2957,69 @@ function aspectRatio(value) {
2782
2957
  if (typeof width === "number" && typeof height === "number") return { width, height };
2783
2958
  return void 0;
2784
2959
  }
2960
+ function asFiniteNumber(value) {
2961
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
2962
+ }
2963
+ function looseBlobCid(value) {
2964
+ const viaRef = blobCid(value);
2965
+ if (viaRef) return viaRef;
2966
+ const cid = asRecord(value)?.cid;
2967
+ return typeof cid === "string" && cid.length > 0 ? cid : void 0;
2968
+ }
2969
+ function blobMedia(value, did, alt) {
2970
+ const cid = looseBlobCid(value);
2971
+ if (!cid) return void 0;
2972
+ const media = { did, cid, alt };
2973
+ const ratio = aspectRatio(asRecord(value)?.aspectRatio);
2974
+ if (ratio) media.aspectRatio = ratio;
2975
+ const mimeType = asNonEmptyString(asRecord(value)?.mimeType);
2976
+ if (mimeType) media.mimeType = mimeType;
2977
+ return media;
2978
+ }
2979
+ function hashSuffix(value) {
2980
+ const i = value.lastIndexOf("#");
2981
+ return i >= 0 ? value.slice(i) : "";
2982
+ }
2983
+ var WORDS_PER_MINUTE = 200;
2984
+ function estimateReadingTime(text) {
2985
+ if (!text) return void 0;
2986
+ const words = text.trim().split(/\s+/).filter(Boolean).length;
2987
+ if (words === 0) return void 0;
2988
+ return Math.max(1, Math.round(words / WORDS_PER_MINUTE));
2989
+ }
2990
+ function beaconGeo(value) {
2991
+ const rec = asRecord(value);
2992
+ if (!rec) return void 0;
2993
+ const { latitude, longitude } = rec;
2994
+ const okType = (v) => typeof v === "string" || typeof v === "number";
2995
+ if (!okType(latitude) || !okType(longitude)) return void 0;
2996
+ const lat = Number(latitude);
2997
+ const lng = Number(longitude);
2998
+ if (!Number.isFinite(lat) || !Number.isFinite(lng)) return void 0;
2999
+ return { latitude: lat, longitude: lng };
3000
+ }
3001
+ function beaconAddress(value) {
3002
+ const rec = asRecord(value);
3003
+ if (!rec) return void 0;
3004
+ const address = {};
3005
+ const name = asNonEmptyString(rec.name);
3006
+ if (name) address.name = name;
3007
+ const street = asNonEmptyString(rec.street);
3008
+ if (street) address.street = street;
3009
+ const locality = asNonEmptyString(rec.locality);
3010
+ if (locality) address.locality = locality;
3011
+ const region = asNonEmptyString(rec.region);
3012
+ if (region) address.region = region;
3013
+ const country = asNonEmptyString(rec.country);
3014
+ if (country) address.country = country;
3015
+ const postalCode = asNonEmptyString(rec.postalCode);
3016
+ if (postalCode) address.postalCode = postalCode;
3017
+ return Object.keys(address).length > 0 ? address : void 0;
3018
+ }
3019
+ function parseAuthors(value) {
3020
+ if (typeof value !== "string") return [];
3021
+ return value.split(" ").map((a) => a.trim()).filter((a) => a.length > 0);
3022
+ }
2785
3023
  function buildSource(item, options) {
2786
3024
  return {
2787
3025
  appId: item.appId,
@@ -2873,6 +3111,416 @@ function applyBskyPost(vm, item, record) {
2873
3111
  vm.body = body;
2874
3112
  return vm;
2875
3113
  }
3114
+ function withGeneric(vm) {
3115
+ vm.body = { kind: "generic" };
3116
+ return vm;
3117
+ }
3118
+ function applyGithubPr(vm, record) {
3119
+ const body = {
3120
+ kind: "github-pr",
3121
+ repoOwner: asNonEmptyString(record.repoOwner) ?? "",
3122
+ repoName: asNonEmptyString(record.repoName) ?? "",
3123
+ prNumber: asFiniteNumber(record.prNumber) ?? 0,
3124
+ title: asNonEmptyString(record.title) ?? "",
3125
+ additions: asFiniteNumber(record.additions) ?? 0,
3126
+ deletions: asFiniteNumber(record.deletions) ?? 0
3127
+ };
3128
+ const url = asNonEmptyString(record.url);
3129
+ if (url) body.url = url;
3130
+ const language = asNonEmptyString(record.language);
3131
+ if (language) body.language = language;
3132
+ const mergedAt = asNonEmptyString(record.mergedAt);
3133
+ if (mergedAt) body.mergedAt = mergedAt;
3134
+ vm.body = body;
3135
+ return vm;
3136
+ }
3137
+ function applyBook(vm, item, record) {
3138
+ const title = asNonEmptyString(record.title) ?? "Untitled book";
3139
+ const body = {
3140
+ kind: "book",
3141
+ title,
3142
+ authors: parseAuthors(record.authors)
3143
+ };
3144
+ const stars = asFiniteNumber(record.stars);
3145
+ if (stars !== void 0 && stars > 0) body.stars = stars;
3146
+ const status = asNonEmptyString(record.status);
3147
+ if (status) body.status = status;
3148
+ const review = asNonEmptyString(
3149
+ typeof record.review === "string" ? record.review.trim() : void 0
3150
+ );
3151
+ if (review) body.review = review;
3152
+ vm.body = body;
3153
+ const did = didFromUri(item.uri);
3154
+ if (did) {
3155
+ const cover = blobMedia(record.cover, did, `The cover of ${title}`);
3156
+ if (cover) vm.media = [cover];
3157
+ }
3158
+ return vm;
3159
+ }
3160
+ function popfeedReviewKind(collection) {
3161
+ if (collection.endsWith(".review")) return "review";
3162
+ if (collection.endsWith(".post")) return "post";
3163
+ if (collection.endsWith(".note")) return "note";
3164
+ return "other";
3165
+ }
3166
+ function applyMediaReview(vm, item, record) {
3167
+ const title = asNonEmptyString(record.title) ?? asNonEmptyString(record.name);
3168
+ const body = {
3169
+ kind: "media-review",
3170
+ reviewKind: popfeedReviewKind(item.collection),
3171
+ isRevisit: record.isRevisit === true
3172
+ };
3173
+ if (title) body.title = title;
3174
+ const mediaType = asNonEmptyString(record.creativeWorkType);
3175
+ if (mediaType) body.mediaType = mediaType;
3176
+ const rating = asFiniteNumber(record.rating);
3177
+ if (rating !== void 0) body.rating = rating;
3178
+ const mainCredit = asNonEmptyString(record.mainCredit);
3179
+ if (mainCredit) body.mainCredit = mainCredit;
3180
+ const reviewText = asNonEmptyString(record.text);
3181
+ if (reviewText) body.reviewText = reviewText;
3182
+ vm.body = body;
3183
+ const posterUrl = asNonEmptyString(record.posterUrl);
3184
+ if (posterUrl) vm.media = [{ url: posterUrl, alt: title ? `${title} poster` : "" }];
3185
+ return vm;
3186
+ }
3187
+ var RSVP_STATUS = {
3188
+ "#going": "going",
3189
+ "#interested": "interested",
3190
+ "#notgoing": "notgoing"
3191
+ };
3192
+ var RSVP_MODE = {
3193
+ "#inperson": "inperson",
3194
+ "#virtual": "virtual",
3195
+ "#hybrid": "hybrid"
3196
+ };
3197
+ function applyEventRsvp(vm, record) {
3198
+ const status = asNonEmptyString(record.status);
3199
+ const body = {
3200
+ kind: "event-rsvp",
3201
+ rsvpStatus: (status ? RSVP_STATUS[hashSuffix(status)] : void 0) ?? "unknown"
3202
+ };
3203
+ const meta = asRecord(record.eventMeta);
3204
+ if (meta) {
3205
+ const eventName = asNonEmptyString(meta.name);
3206
+ if (eventName) body.eventName = eventName;
3207
+ const startsAt = asNonEmptyString(meta.startsAt);
3208
+ if (startsAt) body.startsAt = startsAt;
3209
+ const endsAt = asNonEmptyString(meta.endsAt);
3210
+ if (endsAt) body.endsAt = endsAt;
3211
+ const mode = asNonEmptyString(meta.mode);
3212
+ const modeEnum = mode ? RSVP_MODE[hashSuffix(mode)] : void 0;
3213
+ if (modeEnum) body.mode = modeEnum;
3214
+ const locationName = asNonEmptyString(meta.locationName);
3215
+ if (locationName) body.locationName = locationName;
3216
+ const locationLocality = asNonEmptyString(meta.locationLocality);
3217
+ if (locationLocality) body.locationLocality = locationLocality;
3218
+ const locationCountry = asNonEmptyString(meta.locationCountry);
3219
+ if (locationCountry) body.locationCountry = locationCountry;
3220
+ }
3221
+ vm.body = body;
3222
+ return vm;
3223
+ }
3224
+ function applyKeytraceVerification(vm, record) {
3225
+ const identity = asRecord(record.identity) ?? {};
3226
+ const subject = asNonEmptyString(identity.subject);
3227
+ const displayName = asNonEmptyString(identity.displayName);
3228
+ const body = {
3229
+ kind: "verification",
3230
+ platform: asNonEmptyString(record.type) ?? "unknown",
3231
+ verified: record.status === "verified"
3232
+ };
3233
+ const subjectLabel = displayName ?? subject;
3234
+ if (subjectLabel) body.subjectLabel = subjectLabel;
3235
+ const profileUrl = asNonEmptyString(identity.profileUrl);
3236
+ if (profileUrl) body.profileUrl = profileUrl;
3237
+ vm.body = body;
3238
+ return vm;
3239
+ }
3240
+ function applyBskyVerification(vm, record) {
3241
+ const handle = asNonEmptyString(record.handle);
3242
+ const displayName = asNonEmptyString(record.displayName);
3243
+ const body = {
3244
+ kind: "verification",
3245
+ platform: "bluesky",
3246
+ verified: true
3247
+ };
3248
+ const subjectLabel = displayName ?? handle;
3249
+ if (subjectLabel) body.subjectLabel = subjectLabel;
3250
+ if (handle) body.handle = handle;
3251
+ vm.body = body;
3252
+ return vm;
3253
+ }
3254
+ function applyMembership(vm, record) {
3255
+ const body = { kind: "membership" };
3256
+ const communityUri = asNonEmptyString(record.community);
3257
+ if (communityUri) body.communityUri = communityUri;
3258
+ const meta = asRecord(record.communityMeta);
3259
+ const communityName = meta ? asNonEmptyString(meta.name) : void 0;
3260
+ if (communityName) body.communityName = communityName;
3261
+ const description = meta ? asNonEmptyString(meta.description) : void 0;
3262
+ if (description) body.description = description;
3263
+ vm.body = body;
3264
+ if (meta) {
3265
+ const ownerDid = asNonEmptyString(meta.ownerDid) ?? (communityUri ? didFromUri(communityUri) : void 0);
3266
+ if (ownerDid) {
3267
+ const picture = blobMedia(meta.picture, ownerDid, communityName ?? "");
3268
+ if (picture) vm.media = [picture];
3269
+ }
3270
+ }
3271
+ return vm;
3272
+ }
3273
+ function applyLocation(vm, record) {
3274
+ const body = { kind: "location" };
3275
+ const venueName = asNonEmptyString(record.venueName);
3276
+ if (venueName) body.venueName = venueName;
3277
+ const shout = asNonEmptyString(record.shout);
3278
+ if (shout) body.shout = shout;
3279
+ const address = beaconAddress(record.addressDetails);
3280
+ if (address) body.address = address;
3281
+ const geo = beaconGeo(record.location);
3282
+ if (geo) body.geo = geo;
3283
+ vm.body = body;
3284
+ return vm;
3285
+ }
3286
+ function applyTravel(vm, record) {
3287
+ const body = { kind: "travel" };
3288
+ const origin = asNonEmptyString(record.originTransportCode);
3289
+ if (origin) body.origin = origin;
3290
+ const destination = asNonEmptyString(record.destinationTransportCode);
3291
+ if (destination) body.destination = destination;
3292
+ const transportation = asNonEmptyString(record.transportation);
3293
+ if (transportation) body.transportation = transportation;
3294
+ const carrier = asNonEmptyString(record.carrier);
3295
+ if (carrier) body.carrier = carrier;
3296
+ const carrierCode = asNonEmptyString(record.carrierCode);
3297
+ if (carrierCode) body.carrierCode = carrierCode;
3298
+ const startDate = asNonEmptyString(record.startDate);
3299
+ if (startDate) body.startDate = startDate;
3300
+ const endDate = asNonEmptyString(record.endDate);
3301
+ if (endDate) body.endDate = endDate;
3302
+ vm.body = body;
3303
+ return vm;
3304
+ }
3305
+ function applyStandardSite(vm, record) {
3306
+ const body = { kind: "standard-site" };
3307
+ const title = asNonEmptyString(record.title);
3308
+ if (title) body.title = title;
3309
+ const description = asNonEmptyString(record.description);
3310
+ if (description) body.description = description;
3311
+ const siteUrl = asNonEmptyString(record.siteUrl);
3312
+ if (siteUrl) {
3313
+ body.siteUrl = siteUrl;
3314
+ const publisherName = matchPublisherByUri(siteUrl)?.name;
3315
+ if (publisherName) body.publisherName = publisherName;
3316
+ }
3317
+ const path = asNonEmptyString(record.path);
3318
+ if (path) body.path = path;
3319
+ const icon = asNonEmptyString(record.publicationIcon);
3320
+ if (icon) body.icon = icon;
3321
+ const coverImageUrl = asNonEmptyString(record.coverImageUrl);
3322
+ if (coverImageUrl) body.coverImageUrl = coverImageUrl;
3323
+ const readingTime = estimateReadingTime(asNonEmptyString(record.textContent));
3324
+ if (readingTime !== void 0) body.readingTime = readingTime;
3325
+ const publishedAt = asNonEmptyString(record.publishedAt);
3326
+ if (publishedAt) body.publishedAt = publishedAt;
3327
+ vm.body = body;
3328
+ return vm;
3329
+ }
3330
+ function applyYouAndMe(vm, record) {
3331
+ const did = asNonEmptyString(record.subject);
3332
+ if (did) vm.subject = { kind: "person", did };
3333
+ vm.body = { kind: "generic" };
3334
+ return vm;
3335
+ }
3336
+ function applyAsqAnswer(vm, record) {
3337
+ const uri = asNonEmptyString(asRecord(record.subject)?.uri);
3338
+ if (uri) vm.subject = { kind: "record", uri };
3339
+ vm.body = { kind: "generic" };
3340
+ return vm;
3341
+ }
3342
+ function nonBlankString(value) {
3343
+ return typeof value === "string" && value.trim().length > 0 ? value : void 0;
3344
+ }
3345
+ function readBodyField(value) {
3346
+ const direct = nonBlankString(value);
3347
+ if (direct) return direct;
3348
+ return nonBlankString(asRecord(value)?.value);
3349
+ }
3350
+ function httpUrl(value) {
3351
+ return typeof value === "string" && /^https?:\/\//i.test(value) ? value : void 0;
3352
+ }
3353
+ var GENERIC_TEXT_ORDER = [
3354
+ "text",
3355
+ "title",
3356
+ "name",
3357
+ "description",
3358
+ "content",
3359
+ "body",
3360
+ "message",
3361
+ "note",
3362
+ "caption",
3363
+ "summary",
3364
+ "status"
3365
+ ];
3366
+ function genericText(collection, record) {
3367
+ if (collection === "social.passports.fiftyStates.visit") {
3368
+ return nonBlankString(record.city);
3369
+ }
3370
+ for (const field of GENERIC_TEXT_ORDER) {
3371
+ if (field === "body") {
3372
+ const body = readBodyField(record.body);
3373
+ if (body) return body;
3374
+ continue;
3375
+ }
3376
+ const value = nonBlankString(record[field]);
3377
+ if (value) return value;
3378
+ }
3379
+ return void 0;
3380
+ }
3381
+ function genericTags(record) {
3382
+ const tags = record.tags;
3383
+ if (!Array.isArray(tags)) return void 0;
3384
+ const out = tags.filter((t) => typeof t === "string" && t.length > 0);
3385
+ return out.length > 0 ? out : void 0;
3386
+ }
3387
+ function genericMedia(record, did, alt) {
3388
+ const fromArray = (raw) => {
3389
+ const img = asRecord(raw);
3390
+ if (!img) return void 0;
3391
+ return blobMedia(img.image ?? raw, did, asNonEmptyString(img.alt) ?? alt);
3392
+ };
3393
+ const images = record.images;
3394
+ if (Array.isArray(images)) {
3395
+ const out = images.map(fromArray).filter((m) => m !== void 0);
3396
+ if (out.length > 0) return out;
3397
+ }
3398
+ const embed = asRecord(record.embed);
3399
+ if (embed && Array.isArray(embed.images)) {
3400
+ const out = embed.images.map(fromArray).filter((m) => m !== void 0);
3401
+ if (out.length > 0) return out;
3402
+ }
3403
+ const single = blobMedia(record.image, did, alt) ?? blobMedia(record.thumbnail, did, alt) ?? blobMedia(record.thumb, did, alt) ?? blobMedia(record.photo, did, alt) ?? (embed ? blobMedia(embed.thumbnail, did, alt) : void 0);
3404
+ if (single) return [single];
3405
+ const coverCid = asRecord(record.galleryMeta)?.coverPhotoCid;
3406
+ if (typeof coverCid === "string" && coverCid.length > 0) {
3407
+ return [{ did, cid: coverCid, alt }];
3408
+ }
3409
+ return [];
3410
+ }
3411
+ function genericExternalLink(record) {
3412
+ const embed = asRecord(record.embed);
3413
+ if (embed) {
3414
+ const fromEmbed = bskyExternal(embed);
3415
+ if (fromEmbed) return fromEmbed;
3416
+ }
3417
+ const url = httpUrl(record.source) ?? httpUrl(record.subject) ?? httpUrl(record.url);
3418
+ return url ? { url } : void 0;
3419
+ }
3420
+ function genericSubject(record) {
3421
+ const subject = record.subject;
3422
+ if (typeof subject === "string") {
3423
+ if (subject.startsWith("at://")) return { kind: "record", uri: subject };
3424
+ if (subject.startsWith("did:")) return { kind: "person", did: subject };
3425
+ return void 0;
3426
+ }
3427
+ const uri = nonBlankString(asRecord(subject)?.uri);
3428
+ if (uri && uri.startsWith("at://")) return { kind: "record", uri };
3429
+ return void 0;
3430
+ }
3431
+ function parseFacetFeature(features) {
3432
+ for (const raw of features) {
3433
+ const feat = asRecord(raw);
3434
+ if (!feat) continue;
3435
+ const type = asNonEmptyString(feat["$type"]) ?? "";
3436
+ const uri = asNonEmptyString(feat.uri);
3437
+ const did = asNonEmptyString(feat.did);
3438
+ const tag = asNonEmptyString(feat.tag);
3439
+ if (type.endsWith("#link") && uri) return { link: uri };
3440
+ if (type.endsWith("#mention") && did) return { mention: did };
3441
+ if (type.endsWith("#tag") && tag) return { tag };
3442
+ if (uri) return { link: uri };
3443
+ if (did) return { mention: did };
3444
+ if (tag) return { tag };
3445
+ }
3446
+ return void 0;
3447
+ }
3448
+ function genericRichSegments(text, record) {
3449
+ const facets = record.facets;
3450
+ if (!Array.isArray(facets)) return void 0;
3451
+ const parsed3 = [];
3452
+ for (const raw of facets) {
3453
+ const facet = asRecord(raw);
3454
+ const index = asRecord(facet?.index);
3455
+ const start = asFiniteNumber(index?.byteStart);
3456
+ const end = asFiniteNumber(index?.byteEnd);
3457
+ if (start === void 0 || end === void 0 || start < 0 || end <= start) continue;
3458
+ const features = facet?.features;
3459
+ if (!Array.isArray(features)) continue;
3460
+ const feature = parseFacetFeature(features);
3461
+ if (!feature) continue;
3462
+ parsed3.push({ start, end, ...feature });
3463
+ }
3464
+ if (parsed3.length === 0) return void 0;
3465
+ const bytes = new TextEncoder().encode(text);
3466
+ const decoder = new TextDecoder();
3467
+ parsed3.sort((a, b) => a.start - b.start);
3468
+ const segments = [];
3469
+ let cursor = 0;
3470
+ for (const span of parsed3) {
3471
+ if (span.start < cursor || span.start > bytes.length) continue;
3472
+ const end = Math.min(span.end, bytes.length);
3473
+ if (span.start > cursor) {
3474
+ const plain = decoder.decode(bytes.slice(cursor, span.start));
3475
+ if (plain) segments.push({ text: plain });
3476
+ }
3477
+ const seg = { text: decoder.decode(bytes.slice(span.start, end)) };
3478
+ if (span.link) seg.link = span.link;
3479
+ if (span.mention) seg.mention = span.mention;
3480
+ if (span.tag) seg.tag = span.tag;
3481
+ segments.push(seg);
3482
+ cursor = end;
3483
+ }
3484
+ if (cursor < bytes.length) {
3485
+ const rest = decoder.decode(bytes.slice(cursor));
3486
+ if (rest) segments.push({ text: rest });
3487
+ }
3488
+ return segments.some((s) => s.link ?? s.mention ?? s.tag) ? segments : void 0;
3489
+ }
3490
+ function applyGeneric(vm, item, record) {
3491
+ if (!record) return withGeneric(vm);
3492
+ const text = genericText(item.collection, record);
3493
+ const tags = genericTags(record);
3494
+ const did = didFromUri(item.uri);
3495
+ if (did) {
3496
+ const media = genericMedia(record, did, text ?? "");
3497
+ if (media.length > 0) vm.media = media;
3498
+ }
3499
+ const externalLink = genericExternalLink(record);
3500
+ if (externalLink) vm.externalLink = externalLink;
3501
+ if (!vm.subject) {
3502
+ const subject = genericSubject(record);
3503
+ if (subject) vm.subject = subject;
3504
+ }
3505
+ let body;
3506
+ if (text) {
3507
+ body = { kind: "text", text };
3508
+ const richSegments = genericRichSegments(text, record);
3509
+ if (richSegments) body.richSegments = richSegments;
3510
+ if (tags) body.tags = tags;
3511
+ } else if (vm.media) {
3512
+ body = { kind: "media" };
3513
+ if (tags) body.tags = tags;
3514
+ } else if (vm.externalLink) {
3515
+ body = { kind: "link" };
3516
+ if (tags) body.tags = tags;
3517
+ } else {
3518
+ body = { kind: "generic" };
3519
+ if (tags) body.tags = tags;
3520
+ }
3521
+ vm.body = body;
3522
+ return vm;
3523
+ }
2876
3524
  function toStreamCardVM(item, options = {}) {
2877
3525
  const verb = verbForCollection(item.collection);
2878
3526
  const source = buildSource(item, options);
@@ -2892,11 +3540,36 @@ function toStreamCardVM(item, options = {}) {
2892
3540
  if (item.subject) {
2893
3541
  vm.subject = { kind: "post", post: toStreamCardVM(item.subject, options) };
2894
3542
  }
2895
- if (item.collection === "app.bsky.feed.post") {
2896
- return applyBskyPost(vm, item, record);
3543
+ switch (item.collection) {
3544
+ case "app.bsky.feed.post":
3545
+ return applyBskyPost(vm, item, record);
3546
+ case "github.pull_request":
3547
+ return record ? applyGithubPr(vm, record) : withGeneric(vm);
3548
+ case "buzz.bookhive.book":
3549
+ return record ? applyBook(vm, item, record) : withGeneric(vm);
3550
+ case "community.lexicon.calendar.rsvp":
3551
+ return record ? applyEventRsvp(vm, record) : withGeneric(vm);
3552
+ case "dev.keytrace.claim":
3553
+ return record ? applyKeytraceVerification(vm, record) : withGeneric(vm);
3554
+ case "app.bsky.graph.verification":
3555
+ return record ? applyBskyVerification(vm, record) : withGeneric(vm);
3556
+ case "social.colibri.membership":
3557
+ return record ? applyMembership(vm, record) : withGeneric(vm);
3558
+ case "app.beaconbits.beacon":
3559
+ return record ? applyLocation(vm, record) : withGeneric(vm);
3560
+ case "social.passports.travel.leg":
3561
+ return record ? applyTravel(vm, record) : withGeneric(vm);
3562
+ case "site.standard.document":
3563
+ return record ? applyStandardSite(vm, record) : withGeneric(vm);
3564
+ case "at.youandme.connection":
3565
+ return record ? applyYouAndMe(vm, record) : withGeneric(vm);
3566
+ case "fyi.asq.answer":
3567
+ return record ? applyAsqAnswer(vm, record) : withGeneric(vm);
2897
3568
  }
2898
- vm.body = { kind: "generic" };
2899
- return vm;
3569
+ if (record && item.collection.startsWith("social.popfeed.feed.")) {
3570
+ return applyMediaReview(vm, item, record);
3571
+ }
3572
+ return applyGeneric(vm, item, record);
2900
3573
  }
2901
3574
  function toStreamCardVMs(items, options = {}) {
2902
3575
  const out = [];
@@ -3312,38 +3985,6 @@ function groupInvolvementByHeading(items) {
3312
3985
  }
3313
3986
  return groups;
3314
3987
  }
3315
- function maxGraphemes(max) {
3316
- return (value) => {
3317
- const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
3318
- let count = 0;
3319
- for (const _ of segmenter.segment(value)) {
3320
- count++;
3321
- if (count > max) return false;
3322
- }
3323
- return true;
3324
- };
3325
- }
3326
- var didSchema = zod.z.string().regex(/^did:[a-z]+:[a-zA-Z0-9._:%-]+$/, "Invalid DID");
3327
- var datetimeSchema = zod.z.string().datetime({ offset: true });
3328
- var partialDateSchema = zod.z.string().regex(/^\d{4}(-\d{2}(-\d{2}(T.+)?)?)?$/, "Expected YYYY, YYYY-MM, YYYY-MM-DD, or a datetime");
3329
- var atUriSchema = zod.z.string().regex(/^at:\/\/[^\s]+$/, "Invalid AT-URI");
3330
- var cidSchema = zod.z.string().regex(/^(Qm[1-9A-HJ-NP-Za-km-z]{44}|b[A-Za-z0-9+/=]+)$/, "Invalid CID");
3331
- var languageTagSchema = zod.z.string().regex(/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/, "Invalid BCP 47 language tag");
3332
- var uriSchema = zod.z.string().url();
3333
- var strongRefSchema = zod.z.object({
3334
- uri: atUriSchema,
3335
- cid: cidSchema
3336
- });
3337
- var externalRecordRefSchema = zod.z.object({
3338
- uri: atUriSchema,
3339
- cid: cidSchema.optional()
3340
- });
3341
- var selfLabelsSchema = zod.z.object({
3342
- $type: zod.z.literal("com.atproto.label.defs#selfLabels").optional(),
3343
- values: zod.z.array(zod.z.object({ val: zod.z.string() }))
3344
- });
3345
-
3346
- // src/schemas/endorsement-confirmation.ts
3347
3988
  var EndorsementConfirmationRecordSchema = zod.z.object({
3348
3989
  endorsement: strongRefSchema,
3349
3990
  createdAt: datetimeSchema
@@ -3738,7 +4379,7 @@ var ProfileVolunteeringRecordSchema = zod.z.object({
3738
4379
  });
3739
4380
 
3740
4381
  // src/index.ts
3741
- var SIFA_SDK_VERSION = "0.12.9";
4382
+ var SIFA_SDK_VERSION = "0.12.11";
3742
4383
 
3743
4384
  exports.ACTIVITY_TIERS = ACTIVITY_TIERS;
3744
4385
  exports.ACTIVITY_VERBS = ACTIVITY_VERBS;
@@ -3957,11 +4598,14 @@ exports.sortLanguagesByProficiency = sortLanguagesByProficiency;
3957
4598
  exports.sortPositions = sortPositions;
3958
4599
  exports.sortProjects = sortProjects;
3959
4600
  exports.sortPublications = sortPublications;
4601
+ exports.streamAddressSchema = streamAddressSchema;
3960
4602
  exports.streamCardBodySchema = streamCardBodySchema;
3961
4603
  exports.streamCardSubjectSchema = streamCardSubjectSchema;
3962
4604
  exports.streamCardVMSchema = streamCardVMSchema;
3963
4605
  exports.streamExternalLinkSchema = streamExternalLinkSchema;
4606
+ exports.streamGeoSchema = streamGeoSchema;
3964
4607
  exports.streamMediaSchema = streamMediaSchema;
4608
+ exports.streamRichSegmentSchema = streamRichSegmentSchema;
3965
4609
  exports.streamSourceSchema = streamSourceSchema;
3966
4610
  exports.streamThemeSchema = streamThemeSchema;
3967
4611
  exports.streamVerbSchema = streamVerbSchema;