@fonderie/customers 1.1.2 → 2.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.
@@ -0,0 +1,18 @@
1
+ -- Referral: a random, workspace-unique code each customer can share, plus a
2
+ -- nullable pointer to the customer who referred them (set at signup). The code
3
+ -- is 1:1 (one per customer); the relationship is 1:many (one referrer → many
4
+ -- referees, each referee has at most one referrer — enforced by the single FK).
5
+
6
+ ALTER TABLE fonderie_customers
7
+ ADD COLUMN IF NOT EXISTS referral_code TEXT,
8
+ ADD COLUMN IF NOT EXISTS referred_by UUID REFERENCES fonderie_customers(id) ON DELETE SET NULL;
9
+
10
+ -- Same workspace-scoped uniqueness as reference_code: two workspaces may share a
11
+ -- code, but never two customers in the same workspace.
12
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_fc_referral_code
13
+ ON fonderie_customers (workspace_id, referral_code)
14
+ WHERE referral_code IS NOT NULL;
15
+
16
+ -- Fast "who did this customer refer" lookups (the 1:many side).
17
+ CREATE INDEX IF NOT EXISTS idx_fc_referred_by
18
+ ON fonderie_customers (referred_by);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export type CustomerType = 'individual' | 'business';\nexport type CustomerSex = 'UNKNOWN' | 'MALE' | 'FEMALE';\nexport type CustomerLabelType = 'email' | 'phone' | 'address';\n\n/** @deprecated resolved dynamically via fonderie_customer_labels */\nexport type EmailLabel = 'work' | 'personal' | 'billing';\n/** @deprecated resolved dynamically via fonderie_customer_labels */\nexport type PhoneLabel = 'mobile' | 'office' | 'home' | 'fax';\n/** @deprecated resolved dynamically via fonderie_customer_labels */\nexport type AddressLabel = 'service' | 'billing' | 'other';\n\nexport interface ICustomerLabel {\n\tid: string;\n\ttype: CustomerLabelType;\n\tvalue: string;\n\tcreatedAt: string;\n}\n\nexport interface ICustomer {\n\tid: string;\n\tworkspaceId: string;\n\ttype: CustomerType;\n\tsex: CustomerSex;\n\tfirstName: string | null;\n\tlastName: string | null;\n\tcompanyName: string | null;\n\tavatarUrl: string | null;\n\tlocale: string;\n\treferenceCode: string | null;\n\tisBlacklisted: boolean;\n\tblacklistReason: string | null;\n\tcreatedBy: string | null;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface ICustomerEmail {\n\tid: string;\n\tcustomerId: string;\n\temail: string;\n\tlabelId: string;\n\tlabel: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n}\n\nexport interface ICustomerPhone {\n\tid: string;\n\tcustomerId: string;\n\tphone: string;\n\tlabelId: string;\n\tlabel: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n}\n\nexport interface IAddress {\n\tid: string;\n\tcountryIso: string;\n\tsubdivision1Iso: string | null;\n\tsubdivision2Iso: string | null;\n\tzipPostalCode: string;\n\tunit: string | null;\n\tline1: string | null;\n\tline2: string | null;\n}\n\nexport interface ICustomerAddress {\n\taddrId: string;\n\tcustomerId: string;\n\tlabelId: string;\n\tlabel: string;\n\tisPrimary: boolean;\n\taddress: IAddress;\n}\n\nexport interface ICustomerNote {\n\tid: string;\n\tcustomerId: string;\n\tauthorId: string | null;\n\tbody: string;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface ICustomerTag {\n\tcustomerId: string;\n\ttag: string;\n}\n\nexport interface ICustomerRelationship {\n\tid: string;\n\tworkspaceId: string;\n\tcustomerId: string;\n\trelatedId: string;\n\trelationship: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n}\n\nexport interface ICustomerShallow extends ICustomer {\n\temails: ICustomerEmail[];\n\tphones: ICustomerPhone[];\n\taddresses: ICustomerAddress[];\n\tnotes: ICustomerNote[];\n\ttags: string[];\n}\n\nexport interface ICustomerRelationshipExpanded {\n\tid: string;\n\tworkspaceId: string;\n\tcustomerId: string;\n\trelationship: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n\tcustomer: ICustomerShallow;\n}\n\nexport interface ICustomerDetail extends ICustomer {\n\temails: ICustomerEmail[];\n\tphones: ICustomerPhone[];\n\taddresses: ICustomerAddress[];\n\tnotes: ICustomerNote[];\n\trelationships: ICustomerRelationshipExpanded[];\n\ttags: string[];\n}\n\n// Depth-2 variants: depth-1 customers have their own relationships resolved.\nexport interface ICustomerShallowD2 extends ICustomerShallow {\n\trelationships: ICustomerRelationshipExpanded[];\n}\n\nexport interface ICustomerRelationshipExpandedD2 extends Omit<ICustomerRelationshipExpanded, 'customer'> {\n\tcustomer: ICustomerShallowD2;\n}\n\nexport interface ICustomerDetailD2 extends Omit<ICustomerDetail, 'relationships'> {\n\trelationships: ICustomerRelationshipExpandedD2[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export type CustomerType = 'individual' | 'business';\nexport type CustomerSex = 'UNKNOWN' | 'MALE' | 'FEMALE';\nexport type CustomerLabelType = 'email' | 'phone' | 'address';\n\n/** @deprecated resolved dynamically via fonderie_customer_labels */\nexport type EmailLabel = 'work' | 'personal' | 'billing';\n/** @deprecated resolved dynamically via fonderie_customer_labels */\nexport type PhoneLabel = 'mobile' | 'office' | 'home' | 'fax';\n/** @deprecated resolved dynamically via fonderie_customer_labels */\nexport type AddressLabel = 'service' | 'billing' | 'other';\n\nexport interface ICustomerLabel {\n\tid: string;\n\ttype: CustomerLabelType;\n\tvalue: string;\n\tcreatedAt: string;\n}\n\nexport interface ICustomer {\n\tid: string;\n\tworkspaceId: string;\n\ttype: CustomerType;\n\tsex: CustomerSex;\n\tfirstName: string | null;\n\tlastName: string | null;\n\tcompanyName: string | null;\n\tavatarUrl: string | null;\n\tlocale: string;\n\treferenceCode: string | null;\n\treferralCode: string | null;\n\treferredBy: string | null;\n\tisBlacklisted: boolean;\n\tblacklistReason: string | null;\n\tcreatedBy: string | null;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface ICustomerEmail {\n\tid: string;\n\tcustomerId: string;\n\temail: string;\n\tlabelId: string;\n\tlabel: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n}\n\nexport interface ICustomerPhone {\n\tid: string;\n\tcustomerId: string;\n\tphone: string;\n\tlabelId: string;\n\tlabel: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n}\n\nexport interface IAddress {\n\tid: string;\n\tcountryIso: string;\n\tsubdivision1Iso: string | null;\n\tsubdivision2Iso: string | null;\n\tzipPostalCode: string;\n\tunit: string | null;\n\tline1: string | null;\n\tline2: string | null;\n}\n\nexport interface ICustomerAddress {\n\taddrId: string;\n\tcustomerId: string;\n\tlabelId: string;\n\tlabel: string;\n\tisPrimary: boolean;\n\taddress: IAddress;\n}\n\nexport interface ICustomerNote {\n\tid: string;\n\tcustomerId: string;\n\tauthorId: string | null;\n\tbody: string;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface ICustomerTag {\n\tcustomerId: string;\n\ttag: string;\n}\n\nexport interface ICustomerRelationship {\n\tid: string;\n\tworkspaceId: string;\n\tcustomerId: string;\n\trelatedId: string;\n\trelationship: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n}\n\nexport interface ICustomerShallow extends ICustomer {\n\temails: ICustomerEmail[];\n\tphones: ICustomerPhone[];\n\taddresses: ICustomerAddress[];\n\tnotes: ICustomerNote[];\n\ttags: string[];\n}\n\nexport interface ICustomerRelationshipExpanded {\n\tid: string;\n\tworkspaceId: string;\n\tcustomerId: string;\n\trelationship: string;\n\tisPrimary: boolean;\n\tcreatedAt: string;\n\tcustomer: ICustomerShallow;\n}\n\nexport interface ICustomerDetail extends ICustomer {\n\temails: ICustomerEmail[];\n\tphones: ICustomerPhone[];\n\taddresses: ICustomerAddress[];\n\tnotes: ICustomerNote[];\n\trelationships: ICustomerRelationshipExpanded[];\n\ttags: string[];\n}\n\n// Depth-2 variants: depth-1 customers have their own relationships resolved.\nexport interface ICustomerShallowD2 extends ICustomerShallow {\n\trelationships: ICustomerRelationshipExpanded[];\n}\n\nexport interface ICustomerRelationshipExpandedD2 extends Omit<ICustomerRelationshipExpanded, 'customer'> {\n\tcustomer: ICustomerShallowD2;\n}\n\nexport interface ICustomerDetailD2 extends Omit<ICustomerDetail, 'relationships'> {\n\trelationships: ICustomerRelationshipExpandedD2[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
package/dist/types.d.cts CHANGED
@@ -24,6 +24,8 @@ interface ICustomer {
24
24
  avatarUrl: string | null;
25
25
  locale: string;
26
26
  referenceCode: string | null;
27
+ referralCode: string | null;
28
+ referredBy: string | null;
27
29
  isBlacklisted: boolean;
28
30
  blacklistReason: string | null;
29
31
  createdBy: string | null;
package/dist/types.d.ts CHANGED
@@ -24,6 +24,8 @@ interface ICustomer {
24
24
  avatarUrl: string | null;
25
25
  locale: string;
26
26
  referenceCode: string | null;
27
+ referralCode: string | null;
28
+ referredBy: string | null;
27
29
  isBlacklisted: boolean;
28
30
  blacklistReason: string | null;
29
31
  createdBy: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonderie/customers",
3
- "version": "1.1.2",
3
+ "version": "2.0.1",
4
4
  "description": "Workspace-scoped customer records — individuals and businesses with multiple emails, phones, addresses, notes, and tags.",
5
5
  "keywords": [
6
6
  "fonderie-js",
@@ -42,10 +42,10 @@
42
42
  "check": "biome check --write src"
43
43
  },
44
44
  "peerDependencies": {
45
- "@fonderie/core": "^0.1.1",
46
- "@fonderie/events": "^1.0.1",
45
+ "@fonderie/core": "^0.2.0",
46
+ "@fonderie/events": "^2.0.0",
47
47
  "@fonderie/store": "^0.1.1",
48
- "@fonderie/workspaces": "^1.0.1"
48
+ "@fonderie/workspaces": "^2.0.0"
49
49
  },
50
50
  "peerDependenciesMeta": {
51
51
  "@fonderie/events": {