@grapadigital/shared-schemas 2.8.0 → 2.9.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/schemas/routine.schema.d.ts +69 -0
- package/dist/schemas/routine.schema.js +127 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -38,5 +38,6 @@ export * from "./schemas/snapshot.schema";
|
|
|
38
38
|
export * from "./schemas/lead.schema";
|
|
39
39
|
export * from "./schemas/store.schema";
|
|
40
40
|
export * from "./schemas/store-visit.schema";
|
|
41
|
+
export * from "./schemas/routine.schema";
|
|
41
42
|
export * from "./utils/normalize-content-link.util";
|
|
42
43
|
export * from "./utils/merge-metrics-breakdown.util";
|
package/dist/index.js
CHANGED
|
@@ -59,5 +59,6 @@ __exportStar(require("./schemas/snapshot.schema"), exports);
|
|
|
59
59
|
__exportStar(require("./schemas/lead.schema"), exports);
|
|
60
60
|
__exportStar(require("./schemas/store.schema"), exports);
|
|
61
61
|
__exportStar(require("./schemas/store-visit.schema"), exports);
|
|
62
|
+
__exportStar(require("./schemas/routine.schema"), exports);
|
|
62
63
|
__exportStar(require("./utils/normalize-content-link.util"), exports);
|
|
63
64
|
__exportStar(require("./utils/merge-metrics-breakdown.util"), exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { HydratedDocument, Schema as MongooseSchema, Types } from "mongoose";
|
|
2
|
+
import { Action } from "./action.schema";
|
|
3
|
+
export type RoutineDocument = HydratedDocument<Routine>;
|
|
4
|
+
export declare const ROUTINE_TRIGGERS: readonly ["schedule", "manual"];
|
|
5
|
+
export type RoutineTrigger = (typeof ROUTINE_TRIGGERS)[number];
|
|
6
|
+
export declare const ROUTINE_STATUSES: readonly ["running", "done", "error"];
|
|
7
|
+
export type RoutineStatus = (typeof ROUTINE_STATUSES)[number];
|
|
8
|
+
export declare class RoutineItem {
|
|
9
|
+
actionId?: Types.ObjectId | Action;
|
|
10
|
+
title?: string;
|
|
11
|
+
outcome: string;
|
|
12
|
+
reasonKey?: string;
|
|
13
|
+
details?: unknown;
|
|
14
|
+
primetagId?: string;
|
|
15
|
+
emailedTo?: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare const RoutineItemSchema: MongooseSchema<RoutineItem, import("mongoose").Model<RoutineItem, any, any, any, import("mongoose").Document<unknown, any, RoutineItem, any, {}> & RoutineItem & {
|
|
18
|
+
_id: Types.ObjectId;
|
|
19
|
+
} & {
|
|
20
|
+
__v: number;
|
|
21
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, RoutineItem, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<RoutineItem>, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").FlatRecord<RoutineItem> & {
|
|
22
|
+
_id: Types.ObjectId;
|
|
23
|
+
} & {
|
|
24
|
+
__v: number;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Uma linha por execução de rotina do routines-worker (GD-888). `routine` é o
|
|
28
|
+
* nome da rotina e `runId` a chave da rodada (a data nas diárias, a segunda-feira
|
|
29
|
+
* no resumo semanal, `manual:<ISO>` nas manuais): a reentrega da mesma mensagem
|
|
30
|
+
* atualiza a mesma linha. `result` resume a execução e `items` detalha por Ação
|
|
31
|
+
* quando a rotina trata Ações uma a uma.
|
|
32
|
+
*/
|
|
33
|
+
export declare class Routine {
|
|
34
|
+
_id?: Types.ObjectId;
|
|
35
|
+
routine: string;
|
|
36
|
+
runId: string;
|
|
37
|
+
trigger: RoutineTrigger;
|
|
38
|
+
status: RoutineStatus;
|
|
39
|
+
startedAt: Date;
|
|
40
|
+
finishedAt?: Date;
|
|
41
|
+
input?: unknown;
|
|
42
|
+
result?: unknown;
|
|
43
|
+
items?: RoutineItem[];
|
|
44
|
+
error?: string;
|
|
45
|
+
createdAt?: Date;
|
|
46
|
+
updatedAt?: Date;
|
|
47
|
+
}
|
|
48
|
+
export declare const RoutineSchema: MongooseSchema<Routine, import("mongoose").Model<Routine, any, any, any, import("mongoose").Document<unknown, any, Routine, any, {}> & Routine & Required<{
|
|
49
|
+
_id: Types.ObjectId;
|
|
50
|
+
}> & {
|
|
51
|
+
__v: number;
|
|
52
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Routine, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Routine>, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").FlatRecord<Routine> & Required<{
|
|
53
|
+
_id: Types.ObjectId;
|
|
54
|
+
}> & {
|
|
55
|
+
__v: number;
|
|
56
|
+
}>;
|
|
57
|
+
export declare const RoutineModel: import("mongoose").Model<Routine, {}, {}, {}, import("mongoose").Document<unknown, {}, Routine, {}, import("mongoose").DefaultSchemaOptions> & Routine & Required<{
|
|
58
|
+
_id: Types.ObjectId;
|
|
59
|
+
}> & {
|
|
60
|
+
__v: number;
|
|
61
|
+
}, MongooseSchema<Routine, import("mongoose").Model<Routine, any, any, any, import("mongoose").Document<unknown, any, Routine, any, {}> & Routine & Required<{
|
|
62
|
+
_id: Types.ObjectId;
|
|
63
|
+
}> & {
|
|
64
|
+
__v: number;
|
|
65
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Routine, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Routine>, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").FlatRecord<Routine> & Required<{
|
|
66
|
+
_id: Types.ObjectId;
|
|
67
|
+
}> & {
|
|
68
|
+
__v: number;
|
|
69
|
+
}>>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RoutineModel = exports.RoutineSchema = exports.Routine = exports.RoutineItemSchema = exports.RoutineItem = exports.ROUTINE_STATUSES = exports.ROUTINE_TRIGGERS = void 0;
|
|
13
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
+
const mongoose_2 = require("mongoose");
|
|
15
|
+
// schedule: disparada pelo Cloud Scheduler; manual: mensagem publicada à mão
|
|
16
|
+
// (ex.: resumo semanal com destinatários de teste).
|
|
17
|
+
exports.ROUTINE_TRIGGERS = ["schedule", "manual"];
|
|
18
|
+
exports.ROUTINE_STATUSES = ["running", "done", "error"];
|
|
19
|
+
// O que aconteceu com uma Ação numa rodada (ex.: lançamento na Primetag).
|
|
20
|
+
let RoutineItem = class RoutineItem {
|
|
21
|
+
};
|
|
22
|
+
exports.RoutineItem = RoutineItem;
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: "Action", required: false }),
|
|
25
|
+
__metadata("design:type", Object)
|
|
26
|
+
], RoutineItem.prototype, "actionId", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], RoutineItem.prototype, "title", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], RoutineItem.prototype, "outcome", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
37
|
+
__metadata("design:type", String)
|
|
38
|
+
], RoutineItem.prototype, "reasonKey", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.Mixed, required: false }),
|
|
41
|
+
__metadata("design:type", Object)
|
|
42
|
+
], RoutineItem.prototype, "details", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
45
|
+
__metadata("design:type", String)
|
|
46
|
+
], RoutineItem.prototype, "primetagId", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, mongoose_1.Prop)({ type: [String], required: false, default: undefined }),
|
|
49
|
+
__metadata("design:type", Array)
|
|
50
|
+
], RoutineItem.prototype, "emailedTo", void 0);
|
|
51
|
+
exports.RoutineItem = RoutineItem = __decorate([
|
|
52
|
+
(0, mongoose_1.Schema)({ _id: false })
|
|
53
|
+
], RoutineItem);
|
|
54
|
+
exports.RoutineItemSchema = mongoose_1.SchemaFactory.createForClass(RoutineItem);
|
|
55
|
+
/**
|
|
56
|
+
* Uma linha por execução de rotina do routines-worker (GD-888). `routine` é o
|
|
57
|
+
* nome da rotina e `runId` a chave da rodada (a data nas diárias, a segunda-feira
|
|
58
|
+
* no resumo semanal, `manual:<ISO>` nas manuais): a reentrega da mesma mensagem
|
|
59
|
+
* atualiza a mesma linha. `result` resume a execução e `items` detalha por Ação
|
|
60
|
+
* quando a rotina trata Ações uma a uma.
|
|
61
|
+
*/
|
|
62
|
+
let Routine = class Routine {
|
|
63
|
+
};
|
|
64
|
+
exports.Routine = Routine;
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, auto: true, required: false }),
|
|
67
|
+
__metadata("design:type", mongoose_2.Types.ObjectId)
|
|
68
|
+
], Routine.prototype, "_id", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
71
|
+
__metadata("design:type", String)
|
|
72
|
+
], Routine.prototype, "routine", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
75
|
+
__metadata("design:type", String)
|
|
76
|
+
], Routine.prototype, "runId", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, mongoose_1.Prop)({ type: String, enum: exports.ROUTINE_TRIGGERS, required: true }),
|
|
79
|
+
__metadata("design:type", String)
|
|
80
|
+
], Routine.prototype, "trigger", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
(0, mongoose_1.Prop)({ type: String, enum: exports.ROUTINE_STATUSES, required: true }),
|
|
83
|
+
__metadata("design:type", String)
|
|
84
|
+
], Routine.prototype, "status", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, mongoose_1.Prop)({ type: Date, required: true }),
|
|
87
|
+
__metadata("design:type", Date)
|
|
88
|
+
], Routine.prototype, "startedAt", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, mongoose_1.Prop)({ type: Date, required: false }),
|
|
91
|
+
__metadata("design:type", Date)
|
|
92
|
+
], Routine.prototype, "finishedAt", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.Mixed, required: false }),
|
|
95
|
+
__metadata("design:type", Object)
|
|
96
|
+
], Routine.prototype, "input", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
(0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.Mixed, required: false }),
|
|
99
|
+
__metadata("design:type", Object)
|
|
100
|
+
], Routine.prototype, "result", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, mongoose_1.Prop)({ type: [exports.RoutineItemSchema], required: false, default: undefined }),
|
|
103
|
+
__metadata("design:type", Array)
|
|
104
|
+
], Routine.prototype, "items", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
107
|
+
__metadata("design:type", String)
|
|
108
|
+
], Routine.prototype, "error", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
(0, mongoose_1.Prop)({ default: Date.now, required: false }),
|
|
111
|
+
__metadata("design:type", Date)
|
|
112
|
+
], Routine.prototype, "createdAt", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
(0, mongoose_1.Prop)({ default: Date.now, required: false }),
|
|
115
|
+
__metadata("design:type", Date)
|
|
116
|
+
], Routine.prototype, "updatedAt", void 0);
|
|
117
|
+
exports.Routine = Routine = __decorate([
|
|
118
|
+
(0, mongoose_1.Schema)({ collection: "routines", timestamps: true })
|
|
119
|
+
], Routine);
|
|
120
|
+
exports.RoutineSchema = mongoose_1.SchemaFactory.createForClass(Routine);
|
|
121
|
+
// Reentrega da mesma mensagem atualiza a mesma linha.
|
|
122
|
+
exports.RoutineSchema.index({ routine: 1, runId: 1 }, { unique: true });
|
|
123
|
+
// Última execução de uma rotina.
|
|
124
|
+
exports.RoutineSchema.index({ routine: 1, startedAt: -1 });
|
|
125
|
+
// O Mongo apaga sozinho as execuções com mais de 90 dias.
|
|
126
|
+
exports.RoutineSchema.index({ createdAt: 1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 });
|
|
127
|
+
exports.RoutineModel = (0, mongoose_2.model)("Routine", exports.RoutineSchema);
|