swallowkit 1.0.0-beta.55 → 1.0.0-beta.57
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/dist/cli/commands/add-auth.d.ts.map +1 -1
- package/dist/cli/commands/add-auth.js +154 -157
- package/dist/cli/commands/add-auth.js.map +1 -1
- package/dist/cli/commands/init.d.ts +5 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +178 -25
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +7 -2
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +113 -123
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +127 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +8 -4
- package/dist/core/config.js.map +1 -1
- package/dist/core/operations/auth-operations.d.ts +57 -0
- package/dist/core/operations/auth-operations.d.ts.map +1 -0
- package/dist/core/operations/auth-operations.js +269 -0
- package/dist/core/operations/auth-operations.js.map +1 -0
- package/dist/core/operations/create-model.d.ts.map +1 -1
- package/dist/core/operations/create-model.js +23 -13
- package/dist/core/operations/create-model.js.map +1 -1
- package/dist/core/operations/file-session.d.ts +56 -0
- package/dist/core/operations/file-session.d.ts.map +1 -0
- package/dist/core/operations/file-session.js +203 -0
- package/dist/core/operations/file-session.js.map +1 -0
- package/dist/core/operations/provision-operations.d.ts +52 -0
- package/dist/core/operations/provision-operations.d.ts.map +1 -0
- package/dist/core/operations/provision-operations.js +211 -0
- package/dist/core/operations/provision-operations.js.map +1 -0
- package/dist/core/operations/runtime.d.ts +5 -0
- package/dist/core/operations/runtime.d.ts.map +1 -1
- package/dist/core/operations/runtime.js +23 -0
- package/dist/core/operations/runtime.js.map +1 -1
- package/dist/core/operations/scaffold-apply.d.ts +21 -0
- package/dist/core/operations/scaffold-apply.d.ts.map +1 -0
- package/dist/core/operations/scaffold-apply.js +57 -0
- package/dist/core/operations/scaffold-apply.js.map +1 -0
- package/dist/core/operations/scaffold-machine.d.ts.map +1 -1
- package/dist/core/operations/scaffold-machine.js +1 -13
- package/dist/core/operations/scaffold-machine.js.map +1 -1
- package/dist/core/operations/scaffold-plan.d.ts +43 -0
- package/dist/core/operations/scaffold-plan.d.ts.map +1 -0
- package/dist/core/operations/scaffold-plan.js +187 -0
- package/dist/core/operations/scaffold-plan.js.map +1 -0
- package/dist/core/project/artifacts.d.ts +58 -0
- package/dist/core/project/artifacts.d.ts.map +1 -0
- package/dist/core/project/artifacts.js +179 -0
- package/dist/core/project/artifacts.js.map +1 -0
- package/dist/core/project/boundaries.d.ts +50 -0
- package/dist/core/project/boundaries.d.ts.map +1 -0
- package/dist/core/project/boundaries.js +117 -0
- package/dist/core/project/boundaries.js.map +1 -0
- package/dist/core/project/drift.d.ts +29 -0
- package/dist/core/project/drift.d.ts.map +1 -0
- package/dist/core/project/drift.js +188 -0
- package/dist/core/project/drift.js.map +1 -0
- package/dist/core/project/infra.d.ts +49 -0
- package/dist/core/project/infra.d.ts.map +1 -0
- package/dist/core/project/infra.js +167 -0
- package/dist/core/project/infra.js.map +1 -0
- package/dist/core/project/state.d.ts +15 -0
- package/dist/core/project/state.d.ts.map +1 -0
- package/dist/core/project/state.js +106 -0
- package/dist/core/project/state.js.map +1 -0
- package/dist/core/project/workflows.d.ts +43 -0
- package/dist/core/project/workflows.d.ts.map +1 -0
- package/dist/core/project/workflows.js +255 -0
- package/dist/core/project/workflows.js.map +1 -0
- package/dist/core/scaffold/auth-generator.d.ts.map +1 -1
- package/dist/core/scaffold/auth-generator.js +24 -27
- package/dist/core/scaffold/auth-generator.js.map +1 -1
- package/dist/core/scaffold/functions-generator.js +9 -9
- package/dist/core/scaffold/native-schema-generator.d.ts +7 -1
- package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -1
- package/dist/core/scaffold/native-schema-generator.js +104 -47
- package/dist/core/scaffold/native-schema-generator.js.map +1 -1
- package/dist/core/scaffold/nextjs-generator.js +6 -6
- package/dist/core/scaffold/ui-generator.js +19 -19
- package/dist/core/scaffold/ui-generator.js.map +1 -1
- package/dist/core/verify/index.d.ts +62 -0
- package/dist/core/verify/index.d.ts.map +1 -0
- package/dist/core/verify/index.js +343 -0
- package/dist/core/verify/index.js.map +1 -0
- package/dist/machine/contracts.d.ts +8 -0
- package/dist/machine/contracts.d.ts.map +1 -1
- package/dist/machine/errors.d.ts +4 -1
- package/dist/machine/errors.d.ts.map +1 -1
- package/dist/machine/errors.js +9 -1
- package/dist/machine/errors.js.map +1 -1
- package/dist/machine/index.d.ts.map +1 -1
- package/dist/machine/index.js +350 -16
- package/dist/machine/index.js.map +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +202 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +17 -17
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +6 -6
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +11 -11
- package/src/__tests__/agent-loop-phase34.test.ts +449 -0
- package/src/__tests__/file-session.test.ts +98 -0
- package/src/__tests__/init.test.ts +50 -0
- package/src/__tests__/mcp.test.ts +113 -5
- package/src/__tests__/plan-apply.test.ts +461 -0
- package/src/__tests__/scaffold.test.ts +2 -2
- package/src/cli/commands/add-auth.ts +164 -164
- package/src/cli/commands/init.ts +186 -24
- package/src/cli/commands/scaffold.ts +136 -130
- package/src/cli/index.ts +148 -2
- package/src/core/config.ts +5 -4
- package/src/core/operations/auth-operations.ts +353 -0
- package/src/core/operations/create-model.ts +25 -13
- package/src/core/operations/file-session.ts +222 -0
- package/src/core/operations/provision-operations.ts +297 -0
- package/src/core/operations/runtime.ts +23 -0
- package/src/core/operations/scaffold-apply.ts +106 -0
- package/src/core/operations/scaffold-machine.ts +2 -16
- package/src/core/operations/scaffold-plan.ts +215 -0
- package/src/core/project/artifacts.ts +205 -0
- package/src/core/project/boundaries.ts +170 -0
- package/src/core/project/drift.ts +202 -0
- package/src/core/project/infra.ts +196 -0
- package/src/core/project/state.ts +77 -0
- package/src/core/project/workflows.ts +249 -0
- package/src/core/scaffold/auth-generator.ts +24 -27
- package/src/core/scaffold/functions-generator.ts +9 -9
- package/src/core/scaffold/native-schema-generator.ts +152 -70
- package/src/core/scaffold/nextjs-generator.ts +6 -6
- package/src/core/scaffold/ui-generator.ts +19 -19
- package/src/core/verify/index.ts +392 -0
- package/src/machine/contracts.ts +16 -0
- package/src/machine/errors.ts +12 -1
- package/src/machine/index.ts +444 -15
- package/src/mcp/index.ts +198 -2
- package/src/types/index.ts +17 -0
|
@@ -45,12 +45,17 @@ const path = __importStar(require("path"));
|
|
|
45
45
|
const config_1 = require("../../core/config");
|
|
46
46
|
const auth_generator_1 = require("../../core/scaffold/auth-generator");
|
|
47
47
|
const manifest_1 = require("../../core/project/manifest");
|
|
48
|
+
const file_session_1 = require("../../core/operations/file-session");
|
|
49
|
+
const artifacts_1 = require("../../core/project/artifacts");
|
|
48
50
|
const init_1 = require("./init");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
const AUTH_GENERATOR = "add-auth";
|
|
52
|
+
const managedMeta = { ownership: "managed", generator: AUTH_GENERATOR };
|
|
53
|
+
const extensionMeta = { ownership: "extension-point", generator: AUTH_GENERATOR };
|
|
54
|
+
const onceMeta = { ownership: "generated-once", generator: AUTH_GENERATOR };
|
|
55
|
+
function writeIfMissing(session, filePath, content) {
|
|
56
|
+
if (session.fileExists(filePath))
|
|
51
57
|
return;
|
|
52
|
-
|
|
53
|
-
fs.writeFileSync(filePath, content, "utf-8");
|
|
58
|
+
session.writeFile(filePath, content, onceMeta);
|
|
54
59
|
}
|
|
55
60
|
function defaultCustomJwtConfig() {
|
|
56
61
|
return {
|
|
@@ -63,78 +68,71 @@ function defaultCustomJwtConfig() {
|
|
|
63
68
|
tokenExpiry: "24h",
|
|
64
69
|
};
|
|
65
70
|
}
|
|
66
|
-
function setupSwaAuth(cwd, backendLanguage) {
|
|
71
|
+
function setupSwaAuth(cwd, backendLanguage, session) {
|
|
67
72
|
const helperPath = backendLanguage === "typescript"
|
|
68
73
|
? path.join(cwd, "functions", "src", "auth", "jwt-helper.ts")
|
|
69
74
|
: backendLanguage === "csharp"
|
|
70
75
|
? path.join(cwd, "functions", "Auth", "JwtHelper.cs")
|
|
71
76
|
: path.join(cwd, "functions", "auth", "jwt_helper.py");
|
|
72
|
-
fs.mkdirSync(path.dirname(helperPath), { recursive: true });
|
|
73
77
|
const helper = backendLanguage === "typescript"
|
|
74
78
|
? (0, auth_generator_1.generateSwaAuthHelperTS)()
|
|
75
79
|
: backendLanguage === "csharp"
|
|
76
80
|
? (0, auth_generator_1.generateSwaAuthHelperCSharp)()
|
|
77
81
|
: (0, auth_generator_1.generateSwaAuthHelperPython)();
|
|
78
|
-
|
|
82
|
+
session.writeFile(helperPath, helper, managedMeta);
|
|
79
83
|
const callFnPath = path.join(cwd, "lib", "api", "call-function.ts");
|
|
80
|
-
|
|
81
|
-
fs.writeFileSync(callFnPath, (0, auth_generator_1.generateBFFCallFunctionWithSwaAuth)(), "utf-8");
|
|
84
|
+
session.writeFile(callFnPath, (0, auth_generator_1.generateBFFCallFunctionWithSwaAuth)(), managedMeta);
|
|
82
85
|
const authDir = path.join(cwd, "lib", "auth");
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
updateRootLayoutWithAuthProvider(cwd);
|
|
86
|
+
session.writeFile(path.join(authDir, "auth-context.tsx"), generateSwaAuthContext(), managedMeta);
|
|
87
|
+
updateRootLayoutWithAuthProvider(cwd, session);
|
|
86
88
|
const loginDir = path.join(cwd, "app", "login");
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
updateSwaRouteConfig(cwd);
|
|
89
|
+
session.writeFile(path.join(loginDir, "page.tsx"), generateSwaLoginPage(), managedMeta);
|
|
90
|
+
updateSwaRouteConfig(cwd, session);
|
|
90
91
|
}
|
|
91
|
-
function setupExternalTokenAuth(cwd, backendLanguage) {
|
|
92
|
+
function setupExternalTokenAuth(cwd, backendLanguage, session) {
|
|
92
93
|
const authDir = path.join(cwd, "lib", "auth");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
fs.writeFileSync(path.join(cwd, "lib", "api", "call-function.ts"), (0, auth_generator_1.generateBFFCallFunctionWithAuth)(), "utf-8");
|
|
94
|
+
writeIfMissing(session, path.join(authDir, "external-token-adapter.ts"), (0, auth_generator_1.generateExternalTokenAdapter)());
|
|
95
|
+
session.writeFile(path.join(authDir, "authenticated-fetch.ts"), (0, auth_generator_1.generateAuthenticatedFetch)(), managedMeta);
|
|
96
|
+
session.writeFile(path.join(authDir, "auth-context.tsx"), (0, auth_generator_1.generateExternalTokenAuthContext)(), managedMeta);
|
|
97
|
+
session.writeFile(path.join(cwd, "lib", "api", "call-function.ts"), (0, auth_generator_1.generateBFFCallFunctionWithAuth)(), managedMeta);
|
|
98
98
|
const meDir = path.join(cwd, "app", "api", "auth", "me");
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
updateRootLayoutWithAuthProvider(cwd);
|
|
99
|
+
session.writeFile(path.join(meDir, "route.ts"), (0, auth_generator_1.generateExternalTokenBFFMeRoute)(), managedMeta);
|
|
100
|
+
updateRootLayoutWithAuthProvider(cwd, session);
|
|
102
101
|
if (backendLanguage === "typescript") {
|
|
103
102
|
const verifier = path.join(cwd, "functions", "src", "auth", "external-token-verifier.ts");
|
|
104
|
-
writeIfMissing(verifier, (0, auth_generator_1.generateExternalTokenVerifierTS)());
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
writeIfMissing(session, verifier, (0, auth_generator_1.generateExternalTokenVerifierTS)());
|
|
104
|
+
session.writeFile(path.join(cwd, "functions", "src", "auth", "jwt-helper.ts"), (0, auth_generator_1.generateExternalTokenHelperTS)(), managedMeta);
|
|
105
|
+
session.writeFile(path.join(cwd, "functions", "src", "auth-me.ts"), (0, auth_generator_1.generateExternalAuthMeTS)(), managedMeta);
|
|
107
106
|
}
|
|
108
107
|
else if (backendLanguage === "csharp") {
|
|
109
108
|
const verifier = path.join(cwd, "functions", "Auth", "ExternalTokenVerifier.cs");
|
|
110
|
-
writeIfMissing(verifier, (0, auth_generator_1.generateExternalTokenVerifierCSharp)());
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
writeIfMissing(session, verifier, (0, auth_generator_1.generateExternalTokenVerifierCSharp)());
|
|
110
|
+
session.writeFile(path.join(cwd, "functions", "Auth", "JwtHelper.cs"), (0, auth_generator_1.generateExternalTokenHelperCSharp)(), managedMeta);
|
|
111
|
+
session.writeFile(path.join(cwd, "functions", "Auth", "ExternalAuthMe.cs"), (0, auth_generator_1.generateExternalAuthMeCSharp)(), managedMeta);
|
|
113
112
|
}
|
|
114
113
|
else {
|
|
115
114
|
const verifier = path.join(cwd, "functions", "auth", "external_token_verifier.py");
|
|
116
|
-
writeIfMissing(verifier, (0, auth_generator_1.generateExternalTokenVerifierPython)());
|
|
117
|
-
|
|
115
|
+
writeIfMissing(session, verifier, (0, auth_generator_1.generateExternalTokenVerifierPython)());
|
|
116
|
+
session.writeFile(path.join(cwd, "functions", "auth", "jwt_helper.py"), (0, auth_generator_1.generateExternalTokenHelperPython)(), managedMeta);
|
|
118
117
|
const authMePath = path.join(cwd, "functions", "blueprints", "auth_me.py");
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
updatePythonAuthMeRegistration(cwd);
|
|
118
|
+
session.writeFile(authMePath, (0, auth_generator_1.generateExternalAuthMePython)(), managedMeta);
|
|
119
|
+
updatePythonAuthMeRegistration(cwd, session);
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
|
-
function updatePythonAuthMeRegistration(cwd) {
|
|
122
|
+
function updatePythonAuthMeRegistration(cwd, session) {
|
|
125
123
|
const appPath = path.join(cwd, "functions", "function_app.py");
|
|
126
|
-
if (!
|
|
124
|
+
if (!session.fileExists(appPath))
|
|
127
125
|
return;
|
|
128
126
|
const importLine = "from blueprints.auth_me import bp as external_auth_me_bp";
|
|
129
127
|
const registerLine = "app.register_blueprint(external_auth_me_bp)";
|
|
130
|
-
let content =
|
|
128
|
+
let content = session.readFile(appPath);
|
|
131
129
|
if (content.includes(importLine))
|
|
132
130
|
return;
|
|
133
131
|
const marker = "# SwallowKit scaffold registrations";
|
|
134
132
|
content = content.includes(marker)
|
|
135
133
|
? content.replace(marker, `${importLine}\n${registerLine}\n${marker}`)
|
|
136
134
|
: `${content.trimEnd()}\n${importLine}\n${registerLine}\n`;
|
|
137
|
-
|
|
135
|
+
session.writeFile(appPath, content, extensionMeta);
|
|
138
136
|
}
|
|
139
137
|
function generateSwaLoginPage() {
|
|
140
138
|
return `'use client';
|
|
@@ -199,25 +197,25 @@ function addAuthProviderToRootLayout(layout) {
|
|
|
199
197
|
}
|
|
200
198
|
return updated;
|
|
201
199
|
}
|
|
202
|
-
function updateRootLayoutWithAuthProvider(cwd) {
|
|
200
|
+
function updateRootLayoutWithAuthProvider(cwd, session) {
|
|
203
201
|
const layoutPath = path.join(cwd, "app", "layout.tsx");
|
|
204
|
-
if (!
|
|
202
|
+
if (!session.fileExists(layoutPath)) {
|
|
205
203
|
throw new Error("app/layout.tsx was not found; cannot install AuthProvider");
|
|
206
204
|
}
|
|
207
|
-
const layout =
|
|
205
|
+
const layout = session.readFile(layoutPath);
|
|
208
206
|
const updated = addAuthProviderToRootLayout(layout);
|
|
209
207
|
if (updated !== layout)
|
|
210
|
-
|
|
208
|
+
session.writeFile(layoutPath, updated, extensionMeta);
|
|
211
209
|
}
|
|
212
|
-
function updateSwaRouteConfig(cwd) {
|
|
210
|
+
function updateSwaRouteConfig(cwd, session) {
|
|
213
211
|
const configPath = path.join(cwd, "staticwebapp.config.json");
|
|
214
|
-
const config =
|
|
212
|
+
const config = session.fileExists(configPath) ? JSON.parse(session.readFile(configPath)) : {};
|
|
215
213
|
config.routes = Array.isArray(config.routes)
|
|
216
214
|
? config.routes.filter((route) => route.route !== "/api/*")
|
|
217
215
|
: [];
|
|
218
216
|
config.routes.unshift({ route: "/api/*", allowedRoles: ["authenticated"] });
|
|
219
217
|
config.responseOverrides = { ...(config.responseOverrides || {}), "401": { statusCode: 302, redirect: "/.auth/login/aad?post_login_redirect_uri=.referrer" } };
|
|
220
|
-
|
|
218
|
+
session.writeFile(configPath, JSON.stringify(config, null, 2), extensionMeta);
|
|
221
219
|
}
|
|
222
220
|
async function addAuthCommand(options) {
|
|
223
221
|
(0, config_1.ensureSwallowKitProject)("add-auth");
|
|
@@ -230,13 +228,21 @@ async function addAuthCommand(options) {
|
|
|
230
228
|
const backendLanguage = (0, config_1.getBackendLanguage)();
|
|
231
229
|
const config = (0, config_1.getValidatedFullConfig)();
|
|
232
230
|
const cwd = process.cwd();
|
|
231
|
+
// Plan(dry-run) や Apply からセッションが供給される。単体実行時は commit セッションを生成。
|
|
232
|
+
const session = (0, file_session_1.getActiveFileSession)() ?? new file_session_1.FileOperationSession("commit");
|
|
233
|
+
const finalize = async () => {
|
|
234
|
+
if (session.mode === "commit") {
|
|
235
|
+
(0, artifacts_1.recordSessionOperations)(session.operations);
|
|
236
|
+
await (0, manifest_1.syncProjectManifest)();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
233
239
|
if (options.scheme) {
|
|
234
240
|
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(options.scheme))
|
|
235
241
|
throw new Error("--scheme must start with a letter and contain only letters, digits, '_' or '-'");
|
|
236
242
|
if (provider === "none" || provider === "swa-custom")
|
|
237
243
|
throw new Error(`Provider '${provider}' cannot be added as a named scheme`);
|
|
238
|
-
addNamedScheme(cwd, options.scheme, provider, backendLanguage);
|
|
239
|
-
await (
|
|
244
|
+
addNamedScheme(cwd, options.scheme, provider, backendLanguage, session);
|
|
245
|
+
await finalize();
|
|
240
246
|
console.log(`\n Named authentication scheme '${options.scheme}' added.`);
|
|
241
247
|
return;
|
|
242
248
|
}
|
|
@@ -244,22 +250,22 @@ async function addAuthCommand(options) {
|
|
|
244
250
|
throw new Error("The swa-custom provider is not implemented. Use --provider swa or --provider custom-jwt.");
|
|
245
251
|
}
|
|
246
252
|
if (provider === "none") {
|
|
247
|
-
updateConfigWithAuth(cwd, provider, config.auth?.customJwt || defaultCustomJwtConfig());
|
|
248
|
-
await (
|
|
253
|
+
updateConfigWithAuth(cwd, provider, config.auth?.customJwt || defaultCustomJwtConfig(), session);
|
|
254
|
+
await finalize();
|
|
249
255
|
console.log(" Authentication disabled in swallowkit.config.js");
|
|
250
256
|
return;
|
|
251
257
|
}
|
|
252
258
|
if (provider === "swa") {
|
|
253
|
-
setupSwaAuth(cwd, backendLanguage);
|
|
254
|
-
updateConfigWithAuth(cwd, provider, config.auth?.customJwt || defaultCustomJwtConfig());
|
|
255
|
-
await (
|
|
259
|
+
setupSwaAuth(cwd, backendLanguage, session);
|
|
260
|
+
updateConfigWithAuth(cwd, provider, config.auth?.customJwt || defaultCustomJwtConfig(), session);
|
|
261
|
+
await finalize();
|
|
256
262
|
console.log("\n SWA built-in authentication setup complete!");
|
|
257
263
|
return;
|
|
258
264
|
}
|
|
259
265
|
if (provider === "external-token") {
|
|
260
|
-
setupExternalTokenAuth(cwd, backendLanguage);
|
|
261
|
-
updateConfigWithAuth(cwd, provider, config.auth?.customJwt || defaultCustomJwtConfig());
|
|
262
|
-
await (
|
|
266
|
+
setupExternalTokenAuth(cwd, backendLanguage, session);
|
|
267
|
+
updateConfigWithAuth(cwd, provider, config.auth?.customJwt || defaultCustomJwtConfig(), session);
|
|
268
|
+
await finalize();
|
|
263
269
|
console.log("\n External token authentication setup complete!");
|
|
264
270
|
console.log(" Implement the generated frontend adapter and backend verifier before use.");
|
|
265
271
|
return;
|
|
@@ -281,57 +287,52 @@ async function addAuthCommand(options) {
|
|
|
281
287
|
// 1. Generate shared/models/auth.ts
|
|
282
288
|
console.log(" Generating auth models...");
|
|
283
289
|
const modelsDir = path.join(cwd, "shared", "models");
|
|
284
|
-
fs.mkdirSync(modelsDir, { recursive: true });
|
|
285
290
|
const authModelPath = path.join(modelsDir, "auth.ts");
|
|
286
|
-
|
|
291
|
+
session.writeFile(authModelPath, (0, auth_generator_1.generateAuthModels)(), managedMeta);
|
|
287
292
|
console.log(` Created: shared/models/auth.ts`);
|
|
288
293
|
// Ensure shared package has build infrastructure (tsconfig, build script)
|
|
289
|
-
ensureSharedBuildInfrastructure(cwd);
|
|
294
|
+
ensureSharedBuildInfrastructure(cwd, session);
|
|
290
295
|
// Update shared/index.ts to re-export auth
|
|
291
|
-
updateSharedIndex(cwd);
|
|
296
|
+
updateSharedIndex(cwd, session);
|
|
292
297
|
// Resolve RDB provider for dependency installation
|
|
293
298
|
const connDef = (0, config_1.getConnectorDefinition)(customJwtConfig.userConnector);
|
|
294
299
|
const rdbProvider = connDef?.provider ?? "mysql";
|
|
295
300
|
// 2. Generate Functions auth code
|
|
296
301
|
console.log("\n Generating auth functions...");
|
|
297
|
-
generateFunctionsAuth(cwd, backendLanguage, sharedPackageName, customJwtConfig);
|
|
302
|
+
generateFunctionsAuth(cwd, backendLanguage, sharedPackageName, customJwtConfig, session);
|
|
298
303
|
// 3. Generate BFF auth routes
|
|
299
304
|
console.log("\n Generating BFF auth routes...");
|
|
300
|
-
generateBFFAuth(cwd, projectName, sharedPackageName);
|
|
305
|
+
generateBFFAuth(cwd, projectName, sharedPackageName, session);
|
|
301
306
|
// 4. Generate proxy
|
|
302
307
|
console.log("\n Generating proxy...");
|
|
303
308
|
const proxyPath = path.join(cwd, "proxy.ts");
|
|
304
|
-
|
|
309
|
+
session.writeFile(proxyPath, (0, auth_generator_1.generateProxy)(projectName), managedMeta);
|
|
305
310
|
console.log(` Created: proxy.ts`);
|
|
306
311
|
// 5. Generate login page
|
|
307
312
|
console.log("\n Generating login page...");
|
|
308
313
|
const loginDir = path.join(cwd, "app", "login");
|
|
309
|
-
|
|
310
|
-
fs.writeFileSync(path.join(loginDir, "page.tsx"), (0, auth_generator_1.generateLoginPage)(), "utf-8");
|
|
314
|
+
session.writeFile(path.join(loginDir, "page.tsx"), (0, auth_generator_1.generateLoginPage)(), managedMeta);
|
|
311
315
|
console.log(` Created: app/login/page.tsx`);
|
|
312
316
|
// 6. Generate auth context
|
|
313
317
|
console.log("\n Generating auth context...");
|
|
314
318
|
const authLibDir = path.join(cwd, "lib", "auth");
|
|
315
|
-
|
|
316
|
-
fs.writeFileSync(path.join(authLibDir, "auth-context.tsx"), (0, auth_generator_1.generateAuthContext)(), "utf-8");
|
|
319
|
+
session.writeFile(path.join(authLibDir, "auth-context.tsx"), (0, auth_generator_1.generateAuthContext)(), managedMeta);
|
|
317
320
|
console.log(`✅ Created: lib/auth/auth-context.tsx`);
|
|
318
321
|
// 7. Update callFunction with auth support
|
|
319
322
|
console.log("\n Updating callFunction with auth support...");
|
|
320
323
|
const callFnPath = path.join(cwd, "lib", "api", "call-function.ts");
|
|
321
|
-
|
|
322
|
-
fs.mkdirSync(callFnDir, { recursive: true });
|
|
323
|
-
fs.writeFileSync(callFnPath, (0, auth_generator_1.generateBFFCallFunctionWithAuth)(), "utf-8");
|
|
324
|
+
session.writeFile(callFnPath, (0, auth_generator_1.generateBFFCallFunctionWithAuth)(), managedMeta);
|
|
324
325
|
console.log(` Updated: lib/api/call-function.ts`);
|
|
325
326
|
// 8. Update swallowkit.config.js
|
|
326
327
|
console.log("\n Updating configuration...");
|
|
327
|
-
updateConfigWithAuth(cwd, provider, customJwtConfig);
|
|
328
|
+
updateConfigWithAuth(cwd, provider, customJwtConfig, session);
|
|
328
329
|
// 9. Update environment files
|
|
329
330
|
console.log("\n Updating environment files...");
|
|
330
|
-
updateEnvironmentFiles(cwd);
|
|
331
|
+
updateEnvironmentFiles(cwd, session);
|
|
331
332
|
// 10. Install dependencies
|
|
332
333
|
console.log("\n Installing auth dependencies...");
|
|
333
|
-
await installAuthDependencies(cwd, backendLanguage, rdbProvider);
|
|
334
|
-
await (
|
|
334
|
+
await installAuthDependencies(cwd, backendLanguage, rdbProvider, session);
|
|
335
|
+
await finalize();
|
|
335
336
|
console.log("\n Authentication setup complete!");
|
|
336
337
|
console.log("\n Next steps:");
|
|
337
338
|
console.log(" 1. Review the generated files");
|
|
@@ -363,25 +364,25 @@ function findObjectEnd(content, open) {
|
|
|
363
364
|
}
|
|
364
365
|
return -1;
|
|
365
366
|
}
|
|
366
|
-
function updateConfigWithNamedScheme(cwd, scheme, provider) {
|
|
367
|
+
function updateConfigWithNamedScheme(cwd, scheme, provider, session) {
|
|
367
368
|
var _a, _b;
|
|
368
369
|
const jsPath = path.join(cwd, "swallowkit.config.js");
|
|
369
370
|
const jsonPath = path.join(cwd, "swallowkit.config.json");
|
|
370
|
-
const configPath =
|
|
371
|
-
if (!
|
|
371
|
+
const configPath = session.fileExists(jsPath) ? jsPath : jsonPath;
|
|
372
|
+
if (!session.fileExists(configPath))
|
|
372
373
|
throw new Error("swallowkit.config.js or swallowkit.config.json is required");
|
|
373
374
|
if (configPath.endsWith(".json")) {
|
|
374
|
-
const value = JSON.parse(
|
|
375
|
+
const value = JSON.parse(session.readFile(configPath));
|
|
375
376
|
value.auth ?? (value.auth = {});
|
|
376
377
|
(_a = value.auth).schemes ?? (_a.schemes = {});
|
|
377
378
|
if (value.auth.schemes[scheme])
|
|
378
379
|
throw new Error(`auth.schemes.${scheme} already exists; no files were changed`);
|
|
379
380
|
value.auth.schemes[scheme] = provider === "custom-jwt" ? { provider, customJwt: defaultCustomJwtConfig() } : { provider };
|
|
380
381
|
(_b = value.auth).authorization ?? (_b.authorization = { defaultPolicy: "anonymous", policies: {} });
|
|
381
|
-
|
|
382
|
+
session.writeFile(configPath, JSON.stringify(value, null, 2) + "\n", extensionMeta);
|
|
382
383
|
return;
|
|
383
384
|
}
|
|
384
|
-
let content =
|
|
385
|
+
let content = session.readFile(configPath);
|
|
385
386
|
const authMatch = /\bauth\s*:\s*\{/.exec(content);
|
|
386
387
|
const customJwt = defaultCustomJwtConfig();
|
|
387
388
|
const entry = provider === "custom-jwt"
|
|
@@ -410,59 +411,59 @@ function updateConfigWithNamedScheme(cwd, scheme, provider) {
|
|
|
410
411
|
content = content.slice(0, authOpen + 1) + `\n schemes: {${entry}\n },` + content.slice(authOpen + 1);
|
|
411
412
|
}
|
|
412
413
|
}
|
|
413
|
-
|
|
414
|
+
session.writeFile(configPath, content, extensionMeta);
|
|
414
415
|
}
|
|
415
|
-
function addNamedScheme(cwd, scheme, provider, language) {
|
|
416
|
+
function addNamedScheme(cwd, scheme, provider, language, session) {
|
|
416
417
|
// Validate/update config before creating files, so duplicate names stop safely.
|
|
417
|
-
updateConfigWithNamedScheme(cwd, scheme, provider);
|
|
418
|
+
updateConfigWithNamedScheme(cwd, scheme, provider, session);
|
|
418
419
|
const slug = scheme.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/_/g, "-").toLowerCase();
|
|
419
420
|
if (language === "typescript") {
|
|
420
421
|
const dir = path.join(cwd, "functions", "src", "auth", "schemes", slug);
|
|
421
422
|
if (provider === "external-token")
|
|
422
|
-
writeIfMissing(path.join(dir, "verifier.ts"), (0, auth_generator_1.generateExternalTokenVerifierTS)());
|
|
423
|
+
writeIfMissing(session, path.join(dir, "verifier.ts"), (0, auth_generator_1.generateExternalTokenVerifierTS)());
|
|
423
424
|
else if (provider === "swa")
|
|
424
|
-
writeIfMissing(path.join(dir, "adapter.ts"), (0, auth_generator_1.generateSwaAuthHelperTS)());
|
|
425
|
+
writeIfMissing(session, path.join(dir, "adapter.ts"), (0, auth_generator_1.generateSwaAuthHelperTS)());
|
|
425
426
|
else
|
|
426
|
-
writeIfMissing(path.join(dir, "jwt-helper.ts"), (0, auth_generator_1.generateJwtHelperTS)());
|
|
427
|
+
writeIfMissing(session, path.join(dir, "jwt-helper.ts"), (0, auth_generator_1.generateJwtHelperTS)());
|
|
427
428
|
}
|
|
428
429
|
else if (language === "csharp") {
|
|
429
430
|
const dir = path.join(cwd, "functions", "Auth", "Schemes", slug);
|
|
430
431
|
if (provider === "external-token")
|
|
431
|
-
writeIfMissing(path.join(dir, "ExternalTokenVerifier.cs"), (0, auth_generator_1.generateNamedExternalTokenVerifierCSharp)(scheme));
|
|
432
|
+
writeIfMissing(session, path.join(dir, "ExternalTokenVerifier.cs"), (0, auth_generator_1.generateNamedExternalTokenVerifierCSharp)(scheme));
|
|
432
433
|
else if (provider === "swa")
|
|
433
|
-
writeIfMissing(path.join(dir, "SwaAdapter.cs"), (0, auth_generator_1.generateSwaAuthHelperCSharp)());
|
|
434
|
+
writeIfMissing(session, path.join(dir, "SwaAdapter.cs"), (0, auth_generator_1.generateSwaAuthHelperCSharp)());
|
|
434
435
|
else
|
|
435
|
-
writeIfMissing(path.join(dir, "JwtHelper.cs"), (0, auth_generator_1.generateJwtHelperCSharp)());
|
|
436
|
+
writeIfMissing(session, path.join(dir, "JwtHelper.cs"), (0, auth_generator_1.generateJwtHelperCSharp)());
|
|
436
437
|
}
|
|
437
438
|
else {
|
|
438
439
|
const dir = path.join(cwd, "functions", "auth", "schemes", slug.replace(/-/g, "_"));
|
|
439
440
|
if (provider === "external-token")
|
|
440
|
-
writeIfMissing(path.join(dir, "verifier.py"), (0, auth_generator_1.generateNamedExternalTokenVerifierPython)(scheme));
|
|
441
|
+
writeIfMissing(session, path.join(dir, "verifier.py"), (0, auth_generator_1.generateNamedExternalTokenVerifierPython)(scheme));
|
|
441
442
|
else if (provider === "swa")
|
|
442
|
-
writeIfMissing(path.join(dir, "adapter.py"), (0, auth_generator_1.generateSwaAuthHelperPython)());
|
|
443
|
+
writeIfMissing(session, path.join(dir, "adapter.py"), (0, auth_generator_1.generateSwaAuthHelperPython)());
|
|
443
444
|
else
|
|
444
|
-
writeIfMissing(path.join(dir, "jwt_helper.py"), (0, auth_generator_1.generateJwtHelperPython)());
|
|
445
|
+
writeIfMissing(session, path.join(dir, "jwt_helper.py"), (0, auth_generator_1.generateJwtHelperPython)());
|
|
445
446
|
}
|
|
446
447
|
const clientDir = path.join(cwd, "lib", "auth", "schemes", slug);
|
|
447
448
|
if (provider === "external-token") {
|
|
448
|
-
writeIfMissing(path.join(clientDir, "token-adapter.ts"), (0, auth_generator_1.generateExternalTokenAdapter)());
|
|
449
|
-
writeIfMissing(path.join(clientDir, "authenticated-fetch.ts"), (0, auth_generator_1.generateAuthenticatedFetch)().replace("'./external-token-adapter'", "'./token-adapter'"));
|
|
450
|
-
writeIfMissing(path.join(clientDir, "auth-context.tsx"), (0, auth_generator_1.generateExternalTokenAuthContext)().replace(/external-token-adapter/g, "token-adapter"));
|
|
449
|
+
writeIfMissing(session, path.join(clientDir, "token-adapter.ts"), (0, auth_generator_1.generateExternalTokenAdapter)());
|
|
450
|
+
writeIfMissing(session, path.join(clientDir, "authenticated-fetch.ts"), (0, auth_generator_1.generateAuthenticatedFetch)().replace("'./external-token-adapter'", "'./token-adapter'"));
|
|
451
|
+
writeIfMissing(session, path.join(clientDir, "auth-context.tsx"), (0, auth_generator_1.generateExternalTokenAuthContext)().replace(/external-token-adapter/g, "token-adapter"));
|
|
451
452
|
}
|
|
452
453
|
else if (provider === "swa") {
|
|
453
|
-
writeIfMissing(path.join(clientDir, "auth-context.tsx"), generateSwaAuthContext());
|
|
454
|
+
writeIfMissing(session, path.join(clientDir, "auth-context.tsx"), generateSwaAuthContext());
|
|
454
455
|
}
|
|
455
456
|
else if (provider === "custom-jwt") {
|
|
456
|
-
writeIfMissing(path.join(clientDir, "auth-context.tsx"), (0, auth_generator_1.generateAuthContext)());
|
|
457
|
+
writeIfMissing(session, path.join(clientDir, "auth-context.tsx"), (0, auth_generator_1.generateAuthContext)());
|
|
457
458
|
}
|
|
458
459
|
const callFunctionPath = path.join(cwd, "lib", "api", "call-function.ts");
|
|
459
|
-
if (!
|
|
460
|
-
writeIfMissing(callFunctionPath, (0, auth_generator_1.generateBFFCallFunctionWithMultipleAuth)());
|
|
460
|
+
if (!session.fileExists(callFunctionPath))
|
|
461
|
+
writeIfMissing(session, callFunctionPath, (0, auth_generator_1.generateBFFCallFunctionWithMultipleAuth)());
|
|
461
462
|
else {
|
|
462
|
-
const current =
|
|
463
|
+
const current = session.readFile(callFunctionPath);
|
|
463
464
|
if (!current.includes("x-ms-client-principal") || !current.includes("fetchHeaders['Authorization']")) {
|
|
464
465
|
if (current.includes("SwallowKit BFF Call Function Helper"))
|
|
465
|
-
|
|
466
|
+
session.writeFile(callFunctionPath, (0, auth_generator_1.generateBFFCallFunctionWithMultipleAuth)(), managedMeta);
|
|
466
467
|
else
|
|
467
468
|
console.warn(" Existing customized lib/api/call-function.ts was preserved. Ensure it forwards Bearer and SWA credentials without logging them.");
|
|
468
469
|
}
|
|
@@ -473,12 +474,12 @@ function addNamedScheme(cwd, scheme, provider, language) {
|
|
|
473
474
|
* (tsconfig.json, build script, typescript devDependency).
|
|
474
475
|
* Required for `dev` command which runs `npm run --workspace=shared build`.
|
|
475
476
|
*/
|
|
476
|
-
function ensureSharedBuildInfrastructure(cwd) {
|
|
477
|
+
function ensureSharedBuildInfrastructure(cwd, session) {
|
|
477
478
|
const sharedDir = path.join(cwd, "shared");
|
|
478
479
|
const pkgPath = path.join(sharedDir, "package.json");
|
|
479
|
-
if (!
|
|
480
|
+
if (!session.fileExists(pkgPath))
|
|
480
481
|
return;
|
|
481
|
-
const pkg = JSON.parse(
|
|
482
|
+
const pkg = JSON.parse(session.readFile(pkgPath));
|
|
482
483
|
let updated = false;
|
|
483
484
|
// Ensure scripts.build exists
|
|
484
485
|
if (!pkg.scripts?.build) {
|
|
@@ -502,32 +503,32 @@ function ensureSharedBuildInfrastructure(cwd) {
|
|
|
502
503
|
updated = true;
|
|
503
504
|
}
|
|
504
505
|
if (updated) {
|
|
505
|
-
|
|
506
|
+
session.writeFile(pkgPath, JSON.stringify(pkg, null, 2), extensionMeta);
|
|
506
507
|
console.log(` Updated: shared/package.json (added build infrastructure)`);
|
|
507
508
|
}
|
|
508
509
|
// Ensure tsconfig.json exists
|
|
509
510
|
const tsconfigPath = path.join(sharedDir, "tsconfig.json");
|
|
510
|
-
if (!
|
|
511
|
-
|
|
511
|
+
if (!session.fileExists(tsconfigPath)) {
|
|
512
|
+
session.writeFile(tsconfigPath, JSON.stringify((0, init_1.buildSharedTsConfig)(), null, 2), onceMeta);
|
|
512
513
|
console.log(` Created: shared/tsconfig.json`);
|
|
513
514
|
}
|
|
514
515
|
}
|
|
515
|
-
function updateSharedIndex(cwd) {
|
|
516
|
+
function updateSharedIndex(cwd, session) {
|
|
516
517
|
const indexPath = path.join(cwd, "shared", "index.ts");
|
|
517
|
-
if (
|
|
518
|
-
let content =
|
|
518
|
+
if (session.fileExists(indexPath)) {
|
|
519
|
+
let content = session.readFile(indexPath);
|
|
519
520
|
if (!content.includes("./models/auth")) {
|
|
520
521
|
content += `\nexport { LoginRequest, AuthUser, LoginResponse } from './models/auth';\n`;
|
|
521
|
-
|
|
522
|
+
session.writeFile(indexPath, content, extensionMeta);
|
|
522
523
|
console.log(` Updated: shared/index.ts`);
|
|
523
524
|
}
|
|
524
525
|
}
|
|
525
526
|
else {
|
|
526
|
-
|
|
527
|
+
session.writeFile(indexPath, `export { LoginRequest, AuthUser, LoginResponse } from './models/auth';\n`, extensionMeta);
|
|
527
528
|
console.log(` Created: shared/index.ts`);
|
|
528
529
|
}
|
|
529
530
|
}
|
|
530
|
-
function generateFunctionsAuth(cwd, backendLanguage, sharedPackageName, config) {
|
|
531
|
+
function generateFunctionsAuth(cwd, backendLanguage, sharedPackageName, config, session) {
|
|
531
532
|
const functionsDir = path.join(cwd, "functions");
|
|
532
533
|
// Resolve the RDB provider from the connector definition
|
|
533
534
|
const connDef = (0, config_1.getConnectorDefinition)(config.userConnector);
|
|
@@ -535,76 +536,70 @@ function generateFunctionsAuth(cwd, backendLanguage, sharedPackageName, config)
|
|
|
535
536
|
if (backendLanguage === "typescript") {
|
|
536
537
|
// Auth functions
|
|
537
538
|
const srcDir = path.join(functionsDir, "src");
|
|
538
|
-
|
|
539
|
-
fs.writeFileSync(path.join(srcDir, "auth.ts"), (0, auth_generator_1.generateAuthFunctionsTS)(sharedPackageName, config, provider), "utf-8");
|
|
539
|
+
session.writeFile(path.join(srcDir, "auth.ts"), (0, auth_generator_1.generateAuthFunctionsTS)(sharedPackageName, config, provider), managedMeta);
|
|
540
540
|
console.log(` Created: functions/src/auth.ts`);
|
|
541
541
|
// JWT helper
|
|
542
542
|
const authDir = path.join(srcDir, "auth");
|
|
543
|
-
|
|
544
|
-
fs.writeFileSync(path.join(authDir, "jwt-helper.ts"), (0, auth_generator_1.generateJwtHelperTS)(), "utf-8");
|
|
543
|
+
session.writeFile(path.join(authDir, "jwt-helper.ts"), (0, auth_generator_1.generateJwtHelperTS)(), managedMeta);
|
|
545
544
|
console.log(` Created: functions/src/auth/jwt-helper.ts`);
|
|
546
545
|
}
|
|
547
546
|
else if (backendLanguage === "csharp") {
|
|
548
547
|
const authDir = path.join(functionsDir, "Auth");
|
|
549
|
-
|
|
550
|
-
fs.writeFileSync(path.join(authDir, "AuthFunctions.cs"), (0, auth_generator_1.generateAuthFunctionsCSharp)(config, provider), "utf-8");
|
|
548
|
+
session.writeFile(path.join(authDir, "AuthFunctions.cs"), (0, auth_generator_1.generateAuthFunctionsCSharp)(config, provider), managedMeta);
|
|
551
549
|
console.log(` Created: functions/Auth/AuthFunctions.cs`);
|
|
552
|
-
|
|
550
|
+
session.writeFile(path.join(authDir, "JwtHelper.cs"), (0, auth_generator_1.generateJwtHelperCSharp)(), managedMeta);
|
|
553
551
|
console.log(` Created: functions/Auth/JwtHelper.cs`);
|
|
554
552
|
}
|
|
555
553
|
else if (backendLanguage === "python") {
|
|
556
554
|
const blueprintsDir = path.join(functionsDir, "blueprints");
|
|
557
|
-
|
|
558
|
-
fs.writeFileSync(path.join(blueprintsDir, "auth.py"), (0, auth_generator_1.generateAuthFunctionsPython)(config, provider), "utf-8");
|
|
555
|
+
session.writeFile(path.join(blueprintsDir, "auth.py"), (0, auth_generator_1.generateAuthFunctionsPython)(config, provider), managedMeta);
|
|
559
556
|
console.log(` Created: functions/blueprints/auth.py`);
|
|
560
557
|
const authDir = path.join(functionsDir, "auth");
|
|
561
|
-
|
|
562
|
-
fs.writeFileSync(path.join(authDir, "jwt_helper.py"), (0, auth_generator_1.generateJwtHelperPython)(), "utf-8");
|
|
558
|
+
session.writeFile(path.join(authDir, "jwt_helper.py"), (0, auth_generator_1.generateJwtHelperPython)(), managedMeta);
|
|
563
559
|
console.log(` Created: functions/auth/jwt_helper.py`);
|
|
564
560
|
// __init__.py
|
|
565
|
-
|
|
561
|
+
if (!session.fileExists(path.join(authDir, "__init__.py"))) {
|
|
562
|
+
session.writeFile(path.join(authDir, "__init__.py"), "", onceMeta);
|
|
563
|
+
}
|
|
566
564
|
// Register auth blueprint in function_app.py
|
|
567
565
|
const functionAppPath = path.join(functionsDir, "function_app.py");
|
|
568
|
-
if (
|
|
569
|
-
const content =
|
|
566
|
+
if (session.fileExists(functionAppPath)) {
|
|
567
|
+
const content = session.readFile(functionAppPath);
|
|
570
568
|
const authImport = "from blueprints.auth import bp as auth_bp";
|
|
571
569
|
const authRegister = "app.register_blueprint(auth_bp)";
|
|
572
570
|
if (!content.includes(authImport)) {
|
|
573
571
|
const marker = "# SwallowKit scaffold registrations";
|
|
574
572
|
if (content.includes(marker)) {
|
|
575
573
|
const updated = content.replace(marker, `${authImport}\n${authRegister}\n${marker}`);
|
|
576
|
-
|
|
574
|
+
session.writeFile(functionAppPath, updated, extensionMeta);
|
|
577
575
|
console.log(` Updated: functions/function_app.py (registered auth blueprint)`);
|
|
578
576
|
}
|
|
579
577
|
}
|
|
580
578
|
}
|
|
581
579
|
}
|
|
582
580
|
}
|
|
583
|
-
function generateBFFAuth(cwd, projectName, sharedPackageName) {
|
|
581
|
+
function generateBFFAuth(cwd, projectName, sharedPackageName, session) {
|
|
584
582
|
const authApiDir = path.join(cwd, "app", "api", "auth");
|
|
585
583
|
// Login route
|
|
586
584
|
const loginDir = path.join(authApiDir, "login");
|
|
587
|
-
|
|
588
|
-
fs.writeFileSync(path.join(loginDir, "route.ts"), (0, auth_generator_1.generateBFFAuthLoginRoute)(projectName, sharedPackageName), "utf-8");
|
|
585
|
+
session.writeFile(path.join(loginDir, "route.ts"), (0, auth_generator_1.generateBFFAuthLoginRoute)(projectName, sharedPackageName), managedMeta);
|
|
589
586
|
console.log(` Created: app/api/auth/login/route.ts`);
|
|
590
587
|
// Logout route
|
|
591
588
|
const logoutDir = path.join(authApiDir, "logout");
|
|
592
|
-
|
|
593
|
-
fs.writeFileSync(path.join(logoutDir, "route.ts"), (0, auth_generator_1.generateBFFAuthLogoutRoute)(projectName), "utf-8");
|
|
589
|
+
session.writeFile(path.join(logoutDir, "route.ts"), (0, auth_generator_1.generateBFFAuthLogoutRoute)(projectName), managedMeta);
|
|
594
590
|
console.log(` Created: app/api/auth/logout/route.ts`);
|
|
595
591
|
// Me route
|
|
596
592
|
const meDir = path.join(authApiDir, "me");
|
|
597
|
-
|
|
598
|
-
fs.writeFileSync(path.join(meDir, "route.ts"), (0, auth_generator_1.generateBFFAuthMeRoute)(), "utf-8");
|
|
593
|
+
session.writeFile(path.join(meDir, "route.ts"), (0, auth_generator_1.generateBFFAuthMeRoute)(), managedMeta);
|
|
599
594
|
console.log(` Created: app/api/auth/me/route.ts`);
|
|
600
595
|
}
|
|
601
|
-
function updateConfigWithAuth(cwd, provider, config) {
|
|
596
|
+
function updateConfigWithAuth(cwd, provider, config, session) {
|
|
602
597
|
const configPath = path.join(cwd, "swallowkit.config.js");
|
|
603
|
-
if (!
|
|
598
|
+
if (!session.fileExists(configPath)) {
|
|
604
599
|
console.warn(" swallowkit.config.js not found. Please add auth config manually.");
|
|
605
600
|
return;
|
|
606
601
|
}
|
|
607
|
-
const content =
|
|
602
|
+
const content = session.readFile(configPath);
|
|
608
603
|
if (content.includes("auth:") || content.includes("auth :")) {
|
|
609
604
|
console.log(" 'auth' section already exists in swallowkit.config.js");
|
|
610
605
|
return;
|
|
@@ -642,38 +637,38 @@ ${providerSettings}
|
|
|
642
637
|
},
|
|
643
638
|
`;
|
|
644
639
|
const newContent = content.substring(0, closingBraceIdx) + authBlock + content.substring(closingBraceIdx);
|
|
645
|
-
|
|
640
|
+
session.writeFile(configPath, newContent, extensionMeta);
|
|
646
641
|
console.log(` Updated: swallowkit.config.js`);
|
|
647
642
|
}
|
|
648
|
-
function updateEnvironmentFiles(cwd) {
|
|
643
|
+
function updateEnvironmentFiles(cwd, session) {
|
|
649
644
|
// Update functions/local.settings.json
|
|
650
645
|
const localSettingsPath = path.join(cwd, "functions", "local.settings.json");
|
|
651
|
-
if (
|
|
652
|
-
const settings = JSON.parse(
|
|
646
|
+
if (session.fileExists(localSettingsPath)) {
|
|
647
|
+
const settings = JSON.parse(session.readFile(localSettingsPath));
|
|
653
648
|
if (!settings.Values)
|
|
654
649
|
settings.Values = {};
|
|
655
650
|
if (!settings.Values.JWT_SECRET) {
|
|
656
651
|
settings.Values.JWT_SECRET = "dev-jwt-secret-change-in-production-min-32-chars!!";
|
|
657
652
|
}
|
|
658
|
-
|
|
653
|
+
session.writeFile(localSettingsPath, JSON.stringify(settings, null, 2), extensionMeta);
|
|
659
654
|
console.log(` Updated: functions/local.settings.json`);
|
|
660
655
|
}
|
|
661
656
|
// Update .env.example
|
|
662
657
|
const envExamplePath = path.join(cwd, ".env.example");
|
|
663
|
-
if (
|
|
664
|
-
let content =
|
|
658
|
+
if (session.fileExists(envExamplePath)) {
|
|
659
|
+
let content = session.readFile(envExamplePath);
|
|
665
660
|
if (!content.includes("JWT_SECRET")) {
|
|
666
661
|
content += "\n# Authentication\nJWT_SECRET=your-jwt-secret-key-at-least-32-chars\n";
|
|
667
|
-
|
|
662
|
+
session.writeFile(envExamplePath, content, extensionMeta);
|
|
668
663
|
console.log(` Updated: .env.example`);
|
|
669
664
|
}
|
|
670
665
|
}
|
|
671
666
|
}
|
|
672
|
-
async function installAuthDependencies(cwd, backendLanguage, provider = "mysql") {
|
|
667
|
+
async function installAuthDependencies(cwd, backendLanguage, provider = "mysql", session) {
|
|
673
668
|
if (backendLanguage === "typescript") {
|
|
674
669
|
const funcPkgPath = path.join(cwd, "functions", "package.json");
|
|
675
|
-
if (
|
|
676
|
-
const funcPkg = JSON.parse(
|
|
670
|
+
if (session.fileExists(funcPkgPath)) {
|
|
671
|
+
const funcPkg = JSON.parse(session.readFile(funcPkgPath));
|
|
677
672
|
if (!funcPkg.dependencies)
|
|
678
673
|
funcPkg.dependencies = {};
|
|
679
674
|
funcPkg.dependencies["jsonwebtoken"] = "^9.0.0";
|
|
@@ -691,17 +686,19 @@ async function installAuthDependencies(cwd, backendLanguage, provider = "mysql")
|
|
|
691
686
|
funcPkg.devDependencies["@types/bcryptjs"] = "^2.4.0";
|
|
692
687
|
if (provider === "postgres")
|
|
693
688
|
funcPkg.devDependencies["@types/pg"] = "^8.11.0";
|
|
694
|
-
|
|
689
|
+
session.writeFile(funcPkgPath, JSON.stringify(funcPkg, null, 2), extensionMeta);
|
|
695
690
|
console.log(` Updated: functions/package.json with auth dependencies (${provider})`);
|
|
696
691
|
}
|
|
697
692
|
}
|
|
698
693
|
else if (backendLanguage === "csharp") {
|
|
699
694
|
// Add NuGet package references to .csproj
|
|
700
695
|
const functionsDir = path.join(cwd, "functions");
|
|
701
|
-
const csprojFiles = fs.
|
|
696
|
+
const csprojFiles = fs.existsSync(functionsDir)
|
|
697
|
+
? fs.readdirSync(functionsDir).filter((f) => f.endsWith(".csproj"))
|
|
698
|
+
: [];
|
|
702
699
|
if (csprojFiles.length > 0) {
|
|
703
700
|
const csprojPath = path.join(functionsDir, csprojFiles[0]);
|
|
704
|
-
let csprojContent =
|
|
701
|
+
let csprojContent = session.readFile(csprojPath);
|
|
705
702
|
const nugetPackages = [
|
|
706
703
|
{ name: "System.IdentityModel.Tokens.Jwt", version: "7.0.0" },
|
|
707
704
|
{ name: "Microsoft.IdentityModel.Tokens", version: "7.0.0" },
|
|
@@ -725,7 +722,7 @@ async function installAuthDependencies(cwd, backendLanguage, provider = "mysql")
|
|
|
725
722
|
}
|
|
726
723
|
}
|
|
727
724
|
}
|
|
728
|
-
|
|
725
|
+
session.writeFile(csprojPath, csprojContent, extensionMeta);
|
|
729
726
|
console.log(` Updated: ${csprojFiles[0]} with auth NuGet packages (${provider})`);
|
|
730
727
|
}
|
|
731
728
|
}
|
|
@@ -740,18 +737,18 @@ async function installAuthDependencies(cwd, backendLanguage, provider = "mysql")
|
|
|
740
737
|
baseDeps.push("psycopg2-binary>=2.9.0");
|
|
741
738
|
else
|
|
742
739
|
baseDeps.push("pymssql>=2.2.0");
|
|
743
|
-
if (
|
|
744
|
-
let content =
|
|
740
|
+
if (session.fileExists(requirementsPath)) {
|
|
741
|
+
let content = session.readFile(requirementsPath);
|
|
745
742
|
for (const dep of baseDeps) {
|
|
746
743
|
const pkgName = dep.split(">=")[0].split("==")[0];
|
|
747
744
|
if (!content.includes(pkgName)) {
|
|
748
745
|
content += `${dep}\n`;
|
|
749
746
|
}
|
|
750
747
|
}
|
|
751
|
-
|
|
748
|
+
session.writeFile(requirementsPath, content, extensionMeta);
|
|
752
749
|
}
|
|
753
750
|
else {
|
|
754
|
-
|
|
751
|
+
session.writeFile(requirementsPath, baseDeps.join("\n") + "\n", extensionMeta);
|
|
755
752
|
}
|
|
756
753
|
console.log(` Updated: functions/requirements.txt with auth dependencies`);
|
|
757
754
|
}
|