@amohamud23/notihub 1.0.178 → 1.0.180

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 CHANGED
@@ -173,14 +173,21 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
173
173
  var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
174
174
  var import_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
175
175
  var isOffline = process.env.IS_OFFLINE === "true";
176
- var ddbClient = new import_client_dynamodb.DynamoDBClient({
177
- region: "localhost",
178
- endpoint: "http://0.0.0.0:8000",
179
- credentials: {
180
- accessKeyId: "MockAccessKeyId",
181
- secretAccessKey: "MockSecretAccessKey"
182
- }
183
- });
176
+ var ddbClient;
177
+ if (isOffline) {
178
+ console.log("Running in offline mode");
179
+ ddbClient = new import_client_dynamodb.DynamoDBClient({
180
+ region: "localhost",
181
+ endpoint: "http://0.0.0.0:8000",
182
+ credentials: {
183
+ accessKeyId: "MockAccessKeyId",
184
+ secretAccessKey: "MockSecretAccessKey"
185
+ }
186
+ });
187
+ } else {
188
+ console.log("Running in production mode");
189
+ ddbClient = new import_client_dynamodb.DynamoDBClient();
190
+ }
184
191
  var ddbDocClient = import_lib_dynamodb.DynamoDBDocumentClient.from(ddbClient, {
185
192
  marshallOptions: {
186
193
  removeUndefinedValues: true
@@ -444,25 +451,20 @@ var Notifications = class _Notifications {
444
451
  throw new Error("Could not fetch notification");
445
452
  }
446
453
  }
447
- static async getNotificationsByEntityId(entityId) {
448
- const command = new import_lib_dynamodb4.QueryCommand({
454
+ static async getNotificationsByEntityId(customerId) {
455
+ const command = new import_lib_dynamodb4.GetCommand({
449
456
  TableName: _Notifications.TABLE_NAME,
450
- IndexName: "EntityIdIndex",
451
- // Assuming you have a GSI for entityId
452
- KeyConditionExpression: "entityId = :entityId",
453
- ExpressionAttributeValues: {
454
- ":entityId": entityId
455
- }
457
+ Key: { customerId }
456
458
  });
457
459
  try {
458
460
  const result = await ddbDocClient.send(command);
459
- return result.Items || null;
461
+ return result.Item || null;
460
462
  } catch (error) {
461
463
  console.error(
462
- `Error fetching notifications by entityId: ${entityId}`,
464
+ `Error fetching notifications by customerId: ${customerId}`,
463
465
  error
464
466
  );
465
- throw new Error("Could not fetch notifications by entityId");
467
+ throw new Error("Could not fetch notifications by customerId");
466
468
  }
467
469
  }
468
470
  /**
package/dist/index.d.cts CHANGED
@@ -343,7 +343,7 @@ declare class Notifications {
343
343
  * @returns A promise that resolves to the notification object or null if not found.
344
344
  */
345
345
  static getNotificationById(id: string): Promise<INotiHubNotification | null>;
346
- static getNotificationsByEntityId(entityId: string): Promise<INotiHubNotification[] | null>;
346
+ static getNotificationsByEntityId(customerId: string): Promise<INotiHubNotification | null>;
347
347
  /**
348
348
  * Creates a new notification.
349
349
  * @param notification - The notification object to create.
package/dist/index.d.ts CHANGED
@@ -343,7 +343,7 @@ declare class Notifications {
343
343
  * @returns A promise that resolves to the notification object or null if not found.
344
344
  */
345
345
  static getNotificationById(id: string): Promise<INotiHubNotification | null>;
346
- static getNotificationsByEntityId(entityId: string): Promise<INotiHubNotification[] | null>;
346
+ static getNotificationsByEntityId(customerId: string): Promise<INotiHubNotification | null>;
347
347
  /**
348
348
  * Creates a new notification.
349
349
  * @param notification - The notification object to create.
package/dist/index.js CHANGED
@@ -134,14 +134,21 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
134
134
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
135
135
  import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
136
136
  var isOffline = process.env.IS_OFFLINE === "true";
137
- var ddbClient = new DynamoDBClient({
138
- region: "localhost",
139
- endpoint: "http://0.0.0.0:8000",
140
- credentials: {
141
- accessKeyId: "MockAccessKeyId",
142
- secretAccessKey: "MockSecretAccessKey"
143
- }
144
- });
137
+ var ddbClient;
138
+ if (isOffline) {
139
+ console.log("Running in offline mode");
140
+ ddbClient = new DynamoDBClient({
141
+ region: "localhost",
142
+ endpoint: "http://0.0.0.0:8000",
143
+ credentials: {
144
+ accessKeyId: "MockAccessKeyId",
145
+ secretAccessKey: "MockSecretAccessKey"
146
+ }
147
+ });
148
+ } else {
149
+ console.log("Running in production mode");
150
+ ddbClient = new DynamoDBClient();
151
+ }
145
152
  var ddbDocClient = DynamoDBDocumentClient.from(ddbClient, {
146
153
  marshallOptions: {
147
154
  removeUndefinedValues: true
@@ -388,6 +395,7 @@ var Customer_default = Customer;
388
395
 
389
396
  // src/DynamoModels/Notifications.ts
390
397
  import {
398
+ GetCommand as GetCommand3,
391
399
  PutCommand as PutCommand3,
392
400
  QueryCommand as QueryCommand3
393
401
  } from "@aws-sdk/lib-dynamodb";
@@ -420,25 +428,20 @@ var Notifications = class _Notifications {
420
428
  throw new Error("Could not fetch notification");
421
429
  }
422
430
  }
423
- static async getNotificationsByEntityId(entityId) {
424
- const command = new QueryCommand3({
431
+ static async getNotificationsByEntityId(customerId) {
432
+ const command = new GetCommand3({
425
433
  TableName: _Notifications.TABLE_NAME,
426
- IndexName: "EntityIdIndex",
427
- // Assuming you have a GSI for entityId
428
- KeyConditionExpression: "entityId = :entityId",
429
- ExpressionAttributeValues: {
430
- ":entityId": entityId
431
- }
434
+ Key: { customerId }
432
435
  });
433
436
  try {
434
437
  const result = await ddbDocClient.send(command);
435
- return result.Items || null;
438
+ return result.Item || null;
436
439
  } catch (error) {
437
440
  console.error(
438
- `Error fetching notifications by entityId: ${entityId}`,
441
+ `Error fetching notifications by customerId: ${customerId}`,
439
442
  error
440
443
  );
441
- throw new Error("Could not fetch notifications by entityId");
444
+ throw new Error("Could not fetch notifications by customerId");
442
445
  }
443
446
  }
444
447
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.0.178",
3
+ "version": "1.0.180",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",