@x12i/keyrox-store-pg 0.0.0-stage → 0.1.1

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.
Files changed (88) hide show
  1. package/dist/database.d.ts +10 -0
  2. package/dist/database.d.ts.map +1 -0
  3. package/dist/database.js +28 -0
  4. package/dist/database.js.map +1 -0
  5. package/dist/directory-access-sql.d.ts +12 -0
  6. package/dist/directory-access-sql.d.ts.map +1 -0
  7. package/dist/directory-access-sql.js +253 -0
  8. package/dist/directory-access-sql.js.map +1 -0
  9. package/dist/directory-sql.d.ts +8 -0
  10. package/dist/directory-sql.d.ts.map +1 -0
  11. package/dist/directory-sql.js +1052 -0
  12. package/dist/directory-sql.js.map +1 -0
  13. package/dist/hosted-human-sessions.d.ts +5 -0
  14. package/dist/hosted-human-sessions.d.ts.map +1 -0
  15. package/dist/hosted-human-sessions.js +105 -0
  16. package/dist/hosted-human-sessions.js.map +1 -0
  17. package/dist/index.d.ts +21 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +59 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/migrate.d.ts +4 -0
  22. package/dist/migrate.d.ts.map +1 -0
  23. package/dist/migrate.js +51 -0
  24. package/dist/migrate.js.map +1 -0
  25. package/dist/notification-deliveries.d.ts +5 -0
  26. package/dist/notification-deliveries.d.ts.map +1 -0
  27. package/dist/notification-deliveries.js +81 -0
  28. package/dist/notification-deliveries.js.map +1 -0
  29. package/dist/notification-webhook-sql.d.ts +4 -0
  30. package/dist/notification-webhook-sql.d.ts.map +1 -0
  31. package/dist/notification-webhook-sql.js +109 -0
  32. package/dist/notification-webhook-sql.js.map +1 -0
  33. package/dist/rows.d.ts +54 -0
  34. package/dist/rows.d.ts.map +1 -0
  35. package/dist/rows.js +426 -0
  36. package/dist/rows.js.map +1 -0
  37. package/dist/sql-store.d.ts +4 -0
  38. package/dist/sql-store.d.ts.map +1 -0
  39. package/dist/sql-store.js +1350 -0
  40. package/dist/sql-store.js.map +1 -0
  41. package/migrations/001_init.sql +260 -0
  42. package/migrations/002_apps.sql +36 -0
  43. package/migrations/003_environments.sql +46 -0
  44. package/migrations/004_sso.sql +62 -0
  45. package/migrations/005_workloads.sql +64 -0
  46. package/migrations/006_directory.sql +155 -0
  47. package/migrations/007_account_sso.sql +40 -0
  48. package/migrations/008_app_sign_in.sql +26 -0
  49. package/migrations/009_account_sso_next.sql +4 -0
  50. package/migrations/010_account_sso_profile.sql +14 -0
  51. package/migrations/011_hosted_sso_profiles.sql +26 -0
  52. package/migrations/012_app_signup_roles.sql +2 -0
  53. package/migrations/013_product_role_catalog.sql +14 -0
  54. package/migrations/014_application_staff_access.sql +21 -0
  55. package/migrations/015_audit_service_actor.sql +7 -0
  56. package/migrations/016_app_waitlist_questions.sql +2 -0
  57. package/migrations/017_app_signup_policy.sql +9 -0
  58. package/migrations/018_managed_app_sign_in.sql +8 -0
  59. package/migrations/019_hosted_sso_email_proofs.sql +12 -0
  60. package/migrations/020_cli_login_codes.sql +15 -0
  61. package/migrations/021_hosted_email_codes.sql +18 -0
  62. package/migrations/022_sso_waitlist_callback.sql +3 -0
  63. package/migrations/023_app_email_code_sign_in.sql +1 -0
  64. package/migrations/024_hosted_auth_copy.sql +2 -0
  65. package/migrations/025_app_directory_workspaces.sql +55 -0
  66. package/migrations/027_role_features_and_configuration.sql +17 -0
  67. package/migrations/028_sso_only_signup_audience.sql +4 -0
  68. package/migrations/029_people_only_directory_model.sql +3 -0
  69. package/migrations/030_typed_questionnaires.sql +3 -0
  70. package/migrations/031_app_notifications.sql +22 -0
  71. package/migrations/032_agent_grant_duration.sql +10 -0
  72. package/migrations/033_application_lifecycle.sql +67 -0
  73. package/migrations/034_notification_deliveries.sql +25 -0
  74. package/migrations/035_app_notification_webhook_jobs.sql +28 -0
  75. package/migrations/036_account_notification_recovery.sql +11 -0
  76. package/migrations/037_waitlist_confirmation.sql +7 -0
  77. package/migrations/039_hosted_human_sessions.sql +45 -0
  78. package/migrations/040_hosted_human_clients.sql +35 -0
  79. package/migrations/041_app_workspace_invitations.sql +9 -0
  80. package/migrations/042_directory_email_proof.sql +16 -0
  81. package/migrations/043_sso_exchange_redirect_uri.sql +1 -0
  82. package/migrations/044_repair_app_sign_in_connections.sql +30 -0
  83. package/migrations/045_directory_integrity.sql +140 -0
  84. package/migrations/046_person_email_across_organizations.sql +7 -0
  85. package/migrations/047_owner_access.sql +35 -0
  86. package/migrations/048_invitation_links.sql +28 -0
  87. package/package.json +36 -4
  88. package/README.md +0 -3
@@ -0,0 +1,11 @@
1
+ ALTER TABLE invites ADD COLUMN revoked_at timestamptz;
2
+ ALTER TABLE invites ADD COLUMN last_mail_requested_at timestamptz;
3
+
4
+ CREATE INDEX invites_open_by_org ON invites (org_id, created_at DESC, id COLLATE "C" DESC)
5
+ WHERE accepted_at IS NULL AND revoked_at IS NULL;
6
+
7
+ CREATE INDEX invites_open_by_recipient ON invites (org_id, lower(email), expires_at)
8
+ WHERE accepted_at IS NULL AND revoked_at IS NULL;
9
+
10
+ CREATE INDEX email_challenges_by_account_and_purpose
11
+ ON email_challenges (user_id, purpose, created_at DESC);
@@ -0,0 +1,7 @@
1
+ ALTER TABLE platform_waitlist ADD COLUMN confirmation_pending boolean NOT NULL DEFAULT false;
2
+ ALTER TABLE platform_waitlist ADD COLUMN confirmation_claimed_at timestamptz;
3
+
4
+ ALTER TABLE app_waitlist ADD COLUMN confirmation_pending boolean NOT NULL DEFAULT false;
5
+ ALTER TABLE app_waitlist ADD COLUMN confirmation_claimed_at timestamptz;
6
+
7
+ CREATE INDEX directory_challenges_recovery_idx ON directory_challenges (environment_id, identity_id, purpose, created_at DESC);
@@ -0,0 +1,45 @@
1
+ CREATE TABLE hosted_human_sessions (
2
+ id text PRIMARY KEY,
3
+ client_id text NOT NULL,
4
+ app_id text NOT NULL,
5
+ environment_id text NOT NULL,
6
+ subject_id text NOT NULL,
7
+ organization_id text,
8
+ workspace_id text,
9
+ audience text NOT NULL,
10
+ created_at timestamptz NOT NULL,
11
+ expires_at timestamptz NOT NULL CHECK (expires_at > created_at),
12
+ revoked_at timestamptz CHECK (revoked_at >= created_at),
13
+ CHECK (organization_id IS NOT NULL OR workspace_id IS NOT NULL),
14
+ FOREIGN KEY (app_id, environment_id) REFERENCES app_environments (app_id, id) ON DELETE CASCADE,
15
+ FOREIGN KEY (environment_id, subject_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE,
16
+ FOREIGN KEY (environment_id, organization_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE,
17
+ FOREIGN KEY (environment_id, workspace_id) REFERENCES app_workspaces (environment_id, id) ON DELETE CASCADE
18
+ );
19
+
20
+ CREATE INDEX hosted_human_sessions_environment_idx ON hosted_human_sessions (environment_id);
21
+ CREATE INDEX hosted_human_sessions_expiry_idx ON hosted_human_sessions (expires_at);
22
+
23
+ CREATE TABLE hosted_human_refresh_tokens (
24
+ token_hash text PRIMARY KEY,
25
+ session_id text NOT NULL REFERENCES hosted_human_sessions(id) ON DELETE CASCADE,
26
+ used_at timestamptz
27
+ );
28
+
29
+ CREATE INDEX hosted_human_refresh_tokens_session_idx ON hosted_human_refresh_tokens (session_id);
30
+ CREATE UNIQUE INDEX hosted_human_refresh_tokens_active_idx ON hosted_human_refresh_tokens (session_id) WHERE used_at IS NULL;
31
+
32
+ CREATE TABLE hosted_human_selections (
33
+ token_hash text PRIMARY KEY,
34
+ client_id text NOT NULL,
35
+ app_id text NOT NULL,
36
+ environment_id text NOT NULL,
37
+ subject_id text NOT NULL,
38
+ created_at timestamptz NOT NULL,
39
+ expires_at timestamptz NOT NULL CHECK (expires_at > created_at),
40
+ FOREIGN KEY (app_id, environment_id) REFERENCES app_environments (app_id, id) ON DELETE CASCADE,
41
+ FOREIGN KEY (environment_id, subject_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE
42
+ );
43
+
44
+ CREATE INDEX hosted_human_selections_environment_idx ON hosted_human_selections (environment_id);
45
+ CREATE INDEX hosted_human_selections_expiry_idx ON hosted_human_selections (expires_at);
@@ -0,0 +1,35 @@
1
+ CREATE TABLE hosted_human_clients (
2
+ id text PRIMARY KEY,
3
+ app_id text NOT NULL REFERENCES applications (id) ON DELETE CASCADE,
4
+ environment_id text NOT NULL REFERENCES app_environments (id) ON DELETE CASCADE,
5
+ org_id text NOT NULL,
6
+ name text NOT NULL,
7
+ redirect_uri text NOT NULL,
8
+ audience text NOT NULL,
9
+ secret_hash text NOT NULL CHECK (secret_hash ~ '^[0-9a-f]{64}$'),
10
+ created_at timestamptz NOT NULL,
11
+ revoked_at timestamptz
12
+ );
13
+
14
+ CREATE INDEX hosted_human_clients_scope_idx ON hosted_human_clients (app_id, environment_id);
15
+
16
+ CREATE TABLE hosted_human_codes (
17
+ code_hash text PRIMARY KEY CHECK (code_hash ~ '^[0-9a-f]{64}$'),
18
+ client_id text NOT NULL REFERENCES hosted_human_clients (id) ON DELETE CASCADE,
19
+ app_id text NOT NULL REFERENCES applications (id) ON DELETE CASCADE,
20
+ environment_id text NOT NULL REFERENCES app_environments (id) ON DELETE CASCADE,
21
+ org_id text NOT NULL,
22
+ redirect_uri text NOT NULL,
23
+ code_challenge text NOT NULL CHECK (code_challenge ~ '^[A-Za-z0-9_-]{43}$'),
24
+ identity_id text NOT NULL REFERENCES app_identities (id) ON DELETE CASCADE,
25
+ provider text NOT NULL,
26
+ created_at timestamptz NOT NULL,
27
+ expires_at timestamptz NOT NULL CHECK (expires_at > created_at)
28
+ );
29
+
30
+ CREATE INDEX hosted_human_codes_expiry_idx ON hosted_human_codes (expires_at);
31
+ CREATE INDEX hosted_human_codes_app_idx ON hosted_human_codes (app_id);
32
+ CREATE INDEX hosted_human_codes_client_idx ON hosted_human_codes (client_id);
33
+
34
+ ALTER TABLE sso_logins ADD COLUMN human_binding jsonb;
35
+ ALTER TABLE hosted_sso_profiles ADD COLUMN human_binding jsonb;
@@ -0,0 +1,9 @@
1
+ ALTER TABLE app_waitlist
2
+ ADD COLUMN invitation_workspace_id text,
3
+ ADD COLUMN invitation_role_id text,
4
+ ADD COLUMN pending_workspace_identity_id text,
5
+ ADD CHECK ((invitation_workspace_id IS NULL) = (invitation_role_id IS NULL)),
6
+ ADD CHECK (pending_workspace_identity_id IS NULL OR (status = 'invited' AND invitation_workspace_id IS NOT NULL));
7
+
8
+ ALTER TABLE app_workspace_memberships
9
+ ADD COLUMN role_id text REFERENCES app_product_roles (id) ON DELETE SET NULL;
@@ -0,0 +1,16 @@
1
+ ALTER TABLE app_identities
2
+ ADD COLUMN email_proof_at timestamptz,
3
+ ADD CHECK (email_proof_at IS NULL OR (kind = 'user' AND email IS NOT NULL AND email_verified_at IS NOT NULL));
4
+
5
+ UPDATE app_identities AS identity
6
+ SET email_proof_at = identity.email_verified_at
7
+ WHERE identity.kind = 'user' AND identity.email IS NOT NULL AND identity.email_verified_at IS NOT NULL
8
+ AND EXISTS (
9
+ SELECT 1 FROM directory_challenges AS challenge
10
+ WHERE challenge.identity_id = identity.id
11
+ AND challenge.environment_id = identity.environment_id
12
+ AND lower(challenge.email) = lower(identity.email)
13
+ AND challenge.purpose = 'verify'
14
+ AND challenge.used_at = identity.email_verified_at
15
+ AND challenge.used_at < challenge.expires_at
16
+ );
@@ -0,0 +1 @@
1
+ ALTER TABLE sso_exchanges ADD COLUMN redirect_uri text;
@@ -0,0 +1,30 @@
1
+ -- Some databases recorded migration 008 without the application provider table.
2
+ -- Keep existing provider connections in place and only restore legacy links when the table is missing.
3
+ CREATE TEMP TABLE keyrox_app_sign_in_repair ON COMMIT DROP AS
4
+ SELECT to_regclass('app_sign_in_connections') IS NULL AS table_was_missing;
5
+
6
+ CREATE TABLE IF NOT EXISTS app_sign_in_connections (
7
+ id text PRIMARY KEY,
8
+ app_id text NOT NULL REFERENCES applications (id) ON DELETE CASCADE,
9
+ provider text NOT NULL,
10
+ client_id text NOT NULL,
11
+ client_secret_enc text NOT NULL,
12
+ directory_id text,
13
+ issuer text,
14
+ created_at timestamptz NOT NULL,
15
+ legacy_connection_id text,
16
+ UNIQUE (app_id, provider)
17
+ );
18
+
19
+ INSERT INTO app_sign_in_connections (
20
+ id, app_id, provider, client_id, client_secret_enc, directory_id, issuer, created_at, legacy_connection_id
21
+ )
22
+ SELECT
23
+ concat('sic_migrated_', length(connection.id), ':', connection.id, ':', application.id),
24
+ application.id, connection.provider, connection.client_id, connection.client_secret_enc,
25
+ connection.directory_id, connection.issuer, connection.created_at, connection.id
26
+ FROM sign_in_connections AS connection
27
+ JOIN applications AS application ON application.org_id = connection.org_id
28
+ JOIN app_sign_in AS settings ON settings.app_id = application.id AND connection.provider = ANY(settings.providers)
29
+ CROSS JOIN pg_temp.keyrox_app_sign_in_repair AS repair
30
+ WHERE repair.table_was_missing;
@@ -0,0 +1,140 @@
1
+ -- Check directory relationships that were previously recorded without validating existing rows.
2
+ ALTER TABLE app_permissions VALIDATE CONSTRAINT app_permissions_environment_id_fkey;
3
+ ALTER TABLE app_product_roles VALIDATE CONSTRAINT app_product_roles_environment_id_fkey;
4
+ ALTER TABLE app_groups VALIDATE CONSTRAINT app_groups_environment_id_fkey;
5
+ ALTER TABLE app_role_bindings VALIDATE CONSTRAINT app_role_bindings_environment_id_fkey;
6
+ ALTER TABLE app_features VALIDATE CONSTRAINT app_features_environment_id_fkey;
7
+ ALTER TABLE app_waitlist VALIDATE CONSTRAINT app_waitlist_environment_id_fkey;
8
+
9
+ ALTER TABLE app_identities
10
+ ADD COLUMN organization_key text GENERATED ALWAYS AS (CASE WHEN kind = 'organization' THEN id END) STORED;
11
+ ALTER TABLE app_identities
12
+ ADD CONSTRAINT app_identities_environment_organization_key UNIQUE (environment_id, organization_key);
13
+
14
+ ALTER TABLE app_identity_memberships
15
+ ADD CONSTRAINT app_identity_memberships_relation_check CHECK (relation IN ('owner', 'member'));
16
+ ALTER TABLE app_identity_memberships
17
+ ADD CONSTRAINT app_identity_memberships_environment_identity_fkey
18
+ FOREIGN KEY (environment_id, identity_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE;
19
+ ALTER TABLE app_identity_memberships
20
+ ADD CONSTRAINT app_identity_memberships_environment_organization_fkey
21
+ FOREIGN KEY (environment_id, organization_id) REFERENCES app_identities (environment_id, organization_key) ON DELETE CASCADE;
22
+
23
+ -- A directory model that includes organizations gives every person an organization.
24
+ -- A model that includes workspaces gives every person a workspace under that organization when one is required.
25
+ WITH missing AS (
26
+ SELECT
27
+ 'idn_' || rtrim(translate(encode(decode(replace(gen_random_uuid()::text, '-', ''), 'hex'), 'base64'), '+/', '-_'), '=') AS organization_id,
28
+ 'dms_' || rtrim(translate(encode(decode(replace(gen_random_uuid()::text, '-', ''), 'hex'), 'base64'), '+/', '-_'), '=') AS membership_id,
29
+ person.app_id,
30
+ person.environment_id,
31
+ person.org_id,
32
+ person.id AS identity_id,
33
+ person.display_name
34
+ FROM app_identities AS person
35
+ JOIN applications AS application ON application.id = person.app_id AND application.trashed_at IS NULL
36
+ WHERE person.kind IN ('user', 'account')
37
+ AND application.directory_model IN ('organizations', 'organizations-and-workspaces')
38
+ AND length(btrim(person.display_name)) > 0
39
+ AND NOT EXISTS (
40
+ SELECT 1 FROM app_identity_memberships AS membership
41
+ WHERE membership.environment_id = person.environment_id AND membership.identity_id = person.id
42
+ )
43
+ ),
44
+ created AS (
45
+ INSERT INTO app_identities (
46
+ id, app_id, environment_id, org_id, kind, email, password_hash, display_name, status,
47
+ email_verified_at, metadata, created_at, updated_at, email_proof_at
48
+ )
49
+ SELECT organization_id, app_id, environment_id, org_id, 'organization', NULL, NULL, display_name, 'active',
50
+ NULL, '{}'::jsonb, now(), now(), NULL
51
+ FROM missing
52
+ RETURNING id
53
+ )
54
+ INSERT INTO app_identity_memberships (id, environment_id, identity_id, organization_id, relation, created_at)
55
+ SELECT membership_id, environment_id, identity_id, organization_id, 'owner', now()
56
+ FROM missing
57
+ WHERE EXISTS (SELECT 1 FROM created);
58
+
59
+ WITH missing AS (
60
+ SELECT
61
+ 'idn_' || rtrim(translate(encode(decode(replace(gen_random_uuid()::text, '-', ''), 'hex'), 'base64'), '+/', '-_'), '=') AS organization_id,
62
+ workspace.id AS workspace_id,
63
+ workspace.environment_id,
64
+ workspace.app_id,
65
+ application.org_id,
66
+ workspace.name AS display_name
67
+ FROM app_workspaces AS workspace
68
+ JOIN applications AS application ON application.id = workspace.app_id AND application.trashed_at IS NULL
69
+ WHERE application.directory_model = 'organizations-and-workspaces' AND workspace.organization_id IS NULL
70
+ ),
71
+ created AS (
72
+ INSERT INTO app_identities (
73
+ id, app_id, environment_id, org_id, kind, email, password_hash, display_name, status,
74
+ email_verified_at, metadata, created_at, updated_at, email_proof_at
75
+ )
76
+ SELECT organization_id, app_id, environment_id, org_id, 'organization', NULL, NULL, display_name, 'active',
77
+ NULL, '{}'::jsonb, now(), now(), NULL
78
+ FROM missing
79
+ RETURNING id
80
+ ),
81
+ owners AS (
82
+ INSERT INTO app_identity_memberships (id, environment_id, identity_id, organization_id, relation, created_at)
83
+ SELECT
84
+ 'dms_' || rtrim(translate(encode(decode(replace(gen_random_uuid()::text, '-', ''), 'hex'), 'base64'), '+/', '-_'), '='),
85
+ missing.environment_id, owner.identity_id, missing.organization_id, 'member', now()
86
+ FROM missing
87
+ JOIN app_workspace_memberships AS owner
88
+ ON owner.environment_id = missing.environment_id AND owner.workspace_id = missing.workspace_id AND owner.relation = 'owner'
89
+ WHERE NOT EXISTS (
90
+ SELECT 1 FROM app_identity_memberships AS membership
91
+ WHERE membership.environment_id = missing.environment_id
92
+ AND membership.identity_id = owner.identity_id
93
+ AND membership.organization_id = missing.organization_id
94
+ )
95
+ RETURNING id
96
+ )
97
+ UPDATE app_workspaces AS workspace
98
+ SET organization_id = missing.organization_id, updated_at = now()
99
+ FROM missing
100
+ WHERE workspace.id = missing.workspace_id AND workspace.environment_id = missing.environment_id
101
+ AND (SELECT count(*) FROM created) >= 0
102
+ AND (SELECT count(*) FROM owners) >= 0;
103
+
104
+ WITH missing AS (
105
+ SELECT
106
+ 'wsp_' || rtrim(translate(encode(decode(replace(gen_random_uuid()::text, '-', ''), 'hex'), 'base64'), '+/', '-_'), '=') AS workspace_id,
107
+ 'wsm_' || rtrim(translate(encode(decode(replace(gen_random_uuid()::text, '-', ''), 'hex'), 'base64'), '+/', '-_'), '=') AS membership_id,
108
+ person.app_id,
109
+ person.environment_id,
110
+ parent.organization_id,
111
+ person.id AS identity_id,
112
+ person.display_name
113
+ FROM app_identities AS person
114
+ JOIN applications AS application ON application.id = person.app_id AND application.trashed_at IS NULL
115
+ LEFT JOIN LATERAL (
116
+ SELECT membership.organization_id
117
+ FROM app_identity_memberships AS membership
118
+ WHERE membership.environment_id = person.environment_id AND membership.identity_id = person.id
119
+ ORDER BY membership.created_at, membership.id
120
+ LIMIT 1
121
+ ) AS parent ON application.directory_model = 'organizations-and-workspaces'
122
+ WHERE person.kind IN ('user', 'account')
123
+ AND application.directory_model IN ('workspaces', 'organizations-and-workspaces')
124
+ AND length(btrim(person.display_name)) > 0
125
+ AND NOT EXISTS (
126
+ SELECT 1 FROM app_workspace_memberships AS membership
127
+ WHERE membership.environment_id = person.environment_id AND membership.identity_id = person.id
128
+ )
129
+ AND (application.directory_model = 'workspaces' OR parent.organization_id IS NOT NULL)
130
+ ),
131
+ created AS (
132
+ INSERT INTO app_workspaces (id, app_id, environment_id, organization_id, name, status, created_at, updated_at)
133
+ SELECT workspace_id, app_id, environment_id, organization_id, display_name, 'active', now(), now()
134
+ FROM missing
135
+ RETURNING id
136
+ )
137
+ INSERT INTO app_workspace_memberships (id, environment_id, workspace_id, identity_id, relation, created_at)
138
+ SELECT membership_id, environment_id, workspace_id, identity_id, 'owner', now()
139
+ FROM missing
140
+ WHERE EXISTS (SELECT 1 FROM created);
@@ -0,0 +1,7 @@
1
+ -- An organization contact address is not a sign-in identity. One person can belong to
2
+ -- many organizations, and those organizations may keep that same contact email.
3
+ DROP INDEX IF EXISTS app_identities_email_idx;
4
+
5
+ CREATE UNIQUE INDEX app_identities_signin_email_idx
6
+ ON app_identities (environment_id, lower(email))
7
+ WHERE email IS NOT NULL AND kind <> 'organization';
@@ -0,0 +1,35 @@
1
+ ALTER TABLE app_product_roles ADD COLUMN owner_access boolean NOT NULL DEFAULT false;
2
+
3
+ CREATE UNIQUE INDEX app_product_roles_owner_access_idx ON app_product_roles (environment_id) WHERE owner_access;
4
+
5
+ CREATE TABLE app_access_checks (
6
+ id text PRIMARY KEY,
7
+ environment_id text NOT NULL,
8
+ client_id text NOT NULL,
9
+ identity_id text NOT NULL,
10
+ workspace_id text,
11
+ organization_id text,
12
+ role_id text NOT NULL,
13
+ reference text NOT NULL,
14
+ audit_id text NOT NULL,
15
+ created_at timestamptz NOT NULL,
16
+ FOREIGN KEY (environment_id, identity_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE,
17
+ FOREIGN KEY (environment_id, workspace_id) REFERENCES app_workspaces (environment_id, id) ON DELETE CASCADE,
18
+ FOREIGN KEY (environment_id, organization_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE
19
+ );
20
+
21
+ CREATE INDEX app_access_checks_scope_idx ON app_access_checks (environment_id, identity_id);
22
+
23
+ DO $$
24
+ DECLARE
25
+ constraint_name text;
26
+ BEGIN
27
+ SELECT con.conname INTO constraint_name
28
+ FROM pg_constraint con
29
+ JOIN pg_class rel ON rel.oid = con.conrelid
30
+ WHERE rel.relname = 'hosted_human_sessions' AND con.contype = 'c'
31
+ AND pg_get_constraintdef(con.oid) ILIKE '%organization_id IS NOT NULL%workspace_id IS NOT NULL%';
32
+ IF constraint_name IS NOT NULL THEN
33
+ EXECUTE format('ALTER TABLE hosted_human_sessions DROP CONSTRAINT %I', constraint_name);
34
+ END IF;
35
+ END $$;
@@ -0,0 +1,28 @@
1
+ ALTER TABLE app_waitlist
2
+ ADD COLUMN invitation_organization_id text,
3
+ ADD COLUMN invitation_delivery text,
4
+ ADD COLUMN invitation_audit_id text,
5
+ ADD COLUMN revoked_at timestamptz;
6
+
7
+ ALTER TABLE sso_logins
8
+ ADD COLUMN invitation_token_hash text;
9
+
10
+ DO $$
11
+ DECLARE
12
+ constraint_name text;
13
+ BEGIN
14
+ SELECT con.conname INTO constraint_name
15
+ FROM pg_constraint con
16
+ JOIN pg_class rel ON rel.oid = con.conrelid
17
+ WHERE rel.relname = 'app_waitlist' AND con.contype = 'c'
18
+ AND pg_get_constraintdef(con.oid) ILIKE '%invitation_workspace_id IS NULL%invitation_role_id IS NULL%';
19
+ IF constraint_name IS NOT NULL THEN
20
+ EXECUTE format('ALTER TABLE app_waitlist DROP CONSTRAINT %I', constraint_name);
21
+ END IF;
22
+ END $$;
23
+
24
+ ALTER TABLE app_waitlist
25
+ ADD CHECK (invitation_delivery IS NULL OR invitation_delivery IN ('email', 'link')),
26
+ ADD CHECK (invitation_organization_id IS NULL OR invitation_workspace_id IS NULL),
27
+ ADD CHECK (invitation_workspace_id IS NULL OR invitation_role_id IS NOT NULL),
28
+ ADD CHECK (invitation_delivery IS DISTINCT FROM 'link' OR invitation_role_id IS NOT NULL);
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@x12i/keyrox-store-pg",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "PostgreSQL repository for Keyrox accounts, grants, and tokens",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist", "migrations"],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.json",
17
+ "test": "vitest run",
18
+ "typecheck": "tsc -p tsconfig.json --noEmit",
19
+ "lint": "echo ok"
20
+ },
21
+ "dependencies": {
22
+ "@x12i/keyrox-store": "0.2.1",
23
+ "@x12i/keyrox-types": "0.2.1",
24
+ "pg": "^8.16.3"
25
+ },
26
+ "devDependencies": {
27
+ "@electric-sql/pglite": "^0.3.14",
28
+ "@types/pg": "^8.15.5",
29
+ "typescript": "^5.8.3",
30
+ "vitest": "^3.2.1"
31
+ },
32
+ "publishConfig": { "access": "public" },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/x12i/keyrox.git",
36
+ "directory": "packages/store-pg"
37
+ }
38
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.