@heychunky/core 0.22.0 → 0.24.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.
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * `register.ts` is deliberately absent. It reads the register's migrations off
8
8
  * disk, and `new URL("../../register/", import.meta.url)` is an asset reference
9
- * a bundler resolves statically — so re-exporting it here broke heychunky-app's
9
+ * a bundler resolves statically — so re-exporting it here broke heychunky-console's
10
10
  * build, which does import this barrel. It has its own subpath,
11
11
  * `@heychunky/core/register`, for the CLI and the worker. Nothing that serves a
12
12
  * request migrates the register's schema, so nothing that serves a request
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * `register.ts` is deliberately absent. It reads the register's migrations off
8
8
  * disk, and `new URL("../../register/", import.meta.url)` is an asset reference
9
- * a bundler resolves statically — so re-exporting it here broke heychunky-app's
9
+ * a bundler resolves statically — so re-exporting it here broke heychunky-console's
10
10
  * build, which does import this barrel. It has its own subpath,
11
11
  * `@heychunky/core/register`, for the CLI and the worker. Nothing that serves a
12
12
  * request migrates the register's schema, so nothing that serves a request
@@ -2,7 +2,7 @@
2
2
  * The database that holds the register — who exists, and what they own.
3
3
  *
4
4
  * Passed in rather than named here. This module used to hardcode
5
- * heychunky-app's production database, which made every register function
5
+ * heychunky-console's production database, which made every register function
6
6
  * reach past whatever environment its caller was running in: an API serving
7
7
  * its dev database looked up users in production and did not find them.
8
8
  *
@@ -15,12 +15,12 @@ import type { RunContext } from "./run.ts";
15
15
  /** What the register needs of a database. Satisfied by `db()`. */
16
16
  export type Register = Pick<ReturnType<typeof db>, "query" | "write">;
17
17
  /**
18
- * The factory's own register: heychunky-app in production.
18
+ * The factory's own register: heychunky-console in production.
19
19
  *
20
20
  * One register for the operator side, because a developer's laptop and the
21
21
  * worker must not each have their own idea of what exists. An app running in
22
22
  * dev is a different case and passes its own.
23
23
  */
24
- export declare const FACTORY_REGISTER = "infisical://heychunky-apps/production/heychunky-app/DATABASE_URL";
24
+ export declare const FACTORY_REGISTER = "infisical://heychunky-apps/production/heychunky-console/DATABASE_URL";
25
25
  export declare const factoryRegister: (ctx: RunContext) => Promise<Register>;
26
26
  //# sourceMappingURL=master.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"master.d.ts","sourceRoot":"","sources":["../../src/admin/master.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,kEAAkE;AAClE,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,qEACuC,CAAC;AAErE,eAAO,MAAM,eAAe,GAAU,KAAK,UAAU,KAAG,OAAO,CAAC,QAAQ,CAC3B,CAAC"}
1
+ {"version":3,"file":"master.d.ts","sourceRoot":"","sources":["../../src/admin/master.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,kEAAkE;AAClE,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,yEAC2C,CAAC;AAEzE,eAAO,MAAM,eAAe,GAAU,KAAK,UAAU,KAAG,OAAO,CAAC,QAAQ,CAC3B,CAAC"}
@@ -2,7 +2,7 @@
2
2
  * The database that holds the register — who exists, and what they own.
3
3
  *
4
4
  * Passed in rather than named here. This module used to hardcode
5
- * heychunky-app's production database, which made every register function
5
+ * heychunky-console's production database, which made every register function
6
6
  * reach past whatever environment its caller was running in: an API serving
7
7
  * its dev database looked up users in production and did not find them.
8
8
  *
@@ -12,12 +12,12 @@
12
12
  */
13
13
  import { db } from "../services/db.js";
14
14
  /**
15
- * The factory's own register: heychunky-app in production.
15
+ * The factory's own register: heychunky-console in production.
16
16
  *
17
17
  * One register for the operator side, because a developer's laptop and the
18
18
  * worker must not each have their own idea of what exists. An app running in
19
19
  * dev is a different case and passes its own.
20
20
  */
21
- export const FACTORY_REGISTER = "infisical://heychunky-apps/production/heychunky-app/DATABASE_URL";
21
+ export const FACTORY_REGISTER = "infisical://heychunky-apps/production/heychunky-console/DATABASE_URL";
22
22
  export const factoryRegister = async (ctx) => db(await ctx.secrets.get(FACTORY_REGISTER));
23
23
  //# sourceMappingURL=master.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"master.js","sourceRoot":"","sources":["../../src/admin/master.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAMvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,kEAAkE,CAAC;AAErE,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,GAAe,EAAqB,EAAE,CAC1E,EAAE,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"master.js","sourceRoot":"","sources":["../../src/admin/master.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAMvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,sEAAsE,CAAC;AAEzE,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,GAAe,EAAqB,EAAE,CAC1E,EAAE,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC"}
@@ -1 +1 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AAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,GAAG,CAAC,CAiCd;AAED,oEAAoE;AACpE,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvF;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAmG/D,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;CACb;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAQ3E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,GAAG,CAAC,CAsBd;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAS1B"}
@@ -103,6 +103,10 @@ export async function claimPersonalOrg(userId, username, register) {
103
103
  throw new OrgNameTakenError(username);
104
104
  await register.write(`insert into org_members (org_id, user_id, role) values ($1, $2, 'admin')
105
105
  on conflict (org_id, user_id) do nothing`, [org.id, userId]);
106
+ // And the pointer, which is what makes this *theirs* rather than one of
107
+ // three facts that happen to agree. Written last, so it is only ever set
108
+ // for an organisation that exists and has them in it.
109
+ await register.write("update users set personal_org_id = $2 where id = $1 and personal_org_id is null", [userId, org.id]);
106
110
  return org;
107
111
  }
108
112
  /** The organisations this person belongs to, personal one first. */
@@ -146,6 +150,26 @@ export const ORG_CHECKS = [
146
150
  and not exists (select 1 from orgs o
147
151
  where lower(o.name) = lower(u.username) and o.kind = 'personal')`,
148
152
  },
153
+ {
154
+ /**
155
+ * The pointer and the membership have to agree.
156
+ *
157
+ * `users.personal_org_id` is the fact now; a membership row and the
158
+ * matching name are what it replaced. A pointer to an organisation the
159
+ * person is not in is one nobody could have reached anyway, and the only
160
+ * way to make one is to write the column by hand.
161
+ */
162
+ check: "people pointed at an organisation they are not a member of",
163
+ sql: `select count(*) as n from users u
164
+ where u.personal_org_id is not null
165
+ and not exists (select 1 from org_members m
166
+ where m.org_id = u.personal_org_id and m.user_id = u.id)`,
167
+ },
168
+ {
169
+ check: "people with a username and no personal organisation recorded",
170
+ sql: `select count(*) as n from users u
171
+ where u.username is not null and u.personal_org_id is null`,
172
+ },
149
173
  {
150
174
  check: "personal organisations whose name is nobody's username",
151
175
  sql: `select count(*) as n from orgs o where o.kind = 'personal'
@@ -278,8 +302,10 @@ export async function createOrg(name, founder, register) {
278
302
  * exists before its owner has chosen what to be called.
279
303
  */
280
304
  export async function personalOrgFor(userId, register) {
281
- const { rows } = await register.query(`select o.* from orgs o join users u on lower(u.username) = lower(o.name)
282
- where u.id = $1 and o.kind = 'personal'`, [userId]);
305
+ // One hop, on a foreign key. It used to join on the username matching the
306
+ // organisation's name, which was true by convention and unenforceable —
307
+ // and silently wrong for anybody mid-rename.
308
+ const { rows } = await register.query("select o.* from orgs o join users u on u.personal_org_id = o.id where u.id = $1", [userId]);
283
309
  return rows[0];
284
310
  }
285
311
  //# sourceMappingURL=orgs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"org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AAC,EAAE,EAAE,OAAO,CAAC,CAClB,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAc,EACd,QAAkB;IAElB,0EAA0E;IAC1E,wEAAwE;IACxE,6CAA6C;IAC7C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,KAAK,CACnC,iFAAiF,EACjF,CAAC,MAAM,CAAC,CACT,CAAC;IACF,OAAO,IAAI,CAAC,CAAC,CAA+B,CAAC;AAC/C,CAAC"}
@@ -35,7 +35,7 @@
35
35
  *
36
36
  * **Reached as `@heychunky/core/register`, not through the admin barrel.** The
37
37
  * directory read below is an asset reference that a bundler resolves at build
38
- * time, and heychunky-app imports `@heychunky/core/admin` — so exporting this
38
+ * time, and heychunky-console imports `@heychunky/core/admin` — so exporting this
39
39
  * from there failed the app's build with `Can't resolve '../../register/'`. Its
40
40
  * own subpath is the honest boundary rather than a workaround: an app never
41
41
  * migrates the register's schema, and the exports map is where this package
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heychunky/core",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "The engine the Chunky CLI, worker and apps run on.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,18 @@
1
+ -- Which organisation is this person's own.
2
+ --
3
+ -- Until now that was three facts that had to agree: a membership row, the
4
+ -- organisation's `kind`, and its name matching the username. Nothing enforced
5
+ -- the set — `register verify` counted the disagreements afterwards, and has
6
+ -- caught drift more than once.
7
+ --
8
+ -- A column, foreign-keyed. Not a shared primary key: an organisation outlives
9
+ -- the people in it (`org_members` cascades, `orgs` does not), so an id that
10
+ -- named a deleted person would make that a contradiction rather than a
11
+ -- decision. And a team could never share one, so half the rows would carry a
12
+ -- shortcut the other half could not — which is how somebody writes a join
13
+ -- that passes in testing and is wrong in production.
14
+ --
15
+ -- `on delete set null` because deleting an organisation is a decision about
16
+ -- the organisation; it must not take the person with it, and it must not be
17
+ -- blocked by them either.
18
+ alter table users add column personal_org_id uuid references orgs(id) on delete set null;
@@ -0,0 +1,3 @@
1
+ -- One personal organisation each, and one person each. The 1:1 the product
2
+ -- has always assumed, said by the database rather than by three conventions.
3
+ create unique index users_personal_org_unique on users (personal_org_id) where personal_org_id is not null;
@@ -0,0 +1,9 @@
1
+ -- Every person who already has one, matched the way the code has been
2
+ -- matching: their username is the organisation's name, and it is personal.
3
+ -- Safe to run twice; touches only rows still without a pointer.
4
+ update users u set personal_org_id = o.id
5
+ from orgs o
6
+ where u.personal_org_id is null
7
+ and u.username is not null
8
+ and o.kind = 'personal'
9
+ and lower(o.name) = lower(u.username);
@@ -31,7 +31,7 @@ heychunky register verify what must be true of the rows
31
31
  ```
32
32
 
33
33
  All four take `--app <app> --env <environment>` to reach a register other than
34
- the factory's own. There is more than one: heychunky-app runs in six
34
+ the factory's own. There is more than one: heychunky-console runs in six
35
35
  environments and each has a database of this shape, which is how the schema
36
36
  reaches the one the tests and the dev deployment use.
37
37