@positronic/cli 0.0.58 → 0.0.60

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.
@@ -233,7 +233,7 @@ import * as https from 'https';
233
233
  import { URL } from 'url';
234
234
  import { createRequire } from 'module';
235
235
  import * as dotenv from 'dotenv';
236
- import { maybeSignRequest } from '../lib/request-signer.js';
236
+ import { getAuthHeader } from '../lib/jwt-auth.js';
237
237
  // API client configuration
238
238
  var apiBaseUrl = null;
239
239
  var isLocalDevMode = true;
@@ -267,44 +267,55 @@ var isLocalDevMode = true;
267
267
  export var apiClient = {
268
268
  fetch: function(apiPath, options) {
269
269
  return _async_to_generator(function() {
270
- var baseUrl, port, fullUrl, requestOptions, method, existingHeaders, headersObj, signatureHeaders;
270
+ var baseUrl, port, fullUrl, requestOptions, existingHeaders, headersObj, authHeader;
271
271
  return _ts_generator(this, function(_state) {
272
- if (apiBaseUrl) {
273
- baseUrl = apiBaseUrl;
274
- } else {
275
- // Fallback to localhost (for backwards compatibility and testing)
276
- port = process.env.POSITRONIC_PORT || '8787';
277
- baseUrl = "http://localhost:".concat(port);
278
- }
279
- fullUrl = "".concat(baseUrl).concat(apiPath.startsWith('/') ? apiPath : '/' + apiPath);
280
- // Sign requests when not in local dev mode
281
- requestOptions = options || {};
282
- if (!isLocalDevMode) {
283
- method = ((options === null || options === void 0 ? void 0 : options.method) || 'GET').toUpperCase();
284
- existingHeaders = (options === null || options === void 0 ? void 0 : options.headers) || {};
285
- headersObj = {};
286
- // Convert headers to plain object
287
- if (_instanceof(existingHeaders, Headers)) {
288
- existingHeaders.forEach(function(value, key) {
289
- headersObj[key] = value;
290
- });
291
- } else if (Array.isArray(existingHeaders)) {
292
- existingHeaders.forEach(function(param) {
293
- var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
294
- headersObj[key] = value;
272
+ switch(_state.label){
273
+ case 0:
274
+ if (apiBaseUrl) {
275
+ baseUrl = apiBaseUrl;
276
+ } else {
277
+ // Fallback to localhost (for backwards compatibility and testing)
278
+ port = process.env.POSITRONIC_PORT || '8787';
279
+ baseUrl = "http://localhost:".concat(port);
280
+ }
281
+ fullUrl = "".concat(baseUrl).concat(apiPath.startsWith('/') ? apiPath : '/' + apiPath);
282
+ // Add auth header when not in local dev mode
283
+ requestOptions = options || {};
284
+ if (!!isLocalDevMode) return [
285
+ 3,
286
+ 2
287
+ ];
288
+ existingHeaders = (options === null || options === void 0 ? void 0 : options.headers) || {};
289
+ headersObj = {};
290
+ // Convert headers to plain object
291
+ if (_instanceof(existingHeaders, Headers)) {
292
+ existingHeaders.forEach(function(value, key) {
293
+ headersObj[key] = value;
294
+ });
295
+ } else if (Array.isArray(existingHeaders)) {
296
+ existingHeaders.forEach(function(param) {
297
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
298
+ headersObj[key] = value;
299
+ });
300
+ } else {
301
+ Object.assign(headersObj, existingHeaders);
302
+ }
303
+ return [
304
+ 4,
305
+ getAuthHeader()
306
+ ];
307
+ case 1:
308
+ authHeader = _state.sent();
309
+ requestOptions = _object_spread_props(_object_spread({}, options), {
310
+ headers: _object_spread({}, headersObj, authHeader)
295
311
  });
296
- } else {
297
- Object.assign(headersObj, existingHeaders);
298
- }
299
- signatureHeaders = maybeSignRequest(method, fullUrl, headersObj);
300
- requestOptions = _object_spread_props(_object_spread({}, options), {
301
- headers: _object_spread({}, headersObj, signatureHeaders)
302
- });
312
+ _state.label = 2;
313
+ case 2:
314
+ return [
315
+ 2,
316
+ fetch(fullUrl, requestOptions)
317
+ ];
303
318
  }
304
- return [
305
- 2,
306
- fetch(fullUrl, requestOptions)
307
- ];
308
319
  });
309
320
  })();
310
321
  },
@@ -47,7 +47,7 @@ function _unsupported_iterable_to_array(o, minLen) {
47
47
  import React, { useState } from 'react';
48
48
  import { Box, Text, useApp } from 'ink';
49
49
  import { discoverSSHKeys, expandPath } from '../lib/ssh-key-utils.js';
50
- import { resetRequestSigner } from '../lib/request-signer.js';
50
+ import { resetJwtAuthProvider } from '../lib/jwt-auth.js';
51
51
  import { SelectList } from './select-list.js';
52
52
  import { existsSync } from 'fs';
53
53
  export var AuthLogin = function(param) {
@@ -103,7 +103,7 @@ export var AuthLogin = function(param) {
103
103
  configManager.setDefaultPrivateKeyPath(keyPath);
104
104
  }
105
105
  // Reset request signer to use new key
106
- resetRequestSigner();
106
+ resetJwtAuthProvider();
107
107
  return /*#__PURE__*/ React.createElement(Box, {
108
108
  flexDirection: "column",
109
109
  paddingTop: 1,
@@ -163,7 +163,7 @@ export var AuthLogin = function(param) {
163
163
  configManager.setDefaultPrivateKeyPath(displayPath);
164
164
  }
165
165
  // Reset request signer to use new key
166
- resetRequestSigner();
166
+ resetJwtAuthProvider();
167
167
  setSelectedPath(displayPath);
168
168
  setState('success');
169
169
  };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Box, Text } from 'ink';
3
- import { resetRequestSigner } from '../lib/request-signer.js';
3
+ import { resetJwtAuthProvider } from '../lib/jwt-auth.js';
4
4
  export var AuthLogout = function(param) {
5
5
  var configManager = param.configManager, forProject = param.forProject;
6
6
  var currentProject = configManager.getCurrentProject();
@@ -33,7 +33,7 @@ export var AuthLogout = function(param) {
33
33
  }, "Nothing to clear.")));
34
34
  }
35
35
  configManager.clearProjectPrivateKeyPath(currentProject.name);
36
- resetRequestSigner();
36
+ resetJwtAuthProvider();
37
37
  return /*#__PURE__*/ React.createElement(Box, {
38
38
  flexDirection: "column",
39
39
  paddingTop: 1,
@@ -60,7 +60,7 @@ export var AuthLogout = function(param) {
60
60
  }, "Nothing to clear.")));
61
61
  }
62
62
  configManager.clearDefaultPrivateKeyPath();
63
- resetRequestSigner();
63
+ resetJwtAuthProvider();
64
64
  return /*#__PURE__*/ React.createElement(Box, {
65
65
  flexDirection: "column",
66
66
  paddingTop: 1,