@lobu/connector-sdk 6.0.1

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 (93) hide show
  1. package/dist/api-paginated.d.ts +79 -0
  2. package/dist/api-paginated.d.ts.map +1 -0
  3. package/dist/api-paginated.js +120 -0
  4. package/dist/api-paginated.js.map +1 -0
  5. package/dist/base.d.ts +66 -0
  6. package/dist/base.d.ts.map +1 -0
  7. package/dist/base.js +122 -0
  8. package/dist/base.js.map +1 -0
  9. package/dist/browser/acquire.d.ts +66 -0
  10. package/dist/browser/acquire.d.ts.map +1 -0
  11. package/dist/browser/acquire.js +109 -0
  12. package/dist/browser/acquire.js.map +1 -0
  13. package/dist/browser/cdp-page.d.ts +48 -0
  14. package/dist/browser/cdp-page.d.ts.map +1 -0
  15. package/dist/browser/cdp-page.js +165 -0
  16. package/dist/browser/cdp-page.js.map +1 -0
  17. package/dist/browser/cdp.d.ts +44 -0
  18. package/dist/browser/cdp.d.ts.map +1 -0
  19. package/dist/browser/cdp.js +252 -0
  20. package/dist/browser/cdp.js.map +1 -0
  21. package/dist/browser/launcher.d.ts +29 -0
  22. package/dist/browser/launcher.d.ts.map +1 -0
  23. package/dist/browser/launcher.js +157 -0
  24. package/dist/browser/launcher.js.map +1 -0
  25. package/dist/browser/stealth.d.ts +55 -0
  26. package/dist/browser/stealth.d.ts.map +1 -0
  27. package/dist/browser/stealth.js +170 -0
  28. package/dist/browser/stealth.js.map +1 -0
  29. package/dist/browser-network.d.ts +51 -0
  30. package/dist/browser-network.d.ts.map +1 -0
  31. package/dist/browser-network.js +175 -0
  32. package/dist/browser-network.js.map +1 -0
  33. package/dist/browser-paginated.d.ts +141 -0
  34. package/dist/browser-paginated.d.ts.map +1 -0
  35. package/dist/browser-paginated.js +269 -0
  36. package/dist/browser-paginated.js.map +1 -0
  37. package/dist/connector-runtime.d.ts +70 -0
  38. package/dist/connector-runtime.d.ts.map +1 -0
  39. package/dist/connector-runtime.js +48 -0
  40. package/dist/connector-runtime.js.map +1 -0
  41. package/dist/connector-types.d.ts +613 -0
  42. package/dist/connector-types.d.ts.map +1 -0
  43. package/dist/connector-types.js +27 -0
  44. package/dist/connector-types.js.map +1 -0
  45. package/dist/event-taxonomy.d.ts +3 -0
  46. package/dist/event-taxonomy.d.ts.map +1 -0
  47. package/dist/event-taxonomy.js +30 -0
  48. package/dist/event-taxonomy.js.map +1 -0
  49. package/dist/http.d.ts +18 -0
  50. package/dist/http.d.ts.map +1 -0
  51. package/dist/http.js +74 -0
  52. package/dist/http.js.map +1 -0
  53. package/dist/identity-normalize.d.ts +53 -0
  54. package/dist/identity-normalize.d.ts.map +1 -0
  55. package/dist/identity-normalize.js +146 -0
  56. package/dist/identity-normalize.js.map +1 -0
  57. package/dist/identity-types.d.ts +214 -0
  58. package/dist/identity-types.d.ts.map +1 -0
  59. package/dist/identity-types.js +217 -0
  60. package/dist/identity-types.js.map +1 -0
  61. package/dist/index.d.ts +37 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +33 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/logger.d.ts +7 -0
  66. package/dist/logger.d.ts.map +1 -0
  67. package/dist/logger.js +10 -0
  68. package/dist/logger.js.map +1 -0
  69. package/dist/paginated.d.ts +93 -0
  70. package/dist/paginated.d.ts.map +1 -0
  71. package/dist/paginated.js +167 -0
  72. package/dist/paginated.js.map +1 -0
  73. package/dist/reaction-sdk.d.ts +43 -0
  74. package/dist/reaction-sdk.d.ts.map +1 -0
  75. package/dist/reaction-sdk.js +9 -0
  76. package/dist/reaction-sdk.js.map +1 -0
  77. package/dist/retry.d.ts +19 -0
  78. package/dist/retry.d.ts.map +1 -0
  79. package/dist/retry.js +131 -0
  80. package/dist/retry.js.map +1 -0
  81. package/dist/scoring.d.ts +17 -0
  82. package/dist/scoring.d.ts.map +1 -0
  83. package/dist/scoring.js +28 -0
  84. package/dist/scoring.js.map +1 -0
  85. package/dist/types.d.ts +280 -0
  86. package/dist/types.d.ts.map +1 -0
  87. package/dist/types.js +2 -0
  88. package/dist/types.js.map +1 -0
  89. package/dist/watcher-time.d.ts +14 -0
  90. package/dist/watcher-time.d.ts.map +1 -0
  91. package/dist/watcher-time.js +112 -0
  92. package/dist/watcher-time.js.map +1 -0
  93. package/package.json +59 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Reaction context types.
3
+ *
4
+ * The runtime SDK reaction scripts call is `ClientSDK` (defined in
5
+ * `packages/server/src/sandbox/client-sdk.ts`); only the context
6
+ * shape is shared across packages, so only those types live here.
7
+ */
8
+ export interface ReactionEntity {
9
+ id: number;
10
+ name: string;
11
+ entity_type: string;
12
+ metadata: Record<string, unknown>;
13
+ }
14
+ /**
15
+ * Context passed to reaction scripts containing the analysis results
16
+ * and metadata about the watcher window. Reaction scripts have the
17
+ * shape `default async (ctx: ReactionContext, client, params?)`.
18
+ */
19
+ export interface ReactionContext {
20
+ /** The extracted analysis data from the completed window */
21
+ extracted_data: Record<string, unknown>;
22
+ /** All entities the watcher is attached to */
23
+ entities: ReactionEntity[];
24
+ /** The window that was just completed */
25
+ window: {
26
+ id: number;
27
+ watcher_id: number;
28
+ window_start: string;
29
+ window_end: string;
30
+ granularity: string;
31
+ content_analyzed: number;
32
+ };
33
+ /** Watcher identity */
34
+ watcher: {
35
+ id: number;
36
+ slug: string;
37
+ name: string;
38
+ version: number;
39
+ };
40
+ /** Organization context */
41
+ organization_id: string;
42
+ }
43
+ //# sourceMappingURL=reaction-sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reaction-sdk.d.ts","sourceRoot":"","sources":["../src/reaction-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,8CAA8C;IAC9C,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,yCAAyC;IACzC,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,uBAAuB;IACvB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,2BAA2B;IAC3B,eAAe,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reaction context types.
3
+ *
4
+ * The runtime SDK reaction scripts call is `ClientSDK` (defined in
5
+ * `packages/server/src/sandbox/client-sdk.ts`); only the context
6
+ * shape is shared across packages, so only those types live here.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=reaction-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reaction-sdk.js","sourceRoot":"","sources":["../src/reaction-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Centralized retry utilities using p-retry
3
+ *
4
+ * Provides retry strategies for HTTP operations (external APIs).
5
+ */
6
+ interface RetryOptions {
7
+ operation?: string;
8
+ context?: Record<string, any>;
9
+ onRetry?: (error: Error, attempt: number) => void;
10
+ }
11
+ /**
12
+ * HTTP retry strategy
13
+ * Exponential backoff with jitter for external API calls
14
+ * - 5 retries
15
+ * - 1s, 2s, 4s, 8s, 16s delays (with jitter)
16
+ */
17
+ export declare function withHttpRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
18
+ export {};
19
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2GH,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACnD;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CA4C/F"}
package/dist/retry.js ADDED
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Centralized retry utilities using p-retry
3
+ *
4
+ * Provides retry strategies for HTTP operations (external APIs).
5
+ */
6
+ import pRetry, { AbortError } from 'p-retry';
7
+ import { sdkLogger } from './logger.js';
8
+ /**
9
+ * Error detection helpers
10
+ */
11
+ function isNetworkError(error) {
12
+ const message = error instanceof Error ? error.message : String(error);
13
+ const lowerMessage = message.toLowerCase();
14
+ const networkKeywords = [
15
+ 'network',
16
+ 'econnrefused',
17
+ 'etimedout',
18
+ 'enotfound',
19
+ 'econnreset',
20
+ 'fetch failed',
21
+ 'socket',
22
+ 'dns',
23
+ ];
24
+ return networkKeywords.some((keyword) => lowerMessage.includes(keyword));
25
+ }
26
+ function isDatabaseError(error) {
27
+ const message = error instanceof Error ? error.message : String(error);
28
+ const lowerMessage = message.toLowerCase();
29
+ const databaseKeywords = [
30
+ 'connection pool',
31
+ 'too many connections',
32
+ 'connection limit',
33
+ 'connection reset',
34
+ 'connection refused',
35
+ 'server closed',
36
+ 'connection terminated',
37
+ 'connection timeout',
38
+ 'deadlock',
39
+ 'lock timeout',
40
+ 'query timeout',
41
+ 'statement timeout',
42
+ 'transaction',
43
+ 'postgres',
44
+ 'postgresql',
45
+ 'pg_',
46
+ 'relation does not exist',
47
+ 'syntax error',
48
+ ];
49
+ return databaseKeywords.some((keyword) => lowerMessage.includes(keyword));
50
+ }
51
+ function isRateLimitError(error) {
52
+ const message = error instanceof Error ? error.message : String(error);
53
+ const lowerMessage = message.toLowerCase();
54
+ return (lowerMessage.includes('rate limit') ||
55
+ lowerMessage.includes('429') ||
56
+ lowerMessage.includes('too many requests'));
57
+ }
58
+ function isServerError(error) {
59
+ const message = error instanceof Error ? error.message : String(error);
60
+ const lowerMessage = message.toLowerCase();
61
+ const serverErrorCodes = ['500', '502', '503', '504'];
62
+ const serverKeywords = ['server error', 'service unavailable', 'gateway timeout'];
63
+ return (serverErrorCodes.some((code) => lowerMessage.includes(code)) ||
64
+ serverKeywords.some((keyword) => lowerMessage.includes(keyword)));
65
+ }
66
+ function isRetryableError(error) {
67
+ return (isNetworkError(error) ||
68
+ isDatabaseError(error) ||
69
+ isRateLimitError(error) ||
70
+ isServerError(error));
71
+ }
72
+ function isPermanentError(error) {
73
+ const message = error instanceof Error ? error.message : String(error);
74
+ const lowerMessage = message.toLowerCase();
75
+ const permanentKeywords = [
76
+ 'not found',
77
+ '404',
78
+ 'unauthorized',
79
+ '401',
80
+ 'forbidden',
81
+ '403',
82
+ 'invalid',
83
+ 'bad request',
84
+ '400',
85
+ ];
86
+ return permanentKeywords.some((keyword) => lowerMessage.includes(keyword));
87
+ }
88
+ /**
89
+ * HTTP retry strategy
90
+ * Exponential backoff with jitter for external API calls
91
+ * - 5 retries
92
+ * - 1s, 2s, 4s, 8s, 16s delays (with jitter)
93
+ */
94
+ export async function withHttpRetry(fn, options) {
95
+ return pRetry(async (_attemptNumber) => {
96
+ try {
97
+ return await fn();
98
+ }
99
+ catch (error) {
100
+ // Abort on permanent errors (404, 401, 403, etc.)
101
+ if (isPermanentError(error)) {
102
+ throw new AbortError(error instanceof Error ? error : new Error(String(error)));
103
+ }
104
+ // Retry on network, rate limit, or server errors
105
+ if (!isRetryableError(error)) {
106
+ throw new AbortError(error instanceof Error ? error : new Error(String(error)));
107
+ }
108
+ throw error;
109
+ }
110
+ }, {
111
+ retries: 5,
112
+ factor: 2,
113
+ minTimeout: 1000,
114
+ maxTimeout: 16000,
115
+ randomize: true,
116
+ onFailedAttempt: (error) => {
117
+ const underlyingError = error;
118
+ if (options?.onRetry) {
119
+ options.onRetry(underlyingError, error.attemptNumber);
120
+ }
121
+ sdkLogger.debug({
122
+ operation: options?.operation || 'HTTP operation',
123
+ attempt: error.attemptNumber,
124
+ retriesLeft: error.retriesLeft,
125
+ error: underlyingError.message || String(underlyingError),
126
+ context: options?.context,
127
+ }, `[Retry:HTTP] Attempt ${error.attemptNumber} failed, ${error.retriesLeft} retries left`);
128
+ },
129
+ });
130
+ }
131
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AAEH,SAAS,cAAc,CAAC,KAAc;IACpC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAE3C,MAAM,eAAe,GAAG;QACtB,SAAS;QACT,cAAc;QACd,WAAW;QACX,WAAW;QACX,YAAY;QACZ,cAAc;QACd,QAAQ;QACR,KAAK;KACN,CAAC;IAEF,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE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CAAC,aAAa,YAAY,KAAK,CAAC,WAAW,eAAe,CACxF,CAAC;QACJ,CAAC;KACF,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Calculate engagement score (0-100) based on engagement data
3
+ * Each connector type has different metrics and scoring logic
4
+ *
5
+ * @param connectorKey - The connector key (reddit, github, google_play, etc.)
6
+ * @param engagementData - Platform-specific engagement metrics
7
+ * @returns Normalized score between 0-100
8
+ */
9
+ export declare function calculateEngagementScore(connectorKey: string, engagementData: {
10
+ score?: number;
11
+ upvotes?: number;
12
+ downvotes?: number;
13
+ rating?: number;
14
+ helpful_count?: number;
15
+ reply_count?: number;
16
+ }): number;
17
+ //# sourceMappingURL=scoring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring.d.ts","sourceRoot":"","sources":["../src/scoring.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GACA,MAAM,CAsBR"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Calculate engagement score (0-100) based on engagement data
3
+ * Each connector type has different metrics and scoring logic
4
+ *
5
+ * @param connectorKey - The connector key (reddit, github, google_play, etc.)
6
+ * @param engagementData - Platform-specific engagement metrics
7
+ * @returns Normalized score between 0-100
8
+ */
9
+ export function calculateEngagementScore(connectorKey, engagementData) {
10
+ if (!engagementData)
11
+ return 0;
12
+ switch (connectorKey) {
13
+ case 'reddit':
14
+ // Reddit: karma score (upvotes - downvotes), normalized to 0-100
15
+ // Max 10000 score = 100 points
16
+ return Math.min(Math.max(engagementData.score || 0, 0), 10000) / 100;
17
+ default: {
18
+ // Generic scoring: combine rating + helpful votes + score
19
+ if (engagementData.rating != null) {
20
+ // Rating-based: rating (1-5) * 10 + helpful votes * 0.5
21
+ return Math.min((engagementData.rating || 0) * 10 + (engagementData.helpful_count || 0) * 0.5, 100);
22
+ }
23
+ // Score-based: use score directly, capped at 100
24
+ return Math.min(engagementData.score || 0, 100);
25
+ }
26
+ }
27
+ }
28
+ //# sourceMappingURL=scoring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoring.js","sourceRoot":"","sources":["../src/scoring.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,YAAoB,EACpB,cAOC;IAED,IAAI,CAAC,cAAc;QAAE,OAAO,CAAC,CAAC;IAE9B,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,iEAAiE;YACjE,+BAA+B;YAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC;QAEvE,OAAO,CAAC,CAAC,CAAC;YACR,0DAA0D;YAC1D,IAAI,cAAc,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBAClC,wDAAwD;gBACxD,OAAO,IAAI,CAAC,GAAG,CACb,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,aAAa,IAAI,CAAC,CAAC,GAAG,GAAG,EAC7E,GAAG,CACJ,CAAC;YACJ,CAAC;YACD,iDAAiD;YACjD,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,280 @@
1
+ import type { TObject } from '@sinclair/typebox';
2
+ /**
3
+ * Checkpoint data structure for tracking feed sync state
4
+ */
5
+ export interface Checkpoint {
6
+ last_timestamp?: Date;
7
+ updated_at: Date;
8
+ total_items_processed?: number;
9
+ }
10
+ /**
11
+ * Sync result containing extracted content and updated checkpoint
12
+ *
13
+ * Note: checkpoint can be null for feeds that use incremental checkpoint
14
+ * updates via updateCheckpointFn during pagination (e.g., Reddit)
15
+ */
16
+ export interface FeedSyncResult {
17
+ contents: Content[];
18
+ checkpoint: Checkpoint | null;
19
+ metadata?: {
20
+ items_found: number;
21
+ items_skipped: number;
22
+ rate_limit_remaining?: number;
23
+ next_sync_recommended_at?: Date;
24
+ parent_map?: Record<string, string>;
25
+ [key: string]: any;
26
+ };
27
+ /**
28
+ * Auth state to persist after sync (browser cookies, etc.)
29
+ * Will be saved back to the linked auth profile for browser-based connectors.
30
+ */
31
+ auth_update?: Record<string, any>;
32
+ }
33
+ export interface ParentFeedDefinition {
34
+ type: string;
35
+ options: FeedOptions;
36
+ description?: string;
37
+ }
38
+ /**
39
+ * Extracted content from platform
40
+ */
41
+ export interface Content {
42
+ origin_id: string;
43
+ payload_text: string;
44
+ title?: string;
45
+ author_name?: string;
46
+ source_url: string;
47
+ occurred_at: Date;
48
+ origin_type?: string;
49
+ semantic_type?: string;
50
+ score: number;
51
+ origin_parent_id?: string | null;
52
+ metadata?: Record<string, any>;
53
+ }
54
+ /**
55
+ * Search result from platform search
56
+ */
57
+ export interface SearchResult {
58
+ url: string;
59
+ title: string;
60
+ description: string;
61
+ metadata?: Record<string, any>;
62
+ }
63
+ /**
64
+ * Feed options passed from MCP tool
65
+ */
66
+ export interface FeedOptions {
67
+ /**
68
+ * Number of days to look back when collecting historical data
69
+ * Default: 365 (1 year)
70
+ */
71
+ lookback_days?: number;
72
+ [key: string]: any;
73
+ }
74
+ /**
75
+ * Consolidated environment bindings used across the platform.
76
+ * This is the single source of truth for environment variable types.
77
+ */
78
+ export interface Env {
79
+ ENVIRONMENT: string;
80
+ MAX_CONSECUTIVE_FAILURES?: string;
81
+ DATABASE_URL?: string;
82
+ PUBLIC_LOGO_URL?: string;
83
+ PUBLIC_LEGAL_URL?: string;
84
+ FRAME_ANCESTORS?: string;
85
+ DEFAULT_SYNC_INTERVAL_MS?: string;
86
+ DEFAULT_SYNC_INTERVAL_HOURS?: string;
87
+ DEFAULT_SYNC_INTERVAL_X_MS?: string;
88
+ DEFAULT_SYNC_INTERVAL_REDDIT_MS?: string;
89
+ DEFAULT_SYNC_INTERVAL_GITHUB_MS?: string;
90
+ GITHUB_TOKEN?: string;
91
+ X_USERNAME?: string;
92
+ X_PASSWORD?: string;
93
+ X_EMAIL?: string;
94
+ X_2FA_SECRET?: string;
95
+ X_COOKIES?: string;
96
+ GOOGLE_MAPS_API_KEY?: string;
97
+ REDDIT_CLIENT_ID?: string;
98
+ REDDIT_CLIENT_SECRET?: string;
99
+ REDDIT_USER_AGENT?: string;
100
+ JWT_SECRET?: string;
101
+ WORKER_API_TOKEN?: string;
102
+ ANTHROPIC_API_KEY?: string;
103
+ EMBEDDINGS_SERVICE_URL?: string;
104
+ EMBEDDINGS_SERVICE_TOKEN?: string;
105
+ EMBEDDINGS_MODEL?: string;
106
+ EMBEDDINGS_DIMENSIONS?: string;
107
+ EMBEDDINGS_TIMEOUT_MS?: string;
108
+ BETTER_AUTH_SECRET?: string;
109
+ GITHUB_CLIENT_ID?: string;
110
+ GITHUB_CLIENT_SECRET?: string;
111
+ GOOGLE_CLIENT_ID?: string;
112
+ GOOGLE_CLIENT_SECRET?: string;
113
+ APPLE_CLIENT_ID?: string;
114
+ APPLE_CLIENT_SECRET?: string;
115
+ RESEND_API_KEY?: string;
116
+ EMAIL_FROM_AUTH?: string;
117
+ EMAIL_FROM_INVITES?: string;
118
+ EMAIL_REPLY_TO?: string;
119
+ EMAIL_UNSUBSCRIBE?: string;
120
+ TWILIO_SID?: string;
121
+ TWILIO_TOKEN?: string;
122
+ TWILIO_WHATSAPP_NUMBER?: string;
123
+ [key: string]: string | undefined;
124
+ }
125
+ /**
126
+ * Base session state type - feeds define their own specific types
127
+ * Values can come from env vars (defaults) or DB (per-connection overrides)
128
+ * At runtime, DB values override env defaults
129
+ */
130
+ export type SessionState = Record<string, any>;
131
+ /**
132
+ * Auth field definition for connector environment keys
133
+ */
134
+ export interface FeedAuthEnvField {
135
+ key: string;
136
+ label?: string;
137
+ description?: string;
138
+ example?: string;
139
+ secret?: boolean;
140
+ }
141
+ export interface FeedAuthNoneMethod {
142
+ type: 'none';
143
+ }
144
+ export interface FeedAuthEnvKeysMethod {
145
+ type: 'env_keys';
146
+ required?: boolean;
147
+ scope?: 'connection' | 'organization';
148
+ fields: FeedAuthEnvField[];
149
+ description?: string;
150
+ }
151
+ export interface FeedAuthOAuthMethod {
152
+ type: 'oauth';
153
+ provider: string;
154
+ requiredScopes: string[];
155
+ optionalScopes?: string[];
156
+ required?: boolean;
157
+ scope?: 'connection' | 'organization';
158
+ description?: string;
159
+ authorizationUrl?: string;
160
+ tokenUrl?: string;
161
+ userinfoUrl?: string;
162
+ authParams?: Record<string, string>;
163
+ tokenEndpointAuthMethod?: 'client_secret_post' | 'client_secret_basic' | 'none';
164
+ usePkce?: boolean;
165
+ loginScopes?: string[];
166
+ clientIdKey?: string;
167
+ clientSecretKey?: string;
168
+ setupInstructions?: string;
169
+ loginProvisioning?: {
170
+ autoCreateConnection?: boolean;
171
+ };
172
+ }
173
+ export interface FeedAuthBrowserMethod {
174
+ type: 'browser';
175
+ required?: boolean;
176
+ description?: string;
177
+ capture?: 'cli';
178
+ }
179
+ export type FeedAuthMethod = FeedAuthNoneMethod | FeedAuthEnvKeysMethod | FeedAuthOAuthMethod | FeedAuthBrowserMethod;
180
+ export interface FeedAuthSchema {
181
+ methods: FeedAuthMethod[];
182
+ }
183
+ /**
184
+ * Scoring configuration for cross-platform content ranking
185
+ */
186
+ export interface ScoringConfig {
187
+ /**
188
+ * Weight for engagement_score percentile (0-1)
189
+ * Higher value prioritizes items with more upvotes/reactions/engagement
190
+ */
191
+ engagement_weight: number;
192
+ /**
193
+ * Weight for inverse rating (100 - rating*20) (0-1)
194
+ * Higher value prioritizes lower-rated content
195
+ */
196
+ inverse_rating_weight: number;
197
+ /**
198
+ * Weight for content length percentile (0-1)
199
+ * Higher value prioritizes longer, more detailed content
200
+ */
201
+ content_length_weight: number;
202
+ /**
203
+ * Cross-platform multiplier (0-1)
204
+ * Used to de-prioritize or boost this feed relative to others
205
+ */
206
+ platform_weight: number;
207
+ }
208
+ /**
209
+ * Main feed interface
210
+ */
211
+ export interface IFeed {
212
+ /**
213
+ * Unique identifier for this feed type
214
+ */
215
+ readonly type: string;
216
+ /**
217
+ * Human-readable display name for this feed
218
+ */
219
+ readonly displayName: string;
220
+ /**
221
+ * API type: 'api' for HTTP/REST APIs, 'browser' for browser rendering
222
+ */
223
+ readonly apiType: 'api' | 'browser';
224
+ /**
225
+ * Feed mode: 'entity' for platforms with specific pages (repos, subreddits, companies)
226
+ * or 'search' for query-based platforms (Hacker News, Twitter search)
227
+ */
228
+ readonly feedMode: 'entity' | 'search';
229
+ /**
230
+ * TypeBox schema for validating feed options
231
+ */
232
+ readonly optionsSchema: TObject;
233
+ /**
234
+ * Default scoring configuration for this feed type
235
+ * @deprecated Use defaultScoringFormula instead
236
+ */
237
+ readonly defaultScoringConfig: ScoringConfig;
238
+ /**
239
+ * Default SQL formula to calculate normalized score (0-100)
240
+ * Can reference: f.score, f.content_length, f.metadata, f.occurred_at
241
+ * Can use window functions like PERCENT_RANK()
242
+ * User can override this per-connection via connections.scoring_formula
243
+ */
244
+ readonly defaultScoringFormula: string;
245
+ /**
246
+ * Pull new content from platform
247
+ */
248
+ pull(options: FeedOptions, checkpoint: Checkpoint | null, env: Env, sessionState?: SessionState | null, updateCheckpointFn?: (checkpoint: Checkpoint) => Promise<void>): Promise<FeedSyncResult>;
249
+ /**
250
+ * Validate feed options before saving to database
251
+ */
252
+ validateOptions(options: FeedOptions): string | null;
253
+ /**
254
+ * Get rate limit information for this platform
255
+ */
256
+ getRateLimit(): {
257
+ requests_per_minute: number;
258
+ requests_per_hour?: number;
259
+ recommended_interval_ms: number;
260
+ };
261
+ /**
262
+ * Search platform for entities
263
+ * Optional method - not all platforms may support search
264
+ */
265
+ search?(searchTerm: string, env: Env): Promise<SearchResult[]>;
266
+ /**
267
+ * Generate a URL for the connection from options
268
+ */
269
+ urlFromOptions(options: FeedOptions): string;
270
+ /**
271
+ * Generate a human-readable display label from options
272
+ */
273
+ displayLabelFromOptions(options: FeedOptions): string;
274
+ /**
275
+ * Return parent feed definitions required to preserve hierarchy.
276
+ */
277
+ getParentFeedDefinitions(options: FeedOptions): ParentFeedDefinition[];
278
+ readonly authSchema?: FeedAuthSchema;
279
+ }
280
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,UAAU;IAEzB,cAAc,CAAC,EAAE,IAAI,CAAC;IAGtB,UAAU,EAAE,IAAI,CAAC;IACjB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAGhC;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,EAAE;QACT,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,wBAAwB,CAAC,EAAE,IAAI,CAAC;QAChC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACpC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC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AAQ,CAAC;IAEvC;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,oBAAoB,EAAE,aAAa,CAAC;IAE7C;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IAEvC;;OAEG;IACH,IAAI,CACF,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,UAAU,GAAG,IAAI,EAC7B,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,EAClC,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GAC7D,OAAO,CAAC,cAAc,CAAC,CAAC;IAE3B;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IAErD;;OAEG;IACH,YAAY,IAAI;QACd,mBAAmB,EAAE,MAAM,CAAC;QAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IAEF;;;OAGG;IACH,MAAM,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAE/D;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAAC;IAE7C;;OAEG;IACH,uBAAuB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAAC;IAEtD;;OAEG;IACH,wBAAwB,CAAC,OAAO,EAAE,WAAW,GAAG,oBAAoB,EAAE,CAAC;IAEvE,QAAQ,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC;CACtC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export declare const WATCHER_TIME_GRANULARITIES: readonly ["daily", "weekly", "monthly", "quarterly"];
2
+ export type WatcherTimeGranularity = (typeof WATCHER_TIME_GRANULARITIES)[number];
3
+ export declare function isWatcherTimeGranularity(value: unknown): value is WatcherTimeGranularity;
4
+ export declare function inferWatcherGranularityFromDays(daysDiff: number): WatcherTimeGranularity;
5
+ export declare function inferWatcherGranularityFromSchedule(schedule: string | null | undefined): WatcherTimeGranularity;
6
+ export declare function getAvailableWatcherGranularities(baseGranularity?: WatcherTimeGranularity): WatcherTimeGranularity[];
7
+ export declare function getFinerWatcherGranularities(granularity: WatcherTimeGranularity): WatcherTimeGranularity[];
8
+ export declare function getNextWatcherGranularity(granularity: WatcherTimeGranularity): WatcherTimeGranularity | null;
9
+ export declare function getWatcherDateTruncUnit(granularity: WatcherTimeGranularity): 'day' | 'week' | 'month' | 'quarter';
10
+ export declare function shiftWatcherPeriod(date: Date, granularity: WatcherTimeGranularity, direction: 1 | -1): Date;
11
+ export declare function addWatcherPeriod(date: Date, granularity: WatcherTimeGranularity): Date;
12
+ export declare function subtractWatcherPeriod(date: Date, granularity: WatcherTimeGranularity): Date;
13
+ export declare function alignToWatcherWindowStart(date: Date, granularity: WatcherTimeGranularity): Date;
14
+ //# sourceMappingURL=watcher-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher-time.d.ts","sourceRoot":"","sources":["../src/watcher-time.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,sDAAuD,CAAC;AAE/F,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AASjF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CAIxF;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,MAAM,GAAG,sBAAsB,CAKxF;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,M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