next-accelerate 1.0.0 → 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/dist/index.js +63 -43
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -322,12 +322,16 @@ var listPageTemplate = (resourceInSingular, resourceInPlural) => `
|
|
|
322
322
|
|
|
323
323
|
type ${resourceInSingular} = {};
|
|
324
324
|
async function get${resourceInPlural.toLocaleLowerCase()}(): Promise<${resourceInSingular}[]> {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
325
|
+
try{
|
|
326
|
+
const response = await fetch(\`\${process.env.NEXT_BACKEND_URL}/${resourceInPlural.toLowerCase()}\`, {
|
|
327
|
+
cache: "no-store",
|
|
328
|
+
});
|
|
329
|
+
if (!response.ok) return [];
|
|
330
|
+
const ${resourceInPlural.toLocaleLowerCase()}: ${resourceInSingular}[] = await response.json();
|
|
331
|
+
return ${resourceInPlural.toLocaleLowerCase()};
|
|
332
|
+
}catch(erro){
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
331
335
|
}
|
|
332
336
|
|
|
333
337
|
export default async function ${resourceInPlural}Page() {
|
|
@@ -501,12 +505,16 @@ var inputTemplate = () => `
|
|
|
501
505
|
pattern?: RegExp;
|
|
502
506
|
placeholder?: string;
|
|
503
507
|
asDate?: boolean;
|
|
508
|
+
mask?: "cpf" | "phone";
|
|
504
509
|
multiline?: boolean;
|
|
505
|
-
}
|
|
510
|
+
};
|
|
506
511
|
|
|
507
|
-
export const InputCustom: React.FC<InputProps> = ({ name, label, type = "text", required, pattern, placeholder, asDate, ishidden, multiline = false }) => {
|
|
512
|
+
export const InputCustom: React.FC<InputProps> = ({ name, label, type = "text", required, pattern, placeholder, asDate, ishidden, mask,multiline = false }) => {
|
|
508
513
|
const { control, formState: { errors } } = useFormContext();
|
|
509
514
|
|
|
515
|
+
const maskCPF = (value: string) => { return value.replace(/\\D/g, "").replace(/(\\d{3})(\\d)/, "$1.$2").replace(/(\\d{3})(\\d)/, "$1.$2").replace(/(\\d{3})(\\d{1,2})$/, "$1-$2"); };
|
|
516
|
+
const maskPhone = (value: string) => { return value.replace(/\\D/g, "").replace(/(\\d{2})(\\d)/, "($1) $2").replace(/(\\d{5})(\\d)/, "$1-$2"); };
|
|
517
|
+
|
|
510
518
|
return (
|
|
511
519
|
<div className="flex flex-col gap-2">
|
|
512
520
|
{!ishidden && (
|
|
@@ -515,10 +523,7 @@ var inputTemplate = () => `
|
|
|
515
523
|
</label>
|
|
516
524
|
)}
|
|
517
525
|
|
|
518
|
-
<Controller
|
|
519
|
-
control={control}
|
|
520
|
-
name={name}
|
|
521
|
-
rules={{
|
|
526
|
+
<Controller control={control} name={name} rules={{
|
|
522
527
|
required: !ishidden && required ? "Campo obrigat\xF3rio" : false,
|
|
523
528
|
pattern: pattern ? { value: pattern, message: "Formato inv\xE1lido" } : undefined,
|
|
524
529
|
}}
|
|
@@ -535,18 +540,20 @@ var inputTemplate = () => `
|
|
|
535
540
|
|
|
536
541
|
return (
|
|
537
542
|
<input {...field} id={name} type={type} placeholder={ishidden ? "" : placeholder} hidden={ishidden} aria-hidden={ishidden} value={value} onChange={(e) => {
|
|
543
|
+
let value = e.target.value;
|
|
544
|
+
|
|
545
|
+
if (mask === "cpf") { value = maskCPF(value); };
|
|
546
|
+
if (mask === "phone") { value = maskPhone(value); };
|
|
547
|
+
|
|
538
548
|
if (asDate) {
|
|
539
|
-
|
|
540
|
-
if (!v) {
|
|
541
|
-
field.onChange(null);
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
const date = new Date(v);
|
|
545
|
-
if (isNaN(date.getTime())) return;
|
|
549
|
+
if (!value) { field.onChange(null); return; };
|
|
546
550
|
|
|
551
|
+
const date = new Date(value);
|
|
552
|
+
if (isNaN(date.getTime())) return;
|
|
547
553
|
field.onChange(date.toISOString());
|
|
554
|
+
|
|
548
555
|
} else {
|
|
549
|
-
field.onChange(
|
|
556
|
+
field.onChange(value);
|
|
550
557
|
}
|
|
551
558
|
}}
|
|
552
559
|
className={\`\${baseClasses} \${errorClass} rounded-full\`}
|
|
@@ -554,11 +561,7 @@ var inputTemplate = () => `
|
|
|
554
561
|
);
|
|
555
562
|
}}
|
|
556
563
|
/>
|
|
557
|
-
{errors[name]?.message && (
|
|
558
|
-
<p className="text-sm text-red-500">
|
|
559
|
-
{errors[name]?.message as string}
|
|
560
|
-
</p>
|
|
561
|
-
)}
|
|
564
|
+
{errors[name]?.message && (<p className="text-sm text-red-500">{errors[name]?.message as string}</p>)}
|
|
562
565
|
</div>
|
|
563
566
|
);
|
|
564
567
|
};
|
|
@@ -775,6 +778,18 @@ var nextSessionTypeTemplate = () => `
|
|
|
775
778
|
// src/templates/config/utils.ts
|
|
776
779
|
var utilsTypeTemplate = () => `export const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));`;
|
|
777
780
|
|
|
781
|
+
// src/templates/routes/logout-route.ts
|
|
782
|
+
var logoutTemplate = () => `
|
|
783
|
+
import { NextResponse } from "next/server";
|
|
784
|
+
|
|
785
|
+
export async function GET() {
|
|
786
|
+
const response = NextResponse.redirect(new URL("/", \`\${process.env.NEXTAUTH_URL}\`));
|
|
787
|
+
response.cookies.set("jwt_back", "", { path: "/", expires: new Date(0) });
|
|
788
|
+
response.cookies.set("jwt_back_refresh", "", { path: "/", expires: new Date(0) });
|
|
789
|
+
return response;
|
|
790
|
+
}
|
|
791
|
+
`;
|
|
792
|
+
|
|
778
793
|
// src/templates/config/environment.ts
|
|
779
794
|
var environmentTemplate = () => `
|
|
780
795
|
NEXTAUTH_URL=http://localhost:3000
|
|
@@ -1207,6 +1222,7 @@ export const FormLogin: React.FC = () => {
|
|
|
1207
1222
|
};
|
|
1208
1223
|
|
|
1209
1224
|
const handleLogout = async () => {
|
|
1225
|
+
await fetch(\`\${process.env.NEXT_PUBLIC_FRONTEND_URL}/api/auth/logout\`);
|
|
1210
1226
|
await signOut({ callbackUrl: "/" });
|
|
1211
1227
|
};
|
|
1212
1228
|
|
|
@@ -1446,12 +1462,13 @@ export const FormRegister = () => {
|
|
|
1446
1462
|
defaultValues: { name: "", email: "", cpf: "", dateOfBirth: new Date(), password: "", repeatPassword: "", phone: "", country: "", state: "", city: "", address: "" },
|
|
1447
1463
|
});
|
|
1448
1464
|
|
|
1465
|
+
const removeMask = (v: string) => v.replace(/\\D/g, "");
|
|
1449
1466
|
const handlesubmitRegister = async (data: FormSchemaType) => {
|
|
1450
1467
|
try {
|
|
1451
1468
|
const response = await fetch(\`\${process.env.NEXT_PUBLIC_URL}/api/users\`, {
|
|
1452
1469
|
method: "POST",
|
|
1453
1470
|
headers: { "Content-Type": "application/json" },
|
|
1454
|
-
body: JSON.stringify(data),
|
|
1471
|
+
body: JSON.stringify({...data, cpf: removeMask(data.cpf), phone: removeMask(data.phone)}),
|
|
1455
1472
|
});
|
|
1456
1473
|
|
|
1457
1474
|
if (response && response.status === 201) {
|
|
@@ -2129,9 +2146,9 @@ export const ButtonGeneric: React.FC<ButtonGenericProps> = ({
|
|
|
2129
2146
|
);
|
|
2130
2147
|
};
|
|
2131
2148
|
`;
|
|
2132
|
-
var buttonGenericTemplateUnitTest = () =>
|
|
2133
|
-
|
|
2134
|
-
|
|
2149
|
+
var buttonGenericTemplateUnitTest = () => {
|
|
2150
|
+
return ``;
|
|
2151
|
+
};
|
|
2135
2152
|
|
|
2136
2153
|
// src/builders/resource-form-builder.ts
|
|
2137
2154
|
var NextResourceFormBuilder = class extends NextAccelerateBuilder {
|
|
@@ -2237,11 +2254,11 @@ import * as yup from "yup";
|
|
|
2237
2254
|
export const formSchema = yup.object({
|
|
2238
2255
|
name: yup.string().required("O nome \xE9 obrigat\xF3rio").min(3, "O nome deve ter pelo menos 3 caracteres"),
|
|
2239
2256
|
email: yup.string().required("O email \xE9 obrigat\xF3rio").email("Digite um email v\xE1lido"),
|
|
2240
|
-
cpf: yup.string().required("O CPF \xE9 obrigat\xF3rio").matches(
|
|
2257
|
+
cpf: yup.string().required("O CPF \xE9 obrigat\xF3rio").transform((v) => v?.replace(/\\D/g, "")).matches(/^\\d{11}$/, "O CPF deve conter 11 d\xEDgitos"),
|
|
2241
2258
|
dateOfBirth: yup.date().required("A data \xE9 obrigat\xF3ria").max(new Date(), "A data de aniversario \xE9 obrigatoria"),
|
|
2242
2259
|
password: yup.string().required("A senha \xE9 obrigat\xF3ria").min(6, "A senha deve ter pelo menos 6 caracteres"),
|
|
2243
2260
|
repeatPassword: yup.string().required("A confirma\xE7\xE3o de senha \xE9 obrigat\xF3ria").oneOf([yup.ref("password")], "As senhas devem ser iguais"),
|
|
2244
|
-
phone: yup.string().required("O telefone \xE9 obrigat\xF3rio").matches(
|
|
2261
|
+
phone: yup.string().required("O telefone \xE9 obrigat\xF3rio").transform((v) => v?.replace(/\\D/g, "")).matches(/^\\+?\\d{10,15}$/, "N\xFAmero de telefone inv\xE1lido"),
|
|
2245
2262
|
country: yup.string().required("O pa\xEDs \xE9 obrigat\xF3rio"),
|
|
2246
2263
|
state: yup.string().required("O estado \xE9 obrigat\xF3rio"),
|
|
2247
2264
|
city: yup.string().required("A cidade \xE9 obrigat\xF3ria"),
|
|
@@ -2268,9 +2285,7 @@ export type UpdateFormSchemaType = yup.InferType<typeof updateFormSchema>;
|
|
|
2268
2285
|
`;
|
|
2269
2286
|
|
|
2270
2287
|
// src/templates/config/hiddenpaths.ts
|
|
2271
|
-
var hiddenPathsTemplate = () => `
|
|
2272
|
-
export const hiddenPaths = ["/manager", "/posts/new", "/posts", "/categories", "/categories/new", "/settings"];
|
|
2273
|
-
`;
|
|
2288
|
+
var hiddenPathsTemplate = () => `export const hiddenPaths = ["/manager", "/posts/new", "/posts", "/categories", "/categories/new", "/settings"];`;
|
|
2274
2289
|
|
|
2275
2290
|
// src/templates/config/proxy.ts
|
|
2276
2291
|
var proxyTemplate = () => `
|
|
@@ -2279,13 +2294,13 @@ import { decoderTokenToClaims } from "./app/api/auth/decode-claims";
|
|
|
2279
2294
|
|
|
2280
2295
|
type Role = "ADMIN" | "AUTHOR" | "COMMENTATOR";
|
|
2281
2296
|
|
|
2282
|
-
const adminRoutes = ["/admin", "/users", "/dashboard/admin", "/settings", "/desk/view"];
|
|
2283
|
-
const authorRoutes = ["/desk/view"];
|
|
2284
|
-
const commntatorRoutes = ["/community", "/messages", "/", "/announced"];
|
|
2297
|
+
const adminRoutes = ["/manager","/admin", "/users", "/dashboard/admin", "/settings", "/desk/view"];
|
|
2298
|
+
const authorRoutes = ["/manager","/desk/view"];
|
|
2299
|
+
const commntatorRoutes = ["/manager","/community", "/messages", "/", "/announced"];
|
|
2285
2300
|
|
|
2286
2301
|
export const config = {
|
|
2287
2302
|
matcher: [
|
|
2288
|
-
"/admin/:path*", "/users/:path*", "/settings", "/settings/:path*", "/desk/view", "/desk/view/:path*", "/messages", "/messages/:path*"
|
|
2303
|
+
"/manager/:path*","/admin/:path*", "/users/:path*", "/settings", "/settings/:path*", "/desk/view", "/desk/view/:path*", "/messages", "/messages/:path*"
|
|
2289
2304
|
]
|
|
2290
2305
|
};
|
|
2291
2306
|
|
|
@@ -2310,7 +2325,7 @@ export function proxy(request: NextRequest) {
|
|
|
2310
2325
|
|
|
2311
2326
|
const token = request.cookies.get("jwt_back")?.value;
|
|
2312
2327
|
if (!token) {
|
|
2313
|
-
return NextResponse.redirect(new URL("/
|
|
2328
|
+
return NextResponse.redirect(new URL("/", request.url));
|
|
2314
2329
|
}
|
|
2315
2330
|
|
|
2316
2331
|
const claims = decoderTokenToClaims(token);
|
|
@@ -2613,6 +2628,13 @@ var NextAuthBuilder = class {
|
|
|
2613
2628
|
}
|
|
2614
2629
|
;
|
|
2615
2630
|
createFile(path6.join(this.basePath, "route.ts"), nextConfigTemplate());
|
|
2631
|
+
const logoutPath = path6.join(process.cwd(), "src/app/api/auth/logout");
|
|
2632
|
+
createDir(logoutPath);
|
|
2633
|
+
if (!pathExists(logoutPath)) {
|
|
2634
|
+
console.error("\x1B[31m \u2716 Erro \x1B[0m creating logout directory.");
|
|
2635
|
+
process.exit(1);
|
|
2636
|
+
}
|
|
2637
|
+
createFile(path6.join(logoutPath, "route.ts"), logoutTemplate());
|
|
2616
2638
|
if (this.options?.git) this.createCommit("feat(next-auth): create config route.");
|
|
2617
2639
|
return this;
|
|
2618
2640
|
}
|
|
@@ -2846,8 +2868,7 @@ import path7 from "path";
|
|
|
2846
2868
|
import fs4 from "fs";
|
|
2847
2869
|
|
|
2848
2870
|
// src/templates/tests/config-vitest.ts
|
|
2849
|
-
var nextConfigViTestTemplate = () =>
|
|
2850
|
-
/// <reference types="vitest" />
|
|
2871
|
+
var nextConfigViTestTemplate = () => `/// <reference types="vitest" />
|
|
2851
2872
|
import { defineConfig } from "vitest/config";
|
|
2852
2873
|
import path from "path";
|
|
2853
2874
|
|
|
@@ -2922,8 +2943,7 @@ var DependencyTetsE2EInstaller = class _DependencyTetsE2EInstaller {
|
|
|
2922
2943
|
};
|
|
2923
2944
|
|
|
2924
2945
|
// src/templates/tests/config-playwright.ts
|
|
2925
|
-
var nextConfigPlaywightTestTemplate = () => `
|
|
2926
|
-
import { defineConfig, devices } from '@playwright/test';
|
|
2946
|
+
var nextConfigPlaywightTestTemplate = () => `import { defineConfig, devices } from '@playwright/test';
|
|
2927
2947
|
|
|
2928
2948
|
export default defineConfig({
|
|
2929
2949
|
testDir: './tests/e2e',
|