@interactive-inc/flume 0.3.0 → 0.6.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.
package/package.json CHANGED
@@ -1,33 +1,38 @@
1
1
  {
2
2
  "name": "@interactive-inc/flume",
3
- "version": "0.3.0",
3
+ "version": "0.6.0",
4
4
  "description": "Unified notification listener for Discord, Slack, and GitHub. Raw WebSocket + fetch + Zod. No SDK dependencies.",
5
5
  "keywords": [
6
6
  "discord",
7
- "slack",
7
+ "event-source",
8
+ "gateway",
8
9
  "github",
10
+ "listener",
9
11
  "notifications",
10
- "webhook",
12
+ "slack",
11
13
  "socket-mode",
12
- "gateway",
13
- "event-source",
14
- "listener"
14
+ "webhook"
15
15
  ],
16
+ "homepage": "https://github.com/interactive-inc/open-flume#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/interactive-inc/open-flume/issues"
19
+ },
16
20
  "license": "MIT",
17
21
  "author": "interactive-inc",
18
22
  "repository": {
19
23
  "type": "git",
20
24
  "url": "git+https://github.com/interactive-inc/open-flume.git"
21
25
  },
22
- "homepage": "https://github.com/interactive-inc/open-flume#readme",
23
- "bugs": {
24
- "url": "https://github.com/interactive-inc/open-flume/issues"
25
- },
26
+ "files": [
27
+ "dist/**/*",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
26
31
  "type": "module",
32
+ "sideEffects": false,
27
33
  "main": "./dist/index.js",
28
34
  "module": "./dist/index.js",
29
35
  "types": "./dist/index.d.ts",
30
- "sideEffects": false,
31
36
  "exports": {
32
37
  ".": {
33
38
  "types": "./dist/index.d.ts",
@@ -51,11 +56,6 @@
51
56
  },
52
57
  "./package.json": "./package.json"
53
58
  },
54
- "files": [
55
- "dist/**/*",
56
- "README.md",
57
- "LICENSE"
58
- ],
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
@@ -67,11 +67,15 @@
67
67
  "lint": "vp lint",
68
68
  "fmt": "vp fmt"
69
69
  },
70
+ "dependencies": {
71
+ "zod": "^4.4.3"
72
+ },
70
73
  "devDependencies": {
74
+ "typescript": "^5.6.0",
71
75
  "vite-plus": "^0.1.21",
72
76
  "vitest": "^4.1.9"
73
77
  },
74
- "dependencies": {
75
- "zod": "^4.4.3"
78
+ "engines": {
79
+ "node": ">=22"
76
80
  }
77
81
  }
@@ -1,6 +0,0 @@
1
- //#region lib/errors/connection-error.d.ts
2
- declare class FlumeConnectionError extends Error {
3
- constructor(message: string);
4
- }
5
- //#endregion
6
- export { FlumeConnectionError as t };
@@ -1,11 +0,0 @@
1
- //#region lib/errors/http-error.d.ts
2
- type Props = {
3
- message: string;
4
- status: number;
5
- };
6
- declare class FlumeHttpError extends Error {
7
- readonly status: number;
8
- constructor(props: Props);
9
- }
10
- //#endregion
11
- export { FlumeHttpError as t };
@@ -1,49 +0,0 @@
1
- //#region lib/deps.ts
2
- function createFlumeDefaultDeps() {
3
- return {
4
- fetch: (url, init) => globalThis.fetch(url, init),
5
- WebSocket: globalThis.WebSocket,
6
- now: () => Date.now(),
7
- random: () => Math.random(),
8
- setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
9
- clearTimeout: (id) => globalThis.clearTimeout(id),
10
- setInterval: (fn, ms) => globalThis.setInterval(fn, ms),
11
- clearInterval: (id) => globalThis.clearInterval(id)
12
- };
13
- }
14
- //#endregion
15
- //#region lib/logger.ts
16
- var FlumeLogger = class {
17
- props;
18
- constructor(props) {
19
- this.props = props;
20
- Object.freeze(this);
21
- }
22
- debug(entry) {
23
- this.emit("debug", entry);
24
- }
25
- info(entry) {
26
- this.emit("info", entry);
27
- }
28
- warn(entry) {
29
- this.emit("warn", entry);
30
- }
31
- error(entry) {
32
- this.emit("error", entry);
33
- }
34
- emit(level, input) {
35
- if (!this.props.handler) return;
36
- const log = {
37
- level,
38
- source: this.props.source,
39
- action: input.action,
40
- message: input.message,
41
- timestamp: this.props.deps.now(),
42
- error: input.error,
43
- detail: input.detail
44
- };
45
- this.props.handler(log);
46
- }
47
- };
48
- //#endregion
49
- export { createFlumeDefaultDeps as n, FlumeLogger as t };
@@ -1,6 +0,0 @@
1
- //#region lib/errors/parse-error.d.ts
2
- declare class FlumeParseError extends Error {
3
- constructor(message: string);
4
- }
5
- //#endregion
6
- export { FlumeParseError as t };
@@ -1,67 +0,0 @@
1
- //#region lib/errors/connection-error.ts
2
- var FlumeConnectionError = class extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = "FlumeConnectionError";
6
- Object.freeze(this);
7
- }
8
- };
9
- //#endregion
10
- //#region lib/errors/parse-error.ts
11
- var FlumeParseError = class extends Error {
12
- constructor(message) {
13
- super(message);
14
- this.name = "FlumeParseError";
15
- Object.freeze(this);
16
- }
17
- };
18
- //#endregion
19
- //#region lib/reconnect-config.ts
20
- const DEFAULTS = {
21
- maxAttempts: Infinity,
22
- baseDelay: 1e3,
23
- maxDelay: 3e4
24
- };
25
- function resolveFlumeReconnectConfig(input) {
26
- if (input === false || input === void 0) return null;
27
- if (input === true) return { ...DEFAULTS };
28
- return {
29
- ...DEFAULTS,
30
- ...input
31
- };
32
- }
33
- //#endregion
34
- //#region lib/reconnector.ts
35
- var FlumeReconnector = class {
36
- props;
37
- attempt = 0;
38
- aborted = false;
39
- timer = null;
40
- constructor(props) {
41
- this.props = props;
42
- }
43
- schedule(fn) {
44
- if (this.aborted) return 0;
45
- if (this.attempt >= this.props.maxAttempts) return -1;
46
- const delay = this.nextDelay();
47
- this.timer = this.props.deps.setTimeout(fn, delay);
48
- return delay;
49
- }
50
- reset() {
51
- this.attempt = 0;
52
- }
53
- cancel() {
54
- this.aborted = true;
55
- if (this.timer !== null) {
56
- this.props.deps.clearTimeout(this.timer);
57
- this.timer = null;
58
- }
59
- }
60
- nextDelay() {
61
- const jitter = Math.min(this.props.baseDelay * 2 ** this.attempt, this.props.maxDelay) * (.5 + this.props.deps.random() * .5);
62
- this.attempt++;
63
- return jitter;
64
- }
65
- };
66
- //#endregion
67
- export { FlumeConnectionError as i, resolveFlumeReconnectConfig as n, FlumeParseError as r, FlumeReconnector as t };
@@ -1,20 +0,0 @@
1
- //#region lib/utils/safe-fetch.ts
2
- /**
3
- * deps.fetch を try/catch で包み、ネットワーク例外を Error として返す。
4
- * HTTP ステータスの解釈や追加の副作用 (リトライ計数等) は呼び出し側の責務
5
- */
6
- async function safeFetch(props) {
7
- try {
8
- return await props.fetch(props.url, props.init);
9
- } catch (error) {
10
- const err = error instanceof Error ? error : new Error(String(error));
11
- props.log.error({
12
- action: "http.error",
13
- message: `network error: ${err.message}`,
14
- error: err
15
- });
16
- return err;
17
- }
18
- }
19
- //#endregion
20
- export { safeFetch as t };
@@ -1,41 +0,0 @@
1
- //#region lib/schedule-reconnect.ts
2
- /**
3
- * 接続が落ちた際の共通再接続スケジューラ。reconnector の状態を見て次回試行を予約し、
4
- * 試行回数が尽きていれば disconnected に落とす
5
- */
6
- function scheduleFlumeReconnect(props) {
7
- if (!props.reconnector || props.reconnector.aborted) {
8
- props.setStatus("disconnected");
9
- return;
10
- }
11
- props.setStatus("reconnecting");
12
- const delay = props.reconnector.schedule(props.retry);
13
- if (delay === -1) {
14
- props.log.error({
15
- action: "reconnect.exhausted",
16
- message: `gave up after ${props.reconnector.attempt} attempts`
17
- });
18
- props.setStatus("disconnected");
19
- return;
20
- }
21
- props.log.info({
22
- action: "reconnect.scheduled",
23
- message: `next attempt in ${Math.round(delay)}ms`
24
- });
25
- }
26
- //#endregion
27
- //#region lib/utils/is-record.ts
28
- function isRecord(value) {
29
- return typeof value === "object" && value !== null;
30
- }
31
- //#endregion
32
- //#region lib/utils/safe-json-parse.ts
33
- function safeJsonParse(raw) {
34
- try {
35
- return JSON.parse(raw);
36
- } catch {
37
- return null;
38
- }
39
- }
40
- //#endregion
41
- export { isRecord as n, scheduleFlumeReconnect as r, safeJsonParse as t };
@@ -1,16 +0,0 @@
1
- //#region lib/utils/serial-queue.ts
2
- /**
3
- * 投入順を保ったまま task を直列実行する。各 task は前の完了を待ってから走る。
4
- * task が throw しても後続には伝播しない (キュー自体は止まらない)
5
- */
6
- var FlumeSerialQueue = class {
7
- chain = Promise.resolve();
8
- add(task) {
9
- this.chain = this.chain.then(task).catch(() => {});
10
- }
11
- async drain() {
12
- await this.chain;
13
- }
14
- };
15
- //#endregion
16
- export { FlumeSerialQueue as t };
@@ -1,143 +0,0 @@
1
- import { z } from "zod/v4";
2
-
3
- //#region lib/discord/discord-gateway-message-schema.d.ts
4
- declare const FlumeGatewayMessageSchema: z.ZodObject<{
5
- op: z.ZodNumber;
6
- d: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
7
- s: z.ZodNullable<z.ZodNumber>;
8
- t: z.ZodNullable<z.ZodString>;
9
- }, z.core.$strip>;
10
- //#endregion
11
- //#region lib/github/github-notification-schema.d.ts
12
- declare const FlumeGitHubNotificationSchema: z.ZodObject<{
13
- id: z.ZodString;
14
- reason: z.ZodString;
15
- unread: z.ZodBoolean;
16
- updated_at: z.ZodString;
17
- subject: z.ZodObject<{
18
- title: z.ZodString;
19
- url: z.ZodNullable<z.ZodString>;
20
- type: z.ZodString;
21
- }, z.core.$strip>;
22
- repository: z.ZodObject<{
23
- full_name: z.ZodString;
24
- }, z.core.$strip>;
25
- }, z.core.$strip>;
26
- //#endregion
27
- //#region lib/slack/slack-connection-response-schema.d.ts
28
- declare const FlumeSlackConnectionResponseSchema: z.ZodObject<{
29
- ok: z.ZodBoolean;
30
- url: z.ZodOptional<z.ZodString>;
31
- error: z.ZodOptional<z.ZodString>;
32
- }, z.core.$strip>;
33
- //#endregion
34
- //#region lib/slack/slack-envelope-schema.d.ts
35
- declare const FlumeSlackEnvelopeSchema: z.ZodObject<{
36
- envelope_id: z.ZodString;
37
- type: z.ZodString;
38
- payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
39
- accepts_response_payload: z.ZodOptional<z.ZodBoolean>;
40
- retry_attempt: z.ZodOptional<z.ZodNumber>;
41
- retry_reason: z.ZodOptional<z.ZodString>;
42
- }, z.core.$strip>;
43
- //#endregion
44
- //#region lib/types.d.ts
45
- type FlumeTimerHandle = ReturnType<typeof setTimeout>;
46
- type FlumeRuntimeDeps = {
47
- fetch(url: string | URL, init?: RequestInit): Promise<Response>;
48
- WebSocket: new (url: string | URL) => WebSocket;
49
- now(): number;
50
- random(): number;
51
- setTimeout(fn: () => void, ms: number): FlumeTimerHandle;
52
- clearTimeout(id: FlumeTimerHandle): void;
53
- setInterval(fn: () => void, ms: number): FlumeTimerHandle;
54
- clearInterval(id: FlumeTimerHandle): void;
55
- };
56
- type FlumeSourceName = "discord" | "slack" | "github";
57
- type FlumeEvent = {
58
- source: FlumeSourceName;
59
- type: string;
60
- data: unknown;
61
- meta: Record<string, string>;
62
- receivedAt: number;
63
- };
64
- type FlumeHandler = (event: FlumeEvent) => void | Promise<void>;
65
- type FlumeStartOk = {
66
- ok: true;
67
- };
68
- type FlumeStartErr = {
69
- ok: false;
70
- error: Error;
71
- };
72
- type FlumeStartResult = FlumeStartOk | FlumeStartErr;
73
- type FlumeSource = {
74
- readonly name: FlumeSourceName;
75
- start(handler: FlumeHandler): Promise<FlumeStartResult>;
76
- stop(): Promise<void>;
77
- status(): FlumeStatus;
78
- };
79
- type FlumeSourceStatus = {
80
- name: FlumeSourceName;
81
- status: FlumeStatus;
82
- };
83
- type FlumeStatus = "disconnected" | "connecting" | "connected" | "reconnecting";
84
- type FlumeStatusHandler = (status: FlumeStatus, detail?: string) => void;
85
- type FlumeLogLevel = "debug" | "info" | "warn" | "error";
86
- type FlumeLog = {
87
- level: FlumeLogLevel;
88
- source: string;
89
- action: string;
90
- message: string;
91
- error?: Error;
92
- detail?: Record<string, unknown>;
93
- timestamp: number;
94
- };
95
- type FlumeLogHandler = (log: FlumeLog) => void;
96
- type FlumeLogInput = {
97
- action: string;
98
- message: string;
99
- error?: Error;
100
- detail?: Record<string, unknown>;
101
- };
102
- type FlumeReconnectOptions = {
103
- maxAttempts?: number;
104
- baseDelay?: number;
105
- maxDelay?: number;
106
- };
107
- type FlumeReconnectConfig = {
108
- maxAttempts: number;
109
- baseDelay: number;
110
- maxDelay: number;
111
- };
112
- type FlumeSourceOptions = {
113
- reconnect?: boolean | FlumeReconnectOptions;
114
- onStatus?: FlumeStatusHandler;
115
- onLog?: FlumeLogHandler;
116
- signal?: AbortSignal;
117
- deps?: FlumeRuntimeDeps;
118
- };
119
- type FlumeDiscordSourceOptions = FlumeSourceOptions & {
120
- token: string;
121
- intents?: number;
122
- };
123
- type FlumeSlackSourceOptions = FlumeSourceOptions & {
124
- appToken: string;
125
- /**
126
- * Bot token (`xoxb-`). Required — used by the host (e.g. funnel) to call
127
- * `auth.test` for self-detection and to post replies. Flume's Socket Mode
128
- * transport only needs `appToken` to open the socket, but every realistic
129
- * consumer needs the bot token too, so the type forces it to be present
130
- * rather than leaving it optional and failing at runtime.
131
- */
132
- botToken: string;
133
- };
134
- type FlumeGitHubSourceOptions = FlumeSourceOptions & {
135
- token: string;
136
- pollInterval?: number;
137
- };
138
- type FlumeGatewayMessage = z.infer<typeof FlumeGatewayMessageSchema>;
139
- type FlumeSlackEnvelope = z.infer<typeof FlumeSlackEnvelopeSchema>;
140
- type FlumeSlackConnectionResponse = z.infer<typeof FlumeSlackConnectionResponseSchema>;
141
- type FlumeGitHubNotification = z.infer<typeof FlumeGitHubNotificationSchema>;
142
- //#endregion
143
- export { FlumeGatewayMessageSchema as A, FlumeStartResult as C, FlumeSlackEnvelopeSchema as D, FlumeTimerHandle as E, FlumeSlackConnectionResponseSchema as O, FlumeStartOk as S, FlumeStatusHandler as T, FlumeSource as _, FlumeGitHubSourceOptions as a, FlumeSourceStatus as b, FlumeLogHandler as c, FlumeReconnectConfig as d, FlumeReconnectOptions as f, FlumeSlackSourceOptions as g, FlumeSlackEnvelope as h, FlumeGitHubNotification as i, FlumeGitHubNotificationSchema as k, FlumeLogInput as l, FlumeSlackConnectionResponse as m, FlumeEvent as n, FlumeHandler as o, FlumeRuntimeDeps as p, FlumeGatewayMessage as r, FlumeLog as s, FlumeDiscordSourceOptions as t, FlumeLogLevel as u, FlumeSourceName as v, FlumeStatus as w, FlumeStartErr as x, FlumeSourceOptions as y };