@tencent-adp/portal-cli 0.0.1 → 0.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.
package/dist/acp/agent.js CHANGED
@@ -10,7 +10,7 @@ import { runAcpTurn } from './turn.js';
10
10
  export function portalInitialize(needsLogin = false) {
11
11
  return {
12
12
  protocolVersion: PROTOCOL_VERSION,
13
- agentInfo: { name: 'portal', title: 'Portal', version: '0.0.1' },
13
+ agentInfo: { name: 'portal', title: 'Portal', version: '0.0.2' },
14
14
  agentCapabilities: {
15
15
  loadSession: true,
16
16
  sessionCapabilities: { list: {} },
@@ -1,6 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash, randomBytes } from 'node:crypto';
3
3
  import { createServer } from 'node:http';
4
+ import { portalHeaders } from '../portal/headers.js';
4
5
  import { readAuthFile, writeAuthFile } from './loadAuth.js';
5
6
  const CALLBACK_PORT = 0;
6
7
  const CALLBACK_PATH = '/callback';
@@ -273,7 +274,7 @@ function openBrowser(url) {
273
274
  child.unref();
274
275
  }
275
276
  async function getJson(url) {
276
- const response = await fetch(url, { headers: { Accept: 'application/json' } });
277
+ const response = await fetch(url, { headers: portalHeaders(url, { Accept: 'application/json' }) });
277
278
  const body = await readResponse(response);
278
279
  if (!response.ok)
279
280
  throw new Error(stringField(body, 'error_description') || `GET ${url.pathname} failed with HTTP ${response.status}`);
@@ -282,7 +283,7 @@ async function getJson(url) {
282
283
  async function postJson(url, payload) {
283
284
  const response = await fetch(url, {
284
285
  method: 'POST',
285
- headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
286
+ headers: portalHeaders(url, { Accept: 'application/json', 'Content-Type': 'application/json' }),
286
287
  body: JSON.stringify(payload),
287
288
  });
288
289
  const body = await readResponse(response);
@@ -293,7 +294,7 @@ async function postJson(url, payload) {
293
294
  async function postForm(url, fields) {
294
295
  const response = await fetch(url, {
295
296
  method: 'POST',
296
- headers: { Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded' },
297
+ headers: portalHeaders(url, { Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded' }),
297
298
  body: new URLSearchParams(fields),
298
299
  });
299
300
  const body = await readResponse(response);
@@ -1,4 +1,5 @@
1
1
  import { randomBytes } from 'node:crypto';
2
+ import { portalHeaders } from './headers.js';
2
3
  import { loggedSseBody, logSse } from './sseLog.js';
3
4
  export class PortalClient {
4
5
  auth;
@@ -72,10 +73,10 @@ export class PortalClient {
72
73
  async call(url, init) {
73
74
  const send = () => fetch(url, {
74
75
  ...init,
75
- headers: {
76
+ headers: portalHeaders(url, {
76
77
  ...init.headers,
77
78
  Authorization: `Bearer ${this.auth.token}`,
78
- },
79
+ }),
79
80
  });
80
81
  const response = await send();
81
82
  if (response.status !== 401 || !this.auth.renew)
@@ -0,0 +1,3 @@
1
+ /** AIO-Forward rejects a POST that has no Origin. Browsers send it; Node does not. */
2
+ export declare function portalHeaders(url: string | URL, headers?: Record<string, string>): Record<string, string>;
3
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1,5 @@
1
+ /** AIO-Forward rejects a POST that has no Origin. Browsers send it; Node does not. */
2
+ export function portalHeaders(url, headers = {}) {
3
+ return { ...headers, Origin: new URL(url).origin };
4
+ }
5
+ //# sourceMappingURL=headers.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencent-adp/portal-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Talk to a Portal agent and let it use this machine",
5
5
  "type": "module",
6
6
  "bin": {