@offsida/cli 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Offsida
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ export declare function bundlePackage(dir: string, opts?: {
2
+ alias?: Record<string, string>;
3
+ }): Promise<string>;
package/dist/bundle.js ADDED
@@ -0,0 +1,34 @@
1
+ import * as esbuild from 'esbuild-wasm';
2
+ import { join } from 'node:path';
3
+ let initialized = false;
4
+ async function ensureInit() {
5
+ if (initialized)
6
+ return;
7
+ await esbuild.initialize({});
8
+ initialized = true;
9
+ }
10
+ // Bundle <dir>/index.ts (and its local imports) into a single ESM module string,
11
+ // preserving the package's `export default {...}`. Used by `offsida build` and by
12
+ // the platform conformance test. `opts.alias` lets callers resolve bare import
13
+ // prefixes (e.g. the `@core` workspace alias) — esbuild rewrites subpaths, so
14
+ // `{ '@core': '/abs/lib/core/src' }` maps `@core/services/x` → `/abs/lib/core/src/services/x`.
15
+ export async function bundlePackage(dir, opts) {
16
+ await ensureInit();
17
+ const result = await esbuild.build({
18
+ entryPoints: [join(dir, 'index.ts')],
19
+ bundle: true,
20
+ format: 'esm',
21
+ platform: 'neutral',
22
+ mainFields: ['module', 'main'],
23
+ conditions: ['workerd', 'worker', 'browser', 'default'],
24
+ external: ['cloudflare:workers', 'cloudflare:test', 'node:*', 'fs', 'fs/promises', 'path'],
25
+ alias: opts?.alias,
26
+ target: 'es2022',
27
+ write: false,
28
+ legalComments: 'none',
29
+ });
30
+ const out = result.outputFiles?.[0]?.text;
31
+ if (!out)
32
+ throw new Error('esbuild produced no output');
33
+ return out;
34
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ import { writeFile } from 'node:fs/promises';
3
+ import { bundlePackage } from './bundle.js';
4
+ import { pushPackage } from './push.js';
5
+ function arg(flags, name) {
6
+ const i = flags.indexOf(`--${name}`);
7
+ return i >= 0 ? flags[i + 1] : undefined;
8
+ }
9
+ async function main() {
10
+ const [cmd, dir, ...flags] = process.argv.slice(2);
11
+ if (cmd === 'build') {
12
+ if (!dir)
13
+ throw new Error('usage: offsida build <dir> [--out <file>]');
14
+ const code = await bundlePackage(dir);
15
+ const out = arg(flags, 'out');
16
+ if (out) {
17
+ await writeFile(out, code);
18
+ process.stdout.write(`wrote ${out}\n`);
19
+ }
20
+ else {
21
+ process.stdout.write(code);
22
+ }
23
+ return;
24
+ }
25
+ if (cmd === 'push') {
26
+ if (!dir)
27
+ throw new Error('usage: offsida push <dir> --url <u> --org <id> [--token <t> | --email <e> --code <c>]');
28
+ await pushPackage({
29
+ dir,
30
+ url: arg(flags, 'url') ?? process.env.OFFSIDA_URL ?? 'http://localhost:3808',
31
+ org: arg(flags, 'org') ?? process.env.OFFSIDA_ORG ?? '',
32
+ // Non-interactive CI auth (preferred for automation): a publish token. Takes precedence.
33
+ token: arg(flags, 'token') ?? process.env.OFFSIDA_TOKEN,
34
+ // Interactive fallback: emailed login code → session cookie.
35
+ email: arg(flags, 'email') ?? process.env.OFFSIDA_EMAIL,
36
+ code: arg(flags, 'code') ?? process.env.OFFSIDA_CODE,
37
+ name: arg(flags, 'name'),
38
+ allowRemote: flags.includes('--allow-remote') || process.env.OFFSIDA_ALLOW_REMOTE === '1',
39
+ });
40
+ return;
41
+ }
42
+ throw new Error(`unknown command: ${cmd ?? '(none)'} — use "build" or "push"`);
43
+ }
44
+ main().catch((e) => {
45
+ process.stderr.write(`${e.message}\n`);
46
+ process.exit(1);
47
+ });
package/dist/push.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export type PushOpts = {
2
+ dir: string;
3
+ url: string;
4
+ org: string;
5
+ email?: string;
6
+ code?: string;
7
+ token?: string;
8
+ name?: string;
9
+ allowRemote?: boolean;
10
+ };
11
+ export declare function pushPackage(opts: PushOpts): Promise<void>;
package/dist/push.js ADDED
@@ -0,0 +1,58 @@
1
+ import { basename } from 'node:path';
2
+ import { ORG_HEADER } from '@offsida/types';
3
+ import { bundlePackage } from './bundle.js';
4
+ function isLocal(url) {
5
+ try {
6
+ const h = new URL(url).hostname;
7
+ return h === 'localhost' || h === '127.0.0.1' || h === '0.0.0.0';
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }
13
+ // Two auth modes:
14
+ // • token — non-interactive (CI): send `Authorization: Bearer <osk_…>`; no login round-trip. The
15
+ // token must hold the `code:publish` scope (an org API token, Story 022).
16
+ // • email+code — interactive: exchange an emailed login code for a session cookie, then upload.
17
+ // A non-local --url is refused without an explicit --allow-remote opt-in (both modes).
18
+ export async function pushPackage(opts) {
19
+ if (!opts.org)
20
+ throw new Error('--org is required');
21
+ if (!opts.token && !(opts.email && opts.code))
22
+ throw new Error('provide --token (CI), or --email and --code (interactive)');
23
+ if (!isLocal(opts.url) && !opts.allowRemote) {
24
+ throw new Error(`refusing to push to non-local URL ${opts.url} without --allow-remote (or OFFSIDA_ALLOW_REMOTE=1)`);
25
+ }
26
+ const name = opts.name ?? basename(opts.dir);
27
+ const code = await bundlePackage(opts.dir);
28
+ // Resolve the auth header: a bearer token, or a session cookie from the emailed-code exchange.
29
+ const authHeaders = {};
30
+ if (opts.token) {
31
+ authHeaders['authorization'] = `Bearer ${opts.token}`;
32
+ }
33
+ else {
34
+ const verify = await fetch(`${opts.url}/api/auth/verify`, {
35
+ method: 'POST',
36
+ headers: { 'content-type': 'application/json' },
37
+ body: JSON.stringify({ email: opts.email, code: opts.code }),
38
+ redirect: 'manual',
39
+ });
40
+ if (!verify.ok)
41
+ throw new Error(`login failed: HTTP ${verify.status}`);
42
+ const cookie = (verify.headers.get('set-cookie') ?? '').match(/session=[^;]+/)?.[0];
43
+ if (!cookie)
44
+ throw new Error('login did not return a session cookie');
45
+ authHeaders['cookie'] = cookie;
46
+ }
47
+ const res = await fetch(`${opts.url}/api/code`, {
48
+ method: 'POST',
49
+ headers: { 'content-type': 'application/json', [ORG_HEADER]: opts.org, ...authHeaders },
50
+ body: JSON.stringify({ name, modules: { 'index.js': code } }),
51
+ });
52
+ if (res.status === 401)
53
+ throw new Error('auth rejected (HTTP 401) — token invalid/revoked, or login expired');
54
+ const body = (await res.json());
55
+ if (!body.ok)
56
+ throw new Error(`publish failed (${body.status ?? res.status}): ${body.failureReason ?? 'unknown'}`);
57
+ process.stdout.write(`pushed ${name}@${body.version} — ${body.status}\n`);
58
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@offsida/cli",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "The `offsida` CLI — bundle an integration package and publish it to a running Offsida environment.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/mark-ironbarklabs/offsida.web.git",
10
+ "directory": "lib/offsida/cli"
11
+ },
12
+ "bin": {
13
+ "offsida": "./dist/cli.js"
14
+ },
15
+ "exports": {
16
+ "./bundle": {
17
+ "types": "./dist/bundle.d.ts",
18
+ "default": "./dist/bundle.js"
19
+ },
20
+ "./push": {
21
+ "types": "./dist/push.d.ts",
22
+ "default": "./dist/push.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "engines": {
32
+ "node": ">=20"
33
+ },
34
+ "dependencies": {
35
+ "esbuild-wasm": "^0.25.12",
36
+ "@offsida/types": "0.1.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^25.9.3",
40
+ "typescript": "^5.9.3",
41
+ "vitest": "^3.2.6"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc",
45
+ "test": "vitest run",
46
+ "typecheck": "tsc --noEmit"
47
+ }
48
+ }