bkper 5.7.3 → 5.8.0
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/README.md +25 -0
- package/lib/agent/bundle/agent-entry.js +110 -103
- package/lib/agent/context-resources.d.ts +44 -0
- package/lib/agent/context-resources.d.ts.map +1 -0
- package/lib/agent/context-resources.js +110 -0
- package/lib/agent/context-resources.js.map +1 -0
- package/lib/agent/interactive/run-agent-mode.d.ts +2 -0
- package/lib/agent/interactive/run-agent-mode.d.ts.map +1 -1
- package/lib/agent/interactive/run-agent-mode.js +22 -3
- package/lib/agent/interactive/run-agent-mode.js.map +1 -1
- package/lib/agent/startup-maintenance.d.ts +13 -2
- package/lib/agent/startup-maintenance.d.ts.map +1 -1
- package/lib/agent/startup-maintenance.js +35 -8
- package/lib/agent/startup-maintenance.js.map +1 -1
- package/lib/cli.js +3 -0
- package/lib/cli.js.map +1 -1
- package/lib/commands/agent-command.d.ts +9 -1
- package/lib/commands/agent-command.d.ts.map +1 -1
- package/lib/commands/agent-command.js +45 -4
- package/lib/commands/agent-command.js.map +1 -1
- package/lib/commands/apps/dev.d.ts.map +1 -1
- package/lib/commands/apps/dev.js +5 -4
- package/lib/commands/apps/dev.js.map +1 -1
- package/lib/commands/apps/git/credentials.d.ts +1 -0
- package/lib/commands/apps/git/credentials.d.ts.map +1 -1
- package/lib/commands/apps/git/credentials.js +1 -1
- package/lib/commands/apps/git/credentials.js.map +1 -1
- package/lib/commands/context/book-context.d.ts +20 -0
- package/lib/commands/context/book-context.d.ts.map +1 -0
- package/lib/commands/context/book-context.js +40 -0
- package/lib/commands/context/book-context.js.map +1 -0
- package/lib/commands/context/domain-context.d.ts +21 -0
- package/lib/commands/context/domain-context.d.ts.map +1 -0
- package/lib/commands/context/domain-context.js +39 -0
- package/lib/commands/context/domain-context.js.map +1 -0
- package/lib/commands/context/git-credential.d.ts +17 -0
- package/lib/commands/context/git-credential.d.ts.map +1 -0
- package/lib/commands/context/git-credential.js +121 -0
- package/lib/commands/context/git-credential.js.map +1 -0
- package/lib/commands/context/platform-context.d.ts +42 -0
- package/lib/commands/context/platform-context.d.ts.map +1 -0
- package/lib/commands/context/platform-context.js +84 -0
- package/lib/commands/context/platform-context.js.map +1 -0
- package/lib/commands/context/register.d.ts +4 -0
- package/lib/commands/context/register.d.ts.map +1 -0
- package/lib/commands/context/register.js +79 -0
- package/lib/commands/context/register.js.map +1 -0
- package/lib/commands/context/user-context.d.ts +36 -0
- package/lib/commands/context/user-context.d.ts.map +1 -0
- package/lib/commands/context/user-context.js +125 -0
- package/lib/commands/context/user-context.js.map +1 -0
- package/lib/dev/auth-middleware.d.ts +11 -1
- package/lib/dev/auth-middleware.d.ts.map +1 -1
- package/lib/dev/auth-middleware.js +16 -1
- package/lib/dev/auth-middleware.js.map +1 -1
- package/lib/dev/local-outbound.d.ts +7 -0
- package/lib/dev/local-outbound.d.ts.map +1 -1
- package/lib/dev/local-outbound.js +26 -12
- package/lib/dev/local-outbound.js.map +1 -1
- package/lib/dev/managed-sandbox.d.ts +11 -0
- package/lib/dev/managed-sandbox.d.ts.map +1 -0
- package/lib/dev/managed-sandbox.js +13 -0
- package/lib/dev/managed-sandbox.js.map +1 -0
- package/lib/dev/tunnel.d.ts +5 -0
- package/lib/dev/tunnel.d.ts.map +1 -1
- package/lib/dev/tunnel.js +15 -0
- package/lib/dev/tunnel.js.map +1 -1
- package/lib/docs/api/managed-agent.md +14 -2
- package/lib/docs/cli/app-management.md +3 -1
- package/lib/docs/sdk/bkper-api-types.md +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { withAction } from '../action.js';
|
|
11
|
+
import { getBookContextDir, pullBookContext } from './book-context.js';
|
|
12
|
+
import { getDomainContextDir, pullDomainContext } from './domain-context.js';
|
|
13
|
+
import { runContextCredentialHelper } from './git-credential.js';
|
|
14
|
+
import { BOOK_ID, ContextError } from './platform-context.js';
|
|
15
|
+
import { getUserContextDir, pullUserContext } from './user-context.js';
|
|
16
|
+
const PULL_MESSAGES = {
|
|
17
|
+
synced: 'Up to date with what you published.',
|
|
18
|
+
unpublished: 'Nothing published yet. Commit and push from here to publish to all your agents.',
|
|
19
|
+
unpushed: 'Not updated: this clone has changes not pushed. Push or discard them, then pull again.',
|
|
20
|
+
failed: 'Could not update your agent context. Check your login (bkper auth login) and connection.',
|
|
21
|
+
};
|
|
22
|
+
/** Without a domain there is no line: most people have none. */
|
|
23
|
+
const DOMAIN_PULL_MESSAGES = {
|
|
24
|
+
synced: "Up to date with what your company's domain admin published.",
|
|
25
|
+
unpublished: "Nothing published for your company yet. Your domain's admin publishes with a commit and push from here, to everyone in the domain.",
|
|
26
|
+
unpushed: 'Not updated: this clone has changes not pushed. Push or discard them, then pull again.',
|
|
27
|
+
failed: "Could not update your company's agent context. Check your login (bkper auth login) and connection.",
|
|
28
|
+
};
|
|
29
|
+
const BOOK_PULL_MESSAGES = {
|
|
30
|
+
synced: "Up to date with what the Book's editors published.",
|
|
31
|
+
unpublished: "Nothing published for this Book yet. Its editors publish with a commit and push from here, to everyone who can view it.",
|
|
32
|
+
unpushed: 'Not updated: this clone has changes not pushed. Push or discard them, then pull again.',
|
|
33
|
+
failed: "Could not update this Book's agent context. Check your login (bkper auth login) and connection.",
|
|
34
|
+
forbidden: "You cannot view this Book, so its agent context was not pulled. Ask the Book's owner to share it with you.",
|
|
35
|
+
};
|
|
36
|
+
/** `bkper context`: the agent context clones (yours, your company's, and a Book's), shared with all your agents. */
|
|
37
|
+
export function registerContextCommands(program) {
|
|
38
|
+
const context = program
|
|
39
|
+
.command('context')
|
|
40
|
+
.description('Your agent context: AGENTS.md and skills shared with all your agents');
|
|
41
|
+
context
|
|
42
|
+
.command('pull')
|
|
43
|
+
.description("Clone or update ~/.bkper/user, and your company's in ~/.bkper/domain when you have one (fast-forward only); with --book, also the Book's in ~/.bkper/books/<bookId>")
|
|
44
|
+
.option('-b, --book <bookId>', "Also pull this Book's agent context")
|
|
45
|
+
.action((options) => withAction('pulling agent context', () => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const bookId = options.book;
|
|
47
|
+
if (bookId !== undefined && !BOOK_ID.test(bookId)) {
|
|
48
|
+
throw new ContextError(`'${bookId}' is not a Book ID.`);
|
|
49
|
+
}
|
|
50
|
+
const [outcome, domainOutcome, bookOutcome] = yield Promise.all([
|
|
51
|
+
pullUserContext(),
|
|
52
|
+
pullDomainContext(),
|
|
53
|
+
bookId === undefined ? undefined : pullBookContext(bookId),
|
|
54
|
+
]);
|
|
55
|
+
console.log(`${getUserContextDir()}: ${PULL_MESSAGES[outcome]}`);
|
|
56
|
+
if (domainOutcome !== 'none') {
|
|
57
|
+
console.log(`${getDomainContextDir()}: ${DOMAIN_PULL_MESSAGES[domainOutcome]}`);
|
|
58
|
+
}
|
|
59
|
+
if (bookId !== undefined && bookOutcome) {
|
|
60
|
+
console.log(`${getBookContextDir(bookId)}: ${BOOK_PULL_MESSAGES[bookOutcome]}`);
|
|
61
|
+
}
|
|
62
|
+
if (outcome === 'failed' ||
|
|
63
|
+
domainOutcome === 'failed' ||
|
|
64
|
+
bookOutcome === 'failed' ||
|
|
65
|
+
bookOutcome === 'forbidden') {
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}), { skipSetup: true })());
|
|
69
|
+
context
|
|
70
|
+
.command('git-credential <scope> [operation]')
|
|
71
|
+
.description('Internal noninteractive credential helper for agent context clones')
|
|
72
|
+
.action((scope, operation) => withAction('running git credential helper', () => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
// Git appends get|store|erase to the configured helper command.
|
|
74
|
+
const exitCode = yield runContextCredentialHelper({ scope, operation: operation !== null && operation !== void 0 ? operation : 'get' });
|
|
75
|
+
if (exitCode !== 0)
|
|
76
|
+
process.exit(exitCode);
|
|
77
|
+
}), { skipSetup: true })());
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../src/commands/context/register.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAuB,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAC,mBAAmB,EAAE,iBAAiB,EAAyB,MAAM,qBAAqB,CAAC;AACnG,OAAO,EAAC,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAmB,MAAM,mBAAmB,CAAC;AAEvF,MAAM,aAAa,GAAgC;IAC/C,MAAM,EAAE,qCAAqC;IAC7C,WAAW,EAAE,iFAAiF;IAC9F,QAAQ,EAAE,wFAAwF;IAClG,MAAM,EAAE,0FAA0F;CACrG,CAAC;AAEF,gEAAgE;AAChE,MAAM,oBAAoB,GAAuD;IAC7E,MAAM,EAAE,6DAA6D;IACrE,WAAW,EACP,oIAAoI;IACxI,QAAQ,EAAE,wFAAwF;IAClG,MAAM,EAAE,oGAAoG;CAC/G,CAAC;AAEF,MAAM,kBAAkB,GAAoC;IACxD,MAAM,EAAE,oDAAoD;IAC5D,WAAW,EAC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O,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,MAAM,CAAC,KAAK,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACpF,CAAC;QACD,IACI,OAAO,KAAK,QAAQ;YACpB,aAAa,KAAK,QAAQ;YAC1B,WAAW,KAAK,QAAQ;YACxB,WAAW,KAAK,WAAW,EAC7B,CAAC;YACC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACL,CAAC,CAAA,EACD,EAAC,SAAS,EAAE,IAAI,EAAC,CACpB,EAAE,CACN,CAAC;IAEN,OAAO;SACF,OAAO,CAAC,oCAAoC,CAAC;SAC7C,WAAW,CAAC,oEAAoE,CAAC;SACjF,MAAM,CAAC,CAAC,KAAa,EAAE,SAA6B,EAAE,EAAE,CACrD,UAAU,CACN,+BAA+B,EAC/B,GAAS,EAAE;QACP,gEAAgE;QAChE,MAAM,QAAQ,GAAG,MAAM,0BAA0B,CAAC,EAAC,KAAK,EAAE,SAAS,EAAE,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,KAAK,EAAC,CAAC,CAAC;QAC1F,IAAI,QAAQ,KAAK,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC,CAAA,EACD,EAAC,SAAS,EAAE,IAAI,EAAC,CACpB,EAAE,CACN,CAAC;AACV,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type GitRunner } from '../apps/git/run-git.js';
|
|
2
|
+
import { type ContextScope, type PlatformContextApi } from './platform-context.js';
|
|
3
|
+
/**
|
|
4
|
+
* The user's agent context clone (docs/plans/agent-context.md in bkper-clients): AGENTS.md and `.agents/skills`, shared
|
|
5
|
+
* with all of the user's agents. A push publishes; a pull brings what others published.
|
|
6
|
+
*/
|
|
7
|
+
export declare const USER_CONTEXT_SCOPE: ContextScope;
|
|
8
|
+
/**
|
|
9
|
+
* Where agent context clones live on every machine, one folder per scope, as in the sandbox (whose home is `/workspace`):
|
|
10
|
+
* `~/.bkper/domain`, `~/.bkper/user`, `~/.bkper/books/<bookId>`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getContextRoot(home?: string): string;
|
|
13
|
+
export declare function getUserContextDir(home?: string): string;
|
|
14
|
+
/** synced; unpublished (nothing pushed yet: the clone is ready to push); unpushed (left as it is); failed. */
|
|
15
|
+
export type PullOutcome = 'synced' | 'unpublished' | 'unpushed' | 'failed';
|
|
16
|
+
/** The Git credential helper for a context scope; Git appends get, store or erase. */
|
|
17
|
+
export declare function buildContextCredentialHelperCommand(scope: string): string;
|
|
18
|
+
export interface PullOptions {
|
|
19
|
+
dir?: string;
|
|
20
|
+
api?: PlatformContextApi;
|
|
21
|
+
runner?: GitRunner;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Bring a scope's clone in `dir` up to date with what is published, fast-forward only: creates it if needed (ready to push
|
|
25
|
+
* even before anything was published), and leaves a clone with unpushed changes as it is. `configure` runs once the clone
|
|
26
|
+
* exists, before fetching. Platform's refusal (no access, no login) throws before anything is created.
|
|
27
|
+
*/
|
|
28
|
+
export declare function syncContextClone(scope: ContextScope, dir: string, options?: Omit<PullOptions, 'dir'> & {
|
|
29
|
+
configure?: (runner: GitRunner, dir: string) => Promise<void>;
|
|
30
|
+
}): Promise<PullOutcome>;
|
|
31
|
+
/**
|
|
32
|
+
* Bring the user's context clone up to date with what is published, fast-forward only: creates it if needed (ready to
|
|
33
|
+
* push even before anything was published), and leaves a clone with unpushed changes as it is. Never throws.
|
|
34
|
+
*/
|
|
35
|
+
export declare function pullUserContext(options?: PullOptions): Promise<PullOutcome>;
|
|
36
|
+
//# sourceMappingURL=user-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-context.d.ts","sourceRoot":"","sources":["../../../src/commands/context/user-context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,KAAK,SAAS,EAAC,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAA2B,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AAE3G;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,YAAqB,CAAC;AACvD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,GAAE,MAAqB,GAAG,MAAM,CAElE;AACD,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,MAAqB,GAAG,MAAM,CAErE;AAED,8GAA8G;AAC9G,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,aAAa,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE3E,sFAAsF;AACtF,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,MAAM,WAAW,WAAW;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,kBAAkB,CAAC;IACzB,MAAM,CAAC,EAAE,SAAS,CAAC;CACtB;AAoCD;;;;GAIG;AACH,wBAAsB,gBAAgB,CAClC,KAAK,EAAE,YAAY,EACnB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG;IAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAM,GACzG,OAAO,CAAC,WAAW,CAAC,CAwBtB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CAMrF"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import os from 'node:os';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { runGit } from '../apps/git/run-git.js';
|
|
14
|
+
import { createPlatformContextApi } from './platform-context.js';
|
|
15
|
+
/**
|
|
16
|
+
* The user's agent context clone (docs/plans/agent-context.md in bkper-clients): AGENTS.md and `.agents/skills`, shared
|
|
17
|
+
* with all of the user's agents. A push publishes; a pull brings what others published.
|
|
18
|
+
*/
|
|
19
|
+
export const USER_CONTEXT_SCOPE = 'user';
|
|
20
|
+
/**
|
|
21
|
+
* Where agent context clones live on every machine, one folder per scope, as in the sandbox (whose home is `/workspace`):
|
|
22
|
+
* `~/.bkper/domain`, `~/.bkper/user`, `~/.bkper/books/<bookId>`.
|
|
23
|
+
*/
|
|
24
|
+
export function getContextRoot(home = os.homedir()) {
|
|
25
|
+
return path.join(home, '.bkper');
|
|
26
|
+
}
|
|
27
|
+
export function getUserContextDir(home = os.homedir()) {
|
|
28
|
+
return path.join(getContextRoot(home), USER_CONTEXT_SCOPE);
|
|
29
|
+
}
|
|
30
|
+
/** The Git credential helper for a context scope; Git appends get, store or erase. */
|
|
31
|
+
export function buildContextCredentialHelperCommand(scope) {
|
|
32
|
+
return `!bkper context git-credential '${scope.replace(/'/g, `'\\''`)}'`;
|
|
33
|
+
}
|
|
34
|
+
/** Abort a stalled transfer instead of keeping a background pull alive. */
|
|
35
|
+
const STALL_ENV = { GIT_HTTP_LOW_SPEED_LIMIT: '1000', GIT_HTTP_LOW_SPEED_TIME: '30' };
|
|
36
|
+
function succeeds(runner, args, cwd) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return (yield runner(args, { cwd, allowFailure: true })).exitCode === 0;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Whether the clone has changes not pushed: files not committed, or commits not on origin/main. */
|
|
42
|
+
function unpushed(runner, cwd) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if ((yield runner(['status', '--porcelain'], { cwd })).stdout)
|
|
45
|
+
return true;
|
|
46
|
+
if (!(yield succeeds(runner, ['rev-parse', '-q', '--verify', 'HEAD'], cwd)))
|
|
47
|
+
return false;
|
|
48
|
+
if (!(yield succeeds(runner, ['rev-parse', '-q', '--verify', 'refs/remotes/origin/main'], cwd)))
|
|
49
|
+
return true;
|
|
50
|
+
return Boolean((yield runner(['rev-list', '-n', '1', 'refs/remotes/origin/main..HEAD'], { cwd })).stdout);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** A clone of the scope's `remote` in `dir`, tracking main, whose credentials come only from the helper (never stored). */
|
|
54
|
+
function prepare(runner, dir, remote, scope) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
if (!fs.existsSync(path.join(dir, '.git'))) {
|
|
58
|
+
yield runner(['init', '-q', '-b', 'main'], { cwd: dir });
|
|
59
|
+
yield runner(['remote', 'add', 'origin', remote], { cwd: dir });
|
|
60
|
+
yield runner(['config', 'branch.main.remote', 'origin'], { cwd: dir });
|
|
61
|
+
yield runner(['config', 'branch.main.merge', 'refs/heads/main'], { cwd: dir });
|
|
62
|
+
}
|
|
63
|
+
yield runner(['remote', 'set-url', 'origin', remote], { cwd: dir });
|
|
64
|
+
const key = `credential.${remote.replace(/\/+$/, '')}`;
|
|
65
|
+
yield runner(['config', `${key}.useHttpPath`, 'true'], { cwd: dir });
|
|
66
|
+
// Clears inherited helpers for this remote, then pins the context helper.
|
|
67
|
+
yield runner(['config', '--replace-all', `${key}.helper`, ''], { cwd: dir });
|
|
68
|
+
yield runner(['config', '--add', `${key}.helper`, buildContextCredentialHelperCommand(scope)], {
|
|
69
|
+
cwd: dir,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Bring a scope's clone in `dir` up to date with what is published, fast-forward only: creates it if needed (ready to push
|
|
75
|
+
* even before anything was published), and leaves a clone with unpushed changes as it is. `configure` runs once the clone
|
|
76
|
+
* exists, before fetching. Platform's refusal (no access, no login) throws before anything is created.
|
|
77
|
+
*/
|
|
78
|
+
export function syncContextClone(scope_1, dir_1) {
|
|
79
|
+
return __awaiter(this, arguments, void 0, function* (scope, dir, options = {}) {
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
const runner = (_a = options.runner) !== null && _a !== void 0 ? _a : runGit;
|
|
82
|
+
const credential = yield ((_b = options.api) !== null && _b !== void 0 ? _b : createPlatformContextApi()).issueCredential('read', scope);
|
|
83
|
+
yield prepare(runner, dir, credential.remote, scope);
|
|
84
|
+
yield ((_c = options.configure) === null || _c === void 0 ? void 0 : _c.call(options, runner, dir));
|
|
85
|
+
if (!('token' in credential))
|
|
86
|
+
return 'unpublished';
|
|
87
|
+
try {
|
|
88
|
+
// The helper answers this fetch with the read token issued above, from the environment only.
|
|
89
|
+
const fetched = yield runner(['fetch', '-q', 'origin'], {
|
|
90
|
+
cwd: dir,
|
|
91
|
+
allowFailure: true,
|
|
92
|
+
env: Object.assign(Object.assign({}, STALL_ENV), { BKPER_CONTEXT_TOKEN: credential.token, BKPER_CONTEXT_REMOTE: credential.remote }),
|
|
93
|
+
});
|
|
94
|
+
if (fetched.exitCode !== 0)
|
|
95
|
+
return 'failed';
|
|
96
|
+
if (!(yield succeeds(runner, ['rev-parse', '-q', '--verify', 'refs/remotes/origin/main'], dir))) {
|
|
97
|
+
return 'unpublished';
|
|
98
|
+
}
|
|
99
|
+
if (yield unpushed(runner, dir))
|
|
100
|
+
return 'unpushed';
|
|
101
|
+
return (yield succeeds(runner, ['merge', '-q', '--ff-only', 'refs/remotes/origin/main'], dir))
|
|
102
|
+
? 'synced'
|
|
103
|
+
: 'failed';
|
|
104
|
+
}
|
|
105
|
+
catch (_d) {
|
|
106
|
+
return 'failed';
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Bring the user's context clone up to date with what is published, fast-forward only: creates it if needed (ready to
|
|
112
|
+
* push even before anything was published), and leaves a clone with unpushed changes as it is. Never throws.
|
|
113
|
+
*/
|
|
114
|
+
export function pullUserContext() {
|
|
115
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
116
|
+
var _a;
|
|
117
|
+
try {
|
|
118
|
+
return yield syncContextClone(USER_CONTEXT_SCOPE, (_a = options.dir) !== null && _a !== void 0 ? _a : getUserContextDir(), options);
|
|
119
|
+
}
|
|
120
|
+
catch (_b) {
|
|
121
|
+
return 'failed';
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=user-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-context.js","sourceRoot":"","sources":["../../../src/commands/context/user-context.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,MAAM,EAAiB,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAC,wBAAwB,EAA6C,MAAM,uBAAuB,CAAC;AAE3G;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAiB,MAAM,CAAC;AACvD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,CAAC,OAAO,EAAE;IACtD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AACD,MAAM,UAAU,iBAAiB,CAAC,OAAe,EAAE,CA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,MAAM,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,0BAA0B,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC9F,OAAO,aAAa,CAAC;YACzB,CAAC;YACD,IAAI,MAAM,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC;gBAAE,OAAO,UAAU,CAAC;YACnD,OAAO,CAAC,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,0BAA0B,CAAC,EAAE,GAAG,CAAC,CAAC;gBAC1F,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,QAAQ,CAAC;QACnB,CAAC;QAAC,WAAM,CAAC;YACL,OAAO,QAAQ,CAAC;QACpB,CAAC;IACL,CAAC;CAAA;AAED;;;GAGG;AACH,MAAM,UAAgB,eAAe;yDAAC,UAAuB,EAAE;;QAC3D,IAAI,CAAC;YACD,OAAO,MAAM,gBAAgB,CAAC,kBAAkB,EAAE,MAAA,OAAO,CAAC,GAAG,mCAAI,iBAAiB,EAAE,EAAE,OAAO,CAAC,CAAC;QACnG,CAAC;QAAC,WAAM,CAAC;YACL,OAAO,QAAQ,CAAC;QACpB,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the dev auth middleware.
|
|
4
|
+
*/
|
|
5
|
+
export interface BkperAuthMiddlewareOptions {
|
|
6
|
+
/** Defaults to `BKPER_MANAGED_SANDBOX=1`. */
|
|
7
|
+
managedSandbox?: boolean;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Creates a Connect-compatible middleware that handles /auth/refresh requests.
|
|
4
11
|
*
|
|
@@ -7,6 +14,9 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
7
14
|
* clients to authenticate during local development without needing
|
|
8
15
|
* to set up session cookies or connect to production auth servers.
|
|
9
16
|
*
|
|
17
|
+
* In the managed sandbox it never reads stored credentials: it answers a fixed placeholder token
|
|
18
|
+
* and user, and the sandbox's Bkper API egress replaces every Authorization header with the owner's.
|
|
19
|
+
*
|
|
10
20
|
* Response format matches production:
|
|
11
21
|
* - 200: { userId: string, accessToken: string }
|
|
12
22
|
* - 401: { error: string } - when not logged in
|
|
@@ -14,6 +24,6 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
14
24
|
*
|
|
15
25
|
* @returns Connect-compatible middleware function (req, res, next)
|
|
16
26
|
*/
|
|
17
|
-
export declare function createBkperAuthMiddleware(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
|
27
|
+
export declare function createBkperAuthMiddleware(options?: BkperAuthMiddlewareOptions): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
|
18
28
|
export declare const createAuthMiddleware: typeof createBkperAuthMiddleware;
|
|
19
29
|
//# sourceMappingURL=auth-middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../src/dev/auth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../src/dev/auth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAajE;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACvC,6CAA6C;IAC7C,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B;AAwDD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACrC,OAAO,GAAE,0BAA+B,GACzC,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,CA2DvE;AAGD,eAAO,MAAM,oBAAoB,kCAA4B,CAAC"}
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AUTHENTICATION_REQUIRED_MESSAGE } from '../auth/auth-errors.js';
|
|
11
11
|
import { getStoredCredentials, getStoredOAuthToken, isLoggedIn, } from '../auth/local-auth-service.js';
|
|
12
|
+
import { isManagedSandbox, MANAGED_SANDBOX_ACCESS_TOKEN, MANAGED_SANDBOX_USER_ID, } from './managed-sandbox.js';
|
|
12
13
|
/**
|
|
13
14
|
* Decodes a JWT token and extracts the payload.
|
|
14
15
|
* Does NOT verify the signature - only extracts the payload.
|
|
@@ -56,6 +57,9 @@ function extractUserId() {
|
|
|
56
57
|
* clients to authenticate during local development without needing
|
|
57
58
|
* to set up session cookies or connect to production auth servers.
|
|
58
59
|
*
|
|
60
|
+
* In the managed sandbox it never reads stored credentials: it answers a fixed placeholder token
|
|
61
|
+
* and user, and the sandbox's Bkper API egress replaces every Authorization header with the owner's.
|
|
62
|
+
*
|
|
59
63
|
* Response format matches production:
|
|
60
64
|
* - 200: { userId: string, accessToken: string }
|
|
61
65
|
* - 401: { error: string } - when not logged in
|
|
@@ -63,7 +67,9 @@ function extractUserId() {
|
|
|
63
67
|
*
|
|
64
68
|
* @returns Connect-compatible middleware function (req, res, next)
|
|
65
69
|
*/
|
|
66
|
-
export function createBkperAuthMiddleware() {
|
|
70
|
+
export function createBkperAuthMiddleware(options = {}) {
|
|
71
|
+
var _a;
|
|
72
|
+
const managedSandbox = (_a = options.managedSandbox) !== null && _a !== void 0 ? _a : isManagedSandbox();
|
|
67
73
|
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
68
74
|
// Only handle POST /auth/refresh
|
|
69
75
|
if (req.url !== '/auth/refresh' || req.method !== 'POST') {
|
|
@@ -71,6 +77,15 @@ export function createBkperAuthMiddleware() {
|
|
|
71
77
|
return;
|
|
72
78
|
}
|
|
73
79
|
res.setHeader('Content-Type', 'application/json');
|
|
80
|
+
if (managedSandbox) {
|
|
81
|
+
const response = {
|
|
82
|
+
userId: MANAGED_SANDBOX_USER_ID,
|
|
83
|
+
accessToken: MANAGED_SANDBOX_ACCESS_TOKEN,
|
|
84
|
+
};
|
|
85
|
+
res.statusCode = 200;
|
|
86
|
+
res.end(JSON.stringify(response));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
74
89
|
// Check if user is logged in to CLI
|
|
75
90
|
if (!isLoggedIn()) {
|
|
76
91
|
res.statusCode = 401;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-middleware.js","sourceRoot":"","sources":["../../src/dev/auth-middleware.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EACH,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,GACb,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-middleware.js","sourceRoot":"","sources":["../../src/dev/auth-middleware.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EACH,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,GACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,gBAAgB,EAChB,4BAA4B,EAC5B,uBAAuB,GAC1B,MAAM,sBAAsB,CAAC;AAyB9B;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,KAAa;IACnC,IAAI,CAAC;QACD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAEpC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,8BAA8B;QAC9B,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW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,MAAM,CAAC,MAAM,oBAAoB,GAAG,yBAAyB,CAAC"}
|
|
@@ -3,6 +3,13 @@ export interface LocalOutboundOptions {
|
|
|
3
3
|
appId: string;
|
|
4
4
|
getAccessToken?: () => Promise<string | undefined>;
|
|
5
5
|
forwardFetch?: (request: Request) => Promise<Response>;
|
|
6
|
+
/**
|
|
7
|
+
* In the managed sandbox, Bkper API and AI requests go out without credentials (its egress adds
|
|
8
|
+
* the owner's), and Bkper API requests go to the host of `bkperApiUrl` when set.
|
|
9
|
+
*/
|
|
10
|
+
managedSandbox?: boolean;
|
|
11
|
+
/** The sandbox's Bkper API (`BKPER_API_URL`); its egress refuses the other environment's. */
|
|
12
|
+
bkperApiUrl?: string;
|
|
6
13
|
}
|
|
7
14
|
export declare function createLocalOutboundService(options: LocalOutboundOptions): LocalOutboundService;
|
|
8
15
|
//# sourceMappingURL=local-outbound.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-outbound.d.ts","sourceRoot":"","sources":["../../src/dev/local-outbound.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"local-outbound.d.ts","sourceRoot":"","sources":["../../src/dev/local-outbound.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE3E,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvD;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,6FAA6F;IAC7F,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAMD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,oBAAoB,GAAG,oBAAoB,CA0C9F"}
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AUTHENTICATION_REQUIRED_MESSAGE } from '../auth/auth-errors.js';
|
|
11
11
|
import { getStoredOAuthToken } from '../auth/local-auth-service.js';
|
|
12
|
+
import { isManagedSandbox } from './managed-sandbox.js';
|
|
12
13
|
const PUBLIC_BKPER_API_HOST = 'api.bkper.app';
|
|
13
14
|
const BKPER_AI_HOSTS = new Set(['ai.bkper.app', 'ai-dev.bkper.app']);
|
|
14
15
|
const PLATFORM_SESSION_COOKIE_NAMES = new Set([
|
|
@@ -17,32 +18,45 @@ const PLATFORM_SESSION_COOKIE_NAMES = new Set([
|
|
|
17
18
|
'bkper_session_local',
|
|
18
19
|
]);
|
|
19
20
|
export function createLocalOutboundService(options) {
|
|
20
|
-
var _a, _b;
|
|
21
|
+
var _a, _b, _c, _d;
|
|
21
22
|
const getAccessToken = (_a = options.getAccessToken) !== null && _a !== void 0 ? _a : getStoredOAuthToken;
|
|
22
23
|
const forwardFetch = (_b = options.forwardFetch) !== null && _b !== void 0 ? _b : ((request) => fetch(request));
|
|
24
|
+
const managedSandbox = (_c = options.managedSandbox) !== null && _c !== void 0 ? _c : isManagedSandbox();
|
|
25
|
+
const bkperApiUrl = (_d = options.bkperApiUrl) !== null && _d !== void 0 ? _d : process.env.BKPER_API_URL;
|
|
26
|
+
const managedApiOrigin = managedSandbox && bkperApiUrl ? new URL(bkperApiUrl).origin : undefined;
|
|
23
27
|
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
24
28
|
const service = getAuthorizedBkperService(request);
|
|
25
29
|
if (!service) {
|
|
26
30
|
return forwardFetch(createForwardRequest(request, new Headers(request.headers), request.redirect));
|
|
27
31
|
}
|
|
28
|
-
const accessToken = normalizeBearerToken(yield getAccessToken());
|
|
29
|
-
if (!accessToken) {
|
|
30
|
-
return new Response(JSON.stringify({ error: AUTHENTICATION_REQUIRED_MESSAGE }), {
|
|
31
|
-
status: 401,
|
|
32
|
-
headers: { 'content-type': 'application/json' },
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
32
|
const headers = new Headers(request.headers);
|
|
36
|
-
|
|
33
|
+
let url = request.url;
|
|
34
|
+
if (managedSandbox) {
|
|
35
|
+
headers.delete('Authorization');
|
|
36
|
+
if (service === 'api' && managedApiOrigin) {
|
|
37
|
+
const target = new URL(request.url);
|
|
38
|
+
url = `${managedApiOrigin}${target.pathname}${target.search}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const accessToken = normalizeBearerToken(yield getAccessToken());
|
|
43
|
+
if (!accessToken) {
|
|
44
|
+
return new Response(JSON.stringify({ error: AUTHENTICATION_REQUIRED_MESSAGE }), {
|
|
45
|
+
status: 401,
|
|
46
|
+
headers: { 'content-type': 'application/json' },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
headers.set('Authorization', `Bearer ${accessToken}`);
|
|
50
|
+
}
|
|
37
51
|
headers.set('bkper-agent-id', options.appId);
|
|
38
52
|
if (service === 'ai') {
|
|
39
53
|
headers.set('bkper-ai-source', options.appId);
|
|
40
54
|
}
|
|
41
55
|
stripPlatformCookieHeaders(headers);
|
|
42
|
-
return forwardFetch(createForwardRequest(request, headers, 'manual'));
|
|
56
|
+
return forwardFetch(createForwardRequest(request, headers, 'manual', url));
|
|
43
57
|
});
|
|
44
58
|
}
|
|
45
|
-
function createForwardRequest(request, headers, redirect) {
|
|
59
|
+
function createForwardRequest(request, headers, redirect, url = request.url) {
|
|
46
60
|
const init = {
|
|
47
61
|
method: request.method,
|
|
48
62
|
headers,
|
|
@@ -54,7 +68,7 @@ function createForwardRequest(request, headers, redirect) {
|
|
|
54
68
|
init.duplex = 'half';
|
|
55
69
|
}
|
|
56
70
|
}
|
|
57
|
-
return new Request(
|
|
71
|
+
return new Request(url, init);
|
|
58
72
|
}
|
|
59
73
|
function getAuthorizedBkperService(request) {
|
|
60
74
|
const url = new URL(request.url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-outbound.js","sourceRoot":"","sources":["../../src/dev/local-outbound.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"local-outbound.js","sourceRoot":"","sources":["../../src/dev/local-outbound.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAC9C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACrE,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;IAC1C,eAAe;IACf,mBAAmB;IACnB,qBAAqB;CACxB,CAAC,CAAC;AAqBH,MAAM,UAAU,0BAA0B,CAAC,OAA6B;;IACpE,MAAM,cAAc,GAAG,MAAA,OAAO,CAAC,cAAc,mCAAI,mBAAmB,CAAC;IACrE,MAAM,YAAY,GAAG,MAAA,OAAO,CAAC,YAAY,mCAAI,CAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACpF,MAAM,cAAc,GAAG,MAAA,OAAO,CAAC,cAAc,mCAAI,gBAAgB,EAAE,CAAC;IACpE,MAAM,WAAW,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IACrE,MAAM,gBAAgB,GAClB,cAAc,IAAI,WAAW,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,C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11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bkper's managed agent sandbox sets `BKPER_MANAGED_SANDBOX=1`. There the CLI has no login of its own:
|
|
3
|
+
* the sandbox's egress adds the owner's credentials to Bkper API and AI requests, replacing any
|
|
4
|
+
* Authorization header. Never inferred from a missing login.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isManagedSandbox(env?: NodeJS.ProcessEnv): boolean;
|
|
7
|
+
/** The access token `bkper app dev` hands out in the managed sandbox; the sandbox's egress replaces it. */
|
|
8
|
+
export declare const MANAGED_SANDBOX_ACCESS_TOKEN = "placeholder-replaced-outside-the-sandbox";
|
|
9
|
+
/** The user id `bkper app dev` hands out in the managed sandbox, where the CLI does not know the owner. */
|
|
10
|
+
export declare const MANAGED_SANDBOX_USER_ID = "managed-sandbox";
|
|
11
|
+
//# sourceMappingURL=managed-sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-sandbox.d.ts","sourceRoot":"","sources":["../../src/dev/managed-sandbox.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAE9E;AAED,2GAA2G;AAC3G,eAAO,MAAM,4BAA4B,6CAA6C,CAAC;AAEvF,2GAA2G;AAC3G,eAAO,MAAM,uBAAuB,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bkper's managed agent sandbox sets `BKPER_MANAGED_SANDBOX=1`. There the CLI has no login of its own:
|
|
3
|
+
* the sandbox's egress adds the owner's credentials to Bkper API and AI requests, replacing any
|
|
4
|
+
* Authorization header. Never inferred from a missing login.
|
|
5
|
+
*/
|
|
6
|
+
export function isManagedSandbox(env = process.env) {
|
|
7
|
+
return env.BKPER_MANAGED_SANDBOX === '1';
|
|
8
|
+
}
|
|
9
|
+
/** The access token `bkper app dev` hands out in the managed sandbox; the sandbox's egress replaces it. */
|
|
10
|
+
export const MANAGED_SANDBOX_ACCESS_TOKEN = 'placeholder-replaced-outside-the-sandbox';
|
|
11
|
+
/** The user id `bkper app dev` hands out in the managed sandbox, where the CLI does not know the owner. */
|
|
12
|
+
export const MANAGED_SANDBOX_USER_ID = 'managed-sandbox';
|
|
13
|
+
//# sourceMappingURL=managed-sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-sandbox.js","sourceRoot":"","sources":["../../src/dev/managed-sandbox.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACjE,OAAO,GAAG,CAAC,qBAAqB,KAAK,GAAG,CAAC;AAC7C,CAAC;AAED,2GAA2G;AAC3G,MAAM,CAAC,MAAM,4BAA4B,GAAG,0CAA0C,CAAC;AAEvF,2GAA2G;AAC3G,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAC"}
|
package/lib/dev/tunnel.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export interface CloudflaredTunnelOptions {
|
|
|
17
17
|
/** Optional logger for status messages. */
|
|
18
18
|
logger?: Logger;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Whether `bkper app dev` starts the events tunnel: only for an App with events, and never in the
|
|
22
|
+
* managed sandbox, where it cannot connect; there it says why, once.
|
|
23
|
+
*/
|
|
24
|
+
export declare function startsEventsTunnel(hasEvents: boolean, logger: Logger, managedSandbox?: boolean): boolean;
|
|
20
25
|
/**
|
|
21
26
|
* Starts a cloudflared Quick Tunnel to expose a local port to the internet.
|
|
22
27
|
*
|
package/lib/dev/tunnel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tunnel.d.ts","sourceRoot":"","sources":["../../src/dev/tunnel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tunnel.d.ts","sourceRoot":"","sources":["../../src/dev/tunnel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,6CAA6C;IAC7C,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACrC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAQD;;;GAGG;AACH,wBAAgB,kBAAkB,CAC9B,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,MAAM,EACd,cAAc,UAAqB,GACpC,OAAO,CAWT;AAED;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CACxC,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,YAAY,CAAC,CA4FvB"}
|
package/lib/dev/tunnel.js
CHANGED
|
@@ -9,11 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import fs from 'fs';
|
|
11
11
|
import { Tunnel, bin, install } from './cloudflared/index.js';
|
|
12
|
+
import { isManagedSandbox } from './managed-sandbox.js';
|
|
12
13
|
/**
|
|
13
14
|
* Maximum number of output lines to show on tunnel failure.
|
|
14
15
|
* Balances debugging context with avoiding log bloat.
|
|
15
16
|
*/
|
|
16
17
|
const MAX_ERROR_OUTPUT_LINES = 20;
|
|
18
|
+
/**
|
|
19
|
+
* Whether `bkper app dev` starts the events tunnel: only for an App with events, and never in the
|
|
20
|
+
* managed sandbox, where it cannot connect; there it says why, once.
|
|
21
|
+
*/
|
|
22
|
+
export function startsEventsTunnel(hasEvents, logger, managedSandbox = isManagedSandbox()) {
|
|
23
|
+
if (!hasEvents) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (managedSandbox) {
|
|
27
|
+
logger.info('Events tunnel skipped: it cannot connect from the managed sandbox. Test events on a deployed preview (bkper app deploy --preview).');
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
17
32
|
/**
|
|
18
33
|
* Starts a cloudflared Quick Tunnel to expose a local port to the internet.
|
|
19
34
|
*
|
package/lib/dev/tunnel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tunnel.js","sourceRoot":"","sources":["../../src/dev/tunnel.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"tunnel.js","sourceRoot":"","sources":["../../src/dev/tunnel.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAsBxD;;;GAGG;AACH,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAC9B,SAAkB,EAClB,MAAc,EACd,cAAc,GAAG,gBAAgB,EAAE;IAEnC,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,cAAc,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CACP,oIAAoI,CACvI,CAAC;QACF,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAgB,sBAAsB,CACxC,OAAiC;;QAEjC,MAAM,EAAE,IAAI,EAAE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