@classytic/party 0.1.0

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,125 @@
1
+ import { z } from "zod";
2
+ //#region src/schemas/index.d.ts
3
+ declare const PARTY_KIND_VALUES: readonly ['person', 'company', 'group'];
4
+ declare const PARTY_ROLE_VALUES: readonly ['customer', 'supplier', 'contact', 'employee', 'partner'];
5
+ declare const ADDRESS_TYPE_VALUES: readonly ['billing', 'shipping', 'contact', 'other'];
6
+ declare const personNameSchema: z.ZodObject<{
7
+ given: z.ZodString;
8
+ family: z.ZodDefault<z.ZodString>;
9
+ middle: z.ZodOptional<z.ZodString>;
10
+ prefix: z.ZodOptional<z.ZodString>;
11
+ suffix: z.ZodOptional<z.ZodString>;
12
+ preferred: z.ZodOptional<z.ZodString>;
13
+ }, z.core.$strip>;
14
+ declare const partyAddressSchema: z.ZodObject<{
15
+ type: z.ZodDefault<z.ZodEnum<{
16
+ billing: "billing";
17
+ contact: "contact";
18
+ other: "other";
19
+ shipping: "shipping";
20
+ }>>;
21
+ isDefault: z.ZodDefault<z.ZodBoolean>;
22
+ label: z.ZodOptional<z.ZodString>;
23
+ name: z.ZodOptional<z.ZodString>;
24
+ phone: z.ZodOptional<z.ZodString>;
25
+ email: z.ZodOptional<z.ZodString>;
26
+ line1: z.ZodString;
27
+ line2: z.ZodOptional<z.ZodString>;
28
+ city: z.ZodString;
29
+ state: z.ZodOptional<z.ZodString>;
30
+ postalCode: z.ZodOptional<z.ZodString>;
31
+ country: z.ZodString;
32
+ }, z.core.$strip>;
33
+ declare const taxIdentitySchema: z.ZodObject<{
34
+ vat: z.ZodOptional<z.ZodString>;
35
+ bin: z.ZodOptional<z.ZodString>;
36
+ fiscalPositionCode: z.ZodOptional<z.ZodString>;
37
+ countryCode: z.ZodOptional<z.ZodString>;
38
+ }, z.core.$strip>;
39
+ declare const externalRefSchema: z.ZodObject<{
40
+ sourceId: z.ZodString;
41
+ sourceModel: z.ZodString;
42
+ }, z.core.$strip>;
43
+ /** Body for `POST /parties/resolve` (the identity resolver — the primary write). */
44
+ declare const resolvePartyBodySchema: z.ZodObject<{
45
+ kind: z.ZodOptional<z.ZodEnum<{
46
+ company: "company";
47
+ group: "group";
48
+ person: "person";
49
+ }>>;
50
+ displayName: z.ZodOptional<z.ZodString>;
51
+ legalName: z.ZodOptional<z.ZodString>;
52
+ personName: z.ZodOptional<z.ZodObject<{
53
+ given: z.ZodString;
54
+ family: z.ZodDefault<z.ZodString>;
55
+ middle: z.ZodOptional<z.ZodString>;
56
+ prefix: z.ZodOptional<z.ZodString>;
57
+ suffix: z.ZodOptional<z.ZodString>;
58
+ preferred: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strip>>;
60
+ emails: z.ZodOptional<z.ZodArray<z.ZodString>>;
61
+ phones: z.ZodOptional<z.ZodArray<z.ZodString>>;
62
+ addresses: z.ZodOptional<z.ZodArray<z.ZodObject<{
63
+ type: z.ZodDefault<z.ZodEnum<{
64
+ billing: "billing";
65
+ contact: "contact";
66
+ other: "other";
67
+ shipping: "shipping";
68
+ }>>;
69
+ isDefault: z.ZodDefault<z.ZodBoolean>;
70
+ label: z.ZodOptional<z.ZodString>;
71
+ name: z.ZodOptional<z.ZodString>;
72
+ phone: z.ZodOptional<z.ZodString>;
73
+ email: z.ZodOptional<z.ZodString>;
74
+ line1: z.ZodString;
75
+ line2: z.ZodOptional<z.ZodString>;
76
+ city: z.ZodString;
77
+ state: z.ZodOptional<z.ZodString>;
78
+ postalCode: z.ZodOptional<z.ZodString>;
79
+ country: z.ZodString;
80
+ }, z.core.$strip>>>;
81
+ taxIdentity: z.ZodOptional<z.ZodObject<{
82
+ vat: z.ZodOptional<z.ZodString>;
83
+ bin: z.ZodOptional<z.ZodString>;
84
+ fiscalPositionCode: z.ZodOptional<z.ZodString>;
85
+ countryCode: z.ZodOptional<z.ZodString>;
86
+ }, z.core.$strip>>;
87
+ roles: z.ZodOptional<z.ZodArray<z.ZodEnum<{
88
+ contact: "contact";
89
+ customer: "customer";
90
+ employee: "employee";
91
+ partner: "partner";
92
+ supplier: "supplier";
93
+ }>>>;
94
+ externalRefs: z.ZodOptional<z.ZodArray<z.ZodObject<{
95
+ sourceId: z.ZodString;
96
+ sourceModel: z.ZodString;
97
+ }, z.core.$strip>>>;
98
+ userId: z.ZodOptional<z.ZodString>;
99
+ parentId: z.ZodOptional<z.ZodString>;
100
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
101
+ }, z.core.$strip>;
102
+ declare const addRoleBodySchema: z.ZodObject<{
103
+ role: z.ZodEnum<{
104
+ contact: "contact";
105
+ customer: "customer";
106
+ employee: "employee";
107
+ partner: "partner";
108
+ supplier: "supplier";
109
+ }>;
110
+ }, z.core.$strip>;
111
+ declare const linkUserBodySchema: z.ZodObject<{
112
+ userId: z.ZodString;
113
+ }, z.core.$strip>;
114
+ declare const attachExternalRefBodySchema: z.ZodObject<{
115
+ sourceId: z.ZodString;
116
+ sourceModel: z.ZodString;
117
+ }, z.core.$strip>;
118
+ declare const mergePartyBodySchema: z.ZodObject<{
119
+ sourceId: z.ZodString;
120
+ }, z.core.$strip>;
121
+ type ResolvePartyBody = z.infer<typeof resolvePartyBodySchema>;
122
+ type AddRoleBody = z.infer<typeof addRoleBodySchema>;
123
+ type MergePartyBody = z.infer<typeof mergePartyBodySchema>;
124
+ //#endregion
125
+ export { ADDRESS_TYPE_VALUES, AddRoleBody, MergePartyBody, PARTY_KIND_VALUES, PARTY_ROLE_VALUES, ResolvePartyBody, addRoleBodySchema, attachExternalRefBodySchema, externalRefSchema, linkUserBodySchema, mergePartyBodySchema, partyAddressSchema, personNameSchema, resolvePartyBodySchema, taxIdentitySchema };
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ //#region src/schemas/index.ts
3
+ /**
4
+ * Zod 4 schemas (PACKAGE_RULES §24) — single source of truth for runtime
5
+ * validation AND arc OpenAPI. In-process bodies use `z.coerce.*`; nothing here
6
+ * is an event payload (those live in the Zod event catalog with `z.iso.*`).
7
+ */
8
+ const PARTY_KIND_VALUES = [
9
+ "person",
10
+ "company",
11
+ "group"
12
+ ];
13
+ const PARTY_ROLE_VALUES = [
14
+ "customer",
15
+ "supplier",
16
+ "contact",
17
+ "employee",
18
+ "partner"
19
+ ];
20
+ const ADDRESS_TYPE_VALUES = [
21
+ "billing",
22
+ "shipping",
23
+ "contact",
24
+ "other"
25
+ ];
26
+ const personNameSchema = z.object({
27
+ given: z.string().min(1),
28
+ family: z.string().default(""),
29
+ middle: z.string().optional(),
30
+ prefix: z.string().optional(),
31
+ suffix: z.string().optional(),
32
+ preferred: z.string().optional()
33
+ });
34
+ const partyAddressSchema = z.object({
35
+ type: z.enum(ADDRESS_TYPE_VALUES).default("contact"),
36
+ isDefault: z.boolean().default(false),
37
+ label: z.string().optional(),
38
+ name: z.string().optional(),
39
+ phone: z.string().optional(),
40
+ email: z.string().optional(),
41
+ line1: z.string().min(1),
42
+ line2: z.string().optional(),
43
+ city: z.string().min(1),
44
+ state: z.string().optional(),
45
+ postalCode: z.string().optional(),
46
+ country: z.string().length(2)
47
+ });
48
+ const taxIdentitySchema = z.object({
49
+ vat: z.string().optional(),
50
+ bin: z.string().optional(),
51
+ fiscalPositionCode: z.string().optional(),
52
+ countryCode: z.string().length(2).optional()
53
+ });
54
+ const externalRefSchema = z.object({
55
+ sourceId: z.string().min(1),
56
+ sourceModel: z.string().min(1)
57
+ });
58
+ /** Body for `POST /parties/resolve` (the identity resolver — the primary write). */
59
+ const resolvePartyBodySchema = z.object({
60
+ kind: z.enum(PARTY_KIND_VALUES).optional(),
61
+ displayName: z.string().optional(),
62
+ legalName: z.string().optional(),
63
+ personName: personNameSchema.optional(),
64
+ emails: z.array(z.string()).optional(),
65
+ phones: z.array(z.string()).optional(),
66
+ addresses: z.array(partyAddressSchema).optional(),
67
+ taxIdentity: taxIdentitySchema.optional(),
68
+ roles: z.array(z.enum(PARTY_ROLE_VALUES)).optional(),
69
+ externalRefs: z.array(externalRefSchema).optional(),
70
+ userId: z.string().optional(),
71
+ parentId: z.string().optional(),
72
+ metadata: z.record(z.string(), z.unknown()).optional()
73
+ });
74
+ const addRoleBodySchema = z.object({ role: z.enum(PARTY_ROLE_VALUES) });
75
+ const linkUserBodySchema = z.object({ userId: z.string().min(1) });
76
+ const attachExternalRefBodySchema = externalRefSchema;
77
+ const mergePartyBodySchema = z.object({ sourceId: z.string().min(1) });
78
+ //#endregion
79
+ export { ADDRESS_TYPE_VALUES, PARTY_KIND_VALUES, PARTY_ROLE_VALUES, addRoleBodySchema, attachExternalRefBodySchema, externalRefSchema, linkUserBodySchema, mergePartyBodySchema, partyAddressSchema, personNameSchema, resolvePartyBodySchema, taxIdentitySchema };
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@classytic/party",
3
+ "version": "0.1.0",
4
+ "description": "Engine-factory Party / Business-Partner identity kernel — one canonical party (person | company | group) carrying customer/supplier/contact/employee roles, contact points, addresses, B2B hierarchy, tax identity, and 1:many auth-user links. Dedup + merge + resolve. SAP-BP shape (thin identity + domain facets), NOT an Odoo god-object. PACKAGE_RULES compliant; Mongoose + mongokit + arc primitives.",
5
+ "author": "Classytic",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "engines": {
10
+ "node": ">=22"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./events": {
21
+ "types": "./dist/events.d.ts",
22
+ "default": "./dist/events.js"
23
+ },
24
+ "./schemas": {
25
+ "types": "./dist/schemas.d.ts",
26
+ "default": "./dist/schemas.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "files": [
33
+ "dist",
34
+ "README.md",
35
+ "CHANGELOG.md",
36
+ "LICENSE"
37
+ ],
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/classytic/party.git"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/classytic/party/issues"
44
+ },
45
+ "homepage": "https://github.com/classytic/party#readme",
46
+ "scripts": {
47
+ "build": "tsdown",
48
+ "typecheck": "tsc --noEmit",
49
+ "test": "vitest run --project unit --project integration",
50
+ "test:unit": "vitest run --project unit",
51
+ "test:integration": "vitest run --project integration",
52
+ "test:e2e": "vitest run --project e2e",
53
+ "test:all": "vitest run",
54
+ "test:watch": "vitest --project unit --project integration"
55
+ },
56
+ "overrides": {
57
+ "mongodb": "7.2.0"
58
+ },
59
+ "peerDependencies": {
60
+ "@classytic/mongokit": ">=3.20.0",
61
+ "@classytic/primitives": ">=0.9.1",
62
+ "@classytic/repo-core": ">=0.9.0",
63
+ "mongoose": ">=9.4.1",
64
+ "zod": ">=4.0.0"
65
+ },
66
+ "devDependencies": {
67
+ "@classytic/mongokit": "^3.20.0",
68
+ "@classytic/primitives": "^0.9.0",
69
+ "@classytic/repo-core": "^0.9.0",
70
+ "@types/node": "^25.5.0",
71
+ "mongodb-memory-server": "^10.1.4",
72
+ "mongoose": "^9.4.1",
73
+ "tsdown": "^0.22.5",
74
+ "typescript": "^7.0.2",
75
+ "vitest": "^3.2.4",
76
+ "zod": "^4.3.6"
77
+ }
78
+ }