@amohamud23/notihub 1.0.149 → 1.0.151
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 +19 -9
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +20 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -527,17 +527,23 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
|
527
527
|
// src/client/DynamoDBClient.ts
|
|
528
528
|
var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
|
|
529
529
|
var import_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
|
|
530
|
-
var
|
|
530
|
+
var isOffline = process.env.IS_OFFLINE === "true";
|
|
531
531
|
var ddbClient = new import_client_dynamodb.DynamoDBClient({
|
|
532
|
-
region:
|
|
533
|
-
|
|
534
|
-
|
|
532
|
+
region: "localhost",
|
|
533
|
+
endpoint: "http://localhost:8000",
|
|
534
|
+
credentials: {
|
|
535
|
+
accessKeyId: "DEFAULT_ACCESS_KEY",
|
|
536
|
+
// needed if you don't have aws credentials at all in env
|
|
537
|
+
secretAccessKey: "DEFAULT_SECRET"
|
|
538
|
+
// needed if you don't have aws credentials at all in env
|
|
539
|
+
}
|
|
535
540
|
});
|
|
536
541
|
var ddbDocClient = import_lib_dynamodb.DynamoDBDocumentClient.from(ddbClient, {
|
|
537
542
|
marshallOptions: {
|
|
538
543
|
removeUndefinedValues: true
|
|
539
544
|
}
|
|
540
545
|
});
|
|
546
|
+
var USER_TABLE_NAME = process.env.USER_TABLE_NAME || "NotiHub-Users-v1-dev";
|
|
541
547
|
|
|
542
548
|
// src/DynamoModels/UserModel.ts
|
|
543
549
|
var import_lib_dynamodb2 = require("@aws-sdk/lib-dynamodb");
|
|
@@ -546,7 +552,7 @@ var User = class _User {
|
|
|
546
552
|
/**
|
|
547
553
|
* The name of the DynamoDB table for users.
|
|
548
554
|
*/
|
|
549
|
-
static TABLE_NAME = `NotiHub-Users-${_User.ENV}`;
|
|
555
|
+
static TABLE_NAME = `NotiHub-Users-v1-${_User.ENV}`;
|
|
550
556
|
/**
|
|
551
557
|
* Retrieves a user by their ID.
|
|
552
558
|
* @param id - The ID of the user to retrieve.
|
|
@@ -571,13 +577,17 @@ var User = class _User {
|
|
|
571
577
|
* @returns A promise that resolves to the user object or null if not found.
|
|
572
578
|
*/
|
|
573
579
|
static async getUserByEmail(email) {
|
|
574
|
-
const command = new import_lib_dynamodb2.
|
|
580
|
+
const command = new import_lib_dynamodb2.QueryCommand({
|
|
575
581
|
TableName: _User.TABLE_NAME,
|
|
576
|
-
|
|
582
|
+
IndexName: "EmailIndex",
|
|
583
|
+
KeyConditionExpression: "email = :email",
|
|
584
|
+
ExpressionAttributeValues: {
|
|
585
|
+
":email": email
|
|
586
|
+
}
|
|
577
587
|
});
|
|
578
588
|
try {
|
|
579
589
|
const result = await ddbDocClient.send(command);
|
|
580
|
-
return result.
|
|
590
|
+
return result.Items || null;
|
|
581
591
|
} catch (error) {
|
|
582
592
|
console.error(`Error fetching user by email: ${email}`, error);
|
|
583
593
|
throw new Error("Could not fetch user by email");
|
|
@@ -617,7 +627,7 @@ var User = class _User {
|
|
|
617
627
|
await ddbDocClient.send(command);
|
|
618
628
|
return user;
|
|
619
629
|
} catch (error) {
|
|
620
|
-
console.error("Error updating user:", error);
|
|
630
|
+
console.error("Error updating user: ", error);
|
|
621
631
|
throw new Error("Could not update user");
|
|
622
632
|
}
|
|
623
633
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -83,7 +83,7 @@ type INotiHubNotificationStats = {
|
|
|
83
83
|
views: number;
|
|
84
84
|
};
|
|
85
85
|
type INotiHubUser = {
|
|
86
|
-
|
|
86
|
+
id: string;
|
|
87
87
|
pushToken: string;
|
|
88
88
|
name: string;
|
|
89
89
|
email: string;
|
|
@@ -205,9 +205,9 @@ declare function getDate(dateStr: string): string;
|
|
|
205
205
|
declare function getDateFormat(dateStr: string): string;
|
|
206
206
|
declare function addMonths({ date, months }: AddMonths): Date;
|
|
207
207
|
|
|
208
|
-
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser &
|
|
209
|
-
_id:
|
|
210
|
-
}
|
|
208
|
+
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser & {
|
|
209
|
+
_id: mongoose.Types.ObjectId;
|
|
210
|
+
} & {
|
|
211
211
|
__v?: number;
|
|
212
212
|
}, any>;
|
|
213
213
|
|
|
@@ -324,7 +324,7 @@ declare class User {
|
|
|
324
324
|
* @param email - The email of the user to retrieve.
|
|
325
325
|
* @returns A promise that resolves to the user object or null if not found.
|
|
326
326
|
*/
|
|
327
|
-
static getUserByEmail(email: string): Promise<INotiHubUser | null>;
|
|
327
|
+
static getUserByEmail(email: string): Promise<INotiHubUser[] | null>;
|
|
328
328
|
/**
|
|
329
329
|
* Creates a new user.
|
|
330
330
|
* @param user - The user object to create.
|
package/dist/index.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ type INotiHubNotificationStats = {
|
|
|
83
83
|
views: number;
|
|
84
84
|
};
|
|
85
85
|
type INotiHubUser = {
|
|
86
|
-
|
|
86
|
+
id: string;
|
|
87
87
|
pushToken: string;
|
|
88
88
|
name: string;
|
|
89
89
|
email: string;
|
|
@@ -205,9 +205,9 @@ declare function getDate(dateStr: string): string;
|
|
|
205
205
|
declare function getDateFormat(dateStr: string): string;
|
|
206
206
|
declare function addMonths({ date, months }: AddMonths): Date;
|
|
207
207
|
|
|
208
|
-
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser &
|
|
209
|
-
_id:
|
|
210
|
-
}
|
|
208
|
+
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser & {
|
|
209
|
+
_id: mongoose.Types.ObjectId;
|
|
210
|
+
} & {
|
|
211
211
|
__v?: number;
|
|
212
212
|
}, any>;
|
|
213
213
|
|
|
@@ -324,7 +324,7 @@ declare class User {
|
|
|
324
324
|
* @param email - The email of the user to retrieve.
|
|
325
325
|
* @returns A promise that resolves to the user object or null if not found.
|
|
326
326
|
*/
|
|
327
|
-
static getUserByEmail(email: string): Promise<INotiHubUser | null>;
|
|
327
|
+
static getUserByEmail(email: string): Promise<INotiHubUser[] | null>;
|
|
328
328
|
/**
|
|
329
329
|
* Creates a new user.
|
|
330
330
|
* @param user - The user object to create.
|
package/dist/index.js
CHANGED
|
@@ -475,23 +475,30 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
|
475
475
|
// src/client/DynamoDBClient.ts
|
|
476
476
|
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
477
477
|
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
478
|
-
var
|
|
478
|
+
var isOffline = process.env.IS_OFFLINE === "true";
|
|
479
479
|
var ddbClient = new DynamoDBClient({
|
|
480
|
-
region:
|
|
481
|
-
|
|
482
|
-
|
|
480
|
+
region: "localhost",
|
|
481
|
+
endpoint: "http://localhost:8000",
|
|
482
|
+
credentials: {
|
|
483
|
+
accessKeyId: "DEFAULT_ACCESS_KEY",
|
|
484
|
+
// needed if you don't have aws credentials at all in env
|
|
485
|
+
secretAccessKey: "DEFAULT_SECRET"
|
|
486
|
+
// needed if you don't have aws credentials at all in env
|
|
487
|
+
}
|
|
483
488
|
});
|
|
484
489
|
var ddbDocClient = DynamoDBDocumentClient.from(ddbClient, {
|
|
485
490
|
marshallOptions: {
|
|
486
491
|
removeUndefinedValues: true
|
|
487
492
|
}
|
|
488
493
|
});
|
|
494
|
+
var USER_TABLE_NAME = process.env.USER_TABLE_NAME || "NotiHub-Users-v1-dev";
|
|
489
495
|
|
|
490
496
|
// src/DynamoModels/UserModel.ts
|
|
491
497
|
import {
|
|
492
498
|
DeleteCommand,
|
|
493
499
|
GetCommand,
|
|
494
500
|
PutCommand,
|
|
501
|
+
QueryCommand,
|
|
495
502
|
UpdateCommand
|
|
496
503
|
} from "@aws-sdk/lib-dynamodb";
|
|
497
504
|
var User = class _User {
|
|
@@ -499,7 +506,7 @@ var User = class _User {
|
|
|
499
506
|
/**
|
|
500
507
|
* The name of the DynamoDB table for users.
|
|
501
508
|
*/
|
|
502
|
-
static TABLE_NAME = `NotiHub-Users-${_User.ENV}`;
|
|
509
|
+
static TABLE_NAME = `NotiHub-Users-v1-${_User.ENV}`;
|
|
503
510
|
/**
|
|
504
511
|
* Retrieves a user by their ID.
|
|
505
512
|
* @param id - The ID of the user to retrieve.
|
|
@@ -524,13 +531,17 @@ var User = class _User {
|
|
|
524
531
|
* @returns A promise that resolves to the user object or null if not found.
|
|
525
532
|
*/
|
|
526
533
|
static async getUserByEmail(email) {
|
|
527
|
-
const command = new
|
|
534
|
+
const command = new QueryCommand({
|
|
528
535
|
TableName: _User.TABLE_NAME,
|
|
529
|
-
|
|
536
|
+
IndexName: "EmailIndex",
|
|
537
|
+
KeyConditionExpression: "email = :email",
|
|
538
|
+
ExpressionAttributeValues: {
|
|
539
|
+
":email": email
|
|
540
|
+
}
|
|
530
541
|
});
|
|
531
542
|
try {
|
|
532
543
|
const result = await ddbDocClient.send(command);
|
|
533
|
-
return result.
|
|
544
|
+
return result.Items || null;
|
|
534
545
|
} catch (error) {
|
|
535
546
|
console.error(`Error fetching user by email: ${email}`, error);
|
|
536
547
|
throw new Error("Could not fetch user by email");
|
|
@@ -570,7 +581,7 @@ var User = class _User {
|
|
|
570
581
|
await ddbDocClient.send(command);
|
|
571
582
|
return user;
|
|
572
583
|
} catch (error) {
|
|
573
|
-
console.error("Error updating user:", error);
|
|
584
|
+
console.error("Error updating user: ", error);
|
|
574
585
|
throw new Error("Could not update user");
|
|
575
586
|
}
|
|
576
587
|
}
|