@timardex/cluemart-shared 1.2.34 → 1.2.35
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/{ad-CiYcsJB7.d.mts → ad-CWAaH5Ql.d.mts} +1 -1
- package/dist/{ad-BZylIpez.d.ts → ad-D60cy5L4.d.ts} +1 -1
- package/dist/{auth-DDtMJHZw.d.mts → auth-BslKse3L.d.mts} +1 -1
- package/dist/{auth-CmaB99NK.d.ts → auth-Ch9Nt77g.d.ts} +1 -1
- package/dist/{chunk-NPHPFWQH.mjs → chunk-WWL2Q5DN.mjs} +3 -22
- package/dist/chunk-WWL2Q5DN.mjs.map +1 -0
- package/dist/formFields/index.d.mts +1 -1
- package/dist/formFields/index.d.ts +1 -1
- package/dist/{global-DVYSZ6LR.d.ts → global-DvxKMAQD.d.ts} +1 -1
- package/dist/{global-ExJZRDGR.d.mts → global-j9FEfVZs.d.mts} +1 -1
- package/dist/graphql/index.d.mts +2 -2
- package/dist/graphql/index.d.ts +2 -2
- package/dist/hooks/index.d.mts +3 -3
- package/dist/hooks/index.d.ts +3 -3
- package/dist/index.cjs +0 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.mjs +0 -110
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.d.mts +3 -3
- package/dist/mongoose/index.d.ts +3 -3
- package/dist/mongoose/index.mjs +76 -60
- package/dist/mongoose/index.mjs.map +1 -1
- package/dist/service/index.cjs +6 -142
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +2 -4
- package/dist/service/index.d.ts +2 -4
- package/dist/service/index.mjs +3 -114
- package/dist/service/index.mjs.map +1 -1
- package/dist/types/index.d.mts +3 -3
- package/dist/types/index.d.ts +3 -3
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/package.json +1 -2
- package/dist/chunk-NPHPFWQH.mjs.map +0 -1
package/dist/service/index.cjs
CHANGED
|
@@ -31,8 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var service_exports = {};
|
|
32
32
|
__export(service_exports, {
|
|
33
33
|
connectToDatabase: () => connectToDatabase,
|
|
34
|
-
saveNotificationsInDb: () => saveNotificationsInDb
|
|
35
|
-
sendPushNotifications: () => sendPushNotifications
|
|
34
|
+
saveNotificationsInDb: () => saveNotificationsInDb
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(service_exports);
|
|
38
37
|
|
|
@@ -45,8 +44,8 @@ var import_timezone = __toESM(require("dayjs/plugin/timezone"));
|
|
|
45
44
|
var import_utc = __toESM(require("dayjs/plugin/utc"));
|
|
46
45
|
import_dayjs.default.extend(import_utc.default);
|
|
47
46
|
import_dayjs.default.extend(import_timezone.default);
|
|
48
|
-
function timezonePlugin(
|
|
49
|
-
if (!
|
|
47
|
+
function timezonePlugin(schema2) {
|
|
48
|
+
if (!schema2.get("timestamps")) return;
|
|
50
49
|
const transform = (_doc, ret) => {
|
|
51
50
|
if (ret.createdAt)
|
|
52
51
|
ret.createdAt = (0, import_dayjs.default)(ret.createdAt).tz("Pacific/Auckland").format();
|
|
@@ -54,8 +53,8 @@ function timezonePlugin(schema3) {
|
|
|
54
53
|
ret.updatedAt = (0, import_dayjs.default)(ret.updatedAt).tz("Pacific/Auckland").format();
|
|
55
54
|
return ret;
|
|
56
55
|
};
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
schema2.set("toJSON", { transform });
|
|
57
|
+
schema2.set("toObject", { transform });
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
// src/service/database.ts
|
|
@@ -87,12 +86,6 @@ var connectToDatabase = async ({
|
|
|
87
86
|
var import_mongoose2 = __toESM(require("mongoose"));
|
|
88
87
|
|
|
89
88
|
// src/enums/index.ts
|
|
90
|
-
var EnumOSPlatform = /* @__PURE__ */ ((EnumOSPlatform2) => {
|
|
91
|
-
EnumOSPlatform2["ANDROID"] = "android";
|
|
92
|
-
EnumOSPlatform2["IOS"] = "ios";
|
|
93
|
-
EnumOSPlatform2["WEB"] = "web";
|
|
94
|
-
return EnumOSPlatform2;
|
|
95
|
-
})(EnumOSPlatform || {});
|
|
96
89
|
var EnumNotificationResourceType = /* @__PURE__ */ ((EnumNotificationResourceType2) => {
|
|
97
90
|
EnumNotificationResourceType2["ADDED_AS_PARTNER_EVENT"] = "added_as_partner_event";
|
|
98
91
|
EnumNotificationResourceType2["ADDED_AS_PARTNER_VENDOR"] = "added_as_partner_vendor";
|
|
@@ -171,138 +164,9 @@ async function saveNotificationsInDb(payload) {
|
|
|
171
164
|
return [];
|
|
172
165
|
}
|
|
173
166
|
}
|
|
174
|
-
|
|
175
|
-
// src/service/sendPushNotifications.ts
|
|
176
|
-
var import_expo_server_sdk = require("expo-server-sdk");
|
|
177
|
-
|
|
178
|
-
// src/mongoose/PushToken.ts
|
|
179
|
-
var import_mongoose3 = __toESM(require("mongoose"));
|
|
180
|
-
var MongooseSchema2 = import_mongoose3.default.Schema;
|
|
181
|
-
var schema2 = new MongooseSchema2(
|
|
182
|
-
{
|
|
183
|
-
platform: {
|
|
184
|
-
enum: Object.values(EnumOSPlatform),
|
|
185
|
-
required: true,
|
|
186
|
-
type: String
|
|
187
|
-
},
|
|
188
|
-
token: { required: true, type: String },
|
|
189
|
-
userId: { required: true, type: import_mongoose3.default.Schema.Types.ObjectId }
|
|
190
|
-
},
|
|
191
|
-
{ timestamps: true }
|
|
192
|
-
);
|
|
193
|
-
var PushTokenModel = import_mongoose3.default.models.PushToken || import_mongoose3.default.model("PushToken", schema2);
|
|
194
|
-
|
|
195
|
-
// src/service/sendPushNotifications.ts
|
|
196
|
-
var expo = new import_expo_server_sdk.Expo();
|
|
197
|
-
function extractTokensFromMessage(message) {
|
|
198
|
-
return Array.isArray(message.to) ? message.to : [message.to];
|
|
199
|
-
}
|
|
200
|
-
function createPushMessages({
|
|
201
|
-
tokens,
|
|
202
|
-
message,
|
|
203
|
-
title,
|
|
204
|
-
data
|
|
205
|
-
}) {
|
|
206
|
-
const messages = [];
|
|
207
|
-
const invalidTokens = [];
|
|
208
|
-
for (const token of tokens) {
|
|
209
|
-
if (!import_expo_server_sdk.Expo.isExpoPushToken(token)) {
|
|
210
|
-
invalidTokens.push(token);
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
messages.push({
|
|
214
|
-
body: message,
|
|
215
|
-
data: { ...data },
|
|
216
|
-
sound: "default",
|
|
217
|
-
title,
|
|
218
|
-
to: token
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
return { invalidTokens, messages };
|
|
222
|
-
}
|
|
223
|
-
function processChunkResults(tickets, chunk) {
|
|
224
|
-
let successCount = 0;
|
|
225
|
-
const failedTokens = [];
|
|
226
|
-
for (const [ticketIndex, ticket] of tickets.entries()) {
|
|
227
|
-
if (ticket.status === "error") {
|
|
228
|
-
const message = chunk[ticketIndex];
|
|
229
|
-
if (message) {
|
|
230
|
-
const tokens = extractTokensFromMessage(message);
|
|
231
|
-
if (ticket.details?.error === "DeviceNotRegistered") {
|
|
232
|
-
failedTokens.push(...tokens);
|
|
233
|
-
}
|
|
234
|
-
console.log("Push notification error", {
|
|
235
|
-
error: ticket.details?.error,
|
|
236
|
-
tokens
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
successCount++;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return { failedTokens, successCount };
|
|
244
|
-
}
|
|
245
|
-
async function sendChunk(chunk, chunkIndex) {
|
|
246
|
-
try {
|
|
247
|
-
const tickets = await expo.sendPushNotificationsAsync(chunk);
|
|
248
|
-
const { successCount, failedTokens } = processChunkResults(tickets, chunk);
|
|
249
|
-
console.log(
|
|
250
|
-
`Chunk ${chunkIndex + 1}: Sent ${successCount}/${chunk.length} notifications successfully`
|
|
251
|
-
);
|
|
252
|
-
return { failedTokens, successCount };
|
|
253
|
-
} catch (error) {
|
|
254
|
-
console.log("Error sending Expo push notification chunk", {
|
|
255
|
-
chunkIndex,
|
|
256
|
-
chunkSize: chunk.length,
|
|
257
|
-
error: error instanceof Error ? error.message : String(error)
|
|
258
|
-
});
|
|
259
|
-
return { failedTokens: [], successCount: 0 };
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
async function sendPushNotifications({
|
|
263
|
-
data,
|
|
264
|
-
message,
|
|
265
|
-
title,
|
|
266
|
-
userIds
|
|
267
|
-
}) {
|
|
268
|
-
const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
|
|
269
|
-
const expoTokens = pushTokens.map((token) => token.token);
|
|
270
|
-
if (!data) return;
|
|
271
|
-
const { messages, invalidTokens } = createPushMessages({
|
|
272
|
-
data,
|
|
273
|
-
message,
|
|
274
|
-
title,
|
|
275
|
-
tokens: expoTokens
|
|
276
|
-
});
|
|
277
|
-
if (invalidTokens.length > 0) {
|
|
278
|
-
console.log(`Found ${invalidTokens.length} invalid push tokens`);
|
|
279
|
-
}
|
|
280
|
-
if (messages.length === 0) {
|
|
281
|
-
console.log("No valid messages to send after filtering tokens");
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
const chunks = expo.chunkPushNotifications(messages);
|
|
285
|
-
let totalSuccessCount = 0;
|
|
286
|
-
const allFailedTokens = [];
|
|
287
|
-
for (const [chunkIndex, chunk] of chunks.entries()) {
|
|
288
|
-
const { successCount, failedTokens } = await sendChunk(
|
|
289
|
-
chunk,
|
|
290
|
-
chunkIndex + 1
|
|
291
|
-
);
|
|
292
|
-
totalSuccessCount += successCount;
|
|
293
|
-
allFailedTokens.push(...failedTokens);
|
|
294
|
-
}
|
|
295
|
-
console.log(
|
|
296
|
-
`Sent push notification to ${totalSuccessCount}/${messages.length} tokens across ${chunks.length} chunks`
|
|
297
|
-
);
|
|
298
|
-
if (allFailedTokens.length > 0) {
|
|
299
|
-
console.log(`Found ${allFailedTokens.length} failed push tokens`);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
303
168
|
0 && (module.exports = {
|
|
304
169
|
connectToDatabase,
|
|
305
|
-
saveNotificationsInDb
|
|
306
|
-
sendPushNotifications
|
|
170
|
+
saveNotificationsInDb
|
|
307
171
|
});
|
|
308
172
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/service/index.ts","../../src/service/database.ts","../../src/service/timezonePlugin.ts","../../src/mongoose/Notification.ts","../../src/enums/index.ts","../../src/service/saveNotificationsInDb.ts","../../src/service/sendPushNotifications.ts","../../src/mongoose/PushToken.ts"],"sourcesContent":["export * from \"./database\";\nexport * from \"./saveNotificationsInDb\";\nexport * from \"./sendPushNotifications\";\n","import mongoose from \"mongoose\";\n\nimport { timezonePlugin } from \"./timezonePlugin\";\n\nmongoose.plugin(timezonePlugin); // applies to all schemas\n\n/**\n * Connect to MongoDB using Mongoose.\n * Supports both local MongoDB (via MONGODB_URI) and MongoDB Atlas (via individual env vars).\n */\nexport const connectToDatabase = async ({\n appName,\n dbName,\n dbPassword,\n dbUser,\n mongodbUri,\n}: {\n appName: string;\n dbName: string;\n dbPassword: string;\n dbUser: string;\n mongodbUri: string;\n}) => {\n try {\n // Check if MONGODB_URI is provided (for local Docker MongoDB)\n const mongoUri = mongodbUri\n ? mongodbUri\n : // Fallback to MongoDB Atlas connection string\n `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`;\n\n await mongoose.connect(mongoUri);\n\n const connectionType = mongodbUri ? \"Local MongoDB\" : \"MongoDB Atlas\";\n console.log(\n `${connectionType} connected from server/src/service/database.ts`,\n );\n } catch (err) {\n console.error(\"Error connecting to MongoDB:\", err);\n throw err; // You can throw the error if you want to stop the server in case of connection failure\n }\n};\n","import dayjs from \"dayjs\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\nimport { Schema } from \"mongoose\";\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\n\nexport function timezonePlugin(schema: Schema) {\n if (!schema.get(\"timestamps\")) return;\n\n const transform = (_doc: any, ret: any) => {\n if (ret.createdAt)\n ret.createdAt = dayjs(ret.createdAt).tz(\"Pacific/Auckland\").format(); // ISO with +13:00 or +12:00 offset\n if (ret.updatedAt)\n ret.updatedAt = dayjs(ret.updatedAt).tz(\"Pacific/Auckland\").format();\n return ret;\n };\n\n schema.set(\"toJSON\", { transform });\n schema.set(\"toObject\", { transform });\n}\n","import mongoose from \"mongoose\";\n\nimport { EnumNotificationResourceType, EnumNotificationType } from \"src/enums\";\nimport {\n CreateBulkNotificationInput,\n NotificationType,\n ObjectId,\n} from \"src/types\";\n\nconst MongooseSchema = mongoose.Schema;\n\nexport type SchemaCreateBulkNotificationInput = Omit<\n CreateBulkNotificationInput,\n \"userIds\"\n> & {\n userIds: ObjectId[];\n};\n\nexport type SchemaNotificationType = Omit<NotificationType, \"userId\"> & {\n userId: ObjectId;\n};\n/**\n * Schema for storing in-app notifications\n * Each notification is tied to a specific user and can be marked as read/unread\n */\nconst schema = new MongooseSchema<SchemaNotificationType>(\n {\n data: {\n resourceId: { required: true, type: String },\n resourceName: { required: true, type: String },\n resourceType: {\n enum: Object.values(EnumNotificationResourceType),\n required: true,\n type: String,\n },\n },\n isRead: { default: false, index: true, required: true, type: Boolean },\n message: { required: true, type: String },\n title: { required: true, type: String },\n type: {\n default: EnumNotificationType.SYSTEM,\n enum: Object.values(EnumNotificationType),\n required: true,\n type: String,\n },\n userId: {\n ref: \"User\",\n required: true,\n type: mongoose.Schema.Types.ObjectId,\n },\n },\n { timestamps: true },\n);\n\n// Compound index for efficient queries\nschema.index({ isRead: 1, userId: 1 });\nschema.index({ createdAt: -1, userId: 1 });\n\nexport const NotificationModel =\n (mongoose.models.Notification as mongoose.Model<SchemaNotificationType>) ||\n mongoose.model<SchemaNotificationType>(\"Notification\", schema);\n","export enum EnumInviteStatus {\n ACCEPTED = \"Accepted\",\n COMPLETED = \"Completed\",\n EXPIRED = \"Expired\",\n NO_STATUS = \"No_Status\",\n PAID = \"Paid\",\n PENDING = \"Pending\",\n REJECTED = \"Rejected\",\n UNAVAILABLE = \"Unavailable\",\n WAITING = \"Waiting\",\n}\n\nexport enum EnumChatType {\n GROUP = \"group\",\n PRIVATE = \"private\",\n RELATION = \"relation\",\n}\n\nexport enum EnumPaymentMethod {\n CASH = \"cash\",\n EFTPOS = \"eftpos\",\n BANK_TRANSFER = \"bank_transfer\",\n PAYPAL = \"paypal\",\n STRIPE = \"stripe\",\n}\n\nexport enum EnumFoodFlavor {\n SALTY = \"Salty\",\n SAVOURY = \"Savoury\",\n SPICY = \"Spicy\",\n SWEET = \"Sweet\",\n}\n\nexport enum EnumResourceType {\n EVENT = \"event\",\n VENDOR = \"vendor\",\n}\n\nexport enum EnumEventType {\n EXPO = \"Expo\",\n FAIR = \"Fair\",\n FESTIVAL = \"Festival\",\n MARKET = \"Market\",\n}\n\nexport enum EnumVendorType {\n STALLHOLDER = \"Stallholder\",\n SHOP = \"Shop\",\n CHARITY = \"Charity\",\n}\n\nexport enum EnumOSPlatform {\n ANDROID = \"android\",\n IOS = \"ios\",\n WEB = \"web\",\n}\n\nexport enum EnumRelationResource {\n EVENT_INVITE_VENDOR = \"event_invite_vendor\",\n VENDOR_APPLICATION_TO_EVENT = \"vendor_application_to_event\",\n}\n\nexport enum EnumNotificationResourceType {\n ADDED_AS_PARTNER_EVENT = \"added_as_partner_event\",\n ADDED_AS_PARTNER_VENDOR = \"added_as_partner_vendor\",\n APPROVED_EVENT = \"approved_event\",\n APPROVED_VENDOR = \"approved_vendor\",\n CREATED_EVENT = \"created_event\",\n CREATED_VENDOR = \"created_vendor\",\n EVENT_INVITE_VENDOR = EnumRelationResource.EVENT_INVITE_VENDOR,\n EVENT_STARTING_SOON = \"event_starting_soon\",\n NEW_CHAT_MESSAGE = \"new_chat_message\",\n VENDOR_APPLICATION_TO_EVENT = EnumRelationResource.VENDOR_APPLICATION_TO_EVENT,\n}\n\nexport enum EnumNotificationType {\n EVENT = EnumResourceType.EVENT,\n VENDOR = EnumResourceType.VENDOR,\n RELATION = \"relation\",\n CHAT = \"chat\",\n SYSTEM = \"system\",\n}\n\nexport enum EnumRegions {\n Auckland = \"Auckland\",\n BayOfPlentyGisborne = \"Bay of Plenty & Gisborne\",\n Canterbury = \"Canterbury\",\n HawkesBay = \"Hawke's Bay\",\n ManawatuWanganui = \"Manawatu-Wanganui\",\n MarlboroughNelson = \"Marlborough & Nelson\",\n Northland = \"Northland\",\n SouthlandOtago = \"Southland & Otago\",\n Taranaki = \"Taranaki\",\n Waikato = \"Waikato\",\n Wellington = \"Wellington\",\n TasmanWestCoast = \"Tasman & West Coast\",\n}\n\nexport enum ImageTypeEnum {\n AVATAR = \"avatar\",\n COVER = \"cover\",\n IMAGE = \"image\",\n LOGO = \"logo\",\n}\n\nexport enum EnumUserLicence {\n PRO_EVENT = \"pro_event\",\n PRO_PLUS_EVENT = \"pro_plus_event\",\n PRO_PLUS_VENDOR = \"pro_plus_vendor\",\n PRO_VENDOR = \"pro_vendor\",\n STANDARD_EVENT = \"standard_event\",\n STANDARD_VENDOR = \"standard_vendor\",\n}\n\nexport enum EnumUserRole {\n ADMIN = \"admin\",\n CUSTOMER = \"customer\",\n MARKETING = \"marketing\",\n MODERATOR = \"moderator\",\n SUPPORT = \"support\",\n}\n\nexport enum EnumSocialMedia {\n FACEBOOK = \"facebook\",\n INSTAGRAM = \"instagram\",\n TIKTOK = \"tiktok\",\n TWITTER = \"twitter\",\n WEBSITE = \"website\",\n YOUTUBE = \"youtube\",\n}\n","import {\n SchemaCreateBulkNotificationInput,\n NotificationModel,\n} from \"src/mongoose/Notification\";\nimport { ObjectId } from \"src/types\";\n\n/**\n * Create notifications in the database for multiple users\n * This is typically called when sending push notifications\n */\nexport async function saveNotificationsInDb(\n payload: SchemaCreateBulkNotificationInput,\n): Promise<ObjectId[]> {\n const { data, message, title, type, userIds } = payload;\n try {\n const notifications = userIds.map((userId) => ({\n data,\n isRead: false,\n message,\n title,\n type,\n userId,\n }));\n\n // Save notifications to database\n await NotificationModel.insertMany(notifications);\n console.log(\n `Created ${notifications.length} notifications for ${userIds.length} users`,\n );\n\n return [...new Set(userIds)];\n } catch (error) {\n console.error(\"Failed to create notifications:\", error);\n return [];\n //throw new Error(`Failed to create notifications: ${error}`);\n }\n}\n","import { Expo, ExpoPushMessage, ExpoPushTicket } from \"expo-server-sdk\";\n\nimport { SchemaCreateBulkNotificationInput } from \"src/mongoose/Notification\";\nimport { PushTokenModel } from \"src/mongoose/PushToken\";\nimport { NotificationDataType, ObjectId } from \"src/types\";\n\nconst expo = new Expo();\n\n/**\n * Safely extract tokens from ExpoPushMessage handling both string and array cases\n */\nfunction extractTokensFromMessage(message: ExpoPushMessage): string[] {\n return Array.isArray(message.to) ? message.to : [message.to];\n}\n\ninterface CreatePushMessagesOptions {\n tokens: string[];\n message: string;\n title: string;\n data: NotificationDataType;\n}\n\n/**\n * Create push messages from valid tokens\n */\nfunction createPushMessages({\n tokens,\n message,\n title,\n data,\n}: CreatePushMessagesOptions): {\n messages: ExpoPushMessage[];\n invalidTokens: string[];\n} {\n const messages: ExpoPushMessage[] = [];\n const invalidTokens: string[] = [];\n\n for (const token of tokens) {\n if (!Expo.isExpoPushToken(token)) {\n invalidTokens.push(token);\n continue;\n }\n\n messages.push({\n body: message,\n data: { ...data },\n sound: \"default\",\n title,\n to: token,\n });\n }\n\n return { invalidTokens, messages };\n}\n\n/**\n * Process chunk results and extract failed tokens\n */\nfunction processChunkResults(\n tickets: ExpoPushTicket[],\n chunk: ExpoPushMessage[],\n): { successCount: number; failedTokens: string[] } {\n let successCount = 0;\n const failedTokens: string[] = [];\n\n for (const [ticketIndex, ticket] of tickets.entries()) {\n if (ticket.status === \"error\") {\n const message = chunk[ticketIndex];\n if (message) {\n const tokens = extractTokensFromMessage(message);\n if (ticket.details?.error === \"DeviceNotRegistered\") {\n failedTokens.push(...tokens);\n }\n console.log(\"Push notification error\", {\n error: ticket.details?.error,\n tokens,\n });\n }\n } else {\n successCount++;\n }\n }\n\n return { failedTokens, successCount };\n}\n\n/**\n * Send a single chunk of push notifications\n */\nasync function sendChunk(\n chunk: ExpoPushMessage[],\n chunkIndex: number,\n): Promise<{ successCount: number; failedTokens: string[] }> {\n try {\n const tickets = await expo.sendPushNotificationsAsync(chunk);\n const { successCount, failedTokens } = processChunkResults(tickets, chunk);\n\n console.log(\n `Chunk ${chunkIndex + 1}: Sent ${successCount}/${chunk.length} notifications successfully`,\n );\n\n return { failedTokens, successCount };\n } catch (error) {\n console.log(\"Error sending Expo push notification chunk\", {\n chunkIndex,\n chunkSize: chunk.length,\n error: error instanceof Error ? error.message : String(error),\n });\n return { failedTokens: [], successCount: 0 };\n }\n}\n\nexport async function sendPushNotifications({\n data,\n message,\n title,\n userIds,\n}: SchemaCreateBulkNotificationInput) {\n const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });\n const expoTokens = pushTokens.map((token) => token.token);\n\n if (!data) return;\n\n const { messages, invalidTokens } = createPushMessages({\n data,\n message,\n title,\n tokens: expoTokens,\n });\n\n // Log invalid tokens\n if (invalidTokens.length > 0) {\n console.log(`Found ${invalidTokens.length} invalid push tokens`);\n }\n\n if (messages.length === 0) {\n console.log(\"No valid messages to send after filtering tokens\");\n return;\n }\n\n // Send notifications in chunks\n const chunks = expo.chunkPushNotifications(messages);\n let totalSuccessCount = 0;\n const allFailedTokens: string[] = [];\n\n for (const [chunkIndex, chunk] of chunks.entries()) {\n const { successCount, failedTokens } = await sendChunk(\n chunk,\n chunkIndex + 1,\n );\n totalSuccessCount += successCount;\n allFailedTokens.push(...failedTokens);\n }\n\n // Log final results\n console.log(\n `Sent push notification to ${totalSuccessCount}/${messages.length} tokens across ${chunks.length} chunks`,\n );\n\n if (allFailedTokens.length > 0) {\n console.log(`Found ${allFailedTokens.length} failed push tokens`);\n }\n}\n","import mongoose from \"mongoose\";\n\nimport { EnumOSPlatform } from \"src/enums\";\nimport { ObjectId } from \"src/types\";\n\nconst MongooseSchema = mongoose.Schema;\n\ntype PushTokenType = {\n _id: string;\n createdAt: Date;\n platform: EnumOSPlatform;\n token: string;\n updatedAt: Date;\n userId: string;\n};\n\nexport type SchemaPushTokenType = Omit<PushTokenType, \"userId\"> & {\n userId: ObjectId;\n};\n\n/**\n * This is the schema for the push token type.\n * It is used to define the structure of the push token type in the database.\n * The schema is used by Mongoose to create a model for the push token type.\n */\nconst schema = new MongooseSchema<SchemaPushTokenType>(\n {\n platform: {\n enum: Object.values(EnumOSPlatform),\n required: true,\n type: String,\n },\n token: { required: true, type: String },\n userId: { required: true, type: mongoose.Schema.Types.ObjectId },\n },\n { timestamps: true },\n);\n\nexport const PushTokenModel =\n (mongoose.models.PushToken as mongoose.Model<SchemaPushTokenType>) ||\n mongoose.model<SchemaPushTokenType>(\"PushToken\", schema);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAAqB;;;ACArB,mBAAkB;AAClB,sBAAqB;AACrB,iBAAgB;AAGhB,aAAAA,QAAM,OAAO,WAAAC,OAAG;AAChB,aAAAD,QAAM,OAAO,gBAAAE,OAAQ;AAEd,SAAS,eAAeC,SAAgB;AAC7C,MAAI,CAACA,QAAO,IAAI,YAAY,EAAG;AAE/B,QAAM,YAAY,CAAC,MAAW,QAAa;AACzC,QAAI,IAAI;AACN,UAAI,gBAAY,aAAAH,SAAM,IAAI,SAAS,EAAE,GAAG,kBAAkB,EAAE,OAAO;AACrE,QAAI,IAAI;AACN,UAAI,gBAAY,aAAAA,SAAM,IAAI,SAAS,EAAE,GAAG,kBAAkB,EAAE,OAAO;AACrE,WAAO;AAAA,EACT;AAEA,EAAAG,QAAO,IAAI,UAAU,EAAE,UAAU,CAAC;AAClC,EAAAA,QAAO,IAAI,YAAY,EAAE,UAAU,CAAC;AACtC;;;ADjBA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AAAA,EACV,CAAC;AAGD,MAAI,cAAc,SAAS,GAAG;AAC5B,YAAQ,IAAI,SAAS,cAAc,MAAM,sBAAsB;AAAA,EACjE;AAEA,MAAI,SAAS,WAAW,GAAG;AACzB,YAAQ,IAAI,kDAAkD;AAC9D;AAAA,EACF;AAGA,QAAM,SAAS,KAAK,uBAAuB,QAAQ;AACnD,MAAI,oBAAoB;AACxB,QAAM,kBAA4B,CAAC;AAEnC,aAAW,CAAC,YAAY,KAAK,KAAK,OAAO,QAAQ,GAAG;AAClD,UAAM,EAAE,cAAc,aAAa,IAAI,MAAM;AAAA,MAC3C;AAAA,MACA,aAAa;AAAA,IACf;AACA,yBAAqB;AACrB,oBAAgB,KAAK,GAAG,YAAY;AAAA,EACtC;AAGA,UAAQ;AAAA,IACN,6BAA6B,iBAAiB,IAAI,SAAS,MAAM,kBAAkB,OAAO,MAAM;AAAA,EAClG;AAEA,MAAI,gBAAgB,SAAS,GAAG;AAC9B,YAAQ,IAAI,SAAS,gBAAgB,MAAM,qBAAqB;AAAA,EAClE;AACF;","names":["dayjs","utc","timezone","schema","mongoose","import_mongoose","EnumOSPlatform","EnumNotificationResourceType","EnumNotificationType","mongoose","import_mongoose","MongooseSchema","mongoose","schema"]}
|
|
1
|
+
{"version":3,"sources":["../../src/service/index.ts","../../src/service/database.ts","../../src/service/timezonePlugin.ts","../../src/mongoose/Notification.ts","../../src/enums/index.ts","../../src/service/saveNotificationsInDb.ts"],"sourcesContent":["export * from \"./database\";\nexport * from \"./saveNotificationsInDb\";\n","import mongoose from \"mongoose\";\n\nimport { timezonePlugin } from \"./timezonePlugin\";\n\nmongoose.plugin(timezonePlugin); // applies to all schemas\n\n/**\n * Connect to MongoDB using Mongoose.\n * Supports both local MongoDB (via MONGODB_URI) and MongoDB Atlas (via individual env vars).\n */\nexport const connectToDatabase = async ({\n appName,\n dbName,\n dbPassword,\n dbUser,\n mongodbUri,\n}: {\n appName: string;\n dbName: string;\n dbPassword: string;\n dbUser: string;\n mongodbUri: string;\n}) => {\n try {\n // Check if MONGODB_URI is provided (for local Docker MongoDB)\n const mongoUri = mongodbUri\n ? mongodbUri\n : // Fallback to MongoDB Atlas connection string\n `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`;\n\n await mongoose.connect(mongoUri);\n\n const connectionType = mongodbUri ? \"Local MongoDB\" : \"MongoDB Atlas\";\n console.log(\n `${connectionType} connected from server/src/service/database.ts`,\n );\n } catch (err) {\n console.error(\"Error connecting to MongoDB:\", err);\n throw err; // You can throw the error if you want to stop the server in case of connection failure\n }\n};\n","import dayjs from \"dayjs\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\nimport { Schema } from \"mongoose\";\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\n\nexport function timezonePlugin(schema: Schema) {\n if (!schema.get(\"timestamps\")) return;\n\n const transform = (_doc: any, ret: any) => {\n if (ret.createdAt)\n ret.createdAt = dayjs(ret.createdAt).tz(\"Pacific/Auckland\").format(); // ISO with +13:00 or +12:00 offset\n if (ret.updatedAt)\n ret.updatedAt = dayjs(ret.updatedAt).tz(\"Pacific/Auckland\").format();\n return ret;\n };\n\n schema.set(\"toJSON\", { transform });\n schema.set(\"toObject\", { transform });\n}\n","import mongoose from \"mongoose\";\n\nimport { EnumNotificationResourceType, EnumNotificationType } from \"src/enums\";\nimport {\n CreateBulkNotificationInput,\n NotificationType,\n ObjectId,\n} from \"src/types\";\n\nconst MongooseSchema = mongoose.Schema;\n\nexport type SchemaCreateBulkNotificationInput = Omit<\n CreateBulkNotificationInput,\n \"userIds\"\n> & {\n userIds: ObjectId[];\n};\n\nexport type SchemaNotificationType = Omit<NotificationType, \"userId\"> & {\n userId: ObjectId;\n};\n/**\n * Schema for storing in-app notifications\n * Each notification is tied to a specific user and can be marked as read/unread\n */\nconst schema = new MongooseSchema<SchemaNotificationType>(\n {\n data: {\n resourceId: { required: true, type: String },\n resourceName: { required: true, type: String },\n resourceType: {\n enum: Object.values(EnumNotificationResourceType),\n required: true,\n type: String,\n },\n },\n isRead: { default: false, index: true, required: true, type: Boolean },\n message: { required: true, type: String },\n title: { required: true, type: String },\n type: {\n default: EnumNotificationType.SYSTEM,\n enum: Object.values(EnumNotificationType),\n required: true,\n type: String,\n },\n userId: {\n ref: \"User\",\n required: true,\n type: mongoose.Schema.Types.ObjectId,\n },\n },\n { timestamps: true },\n);\n\n// Compound index for efficient queries\nschema.index({ isRead: 1, userId: 1 });\nschema.index({ createdAt: -1, userId: 1 });\n\nexport const NotificationModel =\n (mongoose.models.Notification as mongoose.Model<SchemaNotificationType>) ||\n mongoose.model<SchemaNotificationType>(\"Notification\", schema);\n","export enum EnumInviteStatus {\n ACCEPTED = \"Accepted\",\n COMPLETED = \"Completed\",\n EXPIRED = \"Expired\",\n NO_STATUS = \"No_Status\",\n PAID = \"Paid\",\n PENDING = \"Pending\",\n REJECTED = \"Rejected\",\n UNAVAILABLE = \"Unavailable\",\n WAITING = \"Waiting\",\n}\n\nexport enum EnumChatType {\n GROUP = \"group\",\n PRIVATE = \"private\",\n RELATION = \"relation\",\n}\n\nexport enum EnumPaymentMethod {\n CASH = \"cash\",\n EFTPOS = \"eftpos\",\n BANK_TRANSFER = \"bank_transfer\",\n PAYPAL = \"paypal\",\n STRIPE = \"stripe\",\n}\n\nexport enum EnumFoodFlavor {\n SALTY = \"Salty\",\n SAVOURY = \"Savoury\",\n SPICY = \"Spicy\",\n SWEET = \"Sweet\",\n}\n\nexport enum EnumResourceType {\n EVENT = \"event\",\n VENDOR = \"vendor\",\n}\n\nexport enum EnumEventType {\n EXPO = \"Expo\",\n FAIR = \"Fair\",\n FESTIVAL = \"Festival\",\n MARKET = \"Market\",\n}\n\nexport enum EnumVendorType {\n STALLHOLDER = \"Stallholder\",\n SHOP = \"Shop\",\n CHARITY = \"Charity\",\n}\n\nexport enum EnumOSPlatform {\n ANDROID = \"android\",\n IOS = \"ios\",\n WEB = \"web\",\n}\n\nexport enum EnumRelationResource {\n EVENT_INVITE_VENDOR = \"event_invite_vendor\",\n VENDOR_APPLICATION_TO_EVENT = \"vendor_application_to_event\",\n}\n\nexport enum EnumNotificationResourceType {\n ADDED_AS_PARTNER_EVENT = \"added_as_partner_event\",\n ADDED_AS_PARTNER_VENDOR = \"added_as_partner_vendor\",\n APPROVED_EVENT = \"approved_event\",\n APPROVED_VENDOR = \"approved_vendor\",\n CREATED_EVENT = \"created_event\",\n CREATED_VENDOR = \"created_vendor\",\n EVENT_INVITE_VENDOR = EnumRelationResource.EVENT_INVITE_VENDOR,\n EVENT_STARTING_SOON = \"event_starting_soon\",\n NEW_CHAT_MESSAGE = \"new_chat_message\",\n VENDOR_APPLICATION_TO_EVENT = EnumRelationResource.VENDOR_APPLICATION_TO_EVENT,\n}\n\nexport enum EnumNotificationType {\n EVENT = EnumResourceType.EVENT,\n VENDOR = EnumResourceType.VENDOR,\n RELATION = \"relation\",\n CHAT = \"chat\",\n SYSTEM = \"system\",\n}\n\nexport enum EnumRegions {\n Auckland = \"Auckland\",\n BayOfPlentyGisborne = \"Bay of Plenty & Gisborne\",\n Canterbury = \"Canterbury\",\n HawkesBay = \"Hawke's Bay\",\n ManawatuWanganui = \"Manawatu-Wanganui\",\n MarlboroughNelson = \"Marlborough & Nelson\",\n Northland = \"Northland\",\n SouthlandOtago = \"Southland & Otago\",\n Taranaki = \"Taranaki\",\n Waikato = \"Waikato\",\n Wellington = \"Wellington\",\n TasmanWestCoast = \"Tasman & West Coast\",\n}\n\nexport enum ImageTypeEnum {\n AVATAR = \"avatar\",\n COVER = \"cover\",\n IMAGE = \"image\",\n LOGO = \"logo\",\n}\n\nexport enum EnumUserLicence {\n PRO_EVENT = \"pro_event\",\n PRO_PLUS_EVENT = \"pro_plus_event\",\n PRO_PLUS_VENDOR = \"pro_plus_vendor\",\n PRO_VENDOR = \"pro_vendor\",\n STANDARD_EVENT = \"standard_event\",\n STANDARD_VENDOR = \"standard_vendor\",\n}\n\nexport enum EnumUserRole {\n ADMIN = \"admin\",\n CUSTOMER = \"customer\",\n MARKETING = \"marketing\",\n MODERATOR = \"moderator\",\n SUPPORT = \"support\",\n}\n\nexport enum EnumSocialMedia {\n FACEBOOK = \"facebook\",\n INSTAGRAM = \"instagram\",\n TIKTOK = \"tiktok\",\n TWITTER = \"twitter\",\n WEBSITE = \"website\",\n YOUTUBE = \"youtube\",\n}\n","import {\n SchemaCreateBulkNotificationInput,\n NotificationModel,\n} from \"src/mongoose/Notification\";\nimport { ObjectId } from \"src/types\";\n\n/**\n * Create notifications in the database for multiple users\n * This is typically called when sending push notifications\n */\nexport async function saveNotificationsInDb(\n payload: SchemaCreateBulkNotificationInput,\n): Promise<ObjectId[]> {\n const { data, message, title, type, userIds } = payload;\n try {\n const notifications = userIds.map((userId) => ({\n data,\n isRead: false,\n message,\n title,\n type,\n userId,\n }));\n\n // Save notifications to database\n await NotificationModel.insertMany(notifications);\n console.log(\n `Created ${notifications.length} notifications for ${userIds.length} users`,\n );\n\n return [...new Set(userIds)];\n } catch (error) {\n console.error(\"Failed to create notifications:\", error);\n return [];\n //throw new Error(`Failed to create notifications: ${error}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAAqB;;;ACArB,mBAAkB;AAClB,sBAAqB;AACrB,iBAAgB;AAGhB,aAAAA,QAAM,OAAO,WAAAC,OAAG;AAChB,aAAAD,QAAM,OAAO,gBAAAE,OAAQ;AAEd,SAAS,eAAeC,SAAgB;AAC7C,MAAI,CAACA,QAAO,IAAI,YAAY,EAAG;AAE/B,QAAM,YAAY,CAAC,MAAW,QAAa;AACzC,QAAI,IAAI;AACN,UAAI,gBAAY,aAAAH,SAAM,IAAI,SAAS,EAAE,GAAG,kBAAkB,EAAE,OAAO;AACrE,QAAI,IAAI;AACN,UAAI,gBAAY,aAAAA,SAAM,IAAI,SAAS,EAAE,GAAG,kBAAkB,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I,IAAI,OAAO,CAAC;AAAA,EAC7B,SAAS,OAAO;AACd,YAAQ,MAAM,mCAAmC,KAAK;AACtD,WAAO,CAAC;AAAA,EAEV;AACF;","names":["dayjs","utc","timezone","schema","mongoose","import_mongoose","EnumNotificationResourceType","EnumNotificationType","mongoose"]}
|
package/dist/service/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as SchemaCreateBulkNotificationInput, q as ObjectId } from '../global-
|
|
1
|
+
import { G as SchemaCreateBulkNotificationInput, q as ObjectId } from '../global-j9FEfVZs.mjs';
|
|
2
2
|
import 'express';
|
|
3
3
|
import 'mongoose';
|
|
4
4
|
import 'react-hook-form';
|
|
@@ -22,6 +22,4 @@ declare const connectToDatabase: ({ appName, dbName, dbPassword, dbUser, mongodb
|
|
|
22
22
|
*/
|
|
23
23
|
declare function saveNotificationsInDb(payload: SchemaCreateBulkNotificationInput): Promise<ObjectId[]>;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export { connectToDatabase, saveNotificationsInDb, sendPushNotifications };
|
|
25
|
+
export { connectToDatabase, saveNotificationsInDb };
|
package/dist/service/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as SchemaCreateBulkNotificationInput, q as ObjectId } from '../global-
|
|
1
|
+
import { G as SchemaCreateBulkNotificationInput, q as ObjectId } from '../global-DvxKMAQD.js';
|
|
2
2
|
import 'express';
|
|
3
3
|
import 'mongoose';
|
|
4
4
|
import 'react-hook-form';
|
|
@@ -22,6 +22,4 @@ declare const connectToDatabase: ({ appName, dbName, dbPassword, dbUser, mongodb
|
|
|
22
22
|
*/
|
|
23
23
|
declare function saveNotificationsInDb(payload: SchemaCreateBulkNotificationInput): Promise<ObjectId[]>;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export { connectToDatabase, saveNotificationsInDb, sendPushNotifications };
|
|
25
|
+
export { connectToDatabase, saveNotificationsInDb };
|
package/dist/service/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
NotificationModel
|
|
3
|
-
|
|
4
|
-
} from "../chunk-NPHPFWQH.mjs";
|
|
2
|
+
NotificationModel
|
|
3
|
+
} from "../chunk-WWL2Q5DN.mjs";
|
|
5
4
|
import "../chunk-NNS747QT.mjs";
|
|
6
5
|
|
|
7
6
|
// src/service/database.ts
|
|
@@ -73,118 +72,8 @@ async function saveNotificationsInDb(payload) {
|
|
|
73
72
|
return [];
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
// src/service/sendPushNotifications.ts
|
|
78
|
-
import { Expo } from "expo-server-sdk";
|
|
79
|
-
var expo = new Expo();
|
|
80
|
-
function extractTokensFromMessage(message) {
|
|
81
|
-
return Array.isArray(message.to) ? message.to : [message.to];
|
|
82
|
-
}
|
|
83
|
-
function createPushMessages({
|
|
84
|
-
tokens,
|
|
85
|
-
message,
|
|
86
|
-
title,
|
|
87
|
-
data
|
|
88
|
-
}) {
|
|
89
|
-
const messages = [];
|
|
90
|
-
const invalidTokens = [];
|
|
91
|
-
for (const token of tokens) {
|
|
92
|
-
if (!Expo.isExpoPushToken(token)) {
|
|
93
|
-
invalidTokens.push(token);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
messages.push({
|
|
97
|
-
body: message,
|
|
98
|
-
data: { ...data },
|
|
99
|
-
sound: "default",
|
|
100
|
-
title,
|
|
101
|
-
to: token
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return { invalidTokens, messages };
|
|
105
|
-
}
|
|
106
|
-
function processChunkResults(tickets, chunk) {
|
|
107
|
-
let successCount = 0;
|
|
108
|
-
const failedTokens = [];
|
|
109
|
-
for (const [ticketIndex, ticket] of tickets.entries()) {
|
|
110
|
-
if (ticket.status === "error") {
|
|
111
|
-
const message = chunk[ticketIndex];
|
|
112
|
-
if (message) {
|
|
113
|
-
const tokens = extractTokensFromMessage(message);
|
|
114
|
-
if (ticket.details?.error === "DeviceNotRegistered") {
|
|
115
|
-
failedTokens.push(...tokens);
|
|
116
|
-
}
|
|
117
|
-
console.log("Push notification error", {
|
|
118
|
-
error: ticket.details?.error,
|
|
119
|
-
tokens
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
successCount++;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return { failedTokens, successCount };
|
|
127
|
-
}
|
|
128
|
-
async function sendChunk(chunk, chunkIndex) {
|
|
129
|
-
try {
|
|
130
|
-
const tickets = await expo.sendPushNotificationsAsync(chunk);
|
|
131
|
-
const { successCount, failedTokens } = processChunkResults(tickets, chunk);
|
|
132
|
-
console.log(
|
|
133
|
-
`Chunk ${chunkIndex + 1}: Sent ${successCount}/${chunk.length} notifications successfully`
|
|
134
|
-
);
|
|
135
|
-
return { failedTokens, successCount };
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.log("Error sending Expo push notification chunk", {
|
|
138
|
-
chunkIndex,
|
|
139
|
-
chunkSize: chunk.length,
|
|
140
|
-
error: error instanceof Error ? error.message : String(error)
|
|
141
|
-
});
|
|
142
|
-
return { failedTokens: [], successCount: 0 };
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async function sendPushNotifications({
|
|
146
|
-
data,
|
|
147
|
-
message,
|
|
148
|
-
title,
|
|
149
|
-
userIds
|
|
150
|
-
}) {
|
|
151
|
-
const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });
|
|
152
|
-
const expoTokens = pushTokens.map((token) => token.token);
|
|
153
|
-
if (!data) return;
|
|
154
|
-
const { messages, invalidTokens } = createPushMessages({
|
|
155
|
-
data,
|
|
156
|
-
message,
|
|
157
|
-
title,
|
|
158
|
-
tokens: expoTokens
|
|
159
|
-
});
|
|
160
|
-
if (invalidTokens.length > 0) {
|
|
161
|
-
console.log(`Found ${invalidTokens.length} invalid push tokens`);
|
|
162
|
-
}
|
|
163
|
-
if (messages.length === 0) {
|
|
164
|
-
console.log("No valid messages to send after filtering tokens");
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const chunks = expo.chunkPushNotifications(messages);
|
|
168
|
-
let totalSuccessCount = 0;
|
|
169
|
-
const allFailedTokens = [];
|
|
170
|
-
for (const [chunkIndex, chunk] of chunks.entries()) {
|
|
171
|
-
const { successCount, failedTokens } = await sendChunk(
|
|
172
|
-
chunk,
|
|
173
|
-
chunkIndex + 1
|
|
174
|
-
);
|
|
175
|
-
totalSuccessCount += successCount;
|
|
176
|
-
allFailedTokens.push(...failedTokens);
|
|
177
|
-
}
|
|
178
|
-
console.log(
|
|
179
|
-
`Sent push notification to ${totalSuccessCount}/${messages.length} tokens across ${chunks.length} chunks`
|
|
180
|
-
);
|
|
181
|
-
if (allFailedTokens.length > 0) {
|
|
182
|
-
console.log(`Found ${allFailedTokens.length} failed push tokens`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
75
|
export {
|
|
186
76
|
connectToDatabase,
|
|
187
|
-
saveNotificationsInDb
|
|
188
|
-
sendPushNotifications
|
|
77
|
+
saveNotificationsInDb
|
|
189
78
|
};
|
|
190
79
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/service/database.ts","../../src/service/timezonePlugin.ts","../../src/service/saveNotificationsInDb.ts","../../src/service/sendPushNotifications.ts"],"sourcesContent":["import mongoose from \"mongoose\";\n\nimport { timezonePlugin } from \"./timezonePlugin\";\n\nmongoose.plugin(timezonePlugin); // applies to all schemas\n\n/**\n * Connect to MongoDB using Mongoose.\n * Supports both local MongoDB (via MONGODB_URI) and MongoDB Atlas (via individual env vars).\n */\nexport const connectToDatabase = async ({\n appName,\n dbName,\n dbPassword,\n dbUser,\n mongodbUri,\n}: {\n appName: string;\n dbName: string;\n dbPassword: string;\n dbUser: string;\n mongodbUri: string;\n}) => {\n try {\n // Check if MONGODB_URI is provided (for local Docker MongoDB)\n const mongoUri = mongodbUri\n ? mongodbUri\n : // Fallback to MongoDB Atlas connection string\n `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`;\n\n await mongoose.connect(mongoUri);\n\n const connectionType = mongodbUri ? \"Local MongoDB\" : \"MongoDB Atlas\";\n console.log(\n `${connectionType} connected from server/src/service/database.ts`,\n );\n } catch (err) {\n console.error(\"Error connecting to MongoDB:\", err);\n throw err; // You can throw the error if you want to stop the server in case of connection failure\n }\n};\n","import dayjs from \"dayjs\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\nimport { Schema } from \"mongoose\";\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\n\nexport function timezonePlugin(schema: Schema) {\n if (!schema.get(\"timestamps\")) return;\n\n const transform = (_doc: any, ret: any) => {\n if (ret.createdAt)\n ret.createdAt = dayjs(ret.createdAt).tz(\"Pacific/Auckland\").format(); // ISO with +13:00 or +12:00 offset\n if (ret.updatedAt)\n ret.updatedAt = dayjs(ret.updatedAt).tz(\"Pacific/Auckland\").format();\n return ret;\n };\n\n schema.set(\"toJSON\", { transform });\n schema.set(\"toObject\", { transform });\n}\n","import {\n SchemaCreateBulkNotificationInput,\n NotificationModel,\n} from \"src/mongoose/Notification\";\nimport { ObjectId } from \"src/types\";\n\n/**\n * Create notifications in the database for multiple users\n * This is typically called when sending push notifications\n */\nexport async function saveNotificationsInDb(\n payload: SchemaCreateBulkNotificationInput,\n): Promise<ObjectId[]> {\n const { data, message, title, type, userIds } = payload;\n try {\n const notifications = userIds.map((userId) => ({\n data,\n isRead: false,\n message,\n title,\n type,\n userId,\n }));\n\n // Save notifications to database\n await NotificationModel.insertMany(notifications);\n console.log(\n `Created ${notifications.length} notifications for ${userIds.length} users`,\n );\n\n return [...new Set(userIds)];\n } catch (error) {\n console.error(\"Failed to create notifications:\", error);\n return [];\n //throw new Error(`Failed to create notifications: ${error}`);\n }\n}\n","import { Expo, ExpoPushMessage, ExpoPushTicket } from \"expo-server-sdk\";\n\nimport { SchemaCreateBulkNotificationInput } from \"src/mongoose/Notification\";\nimport { PushTokenModel } from \"src/mongoose/PushToken\";\nimport { NotificationDataType, ObjectId } from \"src/types\";\n\nconst expo = new Expo();\n\n/**\n * Safely extract tokens from ExpoPushMessage handling both string and array cases\n */\nfunction extractTokensFromMessage(message: ExpoPushMessage): string[] {\n return Array.isArray(message.to) ? message.to : [message.to];\n}\n\ninterface CreatePushMessagesOptions {\n tokens: string[];\n message: string;\n title: string;\n data: NotificationDataType;\n}\n\n/**\n * Create push messages from valid tokens\n */\nfunction createPushMessages({\n tokens,\n message,\n title,\n data,\n}: CreatePushMessagesOptions): {\n messages: ExpoPushMessage[];\n invalidTokens: string[];\n} {\n const messages: ExpoPushMessage[] = [];\n const invalidTokens: string[] = [];\n\n for (const token of tokens) {\n if (!Expo.isExpoPushToken(token)) {\n invalidTokens.push(token);\n continue;\n }\n\n messages.push({\n body: message,\n data: { ...data },\n sound: \"default\",\n title,\n to: token,\n });\n }\n\n return { invalidTokens, messages };\n}\n\n/**\n * Process chunk results and extract failed tokens\n */\nfunction processChunkResults(\n tickets: ExpoPushTicket[],\n chunk: ExpoPushMessage[],\n): { successCount: number; failedTokens: string[] } {\n let successCount = 0;\n const failedTokens: string[] = [];\n\n for (const [ticketIndex, ticket] of tickets.entries()) {\n if (ticket.status === \"error\") {\n const message = chunk[ticketIndex];\n if (message) {\n const tokens = extractTokensFromMessage(message);\n if (ticket.details?.error === \"DeviceNotRegistered\") {\n failedTokens.push(...tokens);\n }\n console.log(\"Push notification error\", {\n error: ticket.details?.error,\n tokens,\n });\n }\n } else {\n successCount++;\n }\n }\n\n return { failedTokens, successCount };\n}\n\n/**\n * Send a single chunk of push notifications\n */\nasync function sendChunk(\n chunk: ExpoPushMessage[],\n chunkIndex: number,\n): Promise<{ successCount: number; failedTokens: string[] }> {\n try {\n const tickets = await expo.sendPushNotificationsAsync(chunk);\n const { successCount, failedTokens } = processChunkResults(tickets, chunk);\n\n console.log(\n `Chunk ${chunkIndex + 1}: Sent ${successCount}/${chunk.length} notifications successfully`,\n );\n\n return { failedTokens, successCount };\n } catch (error) {\n console.log(\"Error sending Expo push notification chunk\", {\n chunkIndex,\n chunkSize: chunk.length,\n error: error instanceof Error ? error.message : String(error),\n });\n return { failedTokens: [], successCount: 0 };\n }\n}\n\nexport async function sendPushNotifications({\n data,\n message,\n title,\n userIds,\n}: SchemaCreateBulkNotificationInput) {\n const pushTokens = await PushTokenModel.find({ userId: { $in: userIds } });\n const expoTokens = pushTokens.map((token) => token.token);\n\n if (!data) return;\n\n const { messages, invalidTokens } = createPushMessages({\n data,\n message,\n title,\n tokens: expoTokens,\n });\n\n // Log invalid tokens\n if (invalidTokens.length > 0) {\n console.log(`Found ${invalidTokens.length} invalid push tokens`);\n }\n\n if (messages.length === 0) {\n console.log(\"No valid messages to send after filtering tokens\");\n return;\n }\n\n // Send notifications in chunks\n const chunks = expo.chunkPushNotifications(messages);\n let totalSuccessCount = 0;\n const allFailedTokens: string[] = [];\n\n for (const [chunkIndex, chunk] of chunks.entries()) {\n const { successCount, failedTokens } = await sendChunk(\n chunk,\n chunkIndex + 1,\n );\n totalSuccessCount += successCount;\n allFailedTokens.push(...failedTokens);\n }\n\n // Log final results\n console.log(\n `Sent push notification to ${totalSuccessCount}/${messages.length} tokens across ${chunks.length} chunks`,\n );\n\n if (allFailedTokens.length > 0) {\n console.log(`Found ${allFailedTokens.length} failed push tokens`);\n }\n}\n"],"mappings":";;;;;;;AAAA,OAAO,cAAc;;;ACArB,OAAO,WAAW;AAClB,OAAO,cAAc;AACrB,OAAO,SAAS;AAGhB,MAAM,OAAO,GAAG;AAChB,MAAM,OAAO,QAAQ;AAEd,SAAS,eAAe,QAAgB;AAC7C,MAAI,CAAC,OAAO,IAAI,YAAY,EAAG;AAE/B,QAAM,YAAY,CAAC,MAAW,QAAa;AACzC,QAAI,IAAI;AACN,UAAI,YAAY,MAAM,IAAI,SAAS,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AqB;AAAA,EAClE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/service/database.ts","../../src/service/timezonePlugin.ts","../../src/service/saveNotificationsInDb.ts"],"sourcesContent":["import mongoose from \"mongoose\";\n\nimport { timezonePlugin } from \"./timezonePlugin\";\n\nmongoose.plugin(timezonePlugin); // applies to all schemas\n\n/**\n * Connect to MongoDB using Mongoose.\n * Supports both local MongoDB (via MONGODB_URI) and MongoDB Atlas (via individual env vars).\n */\nexport const connectToDatabase = async ({\n appName,\n dbName,\n dbPassword,\n dbUser,\n mongodbUri,\n}: {\n appName: string;\n dbName: string;\n dbPassword: string;\n dbUser: string;\n mongodbUri: string;\n}) => {\n try {\n // Check if MONGODB_URI is provided (for local Docker MongoDB)\n const mongoUri = mongodbUri\n ? mongodbUri\n : // Fallback to MongoDB Atlas connection string\n `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`;\n\n await mongoose.connect(mongoUri);\n\n const connectionType = mongodbUri ? \"Local MongoDB\" : \"MongoDB Atlas\";\n console.log(\n `${connectionType} connected from server/src/service/database.ts`,\n );\n } catch (err) {\n console.error(\"Error connecting to MongoDB:\", err);\n throw err; // You can throw the error if you want to stop the server in case of connection failure\n }\n};\n","import dayjs from \"dayjs\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\nimport { Schema } from \"mongoose\";\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\n\nexport function timezonePlugin(schema: Schema) {\n if (!schema.get(\"timestamps\")) return;\n\n const transform = (_doc: any, ret: any) => {\n if (ret.createdAt)\n ret.createdAt = dayjs(ret.createdAt).tz(\"Pacific/Auckland\").format(); // ISO with +13:00 or +12:00 offset\n if (ret.updatedAt)\n ret.updatedAt = dayjs(ret.updatedAt).tz(\"Pacific/Auckland\").format();\n return ret;\n };\n\n schema.set(\"toJSON\", { transform });\n schema.set(\"toObject\", { transform });\n}\n","import {\n SchemaCreateBulkNotificationInput,\n NotificationModel,\n} from \"src/mongoose/Notification\";\nimport { ObjectId } from \"src/types\";\n\n/**\n * Create notifications in the database for multiple users\n * This is typically called when sending push notifications\n */\nexport async function saveNotificationsInDb(\n payload: SchemaCreateBulkNotificationInput,\n): Promise<ObjectId[]> {\n const { data, message, title, type, userIds } = payload;\n try {\n const notifications = userIds.map((userId) => ({\n data,\n isRead: false,\n message,\n title,\n type,\n userId,\n }));\n\n // Save notifications to database\n await NotificationModel.insertMany(notifications);\n console.log(\n `Created ${notifications.length} notifications for ${userIds.length} users`,\n );\n\n return [...new Set(userIds)];\n } catch (error) {\n console.error(\"Failed to create notifications:\", error);\n return [];\n //throw new Error(`Failed to create notifications: ${error}`);\n }\n}\n"],"mappings":";;;;;;AAAA,OAAO,cAAc;;;ACArB,OAAO,WAAW;AAClB,OAAO,cAAc;AACrB,OAAO,SAAS;AAGhB,MAAM,OAAO,GAAG;AAChB,MAAM,OAAO,QAAQ;AAEd,SAAS,eAAe,QAAgB;AAC7C,MAAI,CAAC,OAAO,IAAI,YAAY,EAAG;AAE/B,QAAM,YAAY,CAAC,MAAW,QAAa;AACzC,QAAI,IAAI;AACN,UAAI,YAAY,MAAM,IAAI,SAAS,EAAE,GAAG,kBAAkB,EAAE,OAAO;AACrE,QAAI,IAAI;AACN,UAAI,YAAY,MAAM,IAAI,SAAS,EAAE,GAAG,kBAAkB,EAAE,OAAO;AACrE,WAAO;AAAA,EACT;AAEA,SAAO,IAAI,UAAU,EAAE,UAAU,CAAC;AAClC,SAAO,IAAI,YAAY,EAAE,UAAU,CAAC;AACtC;;;ADjBA,SAAS,OAAO,cAAc;AAMvB,IAAM,oBAAoB,OAAO;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AACJ,MAAI;AAEF,UAAM,WAAW,aACb;AAAA;AAAA,MAEA,iBAAiB,MAAM,IAAI,UAAU,IAAI,MAAM,qDAAqD,OAAO;AAAA;AAE/G,UAAM,SAAS,QAAQ,QAAQ;AAE/B,UAAM,iBAAiB,aAAa,kBAAkB;AACtD,YAAQ;AAAA,MACN,GAAG,cAAc;AAAA,IACnB;AAAA,EACF,SAAS,KAAK;AACZ,YAAQ,MAAM,gCAAgC,GAAG;AACjD,UAAM;AAAA,EACR;AACF;;;AE9BA,eAAsB,sBACpB,SACqB;AACrB,QAAM,EAAE,MAAM,SAAS,OAAO,MAAM,QAAQ,IAAI;AAChD,MAAI;AACF,UAAM,gBAAgB,QAAQ,IAAI,CAAC,YAAY;AAAA,MAC7C;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,EAAE;AAGF,UAAM,kBAAkB,WAAW,aAAa;AAChD,YAAQ;AAAA,MACN,WAAW,cAAc,MAAM,sBAAsB,QAAQ,MAAM;AAAA,IACrE;AAEA,WAAO,CAAC,GAAG,IAAI,IAAI,OAAO,CAAC;AAAA,EAC7B,SAAS,OAAO;AACd,YAAQ,MAAM,mCAAmC,KAAK;AACtD,WAAO,CAAC;AAAA,EAEV;AACF;","names":[]}
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EnumResourceType } from '../enums/index.mjs';
|
|
2
|
-
export { e as ContactUsFormData, f as CreateContactUsFormData, C as CreateLoginFormData, a as CreateRegisterFormData, b as CreateRequestPasswordResetFormData, d as CreateResetPasswordFormData, c as CreateValidateVerificationTokenFormData, L as LoginFormData, R as RegisterFormData, g as RequestPasswordResetFormData, h as ResetPasswordFormData, V as ValidateVerificationTokenFormData } from '../auth-
|
|
3
|
-
export { a3 as AuthUser, U as BaseResourceType, B as BaseResourceTypeFormData, C as Category, K as ChatMessageInput, M as ChatMessageType, b as ChatType, a9 as CreateBulkNotificationInput, m as CreateEventFormData, o as CreateEventInfoFormData, a1 as CreateFormData, i as CreateVendorFormData, k as CreateVendorInfoFormData, W as DateTimeType, a6 as DateTimeWithPriceType, D as DeviceInfo, a2 as EnumPubSubEvents, l as EventFormData, n as EventInfoFormData, c as EventInfoType, E as EventType, a as FormDateField, F as FormField, Y as GeocodeLocation, a5 as GraphQLContext, a0 as ImageObjectType, L as LocationType, Z as MapMultiLocation, d as NotificationCount, a8 as NotificationDataType, N as NotificationType, Q as Nullable, q as ObjectId, O as OptionItem, p as OwnerType, J as ParticipantType, P as PartnerType, a7 as PaymentInfoType, u as PosterUsageType, X as Region, v as RelationDate, e as RelationType, R as Requirement, f as ResourceConnectionsType, t as ResourceContactDetailsType, s as ResourceImageType, r as SocialMediaType, S as StallType, $ as Subcategory, _ as SubcategoryItems, a4 as SubscriptionPayload, T as TermsAgreement, ac as VendorAttributes, h as VendorFormData, j as VendorInfoFormData, g as VendorInfoType, aa as VendorLocation, ab as VendorMenuType, V as VendorType } from '../global-
|
|
4
|
-
export { d as AdFormData, A as AdType, e as CreateAdFormData, c as CreateTestersFormData, C as CreateUserFormData, h as EnumAdShowOn, E as EnumAdStatus, j as EnumAdStyle, i as EnumAdType, T as TesterType, b as TestersFormData, g as UserActivity, f as UserActivityEvent, a as UserFormData, U as UserType } from '../ad-
|
|
2
|
+
export { e as ContactUsFormData, f as CreateContactUsFormData, C as CreateLoginFormData, a as CreateRegisterFormData, b as CreateRequestPasswordResetFormData, d as CreateResetPasswordFormData, c as CreateValidateVerificationTokenFormData, L as LoginFormData, R as RegisterFormData, g as RequestPasswordResetFormData, h as ResetPasswordFormData, V as ValidateVerificationTokenFormData } from '../auth-BslKse3L.mjs';
|
|
3
|
+
export { a3 as AuthUser, U as BaseResourceType, B as BaseResourceTypeFormData, C as Category, K as ChatMessageInput, M as ChatMessageType, b as ChatType, a9 as CreateBulkNotificationInput, m as CreateEventFormData, o as CreateEventInfoFormData, a1 as CreateFormData, i as CreateVendorFormData, k as CreateVendorInfoFormData, W as DateTimeType, a6 as DateTimeWithPriceType, D as DeviceInfo, a2 as EnumPubSubEvents, l as EventFormData, n as EventInfoFormData, c as EventInfoType, E as EventType, a as FormDateField, F as FormField, Y as GeocodeLocation, a5 as GraphQLContext, a0 as ImageObjectType, L as LocationType, Z as MapMultiLocation, d as NotificationCount, a8 as NotificationDataType, N as NotificationType, Q as Nullable, q as ObjectId, O as OptionItem, p as OwnerType, J as ParticipantType, P as PartnerType, a7 as PaymentInfoType, u as PosterUsageType, X as Region, v as RelationDate, e as RelationType, R as Requirement, f as ResourceConnectionsType, t as ResourceContactDetailsType, s as ResourceImageType, r as SocialMediaType, S as StallType, $ as Subcategory, _ as SubcategoryItems, a4 as SubscriptionPayload, T as TermsAgreement, ac as VendorAttributes, h as VendorFormData, j as VendorInfoFormData, g as VendorInfoType, aa as VendorLocation, ab as VendorMenuType, V as VendorType } from '../global-j9FEfVZs.mjs';
|
|
4
|
+
export { d as AdFormData, A as AdType, e as CreateAdFormData, c as CreateTestersFormData, C as CreateUserFormData, h as EnumAdShowOn, E as EnumAdStatus, j as EnumAdStyle, i as EnumAdType, T as TesterType, b as TestersFormData, g as UserActivity, f as UserActivityEvent, a as UserFormData, U as UserType } from '../ad-CWAaH5Ql.mjs';
|
|
5
5
|
export { E as EnumActivity, a as ResourceActivityEntry, b as ResourceActivityInputType, R as ResourceActivityType } from '../resourceActivities-BIjtlOGp.mjs';
|
|
6
6
|
export { default as mongoose } from 'mongoose';
|
|
7
7
|
import 'express';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EnumResourceType } from '../enums/index.js';
|
|
2
|
-
export { e as ContactUsFormData, f as CreateContactUsFormData, C as CreateLoginFormData, a as CreateRegisterFormData, b as CreateRequestPasswordResetFormData, d as CreateResetPasswordFormData, c as CreateValidateVerificationTokenFormData, L as LoginFormData, R as RegisterFormData, g as RequestPasswordResetFormData, h as ResetPasswordFormData, V as ValidateVerificationTokenFormData } from '../auth-
|
|
3
|
-
export { a3 as AuthUser, U as BaseResourceType, B as BaseResourceTypeFormData, C as Category, K as ChatMessageInput, M as ChatMessageType, b as ChatType, a9 as CreateBulkNotificationInput, m as CreateEventFormData, o as CreateEventInfoFormData, a1 as CreateFormData, i as CreateVendorFormData, k as CreateVendorInfoFormData, W as DateTimeType, a6 as DateTimeWithPriceType, D as DeviceInfo, a2 as EnumPubSubEvents, l as EventFormData, n as EventInfoFormData, c as EventInfoType, E as EventType, a as FormDateField, F as FormField, Y as GeocodeLocation, a5 as GraphQLContext, a0 as ImageObjectType, L as LocationType, Z as MapMultiLocation, d as NotificationCount, a8 as NotificationDataType, N as NotificationType, Q as Nullable, q as ObjectId, O as OptionItem, p as OwnerType, J as ParticipantType, P as PartnerType, a7 as PaymentInfoType, u as PosterUsageType, X as Region, v as RelationDate, e as RelationType, R as Requirement, f as ResourceConnectionsType, t as ResourceContactDetailsType, s as ResourceImageType, r as SocialMediaType, S as StallType, $ as Subcategory, _ as SubcategoryItems, a4 as SubscriptionPayload, T as TermsAgreement, ac as VendorAttributes, h as VendorFormData, j as VendorInfoFormData, g as VendorInfoType, aa as VendorLocation, ab as VendorMenuType, V as VendorType } from '../global-
|
|
4
|
-
export { d as AdFormData, A as AdType, e as CreateAdFormData, c as CreateTestersFormData, C as CreateUserFormData, h as EnumAdShowOn, E as EnumAdStatus, j as EnumAdStyle, i as EnumAdType, T as TesterType, b as TestersFormData, g as UserActivity, f as UserActivityEvent, a as UserFormData, U as UserType } from '../ad-
|
|
2
|
+
export { e as ContactUsFormData, f as CreateContactUsFormData, C as CreateLoginFormData, a as CreateRegisterFormData, b as CreateRequestPasswordResetFormData, d as CreateResetPasswordFormData, c as CreateValidateVerificationTokenFormData, L as LoginFormData, R as RegisterFormData, g as RequestPasswordResetFormData, h as ResetPasswordFormData, V as ValidateVerificationTokenFormData } from '../auth-Ch9Nt77g.js';
|
|
3
|
+
export { a3 as AuthUser, U as BaseResourceType, B as BaseResourceTypeFormData, C as Category, K as ChatMessageInput, M as ChatMessageType, b as ChatType, a9 as CreateBulkNotificationInput, m as CreateEventFormData, o as CreateEventInfoFormData, a1 as CreateFormData, i as CreateVendorFormData, k as CreateVendorInfoFormData, W as DateTimeType, a6 as DateTimeWithPriceType, D as DeviceInfo, a2 as EnumPubSubEvents, l as EventFormData, n as EventInfoFormData, c as EventInfoType, E as EventType, a as FormDateField, F as FormField, Y as GeocodeLocation, a5 as GraphQLContext, a0 as ImageObjectType, L as LocationType, Z as MapMultiLocation, d as NotificationCount, a8 as NotificationDataType, N as NotificationType, Q as Nullable, q as ObjectId, O as OptionItem, p as OwnerType, J as ParticipantType, P as PartnerType, a7 as PaymentInfoType, u as PosterUsageType, X as Region, v as RelationDate, e as RelationType, R as Requirement, f as ResourceConnectionsType, t as ResourceContactDetailsType, s as ResourceImageType, r as SocialMediaType, S as StallType, $ as Subcategory, _ as SubcategoryItems, a4 as SubscriptionPayload, T as TermsAgreement, ac as VendorAttributes, h as VendorFormData, j as VendorInfoFormData, g as VendorInfoType, aa as VendorLocation, ab as VendorMenuType, V as VendorType } from '../global-DvxKMAQD.js';
|
|
4
|
+
export { d as AdFormData, A as AdType, e as CreateAdFormData, c as CreateTestersFormData, C as CreateUserFormData, h as EnumAdShowOn, E as EnumAdStatus, j as EnumAdStyle, i as EnumAdType, T as TesterType, b as TestersFormData, g as UserActivity, f as UserActivityEvent, a as UserFormData, U as UserType } from '../ad-D60cy5L4.js';
|
|
5
5
|
export { E as EnumActivity, a as ResourceActivityEntry, b as ResourceActivityInputType, R as ResourceActivityType } from '../resourceActivities-B4roVKtQ.js';
|
|
6
6
|
export { default as mongoose } from 'mongoose';
|
|
7
7
|
import 'express';
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnumInviteStatus, EnumRegions } from '../enums/index.mjs';
|
|
2
|
-
import { X as Region, O as OptionItem } from '../global-
|
|
2
|
+
import { X as Region, O as OptionItem } from '../global-j9FEfVZs.mjs';
|
|
3
3
|
import 'express';
|
|
4
4
|
import 'mongoose';
|
|
5
5
|
import 'react-hook-form';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnumInviteStatus, EnumRegions } from '../enums/index.js';
|
|
2
|
-
import { X as Region, O as OptionItem } from '../global-
|
|
2
|
+
import { X as Region, O as OptionItem } from '../global-DvxKMAQD.js';
|
|
3
3
|
import 'express';
|
|
4
4
|
import 'mongoose';
|
|
5
5
|
import 'react-hook-form';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timardex/cluemart-shared",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -96,7 +96,6 @@
|
|
|
96
96
|
"@apollo/client": "^3.14.0",
|
|
97
97
|
"@hookform/resolvers": "^4.1.1",
|
|
98
98
|
"dayjs": "^1.11.13",
|
|
99
|
-
"expo-server-sdk": "^4.0.0",
|
|
100
99
|
"express": "^5.1.0",
|
|
101
100
|
"mongoose": "^8.19.3",
|
|
102
101
|
"react": "^19.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mongoose/Notification.ts","../src/mongoose/PushToken.ts"],"sourcesContent":["import mongoose from \"mongoose\";\n\nimport { EnumNotificationResourceType, EnumNotificationType } from \"src/enums\";\nimport {\n CreateBulkNotificationInput,\n NotificationType,\n ObjectId,\n} from \"src/types\";\n\nconst MongooseSchema = mongoose.Schema;\n\nexport type SchemaCreateBulkNotificationInput = Omit<\n CreateBulkNotificationInput,\n \"userIds\"\n> & {\n userIds: ObjectId[];\n};\n\nexport type SchemaNotificationType = Omit<NotificationType, \"userId\"> & {\n userId: ObjectId;\n};\n/**\n * Schema for storing in-app notifications\n * Each notification is tied to a specific user and can be marked as read/unread\n */\nconst schema = new MongooseSchema<SchemaNotificationType>(\n {\n data: {\n resourceId: { required: true, type: String },\n resourceName: { required: true, type: String },\n resourceType: {\n enum: Object.values(EnumNotificationResourceType),\n required: true,\n type: String,\n },\n },\n isRead: { default: false, index: true, required: true, type: Boolean },\n message: { required: true, type: String },\n title: { required: true, type: String },\n type: {\n default: EnumNotificationType.SYSTEM,\n enum: Object.values(EnumNotificationType),\n required: true,\n type: String,\n },\n userId: {\n ref: \"User\",\n required: true,\n type: mongoose.Schema.Types.ObjectId,\n },\n },\n { timestamps: true },\n);\n\n// Compound index for efficient queries\nschema.index({ isRead: 1, userId: 1 });\nschema.index({ createdAt: -1, userId: 1 });\n\nexport const NotificationModel =\n (mongoose.models.Notification as mongoose.Model<SchemaNotificationType>) ||\n mongoose.model<SchemaNotificationType>(\"Notification\", schema);\n","import mongoose from \"mongoose\";\n\nimport { EnumOSPlatform } from \"src/enums\";\nimport { ObjectId } from \"src/types\";\n\nconst MongooseSchema = mongoose.Schema;\n\ntype PushTokenType = {\n _id: string;\n createdAt: Date;\n platform: EnumOSPlatform;\n token: string;\n updatedAt: Date;\n userId: string;\n};\n\nexport type SchemaPushTokenType = Omit<PushTokenType, \"userId\"> & {\n userId: ObjectId;\n};\n\n/**\n * This is the schema for the push token type.\n * It is used to define the structure of the push token type in the database.\n * The schema is used by Mongoose to create a model for the push token type.\n */\nconst schema = new MongooseSchema<SchemaPushTokenType>(\n {\n platform: {\n enum: Object.values(EnumOSPlatform),\n required: true,\n type: String,\n },\n token: { required: true, type: String },\n userId: { required: true, type: mongoose.Schema.Types.ObjectId },\n },\n { timestamps: true },\n);\n\nexport const PushTokenModel =\n (mongoose.models.PushToken as mongoose.Model<SchemaPushTokenType>) ||\n mongoose.model<SchemaPushTokenType>(\"PushToken\", schema);\n"],"mappings":";;;;;;;AAAA,OAAO,cAAc;AASrB,IAAM,iBAAiB,SAAS;AAgBhC,IAAM,SAAS,IAAI;AAAA,EACjB;AAAA,IACE,MAAM;AAAA,MACJ,YAAY,EAAE,UAAU,MAAM,MAAM,OAAO;AAAA,MAC3C,cAAc,EAAE,UAAU,MAAM,MAAM,OAAO;AAAA,MAC7C,cAAc;AAAA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