@rpcbase/db 0.24.0 → 0.25.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.js CHANGED
@@ -31,6 +31,142 @@ const RBTenantSchema = new Schema({
31
31
  parentTenantId: { type: String },
32
32
  name: { type: String }
33
33
  }, { collection: "tenants" });
34
+ const ZRBTenantSubscriptionStatus = z.enum([
35
+ "trialing",
36
+ "active",
37
+ "past_due",
38
+ "paused",
39
+ "canceled",
40
+ "expired"
41
+ ]);
42
+ const ZRBTenantSubscriptionIntervalUnit = z.enum(["day", "month", "year"]);
43
+ const ZRBTenantSubscriptionType = z.enum(["primary", "addon"]);
44
+ const ZRBTenantSubscriptionScope = z.enum(["tenant", "shop", "custom"]);
45
+ const ZRBTenantSubscription = z.object({
46
+ tenantId: z.string(),
47
+ subscriptionId: z.string(),
48
+ type: ZRBTenantSubscriptionType.optional(),
49
+ parentSubscriptionId: z.string().optional(),
50
+ scope: ZRBTenantSubscriptionScope.optional(),
51
+ scopeId: z.string().optional(),
52
+ planKey: z.string(),
53
+ status: ZRBTenantSubscriptionStatus,
54
+ intervalUnit: ZRBTenantSubscriptionIntervalUnit,
55
+ intervalCount: z.number().int().min(1).optional(),
56
+ modules: z.array(z.string()).optional(),
57
+ currentPeriodStart: z.date().optional(),
58
+ currentPeriodEnd: z.date().optional(),
59
+ trialEndsAt: z.date().optional(),
60
+ cancelAt: z.date().optional(),
61
+ cancelAtPeriodEnd: z.boolean().optional(),
62
+ canceledAt: z.date().optional(),
63
+ provider: z.string().optional(),
64
+ providerCustomerId: z.string().optional(),
65
+ providerSubscriptionId: z.string().optional(),
66
+ latestEventId: z.string().optional(),
67
+ latestEventAt: z.date().optional(),
68
+ metadata: z.record(z.string(), z.unknown()).optional()
69
+ });
70
+ const RBTenantSubscriptionSchema = new Schema(
71
+ {
72
+ tenantId: { type: String, required: true, index: true },
73
+ subscriptionId: { type: String, required: true },
74
+ type: { type: String, required: true, enum: ZRBTenantSubscriptionType.options, default: "primary" },
75
+ parentSubscriptionId: { type: String },
76
+ scope: { type: String, enum: ZRBTenantSubscriptionScope.options, default: "tenant" },
77
+ scopeId: { type: String },
78
+ planKey: { type: String, required: true },
79
+ status: { type: String, required: true, enum: ZRBTenantSubscriptionStatus.options },
80
+ intervalUnit: { type: String, required: true, enum: ZRBTenantSubscriptionIntervalUnit.options },
81
+ intervalCount: { type: Number, min: 1, default: 1 },
82
+ modules: { type: [String], default: [] },
83
+ currentPeriodStart: { type: Date },
84
+ currentPeriodEnd: { type: Date },
85
+ trialEndsAt: { type: Date },
86
+ cancelAt: { type: Date },
87
+ cancelAtPeriodEnd: { type: Boolean, default: false },
88
+ canceledAt: { type: Date },
89
+ provider: { type: String },
90
+ providerCustomerId: { type: String },
91
+ providerSubscriptionId: { type: String },
92
+ latestEventId: { type: String },
93
+ latestEventAt: { type: Date },
94
+ metadata: { type: Schema.Types.Mixed }
95
+ },
96
+ {
97
+ collection: "tenantSubscriptions"
98
+ }
99
+ );
100
+ RBTenantSubscriptionSchema.index({ tenantId: 1, subscriptionId: 1 }, { unique: true });
101
+ RBTenantSubscriptionSchema.index({ tenantId: 1, scope: 1, scopeId: 1 });
102
+ const ZRBTenantSubscriptionEventSource = z.enum([
103
+ "admin",
104
+ "system",
105
+ "webhook",
106
+ "user"
107
+ ]);
108
+ const ZRBTenantSubscriptionChangeDirection = z.enum([
109
+ "upgrade",
110
+ "downgrade",
111
+ "lateral"
112
+ ]);
113
+ const ZRBTenantSubscriptionEvent = z.object({
114
+ tenantId: z.string(),
115
+ subscriptionId: z.string(),
116
+ type: z.string(),
117
+ occurredAt: z.date(),
118
+ effectiveAt: z.date().optional(),
119
+ fromPlanKey: z.string().optional(),
120
+ toPlanKey: z.string().optional(),
121
+ fromStatus: ZRBTenantSubscriptionStatus.optional(),
122
+ toStatus: ZRBTenantSubscriptionStatus.optional(),
123
+ fromModules: z.array(z.string()).optional(),
124
+ toModules: z.array(z.string()).optional(),
125
+ fromIntervalUnit: ZRBTenantSubscriptionIntervalUnit.optional(),
126
+ toIntervalUnit: ZRBTenantSubscriptionIntervalUnit.optional(),
127
+ fromIntervalCount: z.number().int().min(1).optional(),
128
+ toIntervalCount: z.number().int().min(1).optional(),
129
+ direction: ZRBTenantSubscriptionChangeDirection.optional(),
130
+ actorUserId: z.string().optional(),
131
+ source: ZRBTenantSubscriptionEventSource.optional(),
132
+ reason: z.string().optional(),
133
+ provider: z.string().optional(),
134
+ providerEventId: z.string().optional(),
135
+ providerPayload: z.unknown().optional(),
136
+ metadata: z.record(z.string(), z.unknown()).optional()
137
+ });
138
+ const RBTenantSubscriptionEventSchema = new Schema(
139
+ {
140
+ tenantId: { type: String, required: true, index: true },
141
+ subscriptionId: { type: String, required: true, index: true },
142
+ type: { type: String, required: true },
143
+ occurredAt: { type: Date, required: true, default: Date.now },
144
+ effectiveAt: { type: Date },
145
+ fromPlanKey: { type: String },
146
+ toPlanKey: { type: String },
147
+ fromStatus: { type: String, enum: ZRBTenantSubscriptionStatus.options },
148
+ toStatus: { type: String, enum: ZRBTenantSubscriptionStatus.options },
149
+ fromModules: { type: [String], default: void 0 },
150
+ toModules: { type: [String], default: void 0 },
151
+ fromIntervalUnit: { type: String, enum: ZRBTenantSubscriptionIntervalUnit.options },
152
+ toIntervalUnit: { type: String, enum: ZRBTenantSubscriptionIntervalUnit.options },
153
+ fromIntervalCount: { type: Number, min: 1 },
154
+ toIntervalCount: { type: Number, min: 1 },
155
+ direction: { type: String, enum: ZRBTenantSubscriptionChangeDirection.options },
156
+ actorUserId: { type: String },
157
+ source: { type: String, enum: ZRBTenantSubscriptionEventSource.options },
158
+ reason: { type: String },
159
+ provider: { type: String },
160
+ providerEventId: { type: String },
161
+ providerPayload: { type: Schema.Types.Mixed },
162
+ metadata: { type: Schema.Types.Mixed }
163
+ },
164
+ {
165
+ collection: "tenantSubscriptionEvents"
166
+ }
167
+ );
168
+ RBTenantSubscriptionEventSchema.index({ tenantId: 1, subscriptionId: 1, occurredAt: 1 });
169
+ RBTenantSubscriptionEventSchema.index({ provider: 1, providerEventId: 1 }, { unique: true, sparse: true });
34
170
  const ZRBRtsCounter = z.object({
35
171
  _id: z.string(),
36
172
  seq: z.number().int().min(0)
@@ -139,6 +275,8 @@ const frameworkSchemas = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.de
139
275
  RBRtsChangeSchema,
140
276
  RBRtsCounterSchema,
141
277
  RBTenantSchema,
278
+ RBTenantSubscriptionEventSchema,
279
+ RBTenantSubscriptionSchema,
142
280
  RBUploadChunkSchema,
143
281
  RBUploadSessionSchema,
144
282
  RBUserSchema,
@@ -146,6 +284,14 @@ const frameworkSchemas = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.de
146
284
  ZRBRtsChangeOp,
147
285
  ZRBRtsCounter,
148
286
  ZRBTenant,
287
+ ZRBTenantSubscription,
288
+ ZRBTenantSubscriptionChangeDirection,
289
+ ZRBTenantSubscriptionEvent,
290
+ ZRBTenantSubscriptionEventSource,
291
+ ZRBTenantSubscriptionIntervalUnit,
292
+ ZRBTenantSubscriptionScope,
293
+ ZRBTenantSubscriptionStatus,
294
+ ZRBTenantSubscriptionType,
149
295
  ZRBUploadChunk,
150
296
  ZRBUploadSession,
151
297
  ZRBUploadSessionStatus,
@@ -1159,6 +1305,8 @@ export {
1159
1305
  RBRtsChangeSchema,
1160
1306
  RBRtsCounterSchema,
1161
1307
  RBTenantSchema,
1308
+ RBTenantSubscriptionEventSchema,
1309
+ RBTenantSubscriptionSchema,
1162
1310
  RBUploadChunkSchema,
1163
1311
  RBUploadSessionSchema,
1164
1312
  RBUserSchema,
@@ -1166,6 +1314,14 @@ export {
1166
1314
  ZRBRtsChangeOp,
1167
1315
  ZRBRtsCounter,
1168
1316
  ZRBTenant,
1317
+ ZRBTenantSubscription,
1318
+ ZRBTenantSubscriptionChangeDirection,
1319
+ ZRBTenantSubscriptionEvent,
1320
+ ZRBTenantSubscriptionEventSource,
1321
+ ZRBTenantSubscriptionIntervalUnit,
1322
+ ZRBTenantSubscriptionScope,
1323
+ ZRBTenantSubscriptionStatus,
1324
+ ZRBTenantSubscriptionType,
1169
1325
  ZRBUploadChunk,
1170
1326
  ZRBUploadSession,
1171
1327
  ZRBUploadSessionStatus,
@@ -0,0 +1,70 @@
1
+ import { Schema } from '../../../vite/node_modules/mongoose';
2
+ import { z } from '../../../vite/node_modules/zod';
3
+ export declare const ZRBTenantSubscriptionStatus: z.ZodEnum<{
4
+ trialing: "trialing";
5
+ active: "active";
6
+ past_due: "past_due";
7
+ paused: "paused";
8
+ canceled: "canceled";
9
+ expired: "expired";
10
+ }>;
11
+ export declare const ZRBTenantSubscriptionIntervalUnit: z.ZodEnum<{
12
+ day: "day";
13
+ month: "month";
14
+ year: "year";
15
+ }>;
16
+ export declare const ZRBTenantSubscriptionType: z.ZodEnum<{
17
+ primary: "primary";
18
+ addon: "addon";
19
+ }>;
20
+ export declare const ZRBTenantSubscriptionScope: z.ZodEnum<{
21
+ custom: "custom";
22
+ tenant: "tenant";
23
+ shop: "shop";
24
+ }>;
25
+ export declare const ZRBTenantSubscription: z.ZodObject<{
26
+ tenantId: z.ZodString;
27
+ subscriptionId: z.ZodString;
28
+ type: z.ZodOptional<z.ZodEnum<{
29
+ primary: "primary";
30
+ addon: "addon";
31
+ }>>;
32
+ parentSubscriptionId: z.ZodOptional<z.ZodString>;
33
+ scope: z.ZodOptional<z.ZodEnum<{
34
+ custom: "custom";
35
+ tenant: "tenant";
36
+ shop: "shop";
37
+ }>>;
38
+ scopeId: z.ZodOptional<z.ZodString>;
39
+ planKey: z.ZodString;
40
+ status: z.ZodEnum<{
41
+ trialing: "trialing";
42
+ active: "active";
43
+ past_due: "past_due";
44
+ paused: "paused";
45
+ canceled: "canceled";
46
+ expired: "expired";
47
+ }>;
48
+ intervalUnit: z.ZodEnum<{
49
+ day: "day";
50
+ month: "month";
51
+ year: "year";
52
+ }>;
53
+ intervalCount: z.ZodOptional<z.ZodNumber>;
54
+ modules: z.ZodOptional<z.ZodArray<z.ZodString>>;
55
+ currentPeriodStart: z.ZodOptional<z.ZodDate>;
56
+ currentPeriodEnd: z.ZodOptional<z.ZodDate>;
57
+ trialEndsAt: z.ZodOptional<z.ZodDate>;
58
+ cancelAt: z.ZodOptional<z.ZodDate>;
59
+ cancelAtPeriodEnd: z.ZodOptional<z.ZodBoolean>;
60
+ canceledAt: z.ZodOptional<z.ZodDate>;
61
+ provider: z.ZodOptional<z.ZodString>;
62
+ providerCustomerId: z.ZodOptional<z.ZodString>;
63
+ providerSubscriptionId: z.ZodOptional<z.ZodString>;
64
+ latestEventId: z.ZodOptional<z.ZodString>;
65
+ latestEventAt: z.ZodOptional<z.ZodDate>;
66
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
67
+ }, z.core.$strip>;
68
+ export type IRBTenantSubscription = z.infer<typeof ZRBTenantSubscription>;
69
+ export declare const RBTenantSubscriptionSchema: Schema;
70
+ //# sourceMappingURL=RBTenantSubscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RBTenantSubscription.d.ts","sourceRoot":"","sources":["../../src/models/RBTenantSubscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,2BAA2B;;;;;;;EAOtC,CAAA;AAEF,eAAO,MAAM,iCAAiC;;;;EAAmC,CAAA;AAEjF,eAAO,MAAM,yBAAyB;;;EAA+B,CAAA;AAErE,eAAO,MAAM,0BAA0B;;;;EAAuC,CAAA;AAE9E,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwBhC,CAAA;AAEF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAA;AAEzE,eAAO,MAAM,0BAA0B,EAAE,MA6BxC,CAAA"}
@@ -0,0 +1,72 @@
1
+ import { Schema } from '../../../vite/node_modules/mongoose';
2
+ import { z } from '../../../vite/node_modules/zod';
3
+ export declare const ZRBTenantSubscriptionEventSource: z.ZodEnum<{
4
+ admin: "admin";
5
+ system: "system";
6
+ webhook: "webhook";
7
+ user: "user";
8
+ }>;
9
+ export declare const ZRBTenantSubscriptionChangeDirection: z.ZodEnum<{
10
+ upgrade: "upgrade";
11
+ downgrade: "downgrade";
12
+ lateral: "lateral";
13
+ }>;
14
+ export declare const ZRBTenantSubscriptionEvent: z.ZodObject<{
15
+ tenantId: z.ZodString;
16
+ subscriptionId: z.ZodString;
17
+ type: z.ZodString;
18
+ occurredAt: z.ZodDate;
19
+ effectiveAt: z.ZodOptional<z.ZodDate>;
20
+ fromPlanKey: z.ZodOptional<z.ZodString>;
21
+ toPlanKey: z.ZodOptional<z.ZodString>;
22
+ fromStatus: z.ZodOptional<z.ZodEnum<{
23
+ trialing: "trialing";
24
+ active: "active";
25
+ past_due: "past_due";
26
+ paused: "paused";
27
+ canceled: "canceled";
28
+ expired: "expired";
29
+ }>>;
30
+ toStatus: z.ZodOptional<z.ZodEnum<{
31
+ trialing: "trialing";
32
+ active: "active";
33
+ past_due: "past_due";
34
+ paused: "paused";
35
+ canceled: "canceled";
36
+ expired: "expired";
37
+ }>>;
38
+ fromModules: z.ZodOptional<z.ZodArray<z.ZodString>>;
39
+ toModules: z.ZodOptional<z.ZodArray<z.ZodString>>;
40
+ fromIntervalUnit: z.ZodOptional<z.ZodEnum<{
41
+ day: "day";
42
+ month: "month";
43
+ year: "year";
44
+ }>>;
45
+ toIntervalUnit: z.ZodOptional<z.ZodEnum<{
46
+ day: "day";
47
+ month: "month";
48
+ year: "year";
49
+ }>>;
50
+ fromIntervalCount: z.ZodOptional<z.ZodNumber>;
51
+ toIntervalCount: z.ZodOptional<z.ZodNumber>;
52
+ direction: z.ZodOptional<z.ZodEnum<{
53
+ upgrade: "upgrade";
54
+ downgrade: "downgrade";
55
+ lateral: "lateral";
56
+ }>>;
57
+ actorUserId: z.ZodOptional<z.ZodString>;
58
+ source: z.ZodOptional<z.ZodEnum<{
59
+ admin: "admin";
60
+ system: "system";
61
+ webhook: "webhook";
62
+ user: "user";
63
+ }>>;
64
+ reason: z.ZodOptional<z.ZodString>;
65
+ provider: z.ZodOptional<z.ZodString>;
66
+ providerEventId: z.ZodOptional<z.ZodString>;
67
+ providerPayload: z.ZodOptional<z.ZodUnknown>;
68
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
69
+ }, z.core.$strip>;
70
+ export type IRBTenantSubscriptionEvent = z.infer<typeof ZRBTenantSubscriptionEvent>;
71
+ export declare const RBTenantSubscriptionEventSchema: Schema;
72
+ //# sourceMappingURL=RBTenantSubscriptionEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RBTenantSubscriptionEvent.d.ts","sourceRoot":"","sources":["../../src/models/RBTenantSubscriptionEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAQvB,eAAO,MAAM,gCAAgC;;;;;EAK3C,CAAA;AAEF,eAAO,MAAM,oCAAoC;;;;EAI/C,CAAA;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwBrC,CAAA;AAEF,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAEnF,eAAO,MAAM,+BAA+B,EAAE,MA6B7C,CAAA"}
@@ -1,5 +1,7 @@
1
1
  export * from './User';
2
2
  export * from './Tenant';
3
+ export * from './RBTenantSubscription';
4
+ export * from './RBTenantSubscriptionEvent';
3
5
  export * from './RBRtsCounter';
4
6
  export * from './RBRtsChange';
5
7
  export * from './RBUploadSession';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/db",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"