@positronic/cli 0.0.28 → 0.0.29

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.
@@ -226,14 +226,37 @@ import * as http from 'http';
226
226
  import * as https from 'https';
227
227
  import { URL } from 'url';
228
228
  import { createRequire } from 'module';
229
+ // API client configuration
230
+ var apiBaseUrl = null;
231
+ var isLocalDevMode = true;
232
+ /**
233
+ * Configure the API client with a base URL.
234
+ * Call this at startup to set where API requests should go.
235
+ * @param baseUrl - The base URL for API requests (e.g., "http://localhost:8787" or "https://api.project.positronic.sh")
236
+ * @param localDevMode - Whether we're in local development mode (affects error messages)
237
+ */ export function configureApiClient(baseUrl) {
238
+ var localDevMode = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
239
+ apiBaseUrl = baseUrl;
240
+ isLocalDevMode = localDevMode;
241
+ }
242
+ /**
243
+ * Get whether the API client is in local dev mode (for error message context)
244
+ */ export function isApiLocalDevMode() {
245
+ return isLocalDevMode;
246
+ }
229
247
  // Singleton API client instance
230
248
  export var apiClient = {
231
249
  fetch: function(apiPath, options) {
232
250
  return _async_to_generator(function() {
233
- var port, baseUrl, fullUrl;
251
+ var baseUrl, port, fullUrl;
234
252
  return _ts_generator(this, function(_state) {
235
- port = process.env.POSITRONIC_PORT || '8787';
236
- baseUrl = "http://localhost:".concat(port);
253
+ if (apiBaseUrl) {
254
+ baseUrl = apiBaseUrl;
255
+ } else {
256
+ // Fallback to localhost (for backwards compatibility and testing)
257
+ port = process.env.POSITRONIC_PORT || '8787';
258
+ baseUrl = "http://localhost:".concat(port);
259
+ }
237
260
  fullUrl = "".concat(baseUrl).concat(apiPath.startsWith('/') ? apiPath : '/' + apiPath);
238
261
  return [
239
262
  2,
@@ -217,7 +217,22 @@ function _ts_generator(thisArg, body) {
217
217
  }
218
218
  }
219
219
  import { useState, useEffect, useCallback } from 'react';
220
- import { apiClient } from '../commands/helpers.js';
220
+ import { apiClient, isApiLocalDevMode } from '../commands/helpers.js';
221
+ function getConnectionErrorMessage() {
222
+ if (isApiLocalDevMode()) {
223
+ return {
224
+ title: 'Connection Error',
225
+ message: 'Error connecting to the local development server.',
226
+ details: "Please ensure the server is running ('positronic server' or 'px s')."
227
+ };
228
+ } else {
229
+ return {
230
+ title: 'Connection Error',
231
+ message: 'Error connecting to the remote project server.',
232
+ details: 'Please check your network connection and verify the project URL is correct.'
233
+ };
234
+ }
235
+ }
221
236
  export function useApiGet(endpoint, options) {
222
237
  var _useState = _sliced_to_array(useState(null), 2), data = _useState[0], setData = _useState[1];
223
238
  var _useState1 = _sliced_to_array(useState(true), 2), loading = _useState1[0], setLoading = _useState1[1];
@@ -225,7 +240,7 @@ export function useApiGet(endpoint, options) {
225
240
  useEffect(function() {
226
241
  var fetchData = function() {
227
242
  return _async_to_generator(function() {
228
- var response, result, errorText, err, errorDetails;
243
+ var response, result, errorText, err, baseError, errorDetails;
229
244
  return _ts_generator(this, function(_state) {
230
245
  switch(_state.label){
231
246
  case 0:
@@ -280,15 +295,14 @@ export function useApiGet(endpoint, options) {
280
295
  ];
281
296
  case 6:
282
297
  err = _state.sent();
298
+ baseError = getConnectionErrorMessage();
283
299
  errorDetails = err.message;
284
300
  if (err.code === 'ECONNREFUSED') {
285
301
  errorDetails = 'Connection refused. The server might not be running or is listening on a different port.';
286
302
  }
287
- setError({
288
- title: 'Connection Error',
289
- message: 'Error connecting to the local development server.',
290
- details: "Please ensure the server is running ('positronic server' or 'px s'). ".concat(errorDetails)
291
- });
303
+ setError(_object_spread_props(_object_spread({}, baseError), {
304
+ details: "".concat(baseError.details, " ").concat(errorDetails)
305
+ }));
292
306
  return [
293
307
  3,
294
308
  8
@@ -322,7 +336,7 @@ export function useApiPost(endpoint, defaultOptions) {
322
336
  var _useState2 = _sliced_to_array(useState(null), 2), error = _useState2[0], setError = _useState2[1];
323
337
  var execute = useCallback(function(body, options) {
324
338
  return _async_to_generator(function() {
325
- var response, result, errorText, errorObj, err, errorDetails, errorObj1;
339
+ var response, result, errorText, errorObj, err, baseError, errorDetails, errorObj1;
326
340
  return _ts_generator(this, function(_state) {
327
341
  switch(_state.label){
328
342
  case 0:
@@ -385,15 +399,14 @@ export function useApiPost(endpoint, defaultOptions) {
385
399
  setError(err);
386
400
  throw err;
387
401
  }
402
+ baseError = getConnectionErrorMessage();
388
403
  errorDetails = err.message;
389
404
  if (err.code === 'ECONNREFUSED') {
390
405
  errorDetails = 'Connection refused. The server might not be running or is listening on a different port.';
391
406
  }
392
- errorObj1 = {
393
- title: 'Connection Error',
394
- message: 'Error connecting to the local development server.',
395
- details: "Please ensure the server is running ('positronic server' or 'px s'). ".concat(errorDetails)
396
- };
407
+ errorObj1 = _object_spread_props(_object_spread({}, baseError), {
408
+ details: "".concat(baseError.details, " ").concat(errorDetails)
409
+ });
397
410
  setError(errorObj1);
398
411
  throw errorObj1;
399
412
  case 7:
@@ -424,7 +437,7 @@ export function useApiDelete(resourceType) {
424
437
  var _useState1 = _sliced_to_array(useState(null), 2), error = _useState1[0], setError = _useState1[1];
425
438
  var execute = useCallback(function(endpoint, options) {
426
439
  return _async_to_generator(function() {
427
- var response, errorText, errorObj, err, errorDetails, errorObj1;
440
+ var response, errorText, errorObj, err, baseError, errorDetails, errorObj1;
428
441
  return _ts_generator(this, function(_state) {
429
442
  switch(_state.label){
430
443
  case 0:
@@ -478,15 +491,14 @@ export function useApiDelete(resourceType) {
478
491
  setError(err);
479
492
  throw err;
480
493
  }
494
+ baseError = getConnectionErrorMessage();
481
495
  errorDetails = err.message;
482
496
  if (err.code === 'ECONNREFUSED') {
483
497
  errorDetails = 'Connection refused. The server might not be running or is listening on a different port.';
484
498
  }
485
- errorObj1 = {
486
- title: 'Connection Error',
487
- message: 'Error connecting to the local development server.',
488
- details: "Please ensure the server is running ('positronic server' or 'px s'). ".concat(errorDetails)
489
- };
499
+ errorObj1 = _object_spread_props(_object_spread({}, baseError), {
500
+ details: "".concat(baseError.details, " ").concat(errorDetails)
501
+ });
490
502
  setError(errorObj1);
491
503
  throw errorObj1;
492
504
  case 6:
@@ -4,6 +4,8 @@ import * as path from 'path';
4
4
  import { buildCli } from './cli.js';
5
5
  import { render } from 'ink';
6
6
  import { createDevServer } from './commands/backend.js';
7
+ import { configureApiClient } from './commands/helpers.js';
8
+ import { ProjectConfigManager } from './commands/project-config-manager.js';
7
9
  function findProjectRootSync(startDir) {
8
10
  var currentDir = path.resolve(startDir);
9
11
  while(true){
@@ -23,6 +25,21 @@ function findProjectRootSync(startDir) {
23
25
  // Determine mode and project path once at the start
24
26
  var projectRootPath = findProjectRootSync(process.cwd());
25
27
  var server = projectRootPath ? await createDevServer(projectRootPath) : undefined;
28
+ // Configure API client based on mode
29
+ if (projectRootPath) {
30
+ // Local Dev Mode: connect to localhost
31
+ var port = process.env.POSITRONIC_PORT || '8787';
32
+ configureApiClient("http://localhost:".concat(port), true);
33
+ } else {
34
+ // Global Mode: connect to the selected project's URL
35
+ var configManager = new ProjectConfigManager();
36
+ var currentProject = configManager.getCurrentProject();
37
+ if (currentProject) {
38
+ configureApiClient(currentProject.url, false);
39
+ }
40
+ // If no project is selected, leave apiClient unconfigured
41
+ // Commands will show appropriate errors when they try to connect
42
+ }
26
43
  // Build and parse the CLI
27
44
  var cli = buildCli({
28
45
  server: server,
@@ -6,6 +6,17 @@ export interface ProgressInfo {
6
6
  }
7
7
  export type ProgressCallback = (progress: ProgressInfo) => void;
8
8
  export type ApiClient = typeof apiClient;
9
+ /**
10
+ * Configure the API client with a base URL.
11
+ * Call this at startup to set where API requests should go.
12
+ * @param baseUrl - The base URL for API requests (e.g., "http://localhost:8787" or "https://api.project.positronic.sh")
13
+ * @param localDevMode - Whether we're in local development mode (affects error messages)
14
+ */
15
+ export declare function configureApiClient(baseUrl: string, localDevMode?: boolean): void;
16
+ /**
17
+ * Get whether the API client is in local dev mode (for error message context)
18
+ */
19
+ export declare function isApiLocalDevMode(): boolean;
9
20
  export declare const apiClient: {
10
21
  fetch: (apiPath: string, options?: RequestInit) =>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,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;;;;eAIjD,MAAM;iBACJ,MAAM;kBACL,MAAM;;EA8CnB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,GAAG;;;;eAIzD,MAAM;iBACJ,MAAM;kBACL,MAAM;;qBAIF,GAAG,YAAY,GAAG;EAsDnC;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM;;;eAGtC,MAAM;iBACJ,MAAM;kBACL,MAAM;;wBAIC,MAAM,YAAY,GAAG;EAkDzC"}
1
+ {"version":3,"file":"useApi.d.ts","sourceRoot":"","sources":["../../../src/hooks/useApi.ts"],"names":[],"mappings":"AAmBA,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;;;;eAIjD,MAAM;iBACJ,MAAM;kBACL,MAAM;;EA8CnB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,GAAG;;;;eAIzD,MAAM;iBACJ,MAAM;kBACL,MAAM;;qBAIF,GAAG,YAAY,GAAG;EAsDnC;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM;;;eAGtC,MAAM;iBACJ,MAAM;kBACL,MAAM;;wBAIC,MAAM,YAAY,GAAG;EAkDzC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@positronic/cli",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -23,9 +23,9 @@
23
23
  "clean": "rm -rf tsconfig.tsbuildinfo dist node_modules"
24
24
  },
25
25
  "dependencies": {
26
- "@positronic/core": "^0.0.28",
27
- "@positronic/spec": "^0.0.28",
28
- "@positronic/template-new-project": "^0.0.28",
26
+ "@positronic/core": "^0.0.29",
27
+ "@positronic/spec": "^0.0.29",
28
+ "@positronic/template-new-project": "^0.0.29",
29
29
  "caz": "^2.0.0",
30
30
  "chokidar": "^3.6.0",
31
31
  "eventsource": "^3.0.6",