@grapadigital/shared-schemas 2.12.0 → 2.14.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.
@@ -1,9 +1,19 @@
1
1
  import { HydratedDocument, Schema as MongooseSchema, Types } from "mongoose";
2
2
  import { Client } from "./client.schema";
3
- /** Métrica do benchmark, com nomes por extenso (GD-751). */
4
- export declare const BENCHMARK_METRIC_VALUES: readonly ["reach", "engagementRate", "costPerThousandImpressions", "costPerEngagement"];
3
+ /**
4
+ * Métrica do benchmark, com nomes por extenso (GD-751). Alcance e Alcance
5
+ * efetivo são métricas diferentes: `reach` é contagem, `effectiveReach` é
6
+ * alcance sobre os seguidores no momento do post, em % (GD-668).
7
+ */
8
+ export declare const BENCHMARK_METRIC_VALUES: readonly ["reach", "effectiveReach", "impressions", "engagementCount", "engagementRate", "qualifiedEngagementRate", "score", "costPerInfluency", "costPerThousandImpressions", "costPerEngagement"];
5
9
  export type BenchmarkMetric = (typeof BENCHMARK_METRIC_VALUES)[number];
6
10
  export type BenchmarkMode = "organic" | "paid";
11
+ /**
12
+ * Unidade dos percentis da faixa: médias por campanha no registro de um
13
+ * cliente, medianas por cliente no registro global. Ver GD-668.
14
+ */
15
+ export declare const BENCHMARK_SAMPLE_UNIT_VALUES: readonly ["campaigns", "clients"];
16
+ export type BenchmarkSampleUnit = (typeof BENCHMARK_SAMPLE_UNIT_VALUES)[number];
7
17
  export type BenchmarkDocument = HydratedDocument<Benchmark>;
8
18
  export declare class Benchmark {
9
19
  _id?: Types.ObjectId;
@@ -14,6 +24,22 @@ export declare class Benchmark {
14
24
  good: number;
15
25
  inverted: boolean;
16
26
  client?: Types.ObjectId | Client;
27
+ /** Mediana da distribuição, entre `bad` e `good`. */
28
+ p50?: number | null;
29
+ /** Quantas unidades formaram os percentis; a unidade está em `sampleUnit`. */
30
+ sampleSize?: number | null;
31
+ sampleUnit?: BenchmarkSampleUnit | null;
32
+ /** Conteúdos por trás da faixa. Só para depuração, não vai para a tela. */
33
+ contentCount?: number | null;
34
+ /** Início da janela móvel considerada, inclusivo. */
35
+ from?: Date | null;
36
+ /** Fim da janela móvel considerada, exclusivo. */
37
+ to?: Date | null;
38
+ /**
39
+ * Quando a rotina gravou este registro. Vazio é registro que não veio dela:
40
+ * legado do script de 26/10 ou gravado à mão pelo `POST /admin/benchmark`.
41
+ */
42
+ generatedAt?: Date | null;
17
43
  }
18
44
  export declare const BenchmarkSchema: MongooseSchema<Benchmark, import("mongoose").Model<Benchmark, any, any, any, import("mongoose").Document<unknown, any, Benchmark, any, {}> & Benchmark & Required<{
19
45
  _id: Types.ObjectId;
@@ -9,16 +9,32 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.BenchmarkModel = exports.BenchmarkSchema = exports.Benchmark = exports.BENCHMARK_METRIC_VALUES = void 0;
12
+ exports.BenchmarkModel = exports.BenchmarkSchema = exports.Benchmark = exports.BENCHMARK_SAMPLE_UNIT_VALUES = exports.BENCHMARK_METRIC_VALUES = void 0;
13
13
  const mongoose_1 = require("@nestjs/mongoose");
14
+ const swagger_1 = require("@nestjs/swagger");
14
15
  const mongoose_2 = require("mongoose");
15
- /** Métrica do benchmark, com nomes por extenso (GD-751). */
16
+ /**
17
+ * Métrica do benchmark, com nomes por extenso (GD-751). Alcance e Alcance
18
+ * efetivo são métricas diferentes: `reach` é contagem, `effectiveReach` é
19
+ * alcance sobre os seguidores no momento do post, em % (GD-668).
20
+ */
16
21
  exports.BENCHMARK_METRIC_VALUES = [
17
22
  "reach",
23
+ "effectiveReach",
24
+ "impressions",
25
+ "engagementCount",
18
26
  "engagementRate",
27
+ "qualifiedEngagementRate",
28
+ "score",
29
+ "costPerInfluency",
19
30
  "costPerThousandImpressions",
20
31
  "costPerEngagement",
21
32
  ];
33
+ /**
34
+ * Unidade dos percentis da faixa: médias por campanha no registro de um
35
+ * cliente, medianas por cliente no registro global. Ver GD-668.
36
+ */
37
+ exports.BENCHMARK_SAMPLE_UNIT_VALUES = ["campaigns", "clients"];
22
38
  let Benchmark = class Benchmark {
23
39
  };
24
40
  exports.Benchmark = Benchmark;
@@ -54,8 +70,58 @@ __decorate([
54
70
  (0, mongoose_1.Prop)({ type: mongoose_2.Schema.Types.ObjectId, ref: "Client", required: false }),
55
71
  __metadata("design:type", Object)
56
72
  ], Benchmark.prototype, "client", void 0);
73
+ __decorate([
74
+ (0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true }),
75
+ (0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
76
+ __metadata("design:type", Object)
77
+ ], Benchmark.prototype, "p50", void 0);
78
+ __decorate([
79
+ (0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true }),
80
+ (0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
81
+ __metadata("design:type", Object)
82
+ ], Benchmark.prototype, "sampleSize", void 0);
83
+ __decorate([
84
+ (0, swagger_1.ApiProperty)({ enum: exports.BENCHMARK_SAMPLE_UNIT_VALUES, required: false, nullable: true }),
85
+ (0, mongoose_1.Prop)({ type: String, enum: exports.BENCHMARK_SAMPLE_UNIT_VALUES, required: false, default: null }),
86
+ __metadata("design:type", Object)
87
+ ], Benchmark.prototype, "sampleUnit", void 0);
88
+ __decorate([
89
+ (0, swagger_1.ApiProperty)({ type: Number, required: false, nullable: true }),
90
+ (0, mongoose_1.Prop)({ type: Number, required: false, default: null }),
91
+ __metadata("design:type", Object)
92
+ ], Benchmark.prototype, "contentCount", void 0);
93
+ __decorate([
94
+ (0, swagger_1.ApiProperty)({ type: Date, required: false, nullable: true }),
95
+ (0, mongoose_1.Prop)({ type: Date, required: false, default: null }),
96
+ __metadata("design:type", Object)
97
+ ], Benchmark.prototype, "from", void 0);
98
+ __decorate([
99
+ (0, swagger_1.ApiProperty)({ type: Date, required: false, nullable: true }),
100
+ (0, mongoose_1.Prop)({ type: Date, required: false, default: null }),
101
+ __metadata("design:type", Object)
102
+ ], Benchmark.prototype, "to", void 0);
103
+ __decorate([
104
+ (0, swagger_1.ApiProperty)({ type: Date, required: false, nullable: true }),
105
+ (0, mongoose_1.Prop)({ type: Date, required: false, default: null }),
106
+ __metadata("design:type", Object)
107
+ ], Benchmark.prototype, "generatedAt", void 0);
57
108
  exports.Benchmark = Benchmark = __decorate([
58
109
  (0, mongoose_1.Schema)({ timestamps: true })
59
110
  ], Benchmark);
60
111
  exports.BenchmarkSchema = mongoose_1.SchemaFactory.createForClass(Benchmark);
112
+ /**
113
+ * `metric` vem antes de `format` e `mode` porque a consulta mais frequente é a
114
+ * do relatório, que filtra por cliente e métrica sem citar formato nem modo
115
+ * (GD-998). Nesta ordem o índice serve também ao `find` por escopo da rotina,
116
+ * que usa só o prefixo `client`.
117
+ *
118
+ * Ainda **não é único**: a chave única só pode subir depois da primeira rodada
119
+ * da rotina, que é quando a coleção passa a ter uma combinação por chave
120
+ * garantida (Passo 9 da GD-668). O nome é explícito porque o `autoIndex` não
121
+ * altera índice existente: criar o único com o nome que o Mongoose daria a
122
+ * este devolveria `IndexOptionsConflict`, que o Mongoose só emite no evento
123
+ * `index` do model e passa batido no boot. O Passo 9 derruba
124
+ * `benchmark_scope` e cria `benchmark_scope_unique`.
125
+ */
126
+ exports.BenchmarkSchema.index({ client: 1, metric: 1, format: 1, mode: 1 }, { name: "benchmark_scope" });
61
127
  exports.BenchmarkModel = (0, mongoose_2.model)("Benchmark", exports.BenchmarkSchema);
@@ -72,9 +72,22 @@ export declare const ClientBillingDefaultsSchema: MongooseSchema<ClientBillingDe
72
72
  } & {
73
73
  __v: number;
74
74
  }>;
75
+ /**
76
+ * Empresa tomadora da nota do cliente. Quando a tomadora é do exterior não há
77
+ * CNPJ: `isForeign` liga o cadastro estrangeiro, `document` fica vazio e o
78
+ * identificador fiscal de lá vai em `foreignDocument` (VAT, NIF, EIN).
79
+ * Na Omie o que define cliente do exterior é `estado: "EX"` mais o
80
+ * `codigo_pais`, por isso `countryCode` é obrigatório nesse caso.
81
+ */
75
82
  export declare class Company {
76
83
  legalName: string;
77
84
  document: string;
85
+ /** Tomadora do exterior: sem CNPJ, faturada na Omie com `estado: "EX"`. */
86
+ isForeign?: boolean;
87
+ /** Código do país aceito pela Omie: sigla ISO de 2 letras (ex.: `GB`). */
88
+ countryCode?: string;
89
+ /** Identificador fiscal no exterior (VAT, NIF, EIN), como está no documento. */
90
+ foreignDocument?: string;
78
91
  }
79
92
  export declare const CompanySchema: MongooseSchema<Company, import("mongoose").Model<Company, any, any, any, import("mongoose").Document<unknown, any, Company, any, {}> & Company & {
80
93
  _id: Types.ObjectId;
@@ -125,6 +125,13 @@ exports.ClientBillingDefaults = ClientBillingDefaults = __decorate([
125
125
  (0, mongoose_1.Schema)({ _id: false })
126
126
  ], ClientBillingDefaults);
127
127
  exports.ClientBillingDefaultsSchema = mongoose_1.SchemaFactory.createForClass(ClientBillingDefaults);
128
+ /**
129
+ * Empresa tomadora da nota do cliente. Quando a tomadora é do exterior não há
130
+ * CNPJ: `isForeign` liga o cadastro estrangeiro, `document` fica vazio e o
131
+ * identificador fiscal de lá vai em `foreignDocument` (VAT, NIF, EIN).
132
+ * Na Omie o que define cliente do exterior é `estado: "EX"` mais o
133
+ * `codigo_pais`, por isso `countryCode` é obrigatório nesse caso.
134
+ */
128
135
  let Company = class Company {
129
136
  };
130
137
  exports.Company = Company;
@@ -136,6 +143,18 @@ __decorate([
136
143
  (0, mongoose_1.Prop)(),
137
144
  __metadata("design:type", String)
138
145
  ], Company.prototype, "document", void 0);
146
+ __decorate([
147
+ (0, mongoose_1.Prop)({ type: Boolean, required: false }),
148
+ __metadata("design:type", Boolean)
149
+ ], Company.prototype, "isForeign", void 0);
150
+ __decorate([
151
+ (0, mongoose_1.Prop)({ type: String, required: false }),
152
+ __metadata("design:type", String)
153
+ ], Company.prototype, "countryCode", void 0);
154
+ __decorate([
155
+ (0, mongoose_1.Prop)({ type: String, required: false }),
156
+ __metadata("design:type", String)
157
+ ], Company.prototype, "foreignDocument", void 0);
139
158
  exports.Company = Company = __decorate([
140
159
  (0, mongoose_1.Schema)({ _id: false })
141
160
  ], Company);
@@ -9,6 +9,15 @@ declare class Recipient {
9
9
  declare class Inbox {
10
10
  document?: string;
11
11
  legalName?: string;
12
+ /**
13
+ * Tomadora do exterior (Client.companies[].isForeign): não há CNPJ, então
14
+ * `document` fica vazio e a OS vai para a Omie com `estado: "EX"`. Copiado da
15
+ * empresa escolhida na Caixa de entrada para a fatura não depender de o
16
+ * cadastro do cliente mudar depois.
17
+ */
18
+ isForeign?: boolean;
19
+ countryCode?: string;
20
+ foreignDocument?: string;
12
21
  invoiceDescription?: string;
13
22
  influencerInvoiceDescription?: string;
14
23
  invoiceEmail?: string;
@@ -41,6 +41,21 @@ __decorate([
41
41
  (0, mongoose_1.Prop)(),
42
42
  __metadata("design:type", String)
43
43
  ], Inbox.prototype, "legalName", void 0);
44
+ __decorate([
45
+ (0, swagger_1.ApiProperty)({ example: false, description: "Tomadora do exterior, faturada sem CNPJ" }),
46
+ (0, mongoose_1.Prop)({ type: Boolean, required: false }),
47
+ __metadata("design:type", Boolean)
48
+ ], Inbox.prototype, "isForeign", void 0);
49
+ __decorate([
50
+ (0, swagger_1.ApiProperty)({ example: "GB", description: "Sigla ISO de 2 letras do país da tomadora" }),
51
+ (0, mongoose_1.Prop)({ type: String, required: false }),
52
+ __metadata("design:type", String)
53
+ ], Inbox.prototype, "countryCode", void 0);
54
+ __decorate([
55
+ (0, swagger_1.ApiProperty)({ example: "GB 460 6395 83", description: "Identificador fiscal no exterior" }),
56
+ (0, mongoose_1.Prop)({ type: String, required: false }),
57
+ __metadata("design:type", String)
58
+ ], Inbox.prototype, "foreignDocument", void 0);
44
59
  __decorate([
45
60
  (0, swagger_1.ApiProperty)({
46
61
  example: "Descrição que deve contar na nota fiscal referente à prestação de serviços",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grapadigital/shared-schemas",
3
- "version": "2.12.0",
3
+ "version": "2.14.0",
4
4
  "description": "Shared Mongoose Schemas",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",