@amohamud23/notihub 1.0.146 → 1.0.148
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.cjs +234 -16
- package/dist/index.d.cts +88 -19
- package/dist/index.d.ts +88 -19
- package/dist/index.js +243 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -47,6 +47,7 @@ __export(src_exports, {
|
|
|
47
47
|
Subscription: () => SubscriptionModel_default,
|
|
48
48
|
SubscriptionActivity: () => SubscriptionActivity_default,
|
|
49
49
|
SubscriptionType: () => SubscriptionTypeModel_default,
|
|
50
|
+
TABLES: () => TABLES,
|
|
50
51
|
UserModel: () => UserModel_default,
|
|
51
52
|
ViewsModel: () => ViewsModel_default,
|
|
52
53
|
addMonths: () => addMonths,
|
|
@@ -500,24 +501,20 @@ var CustomerMetadataModel_default = CustomerMetadata;
|
|
|
500
501
|
|
|
501
502
|
// src/client/MongooseClient.ts
|
|
502
503
|
var import_mongoose24 = __toESM(require("mongoose"), 1);
|
|
503
|
-
var
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
504
|
+
var conn = null;
|
|
505
|
+
var connectionStr = process.env.DB_CONNECTION_STRING;
|
|
506
|
+
var dbName = process.env.DB_NAME;
|
|
507
|
+
var client = async function() {
|
|
508
|
+
if (conn == null) {
|
|
509
|
+
conn = import_mongoose24.default.createConnection(connectionStr, {
|
|
510
|
+
dbName,
|
|
511
|
+
serverSelectionTimeoutMS: 5e3
|
|
512
|
+
});
|
|
513
|
+
await conn.asPromise();
|
|
513
514
|
}
|
|
514
|
-
return
|
|
515
|
-
console.log("Database Connected!");
|
|
516
|
-
}).catch((err) => {
|
|
517
|
-
console.error(`Error Connecting to the Database: ${err}`);
|
|
518
|
-
});
|
|
515
|
+
return conn;
|
|
519
516
|
};
|
|
520
|
-
var MongooseClient_default =
|
|
517
|
+
var MongooseClient_default = client;
|
|
521
518
|
|
|
522
519
|
// src/exceptions.ts
|
|
523
520
|
var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
@@ -527,6 +524,226 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
|
527
524
|
}
|
|
528
525
|
};
|
|
529
526
|
|
|
527
|
+
// src/client/DynamoDBClient.ts
|
|
528
|
+
var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
|
|
529
|
+
var import_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
|
|
530
|
+
var REGION = process.env.AWS_REGION || "us-west-2";
|
|
531
|
+
var ddbClient = new import_client_dynamodb.DynamoDBClient({
|
|
532
|
+
region: REGION,
|
|
533
|
+
maxAttempts: 3
|
|
534
|
+
// Retry config
|
|
535
|
+
});
|
|
536
|
+
var ddbDocClient = import_lib_dynamodb.DynamoDBDocumentClient.from(ddbClient, {
|
|
537
|
+
marshallOptions: {
|
|
538
|
+
removeUndefinedValues: true
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// src/DynamoModels/UserModel.ts
|
|
543
|
+
var import_lib_dynamodb2 = require("@aws-sdk/lib-dynamodb");
|
|
544
|
+
var User = class _User {
|
|
545
|
+
static TABLE_NAME = "User";
|
|
546
|
+
/**
|
|
547
|
+
* Retrieves a user by their ID.
|
|
548
|
+
* @param id - The ID of the user to retrieve.
|
|
549
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
550
|
+
*/
|
|
551
|
+
static async getUserById(id) {
|
|
552
|
+
const command = new import_lib_dynamodb2.GetCommand({
|
|
553
|
+
TableName: _User.TABLE_NAME,
|
|
554
|
+
Key: { id }
|
|
555
|
+
});
|
|
556
|
+
try {
|
|
557
|
+
const result = await ddbDocClient.send(command);
|
|
558
|
+
return result.Item || null;
|
|
559
|
+
} catch (error) {
|
|
560
|
+
console.error("Error fetching user:", error);
|
|
561
|
+
throw new Error("Could not fetch user");
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Retrieves a user by their email.
|
|
566
|
+
* @param email - The email of the user to retrieve.
|
|
567
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
568
|
+
*/
|
|
569
|
+
static async getUserByEmail(email) {
|
|
570
|
+
const command = new import_lib_dynamodb2.GetCommand({
|
|
571
|
+
TableName: _User.TABLE_NAME,
|
|
572
|
+
Key: { email }
|
|
573
|
+
});
|
|
574
|
+
try {
|
|
575
|
+
const result = await ddbDocClient.send(command);
|
|
576
|
+
return result.Item || null;
|
|
577
|
+
} catch (error) {
|
|
578
|
+
console.error(`Error fetching user by email: ${email}`, error);
|
|
579
|
+
throw new Error("Could not fetch user by email");
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Creates a new user.
|
|
584
|
+
* @param user - The user object to create.
|
|
585
|
+
* @returns A promise that resolves to the created user object.
|
|
586
|
+
*/
|
|
587
|
+
static async createUser(user) {
|
|
588
|
+
const command = new import_lib_dynamodb2.PutCommand({
|
|
589
|
+
TableName: _User.TABLE_NAME,
|
|
590
|
+
Item: user
|
|
591
|
+
});
|
|
592
|
+
try {
|
|
593
|
+
await ddbDocClient.send(command);
|
|
594
|
+
return user;
|
|
595
|
+
} catch (error) {
|
|
596
|
+
console.error("Error creating user:", error);
|
|
597
|
+
throw new Error("Could not create user");
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Updates an existing user.
|
|
602
|
+
* @param user - The user object to update.
|
|
603
|
+
* @returns A promise that resolves to the updated user object.
|
|
604
|
+
*/
|
|
605
|
+
static async updateUser(id, user) {
|
|
606
|
+
const command = new import_lib_dynamodb2.UpdateCommand({
|
|
607
|
+
TableName: _User.TABLE_NAME,
|
|
608
|
+
Key: {
|
|
609
|
+
id
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
try {
|
|
613
|
+
await ddbDocClient.send(command);
|
|
614
|
+
return user;
|
|
615
|
+
} catch (error) {
|
|
616
|
+
console.error("Error updating user:", error);
|
|
617
|
+
throw new Error("Could not update user");
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
static async deleteUser(userId) {
|
|
621
|
+
const command = new import_lib_dynamodb2.DeleteCommand({
|
|
622
|
+
TableName: _User.TABLE_NAME,
|
|
623
|
+
Key: { userId }
|
|
624
|
+
});
|
|
625
|
+
try {
|
|
626
|
+
await ddbDocClient.send(command);
|
|
627
|
+
} catch (error) {
|
|
628
|
+
console.error("Error deleting user:", error);
|
|
629
|
+
throw new Error("Could not delete user");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
var UserModel_default2 = User;
|
|
634
|
+
|
|
635
|
+
// src/DynamoModels/Customer.ts
|
|
636
|
+
var import_lib_dynamodb3 = require("@aws-sdk/lib-dynamodb");
|
|
637
|
+
var Customer2 = class _Customer {
|
|
638
|
+
static TABLE_NAME = "Customer";
|
|
639
|
+
/**
|
|
640
|
+
* Retrieves a customer by their ID.
|
|
641
|
+
* @param id - The ID of the customer to retrieve.
|
|
642
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
643
|
+
*/
|
|
644
|
+
static async getCustomerById(id) {
|
|
645
|
+
const command = new import_lib_dynamodb3.GetCommand({
|
|
646
|
+
TableName: _Customer.TABLE_NAME,
|
|
647
|
+
Key: { id }
|
|
648
|
+
});
|
|
649
|
+
try {
|
|
650
|
+
const result = await ddbDocClient.send(command);
|
|
651
|
+
return result.Item || null;
|
|
652
|
+
} catch (error) {
|
|
653
|
+
console.error("Error fetching customer:", error);
|
|
654
|
+
throw new Error("Could not fetch customer");
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Retrieves a customer by their email.
|
|
659
|
+
* @param email - The email of the customer to retrieve.
|
|
660
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
661
|
+
*/
|
|
662
|
+
static async getCustomerByEmail(email) {
|
|
663
|
+
const command = new import_lib_dynamodb3.GetCommand({
|
|
664
|
+
TableName: _Customer.TABLE_NAME,
|
|
665
|
+
Key: { email }
|
|
666
|
+
});
|
|
667
|
+
try {
|
|
668
|
+
const result = await ddbDocClient.send(command);
|
|
669
|
+
return result.Item || null;
|
|
670
|
+
} catch (error) {
|
|
671
|
+
console.error(`Error fetching customer by email: ${email}`, error);
|
|
672
|
+
throw new Error("Could not fetch customer by email");
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Creates a new customer.
|
|
677
|
+
* @param customer - The customer object to create.
|
|
678
|
+
* @returns A promise that resolves to the created customer object.
|
|
679
|
+
*/
|
|
680
|
+
static async createCustomer(customer) {
|
|
681
|
+
const command = new import_lib_dynamodb3.PutCommand({
|
|
682
|
+
TableName: _Customer.TABLE_NAME,
|
|
683
|
+
Item: customer
|
|
684
|
+
});
|
|
685
|
+
try {
|
|
686
|
+
await ddbDocClient.send(command);
|
|
687
|
+
return customer;
|
|
688
|
+
} catch (error) {
|
|
689
|
+
console.error("Error creating customer:", error);
|
|
690
|
+
throw new Error("Could not create customer");
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Deletes a customer by their ID.
|
|
695
|
+
* @param id - The ID of the customer to delete.
|
|
696
|
+
* @returns A promise that resolves when the customer is deleted.
|
|
697
|
+
*/
|
|
698
|
+
static async deleteCustomer(id) {
|
|
699
|
+
const command = new import_lib_dynamodb3.DeleteCommand({
|
|
700
|
+
TableName: _Customer.TABLE_NAME,
|
|
701
|
+
Key: { id }
|
|
702
|
+
});
|
|
703
|
+
try {
|
|
704
|
+
await ddbDocClient.send(command);
|
|
705
|
+
} catch (error) {
|
|
706
|
+
console.error("Error deleting customer:", error);
|
|
707
|
+
throw new Error("Could not delete customer");
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Updates an existing customer.
|
|
712
|
+
* @param id - The ID of the customer to update.
|
|
713
|
+
* @param customer - The updated customer object.
|
|
714
|
+
* @returns A promise that resolves to the updated customer object.
|
|
715
|
+
*/
|
|
716
|
+
static async updateCustomer(id, updates) {
|
|
717
|
+
const updateExpressions = [];
|
|
718
|
+
const expressionAttributeValues = {};
|
|
719
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
720
|
+
updateExpressions.push(`${key} = :${key}`);
|
|
721
|
+
expressionAttributeValues[`:${key}`] = value;
|
|
722
|
+
}
|
|
723
|
+
const command = new import_lib_dynamodb3.UpdateCommand({
|
|
724
|
+
TableName: _Customer.TABLE_NAME,
|
|
725
|
+
Key: { id },
|
|
726
|
+
UpdateExpression: `SET ${updateExpressions.join(", ")}`,
|
|
727
|
+
ExpressionAttributeValues: expressionAttributeValues,
|
|
728
|
+
ReturnValues: "ALL_NEW"
|
|
729
|
+
});
|
|
730
|
+
try {
|
|
731
|
+
const result = await ddbDocClient.send(command);
|
|
732
|
+
return result.Attributes;
|
|
733
|
+
} catch (error) {
|
|
734
|
+
console.error("Error updating customer:", error);
|
|
735
|
+
throw new Error("Could not update customer");
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
var Customer_default = Customer2;
|
|
740
|
+
|
|
741
|
+
// src/DynamoModels/index.ts
|
|
742
|
+
var TABLES = {
|
|
743
|
+
User: UserModel_default2,
|
|
744
|
+
Customer: Customer_default
|
|
745
|
+
};
|
|
746
|
+
|
|
530
747
|
// src/errorcodes.ts
|
|
531
748
|
var errorcodes_exports = {};
|
|
532
749
|
__export(errorcodes_exports, {
|
|
@@ -564,6 +781,7 @@ var InvalidPushToken = "4009";
|
|
|
564
781
|
Subscription,
|
|
565
782
|
SubscriptionActivity,
|
|
566
783
|
SubscriptionType,
|
|
784
|
+
TABLES,
|
|
567
785
|
UserModel,
|
|
568
786
|
ViewsModel,
|
|
569
787
|
addMonths,
|
package/dist/index.d.cts
CHANGED
|
@@ -208,105 +208,174 @@ declare function addMonths({ date, months }: AddMonths): Date;
|
|
|
208
208
|
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser & Required<{
|
|
209
209
|
_id: string;
|
|
210
210
|
}> & {
|
|
211
|
-
__v?: number
|
|
211
|
+
__v?: number;
|
|
212
212
|
}, any>;
|
|
213
213
|
|
|
214
214
|
declare const Subscription: mongoose__default.Model<INotiHubSubscription, {}, {}, {}, mongoose__default.Document<unknown, {}, INotiHubSubscription> & INotiHubSubscription & Required<{
|
|
215
215
|
_id: string;
|
|
216
216
|
}> & {
|
|
217
|
-
__v?: number
|
|
217
|
+
__v?: number;
|
|
218
218
|
}, any>;
|
|
219
219
|
|
|
220
220
|
declare const NotiTypeModel: mongoose.Model<INotiType, {}, {}, {}, mongoose.Document<unknown, {}, INotiType> & INotiType & Required<{
|
|
221
221
|
_id: string;
|
|
222
222
|
}> & {
|
|
223
|
-
__v?: number
|
|
223
|
+
__v?: number;
|
|
224
224
|
}, any>;
|
|
225
225
|
|
|
226
226
|
declare const NotiHubStatsHistory: mongoose.Model<INotiHubStatsHistory, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubStatsHistory> & INotiHubStatsHistory & {
|
|
227
227
|
_id: mongoose.Types.ObjectId;
|
|
228
228
|
} & {
|
|
229
|
-
__v?: number
|
|
229
|
+
__v?: number;
|
|
230
230
|
}, any>;
|
|
231
231
|
|
|
232
232
|
declare const NotificationStatsModel: mongoose.Model<INotiHubNotificationStats, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubNotificationStats> & INotiHubNotificationStats & Required<{
|
|
233
233
|
_id: string;
|
|
234
234
|
}> & {
|
|
235
|
-
__v?: number
|
|
235
|
+
__v?: number;
|
|
236
236
|
}, any>;
|
|
237
237
|
|
|
238
238
|
declare const NotificationModel: mongoose.Model<INotiHubNotification, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubNotification> & INotiHubNotification & Required<{
|
|
239
239
|
_id: string;
|
|
240
240
|
}> & {
|
|
241
|
-
__v?: number
|
|
241
|
+
__v?: number;
|
|
242
242
|
}, any>;
|
|
243
243
|
|
|
244
|
-
declare const Customer: mongoose.Model<INotiHubCustomer, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomer> & INotiHubCustomer & Required<{
|
|
244
|
+
declare const Customer$1: mongoose.Model<INotiHubCustomer, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomer> & INotiHubCustomer & Required<{
|
|
245
245
|
_id: string;
|
|
246
246
|
}> & {
|
|
247
|
-
__v?: number
|
|
247
|
+
__v?: number;
|
|
248
248
|
}, any>;
|
|
249
249
|
|
|
250
250
|
declare const CustomerMinified: mongoose.Model<INotiHubCustomerMinified, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomerMinified> & INotiHubCustomerMinified & Required<{
|
|
251
251
|
_id: string;
|
|
252
252
|
}> & {
|
|
253
|
-
__v?: number
|
|
253
|
+
__v?: number;
|
|
254
254
|
}, any>;
|
|
255
255
|
|
|
256
256
|
declare const SubscriptionType: mongoose.Model<IUserSubscribeNotifier, {}, {}, {}, mongoose.Document<unknown, {}, IUserSubscribeNotifier> & IUserSubscribeNotifier & {
|
|
257
257
|
_id: mongoose.Types.ObjectId;
|
|
258
258
|
} & {
|
|
259
|
-
__v?: number
|
|
259
|
+
__v?: number;
|
|
260
260
|
}, any>;
|
|
261
261
|
|
|
262
262
|
declare const CustomerNotiHubStats: mongoose.Model<INotiHubStats, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubStats> & INotiHubStats & {
|
|
263
263
|
_id: mongoose.Types.ObjectId;
|
|
264
264
|
} & {
|
|
265
|
-
__v?: number
|
|
265
|
+
__v?: number;
|
|
266
266
|
}, any>;
|
|
267
267
|
|
|
268
268
|
declare const ViewsModel: mongoose.Model<INotiHubUserView, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUserView> & INotiHubUserView & {
|
|
269
269
|
_id: mongoose.Types.ObjectId;
|
|
270
270
|
} & {
|
|
271
|
-
__v?: number
|
|
271
|
+
__v?: number;
|
|
272
272
|
}, any>;
|
|
273
273
|
|
|
274
274
|
declare const NotiTypeStatsModel: mongoose.Model<INotiTypeStats, {}, {}, {}, mongoose.Document<unknown, {}, INotiTypeStats> & INotiTypeStats & Required<{
|
|
275
275
|
_id: string;
|
|
276
276
|
}> & {
|
|
277
|
-
__v?: number
|
|
277
|
+
__v?: number;
|
|
278
278
|
}, any>;
|
|
279
279
|
|
|
280
280
|
declare const StripScriptionModel: mongoose.Model<INotiHubStripeSubscription, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubStripeSubscription> & INotiHubStripeSubscription & {
|
|
281
281
|
_id: mongoose.Types.ObjectId;
|
|
282
282
|
} & {
|
|
283
|
-
__v?: number
|
|
283
|
+
__v?: number;
|
|
284
284
|
}, any>;
|
|
285
285
|
|
|
286
286
|
declare const PaymentSessionModel: mongoose.Model<INotiHubPaymentSession, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubPaymentSession> & INotiHubPaymentSession & {
|
|
287
287
|
_id: mongoose.Types.ObjectId;
|
|
288
288
|
} & {
|
|
289
|
-
__v?: number
|
|
289
|
+
__v?: number;
|
|
290
290
|
}, any>;
|
|
291
291
|
|
|
292
292
|
declare const SubscriptionActivity: mongoose.Model<INotiHubSubscriptionActivity, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubSubscriptionActivity> & INotiHubSubscriptionActivity & Required<{
|
|
293
293
|
_id: string;
|
|
294
294
|
}> & {
|
|
295
|
-
__v?: number
|
|
295
|
+
__v?: number;
|
|
296
296
|
}, any>;
|
|
297
297
|
|
|
298
298
|
declare const CustomerMetadata: mongoose.Model<INotiHubCustomerMetadata, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomerMetadata> & INotiHubCustomerMetadata & Required<{
|
|
299
299
|
_id: string;
|
|
300
300
|
}> & {
|
|
301
|
-
__v?: number
|
|
301
|
+
__v?: number;
|
|
302
302
|
}, any>;
|
|
303
303
|
|
|
304
|
-
declare const
|
|
304
|
+
declare const client: () => Promise<mongoose__default.Connection>;
|
|
305
305
|
|
|
306
306
|
declare class DocumentNotFoundException extends Error {
|
|
307
307
|
constructor(msg: string);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
declare class User {
|
|
311
|
+
static TABLE_NAME: string;
|
|
312
|
+
/**
|
|
313
|
+
* Retrieves a user by their ID.
|
|
314
|
+
* @param id - The ID of the user to retrieve.
|
|
315
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
316
|
+
*/
|
|
317
|
+
static getUserById(id: string): Promise<INotiHubUser | null>;
|
|
318
|
+
/**
|
|
319
|
+
* Retrieves a user by their email.
|
|
320
|
+
* @param email - The email of the user to retrieve.
|
|
321
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
322
|
+
*/
|
|
323
|
+
static getUserByEmail(email: string): Promise<INotiHubUser | null>;
|
|
324
|
+
/**
|
|
325
|
+
* Creates a new user.
|
|
326
|
+
* @param user - The user object to create.
|
|
327
|
+
* @returns A promise that resolves to the created user object.
|
|
328
|
+
*/
|
|
329
|
+
static createUser(user: INotiHubUser): Promise<INotiHubUser>;
|
|
330
|
+
/**
|
|
331
|
+
* Updates an existing user.
|
|
332
|
+
* @param user - The user object to update.
|
|
333
|
+
* @returns A promise that resolves to the updated user object.
|
|
334
|
+
*/
|
|
335
|
+
static updateUser(id: string, user: INotiHubUser): Promise<INotiHubUser>;
|
|
336
|
+
static deleteUser(userId: string): Promise<void>;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class Customer {
|
|
340
|
+
static TABLE_NAME: string;
|
|
341
|
+
/**
|
|
342
|
+
* Retrieves a customer by their ID.
|
|
343
|
+
* @param id - The ID of the customer to retrieve.
|
|
344
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
345
|
+
*/
|
|
346
|
+
static getCustomerById(id: string): Promise<INotiHubCustomer | null>;
|
|
347
|
+
/**
|
|
348
|
+
* Retrieves a customer by their email.
|
|
349
|
+
* @param email - The email of the customer to retrieve.
|
|
350
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
351
|
+
*/
|
|
352
|
+
static getCustomerByEmail(email: string): Promise<INotiHubCustomer | null>;
|
|
353
|
+
/**
|
|
354
|
+
* Creates a new customer.
|
|
355
|
+
* @param customer - The customer object to create.
|
|
356
|
+
* @returns A promise that resolves to the created customer object.
|
|
357
|
+
*/
|
|
358
|
+
static createCustomer(customer: INotiHubCustomer): Promise<INotiHubCustomer>;
|
|
359
|
+
/**
|
|
360
|
+
* Deletes a customer by their ID.
|
|
361
|
+
* @param id - The ID of the customer to delete.
|
|
362
|
+
* @returns A promise that resolves when the customer is deleted.
|
|
363
|
+
*/
|
|
364
|
+
static deleteCustomer(id: string): Promise<void>;
|
|
365
|
+
/**
|
|
366
|
+
* Updates an existing customer.
|
|
367
|
+
* @param id - The ID of the customer to update.
|
|
368
|
+
* @param customer - The updated customer object.
|
|
369
|
+
* @returns A promise that resolves to the updated customer object.
|
|
370
|
+
*/
|
|
371
|
+
static updateCustomer(id: string, updates: Partial<INotiHubCustomer>): Promise<INotiHubCustomer>;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
declare const TABLES: {
|
|
375
|
+
User: typeof User;
|
|
376
|
+
Customer: typeof Customer;
|
|
377
|
+
};
|
|
378
|
+
|
|
310
379
|
declare const DocumentNotFound = "4001";
|
|
311
380
|
declare const UserNotFound = "4002";
|
|
312
381
|
declare const CustomerNotFound = "4003";
|
|
@@ -326,4 +395,4 @@ declare namespace errorcodes {
|
|
|
326
395
|
export { errorcodes_CustomerNotFound as CustomerNotFound, errorcodes_DocumentNotFound as DocumentNotFound, errorcodes_InvalidEmail as InvalidEmail, errorcodes_InvalidName as InvalidName, errorcodes_InvalidPassword as InvalidPassword, errorcodes_InvalidPushToken as InvalidPushToken, errorcodes_UserNotFound as UserNotFound };
|
|
327
396
|
}
|
|
328
397
|
|
|
329
|
-
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription,
|
|
398
|
+
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer$1 as Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription, client as MongooseClient, NotiHubStatsHistory, type NotiHubTypes, NotiTypeModel, NotiTypeStatsModel, NotificationModel, NotificationStatsModel as NotificationStats, PaymentSessionModel, StripScriptionModel, Subscription, SubscriptionActivity, SubscriptionType, TABLES, UserModel, ViewsModel, addMonths, getDate, getDateFormat };
|
package/dist/index.d.ts
CHANGED
|
@@ -208,105 +208,174 @@ declare function addMonths({ date, months }: AddMonths): Date;
|
|
|
208
208
|
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser & Required<{
|
|
209
209
|
_id: string;
|
|
210
210
|
}> & {
|
|
211
|
-
__v?: number
|
|
211
|
+
__v?: number;
|
|
212
212
|
}, any>;
|
|
213
213
|
|
|
214
214
|
declare const Subscription: mongoose__default.Model<INotiHubSubscription, {}, {}, {}, mongoose__default.Document<unknown, {}, INotiHubSubscription> & INotiHubSubscription & Required<{
|
|
215
215
|
_id: string;
|
|
216
216
|
}> & {
|
|
217
|
-
__v?: number
|
|
217
|
+
__v?: number;
|
|
218
218
|
}, any>;
|
|
219
219
|
|
|
220
220
|
declare const NotiTypeModel: mongoose.Model<INotiType, {}, {}, {}, mongoose.Document<unknown, {}, INotiType> & INotiType & Required<{
|
|
221
221
|
_id: string;
|
|
222
222
|
}> & {
|
|
223
|
-
__v?: number
|
|
223
|
+
__v?: number;
|
|
224
224
|
}, any>;
|
|
225
225
|
|
|
226
226
|
declare const NotiHubStatsHistory: mongoose.Model<INotiHubStatsHistory, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubStatsHistory> & INotiHubStatsHistory & {
|
|
227
227
|
_id: mongoose.Types.ObjectId;
|
|
228
228
|
} & {
|
|
229
|
-
__v?: number
|
|
229
|
+
__v?: number;
|
|
230
230
|
}, any>;
|
|
231
231
|
|
|
232
232
|
declare const NotificationStatsModel: mongoose.Model<INotiHubNotificationStats, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubNotificationStats> & INotiHubNotificationStats & Required<{
|
|
233
233
|
_id: string;
|
|
234
234
|
}> & {
|
|
235
|
-
__v?: number
|
|
235
|
+
__v?: number;
|
|
236
236
|
}, any>;
|
|
237
237
|
|
|
238
238
|
declare const NotificationModel: mongoose.Model<INotiHubNotification, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubNotification> & INotiHubNotification & Required<{
|
|
239
239
|
_id: string;
|
|
240
240
|
}> & {
|
|
241
|
-
__v?: number
|
|
241
|
+
__v?: number;
|
|
242
242
|
}, any>;
|
|
243
243
|
|
|
244
|
-
declare const Customer: mongoose.Model<INotiHubCustomer, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomer> & INotiHubCustomer & Required<{
|
|
244
|
+
declare const Customer$1: mongoose.Model<INotiHubCustomer, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomer> & INotiHubCustomer & Required<{
|
|
245
245
|
_id: string;
|
|
246
246
|
}> & {
|
|
247
|
-
__v?: number
|
|
247
|
+
__v?: number;
|
|
248
248
|
}, any>;
|
|
249
249
|
|
|
250
250
|
declare const CustomerMinified: mongoose.Model<INotiHubCustomerMinified, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomerMinified> & INotiHubCustomerMinified & Required<{
|
|
251
251
|
_id: string;
|
|
252
252
|
}> & {
|
|
253
|
-
__v?: number
|
|
253
|
+
__v?: number;
|
|
254
254
|
}, any>;
|
|
255
255
|
|
|
256
256
|
declare const SubscriptionType: mongoose.Model<IUserSubscribeNotifier, {}, {}, {}, mongoose.Document<unknown, {}, IUserSubscribeNotifier> & IUserSubscribeNotifier & {
|
|
257
257
|
_id: mongoose.Types.ObjectId;
|
|
258
258
|
} & {
|
|
259
|
-
__v?: number
|
|
259
|
+
__v?: number;
|
|
260
260
|
}, any>;
|
|
261
261
|
|
|
262
262
|
declare const CustomerNotiHubStats: mongoose.Model<INotiHubStats, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubStats> & INotiHubStats & {
|
|
263
263
|
_id: mongoose.Types.ObjectId;
|
|
264
264
|
} & {
|
|
265
|
-
__v?: number
|
|
265
|
+
__v?: number;
|
|
266
266
|
}, any>;
|
|
267
267
|
|
|
268
268
|
declare const ViewsModel: mongoose.Model<INotiHubUserView, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUserView> & INotiHubUserView & {
|
|
269
269
|
_id: mongoose.Types.ObjectId;
|
|
270
270
|
} & {
|
|
271
|
-
__v?: number
|
|
271
|
+
__v?: number;
|
|
272
272
|
}, any>;
|
|
273
273
|
|
|
274
274
|
declare const NotiTypeStatsModel: mongoose.Model<INotiTypeStats, {}, {}, {}, mongoose.Document<unknown, {}, INotiTypeStats> & INotiTypeStats & Required<{
|
|
275
275
|
_id: string;
|
|
276
276
|
}> & {
|
|
277
|
-
__v?: number
|
|
277
|
+
__v?: number;
|
|
278
278
|
}, any>;
|
|
279
279
|
|
|
280
280
|
declare const StripScriptionModel: mongoose.Model<INotiHubStripeSubscription, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubStripeSubscription> & INotiHubStripeSubscription & {
|
|
281
281
|
_id: mongoose.Types.ObjectId;
|
|
282
282
|
} & {
|
|
283
|
-
__v?: number
|
|
283
|
+
__v?: number;
|
|
284
284
|
}, any>;
|
|
285
285
|
|
|
286
286
|
declare const PaymentSessionModel: mongoose.Model<INotiHubPaymentSession, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubPaymentSession> & INotiHubPaymentSession & {
|
|
287
287
|
_id: mongoose.Types.ObjectId;
|
|
288
288
|
} & {
|
|
289
|
-
__v?: number
|
|
289
|
+
__v?: number;
|
|
290
290
|
}, any>;
|
|
291
291
|
|
|
292
292
|
declare const SubscriptionActivity: mongoose.Model<INotiHubSubscriptionActivity, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubSubscriptionActivity> & INotiHubSubscriptionActivity & Required<{
|
|
293
293
|
_id: string;
|
|
294
294
|
}> & {
|
|
295
|
-
__v?: number
|
|
295
|
+
__v?: number;
|
|
296
296
|
}, any>;
|
|
297
297
|
|
|
298
298
|
declare const CustomerMetadata: mongoose.Model<INotiHubCustomerMetadata, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubCustomerMetadata> & INotiHubCustomerMetadata & Required<{
|
|
299
299
|
_id: string;
|
|
300
300
|
}> & {
|
|
301
|
-
__v?: number
|
|
301
|
+
__v?: number;
|
|
302
302
|
}, any>;
|
|
303
303
|
|
|
304
|
-
declare const
|
|
304
|
+
declare const client: () => Promise<mongoose__default.Connection>;
|
|
305
305
|
|
|
306
306
|
declare class DocumentNotFoundException extends Error {
|
|
307
307
|
constructor(msg: string);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
declare class User {
|
|
311
|
+
static TABLE_NAME: string;
|
|
312
|
+
/**
|
|
313
|
+
* Retrieves a user by their ID.
|
|
314
|
+
* @param id - The ID of the user to retrieve.
|
|
315
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
316
|
+
*/
|
|
317
|
+
static getUserById(id: string): Promise<INotiHubUser | null>;
|
|
318
|
+
/**
|
|
319
|
+
* Retrieves a user by their email.
|
|
320
|
+
* @param email - The email of the user to retrieve.
|
|
321
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
322
|
+
*/
|
|
323
|
+
static getUserByEmail(email: string): Promise<INotiHubUser | null>;
|
|
324
|
+
/**
|
|
325
|
+
* Creates a new user.
|
|
326
|
+
* @param user - The user object to create.
|
|
327
|
+
* @returns A promise that resolves to the created user object.
|
|
328
|
+
*/
|
|
329
|
+
static createUser(user: INotiHubUser): Promise<INotiHubUser>;
|
|
330
|
+
/**
|
|
331
|
+
* Updates an existing user.
|
|
332
|
+
* @param user - The user object to update.
|
|
333
|
+
* @returns A promise that resolves to the updated user object.
|
|
334
|
+
*/
|
|
335
|
+
static updateUser(id: string, user: INotiHubUser): Promise<INotiHubUser>;
|
|
336
|
+
static deleteUser(userId: string): Promise<void>;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class Customer {
|
|
340
|
+
static TABLE_NAME: string;
|
|
341
|
+
/**
|
|
342
|
+
* Retrieves a customer by their ID.
|
|
343
|
+
* @param id - The ID of the customer to retrieve.
|
|
344
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
345
|
+
*/
|
|
346
|
+
static getCustomerById(id: string): Promise<INotiHubCustomer | null>;
|
|
347
|
+
/**
|
|
348
|
+
* Retrieves a customer by their email.
|
|
349
|
+
* @param email - The email of the customer to retrieve.
|
|
350
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
351
|
+
*/
|
|
352
|
+
static getCustomerByEmail(email: string): Promise<INotiHubCustomer | null>;
|
|
353
|
+
/**
|
|
354
|
+
* Creates a new customer.
|
|
355
|
+
* @param customer - The customer object to create.
|
|
356
|
+
* @returns A promise that resolves to the created customer object.
|
|
357
|
+
*/
|
|
358
|
+
static createCustomer(customer: INotiHubCustomer): Promise<INotiHubCustomer>;
|
|
359
|
+
/**
|
|
360
|
+
* Deletes a customer by their ID.
|
|
361
|
+
* @param id - The ID of the customer to delete.
|
|
362
|
+
* @returns A promise that resolves when the customer is deleted.
|
|
363
|
+
*/
|
|
364
|
+
static deleteCustomer(id: string): Promise<void>;
|
|
365
|
+
/**
|
|
366
|
+
* Updates an existing customer.
|
|
367
|
+
* @param id - The ID of the customer to update.
|
|
368
|
+
* @param customer - The updated customer object.
|
|
369
|
+
* @returns A promise that resolves to the updated customer object.
|
|
370
|
+
*/
|
|
371
|
+
static updateCustomer(id: string, updates: Partial<INotiHubCustomer>): Promise<INotiHubCustomer>;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
declare const TABLES: {
|
|
375
|
+
User: typeof User;
|
|
376
|
+
Customer: typeof Customer;
|
|
377
|
+
};
|
|
378
|
+
|
|
310
379
|
declare const DocumentNotFound = "4001";
|
|
311
380
|
declare const UserNotFound = "4002";
|
|
312
381
|
declare const CustomerNotFound = "4003";
|
|
@@ -326,4 +395,4 @@ declare namespace errorcodes {
|
|
|
326
395
|
export { errorcodes_CustomerNotFound as CustomerNotFound, errorcodes_DocumentNotFound as DocumentNotFound, errorcodes_InvalidEmail as InvalidEmail, errorcodes_InvalidName as InvalidName, errorcodes_InvalidPassword as InvalidPassword, errorcodes_InvalidPushToken as InvalidPushToken, errorcodes_UserNotFound as UserNotFound };
|
|
327
396
|
}
|
|
328
397
|
|
|
329
|
-
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription,
|
|
398
|
+
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer$1 as Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription, client as MongooseClient, NotiHubStatsHistory, type NotiHubTypes, NotiTypeModel, NotiTypeStatsModel, NotificationModel, NotificationStatsModel as NotificationStats, PaymentSessionModel, StripScriptionModel, Subscription, SubscriptionActivity, SubscriptionType, TABLES, UserModel, ViewsModel, addMonths, getDate, getDateFormat };
|
package/dist/index.js
CHANGED
|
@@ -449,24 +449,20 @@ var CustomerMetadataModel_default = CustomerMetadata;
|
|
|
449
449
|
|
|
450
450
|
// src/client/MongooseClient.ts
|
|
451
451
|
import mongoose3 from "mongoose";
|
|
452
|
-
var
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
452
|
+
var conn = null;
|
|
453
|
+
var connectionStr = process.env.DB_CONNECTION_STRING;
|
|
454
|
+
var dbName = process.env.DB_NAME;
|
|
455
|
+
var client = async function() {
|
|
456
|
+
if (conn == null) {
|
|
457
|
+
conn = mongoose3.createConnection(connectionStr, {
|
|
458
|
+
dbName,
|
|
459
|
+
serverSelectionTimeoutMS: 5e3
|
|
460
|
+
});
|
|
461
|
+
await conn.asPromise();
|
|
462
462
|
}
|
|
463
|
-
return
|
|
464
|
-
console.log("Database Connected!");
|
|
465
|
-
}).catch((err) => {
|
|
466
|
-
console.error(`Error Connecting to the Database: ${err}`);
|
|
467
|
-
});
|
|
463
|
+
return conn;
|
|
468
464
|
};
|
|
469
|
-
var MongooseClient_default =
|
|
465
|
+
var MongooseClient_default = client;
|
|
470
466
|
|
|
471
467
|
// src/exceptions.ts
|
|
472
468
|
var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
@@ -476,6 +472,236 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
|
476
472
|
}
|
|
477
473
|
};
|
|
478
474
|
|
|
475
|
+
// src/client/DynamoDBClient.ts
|
|
476
|
+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
477
|
+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
478
|
+
var REGION = process.env.AWS_REGION || "us-west-2";
|
|
479
|
+
var ddbClient = new DynamoDBClient({
|
|
480
|
+
region: REGION,
|
|
481
|
+
maxAttempts: 3
|
|
482
|
+
// Retry config
|
|
483
|
+
});
|
|
484
|
+
var ddbDocClient = DynamoDBDocumentClient.from(ddbClient, {
|
|
485
|
+
marshallOptions: {
|
|
486
|
+
removeUndefinedValues: true
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// src/DynamoModels/UserModel.ts
|
|
491
|
+
import {
|
|
492
|
+
DeleteCommand,
|
|
493
|
+
GetCommand,
|
|
494
|
+
PutCommand,
|
|
495
|
+
UpdateCommand
|
|
496
|
+
} from "@aws-sdk/lib-dynamodb";
|
|
497
|
+
var User = class _User {
|
|
498
|
+
static TABLE_NAME = "User";
|
|
499
|
+
/**
|
|
500
|
+
* Retrieves a user by their ID.
|
|
501
|
+
* @param id - The ID of the user to retrieve.
|
|
502
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
503
|
+
*/
|
|
504
|
+
static async getUserById(id) {
|
|
505
|
+
const command = new GetCommand({
|
|
506
|
+
TableName: _User.TABLE_NAME,
|
|
507
|
+
Key: { id }
|
|
508
|
+
});
|
|
509
|
+
try {
|
|
510
|
+
const result = await ddbDocClient.send(command);
|
|
511
|
+
return result.Item || null;
|
|
512
|
+
} catch (error) {
|
|
513
|
+
console.error("Error fetching user:", error);
|
|
514
|
+
throw new Error("Could not fetch user");
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Retrieves a user by their email.
|
|
519
|
+
* @param email - The email of the user to retrieve.
|
|
520
|
+
* @returns A promise that resolves to the user object or null if not found.
|
|
521
|
+
*/
|
|
522
|
+
static async getUserByEmail(email) {
|
|
523
|
+
const command = new GetCommand({
|
|
524
|
+
TableName: _User.TABLE_NAME,
|
|
525
|
+
Key: { email }
|
|
526
|
+
});
|
|
527
|
+
try {
|
|
528
|
+
const result = await ddbDocClient.send(command);
|
|
529
|
+
return result.Item || null;
|
|
530
|
+
} catch (error) {
|
|
531
|
+
console.error(`Error fetching user by email: ${email}`, error);
|
|
532
|
+
throw new Error("Could not fetch user by email");
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Creates a new user.
|
|
537
|
+
* @param user - The user object to create.
|
|
538
|
+
* @returns A promise that resolves to the created user object.
|
|
539
|
+
*/
|
|
540
|
+
static async createUser(user) {
|
|
541
|
+
const command = new PutCommand({
|
|
542
|
+
TableName: _User.TABLE_NAME,
|
|
543
|
+
Item: user
|
|
544
|
+
});
|
|
545
|
+
try {
|
|
546
|
+
await ddbDocClient.send(command);
|
|
547
|
+
return user;
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.error("Error creating user:", error);
|
|
550
|
+
throw new Error("Could not create user");
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Updates an existing user.
|
|
555
|
+
* @param user - The user object to update.
|
|
556
|
+
* @returns A promise that resolves to the updated user object.
|
|
557
|
+
*/
|
|
558
|
+
static async updateUser(id, user) {
|
|
559
|
+
const command = new UpdateCommand({
|
|
560
|
+
TableName: _User.TABLE_NAME,
|
|
561
|
+
Key: {
|
|
562
|
+
id
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
try {
|
|
566
|
+
await ddbDocClient.send(command);
|
|
567
|
+
return user;
|
|
568
|
+
} catch (error) {
|
|
569
|
+
console.error("Error updating user:", error);
|
|
570
|
+
throw new Error("Could not update user");
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
static async deleteUser(userId) {
|
|
574
|
+
const command = new DeleteCommand({
|
|
575
|
+
TableName: _User.TABLE_NAME,
|
|
576
|
+
Key: { userId }
|
|
577
|
+
});
|
|
578
|
+
try {
|
|
579
|
+
await ddbDocClient.send(command);
|
|
580
|
+
} catch (error) {
|
|
581
|
+
console.error("Error deleting user:", error);
|
|
582
|
+
throw new Error("Could not delete user");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
var UserModel_default2 = User;
|
|
587
|
+
|
|
588
|
+
// src/DynamoModels/Customer.ts
|
|
589
|
+
import {
|
|
590
|
+
DeleteCommand as DeleteCommand2,
|
|
591
|
+
GetCommand as GetCommand2,
|
|
592
|
+
PutCommand as PutCommand2,
|
|
593
|
+
UpdateCommand as UpdateCommand2
|
|
594
|
+
} from "@aws-sdk/lib-dynamodb";
|
|
595
|
+
var Customer2 = class _Customer {
|
|
596
|
+
static TABLE_NAME = "Customer";
|
|
597
|
+
/**
|
|
598
|
+
* Retrieves a customer by their ID.
|
|
599
|
+
* @param id - The ID of the customer to retrieve.
|
|
600
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
601
|
+
*/
|
|
602
|
+
static async getCustomerById(id) {
|
|
603
|
+
const command = new GetCommand2({
|
|
604
|
+
TableName: _Customer.TABLE_NAME,
|
|
605
|
+
Key: { id }
|
|
606
|
+
});
|
|
607
|
+
try {
|
|
608
|
+
const result = await ddbDocClient.send(command);
|
|
609
|
+
return result.Item || null;
|
|
610
|
+
} catch (error) {
|
|
611
|
+
console.error("Error fetching customer:", error);
|
|
612
|
+
throw new Error("Could not fetch customer");
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Retrieves a customer by their email.
|
|
617
|
+
* @param email - The email of the customer to retrieve.
|
|
618
|
+
* @returns A promise that resolves to the customer object or null if not found.
|
|
619
|
+
*/
|
|
620
|
+
static async getCustomerByEmail(email) {
|
|
621
|
+
const command = new GetCommand2({
|
|
622
|
+
TableName: _Customer.TABLE_NAME,
|
|
623
|
+
Key: { email }
|
|
624
|
+
});
|
|
625
|
+
try {
|
|
626
|
+
const result = await ddbDocClient.send(command);
|
|
627
|
+
return result.Item || null;
|
|
628
|
+
} catch (error) {
|
|
629
|
+
console.error(`Error fetching customer by email: ${email}`, error);
|
|
630
|
+
throw new Error("Could not fetch customer by email");
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Creates a new customer.
|
|
635
|
+
* @param customer - The customer object to create.
|
|
636
|
+
* @returns A promise that resolves to the created customer object.
|
|
637
|
+
*/
|
|
638
|
+
static async createCustomer(customer) {
|
|
639
|
+
const command = new PutCommand2({
|
|
640
|
+
TableName: _Customer.TABLE_NAME,
|
|
641
|
+
Item: customer
|
|
642
|
+
});
|
|
643
|
+
try {
|
|
644
|
+
await ddbDocClient.send(command);
|
|
645
|
+
return customer;
|
|
646
|
+
} catch (error) {
|
|
647
|
+
console.error("Error creating customer:", error);
|
|
648
|
+
throw new Error("Could not create customer");
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Deletes a customer by their ID.
|
|
653
|
+
* @param id - The ID of the customer to delete.
|
|
654
|
+
* @returns A promise that resolves when the customer is deleted.
|
|
655
|
+
*/
|
|
656
|
+
static async deleteCustomer(id) {
|
|
657
|
+
const command = new DeleteCommand2({
|
|
658
|
+
TableName: _Customer.TABLE_NAME,
|
|
659
|
+
Key: { id }
|
|
660
|
+
});
|
|
661
|
+
try {
|
|
662
|
+
await ddbDocClient.send(command);
|
|
663
|
+
} catch (error) {
|
|
664
|
+
console.error("Error deleting customer:", error);
|
|
665
|
+
throw new Error("Could not delete customer");
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Updates an existing customer.
|
|
670
|
+
* @param id - The ID of the customer to update.
|
|
671
|
+
* @param customer - The updated customer object.
|
|
672
|
+
* @returns A promise that resolves to the updated customer object.
|
|
673
|
+
*/
|
|
674
|
+
static async updateCustomer(id, updates) {
|
|
675
|
+
const updateExpressions = [];
|
|
676
|
+
const expressionAttributeValues = {};
|
|
677
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
678
|
+
updateExpressions.push(`${key} = :${key}`);
|
|
679
|
+
expressionAttributeValues[`:${key}`] = value;
|
|
680
|
+
}
|
|
681
|
+
const command = new UpdateCommand2({
|
|
682
|
+
TableName: _Customer.TABLE_NAME,
|
|
683
|
+
Key: { id },
|
|
684
|
+
UpdateExpression: `SET ${updateExpressions.join(", ")}`,
|
|
685
|
+
ExpressionAttributeValues: expressionAttributeValues,
|
|
686
|
+
ReturnValues: "ALL_NEW"
|
|
687
|
+
});
|
|
688
|
+
try {
|
|
689
|
+
const result = await ddbDocClient.send(command);
|
|
690
|
+
return result.Attributes;
|
|
691
|
+
} catch (error) {
|
|
692
|
+
console.error("Error updating customer:", error);
|
|
693
|
+
throw new Error("Could not update customer");
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var Customer_default = Customer2;
|
|
698
|
+
|
|
699
|
+
// src/DynamoModels/index.ts
|
|
700
|
+
var TABLES = {
|
|
701
|
+
User: UserModel_default2,
|
|
702
|
+
Customer: Customer_default
|
|
703
|
+
};
|
|
704
|
+
|
|
479
705
|
// src/errorcodes.ts
|
|
480
706
|
var errorcodes_exports = {};
|
|
481
707
|
__export(errorcodes_exports, {
|
|
@@ -512,6 +738,7 @@ export {
|
|
|
512
738
|
SubscriptionModel_default as Subscription,
|
|
513
739
|
SubscriptionActivity_default as SubscriptionActivity,
|
|
514
740
|
SubscriptionTypeModel_default as SubscriptionType,
|
|
741
|
+
TABLES,
|
|
515
742
|
UserModel_default as UserModel,
|
|
516
743
|
ViewsModel_default as ViewsModel,
|
|
517
744
|
addMonths,
|