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

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
package/dist/auth.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { LANGUAGES } from "./db/src/enums.js";
2
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
2
3
  import { isoDate } from "./common.js";
3
4
  import { NewPassword } from "./values.js";
4
5
  import { Organization, OrganizationRegion } from "./organizations.js";
@@ -12,13 +13,41 @@ const Session = z.object({
12
13
  /** What the member may do (actions); owners have every one. */
13
14
  permissions: z.array(z.string())
14
15
  });
16
+ const { ALREADY_ENABLED, BEYOND_OWN_PERMISSIONS, BUILTIN_ROLE, CHALLENGE_EXPIRED, CROSS_SITE, FIXED_ROLE, INVALID_CREDENTIALS, INVALID_LINK, LIMIT_EXCEEDED, NOT_ENABLED, NOT_INVITED, NOT_SET_UP, ORGANIZATION_REQUIRED, OWNER_ONLY_PERMISSION, ROLE_IN_USE, ROLE_NOT_FOUND, SAME_PASSWORD, SETUP_DISABLED, SETUP_DONE, TOO_MANY_ATTEMPTS, UNKNOWN_PERMISSION, WRONG_CODE, WRONG_PASSWORD } = ERRORS;
17
+ /** What these procedures answer with besides the common errors. */
18
+ const base = oc.errors({
19
+ ...COMMON_ERRORS,
20
+ ALREADY_ENABLED,
21
+ BEYOND_OWN_PERMISSIONS,
22
+ BUILTIN_ROLE,
23
+ CHALLENGE_EXPIRED,
24
+ CROSS_SITE,
25
+ FIXED_ROLE,
26
+ INVALID_CREDENTIALS,
27
+ INVALID_LINK,
28
+ LIMIT_EXCEEDED,
29
+ NOT_ENABLED,
30
+ NOT_INVITED,
31
+ NOT_SET_UP,
32
+ ORGANIZATION_REQUIRED,
33
+ OWNER_ONLY_PERMISSION,
34
+ ROLE_IN_USE,
35
+ ROLE_NOT_FOUND,
36
+ SAME_PASSWORD,
37
+ SETUP_DISABLED,
38
+ SETUP_DONE,
39
+ TOO_MANY_ATTEMPTS,
40
+ UNKNOWN_PERMISSION,
41
+ WRONG_CODE,
42
+ WRONG_PASSWORD
43
+ });
15
44
  const authContract = {
16
- setupStatus: oc.route({
45
+ setupStatus: base.route({
17
46
  method: "GET",
18
47
  path: "/setup",
19
48
  summary: "Whether this installation still needs its first organisation and owner"
20
49
  }).output(z.object({ required: z.boolean() })),
21
- setup: oc.route({
50
+ setup: base.route({
22
51
  method: "POST",
23
52
  path: "/setup",
24
53
  successStatus: 201,
@@ -32,7 +61,7 @@ const authContract = {
32
61
  email: z.string().trim().check(z.email()).max(254),
33
62
  password: NewPassword
34
63
  })).output(Session),
35
- signIn: oc.route({
64
+ signIn: base.route({
36
65
  method: "POST",
37
66
  path: "/auth/sign-in",
38
67
  summary: "Sign in with email and password; sets the session cookie"
@@ -45,7 +74,7 @@ const authContract = {
45
74
  twoFactorRequired: z.literal(true),
46
75
  challenge: z.string()
47
76
  })])),
48
- requestPasswordReset: oc.route({
77
+ requestPasswordReset: base.route({
49
78
  method: "POST",
50
79
  path: "/auth/password-reset",
51
80
  summary: "Email a password reset link. Always answers ok: it never tells whether an email has an account"
@@ -53,7 +82,7 @@ const authContract = {
53
82
  email: z.string().trim().check(z.email()).max(254),
54
83
  subdomain: z.string().trim().max(63).optional()
55
84
  })).output(z.object({ ok: z.literal(true) })),
56
- resetPassword: oc.route({
85
+ resetPassword: base.route({
57
86
  method: "POST",
58
87
  path: "/auth/password-reset/confirm",
59
88
  summary: "Set a new password with the emailed link's token; signs in"
@@ -61,7 +90,7 @@ const authContract = {
61
90
  token: z.string().min(10).max(300),
62
91
  password: NewPassword
63
92
  })).output(Session),
64
- invitation: oc.route({
93
+ invitation: base.route({
65
94
  method: "GET",
66
95
  path: "/auth/invitation",
67
96
  summary: "What an invitation link is for (organisation, email), to show before accepting"
@@ -70,7 +99,7 @@ const authContract = {
70
99
  email: z.string(),
71
100
  inviter: z.string().nullable()
72
101
  })),
73
- acceptInvitation: oc.route({
102
+ acceptInvitation: base.route({
74
103
  method: "POST",
75
104
  path: "/auth/invitation/accept",
76
105
  summary: "Accept an invitation: choose a password; signs in"
@@ -80,7 +109,7 @@ const authContract = {
80
109
  firstName: z.string().trim().max(100).optional(),
81
110
  lastName: z.string().trim().max(100).optional()
82
111
  })).output(Session),
83
- signInTwoFactor: oc.route({
112
+ signInTwoFactor: base.route({
84
113
  method: "POST",
85
114
  path: "/auth/sign-in/2fa",
86
115
  summary: "The sign-in's second step: an authenticator code, or a recovery code"
@@ -89,7 +118,7 @@ const authContract = {
89
118
  code: z.string().trim().regex(/^\d{6}$/).optional(),
90
119
  recoveryCode: z.string().trim().min(8).max(40).optional()
91
120
  }).refine((value) => Boolean(value.code || value.recoveryCode), "a code or a recovery code")).output(Session),
92
- twoFactorSetup: oc.route({
121
+ twoFactorSetup: base.route({
93
122
  method: "POST",
94
123
  path: "/auth/2fa/setup",
95
124
  summary: "Start turning on two-factor sign-in: a new secret for an authenticator app"
@@ -97,37 +126,37 @@ const authContract = {
97
126
  secret: z.string(),
98
127
  uri: z.string()
99
128
  })),
100
- twoFactorEnable: oc.route({
129
+ twoFactorEnable: base.route({
101
130
  method: "POST",
102
131
  path: "/auth/2fa/enable",
103
132
  summary: "Confirm with a code from the app; returns recovery codes (shown once)"
104
133
  }).input(z.object({ code: z.string().trim().regex(/^\d{6}$/) })).output(z.object({ recoveryCodes: z.array(z.string()) })),
105
- twoFactorDisable: oc.route({
134
+ twoFactorDisable: base.route({
106
135
  method: "POST",
107
136
  path: "/auth/2fa/disable",
108
137
  summary: "Turn two-factor sign-in off (needs the password)"
109
138
  }).input(z.object({ password: z.string().min(1).max(200) })).output(z.object({ ok: z.literal(true) })),
110
- twoFactorRecoveryCodes: oc.route({
139
+ twoFactorRecoveryCodes: base.route({
111
140
  method: "POST",
112
141
  path: "/auth/2fa/recovery-codes",
113
142
  summary: "New recovery codes (the old ones stop working; needs the password)"
114
143
  }).input(z.object({ password: z.string().min(1).max(200) })).output(z.object({ recoveryCodes: z.array(z.string()) })),
115
- signOutEverywhere: oc.route({
144
+ signOutEverywhere: base.route({
116
145
  method: "POST",
117
146
  path: "/auth/sign-out-everywhere",
118
147
  summary: "End every session of the signed-in member, on every device"
119
148
  }).output(z.object({ ok: z.literal(true) })),
120
- signOut: oc.route({
149
+ signOut: base.route({
121
150
  method: "POST",
122
151
  path: "/auth/sign-out",
123
152
  summary: "Sign out; clears the session cookie"
124
153
  }).output(z.object({ ok: z.literal(true) })),
125
- me: oc.route({
154
+ me: base.route({
126
155
  method: "GET",
127
156
  path: "/auth/me",
128
157
  summary: "The signed-in team member and their organisation"
129
158
  }).output(Session),
130
- onboarded: oc.route({
159
+ onboarded: base.route({
131
160
  method: "POST",
132
161
  path: "/auth/onboarded",
133
162
  summary: "The signed-in member finished the welcome steps (on every browser)"
@@ -137,7 +166,7 @@ const authContract = {
137
166
  /** The language of the example data: the member's UI language. */
138
167
  language: z.enum(LANGUAGES).optional()
139
168
  }).optional()).output(Session),
140
- changePassword: oc.route({
169
+ changePassword: base.route({
141
170
  method: "POST",
142
171
  path: "/auth/password",
143
172
  summary: "Change my own password. 400 WRONG_PASSWORD when the current one is wrong; SAME_PASSWORD when unchanged"
@@ -145,7 +174,7 @@ const authContract = {
145
174
  currentPassword: z.string().min(1).max(200),
146
175
  newPassword: NewPassword
147
176
  })).output(z.object({ ok: z.literal(true) })),
148
- signIns: oc.route({
177
+ signIns: base.route({
149
178
  method: "GET",
150
179
  path: "/auth/sign-ins",
151
180
  summary: "My 15 most recent sign-ins and failed attempts, newest first"
@@ -82,6 +82,11 @@ export declare const AutomationRun: z.ZodObject<{
82
82
  version: z.ZodInt;
83
83
  eventId: z.ZodString;
84
84
  eventType: z.ZodString;
85
+ subjectType: z.ZodNullable<z.ZodEnum<{
86
+ company: "company";
87
+ customer: "customer";
88
+ }>>;
89
+ subjectId: z.ZodNullable<z.ZodString>;
85
90
  status: z.ZodEnum<{
86
91
  cancelled: "cancelled";
87
92
  failed: "failed";
@@ -91,17 +96,10 @@ export declare const AutomationRun: z.ZodObject<{
91
96
  }>;
92
97
  error: z.ZodNullable<z.ZodString>;
93
98
  waitingUntil: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
99
+ goalReachedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
94
100
  startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
95
101
  finishedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
96
- subject: z.ZodNullable<z.ZodObject<{
97
- type: z.ZodEnum<{
98
- company: "company";
99
- customer: "customer";
100
- }>;
101
- id: z.ZodString;
102
- name: z.ZodNullable<z.ZodString>;
103
- }, z.core.$strip>>;
104
- goalReached: z.ZodBoolean;
102
+ subjectName: z.ZodNullable<z.ZodString>;
105
103
  }, {
106
104
  out: {};
107
105
  in: {};
@@ -1,9 +1,9 @@
1
- import { ACTION_FIELD_TYPES, AUTOMATION_SUBJECTS, CONTENT_TYPES, RUN_STATUSES } from "./db/src/enums.js";
1
+ import { ACTION_FIELD_TYPES, AUTOMATION_SUBJECTS, RUN_STATUSES } from "./db/src/enums.js";
2
2
  import { automationRunSteps, automationRuns } from "./db/src/schema/automations.js";
3
3
  import "./db/src/schema/index.js";
4
4
  import { Id, isoDate } from "./common.js";
5
- import { createSelectSchema } from "drizzle-zod";
6
5
  import { z } from "zod";
6
+ import { createSelectSchema } from "drizzle-zod";
7
7
  // src/automationRuns.ts
8
8
  /**
9
9
  * One input of an action. Besides plain values: `custom_field` (one of the
@@ -41,28 +41,27 @@ const AutomationRun = createSelectSchema(automationRuns, {
41
41
  version: int,
42
42
  waitingUntil: isoDate,
43
43
  startedAt: isoDate,
44
- finishedAt: isoDate
44
+ finishedAt: isoDate,
45
+ goalReachedAt: isoDate
45
46
  }).pick({
46
47
  id: true,
47
48
  automationId: true,
48
49
  version: true,
49
50
  eventId: true,
50
51
  eventType: true,
52
+ /** The customer or company the run is about. */
53
+ subjectType: true,
54
+ subjectId: true,
51
55
  status: true,
52
56
  error: true,
53
57
  waitingUntil: true,
54
58
  startedAt: true,
55
- finishedAt: true
56
- }).extend({
57
- subject: z.object({
58
- type: z.enum(CONTENT_TYPES),
59
- id: Id,
60
- /** The customer's or company's name now; null once it is deleted. */
61
- name: z.string().nullable()
62
- }).nullable(),
59
+ finishedAt: true,
63
60
  /** Left early because the automation's goal was met. */
64
- goalReached: z.boolean()
65
- });
61
+ goalReachedAt: true
62
+ }).extend({
63
+ /** The customer's or company's name now; null once it is deleted. */
64
+ subjectName: z.string().nullable() });
66
65
  const RunStep = createSelectSchema(automationRunSteps, {
67
66
  id: Id,
68
67
  input: () => z.unknown(),