@nukleus-sports/core 0.1.0 → 0.2.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.cjs +12 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -58
- package/dist/index.d.ts +23 -58
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
abbreviatePersonName: () => abbreviatePersonName,
|
|
23
24
|
canEditMarketingDeals: () => canEditMarketingDeals,
|
|
24
25
|
canEditProject: () => canEditProject,
|
|
25
26
|
canEditTaskStatus: () => canEditTaskStatus,
|
|
@@ -128,8 +129,19 @@ function canViewMarketingDeals(permission) {
|
|
|
128
129
|
function canEditMarketingDeals(permission) {
|
|
129
130
|
return permission.kind === "levels" && permission.level === "Edit";
|
|
130
131
|
}
|
|
132
|
+
|
|
133
|
+
// src/personName.ts
|
|
134
|
+
function abbreviatePersonName(name) {
|
|
135
|
+
const trimmed = name?.trim();
|
|
136
|
+
if (!trimmed) return null;
|
|
137
|
+
const parts = trimmed.split(" ");
|
|
138
|
+
const initial = parts[0]?.charAt(0).toUpperCase() ?? "";
|
|
139
|
+
const last = parts[1] ?? "";
|
|
140
|
+
return `${initial}. ${last}`;
|
|
141
|
+
}
|
|
131
142
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
143
|
0 && (module.exports = {
|
|
144
|
+
abbreviatePersonName,
|
|
133
145
|
canEditMarketingDeals,
|
|
134
146
|
canEditProject,
|
|
135
147
|
canEditTaskStatus,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/dealStatus.ts","../src/currency.ts","../src/projectPermissions.ts","../src/marketingPermission.ts"],"sourcesContent":["export * from \"./dealStatus\";\nexport * from \"./currency\";\nexport * from \"./projectPermissions\";\nexport * from \"./marketingPermission\";\n","import { format, parseISO } from \"date-fns\";\n\nexport type DealStatus = \"Active\" | \"Upcoming\" | \"Complete\";\n\ninterface DealLike {\n deal_terms?: {\n startDate?: string | null;\n } | null;\n}\n\n/** Identical logic in both nukleus-app and nukleus-clientapp's ProjectDealCard. */\nexport function getDealStatus(deal: DealLike, isCompleted: boolean): DealStatus {\n if (isCompleted) return \"Complete\";\n const start = deal.deal_terms?.startDate;\n if (start && parseISO(start) > new Date()) return \"Upcoming\";\n return \"Active\";\n}\n\n/** Identical logic in both apps' ProjectDealCard. */\nexport function formatDealDate(dateStr?: string | null): string {\n if (!dateStr) return \"—\";\n try {\n return format(parseISO(dateStr), \"MMM d, yyyy\");\n } catch {\n return dateStr;\n }\n}\n","/** Full-precision USD, e.g. \"$1,234.56\".
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/dealStatus.ts","../src/currency.ts","../src/projectPermissions.ts","../src/marketingPermission.ts","../src/personName.ts"],"sourcesContent":["export * from \"./dealStatus\";\nexport * from \"./currency\";\nexport * from \"./projectPermissions\";\nexport * from \"./marketingPermission\";\nexport * from \"./personName\";\n","import { format, parseISO } from \"date-fns\";\n\nexport type DealStatus = \"Active\" | \"Upcoming\" | \"Complete\";\n\ninterface DealLike {\n deal_terms?: {\n startDate?: string | null;\n } | null;\n}\n\n/** Identical logic in both nukleus-app and nukleus-clientapp's ProjectDealCard. */\nexport function getDealStatus(deal: DealLike, isCompleted: boolean): DealStatus {\n if (isCompleted) return \"Complete\";\n const start = deal.deal_terms?.startDate;\n if (start && parseISO(start) > new Date()) return \"Upcoming\";\n return \"Active\";\n}\n\n/** Identical logic in both apps' ProjectDealCard. */\nexport function formatDealDate(dateStr?: string | null): string {\n if (!dateStr) return \"—\";\n try {\n return format(parseISO(dateStr), \"MMM d, yyyy\");\n } catch {\n return dateStr;\n }\n}\n","/** Full-precision USD, e.g. \"$1,234.56\". */\nexport function fmtUSD(n: number): string {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n }).format(n);\n}\n\n// Reconciled from both apps -- see RECONCILIATION.md#currencyts\n/** Whole-dollar USD, e.g. \"$1,235\"; null-safe, falls back to \"--\". */\nexport function fmtUSDWhole(n?: number): string {\n return n != null\n ? new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n maximumFractionDigits: 0,\n }).format(n)\n : \"--\";\n}\n\n/** \"$54,000\" for whole dollars, \"$84.50\" otherwise. */\nexport function fmtUSDCompact(n: number): string {\n const cents = Math.round(n * 100);\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: cents % 100 === 0 ? 0 : 2,\n maximumFractionDigits: 2,\n }).format(cents / 100);\n}\n\n/** Generic \"--\"-on-empty stringifier. */\nexport function fmt(value: string | number | null | undefined, fallback = \"--\"): string {\n if (value === null || value === undefined || value === \"\") return fallback;\n return String(value);\n}\n\n/** Whole-dollar \"$\"-prefixed display via toLocaleString, no Intl currency\n * formatting -- kept distinct from fmtUSDWhole to match an exact call site. */\nexport function fmtCurrency(amount: number | null | undefined): string {\n if (amount === null || amount === undefined) return \"--\";\n return `$${Number(amount).toLocaleString(\"en-US\", {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n })}`;\n}\n\n/** MM/DD/YYYY, \"--\" on empty/invalid. */\nexport function fmtDate(dateStr: string | null | undefined): string {\n if (!dateStr) return \"--\";\n try {\n return new Date(dateStr).toLocaleDateString(\"en-US\", {\n month: \"2-digit\",\n day: \"2-digit\",\n year: \"numeric\",\n });\n } catch {\n return dateStr;\n }\n}\n","export type ProjectMemberRole = \"Owner\" | \"Editor\" | \"Viewer\";\n\n// Reconciled from both apps -- see RECONCILIATION.md#projectpermissionsts\nexport function canEditProject(role: ProjectMemberRole | null | undefined): boolean {\n return role === \"Owner\" || role === \"Editor\";\n}\n\n/** Changing task status requires Editor specifically, not just edit access. */\nexport function canEditTaskStatus(role: ProjectMemberRole | null | undefined): boolean {\n return role === \"Editor\";\n}\n\n/** Owner-only; nukleus-clientapp has no equivalent affordance today. */\nexport function canManageMembers(role: ProjectMemberRole | null | undefined): boolean {\n return role === \"Owner\";\n}\n\ninterface ProjectLike {\n status?: string | null;\n}\n\n/** Drives UI gating only -- server-side RLS already blocks writes regardless. */\nexport function isProjectCancelled(project: ProjectLike | null | undefined): boolean {\n return project?.status === \"Cancelled\";\n}\n\n// Reconciled from both apps -- see RECONCILIATION.md#projectpermissionsts\nexport function getEffectiveMemberRole(\n role: ProjectMemberRole | null | undefined,\n isCancelled: boolean,\n): ProjectMemberRole | null | undefined {\n return isCancelled ? \"Viewer\" : role;\n}\n","// Reconciled from both apps -- see RECONCILIATION.md#marketingpermissionts\nexport type MarketingPermission =\n { kind: \"levels\"; level: \"No Access\" | \"View\" | \"Edit\" } | { kind: \"linked\"; isLinked: boolean };\n\nexport function canViewMarketingDeals(permission: MarketingPermission): boolean {\n return permission.kind === \"levels\" ? permission.level !== \"No Access\" : permission.isLinked;\n}\n\n/** Always false for the \"linked\" shape -- clients never get write access. */\nexport function canEditMarketingDeals(permission: MarketingPermission): boolean {\n return permission.kind === \"levels\" && permission.level === \"Edit\";\n}\n","/** \"J. Smith\" from \"John Smith\" -- both apps' real current behavior for a\n * project deal's owner name (nukleus-app's pre-retrofit local helper and\n * clientapp's current `getInitialFullName(name, null, true)`), reconciled\n * here as the single implementation. Matches the exact algorithm both\n * apps already use: first initial of the first word + the second word\n * verbatim, dropping anything beyond that (e.g. \"John Van Buren\" -> \"J.\n * Van\", not \"J. Buren\") -- not fixed here, since fixing it would make this\n * package's output diverge from what both apps' real data already looks\n * like today. */\nexport function abbreviatePersonName(name: string | null | undefined): string | null {\n const trimmed = name?.trim();\n if (!trimmed) return null;\n const parts = trimm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K,IAAI;AAC5B;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -9,78 +9,33 @@ declare function getDealStatus(deal: DealLike, isCompleted: boolean): DealStatus
|
|
|
9
9
|
/** Identical logic in both apps' ProjectDealCard. */
|
|
10
10
|
declare function formatDealDate(dateStr?: string | null): string;
|
|
11
11
|
|
|
12
|
-
/** Full-precision USD, e.g. "$1,234.56".
|
|
13
|
-
* identical (nukleus-app is explicit about the 2-decimal default; clientapp
|
|
14
|
-
* relies on Intl's own default, which is also 2 for USD). */
|
|
12
|
+
/** Full-precision USD, e.g. "$1,234.56". */
|
|
15
13
|
declare function fmtUSD(n: number): string;
|
|
16
|
-
/** Whole-dollar USD, e.g. "$1,235"
|
|
17
|
-
* version accepted `n?: number` and fell back to "--"; clientapp's required
|
|
18
|
-
* `n: number` with no fallback. Kept the null-safe contract -- a strict
|
|
19
|
-
* superset, since every existing call site passing a real number already
|
|
20
|
-
* satisfies it too. */
|
|
14
|
+
/** Whole-dollar USD, e.g. "$1,235"; null-safe, falls back to "--". */
|
|
21
15
|
declare function fmtUSDWhole(n?: number): string;
|
|
22
|
-
/** "$54,000" for whole dollars, "$84.50" otherwise
|
|
23
|
-
* UI money format. No clientapp equivalent to reconcile against. */
|
|
16
|
+
/** "$54,000" for whole dollars, "$84.50" otherwise. */
|
|
24
17
|
declare function fmtUSDCompact(n: number): string;
|
|
25
|
-
/** Generic "--"-on-empty stringifier
|
|
26
|
-
* dialogs. */
|
|
18
|
+
/** Generic "--"-on-empty stringifier. */
|
|
27
19
|
declare function fmt(value: string | number | null | undefined, fallback?: string): string;
|
|
28
|
-
/** Whole-dollar display
|
|
29
|
-
*
|
|
30
|
-
* this is a simpler toLocaleString-based formatter the preview dialogs use
|
|
31
|
-
* directly, kept as its own function to match the exact source behavior
|
|
32
|
-
* rather than merging it into fmtUSDWhole. */
|
|
20
|
+
/** Whole-dollar "$"-prefixed display via toLocaleString, no Intl currency
|
|
21
|
+
* formatting -- kept distinct from fmtUSDWhole to match an exact call site. */
|
|
33
22
|
declare function fmtCurrency(amount: number | null | undefined): string;
|
|
34
|
-
/** MM/DD/YYYY, "--" on empty/invalid
|
|
35
|
-
* dialogs. */
|
|
23
|
+
/** MM/DD/YYYY, "--" on empty/invalid. */
|
|
36
24
|
declare function fmtDate(dateStr: string | null | undefined): string;
|
|
37
25
|
|
|
38
26
|
type ProjectMemberRole = "Owner" | "Editor" | "Viewer";
|
|
39
|
-
/** Files + task/deliverable editing are gated on this exact rule in both
|
|
40
|
-
* apps today -- duplicated independently across several files per app
|
|
41
|
-
* (`roleCanEdit`/`canUpload`/`canEditDeliverables`), never centralized.
|
|
42
|
-
* One source of truth instead of several copies that can drift apart. */
|
|
43
27
|
declare function canEditProject(role: ProjectMemberRole | null | undefined): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* nukleus-clientapp's own comment: "only 'Editor' may change task status." */
|
|
28
|
+
/** Changing task status requires Editor specifically, not just edit access. */
|
|
46
29
|
declare function canEditTaskStatus(role: ProjectMemberRole | null | undefined): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* nukleus-clientapp has no edit affordance here at all -- looks like unbuilt
|
|
49
|
-
* feature parity, not an intentional restriction (the role vocabulary
|
|
50
|
-
* already supports it). */
|
|
30
|
+
/** Owner-only; nukleus-clientapp has no equivalent affordance today. */
|
|
51
31
|
declare function canManageMembers(role: ProjectMemberRole | null | undefined): boolean;
|
|
52
32
|
interface ProjectLike {
|
|
53
33
|
status?: string | null;
|
|
54
34
|
}
|
|
55
|
-
/**
|
|
56
|
-
* server-side (RLS) regardless of this check; this just drives UI gating. */
|
|
35
|
+
/** Drives UI gating only -- server-side RLS already blocks writes regardless. */
|
|
57
36
|
declare function isProjectCancelled(project: ProjectLike | null | undefined): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* nukleus-app forces every member's effective role to "Viewer" once a
|
|
60
|
-
* project is cancelled (`useProjectReadOnly` + `effectiveMemberRole`),
|
|
61
|
-
* regardless of their stored role. nukleus-clientapp does not apply this
|
|
62
|
-
* downgrade anywhere today -- a real, confirmed asymmetry, not a styling
|
|
63
|
-
* difference. Exposed here so both apps can share the same rule once
|
|
64
|
-
* clientapp adopts it; until then, clientapp callers should apply this
|
|
65
|
-
* explicitly rather than assume parity.
|
|
66
|
-
*/
|
|
67
37
|
declare function getEffectiveMemberRole(role: ProjectMemberRole | null | undefined, isCancelled: boolean): ProjectMemberRole | null | undefined;
|
|
68
38
|
|
|
69
|
-
/**
|
|
70
|
-
* Marketing deals' permission check is NOT one shared enum downgraded for
|
|
71
|
-
* the client side -- it's two genuinely different shapes, confirmed against
|
|
72
|
-
* real code:
|
|
73
|
-
*
|
|
74
|
-
* - nukleus-app: a 3-state enum via `getPermissionLevel(PERMISSIONS.CLIENT_MARKETING)`
|
|
75
|
-
* ("No Access" | "View" | "Edit") -- the agency can have no access, view
|
|
76
|
-
* only, or full edit, independent of org membership.
|
|
77
|
-
* - nukleus-clientapp: a boolean `hasActiveAgencyLink` -- the client either
|
|
78
|
-
* has an active link to the agency that owns these deals, or doesn't.
|
|
79
|
-
* There is no view/edit distinction; clients never get write access here.
|
|
80
|
-
*
|
|
81
|
-
* Modeled as a discriminated union so each app's adapter supplies its own
|
|
82
|
-
* real shape rather than being forced through the other's.
|
|
83
|
-
*/
|
|
84
39
|
type MarketingPermission = {
|
|
85
40
|
kind: "levels";
|
|
86
41
|
level: "No Access" | "View" | "Edit";
|
|
@@ -89,8 +44,18 @@ type MarketingPermission = {
|
|
|
89
44
|
isLinked: boolean;
|
|
90
45
|
};
|
|
91
46
|
declare function canViewMarketingDeals(permission: MarketingPermission): boolean;
|
|
92
|
-
/** Always false for the "linked" shape -- clients never get write access
|
|
93
|
-
* Marketing deals today (confirmed: clientapp has zero write UI). */
|
|
47
|
+
/** Always false for the "linked" shape -- clients never get write access. */
|
|
94
48
|
declare function canEditMarketingDeals(permission: MarketingPermission): boolean;
|
|
95
49
|
|
|
96
|
-
|
|
50
|
+
/** "J. Smith" from "John Smith" -- both apps' real current behavior for a
|
|
51
|
+
* project deal's owner name (nukleus-app's pre-retrofit local helper and
|
|
52
|
+
* clientapp's current `getInitialFullName(name, null, true)`), reconciled
|
|
53
|
+
* here as the single implementation. Matches the exact algorithm both
|
|
54
|
+
* apps already use: first initial of the first word + the second word
|
|
55
|
+
* verbatim, dropping anything beyond that (e.g. "John Van Buren" -> "J.
|
|
56
|
+
* Van", not "J. Buren") -- not fixed here, since fixing it would make this
|
|
57
|
+
* package's output diverge from what both apps' real data already looks
|
|
58
|
+
* like today. */
|
|
59
|
+
declare function abbreviatePersonName(name: string | null | undefined): string | null;
|
|
60
|
+
|
|
61
|
+
export { type DealStatus, type MarketingPermission, type ProjectMemberRole, abbreviatePersonName, canEditMarketingDeals, canEditProject, canEditTaskStatus, canManageMembers, canViewMarketingDeals, fmt, fmtCurrency, fmtDate, fmtUSD, fmtUSDCompact, fmtUSDWhole, formatDealDate, getDealStatus, getEffectiveMemberRole, isProjectCancelled };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,78 +9,33 @@ declare function getDealStatus(deal: DealLike, isCompleted: boolean): DealStatus
|
|
|
9
9
|
/** Identical logic in both apps' ProjectDealCard. */
|
|
10
10
|
declare function formatDealDate(dateStr?: string | null): string;
|
|
11
11
|
|
|
12
|
-
/** Full-precision USD, e.g. "$1,234.56".
|
|
13
|
-
* identical (nukleus-app is explicit about the 2-decimal default; clientapp
|
|
14
|
-
* relies on Intl's own default, which is also 2 for USD). */
|
|
12
|
+
/** Full-precision USD, e.g. "$1,234.56". */
|
|
15
13
|
declare function fmtUSD(n: number): string;
|
|
16
|
-
/** Whole-dollar USD, e.g. "$1,235"
|
|
17
|
-
* version accepted `n?: number` and fell back to "--"; clientapp's required
|
|
18
|
-
* `n: number` with no fallback. Kept the null-safe contract -- a strict
|
|
19
|
-
* superset, since every existing call site passing a real number already
|
|
20
|
-
* satisfies it too. */
|
|
14
|
+
/** Whole-dollar USD, e.g. "$1,235"; null-safe, falls back to "--". */
|
|
21
15
|
declare function fmtUSDWhole(n?: number): string;
|
|
22
|
-
/** "$54,000" for whole dollars, "$84.50" otherwise
|
|
23
|
-
* UI money format. No clientapp equivalent to reconcile against. */
|
|
16
|
+
/** "$54,000" for whole dollars, "$84.50" otherwise. */
|
|
24
17
|
declare function fmtUSDCompact(n: number): string;
|
|
25
|
-
/** Generic "--"-on-empty stringifier
|
|
26
|
-
* dialogs. */
|
|
18
|
+
/** Generic "--"-on-empty stringifier. */
|
|
27
19
|
declare function fmt(value: string | number | null | undefined, fallback?: string): string;
|
|
28
|
-
/** Whole-dollar display
|
|
29
|
-
*
|
|
30
|
-
* this is a simpler toLocaleString-based formatter the preview dialogs use
|
|
31
|
-
* directly, kept as its own function to match the exact source behavior
|
|
32
|
-
* rather than merging it into fmtUSDWhole. */
|
|
20
|
+
/** Whole-dollar "$"-prefixed display via toLocaleString, no Intl currency
|
|
21
|
+
* formatting -- kept distinct from fmtUSDWhole to match an exact call site. */
|
|
33
22
|
declare function fmtCurrency(amount: number | null | undefined): string;
|
|
34
|
-
/** MM/DD/YYYY, "--" on empty/invalid
|
|
35
|
-
* dialogs. */
|
|
23
|
+
/** MM/DD/YYYY, "--" on empty/invalid. */
|
|
36
24
|
declare function fmtDate(dateStr: string | null | undefined): string;
|
|
37
25
|
|
|
38
26
|
type ProjectMemberRole = "Owner" | "Editor" | "Viewer";
|
|
39
|
-
/** Files + task/deliverable editing are gated on this exact rule in both
|
|
40
|
-
* apps today -- duplicated independently across several files per app
|
|
41
|
-
* (`roleCanEdit`/`canUpload`/`canEditDeliverables`), never centralized.
|
|
42
|
-
* One source of truth instead of several copies that can drift apart. */
|
|
43
27
|
declare function canEditProject(role: ProjectMemberRole | null | undefined): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* nukleus-clientapp's own comment: "only 'Editor' may change task status." */
|
|
28
|
+
/** Changing task status requires Editor specifically, not just edit access. */
|
|
46
29
|
declare function canEditTaskStatus(role: ProjectMemberRole | null | undefined): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* nukleus-clientapp has no edit affordance here at all -- looks like unbuilt
|
|
49
|
-
* feature parity, not an intentional restriction (the role vocabulary
|
|
50
|
-
* already supports it). */
|
|
30
|
+
/** Owner-only; nukleus-clientapp has no equivalent affordance today. */
|
|
51
31
|
declare function canManageMembers(role: ProjectMemberRole | null | undefined): boolean;
|
|
52
32
|
interface ProjectLike {
|
|
53
33
|
status?: string | null;
|
|
54
34
|
}
|
|
55
|
-
/**
|
|
56
|
-
* server-side (RLS) regardless of this check; this just drives UI gating. */
|
|
35
|
+
/** Drives UI gating only -- server-side RLS already blocks writes regardless. */
|
|
57
36
|
declare function isProjectCancelled(project: ProjectLike | null | undefined): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* nukleus-app forces every member's effective role to "Viewer" once a
|
|
60
|
-
* project is cancelled (`useProjectReadOnly` + `effectiveMemberRole`),
|
|
61
|
-
* regardless of their stored role. nukleus-clientapp does not apply this
|
|
62
|
-
* downgrade anywhere today -- a real, confirmed asymmetry, not a styling
|
|
63
|
-
* difference. Exposed here so both apps can share the same rule once
|
|
64
|
-
* clientapp adopts it; until then, clientapp callers should apply this
|
|
65
|
-
* explicitly rather than assume parity.
|
|
66
|
-
*/
|
|
67
37
|
declare function getEffectiveMemberRole(role: ProjectMemberRole | null | undefined, isCancelled: boolean): ProjectMemberRole | null | undefined;
|
|
68
38
|
|
|
69
|
-
/**
|
|
70
|
-
* Marketing deals' permission check is NOT one shared enum downgraded for
|
|
71
|
-
* the client side -- it's two genuinely different shapes, confirmed against
|
|
72
|
-
* real code:
|
|
73
|
-
*
|
|
74
|
-
* - nukleus-app: a 3-state enum via `getPermissionLevel(PERMISSIONS.CLIENT_MARKETING)`
|
|
75
|
-
* ("No Access" | "View" | "Edit") -- the agency can have no access, view
|
|
76
|
-
* only, or full edit, independent of org membership.
|
|
77
|
-
* - nukleus-clientapp: a boolean `hasActiveAgencyLink` -- the client either
|
|
78
|
-
* has an active link to the agency that owns these deals, or doesn't.
|
|
79
|
-
* There is no view/edit distinction; clients never get write access here.
|
|
80
|
-
*
|
|
81
|
-
* Modeled as a discriminated union so each app's adapter supplies its own
|
|
82
|
-
* real shape rather than being forced through the other's.
|
|
83
|
-
*/
|
|
84
39
|
type MarketingPermission = {
|
|
85
40
|
kind: "levels";
|
|
86
41
|
level: "No Access" | "View" | "Edit";
|
|
@@ -89,8 +44,18 @@ type MarketingPermission = {
|
|
|
89
44
|
isLinked: boolean;
|
|
90
45
|
};
|
|
91
46
|
declare function canViewMarketingDeals(permission: MarketingPermission): boolean;
|
|
92
|
-
/** Always false for the "linked" shape -- clients never get write access
|
|
93
|
-
* Marketing deals today (confirmed: clientapp has zero write UI). */
|
|
47
|
+
/** Always false for the "linked" shape -- clients never get write access. */
|
|
94
48
|
declare function canEditMarketingDeals(permission: MarketingPermission): boolean;
|
|
95
49
|
|
|
96
|
-
|
|
50
|
+
/** "J. Smith" from "John Smith" -- both apps' real current behavior for a
|
|
51
|
+
* project deal's owner name (nukleus-app's pre-retrofit local helper and
|
|
52
|
+
* clientapp's current `getInitialFullName(name, null, true)`), reconciled
|
|
53
|
+
* here as the single implementation. Matches the exact algorithm both
|
|
54
|
+
* apps already use: first initial of the first word + the second word
|
|
55
|
+
* verbatim, dropping anything beyond that (e.g. "John Van Buren" -> "J.
|
|
56
|
+
* Van", not "J. Buren") -- not fixed here, since fixing it would make this
|
|
57
|
+
* package's output diverge from what both apps' real data already looks
|
|
58
|
+
* like today. */
|
|
59
|
+
declare function abbreviatePersonName(name: string | null | undefined): string | null;
|
|
60
|
+
|
|
61
|
+
export { type DealStatus, type MarketingPermission, type ProjectMemberRole, abbreviatePersonName, canEditMarketingDeals, canEditProject, canEditTaskStatus, canManageMembers, canViewMarketingDeals, fmt, fmtCurrency, fmtDate, fmtUSD, fmtUSDCompact, fmtUSDWhole, formatDealDate, getDealStatus, getEffectiveMemberRole, isProjectCancelled };
|
package/dist/index.js
CHANGED
|
@@ -88,7 +88,18 @@ function canViewMarketingDeals(permission) {
|
|
|
88
88
|
function canEditMarketingDeals(permission) {
|
|
89
89
|
return permission.kind === "levels" && permission.level === "Edit";
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
// src/personName.ts
|
|
93
|
+
function abbreviatePersonName(name) {
|
|
94
|
+
const trimmed = name?.trim();
|
|
95
|
+
if (!trimmed) return null;
|
|
96
|
+
const parts = trimmed.split(" ");
|
|
97
|
+
const initial = parts[0]?.charAt(0).toUpperCase() ?? "";
|
|
98
|
+
const last = parts[1] ?? "";
|
|
99
|
+
return `${initial}. ${last}`;
|
|
100
|
+
}
|
|
91
101
|
export {
|
|
102
|
+
abbreviatePersonName,
|
|
92
103
|
canEditMarketingDeals,
|
|
93
104
|
canEditProject,
|
|
94
105
|
canEditTaskStatus,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dealStatus.ts","../src/currency.ts","../src/projectPermissions.ts","../src/marketingPermission.ts"],"sourcesContent":["import { format, parseISO } from \"date-fns\";\n\nexport type DealStatus = \"Active\" | \"Upcoming\" | \"Complete\";\n\ninterface DealLike {\n deal_terms?: {\n startDate?: string | null;\n } | null;\n}\n\n/** Identical logic in both nukleus-app and nukleus-clientapp's ProjectDealCard. */\nexport function getDealStatus(deal: DealLike, isCompleted: boolean): DealStatus {\n if (isCompleted) return \"Complete\";\n const start = deal.deal_terms?.startDate;\n if (start && parseISO(start) > new Date()) return \"Upcoming\";\n return \"Active\";\n}\n\n/** Identical logic in both apps' ProjectDealCard. */\nexport function formatDealDate(dateStr?: string | null): string {\n if (!dateStr) return \"—\";\n try {\n return format(parseISO(dateStr), \"MMM d, yyyy\");\n } catch {\n return dateStr;\n }\n}\n","/** Full-precision USD, e.g. \"$1,234.56\".
|
|
1
|
+
{"version":3,"sources":["../src/dealStatus.ts","../src/currency.ts","../src/projectPermissions.ts","../src/marketingPermission.ts","../src/personName.ts"],"sourcesContent":["import { format, parseISO } from \"date-fns\";\n\nexport type DealStatus = \"Active\" | \"Upcoming\" | \"Complete\";\n\ninterface DealLike {\n deal_terms?: {\n startDate?: string | null;\n } | null;\n}\n\n/** Identical logic in both nukleus-app and nukleus-clientapp's ProjectDealCard. */\nexport function getDealStatus(deal: DealLike, isCompleted: boolean): DealStatus {\n if (isCompleted) return \"Complete\";\n const start = deal.deal_terms?.startDate;\n if (start && parseISO(start) > new Date()) return \"Upcoming\";\n return \"Active\";\n}\n\n/** Identical logic in both apps' ProjectDealCard. */\nexport function formatDealDate(dateStr?: string | null): string {\n if (!dateStr) return \"—\";\n try {\n return format(parseISO(dateStr), \"MMM d, yyyy\");\n } catch {\n return dateStr;\n }\n}\n","/** Full-precision USD, e.g. \"$1,234.56\". */\nexport function fmtUSD(n: number): string {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n }).format(n);\n}\n\n// Reconciled from both apps -- see RECONCILIATION.md#currencyts\n/** Whole-dollar USD, e.g. \"$1,235\"; null-safe, falls back to \"--\". */\nexport function fmtUSDWhole(n?: number): string {\n return n != null\n ? new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n maximumFractionDigits: 0,\n }).format(n)\n : \"--\";\n}\n\n/** \"$54,000\" for whole dollars, \"$84.50\" otherwise. */\nexport function fmtUSDCompact(n: number): string {\n const cents = Math.round(n * 100);\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: cents % 100 === 0 ? 0 : 2,\n maximumFractionDigits: 2,\n }).format(cents / 100);\n}\n\n/** Generic \"--\"-on-empty stringifier. */\nexport function fmt(value: string | number | null | undefined, fallback = \"--\"): string {\n if (value === null || value === undefined || value === \"\") return fallback;\n return String(value);\n}\n\n/** Whole-dollar \"$\"-prefixed display via toLocaleString, no Intl currency\n * formatting -- kept distinct from fmtUSDWhole to match an exact call site. */\nexport function fmtCurrency(amount: number | null | undefined): string {\n if (amount === null || amount === undefined) return \"--\";\n return `$${Number(amount).toLocaleString(\"en-US\", {\n minimumFractionDigits: 0,\n maximumFractionDigits: 0,\n })}`;\n}\n\n/** MM/DD/YYYY, \"--\" on empty/invalid. */\nexport function fmtDate(dateStr: string | null | undefined): string {\n if (!dateStr) return \"--\";\n try {\n return new Date(dateStr).toLocaleDateString(\"en-US\", {\n month: \"2-digit\",\n day: \"2-digit\",\n year: \"numeric\",\n });\n } catch {\n return dateStr;\n }\n}\n","export type ProjectMemberRole = \"Owner\" | \"Editor\" | \"Viewer\";\n\n// Reconciled from both apps -- see RECONCILIATION.md#projectpermissionsts\nexport function canEditProject(role: ProjectMemberRole | null | undefined): boolean {\n return role === \"Owner\" || role === \"Editor\";\n}\n\n/** Changing task status requires Editor specifically, not just edit access. */\nexport function canEditTaskStatus(role: ProjectMemberRole | null | undefined): boolean {\n return role === \"Editor\";\n}\n\n/** Owner-only; nukleus-clientapp has no equivalent affordance today. */\nexport function canManageMembers(role: ProjectMemberRole | null | undefined): boolean {\n return role === \"Owner\";\n}\n\ninterface ProjectLike {\n status?: string | null;\n}\n\n/** Drives UI gating only -- server-side RLS already blocks writes regardless. */\nexport function isProjectCancelled(project: ProjectLike | null | undefined): boolean {\n return project?.status === \"Cancelled\";\n}\n\n// Reconciled from both apps -- see RECONCILIATION.md#projectpermissionsts\nexport function getEffectiveMemberRole(\n role: ProjectMemberRole | null | undefined,\n isCancelled: boolean,\n): ProjectMemberRole | null | undefined {\n return isCancelled ? \"Viewer\" : role;\n}\n","// Reconciled from both apps -- see RECONCILIATION.md#marketingpermissionts\nexport type MarketingPermission =\n { kind: \"levels\"; level: \"No Access\" | \"View\" | \"Edit\" } | { kind: \"linked\"; isLinked: boolean };\n\nexport function canViewMarketingDeals(permission: MarketingPermission): boolean {\n return permission.kind === \"levels\" ? permission.level !== \"No Access\" : permission.isLinked;\n}\n\n/** Always false for the \"linked\" shape -- clients never get write access. */\nexport function canEditMarketingDeals(permission: MarketingPermission): boolean {\n return permission.kind === \"levels\" && permission.level === \"Edit\";\n}\n","/** \"J. Smith\" from \"John Smith\" -- both apps' real current behavior for a\n * project deal's owner name (nukleus-app's pre-retrofit local helper and\n * clientapp's current `getInitialFullName(name, null, true)`), reconciled\n * here as the single implementation. Matches the exact algorithm both\n * apps already use: first initial of the first word + the second word\n * verbatim, dropping anything beyond that (e.g. \"John Van Buren\" -> \"J.\n * Van\", not \"J. Buren\") -- not fixed here, since fixing it would make this\n * package's output diverge from what both apps' real data already looks\n * like today. */\nexport function abbreviatePersonName(name: string | null | undefined): string | null {\n const trimmed = name?.trim();\n if (!trimmed) return null;\n const parts = trimmed.split(\" \");\n const initial = parts[0]?.charAt(0).toUpperCase() ?? \"\";\n const last = parts[1] ?? \"\";\n return `${initial}. ${last}`;\n}\n"],"mappings":";AAAA,SAAS,QAAQ,gBAAgB;AAW1B,SAAS,cAAc,MAAgB,aAAkC;AAC9E,MAAI,YAAa,QAAO;AACxB,QAAM,QAAQ,KAAK,YAAY;AAC/B,MAAI,SAAS,SAAS,KAAK,IAAI,oBAAI,KAAK,EAAG,QAAO;AAClD,SAAO;AACT;AAGO,SAAS,eAAe,SAAiC;AAC9D,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI;AACF,WAAO,OAAO,SAAS,OAAO,GAAG,aAAa;AAAA,EAChD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;;;ACzBO,SAAS,OAAO,GAAmB;AACxC,SAAO,IAAI,KAAK,aAAa,SAAS;AAAA,IACpC,OAAO;AAAA,IACP,UAAU;AAAA,IACV,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EACzB,CAAC,EAAE,OAAO,CAAC;AACb;AAIO,SAAS,YAAY,GAAoB;AAC9C,SAAO,KAAK,OACR,IAAI,KAAK,aAAa,SAAS;AAAA,IAC7B,OAAO;AAAA,IACP,UAAU;AAAA,IACV,uBAAuB;AAAA,EACzB,CAAC,EAAE,OAAO,CAAC,IACX;AACN;AAGO,SAAS,cAAc,GAAmB;AAC/C,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