@antiphony/shared 0.1.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/dist/cjs/api-codecs.cjs +971 -0
  4. package/dist/cjs/api-codecs.d.cts +542 -0
  5. package/dist/cjs/errors/index.cjs +56 -0
  6. package/dist/cjs/errors/index.d.cts +45 -0
  7. package/dist/cjs/index.cjs +1276 -0
  8. package/dist/cjs/index.d.cts +11 -0
  9. package/dist/cjs/nsid.cjs +37 -0
  10. package/dist/cjs/nsid.d.cts +42 -0
  11. package/dist/cjs/observability/index.cjs +58 -0
  12. package/dist/cjs/observability/index.d.cts +1 -0
  13. package/dist/cjs/observability/report-error.cjs +58 -0
  14. package/dist/cjs/observability/report-error.d.cts +48 -0
  15. package/dist/cjs/types/api.cjs +726 -0
  16. package/dist/cjs/types/api.d.cts +494 -0
  17. package/dist/cjs/types/audio.cjs +835 -0
  18. package/dist/cjs/types/audio.d.cts +1149 -0
  19. package/dist/cjs/types/blob.cjs +23 -0
  20. package/dist/cjs/types/blob.d.cts +45 -0
  21. package/dist/cjs/types/channels.cjs +170 -0
  22. package/dist/cjs/types/channels.d.cts +262 -0
  23. package/dist/cjs/types/records.cjs +407 -0
  24. package/dist/cjs/types/records.d.cts +840 -0
  25. package/dist/cjs/types/storage.cjs +414 -0
  26. package/dist/cjs/types/storage.d.cts +197 -0
  27. package/dist/cjs/types/views.cjs +820 -0
  28. package/dist/cjs/types/views.d.cts +9806 -0
  29. package/dist/cjs/utils/index.cjs +8 -0
  30. package/dist/cjs/utils/index.d.cts +7 -0
  31. package/dist/esm/api-codecs.d.ts +542 -0
  32. package/dist/esm/api-codecs.js +6 -0
  33. package/dist/esm/chunk-24KIXQZK.js +6 -0
  34. package/dist/esm/chunk-3WZJXJNU.js +378 -0
  35. package/dist/esm/chunk-5EHV73BA.js +20 -0
  36. package/dist/esm/chunk-72G3LBUQ.js +1 -0
  37. package/dist/esm/chunk-7LW2FHLD.js +48 -0
  38. package/dist/esm/chunk-7V44CPRR.js +132 -0
  39. package/dist/esm/chunk-BUNMR4ZO.js +127 -0
  40. package/dist/esm/chunk-EA4OONDV.js +380 -0
  41. package/dist/esm/chunk-F2CANZZ7.js +40 -0
  42. package/dist/esm/chunk-ORMEWXMH.js +33 -0
  43. package/dist/esm/chunk-TIZRJORN.js +24 -0
  44. package/dist/esm/chunk-XDBKR6LW.js +32 -0
  45. package/dist/esm/errors/index.d.ts +45 -0
  46. package/dist/esm/errors/index.js +2 -0
  47. package/dist/esm/index.d.ts +11 -0
  48. package/dist/esm/index.js +12 -0
  49. package/dist/esm/nsid.d.ts +42 -0
  50. package/dist/esm/nsid.js +2 -0
  51. package/dist/esm/observability/index.d.ts +1 -0
  52. package/dist/esm/observability/index.js +3 -0
  53. package/dist/esm/observability/report-error.d.ts +48 -0
  54. package/dist/esm/observability/report-error.js +2 -0
  55. package/dist/esm/types/api.d.ts +494 -0
  56. package/dist/esm/types/api.js +5 -0
  57. package/dist/esm/types/audio.d.ts +1149 -0
  58. package/dist/esm/types/audio.js +5 -0
  59. package/dist/esm/types/blob.d.ts +45 -0
  60. package/dist/esm/types/blob.js +2 -0
  61. package/dist/esm/types/channels.d.ts +262 -0
  62. package/dist/esm/types/channels.js +162 -0
  63. package/dist/esm/types/records.d.ts +840 -0
  64. package/dist/esm/types/records.js +3 -0
  65. package/dist/esm/types/storage.d.ts +197 -0
  66. package/dist/esm/types/storage.js +26 -0
  67. package/dist/esm/types/views.d.ts +9806 -0
  68. package/dist/esm/types/views.js +4 -0
  69. package/dist/esm/utils/index.d.ts +7 -0
  70. package/dist/esm/utils/index.js +2 -0
  71. package/package.json +82 -0
@@ -0,0 +1,11 @@
1
+ export { BadgeResetRequestSchema, BulkReplyActionRequestSchema, ConnectorConfigInputSchema, ConnectorConfigUpdateSchema, CreateAudioPostRequest, CreateAudioPostRequestSchema, CreateOrgInviteRequestSchema, CreateOrgRequestSchema, CreatePromptRequestSchema, FcmTokenRequestSchema, PersonMergeRequestSchema, PersonNotesUpdateSchema, ScreeningRuleInputSchema, ScreeningRuleUpdateSchema, SwitchOrgRequestSchema, UpdateMemberRoleRequestSchema, UpdateOrgRequestSchema, UpdateProfileRequestSchema, UpdateReplyStatusRequestSchema } from './api-codecs.cjs';
2
+ export { CallForwardingConfig, CallForwardingConfigSchema, ConnectorConfigRecord, ConnectorConfigRecordSchema, ConnectorStatus, ConnectorStatusSchema, ConnectorType, ConnectorTypeSchema, FirestoreTimestamp, FirestoreTimestampSchema, OrgInviteRecord, OrgInviteRecordSchema, OrganizationMemberRecord, OrganizationMemberRecordSchema, OrganizationRecord, OrganizationRecordSchema, PersonEnrichmentRecord, PersonEnrichmentRecordSchema, PromptRecord, PromptRecordSchema, ReplyEnrichmentRecord, ReplyEnrichmentRecordSchema, ReplyRecord, ReplyRecordSchema, ScreeningRuleRecord, ScreeningRuleRecordSchema, SipEnrichment, SipEnrichmentSchema, UserRecord, UserRecordSchema, httpsUrl } from './types/records.cjs';
3
+ export { ContactCrmData, EnrichedReplier, EnrichedReplierSchema, HandleResolution, HandleResolutionSchema, OrgInviteView, OrgInviteViewSchema, OrgProfileData, OrgProfileDataSchema, OrganizationMemberView, OrganizationMemberViewSchema, OrganizationView, OrganizationViewSchema, ProfileView, ProfileViewAdmin, ProfileViewAdminSchema, ProfileViewBasic, ProfileViewBasicSchema, ProfileViewDetailed, ProfileViewDetailedSchema, ProfileViewSchema, ProfileViewSelf, ProfileViewSelfSchema, PromptRepliers, PromptRepliersSchema, PromptView, PromptViewPublic, PromptViewPublicSchema, PromptViewSchema, PromptWithReplies, PromptWithRepliesSchema, Replier, ReplierSchema, ReplyView, ReplyViewPublic, ReplyViewPublicSchema, ReplyViewSchema, RssSummary, RssSummarySchema, UserProfileData, UserProfileDataSchema, VoxPopEmbedWidgetProps, toProfileViewBasic, toPromptViewPublic, toReplyViewPublic } from './types/views.cjs';
4
+ export { ActorProfileRecord, ActorProfileRecordSchema, AudioEmbed, AudioEmbedSchema, AudioEmbedView, AudioEmbedViewSchema, AudioPostRecord, AudioPostRecordSchema, AudioPostView, AudioPostViewSchema, PostRecordPublic, PostRecordPublicSchema, ReplyRef, ReplyRefSchema, StrongRef, StrongRefSchema, TimedTranscript, TimedTranscriptSchema, TranscriptEnrichmentRecord, TranscriptEnrichmentRecordSchema, TranscriptSegment, TranscriptSegmentSchema, ViewerState, ViewerStateSchema } from './types/audio.cjs';
5
+ export { BlobRef, BlobRefSchema, resolveAudioUrl } from './types/blob.cjs';
6
+ export { ActorView, ActorViewSchema, PublicProfileDto, PublicProfileDtoSchema, PublicReplyDto, PublicReplyDtoSchema } from './types/api.cjs';
7
+ export { COLLECTIONS, EMBED_NSID, NSID, NsidValue, nsidForCollection } from './nsid.cjs';
8
+ export { ConflictError, ForbiddenError, NotFoundError, RateLimitError, ServiceError, UnauthorizedError, ValidationError } from './errors/index.cjs';
9
+ export { isFirestoreTimestamp } from './utils/index.cjs';
10
+ export { ReportedErrorEvent, buildReportedErrorEvent, reportError } from './observability/report-error.cjs';
11
+ import 'zod';
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ // nsid.ts
4
+ var NSID = {
5
+ // Legacy Vox Pop record types (deprecated; removed in Stream 4).
6
+ Prompt: "com.voxpop.audio.prompt",
7
+ Reply: "com.voxpop.audio.reply",
8
+ Profile: "com.voxpop.actor.profile",
9
+ // Antiphony canonical record types (dev.antiphony.*). Added additively in
10
+ // Stream 1; see lexicons/dev/antiphony/ + packages/shared/types/audio.ts.
11
+ AudioPost: "dev.antiphony.audio.post",
12
+ AudioTranscript: "dev.antiphony.audio.transcript",
13
+ ActorProfile: "dev.antiphony.actor.profile"
14
+ };
15
+ var EMBED_NSID = {
16
+ Audio: "dev.antiphony.embed.audio",
17
+ RecordWithAudio: "dev.antiphony.embed.recordWithAudio"
18
+ };
19
+ var COLLECTIONS = {
20
+ [NSID.Prompt]: "prompts",
21
+ [NSID.Reply]: "replies",
22
+ [NSID.Profile]: "users",
23
+ // Antiphony: one post collection + the transcript enrichment namespace.
24
+ [NSID.AudioPost]: "posts",
25
+ [NSID.AudioTranscript]: "audio_transcripts",
26
+ [NSID.ActorProfile]: "users"
27
+ };
28
+ function nsidForCollection(collection) {
29
+ const entries = Object.entries(COLLECTIONS);
30
+ const match = entries.find(([, col]) => col === collection);
31
+ return match == null ? void 0 : match[0];
32
+ }
33
+
34
+ exports.COLLECTIONS = COLLECTIONS;
35
+ exports.EMBED_NSID = EMBED_NSID;
36
+ exports.NSID = NSID;
37
+ exports.nsidForCollection = nsidForCollection;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * AT Protocol Namespaced Identifiers (NSIDs) for Vox Pop record types.
3
+ *
4
+ * NSIDs are the canonical way to identify record types in AT Protocol.
5
+ * This mapping connects AT Protocol NSIDs to Firestore collection names,
6
+ * creating a single source of truth for the relationship.
7
+ *
8
+ * @see https://atproto.com/specs/nsid
9
+ */
10
+ declare const NSID: {
11
+ readonly Prompt: "com.voxpop.audio.prompt";
12
+ readonly Reply: "com.voxpop.audio.reply";
13
+ readonly Profile: "com.voxpop.actor.profile";
14
+ readonly AudioPost: "dev.antiphony.audio.post";
15
+ readonly AudioTranscript: "dev.antiphony.audio.transcript";
16
+ readonly ActorProfile: "dev.antiphony.actor.profile";
17
+ };
18
+ type NsidValue = typeof NSID[keyof typeof NSID];
19
+ /**
20
+ * Antiphony embed NSIDs. Embeds live inline on a post's `embed` field, not in
21
+ * their own collection — kept out of `NSID`/`COLLECTIONS`.
22
+ */
23
+ declare const EMBED_NSID: {
24
+ readonly Audio: "dev.antiphony.embed.audio";
25
+ readonly RecordWithAudio: "dev.antiphony.embed.recordWithAudio";
26
+ };
27
+ /**
28
+ * Maps AT Protocol record-type NSIDs to Firestore collection names.
29
+ * When migrating to a PDS, this mapping becomes the adapter layer.
30
+ *
31
+ * Note: `dev.antiphony.actor.profile` and the legacy `com.voxpop.actor.profile`
32
+ * both map to `users`. `nsidForCollection('users')` returns the legacy NSID
33
+ * (listed first) — preserving today's reverse-lookup behavior until Stream 4
34
+ * removes the legacy entry.
35
+ */
36
+ declare const COLLECTIONS: Record<NsidValue, string>;
37
+ /**
38
+ * Reverse lookup: get the NSID for a Firestore collection name.
39
+ */
40
+ declare function nsidForCollection(collection: string): NsidValue | undefined;
41
+
42
+ export { COLLECTIONS, EMBED_NSID, NSID, type NsidValue, nsidForCollection };
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+
20
+ // observability/report-error.ts
21
+ var REPORTED_ERROR_EVENT_TYPE = "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent";
22
+ function serviceName() {
23
+ var _a, _b;
24
+ return (_b = (_a = process.env.K_SERVICE) != null ? _a : process.env.SERVICE_NAME) != null ? _b : "unknown";
25
+ }
26
+ function serviceVersion() {
27
+ var _a, _b;
28
+ return (_b = (_a = process.env.COMMIT_SHA) != null ? _a : process.env.K_REVISION) != null ? _b : "dev";
29
+ }
30
+ function formatUnknownError(err) {
31
+ var _a;
32
+ if (typeof err === "string") return err;
33
+ try {
34
+ return (_a = JSON.stringify(err)) != null ? _a : String(err);
35
+ } catch (e) {
36
+ return String(err);
37
+ }
38
+ }
39
+ function buildReportedErrorEvent(err, context) {
40
+ var _a;
41
+ const error = err instanceof Error ? err : new Error(formatUnknownError(err));
42
+ const message = (_a = error.stack) != null ? _a : `${error.name}: ${error.message}`;
43
+ return __spreadValues({
44
+ severity: "ERROR",
45
+ "@type": REPORTED_ERROR_EVENT_TYPE,
46
+ message,
47
+ serviceContext: { service: serviceName(), version: serviceVersion() }
48
+ }, context && Object.keys(context).length > 0 ? { context } : {});
49
+ }
50
+ function reportError(err, context) {
51
+ try {
52
+ console.error(JSON.stringify(buildReportedErrorEvent(err, context)));
53
+ } catch (e) {
54
+ }
55
+ }
56
+
57
+ exports.buildReportedErrorEvent = buildReportedErrorEvent;
58
+ exports.reportError = reportError;
@@ -0,0 +1 @@
1
+ export { ReportedErrorEvent, buildReportedErrorEvent, reportError } from './report-error.cjs';
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+
20
+ // observability/report-error.ts
21
+ var REPORTED_ERROR_EVENT_TYPE = "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent";
22
+ function serviceName() {
23
+ var _a, _b;
24
+ return (_b = (_a = process.env.K_SERVICE) != null ? _a : process.env.SERVICE_NAME) != null ? _b : "unknown";
25
+ }
26
+ function serviceVersion() {
27
+ var _a, _b;
28
+ return (_b = (_a = process.env.COMMIT_SHA) != null ? _a : process.env.K_REVISION) != null ? _b : "dev";
29
+ }
30
+ function formatUnknownError(err) {
31
+ var _a;
32
+ if (typeof err === "string") return err;
33
+ try {
34
+ return (_a = JSON.stringify(err)) != null ? _a : String(err);
35
+ } catch (e) {
36
+ return String(err);
37
+ }
38
+ }
39
+ function buildReportedErrorEvent(err, context) {
40
+ var _a;
41
+ const error = err instanceof Error ? err : new Error(formatUnknownError(err));
42
+ const message = (_a = error.stack) != null ? _a : `${error.name}: ${error.message}`;
43
+ return __spreadValues({
44
+ severity: "ERROR",
45
+ "@type": REPORTED_ERROR_EVENT_TYPE,
46
+ message,
47
+ serviceContext: { service: serviceName(), version: serviceVersion() }
48
+ }, context && Object.keys(context).length > 0 ? { context } : {});
49
+ }
50
+ function reportError(err, context) {
51
+ try {
52
+ console.error(JSON.stringify(buildReportedErrorEvent(err, context)));
53
+ } catch (e) {
54
+ }
55
+ }
56
+
57
+ exports.buildReportedErrorEvent = buildReportedErrorEvent;
58
+ exports.reportError = reportError;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * GCP Cloud Error Reporting integration — log-based, dependency-free.
3
+ *
4
+ * Cloud Error Reporting auto-ingests Cloud Logging entries shaped as a
5
+ * `ReportedErrorEvent`. On Firebase App Hosting (Cloud Run), single-line JSON
6
+ * written to stderr lands in Cloud Logging automatically — so emitting a
7
+ * correctly-shaped line is all it takes to surface a grouped, deduplicated
8
+ * error in the Error Reporting console. No SDK, no auth, no secrets (the
9
+ * `@google-cloud/error-reporting` library would add a gRPC client + cold-start
10
+ * weight + credential config for the same outcome on serverless).
11
+ *
12
+ * See https://cloud.google.com/error-reporting/docs/formatting-error-messages
13
+ *
14
+ * Grouping rules we satisfy:
15
+ * - `severity` must be ERROR or higher.
16
+ * - `message` must contain a full stack trace (that's what Error Reporting
17
+ * fingerprints on); we fall back to "name: message" when no stack exists,
18
+ * which still surfaces, just grouped less precisely.
19
+ * - `serviceContext.service` separates errors per deployable
20
+ * (core-api / web / public), so each app's errors are tracked apart.
21
+ *
22
+ * This module only ever *runs* from server code (core-api error-handler,
23
+ * Next instrumentation hooks, /api/client-error route handlers). It has no
24
+ * Node-only or heavy imports, so it stays safe to live in the shared package.
25
+ */
26
+ interface ReportedErrorEvent {
27
+ severity: 'ERROR';
28
+ '@type': string;
29
+ message: string;
30
+ serviceContext: {
31
+ service: string;
32
+ version: string;
33
+ };
34
+ context?: Record<string, unknown>;
35
+ }
36
+ /**
37
+ * Build the `ReportedErrorEvent` payload. Exported for unit testing; most
38
+ * callers want `reportError` instead.
39
+ */
40
+ declare function buildReportedErrorEvent(err: unknown, context?: Record<string, unknown>): ReportedErrorEvent;
41
+ /**
42
+ * Report an error to GCP Error Reporting by emitting a single-line
43
+ * ReportedErrorEvent to stderr. Best-effort and total — a failure inside the
44
+ * reporter is swallowed so it can never mask the original error.
45
+ */
46
+ declare function reportError(err: unknown, context?: Record<string, unknown>): void;
47
+
48
+ export { type ReportedErrorEvent, buildReportedErrorEvent, reportError };