create-nextly-app 0.0.2-alpha.66 → 0.0.2-alpha.68

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.
@@ -0,0 +1,20 @@
1
+ // Warm up Nextly once per worker at startup (Node.js runtime only) so admin/API
2
+ // handlers never run before init and schema boot-apply runs once, not per request.
3
+ // Imported dynamically + guarded so nextly stays out of the Edge bundle. It sits
4
+ // in src/ beside app/, where Next.js looks for it when an app lives under src/.
5
+ export async function register(): Promise<void> {
6
+ if (process.env.NEXT_RUNTIME !== "nodejs") return;
7
+
8
+ const { createRegister, getService } = await import("nextly");
9
+ const { default: config } = await import("../nextly.config");
10
+ await createRegister(config)();
11
+
12
+ // Create the user admin.devAutoLogin signs in as (see seed-dev-user.ts).
13
+ // After boot, because boot seeds every permission and the Super Admin role
14
+ // created here takes all that exist.
15
+ const { seedSuperAdmin } = await import("nextly/database/seeders");
16
+ const { seedDevUser } = await import("./seed-dev-user");
17
+ await seedDevUser(config.admin?.devAutoLogin, options =>
18
+ seedSuperAdmin(getService("adapter"), options)
19
+ );
20
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Create the account `admin.devAutoLogin` signs in as.
3
+ *
4
+ * Auto-login signs in a user that already exists and never creates one, so
5
+ * without this the first /admin visit lands on the setup wizard. The seeder is
6
+ * passed in by instrumentation.ts, which keeps this file free of imports and
7
+ * lets it run on its own.
8
+ */
9
+
10
+ /** The account `admin.devAutoLogin` names, as nextly.config.ts declares it. */
11
+ export type DevAutoLogin = false | { email: string; password?: string };
12
+
13
+ /** Creates a super-admin, skipping one that already exists. */
14
+ export type SeedSuperAdmin = (options: {
15
+ email: string;
16
+ password: string;
17
+ name: string;
18
+ silent: boolean;
19
+ }) => Promise<{ success: boolean; errorMessages?: string[] }>;
20
+
21
+ export async function seedDevUser(
22
+ login: DevAutoLogin | undefined,
23
+ seed: SeedSuperAdmin
24
+ ): Promise<void> {
25
+ // `next dev` only: no credentials in a production build, and tests bring
26
+ // their own fixtures.
27
+ if (process.env.NODE_ENV !== "development" || !login) return;
28
+
29
+ // Auto-login needs no password, but creating the account does.
30
+ if (!login.password) {
31
+ console.warn(
32
+ `[dev] admin.devAutoLogin names ${login.email} without a password, so that user is not created.`
33
+ );
34
+ return;
35
+ }
36
+
37
+ const result = await seed({
38
+ email: login.email,
39
+ password: login.password,
40
+ name: "Dev User",
41
+ silent: true,
42
+ });
43
+ if (!result.success) {
44
+ // Otherwise the only sign is the setup wizard, with nothing saying why.
45
+ console.warn(
46
+ `[dev] Could not create the auto-login user ${login.email}: ${
47
+ result.errorMessages?.join("; ") ?? "unknown error"
48
+ }`
49
+ );
50
+ }
51
+ }
@@ -4,7 +4,10 @@ dist
4
4
 
5
5
  # Embedded dev playground — never published, never committed build output
6
6
  dev/.next
7
- dev/*.db
8
- dev/*.db-journal
7
+ # SQLite files, and the journal and WAL files beside them, wherever they land.
8
+ *.db
9
+ *.db-journal
10
+ *.db-wal
11
+ *.db-shm
9
12
  .env
10
13
  .env.local
@@ -20,9 +20,16 @@ afterEach(async () => {
20
20
  it("boots and exposes the plugin's example collection (real table)", async () => {
21
21
  // Creating an entry proves the contributed collection got a real table and
22
22
  // the plugin's lifecycle ran. Replace with assertions for your own behavior.
23
- const created = await t.nextly.create("examples", { title: "First example" });
23
+ // The Direct API takes one argument object per call.
24
+ const created = await t.nextly.create({
25
+ collection: "examples",
26
+ data: { title: "First example" },
27
+ });
24
28
  expect(created.item.id).toBeDefined();
25
29
 
26
- const fetched = await t.nextly.findById("examples", created.item.id);
30
+ const fetched = await t.nextly.findByID({
31
+ collection: "examples",
32
+ id: String(created.item.id),
33
+ });
27
34
  expect(fetched?.title).toBe("First example");
28
35
  });