@erxes/core-contract 0.1.0-v2.1 → 0.1.0-v2.3

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.
Files changed (77) hide show
  1. package/dist/activities.d.ts +1387 -139
  2. package/dist/activities.js +90 -30
  3. package/dist/audit.d.ts +1081 -33
  4. package/dist/audit.js +28 -14
  5. package/dist/auth.d.ts +2834 -26
  6. package/dist/auth.js +47 -18
  7. package/dist/automationRuns.d.ts +7 -9
  8. package/dist/automationRuns.js +12 -13
  9. package/dist/automations.d.ts +2443 -61
  10. package/dist/automations.js +41 -21
  11. package/dist/client.d.ts +30704 -0
  12. package/dist/client.js +62 -0
  13. package/dist/common.d.ts +0 -13
  14. package/dist/common.js +1 -13
  15. package/dist/companies.d.ts +1120 -10
  16. package/dist/companies.js +27 -12
  17. package/dist/contract/routes.json.js +17 -1
  18. package/dist/customerAuth.d.ts +1456 -17
  19. package/dist/customerAuth.js +33 -16
  20. package/dist/customers.d.ts +1232 -11
  21. package/dist/customers.js +28 -13
  22. package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
  23. package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
  24. package/dist/db/src/enums.js +1 -3
  25. package/dist/db/src/schema/automations.d.ts +1 -0
  26. package/dist/db/src/schema/automations.js +3 -3
  27. package/dist/db/src/schema/index.d.ts +3 -0
  28. package/dist/db/src/schema/index.js +3 -2
  29. package/dist/db/src/schema/leads.js +2 -2
  30. package/dist/db/src/schema/notes.js +92 -0
  31. package/dist/db/src/schema/payments.js +2 -2
  32. package/dist/db/src/schema/platform.js +0 -5
  33. package/dist/db/src/schema/plugins.js +7 -2
  34. package/dist/db/src/schema/transfer.js +2 -2
  35. package/dist/errors.d.ts +516 -0
  36. package/dist/errors.js +218 -0
  37. package/dist/events.d.ts +570 -121
  38. package/dist/events.js +41 -24
  39. package/dist/fields.d.ts +1456 -16
  40. package/dist/fields.js +27 -19
  41. package/dist/files.d.ts +761 -62
  42. package/dist/files.js +32 -21
  43. package/dist/index.d.ts +25187 -618
  44. package/dist/index.js +8 -7
  45. package/dist/leads.d.ts +1105 -21
  46. package/dist/leads.js +31 -13
  47. package/dist/notifications.d.ts +689 -48
  48. package/dist/notifications.js +38 -18
  49. package/dist/organizations.d.ts +260 -2
  50. package/dist/organizations.js +21 -2
  51. package/dist/payments.d.ts +1766 -62
  52. package/dist/payments.js +48 -26
  53. package/dist/platform.d.ts +12 -21
  54. package/dist/platform.js +7 -17
  55. package/dist/plugins.d.ts +802 -71
  56. package/dist/plugins.js +48 -27
  57. package/dist/products.d.ts +1380 -17
  58. package/dist/products.js +32 -16
  59. package/dist/roles.d.ts +560 -5
  60. package/dist/roles.js +20 -6
  61. package/dist/saas.d.ts +164 -2
  62. package/dist/saas.js +9 -2
  63. package/dist/tags.d.ts +340 -4
  64. package/dist/tags.js +14 -6
  65. package/dist/transfer.d.ts +1299 -12
  66. package/dist/transfer.js +32 -13
  67. package/dist/trash.d.ts +278 -21
  68. package/dist/trash.js +23 -16
  69. package/dist/users.d.ts +1206 -18
  70. package/dist/users.js +35 -13
  71. package/dist/values.d.ts +0 -9
  72. package/dist/values.js +2 -7
  73. package/dist/views.d.ts +396 -5
  74. package/dist/views.js +10 -7
  75. package/dist/webhooks.d.ts +765 -9
  76. package/dist/webhooks.js +18 -10
  77. package/package.json +6 -2
@@ -1,16 +1,18 @@
1
1
  import { NOTIFICATION_PRIORITIES } from "./db/src/enums.js";
2
2
  import { notifications } from "./db/src/schema/platform.js";
3
3
  import "./db/src/schema/index.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
4
5
  import { NotificationDelivery } from "./values.js";
5
6
  import { CursorQuery, Id, QueryFlag, cursorPageOf, isoDate } from "./common.js";
6
- import { ActorRef, AppLink, DedupeKey, EntityRef, EventType } from "./platform.js";
7
+ import { AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
7
8
  import { oc } from "@orpc/contract";
8
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
9
  import { z } from "zod";
10
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
10
11
  // src/notifications.ts
11
12
  const Notification = createSelectSchema(notifications, {
12
13
  id: Id,
13
14
  data: z.record(z.string(), z.unknown()),
15
+ readAt: isoDate,
14
16
  createdAt: isoDate
15
17
  }).pick({
16
18
  id: true,
@@ -23,11 +25,15 @@ const Notification = createSelectSchema(notifications, {
23
25
  /** Details to show when opened; core's `*.updated` kinds carry `{ changes: { field: [before, after] } }`. */
24
26
  data: true,
25
27
  priority: true,
28
+ /** The plugin's own record it is about. */
29
+ entityType: true,
30
+ entityId: true,
31
+ /** Who it is from: a team member (`actorId` = user id), a plugin (its name) or `system`. */
32
+ actorType: true,
33
+ actorId: true,
34
+ /** Null while unread. */
35
+ readAt: true,
26
36
  createdAt: true
27
- }).extend({
28
- entity: EntityRef.nullable(),
29
- actor: ActorRef,
30
- read: z.boolean()
31
37
  });
32
38
  const NotificationInput = createUpdateSchema(notifications, {
33
39
  kind: () => EventType,
@@ -36,7 +42,9 @@ const NotificationInput = createUpdateSchema(notifications, {
36
42
  link: AppLink.optional(),
37
43
  data: () => z.record(z.string(), z.unknown()).refine((value) => JSON.stringify(value).length <= 8e3, "at most 8 KB"),
38
44
  priority: z.enum(NOTIFICATION_PRIORITIES).default("normal"),
39
- dedupeKey: DedupeKey.optional()
45
+ dedupeKey: DedupeKey.optional(),
46
+ entityType: EntityType.optional(),
47
+ entityId: Id.optional()
40
48
  }).pick({
41
49
  /** Must start with the plugin's name: `hr.leave.requested`. */
42
50
  kind: true,
@@ -47,17 +55,19 @@ const NotificationInput = createUpdateSchema(notifications, {
47
55
  data: true,
48
56
  priority: true,
49
57
  /** Retry-safe: one notification per recipient and key. */
50
- dedupeKey: true
58
+ dedupeKey: true,
59
+ /** The plugin's own record it is about. */
60
+ entityType: true,
61
+ entityId: true
51
62
  }).required({
52
63
  kind: true,
53
64
  title: true
54
65
  }).extend({
55
66
  /** Team members to notify (active members of the organisation). */
56
67
  userIds: z.array(Id).min(1).max(500),
57
- entity: EntityRef.optional(),
58
68
  /** The team member who caused it, if any (shown as the sender). */
59
69
  actorUserId: Id.optional()
60
- });
70
+ }).refine((value) => value.entityType === void 0 === (value.entityId === void 0), "entityType and entityId go together");
61
71
  /**
62
72
  * Notifications core sends itself. Members mute any of them, or a plugin's
63
73
  * notifications by its name, in their notification settings.
@@ -100,9 +110,19 @@ const NotificationSettings = z.object({
100
110
  /** Desktop notifications in this member's browsers (each browser also asks permission). */
101
111
  browser: z.boolean()
102
112
  });
103
- /** The signed-in member's inbox. Plugins create notifications with `create`. */
113
+ const { ALWAYS_ON, INVALID_ACTOR, INVALID_OWNER, INVALID_RECIPIENT, INVALID_TYPE } = ERRORS;
114
+ /** What these procedures answer with besides the common errors. */
115
+ const base = oc.errors({
116
+ ...COMMON_ERRORS,
117
+ /** The signed-in member's inbox. Plugins create notifications with `create`. */
118
+ ALWAYS_ON,
119
+ INVALID_ACTOR,
120
+ INVALID_OWNER,
121
+ INVALID_RECIPIENT,
122
+ INVALID_TYPE
123
+ });
104
124
  const notificationsContract = {
105
- list: oc.route({
125
+ list: base.route({
106
126
  method: "GET",
107
127
  path: "/notifications",
108
128
  summary: "My notifications, newest first"
@@ -113,7 +133,7 @@ const notificationsContract = {
113
133
  /** A kind, or a prefix ending in `.` or `*` (`core.customer.`). */
114
134
  kind: z.string().trim().max(100).optional()
115
135
  })).output(cursorPageOf(Notification)),
116
- unreadCount: oc.route({
136
+ unreadCount: base.route({
117
137
  method: "GET",
118
138
  path: "/notifications/unread-count",
119
139
  summary: "My unread notifications, in total and per inbox (core and each plugin); `source` for one inbox"
@@ -121,7 +141,7 @@ const notificationsContract = {
121
141
  count: z.int(),
122
142
  bySource: z.record(z.string(), z.int())
123
143
  })),
124
- markRead: oc.route({
144
+ markRead: base.route({
125
145
  method: "POST",
126
146
  path: "/notifications/read",
127
147
  summary: "Mark some (`ids`), one inbox’s (`source`) or all of my notifications read, or unread with `read: false`"
@@ -130,17 +150,17 @@ const notificationsContract = {
130
150
  source: z.string().trim().max(40).optional(),
131
151
  read: z.boolean().default(true)
132
152
  })).output(z.object({ updated: z.int() })),
133
- remove: oc.route({
153
+ remove: base.route({
134
154
  method: "DELETE",
135
155
  path: "/notifications/{id}",
136
156
  summary: "Remove one of my notifications"
137
157
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
138
- settings: oc.route({
158
+ settings: base.route({
139
159
  method: "GET",
140
160
  path: "/notifications/settings",
141
161
  summary: "My notification settings"
142
162
  }).output(NotificationSettings),
143
- updateSettings: oc.route({
163
+ updateSettings: base.route({
144
164
  method: "PUT",
145
165
  path: "/notifications/settings",
146
166
  summary: "Where each group of notifications goes, and the email and browser switches"
@@ -149,7 +169,7 @@ const notificationsContract = {
149
169
  email: z.boolean().optional(),
150
170
  browser: z.boolean().optional()
151
171
  })).output(NotificationSettings),
152
- create: oc.route({
172
+ create: base.route({
153
173
  method: "POST",
154
174
  path: "/notifications",
155
175
  successStatus: 201,
@@ -30,7 +30,136 @@ export declare const organizationsContract: {
30
30
  }, {
31
31
  out: {};
32
32
  in: {};
33
- }>, Record<never, never>, Record<never, never>>;
33
+ }>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
34
+ UNAUTHORIZED: {
35
+ status: number;
36
+ };
37
+ NOT_ALLOWED: {
38
+ status: number;
39
+ data: z.ZodOptional<z.ZodObject<{
40
+ permission: z.ZodString;
41
+ }, z.core.$strip>>;
42
+ };
43
+ PLUGIN_ONLY: {
44
+ status: number;
45
+ };
46
+ MEMBERS_ONLY: {
47
+ status: number;
48
+ };
49
+ ORG_REQUIRED: {
50
+ status: number;
51
+ };
52
+ SCOPE_REQUIRED: {
53
+ status: number;
54
+ };
55
+ SERVICE_TOKEN_REQUIRED: {
56
+ status: number;
57
+ };
58
+ ORGANIZATION_DISABLED: {
59
+ status: number;
60
+ data: z.ZodObject<{
61
+ manageUrl: z.ZodNullable<z.ZodString>;
62
+ }, z.core.$strip>;
63
+ };
64
+ NOT_IN_PLAN: {
65
+ status: number;
66
+ data: z.ZodOptional<z.ZodObject<{
67
+ manageUrl: z.ZodNullable<z.ZodString>;
68
+ }, z.core.$strip>>;
69
+ };
70
+ READ_ONLY: {
71
+ status: number;
72
+ };
73
+ TOO_MANY_REQUESTS: {
74
+ status: number;
75
+ };
76
+ INVALID_INPUT: {
77
+ status: number;
78
+ data: z.ZodObject<{
79
+ issues: z.ZodArray<z.ZodObject<{
80
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
81
+ message: z.ZodString;
82
+ }, z.core.$strip>>;
83
+ }, z.core.$strip>;
84
+ };
85
+ NOT_FOUND: {
86
+ status: number;
87
+ };
88
+ TAKEN: {
89
+ status: number;
90
+ data: z.ZodObject<{
91
+ field: z.ZodString;
92
+ id: z.ZodOptional<z.ZodString>;
93
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
94
+ }, z.core.$strip>;
95
+ };
96
+ INVALID_CURSOR: {
97
+ status: number;
98
+ };
99
+ INVALID_REFERENCE: {
100
+ status: number;
101
+ data: z.ZodObject<{
102
+ field: z.ZodString;
103
+ }, z.core.$strip>;
104
+ };
105
+ INVALID_FILTER: {
106
+ status: number;
107
+ };
108
+ FILTER_TOO_SLOW: {
109
+ status: number;
110
+ };
111
+ BEYOND_OWN_PERMISSIONS: {
112
+ status: number;
113
+ data: z.ZodOptional<z.ZodObject<{
114
+ permissions: z.ZodArray<z.ZodString>;
115
+ }, z.core.$strip>>;
116
+ };
117
+ BUILTIN_ROLE: {
118
+ status: number;
119
+ };
120
+ FIXED_ROLE: {
121
+ status: number;
122
+ };
123
+ INVALID_CLIENT: {
124
+ status: number;
125
+ };
126
+ INVALID_SUBDOMAIN: {
127
+ status: number;
128
+ };
129
+ LAST_OPEN_STAGE: {
130
+ status: number;
131
+ };
132
+ LEAD_STAGE_IN_USE: {
133
+ status: number;
134
+ data: z.ZodObject<{
135
+ count: z.ZodInt;
136
+ }, z.core.$strip>;
137
+ };
138
+ NAMESPACE_REQUIRED: {
139
+ status: number;
140
+ };
141
+ NOT_INSTALLED: {
142
+ status: number;
143
+ };
144
+ OWNER_ONLY_PERMISSION: {
145
+ status: number;
146
+ data: z.ZodObject<{
147
+ permissions: z.ZodArray<z.ZodString>;
148
+ }, z.core.$strip>;
149
+ };
150
+ ROLE_IN_USE: {
151
+ status: number;
152
+ };
153
+ ROLE_NOT_FOUND: {
154
+ status: number;
155
+ };
156
+ UNKNOWN_PERMISSION: {
157
+ status: number;
158
+ data: z.ZodObject<{
159
+ permissions: z.ZodArray<z.ZodString>;
160
+ }, z.core.$strip>;
161
+ };
162
+ }>, Record<never, never>>;
34
163
  update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
35
164
  name: z.ZodOptional<z.ZodString>;
36
165
  country: z.ZodOptional<z.ZodString & z.ZodType<"AD" | "AE" | "AF" | "AG" | "AI" | "AL" | "AM" | "AN" | "AO" | "AQ" | "AR" | "AS" | "AT" | "AU" | "AW" | "AX" | "AZ" | "BA" | "BB" | "BD" | "BE" | "BF" | "BG" | "BH" | "BI" | "BJ" | "BL" | "BM" | "BN" | "BO" | "BQ" | "BR" | "BS" | "BT" | "BV" | "BW" | "BY" | "BZ" | "CA" | "CC" | "CD" | "CF" | "CG" | "CH" | "CI" | "CK" | "CL" | "CM" | "CN" | "CO" | "CR" | "CU" | "CV" | "CW" | "CX" | "CY" | "CZ" | "DE" | "DJ" | "DK" | "DM" | "DO" | "DZ" | "EC" | "EE" | "EG" | "EH" | "ER" | "ES" | "ET" | "FI" | "FJ" | "FK" | "FM" | "FO" | "FR" | "GA" | "GB" | "GD" | "GE" | "GF" | "GG" | "GH" | "GI" | "GL" | "GM" | "GN" | "GP" | "GQ" | "GR" | "GS" | "GT" | "GU" | "GW" | "GY" | "HK" | "HM" | "HN" | "HR" | "HT" | "HU" | "ID" | "IE" | "IL" | "IM" | "IN" | "IO" | "IQ" | "IR" | "IS" | "IT" | "JE" | "JM" | "JO" | "JP" | "KE" | "KG" | "KH" | "KI" | "KM" | "KN" | "KP" | "KR" | "KW" | "KY" | "KZ" | "LA" | "LB" | "LC" | "LI" | "LK" | "LR" | "LS" | "LT" | "LU" | "LV" | "LY" | "MA" | "MC" | "MD" | "ME" | "MF" | "MG" | "MH" | "MK" | "ML" | "MM" | "MN" | "MO" | "MP" | "MQ" | "MR" | "MS" | "MT" | "MU" | "MV" | "MW" | "MX" | "MY" | "MZ" | "NA" | "NC" | "NE" | "NF" | "NG" | "NI" | "NL" | "NO" | "NP" | "NR" | "NU" | "NZ" | "OM" | "PA" | "PE" | "PF" | "PG" | "PH" | "PK" | "PL" | "PM" | "PN" | "PR" | "PS" | "PT" | "PW" | "PY" | "QA" | "RE" | "RO" | "RS" | "RU" | "RW" | "SA" | "SB" | "SC" | "SD" | "SE" | "SG" | "SH" | "SI" | "SJ" | "SK" | "SL" | "SM" | "SN" | "SO" | "SR" | "SS" | "ST" | "SV" | "SX" | "SY" | "SZ" | "TC" | "TD" | "TF" | "TG" | "TH" | "TJ" | "TK" | "TL" | "TM" | "TN" | "TO" | "TR" | "TT" | "TV" | "TW" | "TZ" | "UA" | "UG" | "UM" | "US" | "UY" | "UZ" | "VA" | "VC" | "VE" | "VG" | "VI" | "VN" | "VU" | "WF" | "WS" | "XK" | "YE" | "YT" | "ZA" | "ZM" | "ZW", string, z.core.$ZodTypeInternals<"AD" | "AE" | "AF" | "AG" | "AI" | "AL" | "AM" | "AN" | "AO" | "AQ" | "AR" | "AS" | "AT" | "AU" | "AW" | "AX" | "AZ" | "BA" | "BB" | "BD" | "BE" | "BF" | "BG" | "BH" | "BI" | "BJ" | "BL" | "BM" | "BN" | "BO" | "BQ" | "BR" | "BS" | "BT" | "BV" | "BW" | "BY" | "BZ" | "CA" | "CC" | "CD" | "CF" | "CG" | "CH" | "CI" | "CK" | "CL" | "CM" | "CN" | "CO" | "CR" | "CU" | "CV" | "CW" | "CX" | "CY" | "CZ" | "DE" | "DJ" | "DK" | "DM" | "DO" | "DZ" | "EC" | "EE" | "EG" | "EH" | "ER" | "ES" | "ET" | "FI" | "FJ" | "FK" | "FM" | "FO" | "FR" | "GA" | "GB" | "GD" | "GE" | "GF" | "GG" | "GH" | "GI" | "GL" | "GM" | "GN" | "GP" | "GQ" | "GR" | "GS" | "GT" | "GU" | "GW" | "GY" | "HK" | "HM" | "HN" | "HR" | "HT" | "HU" | "ID" | "IE" | "IL" | "IM" | "IN" | "IO" | "IQ" | "IR" | "IS" | "IT" | "JE" | "JM" | "JO" | "JP" | "KE" | "KG" | "KH" | "KI" | "KM" | "KN" | "KP" | "KR" | "KW" | "KY" | "KZ" | "LA" | "LB" | "LC" | "LI" | "LK" | "LR" | "LS" | "LT" | "LU" | "LV" | "LY" | "MA" | "MC" | "MD" | "ME" | "MF" | "MG" | "MH" | "MK" | "ML" | "MM" | "MN" | "MO" | "MP" | "MQ" | "MR" | "MS" | "MT" | "MU" | "MV" | "MW" | "MX" | "MY" | "MZ" | "NA" | "NC" | "NE" | "NF" | "NG" | "NI" | "NL" | "NO" | "NP" | "NR" | "NU" | "NZ" | "OM" | "PA" | "PE" | "PF" | "PG" | "PH" | "PK" | "PL" | "PM" | "PN" | "PR" | "PS" | "PT" | "PW" | "PY" | "QA" | "RE" | "RO" | "RS" | "RU" | "RW" | "SA" | "SB" | "SC" | "SD" | "SE" | "SG" | "SH" | "SI" | "SJ" | "SK" | "SL" | "SM" | "SN" | "SO" | "SR" | "SS" | "ST" | "SV" | "SX" | "SY" | "SZ" | "TC" | "TD" | "TF" | "TG" | "TH" | "TJ" | "TK" | "TL" | "TM" | "TN" | "TO" | "TR" | "TT" | "TV" | "TW" | "TZ" | "UA" | "UG" | "UM" | "US" | "UY" | "UZ" | "VA" | "VC" | "VE" | "VG" | "VI" | "VN" | "VU" | "WF" | "WS" | "XK" | "YE" | "YT" | "ZA" | "ZM" | "ZW", string>>>;
@@ -48,5 +177,134 @@ export declare const organizationsContract: {
48
177
  }, {
49
178
  out: {};
50
179
  in: {};
51
- }>, Record<never, never>, Record<never, never>>;
180
+ }>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
181
+ UNAUTHORIZED: {
182
+ status: number;
183
+ };
184
+ NOT_ALLOWED: {
185
+ status: number;
186
+ data: z.ZodOptional<z.ZodObject<{
187
+ permission: z.ZodString;
188
+ }, z.core.$strip>>;
189
+ };
190
+ PLUGIN_ONLY: {
191
+ status: number;
192
+ };
193
+ MEMBERS_ONLY: {
194
+ status: number;
195
+ };
196
+ ORG_REQUIRED: {
197
+ status: number;
198
+ };
199
+ SCOPE_REQUIRED: {
200
+ status: number;
201
+ };
202
+ SERVICE_TOKEN_REQUIRED: {
203
+ status: number;
204
+ };
205
+ ORGANIZATION_DISABLED: {
206
+ status: number;
207
+ data: z.ZodObject<{
208
+ manageUrl: z.ZodNullable<z.ZodString>;
209
+ }, z.core.$strip>;
210
+ };
211
+ NOT_IN_PLAN: {
212
+ status: number;
213
+ data: z.ZodOptional<z.ZodObject<{
214
+ manageUrl: z.ZodNullable<z.ZodString>;
215
+ }, z.core.$strip>>;
216
+ };
217
+ READ_ONLY: {
218
+ status: number;
219
+ };
220
+ TOO_MANY_REQUESTS: {
221
+ status: number;
222
+ };
223
+ INVALID_INPUT: {
224
+ status: number;
225
+ data: z.ZodObject<{
226
+ issues: z.ZodArray<z.ZodObject<{
227
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
228
+ message: z.ZodString;
229
+ }, z.core.$strip>>;
230
+ }, z.core.$strip>;
231
+ };
232
+ NOT_FOUND: {
233
+ status: number;
234
+ };
235
+ TAKEN: {
236
+ status: number;
237
+ data: z.ZodObject<{
238
+ field: z.ZodString;
239
+ id: z.ZodOptional<z.ZodString>;
240
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
241
+ }, z.core.$strip>;
242
+ };
243
+ INVALID_CURSOR: {
244
+ status: number;
245
+ };
246
+ INVALID_REFERENCE: {
247
+ status: number;
248
+ data: z.ZodObject<{
249
+ field: z.ZodString;
250
+ }, z.core.$strip>;
251
+ };
252
+ INVALID_FILTER: {
253
+ status: number;
254
+ };
255
+ FILTER_TOO_SLOW: {
256
+ status: number;
257
+ };
258
+ BEYOND_OWN_PERMISSIONS: {
259
+ status: number;
260
+ data: z.ZodOptional<z.ZodObject<{
261
+ permissions: z.ZodArray<z.ZodString>;
262
+ }, z.core.$strip>>;
263
+ };
264
+ BUILTIN_ROLE: {
265
+ status: number;
266
+ };
267
+ FIXED_ROLE: {
268
+ status: number;
269
+ };
270
+ INVALID_CLIENT: {
271
+ status: number;
272
+ };
273
+ INVALID_SUBDOMAIN: {
274
+ status: number;
275
+ };
276
+ LAST_OPEN_STAGE: {
277
+ status: number;
278
+ };
279
+ LEAD_STAGE_IN_USE: {
280
+ status: number;
281
+ data: z.ZodObject<{
282
+ count: z.ZodInt;
283
+ }, z.core.$strip>;
284
+ };
285
+ NAMESPACE_REQUIRED: {
286
+ status: number;
287
+ };
288
+ NOT_INSTALLED: {
289
+ status: number;
290
+ };
291
+ OWNER_ONLY_PERMISSION: {
292
+ status: number;
293
+ data: z.ZodObject<{
294
+ permissions: z.ZodArray<z.ZodString>;
295
+ }, z.core.$strip>;
296
+ };
297
+ ROLE_IN_USE: {
298
+ status: number;
299
+ };
300
+ ROLE_NOT_FOUND: {
301
+ status: number;
302
+ };
303
+ UNKNOWN_PERMISSION: {
304
+ status: number;
305
+ data: z.ZodObject<{
306
+ permissions: z.ZodArray<z.ZodString>;
307
+ }, z.core.$strip>;
308
+ };
309
+ }>, Record<never, never>>;
52
310
  };
@@ -1,5 +1,6 @@
1
1
  import { organizations } from "./db/src/schema/organizations.js";
2
2
  import "./db/src/schema/index.js";
3
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
3
4
  import { Id, isoDate } from "./common.js";
4
5
  import { Country, Currency } from "./money.js";
5
6
  import { oc } from "@orpc/contract";
@@ -29,13 +30,31 @@ const OrganizationRegion = OrganizationFields.pick({
29
30
  country: true,
30
31
  currency: true
31
32
  });
33
+ const { BEYOND_OWN_PERMISSIONS, BUILTIN_ROLE, FIXED_ROLE, INVALID_CLIENT, INVALID_SUBDOMAIN, LAST_OPEN_STAGE, LEAD_STAGE_IN_USE, NAMESPACE_REQUIRED, NOT_INSTALLED, OWNER_ONLY_PERMISSION, ROLE_IN_USE, ROLE_NOT_FOUND, UNKNOWN_PERMISSION } = ERRORS;
34
+ /** What these procedures answer with besides the common errors. */
35
+ const base = oc.errors({
36
+ ...COMMON_ERRORS,
37
+ BEYOND_OWN_PERMISSIONS,
38
+ BUILTIN_ROLE,
39
+ FIXED_ROLE,
40
+ INVALID_CLIENT,
41
+ INVALID_SUBDOMAIN,
42
+ LAST_OPEN_STAGE,
43
+ LEAD_STAGE_IN_USE,
44
+ NAMESPACE_REQUIRED,
45
+ NOT_INSTALLED,
46
+ OWNER_ONLY_PERMISSION,
47
+ ROLE_IN_USE,
48
+ ROLE_NOT_FOUND,
49
+ UNKNOWN_PERMISSION
50
+ });
32
51
  const organizationsContract = {
33
- current: oc.route({
52
+ current: base.route({
34
53
  method: "GET",
35
54
  path: "/organization",
36
55
  summary: "The organisation of the signed-in member or the plugin token"
37
56
  }).output(Organization),
38
- update: oc.route({
57
+ update: base.route({
39
58
  method: "PATCH",
40
59
  path: "/organization",
41
60
  summary: "Rename the organisation or change its country and currency. Products and invoices keep the currency they were made in; a new country without a currency also sets the country's currency"