@segmentstream/app 0.0.0-stage → 0.38.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 (125) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +1236 -2
  4. package/dist/agent.d.ts +56 -0
  5. package/dist/agent.js +203 -0
  6. package/dist/app.d.ts +82 -0
  7. package/dist/app.js +434 -0
  8. package/dist/browser-auth-capability.d.ts +2 -0
  9. package/dist/browser-auth-capability.js +2 -0
  10. package/dist/browser-revision.d.ts +19 -0
  11. package/dist/browser-revision.js +140 -0
  12. package/dist/channel-protocol.d.ts +16 -0
  13. package/dist/channel-protocol.js +17 -0
  14. package/dist/channel-session.d.ts +22 -0
  15. package/dist/channel-session.js +89 -0
  16. package/dist/config.d.ts +53 -0
  17. package/dist/config.js +112 -0
  18. package/dist/context.d.ts +10 -0
  19. package/dist/context.js +1 -0
  20. package/dist/cookies.d.ts +56 -0
  21. package/dist/cookies.js +131 -0
  22. package/dist/data.d.ts +233 -0
  23. package/dist/data.js +206 -0
  24. package/dist/decision-pages.d.ts +14 -0
  25. package/dist/decision-pages.js +87 -0
  26. package/dist/deployment.d.ts +30 -0
  27. package/dist/deployment.js +72 -0
  28. package/dist/errors.d.ts +60 -0
  29. package/dist/errors.js +123 -0
  30. package/dist/federation.d.ts +24 -0
  31. package/dist/federation.js +613 -0
  32. package/dist/groups.d.ts +95 -0
  33. package/dist/groups.js +280 -0
  34. package/dist/handlers.d.ts +10 -0
  35. package/dist/handlers.js +161 -0
  36. package/dist/index.d.ts +46 -0
  37. package/dist/index.js +29 -0
  38. package/dist/jobs.d.ts +49 -0
  39. package/dist/jobs.js +40 -0
  40. package/dist/legacy.d.ts +77 -0
  41. package/dist/legacy.js +57 -0
  42. package/dist/logo.d.ts +1 -0
  43. package/dist/logo.js +25 -0
  44. package/dist/me.d.ts +42 -0
  45. package/dist/me.js +54 -0
  46. package/dist/navigation/build.d.ts +68 -0
  47. package/dist/navigation/build.js +290 -0
  48. package/dist/navigation/cli.d.ts +19 -0
  49. package/dist/navigation/cli.js +37 -0
  50. package/dist/navigation/generate.d.ts +43 -0
  51. package/dist/navigation/generate.js +138 -0
  52. package/dist/navigation/next.d.ts +10 -0
  53. package/dist/navigation/next.js +18 -0
  54. package/dist/navigation-protocol.d.ts +55 -0
  55. package/dist/navigation-protocol.js +298 -0
  56. package/dist/neon.d.ts +101 -0
  57. package/dist/neon.js +539 -0
  58. package/dist/oauth-completion.d.ts +6 -0
  59. package/dist/oauth-completion.js +106 -0
  60. package/dist/oauth.d.ts +59 -0
  61. package/dist/oauth.js +129 -0
  62. package/dist/ontology-names.d.ts +10 -0
  63. package/dist/ontology-names.js +38 -0
  64. package/dist/ontology-transport.d.ts +34 -0
  65. package/dist/ontology-transport.js +130 -0
  66. package/dist/ontology-wire.d.ts +66 -0
  67. package/dist/ontology-wire.js +355 -0
  68. package/dist/ontology.d.ts +381 -0
  69. package/dist/ontology.js +367 -0
  70. package/dist/pages.d.ts +6 -0
  71. package/dist/pages.js +6 -0
  72. package/dist/parameters.d.ts +55 -0
  73. package/dist/parameters.js +118 -0
  74. package/dist/permissions.d.ts +19 -0
  75. package/dist/permissions.js +55 -0
  76. package/dist/pkce.d.ts +8 -0
  77. package/dist/pkce.js +40 -0
  78. package/dist/proxy.d.ts +25 -0
  79. package/dist/proxy.js +135 -0
  80. package/dist/request-timing.d.ts +6 -0
  81. package/dist/request-timing.js +53 -0
  82. package/dist/return-to.d.ts +2 -0
  83. package/dist/return-to.js +24 -0
  84. package/dist/server.d.ts +11 -0
  85. package/dist/server.js +80 -0
  86. package/dist/sessions.d.ts +27 -0
  87. package/dist/sessions.js +72 -0
  88. package/dist/sign-in.d.ts +37 -0
  89. package/dist/sign-in.js +95 -0
  90. package/dist/storage.d.ts +79 -0
  91. package/dist/storage.js +180 -0
  92. package/dist/telegram-launch.d.ts +7 -0
  93. package/dist/telegram-launch.js +134 -0
  94. package/dist/telegram.d.ts +2 -0
  95. package/dist/telegram.js +6 -0
  96. package/dist/tokens.d.ts +51 -0
  97. package/dist/tokens.js +70 -0
  98. package/dist/ui/agent-connect.d.ts +18 -0
  99. package/dist/ui/agent-connect.js +23 -0
  100. package/dist/ui/components.d.ts +27 -0
  101. package/dist/ui/components.js +71 -0
  102. package/dist/ui/hooks.d.ts +19 -0
  103. package/dist/ui/hooks.js +56 -0
  104. package/dist/ui/index.d.ts +22 -0
  105. package/dist/ui/index.js +15 -0
  106. package/dist/ui/navigation.d.ts +5 -0
  107. package/dist/ui/navigation.js +8 -0
  108. package/dist/ui/segmentstream-logo.d.ts +2 -0
  109. package/dist/ui/segmentstream-logo.js +7 -0
  110. package/dist/ui/sign-in-check.d.ts +14 -0
  111. package/dist/ui/sign-in-check.js +41 -0
  112. package/dist/ui/sign-in.d.ts +17 -0
  113. package/dist/ui/sign-in.js +65 -0
  114. package/dist/ui/store.d.ts +80 -0
  115. package/dist/ui/store.js +280 -0
  116. package/dist/ui/styles.css +249 -0
  117. package/dist/ui/telegram-sign-in.d.ts +16 -0
  118. package/dist/ui/telegram-sign-in.js +21 -0
  119. package/dist/ui/use-browser-sign-in.d.ts +52 -0
  120. package/dist/ui/use-browser-sign-in.js +169 -0
  121. package/dist/ui/use-channel-sign-in.d.ts +10 -0
  122. package/dist/ui/use-channel-sign-in.js +118 -0
  123. package/dist/ui/use-sign-in.d.ts +109 -0
  124. package/dist/ui/use-sign-in.js +304 -0
  125. package/package.json +95 -4
@@ -0,0 +1,60 @@
1
+ /** One problem with a request's input, as the ontology service reports it. */
2
+ export interface ApiIssue {
3
+ readonly path: ReadonlyArray<string | number>;
4
+ readonly message: string;
5
+ }
6
+ /** Structured platform limits; workspace clients choose their own user-facing wording. */
7
+ export type ApiLimit = {
8
+ readonly kind: "storage_quota";
9
+ readonly usedBytes: number;
10
+ readonly requestedBytes: number;
11
+ readonly quotaBytes: number;
12
+ } | {
13
+ readonly kind: "pending_uploads";
14
+ readonly pending: number;
15
+ readonly max: number;
16
+ readonly uploads?: ReadonlyArray<{
17
+ readonly id: string;
18
+ readonly filename: string;
19
+ readonly expiresAt: string;
20
+ }>;
21
+ } | {
22
+ readonly kind: "member_attachments";
23
+ readonly live: number;
24
+ readonly max: number;
25
+ };
26
+ /**
27
+ * A failed SegmentStream or ontology request; `code` is the API error code, such as `not_invited`,
28
+ * `forbidden`, `action_rejected` or `query_timeout`.
29
+ */
30
+ export declare class SegmentStreamApiError extends Error {
31
+ readonly code: string;
32
+ readonly status: number;
33
+ readonly detail: string;
34
+ readonly requestId: string | undefined;
35
+ readonly retryable: boolean;
36
+ /** The warehouse query this error concerns, when one was started. */
37
+ readonly queryId: string | undefined;
38
+ /** What was wrong with the input, for `invalid_request`, `invalid_input` and `action_rejected`. */
39
+ readonly issues: ReadonlyArray<ApiIssue>;
40
+ readonly limit: ApiLimit | undefined;
41
+ constructor(input: {
42
+ readonly code: string;
43
+ readonly status: number;
44
+ readonly detail: string;
45
+ readonly requestId?: string | undefined;
46
+ readonly retryable?: boolean;
47
+ readonly queryId?: string | undefined;
48
+ readonly issues?: ReadonlyArray<ApiIssue>;
49
+ readonly limit?: ApiLimit | undefined;
50
+ /** The underlying failure, kept for server logs. */
51
+ readonly cause?: unknown;
52
+ });
53
+ }
54
+ /** The person signed in, but the ontology has no member row for them. */
55
+ export declare const NOT_INVITED = "not_invited";
56
+ /** An emailed sign-in link that Neon Auth rejected: expired, already used or unknown. */
57
+ export declare const SIGN_IN_LINK_INVALID = "sign_in_link_invalid";
58
+ /** The error body of a failed response: `{ error, detail, requestId, issues? }`. */
59
+ export declare function apiErrorFrom(status: number, payload: unknown, fallbackDetail: string): SegmentStreamApiError;
60
+ export declare function readJson(response: Response): Promise<unknown>;
package/dist/errors.js ADDED
@@ -0,0 +1,123 @@
1
+ /**
2
+ * A failed SegmentStream or ontology request; `code` is the API error code, such as `not_invited`,
3
+ * `forbidden`, `action_rejected` or `query_timeout`.
4
+ */
5
+ export class SegmentStreamApiError extends Error {
6
+ code;
7
+ status;
8
+ detail;
9
+ requestId;
10
+ retryable;
11
+ /** The warehouse query this error concerns, when one was started. */
12
+ queryId;
13
+ /** What was wrong with the input, for `invalid_request`, `invalid_input` and `action_rejected`. */
14
+ issues;
15
+ limit;
16
+ constructor(input) {
17
+ super(`${input.detail} (${input.code})`, input.cause === undefined ? undefined : { cause: input.cause });
18
+ this.name = "SegmentStreamApiError";
19
+ this.code = input.code;
20
+ this.status = input.status;
21
+ this.detail = input.detail;
22
+ this.requestId = input.requestId;
23
+ this.retryable = input.retryable ?? false;
24
+ this.queryId = input.queryId;
25
+ this.issues = input.issues ?? [];
26
+ this.limit = input.limit;
27
+ }
28
+ }
29
+ /** The person signed in, but the ontology has no member row for them. */
30
+ export const NOT_INVITED = "not_invited";
31
+ /** An emailed sign-in link that Neon Auth rejected: expired, already used or unknown. */
32
+ export const SIGN_IN_LINK_INVALID = "sign_in_link_invalid";
33
+ /** The error body of a failed response: `{ error, detail, requestId, issues? }`. */
34
+ export function apiErrorFrom(status, payload, fallbackDetail) {
35
+ const body = typeof payload === "object" && payload !== null ? payload : {};
36
+ return new SegmentStreamApiError({
37
+ code: typeof body.error === "string" ? body.error : `http_${status}`,
38
+ status,
39
+ detail: typeof body.detail === "string" ? body.detail : fallbackDetail,
40
+ requestId: typeof body.request_id === "string"
41
+ ? body.request_id
42
+ : typeof body.requestId === "string"
43
+ ? body.requestId
44
+ : undefined,
45
+ retryable: typeof body.retryable === "boolean" ? body.retryable : status >= 500 || status === 429,
46
+ issues: issuesFrom(body.issues),
47
+ limit: limitFrom(body.limit),
48
+ });
49
+ }
50
+ function limitFrom(value) {
51
+ if (typeof value !== "object" || value === null) {
52
+ return undefined;
53
+ }
54
+ const limit = value;
55
+ const count = (key) => {
56
+ const candidate = limit[key];
57
+ return typeof candidate === "number" && Number.isSafeInteger(candidate) && candidate >= 0
58
+ ? candidate
59
+ : undefined;
60
+ };
61
+ const max = count("max");
62
+ if (limit.kind === "storage_quota") {
63
+ const usedBytes = count("used_bytes");
64
+ const requestedBytes = count("requested_bytes");
65
+ const quotaBytes = count("quota_bytes");
66
+ return usedBytes !== undefined && requestedBytes !== undefined && quotaBytes !== undefined
67
+ ? { kind: "storage_quota", usedBytes, requestedBytes, quotaBytes }
68
+ : undefined;
69
+ }
70
+ if (limit.kind === "member_attachments") {
71
+ const live = count("live");
72
+ return live !== undefined && max !== undefined
73
+ ? { kind: "member_attachments", live, max }
74
+ : undefined;
75
+ }
76
+ if (limit.kind === "pending_uploads") {
77
+ const pending = count("pending");
78
+ if (pending === undefined || max === undefined) {
79
+ return undefined;
80
+ }
81
+ const uploads = Array.isArray(limit.uploads)
82
+ ? limit.uploads.flatMap((item) => {
83
+ if (typeof item !== "object" || item === null) {
84
+ return [];
85
+ }
86
+ const upload = item;
87
+ return typeof upload.id === "string" &&
88
+ typeof upload.filename === "string" &&
89
+ typeof upload.expires_at === "string"
90
+ ? [{ id: upload.id, filename: upload.filename, expiresAt: upload.expires_at }]
91
+ : [];
92
+ })
93
+ : undefined;
94
+ return { kind: "pending_uploads", pending, max, ...(uploads ? { uploads } : {}) };
95
+ }
96
+ return undefined;
97
+ }
98
+ function issuesFrom(value) {
99
+ if (!Array.isArray(value)) {
100
+ return [];
101
+ }
102
+ return value.flatMap((candidate) => {
103
+ if (typeof candidate !== "object" || candidate === null) {
104
+ return [];
105
+ }
106
+ const { path, message } = candidate;
107
+ if (typeof message !== "string") {
108
+ return [];
109
+ }
110
+ const segments = Array.isArray(path)
111
+ ? path.filter((segment) => typeof segment === "string" || typeof segment === "number")
112
+ : [];
113
+ return [{ path: segments, message }];
114
+ });
115
+ }
116
+ export async function readJson(response) {
117
+ try {
118
+ return await response.json();
119
+ }
120
+ catch {
121
+ return null;
122
+ }
123
+ }
@@ -0,0 +1,24 @@
1
+ import { type BrowserRevision } from "./browser-revision.js";
2
+ import type { SegmentStreamApp } from "./app.js";
3
+ import type { BrowserAuthBinding, ResolvedConfig } from "./config.js";
4
+ import { type OntologyTransport } from "./ontology.js";
5
+ import type { Fetch } from "./sessions.js";
6
+ import type { AppUser } from "./tokens.js";
7
+ /** Public-client RP. Only workspace-owned opaque sessions are stored in its session cookie. */
8
+ export declare function withFederation<O>(base: SegmentStreamApp<O>, config: ResolvedConfig, oidc: {
9
+ issuer: string;
10
+ clientId: string;
11
+ }, options: {
12
+ fetch: Fetch;
13
+ ontologyUrl?: string;
14
+ neon: boolean;
15
+ browserAuth?: BrowserAuthBinding;
16
+ browserRevision?: BrowserRevision;
17
+ proofTransport?: OntologyTransport;
18
+ identityToken?: () => Promise<string | null>;
19
+ channelSession?: {
20
+ readonly getUser: () => Promise<AppUser | null>;
21
+ readonly signOut: () => Promise<void>;
22
+ readonly transport: OntologyTransport;
23
+ };
24
+ }): SegmentStreamApp<O>;