@ankhorage/infra 0.4.2 → 1.0.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.
- package/CHANGELOG.md +15 -0
- package/README.md +1 -1
- package/dist/adapters/minikube/auth/supabase/index.d.ts.map +1 -1
- package/dist/adapters/minikube/auth/supabase/index.js +14 -39
- package/dist/adapters/minikube/auth/supabase/index.js.map +1 -1
- package/dist/adapters/minikube/auth/supabase/profile.d.ts +0 -1
- package/dist/adapters/minikube/auth/supabase/profile.d.ts.map +1 -1
- package/dist/adapters/minikube/auth/supabase/profile.js +1 -1
- package/dist/adapters/minikube/auth/supabase/profile.js.map +1 -1
- package/dist/adapters/minikube/authz/cerbos/index.d.ts.map +1 -1
- package/dist/adapters/minikube/authz/cerbos/index.js +22 -2
- package/dist/adapters/minikube/authz/cerbos/index.js.map +1 -1
- package/dist/adapters/minikube/base/index.d.ts +5 -2
- package/dist/adapters/minikube/base/index.d.ts.map +1 -1
- package/dist/adapters/minikube/base/index.js +2764 -1841
- package/dist/adapters/minikube/base/index.js.map +1 -1
- package/dist/adapters/minikube/contracts.d.ts +25 -0
- package/dist/adapters/minikube/contracts.d.ts.map +1 -1
- package/dist/adapters/minikube/contracts.js +1 -0
- package/dist/adapters/minikube/contracts.js.map +1 -1
- package/dist/adapters/minikube/index.d.ts.map +1 -1
- package/dist/adapters/minikube/index.js +18 -33
- package/dist/adapters/minikube/index.js.map +1 -1
- package/dist/adapters/minikube/secrets/supabase-vault/index.d.ts.map +1 -1
- package/dist/adapters/minikube/secrets/supabase-vault/index.js +49 -6
- package/dist/adapters/minikube/secrets/supabase-vault/index.js.map +1 -1
- package/dist/adapters/minikube/storage/supabase/index.d.ts.map +1 -1
- package/dist/adapters/minikube/storage/supabase/index.js +2 -1
- package/dist/adapters/minikube/storage/supabase/index.js.map +1 -1
- package/package.json +4 -1
- package/src/adapters/minikube/README.md +46 -38
- package/src/adapters/minikube/auth/supabase/index.ts +14 -40
- package/src/adapters/minikube/auth/supabase/profile.ts +1 -1
- package/src/adapters/minikube/authz/cerbos/index.ts +25 -3
- package/src/adapters/minikube/base/index.test.ts +399 -673
- package/src/adapters/minikube/base/index.ts +2969 -1874
- package/src/adapters/minikube/base/twoAppIsolation.integration.test.ts +636 -0
- package/src/adapters/minikube/contracts.ts +29 -0
- package/src/adapters/minikube/index.ts +18 -44
- package/src/adapters/minikube/secrets/index.test.ts +15 -7
- package/src/adapters/minikube/secrets/supabase-vault/index.ts +53 -6
- package/src/adapters/minikube/storage/supabase/index.ts +1 -5
- package/src/apis.test.ts +2 -1
- package/src/index.test.ts +64 -577
- package/src/minikubeImageLifecycle.test.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ankhorage/infra
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- efa43ed: Write generated Supabase browser env values into the app `.env.local` during Minikube Infra
|
|
8
|
+
Up so local Expo auth clients receive the gateway URL and anon key.
|
|
9
|
+
|
|
10
|
+
## 1.0.0
|
|
11
|
+
|
|
12
|
+
### Major Changes
|
|
13
|
+
|
|
14
|
+
- 04b6470: Rebuild generated Minikube infrastructure around one app-owned Minikube profile per app slug.
|
|
15
|
+
|
|
16
|
+
Generated local infra now uses namespace `app` for the app runtime and namespace `supabase` for Kubernetes-owned Supabase workloads. Host-owned Supabase Compose startup, `supabase-local-env.sh`, shared `minikube` profile fallbacks, and `supabase migration up --local` runtime ownership have been removed. Generated lifecycle scripts now use slug-scoped `up`, `down`, `reset`, `destroy`, `status`, and managed port-forward flows.
|
|
17
|
+
|
|
3
18
|
## 0.4.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# INFRA
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Executable infra provider and standalone CLI for Ankhorage project workflows.
|
|
9
9
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAOhE,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IAClD,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,wBAAwB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAOhE,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IAClD,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,wBAAwB,CAiE3B"}
|
|
@@ -27,10 +27,6 @@ export function generateSupabaseAuthArtifacts(args) {
|
|
|
27
27
|
profileModel,
|
|
28
28
|
}),
|
|
29
29
|
},
|
|
30
|
-
{
|
|
31
|
-
path: `${root}/supabase-auth.secret.yaml`,
|
|
32
|
-
content: getSupabaseSecret(namespace),
|
|
33
|
-
},
|
|
34
30
|
{
|
|
35
31
|
path: `${root}/app-runtime-auth.env.configmap.yaml`,
|
|
36
32
|
content: getRuntimeAuthEnvConfigMap({
|
|
@@ -57,18 +53,10 @@ export function generateSupabaseAuthArtifacts(args) {
|
|
|
57
53
|
],
|
|
58
54
|
resources: [
|
|
59
55
|
`${resourceRoot}/supabase-auth.configmap.yaml`,
|
|
60
|
-
`${resourceRoot}/supabase-auth.secret.yaml`,
|
|
61
56
|
`${resourceRoot}/app-runtime-auth.env.configmap.yaml`,
|
|
62
57
|
],
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'SUPABASE_URL=',
|
|
66
|
-
'SUPABASE_ANON_KEY=',
|
|
67
|
-
'SUPABASE_SERVICE_ROLE_KEY=',
|
|
68
|
-
'SUPABASE_JWT_SECRET=',
|
|
69
|
-
'EXPO_PUBLIC_SUPABASE_URL=',
|
|
70
|
-
'EXPO_PUBLIC_SUPABASE_ANON_KEY=',
|
|
71
|
-
],
|
|
58
|
+
providerLifecycle: [],
|
|
59
|
+
envEntries: ['EXPO_PUBLIC_SUPABASE_URL=', 'EXPO_PUBLIC_SUPABASE_ANON_KEY='],
|
|
72
60
|
warnings,
|
|
73
61
|
};
|
|
74
62
|
}
|
|
@@ -95,22 +83,6 @@ data:
|
|
|
95
83
|
AUTH_PROFILE_UPDATE_STRATEGY: "${profileModel.updateStrategy}"
|
|
96
84
|
`;
|
|
97
85
|
}
|
|
98
|
-
function getSupabaseSecret(namespace) {
|
|
99
|
-
return `apiVersion: v1
|
|
100
|
-
kind: Secret
|
|
101
|
-
metadata:
|
|
102
|
-
name: supabase-auth-secrets
|
|
103
|
-
namespace: ${namespace}
|
|
104
|
-
type: Opaque
|
|
105
|
-
stringData:
|
|
106
|
-
SUPABASE_URL: ""
|
|
107
|
-
SUPABASE_ANON_KEY: ""
|
|
108
|
-
SUPABASE_SERVICE_ROLE_KEY: ""
|
|
109
|
-
SUPABASE_JWT_SECRET: ""
|
|
110
|
-
EXPO_PUBLIC_SUPABASE_URL: ""
|
|
111
|
-
EXPO_PUBLIC_SUPABASE_ANON_KEY: ""
|
|
112
|
-
`;
|
|
113
|
-
}
|
|
114
86
|
function getRuntimeAuthEnvConfigMap(args) {
|
|
115
87
|
const { namespace, scope, authzEngine, authzKind, authFieldModel, profileModel } = args;
|
|
116
88
|
return `apiVersion: v1
|
|
@@ -161,7 +133,7 @@ This file documents the runtime conventions generated by the minikube Supabase a
|
|
|
161
133
|
## Generated Kubernetes Objects
|
|
162
134
|
|
|
163
135
|
- \`ConfigMap/supabase-auth-config\`: high-level auth metadata.
|
|
164
|
-
- \`Secret/supabase-
|
|
136
|
+
- \`Secret/supabase-public-runtime\`: browser-safe Supabase URL and anon key material, generated by \`scripts/up.sh\` after local Supabase secrets exist.
|
|
165
137
|
- \`ConfigMap/app-runtime-auth-env\`: auth runtime feature flags and authz metadata.
|
|
166
138
|
|
|
167
139
|
## App Runtime Convention
|
|
@@ -169,7 +141,12 @@ This file documents the runtime conventions generated by the minikube Supabase a
|
|
|
169
141
|
Your app runtime deployment should import both:
|
|
170
142
|
|
|
171
143
|
- \`app-runtime-auth-env\` (configMap)
|
|
172
|
-
- \`supabase-
|
|
144
|
+
- \`supabase-public-runtime\` (secret)
|
|
145
|
+
|
|
146
|
+
For local Expo/Metro development, \`scripts/up.sh\` also writes the same browser-safe
|
|
147
|
+
\`EXPO_PUBLIC_SUPABASE_URL\` and \`EXPO_PUBLIC_SUPABASE_ANON_KEY\` values to
|
|
148
|
+
\`\${APP_SOURCE_DIR}/.env.local\`, preserving unrelated entries. Restart Expo after
|
|
149
|
+
Infra Up so those public values are embedded into the client bundle.
|
|
173
150
|
|
|
174
151
|
Example deployment fragment:
|
|
175
152
|
|
|
@@ -178,7 +155,7 @@ envFrom:
|
|
|
178
155
|
- configMapRef:
|
|
179
156
|
name: app-runtime-auth-env
|
|
180
157
|
- secretRef:
|
|
181
|
-
name: supabase-
|
|
158
|
+
name: supabase-public-runtime
|
|
182
159
|
\`\`\`
|
|
183
160
|
|
|
184
161
|
The generated base deployment at \`k8s/app/deployment.yaml\` already includes this wiring
|
|
@@ -200,18 +177,16 @@ with \`optional: true\` for auth sources.
|
|
|
200
177
|
- \`AUTH_PROFILE_PRIMARY_KEY\`
|
|
201
178
|
- \`AUTH_PROFILE_CREATE_STRATEGY\`
|
|
202
179
|
- \`AUTH_PROFILE_UPDATE_STRATEGY\`
|
|
203
|
-
- \`SUPABASE_SECRET_SYNC_ENABLED\`
|
|
204
180
|
- \`SUPABASE_URL\`
|
|
205
181
|
- \`SUPABASE_ANON_KEY\`
|
|
206
|
-
- \`SUPABASE_SERVICE_ROLE_KEY\`
|
|
207
|
-
- \`SUPABASE_JWT_SECRET\`
|
|
208
182
|
- \`EXPO_PUBLIC_SUPABASE_URL\`
|
|
209
183
|
- \`EXPO_PUBLIC_SUPABASE_ANON_KEY\`
|
|
210
184
|
${profileSection}
|
|
211
|
-
##
|
|
185
|
+
## Runtime Secrets
|
|
212
186
|
|
|
213
|
-
When
|
|
214
|
-
|
|
187
|
+
When Supabase is enabled, \`scripts/up.sh\` creates/updates \`Secret/supabase-public-runtime\`
|
|
188
|
+
with browser-safe values for the app namespace and mirrors the Expo public values into the
|
|
189
|
+
app \`.env.local\`. Privileged Supabase runtime secrets remain in the \`supabase\` namespace.
|
|
215
190
|
`;
|
|
216
191
|
}
|
|
217
192
|
const DEFAULT_SIGN_IN_IDENTIFIERS = ['email'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gCAAgC,EAEhC,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AAEnB,MAAM,UAAU,6BAA6B,CAAC,IAG7C;IACC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAErC,MAAM,IAAI,GAAG,kCAAkC,CAAC;IAChD,MAAM,YAAY,GAAG,eAAe,CAAC;IACrC,MAAM,QAAQ,GAAG,qBAAqB,CAAC;IACvC,MAAM,aAAa,GAAG,mCAAmC,CAAC;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,IAAI,QAAQ,CAAC;IAC/C,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,IAAI,QAAQ,CAAC;IACrE,MAAM,SAAS,GAAG,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AAkB,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE;QACvE,OAAO;QACP,WAAW;QACX,UAAU;KACX,CAAC,CAAC;IAEH,OAAO;QACL,oBAAoB,EAAE,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC;QACjD,uBAAuB,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC;QACvD,uBAAuB,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC;QACvD,YAAY;QACZ,gBAAgB,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CACzB,MAAqC,EACrC,QAA2B;IAE3B,MAAM,MAAM,GAAG,MAAM,IAAI,QAAQ,CAAC;IAClC,MAAM,IAAI,GAAa,EAAE,CAAC;IAE1B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7C,SAAS;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAa;IAC3C,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import type { InfraManifestInput } from '../../../../types';\nimport type { MinikubeAdapterArtifacts } from '../../contracts';\nimport {\n getSupabaseProfileReconciliation,\n type ResolvedProfileModel,\n resolveSupabaseProfileModel,\n} from './profile';\n\nexport function generateSupabaseAuthArtifacts(args: {\n manifest: InfraManifestInput;\n namespace: string;\n}): MinikubeAdapterArtifacts {\n const { manifest, namespace } = args;\n\n const root = 'infra/minikube/k8s/auth/supabase';\n const resourceRoot = 'auth/supabase';\n const docsRoot = 'infra/minikube/auth';\n const generatedRoot = 'infra/minikube/supabase/generated';\n const scope = manifest.auth?.scope ?? 'global';\n const authzEngine = manifest.auth?.authorization?.engine ?? 'native';\n const authzKind = manifest.auth?.authorization?.kind ?? 'RBAC';\n const authFieldModel = resolveAuthFieldModel(manifest);\n const profileModel = resolveSupabaseProfileModel(manifest);\n\n const warnings: string[] = [];\n if (scope !== 'global') {\n warnings.push(\n `Auth scope \"${scope}\" is not fully modeled yet for Supabase. Baseline resources assume global auth.`,\n );\n }\n\n return {\n files: [\n {\n path: `${root}/supabase-auth.configmap.yaml`,\n content: getSupabaseConfigMap({\n namespace,\n scope,\n authzEngine,\n authzKind,\n authFieldModel,\n profileModel,\n }),\n },\n {\n path: `${root}/supabase-auth.secret.yaml`,\n content: getSupabaseSecret(namespace),\n },\n {\n path: `${root}/app-runtime-auth.env.configmap.yaml`,\n content: getRuntimeAuthEnvConfigMap({\n namespace,\n scope,\n authzEngine,\n authzKind,\n authFieldModel,\n profileModel,\n }),\n },\n ...(profileModel.enabled\n ? [\n {\n path: `${generatedRoot}/auth_profiles.sql`,\n content: getSupabaseProfileReconciliation(profileModel),\n },\n ]\n : []),\n {\n path: `${docsRoot}/supabase-runtime-wiring.md`,\n content: getSupabaseRuntimeWiringGuide(profileModel),\n },\n ],\n resources: [\n `${resourceRoot}/supabase-auth.configmap.yaml`,\n `${resourceRoot}/supabase-auth.secret.yaml`,\n `${resourceRoot}/app-runtime-auth.env.configmap.yaml`,\n ],\n envEntries: [\n 'SUPABASE_SECRET_SYNC_ENABLED=true',\n 'SUPABASE_URL=',\n 'SUPABASE_ANON_KEY=',\n 'SUPABASE_SERVICE_ROLE_KEY=',\n 'SUPABASE_JWT_SECRET=',\n 'EXPO_PUBLIC_SUPABASE_URL=',\n 'EXPO_PUBLIC_SUPABASE_ANON_KEY=',\n ],\n warnings,\n };\n}\n\nfunction getSupabaseConfigMap(args: {\n namespace: string;\n scope: string;\n authzEngine: string;\n authzKind: string;\n authFieldModel: ResolvedAuthFieldModel;\n profileModel: ResolvedProfileModel;\n}) {\n const { namespace, scope, authzEngine, authzKind, authFieldModel, profileModel } = args;\n\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: supabase-auth-config\n namespace: ${namespace}\ndata:\n AUTH_PROVIDER: \"supabase\"\n AUTH_SCOPE: \"${scope}\"\n AUTHZ_ENGINE: \"${authzEngine}\"\n AUTHZ_KIND: \"${authzKind}\"\n AUTH_SIGN_IN_IDENTIFIERS: \"${escapeYamlDoubleQuoted(authFieldModel.signInIdentifiersCsv)}\"\n AUTH_SIGN_UP_REQUIRED_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpRequiredFieldsCsv)}\"\n AUTH_SIGN_UP_OPTIONAL_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpOptionalFieldsCsv)}\"\n AUTH_SIGN_UP_POLICY: \"${authFieldModel.signUpPolicy}\"\n AUTH_PROFILE_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.profileFieldsCsv)}\"\n AUTH_PROFILE_TABLE: \"${escapeYamlDoubleQuoted(profileModel.table)}\"\n AUTH_PROFILE_PRIMARY_KEY: \"${profileModel.primaryKey}\"\n AUTH_PROFILE_CREATE_STRATEGY: \"${profileModel.createStrategy}\"\n AUTH_PROFILE_UPDATE_STRATEGY: \"${profileModel.updateStrategy}\"\n`;\n}\n\nfunction getSupabaseSecret(namespace: string) {\n return `apiVersion: v1\nkind: Secret\nmetadata:\n name: supabase-auth-secrets\n namespace: ${namespace}\ntype: Opaque\nstringData:\n SUPABASE_URL: \"\"\n SUPABASE_ANON_KEY: \"\"\n SUPABASE_SERVICE_ROLE_KEY: \"\"\n SUPABASE_JWT_SECRET: \"\"\n EXPO_PUBLIC_SUPABASE_URL: \"\"\n EXPO_PUBLIC_SUPABASE_ANON_KEY: \"\"\n`;\n}\n\nfunction getRuntimeAuthEnvConfigMap(args: {\n namespace: string;\n scope: string;\n authzEngine: string;\n authzKind: string;\n authFieldModel: ResolvedAuthFieldModel;\n profileModel: ResolvedProfileModel;\n}) {\n const { namespace, scope, authzEngine, authzKind, authFieldModel, profileModel } = args;\n\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: app-runtime-auth-env\n namespace: ${namespace}\ndata:\n AUTH_REQUIRED: \"true\"\n AUTH_PROVIDER: \"supabase\"\n AUTH_SCOPE: \"${scope}\"\n AUTHZ_ENGINE: \"${authzEngine}\"\n AUTHZ_KIND: \"${authzKind}\"\n AUTH_SIGN_IN_IDENTIFIERS: \"${escapeYamlDoubleQuoted(authFieldModel.signInIdentifiersCsv)}\"\n AUTH_SIGN_UP_REQUIRED_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpRequiredFieldsCsv)}\"\n AUTH_SIGN_UP_OPTIONAL_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpOptionalFieldsCsv)}\"\n AUTH_SIGN_UP_POLICY: \"${authFieldModel.signUpPolicy}\"\n AUTH_PROFILE_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.profileFieldsCsv)}\"\n AUTH_PROFILE_TABLE: \"${escapeYamlDoubleQuoted(profileModel.table)}\"\n AUTH_PROFILE_PRIMARY_KEY: \"${profileModel.primaryKey}\"\n AUTH_PROFILE_CREATE_STRATEGY: \"${profileModel.createStrategy}\"\n AUTH_PROFILE_UPDATE_STRATEGY: \"${profileModel.updateStrategy}\"\n AUTH_TOKEN_HEADER: \"Authorization\"\n AUTH_TOKEN_PREFIX: \"Bearer\"\n`;\n}\n\nfunction getSupabaseRuntimeWiringGuide(profileModel: ResolvedProfileModel) {\n const profileSection = profileModel.enabled\n ? `\n## App Profile Table\n\nIdentity remains provider-owned in \\`auth.users\\`. App-facing profile data is generated in\n\\`public.${profileModel.table}\\` and linked through \\`${profileModel.table}.id -> auth.users.id\\`.\n\nThe generated profile reconciliation:\n\n- creates the profile table\n- enables row-level security\n- allows signed-in users to read and update their own profile row\n- drops stale Ankhorage-managed profile columns that are no longer configured\n- creates a trigger for new auth users when \\`AUTH_PROFILE_CREATE_STRATEGY=trigger\\`\n`\n : '';\n\n return `# Supabase Runtime Wiring\n\nThis file documents the runtime conventions generated by the minikube Supabase adapter.\n\n## Generated Kubernetes Objects\n\n- \\`ConfigMap/supabase-auth-config\\`: high-level auth metadata.\n- \\`Secret/supabase-auth-secrets\\`: Supabase keys and public runtime keys.\n- \\`ConfigMap/app-runtime-auth-env\\`: auth runtime feature flags and authz metadata.\n\n## App Runtime Convention\n\nYour app runtime deployment should import both:\n\n- \\`app-runtime-auth-env\\` (configMap)\n- \\`supabase-auth-secrets\\` (secret)\n\nExample deployment fragment:\n\n\\`\\`\\`yaml\nenvFrom:\n - configMapRef:\n name: app-runtime-auth-env\n - secretRef:\n name: supabase-auth-secrets\n\\`\\`\\`\n\nThe generated base deployment at \\`k8s/app/deployment.yaml\\` already includes this wiring\nwith \\`optional: true\\` for auth sources.\n\n## Expected Environment Variables\n\n- \\`AUTH_REQUIRED\\`\n- \\`AUTH_PROVIDER\\`\n- \\`AUTH_SCOPE\\`\n- \\`AUTHZ_ENGINE\\`\n- \\`AUTHZ_KIND\\`\n- \\`AUTH_SIGN_IN_IDENTIFIERS\\`\n- \\`AUTH_SIGN_UP_REQUIRED_FIELDS\\`\n- \\`AUTH_SIGN_UP_OPTIONAL_FIELDS\\`\n- \\`AUTH_SIGN_UP_POLICY\\`\n- \\`AUTH_PROFILE_FIELDS\\`\n- \\`AUTH_PROFILE_TABLE\\`\n- \\`AUTH_PROFILE_PRIMARY_KEY\\`\n- \\`AUTH_PROFILE_CREATE_STRATEGY\\`\n- \\`AUTH_PROFILE_UPDATE_STRATEGY\\`\n- \\`SUPABASE_SECRET_SYNC_ENABLED\\`\n- \\`SUPABASE_URL\\`\n- \\`SUPABASE_ANON_KEY\\`\n- \\`SUPABASE_SERVICE_ROLE_KEY\\`\n- \\`SUPABASE_JWT_SECRET\\`\n- \\`EXPO_PUBLIC_SUPABASE_URL\\`\n- \\`EXPO_PUBLIC_SUPABASE_ANON_KEY\\`\n${profileSection}\n## Secret Sync\n\nWhen \\`SUPABASE_SECRET_SYNC_ENABLED=true\\`, \\`scripts/up.sh\\` will create/update\n\\`Secret/supabase-auth-secrets\\` from the loaded environment values.\n`;\n}\n\nconst DEFAULT_SIGN_IN_IDENTIFIERS = ['email'];\nconst DEFAULT_SIGN_UP_REQUIRED_FIELDS = ['email', 'password'];\nconst DEFAULT_SIGN_UP_OPTIONAL_FIELDS = ['firstName', 'lastName'];\nconst DEFAULT_SIGN_UP_POLICY = 'autoSignIn';\ninterface ResolvedAuthFieldModel {\n signInIdentifiersCsv: string;\n signUpRequiredFieldsCsv: string;\n signUpOptionalFieldsCsv: string;\n signUpPolicy: string;\n profileFieldsCsv: string;\n}\n\nfunction resolveAuthFieldModel(manifest: InfraManifestInput): ResolvedAuthFieldModel {\n const signInIdentifiers = normalizeFieldList(\n manifest.auth?.signIn?.identifiers,\n DEFAULT_SIGN_IN_IDENTIFIERS,\n );\n const signUpRequiredFields = normalizeFieldList(\n manifest.auth?.signUp?.requiredFields,\n DEFAULT_SIGN_UP_REQUIRED_FIELDS,\n );\n const signUpOptionalFields = normalizeFieldList(\n manifest.auth?.signUp?.optionalFields,\n DEFAULT_SIGN_UP_OPTIONAL_FIELDS,\n ).filter((field) => !signUpRequiredFields.includes(field));\n const signUpPolicy = manifest.auth?.signUp?.signUpPolicy ?? DEFAULT_SIGN_UP_POLICY;\n const profileFields = normalizeFieldList(manifest.auth?.profile?.fields, [\n 'email',\n 'firstName',\n 'lastName',\n ]);\n\n return {\n signInIdentifiersCsv: signInIdentifiers.join(','),\n signUpRequiredFieldsCsv: signUpRequiredFields.join(','),\n signUpOptionalFieldsCsv: signUpOptionalFields.join(','),\n signUpPolicy,\n profileFieldsCsv: profileFields.join(','),\n };\n}\n\nfunction normalizeFieldList(\n values: readonly string[] | undefined,\n fallback: readonly string[],\n): string[] {\n const source = values ?? fallback;\n const next: string[] = [];\n\n for (const value of source) {\n const normalized = value.trim();\n if (!normalized || next.includes(normalized)) {\n continue;\n }\n next.push(normalized);\n }\n\n if (next.length > 0) {\n return next;\n }\n\n return [...fallback];\n}\n\nfunction escapeYamlDoubleQuoted(value: string): string {\n return value.replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gCAAgC,EAEhC,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AAEnB,MAAM,UAAU,6BAA6B,CAAC,IAG7C;IACC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAErC,MAAM,IAAI,GAAG,kCAAkC,CAAC;IAChD,MAAM,YAAY,GAAG,eAAe,CAAC;IACrC,MAAM,QAAQ,GAAG,qBAAqB,CAAC;IACvC,MAAM,aAAa,GAAG,mCAAmC,CAAC;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,IAAI,QAAQ,CAAC;IAC/C,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,IAAI,QAAQ,CAAC;IACrE,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,IAAI,MAAM,CAAC;IAC/D,MAAM,cAAc,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACvD,MAAM,YAAY,GAAG,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IAE3D,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvB,QAAQ,CAAC,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AAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7C,SAAS;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAa;IAC3C,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import type { InfraManifestInput } from '../../../../types';\nimport type { MinikubeAdapterArtifacts } from '../../contracts';\nimport {\n getSupabaseProfileReconciliation,\n type ResolvedProfileModel,\n resolveSupabaseProfileModel,\n} from './profile';\n\nexport function generateSupabaseAuthArtifacts(args: {\n manifest: InfraManifestInput;\n namespace: string;\n}): MinikubeAdapterArtifacts {\n const { manifest, namespace } = args;\n\n const root = 'infra/minikube/k8s/auth/supabase';\n const resourceRoot = 'auth/supabase';\n const docsRoot = 'infra/minikube/auth';\n const generatedRoot = 'infra/minikube/supabase/generated';\n const scope = manifest.auth?.scope ?? 'global';\n const authzEngine = manifest.auth?.authorization?.engine ?? 'native';\n const authzKind = manifest.auth?.authorization?.kind ?? 'RBAC';\n const authFieldModel = resolveAuthFieldModel(manifest);\n const profileModel = resolveSupabaseProfileModel(manifest);\n\n const warnings: string[] = [];\n if (scope !== 'global') {\n warnings.push(\n `Auth scope \"${scope}\" is not fully modeled yet for Supabase. Baseline resources assume global auth.`,\n );\n }\n\n return {\n files: [\n {\n path: `${root}/supabase-auth.configmap.yaml`,\n content: getSupabaseConfigMap({\n namespace,\n scope,\n authzEngine,\n authzKind,\n authFieldModel,\n profileModel,\n }),\n },\n {\n path: `${root}/app-runtime-auth.env.configmap.yaml`,\n content: getRuntimeAuthEnvConfigMap({\n namespace,\n scope,\n authzEngine,\n authzKind,\n authFieldModel,\n profileModel,\n }),\n },\n ...(profileModel.enabled\n ? [\n {\n path: `${generatedRoot}/auth_profiles.sql`,\n content: getSupabaseProfileReconciliation(profileModel),\n },\n ]\n : []),\n {\n path: `${docsRoot}/supabase-runtime-wiring.md`,\n content: getSupabaseRuntimeWiringGuide(profileModel),\n },\n ],\n resources: [\n `${resourceRoot}/supabase-auth.configmap.yaml`,\n `${resourceRoot}/app-runtime-auth.env.configmap.yaml`,\n ],\n providerLifecycle: [],\n envEntries: ['EXPO_PUBLIC_SUPABASE_URL=', 'EXPO_PUBLIC_SUPABASE_ANON_KEY='],\n warnings,\n };\n}\n\nfunction getSupabaseConfigMap(args: {\n namespace: string;\n scope: string;\n authzEngine: string;\n authzKind: string;\n authFieldModel: ResolvedAuthFieldModel;\n profileModel: ResolvedProfileModel;\n}) {\n const { namespace, scope, authzEngine, authzKind, authFieldModel, profileModel } = args;\n\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: supabase-auth-config\n namespace: ${namespace}\ndata:\n AUTH_PROVIDER: \"supabase\"\n AUTH_SCOPE: \"${scope}\"\n AUTHZ_ENGINE: \"${authzEngine}\"\n AUTHZ_KIND: \"${authzKind}\"\n AUTH_SIGN_IN_IDENTIFIERS: \"${escapeYamlDoubleQuoted(authFieldModel.signInIdentifiersCsv)}\"\n AUTH_SIGN_UP_REQUIRED_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpRequiredFieldsCsv)}\"\n AUTH_SIGN_UP_OPTIONAL_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpOptionalFieldsCsv)}\"\n AUTH_SIGN_UP_POLICY: \"${authFieldModel.signUpPolicy}\"\n AUTH_PROFILE_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.profileFieldsCsv)}\"\n AUTH_PROFILE_TABLE: \"${escapeYamlDoubleQuoted(profileModel.table)}\"\n AUTH_PROFILE_PRIMARY_KEY: \"${profileModel.primaryKey}\"\n AUTH_PROFILE_CREATE_STRATEGY: \"${profileModel.createStrategy}\"\n AUTH_PROFILE_UPDATE_STRATEGY: \"${profileModel.updateStrategy}\"\n`;\n}\n\nfunction getRuntimeAuthEnvConfigMap(args: {\n namespace: string;\n scope: string;\n authzEngine: string;\n authzKind: string;\n authFieldModel: ResolvedAuthFieldModel;\n profileModel: ResolvedProfileModel;\n}) {\n const { namespace, scope, authzEngine, authzKind, authFieldModel, profileModel } = args;\n\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: app-runtime-auth-env\n namespace: ${namespace}\ndata:\n AUTH_REQUIRED: \"true\"\n AUTH_PROVIDER: \"supabase\"\n AUTH_SCOPE: \"${scope}\"\n AUTHZ_ENGINE: \"${authzEngine}\"\n AUTHZ_KIND: \"${authzKind}\"\n AUTH_SIGN_IN_IDENTIFIERS: \"${escapeYamlDoubleQuoted(authFieldModel.signInIdentifiersCsv)}\"\n AUTH_SIGN_UP_REQUIRED_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpRequiredFieldsCsv)}\"\n AUTH_SIGN_UP_OPTIONAL_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.signUpOptionalFieldsCsv)}\"\n AUTH_SIGN_UP_POLICY: \"${authFieldModel.signUpPolicy}\"\n AUTH_PROFILE_FIELDS: \"${escapeYamlDoubleQuoted(authFieldModel.profileFieldsCsv)}\"\n AUTH_PROFILE_TABLE: \"${escapeYamlDoubleQuoted(profileModel.table)}\"\n AUTH_PROFILE_PRIMARY_KEY: \"${profileModel.primaryKey}\"\n AUTH_PROFILE_CREATE_STRATEGY: \"${profileModel.createStrategy}\"\n AUTH_PROFILE_UPDATE_STRATEGY: \"${profileModel.updateStrategy}\"\n AUTH_TOKEN_HEADER: \"Authorization\"\n AUTH_TOKEN_PREFIX: \"Bearer\"\n`;\n}\n\nfunction getSupabaseRuntimeWiringGuide(profileModel: ResolvedProfileModel) {\n const profileSection = profileModel.enabled\n ? `\n## App Profile Table\n\nIdentity remains provider-owned in \\`auth.users\\`. App-facing profile data is generated in\n\\`public.${profileModel.table}\\` and linked through \\`${profileModel.table}.id -> auth.users.id\\`.\n\nThe generated profile reconciliation:\n\n- creates the profile table\n- enables row-level security\n- allows signed-in users to read and update their own profile row\n- drops stale Ankhorage-managed profile columns that are no longer configured\n- creates a trigger for new auth users when \\`AUTH_PROFILE_CREATE_STRATEGY=trigger\\`\n`\n : '';\n\n return `# Supabase Runtime Wiring\n\nThis file documents the runtime conventions generated by the minikube Supabase adapter.\n\n## Generated Kubernetes Objects\n\n- \\`ConfigMap/supabase-auth-config\\`: high-level auth metadata.\n- \\`Secret/supabase-public-runtime\\`: browser-safe Supabase URL and anon key material, generated by \\`scripts/up.sh\\` after local Supabase secrets exist.\n- \\`ConfigMap/app-runtime-auth-env\\`: auth runtime feature flags and authz metadata.\n\n## App Runtime Convention\n\nYour app runtime deployment should import both:\n\n- \\`app-runtime-auth-env\\` (configMap)\n- \\`supabase-public-runtime\\` (secret)\n\nFor local Expo/Metro development, \\`scripts/up.sh\\` also writes the same browser-safe\n\\`EXPO_PUBLIC_SUPABASE_URL\\` and \\`EXPO_PUBLIC_SUPABASE_ANON_KEY\\` values to\n\\`\\${APP_SOURCE_DIR}/.env.local\\`, preserving unrelated entries. Restart Expo after\nInfra Up so those public values are embedded into the client bundle.\n\nExample deployment fragment:\n\n\\`\\`\\`yaml\nenvFrom:\n - configMapRef:\n name: app-runtime-auth-env\n - secretRef:\n name: supabase-public-runtime\n\\`\\`\\`\n\nThe generated base deployment at \\`k8s/app/deployment.yaml\\` already includes this wiring\nwith \\`optional: true\\` for auth sources.\n\n## Expected Environment Variables\n\n- \\`AUTH_REQUIRED\\`\n- \\`AUTH_PROVIDER\\`\n- \\`AUTH_SCOPE\\`\n- \\`AUTHZ_ENGINE\\`\n- \\`AUTHZ_KIND\\`\n- \\`AUTH_SIGN_IN_IDENTIFIERS\\`\n- \\`AUTH_SIGN_UP_REQUIRED_FIELDS\\`\n- \\`AUTH_SIGN_UP_OPTIONAL_FIELDS\\`\n- \\`AUTH_SIGN_UP_POLICY\\`\n- \\`AUTH_PROFILE_FIELDS\\`\n- \\`AUTH_PROFILE_TABLE\\`\n- \\`AUTH_PROFILE_PRIMARY_KEY\\`\n- \\`AUTH_PROFILE_CREATE_STRATEGY\\`\n- \\`AUTH_PROFILE_UPDATE_STRATEGY\\`\n- \\`SUPABASE_URL\\`\n- \\`SUPABASE_ANON_KEY\\`\n- \\`EXPO_PUBLIC_SUPABASE_URL\\`\n- \\`EXPO_PUBLIC_SUPABASE_ANON_KEY\\`\n${profileSection}\n## Runtime Secrets\n\nWhen Supabase is enabled, \\`scripts/up.sh\\` creates/updates \\`Secret/supabase-public-runtime\\`\nwith browser-safe values for the app namespace and mirrors the Expo public values into the\napp \\`.env.local\\`. Privileged Supabase runtime secrets remain in the \\`supabase\\` namespace.\n`;\n}\n\nconst DEFAULT_SIGN_IN_IDENTIFIERS = ['email'];\nconst DEFAULT_SIGN_UP_REQUIRED_FIELDS = ['email', 'password'];\nconst DEFAULT_SIGN_UP_OPTIONAL_FIELDS = ['firstName', 'lastName'];\nconst DEFAULT_SIGN_UP_POLICY = 'autoSignIn';\ninterface ResolvedAuthFieldModel {\n signInIdentifiersCsv: string;\n signUpRequiredFieldsCsv: string;\n signUpOptionalFieldsCsv: string;\n signUpPolicy: string;\n profileFieldsCsv: string;\n}\n\nfunction resolveAuthFieldModel(manifest: InfraManifestInput): ResolvedAuthFieldModel {\n const signInIdentifiers = normalizeFieldList(\n manifest.auth?.signIn?.identifiers,\n DEFAULT_SIGN_IN_IDENTIFIERS,\n );\n const signUpRequiredFields = normalizeFieldList(\n manifest.auth?.signUp?.requiredFields,\n DEFAULT_SIGN_UP_REQUIRED_FIELDS,\n );\n const signUpOptionalFields = normalizeFieldList(\n manifest.auth?.signUp?.optionalFields,\n DEFAULT_SIGN_UP_OPTIONAL_FIELDS,\n ).filter((field) => !signUpRequiredFields.includes(field));\n const signUpPolicy = manifest.auth?.signUp?.signUpPolicy ?? DEFAULT_SIGN_UP_POLICY;\n const profileFields = normalizeFieldList(manifest.auth?.profile?.fields, [\n 'email',\n 'firstName',\n 'lastName',\n ]);\n\n return {\n signInIdentifiersCsv: signInIdentifiers.join(','),\n signUpRequiredFieldsCsv: signUpRequiredFields.join(','),\n signUpOptionalFieldsCsv: signUpOptionalFields.join(','),\n signUpPolicy,\n profileFieldsCsv: profileFields.join(','),\n };\n}\n\nfunction normalizeFieldList(\n values: readonly string[] | undefined,\n fallback: readonly string[],\n): string[] {\n const source = values ?? fallback;\n const next: string[] = [];\n\n for (const value of source) {\n const normalized = value.trim();\n if (!normalized || next.includes(normalized)) {\n continue;\n }\n next.push(normalized);\n }\n\n if (next.length > 0) {\n return next;\n }\n\n return [...fallback];\n}\n\nfunction escapeYamlDoubleQuoted(value: string): string {\n return value.replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"');\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { InfraManifestInput } from '../../../../types';
|
|
2
|
-
export declare const MANAGED_PROFILE_COLUMNS: readonly ["email", "display_name", "first_name", "last_name", "avatar_url", "username", "phone"];
|
|
3
2
|
interface ProfileColumnSpec {
|
|
4
3
|
readonly field: string;
|
|
5
4
|
readonly column: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/profile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/profile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAoB5D,UAAU,iBAAiB;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC/C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,oBAAoB,CA2B9F;AAED,wBAAgB,gCAAgC,CAAC,YAAY,EAAE,oBAAoB,GAAG,MAAM,CAoT3F"}
|
|
@@ -6,7 +6,7 @@ const DEFAULT_PROFILE_UPDATE_STRATEGY = 'api';
|
|
|
6
6
|
const PROFILE_POLICY_VERSION = 1;
|
|
7
7
|
const PROFILE_RECONCILER_VERSION = 1;
|
|
8
8
|
const PROFILE_ARTIFACT_KEY = 'auth.profile';
|
|
9
|
-
|
|
9
|
+
const MANAGED_PROFILE_COLUMNS = [
|
|
10
10
|
'email',
|
|
11
11
|
'display_name',
|
|
12
12
|
'first_name',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,MAAM,sBAAsB,GA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xB,MAAM,IAAI,KAAK,CACb,gKAAgK,CACjK,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,8CAA8C,OAAO,sDAAsD,CAC5G,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\n\nimport type { InfraManifestInput } from '../../../../types';\n\nconst DEFAULT_PROFILE_FIELDS = ['email', 'firstName', 'lastName'];\nconst DEFAULT_PROFILE_PRIMARY_KEY = 'authUserId';\nconst DEFAULT_PROFILE_CREATE_STRATEGY = 'trigger';\nconst DEFAULT_PROFILE_UPDATE_STRATEGY = 'api';\nconst PROFILE_POLICY_VERSION = 1;\nconst PROFILE_RECONCILER_VERSION = 1;\nconst PROFILE_ARTIFACT_KEY = 'auth.profile';\n\nexport const MANAGED_PROFILE_COLUMNS = [\n 'email',\n 'display_name',\n 'first_name',\n 'last_name',\n 'avatar_url',\n 'username',\n 'phone',\n] as const;\n\ninterface ProfileColumnSpec {\n readonly field: string;\n readonly column: string;\n readonly sqlType: string;\n readonly fromNewUser: string;\n}\n\nexport interface ResolvedProfileModel {\n readonly enabled: boolean;\n readonly table: string;\n readonly primaryKey: string;\n readonly createStrategy: string;\n readonly updateStrategy: string;\n readonly columns: readonly ProfileColumnSpec[];\n readonly desiredStateHash: string;\n}\n\nexport function resolveSupabaseProfileModel(manifest: InfraManifestInput): ResolvedProfileModel {\n const table = normalizeIdentifier(manifest.auth?.profile?.table ?? '');\n const fields = normalizeFieldList(manifest.auth?.profile?.fields);\n const primaryKey = manifest.auth?.profile?.primaryKey ?? DEFAULT_PROFILE_PRIMARY_KEY;\n const createStrategy = manifest.auth?.profile?.createStrategy ?? DEFAULT_PROFILE_CREATE_STRATEGY;\n const updateStrategy = manifest.auth?.profile?.updateStrategy ?? DEFAULT_PROFILE_UPDATE_STRATEGY;\n const columns = resolveProfileColumns(fields);\n\n const hash = table\n ? getProfileDesiredStateHash({\n table,\n primaryKey,\n createStrategy,\n updateStrategy,\n columns,\n })\n : '';\n\n return {\n enabled: table.length > 0,\n table,\n primaryKey,\n createStrategy,\n updateStrategy,\n columns,\n desiredStateHash: hash,\n };\n}\n\nexport function getSupabaseProfileReconciliation(profileModel: ResolvedProfileModel): string {\n const table = quoteIdentifier(profileModel.table);\n const functionName = quoteIdentifier(`handle_new_${profileModel.table}_user`);\n const triggerName = quoteIdentifier(`on_auth_user_created_${profileModel.table}`);\n const configuredColumns = new Set(profileModel.columns.map((column) => column.column));\n const addColumnSql = profileModel.columns\n .map(\n (column) =>\n `alter table public.${table} add column if not exists ${quoteIdentifier(column.column)} ${column.sqlType};`,\n )\n .join('\\n');\n const dropStaleManagedColumnSql = MANAGED_PROFILE_COLUMNS.filter(\n (column) => !configuredColumns.has(column),\n )\n .map(\n (column) => `alter table public.${table} drop column if exists ${quoteIdentifier(column)};`,\n )\n .join('\\n');\n const insertColumns = ['id', ...profileModel.columns.map((column) => column.column)]\n .map(quoteIdentifier)\n .join(', ');\n const insertValues = ['new.id', ...profileModel.columns.map((column) => column.fromNewUser)].join(\n ', ',\n );\n const updateAssignments = profileModel.columns\n .filter((column) => column.field === 'email')\n .map(\n (column) => `${quoteIdentifier(column.column)} = excluded.${quoteIdentifier(column.column)}`,\n );\n const conflictUpdate = [...updateAssignments, 'updated_at = now()'].join(',\\n ');\n const updateGrantColumns = profileModel.columns.map((column) => quoteIdentifier(column.column));\n const updateGrantSql =\n updateGrantColumns.length > 0\n ? `grant update (${updateGrantColumns.join(', ')}) on table public.${table} to authenticated;`\n : '';\n const triggerSql =\n profileModel.createStrategy === 'trigger'\n ? `\ncreate or replace function public.${functionName}()\nreturns trigger\nlanguage plpgsql\nsecurity definer\nset search_path = pg_catalog, pg_temp\nas $$\nbegin\n insert into public.${table} (${insertColumns})\n values (${insertValues})\n on conflict (id) do update set\n ${conflictUpdate};\n\n return new;\nend;\n$$;\n\nrevoke execute on function public.${functionName}() from PUBLIC;\nrevoke execute on function public.${functionName}() from anon;\nrevoke execute on function public.${functionName}() from authenticated;\n\ndrop trigger if exists ${triggerName} on auth.users;\ncreate trigger ${triggerName}\n after insert on auth.users\n for each row execute function public.${functionName}();\n`\n : `\ndrop trigger if exists ${triggerName} on auth.users;\ndrop function if exists public.${functionName}();\n`;\n\n return `-- Generated by @ankhorage/infra from manifest.auth.profile.\n-- Desired-state reconciliation for local Supabase; not a migration-history entry.\n\nbegin;\n\ncreate schema if not exists ankhorage_internal;\n\ncreate table if not exists ankhorage_internal.generated_schema_state (\n artifact_key text primary key,\n table_name text,\n content_hash text not null,\n applied_at timestamptz not null\n);\n\nalter table ankhorage_internal.generated_schema_state\n add column if not exists table_name text;\n\ndo $$\ndeclare\n previous_table_name text;\n has_previous_state boolean;\nbegin\n select table_name, true\n into previous_table_name, has_previous_state\n from ankhorage_internal.generated_schema_state\n where artifact_key = '${PROFILE_ARTIFACT_KEY}';\n\n if has_previous_state and previous_table_name is null then\n raise exception 'existing auth.profile generated state is missing table identity; reset local Supabase or add an explicit cleanup migration before applying generated profile reconciliation';\n end if;\n\n if has_previous_state and previous_table_name <> '${escapeSqlLiteral(profileModel.table)}' then\n raise exception 'profile.table changed from % to %; reset local Supabase or add an explicit cleanup migration before applying generated profile reconciliation', previous_table_name, '${escapeSqlLiteral(profileModel.table)}';\n end if;\nend;\n$$;\n\ncreate table if not exists public.${table} (\n id uuid primary key references auth.users(id) on delete cascade,\n created_at timestamptz not null default now(),\n updated_at timestamptz not null default now()\n);\n\nalter table public.${table} add column if not exists id uuid;\nalter table public.${table} add column if not exists created_at timestamptz not null default now();\nalter table public.${table} add column if not exists updated_at timestamptz not null default now();\n${addColumnSql}\nalter table public.${table} drop column if exists role;\n${dropStaleManagedColumnSql}\n\ndo $$\nbegin\n if exists (\n select 1\n from pg_constraint c\n where c.conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and c.contype = 'p'\n and c.conkey <> array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n ) then\n raise exception 'profile table public.${escapeSqlLiteral(profileModel.table)} has a primary key that is not exactly id';\n end if;\n\n if not exists (\n select 1\n from pg_constraint\n where conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and contype = 'p'\n ) then\n alter table public.${table}\n add constraint ${quoteIdentifier(`${profileModel.table}_pkey`)} primary key (id);\n end if;\nend;\n$$;\n\ndo $$\nbegin\n if exists (\n select 1\n from pg_constraint c\n where c.conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and c.contype = 'f'\n and c.confrelid = 'auth.users'::regclass\n and c.conkey && array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n and (\n c.confdeltype <> 'c'\n or c.conkey <> array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n or c.confkey <> array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'auth.users'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n )\n ) then\n raise exception 'profile table public.${escapeSqlLiteral(profileModel.table)} has an auth.users foreign key that is not exactly id -> auth.users(id) on delete cascade';\n end if;\n\n if not exists (\n select 1\n from pg_constraint c\n where c.conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and c.confrelid = 'auth.users'::regclass\n and c.contype = 'f'\n and c.confdeltype = 'c'\n and c.conkey = array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n and c.confkey = array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'auth.users'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n ) then\n alter table public.${table}\n add constraint ${quoteIdentifier(`${profileModel.table}_id_auth_users_fkey`)}\n foreign key (id) references auth.users(id) on delete cascade;\n end if;\nend;\n$$;\n\ndo $$\nbegin\n if not exists (\n select 1\n from information_schema.columns c\n where c.table_schema = 'public'\n and c.table_name = '${escapeSqlLiteral(profileModel.table)}'\n and c.column_name = 'id'\n and c.udt_name = 'uuid'\n and c.is_nullable = 'NO'\n ) then\n raise exception 'profile id column must be uuid not null';\n end if;\n\n if not exists (\n select 1\n from information_schema.columns c\n where c.table_schema = 'public'\n and c.table_name = '${escapeSqlLiteral(profileModel.table)}'\n and c.column_name = 'created_at'\n and c.data_type = 'timestamp with time zone'\n and c.is_nullable = 'NO'\n and c.column_default = 'now()'\n ) then\n raise exception 'profile created_at column must be timestamptz not null default now()';\n end if;\n\n if not exists (\n select 1\n from information_schema.columns c\n where c.table_schema = 'public'\n and c.table_name = '${escapeSqlLiteral(profileModel.table)}'\n and c.column_name = 'updated_at'\n and c.data_type = 'timestamp with time zone'\n and c.is_nullable = 'NO'\n and c.column_default = 'now()'\n ) then\n raise exception 'profile updated_at column must be timestamptz not null default now()';\n end if;\nend;\n$$;\n\nalter table public.${table} enable row level security;\n\nrevoke all on table public.${table} from anon, authenticated;\ngrant select on table public.${table} to authenticated;\n${updateGrantSql}\n\ndrop policy if exists ${quoteIdentifier(`${profileModel.table}_select_own`)} on public.${table};\ncreate policy ${quoteIdentifier(`${profileModel.table}_select_own`)}\n on public.${table}\n for select\n to authenticated\n using ((select auth.uid()) = id);\n\ndrop policy if exists ${quoteIdentifier(`${profileModel.table}_update_own`)} on public.${table};\ncreate policy ${quoteIdentifier(`${profileModel.table}_update_own`)}\n on public.${table}\n for update\n to authenticated\n using ((select auth.uid()) = id)\n with check ((select auth.uid()) = id);\n${triggerSql}\ninsert into ankhorage_internal.generated_schema_state (\n artifact_key,\n table_name,\n content_hash,\n applied_at\n)\nvalues (\n '${PROFILE_ARTIFACT_KEY}',\n '${escapeSqlLiteral(profileModel.table)}',\n '${profileModel.desiredStateHash}',\n now()\n)\non conflict (artifact_key)\ndo update set\n table_name = excluded.table_name,\n content_hash = excluded.content_hash,\n applied_at = excluded.applied_at;\n\ncommit;\n`;\n}\n\nfunction mapProfileFieldToColumn(field: string): ProfileColumnSpec | null {\n switch (field) {\n case 'email':\n return { field, column: 'email', sqlType: 'text', fromNewUser: 'new.email' };\n case 'displayName':\n return {\n field,\n column: 'display_name',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'displayName', new.raw_user_meta_data->>'display_name', split_part(new.email, '@', 1))\",\n };\n case 'firstName':\n return {\n field,\n column: 'first_name',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'firstName', new.raw_user_meta_data->>'first_name')\",\n };\n case 'lastName':\n return {\n field,\n column: 'last_name',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'lastName', new.raw_user_meta_data->>'last_name')\",\n };\n case 'avatarUrl':\n return {\n field,\n column: 'avatar_url',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'avatarUrl', new.raw_user_meta_data->>'avatar_url')\",\n };\n case 'username':\n return {\n field,\n column: 'username',\n sqlType: 'text',\n fromNewUser: \"new.raw_user_meta_data->>'username'\",\n };\n case 'phone':\n return { field, column: 'phone', sqlType: 'text', fromNewUser: 'new.phone' };\n default:\n return null;\n }\n}\n\nfunction quoteIdentifier(value: string): string {\n return `\"${value.replaceAll('\"', '\"\"')}\"`;\n}\n\nfunction getProfileDesiredStateHash(args: {\n readonly table: string;\n readonly primaryKey: string;\n readonly createStrategy: string;\n readonly updateStrategy: string;\n readonly columns: readonly ProfileColumnSpec[];\n}): string {\n const state = {\n artifactKey: PROFILE_ARTIFACT_KEY,\n table: args.table,\n primaryKey: args.primaryKey,\n createStrategy: args.createStrategy,\n updateStrategy: args.updateStrategy,\n managedColumns: args.columns.map((column) => ({\n field: column.field,\n column: column.column,\n sqlType: column.sqlType,\n })),\n policyVersion: PROFILE_POLICY_VERSION,\n reconcilerVersion: PROFILE_RECONCILER_VERSION,\n };\n\n return createHash('sha256').update(JSON.stringify(state)).digest('hex');\n}\n\nfunction resolveProfileColumns(fields: readonly string[]): ProfileColumnSpec[] {\n const columns = new Map<string, ProfileColumnSpec>();\n\n for (const field of fields) {\n const column = mapProfileFieldToColumn(field);\n if (!column) {\n throw new Error(\n `Unsupported Supabase profile field \"${field}\". Supported fields: ${getSupportedProfileFields().join(', ')}.`,\n );\n }\n\n if (columns.has(column.column)) {\n continue;\n }\n columns.set(column.column, column);\n }\n\n return [...columns.values()].sort(\n (left, right) =>\n MANAGED_PROFILE_COLUMNS.indexOf(left.column as (typeof MANAGED_PROFILE_COLUMNS)[number]) -\n MANAGED_PROFILE_COLUMNS.indexOf(right.column as (typeof MANAGED_PROFILE_COLUMNS)[number]),\n );\n}\n\nfunction normalizeFieldList(values: readonly string[] | undefined): string[] {\n const source = values ?? DEFAULT_PROFILE_FIELDS;\n const next: string[] = [];\n\n for (const value of source) {\n const normalized = value.trim();\n if (!normalized) {\n throw new Error('Invalid Supabase profile field \"\". Profile fields must be non-empty.');\n }\n\n if (next.includes(normalized)) {\n continue;\n }\n next.push(normalized);\n }\n\n return next;\n}\n\nfunction getSupportedProfileFields(): string[] {\n return ['email', 'displayName', 'firstName', 'lastName', 'avatarUrl', 'username', 'phone'];\n}\n\nfunction normalizeIdentifier(value: string): string {\n const trimmed = value.trim();\n if (!trimmed) return '';\n\n if (trimmed === 'users') {\n throw new Error(\n 'Invalid Supabase profile table identifier \"users\". public.users is reserved for identity conflict detection; use a dedicated profile table such as \"profiles\".',\n );\n }\n\n if (!/^[a-z_][a-z0-9_]*$/.test(trimmed)) {\n throw new Error(\n `Invalid Supabase profile table identifier \"${trimmed}\". Use snake_case letters, numbers, and underscores.`,\n );\n }\n\n return trimmed;\n}\n\nfunction escapeSqlLiteral(value: string): string {\n return value.replaceAll(\"'\", \"''\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../../src/adapters/minikube/auth/supabase/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAClE,MAAM,2BAA2B,GAAG,YAAY,CAAC;AACjD,MAAM,+BAA+B,GAAG,SAAS,CAAC;AAClD,MAAM,+BAA+B,GAAG,KAAK,CAAC;AAC9C,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AACrC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAE5C,MAAM,uBAAuB,GAAG;IAC9B,OAAO;IACP,cAAc;IACd,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,UAAU;IACV,OAAO;CACC,CAAC;AAmBX,MAAM,UAAU,2BAA2B,CAAC,QAA4B;IACtE,MAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,kBAAkB,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAClE,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,IAAI,2BAA2B,CAAC;IACrF,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc,IAAI,+BAA+B,CAAC;IACjG,MAAM,cAAc,GAAG,Q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AAC,CAAC;IACxB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,yBAAyB;IAChC,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAC7F,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,gKAAgK,CACjK,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,8CAA8C,OAAO,sDAAsD,CAC5G,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\n\nimport type { InfraManifestInput } from '../../../../types';\n\nconst DEFAULT_PROFILE_FIELDS = ['email', 'firstName', 'lastName'];\nconst DEFAULT_PROFILE_PRIMARY_KEY = 'authUserId';\nconst DEFAULT_PROFILE_CREATE_STRATEGY = 'trigger';\nconst DEFAULT_PROFILE_UPDATE_STRATEGY = 'api';\nconst PROFILE_POLICY_VERSION = 1;\nconst PROFILE_RECONCILER_VERSION = 1;\nconst PROFILE_ARTIFACT_KEY = 'auth.profile';\n\nconst MANAGED_PROFILE_COLUMNS = [\n 'email',\n 'display_name',\n 'first_name',\n 'last_name',\n 'avatar_url',\n 'username',\n 'phone',\n] as const;\n\ninterface ProfileColumnSpec {\n readonly field: string;\n readonly column: string;\n readonly sqlType: string;\n readonly fromNewUser: string;\n}\n\nexport interface ResolvedProfileModel {\n readonly enabled: boolean;\n readonly table: string;\n readonly primaryKey: string;\n readonly createStrategy: string;\n readonly updateStrategy: string;\n readonly columns: readonly ProfileColumnSpec[];\n readonly desiredStateHash: string;\n}\n\nexport function resolveSupabaseProfileModel(manifest: InfraManifestInput): ResolvedProfileModel {\n const table = normalizeIdentifier(manifest.auth?.profile?.table ?? '');\n const fields = normalizeFieldList(manifest.auth?.profile?.fields);\n const primaryKey = manifest.auth?.profile?.primaryKey ?? DEFAULT_PROFILE_PRIMARY_KEY;\n const createStrategy = manifest.auth?.profile?.createStrategy ?? DEFAULT_PROFILE_CREATE_STRATEGY;\n const updateStrategy = manifest.auth?.profile?.updateStrategy ?? DEFAULT_PROFILE_UPDATE_STRATEGY;\n const columns = resolveProfileColumns(fields);\n\n const hash = table\n ? getProfileDesiredStateHash({\n table,\n primaryKey,\n createStrategy,\n updateStrategy,\n columns,\n })\n : '';\n\n return {\n enabled: table.length > 0,\n table,\n primaryKey,\n createStrategy,\n updateStrategy,\n columns,\n desiredStateHash: hash,\n };\n}\n\nexport function getSupabaseProfileReconciliation(profileModel: ResolvedProfileModel): string {\n const table = quoteIdentifier(profileModel.table);\n const functionName = quoteIdentifier(`handle_new_${profileModel.table}_user`);\n const triggerName = quoteIdentifier(`on_auth_user_created_${profileModel.table}`);\n const configuredColumns = new Set(profileModel.columns.map((column) => column.column));\n const addColumnSql = profileModel.columns\n .map(\n (column) =>\n `alter table public.${table} add column if not exists ${quoteIdentifier(column.column)} ${column.sqlType};`,\n )\n .join('\\n');\n const dropStaleManagedColumnSql = MANAGED_PROFILE_COLUMNS.filter(\n (column) => !configuredColumns.has(column),\n )\n .map(\n (column) => `alter table public.${table} drop column if exists ${quoteIdentifier(column)};`,\n )\n .join('\\n');\n const insertColumns = ['id', ...profileModel.columns.map((column) => column.column)]\n .map(quoteIdentifier)\n .join(', ');\n const insertValues = ['new.id', ...profileModel.columns.map((column) => column.fromNewUser)].join(\n ', ',\n );\n const updateAssignments = profileModel.columns\n .filter((column) => column.field === 'email')\n .map(\n (column) => `${quoteIdentifier(column.column)} = excluded.${quoteIdentifier(column.column)}`,\n );\n const conflictUpdate = [...updateAssignments, 'updated_at = now()'].join(',\\n ');\n const updateGrantColumns = profileModel.columns.map((column) => quoteIdentifier(column.column));\n const updateGrantSql =\n updateGrantColumns.length > 0\n ? `grant update (${updateGrantColumns.join(', ')}) on table public.${table} to authenticated;`\n : '';\n const triggerSql =\n profileModel.createStrategy === 'trigger'\n ? `\ncreate or replace function public.${functionName}()\nreturns trigger\nlanguage plpgsql\nsecurity definer\nset search_path = pg_catalog, pg_temp\nas $$\nbegin\n insert into public.${table} (${insertColumns})\n values (${insertValues})\n on conflict (id) do update set\n ${conflictUpdate};\n\n return new;\nend;\n$$;\n\nrevoke execute on function public.${functionName}() from PUBLIC;\nrevoke execute on function public.${functionName}() from anon;\nrevoke execute on function public.${functionName}() from authenticated;\n\ndrop trigger if exists ${triggerName} on auth.users;\ncreate trigger ${triggerName}\n after insert on auth.users\n for each row execute function public.${functionName}();\n`\n : `\ndrop trigger if exists ${triggerName} on auth.users;\ndrop function if exists public.${functionName}();\n`;\n\n return `-- Generated by @ankhorage/infra from manifest.auth.profile.\n-- Desired-state reconciliation for local Supabase; not a migration-history entry.\n\nbegin;\n\ncreate schema if not exists ankhorage_internal;\n\ncreate table if not exists ankhorage_internal.generated_schema_state (\n artifact_key text primary key,\n table_name text,\n content_hash text not null,\n applied_at timestamptz not null\n);\n\nalter table ankhorage_internal.generated_schema_state\n add column if not exists table_name text;\n\ndo $$\ndeclare\n previous_table_name text;\n has_previous_state boolean;\nbegin\n select table_name, true\n into previous_table_name, has_previous_state\n from ankhorage_internal.generated_schema_state\n where artifact_key = '${PROFILE_ARTIFACT_KEY}';\n\n if has_previous_state and previous_table_name is null then\n raise exception 'existing auth.profile generated state is missing table identity; reset local Supabase or add an explicit cleanup migration before applying generated profile reconciliation';\n end if;\n\n if has_previous_state and previous_table_name <> '${escapeSqlLiteral(profileModel.table)}' then\n raise exception 'profile.table changed from % to %; reset local Supabase or add an explicit cleanup migration before applying generated profile reconciliation', previous_table_name, '${escapeSqlLiteral(profileModel.table)}';\n end if;\nend;\n$$;\n\ncreate table if not exists public.${table} (\n id uuid primary key references auth.users(id) on delete cascade,\n created_at timestamptz not null default now(),\n updated_at timestamptz not null default now()\n);\n\nalter table public.${table} add column if not exists id uuid;\nalter table public.${table} add column if not exists created_at timestamptz not null default now();\nalter table public.${table} add column if not exists updated_at timestamptz not null default now();\n${addColumnSql}\nalter table public.${table} drop column if exists role;\n${dropStaleManagedColumnSql}\n\ndo $$\nbegin\n if exists (\n select 1\n from pg_constraint c\n where c.conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and c.contype = 'p'\n and c.conkey <> array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n ) then\n raise exception 'profile table public.${escapeSqlLiteral(profileModel.table)} has a primary key that is not exactly id';\n end if;\n\n if not exists (\n select 1\n from pg_constraint\n where conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and contype = 'p'\n ) then\n alter table public.${table}\n add constraint ${quoteIdentifier(`${profileModel.table}_pkey`)} primary key (id);\n end if;\nend;\n$$;\n\ndo $$\nbegin\n if exists (\n select 1\n from pg_constraint c\n where c.conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and c.contype = 'f'\n and c.confrelid = 'auth.users'::regclass\n and c.conkey && array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n and (\n c.confdeltype <> 'c'\n or c.conkey <> array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n or c.confkey <> array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'auth.users'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n )\n ) then\n raise exception 'profile table public.${escapeSqlLiteral(profileModel.table)} has an auth.users foreign key that is not exactly id -> auth.users(id) on delete cascade';\n end if;\n\n if not exists (\n select 1\n from pg_constraint c\n where c.conrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and c.confrelid = 'auth.users'::regclass\n and c.contype = 'f'\n and c.confdeltype = 'c'\n and c.conkey = array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'public.${escapeSqlLiteral(profileModel.table)}'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n and c.confkey = array[\n (\n select a.attnum\n from pg_attribute a\n where a.attrelid = 'auth.users'::regclass\n and a.attname = 'id'\n and not a.attisdropped\n )\n ]::smallint[]\n ) then\n alter table public.${table}\n add constraint ${quoteIdentifier(`${profileModel.table}_id_auth_users_fkey`)}\n foreign key (id) references auth.users(id) on delete cascade;\n end if;\nend;\n$$;\n\ndo $$\nbegin\n if not exists (\n select 1\n from information_schema.columns c\n where c.table_schema = 'public'\n and c.table_name = '${escapeSqlLiteral(profileModel.table)}'\n and c.column_name = 'id'\n and c.udt_name = 'uuid'\n and c.is_nullable = 'NO'\n ) then\n raise exception 'profile id column must be uuid not null';\n end if;\n\n if not exists (\n select 1\n from information_schema.columns c\n where c.table_schema = 'public'\n and c.table_name = '${escapeSqlLiteral(profileModel.table)}'\n and c.column_name = 'created_at'\n and c.data_type = 'timestamp with time zone'\n and c.is_nullable = 'NO'\n and c.column_default = 'now()'\n ) then\n raise exception 'profile created_at column must be timestamptz not null default now()';\n end if;\n\n if not exists (\n select 1\n from information_schema.columns c\n where c.table_schema = 'public'\n and c.table_name = '${escapeSqlLiteral(profileModel.table)}'\n and c.column_name = 'updated_at'\n and c.data_type = 'timestamp with time zone'\n and c.is_nullable = 'NO'\n and c.column_default = 'now()'\n ) then\n raise exception 'profile updated_at column must be timestamptz not null default now()';\n end if;\nend;\n$$;\n\nalter table public.${table} enable row level security;\n\nrevoke all on table public.${table} from anon, authenticated;\ngrant select on table public.${table} to authenticated;\n${updateGrantSql}\n\ndrop policy if exists ${quoteIdentifier(`${profileModel.table}_select_own`)} on public.${table};\ncreate policy ${quoteIdentifier(`${profileModel.table}_select_own`)}\n on public.${table}\n for select\n to authenticated\n using ((select auth.uid()) = id);\n\ndrop policy if exists ${quoteIdentifier(`${profileModel.table}_update_own`)} on public.${table};\ncreate policy ${quoteIdentifier(`${profileModel.table}_update_own`)}\n on public.${table}\n for update\n to authenticated\n using ((select auth.uid()) = id)\n with check ((select auth.uid()) = id);\n${triggerSql}\ninsert into ankhorage_internal.generated_schema_state (\n artifact_key,\n table_name,\n content_hash,\n applied_at\n)\nvalues (\n '${PROFILE_ARTIFACT_KEY}',\n '${escapeSqlLiteral(profileModel.table)}',\n '${profileModel.desiredStateHash}',\n now()\n)\non conflict (artifact_key)\ndo update set\n table_name = excluded.table_name,\n content_hash = excluded.content_hash,\n applied_at = excluded.applied_at;\n\ncommit;\n`;\n}\n\nfunction mapProfileFieldToColumn(field: string): ProfileColumnSpec | null {\n switch (field) {\n case 'email':\n return { field, column: 'email', sqlType: 'text', fromNewUser: 'new.email' };\n case 'displayName':\n return {\n field,\n column: 'display_name',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'displayName', new.raw_user_meta_data->>'display_name', split_part(new.email, '@', 1))\",\n };\n case 'firstName':\n return {\n field,\n column: 'first_name',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'firstName', new.raw_user_meta_data->>'first_name')\",\n };\n case 'lastName':\n return {\n field,\n column: 'last_name',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'lastName', new.raw_user_meta_data->>'last_name')\",\n };\n case 'avatarUrl':\n return {\n field,\n column: 'avatar_url',\n sqlType: 'text',\n fromNewUser:\n \"coalesce(new.raw_user_meta_data->>'avatarUrl', new.raw_user_meta_data->>'avatar_url')\",\n };\n case 'username':\n return {\n field,\n column: 'username',\n sqlType: 'text',\n fromNewUser: \"new.raw_user_meta_data->>'username'\",\n };\n case 'phone':\n return { field, column: 'phone', sqlType: 'text', fromNewUser: 'new.phone' };\n default:\n return null;\n }\n}\n\nfunction quoteIdentifier(value: string): string {\n return `\"${value.replaceAll('\"', '\"\"')}\"`;\n}\n\nfunction getProfileDesiredStateHash(args: {\n readonly table: string;\n readonly primaryKey: string;\n readonly createStrategy: string;\n readonly updateStrategy: string;\n readonly columns: readonly ProfileColumnSpec[];\n}): string {\n const state = {\n artifactKey: PROFILE_ARTIFACT_KEY,\n table: args.table,\n primaryKey: args.primaryKey,\n createStrategy: args.createStrategy,\n updateStrategy: args.updateStrategy,\n managedColumns: args.columns.map((column) => ({\n field: column.field,\n column: column.column,\n sqlType: column.sqlType,\n })),\n policyVersion: PROFILE_POLICY_VERSION,\n reconcilerVersion: PROFILE_RECONCILER_VERSION,\n };\n\n return createHash('sha256').update(JSON.stringify(state)).digest('hex');\n}\n\nfunction resolveProfileColumns(fields: readonly string[]): ProfileColumnSpec[] {\n const columns = new Map<string, ProfileColumnSpec>();\n\n for (const field of fields) {\n const column = mapProfileFieldToColumn(field);\n if (!column) {\n throw new Error(\n `Unsupported Supabase profile field \"${field}\". Supported fields: ${getSupportedProfileFields().join(', ')}.`,\n );\n }\n\n if (columns.has(column.column)) {\n continue;\n }\n columns.set(column.column, column);\n }\n\n return [...columns.values()].sort(\n (left, right) =>\n MANAGED_PROFILE_COLUMNS.indexOf(left.column as (typeof MANAGED_PROFILE_COLUMNS)[number]) -\n MANAGED_PROFILE_COLUMNS.indexOf(right.column as (typeof MANAGED_PROFILE_COLUMNS)[number]),\n );\n}\n\nfunction normalizeFieldList(values: readonly string[] | undefined): string[] {\n const source = values ?? DEFAULT_PROFILE_FIELDS;\n const next: string[] = [];\n\n for (const value of source) {\n const normalized = value.trim();\n if (!normalized) {\n throw new Error('Invalid Supabase profile field \"\". Profile fields must be non-empty.');\n }\n\n if (next.includes(normalized)) {\n continue;\n }\n next.push(normalized);\n }\n\n return next;\n}\n\nfunction getSupportedProfileFields(): string[] {\n return ['email', 'displayName', 'firstName', 'lastName', 'avatarUrl', 'username', 'phone'];\n}\n\nfunction normalizeIdentifier(value: string): string {\n const trimmed = value.trim();\n if (!trimmed) return '';\n\n if (trimmed === 'users') {\n throw new Error(\n 'Invalid Supabase profile table identifier \"users\". public.users is reserved for identity conflict detection; use a dedicated profile table such as \"profiles\".',\n );\n }\n\n if (!/^[a-z_][a-z0-9_]*$/.test(trimmed)) {\n throw new Error(\n `Invalid Supabase profile table identifier \"${trimmed}\". Use snake_case letters, numbers, and underscores.`,\n );\n }\n\n return trimmed;\n}\n\nfunction escapeSqlLiteral(value: string): string {\n return value.replaceAll(\"'\", \"''\");\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/minikube/authz/cerbos/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAkC,MAAM,sBAAsB,CAAC;AAGxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/minikube/authz/cerbos/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAkC,MAAM,sBAAsB,CAAC;AAGxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,wBAAwB,EAA6B,MAAM,iBAAiB,CAAC;AAI3F,wBAAgB,4BAA4B,CAAC,IAAI,EAAE;IACjD,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,GAAG,wBAAwB,CAuD3B;AA2GD,KAAK,iBAAiB,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC,GAAG;IACjF,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC9B,CAAC"}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { resolveAuthFlow } from '@ankhorage/contracts/auth';
|
|
2
|
+
const CERBOS_NAMESPACE = 'cerbos';
|
|
2
3
|
export function generateCerbosAuthzArtifacts(args) {
|
|
3
|
-
const { manifest,
|
|
4
|
+
const { manifest, appManifest } = args;
|
|
5
|
+
const namespace = CERBOS_NAMESPACE;
|
|
4
6
|
const root = 'infra/minikube/k8s/authz/cerbos';
|
|
5
7
|
const resourceRoot = 'authz/cerbos';
|
|
6
8
|
const intent = buildCerbosPolicyIntent({ manifest, appManifest });
|
|
9
|
+
const endpointUrl = `http://cerbos.${namespace}.svc.cluster.local:3592`;
|
|
10
|
+
const lifecycle = {
|
|
11
|
+
id: 'cerbos',
|
|
12
|
+
namespace,
|
|
13
|
+
endpoints: [{ name: 'http', url: endpointUrl }],
|
|
14
|
+
readinessChecks: [
|
|
15
|
+
{
|
|
16
|
+
label: 'cerbos',
|
|
17
|
+
namespace,
|
|
18
|
+
resource: 'deployment/cerbos',
|
|
19
|
+
timeoutSeconds: 180,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
migrationCommands: [],
|
|
23
|
+
reconciliationCommands: [],
|
|
24
|
+
statusChecks: [],
|
|
25
|
+
};
|
|
7
26
|
return {
|
|
8
27
|
files: [
|
|
9
28
|
{
|
|
@@ -29,7 +48,8 @@ export function generateCerbosAuthzArtifacts(args) {
|
|
|
29
48
|
`${resourceRoot}/cerbos.deployment.yaml`,
|
|
30
49
|
`${resourceRoot}/cerbos.service.yaml`,
|
|
31
50
|
],
|
|
32
|
-
|
|
51
|
+
providerLifecycle: [lifecycle],
|
|
52
|
+
envEntries: [`CERBOS_URL=${endpointUrl}`],
|
|
33
53
|
warnings: [],
|
|
34
54
|
};
|
|
35
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/adapters/minikube/authz/cerbos/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAK5D,MAAM,UAAU,4BAA4B,CAAC,IAI5C;IACC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAElD,MAAM,IAAI,GAAG,iCAAiC,CAAC;IAC/C,MAAM,YAAY,GAAG,cAAc,CAAC;IACpC,MAAM,MAAM,GAAG,uBAAuB,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;IAElE,OAAO;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE,GAAG,IAAI,wBAAwB;gBACrC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC;aACvC;YACD;gBACE,IAAI,EAAE,GAAG,IAAI,+BAA+B;gBAC5C,OAAO,EAAE,wBAAwB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;aACzD;YACD;gBACE,IAAI,EAAE,GAAG,IAAI,yBAAyB;gBACtC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC;aACxC;YACD;gBACE,IAAI,EAAE,GAAG,IAAI,sBAAsB;gBACnC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC;aACrC;SACF;QACD,SAAS,EAAE;YACT,GAAG,YAAY,wBAAwB;YACvC,GAAG,YAAY,+BAA+B;YAC9C,GAAG,YAAY,yBAAyB;YACxC,GAAG,YAAY,sBAAsB;SACtC;QACD,UAAU,EAAE,CAAC,+BAA+B,CAAC;QAC7C,QAAQ,EAAE,EAAE;KACb,CAAC;AACJ,CAAC;AAED,SAAS,kBA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NavigatorSpec, RouteDefinition } from '@ankhorage/contracts';\nimport { resolveAuthFlow } from '@ankhorage/contracts/auth';\n\nimport type { InfraManifestInput } from '../../../../types';\nimport type { MinikubeAdapterArtifacts } from '../../contracts';\n\nexport function generateCerbosAuthzArtifacts(args: {\n manifest: InfraManifestInput;\n namespace: string;\n appManifest?: CerbosAppManifest;\n}): MinikubeAdapterArtifacts {\n const { manifest, namespace, appManifest } = args;\n\n const root = 'infra/minikube/k8s/authz/cerbos';\n const resourceRoot = 'authz/cerbos';\n const intent = buildCerbosPolicyIntent({ manifest, appManifest });\n\n return {\n files: [\n {\n path: `${root}/cerbos.configmap.yaml`,\n content: getCerbosConfigMap(namespace),\n },\n {\n path: `${root}/cerbos.policy.configmap.yaml`,\n content: getCerbosPolicyConfigMap({ namespace, intent }),\n },\n {\n path: `${root}/cerbos.deployment.yaml`,\n content: getCerbosDeployment(namespace),\n },\n {\n path: `${root}/cerbos.service.yaml`,\n content: getCerbosService(namespace),\n },\n ],\n resources: [\n `${resourceRoot}/cerbos.configmap.yaml`,\n `${resourceRoot}/cerbos.policy.configmap.yaml`,\n `${resourceRoot}/cerbos.deployment.yaml`,\n `${resourceRoot}/cerbos.service.yaml`,\n ],\n envEntries: ['CERBOS_URL=http://cerbos:3592'],\n warnings: [],\n };\n}\n\nfunction getCerbosConfigMap(namespace: string) {\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cerbos-config\n namespace: ${namespace}\ndata:\n config.yaml: |\n server:\n httpListenAddr: \":3592\"\n storage:\n driver: \"disk\"\n disk:\n directory: /policies\n`;\n}\n\nfunction getCerbosPolicyConfigMap(args: { namespace: string; intent: CerbosPolicyIntent }) {\n const { namespace, intent } = args;\n const entries = getCerbosPolicyEntries(intent);\n const renderedEntries = entries\n .map((entry) => {\n const indented = indentLines(entry.content, 4);\n return ` ${entry.key}: |\n${indented}`;\n })\n .join('\\n');\n\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cerbos-policy\n namespace: ${namespace}\ndata:\n${renderedEntries}\n`;\n}\n\nfunction getCerbosDeployment(namespace: string) {\n return `apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: cerbos\n namespace: ${namespace}\n labels:\n app.kubernetes.io/name: cerbos\nspec:\n replicas: 1\n selector:\n matchLabels:\n app.kubernetes.io/name: cerbos\n template:\n metadata:\n labels:\n app.kubernetes.io/name: cerbos\n spec:\n containers:\n - name: cerbos\n image: ghcr.io/cerbos/cerbos:0.40.0\n args:\n - server\n - --config=/config/config.yaml\n ports:\n - containerPort: 3592\n volumeMounts:\n - name: cerbos-config\n mountPath: /config\n - name: cerbos-policy\n mountPath: /policies\n volumes:\n - name: cerbos-config\n configMap:\n name: cerbos-config\n - name: cerbos-policy\n configMap:\n name: cerbos-policy\n`;\n}\n\nfunction getCerbosService(namespace: string) {\n return `apiVersion: v1\nkind: Service\nmetadata:\n name: cerbos\n namespace: ${namespace}\nspec:\n selector:\n app.kubernetes.io/name: cerbos\n ports:\n - name: http\n port: 3592\n targetPort: 3592\n`;\n}\n\nconst PUBLIC_GUARD_HINTS = new Set(['public', 'guest', 'anonymous', 'unauthenticated']);\nconst AUTH_GUARD_HINTS = new Set([\n 'auth',\n 'authenticated',\n 'private',\n 'protected',\n 'requiresauth',\n 'requires-auth',\n]);\n\ntype CerbosAppManifest = Pick<AppManifest, 'metadata' | 'navigator' | 'screens'> & {\n infra?: AppManifest['infra'];\n};\n\ntype AuthScope = NonNullable<InfraManifestInput['auth']>['scope'] | 'none';\n\ninterface CerbosRouteIntent {\n name: string;\n guards: string[];\n screenId?: string;\n}\n\ninterface CerbosPolicyIntent {\n authScope: AuthScope;\n publicRoutes: string[];\n protectedRoutes: string[];\n publicScreens: string[];\n protectedScreens: string[];\n}\n\ninterface CerbosPolicyEntry {\n key: string;\n content: string;\n}\n\nfunction getCerbosPolicyEntries(intent: CerbosPolicyIntent): CerbosPolicyEntry[] {\n const entries: CerbosPolicyEntry[] = [\n {\n key: 'app.resource_policy.yaml',\n content: getAppPolicy(intent),\n },\n ];\n\n if (intent.publicRoutes.length > 0 || intent.protectedRoutes.length > 0) {\n entries.push({\n key: 'route.resource_policy.yaml',\n content: getRoutePolicy(intent),\n });\n }\n\n if (intent.publicScreens.length > 0 || intent.protectedScreens.length > 0) {\n entries.push({\n key: 'screen.resource_policy.yaml',\n content: getScreenPolicy(intent),\n });\n }\n\n return entries;\n}\n\nfunction getAppPolicy(intent: CerbosPolicyIntent): string {\n const roles = intent.authScope === 'global' ? ['authenticated'] : ['anonymous', 'authenticated'];\n\n return `apiVersion: api.cerbos.dev/v1\nresourcePolicy:\n version: \"default\"\n resource: \"app\"\n rules:\n${indentLines(renderRule({ actions: ['*'], roles }), 4)}\n`;\n}\n\nfunction getRoutePolicy(intent: CerbosPolicyIntent): string {\n const rules: string[] = [];\n\n if (intent.publicRoutes.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'navigate'],\n roles: ['anonymous', 'authenticated'],\n conditionExpr: getInConditionExpr('route', intent.publicRoutes),\n }),\n );\n }\n\n if (intent.protectedRoutes.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'navigate'],\n roles: ['authenticated'],\n conditionExpr: getInConditionExpr('route', intent.protectedRoutes),\n }),\n );\n }\n\n return `apiVersion: api.cerbos.dev/v1\nresourcePolicy:\n version: \"default\"\n resource: \"route\"\n rules:\n${indentLines(rules.join('\\n'), 4)}\n`;\n}\n\nfunction getScreenPolicy(intent: CerbosPolicyIntent): string {\n const rules: string[] = [];\n\n if (intent.publicScreens.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'render'],\n roles: ['anonymous', 'authenticated'],\n conditionExpr: getInConditionExpr('screen_id', intent.publicScreens),\n }),\n );\n }\n\n if (intent.protectedScreens.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'render'],\n roles: ['authenticated'],\n conditionExpr: getInConditionExpr('screen_id', intent.protectedScreens),\n }),\n );\n }\n\n return `apiVersion: api.cerbos.dev/v1\nresourcePolicy:\n version: \"default\"\n resource: \"screen\"\n rules:\n${indentLines(rules.join('\\n'), 4)}\n`;\n}\n\nfunction renderRule(args: { actions: string[]; roles: string[]; conditionExpr?: string }): string {\n const { actions, roles, conditionExpr } = args;\n\n const lines = [\n `- actions: ${JSON.stringify(actions)}`,\n ' effect: EFFECT_ALLOW',\n ` roles: ${JSON.stringify(roles)}`,\n ];\n\n if (conditionExpr) {\n lines.push(' condition:');\n lines.push(' match:');\n lines.push(` expr: ${JSON.stringify(conditionExpr)}`);\n }\n\n return lines.join('\\n');\n}\n\nfunction getInConditionExpr(attribute: string, values: string[]): string {\n return `request.resource.attr.${attribute} in ${JSON.stringify(values)}`;\n}\n\nfunction indentLines(content: string, spaces: number): string {\n const prefix = ' '.repeat(spaces);\n return content\n .trimEnd()\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n');\n}\n\nfunction buildCerbosPolicyIntent(args: {\n manifest: InfraManifestInput;\n appManifest?: CerbosAppManifest;\n}): CerbosPolicyIntent {\n const { manifest, appManifest } = args;\n const authScope = manifest.auth?.scope ?? 'none';\n\n const routes = appManifest?.navigator ? flattenNavigatorRoutes(appManifest.navigator) : [];\n const flow = resolveAuthFlow(appManifest?.infra?.auth?.flow);\n const { signInRoute } = flow;\n const { signUpRoute } = flow;\n const { unauthorizedRoute } = flow;\n\n const publicRouteSet = new Set<string>();\n const protectedRouteSet = new Set<string>();\n\n for (const route of routes) {\n const isPublic = isPublicRoute({\n route,\n authScope,\n signInRoute,\n signUpRoute,\n unauthorizedRoute,\n });\n\n if (isPublic) {\n publicRouteSet.add(route.name);\n } else {\n protectedRouteSet.add(route.name);\n }\n }\n\n const screenVisibility = new Map<string, 'public' | 'protected'>();\n for (const route of routes) {\n if (!route.screenId) continue;\n const isPublic = publicRouteSet.has(route.name);\n\n const current = screenVisibility.get(route.screenId);\n if (current === 'protected') continue;\n screenVisibility.set(route.screenId, isPublic ? 'public' : 'protected');\n }\n\n if (appManifest?.screens) {\n const defaultVisibility: 'public' | 'protected' =\n authScope === 'global' ? 'protected' : 'public';\n\n for (const screenId of Object.keys(appManifest.screens)) {\n if (!screenVisibility.has(screenId)) {\n screenVisibility.set(screenId, defaultVisibility);\n }\n }\n }\n\n const publicScreens = [...screenVisibility.entries()]\n .filter(([, visibility]) => visibility === 'public')\n .map(([screenId]) => screenId)\n .sort();\n const protectedScreens = [...screenVisibility.entries()]\n .filter(([, visibility]) => visibility === 'protected')\n .map(([screenId]) => screenId)\n .sort();\n\n return {\n authScope,\n publicRoutes: [...publicRouteSet].sort(),\n protectedRoutes: [...protectedRouteSet].sort(),\n publicScreens,\n protectedScreens,\n };\n}\n\nfunction flattenNavigatorRoutes(navigator: NavigatorSpec): CerbosRouteIntent[] {\n const deduped = new Map<string, CerbosRouteIntent>();\n\n const walk = (current: NavigatorSpec) => {\n for (const route of current.routes) {\n const normalizedGuards = normalizeGuards(route.guards);\n const existing = deduped.get(route.name);\n deduped.set(route.name, {\n name: route.name,\n guards: unique([...(existing?.guards ?? []), ...normalizedGuards]),\n screenId: route.screenId ?? existing?.screenId,\n });\n\n if (route.navigator) {\n walk(route.navigator);\n }\n }\n };\n\n walk(navigator);\n return [...deduped.values()];\n}\n\nfunction normalizeGuards(guards?: RouteDefinition['guards']): string[] {\n return (guards ?? []).map((guard) => guard.trim().toLowerCase()).filter(Boolean);\n}\n\nfunction isPublicRoute(args: {\n route: CerbosRouteIntent;\n authScope: AuthScope;\n signInRoute?: string;\n signUpRoute?: string;\n unauthorizedRoute?: string;\n}): boolean {\n const { route, authScope, signInRoute, signUpRoute, unauthorizedRoute } = args;\n const guardSet = new Set(route.guards);\n const signInRouteName = authFlowPathToRouteName(signInRoute);\n const signUpRouteName = authFlowPathToRouteName(signUpRoute);\n const unauthorizedRouteName = authFlowPathToRouteName(unauthorizedRoute);\n\n if (\n route.name === signInRouteName ||\n route.name === signUpRouteName ||\n route.name === unauthorizedRouteName\n ) {\n return true;\n }\n\n if (hasAny(guardSet, PUBLIC_GUARD_HINTS)) {\n return true;\n }\n\n if (hasAny(guardSet, AUTH_GUARD_HINTS)) {\n return false;\n }\n\n switch (authScope) {\n case 'none':\n return true;\n case 'global':\n default:\n return false;\n }\n}\n\nfunction hasAny(values: Set<string>, candidates: Set<string>): boolean {\n for (const candidate of candidates) {\n if (values.has(candidate)) return true;\n }\n return false;\n}\n\nfunction unique(values: string[]): string[] {\n return [...new Set(values)];\n}\n\nfunction authFlowPathToRouteName(routePath: string | undefined): string | undefined {\n if (!routePath) {\n return undefined;\n }\n\n const normalized = routePath.trim().replace(/^\\/+/, '').replace(/\\/+$/, '');\n return normalized === '' ? 'index' : normalized;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/adapters/minikube/authz/cerbos/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAK5D,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC,MAAM,UAAU,4BAA4B,CAAC,IAI5C;IACC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACvC,MAAM,SAAS,GAAG,gBAAgB,CAAC;IAEnC,MAAM,IAAI,GAAG,iCAAiC,CAAC;IAC/C,MAAM,YAAY,GAAG,cAAc,CAAC;IACpC,MAAM,MAAM,GAAG,uBAAuB,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;IAElE,MAAM,WAAW,GAAG,iBAAiB,SAAS,yBAAyB,CAAC;IACxE,MAAM,SAAS,GAA8B;QAC3C,EAAE,EAAE,QAAQ;QACZ,SAAS;QACT,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC;QAC/C,eAAe,EAAE;YACf;gBACE,KAAK,EAAE,QAAQ;gBACf,SAAS;gBACT,QAAQ,EAAE,mBAAmB;gBAC7B,cAAc,EAAE,GAAG;aACpB;SACF;QACD,iBAAiB,EAAE,EAAE;QACr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ACT,OAAO,IAAI,CAAC;QACd,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,MAAmB,EAAE,UAAuB;IAC1D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,OAAO,IAAI,CAAC;IACzC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAC,MAAgB;IAC9B,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,uBAAuB,CAAC,SAA6B;IAC5D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5E,OAAO,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;AAClD,CAAC","sourcesContent":["import type { AppManifest, NavigatorSpec, RouteDefinition } from '@ankhorage/contracts';\nimport { resolveAuthFlow } from '@ankhorage/contracts/auth';\n\nimport type { InfraManifestInput } from '../../../../types';\nimport type { MinikubeAdapterArtifacts, MinikubeProviderLifecycle } from '../../contracts';\n\nconst CERBOS_NAMESPACE = 'cerbos';\n\nexport function generateCerbosAuthzArtifacts(args: {\n manifest: InfraManifestInput;\n namespace: string;\n appManifest?: CerbosAppManifest;\n}): MinikubeAdapterArtifacts {\n const { manifest, appManifest } = args;\n const namespace = CERBOS_NAMESPACE;\n\n const root = 'infra/minikube/k8s/authz/cerbos';\n const resourceRoot = 'authz/cerbos';\n const intent = buildCerbosPolicyIntent({ manifest, appManifest });\n\n const endpointUrl = `http://cerbos.${namespace}.svc.cluster.local:3592`;\n const lifecycle: MinikubeProviderLifecycle = {\n id: 'cerbos',\n namespace,\n endpoints: [{ name: 'http', url: endpointUrl }],\n readinessChecks: [\n {\n label: 'cerbos',\n namespace,\n resource: 'deployment/cerbos',\n timeoutSeconds: 180,\n },\n ],\n migrationCommands: [],\n reconciliationCommands: [],\n statusChecks: [],\n };\n\n return {\n files: [\n {\n path: `${root}/cerbos.configmap.yaml`,\n content: getCerbosConfigMap(namespace),\n },\n {\n path: `${root}/cerbos.policy.configmap.yaml`,\n content: getCerbosPolicyConfigMap({ namespace, intent }),\n },\n {\n path: `${root}/cerbos.deployment.yaml`,\n content: getCerbosDeployment(namespace),\n },\n {\n path: `${root}/cerbos.service.yaml`,\n content: getCerbosService(namespace),\n },\n ],\n resources: [\n `${resourceRoot}/cerbos.configmap.yaml`,\n `${resourceRoot}/cerbos.policy.configmap.yaml`,\n `${resourceRoot}/cerbos.deployment.yaml`,\n `${resourceRoot}/cerbos.service.yaml`,\n ],\n providerLifecycle: [lifecycle],\n envEntries: [`CERBOS_URL=${endpointUrl}`],\n warnings: [],\n };\n}\n\nfunction getCerbosConfigMap(namespace: string) {\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cerbos-config\n namespace: ${namespace}\ndata:\n config.yaml: |\n server:\n httpListenAddr: \":3592\"\n storage:\n driver: \"disk\"\n disk:\n directory: /policies\n`;\n}\n\nfunction getCerbosPolicyConfigMap(args: { namespace: string; intent: CerbosPolicyIntent }) {\n const { namespace, intent } = args;\n const entries = getCerbosPolicyEntries(intent);\n const renderedEntries = entries\n .map((entry) => {\n const indented = indentLines(entry.content, 4);\n return ` ${entry.key}: |\n${indented}`;\n })\n .join('\\n');\n\n return `apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cerbos-policy\n namespace: ${namespace}\ndata:\n${renderedEntries}\n`;\n}\n\nfunction getCerbosDeployment(namespace: string) {\n return `apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: cerbos\n namespace: ${namespace}\n labels:\n app.kubernetes.io/name: cerbos\nspec:\n replicas: 1\n selector:\n matchLabels:\n app.kubernetes.io/name: cerbos\n template:\n metadata:\n labels:\n app.kubernetes.io/name: cerbos\n spec:\n containers:\n - name: cerbos\n image: ghcr.io/cerbos/cerbos:0.40.0\n args:\n - server\n - --config=/config/config.yaml\n ports:\n - containerPort: 3592\n volumeMounts:\n - name: cerbos-config\n mountPath: /config\n - name: cerbos-policy\n mountPath: /policies\n volumes:\n - name: cerbos-config\n configMap:\n name: cerbos-config\n - name: cerbos-policy\n configMap:\n name: cerbos-policy\n`;\n}\n\nfunction getCerbosService(namespace: string) {\n return `apiVersion: v1\nkind: Service\nmetadata:\n name: cerbos\n namespace: ${namespace}\nspec:\n selector:\n app.kubernetes.io/name: cerbos\n ports:\n - name: http\n port: 3592\n targetPort: 3592\n`;\n}\n\nconst PUBLIC_GUARD_HINTS = new Set(['public', 'guest', 'anonymous', 'unauthenticated']);\nconst AUTH_GUARD_HINTS = new Set([\n 'auth',\n 'authenticated',\n 'private',\n 'protected',\n 'requiresauth',\n 'requires-auth',\n]);\n\ntype CerbosAppManifest = Pick<AppManifest, 'metadata' | 'navigator' | 'screens'> & {\n infra?: AppManifest['infra'];\n};\n\ntype AuthScope = NonNullable<InfraManifestInput['auth']>['scope'] | 'none';\n\ninterface CerbosRouteIntent {\n name: string;\n guards: string[];\n screenId?: string;\n}\n\ninterface CerbosPolicyIntent {\n authScope: AuthScope;\n publicRoutes: string[];\n protectedRoutes: string[];\n publicScreens: string[];\n protectedScreens: string[];\n}\n\ninterface CerbosPolicyEntry {\n key: string;\n content: string;\n}\n\nfunction getCerbosPolicyEntries(intent: CerbosPolicyIntent): CerbosPolicyEntry[] {\n const entries: CerbosPolicyEntry[] = [\n {\n key: 'app.resource_policy.yaml',\n content: getAppPolicy(intent),\n },\n ];\n\n if (intent.publicRoutes.length > 0 || intent.protectedRoutes.length > 0) {\n entries.push({\n key: 'route.resource_policy.yaml',\n content: getRoutePolicy(intent),\n });\n }\n\n if (intent.publicScreens.length > 0 || intent.protectedScreens.length > 0) {\n entries.push({\n key: 'screen.resource_policy.yaml',\n content: getScreenPolicy(intent),\n });\n }\n\n return entries;\n}\n\nfunction getAppPolicy(intent: CerbosPolicyIntent): string {\n const roles = intent.authScope === 'global' ? ['authenticated'] : ['anonymous', 'authenticated'];\n\n return `apiVersion: api.cerbos.dev/v1\nresourcePolicy:\n version: \"default\"\n resource: \"app\"\n rules:\n${indentLines(renderRule({ actions: ['*'], roles }), 4)}\n`;\n}\n\nfunction getRoutePolicy(intent: CerbosPolicyIntent): string {\n const rules: string[] = [];\n\n if (intent.publicRoutes.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'navigate'],\n roles: ['anonymous', 'authenticated'],\n conditionExpr: getInConditionExpr('route', intent.publicRoutes),\n }),\n );\n }\n\n if (intent.protectedRoutes.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'navigate'],\n roles: ['authenticated'],\n conditionExpr: getInConditionExpr('route', intent.protectedRoutes),\n }),\n );\n }\n\n return `apiVersion: api.cerbos.dev/v1\nresourcePolicy:\n version: \"default\"\n resource: \"route\"\n rules:\n${indentLines(rules.join('\\n'), 4)}\n`;\n}\n\nfunction getScreenPolicy(intent: CerbosPolicyIntent): string {\n const rules: string[] = [];\n\n if (intent.publicScreens.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'render'],\n roles: ['anonymous', 'authenticated'],\n conditionExpr: getInConditionExpr('screen_id', intent.publicScreens),\n }),\n );\n }\n\n if (intent.protectedScreens.length > 0) {\n rules.push(\n renderRule({\n actions: ['view', 'render'],\n roles: ['authenticated'],\n conditionExpr: getInConditionExpr('screen_id', intent.protectedScreens),\n }),\n );\n }\n\n return `apiVersion: api.cerbos.dev/v1\nresourcePolicy:\n version: \"default\"\n resource: \"screen\"\n rules:\n${indentLines(rules.join('\\n'), 4)}\n`;\n}\n\nfunction renderRule(args: { actions: string[]; roles: string[]; conditionExpr?: string }): string {\n const { actions, roles, conditionExpr } = args;\n\n const lines = [\n `- actions: ${JSON.stringify(actions)}`,\n ' effect: EFFECT_ALLOW',\n ` roles: ${JSON.stringify(roles)}`,\n ];\n\n if (conditionExpr) {\n lines.push(' condition:');\n lines.push(' match:');\n lines.push(` expr: ${JSON.stringify(conditionExpr)}`);\n }\n\n return lines.join('\\n');\n}\n\nfunction getInConditionExpr(attribute: string, values: string[]): string {\n return `request.resource.attr.${attribute} in ${JSON.stringify(values)}`;\n}\n\nfunction indentLines(content: string, spaces: number): string {\n const prefix = ' '.repeat(spaces);\n return content\n .trimEnd()\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n');\n}\n\nfunction buildCerbosPolicyIntent(args: {\n manifest: InfraManifestInput;\n appManifest?: CerbosAppManifest;\n}): CerbosPolicyIntent {\n const { manifest, appManifest } = args;\n const authScope = manifest.auth?.scope ?? 'none';\n\n const routes = appManifest?.navigator ? flattenNavigatorRoutes(appManifest.navigator) : [];\n const flow = resolveAuthFlow(appManifest?.infra?.auth?.flow);\n const { signInRoute } = flow;\n const { signUpRoute } = flow;\n const { unauthorizedRoute } = flow;\n\n const publicRouteSet = new Set<string>();\n const protectedRouteSet = new Set<string>();\n\n for (const route of routes) {\n const isPublic = isPublicRoute({\n route,\n authScope,\n signInRoute,\n signUpRoute,\n unauthorizedRoute,\n });\n\n if (isPublic) {\n publicRouteSet.add(route.name);\n } else {\n protectedRouteSet.add(route.name);\n }\n }\n\n const screenVisibility = new Map<string, 'public' | 'protected'>();\n for (const route of routes) {\n if (!route.screenId) continue;\n const isPublic = publicRouteSet.has(route.name);\n\n const current = screenVisibility.get(route.screenId);\n if (current === 'protected') continue;\n screenVisibility.set(route.screenId, isPublic ? 'public' : 'protected');\n }\n\n if (appManifest?.screens) {\n const defaultVisibility: 'public' | 'protected' =\n authScope === 'global' ? 'protected' : 'public';\n\n for (const screenId of Object.keys(appManifest.screens)) {\n if (!screenVisibility.has(screenId)) {\n screenVisibility.set(screenId, defaultVisibility);\n }\n }\n }\n\n const publicScreens = [...screenVisibility.entries()]\n .filter(([, visibility]) => visibility === 'public')\n .map(([screenId]) => screenId)\n .sort();\n const protectedScreens = [...screenVisibility.entries()]\n .filter(([, visibility]) => visibility === 'protected')\n .map(([screenId]) => screenId)\n .sort();\n\n return {\n authScope,\n publicRoutes: [...publicRouteSet].sort(),\n protectedRoutes: [...protectedRouteSet].sort(),\n publicScreens,\n protectedScreens,\n };\n}\n\nfunction flattenNavigatorRoutes(navigator: NavigatorSpec): CerbosRouteIntent[] {\n const deduped = new Map<string, CerbosRouteIntent>();\n\n const walk = (current: NavigatorSpec) => {\n for (const route of current.routes) {\n const normalizedGuards = normalizeGuards(route.guards);\n const existing = deduped.get(route.name);\n deduped.set(route.name, {\n name: route.name,\n guards: unique([...(existing?.guards ?? []), ...normalizedGuards]),\n screenId: route.screenId ?? existing?.screenId,\n });\n\n if (route.navigator) {\n walk(route.navigator);\n }\n }\n };\n\n walk(navigator);\n return [...deduped.values()];\n}\n\nfunction normalizeGuards(guards?: RouteDefinition['guards']): string[] {\n return (guards ?? []).map((guard) => guard.trim().toLowerCase()).filter(Boolean);\n}\n\nfunction isPublicRoute(args: {\n route: CerbosRouteIntent;\n authScope: AuthScope;\n signInRoute?: string;\n signUpRoute?: string;\n unauthorizedRoute?: string;\n}): boolean {\n const { route, authScope, signInRoute, signUpRoute, unauthorizedRoute } = args;\n const guardSet = new Set(route.guards);\n const signInRouteName = authFlowPathToRouteName(signInRoute);\n const signUpRouteName = authFlowPathToRouteName(signUpRoute);\n const unauthorizedRouteName = authFlowPathToRouteName(unauthorizedRoute);\n\n if (\n route.name === signInRouteName ||\n route.name === signUpRouteName ||\n route.name === unauthorizedRouteName\n ) {\n return true;\n }\n\n if (hasAny(guardSet, PUBLIC_GUARD_HINTS)) {\n return true;\n }\n\n if (hasAny(guardSet, AUTH_GUARD_HINTS)) {\n return false;\n }\n\n switch (authScope) {\n case 'none':\n return true;\n case 'global':\n default:\n return false;\n }\n}\n\nfunction hasAny(values: Set<string>, candidates: Set<string>): boolean {\n for (const candidate of candidates) {\n if (values.has(candidate)) return true;\n }\n return false;\n}\n\nfunction unique(values: string[]): string[] {\n return [...new Set(values)];\n}\n\nfunction authFlowPathToRouteName(routePath: string | undefined): string | undefined {\n if (!routePath) {\n return undefined;\n }\n\n const normalized = routePath.trim().replace(/^\\/+/, '').replace(/\\/+$/, '');\n return normalized === '' ? 'index' : normalized;\n}\n"]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { GeneratedInfrastructureFile } from '../../../types';
|
|
2
2
|
import type { InfraManifestInput } from '../../../types';
|
|
3
|
+
import type { MinikubeProviderLifecycle } from '../contracts';
|
|
4
|
+
export declare const APP_NAMESPACE = "app";
|
|
3
5
|
export declare function generateMinikubeBaseArtifacts(args: {
|
|
4
6
|
manifest: InfraManifestInput;
|
|
5
|
-
|
|
6
|
-
supabaseProjectId: string | null;
|
|
7
|
+
appSlug: string;
|
|
7
8
|
extraResources: string[];
|
|
9
|
+
providerNamespaces: string[];
|
|
10
|
+
providerLifecycle: MinikubeProviderLifecycle[];
|
|
8
11
|
extraEnvEntries: string[];
|
|
9
12
|
}): GeneratedInfrastructureFile[];
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/minikube/base/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/minikube/base/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9D,eAAO,MAAM,aAAa,QAAQ,CAAC;AAoDnC,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IAClD,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,iBAAiB,EAAE,yBAAyB,EAAE,CAAC;IAC/C,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,GAAG,2BAA2B,EAAE,CAoLhC"}
|