@positronic/cli 0.0.57 → 0.0.59
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/dist/src/cli.js +9 -0
- package/dist/src/commands/auth.js +13 -0
- package/dist/src/commands/helpers.js +60 -27
- package/dist/src/components/auth-format-jwk-key.js +457 -0
- package/dist/src/components/auth-login.js +3 -3
- package/dist/src/components/auth-logout.js +3 -3
- package/dist/src/hooks/useApi.js +183 -49
- package/dist/src/lib/jwt-auth.js +364 -0
- package/dist/src/lib/ssh-key-utils.js +0 -9
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/commands/auth.d.ts +8 -0
- package/dist/types/commands/auth.d.ts.map +1 -1
- package/dist/types/commands/helpers.d.ts +4 -0
- package/dist/types/commands/helpers.d.ts.map +1 -1
- package/dist/types/components/auth-format-jwk-key.d.ts +6 -0
- package/dist/types/components/auth-format-jwk-key.d.ts.map +1 -0
- package/dist/types/hooks/useApi.d.ts.map +1 -1
- package/dist/types/lib/jwt-auth.d.ts +51 -0
- package/dist/types/lib/jwt-auth.d.ts.map +1 -0
- package/dist/types/lib/ssh-key-utils.d.ts +0 -4
- package/dist/types/lib/ssh-key-utils.d.ts.map +1 -1
- package/package.json +5 -4
- package/dist/src/lib/request-signer.js +0 -208
- package/dist/types/lib/request-signer.d.ts +0 -51
- package/dist/types/lib/request-signer.d.ts.map +0 -1
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
function _class_call_check(instance, Constructor) {
|
|
2
|
-
if (!(instance instanceof Constructor)) {
|
|
3
|
-
throw new TypeError("Cannot call a class as a function");
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
function _defineProperties(target, props) {
|
|
7
|
-
for(var i = 0; i < props.length; i++){
|
|
8
|
-
var descriptor = props[i];
|
|
9
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
-
descriptor.configurable = true;
|
|
11
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
-
return Constructor;
|
|
19
|
-
}
|
|
20
|
-
function _define_property(obj, key, value) {
|
|
21
|
-
if (key in obj) {
|
|
22
|
-
Object.defineProperty(obj, key, {
|
|
23
|
-
value: value,
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
obj[key] = value;
|
|
30
|
-
}
|
|
31
|
-
return obj;
|
|
32
|
-
}
|
|
33
|
-
function _instanceof(left, right) {
|
|
34
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
35
|
-
return !!right[Symbol.hasInstance](left);
|
|
36
|
-
} else {
|
|
37
|
-
return left instanceof right;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
import { loadPrivateKey, getPrivateKeyFingerprint, signWithPrivateKey, resolvePrivateKeyPath } from './ssh-key-utils.js';
|
|
41
|
-
import { existsSync } from 'fs';
|
|
42
|
-
import { ProjectConfigManager } from '../commands/project-config-manager.js';
|
|
43
|
-
/**
|
|
44
|
-
* Request signer for RFC 9421 HTTP Message Signatures
|
|
45
|
-
*/ export var RequestSigner = /*#__PURE__*/ function() {
|
|
46
|
-
"use strict";
|
|
47
|
-
function RequestSigner() {
|
|
48
|
-
_class_call_check(this, RequestSigner);
|
|
49
|
-
_define_property(this, "privateKey", null);
|
|
50
|
-
_define_property(this, "fingerprint", null);
|
|
51
|
-
_define_property(this, "initialized", false);
|
|
52
|
-
_define_property(this, "initError", null);
|
|
53
|
-
this.initialize();
|
|
54
|
-
}
|
|
55
|
-
_create_class(RequestSigner, [
|
|
56
|
-
{
|
|
57
|
-
key: "initialize",
|
|
58
|
-
value: function initialize() {
|
|
59
|
-
try {
|
|
60
|
-
// Get configured path from project config manager
|
|
61
|
-
var configManager = new ProjectConfigManager();
|
|
62
|
-
var configuredPath = configManager.getPrivateKeyPath();
|
|
63
|
-
var keyPath = resolvePrivateKeyPath(configuredPath);
|
|
64
|
-
if (!existsSync(keyPath)) {
|
|
65
|
-
this.initError = new Error("Private key not found at ".concat(keyPath, ". Run 'px auth login' to configure your SSH key, or set POSITRONIC_PRIVATE_KEY environment variable."));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
this.privateKey = loadPrivateKey(keyPath);
|
|
69
|
-
this.fingerprint = getPrivateKeyFingerprint(this.privateKey);
|
|
70
|
-
this.initialized = true;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
this.initError = _instanceof(error, Error) ? error : new Error('Failed to initialize request signer');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
/**
|
|
78
|
-
* Check if the signer is ready to sign requests
|
|
79
|
-
*/ key: "isReady",
|
|
80
|
-
value: function isReady() {
|
|
81
|
-
return this.initialized && this.privateKey !== null;
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
/**
|
|
86
|
-
* Get the error that occurred during initialization, if any
|
|
87
|
-
*/ key: "getError",
|
|
88
|
-
value: function getError() {
|
|
89
|
-
return this.initError;
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
/**
|
|
94
|
-
* Get the fingerprint of the loaded private key
|
|
95
|
-
*/ key: "getFingerprint",
|
|
96
|
-
value: function getFingerprint() {
|
|
97
|
-
return this.fingerprint;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
/**
|
|
102
|
-
* Sign an HTTP request and return the signature headers
|
|
103
|
-
*/ key: "signRequest",
|
|
104
|
-
value: function signRequest(method, url) {
|
|
105
|
-
var headers = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
106
|
-
if (!this.privateKey || !this.fingerprint) {
|
|
107
|
-
throw new Error('Request signer not initialized');
|
|
108
|
-
}
|
|
109
|
-
var parsedUrl = new URL(url);
|
|
110
|
-
var created = Math.floor(Date.now() / 1000);
|
|
111
|
-
// Build the signature base
|
|
112
|
-
var coveredComponents = [
|
|
113
|
-
'"@method"',
|
|
114
|
-
'"@path"',
|
|
115
|
-
'"@authority"'
|
|
116
|
-
];
|
|
117
|
-
// Add content-type if present
|
|
118
|
-
if (headers['Content-Type'] || headers['content-type']) {
|
|
119
|
-
coveredComponents.push('"content-type"');
|
|
120
|
-
}
|
|
121
|
-
// Create the signature base string
|
|
122
|
-
var signatureBaseLines = [];
|
|
123
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
124
|
-
try {
|
|
125
|
-
for(var _iterator = coveredComponents[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
126
|
-
var component = _step.value;
|
|
127
|
-
var componentName = component.replace(/"/g, '');
|
|
128
|
-
if (componentName === '@method') {
|
|
129
|
-
signatureBaseLines.push('"@method": '.concat(method.toUpperCase()));
|
|
130
|
-
} else if (componentName === '@path') {
|
|
131
|
-
signatureBaseLines.push('"@path": '.concat(parsedUrl.pathname));
|
|
132
|
-
} else if (componentName === '@authority') {
|
|
133
|
-
signatureBaseLines.push('"@authority": '.concat(parsedUrl.host));
|
|
134
|
-
} else {
|
|
135
|
-
// Regular header
|
|
136
|
-
var headerValue = headers[componentName] || headers[componentName.toLowerCase()] || headers[componentName.charAt(0).toUpperCase() + componentName.slice(1)];
|
|
137
|
-
if (headerValue) {
|
|
138
|
-
signatureBaseLines.push('"'.concat(componentName.toLowerCase(), '": ').concat(headerValue));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
} catch (err) {
|
|
143
|
-
_didIteratorError = true;
|
|
144
|
-
_iteratorError = err;
|
|
145
|
-
} finally{
|
|
146
|
-
try {
|
|
147
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
148
|
-
_iterator.return();
|
|
149
|
-
}
|
|
150
|
-
} finally{
|
|
151
|
-
if (_didIteratorError) {
|
|
152
|
-
throw _iteratorError;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// Create the signature-params line
|
|
157
|
-
var signatureParams = "(".concat(coveredComponents.join(' '), ");created=").concat(created, ';keyid="').concat(this.fingerprint, '"');
|
|
158
|
-
signatureBaseLines.push('"@signature-params": '.concat(signatureParams));
|
|
159
|
-
var signatureBase = signatureBaseLines.join('\n');
|
|
160
|
-
// Sign the base
|
|
161
|
-
var signatureBytes = signWithPrivateKey(this.privateKey, signatureBase);
|
|
162
|
-
var signatureValue = signatureBytes.toString('base64');
|
|
163
|
-
return {
|
|
164
|
-
Signature: "sig1=:".concat(signatureValue, ":"),
|
|
165
|
-
'Signature-Input': "sig1=".concat(signatureParams)
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
]);
|
|
170
|
-
return RequestSigner;
|
|
171
|
-
}();
|
|
172
|
-
// Singleton instance
|
|
173
|
-
var signerInstance = null;
|
|
174
|
-
/**
|
|
175
|
-
* Get the singleton request signer instance
|
|
176
|
-
*/ export function getRequestSigner() {
|
|
177
|
-
if (!signerInstance) {
|
|
178
|
-
signerInstance = new RequestSigner();
|
|
179
|
-
}
|
|
180
|
-
return signerInstance;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Reset the request signer singleton
|
|
184
|
-
* Call this after auth config changes to force reinitialization with new key
|
|
185
|
-
*/ export function resetRequestSigner() {
|
|
186
|
-
signerInstance = null;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Check if request signing is available
|
|
190
|
-
*/ export function isSigningAvailable() {
|
|
191
|
-
return getRequestSigner().isReady();
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Sign an HTTP request if signing is available
|
|
195
|
-
* Returns the additional headers to add, or empty object if signing is not available
|
|
196
|
-
*/ export function maybeSignRequest(method, url) {
|
|
197
|
-
var headers = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
198
|
-
var signer = getRequestSigner();
|
|
199
|
-
if (!signer.isReady()) {
|
|
200
|
-
return {};
|
|
201
|
-
}
|
|
202
|
-
try {
|
|
203
|
-
return signer.signRequest(method, url, headers);
|
|
204
|
-
} catch (error) {
|
|
205
|
-
console.error('Warning: Failed to sign request:', error);
|
|
206
|
-
return {};
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export type SignedHeaders = {
|
|
2
|
-
Signature: string;
|
|
3
|
-
'Signature-Input': string;
|
|
4
|
-
[key: string]: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Request signer for RFC 9421 HTTP Message Signatures
|
|
8
|
-
*/
|
|
9
|
-
export declare class RequestSigner {
|
|
10
|
-
private privateKey;
|
|
11
|
-
private fingerprint;
|
|
12
|
-
private initialized;
|
|
13
|
-
private initError;
|
|
14
|
-
constructor();
|
|
15
|
-
private initialize;
|
|
16
|
-
/**
|
|
17
|
-
* Check if the signer is ready to sign requests
|
|
18
|
-
*/
|
|
19
|
-
isReady(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Get the error that occurred during initialization, if any
|
|
22
|
-
*/
|
|
23
|
-
getError(): Error | null;
|
|
24
|
-
/**
|
|
25
|
-
* Get the fingerprint of the loaded private key
|
|
26
|
-
*/
|
|
27
|
-
getFingerprint(): string | null;
|
|
28
|
-
/**
|
|
29
|
-
* Sign an HTTP request and return the signature headers
|
|
30
|
-
*/
|
|
31
|
-
signRequest(method: string, url: string, headers?: Record<string, string>): SignedHeaders;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Get the singleton request signer instance
|
|
35
|
-
*/
|
|
36
|
-
export declare function getRequestSigner(): RequestSigner;
|
|
37
|
-
/**
|
|
38
|
-
* Reset the request signer singleton
|
|
39
|
-
* Call this after auth config changes to force reinitialization with new key
|
|
40
|
-
*/
|
|
41
|
-
export declare function resetRequestSigner(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Check if request signing is available
|
|
44
|
-
*/
|
|
45
|
-
export declare function isSigningAvailable(): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Sign an HTTP request if signing is available
|
|
48
|
-
* Returns the additional headers to add, or empty object if signing is not available
|
|
49
|
-
*/
|
|
50
|
-
export declare function maybeSignRequest(method: string, url: string, headers?: Record<string, string>): Record<string, string>;
|
|
51
|
-
//# sourceMappingURL=request-signer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-signer.d.ts","sourceRoot":"","sources":["../../../src/lib/request-signer.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAsB;;IAMvC,OAAO,CAAC,UAAU;IA0BlB;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,QAAQ,IAAI,KAAK,GAAG,IAAI;IAIxB;;OAEG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACH,WAAW,CACT,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,aAAa;CAuDjB;AAKD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYxB"}
|