@likewatt/models 1.19.0 → 1.20.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/core/Subscription.d.ts +62 -0
- package/dist/core/Subscription.js +223 -0
- package/dist/core/User.d.ts +1 -0
- package/dist/core/User.js +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Document } from 'mongoose';
|
|
2
|
+
export declare enum SubscriptionStatus {
|
|
3
|
+
ACTIVE = "active",
|
|
4
|
+
PAST_DUE = "past_due",
|
|
5
|
+
CANCELED = "canceled",
|
|
6
|
+
INCOMPLETE = "incomplete",
|
|
7
|
+
TRIALING = "trialing"
|
|
8
|
+
}
|
|
9
|
+
export declare enum SubscriptionPlan {
|
|
10
|
+
ESSENTIAL = "essential",
|
|
11
|
+
STANDARD = "standard",
|
|
12
|
+
PREMIUM = "premium"
|
|
13
|
+
}
|
|
14
|
+
export declare enum BillingCycle {
|
|
15
|
+
MONTHLY = "monthly",
|
|
16
|
+
YEARLY = "yearly"
|
|
17
|
+
}
|
|
18
|
+
export declare class SubscriptionAddons {
|
|
19
|
+
projectsPack: number;
|
|
20
|
+
extraUsers: number;
|
|
21
|
+
accModule: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare const SubscriptionAddonsSchema: import("mongoose").Schema<SubscriptionAddons, import("mongoose").Model<SubscriptionAddons, any, any, any, Document<unknown, any, SubscriptionAddons, any, {}> & SubscriptionAddons & {
|
|
24
|
+
_id: import("mongoose").Types.ObjectId;
|
|
25
|
+
} & {
|
|
26
|
+
__v: number;
|
|
27
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, SubscriptionAddons, Document<unknown, {}, import("mongoose").FlatRecord<SubscriptionAddons>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<SubscriptionAddons> & {
|
|
28
|
+
_id: import("mongoose").Types.ObjectId;
|
|
29
|
+
} & {
|
|
30
|
+
__v: number;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Représente un abonnement Stripe synchronisé localement.
|
|
34
|
+
* - @Schema/timestamps : gère createdAt et updatedAt automatiques
|
|
35
|
+
* - @Prop : schéma Mongoose
|
|
36
|
+
* - @ApiProperty : documentation Swagger
|
|
37
|
+
* - class-validator rules : validation runtime
|
|
38
|
+
*/
|
|
39
|
+
export declare class Subscription {
|
|
40
|
+
_id: string;
|
|
41
|
+
userId: string;
|
|
42
|
+
stripeCustomerId: string;
|
|
43
|
+
stripeSubscriptionId: string;
|
|
44
|
+
status: SubscriptionStatus;
|
|
45
|
+
plan: SubscriptionPlan;
|
|
46
|
+
billingCycle: BillingCycle;
|
|
47
|
+
currentPeriodStart: Date;
|
|
48
|
+
currentPeriodEnd: Date;
|
|
49
|
+
cancelAtPeriodEnd: boolean;
|
|
50
|
+
addons: SubscriptionAddons;
|
|
51
|
+
lastSyncedAt?: Date;
|
|
52
|
+
}
|
|
53
|
+
export type SubscriptionDocument = Subscription & Document;
|
|
54
|
+
export declare const SubscriptionSchema: import("mongoose").Schema<Subscription, import("mongoose").Model<Subscription, any, any, any, Document<unknown, any, Subscription, any, {}> & Subscription & Required<{
|
|
55
|
+
_id: string;
|
|
56
|
+
}> & {
|
|
57
|
+
__v: number;
|
|
58
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Subscription, Document<unknown, {}, import("mongoose").FlatRecord<Subscription>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<Subscription> & Required<{
|
|
59
|
+
_id: string;
|
|
60
|
+
}> & {
|
|
61
|
+
__v: number;
|
|
62
|
+
}>;
|
|
@@ -0,0 +1,223 @@
|
|
|
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.SubscriptionSchema = exports.Subscription = exports.SubscriptionAddonsSchema = exports.SubscriptionAddons = exports.BillingCycle = exports.SubscriptionPlan = exports.SubscriptionStatus = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
const class_validator_1 = require("class-validator");
|
|
17
|
+
// ── Enums ────────────────────────────────────────────────────────────────────
|
|
18
|
+
var SubscriptionStatus;
|
|
19
|
+
(function (SubscriptionStatus) {
|
|
20
|
+
SubscriptionStatus["ACTIVE"] = "active";
|
|
21
|
+
SubscriptionStatus["PAST_DUE"] = "past_due";
|
|
22
|
+
SubscriptionStatus["CANCELED"] = "canceled";
|
|
23
|
+
SubscriptionStatus["INCOMPLETE"] = "incomplete";
|
|
24
|
+
SubscriptionStatus["TRIALING"] = "trialing";
|
|
25
|
+
})(SubscriptionStatus || (exports.SubscriptionStatus = SubscriptionStatus = {}));
|
|
26
|
+
var SubscriptionPlan;
|
|
27
|
+
(function (SubscriptionPlan) {
|
|
28
|
+
SubscriptionPlan["ESSENTIAL"] = "essential";
|
|
29
|
+
SubscriptionPlan["STANDARD"] = "standard";
|
|
30
|
+
SubscriptionPlan["PREMIUM"] = "premium";
|
|
31
|
+
})(SubscriptionPlan || (exports.SubscriptionPlan = SubscriptionPlan = {}));
|
|
32
|
+
var BillingCycle;
|
|
33
|
+
(function (BillingCycle) {
|
|
34
|
+
BillingCycle["MONTHLY"] = "monthly";
|
|
35
|
+
BillingCycle["YEARLY"] = "yearly";
|
|
36
|
+
})(BillingCycle || (exports.BillingCycle = BillingCycle = {}));
|
|
37
|
+
// ── Embedded schema: Addons ──────────────────────────────────────────────────
|
|
38
|
+
let SubscriptionAddons = class SubscriptionAddons {
|
|
39
|
+
};
|
|
40
|
+
exports.SubscriptionAddons = SubscriptionAddons;
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, swagger_1.ApiProperty)({
|
|
43
|
+
description: "Nombre de packs de projets supplémentaires",
|
|
44
|
+
example: 0,
|
|
45
|
+
}),
|
|
46
|
+
(0, mongoose_1.Prop)({ type: Number, default: 0 }),
|
|
47
|
+
(0, class_validator_1.IsOptional)(),
|
|
48
|
+
(0, class_validator_1.IsNumber)(),
|
|
49
|
+
__metadata("design:type", Number)
|
|
50
|
+
], SubscriptionAddons.prototype, "projectsPack", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, swagger_1.ApiProperty)({
|
|
53
|
+
description: "Nombre d'utilisateurs supplémentaires",
|
|
54
|
+
example: 0,
|
|
55
|
+
}),
|
|
56
|
+
(0, mongoose_1.Prop)({ type: Number, default: 0 }),
|
|
57
|
+
(0, class_validator_1.IsOptional)(),
|
|
58
|
+
(0, class_validator_1.IsNumber)(),
|
|
59
|
+
__metadata("design:type", Number)
|
|
60
|
+
], SubscriptionAddons.prototype, "extraUsers", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, swagger_1.ApiProperty)({
|
|
63
|
+
description: 'Module ACC activé',
|
|
64
|
+
example: false,
|
|
65
|
+
}),
|
|
66
|
+
(0, mongoose_1.Prop)({ type: Boolean, default: false }),
|
|
67
|
+
(0, class_validator_1.IsOptional)(),
|
|
68
|
+
(0, class_validator_1.IsBoolean)(),
|
|
69
|
+
__metadata("design:type", Boolean)
|
|
70
|
+
], SubscriptionAddons.prototype, "accModule", void 0);
|
|
71
|
+
exports.SubscriptionAddons = SubscriptionAddons = __decorate([
|
|
72
|
+
(0, mongoose_1.Schema)({ _id: false })
|
|
73
|
+
], SubscriptionAddons);
|
|
74
|
+
exports.SubscriptionAddonsSchema = mongoose_1.SchemaFactory.createForClass(SubscriptionAddons);
|
|
75
|
+
// ── Main schema: Subscription ────────────────────────────────────────────────
|
|
76
|
+
/**
|
|
77
|
+
* Représente un abonnement Stripe synchronisé localement.
|
|
78
|
+
* - @Schema/timestamps : gère createdAt et updatedAt automatiques
|
|
79
|
+
* - @Prop : schéma Mongoose
|
|
80
|
+
* - @ApiProperty : documentation Swagger
|
|
81
|
+
* - class-validator rules : validation runtime
|
|
82
|
+
*/
|
|
83
|
+
let Subscription = class Subscription {
|
|
84
|
+
};
|
|
85
|
+
exports.Subscription = Subscription;
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, swagger_1.ApiProperty)({
|
|
88
|
+
description: 'Identifiant unique (UUID auto-généré)',
|
|
89
|
+
example: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
|
|
90
|
+
type: String,
|
|
91
|
+
readOnly: true,
|
|
92
|
+
}),
|
|
93
|
+
(0, mongoose_1.Prop)({ type: String }),
|
|
94
|
+
__metadata("design:type", String)
|
|
95
|
+
], Subscription.prototype, "_id", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, swagger_1.ApiProperty)({
|
|
98
|
+
description: "Identifiant de l'utilisateur principal",
|
|
99
|
+
example: '2M61PGSm7lRpqXeaDacbAYOLTYG3',
|
|
100
|
+
}),
|
|
101
|
+
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
102
|
+
(0, class_validator_1.IsString)(),
|
|
103
|
+
__metadata("design:type", String)
|
|
104
|
+
], Subscription.prototype, "userId", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, swagger_1.ApiProperty)({
|
|
107
|
+
description: 'Identifiant client Stripe',
|
|
108
|
+
example: 'cus_Abc123Def456',
|
|
109
|
+
}),
|
|
110
|
+
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
111
|
+
(0, class_validator_1.IsString)(),
|
|
112
|
+
__metadata("design:type", String)
|
|
113
|
+
], Subscription.prototype, "stripeCustomerId", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, swagger_1.ApiProperty)({
|
|
116
|
+
description: 'Identifiant abonnement Stripe',
|
|
117
|
+
example: 'sub_Abc123Def456',
|
|
118
|
+
}),
|
|
119
|
+
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
120
|
+
(0, class_validator_1.IsString)(),
|
|
121
|
+
__metadata("design:type", String)
|
|
122
|
+
], Subscription.prototype, "stripeSubscriptionId", void 0);
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, swagger_1.ApiProperty)({
|
|
125
|
+
description: "Statut de l'abonnement",
|
|
126
|
+
enum: SubscriptionStatus,
|
|
127
|
+
example: SubscriptionStatus.ACTIVE,
|
|
128
|
+
}),
|
|
129
|
+
(0, mongoose_1.Prop)({
|
|
130
|
+
type: String,
|
|
131
|
+
enum: SubscriptionStatus,
|
|
132
|
+
default: SubscriptionStatus.INCOMPLETE,
|
|
133
|
+
}),
|
|
134
|
+
(0, class_validator_1.IsEnum)(SubscriptionStatus),
|
|
135
|
+
__metadata("design:type", String)
|
|
136
|
+
], Subscription.prototype, "status", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
(0, swagger_1.ApiProperty)({
|
|
139
|
+
description: "Plan d'abonnement",
|
|
140
|
+
enum: SubscriptionPlan,
|
|
141
|
+
example: SubscriptionPlan.STANDARD,
|
|
142
|
+
}),
|
|
143
|
+
(0, mongoose_1.Prop)({ type: String, enum: SubscriptionPlan, required: true }),
|
|
144
|
+
(0, class_validator_1.IsEnum)(SubscriptionPlan),
|
|
145
|
+
__metadata("design:type", String)
|
|
146
|
+
], Subscription.prototype, "plan", void 0);
|
|
147
|
+
__decorate([
|
|
148
|
+
(0, swagger_1.ApiProperty)({
|
|
149
|
+
description: 'Cycle de facturation',
|
|
150
|
+
enum: BillingCycle,
|
|
151
|
+
example: BillingCycle.MONTHLY,
|
|
152
|
+
}),
|
|
153
|
+
(0, mongoose_1.Prop)({ type: String, enum: BillingCycle, required: true }),
|
|
154
|
+
(0, class_validator_1.IsEnum)(BillingCycle),
|
|
155
|
+
__metadata("design:type", String)
|
|
156
|
+
], Subscription.prototype, "billingCycle", void 0);
|
|
157
|
+
__decorate([
|
|
158
|
+
(0, swagger_1.ApiProperty)({
|
|
159
|
+
description: 'Début de la période courante',
|
|
160
|
+
example: '2024-01-01T00:00:00Z',
|
|
161
|
+
}),
|
|
162
|
+
(0, mongoose_1.Prop)({ type: Date, required: true }),
|
|
163
|
+
(0, class_validator_1.IsDate)(),
|
|
164
|
+
__metadata("design:type", Date)
|
|
165
|
+
], Subscription.prototype, "currentPeriodStart", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
(0, swagger_1.ApiProperty)({
|
|
168
|
+
description: 'Fin de la période courante',
|
|
169
|
+
example: '2024-02-01T00:00:00Z',
|
|
170
|
+
}),
|
|
171
|
+
(0, mongoose_1.Prop)({ type: Date, required: true }),
|
|
172
|
+
(0, class_validator_1.IsDate)(),
|
|
173
|
+
__metadata("design:type", Date)
|
|
174
|
+
], Subscription.prototype, "currentPeriodEnd", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
(0, swagger_1.ApiProperty)({
|
|
177
|
+
description: "Annuler à la fin de la période en cours",
|
|
178
|
+
example: false,
|
|
179
|
+
}),
|
|
180
|
+
(0, mongoose_1.Prop)({ type: Boolean, default: false }),
|
|
181
|
+
(0, class_validator_1.IsBoolean)(),
|
|
182
|
+
__metadata("design:type", Boolean)
|
|
183
|
+
], Subscription.prototype, "cancelAtPeriodEnd", void 0);
|
|
184
|
+
__decorate([
|
|
185
|
+
(0, swagger_1.ApiProperty)({
|
|
186
|
+
description: 'Options / modules complémentaires',
|
|
187
|
+
type: () => SubscriptionAddons,
|
|
188
|
+
}),
|
|
189
|
+
(0, mongoose_1.Prop)({ type: exports.SubscriptionAddonsSchema, _id: false, default: () => ({}) }),
|
|
190
|
+
(0, class_validator_1.IsOptional)(),
|
|
191
|
+
(0, class_validator_1.ValidateNested)(),
|
|
192
|
+
__metadata("design:type", SubscriptionAddons)
|
|
193
|
+
], Subscription.prototype, "addons", void 0);
|
|
194
|
+
__decorate([
|
|
195
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
196
|
+
description: 'Dernière synchronisation avec Stripe',
|
|
197
|
+
example: '2024-01-15T12:00:00Z',
|
|
198
|
+
}),
|
|
199
|
+
(0, mongoose_1.Prop)({ type: Date, required: false }),
|
|
200
|
+
(0, class_validator_1.IsOptional)(),
|
|
201
|
+
(0, class_validator_1.IsDate)(),
|
|
202
|
+
__metadata("design:type", Date)
|
|
203
|
+
], Subscription.prototype, "lastSyncedAt", void 0);
|
|
204
|
+
exports.Subscription = Subscription = __decorate([
|
|
205
|
+
(0, mongoose_1.Schema)({
|
|
206
|
+
id: false,
|
|
207
|
+
timestamps: true,
|
|
208
|
+
toJSON: { virtuals: true, versionKey: false },
|
|
209
|
+
toObject: { virtuals: true, versionKey: false },
|
|
210
|
+
})
|
|
211
|
+
], Subscription);
|
|
212
|
+
exports.SubscriptionSchema = mongoose_1.SchemaFactory.createForClass(Subscription);
|
|
213
|
+
// Hook pre-save pour générer automatiquement un UUID si _id n'est pas fourni
|
|
214
|
+
exports.SubscriptionSchema.pre('save', function (next) {
|
|
215
|
+
if (!this._id) {
|
|
216
|
+
this._id = (0, uuid_1.v4)();
|
|
217
|
+
}
|
|
218
|
+
next();
|
|
219
|
+
});
|
|
220
|
+
// ── Indexes ──────────────────────────────────────────────────────────────────
|
|
221
|
+
exports.SubscriptionSchema.index({ userId: 1 }, { unique: true });
|
|
222
|
+
exports.SubscriptionSchema.index({ stripeCustomerId: 1 });
|
|
223
|
+
exports.SubscriptionSchema.index({ stripeSubscriptionId: 1 }, { unique: true });
|
package/dist/core/User.d.ts
CHANGED
|
@@ -119,6 +119,7 @@ export declare class User {
|
|
|
119
119
|
_lastConnected?: string;
|
|
120
120
|
startDate?: Date;
|
|
121
121
|
endDate?: Date;
|
|
122
|
+
stripeCustomerId?: string;
|
|
122
123
|
}
|
|
123
124
|
export type UserDocument = User & Document;
|
|
124
125
|
export declare const UserSchema: import("mongoose").Schema<User, import("mongoose").Model<User, any, any, any, Document<unknown, any, User, any, {}> & User & Required<{
|
package/dist/core/User.js
CHANGED
|
@@ -640,6 +640,17 @@ __decorate([
|
|
|
640
640
|
(0, class_validator_1.IsDate)(),
|
|
641
641
|
__metadata("design:type", Date)
|
|
642
642
|
], User.prototype, "endDate", void 0);
|
|
643
|
+
__decorate([
|
|
644
|
+
(0, swagger_1.ApiProperty)({
|
|
645
|
+
description: 'Stripe Customer ID',
|
|
646
|
+
example: 'cus_xxx',
|
|
647
|
+
required: false,
|
|
648
|
+
}),
|
|
649
|
+
(0, mongoose_1.Prop)({ type: String, required: false }),
|
|
650
|
+
(0, class_validator_1.IsOptional)(),
|
|
651
|
+
(0, class_validator_1.IsString)(),
|
|
652
|
+
__metadata("design:type", String)
|
|
653
|
+
], User.prototype, "stripeCustomerId", void 0);
|
|
643
654
|
exports.User = User = __decorate([
|
|
644
655
|
(0, mongoose_1.Schema)({
|
|
645
656
|
id: false,
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './core/Site';
|
|
|
4
4
|
export * from './core/Consent';
|
|
5
5
|
export * from './core/User';
|
|
6
6
|
export * from './core/License';
|
|
7
|
+
export * from './core/Subscription';
|
|
7
8
|
export * from './core/ScenarioDefaultValue';
|
|
8
9
|
export * from './core/Invitation';
|
|
9
10
|
export * from './core/DefaultRate';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./core/Site"), exports);
|
|
|
22
22
|
__exportStar(require("./core/Consent"), exports);
|
|
23
23
|
__exportStar(require("./core/User"), exports);
|
|
24
24
|
__exportStar(require("./core/License"), exports);
|
|
25
|
+
__exportStar(require("./core/Subscription"), exports);
|
|
25
26
|
__exportStar(require("./core/ScenarioDefaultValue"), exports);
|
|
26
27
|
__exportStar(require("./core/Invitation"), exports);
|
|
27
28
|
__exportStar(require("./core/DefaultRate"), exports);
|