polyv-live-cli 1.0.2

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +417 -0
  3. package/dist/commands/channel.commands.d.ts +9 -0
  4. package/dist/commands/channel.commands.d.ts.map +1 -0
  5. package/dist/commands/channel.commands.js +439 -0
  6. package/dist/commands/channel.commands.js.map +1 -0
  7. package/dist/commands/index.d.ts +3 -0
  8. package/dist/commands/index.d.ts.map +1 -0
  9. package/dist/commands/index.js +8 -0
  10. package/dist/commands/index.js.map +1 -0
  11. package/dist/commands/stream.commands.d.ts +3 -0
  12. package/dist/commands/stream.commands.d.ts.map +1 -0
  13. package/dist/commands/stream.commands.js +272 -0
  14. package/dist/commands/stream.commands.js.map +1 -0
  15. package/dist/config/auth.d.ts +11 -0
  16. package/dist/config/auth.d.ts.map +1 -0
  17. package/dist/config/auth.js +124 -0
  18. package/dist/config/auth.js.map +1 -0
  19. package/dist/config/loader.d.ts +22 -0
  20. package/dist/config/loader.d.ts.map +1 -0
  21. package/dist/config/loader.js +127 -0
  22. package/dist/config/loader.js.map +1 -0
  23. package/dist/config/manager.d.ts +20 -0
  24. package/dist/config/manager.d.ts.map +1 -0
  25. package/dist/config/manager.js +258 -0
  26. package/dist/config/manager.js.map +1 -0
  27. package/dist/config/validator.d.ts +43 -0
  28. package/dist/config/validator.d.ts.map +1 -0
  29. package/dist/config/validator.js +222 -0
  30. package/dist/config/validator.js.map +1 -0
  31. package/dist/handlers/base.handler.d.ts +15 -0
  32. package/dist/handlers/base.handler.d.ts.map +1 -0
  33. package/dist/handlers/base.handler.js +122 -0
  34. package/dist/handlers/base.handler.js.map +1 -0
  35. package/dist/handlers/channel.handler.d.ts +31 -0
  36. package/dist/handlers/channel.handler.d.ts.map +1 -0
  37. package/dist/handlers/channel.handler.js +690 -0
  38. package/dist/handlers/channel.handler.js.map +1 -0
  39. package/dist/handlers/index.d.ts +4 -0
  40. package/dist/handlers/index.d.ts.map +1 -0
  41. package/dist/handlers/index.js +10 -0
  42. package/dist/handlers/index.js.map +1 -0
  43. package/dist/handlers/stream.handler.d.ts +25 -0
  44. package/dist/handlers/stream.handler.d.ts.map +1 -0
  45. package/dist/handlers/stream.handler.js +241 -0
  46. package/dist/handlers/stream.handler.js.map +1 -0
  47. package/dist/index.d.ts +4 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +342 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/services/channel.service.d.ts +25 -0
  52. package/dist/services/channel.service.d.ts.map +1 -0
  53. package/dist/services/channel.service.js +672 -0
  54. package/dist/services/channel.service.js.map +1 -0
  55. package/dist/services/index.d.ts +3 -0
  56. package/dist/services/index.d.ts.map +1 -0
  57. package/dist/services/index.js +8 -0
  58. package/dist/services/index.js.map +1 -0
  59. package/dist/services/stream.service.d.ts +29 -0
  60. package/dist/services/stream.service.d.ts.map +1 -0
  61. package/dist/services/stream.service.js +489 -0
  62. package/dist/services/stream.service.js.map +1 -0
  63. package/dist/types/auth.d.ts +31 -0
  64. package/dist/types/auth.d.ts.map +1 -0
  65. package/dist/types/auth.js +14 -0
  66. package/dist/types/auth.js.map +1 -0
  67. package/dist/types/channel.d.ts +262 -0
  68. package/dist/types/channel.d.ts.map +1 -0
  69. package/dist/types/channel.js +3 -0
  70. package/dist/types/channel.js.map +1 -0
  71. package/dist/types/config.d.ts +82 -0
  72. package/dist/types/config.d.ts.map +1 -0
  73. package/dist/types/config.js +56 -0
  74. package/dist/types/config.js.map +1 -0
  75. package/dist/types/index.d.ts +6 -0
  76. package/dist/types/index.d.ts.map +1 -0
  77. package/dist/types/index.js +22 -0
  78. package/dist/types/index.js.map +1 -0
  79. package/dist/types/signature.d.ts +22 -0
  80. package/dist/types/signature.d.ts.map +1 -0
  81. package/dist/types/signature.js +3 -0
  82. package/dist/types/signature.js.map +1 -0
  83. package/dist/types/stream.d.ts +104 -0
  84. package/dist/types/stream.d.ts.map +1 -0
  85. package/dist/types/stream.js +3 -0
  86. package/dist/types/stream.js.map +1 -0
  87. package/dist/utils/confirmation.d.ts +12 -0
  88. package/dist/utils/confirmation.d.ts.map +1 -0
  89. package/dist/utils/confirmation.js +164 -0
  90. package/dist/utils/confirmation.js.map +1 -0
  91. package/dist/utils/errors.d.ts +40 -0
  92. package/dist/utils/errors.d.ts.map +1 -0
  93. package/dist/utils/errors.js +113 -0
  94. package/dist/utils/errors.js.map +1 -0
  95. package/dist/utils/formatter.d.ts +8 -0
  96. package/dist/utils/formatter.d.ts.map +1 -0
  97. package/dist/utils/formatter.js +93 -0
  98. package/dist/utils/formatter.js.map +1 -0
  99. package/dist/utils/index.d.ts +4 -0
  100. package/dist/utils/index.d.ts.map +1 -0
  101. package/dist/utils/index.js +20 -0
  102. package/dist/utils/index.js.map +1 -0
  103. package/dist/utils/signature.d.ts +9 -0
  104. package/dist/utils/signature.d.ts.map +1 -0
  105. package/dist/utils/signature.js +77 -0
  106. package/dist/utils/signature.js.map +1 -0
  107. package/package.json +86 -0
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerStreamCommands = registerStreamCommands;
4
+ const stream_handler_1 = require("../handlers/stream.handler");
5
+ const stream_service_1 = require("../services/stream.service");
6
+ const manager_1 = require("../config/manager");
7
+ const errors_1 = require("../utils/errors");
8
+ function registerStreamCommands(program) {
9
+ const streamCmd = program.command('stream');
10
+ streamCmd.description('Manage live streaming operations');
11
+ const getKeyCmd = streamCmd
12
+ .command('get-key')
13
+ .description('Get RTMP URL and stream key for a live channel')
14
+ .requiredOption('-c, --channelId <id>', 'channel ID (required, must be a live channel)')
15
+ .option('-o, --output <format>', 'output format (table|json)', validateOutputFormat, 'table')
16
+ .action(async (options) => {
17
+ try {
18
+ const parentOptions = program.opts();
19
+ const configResult = await manager_1.configManager.load({
20
+ cliOptions: parentOptions,
21
+ });
22
+ const serviceConfig = {
23
+ baseUrl: configResult.config.baseUrl,
24
+ timeout: configResult.config.timeout,
25
+ debug: configResult.config.debug
26
+ };
27
+ const streamService = new stream_service_1.StreamService(configResult.config.auth, serviceConfig);
28
+ const streamHandler = new stream_handler_1.StreamHandler(streamService);
29
+ const streamOptions = {
30
+ channelId: options.channelId,
31
+ output: options.output
32
+ };
33
+ await streamHandler.getStreamKey(streamOptions);
34
+ }
35
+ catch (error) {
36
+ (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error)));
37
+ process.exit(1);
38
+ }
39
+ });
40
+ getKeyCmd.addHelpText('after', `
41
+ Examples:
42
+ $ polyv-cli stream get-key -c 3151318
43
+ $ polyv-cli stream get-key -c 3151318 -o json
44
+ $ polyv-cli stream get-key -c 3151318 -o table
45
+
46
+ Alternative (full parameter names):
47
+ $ polyv-cli stream get-key -c 3151318 -o json
48
+
49
+ Requirements:
50
+ • Channel must be in live streaming state
51
+ • Valid authentication credentials required
52
+ • Channel ID must exist and be accessible
53
+
54
+ Output Formats:
55
+ table Formatted table output with masked stream key (default)
56
+ json JSON format with full credentials (for programmatic use)
57
+
58
+ Security Notes:
59
+ • Stream keys are sensitive credentials - keep them secure
60
+ • Table format masks the stream key for security
61
+ • JSON format shows full credentials - use carefully
62
+ • Do not share stream keys in public channels or logs
63
+
64
+ Usage in OBS/Streaming Software:
65
+ 1. Copy the RTMP URL to your streaming software's server field
66
+ 2. Copy the stream key to your streaming software's key field
67
+ 3. Start streaming to begin live broadcast
68
+ `);
69
+ const startCmd = streamCmd
70
+ .command('start')
71
+ .description('Start live streaming for a channel')
72
+ .requiredOption('-c, --channelId <id>', 'channel ID (required)')
73
+ .action(async (options) => {
74
+ try {
75
+ const parentOptions = program.opts();
76
+ const configResult = await manager_1.configManager.load({
77
+ cliOptions: parentOptions,
78
+ });
79
+ const serviceConfig = {
80
+ baseUrl: configResult.config.baseUrl,
81
+ timeout: configResult.config.timeout,
82
+ debug: configResult.config.debug
83
+ };
84
+ const streamService = new stream_service_1.StreamService(configResult.config.auth, serviceConfig);
85
+ const streamHandler = new stream_handler_1.StreamHandler(streamService);
86
+ const streamOptions = {
87
+ channelId: options.channelId
88
+ };
89
+ await streamHandler.startStream(streamOptions);
90
+ }
91
+ catch (error) {
92
+ (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error)));
93
+ process.exit(1);
94
+ }
95
+ });
96
+ startCmd.addHelpText('after', `
97
+ Examples:
98
+ $ polyv-cli stream start -c 3151318
99
+ $ polyv-cli stream start -c 3151318 --appId <id> --appSecret <secret>
100
+
101
+ Requirements:
102
+ • Channel must exist and be accessible
103
+ • Valid authentication credentials required
104
+ • User must have permission to start streams for the channel
105
+
106
+ Usage Notes:
107
+ • This command sets the channel status to "live"
108
+ • The actual streaming still requires OBS or other streaming software
109
+ • Use 'stream get-key' to obtain streaming credentials after starting
110
+ • Stream status changes do not trigger automatic callbacks
111
+
112
+ Expected Behavior:
113
+ • Success: Channel status changes to live, confirmation displayed
114
+ • Already Started: Command completes with informational message
115
+ • Channel Not Found: Error message displayed with specific details
116
+ • Permission Denied: Authentication or authorization error displayed
117
+ `);
118
+ const stopCmd = streamCmd
119
+ .command('stop')
120
+ .description('Stop live streaming for a channel')
121
+ .requiredOption('-c, --channelId <id>', 'channel ID (required)')
122
+ .action(async (options) => {
123
+ try {
124
+ const parentOptions = program.opts();
125
+ const configResult = await manager_1.configManager.load({
126
+ cliOptions: parentOptions,
127
+ });
128
+ const serviceConfig = {
129
+ baseUrl: configResult.config.baseUrl,
130
+ timeout: configResult.config.timeout,
131
+ debug: configResult.config.debug
132
+ };
133
+ const streamService = new stream_service_1.StreamService(configResult.config.auth, serviceConfig);
134
+ const streamHandler = new stream_handler_1.StreamHandler(streamService);
135
+ const streamOptions = {
136
+ channelId: options.channelId
137
+ };
138
+ await streamHandler.stopStream(streamOptions);
139
+ }
140
+ catch (error) {
141
+ (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error)));
142
+ process.exit(1);
143
+ }
144
+ });
145
+ stopCmd.addHelpText('after', `
146
+ Examples:
147
+ $ polyv-cli stream stop -c 3151318
148
+ $ polyv-cli stream stop -c 3151318 --appId <id> --appSecret <secret>
149
+
150
+ Requirements:
151
+ • Channel must exist and be accessible
152
+ • Valid authentication credentials required
153
+ • User must have permission to stop streams for the channel
154
+
155
+ Usage Notes:
156
+ • This command sets the channel status to "stopped"
157
+ • The streaming session will be terminated immediately
158
+ • Use this command to end live broadcasts cleanly
159
+ • Stream status changes do not trigger automatic callbacks
160
+
161
+ Expected Behavior:
162
+ • Success: Channel status changes to stopped, confirmation displayed
163
+ • Already Stopped: Command completes with informational message
164
+ • Channel Not Found: Error message displayed with specific details
165
+ • Permission Denied: Authentication or authorization error displayed
166
+ • Not Live: Error if channel is not currently streaming
167
+ `);
168
+ const statusCmd = streamCmd
169
+ .command('status')
170
+ .description('Get real-time status information for a live channel')
171
+ .requiredOption('-c, --channelId <id>', 'channel ID (required)')
172
+ .option('-o, --output <format>', 'output format (table|json)', validateOutputFormat, 'table')
173
+ .option('-w, --watch', 'enable continuous monitoring (updates every 5 seconds)')
174
+ .action(async (options) => {
175
+ try {
176
+ const parentOptions = program.opts();
177
+ const configResult = await manager_1.configManager.load({
178
+ cliOptions: parentOptions,
179
+ });
180
+ const serviceConfig = {
181
+ baseUrl: configResult.config.baseUrl,
182
+ timeout: configResult.config.timeout,
183
+ debug: configResult.config.debug
184
+ };
185
+ const streamService = new stream_service_1.StreamService(configResult.config.auth, serviceConfig);
186
+ const streamHandler = new stream_handler_1.StreamHandler(streamService);
187
+ const streamOptions = {
188
+ channelId: options.channelId,
189
+ output: options.output,
190
+ watch: options.watch
191
+ };
192
+ if (options.watch) {
193
+ console.log('📺 Starting continuous monitoring (Press Ctrl+C to stop)...\n');
194
+ const updateInterval = setInterval(async () => {
195
+ try {
196
+ process.stdout.write('\x1Bc');
197
+ console.log('📺 Live Stream Monitor - Press Ctrl+C to stop\n');
198
+ await streamHandler.getStreamStatus(streamOptions);
199
+ console.log(`\n⏱️ Last updated: ${new Date().toLocaleTimeString()}`);
200
+ console.log('🔄 Updating in 5 seconds...');
201
+ }
202
+ catch (error) {
203
+ console.error('❌ Error updating status:', error instanceof Error ? error.message : String(error));
204
+ }
205
+ }, 5000);
206
+ process.on('SIGINT', () => {
207
+ clearInterval(updateInterval);
208
+ console.log('\n\n👋 Monitoring stopped. Goodbye!');
209
+ process.exit(0);
210
+ });
211
+ await streamHandler.getStreamStatus(streamOptions);
212
+ console.log(`\n⏱️ Last updated: ${new Date().toLocaleTimeString()}`);
213
+ console.log('🔄 Updating in 5 seconds...');
214
+ }
215
+ else {
216
+ await streamHandler.getStreamStatus(streamOptions);
217
+ }
218
+ }
219
+ catch (error) {
220
+ (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error)));
221
+ process.exit(1);
222
+ }
223
+ });
224
+ statusCmd.addHelpText('after', `
225
+ Examples:
226
+ $ polyv-cli stream status -c 3151318
227
+ $ polyv-cli stream status -c 3151318 -o json
228
+ $ polyv-cli stream status -c 3151318 -w
229
+ $ polyv-cli stream status -c 3151318 -w -o table
230
+
231
+ Alternative (full parameter names):
232
+ $ polyv-cli stream status --channelId 3151318 --output json --watch
233
+
234
+ Requirements:
235
+ • Channel must exist and be accessible
236
+ • Valid authentication credentials required
237
+ • No special permissions needed for status checking
238
+
239
+ Usage Notes:
240
+ • Status command works for channels in any state (live, waiting, stopped)
241
+ • Live channels show detailed performance metrics and network information
242
+ • Watch mode refreshes status every 5 seconds automatically
243
+ • Use Ctrl+C to stop watch mode
244
+ • JSON output provides complete status data for programmatic use
245
+
246
+ Status Information Displayed:
247
+ • Current streaming status (Live, Waiting, Stopped, Error)
248
+ • Stream duration (for live streams)
249
+ • Performance metrics (FPS, bandwidth, frame loss rate)
250
+ • Network information (deploy address, input address, stream name)
251
+ • Error details (if applicable)
252
+ • Last update timestamp
253
+
254
+ Output Formats:
255
+ table Formatted table output with status icons (default)
256
+ json Complete JSON data for programmatic use
257
+
258
+ Watch Mode:
259
+ • Continuously monitors stream status
260
+ • Updates every 5 seconds automatically
261
+ • Shows live performance metrics
262
+ • Perfect for monitoring active streams
263
+ • Press Ctrl+C to exit
264
+ `);
265
+ }
266
+ function validateOutputFormat(value) {
267
+ if (value !== 'table' && value !== 'json') {
268
+ throw new Error(`Invalid output format: ${value}. Must be 'table' or 'json'`);
269
+ }
270
+ return value;
271
+ }
272
+ //# sourceMappingURL=stream.commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.commands.js","sourceRoot":"","sources":["../../src/commands/stream.commands.ts"],"names":[],"mappings":";;AAiBA,wDAmUC;AA7UD,+DAA2D;AAC3D,+DAAgF;AAEhF,+CAAkD;AAClD,4CAA2C;AAM3C,SAAgB,sBAAsB,CAAC,OAAgB;IAGrD,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5C,SAAS,CAAC,WAAW,CAAC,kCAAkC,CAAC,CAAC;IAG1D,MAAM,SAAS,GAAG,SAAS;SACxB,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,gDAAgD,CAAC;SAC7D,cAAc,CAAC,sBAAsB,EAAE,+CAA+C,CAAC;SACvF,MAAM,CAAC,uBAAuB,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,OAAO,CAAC;SAC5F,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,IAAI,CAAC;YAEH,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;YACrC,MAAM,YAAY,GAAG,MAAM,uBAAa,CAAC,IAAI,CAAC;gBAC5C,UAAU,EAAE,aAAa;aAC1B,CAAC,CAAC;YAGH,MAAM,aAAa,GAAwB;gBACzC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO;gBACpC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO;gBACpC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK;aACjC,CAAC;YAGF,MAAM,aAAa,GAAG,IAAI,8BAAa,CAAC,Y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C,IAAI,CAAC,CAAC,CAAC,CAAC;gBAClB,CAAC,CAAC,CAAC;gBAGH,MAAM,aAAa,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;gBACnD,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,IAAI,EAAE,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;gBACtE,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;YAC7C,CAAC;iBAAM,CAAC;gBAEN,MAAM,aAAa,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;YACrD,CAAC;QAEH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEf,IAAA,iBAAQ,EAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAGL,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwChC,CAAC,CAAC;AACH,CAAC;AAQD,SAAS,oBAAoB,CAAC,KAAa;IACzC,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,6BAA6B,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { AuthOptions, AuthResult, AuthSource } from '../types/auth';
2
+ export declare function loadAuthFromCLI(cliOptions: Record<string, unknown>): AuthOptions;
3
+ export declare function loadAuthFromEnv(): AuthOptions;
4
+ export declare function mergeAuthOptions(cliOptions: AuthOptions, envOptions: AuthOptions): {
5
+ options: AuthOptions;
6
+ sources: AuthSource;
7
+ };
8
+ export declare function validateAuthConfig(authOptions: AuthOptions): boolean;
9
+ export declare function createAuthErrorMessage(authOptions: AuthOptions, sources: AuthSource): string;
10
+ export declare function loadAuthConfig(cliOptions?: Record<string, unknown>): AuthResult;
11
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/config/auth.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,WAAW,EAAE,UAAU,EAAE,UAAU,EAAmC,MAAM,eAAe,CAAC;AAQjH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAgBhF;AAMD,wBAAgB,eAAe,IAAI,WAAW,CAmB7C;AAQD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,GAAG;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,CAgChI;AAOD,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAEpE;AAQD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,GAAG,MAAM,CAuC5F;AAOD,wBAAgB,cAAc,CAAC,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,UAAU,CA4BnF"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadAuthFromCLI = loadAuthFromCLI;
4
+ exports.loadAuthFromEnv = loadAuthFromEnv;
5
+ exports.mergeAuthOptions = mergeAuthOptions;
6
+ exports.validateAuthConfig = validateAuthConfig;
7
+ exports.createAuthErrorMessage = createAuthErrorMessage;
8
+ exports.loadAuthConfig = loadAuthConfig;
9
+ const auth_1 = require("../types/auth");
10
+ const errors_1 = require("../utils/errors");
11
+ function loadAuthFromCLI(cliOptions) {
12
+ const authOptions = {};
13
+ if (typeof cliOptions[auth_1.AUTH_CLI_OPTIONS.APP_ID] === 'string') {
14
+ authOptions.appId = cliOptions[auth_1.AUTH_CLI_OPTIONS.APP_ID];
15
+ }
16
+ if (typeof cliOptions[auth_1.AUTH_CLI_OPTIONS.APP_SECRET] === 'string') {
17
+ authOptions.appSecret = cliOptions[auth_1.AUTH_CLI_OPTIONS.APP_SECRET];
18
+ }
19
+ if (typeof cliOptions[auth_1.AUTH_CLI_OPTIONS.USER_ID] === 'string') {
20
+ authOptions.userId = cliOptions[auth_1.AUTH_CLI_OPTIONS.USER_ID];
21
+ }
22
+ return authOptions;
23
+ }
24
+ function loadAuthFromEnv() {
25
+ const authOptions = {};
26
+ const appId = process.env[auth_1.AUTH_ENV_VARS.APP_ID];
27
+ if (appId && appId.trim()) {
28
+ authOptions.appId = appId.trim();
29
+ }
30
+ const appSecret = process.env[auth_1.AUTH_ENV_VARS.APP_SECRET];
31
+ if (appSecret && appSecret.trim()) {
32
+ authOptions.appSecret = appSecret.trim();
33
+ }
34
+ const userId = process.env[auth_1.AUTH_ENV_VARS.USER_ID];
35
+ if (userId && userId.trim()) {
36
+ authOptions.userId = userId.trim();
37
+ }
38
+ return authOptions;
39
+ }
40
+ function mergeAuthOptions(cliOptions, envOptions) {
41
+ const mergedOptions = {};
42
+ const sources = {};
43
+ if (cliOptions.appId) {
44
+ mergedOptions.appId = cliOptions.appId;
45
+ sources.appIdSource = 'cli';
46
+ }
47
+ else if (envOptions.appId) {
48
+ mergedOptions.appId = envOptions.appId;
49
+ sources.appIdSource = 'env';
50
+ }
51
+ if (cliOptions.appSecret) {
52
+ mergedOptions.appSecret = cliOptions.appSecret;
53
+ sources.appSecretSource = 'cli';
54
+ }
55
+ else if (envOptions.appSecret) {
56
+ mergedOptions.appSecret = envOptions.appSecret;
57
+ sources.appSecretSource = 'env';
58
+ }
59
+ if (cliOptions.userId) {
60
+ mergedOptions.userId = cliOptions.userId;
61
+ sources.userIdSource = 'cli';
62
+ }
63
+ else if (envOptions.userId) {
64
+ mergedOptions.userId = envOptions.userId;
65
+ sources.userIdSource = 'env';
66
+ }
67
+ return { options: mergedOptions, sources };
68
+ }
69
+ function validateAuthConfig(authOptions) {
70
+ return !!(authOptions.appId && authOptions.appSecret);
71
+ }
72
+ function createAuthErrorMessage(authOptions, sources) {
73
+ const missing = [];
74
+ if (!authOptions.appId) {
75
+ missing.push('appId');
76
+ }
77
+ if (!authOptions.appSecret) {
78
+ missing.push('appSecret');
79
+ }
80
+ if (missing.length === 0) {
81
+ return 'Authentication configuration is valid';
82
+ }
83
+ const missingStr = missing.join(', ');
84
+ const hasCliSource = Object.values(sources).some(source => source === 'cli');
85
+ const hasEnvSource = Object.values(sources).some(source => source === 'env');
86
+ let message = `Missing required authentication parameters: ${missingStr}\n\n`;
87
+ message += 'You can provide authentication in two ways:\n';
88
+ message += '1. Command line: --appId <ID> --appSecret <SECRET> [--userId <USER_ID>]\n';
89
+ message += '2. Environment variables: POLYV_APP_ID, POLYV_APP_SECRET, POLYV_USER_ID\n\n';
90
+ if (hasCliSource || hasEnvSource) {
91
+ message += 'Current configuration sources:\n';
92
+ if (sources.appIdSource) {
93
+ message += ` appId: ${sources.appIdSource}\n`;
94
+ }
95
+ if (sources.appSecretSource) {
96
+ message += ` appSecret: ${sources.appSecretSource}\n`;
97
+ }
98
+ if (sources.userIdSource) {
99
+ message += ` userId: ${sources.userIdSource}\n`;
100
+ }
101
+ }
102
+ return message.trim();
103
+ }
104
+ function loadAuthConfig(cliOptions = {}) {
105
+ const cliAuth = loadAuthFromCLI(cliOptions);
106
+ const envAuth = loadAuthFromEnv();
107
+ const { options: mergedOptions, sources } = mergeAuthOptions(cliAuth, envAuth);
108
+ const isValid = validateAuthConfig(mergedOptions);
109
+ if (!isValid) {
110
+ const errorMessage = createAuthErrorMessage(mergedOptions, sources);
111
+ throw new errors_1.ConfigurationError(errorMessage);
112
+ }
113
+ const config = {
114
+ appId: mergedOptions.appId,
115
+ appSecret: mergedOptions.appSecret,
116
+ ...(mergedOptions.userId && { userId: mergedOptions.userId }),
117
+ };
118
+ return {
119
+ config,
120
+ sources,
121
+ isValid: true,
122
+ };
123
+ }
124
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/config/auth.ts"],"names":[],"mappings":";;AAYA,0CAgBC;AAMD,0CAmBC;AAQD,4CAgCC;AAOD,gDAEC;AAQD,wDAuCC;AAOD,wCA4BC;AApLD,wCAAiH;AACjH,4CAAqD;AAOrD,SAAgB,eAAe,CAAC,UAAmC;IACjE,MAAM,WAAW,GAAgB,EAAE,CAAC;IAEpC,IAAI,OAAO,UAAU,CAAC,uBAAgB,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC5D,WAAW,CAAC,KAAK,GAAG,UAAU,CAAC,uBAAgB,CAAC,MAAM,CAAW,CAAC;IACpE,CAAC;IAED,IAAI,OAAO,UAAU,CAAC,uBAAgB,CAAC,UAAU,CAAC,KAAK,QAAQ,EAAE,CAAC;QAChE,WAAW,CAAC,SAAS,GAAG,UAAU,CAAC,uBAAgB,CAAC,UAAU,CAAW,CAAC;IAC5E,CAAC;IAED,IAAI,OAAO,UAAU,CAAC,uBAAgB,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC7D,WAAW,CAAC,MAAM,GAAG,UAAU,CAAC,uBAAgB,CAAC,OAAO,CAAW,CAAC;IACtE,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAMD,SAAgB,eAAe;IAC7B,MAAM,WAAW,GAAgB,EAAE,CAAC;IAEpC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAa,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC1B,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,C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AAO;QACP,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { Environment, RawConfig } from '../types/config';
2
+ export interface EnvFileResult {
3
+ path: string;
4
+ loaded: boolean;
5
+ error?: string;
6
+ }
7
+ export interface EnvFileOptions {
8
+ baseDir?: string;
9
+ override?: boolean;
10
+ additionalFiles?: string[];
11
+ }
12
+ export declare function getEnvFilePaths(environment: Environment, options?: EnvFileOptions): string[];
13
+ export declare function loadEnvFile(filePath: string, override?: boolean): EnvFileResult;
14
+ export declare function loadEnvFiles(filePaths: string[], override?: boolean): EnvFileResult[];
15
+ export declare function loadEnvironmentConfig(environment: Environment, options?: EnvFileOptions, override?: boolean): EnvFileResult[];
16
+ export declare function extractRawConfig(): RawConfig;
17
+ export declare function validateEnvironment(env: string | undefined): Environment | undefined;
18
+ export declare function parseBoolean(value: string | undefined, defaultValue?: boolean): boolean;
19
+ export declare function parseInteger(value: string | undefined, defaultValue: number, min?: number, max?: number): number;
20
+ export declare function parseUrl(value: string | undefined, defaultValue: string): string;
21
+ export declare function findConfigFile(configPath?: string, baseDir?: string): string | undefined;
22
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAqB,MAAM,iBAAiB,CAAC;AAK5E,MAAM,WAAW,aAAa;IAE5B,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,OAAO,CAAC;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD,MAAM,WAAW,cAAc;IAE7B,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAQD,wBAAgB,eAAe,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,EAAE,CAqBhG;AAQD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,aAAa,CAwBtF;AAQD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAE,OAAe,GAAG,aAAa,EAAE,CAE5F;AASD,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,GAAE,cAAmB,EAAE,QAAQ,GAAE,OAAe,GAAG,aAAa,EAAE,CAGxI;AAMD,wBAAgB,gBAAgB,IAAI,SAAS,CAY5C;AAOD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAepF;AAQD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,YAAY,GAAE,OAAe,GAAG,OAAO,CAK9F;AAUD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAUR;AAQD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAYhF;AAQD,wBAAgB,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,MAAsB,GAAG,MAAM,GAAG,SAAS,CAKvG"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEnvFilePaths = getEnvFilePaths;
4
+ exports.loadEnvFile = loadEnvFile;
5
+ exports.loadEnvFiles = loadEnvFiles;
6
+ exports.loadEnvironmentConfig = loadEnvironmentConfig;
7
+ exports.extractRawConfig = extractRawConfig;
8
+ exports.validateEnvironment = validateEnvironment;
9
+ exports.parseBoolean = parseBoolean;
10
+ exports.parseInteger = parseInteger;
11
+ exports.parseUrl = parseUrl;
12
+ exports.findConfigFile = findConfigFile;
13
+ const dotenv_1 = require("dotenv");
14
+ const fs_1 = require("fs");
15
+ const path_1 = require("path");
16
+ const config_1 = require("../types/config");
17
+ function getEnvFilePaths(environment, options = {}) {
18
+ const baseDir = options.baseDir || process.cwd();
19
+ const files = [];
20
+ if (options.override && options.additionalFiles) {
21
+ return options.additionalFiles.map(file => (0, path_1.resolve)(baseDir, file));
22
+ }
23
+ files.push((0, path_1.resolve)(baseDir, config_1.ENV_FILE_PATTERNS.base));
24
+ files.push((0, path_1.resolve)(baseDir, config_1.ENV_FILE_PATTERNS.environment(environment)));
25
+ files.push((0, path_1.resolve)(baseDir, config_1.ENV_FILE_PATTERNS.local));
26
+ files.push((0, path_1.resolve)(baseDir, config_1.ENV_FILE_PATTERNS.environmentLocal(environment)));
27
+ if (options.additionalFiles) {
28
+ files.push(...options.additionalFiles.map(file => (0, path_1.resolve)(baseDir, file)));
29
+ }
30
+ return files;
31
+ }
32
+ function loadEnvFile(filePath, override = false) {
33
+ const result = {
34
+ path: filePath,
35
+ loaded: false,
36
+ };
37
+ try {
38
+ if (!(0, fs_1.existsSync)(filePath)) {
39
+ return result;
40
+ }
41
+ const dotenvResult = (0, dotenv_1.config)({ path: filePath, override });
42
+ if (dotenvResult.error) {
43
+ result.error = dotenvResult.error.message;
44
+ return result;
45
+ }
46
+ result.loaded = true;
47
+ return result;
48
+ }
49
+ catch (error) {
50
+ result.error = error instanceof Error ? error.message : 'Unknown error occurred';
51
+ return result;
52
+ }
53
+ }
54
+ function loadEnvFiles(filePaths, override = false) {
55
+ return filePaths.map(path => loadEnvFile(path, override));
56
+ }
57
+ function loadEnvironmentConfig(environment, options = {}, override = false) {
58
+ const filePaths = getEnvFilePaths(environment, options);
59
+ return loadEnvFiles(filePaths, override);
60
+ }
61
+ function extractRawConfig() {
62
+ return {
63
+ POLYV_ENVIRONMENT: process.env['POLYV_ENVIRONMENT'],
64
+ POLYV_DEBUG: process.env['POLYV_DEBUG'],
65
+ POLYV_TIMEOUT: process.env['POLYV_TIMEOUT'],
66
+ POLYV_BASE_URL: process.env['POLYV_BASE_URL'],
67
+ POLYV_MAX_RETRIES: process.env['POLYV_MAX_RETRIES'],
68
+ POLYV_CONFIG_PATH: process.env['POLYV_CONFIG_PATH'],
69
+ POLYV_APP_ID: process.env['POLYV_APP_ID'],
70
+ POLYV_APP_SECRET: process.env['POLYV_APP_SECRET'],
71
+ POLYV_USER_ID: process.env['POLYV_USER_ID'],
72
+ };
73
+ }
74
+ function validateEnvironment(env) {
75
+ if (!env)
76
+ return undefined;
77
+ const normalizedEnv = env.toLowerCase().trim();
78
+ if (normalizedEnv === 'development' || normalizedEnv === 'dev') {
79
+ return 'development';
80
+ }
81
+ if (normalizedEnv === 'production' || normalizedEnv === 'prod') {
82
+ return 'production';
83
+ }
84
+ if (normalizedEnv === 'test') {
85
+ return 'test';
86
+ }
87
+ return undefined;
88
+ }
89
+ function parseBoolean(value, defaultValue = false) {
90
+ if (!value)
91
+ return defaultValue;
92
+ const normalized = value.toLowerCase().trim();
93
+ return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on';
94
+ }
95
+ function parseInteger(value, defaultValue, min, max) {
96
+ if (!value)
97
+ return defaultValue;
98
+ const parsed = parseInt(value.trim(), 10);
99
+ if (isNaN(parsed))
100
+ return defaultValue;
101
+ if (min !== undefined && parsed < min)
102
+ return defaultValue;
103
+ if (max !== undefined && parsed > max)
104
+ return defaultValue;
105
+ return parsed;
106
+ }
107
+ function parseUrl(value, defaultValue) {
108
+ if (!value)
109
+ return defaultValue;
110
+ const trimmed = value.trim();
111
+ if (!trimmed)
112
+ return defaultValue;
113
+ try {
114
+ new URL(trimmed);
115
+ return trimmed;
116
+ }
117
+ catch {
118
+ return defaultValue;
119
+ }
120
+ }
121
+ function findConfigFile(configPath, baseDir = process.cwd()) {
122
+ if (!configPath)
123
+ return undefined;
124
+ const resolvedPath = (0, path_1.resolve)(baseDir, configPath);
125
+ return (0, fs_1.existsSync)(resolvedPath) ? resolvedPath : undefined;
126
+ }
127
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":";;AAuCA,0CAqBC;AAQD,kCAwBC;AAQD,oCAEC;AASD,sDAGC;AAMD,4CAYC;AAOD,kDAeC;AAQD,oCAKC;AAUD,oCAeC;AAQD,4BAYC;AAQD,wCAKC;AA7ND,mCAAgD;AAChD,2BAAgC;AAChC,+BAA+B;AAC/B,4CAA4E;AAgC5E,SAAgB,eAAe,CAAC,WAAwB,EAAE,UAA0B,EAAE;IACpF,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACjD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;QAEhD,OAAO,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAA,cAAO,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;IAGD,KAAK,CAAC,IAAI,CAAC,IAAA,cAAO,EAAC,OAAO,EAAE,0BAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IACrD,KAAK,CAAC,IAAI,CAAC,IAAA,cAAO,EAAC,OAAO,EAAE,0BAAiB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACzE,KAAK,CAAC,IAAI,CAAC,IAAA,cAAO,EAAC,OAAO,EAAE,0BAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IACtD,KAAK,CAAC,IAAI,CAAC,IAAA,cAAO,EAAC,OAAO,EAAE,0BAAiB,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAG9E,IAAI,OAAO,CAAC,eAAe,EAAE,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AAU,CAAC,CAAC;IAClD,OAAO,IAAA,eAAU,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { AppConfig, ConfigResult, ConfigOptions, ConfigSources } from '../types/config';
2
+ export declare class ConfigManager {
3
+ private config;
4
+ private sources;
5
+ private loadedEnvFiles;
6
+ load(options?: ConfigOptions): Promise<ConfigResult>;
7
+ getConfig(): AppConfig | null;
8
+ getSources(): ConfigSources | null;
9
+ getLoadedEnvFiles(): string[];
10
+ reload(options?: ConfigOptions): Promise<ConfigResult>;
11
+ private determineEnvironment;
12
+ private loadCliConfig;
13
+ private mergeConfigurations;
14
+ private createAuthConfig;
15
+ }
16
+ export declare const configManager: ConfigManager;
17
+ export declare function loadConfig(options?: ConfigOptions): Promise<ConfigResult>;
18
+ export declare function getConfig(): AppConfig | null;
19
+ export declare function reloadConfig(options?: ConfigOptions): Promise<ConfigResult>;
20
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/config/manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAe,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAUrG,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,cAAc,CAAgB;IAOhC,IAAI,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAsH9D,SAAS,IAAI,SAAS,GAAG,IAAI;IAQ7B,UAAU,IAAI,aAAa,GAAG,IAAI;IAQlC,iBAAiB,IAAI,MAAM,EAAE;IASvB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAShE,OAAO,CAAC,oBAAoB;IA+B5B,OAAO,CAAC,aAAa;IAiErB,OAAO,CAAC,mBAAmB;IA4H3B,OAAO,CAAC,gBAAgB;CAWzB;AAKD,eAAO,MAAM,aAAa,eAAsB,CAAC;AAOjD,wBAAsB,UAAU,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAEnF;AAMD,wBAAgB,SAAS,IAAI,SAAS,GAAG,IAAI,CAE5C;AAOD,wBAAsB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAErF"}