c2-desafiox 1.0.136 → 1.0.143
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/models/ChatMessage.d.ts +3 -3
- package/dist/models/EventComunication.d.ts +3 -3
- package/dist/models/TicketTransfer.d.ts +74 -0
- package/dist/models/TicketTransfer.js +62 -0
- package/dist/models/WalletMoviment.d.ts +1 -0
- package/dist/models/WalletMoviment.js +1 -0
- package/dist/models/WhatsAppTemplate.d.ts +72 -0
- package/dist/models/WhatsAppTemplate.js +281 -0
- package/dist/models/index.d.ts +4 -2
- package/dist/models/index.js +4 -2
- package/package.json +1 -1
|
@@ -84,8 +84,8 @@ export declare const ChatMessageSchema: Schema<any, import("mongoose").Model<any
|
|
|
84
84
|
seenBy?: Types.ObjectId | null | undefined;
|
|
85
85
|
seenDateTime?: NativeDate | null | undefined;
|
|
86
86
|
}>;
|
|
87
|
-
content?: string | null | undefined;
|
|
88
87
|
category?: string | null | undefined;
|
|
88
|
+
content?: string | null | undefined;
|
|
89
89
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{} & {
|
|
90
90
|
status: string;
|
|
91
91
|
chat: Types.ObjectId;
|
|
@@ -133,8 +133,8 @@ export declare const ChatMessageSchema: Schema<any, import("mongoose").Model<any
|
|
|
133
133
|
seenBy?: Types.ObjectId | null | undefined;
|
|
134
134
|
seenDateTime?: NativeDate | null | undefined;
|
|
135
135
|
}>;
|
|
136
|
-
content?: string | null | undefined;
|
|
137
136
|
category?: string | null | undefined;
|
|
137
|
+
content?: string | null | undefined;
|
|
138
138
|
}>, {}> & import("mongoose").FlatRecord<{} & {
|
|
139
139
|
status: string;
|
|
140
140
|
chat: Types.ObjectId;
|
|
@@ -182,8 +182,8 @@ export declare const ChatMessageSchema: Schema<any, import("mongoose").Model<any
|
|
|
182
182
|
seenBy?: Types.ObjectId | null | undefined;
|
|
183
183
|
seenDateTime?: NativeDate | null | undefined;
|
|
184
184
|
}>;
|
|
185
|
-
content?: string | null | undefined;
|
|
186
185
|
category?: string | null | undefined;
|
|
186
|
+
content?: string | null | undefined;
|
|
187
187
|
}> & {
|
|
188
188
|
_id: Types.ObjectId;
|
|
189
189
|
} & {
|
|
@@ -51,6 +51,7 @@ export declare const EventComunicationSchema: Schema<any, import("mongoose").Mod
|
|
|
51
51
|
isValid?: {} | null | undefined;
|
|
52
52
|
};
|
|
53
53
|
status: string;
|
|
54
|
+
content: any;
|
|
54
55
|
comunication: {
|
|
55
56
|
prototype?: Types.ObjectId | null | undefined;
|
|
56
57
|
cacheHexString?: unknown;
|
|
@@ -61,7 +62,6 @@ export declare const EventComunicationSchema: Schema<any, import("mongoose").Mod
|
|
|
61
62
|
isValid?: {} | null | undefined;
|
|
62
63
|
};
|
|
63
64
|
statusDelivery: string;
|
|
64
|
-
content: any;
|
|
65
65
|
message?: string | null | undefined;
|
|
66
66
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{} & {
|
|
67
67
|
type: string;
|
|
@@ -75,6 +75,7 @@ export declare const EventComunicationSchema: Schema<any, import("mongoose").Mod
|
|
|
75
75
|
isValid?: {} | null | undefined;
|
|
76
76
|
};
|
|
77
77
|
status: string;
|
|
78
|
+
content: any;
|
|
78
79
|
comunication: {
|
|
79
80
|
prototype?: Types.ObjectId | null | undefined;
|
|
80
81
|
cacheHexString?: unknown;
|
|
@@ -85,7 +86,6 @@ export declare const EventComunicationSchema: Schema<any, import("mongoose").Mod
|
|
|
85
86
|
isValid?: {} | null | undefined;
|
|
86
87
|
};
|
|
87
88
|
statusDelivery: string;
|
|
88
|
-
content: any;
|
|
89
89
|
message?: string | null | undefined;
|
|
90
90
|
}>, {}> & import("mongoose").FlatRecord<{} & {
|
|
91
91
|
type: string;
|
|
@@ -99,6 +99,7 @@ export declare const EventComunicationSchema: Schema<any, import("mongoose").Mod
|
|
|
99
99
|
isValid?: {} | null | undefined;
|
|
100
100
|
};
|
|
101
101
|
status: string;
|
|
102
|
+
content: any;
|
|
102
103
|
comunication: {
|
|
103
104
|
prototype?: Types.ObjectId | null | undefined;
|
|
104
105
|
cacheHexString?: unknown;
|
|
@@ -109,7 +110,6 @@ export declare const EventComunicationSchema: Schema<any, import("mongoose").Mod
|
|
|
109
110
|
isValid?: {} | null | undefined;
|
|
110
111
|
};
|
|
111
112
|
statusDelivery: string;
|
|
112
|
-
content: any;
|
|
113
113
|
message?: string | null | undefined;
|
|
114
114
|
}> & {
|
|
115
115
|
_id: Types.ObjectId;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Schema, Types } from "mongoose";
|
|
2
|
+
import { IAccount } from "./Account";
|
|
3
|
+
import { ITicket } from "./Ticket";
|
|
4
|
+
import { IAcceptTermsOfChallenge } from "./TicketOrder";
|
|
5
|
+
import { IWalletMoviment } from "./WalletMoviment";
|
|
6
|
+
export declare enum TicketTransferPaymentMethod {
|
|
7
|
+
WALLET = "WALLET",
|
|
8
|
+
CREDIT_CARD = "CREDIT_CARD",
|
|
9
|
+
DEBIT_CARD = "DEBIT_CARD",
|
|
10
|
+
PIX = "PIX",
|
|
11
|
+
/** Checkout InfinitePay (Pix ou cartão definidos no checkout externo). */
|
|
12
|
+
CHECKOUT = "CHECKOUT"
|
|
13
|
+
}
|
|
14
|
+
export declare enum TicketTransferStatus {
|
|
15
|
+
REQUESTED = "REQUESTED",
|
|
16
|
+
PROCESSING = "PROCESSING",
|
|
17
|
+
COMPLETED = "COMPLETED",
|
|
18
|
+
CANCELLED = "CANCELLED",
|
|
19
|
+
FAILED = "FAILED"
|
|
20
|
+
}
|
|
21
|
+
/** Tracking / conciliação InfinitePay (checkout + webhook). */
|
|
22
|
+
export interface ITicketTransferInfinitePay {
|
|
23
|
+
handle?: string;
|
|
24
|
+
/** Nosso identificador enviado como Transfer_nsu (geralmente o _id do pedido). */
|
|
25
|
+
TransferNsu?: string;
|
|
26
|
+
checkoutUrl?: string;
|
|
27
|
+
invoiceSlug?: string;
|
|
28
|
+
transactionNsu?: string;
|
|
29
|
+
captureMethod?: string;
|
|
30
|
+
amountCents?: number;
|
|
31
|
+
paidAmountCents?: number;
|
|
32
|
+
installments?: number;
|
|
33
|
+
receiptUrl?: string;
|
|
34
|
+
/** pending | paid | failed | ... */
|
|
35
|
+
paymentStatus?: string;
|
|
36
|
+
webhookReceivedAt?: Date;
|
|
37
|
+
/** Último payload de webhook (auditoria / reprocessamento). */
|
|
38
|
+
lastWebhookPayload?: Record<string, unknown>;
|
|
39
|
+
checkoutCreatedAt?: Date;
|
|
40
|
+
}
|
|
41
|
+
export interface ITicketTransfer {
|
|
42
|
+
_id: Types.ObjectId;
|
|
43
|
+
sequenceNumber: number;
|
|
44
|
+
ticket: Types.ObjectId | ITicket;
|
|
45
|
+
accountOrigin: Types.ObjectId | IAccount;
|
|
46
|
+
accountDestination: Types.ObjectId | IAccount;
|
|
47
|
+
status: TicketTransferStatus;
|
|
48
|
+
originAccepted: boolean;
|
|
49
|
+
paymentMethod: TicketTransferPaymentMethod;
|
|
50
|
+
amount: number;
|
|
51
|
+
acceptTermsOfChallenge: IAcceptTermsOfChallenge;
|
|
52
|
+
infinitePay?: ITicketTransferInfinitePay;
|
|
53
|
+
walletMoviment?: Types.ObjectId | IWalletMoviment;
|
|
54
|
+
createdAtDateTime: Date;
|
|
55
|
+
updatedAtDateTime: Date;
|
|
56
|
+
}
|
|
57
|
+
export declare const TicketTransferInfinitePaySchema: Schema<ITicketTransferInfinitePay, import("mongoose").Model<ITicketTransferInfinitePay, any, any, any, import("mongoose").Document<unknown, any, ITicketTransferInfinitePay, any> & ITicketTransferInfinitePay & {
|
|
58
|
+
_id: Types.ObjectId;
|
|
59
|
+
} & {
|
|
60
|
+
__v: number;
|
|
61
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ITicketTransferInfinitePay, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<ITicketTransferInfinitePay>, {}> & import("mongoose").FlatRecord<ITicketTransferInfinitePay> & {
|
|
62
|
+
_id: Types.ObjectId;
|
|
63
|
+
} & {
|
|
64
|
+
__v: number;
|
|
65
|
+
}>;
|
|
66
|
+
export declare const TicketTransferSchema: Schema<ITicketTransfer, import("mongoose").Model<ITicketTransfer, any, any, any, import("mongoose").Document<unknown, any, ITicketTransfer, any> & ITicketTransfer & Required<{
|
|
67
|
+
_id: Types.ObjectId;
|
|
68
|
+
}> & {
|
|
69
|
+
__v: number;
|
|
70
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, ITicketTransfer, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<ITicketTransfer>, {}> & import("mongoose").FlatRecord<ITicketTransfer> & Required<{
|
|
71
|
+
_id: Types.ObjectId;
|
|
72
|
+
}> & {
|
|
73
|
+
__v: number;
|
|
74
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TicketTransferSchema = exports.TicketTransferInfinitePaySchema = exports.TicketTransferStatus = exports.TicketTransferPaymentMethod = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const TicketOrder_1 = require("./TicketOrder");
|
|
6
|
+
var TicketTransferPaymentMethod;
|
|
7
|
+
(function (TicketTransferPaymentMethod) {
|
|
8
|
+
TicketTransferPaymentMethod["WALLET"] = "WALLET";
|
|
9
|
+
TicketTransferPaymentMethod["CREDIT_CARD"] = "CREDIT_CARD";
|
|
10
|
+
TicketTransferPaymentMethod["DEBIT_CARD"] = "DEBIT_CARD";
|
|
11
|
+
TicketTransferPaymentMethod["PIX"] = "PIX";
|
|
12
|
+
/** Checkout InfinitePay (Pix ou cartão definidos no checkout externo). */
|
|
13
|
+
TicketTransferPaymentMethod["CHECKOUT"] = "CHECKOUT";
|
|
14
|
+
})(TicketTransferPaymentMethod || (exports.TicketTransferPaymentMethod = TicketTransferPaymentMethod = {}));
|
|
15
|
+
var TicketTransferStatus;
|
|
16
|
+
(function (TicketTransferStatus) {
|
|
17
|
+
TicketTransferStatus["REQUESTED"] = "REQUESTED";
|
|
18
|
+
TicketTransferStatus["PROCESSING"] = "PROCESSING";
|
|
19
|
+
TicketTransferStatus["COMPLETED"] = "COMPLETED";
|
|
20
|
+
TicketTransferStatus["CANCELLED"] = "CANCELLED";
|
|
21
|
+
TicketTransferStatus["FAILED"] = "FAILED";
|
|
22
|
+
})(TicketTransferStatus || (exports.TicketTransferStatus = TicketTransferStatus = {}));
|
|
23
|
+
exports.TicketTransferInfinitePaySchema = new mongoose_1.Schema({
|
|
24
|
+
handle: { type: String, required: false },
|
|
25
|
+
TransferNsu: { type: String, required: false, index: true },
|
|
26
|
+
checkoutUrl: { type: String, required: false },
|
|
27
|
+
invoiceSlug: { type: String, required: false, index: true },
|
|
28
|
+
transactionNsu: { type: String, required: false, index: true },
|
|
29
|
+
captureMethod: { type: String, required: false },
|
|
30
|
+
amountCents: { type: Number, required: false },
|
|
31
|
+
paidAmountCents: { type: Number, required: false },
|
|
32
|
+
installments: { type: Number, required: false },
|
|
33
|
+
receiptUrl: { type: String, required: false },
|
|
34
|
+
paymentStatus: { type: String, required: false },
|
|
35
|
+
webhookReceivedAt: { type: Date, required: false },
|
|
36
|
+
lastWebhookPayload: { type: mongoose_1.Schema.Types.Mixed, required: false },
|
|
37
|
+
checkoutCreatedAt: { type: Date, required: false },
|
|
38
|
+
}, { _id: false });
|
|
39
|
+
exports.TicketTransferSchema = new mongoose_1.Schema({
|
|
40
|
+
sequenceNumber: { type: Number, required: true },
|
|
41
|
+
ticket: { type: mongoose_1.Schema.Types.ObjectId, ref: "ticket", required: true },
|
|
42
|
+
accountOrigin: { type: mongoose_1.Schema.Types.ObjectId, ref: "account", required: true },
|
|
43
|
+
accountDestination: { type: mongoose_1.Schema.Types.ObjectId, ref: "account", required: true },
|
|
44
|
+
status: { type: String, required: true, enum: TicketTransferStatus },
|
|
45
|
+
originAccepted: { type: Boolean, default: false },
|
|
46
|
+
paymentMethod: { type: String, enum: TicketTransferPaymentMethod },
|
|
47
|
+
amount: { type: Number, required: true },
|
|
48
|
+
acceptTermsOfChallenge: { type: TicketOrder_1.AcceptTermsOfChallengeSchema, required: true },
|
|
49
|
+
infinitePay: { type: exports.TicketTransferInfinitePaySchema, required: false },
|
|
50
|
+
walletMoviment: { type: mongoose_1.Schema.Types.ObjectId, ref: "wallet-moviment", required: false },
|
|
51
|
+
}, {
|
|
52
|
+
timestamps: {
|
|
53
|
+
createdAt: "createdAtDateTime",
|
|
54
|
+
updatedAt: "updatedAtDateTime"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
exports.TicketTransferSchema.index({ accountOrigin: 1 });
|
|
58
|
+
exports.TicketTransferSchema.index({ accountDestination: 1 });
|
|
59
|
+
exports.TicketTransferSchema.index({ status: 1 });
|
|
60
|
+
exports.TicketTransferSchema.index({ paymentMethod: 1 });
|
|
61
|
+
exports.TicketTransferSchema.index({ "infinitePay.TransferNsu": 1 });
|
|
62
|
+
exports.TicketTransferSchema.index({ "infinitePay.transactionNsu": 1 });
|
|
@@ -12,6 +12,7 @@ var WalletMovimentStatus;
|
|
|
12
12
|
var WalletMovimentType;
|
|
13
13
|
(function (WalletMovimentType) {
|
|
14
14
|
WalletMovimentType["DEPOSIT"] = "DEPOSIT";
|
|
15
|
+
WalletMovimentType["SALE_TICKET"] = "SALE_TICKET";
|
|
15
16
|
WalletMovimentType["WITHDRAW"] = "WITHDRAW";
|
|
16
17
|
WalletMovimentType["BUY_TICKET"] = "BUY_TICKET";
|
|
17
18
|
WalletMovimentType["AWARD"] = "AWARD";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Schema, Types } from "mongoose";
|
|
2
|
+
import { IDefault } from "./IDefault";
|
|
3
|
+
export declare enum WhatsAppTemplateStatus {
|
|
4
|
+
APPROVED = "APPROVED",
|
|
5
|
+
PENDING = "PENDING",
|
|
6
|
+
REJECTED = "REJECTED",
|
|
7
|
+
PAUSED = "PAUSED",
|
|
8
|
+
DISABLED = "DISABLED",
|
|
9
|
+
IN_APPEAL = "IN_APPEAL",
|
|
10
|
+
DELETED = "DELETED"
|
|
11
|
+
}
|
|
12
|
+
export declare enum WhatsAppTemplateCategory {
|
|
13
|
+
MARKETING = "MARKETING",
|
|
14
|
+
UTILITY = "UTILITY",
|
|
15
|
+
AUTHENTICATION = "AUTHENTICATION"
|
|
16
|
+
}
|
|
17
|
+
export type WhatsAppTemplateComponentType = "HEADER" | "BODY" | "FOOTER" | "BUTTONS";
|
|
18
|
+
export type WhatsAppTemplateHeaderFormat = "TEXT" | "IMAGE" | "VIDEO" | "DOCUMENT" | "LOCATION";
|
|
19
|
+
export type WhatsAppTemplateVariableKind = "text" | "media";
|
|
20
|
+
export interface IWhatsAppTemplateButton {
|
|
21
|
+
type?: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
phoneNumber?: string;
|
|
25
|
+
example?: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface IWhatsAppTemplateComponent {
|
|
28
|
+
type: string;
|
|
29
|
+
format?: string;
|
|
30
|
+
text?: string;
|
|
31
|
+
example?: unknown;
|
|
32
|
+
buttons?: IWhatsAppTemplateButton[];
|
|
33
|
+
}
|
|
34
|
+
export interface IWhatsAppTemplateVariable {
|
|
35
|
+
key: string;
|
|
36
|
+
component: string;
|
|
37
|
+
buttonIndex?: number;
|
|
38
|
+
index?: number;
|
|
39
|
+
name?: string;
|
|
40
|
+
label: string;
|
|
41
|
+
example?: string;
|
|
42
|
+
kind: WhatsAppTemplateVariableKind;
|
|
43
|
+
}
|
|
44
|
+
export interface IWhatsAppTemplate extends IDefault {
|
|
45
|
+
_id?: Types.ObjectId;
|
|
46
|
+
externalId?: string;
|
|
47
|
+
wabaId?: string;
|
|
48
|
+
name: string;
|
|
49
|
+
language: string;
|
|
50
|
+
status: string;
|
|
51
|
+
category?: string;
|
|
52
|
+
parameterFormat?: string;
|
|
53
|
+
qualityScore?: string;
|
|
54
|
+
rejectedReason?: string;
|
|
55
|
+
components: IWhatsAppTemplateComponent[];
|
|
56
|
+
variables: IWhatsAppTemplateVariable[];
|
|
57
|
+
lastSyncedAt?: Date;
|
|
58
|
+
}
|
|
59
|
+
export declare const WhatsAppTemplateSchema: Schema<IWhatsAppTemplate, import("mongoose").Model<IWhatsAppTemplate, any, any, any, import("mongoose").Document<unknown, any, IWhatsAppTemplate, any> & IWhatsAppTemplate & Required<{
|
|
60
|
+
_id: Types.ObjectId;
|
|
61
|
+
}> & {
|
|
62
|
+
__v: number;
|
|
63
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, IWhatsAppTemplate, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<IWhatsAppTemplate>, {}> & import("mongoose").FlatRecord<IWhatsAppTemplate> & Required<{
|
|
64
|
+
_id: Types.ObjectId;
|
|
65
|
+
}> & {
|
|
66
|
+
__v: number;
|
|
67
|
+
}>;
|
|
68
|
+
export declare function extractPlaceholders(text?: string): string[];
|
|
69
|
+
export declare function extractWhatsAppTemplateVariables(components: IWhatsAppTemplateComponent[]): IWhatsAppTemplateVariable[];
|
|
70
|
+
export declare function applyWhatsAppTemplateValues(text: string | undefined, values: Record<string, string>, prefix: string): string;
|
|
71
|
+
export declare function renderWhatsAppTemplateContent(template: Pick<IWhatsAppTemplate, "components" | "name">, values?: Record<string, string>): string;
|
|
72
|
+
export declare function buildWhatsAppSendComponents(template: Pick<IWhatsAppTemplate, "components" | "parameterFormat">, values?: Record<string, string>): Record<string, unknown>[];
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhatsAppTemplateSchema = exports.WhatsAppTemplateCategory = exports.WhatsAppTemplateStatus = void 0;
|
|
4
|
+
exports.extractPlaceholders = extractPlaceholders;
|
|
5
|
+
exports.extractWhatsAppTemplateVariables = extractWhatsAppTemplateVariables;
|
|
6
|
+
exports.applyWhatsAppTemplateValues = applyWhatsAppTemplateValues;
|
|
7
|
+
exports.renderWhatsAppTemplateContent = renderWhatsAppTemplateContent;
|
|
8
|
+
exports.buildWhatsAppSendComponents = buildWhatsAppSendComponents;
|
|
9
|
+
const mongoose_1 = require("mongoose");
|
|
10
|
+
var WhatsAppTemplateStatus;
|
|
11
|
+
(function (WhatsAppTemplateStatus) {
|
|
12
|
+
WhatsAppTemplateStatus["APPROVED"] = "APPROVED";
|
|
13
|
+
WhatsAppTemplateStatus["PENDING"] = "PENDING";
|
|
14
|
+
WhatsAppTemplateStatus["REJECTED"] = "REJECTED";
|
|
15
|
+
WhatsAppTemplateStatus["PAUSED"] = "PAUSED";
|
|
16
|
+
WhatsAppTemplateStatus["DISABLED"] = "DISABLED";
|
|
17
|
+
WhatsAppTemplateStatus["IN_APPEAL"] = "IN_APPEAL";
|
|
18
|
+
WhatsAppTemplateStatus["DELETED"] = "DELETED";
|
|
19
|
+
})(WhatsAppTemplateStatus || (exports.WhatsAppTemplateStatus = WhatsAppTemplateStatus = {}));
|
|
20
|
+
var WhatsAppTemplateCategory;
|
|
21
|
+
(function (WhatsAppTemplateCategory) {
|
|
22
|
+
WhatsAppTemplateCategory["MARKETING"] = "MARKETING";
|
|
23
|
+
WhatsAppTemplateCategory["UTILITY"] = "UTILITY";
|
|
24
|
+
WhatsAppTemplateCategory["AUTHENTICATION"] = "AUTHENTICATION";
|
|
25
|
+
})(WhatsAppTemplateCategory || (exports.WhatsAppTemplateCategory = WhatsAppTemplateCategory = {}));
|
|
26
|
+
const WhatsAppTemplateButtonSchema = new mongoose_1.Schema({
|
|
27
|
+
type: { type: String },
|
|
28
|
+
text: { type: String },
|
|
29
|
+
url: { type: String },
|
|
30
|
+
phoneNumber: { type: String },
|
|
31
|
+
example: [{ type: String }],
|
|
32
|
+
}, { _id: false });
|
|
33
|
+
const WhatsAppTemplateComponentSchema = new mongoose_1.Schema({
|
|
34
|
+
type: { type: String, required: true },
|
|
35
|
+
format: { type: String },
|
|
36
|
+
text: { type: String },
|
|
37
|
+
example: { type: mongoose_1.Schema.Types.Mixed },
|
|
38
|
+
buttons: [WhatsAppTemplateButtonSchema],
|
|
39
|
+
}, { _id: false });
|
|
40
|
+
const WhatsAppTemplateVariableSchema = new mongoose_1.Schema({
|
|
41
|
+
key: { type: String, required: true },
|
|
42
|
+
component: { type: String, required: true },
|
|
43
|
+
buttonIndex: { type: Number },
|
|
44
|
+
index: { type: Number },
|
|
45
|
+
name: { type: String },
|
|
46
|
+
label: { type: String, required: true },
|
|
47
|
+
example: { type: String },
|
|
48
|
+
kind: { type: String, enum: ["text", "media"], required: true, default: "text" },
|
|
49
|
+
}, { _id: false });
|
|
50
|
+
exports.WhatsAppTemplateSchema = new mongoose_1.Schema({
|
|
51
|
+
externalId: { type: String },
|
|
52
|
+
wabaId: { type: String },
|
|
53
|
+
name: { type: String, required: true },
|
|
54
|
+
language: { type: String, required: true },
|
|
55
|
+
status: { type: String, required: true },
|
|
56
|
+
category: { type: String },
|
|
57
|
+
parameterFormat: { type: String },
|
|
58
|
+
qualityScore: { type: String },
|
|
59
|
+
rejectedReason: { type: String },
|
|
60
|
+
components: { type: [WhatsAppTemplateComponentSchema], default: [] },
|
|
61
|
+
variables: { type: [WhatsAppTemplateVariableSchema], default: [] },
|
|
62
|
+
lastSyncedAt: { type: Date },
|
|
63
|
+
}, {
|
|
64
|
+
timestamps: { createdAt: "createdAtDateTime", updatedAt: "updatedAtDateTime" },
|
|
65
|
+
});
|
|
66
|
+
exports.WhatsAppTemplateSchema.index({ name: 1, language: 1 }, { unique: true });
|
|
67
|
+
exports.WhatsAppTemplateSchema.index({ status: 1, name: 1 });
|
|
68
|
+
exports.WhatsAppTemplateSchema.index({ externalId: 1 });
|
|
69
|
+
const PLACEHOLDER_RE = /\{\{\s*([a-zA-Z_][\w]*|\d+)\s*\}\}/g;
|
|
70
|
+
function asRecord(value) {
|
|
71
|
+
return value && typeof value === "object" ? value : {};
|
|
72
|
+
}
|
|
73
|
+
function firstExampleString(example, fallbackIndex = 0) {
|
|
74
|
+
const record = asRecord(example);
|
|
75
|
+
const headerText = record.header_text;
|
|
76
|
+
if (Array.isArray(headerText) && headerText[fallbackIndex] != null)
|
|
77
|
+
return String(headerText[fallbackIndex]);
|
|
78
|
+
const headerHandle = record.header_handle;
|
|
79
|
+
if (Array.isArray(headerHandle) && headerHandle[0] != null)
|
|
80
|
+
return String(headerHandle[0]);
|
|
81
|
+
const bodyText = record.body_text;
|
|
82
|
+
if (Array.isArray(bodyText) && Array.isArray(bodyText[0]) && bodyText[0][fallbackIndex] != null) {
|
|
83
|
+
return String(bodyText[0][fallbackIndex]);
|
|
84
|
+
}
|
|
85
|
+
const named = record.body_text_named_params;
|
|
86
|
+
if (Array.isArray(named) && named[fallbackIndex]) {
|
|
87
|
+
const row = asRecord(named[fallbackIndex]);
|
|
88
|
+
if (row.example != null)
|
|
89
|
+
return String(row.example);
|
|
90
|
+
}
|
|
91
|
+
const headerNamed = record.header_text_named_params;
|
|
92
|
+
if (Array.isArray(headerNamed) && headerNamed[fallbackIndex]) {
|
|
93
|
+
const row = asRecord(headerNamed[fallbackIndex]);
|
|
94
|
+
if (row.example != null)
|
|
95
|
+
return String(row.example);
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
function extractPlaceholders(text) {
|
|
100
|
+
if (!text)
|
|
101
|
+
return [];
|
|
102
|
+
const found = [];
|
|
103
|
+
const seen = new Set();
|
|
104
|
+
const re = new RegExp(PLACEHOLDER_RE.source, "g");
|
|
105
|
+
let match;
|
|
106
|
+
while ((match = re.exec(text))) {
|
|
107
|
+
const token = match[1];
|
|
108
|
+
if (seen.has(token))
|
|
109
|
+
continue;
|
|
110
|
+
seen.add(token);
|
|
111
|
+
found.push(token);
|
|
112
|
+
}
|
|
113
|
+
return found;
|
|
114
|
+
}
|
|
115
|
+
function placeholderLabel(component, token, kind) {
|
|
116
|
+
if (kind === "media") {
|
|
117
|
+
if (component === "HEADER")
|
|
118
|
+
return "Mídia do cabeçalho (URL)";
|
|
119
|
+
return `Mídia (${component})`;
|
|
120
|
+
}
|
|
121
|
+
const where = component === "HEADER" ? "cabeçalho" : component === "BODY" ? "corpo" : component === "BUTTON" ? "botão" : component.toLowerCase();
|
|
122
|
+
return isNaN(Number(token)) ? `${where}: {{${token}}}` : `${where} {{${token}}}`;
|
|
123
|
+
}
|
|
124
|
+
function extractWhatsAppTemplateVariables(components) {
|
|
125
|
+
const variables = [];
|
|
126
|
+
for (const component of components) {
|
|
127
|
+
const type = String(component.type || "").toUpperCase();
|
|
128
|
+
if (type === "HEADER") {
|
|
129
|
+
const format = String(component.format || "TEXT").toUpperCase();
|
|
130
|
+
if (format === "IMAGE" || format === "VIDEO" || format === "DOCUMENT") {
|
|
131
|
+
variables.push({
|
|
132
|
+
key: "header.media",
|
|
133
|
+
component: "HEADER",
|
|
134
|
+
label: placeholderLabel("HEADER", "media", "media"),
|
|
135
|
+
example: firstExampleString(component.example),
|
|
136
|
+
kind: "media",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (type === "HEADER" || type === "BODY") {
|
|
141
|
+
const tokens = extractPlaceholders(component.text);
|
|
142
|
+
tokens.forEach((token, order) => {
|
|
143
|
+
const index = Number(token);
|
|
144
|
+
variables.push({
|
|
145
|
+
key: `${type.toLowerCase()}.${token}`,
|
|
146
|
+
component: type,
|
|
147
|
+
index: Number.isFinite(index) ? index : order + 1,
|
|
148
|
+
name: Number.isFinite(index) ? undefined : token,
|
|
149
|
+
label: placeholderLabel(type, token, "text"),
|
|
150
|
+
example: firstExampleString(component.example, Number.isFinite(index) ? index - 1 : order),
|
|
151
|
+
kind: "text",
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (type === "BUTTONS") {
|
|
156
|
+
(component.buttons || []).forEach((button, buttonIndex) => {
|
|
157
|
+
const tokens = extractPlaceholders(button.url);
|
|
158
|
+
tokens.forEach((token, order) => {
|
|
159
|
+
const index = Number(token);
|
|
160
|
+
variables.push({
|
|
161
|
+
key: `button.${buttonIndex}.${token}`,
|
|
162
|
+
component: "BUTTON",
|
|
163
|
+
buttonIndex,
|
|
164
|
+
index: Number.isFinite(index) ? index : order + 1,
|
|
165
|
+
name: Number.isFinite(index) ? undefined : token,
|
|
166
|
+
label: `botão ${button.text || buttonIndex + 1} {{${token}}}`,
|
|
167
|
+
example: button.example?.[order],
|
|
168
|
+
kind: "text",
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return variables;
|
|
175
|
+
}
|
|
176
|
+
function applyWhatsAppTemplateValues(text, values, prefix) {
|
|
177
|
+
if (!text)
|
|
178
|
+
return "";
|
|
179
|
+
return text.replace(PLACEHOLDER_RE, (_full, token) => {
|
|
180
|
+
const exact = values[`${prefix}.${token}`];
|
|
181
|
+
if (exact != null && exact !== "")
|
|
182
|
+
return exact;
|
|
183
|
+
const byToken = values[token];
|
|
184
|
+
if (byToken != null && byToken !== "")
|
|
185
|
+
return byToken;
|
|
186
|
+
return `{{${token}}}`;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function renderWhatsAppTemplateContent(template, values = {}) {
|
|
190
|
+
const parts = [];
|
|
191
|
+
for (const component of template.components || []) {
|
|
192
|
+
const type = String(component.type || "").toUpperCase();
|
|
193
|
+
if (type === "HEADER") {
|
|
194
|
+
const format = String(component.format || "TEXT").toUpperCase();
|
|
195
|
+
if (format === "TEXT") {
|
|
196
|
+
const text = applyWhatsAppTemplateValues(component.text, values, "header");
|
|
197
|
+
if (text)
|
|
198
|
+
parts.push(text);
|
|
199
|
+
}
|
|
200
|
+
else if (values["header.media"]) {
|
|
201
|
+
parts.push(values["header.media"]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (type === "BODY") {
|
|
205
|
+
const text = applyWhatsAppTemplateValues(component.text, values, "body");
|
|
206
|
+
if (text)
|
|
207
|
+
parts.push(text);
|
|
208
|
+
}
|
|
209
|
+
if (type === "FOOTER" && component.text) {
|
|
210
|
+
parts.push(component.text);
|
|
211
|
+
}
|
|
212
|
+
if (type === "BUTTONS") {
|
|
213
|
+
for (const button of component.buttons || []) {
|
|
214
|
+
if (button.text)
|
|
215
|
+
parts.push(button.text);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return parts.join("\n\n").trim() || template.name;
|
|
220
|
+
}
|
|
221
|
+
function buildWhatsAppSendComponents(template, values = {}) {
|
|
222
|
+
const named = String(template.parameterFormat || "").toUpperCase() === "NAMED";
|
|
223
|
+
const payload = [];
|
|
224
|
+
for (const component of template.components || []) {
|
|
225
|
+
const type = String(component.type || "").toUpperCase();
|
|
226
|
+
if (type === "HEADER") {
|
|
227
|
+
const format = String(component.format || "TEXT").toUpperCase();
|
|
228
|
+
if (format === "IMAGE" || format === "VIDEO" || format === "DOCUMENT") {
|
|
229
|
+
const link = values["header.media"];
|
|
230
|
+
if (link) {
|
|
231
|
+
const mediaType = format.toLowerCase();
|
|
232
|
+
payload.push({
|
|
233
|
+
type: "header",
|
|
234
|
+
parameters: [{ type: mediaType, [mediaType]: { link } }],
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const tokens = extractPlaceholders(component.text);
|
|
240
|
+
if (!tokens.length)
|
|
241
|
+
continue;
|
|
242
|
+
payload.push({
|
|
243
|
+
type: "header",
|
|
244
|
+
parameters: tokens.map((token) => parameterOf(token, values, "header", named)),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
if (type === "BODY") {
|
|
248
|
+
const tokens = extractPlaceholders(component.text);
|
|
249
|
+
if (!tokens.length)
|
|
250
|
+
continue;
|
|
251
|
+
payload.push({
|
|
252
|
+
type: "body",
|
|
253
|
+
parameters: tokens.map((token) => parameterOf(token, values, "body", named)),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (type === "BUTTONS") {
|
|
257
|
+
(component.buttons || []).forEach((button, buttonIndex) => {
|
|
258
|
+
const tokens = extractPlaceholders(button.url);
|
|
259
|
+
if (!tokens.length)
|
|
260
|
+
return;
|
|
261
|
+
payload.push({
|
|
262
|
+
type: "button",
|
|
263
|
+
sub_type: "url",
|
|
264
|
+
index: String(buttonIndex),
|
|
265
|
+
parameters: tokens.map((token) => ({
|
|
266
|
+
type: "text",
|
|
267
|
+
text: values[`button.${buttonIndex}.${token}`] || values[token] || "",
|
|
268
|
+
})),
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return payload;
|
|
274
|
+
}
|
|
275
|
+
function parameterOf(token, values, prefix, named) {
|
|
276
|
+
const text = values[`${prefix}.${token}`] || values[token] || "";
|
|
277
|
+
if (named && isNaN(Number(token))) {
|
|
278
|
+
return { type: "text", parameter_name: token, text };
|
|
279
|
+
}
|
|
280
|
+
return { type: "text", text };
|
|
281
|
+
}
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export * from "./Access";
|
|
2
2
|
export * from "./Account";
|
|
3
3
|
export * from "./AccountDeletionRequest";
|
|
4
|
-
export * from "./AdminAccount";
|
|
5
4
|
export * from "./AdminAccessProfile";
|
|
5
|
+
export * from "./AdminAccount";
|
|
6
6
|
export * from "./AdminComunication";
|
|
7
|
-
export * from "./EventComunication";
|
|
8
7
|
export * from "./AdminTemplateEmail";
|
|
9
8
|
export * from "./AdminTemplatePush";
|
|
10
9
|
export * from "./Challenge";
|
|
@@ -17,9 +16,12 @@ export * from "./ChampionshipRound";
|
|
|
17
16
|
export * from "./Chat";
|
|
18
17
|
export * from "./ChatMessage";
|
|
19
18
|
export * from "./Contact";
|
|
19
|
+
export * from "./EventComunication";
|
|
20
20
|
export * from "./File";
|
|
21
21
|
export * from "./Team";
|
|
22
22
|
export * from "./Ticket";
|
|
23
23
|
export * from "./TicketGuess";
|
|
24
24
|
export * from "./TicketOrder";
|
|
25
|
+
export * from "./TicketTransfer";
|
|
25
26
|
export * from "./WalletMoviment";
|
|
27
|
+
export * from "./WhatsAppTemplate";
|
package/dist/models/index.js
CHANGED
|
@@ -17,10 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./Access"), exports);
|
|
18
18
|
__exportStar(require("./Account"), exports);
|
|
19
19
|
__exportStar(require("./AccountDeletionRequest"), exports);
|
|
20
|
-
__exportStar(require("./AdminAccount"), exports);
|
|
21
20
|
__exportStar(require("./AdminAccessProfile"), exports);
|
|
21
|
+
__exportStar(require("./AdminAccount"), exports);
|
|
22
22
|
__exportStar(require("./AdminComunication"), exports);
|
|
23
|
-
__exportStar(require("./EventComunication"), exports);
|
|
24
23
|
__exportStar(require("./AdminTemplateEmail"), exports);
|
|
25
24
|
__exportStar(require("./AdminTemplatePush"), exports);
|
|
26
25
|
__exportStar(require("./Challenge"), exports);
|
|
@@ -33,9 +32,12 @@ __exportStar(require("./ChampionshipRound"), exports);
|
|
|
33
32
|
__exportStar(require("./Chat"), exports);
|
|
34
33
|
__exportStar(require("./ChatMessage"), exports);
|
|
35
34
|
__exportStar(require("./Contact"), exports);
|
|
35
|
+
__exportStar(require("./EventComunication"), exports);
|
|
36
36
|
__exportStar(require("./File"), exports);
|
|
37
37
|
__exportStar(require("./Team"), exports);
|
|
38
38
|
__exportStar(require("./Ticket"), exports);
|
|
39
39
|
__exportStar(require("./TicketGuess"), exports);
|
|
40
40
|
__exportStar(require("./TicketOrder"), exports);
|
|
41
|
+
__exportStar(require("./TicketTransfer"), exports);
|
|
41
42
|
__exportStar(require("./WalletMoviment"), exports);
|
|
43
|
+
__exportStar(require("./WhatsAppTemplate"), exports);
|
package/package.json
CHANGED