@relayplane/proxy 0.1.10 → 0.2.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.
@@ -0,0 +1,80 @@
1
+ /**
2
+ * RelayPlane Proxy Configuration
3
+ *
4
+ * Handles configuration persistence, telemetry settings, and device identity.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ /**
9
+ * Configuration schema for RelayPlane proxy
10
+ */
11
+ export interface ProxyConfig {
12
+ /** Anonymous device ID (generated on first run) */
13
+ device_id: string;
14
+ /** Telemetry enabled state */
15
+ telemetry_enabled: boolean;
16
+ /** Whether first run disclosure has been shown */
17
+ first_run_complete: boolean;
18
+ /** RelayPlane API key (for Pro features) */
19
+ api_key?: string;
20
+ /** Schema version for migrations */
21
+ config_version: number;
22
+ /** Timestamp of config creation */
23
+ created_at: string;
24
+ /** Timestamp of last update */
25
+ updated_at: string;
26
+ }
27
+ /**
28
+ * Load configuration from disk
29
+ * Creates default config if none exists
30
+ */
31
+ export declare function loadConfig(): ProxyConfig;
32
+ /**
33
+ * Save configuration to disk
34
+ */
35
+ export declare function saveConfig(config: ProxyConfig): void;
36
+ /**
37
+ * Update specific config fields
38
+ */
39
+ export declare function updateConfig(updates: Partial<ProxyConfig>): ProxyConfig;
40
+ /**
41
+ * Check if this is the first run (disclosure not shown yet)
42
+ */
43
+ export declare function isFirstRun(): boolean;
44
+ /**
45
+ * Mark first run as complete
46
+ */
47
+ export declare function markFirstRunComplete(): void;
48
+ /**
49
+ * Check if telemetry is enabled
50
+ */
51
+ export declare function isTelemetryEnabled(): boolean;
52
+ /**
53
+ * Enable telemetry
54
+ */
55
+ export declare function enableTelemetry(): void;
56
+ /**
57
+ * Disable telemetry
58
+ */
59
+ export declare function disableTelemetry(): void;
60
+ /**
61
+ * Get device ID for telemetry
62
+ */
63
+ export declare function getDeviceId(): string;
64
+ /**
65
+ * Set API key for Pro features
66
+ */
67
+ export declare function setApiKey(key: string): void;
68
+ /**
69
+ * Get API key
70
+ */
71
+ export declare function getApiKey(): string | undefined;
72
+ /**
73
+ * Get config directory path
74
+ */
75
+ export declare function getConfigDir(): string;
76
+ /**
77
+ * Get config file path
78
+ */
79
+ export declare function getConfigPath(): string;
80
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAElB,8BAA8B;IAC9B,iBAAiB,EAAE,OAAO,CAAC;IAE3B,kDAAkD;IAClD,kBAAkB,EAAE,OAAO,CAAC;IAE5B,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IAEvB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IAEnB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;CACpB;AAwCD;;;GAGG;AACH,wBAAgB,UAAU,IAAI,WAAW,CA+BxC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAIpD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAKvE;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAGpC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAG5C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAGpC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE3C;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAG9C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
package/dist/config.js ADDED
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ /**
3
+ * RelayPlane Proxy Configuration
4
+ *
5
+ * Handles configuration persistence, telemetry settings, and device identity.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.loadConfig = loadConfig;
44
+ exports.saveConfig = saveConfig;
45
+ exports.updateConfig = updateConfig;
46
+ exports.isFirstRun = isFirstRun;
47
+ exports.markFirstRunComplete = markFirstRunComplete;
48
+ exports.isTelemetryEnabled = isTelemetryEnabled;
49
+ exports.enableTelemetry = enableTelemetry;
50
+ exports.disableTelemetry = disableTelemetry;
51
+ exports.getDeviceId = getDeviceId;
52
+ exports.setApiKey = setApiKey;
53
+ exports.getApiKey = getApiKey;
54
+ exports.getConfigDir = getConfigDir;
55
+ exports.getConfigPath = getConfigPath;
56
+ const fs = __importStar(require("fs"));
57
+ const path = __importStar(require("path"));
58
+ const os = __importStar(require("os"));
59
+ const crypto = __importStar(require("crypto"));
60
+ const CONFIG_VERSION = 1;
61
+ const CONFIG_DIR = path.join(os.homedir(), '.relayplane');
62
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
63
+ /**
64
+ * Generate an anonymous device ID
65
+ * Uses a random hash that cannot be traced back to the device
66
+ */
67
+ function generateDeviceId() {
68
+ const randomBytes = crypto.randomBytes(16);
69
+ const hash = crypto.createHash('sha256').update(randomBytes).digest('hex');
70
+ return `anon_${hash.slice(0, 16)}`;
71
+ }
72
+ /**
73
+ * Ensure config directory exists
74
+ */
75
+ function ensureConfigDir() {
76
+ if (!fs.existsSync(CONFIG_DIR)) {
77
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
78
+ }
79
+ }
80
+ /**
81
+ * Create default configuration
82
+ */
83
+ function createDefaultConfig() {
84
+ const now = new Date().toISOString();
85
+ return {
86
+ device_id: generateDeviceId(),
87
+ telemetry_enabled: true, // On by default, opt-out available
88
+ first_run_complete: false,
89
+ config_version: CONFIG_VERSION,
90
+ created_at: now,
91
+ updated_at: now,
92
+ };
93
+ }
94
+ /**
95
+ * Load configuration from disk
96
+ * Creates default config if none exists
97
+ */
98
+ function loadConfig() {
99
+ ensureConfigDir();
100
+ if (!fs.existsSync(CONFIG_FILE)) {
101
+ const config = createDefaultConfig();
102
+ saveConfig(config);
103
+ return config;
104
+ }
105
+ try {
106
+ const data = fs.readFileSync(CONFIG_FILE, 'utf-8');
107
+ const config = JSON.parse(data);
108
+ // Ensure required fields exist (for migrations)
109
+ if (!config.device_id) {
110
+ config.device_id = generateDeviceId();
111
+ }
112
+ if (config.telemetry_enabled === undefined) {
113
+ config.telemetry_enabled = true;
114
+ }
115
+ if (!config.config_version) {
116
+ config.config_version = CONFIG_VERSION;
117
+ }
118
+ return config;
119
+ }
120
+ catch (err) {
121
+ // If config is corrupted, create new one
122
+ const config = createDefaultConfig();
123
+ saveConfig(config);
124
+ return config;
125
+ }
126
+ }
127
+ /**
128
+ * Save configuration to disk
129
+ */
130
+ function saveConfig(config) {
131
+ ensureConfigDir();
132
+ config.updated_at = new Date().toISOString();
133
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
134
+ }
135
+ /**
136
+ * Update specific config fields
137
+ */
138
+ function updateConfig(updates) {
139
+ const config = loadConfig();
140
+ Object.assign(config, updates);
141
+ saveConfig(config);
142
+ return config;
143
+ }
144
+ /**
145
+ * Check if this is the first run (disclosure not shown yet)
146
+ */
147
+ function isFirstRun() {
148
+ const config = loadConfig();
149
+ return !config.first_run_complete;
150
+ }
151
+ /**
152
+ * Mark first run as complete
153
+ */
154
+ function markFirstRunComplete() {
155
+ updateConfig({ first_run_complete: true });
156
+ }
157
+ /**
158
+ * Check if telemetry is enabled
159
+ */
160
+ function isTelemetryEnabled() {
161
+ const config = loadConfig();
162
+ return config.telemetry_enabled;
163
+ }
164
+ /**
165
+ * Enable telemetry
166
+ */
167
+ function enableTelemetry() {
168
+ updateConfig({ telemetry_enabled: true });
169
+ }
170
+ /**
171
+ * Disable telemetry
172
+ */
173
+ function disableTelemetry() {
174
+ updateConfig({ telemetry_enabled: false });
175
+ }
176
+ /**
177
+ * Get device ID for telemetry
178
+ */
179
+ function getDeviceId() {
180
+ const config = loadConfig();
181
+ return config.device_id;
182
+ }
183
+ /**
184
+ * Set API key for Pro features
185
+ */
186
+ function setApiKey(key) {
187
+ updateConfig({ api_key: key });
188
+ }
189
+ /**
190
+ * Get API key
191
+ */
192
+ function getApiKey() {
193
+ const config = loadConfig();
194
+ return config.api_key;
195
+ }
196
+ /**
197
+ * Get config directory path
198
+ */
199
+ function getConfigDir() {
200
+ return CONFIG_DIR;
201
+ }
202
+ /**
203
+ * Get config file path
204
+ */
205
+ function getConfigPath() {
206
+ return CONFIG_FILE;
207
+ }
208
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EH,gCA+BC;AAKD,gCAIC;AAKD,oCAKC;AAKD,gCAGC;AAKD,oDAEC;AAKD,gDAGC;AAKD,0CAEC;AAKD,4CAEC;AAKD,kCAGC;AAKD,8BAEC;AAKD,8BAGC;AAKD,oCAEC;AAKD,sCAEC;AArMD,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,+CAAiC;AA4BjC,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,aAAa,CAAC,CAAC;AAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAEzD;;;GAGG;AACH,SAAS,gBAAgB;IACvB,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3E,OAAO,QAAQ,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAS,eAAe;IACt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