UNPKG

@rnaga/wp-node

Version:

👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**

105 lines (104 loc) • 3.87 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.userUpdate = exports.userInsert = exports.userUpsert = exports.userLogin = exports.userUpsertMeta = void 0; const zod_1 = require("zod"); const database = __importStar(require("../database")); const constants_1 = require("../../constants"); const helpers_1 = require("../helpers"); const date_1 = require("../date"); exports.userUpsertMeta = zod_1.z.object({ nickname: helpers_1.string.optional().default(""), first_name: helpers_1.string.optional().default(""), last_name: helpers_1.string.optional().default(""), description: helpers_1.string.default(""), rich_editing: (0, helpers_1.booleanWithDefault)("true"), syntax_highlighting: (0, helpers_1.booleanWithDefault)("true"), comment_shortcuts: (0, helpers_1.booleanWithDefault)("false"), admin_color: helpers_1.string.default("fresh"), use_ssl: helpers_1.stringZeroOrOne, show_admin_bar_front: (0, helpers_1.booleanWithDefault)("true"), locale: helpers_1.string.optional(), }); // Define the forbidden words const forbiddenUserLogins = [ "www", "web", "root", "admin", "main", "invite", "administrator", ]; // Apply when creating a new user exports.userLogin = zod_1.z .string() .min(4) .max(60) .trim() .toLowerCase() .regex(/^[a-z0-9_-]*$/) .refine((value) => /[a-z_-]/.test(value)) .refine((value) => !/^[-0-9]*$/.test(value)) .refine((value) => !forbiddenUserLogins.includes(value)); exports.userUpsert = database.wpUsers.merge(zod_1.z .object({ ID: zod_1.z.number().int().nonnegative().optional(), user_login: zod_1.z.string(), user_registered: date_1.mySQLDate, //z.union([z.string(), z.date(), z.undefined()]), role: zod_1.z.union([ zod_1.z .enum([...constants_1.ROLE_NAMES]) .optional() .default("subscriber"), zod_1.z.array(zod_1.z.enum([...constants_1.ROLE_NAMES])).optional(), zod_1.z.array(zod_1.z.string()).optional(), ]), meta_input: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional().default({}), }) .merge(exports.userUpsertMeta)); exports.userInsert = database.wpUsers.pick({ user_pass: true, user_login: true, user_nicename: true, user_email: true, user_url: true, user_registered: true, user_activation_key: true, display_name: true, }); exports.userUpdate = exports.userInsert.omit({ user_login: true, });