@cryptlex/web-components 6.6.6-alpha41 → 6.6.6-alpha46
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/components/checkbox.d.ts +4 -2
- package/dist/components/checkbox.js +1 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/data-table-filter.d.ts +1 -1
- package/dist/components/data-table-filter.js +1 -1
- package/dist/components/data-table.d.ts +3 -11
- package/dist/components/data-table.js +1 -1
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/dialog-action-utils.d.ts +38 -0
- package/dist/components/dialog-action-utils.js +2 -0
- package/dist/components/dialog-action-utils.js.map +1 -0
- package/dist/components/dialog-menu.d.ts +3 -3
- package/dist/components/dialog-menu.js +1 -1
- package/dist/components/dialog-menu.js.map +1 -1
- package/dist/components/id-search.d.ts +12 -11
- package/dist/components/id-search.js +1 -1
- package/dist/components/id-search.js.map +1 -1
- package/dist/components/select-options.d.ts +8 -0
- package/dist/components/select-options.js +1 -1
- package/dist/components/select-options.js.map +1 -1
- package/dist/components/table-actions.d.ts +46 -0
- package/dist/components/table-actions.js +2 -0
- package/dist/components/table-actions.js.map +1 -0
- package/dist/utilities/countries.d.ts +3 -0
- package/dist/utilities/countries.js +2 -0
- package/dist/utilities/countries.js.map +1 -0
- package/dist/utilities/ctx-client.d.ts +8 -0
- package/dist/utilities/ctx-client.js +2 -0
- package/dist/utilities/ctx-client.js.map +1 -0
- package/dist/utilities/numbers.d.ts +1 -0
- package/dist/utilities/numbers.js +1 -1
- package/dist/utilities/numbers.js.map +1 -1
- package/dist/utilities/resources.d.ts +8 -1
- package/dist/utilities/resources.js +1 -1
- package/dist/utilities/resources.js.map +1 -1
- package/dist/utilities/string.d.ts +5 -0
- package/dist/utilities/string.js +1 -1
- package/dist/utilities/string.js.map +1 -1
- package/dist/utilities/validators.d.ts +16 -0
- package/dist/utilities/validators.js +2 -0
- package/dist/utilities/validators.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.js","sources":["../../lib/utilities/numbers.ts"],"sourcesContent":["import z from 'zod';\nimport { Duration } from './duration';\n\nexport const MAX_INT32 = 2147483647;\nexport const MAX_INT32_DAYS = Math.floor(MAX_INT32 / 86400);\nexport const MIN_INT32 = -2147483648;\nexport const MIN_INT32_DAYS = Math.ceil(MIN_INT32 / 86400);\n\nexport function getNumberValidator(min: number, max: number) {\n return z\n .number()\n .min(min, {\n error: issue => {\n if (issue.code === 'too_small') return `The number must be at least ${formatNumber(min)}.`;\n },\n })\n .max(max, {\n error: issue => {\n if (issue.code === 'too_big') return `The number must be at most ${formatNumber(max)}.`;\n },\n });\n}\n\nconst SECONDS_PER_DAY = 86400;\n\nexport function getDaysValidator(min: number) {\n const minSeconds = min * SECONDS_PER_DAY;\n const maxSeconds = MAX_INT32_DAYS * SECONDS_PER_DAY;\n\n return z\n .number()\n .min(minSeconds, {\n error: `The number must be at least ${formatNumber(min)} days.`,\n })\n .max(maxSeconds, {\n error: `The number must be at most ${formatNumber(MAX_INT32_DAYS)} days.`,\n });\n}\n\nexport function formatNumber(num: number | bigint, options?: Intl.NumberFormatOptions) {\n return Intl.NumberFormat(navigator.language, options).format(num);\n}\n\n/**\n * @returns A formatted string for the number of bytes\n */\nexport function formatFilesize(bytes: number): string {\n if (bytes < 1024) {\n return `${bytes} B`;\n } else if (bytes < 1024 * 1024) {\n return `${(bytes / 1024).toFixed(1)} KB`;\n } else if (bytes < 1024 * 1024 * 1024) {\n return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;\n } else {\n return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;\n }\n}\n\n/**\n * Validates an ISO8601 duration string\n * @param maxYears Maximum allowed years (default: 10)\n * @returns A Zod validator that checks:\n * - Duration format is valid (matches ISO8601 pattern)\n * - Duration is not empty\n * - At least one value (years, months, days, hours, minutes, or seconds) is non-zero\n * - Total duration does not exceed maxYears\n */\nexport function getISO8601DurationValidator(maxYears: number = 10) {\n const MAX_DURATION_DAYS = 365 * maxYears;\n\n const getParts = (value: string) => {\n try {\n const parsed = Duration.parse(value);\n return {\n years: parsed.years ?? 0,\n months: parsed.months ?? 0,\n days: (parsed.days ?? 0) + (parsed.weeks ?? 0) * 7,\n hours: parsed.hours ?? 0,\n minutes: parsed.minutes ?? 0,\n seconds: parsed.seconds ?? 0,\n };\n } catch {\n return { years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0 };\n }\n };\n\n return z\n .string()\n .refine(\n value => {\n const parts = getParts(value);\n return Object.values(parts).some(v => v > 0);\n },\n {\n message: 'At least one value (years, months, days, hours, minutes, or seconds) must be non-zero',\n }\n )\n .refine(\n value => {\n const parts = getParts(value);\n const timeInDays = (parts.hours * 3600 + parts.minutes * 60 + parts.seconds) / SECONDS_PER_DAY;\n return parts.years * 365 + parts.months * 30 + parts.days + timeInDays <= MAX_DURATION_DAYS;\n },\n {\n message: `Subscription interval cannot exceed ${maxYears} years`,\n }\n );\n}\n"],"names":["MAX_INT32","MAX_INT32_DAYS","MIN_INT32","MIN_INT32_DAYS","getNumberValidator","min","max","z","issue","formatNumber","SECONDS_PER_DAY","getDaysValidator","minSeconds","maxSeconds","num","options","formatFilesize","bytes","getISO8601DurationValidator","maxYears","MAX_DURATION_DAYS","getParts","value","parsed","Duration","parts","v","timeInDays"],"mappings":"4DAGO,MAAMA,EAAY,WACZC,EAAiB,KAAK,MAAMD,EAAY,KAAK,EAC7CE,EAAY,YACZC,EAAiB,KAAK,KAAKD,EAAY,KAAK,EAElD,SAASE,EAAmBC,EAAaC,EAAa,CACzD,OAAOC,EACF,SACA,IAAIF,EAAK,CACN,MAAOG,GAAS,CACZ,GAAIA,EAAM,OAAS,kBAAoB,+BAA+BC,EAAaJ,CAAG,CAAC,GAC3F,CAAA,CACH,EACA,IAAIC,EAAK,CACN,MAAOE,GAAS,CACZ,GAAIA,EAAM,OAAS,gBAAkB,8BAA8BC,EAAaH,CAAG,CAAC,GACxF,CAAA,CACH,CACT,CAEA,MAAMI,EAAkB,MAEjB,SAASC,EAAiBN,EAAa,CAC1C,MAAMO,EAAaP,EAAMK,EACnBG,EAAaZ,EAAiBS,EAEpC,OAAOH,EACF,SACA,IAAIK,EAAY,CACb,MAAO,+BAA+BH,EAAaJ,CAAG,CAAC,QAAA,CAC1D,EACA,IAAIQ,EAAY,CACb,MAAO,8BAA8BJ,EAAaR,CAAc,CAAC,QAAA,CACpE,CACT,CAEO,
|
|
1
|
+
{"version":3,"file":"numbers.js","sources":["../../lib/utilities/numbers.ts"],"sourcesContent":["import z from 'zod';\nimport { Duration } from './duration';\n\nexport const MAX_INT32 = 2147483647;\nexport const MAX_INT32_DAYS = Math.floor(MAX_INT32 / 86400);\nexport const MIN_INT32 = -2147483648;\nexport const MIN_INT32_DAYS = Math.ceil(MIN_INT32 / 86400);\n\nexport function getNumberValidator(min: number, max: number) {\n return z\n .number()\n .min(min, {\n error: issue => {\n if (issue.code === 'too_small') return `The number must be at least ${formatNumber(min)}.`;\n },\n })\n .max(max, {\n error: issue => {\n if (issue.code === 'too_big') return `The number must be at most ${formatNumber(max)}.`;\n },\n });\n}\n\nconst SECONDS_PER_DAY = 86400;\n\nexport function getDaysValidator(min: number) {\n const minSeconds = min * SECONDS_PER_DAY;\n const maxSeconds = MAX_INT32_DAYS * SECONDS_PER_DAY;\n\n return z\n .number()\n .min(minSeconds, {\n error: `The number must be at least ${formatNumber(min)} days.`,\n })\n .max(maxSeconds, {\n error: `The number must be at most ${formatNumber(MAX_INT32_DAYS)} days.`,\n });\n}\n\nexport function formatDays(seconds: number): string {\n return `${Math.floor(seconds / SECONDS_PER_DAY)} days`;\n}\nexport function formatNumber(num: number | bigint, options?: Intl.NumberFormatOptions) {\n return Intl.NumberFormat(navigator.language, options).format(num);\n}\n\n/**\n * @returns A formatted string for the number of bytes\n */\nexport function formatFilesize(bytes: number): string {\n if (bytes < 1024) {\n return `${bytes} B`;\n } else if (bytes < 1024 * 1024) {\n return `${(bytes / 1024).toFixed(1)} KB`;\n } else if (bytes < 1024 * 1024 * 1024) {\n return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;\n } else {\n return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;\n }\n}\n\n/**\n * Validates an ISO8601 duration string\n * @param maxYears Maximum allowed years (default: 10)\n * @returns A Zod validator that checks:\n * - Duration format is valid (matches ISO8601 pattern)\n * - Duration is not empty\n * - At least one value (years, months, days, hours, minutes, or seconds) is non-zero\n * - Total duration does not exceed maxYears\n */\nexport function getISO8601DurationValidator(maxYears: number = 10) {\n const MAX_DURATION_DAYS = 365 * maxYears;\n\n const getParts = (value: string) => {\n try {\n const parsed = Duration.parse(value);\n return {\n years: parsed.years ?? 0,\n months: parsed.months ?? 0,\n days: (parsed.days ?? 0) + (parsed.weeks ?? 0) * 7,\n hours: parsed.hours ?? 0,\n minutes: parsed.minutes ?? 0,\n seconds: parsed.seconds ?? 0,\n };\n } catch {\n return { years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0 };\n }\n };\n\n return z\n .string()\n .refine(\n value => {\n const parts = getParts(value);\n return Object.values(parts).some(v => v > 0);\n },\n {\n message: 'At least one value (years, months, days, hours, minutes, or seconds) must be non-zero',\n }\n )\n .refine(\n value => {\n const parts = getParts(value);\n const timeInDays = (parts.hours * 3600 + parts.minutes * 60 + parts.seconds) / SECONDS_PER_DAY;\n return parts.years * 365 + parts.months * 30 + parts.days + timeInDays <= MAX_DURATION_DAYS;\n },\n {\n message: `Subscription interval cannot exceed ${maxYears} years`,\n }\n );\n}\n"],"names":["MAX_INT32","MAX_INT32_DAYS","MIN_INT32","MIN_INT32_DAYS","getNumberValidator","min","max","z","issue","formatNumber","SECONDS_PER_DAY","getDaysValidator","minSeconds","maxSeconds","formatDays","seconds","num","options","formatFilesize","bytes","getISO8601DurationValidator","maxYears","MAX_DURATION_DAYS","getParts","value","parsed","Duration","parts","v","timeInDays"],"mappings":"4DAGO,MAAMA,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S,MAAMF,CAAK,EACnC,MAAO,CACH,MAAOC,EAAO,OAAS,EACvB,OAAQA,EAAO,QAAU,EACzB,MAAOA,EAAO,MAAQ,IAAMA,EAAO,OAAS,GAAK,EACjD,MAAOA,EAAO,OAAS,EACvB,QAASA,EAAO,SAAW,EAC3B,QAASA,EAAO,SAAW,CAAA,CAEnC,MAAQ,CACJ,MAAO,CAAE,MAAO,EAAG,OAAQ,EAAG,KAAM,EAAG,MAAO,EAAG,QAAS,EAAG,QAAS,CAAA,CAC1E,CACJ,EAEA,OAAOlB,EACF,SACA,OACGiB,GAAS,CACL,MAAMG,EAAQJ,EAASC,CAAK,EAC5B,OAAO,OAAO,OAAOG,CAAK,EAAE,KAAKC,GAAKA,EAAI,CAAC,CAC/C,EACA,CACI,QAAS,uFAAA,CACb,EAEH,OACGJ,GAAS,CACL,MAAMG,EAAQJ,EAASC,CAAK,EACtBK,GAAcF,EAAM,MAAQ,KAAOA,EAAM,QAAU,GAAKA,EAAM,SAAWjB,EAC/E,OAAOiB,EAAM,MAAQ,IAAMA,EAAM,OAAS,GAAKA,EAAM,KAAOE,GAAcP,CAC9E,EACA,CACI,QAAS,uCAAuCD,CAAQ,QAAA,CAC5D,CAEZ"}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { components, operations } from '@cryptlex/web-api-types/develop';
|
|
2
|
+
import { ClientPathsWithMethod } from 'openapi-fetch';
|
|
3
|
+
import { CtxClientType } from './ctx-client';
|
|
2
4
|
export type ApiSchema<T extends keyof components['schemas']> = components['schemas'][T];
|
|
3
5
|
export type ApiQuery<T extends keyof operations> = NonNullable<operations[T]['parameters']['query']>;
|
|
4
6
|
export type ApiFilter<T extends keyof operations> = Omit<ApiQuery<T>, 'page' | 'limit' | 'sort' | 'search'>;
|
|
5
7
|
export type ApiFilters<T extends keyof operations> = NonNullable<ApiFilter<T>>;
|
|
6
8
|
export type CtxPortals = 'customer-portal' | 'system-portal' | 'reseller-portal' | 'admin-portal';
|
|
7
9
|
/** Resource Name should ALWAYS be in singular form */
|
|
8
|
-
export declare const RESOURCE_NAMES: readonly ["access-token", "account", "activation", "activation-log", "admin-role", "audit-log", "automated-email", "automated-email-event-log", "card", "entitlement-set", "feature-flag", "feature", "invoice", "license", "license-template", "maintenance-policy", "organization", "plan", "product", "product-version", "profile", "release", "release-channel", "release-file", "release-platform", "
|
|
10
|
+
export declare const RESOURCE_NAMES: readonly ["access-token", "account", "activation", "activation-log", "admin-role", "audit-log", "automated-email", "automated-email-event-log", "card", "entitlement-set", "feature-flag", "feature", "invoice", "license", "license-template", "maintenance-policy", "organization", "plan", "product", "product-version", "profile", "release", "release-channel", "release-file", "release-platform", "role", "role-claim", "saml-configuration", "segment", "sending-domain", "tag", "trial", "trial-policy", "user", "user-group", "webhook", "webhook-event-log", "webhook-event", "reseller", "oidc-configuration", "tenant-database-cluster"];
|
|
9
11
|
export type CtxResourceName = (typeof RESOURCE_NAMES)[number];
|
|
10
12
|
export declare function ProjectProvider({ projectName, children }: {
|
|
11
13
|
projectName: CtxPortals;
|
|
12
14
|
children: React.ReactNode;
|
|
13
15
|
}): import("react/jsx-runtime").JSX.Element;
|
|
14
16
|
export declare function useProjectName(): CtxPortals;
|
|
17
|
+
/**
|
|
18
|
+
* Mapping from resource names to their API endpoint paths.
|
|
19
|
+
* Based on the OpenAPI spec paths.
|
|
20
|
+
*/
|
|
21
|
+
export declare const RESOURCE_ENDPOINT_MAP: Record<CtxResourceName, ClientPathsWithMethod<CtxClientType, 'get'>>;
|
|
15
22
|
export declare function useResourceFormatter(): (resourceName: string) => string;
|
|
16
23
|
/**
|
|
17
24
|
* Format multiple license parameters (expired, suspended, revoked) into a single status
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as s}from"react/jsx-runtime";import{createContext as i,use as r}from"react";import{toTitleCase as l}from"./string.js";import"lodash-es";const t={"product.displayName":"Product",product_displayName:"Product"},g=["access-token","account","activation","activation-log","admin-role","audit-log","automated-email","automated-email-event-log","card","entitlement-set","feature-flag","feature","invoice","license","license-template","maintenance-policy","organization","plan","product","product-version","profile","release","release-channel","release-file","release-platform","role","role-claim","saml-configuration","segment","sending-domain","tag","trial","trial-policy","user","user-group","webhook","webhook-event-log","webhook-event","reseller","oidc-configuration","tenant-database-cluster"],a={id:"ID",createdAt:"Creation Date",scopes:"Permissions",updatedAt:"Last Updated",expiresAt:"Expiration Date",lastSeenAt:"Last Seen",os:"OS",osVersion:"OS Version",key:"License Key",vmName:"VM Name",container:"Container",allowedIpRange:"Allowed IP Range",allowedIpRanges:"Allowed IP Ranges",allowedIpAddresses:"Allowed IP Addresses",disallowedIpAddresses:"Disallowed IP Addresses",allowVmActivation:"Allow VM Activation",disableGeoLocation:"Disable Geolocation","user.id":"User ID",userId:"User",productId:"Product",downloads:"Total Downloads",claims:"Permissions",googleSsoEnabled:"Google Login Enabled",lastAttemptedAt:"Last Attempt Date",url:"URL","trialPolicy.name":"Trial Policy Name","licensePolicy.name":"License Template Name",licensePolicy:"License Template",eventLog:"Audit Log",cc:"CC Recepients",bcc:"BCC Recepients",ipAddress:"IP Address",resellerId:"Reseller",productVersionId:"Product Version",releaseId:"Release",maintenancePolicyId:"Maintenance Policy",webhookId:"Webhook",automatedEmailId:"Automated Email","location.countryName":"Country","location.ipAddress":"IP Address","location.countryCode":"Country",organizationId:"Organization","address.country":"Country","address.addressLine1":"Address Line 1","address.addressLine2":"Address Line 2",responseStatusCode:"HTTP Status Code",resourceId:"Resource ID",Sso:"SAML SSO 2.0","reseller.name":"Reseller",sendingDomain:"Email Sending Domain"};function d(e,o){return o!=="admin-portal"&&e in t?t[e]:e in a?a[e]:l(e)}const n=i("admin-portal");function A({projectName:e,children:o}){return s(n.Provider,{value:e,children:o})}function c(){return r(n)}const f={"access-token":"/v3/personal-access-tokens",account:"/v3/admin/accounts",activation:"/v3/activations","activation-log":"/v3/activation-logs","admin-role":"/v3/roles","audit-log":"/v3/event-logs","automated-email":"/v3/automated-emails","automated-email-event-log":"/v3/automated-email-event-logs","entitlement-set":"/v3/entitlement-sets","feature-flag":"/v3/feature-flags",feature:"/v3/features",license:"/v3/licenses","license-template":"/v3/license-templates","maintenance-policy":"/v3/maintenance-policies",organization:"/v3/organizations",plan:"/v3/plans",product:"/v3/products","product-version":"/v3/product-versions",release:"/v3/releases","release-channel":"/v3/release-channels","release-file":"/v3/release-files","release-platform":"/v3/release-platforms",reseller:"/v3/resellers",role:"/v3/roles",segment:"/v3/segments","sending-domain":"/v3/sending-domains",tag:"/v3/tags",trial:"/v3/trial-activations","trial-policy":"/v3/trial-policies",user:"/v3/users","user-group":"/v3/organizations/{organizationId}/user-groups",webhook:"/v3/webhooks","webhook-event-log":"/v3/webhook-event-logs",card:"/v3/billing/payment-methods/cards",invoice:"/v3/billing/invoices",profile:"/v3/me","role-claim":"/v3/roles/claims","saml-configuration":"/v3/accounts/{id}/saml-configuration","webhook-event":"/v3/webhooks/events","oidc-configuration":"/v3/accounts/{id}/oidc-configuration","tenant-database-cluster":"/v3/admin/tenant-database-clusters"};function P(){const e=c();return o=>d(o,e)}function w(e){const o=e.expiresAt&&new Date(e.expiresAt)<new Date;switch(!0){case(e.revoked&&e.suspended&&o):return"Revoked, Suspended, Expired";case(e.revoked&&e.suspended):return"Revoked, Suspended";case(e.revoked&&o):return"Revoked, Expired";case(e.suspended&&o):return"Suspended, Expired";case e.suspended:return"Suspended";case e.revoked:return"Revoked";case o:return"Expired";default:return"Active"}}const S={windows:"Windows",macos:"macOS",linux:"Linux",ios:"iOS",android:"Android"};export{S as ALL_OS,A as ProjectProvider,f as RESOURCE_ENDPOINT_MAP,g as RESOURCE_NAMES,w as getLicenseStatus,c as useProjectName,P as useResourceFormatter};
|
|
2
2
|
//# sourceMappingURL=resources.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sources":["../../lib/utilities/resources.tsx"],"sourcesContent":["import type { components, operations } from '@cryptlex/web-api-types/develop';\nimport { createContext, use } from 'react';\nimport { toTitleCase } from './string';\n\nexport type ApiSchema<T extends keyof components['schemas']> = components['schemas'][T];\nexport type ApiQuery<T extends keyof operations> = NonNullable<operations[T]['parameters']['query']>;\nexport type ApiFilter<T extends keyof operations> = Omit<ApiQuery<T>, 'page' | 'limit' | 'sort' | 'search'>;\nexport type ApiFilters<T extends keyof operations> = NonNullable<ApiFilter<T>>;\nexport type CtxPortals = 'customer-portal' | 'system-portal' | 'reseller-portal' | 'admin-portal';\n// Display names specific to customer and reseller portal\nconst OTHER_PORTALS_DISPLAY_NAME: Record<string, string> = {\n 'product.displayName': 'Product',\n // TanStack Table converts . -> _ TODO\n product_displayName: 'Product',\n};\n\n// TODO, this drifts quite a lot from the API, should be updated\n/** Resource Name should ALWAYS be in singular form */\nexport const RESOURCE_NAMES = [\n 'access-token',\n 'account',\n 'activation',\n 'activation-log',\n 'admin-role',\n 'audit-log',\n 'automated-email',\n 'automated-email-event-log',\n 'card',\n 'entitlement-set',\n 'feature-flag',\n 'feature',\n 'invoice',\n 'license',\n 'license-template',\n 'maintenance-policy',\n 'organization',\n 'plan',\n 'product',\n 'product-version',\n 'profile',\n 'release',\n 'release-channel',\n 'release-file',\n 'release-platform',\n 'report',\n 'role',\n 'role-claim',\n 'saml-configuration',\n 'segment',\n 'sending-domain',\n 'setting',\n 'tag',\n 'team-member',\n 'trial',\n 'trial-policy',\n 'user',\n 'user-group',\n 'webhook',\n 'webhook-event-log',\n 'webhook-trigger',\n 'reseller',\n 'oidc-configuration',\n 'organization-claim',\n 'reseller-claim',\n 'tenant-database-cluster',\n 'customer',\n] as const;\nexport type CtxResourceName = (typeof RESOURCE_NAMES)[number];\n\n// TODO, use OpenAPI spec\n// export const RESOURCE_DEFINITIONS: Record<CtxResourceName, string> = {\n// account: 'Your organization account.',\n// product: 'Products are the software products you want to license',\n// license:\n// 'Licenses represent a purchase of your software. These can be linked to customers, and the license key is required to use the product.',\n// 'access-token': 'Access Tokens are used to authenticate your API requests.',\n// activation: 'Activations, also known as devices/machines/seats are the devices consuming licenses.',\n// 'activation-log': 'Activation Log is a log entry of activation/deactivation of a particular license.',\n// trial: 'Trial/Trial Activation is a device that has activated a trial of your product.',\n// 'audit-log': 'Audit logs contain all the changes made to your account.',\n// 'automated-email': 'Automated Email allow you to send marketing emails based on events on the linked product.',\n// 'automated-email-event-log':\n// 'Automated email event log is the log of all the automated email events for your product.',\n// card: 'The payment card for your account.',\n// 'feature-flag': 'Feature flags define features that make up tiers for your products.',\n// invoice: '',\n// 'license-template':\n// 'License templates are a blueprint for the licenses you create for your customers and prevent repetition when creating licenses.',\n// 'maintenance-policy': 'Maintenance policies represent support contracts and can be linked to licenses.',\n// plan: '',\n// 'product-version': 'Product Versions are sets of Feature Flags that define the tiers of your products.',\n// 'release-channel': 'Release channel is the release channel for your product.',\n// 'release-file': 'Release files are files within your created releases.',\n// 'release-platform':\n// 'Release Platforms differentiate the target platform for your release. Common platforms include \"Windows\", \"macOS\", and \"Linux\".',\n// release: 'Releases help you to manage different versions of your app, and secure distribute it to licensed users.',\n// report: 'Analytics data for your account',\n// 'role-claim': '',\n// role: 'Roles define permissions for your team.',\n// 'saml-configuration': '',\n// segment: 'Sets of filters that can be saved to filter resources.',\n// 'trial-policy': 'Trial policies are templates for creating trials for your products.',\n// 'webhook-event-log': 'Webhook Event Logs are logs of events that have occured on webhooks.',\n// 'webhook-trigger': '',\n// webhook: 'Webhooks are HTTP callbacks which are triggered by specific events.',\n// organization: '',\n// profile: '',\n// setting: '',\n// tag: 'Tags allow you to manage your licenses and customers on the dashboard.',\n// 'team-member': 'Team members can access the account based on their roles.',\n// user: 'A user refers to your customer whom you want to license your product.',\n// 'sending-domain': 'Allows Cryptlex to send emails on your behalf using your From Email address',\n// 'admin-role': 'Roles that have type admin',\n// 'user-group': 'Groups of users that you can assign licenses to.',\n// reseller: 'Resellers allow you to delegate user management to third parties or partners',\n// 'oidc-configuration': '',\n// 'organization-claim': '',\n// 'reseller-claim': '',\n// 'tenant-database-cluster': '',\n// customer: '',\n// };\n\nconst RESOURCE_DISPLAY_NAMES: Record<string, string> = {\n id: 'ID',\n createdAt: 'Creation Date',\n scopes: 'Permissions',\n updatedAt: 'Last Updated',\n expiresAt: 'Expiration Date',\n lastSeenAt: 'Last Seen',\n os: 'OS',\n osVersion: 'OS Version',\n key: 'License Key',\n vmName: 'VM Name',\n container: 'Container',\n allowedIpRange: 'Allowed IP Range',\n allowedIpRanges: 'Allowed IP Ranges',\n allowedIpAddresses: 'Allowed IP Addresses',\n disallowedIpAddresses: 'Disallowed IP Addresses',\n allowVmActivation: 'Allow VM Activation',\n disableGeoLocation: 'Disable Geolocation',\n 'user.id': 'User ID',\n userId: 'User',\n productId: 'Product',\n downloads: 'Total Downloads',\n claims: 'Permissions',\n googleSsoEnabled: 'Google Login Enabled',\n lastAttemptedAt: 'Last Attempt Date',\n url: 'URL',\n 'trialPolicy.name': 'Trial Policy Name',\n 'licensePolicy.name': 'License Template Name',\n licensePolicy: 'License Template',\n eventLog: 'Audit Log',\n cc: 'CC Recepients',\n bcc: 'BCC Recepients',\n ipAddress: 'IP Address',\n resellerId: 'Reseller',\n productVersionId: 'Product Version',\n releaseId: 'Release',\n maintenancePolicyId: 'Maintenance Policy',\n webhookId: 'Webhook',\n automatedEmailId: 'Automated Email',\n 'location.countryName': 'Country',\n 'location.ipAddress': 'IP Address',\n 'location.countryCode': 'Country',\n organizationId: 'Organization',\n 'address.country': 'Country',\n 'address.addressLine1': 'Address Line 1',\n 'address.addressLine2': 'Address Line 2',\n responseStatusCode: 'HTTP Status Code',\n resourceId: 'Resource ID',\n Sso: 'SAML SSO 2.0',\n 'reseller.name': 'Reseller',\n sendingDomain: 'Email Sending Domain',\n};\n\nfunction getResourceDisplayName(resourceName: string, portal: CtxPortals) {\n if (portal !== 'admin-portal' && resourceName in OTHER_PORTALS_DISPLAY_NAME) {\n return OTHER_PORTALS_DISPLAY_NAME[resourceName];\n } else if (resourceName in RESOURCE_DISPLAY_NAMES) {\n return RESOURCE_DISPLAY_NAMES[resourceName];\n } else {\n return toTitleCase(resourceName);\n }\n}\n\nconst ProjectContext = createContext<CtxPortals>('admin-portal');\n\nexport function ProjectProvider({ projectName, children }: { projectName: CtxPortals; children: React.ReactNode }) {\n return <ProjectContext.Provider value={projectName}>{children}</ProjectContext.Provider>;\n}\n\nexport function useProjectName(): CtxPortals {\n const projectName = use(ProjectContext);\n return projectName;\n}\n\nexport function useResourceFormatter(): (resourceName: string) => string {\n const portal = useProjectName();\n return (resourceName: string) => getResourceDisplayName(resourceName, portal);\n}\n\n/**\n * Format multiple license parameters (expired, suspended, revoked) into a single status\n */\nexport function getLicenseStatus(license: any): string {\n const licenseExpired = license.expiresAt && new Date(license.expiresAt) < new Date();\n // Status Column\n switch (true) {\n case license.revoked && license.suspended && licenseExpired:\n return 'Revoked, Suspended, Expired';\n case license.revoked && license.suspended:\n return 'Revoked, Suspended';\n case license.revoked && licenseExpired:\n return 'Revoked, Expired';\n case license.suspended && licenseExpired:\n return 'Suspended, Expired';\n case license.suspended:\n return 'Suspended';\n case license.revoked:\n return 'Revoked';\n case licenseExpired:\n return 'Expired';\n default:\n return 'Active';\n }\n}\ntype OsType = ApiSchema<'ActivationCreateRequestModel'>['os'];\nexport const ALL_OS: Record<OsType, string> = {\n windows: 'Windows',\n macos: 'macOS',\n linux: 'Linux',\n ios: 'iOS',\n android: 'Android',\n};\n"],"names":["OTHER_PORTALS_DISPLAY_NAME","RESOURCE_NAMES","RESOURCE_DISPLAY_NAMES","getResourceDisplayName","resourceName","portal","toTitleCase","ProjectContext","createContext","ProjectProvider","projectName","children","useProjectName","use","useResourceFormatter","getLicenseStatus","license","licenseExpired","ALL_OS"],"mappings":"mJAUA,MAAMA,EAAqD,CACvD,sBAAuB,UAEvB,oBAAqB,SACzB,EAIaC,EAAiB,CAC1B,eACA,UACA,aACA,iBACA,aACA,YACA,kBACA,4BACA,OACA,kBACA,eACA,UACA,UACA,UACA,mBACA,qBACA,eACA,OACA,UACA,kBACA,UACA,UACA,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ACf,OAAQR,GAAyBD,EAAuBC,EAAcC,CAAM,CAChF,CAKO,SAASU,EAAiBC,EAAsB,CACnD,MAAMC,EAAiBD,EAAQ,WAAa,IAAI,KAAKA,EAAQ,SAAS,EAAI,IAAI,KAE9E,OAAQ,GAAA,CACJ,KAAKA,EAAQ,SAAWA,EAAQ,WAAaC,GACzC,MAAO,8BACX,KAAKD,EAAQ,SAAWA,EAAQ,WAC5B,MAAO,qBACX,KAAKA,EAAQ,SAAWC,GACpB,MAAO,mBACX,KAAKD,EAAQ,WAAaC,GACtB,MAAO,qBACX,KAAKD,EAAQ,UACT,MAAO,YACX,KAAKA,EAAQ,QACT,MAAO,UACX,KAAKC,EACD,MAAO,UACX,QACI,MAAO,QAAA,CAEnB,CAEO,MAAMC,EAAiC,CAC1C,QAAS,UACT,MAAO,QACP,MAAO,QACP,IAAK,MACL,QAAS,SACb"}
|
|
1
|
+
{"version":3,"file":"resources.js","sources":["../../lib/utilities/resources.tsx"],"sourcesContent":["import type { components, operations } from '@cryptlex/web-api-types/develop';\nimport type { ClientPathsWithMethod } from 'openapi-fetch';\nimport { createContext, use } from 'react';\nimport type { CtxClientType } from './ctx-client';\nimport { toTitleCase } from './string';\n\nexport type ApiSchema<T extends keyof components['schemas']> = components['schemas'][T];\nexport type ApiQuery<T extends keyof operations> = NonNullable<operations[T]['parameters']['query']>;\nexport type ApiFilter<T extends keyof operations> = Omit<ApiQuery<T>, 'page' | 'limit' | 'sort' | 'search'>;\nexport type ApiFilters<T extends keyof operations> = NonNullable<ApiFilter<T>>;\nexport type CtxPortals = 'customer-portal' | 'system-portal' | 'reseller-portal' | 'admin-portal';\n// Display names specific to customer and reseller portal\nconst OTHER_PORTALS_DISPLAY_NAME: Record<string, string> = {\n 'product.displayName': 'Product',\n // TanStack Table converts . -> _ TODO\n product_displayName: 'Product',\n};\n\n// TODO, this drifts quite a lot from the API, should be updated\n/** Resource Name should ALWAYS be in singular form */\nexport const RESOURCE_NAMES = [\n 'access-token',\n 'account',\n 'activation',\n 'activation-log',\n 'admin-role',\n 'audit-log',\n 'automated-email',\n 'automated-email-event-log',\n 'card',\n 'entitlement-set',\n 'feature-flag',\n 'feature',\n 'invoice',\n 'license',\n 'license-template',\n 'maintenance-policy',\n 'organization',\n 'plan',\n 'product',\n 'product-version',\n 'profile',\n 'release',\n 'release-channel',\n 'release-file',\n 'release-platform',\n 'role',\n 'role-claim',\n 'saml-configuration',\n 'segment',\n 'sending-domain',\n 'tag',\n 'trial',\n 'trial-policy',\n 'user',\n 'user-group',\n 'webhook',\n 'webhook-event-log',\n 'webhook-event',\n 'reseller',\n 'oidc-configuration',\n 'tenant-database-cluster',\n] as const;\nexport type CtxResourceName = (typeof RESOURCE_NAMES)[number];\n\n// TODO, use OpenAPI spec for resource definitions\n\nconst RESOURCE_DISPLAY_NAMES: Record<string, string> = {\n id: 'ID',\n createdAt: 'Creation Date',\n scopes: 'Permissions',\n updatedAt: 'Last Updated',\n expiresAt: 'Expiration Date',\n lastSeenAt: 'Last Seen',\n os: 'OS',\n osVersion: 'OS Version',\n key: 'License Key',\n vmName: 'VM Name',\n container: 'Container',\n allowedIpRange: 'Allowed IP Range',\n allowedIpRanges: 'Allowed IP Ranges',\n allowedIpAddresses: 'Allowed IP Addresses',\n disallowedIpAddresses: 'Disallowed IP Addresses',\n allowVmActivation: 'Allow VM Activation',\n disableGeoLocation: 'Disable Geolocation',\n 'user.id': 'User ID',\n userId: 'User',\n productId: 'Product',\n downloads: 'Total Downloads',\n claims: 'Permissions',\n googleSsoEnabled: 'Google Login Enabled',\n lastAttemptedAt: 'Last Attempt Date',\n url: 'URL',\n 'trialPolicy.name': 'Trial Policy Name',\n 'licensePolicy.name': 'License Template Name',\n licensePolicy: 'License Template',\n eventLog: 'Audit Log',\n cc: 'CC Recepients',\n bcc: 'BCC Recepients',\n ipAddress: 'IP Address',\n resellerId: 'Reseller',\n productVersionId: 'Product Version',\n releaseId: 'Release',\n maintenancePolicyId: 'Maintenance Policy',\n webhookId: 'Webhook',\n automatedEmailId: 'Automated Email',\n 'location.countryName': 'Country',\n 'location.ipAddress': 'IP Address',\n 'location.countryCode': 'Country',\n organizationId: 'Organization',\n 'address.country': 'Country',\n 'address.addressLine1': 'Address Line 1',\n 'address.addressLine2': 'Address Line 2',\n responseStatusCode: 'HTTP Status Code',\n resourceId: 'Resource ID',\n Sso: 'SAML SSO 2.0',\n 'reseller.name': 'Reseller',\n sendingDomain: 'Email Sending Domain',\n};\n\nfunction getResourceDisplayName(resourceName: string, portal: CtxPortals) {\n if (portal !== 'admin-portal' && resourceName in OTHER_PORTALS_DISPLAY_NAME) {\n return OTHER_PORTALS_DISPLAY_NAME[resourceName];\n } else if (resourceName in RESOURCE_DISPLAY_NAMES) {\n return RESOURCE_DISPLAY_NAMES[resourceName];\n } else {\n return toTitleCase(resourceName);\n }\n}\n\nconst ProjectContext = createContext<CtxPortals>('admin-portal');\n\nexport function ProjectProvider({ projectName, children }: { projectName: CtxPortals; children: React.ReactNode }) {\n return <ProjectContext.Provider value={projectName}>{children}</ProjectContext.Provider>;\n}\n\nexport function useProjectName(): CtxPortals {\n const projectName = use(ProjectContext);\n return projectName;\n}\n\n/**\n * Mapping from resource names to their API endpoint paths.\n * Based on the OpenAPI spec paths.\n */\nexport const RESOURCE_ENDPOINT_MAP: Record<CtxResourceName, ClientPathsWithMethod<CtxClientType, 'get'>> = {\n 'access-token': '/v3/personal-access-tokens',\n account: '/v3/admin/accounts',\n activation: '/v3/activations',\n 'activation-log': '/v3/activation-logs',\n 'admin-role': '/v3/roles',\n 'audit-log': '/v3/event-logs',\n 'automated-email': '/v3/automated-emails',\n 'automated-email-event-log': '/v3/automated-email-event-logs',\n 'entitlement-set': '/v3/entitlement-sets',\n 'feature-flag': '/v3/feature-flags',\n feature: '/v3/features',\n license: '/v3/licenses',\n 'license-template': '/v3/license-templates',\n 'maintenance-policy': '/v3/maintenance-policies',\n organization: '/v3/organizations',\n plan: '/v3/plans',\n product: '/v3/products',\n 'product-version': '/v3/product-versions',\n release: '/v3/releases',\n 'release-channel': '/v3/release-channels',\n 'release-file': '/v3/release-files',\n 'release-platform': '/v3/release-platforms',\n reseller: '/v3/resellers',\n role: '/v3/roles',\n segment: '/v3/segments',\n 'sending-domain': '/v3/sending-domains',\n tag: '/v3/tags',\n trial: '/v3/trial-activations',\n 'trial-policy': '/v3/trial-policies',\n user: '/v3/users',\n 'user-group': '/v3/organizations/{organizationId}/user-groups',\n webhook: '/v3/webhooks',\n 'webhook-event-log': '/v3/webhook-event-logs',\n card: '/v3/billing/payment-methods/cards',\n invoice: '/v3/billing/invoices',\n /** This one is an exception, it does not return an array. DO NOT USE WITH IdSearch. */\n profile: '/v3/me',\n 'role-claim': '/v3/roles/claims',\n 'saml-configuration': '/v3/accounts/{id}/saml-configuration',\n 'webhook-event': '/v3/webhooks/events',\n 'oidc-configuration': '/v3/accounts/{id}/oidc-configuration',\n 'tenant-database-cluster': '/v3/admin/tenant-database-clusters',\n};\n\nexport function useResourceFormatter(): (resourceName: string) => string {\n const portal = useProjectName();\n return (resourceName: string) => getResourceDisplayName(resourceName, portal);\n}\n\n/**\n * Format multiple license parameters (expired, suspended, revoked) into a single status\n */\nexport function getLicenseStatus(license: any): string {\n const licenseExpired = license.expiresAt && new Date(license.expiresAt) < new Date();\n // Status Column\n switch (true) {\n case license.revoked && license.suspended && licenseExpired:\n return 'Revoked, Suspended, Expired';\n case license.revoked && license.suspended:\n return 'Revoked, Suspended';\n case license.revoked && licenseExpired:\n return 'Revoked, Expired';\n case license.suspended && licenseExpired:\n return 'Suspended, Expired';\n case license.suspended:\n return 'Suspended';\n case license.revoked:\n return 'Revoked';\n case licenseExpired:\n return 'Expired';\n default:\n return 'Active';\n }\n}\ntype OsType = ApiSchema<'ActivationCreateRequestModel'>['os'];\nexport const ALL_OS: Record<OsType, string> = {\n windows: 'Windows',\n macos: 'macOS',\n linux: 'Linux',\n ios: 'iOS',\n android: 'Android',\n};\n"],"names":["OTHER_PORTALS_DISPLAY_NAME","RESOURCE_NAMES","RESOURCE_DISPLAY_NAMES","getResourceDisplayName","resourceName","portal","toTitleCase","ProjectContext","createContext","ProjectProvider","projectName","children","useProjectName","use","RESOURCE_ENDPOINT_MAP","useResourceFormatter","getLicenseStatus","license","licenseExpired","ALL_OS"],"mappings":"mJAYA,MAAMA,EAAqD,CACvD,sBAAuB,UAEvB,oBAAqB,SACzB,EAIaC,EAAiB,CAC1B,eACA,UACA,aACA,iBACA,aACA,YACA,kBACA,4BACA,OACA,kBACA,eACA,UACA,UACA,UACA,mBACA,qBACA,eACA,OACA,UACA,kBACA,UACA,UACA,kBACA,eACA,mBACA,OACA,aACA,qBACA,UACA,iBACA,MACA,QACA,eACA,OACA,aACA,UACA,oBACA,gBACA,WACA,qBACA,yBACJ,EAKMC,EAAiD,CACnD,GAAI,KACJ,UAAW,gBACX,OAAQ,cACR,UAAW,eACX,UAAW,kBACX,WAAY,YACZ,GAAI,KACJ,UAAW,aACX,IAAK,cACL,OAAQ,UACR,UAAW,YACX,eAAgB,mBAChB,gBAAiB,oBACjB,mBAAoB,uBACpB,sBAAuB,0BACvB,kBAAmB,sBACnB,mBAAoB,sBACpB,UAAW,UACX,OAAQ,OACR,UAAW,UACX,UAAW,kBACX,OAAQ,cACR,iBAAkB,uBAClB,gBAAiB,oBACjB,IAAK,MACL,mBAAoB,oBACpB,qBAAsB,wBACtB,cAAe,mBACf,SAAU,YACV,GAAI,gBACJ,IAAK,iBACL,UAAW,aACX,WAAY,WACZ,iBAAkB,kBAClB,UAAW,UACX,oBAAqB,qBACrB,UAAW,UACX,iBAAkB,kBAClB,uBAAwB,UACxB,qBAAsB,aACtB,uBAAwB,UACxB,eAAgB,eAChB,kBAAmB,UACnB,uBAAwB,iBACxB,uBAAwB,iBACxB,mBAAoB,mBACpB,WAAY,cACZ,IAAK,eACL,gBAAiB,WACjB,cAAe,sBACnB,EAEA,SAASC,EAAuBC,EAAsBC,EAAoB,CACtE,OAAIA,IAAW,gBAAkBD,KAAgBJ,EACtC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D,EAAQ,WAAaC,GACtB,MAAO,qBACX,KAAKD,EAAQ,UACT,MAAO,YACX,KAAKA,EAAQ,QACT,MAAO,UACX,KAAKC,EACD,MAAO,UACX,QACI,MAAO,QAAA,CAEnB,CAEO,MAAMC,EAAiC,CAC1C,QAAS,UACT,MAAO,QACP,MAAO,QACP,IAAK,MACL,QAAS,SACb"}
|
|
@@ -3,3 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare function toTitleCase(input?: string): string;
|
|
5
5
|
export declare function pluralizeTimes(resourceName: string, count: number): string;
|
|
6
|
+
/**
|
|
7
|
+
* Normalizes a label string by trimming, lowercasing, and replacing whitespace with hyphens.
|
|
8
|
+
* Used for generating consistent IDs from user-facing labels.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeLabel(label: string): string;
|
package/dist/utilities/string.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{startCase as
|
|
1
|
+
import{startCase as r}from"lodash-es";function e(t){return r(t)}function a(t,n){return n>1?/y$/.test(t)?t==="Day"?"Days":t.replace(/y$/,"ies"):t.concat("s"):t}function f(t){return t.trim().toLowerCase().replace(/\s+/g,"-")}export{f as normalizeLabel,a as pluralizeTimes,e as toTitleCase};
|
|
2
2
|
//# sourceMappingURL=string.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sources":["../../lib/utilities/string.ts"],"sourcesContent":["import { startCase } from 'lodash-es';\n\n/**\n *\n */\nexport function toTitleCase(input?: string): string {\n return startCase(input);\n}\n\nexport function pluralizeTimes(resourceName: string, count: number) {\n if (count > 1) {\n if (/y$/.test(resourceName)) {\n if (resourceName === 'Day') return 'Days';\n return resourceName.replace(/y$/, 'ies');\n }\n return resourceName.concat('s');\n }\n return resourceName;\n}\n"],"names":["toTitleCase","input","startCase","pluralizeTimes","resourceName","count"],"mappings":"sCAKO,SAASA,EAAYC,EAAwB,CAChD,OAAOC,EAAUD,CAAK,CAC1B,CAEO,SAASE,EAAeC,EAAsBC,EAAe,CAChE,OAAIA,EAAQ,EACJ,KAAK,KAAKD,CAAY,EAClBA,IAAiB,MAAc,OAC5BA,EAAa,QAAQ,KAAM,KAAK,EAEpCA,EAAa,OAAO,GAAG,EAE3BA,CACX"}
|
|
1
|
+
{"version":3,"file":"string.js","sources":["../../lib/utilities/string.ts"],"sourcesContent":["import { startCase } from 'lodash-es';\n\n/**\n *\n */\nexport function toTitleCase(input?: string): string {\n return startCase(input);\n}\n\nexport function pluralizeTimes(resourceName: string, count: number) {\n if (count > 1) {\n if (/y$/.test(resourceName)) {\n if (resourceName === 'Day') return 'Days';\n return resourceName.replace(/y$/, 'ies');\n }\n return resourceName.concat('s');\n }\n return resourceName;\n}\n\n/**\n * Normalizes a label string by trimming, lowercasing, and replacing whitespace with hyphens.\n * Used for generating consistent IDs from user-facing labels.\n */\nexport function normalizeLabel(label: string): string {\n return label.trim().toLowerCase().replace(/\\s+/g, '-');\n}\n"],"names":["toTitleCase","input","startCase","pluralizeTimes","resourceName","count","normalizeLabel","label"],"mappings":"sCAKO,SAASA,EAAYC,EAAwB,CAChD,OAAOC,EAAUD,CAAK,CAC1B,CAEO,SAASE,EAAeC,EAAsBC,EAAe,CAChE,OAAIA,EAAQ,EACJ,KAAK,KAAKD,CAAY,EAClBA,IAAiB,MAAc,OAC5BA,EAAa,QAAQ,KAAM,KAAK,EAEpCA,EAAa,OAAO,GAAG,EAE3BA,CACX,CAMO,SAASE,EAAeC,EAAuB,CAClD,OAAOA,EAAM,OAAO,cAAc,QAAQ,OAAQ,GAAG,CACzD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FieldApi as FieldApiType } from '@tanstack/react-form';
|
|
2
|
+
type FieldApi = FieldApiType<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
3
|
+
/**
|
|
4
|
+
* Validates that the value of an array item is unique.
|
|
5
|
+
* @param arrayFieldName - The field name of the array.
|
|
6
|
+
* @param currentIndex - The current index of the array item.
|
|
7
|
+
* @param key - The property name of the item.
|
|
8
|
+
* @returns A validator function.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getUniqueArrayItemValidator(arrayFieldName: string, currentIndex: number, key: string): ({ value, fieldApi }: {
|
|
11
|
+
value: any;
|
|
12
|
+
fieldApi: FieldApi;
|
|
13
|
+
}) => {
|
|
14
|
+
message: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{z as m}from"zod";function I(a,o,f){return({value:t,fieldApi:l})=>{const r=l.form.state.values[a],c=s=>{if(!Array.isArray(r))return!0;const g=s.toLowerCase();let i=null;for(let e=0;e<r.length;e++){const u=r[e]?.[f];if(typeof u=="string"&&u.toLowerCase()===g){if(i===null)i=e;else if(e===o)return!1}}return!0},n=m.string().min(1).refine(s=>c(s),{message:`'${t}' already exists. Enter a unique value.`}).safeParse(t);return n.success?void 0:{message:n.error.issues[0]?.message}}}export{I as getUniqueArrayItemValidator};
|
|
2
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sources":["../../lib/utilities/validators.ts"],"sourcesContent":["import type { FieldApi as FieldApiType } from '@tanstack/react-form';\nimport { z } from 'zod';\ntype FieldApi = FieldApiType<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\n\n/**\n * Validates that the value of an array item is unique.\n * @param arrayFieldName - The field name of the array.\n * @param currentIndex - The current index of the array item.\n * @param key - The property name of the item.\n * @returns A validator function.\n */\nexport function getUniqueArrayItemValidator(arrayFieldName: string, currentIndex: number, key: string) {\n return ({ value, fieldApi }: { value: any; fieldApi: FieldApi }): { message: string } | undefined => {\n const arrayValue = fieldApi.form.state.values[arrayFieldName];\n const checkUniqueness = (stringValue: string): boolean => {\n if (!Array.isArray(arrayValue)) return true;\n\n const target = stringValue.toLowerCase();\n let firstIndex: number | null = null;\n\n for (let i = 0; i < arrayValue.length; i++) {\n const v = arrayValue[i]?.[key];\n if (typeof v !== 'string') continue;\n\n if (v.toLowerCase() === target) {\n if (firstIndex === null) {\n firstIndex = i; // first match\n } else if (i === currentIndex) {\n // this is the second+ occurrence → invalid\n return false;\n }\n }\n }\n\n // Valid if it's the first match or no match\n return true;\n };\n\n const result = z\n .string()\n .min(1)\n .refine(value => checkUniqueness(value), {\n message: `'${value}' already exists. Enter a unique value.`,\n })\n .safeParse(value);\n\n if (result.success) {\n return undefined;\n }\n\n const firstIssue = result.error.issues[0];\n return {\n message: firstIssue?.message,\n };\n };\n}\n"],"names":["getUniqueArrayItemValidator","arrayFieldName","currentIndex","key","value","fieldApi","arrayValue","checkUniqueness","stringValue","target","firstIndex","i","v","result","z"],"mappings":"wBA+BO,SAASA,EAA4BC,EAAwBC,EAAsBC,EAAa,CACnG,MAAO,CAAC,CAAE,MAAAC,EAAO,SAAAC,KAAoF,CACjG,MAAMC,EAAaD,EAAS,KAAK,MAAM,OAAOJ,CAAc,EACtDM,EAAmBC,GAAiC,CACtD,GAAI,CAAC,MAAM,QAAQF,CAAU,EAAG,MAAO,GAEvC,MAAMG,EAASD,EAAY,YAAA,EAC3B,IAAIE,EAA4B,KAEhC,QAASC,EAAI,EAAGA,EAAIL,EAAW,OAAQK,IAAK,CACxC,MAAMC,EAAIN,EAAWK,CAAC,IAAIR,CAAG,EAC7B,GAAI,OAAOS,GAAM,UAEbA,EAAE,YAAA,IAAkBH,GACpB,GAAIC,IAAe,KACfA,EAAaC,UACNA,IAAMT,EAEb,MAAO,GAGnB,CAGA,MAAO,EACX,EAEMW,EAASC,EACV,OAAA,EACA,IAAI,CAAC,EACL,OAAOV,GAASG,EAAgBH,CAAK,EAAG,CACrC,QAAS,IAAIA,CAAK,yCAAA,CACrB,EACA,UAAUA,CAAK,EAEpB,OAAIS,EAAO,QACP,OAIG,CACH,QAFeA,EAAO,MAAM,OAAO,CAAC,GAEf,OAAA,CAE7B,CACJ"}
|