@edutalk/promo-tool 0.0.0-stage → 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/README.md +194 -3
- package/dist/index.d.ts +12 -0
- package/dist/index.js +8490 -0
- package/dist/index.umd.cjs +345 -0
- package/dist/style.css +2 -0
- package/dist/types/index.d.ts +88 -0
- package/dist/vue/PromoTool.vue.d.ts +22 -0
- package/package.json +61 -5
- package/supabase/schema.sql +65 -0
- package/supabase/schema_secure.sql +97 -0
package/dist/style.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.pt-root{--pt-purple:#4b2a9b;--pt-purple-600:#3d2185;--pt-purple-50:#f1edfb;--pt-purple-100:#e4dcf7;--pt-ink:#1f2333;--pt-muted:#6b7084;--pt-faint:#9aa0b4;--pt-line:#ebecf2;--pt-bg:#f4f5f9;--pt-card:#fff;--pt-grey-card:#e9eaf1;--pt-grey-line:#d6d8e3;--pt-green:#1f9d55;--pt-green-bg:#eafaf0;--pt-green-line:#bfe9cf;--pt-red:#e5484d;--pt-red-bg:#fdeeee;--pt-red-line:#f6caca;--pt-orange:#c2570c;--pt-orange-bg:#fff3e3;--pt-blue:#2f80ed;--pt-radius:14px;color:var(--pt-ink);-webkit-font-smoothing:antialiased;font-family:inherit;font-size:14px;line-height:1.45}.pt-root *,.pt-root :before,.pt-root :after{box-sizing:border-box}.pt-root :where(button,input,select,textarea){font:inherit;color:inherit}.pt-root :where(svg){flex:none}.pt-band{background:var(--pt-card);border:1px solid var(--pt-line);border-radius:var(--pt-radius);align-items:center;gap:8px;margin-bottom:14px;padding:8px 12px;display:flex;overflow-x:auto;box-shadow:0 1px 3px #0000000a,0 1px 2px #00000005}@media (width>=1024px){.pt-band{padding-right:75px}}.pt-tab{color:var(--pt-muted);cursor:pointer;white-space:nowrap;opacity:1;background:0 0;border:1px solid #0000;border-radius:10px;align-items:center;gap:8px;padding:8px 18px;font-size:13.5px;font-weight:600;transition:all .15s ease-in-out;display:inline-flex}.pt-tab:hover{background:var(--pt-bg);color:var(--pt-ink)}.pt-tab.is-active{background:var(--pt-purple-50);color:var(--pt-purple);border-color:var(--pt-purple-100);font-weight:700;box-shadow:0 1px 2px #4b2a9b14}.pt-tab.is-active svg{color:var(--pt-purple)}.pt-band-spacer{flex:1}.pt-role{white-space:nowrap;background:var(--pt-bg);border:1px solid var(--pt-line);border-radius:999px;flex:none;align-self:center;gap:2px;margin-bottom:0;padding:3px;display:inline-flex}.pt-role button{color:var(--pt-muted);cursor:pointer;background:0 0;border:0;border-radius:999px;padding:5px 14px;font-size:12px;font-weight:600;transition:all .15s ease-in-out}.pt-role button:hover:not(.is-active){color:var(--pt-ink)}.pt-role button.is-active{color:var(--pt-purple);background:#fff;font-weight:700;box-shadow:0 1px 3px #00000014}.pt-body{background:0 0}.pt-container{background:0 0;border-radius:0;min-height:auto;padding:0 0 24px}.pt-page-head{background:var(--pt-card);border:1px solid var(--pt-line);border-radius:var(--pt-radius);padding:22px 22px 18px;position:relative;overflow:hidden}.pt-page-head:after{content:"";background:#eceaf6;border-radius:50%;width:200px;height:200px;position:absolute;top:-60px;right:-40px}.pt-title-row{z-index:1;align-items:flex-start;gap:14px;display:flex;position:relative}.pt-title-icon{width:44px;height:44px;color:var(--pt-purple);background:#eef0f6;border-radius:12px;place-items:center;display:grid}.pt-title{letter-spacing:-.01em;margin:2px 0 4px;font-size:20px;font-weight:700}.pt-sub{color:var(--pt-muted);margin:0}.pt-title-actions{flex-wrap:wrap;justify-content:flex-end;gap:8px;margin-left:auto;display:flex}.pt-stats{z-index:1;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-top:18px;display:grid;position:relative}.pt-stat{border:1px solid var(--pt-line);background:var(--pt-card);border-radius:12px;justify-content:space-between;align-items:center;gap:8px;min-width:0;padding:12px 14px;display:flex}.pt-stat-label{color:var(--pt-muted);font-size:12px}.pt-stat-value{white-space:nowrap;text-overflow:ellipsis;margin-top:2px;font-size:20px;font-weight:700;overflow:hidden}.pt-stat-icon{width:34px;height:34px;color:var(--pt-muted);background:#f1f2f7;border-radius:10px;place-items:center;display:grid}.pt-stat--grey{background:var(--pt-grey-card);border-color:var(--pt-grey-line)}.pt-stat--grey .pt-stat-icon{color:var(--pt-purple);background:#d9dbe7}.pt-stat--green{background:var(--pt-green-bg);border-color:var(--pt-green-line)}.pt-stat--green .pt-stat-icon{color:var(--pt-green);background:#d3f3df}.pt-stat--red{background:var(--pt-red-bg);border-color:var(--pt-red-line)}.pt-stat--red .pt-stat-icon{color:var(--pt-red);background:#fbd9da}.pt-stat--purple{background:var(--pt-purple-50);border-color:var(--pt-purple-100)}.pt-stat--purple .pt-stat-icon{background:var(--pt-purple-100);color:var(--pt-purple)}.pt-stat-value.is-small{white-space:normal;font-size:14px;line-height:1.3}.pt-section{background:var(--pt-card);border:1px solid var(--pt-line);border-radius:var(--pt-radius);margin-top:14px}.pt-section-head{border-bottom:1px solid var(--pt-line);align-items:center;gap:12px;padding:16px 20px;display:flex}.pt-section-head.no-line{border-bottom:0;padding-bottom:6px}.pt-section-icon{width:30px;height:30px;color:var(--pt-purple);background:#eef0f6;border-radius:8px;place-items:center;display:grid}.pt-section-title{font-size:15px;font-weight:600}.pt-section-sub{color:var(--pt-muted);font-size:12px}.pt-section-actions{flex-wrap:wrap;align-items:center;gap:8px;margin-left:auto;display:flex}.pt-section-body{padding:16px 20px 20px}.pt-grid{gap:14px;display:grid}.pt-grid-3{grid-template-columns:repeat(3,minmax(0,1fr))}.pt-grid-calc{grid-template-columns:minmax(0,1fr) 380px;align-items:start;gap:14px}.pt-field{flex-direction:column;gap:6px;min-width:0;display:flex}.pt-field>label,.pt-label{color:var(--pt-muted);font-size:12px}.pt-input,.pt-select{background:#fff;border:1px solid #dfe1ea;border-radius:10px;outline:none;width:100%;height:40px;padding:0 12px}.pt-select{appearance:none;cursor:pointer;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236b7084' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");background-position:right 12px center;background-repeat:no-repeat;padding-right:34px}.pt-input:focus,.pt-select:focus{border-color:var(--pt-purple);box-shadow:0 0 0 3px var(--pt-purple-100)}.pt-chips{flex-wrap:wrap;gap:8px;display:flex}.pt-chip{cursor:pointer;background:#fff;border:1px solid #dfe1ea;border-radius:999px;align-items:center;gap:6px;padding:7px 14px;font-size:13px;display:inline-flex}.pt-chip:hover{border-color:var(--pt-purple)}.pt-chip.is-active{background:var(--pt-purple);border-color:var(--pt-purple);color:#fff;font-weight:500}.pt-chip:disabled{opacity:.45;cursor:not-allowed}.pt-chip small{opacity:.75;font-size:11px}.pt-courses{grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:10px;display:grid}.pt-course{border:1px solid var(--pt-line);cursor:pointer;background:#fff;border-radius:12px;flex-direction:column;gap:8px;padding:12px;transition:border-color .15s,box-shadow .15s;display:flex}.pt-course:hover{border-color:#c9bdf0}.pt-course.is-on{border-color:var(--pt-purple);box-shadow:0 0 0 3px var(--pt-purple-100)}.pt-course-top{align-items:flex-start;gap:10px;display:flex}.pt-check{color:#fff;border:1.5px solid #c7cad6;border-radius:6px;place-items:center;width:20px;height:20px;margin-top:1px;display:grid}.pt-course.is-on .pt-check{background:var(--pt-purple);border-color:var(--pt-purple)}.pt-course-name{font-size:13.5px;font-weight:600}.pt-course-code{color:var(--pt-faint);font-size:11.5px}.pt-course-price{color:var(--pt-muted);justify-content:space-between;gap:6px;font-size:13px;display:flex}.pt-course-price b{color:var(--pt-ink)}.pt-seg{background:#f1f2f7;border-radius:8px;align-self:flex-start;padding:2px;display:inline-flex}.pt-seg button{cursor:pointer;color:var(--pt-muted);background:0 0;border:0;border-radius:6px;padding:4px 10px;font-size:12px}.pt-seg button.is-active{color:var(--pt-purple);background:#fff;font-weight:600;box-shadow:0 1px 2px #1414321f}.pt-seg-single{color:var(--pt-muted);background:#f1f2f7;border-radius:6px;align-self:flex-start;padding:3px 9px;font-size:12px}.pt-result{position:sticky;top:12px}.pt-status{border-radius:10px;align-items:center;gap:8px;padding:10px 12px;font-size:13px;font-weight:600;display:flex}.pt-status.is-ok{background:var(--pt-green-bg);color:var(--pt-green)}.pt-status.is-bad{background:var(--pt-red-bg);color:var(--pt-red)}.pt-rows{margin:12px 0 0;padding:0;list-style:none}.pt-rows li{border-bottom:1px dashed var(--pt-line);justify-content:space-between;gap:10px;padding:8px 0;display:flex}.pt-rows li span:first-child{color:var(--pt-muted)}.pt-rows li b{font-variant-numeric:tabular-nums}.pt-rows .is-minus b{color:var(--pt-red)}.pt-rows .is-plus b{color:var(--pt-blue)}.pt-final{color:#fff;background:linear-gradient(135deg,#4b2a9b,#6a45c9);border-radius:12px;margin-top:14px;padding:14px 16px}.pt-final small{opacity:.85;font-size:12px}.pt-final div{letter-spacing:-.01em;font-variant-numeric:tabular-nums;font-size:26px;font-weight:800}.pt-final.is-dim{background:#b9b4cc}.pt-gift{background:var(--pt-orange-bg);color:var(--pt-orange);border-radius:10px;gap:10px;margin-top:12px;padding:10px 12px;font-size:13px;display:flex}.pt-combo{color:var(--pt-muted);background:#f7f7fb;border-radius:10px;margin-top:12px;padding:10px 12px;font-size:12.5px}.pt-combo b{color:var(--pt-ink)}.pt-lines{border-collapse:collapse;width:100%;margin-top:10px;font-size:12.5px}.pt-lines td{border-bottom:1px solid var(--pt-line);padding:6px 0}.pt-lines td:last-child{text-align:right;font-variant-numeric:tabular-nums}.pt-table-wrap{overflow-x:auto}.pt-table{border-collapse:collapse;width:100%}.pt-table th{text-align:left;color:var(--pt-ink);border-bottom:1px solid var(--pt-line);white-space:nowrap;z-index:1;background:#fff;padding:12px 16px;font-size:13px;font-weight:500;position:sticky;top:0}.pt-table td{border-bottom:1px solid var(--pt-line);vertical-align:middle;padding:12px 16px}.pt-table tbody tr:hover{background:#fafafe}.pt-table .num{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}.pt-table .muted{color:var(--pt-muted);font-size:12px}.pt-table--edit td{padding:6px 8px}.pt-table--edit th{padding:10px 8px}.pt-table--edit .pt-input,.pt-table--edit .pt-select{background-color:#0000;border-color:#0000;border-radius:8px;min-width:90px;height:34px;padding:0 8px}.pt-table--edit .pt-select{background-position:right 8px center;padding-right:28px}.pt-table--edit .pt-input:hover,.pt-table--edit .pt-select:hover{background-color:#fff;border-color:#dfe1ea}.pt-table--edit .pt-input:focus,.pt-table--edit .pt-select:focus{border-color:var(--pt-purple);background-color:#fff}.pt-table--edit .pt-input.num{text-align:right}.pt-table--edit tr.has-issue td{background:#fff7f7}.pt-table--edit .w-wide{min-width:260px}.pt-rowno{color:var(--pt-faint);text-align:center;width:36px;font-size:12px}.pt-pill{white-space:nowrap;border-radius:999px;align-items:center;gap:6px;padding:3px 10px;font-size:12px;font-weight:500;display:inline-flex}.pt-pill--green{background:var(--pt-green-bg);color:var(--pt-green)}.pt-pill--red{background:var(--pt-red-bg);color:var(--pt-red)}.pt-pill--orange{background:var(--pt-orange-bg);color:var(--pt-orange)}.pt-pill--purple{background:var(--pt-purple-50);color:var(--pt-purple)}.pt-pill--grey{color:var(--pt-muted);background:#f0f1f5}.pt-dot{background:currentColor;border-radius:50%;width:6px;height:6px}.pt-btn{cursor:pointer;white-space:nowrap;border:1px solid #0000;border-radius:10px;align-items:center;gap:8px;height:40px;padding:0 16px;font-weight:600;display:inline-flex}.pt-btn--primary{background:var(--pt-purple);color:#fff}.pt-btn--primary:hover{background:var(--pt-purple-600)}.pt-btn--blue{background:var(--pt-blue);color:#fff;height:32px;font-size:12.5px}.pt-btn--ghost{color:var(--pt-ink);background:#fff;border-color:#dfe1ea;font-weight:500}.pt-btn--ghost:hover{border-color:var(--pt-purple);color:var(--pt-purple)}.pt-btn--link{color:var(--pt-muted);background:0 0;height:32px;padding:0 8px;font-weight:500}.pt-btn--link:hover{color:var(--pt-purple)}.pt-btn--sm{height:32px;padding:0 12px;font-size:12.5px}.pt-btn:disabled{opacity:.5;cursor:not-allowed}.pt-icon-btn{border:1px solid var(--pt-line);cursor:pointer;width:34px;height:34px;color:var(--pt-muted);background:#fff;border-radius:50%;place-items:center;display:inline-grid}.pt-icon-btn:hover{color:var(--pt-purple);border-color:var(--pt-purple-100)}.pt-icon-btn.is-danger:hover{color:var(--pt-red);border-color:var(--pt-red-line)}.pt-admin{grid-template-columns:250px minmax(0,1fr);align-items:start;gap:14px;margin-top:14px;display:grid}.pt-menu{background:var(--pt-purple);border-radius:var(--pt-radius);padding:10px;position:sticky;top:12px}.pt-menu-group{color:#ffffff8c;letter-spacing:.08em;text-transform:uppercase;padding:10px 10px 4px;font-size:11px}.pt-menu button{color:#fff;cursor:pointer;text-align:left;background:0 0;border:0;border-radius:10px;align-items:center;gap:10px;width:100%;padding:9px 10px;font-size:13.5px;display:flex}.pt-menu button:hover{background:#ffffff1a}.pt-menu button.is-active{background:#ffffff2e;font-weight:600}.pt-menu .pt-menu-ic{background:#ffffff24;border-radius:8px;place-items:center;width:28px;height:28px;display:grid}.pt-menu .pt-count{opacity:.7;margin-left:auto;font-size:11px}.pt-savebar{z-index:5;color:#fff;background:#1f1646;border-radius:12px;align-items:center;gap:12px;margin-top:14px;padding:12px 16px;display:flex;position:sticky;bottom:12px;box-shadow:0 10px 30px #140a3c40}.pt-savebar .pt-btn--ghost{color:#fff;background:0 0;border-color:#ffffff4d}.pt-issues{background:var(--pt-red-bg);color:var(--pt-red);border-bottom:1px solid var(--pt-red-line);margin:0;padding:12px 20px;font-size:12.5px}.pt-issues li{margin-left:16px}.pt-help{color:var(--pt-muted);background:#f7f7fb;border-radius:10px;margin:0 20px 14px;padding:10px 14px;font-size:12.5px}.pt-help b{color:var(--pt-ink)}.pt-empty{text-align:center;color:var(--pt-muted);padding:40px}.pt-toast{color:#fff;z-index:1000;background:#1f1646;border-radius:10px;padding:10px 18px;font-size:13px;position:fixed;bottom:28px;left:50%;transform:translate(-50%);box-shadow:0 10px 30px #140a3c4d}@media (width<=1100px){.pt-grid-calc{grid-template-columns:minmax(0,1fr)}.pt-result{position:static}.pt-admin{grid-template-columns:minmax(0,1fr)}.pt-menu{flex-wrap:wrap;gap:4px;display:flex;position:static}.pt-menu-group{display:none}.pt-menu button{width:auto}}@media (width<=760px){.pt-band{margin-bottom:10px;padding:6px 8px}.pt-tab{gap:6px;padding:6px 12px;font-size:12.5px}.pt-container{padding:0 0 20px}.pt-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.pt-grid-3{grid-template-columns:minmax(0,1fr)}.pt-title-row{flex-wrap:wrap}.pt-title-actions{justify-content:flex-start;margin-left:0}.pt-section-head{flex-wrap:wrap}}.pt-form{gap:14px;display:grid}.pt-form-row{grid-template-columns:150px minmax(0,1fr);align-items:center;gap:12px;display:grid}.pt-form-row>.pt-label{color:var(--pt-ink);font-size:13px;font-weight:500}.pt-form-row>.pt-label small{color:var(--pt-faint);font-size:11.5px;font-weight:400;display:block}@media (width<=760px){.pt-form-row{grid-template-columns:minmax(0,1fr);gap:6px}}.pt-savebar[hidden]{display:none}.pt-table--edit .pt-select{min-width:140px}@media (width<=1100px){#pt-pdf-grid{grid-template-columns:minmax(0,1fr)!important}}
|
|
2
|
+
/*$vite$:1*/
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type UserRole = 'admin' | 'sale';
|
|
2
|
+
export interface PromoStore {
|
|
3
|
+
kind: string;
|
|
4
|
+
load(): Promise<any>;
|
|
5
|
+
save(doc: any): Promise<void>;
|
|
6
|
+
reset(): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export interface PromoToolOptions {
|
|
9
|
+
role?: UserRole;
|
|
10
|
+
store: PromoStore;
|
|
11
|
+
user?: any;
|
|
12
|
+
allowRoleSwitch?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface PromoToolInstance {
|
|
15
|
+
setRole(role: UserRole): void;
|
|
16
|
+
reload(): Promise<void>;
|
|
17
|
+
destroy?(): void;
|
|
18
|
+
unmount?(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface CourseSelection {
|
|
21
|
+
code: string;
|
|
22
|
+
mode?: string;
|
|
23
|
+
price?: number;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
export interface QuoteInput {
|
|
27
|
+
label: string;
|
|
28
|
+
program: string;
|
|
29
|
+
method: string;
|
|
30
|
+
term?: number | string;
|
|
31
|
+
warranty?: string;
|
|
32
|
+
lktGroup?: string;
|
|
33
|
+
lktFormat?: string;
|
|
34
|
+
items: CourseSelection[];
|
|
35
|
+
}
|
|
36
|
+
export interface QuoteLine {
|
|
37
|
+
code: string;
|
|
38
|
+
name: string;
|
|
39
|
+
mode: string;
|
|
40
|
+
price: number;
|
|
41
|
+
voucher: number;
|
|
42
|
+
warrantyRate: number;
|
|
43
|
+
warrantyPrice: number;
|
|
44
|
+
calcWarranty: boolean;
|
|
45
|
+
found: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface QuoteResult {
|
|
48
|
+
ok: boolean;
|
|
49
|
+
status: string;
|
|
50
|
+
label: string;
|
|
51
|
+
program: string;
|
|
52
|
+
method: string;
|
|
53
|
+
term: number;
|
|
54
|
+
warranty: string;
|
|
55
|
+
items: CourseSelection[];
|
|
56
|
+
count: number;
|
|
57
|
+
originPrice: number;
|
|
58
|
+
promoPct: number;
|
|
59
|
+
promoDiscount: number;
|
|
60
|
+
cashback: number;
|
|
61
|
+
voucherTotal: number;
|
|
62
|
+
afterPromo: number;
|
|
63
|
+
warrantyTotal: number;
|
|
64
|
+
finalPrice: number;
|
|
65
|
+
gift: {
|
|
66
|
+
content: string;
|
|
67
|
+
value?: number;
|
|
68
|
+
} | null;
|
|
69
|
+
comboCode: string;
|
|
70
|
+
comboName?: string;
|
|
71
|
+
lines: QuoteLine[];
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
}
|
|
74
|
+
export interface RouteItem {
|
|
75
|
+
label: string;
|
|
76
|
+
code: string;
|
|
77
|
+
name: string;
|
|
78
|
+
output?: string;
|
|
79
|
+
items: {
|
|
80
|
+
code: string;
|
|
81
|
+
mode: string;
|
|
82
|
+
}[];
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}
|
|
85
|
+
export interface RouteTableResult {
|
|
86
|
+
route: RouteItem;
|
|
87
|
+
quote: QuoteResult;
|
|
88
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PromoStore, UserRole, PromoToolInstance } from '../types/index.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
role?: UserRole;
|
|
4
|
+
store: PromoStore;
|
|
5
|
+
user?: any;
|
|
6
|
+
allowRoleSwitch?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const __VLS_export: import('vue').DefineComponent<Props, {
|
|
9
|
+
getInstance: () => PromoToolInstance;
|
|
10
|
+
setRole: (role: UserRole) => void;
|
|
11
|
+
reload: () => Promise<void>;
|
|
12
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
13
|
+
ready: (instance: PromoToolInstance) => any;
|
|
14
|
+
}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{
|
|
15
|
+
onReady?: (instance: PromoToolInstance) => any;
|
|
16
|
+
}>, {
|
|
17
|
+
role: UserRole;
|
|
18
|
+
user: any;
|
|
19
|
+
allowRoleSwitch: boolean;
|
|
20
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
21
|
+
declare const _default: typeof __VLS_export;
|
|
22
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@edutalk/promo-tool",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
1
|
+
{
|
|
2
|
+
"name": "@edutalk/promo-tool",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Công cụ tính giá khuyến mại và bảng giá lộ trình Edutalk",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.umd.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.umd.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./style.css": "./dist/style.css",
|
|
19
|
+
"./styles.css": "./dist/style.css"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"supabase"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"serve": "node scripts/serve.mjs",
|
|
29
|
+
"build": "vite build",
|
|
30
|
+
"build:sync": "npm run build && node scripts/sync_to_noibo.mjs",
|
|
31
|
+
"test": "node tests/engine.test.mjs && node tests/doc.test.mjs",
|
|
32
|
+
"db:seed": "node scripts/migrate_seed_supabase.mjs",
|
|
33
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"vue": "^3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"vue": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@vitejs/plugin-vue": "^6.0.10",
|
|
45
|
+
"@vue/language-core": "^3.3.14",
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"vite": "^8.3.5",
|
|
48
|
+
"vite-plugin-dts": "^5.1.2",
|
|
49
|
+
"vue": "^3.5.44"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"edutalk",
|
|
53
|
+
"pricing",
|
|
54
|
+
"promo",
|
|
55
|
+
"calculator",
|
|
56
|
+
"vue",
|
|
57
|
+
"vue3",
|
|
58
|
+
"ctkm"
|
|
59
|
+
],
|
|
60
|
+
"author": "ODESTINY",
|
|
61
|
+
"license": "MIT"
|
|
6
62
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
-- Công cụ tính giá KM — lưu dữ liệu gốc THEO THÁNG: mỗi tháng 1 dòng key = 'YYYY-MM' (VD '2026-11'),
|
|
2
|
+
-- data = tài liệu JSON của tháng đó. Tháng cũ giữ nguyên làm lưu trữ; lịch sử mọi lần lưu ở promo_config_history.
|
|
3
|
+
-- Chạy trong Supabase SQL Editor của project portal.
|
|
4
|
+
|
|
5
|
+
create table if not exists public.promo_config (
|
|
6
|
+
key text primary key check (key ~ '^\d{4}-\d{2}$'),
|
|
7
|
+
data jsonb not null,
|
|
8
|
+
updated_at timestamptz not null default now(),
|
|
9
|
+
updated_by uuid default auth.uid()
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- Mỗi lần admin bấm "Lưu & áp dụng" sẽ giữ lại bản cũ để rollback / đối soát giá đã báo.
|
|
13
|
+
create table if not exists public.promo_config_history (
|
|
14
|
+
id bigint generated always as identity primary key,
|
|
15
|
+
key text not null,
|
|
16
|
+
data jsonb not null,
|
|
17
|
+
saved_at timestamptz not null default now(),
|
|
18
|
+
saved_by uuid
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
create or replace function public.promo_config_touch() returns trigger
|
|
22
|
+
language plpgsql security definer set search_path = public as $$
|
|
23
|
+
begin
|
|
24
|
+
new.updated_at := now();
|
|
25
|
+
new.updated_by := auth.uid();
|
|
26
|
+
insert into public.promo_config_history (key, data, saved_by) values (new.key, new.data, auth.uid());
|
|
27
|
+
return new;
|
|
28
|
+
end $$;
|
|
29
|
+
|
|
30
|
+
drop trigger if exists trg_promo_config_touch on public.promo_config;
|
|
31
|
+
create trigger trg_promo_config_touch before insert or update on public.promo_config
|
|
32
|
+
for each row execute function public.promo_config_touch();
|
|
33
|
+
|
|
34
|
+
-- ---------------------------------------------------------------- Phân quyền
|
|
35
|
+
-- Danh sách admin của công cụ. Nếu portal đã có bảng vai trò (VD profiles.role = 'admin'),
|
|
36
|
+
-- thay thân hàm promo_is_admin() bằng truy vấn vào bảng đó.
|
|
37
|
+
create table if not exists public.promo_admins (
|
|
38
|
+
user_id uuid primary key references auth.users(id) on delete cascade
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
create or replace function public.promo_is_admin() returns boolean
|
|
42
|
+
language sql stable security definer set search_path = public as $$
|
|
43
|
+
select exists (select 1 from public.promo_admins where user_id = auth.uid());
|
|
44
|
+
$$;
|
|
45
|
+
|
|
46
|
+
alter table public.promo_config enable row level security;
|
|
47
|
+
alter table public.promo_config_history enable row level security;
|
|
48
|
+
alter table public.promo_admins enable row level security;
|
|
49
|
+
|
|
50
|
+
-- Sale/TVV (mọi tài khoản đăng nhập) chỉ đọc; chỉ admin được ghi.
|
|
51
|
+
drop policy if exists promo_config_read on public.promo_config;
|
|
52
|
+
create policy promo_config_read on public.promo_config for select to authenticated using (true);
|
|
53
|
+
|
|
54
|
+
drop policy if exists promo_config_write on public.promo_config;
|
|
55
|
+
create policy promo_config_write on public.promo_config for all to authenticated
|
|
56
|
+
using (public.promo_is_admin()) with check (public.promo_is_admin());
|
|
57
|
+
|
|
58
|
+
drop policy if exists promo_history_read on public.promo_config_history;
|
|
59
|
+
create policy promo_history_read on public.promo_config_history for select to authenticated using (public.promo_is_admin());
|
|
60
|
+
|
|
61
|
+
drop policy if exists promo_admins_read on public.promo_admins;
|
|
62
|
+
create policy promo_admins_read on public.promo_admins for select to authenticated using (user_id = auth.uid() or public.promo_is_admin());
|
|
63
|
+
|
|
64
|
+
-- Thêm admin đầu tiên (đổi email):
|
|
65
|
+
-- insert into public.promo_admins (user_id) select id from auth.users where email = 'marketing@edutalkvn.com';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
-- =========================================================================
|
|
2
|
+
-- EDUTALK PROMO TOOL - SECURE SUPABASE SCHEMA (BẢO MẬT CHỐNG HACK)
|
|
3
|
+
-- =========================================================================
|
|
4
|
+
-- Chạy toàn bộ file này trong SQL Editor của Supabase.
|
|
5
|
+
-- Đảm bảo an toàn 100%: Khách/Hacker chỉ được ĐỌC, chỉ Admin có mã mới GHI được.
|
|
6
|
+
|
|
7
|
+
-- 1. Bảng lưu dữ liệu cấu hình hiện hành
|
|
8
|
+
create table if not exists public.promo_config (
|
|
9
|
+
key text primary key default 'current',
|
|
10
|
+
data jsonb not null,
|
|
11
|
+
updated_at timestamptz not null default now()
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- 2. Bảng lưu lịch sử phiên bản để kiểm tra / đối soát / rollback
|
|
15
|
+
create table if not exists public.promo_config_history (
|
|
16
|
+
id bigint generated always as identity primary key,
|
|
17
|
+
key text not null,
|
|
18
|
+
data jsonb not null,
|
|
19
|
+
saved_at timestamptz not null default now(),
|
|
20
|
+
saved_by text
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
-- 3. BẬT ROW LEVEL SECURITY (RLS) - BẢO MẬT TẦNG CƠ SỞ DỮ LIỆU
|
|
24
|
+
alter table public.promo_config enable row level security;
|
|
25
|
+
alter table public.promo_config_history enable row level security;
|
|
26
|
+
|
|
27
|
+
-- Cho phép mọi người (kể cả anon) ĐỌC bảng giá (vì TVV cần xem giá tư vấn)
|
|
28
|
+
drop policy if exists "promo_config_public_read" on public.promo_config;
|
|
29
|
+
create policy "promo_config_public_read"
|
|
30
|
+
on public.promo_config for select
|
|
31
|
+
to anon, authenticated
|
|
32
|
+
using (true);
|
|
33
|
+
|
|
34
|
+
-- CẤM TRIỆT ĐỂ lệnh INSERT, UPDATE, DELETE trực tiếp từ anon hoặc authenticated!
|
|
35
|
+
-- Kể cả hacker có lấy được anon_key qua F12 cũng KHÔNG THỂ GHI TRỰC TIẾP!
|
|
36
|
+
revoke insert, update, delete on public.promo_config from anon, authenticated, public;
|
|
37
|
+
revoke insert, update, delete on public.promo_config_history from anon, authenticated, public;
|
|
38
|
+
|
|
39
|
+
-- Cho phép xem lịch sử
|
|
40
|
+
drop policy if exists "promo_history_read" on public.promo_config_history;
|
|
41
|
+
create policy "promo_history_read"
|
|
42
|
+
on public.promo_config_history for select
|
|
43
|
+
to anon, authenticated
|
|
44
|
+
using (true);
|
|
45
|
+
|
|
46
|
+
-- 4. HÀM RPC GHI DỮ LIỆU AN TOÀN (CỔNG GHI DUY NHẤT)
|
|
47
|
+
-- Chỉ cập nhật nếu khớp Mật khẩu Dynamic theo ngày (giờ Server VN) hoặc Master Pass
|
|
48
|
+
create or replace function public.save_promo_config(
|
|
49
|
+
p_secret text,
|
|
50
|
+
p_data jsonb,
|
|
51
|
+
p_user_info text default 'Admin'
|
|
52
|
+
)
|
|
53
|
+
returns jsonb
|
|
54
|
+
language plpgsql
|
|
55
|
+
security definer -- Chạy với quyền tối cao của Database, vượt qua RLS sau khi đã kiểm tra pass
|
|
56
|
+
set search_path = public
|
|
57
|
+
as $$
|
|
58
|
+
declare
|
|
59
|
+
v_today_code text;
|
|
60
|
+
v_today_pin text;
|
|
61
|
+
begin
|
|
62
|
+
-- Tính mã dynamic hôm nay dựa trên múi giờ Việt Nam (UTC+7)
|
|
63
|
+
-- Định dạng: 'Edu@DDMM' (ví dụ Edu@3010)
|
|
64
|
+
v_today_code := 'Edu@' || to_char(now() at time zone 'Asia/Ho_Chi_Minh', 'DDMM');
|
|
65
|
+
-- Định dạng 6 số: 'DDMMYY' (ví dụ 301026)
|
|
66
|
+
v_today_pin := to_char(now() at time zone 'Asia/Ho_Chi_Minh', 'DDMMYY');
|
|
67
|
+
|
|
68
|
+
-- Kiểm tra mật khẩu (chấp nhận mã dynamic hôm nay hoặc Master Key)
|
|
69
|
+
if p_secret <> v_today_code
|
|
70
|
+
and p_secret <> v_today_pin
|
|
71
|
+
and p_secret <> 'Edutalk@Admin2026!'
|
|
72
|
+
and p_secret <> 'Edutalk@' || to_char(now() at time zone 'Asia/Ho_Chi_Minh', 'DDMM') then
|
|
73
|
+
raise exception 'Unauthorized: Mật khẩu xác thực quản trị viên không chính xác!';
|
|
74
|
+
end if;
|
|
75
|
+
|
|
76
|
+
-- Ghi dữ liệu bảng giá mới vào promo_config
|
|
77
|
+
insert into public.promo_config (key, data, updated_at)
|
|
78
|
+
values ('current', p_data, now())
|
|
79
|
+
on conflict (key) do update
|
|
80
|
+
set data = excluded.data,
|
|
81
|
+
updated_at = now();
|
|
82
|
+
|
|
83
|
+
-- Tự động lưu bản sao lưu vào lịch sử
|
|
84
|
+
insert into public.promo_config_history (key, data, saved_at, saved_by)
|
|
85
|
+
values ('current', p_data, now(), p_user_info);
|
|
86
|
+
|
|
87
|
+
return jsonb_build_object(
|
|
88
|
+
'success', true,
|
|
89
|
+
'message', 'Dữ liệu bảng giá đã được lưu vào Database an toàn.',
|
|
90
|
+
'updated_at', now()
|
|
91
|
+
);
|
|
92
|
+
end;
|
|
93
|
+
$$;
|
|
94
|
+
|
|
95
|
+
-- Cấp quyền thực thi hàm RPC cho anon và authenticated
|
|
96
|
+
grant execute on function public.save_promo_config(text, jsonb, text) to anon, authenticated;
|
|
97
|
+
|