@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.
- package/dist/activities.d.ts +1387 -139
- package/dist/activities.js +90 -30
- package/dist/audit.d.ts +1081 -33
- package/dist/audit.js +28 -14
- package/dist/auth.d.ts +2834 -26
- package/dist/auth.js +47 -18
- package/dist/automationRuns.d.ts +7 -9
- package/dist/automationRuns.js +12 -13
- package/dist/automations.d.ts +2443 -61
- package/dist/automations.js +41 -21
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +0 -13
- package/dist/common.js +1 -13
- package/dist/companies.d.ts +1120 -10
- package/dist/companies.js +27 -12
- package/dist/contract/routes.json.js +17 -1
- package/dist/customerAuth.d.ts +1456 -17
- package/dist/customerAuth.js +33 -16
- package/dist/customers.d.ts +1232 -11
- package/dist/customers.js +28 -13
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
- package/dist/db/src/enums.js +1 -3
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +3 -3
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +3 -2
- package/dist/db/src/schema/leads.js +2 -2
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/payments.js +2 -2
- package/dist/db/src/schema/platform.js +0 -5
- package/dist/db/src/schema/plugins.js +7 -2
- package/dist/db/src/schema/transfer.js +2 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +570 -121
- package/dist/events.js +41 -24
- package/dist/fields.d.ts +1456 -16
- package/dist/fields.js +27 -19
- package/dist/files.d.ts +761 -62
- package/dist/files.js +32 -21
- package/dist/index.d.ts +25187 -618
- package/dist/index.js +8 -7
- package/dist/leads.d.ts +1105 -21
- package/dist/leads.js +31 -13
- package/dist/notifications.d.ts +689 -48
- package/dist/notifications.js +38 -18
- package/dist/organizations.d.ts +260 -2
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1766 -62
- package/dist/payments.js +48 -26
- package/dist/platform.d.ts +12 -21
- package/dist/platform.js +7 -17
- package/dist/plugins.d.ts +802 -71
- package/dist/plugins.js +48 -27
- package/dist/products.d.ts +1380 -17
- package/dist/products.js +32 -16
- package/dist/roles.d.ts +560 -5
- package/dist/roles.js +20 -6
- package/dist/saas.d.ts +164 -2
- package/dist/saas.js +9 -2
- package/dist/tags.d.ts +340 -4
- package/dist/tags.js +14 -6
- package/dist/transfer.d.ts +1299 -12
- package/dist/transfer.js +32 -13
- package/dist/trash.d.ts +278 -21
- package/dist/trash.js +23 -16
- package/dist/users.d.ts +1206 -18
- package/dist/users.js +35 -13
- package/dist/values.d.ts +0 -9
- package/dist/values.js +2 -7
- package/dist/views.d.ts +396 -5
- package/dist/views.js +10 -7
- package/dist/webhooks.d.ts +765 -9
- package/dist/webhooks.js +18 -10
- package/package.json +6 -2
package/dist/payments.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { GATEWAY_REFUND_KINDS, PAYMENT_GATEWAY_STATUSES } from "./db/src/enums.js";
|
|
2
2
|
import { paymentGateways, paymentInvoices, paymentPluginSettings, paymentRefunds } from "./db/src/schema/payments.js";
|
|
3
3
|
import "./db/src/schema/index.js";
|
|
4
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
4
5
|
import { InvoiceStatus, PaymentGatewayKind } from "./values.js";
|
|
5
6
|
import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
|
|
6
7
|
import { Currency } from "./money.js";
|
|
7
8
|
import { DedupeKey } from "./platform.js";
|
|
8
9
|
import { PluginName } from "./plugins.js";
|
|
9
10
|
import { oc } from "@orpc/contract";
|
|
10
|
-
import { createSelectSchema } from "drizzle-zod";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
+
import { createSelectSchema } from "drizzle-zod";
|
|
12
13
|
// src/payments.ts
|
|
13
14
|
/** What each gateway needs (secrets are write-only: never returned). */
|
|
14
15
|
const GatewayConfig = z.discriminatedUnion("kind", [z.object({
|
|
@@ -88,6 +89,9 @@ const Invoice = createSelectSchema(paymentInvoices, {
|
|
|
88
89
|
/** ISO 4217. */
|
|
89
90
|
currency: true,
|
|
90
91
|
description: true,
|
|
92
|
+
/** The caller's record it is for (`order` and its id). */
|
|
93
|
+
referenceType: true,
|
|
94
|
+
referenceId: true,
|
|
91
95
|
status: true,
|
|
92
96
|
metadata: true,
|
|
93
97
|
lines: true,
|
|
@@ -100,11 +104,8 @@ const Invoice = createSelectSchema(paymentInvoices, {
|
|
|
100
104
|
paidAt: true,
|
|
101
105
|
createdAt: true
|
|
102
106
|
}).extend({
|
|
107
|
+
/** The gateway's kind, joined in the query. */
|
|
103
108
|
gatewayKind: PaymentGatewayKind,
|
|
104
|
-
reference: z.object({
|
|
105
|
-
type: z.string(),
|
|
106
|
-
id: z.string()
|
|
107
|
-
}),
|
|
108
109
|
/** What can still be refunded, and how the gateway refunds (`full`: only the whole payment). */
|
|
109
110
|
refundable: z.object({
|
|
110
111
|
amount: z.int(),
|
|
@@ -125,11 +126,11 @@ const Refund = createSelectSchema(paymentRefunds, {
|
|
|
125
126
|
method: true,
|
|
126
127
|
status: true,
|
|
127
128
|
error: true,
|
|
129
|
+
/** Who asked: a team member (`requestedBy` = user id), a plugin (its name) or `system`. */
|
|
130
|
+
requestedByType: true,
|
|
131
|
+
requestedBy: true,
|
|
128
132
|
createdAt: true
|
|
129
|
-
})
|
|
130
|
-
type: z.string(),
|
|
131
|
-
id: z.string().nullable()
|
|
132
|
-
}) });
|
|
133
|
+
});
|
|
133
134
|
/** How a plugin takes payments here: its default gateway, and the only ones it may use (none: any). */
|
|
134
135
|
const PluginPaymentSettings = createSelectSchema(paymentPluginSettings, {
|
|
135
136
|
defaultGatewayId: () => Id,
|
|
@@ -144,12 +145,34 @@ const PluginPaymentSettings = createSelectSchema(paymentPluginSettings, {
|
|
|
144
145
|
* made through them for plugins' records. Paid invoices publish
|
|
145
146
|
* `core.payment.paid` (webhooks, automations, the plugin's own consumer).
|
|
146
147
|
*/
|
|
148
|
+
const { CURRENCY_NOT_SUPPORTED, DEFAULT_NOT_ALLOWED, GATEWAY_IN_USE, GATEWAY_NOT_ALLOWED, GATEWAY_REFUSED, INVALID_PRODUCT, INVALID_SUBDOMAIN, KIND_CHANGED, LIMIT_EXCEEDED, LINES_MISMATCH, NOTHING_TO_RETRY, NOT_PENDING, NOT_REFUNDABLE, NOT_TEST, NO_GATEWAY, PARTIAL_NOT_SUPPORTED, SUBJECT_REQUIRED } = ERRORS;
|
|
149
|
+
/** What these procedures answer with besides the common errors. */
|
|
150
|
+
const base = oc.errors({
|
|
151
|
+
...COMMON_ERRORS,
|
|
152
|
+
CURRENCY_NOT_SUPPORTED,
|
|
153
|
+
DEFAULT_NOT_ALLOWED,
|
|
154
|
+
GATEWAY_IN_USE,
|
|
155
|
+
GATEWAY_NOT_ALLOWED,
|
|
156
|
+
GATEWAY_REFUSED,
|
|
157
|
+
INVALID_PRODUCT,
|
|
158
|
+
INVALID_SUBDOMAIN,
|
|
159
|
+
KIND_CHANGED,
|
|
160
|
+
LIMIT_EXCEEDED,
|
|
161
|
+
LINES_MISMATCH,
|
|
162
|
+
NOTHING_TO_RETRY,
|
|
163
|
+
NOT_PENDING,
|
|
164
|
+
NOT_REFUNDABLE,
|
|
165
|
+
NOT_TEST,
|
|
166
|
+
NO_GATEWAY,
|
|
167
|
+
PARTIAL_NOT_SUPPORTED,
|
|
168
|
+
SUBJECT_REQUIRED
|
|
169
|
+
});
|
|
147
170
|
const paymentsContract = {
|
|
148
|
-
gateways:
|
|
171
|
+
gateways: base.route({
|
|
149
172
|
method: "GET",
|
|
150
173
|
path: "/payments/gateways"
|
|
151
174
|
}).output(listOf(PaymentGateway)),
|
|
152
|
-
addGateway:
|
|
175
|
+
addGateway: base.route({
|
|
153
176
|
method: "POST",
|
|
154
177
|
path: "/payments/gateways",
|
|
155
178
|
successStatus: 201,
|
|
@@ -158,7 +181,7 @@ const paymentsContract = {
|
|
|
158
181
|
name: z.string().trim().min(1).max(80),
|
|
159
182
|
config: GatewayConfig
|
|
160
183
|
})).output(PaymentGateway),
|
|
161
|
-
updateGateway:
|
|
184
|
+
updateGateway: base.route({
|
|
162
185
|
method: "PATCH",
|
|
163
186
|
path: "/payments/gateways/{id}"
|
|
164
187
|
}).input(z.object({
|
|
@@ -167,12 +190,12 @@ const paymentsContract = {
|
|
|
167
190
|
config: GatewayConfig.optional(),
|
|
168
191
|
status: z.enum(PAYMENT_GATEWAY_STATUSES).optional()
|
|
169
192
|
})).output(PaymentGateway),
|
|
170
|
-
removeGateway:
|
|
193
|
+
removeGateway: base.route({
|
|
171
194
|
method: "DELETE",
|
|
172
195
|
path: "/payments/gateways/{id}",
|
|
173
196
|
summary: "Remove a gateway without invoices (turn it off otherwise)"
|
|
174
197
|
}).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
|
|
175
|
-
createInvoice:
|
|
198
|
+
createInvoice: base.route({
|
|
176
199
|
method: "POST",
|
|
177
200
|
path: "/payments/invoices",
|
|
178
201
|
successStatus: 201,
|
|
@@ -182,26 +205,25 @@ const paymentsContract = {
|
|
|
182
205
|
amount: z.int().min(1).max(1e11),
|
|
183
206
|
currency: Currency.optional(),
|
|
184
207
|
description: z.string().trim().min(1).max(255),
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}),
|
|
208
|
+
/** The caller's record it is for: `order` and its id. */
|
|
209
|
+
referenceType: z.string().trim().min(1).max(60),
|
|
210
|
+
referenceId: z.string().trim().min(1).max(100),
|
|
189
211
|
/** Minutes the invoice can be paid in (default 30). */
|
|
190
212
|
expiresInMinutes: z.int().min(1).max(10080).default(30),
|
|
191
213
|
dedupeKey: DedupeKey.optional(),
|
|
192
214
|
metadata: InvoiceMetadata.optional(),
|
|
193
215
|
lines: z.array(InvoiceLineInput).max(100).optional()
|
|
194
216
|
})).output(Invoice),
|
|
195
|
-
getInvoice:
|
|
217
|
+
getInvoice: base.route({
|
|
196
218
|
method: "GET",
|
|
197
219
|
path: "/payments/invoices/{id}",
|
|
198
220
|
summary: "An invoice; a pending one is checked with the gateway"
|
|
199
221
|
}).input(z.object({ id: Id })).output(Invoice),
|
|
200
|
-
cancelInvoice:
|
|
222
|
+
cancelInvoice: base.route({
|
|
201
223
|
method: "POST",
|
|
202
224
|
path: "/payments/invoices/{id}/cancel"
|
|
203
225
|
}).input(z.object({ id: Id })).output(Invoice),
|
|
204
|
-
refund:
|
|
226
|
+
refund: base.route({
|
|
205
227
|
method: "POST",
|
|
206
228
|
path: "/payments/invoices/{id}/refunds",
|
|
207
229
|
successStatus: 201,
|
|
@@ -216,16 +238,16 @@ const paymentsContract = {
|
|
|
216
238
|
refund: Refund,
|
|
217
239
|
invoice: Invoice
|
|
218
240
|
})),
|
|
219
|
-
refunds:
|
|
241
|
+
refunds: base.route({
|
|
220
242
|
method: "GET",
|
|
221
243
|
path: "/payments/invoices/{id}/refunds"
|
|
222
244
|
}).input(z.object({ id: Id })).output(listOf(Refund)),
|
|
223
|
-
pluginSettings:
|
|
245
|
+
pluginSettings: base.route({
|
|
224
246
|
method: "GET",
|
|
225
247
|
path: "/payments/plugins",
|
|
226
248
|
summary: "Installed plugins that take payments, with their gateway settings"
|
|
227
249
|
}).output(listOf(PluginPaymentSettings)),
|
|
228
|
-
updatePluginSettings:
|
|
250
|
+
updatePluginSettings: base.route({
|
|
229
251
|
method: "PUT",
|
|
230
252
|
path: "/payments/plugins/{plugin}"
|
|
231
253
|
}).input(z.object({
|
|
@@ -233,7 +255,7 @@ const paymentsContract = {
|
|
|
233
255
|
defaultGatewayId: Id.nullable(),
|
|
234
256
|
allowedGatewayIds: z.array(Id).max(50)
|
|
235
257
|
})).output(PluginPaymentSettings),
|
|
236
|
-
invoices:
|
|
258
|
+
invoices: base.route({
|
|
237
259
|
method: "GET",
|
|
238
260
|
path: "/payments/invoices",
|
|
239
261
|
summary: "Invoices, newest first"
|
|
@@ -242,7 +264,7 @@ const paymentsContract = {
|
|
|
242
264
|
source: z.string().max(40).optional(),
|
|
243
265
|
referenceId: z.string().max(100).optional()
|
|
244
266
|
})).output(cursorPageOf(Invoice)),
|
|
245
|
-
payTestInvoice:
|
|
267
|
+
payTestInvoice: base.route({
|
|
246
268
|
method: "POST",
|
|
247
269
|
path: "/payments/invoices/{id}/test-pay",
|
|
248
270
|
summary: "Pay an invoice of the test gateway (development)"
|
package/dist/platform.d.ts
CHANGED
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
/**
|
|
3
|
-
* Who did something
|
|
4
|
-
* name, e.g. `hr`)
|
|
5
|
-
*
|
|
3
|
+
* Who did something, stored as `actorType` with `actorId`: a team member (the
|
|
4
|
+
* user id), a plugin (its name, e.g. `hr`), a customer (the customer id) or
|
|
5
|
+
* core itself (`system`, no id).
|
|
6
6
|
*/
|
|
7
|
-
export declare const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
-
}, z.core.$strip>;
|
|
18
|
-
export type ActorRef = z.infer<typeof ActorRef>;
|
|
19
|
-
/** A record in a plugin that an entry points at. */
|
|
20
|
-
export declare const EntityRef: z.ZodObject<{
|
|
21
|
-
type: z.ZodString;
|
|
22
|
-
id: z.ZodString;
|
|
23
|
-
}, z.core.$strip>;
|
|
24
|
-
export type EntityRef = z.infer<typeof EntityRef>;
|
|
7
|
+
export declare const ActorType: z.ZodEnum<{
|
|
8
|
+
customer: "customer";
|
|
9
|
+
plugin: "plugin";
|
|
10
|
+
system: "system";
|
|
11
|
+
user: "user";
|
|
12
|
+
}>;
|
|
13
|
+
export type ActorType = z.infer<typeof ActorType>;
|
|
14
|
+
/** The type of a plugin's record an entry points at (`entityType`, with `entityId`). */
|
|
15
|
+
export declare const EntityType: z.ZodString;
|
|
25
16
|
/** An app path inside erxes (`/hr/leaves/abc`), never another site. */
|
|
26
17
|
export declare const AppLink: z.ZodString;
|
|
27
18
|
/**
|
package/dist/platform.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import { ACTOR_TYPES } from "./db/src/enums.js";
|
|
2
|
-
import { Id } from "./common.js";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
// src/platform.ts
|
|
5
4
|
/**
|
|
6
|
-
* Who did something
|
|
7
|
-
* name, e.g. `hr`)
|
|
8
|
-
*
|
|
5
|
+
* Who did something, stored as `actorType` with `actorId`: a team member (the
|
|
6
|
+
* user id), a plugin (its name, e.g. `hr`), a customer (the customer id) or
|
|
7
|
+
* core itself (`system`, no id).
|
|
9
8
|
*/
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** A team member's name and picture, where a list includes them (timelines), so it reads at once. */
|
|
14
|
-
name: z.string().nullable().optional(),
|
|
15
|
-
avatarUrl: z.string().nullable().optional()
|
|
16
|
-
});
|
|
17
|
-
/** A record in a plugin that an entry points at. */
|
|
18
|
-
const EntityRef = z.object({
|
|
19
|
-
type: z.string().trim().min(1).max(64),
|
|
20
|
-
id: Id
|
|
21
|
-
});
|
|
9
|
+
const ActorType = z.enum(ACTOR_TYPES);
|
|
10
|
+
/** The type of a plugin's record an entry points at (`entityType`, with `entityId`). */
|
|
11
|
+
const EntityType = z.string().trim().min(1).max(64);
|
|
22
12
|
/** An app path inside erxes (`/hr/leaves/abc`), never another site. */
|
|
23
13
|
const AppLink = z.string().trim().max(500).regex(/^\/(?!\/)[^\s]*$/, "an app path starting with /");
|
|
24
14
|
/**
|
|
@@ -28,4 +18,4 @@ const AppLink = z.string().trim().max(500).regex(/^\/(?!\/)[^\s]*$/, "an app pat
|
|
|
28
18
|
const DedupeKey = z.string().trim().min(1).max(200);
|
|
29
19
|
/** `<source>.<what>`, lower case: `hr.leave.requested`. */
|
|
30
20
|
const EventType = z.string().trim().max(100).regex(/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/, "dotted lower-case name, e.g. hr.leave.requested");
|
|
31
|
-
export {
|
|
21
|
+
export { ActorType, AppLink, DedupeKey, EntityType, EventType };
|