usebecky 0.0.0-stage → 0.2.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 +701 -2
- package/dist/analytics/client.d.ts +219 -0
- package/dist/analytics/client.js +923 -0
- package/dist/analytics/cmp.d.ts +20 -0
- package/dist/analytics/cmp.js +166 -0
- package/dist/analytics/context.d.ts +29 -0
- package/dist/analytics/context.js +97 -0
- package/dist/auth/client.d.ts +401 -0
- package/dist/auth/client.js +1081 -0
- package/dist/auth/webauthn.d.ts +18 -0
- package/dist/auth/webauthn.js +138 -0
- package/dist/cli/ai.d.ts +54 -0
- package/dist/cli/ai.js +202 -0
- package/dist/cli/analytics.d.ts +53 -0
- package/dist/cli/analytics.js +357 -0
- package/dist/cli/config.d.ts +75 -0
- package/dist/cli/config.js +718 -0
- package/dist/cli/db.d.ts +48 -0
- package/dist/cli/db.js +215 -0
- package/dist/cli/deploy-api.d.ts +168 -0
- package/dist/cli/deploy-api.js +177 -0
- package/dist/cli/deploy-ci.d.ts +15 -0
- package/dist/cli/deploy-ci.js +54 -0
- package/dist/cli/deploy-detect.d.ts +64 -0
- package/dist/cli/deploy-detect.js +249 -0
- package/dist/cli/deploy-files.d.ts +112 -0
- package/dist/cli/deploy-files.js +778 -0
- package/dist/cli/deploy.d.ts +10 -0
- package/dist/cli/deploy.js +430 -0
- package/dist/cli/emails.d.ts +29 -0
- package/dist/cli/emails.js +122 -0
- package/dist/cli/framework.d.ts +135 -0
- package/dist/cli/framework.js +459 -0
- package/dist/cli/functions.d.ts +59 -0
- package/dist/cli/functions.js +426 -0
- package/dist/cli/hosting.d.ts +4 -0
- package/dist/cli/hosting.js +532 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/payments.d.ts +35 -0
- package/dist/cli/payments.js +176 -0
- package/dist/cli/push.d.ts +36 -0
- package/dist/cli/push.js +172 -0
- package/dist/cli/run.d.ts +65 -0
- package/dist/cli/run.js +850 -0
- package/dist/cli/social.d.ts +52 -0
- package/dist/cli/social.js +532 -0
- package/dist/cli/tokens.d.ts +28 -0
- package/dist/cli/tokens.js +114 -0
- package/dist/cli/ui.d.ts +38 -0
- package/dist/cli/ui.js +140 -0
- package/dist/client.d.ts +94 -0
- package/dist/client.js +156 -0
- package/dist/db/query.d.ts +162 -0
- package/dist/db/query.js +336 -0
- package/dist/db/types.d.ts +93 -0
- package/dist/db/types.js +4 -0
- package/dist/forms/client.d.ts +65 -0
- package/dist/forms/client.js +106 -0
- package/dist/functions/client.d.ts +37 -0
- package/dist/functions/client.js +76 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +16 -0
- package/dist/lib/dashboard-paths.d.ts +4 -0
- package/dist/lib/dashboard-paths.js +8 -0
- package/dist/lib/env.d.ts +9 -0
- package/dist/lib/env.js +55 -0
- package/dist/lib/errors.d.ts +22 -0
- package/dist/lib/errors.js +90 -0
- package/dist/lib/hosted.d.ts +2 -0
- package/dist/lib/hosted.js +7 -0
- package/dist/lib/http.d.ts +59 -0
- package/dist/lib/http.js +172 -0
- package/dist/lib/jwt.d.ts +1 -0
- package/dist/lib/jwt.js +31 -0
- package/dist/lib/locale.d.ts +12 -0
- package/dist/lib/locale.js +51 -0
- package/dist/lib/pkce.d.ts +20 -0
- package/dist/lib/pkce.js +124 -0
- package/dist/lib/storage-adapter.d.ts +15 -0
- package/dist/lib/storage-adapter.js +91 -0
- package/dist/lib/types.d.ts +339 -0
- package/dist/lib/types.js +1 -0
- package/dist/newsletter/client.d.ts +140 -0
- package/dist/newsletter/client.js +85 -0
- package/dist/payments/client.d.ts +352 -0
- package/dist/payments/client.js +323 -0
- package/dist/push/client.d.ts +110 -0
- package/dist/push/client.js +179 -0
- package/dist/realtime/client.d.ts +131 -0
- package/dist/realtime/client.js +513 -0
- package/dist/server/analytics.d.ts +176 -0
- package/dist/server/analytics.js +49 -0
- package/dist/server/cache.d.ts +74 -0
- package/dist/server/cache.js +154 -0
- package/dist/server/emails.d.ts +142 -0
- package/dist/server/emails.js +123 -0
- package/dist/server/events.d.ts +357 -0
- package/dist/server/events.js +219 -0
- package/dist/server/functions.d.ts +40 -0
- package/dist/server/functions.js +1 -0
- package/dist/server/http-utils.d.ts +10 -0
- package/dist/server/http-utils.js +115 -0
- package/dist/server/index.d.ts +195 -0
- package/dist/server/index.js +314 -0
- package/dist/server/payments.d.ts +218 -0
- package/dist/server/payments.js +150 -0
- package/dist/server/push.d.ts +85 -0
- package/dist/server/push.js +37 -0
- package/dist/server/usage.d.ts +43 -0
- package/dist/server/usage.js +8 -0
- package/dist/storage/client.d.ts +143 -0
- package/dist/storage/client.js +224 -0
- package/package.json +52 -4
- package/skill/usebecky/SKILL.md +339 -0
- package/skill/usebecky/references/access-rules.md +307 -0
- package/skill/usebecky/references/addons.md +68 -0
- package/skill/usebecky/references/analytics.md +166 -0
- package/skill/usebecky/references/android.md +434 -0
- package/skill/usebecky/references/auth.md +379 -0
- package/skill/usebecky/references/cache.md +51 -0
- package/skill/usebecky/references/components.md +127 -0
- package/skill/usebecky/references/emails.md +105 -0
- package/skill/usebecky/references/expo.md +147 -0
- package/skill/usebecky/references/functions.md +99 -0
- package/skill/usebecky/references/hosting.md +119 -0
- package/skill/usebecky/references/http-api.md +233 -0
- package/skill/usebecky/references/ios.md +355 -0
- package/skill/usebecky/references/payments.md +493 -0
- package/skill/usebecky/references/realtime.md +143 -0
- package/skill/usebecky/references/scheduled-jobs.md +82 -0
- package/skill/usebecky/references/sdk.md +838 -0
- package/skill/usebecky/references/storage.md +210 -0
- package/skill/usebecky/references/templates.md +191 -0
- package/skill/usebecky/references/wordpress.md +87 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/** The docs site (placeholder until published; docs/PUBLISHING.md). A page is `${DOCS_URL}/<path under docs/guide without .md>`. */
|
|
2
|
+
export declare const DOCS_URL = "https://usebecky.com/docs";
|
|
3
|
+
/** The Swift package customers add in Xcode (the client library is MIT; the service itself is hosted, closed source). */
|
|
4
|
+
export declare const SWIFT_PACKAGE_URL = "https://github.com/usebecky/usebecky-swift";
|
|
5
|
+
/** The Kotlin client library on Maven Central. */
|
|
6
|
+
export declare const KOTLIN_ARTIFACT = "com.usebecky:usebecky-kotlin";
|
|
7
|
+
export type Framework = 'next' | 'vite' | 'remix' | 'nuxt' | 'sveltekit' | 'expo' | 'express' | 'node';
|
|
8
|
+
export interface Detected {
|
|
9
|
+
framework: Framework;
|
|
10
|
+
label: string;
|
|
11
|
+
typescript: boolean;
|
|
12
|
+
srcDir: boolean;
|
|
13
|
+
hasPackageJson: boolean;
|
|
14
|
+
dependencies: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export declare const FRAMEWORK_LABELS: Record<Framework, string>;
|
|
17
|
+
export declare function readPackageJson(dir: string): Record<string, any> | null;
|
|
18
|
+
export declare function detectFramework(dir: string): Detected;
|
|
19
|
+
export type NativePlatform = 'ios' | 'android';
|
|
20
|
+
export interface NativeProject {
|
|
21
|
+
/** Platforms found, iOS first. */
|
|
22
|
+
platforms: NativePlatform[];
|
|
23
|
+
/** The files and folders that gave it away, e.g. `MyNotes.xcodeproj`, `settings.gradle.kts`. */
|
|
24
|
+
markers: string[];
|
|
25
|
+
}
|
|
26
|
+
export declare const NATIVE_LABELS: Record<NativePlatform, string>;
|
|
27
|
+
/** An Xcode project or workspace, or Package.swift (iOS / Swift), or a Gradle build (Android / Kotlin), at the top of `dir`. */
|
|
28
|
+
export declare function detectNative(dir: string): NativeProject | null;
|
|
29
|
+
export type AppProject = {
|
|
30
|
+
kind: 'js';
|
|
31
|
+
detected: Detected;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'native';
|
|
34
|
+
native: NativeProject;
|
|
35
|
+
detected: Detected;
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'none';
|
|
38
|
+
detected: Detected;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* What kind of app lives in `dir`, checked before any Node.js fallback:
|
|
42
|
+
* a package.json with a known framework (Expo included) is JavaScript; otherwise an Xcode project,
|
|
43
|
+
* Package.swift or Gradle build makes it native (a package.json that only holds tooling doesn't turn an
|
|
44
|
+
* iOS app into a Node.js app); a package.json alone is Node.js; nothing recognisable is 'none'.
|
|
45
|
+
*/
|
|
46
|
+
export declare function detectProject(dir: string): AppProject;
|
|
47
|
+
/** Printed when nothing in the folder looks like an app. */
|
|
48
|
+
export declare const LOOKED_FOR = "package.json (JavaScript), an Xcode project (*.xcodeproj, *.xcworkspace or Package.swift) or a Gradle build (settings.gradle(.kts) or build.gradle(.kts))";
|
|
49
|
+
export interface NativeSetup {
|
|
50
|
+
platform: NativePlatform;
|
|
51
|
+
/** Short name for headings: "iOS (Swift)". */
|
|
52
|
+
title: string;
|
|
53
|
+
/** The file `code` goes into. */
|
|
54
|
+
file: string;
|
|
55
|
+
code: string;
|
|
56
|
+
/** Warnings worth reading first (local server addresses). */
|
|
57
|
+
notes: string[];
|
|
58
|
+
/** Numbered next steps; continuation lines start with spaces. Plain text. */
|
|
59
|
+
steps: string[];
|
|
60
|
+
guide: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* What a native app needs to connect: the client code with the Project URL and the publishable key
|
|
64
|
+
* (never the secret key: anyone can read every value inside an app), plus how to add the SDK.
|
|
65
|
+
*/
|
|
66
|
+
export declare function nativeSetup(platform: NativePlatform, keys: {
|
|
67
|
+
url: string;
|
|
68
|
+
publishableKey: string;
|
|
69
|
+
}, cwd: string, _home?: string): NativeSetup;
|
|
70
|
+
export interface ProjectKeys {
|
|
71
|
+
url: string;
|
|
72
|
+
publishableKey: string;
|
|
73
|
+
secretKey: string;
|
|
74
|
+
}
|
|
75
|
+
export interface EnvVar {
|
|
76
|
+
name: string;
|
|
77
|
+
value: string;
|
|
78
|
+
}
|
|
79
|
+
export interface EnvPlan {
|
|
80
|
+
file: '.env.local' | '.env';
|
|
81
|
+
vars: EnvVar[];
|
|
82
|
+
}
|
|
83
|
+
/** Which env file and variable names each framework uses (docs/SDK.md). */
|
|
84
|
+
export declare function envPlanFor(framework: Framework, keys: ProjectKeys): EnvPlan;
|
|
85
|
+
/** Parse a .env file into name → value. */
|
|
86
|
+
export declare function parseEnv(content: string): Record<string, string>;
|
|
87
|
+
export interface EnvWriteResult {
|
|
88
|
+
file: string;
|
|
89
|
+
created: boolean;
|
|
90
|
+
added: string[];
|
|
91
|
+
updated: string[];
|
|
92
|
+
kept: string[];
|
|
93
|
+
unchanged: string[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Add variables to an env file. Existing different values are only replaced when
|
|
97
|
+
* `confirmReplace` says yes. Other lines and comments are left untouched.
|
|
98
|
+
*/
|
|
99
|
+
export declare function writeEnvFile(file: string, vars: EnvVar[], confirmReplace: (name: string, oldValue: string, newValue: string) => Promise<boolean> | boolean): Promise<EnvWriteResult>;
|
|
100
|
+
/** Would git ignore `file` (a top-level file name) with these .gitignore contents? */
|
|
101
|
+
export declare function isIgnored(gitignore: string, file: string): boolean;
|
|
102
|
+
/** Make sure the env files are listed in .gitignore (creates it if needed). */
|
|
103
|
+
export declare function ensureGitignore(dir: string, files: string[]): {
|
|
104
|
+
file: string;
|
|
105
|
+
created: boolean;
|
|
106
|
+
added: string[];
|
|
107
|
+
};
|
|
108
|
+
export interface LibFile {
|
|
109
|
+
path: string;
|
|
110
|
+
content: string;
|
|
111
|
+
}
|
|
112
|
+
/** How to import the client file from the file a beginner types the code in. */
|
|
113
|
+
export interface ClientImport {
|
|
114
|
+
/** Where to type it, for people: "files directly inside src/ (like src/main.ts or src/App.tsx)". */
|
|
115
|
+
where: string;
|
|
116
|
+
/** One real file of that kind (relative specifiers in `from` and `also` resolve from its folder). */
|
|
117
|
+
file: string;
|
|
118
|
+
/** The module specifier: './lib/usebecky', '@/lib/usebecky', '$lib/usebecky', ... */
|
|
119
|
+
from: string;
|
|
120
|
+
/** Another common spot, already worded: "in src/components/: '../lib/usebecky'". */
|
|
121
|
+
also?: string;
|
|
122
|
+
}
|
|
123
|
+
/** `from` for an import in `fromFile` of the file at `target` (project-relative, forward slashes). */
|
|
124
|
+
export declare function relativeImport(fromFile: string, target: string): string;
|
|
125
|
+
/** The import line for the client file, correct relative to the file people type it in. */
|
|
126
|
+
export declare function clientImport(d: Pick<Detected, 'framework' | 'typescript' | 'dependencies'>, libPath: string): ClientImport;
|
|
127
|
+
/** The `lib/usebecky.ts` (or .js) file for a framework. */
|
|
128
|
+
export declare function libFileFor(d: Pick<Detected, 'framework' | 'typescript' | 'srcDir' | 'dependencies'>): LibFile;
|
|
129
|
+
/** Create the client file unless it already exists. */
|
|
130
|
+
export declare function writeLibFile(dir: string, lib: LibFile): {
|
|
131
|
+
path: string;
|
|
132
|
+
created: boolean;
|
|
133
|
+
};
|
|
134
|
+
/** Copy-paste next steps for a framework. */
|
|
135
|
+
export declare function nextSteps(d: Detected, lib: LibFile, needsInstall: boolean): string[];
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
// Framework detection + writing env files / the client file for `npx usebecky init`.
|
|
2
|
+
// Also recognises native apps (Xcode / Swift package / Gradle), which never get the secret key.
|
|
3
|
+
// Pure functions over a directory so they are easy to test.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
/** The docs site (placeholder until published; docs/PUBLISHING.md). A page is `${DOCS_URL}/<path under docs/guide without .md>`. */
|
|
8
|
+
export const DOCS_URL = 'https://usebecky.com/docs';
|
|
9
|
+
/** The Swift package customers add in Xcode (the client library is MIT; the service itself is hosted, closed source). */
|
|
10
|
+
export const SWIFT_PACKAGE_URL = 'https://github.com/usebecky/usebecky-swift';
|
|
11
|
+
/** The Kotlin client library on Maven Central. */
|
|
12
|
+
export const KOTLIN_ARTIFACT = 'com.usebecky:usebecky-kotlin';
|
|
13
|
+
/**
|
|
14
|
+
* Same text as DASHBOARD_API_KEYS in src/lib/dashboard-paths.ts. Repeated because this file is also
|
|
15
|
+
* copied into create-usebecky, which has no src/lib; test/cli-dashboard-paths.test.ts keeps them equal.
|
|
16
|
+
*/
|
|
17
|
+
const KEYS_PAGE = 'Dashboard → Settings → API keys';
|
|
18
|
+
export const FRAMEWORK_LABELS = {
|
|
19
|
+
next: 'Next.js',
|
|
20
|
+
vite: 'Vite',
|
|
21
|
+
remix: 'Remix',
|
|
22
|
+
nuxt: 'Nuxt',
|
|
23
|
+
sveltekit: 'SvelteKit',
|
|
24
|
+
expo: 'Expo (React Native)',
|
|
25
|
+
express: 'Express',
|
|
26
|
+
node: 'Node.js',
|
|
27
|
+
};
|
|
28
|
+
export function readPackageJson(dir) {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function detectFramework(dir) {
|
|
37
|
+
const pkg = readPackageJson(dir);
|
|
38
|
+
const deps = { ...(pkg?.devDependencies ?? {}), ...(pkg?.dependencies ?? {}) };
|
|
39
|
+
const has = (name) => Object.prototype.hasOwnProperty.call(deps, name);
|
|
40
|
+
let framework = 'node';
|
|
41
|
+
if (has('expo') || has('react-native'))
|
|
42
|
+
framework = 'expo';
|
|
43
|
+
else if (has('next'))
|
|
44
|
+
framework = 'next';
|
|
45
|
+
else if (Object.keys(deps).some((d) => d.startsWith('@remix-run/')))
|
|
46
|
+
framework = 'remix';
|
|
47
|
+
else if (has('nuxt') || has('nuxt3'))
|
|
48
|
+
framework = 'nuxt';
|
|
49
|
+
else if (has('@sveltejs/kit'))
|
|
50
|
+
framework = 'sveltekit';
|
|
51
|
+
else if (has('vite'))
|
|
52
|
+
framework = 'vite';
|
|
53
|
+
else if (has('express'))
|
|
54
|
+
framework = 'express';
|
|
55
|
+
const typescript = fs.existsSync(path.join(dir, 'tsconfig.json')) || has('typescript');
|
|
56
|
+
const srcDir = fs.existsSync(path.join(dir, 'src')) && fs.statSync(path.join(dir, 'src')).isDirectory();
|
|
57
|
+
return { framework, label: FRAMEWORK_LABELS[framework], typescript, srcDir, hasPackageJson: !!pkg, dependencies: deps };
|
|
58
|
+
}
|
|
59
|
+
export const NATIVE_LABELS = {
|
|
60
|
+
ios: 'an iOS app (Swift)',
|
|
61
|
+
android: 'an Android app (Kotlin)',
|
|
62
|
+
};
|
|
63
|
+
const GRADLE_FILES = ['settings.gradle.kts', 'settings.gradle', 'build.gradle.kts', 'build.gradle'];
|
|
64
|
+
/** An Xcode project or workspace, or Package.swift (iOS / Swift), or a Gradle build (Android / Kotlin), at the top of `dir`. */
|
|
65
|
+
export function detectNative(dir) {
|
|
66
|
+
let entries;
|
|
67
|
+
try {
|
|
68
|
+
entries = fs.readdirSync(dir).sort();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const ios = entries.filter((e) => e === 'Package.swift' || (/\.(xcodeproj|xcworkspace)$/.test(e) && !e.startsWith('.')));
|
|
74
|
+
const android = GRADLE_FILES.filter((f) => entries.includes(f));
|
|
75
|
+
const platforms = [];
|
|
76
|
+
if (ios.length)
|
|
77
|
+
platforms.push('ios');
|
|
78
|
+
if (android.length)
|
|
79
|
+
platforms.push('android');
|
|
80
|
+
return platforms.length ? { platforms, markers: [...ios, ...android] } : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* What kind of app lives in `dir`, checked before any Node.js fallback:
|
|
84
|
+
* a package.json with a known framework (Expo included) is JavaScript; otherwise an Xcode project,
|
|
85
|
+
* Package.swift or Gradle build makes it native (a package.json that only holds tooling doesn't turn an
|
|
86
|
+
* iOS app into a Node.js app); a package.json alone is Node.js; nothing recognisable is 'none'.
|
|
87
|
+
*/
|
|
88
|
+
export function detectProject(dir) {
|
|
89
|
+
const detected = detectFramework(dir);
|
|
90
|
+
if (detected.hasPackageJson && detected.framework !== 'node')
|
|
91
|
+
return { kind: 'js', detected };
|
|
92
|
+
const native = detectNative(dir);
|
|
93
|
+
if (native)
|
|
94
|
+
return { kind: 'native', native, detected };
|
|
95
|
+
if (detected.hasPackageJson)
|
|
96
|
+
return { kind: 'js', detected };
|
|
97
|
+
return { kind: 'none', detected };
|
|
98
|
+
}
|
|
99
|
+
/** Printed when nothing in the folder looks like an app. */
|
|
100
|
+
export const LOOKED_FOR = 'package.json (JavaScript), an Xcode project (*.xcodeproj, *.xcworkspace or Package.swift) or a Gradle build (settings.gradle(.kts) or build.gradle(.kts))';
|
|
101
|
+
const LOCAL_URL = /^(https?:\/\/)(localhost|127\.0\.0\.1)(?=[:/]|$)/i;
|
|
102
|
+
/**
|
|
103
|
+
* What a native app needs to connect: the client code with the Project URL and the publishable key
|
|
104
|
+
* (never the secret key: anyone can read every value inside an app), plus how to add the SDK.
|
|
105
|
+
*/
|
|
106
|
+
export function nativeSetup(platform, keys, cwd, _home = os.homedir()) {
|
|
107
|
+
const local = LOCAL_URL.test(keys.url);
|
|
108
|
+
if (platform === 'ios') {
|
|
109
|
+
return {
|
|
110
|
+
platform,
|
|
111
|
+
title: 'iOS (Swift)',
|
|
112
|
+
file: 'Baas.swift',
|
|
113
|
+
code: [
|
|
114
|
+
'// Baas.swift',
|
|
115
|
+
'import UseBecky',
|
|
116
|
+
'',
|
|
117
|
+
'// Your connection to usebecky. The whole app uses this one `baas`.',
|
|
118
|
+
'let baas = UseBecky(',
|
|
119
|
+
` url: "${keys.url}",`,
|
|
120
|
+
` publishableKey: "${keys.publishableKey}"`,
|
|
121
|
+
')',
|
|
122
|
+
].join('\n'),
|
|
123
|
+
notes: local ? [`${keys.url} works in the iOS Simulator, not on an iPhone: on a phone use your hosted Project URL, or your Mac's Wi-Fi address (see "Test on your phone" in the iOS guide).`] : [],
|
|
124
|
+
steps: [
|
|
125
|
+
`Add the Swift package: Xcode → File → Add Package Dependencies… → paste ${SWIFT_PACKAGE_URL} → Add Package → tick your app target`,
|
|
126
|
+
'Xcode → File → New → File from Template… → Swift File, name it Baas, paste the code above, then build (Cmd+B)',
|
|
127
|
+
`Follow the iOS guide for sign-in, data, files and payments: ${DOCS_URL}/frameworks/ios`,
|
|
128
|
+
'Teach your AI assistant (it reads references/ios.md): npx usebecky ai',
|
|
129
|
+
],
|
|
130
|
+
guide: `${DOCS_URL}/frameworks/ios`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const appBuild = fs.existsSync(path.join(cwd, 'app', 'build.gradle')) ? 'app/build.gradle' : 'app/build.gradle.kts';
|
|
134
|
+
const url = keys.url.replace(LOCAL_URL, (_m, scheme) => `${scheme}10.0.2.2`);
|
|
135
|
+
return {
|
|
136
|
+
platform,
|
|
137
|
+
title: 'Android (Kotlin)',
|
|
138
|
+
file: 'Backend.kt',
|
|
139
|
+
code: [
|
|
140
|
+
'// Backend.kt (the Android guide shows the whole file: client, session storage, helpers)',
|
|
141
|
+
'object UseBeckyConfig {',
|
|
142
|
+
` const val URL = "${url}"`,
|
|
143
|
+
` const val PUBLISHABLE_KEY = "${keys.publishableKey}"`,
|
|
144
|
+
'}',
|
|
145
|
+
].join('\n'),
|
|
146
|
+
notes: local
|
|
147
|
+
? [`10.0.2.2 is your computer as the Android emulator sees it (on a phone, use your computer's Wi-Fi address). Plain http:// also needs android:usesCleartextTraffic="true" on <application> in AndroidManifest.xml: remove it before you publish.`]
|
|
148
|
+
: [],
|
|
149
|
+
steps: [
|
|
150
|
+
`Add the Kotlin SDK from Maven Central: ${appBuild}, in dependencies { }: implementation("${KOTLIN_ARTIFACT}:0.2.0")`,
|
|
151
|
+
'AndroidManifest.xml, inside <manifest>: <uses-permission android:name="android.permission.INTERNET" />',
|
|
152
|
+
'Put the code above in Backend.kt, next to MainActivity.kt',
|
|
153
|
+
`Follow the Android guide for sign-in, data, files and payments: ${DOCS_URL}/frameworks/android`,
|
|
154
|
+
'Teach your AI assistant (it reads references/android.md): npx usebecky ai',
|
|
155
|
+
],
|
|
156
|
+
guide: `${DOCS_URL}/frameworks/android`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Which env file and variable names each framework uses (docs/SDK.md). */
|
|
160
|
+
export function envPlanFor(framework, keys) {
|
|
161
|
+
const server = [
|
|
162
|
+
{ name: 'USEBECKY_URL', value: keys.url },
|
|
163
|
+
{ name: 'USEBECKY_SECRET_KEY', value: keys.secretKey },
|
|
164
|
+
];
|
|
165
|
+
switch (framework) {
|
|
166
|
+
case 'next':
|
|
167
|
+
return { file: '.env.local', vars: [{ name: 'NEXT_PUBLIC_USEBECKY_URL', value: keys.url }, { name: 'NEXT_PUBLIC_USEBECKY_PUBLISHABLE_KEY', value: keys.publishableKey }, ...server] };
|
|
168
|
+
case 'vite':
|
|
169
|
+
return { file: '.env.local', vars: [{ name: 'VITE_USEBECKY_URL', value: keys.url }, { name: 'VITE_USEBECKY_PUBLISHABLE_KEY', value: keys.publishableKey }] };
|
|
170
|
+
case 'remix':
|
|
171
|
+
return { file: '.env', vars: [{ name: 'VITE_USEBECKY_URL', value: keys.url }, { name: 'VITE_USEBECKY_PUBLISHABLE_KEY', value: keys.publishableKey }, ...server] };
|
|
172
|
+
case 'nuxt':
|
|
173
|
+
return { file: '.env', vars: [{ name: 'NUXT_PUBLIC_USEBECKY_URL', value: keys.url }, { name: 'NUXT_PUBLIC_USEBECKY_PUBLISHABLE_KEY', value: keys.publishableKey }, ...server] };
|
|
174
|
+
case 'sveltekit':
|
|
175
|
+
return { file: '.env', vars: [{ name: 'PUBLIC_USEBECKY_URL', value: keys.url }, { name: 'PUBLIC_USEBECKY_PUBLISHABLE_KEY', value: keys.publishableKey }, ...server] };
|
|
176
|
+
case 'expo':
|
|
177
|
+
return { file: '.env', vars: [{ name: 'EXPO_PUBLIC_USEBECKY_URL', value: keys.url }, { name: 'EXPO_PUBLIC_USEBECKY_PUBLISHABLE_KEY', value: keys.publishableKey }] };
|
|
178
|
+
default:
|
|
179
|
+
return { file: '.env', vars: [{ name: 'USEBECKY_URL', value: keys.url }, { name: 'USEBECKY_PUBLISHABLE_KEY', value: keys.publishableKey }, { name: 'USEBECKY_SECRET_KEY', value: keys.secretKey }] };
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const LINE_RE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=\s*(.*)?$/;
|
|
183
|
+
function unquote(v) {
|
|
184
|
+
const t = v.trim();
|
|
185
|
+
if ((t.startsWith('"') && t.endsWith('"')) || (t.startsWith("'") && t.endsWith("'")))
|
|
186
|
+
return t.slice(1, -1);
|
|
187
|
+
const hash = t.indexOf(' #');
|
|
188
|
+
return hash >= 0 ? t.slice(0, hash).trim() : t;
|
|
189
|
+
}
|
|
190
|
+
/** Parse a .env file into name → value. */
|
|
191
|
+
export function parseEnv(content) {
|
|
192
|
+
const out = {};
|
|
193
|
+
for (const line of content.split(/\r?\n/)) {
|
|
194
|
+
if (/^\s*#/.test(line))
|
|
195
|
+
continue;
|
|
196
|
+
const m = LINE_RE.exec(line);
|
|
197
|
+
if (m)
|
|
198
|
+
out[m[1]] = unquote(m[2] ?? '');
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Add variables to an env file. Existing different values are only replaced when
|
|
204
|
+
* `confirmReplace` says yes. Other lines and comments are left untouched.
|
|
205
|
+
*/
|
|
206
|
+
export async function writeEnvFile(file, vars, confirmReplace) {
|
|
207
|
+
const exists = fs.existsSync(file);
|
|
208
|
+
const original = exists ? fs.readFileSync(file, 'utf8') : '';
|
|
209
|
+
const lines = original === '' ? [] : original.split(/\r?\n/);
|
|
210
|
+
if (lines.length && lines[lines.length - 1] === '')
|
|
211
|
+
lines.pop();
|
|
212
|
+
const result = { file, created: !exists, added: [], updated: [], kept: [], unchanged: [] };
|
|
213
|
+
const toAppend = [];
|
|
214
|
+
for (const v of vars) {
|
|
215
|
+
const idx = lines.findIndex((l) => !/^\s*#/.test(l) && LINE_RE.exec(l)?.[1] === v.name);
|
|
216
|
+
if (idx === -1) {
|
|
217
|
+
toAppend.push(`${v.name}=${v.value}`);
|
|
218
|
+
result.added.push(v.name);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const current = unquote(LINE_RE.exec(lines[idx])[2] ?? '');
|
|
222
|
+
if (current === v.value) {
|
|
223
|
+
result.unchanged.push(v.name);
|
|
224
|
+
}
|
|
225
|
+
else if (current === '' || (await confirmReplace(v.name, current, v.value))) {
|
|
226
|
+
lines[idx] = `${v.name}=${v.value}`;
|
|
227
|
+
result.updated.push(v.name);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
result.kept.push(v.name);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (toAppend.length) {
|
|
234
|
+
if (lines.length && lines[lines.length - 1].trim() !== '')
|
|
235
|
+
lines.push('');
|
|
236
|
+
lines.push(`# usebecky: values from ${KEYS_PAGE} (written by \`npx usebecky init\`)`, ...toAppend);
|
|
237
|
+
}
|
|
238
|
+
if (result.added.length || result.updated.length || !exists)
|
|
239
|
+
fs.writeFileSync(file, lines.join('\n') + '\n', { mode: 0o600 });
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
function globToRegex(glob) {
|
|
243
|
+
let re = '';
|
|
244
|
+
for (const ch of glob) {
|
|
245
|
+
if (ch === '*')
|
|
246
|
+
re += '[^/]*';
|
|
247
|
+
else if (ch === '?')
|
|
248
|
+
re += '[^/]';
|
|
249
|
+
else
|
|
250
|
+
re += ch.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
251
|
+
}
|
|
252
|
+
return new RegExp(`^${re}$`);
|
|
253
|
+
}
|
|
254
|
+
/** Would git ignore `file` (a top-level file name) with these .gitignore contents? */
|
|
255
|
+
export function isIgnored(gitignore, file) {
|
|
256
|
+
let ignored = false;
|
|
257
|
+
for (const raw of gitignore.split(/\r?\n/)) {
|
|
258
|
+
let line = raw.trim();
|
|
259
|
+
if (!line || line.startsWith('#'))
|
|
260
|
+
continue;
|
|
261
|
+
const negate = line.startsWith('!');
|
|
262
|
+
if (negate)
|
|
263
|
+
line = line.slice(1);
|
|
264
|
+
line = line.replace(/^\/+/, '').replace(/^\*\*\//, '');
|
|
265
|
+
if (line.endsWith('/'))
|
|
266
|
+
continue;
|
|
267
|
+
if (globToRegex(line).test(file))
|
|
268
|
+
ignored = !negate;
|
|
269
|
+
}
|
|
270
|
+
return ignored;
|
|
271
|
+
}
|
|
272
|
+
/** Make sure the env files are listed in .gitignore (creates it if needed). */
|
|
273
|
+
export function ensureGitignore(dir, files) {
|
|
274
|
+
const file = path.join(dir, '.gitignore');
|
|
275
|
+
const exists = fs.existsSync(file);
|
|
276
|
+
const content = exists ? fs.readFileSync(file, 'utf8') : '';
|
|
277
|
+
const missing = files.filter((f) => !isIgnored(content, f));
|
|
278
|
+
if (missing.length) {
|
|
279
|
+
const prefix = content && !content.endsWith('\n') ? '\n' : '';
|
|
280
|
+
const block = `${prefix}${content ? '\n' : ''}# usebecky: keep your keys out of git\n${missing.join('\n')}\n`;
|
|
281
|
+
fs.writeFileSync(file, content + block);
|
|
282
|
+
}
|
|
283
|
+
return { file, created: !exists && missing.length > 0, added: missing };
|
|
284
|
+
}
|
|
285
|
+
/** `from` for an import in `fromFile` of the file at `target` (project-relative, forward slashes). */
|
|
286
|
+
export function relativeImport(fromFile, target) {
|
|
287
|
+
const rel = path.posix.relative(path.posix.dirname(fromFile), target);
|
|
288
|
+
return rel.startsWith('.') ? rel : `./${rel}`;
|
|
289
|
+
}
|
|
290
|
+
/** The import line for the client file, correct relative to the file people type it in. */
|
|
291
|
+
export function clientImport(d, libPath) {
|
|
292
|
+
const noExt = libPath.replace(/\.(ts|js)$/, '');
|
|
293
|
+
const src = libPath.startsWith('src/') ? 'src/' : '';
|
|
294
|
+
const ts = d.typescript;
|
|
295
|
+
switch (d.framework) {
|
|
296
|
+
case 'next': {
|
|
297
|
+
const file = `${src}app/page.${ts ? 'tsx' : 'js'}`;
|
|
298
|
+
return { where: `a client component, like ${file} (with 'use client' at the top)`, file, from: '@/lib/usebecky', also: `without the @/ alias in ${ts ? 'tsconfig.json' : 'jsconfig.json'}: '${relativeImport(file, noExt)}'` };
|
|
299
|
+
}
|
|
300
|
+
case 'vite': {
|
|
301
|
+
const file = src ? `src/main.${ts ? 'ts' : 'js'}` : `main.${ts ? 'ts' : 'js'}`;
|
|
302
|
+
const where = src ? `files directly inside src/ (like ${file} or src/App.${ts ? 'tsx' : 'jsx'})` : `files in the project folder (like ${file})`;
|
|
303
|
+
return { where, file, from: relativeImport(file, noExt), also: `in ${src}components/: '${relativeImport(`${src}components/x.${ts ? 'tsx' : 'jsx'}`, noExt)}'` };
|
|
304
|
+
}
|
|
305
|
+
case 'remix': {
|
|
306
|
+
const file = `app/routes/_index.${ts ? 'tsx' : 'jsx'}`;
|
|
307
|
+
return { where: `a route, like ${file}`, file, from: relativeImport(file, noExt), also: `in app/root.${ts ? 'tsx' : 'jsx'}: '${relativeImport('app/root.tsx', noExt)}'` };
|
|
308
|
+
}
|
|
309
|
+
case 'nuxt':
|
|
310
|
+
// ~~ is the project folder in Nuxt 3 and 4 (~ is app/ in Nuxt 4).
|
|
311
|
+
return { where: 'a page or component, like app.vue or pages/index.vue', file: 'app.vue', from: '~~/lib/usebecky' };
|
|
312
|
+
case 'sveltekit':
|
|
313
|
+
return { where: 'any file in src/, like src/routes/+page.svelte', file: 'src/routes/+page.svelte', from: '$lib/usebecky' };
|
|
314
|
+
case 'expo': {
|
|
315
|
+
const router = Object.prototype.hasOwnProperty.call(d.dependencies, 'expo-router');
|
|
316
|
+
const file = router ? `app/index.${ts ? 'tsx' : 'js'}` : `App.${ts ? 'tsx' : 'js'}`;
|
|
317
|
+
return { where: router ? `a screen, like ${file}` : file, file, from: relativeImport(file, noExt), also: `in files inside lib/: './usebecky'` };
|
|
318
|
+
}
|
|
319
|
+
default: {
|
|
320
|
+
// Node runs ESM with the file extension in relative imports (.ts too, with Node's type stripping).
|
|
321
|
+
const file = `server.${ts ? 'ts' : 'js'}`;
|
|
322
|
+
return { where: `${file} in the project folder`, file, from: relativeImport(file, libPath), also: `in src/index.${ts ? 'ts' : 'js'}: '${relativeImport('src/index.js', libPath)}'` };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/** The `lib/usebecky.ts` (or .js) file for a framework. */
|
|
327
|
+
export function libFileFor(d) {
|
|
328
|
+
const ext = d.typescript ? 'ts' : 'js';
|
|
329
|
+
const bang = d.typescript ? '!' : '';
|
|
330
|
+
const useSrc = d.srcDir && (d.framework === 'next' || d.framework === 'vite' || d.framework === 'sveltekit' || d.framework === 'remix');
|
|
331
|
+
const dir = d.framework === 'sveltekit' ? 'src/lib' : useSrc ? 'src/lib' : 'lib';
|
|
332
|
+
const file = `${dir}/usebecky.${ext}`;
|
|
333
|
+
const imp = clientImport(d, file);
|
|
334
|
+
let content;
|
|
335
|
+
switch (d.framework) {
|
|
336
|
+
case 'next':
|
|
337
|
+
content = `// Your usebecky client for browser code ('use client' components).
|
|
338
|
+
// In server code (route handlers, server actions) use: import { baas } from 'usebecky/server'
|
|
339
|
+
import { createClient } from 'usebecky'
|
|
340
|
+
|
|
341
|
+
export const baas = createClient(
|
|
342
|
+
process.env.NEXT_PUBLIC_USEBECKY_URL${bang},
|
|
343
|
+
process.env.NEXT_PUBLIC_USEBECKY_PUBLISHABLE_KEY${bang},
|
|
344
|
+
)
|
|
345
|
+
`;
|
|
346
|
+
break;
|
|
347
|
+
case 'vite':
|
|
348
|
+
case 'remix':
|
|
349
|
+
content = `// Your usebecky client. In ${imp.where}: import { baas } from '${imp.from}'
|
|
350
|
+
// (${imp.also})
|
|
351
|
+
import { createClient } from 'usebecky'
|
|
352
|
+
|
|
353
|
+
export const baas = createClient(
|
|
354
|
+
import.meta.env.VITE_USEBECKY_URL,
|
|
355
|
+
import.meta.env.VITE_USEBECKY_PUBLISHABLE_KEY,
|
|
356
|
+
)
|
|
357
|
+
`;
|
|
358
|
+
break;
|
|
359
|
+
case 'nuxt':
|
|
360
|
+
content = `// Your usebecky client. In ${imp.where}: import { useBecky } from '${imp.from}', then const baas = useBecky()
|
|
361
|
+
// nuxt.config: runtimeConfig: { public: { usebeckyUrl: '', usebeckyPublishableKey: '' } }
|
|
362
|
+
import { createClient${d.typescript ? ', type UseBeckyClient' : ''} } from 'usebecky'
|
|
363
|
+
import { useRuntimeConfig } from '#imports'
|
|
364
|
+
|
|
365
|
+
let client${d.typescript ? ': UseBeckyClient | undefined' : ''}
|
|
366
|
+
|
|
367
|
+
export function useBecky() {
|
|
368
|
+
const config = useRuntimeConfig()
|
|
369
|
+
client ??= createClient(config.public.usebeckyUrl${d.typescript ? ' as string' : ''}, config.public.usebeckyPublishableKey${d.typescript ? ' as string' : ''})
|
|
370
|
+
return client
|
|
371
|
+
}
|
|
372
|
+
`;
|
|
373
|
+
break;
|
|
374
|
+
case 'sveltekit':
|
|
375
|
+
content = `// Your usebecky client. Import it anywhere: import { baas } from '$lib/usebecky'
|
|
376
|
+
import { createClient } from 'usebecky'
|
|
377
|
+
import { PUBLIC_USEBECKY_URL, PUBLIC_USEBECKY_PUBLISHABLE_KEY } from '$env/static/public'
|
|
378
|
+
|
|
379
|
+
export const baas = createClient(PUBLIC_USEBECKY_URL, PUBLIC_USEBECKY_PUBLISHABLE_KEY)
|
|
380
|
+
`;
|
|
381
|
+
break;
|
|
382
|
+
case 'expo': {
|
|
383
|
+
const hasAsync = Object.prototype.hasOwnProperty.call(d.dependencies, '@react-native-async-storage/async-storage');
|
|
384
|
+
content = hasAsync
|
|
385
|
+
? `// Your usebecky client. Sessions are saved with AsyncStorage so users stay signed in.
|
|
386
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
387
|
+
import { createClient } from 'usebecky'
|
|
388
|
+
|
|
389
|
+
export const baas = createClient(
|
|
390
|
+
process.env.EXPO_PUBLIC_USEBECKY_URL${bang},
|
|
391
|
+
process.env.EXPO_PUBLIC_USEBECKY_PUBLISHABLE_KEY${bang},
|
|
392
|
+
{ storage: AsyncStorage, detectSessionInUrl: false },
|
|
393
|
+
)
|
|
394
|
+
`
|
|
395
|
+
: `// Your usebecky client.
|
|
396
|
+
// To keep users signed in after the app restarts, run
|
|
397
|
+
// npx expo install @react-native-async-storage/async-storage
|
|
398
|
+
// then pass { storage: AsyncStorage } as the third argument below.
|
|
399
|
+
import { createClient } from 'usebecky'
|
|
400
|
+
|
|
401
|
+
export const baas = createClient(
|
|
402
|
+
process.env.EXPO_PUBLIC_USEBECKY_URL${bang},
|
|
403
|
+
process.env.EXPO_PUBLIC_USEBECKY_PUBLISHABLE_KEY${bang},
|
|
404
|
+
{ detectSessionInUrl: false },
|
|
405
|
+
)
|
|
406
|
+
`;
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
default:
|
|
410
|
+
content = `// Server-side usebecky client. It reads USEBECKY_URL and USEBECKY_SECRET_KEY from the environment.
|
|
411
|
+
// Start your app with the .env file loaded: node --env-file=.env ${imp.file}
|
|
412
|
+
//
|
|
413
|
+
// import { baas } from '${imp.from}' // in ${imp.file}; ${imp.also}
|
|
414
|
+
// app.use(baas.auth.middleware()) // req.user = the signed-in user, or null
|
|
415
|
+
// await baas.as(req).from('todos').select() // as that user (Row Level Security applies)
|
|
416
|
+
export { baas } from 'usebecky/server'
|
|
417
|
+
`;
|
|
418
|
+
}
|
|
419
|
+
return { path: file, content };
|
|
420
|
+
}
|
|
421
|
+
/** Create the client file unless it already exists. */
|
|
422
|
+
export function writeLibFile(dir, lib) {
|
|
423
|
+
const full = path.join(dir, lib.path);
|
|
424
|
+
if (fs.existsSync(full))
|
|
425
|
+
return { path: lib.path, created: false };
|
|
426
|
+
fs.mkdirSync(path.dirname(full), { recursive: true });
|
|
427
|
+
fs.writeFileSync(full, lib.content);
|
|
428
|
+
return { path: lib.path, created: true };
|
|
429
|
+
}
|
|
430
|
+
/** Copy-paste next steps for a framework. */
|
|
431
|
+
export function nextSteps(d, lib, needsInstall) {
|
|
432
|
+
const imp = clientImport(d, lib.path);
|
|
433
|
+
const use = (code) => `In ${imp.where}:\n import { baas } from '${imp.from}'\n ${code}${imp.also ? `\n (${imp.also})` : ''}`;
|
|
434
|
+
const steps = [];
|
|
435
|
+
if (needsInstall)
|
|
436
|
+
steps.push(d.framework === 'expo' ? 'npx expo install usebecky' : 'npm install usebecky');
|
|
437
|
+
switch (d.framework) {
|
|
438
|
+
case 'next':
|
|
439
|
+
steps.push(use("await baas.auth.signInWith('google')"), `In a route handler or server action, like ${imp.file.replace(/page\.(tsx|js)$/, `api/notes/route.${d.typescript ? 'ts' : 'js'}`)}:\n import { baas } from 'usebecky/server'\n const user = await baas.auth.getUser(request)`, 'Restart `npm run dev` so Next.js loads .env.local');
|
|
440
|
+
break;
|
|
441
|
+
case 'vite':
|
|
442
|
+
case 'remix':
|
|
443
|
+
steps.push(use("const { data, error } = await baas.from('todos').select()"), 'Restart `npm run dev` so Vite loads the new env file');
|
|
444
|
+
break;
|
|
445
|
+
case 'nuxt':
|
|
446
|
+
steps.push("Add to nuxt.config: runtimeConfig: { public: { usebeckyUrl: '', usebeckyPublishableKey: '' } }", `In ${imp.where}, inside <script setup>:\n import { useBecky } from '${imp.from}'\n const baas = useBecky()`, 'Restart `npm run dev`');
|
|
447
|
+
break;
|
|
448
|
+
case 'sveltekit':
|
|
449
|
+
steps.push(use("const { data, error } = await baas.from('todos').select()"), "On the server, like src/routes/+page.server.ts:\n import { createServerClient } from 'usebecky/server'\n import { USEBECKY_URL, USEBECKY_SECRET_KEY } from '$env/static/private'\n const baas = createServerClient({ url: USEBECKY_URL, secretKey: USEBECKY_SECRET_KEY })");
|
|
450
|
+
break;
|
|
451
|
+
case 'expo':
|
|
452
|
+
steps.push(use("const { data, error } = await baas.from('todos').select()"), 'Restart Expo with `npx expo start -c` so it picks up the env vars');
|
|
453
|
+
break;
|
|
454
|
+
default:
|
|
455
|
+
steps.push(use('app.use(baas.auth.middleware())'), `Start with your env file loaded: node --env-file=.env ${imp.file}`);
|
|
456
|
+
}
|
|
457
|
+
steps.push('Generate types for autocomplete: npx usebecky types');
|
|
458
|
+
return steps;
|
|
459
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Ui } from './ui.ts';
|
|
2
|
+
export declare const FUNCTIONS_DIR: string;
|
|
3
|
+
export declare const NAME_RE: RegExp;
|
|
4
|
+
export declare const CODE_MAX_BYTES: number;
|
|
5
|
+
type ApiResult<T> = {
|
|
6
|
+
data: T | null;
|
|
7
|
+
error: {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
status: number;
|
|
12
|
+
details?: any;
|
|
13
|
+
} | null;
|
|
14
|
+
};
|
|
15
|
+
/** The part of esbuild's API we use (so tests can pass a fake). */
|
|
16
|
+
export interface EsbuildLike {
|
|
17
|
+
build(options: Record<string, unknown>): Promise<{
|
|
18
|
+
outputFiles?: {
|
|
19
|
+
path: string;
|
|
20
|
+
text: string;
|
|
21
|
+
}[];
|
|
22
|
+
errors?: unknown[];
|
|
23
|
+
warnings?: unknown[];
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export interface FunctionsContext {
|
|
27
|
+
cwd: string;
|
|
28
|
+
ui: Ui;
|
|
29
|
+
/** Positional arguments after `functions` (subcommand first; unknown --flags included). */
|
|
30
|
+
args: string[];
|
|
31
|
+
ref: string | null;
|
|
32
|
+
yes: boolean;
|
|
33
|
+
force: boolean;
|
|
34
|
+
/** Platform API call for this project, already signed in: api('GET', '/functions'). */
|
|
35
|
+
api: <T = any>(method: string, path: string, body?: unknown) => Promise<ApiResult<T>>;
|
|
36
|
+
signIn: () => Promise<boolean>;
|
|
37
|
+
printError: (e: {
|
|
38
|
+
message: string;
|
|
39
|
+
hint?: string;
|
|
40
|
+
status?: number;
|
|
41
|
+
}) => number;
|
|
42
|
+
noProject: () => number;
|
|
43
|
+
/** esbuild from the app's own node_modules (tests pass a fake). null = not installed. */
|
|
44
|
+
loadEsbuild?: () => Promise<EsbuildLike | null>;
|
|
45
|
+
}
|
|
46
|
+
/** `--template x` / `--template=x` / `--errors` out of the positional list. */
|
|
47
|
+
export declare function splitArgs(args: string[]): {
|
|
48
|
+
positional: string[];
|
|
49
|
+
template?: string;
|
|
50
|
+
errors: boolean;
|
|
51
|
+
};
|
|
52
|
+
/** The entry file of a function: usebecky/functions/<name>.ts (or .mts/.js/.mjs), or <name>/index.ts. */
|
|
53
|
+
export declare function entryFor(cwd: string, name: string): string | null;
|
|
54
|
+
/** Every function in usebecky/functions/ (files and folders starting with "_" are shared code). */
|
|
55
|
+
export declare function listLocalFunctions(cwd: string): string[];
|
|
56
|
+
/** esbuild as installed in the app (never bundled with usebecky). */
|
|
57
|
+
export declare function loadProjectEsbuild(cwd: string): Promise<EsbuildLike | null>;
|
|
58
|
+
export declare function functionsCommand(ctx: FunctionsContext): Promise<number>;
|
|
59
|
+
export {};
|