@agimon-ai/po-auth-server 0.0.2-alpha.0 → 0.0.2-alpha.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.
@@ -34,6 +34,7 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
34
34
  home = await require_index.createIdentityHome({
35
35
  ...configuration.config,
36
36
  filename: node_path.default.join(directory, "identity.sqlite"),
37
+ cloud: false,
37
38
  clientAddress: {
38
39
  header: _agimon_ai_po_core_packageApi.PO_API_PEER_ADDRESS_HEADER,
39
40
  trustedProxies: configuration.trustedProxies
@@ -80,7 +81,8 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
80
81
  if (!host) return;
81
82
  const undo = host.setSource({
82
83
  issuer: configuration.config.issuer,
83
- team: (owner) => home.ownedTeam(owner)
84
+ team: (owner) => home.ownedTeam(owner),
85
+ settings: async (subject, org) => await home.isOrgMember(subject, org) ? { yaml: (await home.readMemberSettings(subject, org)).yaml } : void 0
84
86
  });
85
87
  teamChanged = () => host.changed();
86
88
  audit = (entry) => host.audit(entry);
@@ -120,27 +122,41 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
120
122
  return response;
121
123
  };
122
124
  return {
123
- api: [{
124
- basePath: "auth",
125
- publicRoutes: {
126
- paths: ["/"],
127
- authenticate: () => true
125
+ api: [
126
+ {
127
+ basePath: "auth",
128
+ publicRoutes: {
129
+ paths: ["/"],
130
+ authenticate: () => true
131
+ },
132
+ start: () => ({
133
+ fetch,
134
+ close() {}
135
+ })
128
136
  },
129
- start: () => ({
130
- fetch,
131
- close() {}
132
- })
133
- }, {
134
- basePath: "networks",
135
- publicRoutes: {
136
- paths: ["/"],
137
- authenticate: () => true
137
+ {
138
+ basePath: "networks",
139
+ publicRoutes: {
140
+ paths: ["/"],
141
+ authenticate: () => true
142
+ },
143
+ start: () => ({
144
+ fetch,
145
+ close() {}
146
+ })
138
147
  },
139
- start: () => ({
140
- fetch,
141
- close() {}
142
- })
143
- }],
148
+ {
149
+ basePath: "account",
150
+ publicRoutes: {
151
+ paths: ["/"],
152
+ authenticate: () => true
153
+ },
154
+ start: () => ({
155
+ fetch,
156
+ close() {}
157
+ })
158
+ }
159
+ ],
144
160
  onStart: async () => {
145
161
  started = true;
146
162
  await home.runDueRecovery();
@@ -28,6 +28,7 @@ const serverPlugin = defineServerPlugin({
28
28
  home = await createIdentityHome({
29
29
  ...configuration.config,
30
30
  filename: path.join(directory, "identity.sqlite"),
31
+ cloud: false,
31
32
  clientAddress: {
32
33
  header: PO_API_PEER_ADDRESS_HEADER,
33
34
  trustedProxies: configuration.trustedProxies
@@ -74,7 +75,8 @@ const serverPlugin = defineServerPlugin({
74
75
  if (!host) return;
75
76
  const undo = host.setSource({
76
77
  issuer: configuration.config.issuer,
77
- team: (owner) => home.ownedTeam(owner)
78
+ team: (owner) => home.ownedTeam(owner),
79
+ settings: async (subject, org) => await home.isOrgMember(subject, org) ? { yaml: (await home.readMemberSettings(subject, org)).yaml } : void 0
78
80
  });
79
81
  teamChanged = () => host.changed();
80
82
  audit = (entry) => host.audit(entry);
@@ -114,27 +116,41 @@ const serverPlugin = defineServerPlugin({
114
116
  return response;
115
117
  };
116
118
  return {
117
- api: [{
118
- basePath: "auth",
119
- publicRoutes: {
120
- paths: ["/"],
121
- authenticate: () => true
119
+ api: [
120
+ {
121
+ basePath: "auth",
122
+ publicRoutes: {
123
+ paths: ["/"],
124
+ authenticate: () => true
125
+ },
126
+ start: () => ({
127
+ fetch,
128
+ close() {}
129
+ })
122
130
  },
123
- start: () => ({
124
- fetch,
125
- close() {}
126
- })
127
- }, {
128
- basePath: "networks",
129
- publicRoutes: {
130
- paths: ["/"],
131
- authenticate: () => true
131
+ {
132
+ basePath: "networks",
133
+ publicRoutes: {
134
+ paths: ["/"],
135
+ authenticate: () => true
136
+ },
137
+ start: () => ({
138
+ fetch,
139
+ close() {}
140
+ })
132
141
  },
133
- start: () => ({
134
- fetch,
135
- close() {}
136
- })
137
- }],
142
+ {
143
+ basePath: "account",
144
+ publicRoutes: {
145
+ paths: ["/"],
146
+ authenticate: () => true
147
+ },
148
+ start: () => ({
149
+ fetch,
150
+ close() {}
151
+ })
152
+ }
153
+ ],
138
154
  onStart: async () => {
139
155
  started = true;
140
156
  await home.runDueRecovery();
@@ -80,6 +80,22 @@ async function createIdentityHome(config, ports) {
80
80
  encryptOAuthTokens: true,
81
81
  accountLinking: { enabled: false }
82
82
  },
83
+ databaseHooks: { session: { create: { before: async (session, context) => {
84
+ if (session.activeOrganizationId || !context) return;
85
+ const teams = await context.context.adapter.findMany({
86
+ model: "member",
87
+ where: [{
88
+ field: "userId",
89
+ value: session.userId
90
+ }],
91
+ limit: 2
92
+ });
93
+ if (teams.length !== 1) return;
94
+ return { data: {
95
+ ...session,
96
+ activeOrganizationId: teams[0].organizationId
97
+ } };
98
+ } } } },
83
99
  ...config.emailPassword ? { emailAndPassword: {
84
100
  enabled: true,
85
101
  requireEmailVerification: true,
@@ -1116,7 +1132,8 @@ async function createIdentityHome(config, ports) {
1116
1132
  deviceSignIn: !!config.deviceSignIn,
1117
1133
  providers: Object.keys(socialProviders).filter((id) => socialProviders[id] !== void 0)
1118
1134
  },
1119
- session: await signedIn(headers)
1135
+ session: await signedIn(headers),
1136
+ cloud: config.cloud !== false
1120
1137
  };
1121
1138
  }
1122
1139
  async function fetchHandler(request) {
@@ -25,6 +25,8 @@ export interface IdentityHomeConfig {
25
25
  verificationUri: string;
26
26
  clientId: string;
27
27
  };
28
+ /** False on a host that signs people in but runs no Po Cloud, such as a Node server. The bootstrap says so. */
29
+ cloud?: boolean;
28
30
  /** The page an invitation email opens, followed by the invitation id. Absent mails the id itself. */
29
31
  invitationUrl?: string;
30
32
  /**
@@ -80,6 +80,22 @@ async function createIdentityHome(config, ports) {
80
80
  encryptOAuthTokens: true,
81
81
  accountLinking: { enabled: false }
82
82
  },
83
+ databaseHooks: { session: { create: { before: async (session, context) => {
84
+ if (session.activeOrganizationId || !context) return;
85
+ const teams = await context.context.adapter.findMany({
86
+ model: "member",
87
+ where: [{
88
+ field: "userId",
89
+ value: session.userId
90
+ }],
91
+ limit: 2
92
+ });
93
+ if (teams.length !== 1) return;
94
+ return { data: {
95
+ ...session,
96
+ activeOrganizationId: teams[0].organizationId
97
+ } };
98
+ } } } },
83
99
  ...config.emailPassword ? { emailAndPassword: {
84
100
  enabled: true,
85
101
  requireEmailVerification: true,
@@ -1116,7 +1132,8 @@ async function createIdentityHome(config, ports) {
1116
1132
  deviceSignIn: !!config.deviceSignIn,
1117
1133
  providers: Object.keys(socialProviders).filter((id) => socialProviders[id] !== void 0)
1118
1134
  },
1119
- session: await signedIn(headers)
1135
+ session: await signedIn(headers),
1136
+ cloud: config.cloud !== false
1120
1137
  };
1121
1138
  }
1122
1139
  async function fetchHandler(request) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po-auth-server",
3
- "version": "0.0.2-alpha.0",
3
+ "version": "0.0.2-alpha.1",
4
4
  "description": "Po auth server: sign-in, teams, device trust, recovery, rosters and delegated tokens for Node and Cloudflare hosts",
5
5
  "keywords": [
6
6
  "ai",
@@ -48,8 +48,8 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@agimon-ai/po-core": "0.0.0-alpha.158",
52
- "@agimon-ai/po-web-security": "0.0.0-alpha.158",
51
+ "@agimon-ai/po-core": "0.0.0-alpha.159",
52
+ "@agimon-ai/po-web-security": "0.0.0-alpha.159",
53
53
  "@better-auth/expo": "1.7.12",
54
54
  "@better-auth/passkey": "1.7.12",
55
55
  "@better-auth/sso": "1.7.12",
@@ -59,8 +59,8 @@
59
59
  "jose": "6.2.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@agimon-ai/po-network": "0.0.2-alpha.105",
63
- "@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.158",
62
+ "@agimon-ai/po-network": "0.0.2-alpha.106",
63
+ "@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.159",
64
64
  "@types/node": "26.4.1",
65
65
  "tsdown": "0.23.0",
66
66
  "typescript": "7.0.2",