@lyxa.ai/core 1.0.32 → 1.0.34
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/libraries/mongo/models/activity-log.model.js +6 -1
- package/dist/libraries/mongo/models/activity-log.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/parent-document.model.d.ts +3 -3
- package/dist/libraries/mongo/models/embedded/parent-document.model.js +3 -3
- package/dist/libraries/mongo/models/embedded/parent-document.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/shop-document.model.d.ts +3 -3
- package/dist/libraries/mongo/models/embedded/shop-document.model.js +3 -3
- package/dist/libraries/mongo/models/embedded/shop-document.model.js.map +1 -1
- package/dist/libraries/mongo/models/parent.model.d.ts +2 -2
- package/dist/libraries/mongo/models/parent.model.js +2 -2
- package/dist/libraries/mongo/models/parent.model.js.map +1 -1
- package/dist/libraries/mongo/models/providers/courier-order.model.d.ts +2 -2
- package/dist/libraries/mongo/models/providers/courier-order.model.js +4 -4
- package/dist/libraries/mongo/models/providers/courier-order.model.js.map +1 -1
- package/dist/libraries/mongo/models/providers/regular-order.model.d.ts +2 -2
- package/dist/libraries/mongo/models/providers/regular-order.model.js +4 -4
- package/dist/libraries/mongo/models/providers/regular-order.model.js.map +1 -1
- package/dist/libraries/mongo/models/rider-review.model.js +6 -1
- package/dist/libraries/mongo/models/rider-review.model.js.map +1 -1
- package/dist/libraries/mongo/models/shop.model.d.ts +3 -3
- package/dist/libraries/mongo/models/shop.model.js +5 -4
- package/dist/libraries/mongo/models/shop.model.js.map +1 -1
- package/dist/libraries/trpc/middlewares/cors.js +2 -2
- package/dist/libraries/trpc/middlewares/cors.js.map +1 -1
- package/dist/libraries/upload/index.d.ts +20 -0
- package/dist/libraries/upload/index.js +93 -3
- package/dist/libraries/upload/index.js.map +1 -1
- package/package.json +3 -1
|
@@ -38,6 +38,11 @@ __decorate([
|
|
|
38
38
|
__metadata("design:type", Object)
|
|
39
39
|
], ActivityLog.prototype, "newDocument", void 0);
|
|
40
40
|
exports.ActivityLog = ActivityLog = __decorate([
|
|
41
|
-
(0, typegoose_1.modelOptions)({
|
|
41
|
+
(0, typegoose_1.modelOptions)({
|
|
42
|
+
schemaOptions: { collection: 'activityLogs' },
|
|
43
|
+
options: {
|
|
44
|
+
allowMixed: typegoose_1.Severity.ALLOW,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
42
47
|
], ActivityLog);
|
|
43
48
|
//# sourceMappingURL=activity-log.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activity-log.model.js","sourceRoot":"/","sources":["libraries/mongo/models/activity-log.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"activity-log.model.js","sourceRoot":"/","sources":["libraries/mongo/models/activity-log.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAmF;AACnF,4EAAqE;AACrE,kDAAuD;AACvD,+CAAsC;AAQ/B,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,2BAAU;IAEnC,KAAK,CAAc;IAGnB,YAAY,CAAgB;IAG5B,WAAW,CAAO;IAGlB,WAAW,CAAO;CACzB,CAAA;AAZY,kCAAW;AAEhB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,mBAAK,EAAE,CAAC;;0CACjB;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAY,EAAE,CAAC;;iDACxB;AAG5B;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,oBAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;;gDACnC;AAGlB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,oBAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;;gDACnC;sBAXb,WAAW;IANvB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE;QAC7C,OAAO,EAAE;YACR,UAAU,EAAE,oBAAQ,CAAC,KAAK;SAC1B;KACD,CAAC;GACW,WAAW,CAYvB","sourcesContent":["import { modelOptions, prop, Severity, mongoose, Ref } from '@typegoose/typegoose';\r\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\r\nimport { UpdatedField } from '../../../utilities/enum';\r\nimport { Admin } from './admin.model';\r\n\r\n@modelOptions({\r\n\tschemaOptions: { collection: 'activityLogs' },\r\n\toptions: {\r\n\t\tallowMixed: Severity.ALLOW,\r\n\t},\r\n})\r\nexport class ActivityLog extends TimeStamps {\r\n\t@prop({ required: true, ref: () => Admin })\r\n\tpublic admin!: Ref<Admin>;\r\n\r\n\t@prop({ required: true, type: String, enum: UpdatedField })\r\n\tpublic updatedField!: UpdatedField;\r\n\r\n\t@prop({ required: true, type: mongoose.Schema.Types.Mixed })\r\n\tpublic oldDocument!: any;\r\n\r\n\t@prop({ required: true, type: mongoose.Schema.Types.Mixed })\r\n\tpublic newDocument!: any;\r\n}\r\n"]}
|
|
@@ -18,15 +18,15 @@ class ParentDocument {
|
|
|
18
18
|
}
|
|
19
19
|
exports.ParentDocument = ParentDocument;
|
|
20
20
|
__decorate([
|
|
21
|
-
(0, typegoose_1.prop)({
|
|
21
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
22
22
|
__metadata("design:type", String)
|
|
23
23
|
], ParentDocument.prototype, "commercialCircularDocument", void 0);
|
|
24
24
|
__decorate([
|
|
25
|
-
(0, typegoose_1.prop)({
|
|
25
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
26
26
|
__metadata("design:type", String)
|
|
27
27
|
], ParentDocument.prototype, "nationalId", void 0);
|
|
28
28
|
__decorate([
|
|
29
|
-
(0, typegoose_1.prop)({
|
|
29
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
30
30
|
__metadata("design:type", String)
|
|
31
31
|
], ParentDocument.prototype, "contractPaper", void 0);
|
|
32
32
|
//# sourceMappingURL=parent-document.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parent-document.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/parent-document.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,cAAc;IAEnB,0BAA0B,CAAU;IAGpC,UAAU,CAAU;IAGpB,aAAa,CAAU;CAC9B;AATD,wCASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"parent-document.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/parent-document.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,cAAc;IAEnB,0BAA0B,CAAU;IAGpC,UAAU,CAAU;IAGpB,aAAa,CAAU;CAC9B;AATD,wCASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;kEACoB;AAGpC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;kDACI;AAGpB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qDACO","sourcesContent":["import { prop } from '@typegoose/typegoose';\r\n\r\nexport class ParentDocument {\r\n\t@prop({ type: String })\r\n\tpublic commercialCircularDocument?: string;\r\n\r\n\t@prop({ type: String })\r\n\tpublic nationalId?: string;\r\n\r\n\t@prop({ type: String })\r\n\tpublic contractPaper?: string;\r\n}\r\n"]}
|
|
@@ -18,15 +18,15 @@ class ShopDocument {
|
|
|
18
18
|
}
|
|
19
19
|
exports.ShopDocument = ShopDocument;
|
|
20
20
|
__decorate([
|
|
21
|
-
(0, typegoose_1.prop)({
|
|
21
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
22
22
|
__metadata("design:type", String)
|
|
23
23
|
], ShopDocument.prototype, "commercialCircularDocument", void 0);
|
|
24
24
|
__decorate([
|
|
25
|
-
(0, typegoose_1.prop)({
|
|
25
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
26
26
|
__metadata("design:type", String)
|
|
27
27
|
], ShopDocument.prototype, "taxRegistration", void 0);
|
|
28
28
|
__decorate([
|
|
29
|
-
(0, typegoose_1.prop)({
|
|
29
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
30
30
|
__metadata("design:type", String)
|
|
31
31
|
], ShopDocument.prototype, "identityDoc", void 0);
|
|
32
32
|
//# sourceMappingURL=shop-document.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shop-document.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/shop-document.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,YAAY;IAEjB,0BAA0B,CAAU;IAGpC,eAAe,CAAU;IAGzB,WAAW,CAAU;CAC5B;AATD,oCASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"shop-document.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/shop-document.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,YAAY;IAEjB,0BAA0B,CAAU;IAGpC,eAAe,CAAU;IAGzB,WAAW,CAAU;CAC5B;AATD,oCASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gEACoB;AAGpC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qDACS;AAGzB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDACK","sourcesContent":["import { prop } from '@typegoose/typegoose';\r\n\r\nexport class ShopDocument {\r\n\t@prop({ type: String })\r\n\tpublic commercialCircularDocument?: string;\r\n\r\n\t@prop({ type: String })\r\n\tpublic taxRegistration?: string;\r\n\r\n\t@prop({ type: String })\r\n\tpublic identityDoc?: string;\r\n}\r\n"]}
|
|
@@ -18,7 +18,7 @@ export declare class Parent extends TimeStamps {
|
|
|
18
18
|
isServiceFeeCharged: boolean;
|
|
19
19
|
businessDevExecutive?: Ref<Admin>;
|
|
20
20
|
status?: Status;
|
|
21
|
-
profilePhoto
|
|
22
|
-
document
|
|
21
|
+
profilePhoto?: string;
|
|
22
|
+
document?: ParentDocument;
|
|
23
23
|
shopCount?: number;
|
|
24
24
|
}
|
|
@@ -81,11 +81,11 @@ __decorate([
|
|
|
81
81
|
__metadata("design:type", String)
|
|
82
82
|
], Parent.prototype, "status", void 0);
|
|
83
83
|
__decorate([
|
|
84
|
-
(0, typegoose_1.prop)({
|
|
84
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
85
85
|
__metadata("design:type", String)
|
|
86
86
|
], Parent.prototype, "profilePhoto", void 0);
|
|
87
87
|
__decorate([
|
|
88
|
-
(0, typegoose_1.prop)({
|
|
88
|
+
(0, typegoose_1.prop)({ type: parent_document_model_1.ParentDocument }),
|
|
89
89
|
__metadata("design:type", parent_document_model_1.ParentDocument)
|
|
90
90
|
], Parent.prototype, "document", void 0);
|
|
91
91
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parent.model.js","sourceRoot":"/","sources":["libraries/mongo/models/parent.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAgF;AAChF,4EAAqE;AACrE,kDAAuE;AACvE,+CAAsC;AACtC,0DAAiD;AACjD,4EAAkE;AAClE,0DAAiD;AACjD,4DAAmD;AACnD,6CAAoC;AAQ7B,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,2BAAU;IAE9B,IAAI,CAAU;IAGd,KAAK,CAAU;IAGf,WAAW,CAAU;IAGrB,OAAO,CAAW;IAGlB,UAAU,CAAc;IAGxB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iBAAI;QACf,YAAY,EAAE,QAAQ;QACtB,UAAU,EAAE,KAAK;QACjB,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;KAC1B,CAAC;;yCACwB;iBA/Cd,MAAM;IANlB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;QAClG,OAAO,EAAE;YACR,UAAU,EAAE,oBAAQ,CAAC,KAAK;SAC1B;KACD,CAAC;GACW,MAAM,CAgDlB","sourcesContent":["import { index, modelOptions, prop, Ref, Severity } from '@typegoose/typegoose';\r\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\r\nimport { ChargeType, ItemType, Status } from '../../../utilities/enum';\r\nimport { Admin } from './admin.model';\r\nimport { Charge } from './embedded/charge.model';\r\nimport { ParentDocument } from './embedded/parent-document.model';\r\nimport { Address } from './shared/address.model';\r\nimport { Duration } from './shared/duration.model';\r\nimport { Shop } from './shop.model';\r\n\r\n@modelOptions({\r\n\tschemaOptions: { collection: 'parents', toJSON: { virtuals: true }, toObject: { virtuals: true } },\r\n\toptions: {\r\n\t\tallowMixed: Severity.ALLOW,\r\n\t},\r\n})\r\nexport class Parent extends TimeStamps {\r\n\t@prop({ required: true, type: String, maxlength: 50 })\r\n\tpublic name!: string;\r\n\r\n\t@prop({ required: true, type: String })\r\n\tpublic email!: string;\r\n\r\n\t@prop({ required: true, type: String })\r\n\tpublic phoneNumber!: string;\r\n\r\n\t@prop({ required: true, type: Address })\r\n\tpublic address!: Address;\r\n\r\n\t@prop({ required: true, type: String, enum: ChargeType, default: ChargeType.CUSTOM })\r\n\tpublic chargeType!: ChargeType;\r\n\r\n\t@prop({ required: true, type: Charge })\r\n\tpublic charge!: Charge;\r\n\r\n\t@prop({ required: true, type: Duration })\r\n\tpublic commissionDuration!: Duration;\r\n\r\n\t@prop({ required: true, type: String, enum: ItemType })\r\n\tpublic itemType!: ItemType;\r\n\r\n\t@prop({ required: true, type: Boolean, default: true })\r\n\tpublic isServiceFeeCharged!: boolean;\r\n\r\n\t@prop({ ref: () => Admin })\r\n\tpublic businessDevExecutive?: Ref<Admin>;\r\n\r\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\r\n\tpublic status?: Status;\r\n\r\n\t@prop({ type: String })\r\n\tpublic profilePhoto?: string;\r\n\r\n\t@prop({ type: ParentDocument })\r\n\tpublic document?: ParentDocument;\r\n\r\n\t@prop({\r\n\t\tref: () => Shop,\r\n\t\tforeignField: 'parent',\r\n\t\tlocalField: '_id',\r\n\t\tcount: true,\r\n\t\tmatch: { deletedAt: null },\r\n\t})\r\n\tpublic shopCount?: number;\r\n}\r\n"]}
|
|
@@ -16,8 +16,8 @@ export declare class CourierOrder extends Order {
|
|
|
16
16
|
status?: CourierOrderStatus;
|
|
17
17
|
statusTimeline: CourierOrderStatusTimeline[];
|
|
18
18
|
courierType: CourierServiceType;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
pickupAddress: CourierAddress;
|
|
20
|
+
deliveryAddress: CourierAddress;
|
|
21
21
|
items?: CourierItem[];
|
|
22
22
|
}
|
|
23
23
|
export {};
|
|
@@ -57,8 +57,8 @@ class CourierOrder extends order_model_1.Order {
|
|
|
57
57
|
status;
|
|
58
58
|
statusTimeline;
|
|
59
59
|
courierType;
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
pickupAddress;
|
|
61
|
+
deliveryAddress;
|
|
62
62
|
items;
|
|
63
63
|
}
|
|
64
64
|
exports.CourierOrder = CourierOrder;
|
|
@@ -77,11 +77,11 @@ __decorate([
|
|
|
77
77
|
__decorate([
|
|
78
78
|
(0, typegoose_1.prop)({ required: true, type: () => address_model_1.CourierAddress }),
|
|
79
79
|
__metadata("design:type", address_model_1.CourierAddress)
|
|
80
|
-
], CourierOrder.prototype, "
|
|
80
|
+
], CourierOrder.prototype, "pickupAddress", void 0);
|
|
81
81
|
__decorate([
|
|
82
82
|
(0, typegoose_1.prop)({ required: true, type: address_model_1.CourierAddress }),
|
|
83
83
|
__metadata("design:type", address_model_1.CourierAddress)
|
|
84
|
-
], CourierOrder.prototype, "
|
|
84
|
+
], CourierOrder.prototype, "deliveryAddress", void 0);
|
|
85
85
|
__decorate([
|
|
86
86
|
(0, typegoose_1.prop)({ type: () => [CourierItem], default: [] }),
|
|
87
87
|
__metadata("design:type", Array)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"courier-order.model.js","sourceRoot":"/","sources":["libraries/mongo/models/providers/courier-order.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAC5C,gDAAuC;AACvC,qDAA+F;AAC/F,2DAAyD;AACzD,6EAA+E;AAE/E,MAAM,WAAW;IAEhB,WAAW,CAAS;IAGpB,YAAY,CAAU;IAGtB,QAAQ,CAAS;IAGjB,SAAS,CAAU;IAGnB,kBAAkB,CAAU;IAG5B,UAAU,CAAU;IAGpB,mBAAmB,CAAU;CAC7B;AAnBA;IADC,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACL;AAGpB;IADC,IAAA,gBAAI,GAAE;;iDACe;AAGtB;IADC,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;;6CAChB;AAGjB;IADC,IAAA,gBAAI,GAAE;;8CACY;AAGnB;IADC,IAAA,gBAAI,GAAE;;uDACqB;AAG5B;IADC,IAAA,gBAAI,GAAE;;+CACa;AAGpB;IADC,IAAA,gBAAI,GAAE;;wDACsB;AAG9B,MAAa,YAAa,SAAQ,mBAAK;IAC/B,SAAS,GAAG,gBAAS,CAAC,OAAgB,CAAC;IAGvC,MAAM,CAAsB;IAG5B,cAAc,CAA+B;IAGpD,WAAW,CAAsB;IAGjC,
|
|
1
|
+
{"version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EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAkB,EAAE,CAAC;;iDAChC;AAGjC;IADC,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,8BAAc,EAAE,CAAC;8BACrC,8BAAc;mDAAC;AAG/B;IADC,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,8BAAc,EAAE,CAAC;8BAC7B,8BAAc;qDAAC;AAGjC;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;2CAC3B","sourcesContent":["import { prop } from '@typegoose/typegoose';\r\nimport { Order } from '../order.model';\r\nimport { CourierOrderStatus, CourierServiceType, OrderType } from '../../../../utilities/enum';\r\nimport { CourierAddress } from '../shared/address.model';\r\nimport { CourierOrderStatusTimeline } from '../embedded/status-timeline.model';\r\n\r\nclass CourierItem {\r\n\t@prop({ required: true })\r\n\tproductName: string;\r\n\r\n\t@prop()\r\n\tproductImage?: string;\r\n\r\n\t@prop({ required: true, min: 1 })\r\n\tquantity: number;\r\n\r\n\t@prop()\r\n\tunitPrice?: number;\r\n\r\n\t@prop()\r\n\tsecondaryUnitPrice?: number;\r\n\r\n\t@prop()\r\n\ttotalPrice?: number;\r\n\r\n\t@prop()\r\n\tsecondaryTotalPrice?: number;\r\n}\r\n\r\nexport class CourierOrder extends Order {\r\n\tpublic orderType = OrderType.COURIER as const;\r\n\r\n\t@prop({ type: String, enum: CourierOrderStatus, default: CourierOrderStatus.PLACED })\r\n\tpublic status?: CourierOrderStatus;\r\n\r\n\t@prop({ type: () => [CourierOrderStatusTimeline], default: [] })\r\n\tpublic statusTimeline: CourierOrderStatusTimeline[];\r\n\r\n\t@prop({ required: true, type: String, enum: CourierServiceType })\r\n\tcourierType!: CourierServiceType;\r\n\r\n\t@prop({ required: true, type: () => CourierAddress })\r\n\tpickupAddress!: CourierAddress;\r\n\r\n\t@prop({ required: true, type: CourierAddress })\r\n\tdeliveryAddress!: CourierAddress;\r\n\r\n\t@prop({ type: () => [CourierItem], default: [] })\r\n\titems?: CourierItem[];\r\n}\r\n"]}
|
|
@@ -11,8 +11,8 @@ export declare class RegularOrder extends Order {
|
|
|
11
11
|
status?: string;
|
|
12
12
|
statusTimeline: RegularOrderStatusTimeline[];
|
|
13
13
|
itemType?: string;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
pickupAddress: Address;
|
|
15
|
+
deliveryAddress: UserAddress;
|
|
16
16
|
parent?: Ref<Parent>;
|
|
17
17
|
shop?: Ref<Shop>;
|
|
18
18
|
cart?: Ref<Cart>;
|
|
@@ -23,8 +23,8 @@ class RegularOrder extends order_model_1.Order {
|
|
|
23
23
|
status;
|
|
24
24
|
statusTimeline;
|
|
25
25
|
itemType;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
pickupAddress;
|
|
27
|
+
deliveryAddress;
|
|
28
28
|
parent;
|
|
29
29
|
shop;
|
|
30
30
|
cart;
|
|
@@ -49,11 +49,11 @@ __decorate([
|
|
|
49
49
|
__decorate([
|
|
50
50
|
(0, typegoose_1.prop)({ required: true, type: address_model_1.Address }),
|
|
51
51
|
__metadata("design:type", address_model_1.Address)
|
|
52
|
-
], RegularOrder.prototype, "
|
|
52
|
+
], RegularOrder.prototype, "pickupAddress", void 0);
|
|
53
53
|
__decorate([
|
|
54
54
|
(0, typegoose_1.prop)({ required: true, type: address_model_1.UserAddress }),
|
|
55
55
|
__metadata("design:type", address_model_1.UserAddress)
|
|
56
|
-
], RegularOrder.prototype, "
|
|
56
|
+
], RegularOrder.prototype, "deliveryAddress", void 0);
|
|
57
57
|
__decorate([
|
|
58
58
|
(0, typegoose_1.prop)({ ref: () => parent_model_1.Parent }),
|
|
59
59
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regular-order.model.js","sourceRoot":"/","sources":["libraries/mongo/models/providers/regular-order.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,gDAAuC;AACvC,qDAAqF;AACrF,kDAAyC;AACzC,8CAAqC;AACrC,8CAAqC;AACrC,2DAA+D;AAC/D,6EAA+E;AAE/E,MAAa,YAAa,SAAQ,mBAAK;IAC/B,SAAS,GAAG,gBAAS,CAAC,OAAgB,CAAC;IAGvC,MAAM,CAAU;IAGhB,cAAc,CAA+B;IAGpD,QAAQ,CAAU;IAGlB,
|
|
1
|
+
{"version":3,"file":"regular-order.model.js","sourceRoot":"/","sources":["libraries/mongo/models/providers/regular-order.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,gDAAuC;AACvC,qDAAqF;AACrF,kDAAyC;AACzC,8CAAqC;AACrC,8CAAqC;AACrC,2DAA+D;AAC/D,6EAA+E;AAE/E,MAAa,YAAa,SAAQ,mBAAK;IAC/B,SAAS,GAAG,gBAAS,CAAC,OAAgB,CAAC;IAGvC,MAAM,CAAU;IAGhB,cAAc,CAA+B;IAGpD,QAAQ,CAAU;IAGlB,aAAa,CAAU;IAGvB,eAAe,CAAc;IAG7B,MAAM,CAAe;IAGrB,IAAI,CAAa;IAGjB,IAAI,CAAa;IAGV,cAAc,CAAW;IAGzB,sBAAsB,CAAU;IAGhC,kBAAkB,CAAW;IAG7B,2BAA2B,CAAc;CAChD;AAtCD,oCAsCC;AAlCO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAkB,EAAE,OAAO,EAAE,yBAAkB,CAAC,MAAM,EAAE,CAAC;;4CAC9D;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,kDAA0B,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;oDACZ;AAGpD;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAQ,EAAE,OAAO,EAAE,eAAQ,CAAC,IAAI,EAAE,CAAC;;8CAC7C;AAGlB;IADC,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,uBAAO,EAAE,CAAC;8BACzB,uBAAO;mDAAC;AAGvB;IADC,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,2BAAW,EAAE,CAAC;8BAC3B,2BAAW;qDAAC;AAG7B;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,qBAAM,EAAE,CAAC;;4CACP;AAGrB;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;0CACT;AAGjB;IADC,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;0CACT;AAGV;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;oDACR;AAGzB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;4DACI;AAGhC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;wDACJ;AAG7B;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,mBAAK,EAAE,CAAC;;iEACqB","sourcesContent":["import { prop, Ref } from '@typegoose/typegoose';\r\nimport { Order } from '../order.model';\r\nimport { ItemType, OrderType, RegularOrderStatus } from '../../../../utilities/enum';\r\nimport { Parent } from '../parent.model';\r\nimport { Shop } from '../shop.model';\r\nimport { Cart } from '../cart.model';\r\nimport { Address, UserAddress } from '../shared/address.model';\r\nimport { RegularOrderStatusTimeline } from '../embedded/status-timeline.model';\r\n\r\nexport class RegularOrder extends Order {\r\n\tpublic orderType = OrderType.REGULAR as const;\r\n\r\n\t@prop({ type: String, enum: RegularOrderStatus, default: RegularOrderStatus.PLACED })\r\n\tpublic status?: string;\r\n\r\n\t@prop({ type: () => [RegularOrderStatusTimeline], default: [] })\r\n\tpublic statusTimeline: RegularOrderStatusTimeline[];\r\n\r\n\t@prop({ type: String, enum: ItemType, default: ItemType.FOOD })\r\n\titemType?: string;\r\n\r\n\t@prop({ required: true, type: Address })\r\n\tpickupAddress: Address;\r\n\r\n\t@prop({ required: true, type: UserAddress })\r\n\tdeliveryAddress: UserAddress;\r\n\r\n\t@prop({ ref: () => Parent })\r\n\tparent?: Ref<Parent>;\r\n\r\n\t@prop({ ref: () => Shop })\r\n\tshop?: Ref<Shop>;\r\n\r\n\t@prop({ ref: () => Cart })\r\n\tcart?: Ref<Cart>;\r\n\r\n\t@prop({ type: Boolean, default: false })\r\n\tpublic isShopDelivery?: boolean;\r\n\r\n\t@prop({ type: Number, default: 0 })\r\n\tpublic preparingTimeInMinutes?: number;\r\n\r\n\t@prop({ type: Boolean, default: false })\r\n\tpublic isReplacementOrder?: boolean;\r\n\r\n\t@prop({ ref: () => Order })\r\n\tpublic originalOrderForReplacement?: Ref<Order>;\r\n}\r\n"]}
|
|
@@ -22,6 +22,11 @@ __decorate([
|
|
|
22
22
|
__metadata("design:type", Object)
|
|
23
23
|
], RiderReview.prototype, "rider", void 0);
|
|
24
24
|
exports.RiderReview = RiderReview = __decorate([
|
|
25
|
-
(0, typegoose_1.modelOptions)({
|
|
25
|
+
(0, typegoose_1.modelOptions)({
|
|
26
|
+
schemaOptions: { collection: 'riderReviews' },
|
|
27
|
+
options: {
|
|
28
|
+
allowMixed: typegoose_1.Severity.ALLOW,
|
|
29
|
+
},
|
|
30
|
+
})
|
|
26
31
|
], RiderReview);
|
|
27
32
|
//# sourceMappingURL=rider-review.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rider-review.model.js","sourceRoot":"/","sources":["libraries/mongo/models/rider-review.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"rider-review.model.js","sourceRoot":"/","sources":["libraries/mongo/models/rider-review.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAyE;AACzE,gEAAsD;AACtD,+CAAsC;AAQ/B,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,8BAAU;IAEnC,KAAK,CAAc;CAC1B,CAAA;AAHY,kCAAW;AAEhB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,mBAAK,EAAE,CAAC;;0CACnB;sBAFd,WAAW;IANvB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE;QAC7C,OAAO,EAAE;YACR,UAAU,EAAE,oBAAQ,CAAC,KAAK;SAC1B;KACD,CAAC;GACW,WAAW,CAGvB","sourcesContent":["import { modelOptions, Severity, prop, Ref } from '@typegoose/typegoose';\r\nimport { BaseReview } from './base/base-review.model';\r\nimport { Rider } from './rider.model';\r\n\r\n@modelOptions({\r\n\tschemaOptions: { collection: 'riderReviews' },\r\n\toptions: {\r\n\t\tallowMixed: Severity.ALLOW,\r\n\t},\r\n})\r\nexport class RiderReview extends BaseReview {\r\n\t@prop({ required: true, Rider: () => Rider })\r\n\tpublic rider!: Ref<Rider>;\r\n}\r\n"]}
|
|
@@ -21,9 +21,9 @@ export declare class Shop extends TimeStamps {
|
|
|
21
21
|
additionalPhoneNumbers?: string[];
|
|
22
22
|
address: Address;
|
|
23
23
|
zone: Ref<Zone>;
|
|
24
|
-
logo
|
|
25
|
-
banner
|
|
26
|
-
document
|
|
24
|
+
logo?: string;
|
|
25
|
+
banner?: string;
|
|
26
|
+
document?: ShopDocument;
|
|
27
27
|
isBeirutAuthentic: boolean;
|
|
28
28
|
isVisibleToUser: boolean;
|
|
29
29
|
status: Status;
|
|
@@ -110,15 +110,15 @@ __decorate([
|
|
|
110
110
|
__metadata("design:type", Object)
|
|
111
111
|
], Shop.prototype, "zone", void 0);
|
|
112
112
|
__decorate([
|
|
113
|
-
(0, typegoose_1.prop)({
|
|
113
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
114
114
|
__metadata("design:type", String)
|
|
115
115
|
], Shop.prototype, "logo", void 0);
|
|
116
116
|
__decorate([
|
|
117
|
-
(0, typegoose_1.prop)({
|
|
117
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
118
118
|
__metadata("design:type", String)
|
|
119
119
|
], Shop.prototype, "banner", void 0);
|
|
120
120
|
__decorate([
|
|
121
|
-
(0, typegoose_1.prop)({
|
|
121
|
+
(0, typegoose_1.prop)({ type: shop_document_model_1.ShopDocument }),
|
|
122
122
|
__metadata("design:type", shop_document_model_1.ShopDocument)
|
|
123
123
|
], Shop.prototype, "document", void 0);
|
|
124
124
|
__decorate([
|
|
@@ -221,6 +221,7 @@ exports.Shop = Shop = __decorate([
|
|
|
221
221
|
(0, typegoose_1.modelOptions)({
|
|
222
222
|
schemaOptions: { collection: 'shops' },
|
|
223
223
|
options: { allowMixed: typegoose_1.Severity.ALLOW },
|
|
224
|
-
})
|
|
224
|
+
}),
|
|
225
|
+
(0, typegoose_1.Index)({ name: 1, itemType: 1 }, { unique: true, partialFilterExpression: { deletedAt: null } })
|
|
225
226
|
], Shop);
|
|
226
227
|
//# sourceMappingURL=shop.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shop.model.js","sourceRoot":"/","sources":["libraries/mongo/models/shop.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"shop.model.js","sourceRoot":"/","sources":["libraries/mongo/models/shop.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAgF;AAChF,4EAAqE;AACrE,kDAA6E;AAC7E,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,MAAM,EAAE,CAAC;;qDACN;AAGjC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;0CACN;eAtHjB,IAAI;IARhB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE;QACtC,OAAO,EAAE,EAAE,UAAU,EAAE,oBAAQ,CAAC,KAAK,EAAE;KACvC,CAAC;IACD,IAAA,iBAAK,EACL,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EACxB,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAC,EAAE,CAC7D;GACY,IAAI,CAuHhB","sourcesContent":["import { modelOptions, prop, Ref, Severity, Index } from '@typegoose/typegoose';\r\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\r\nimport { ItemType, ShopOnlineStatus, Status } from '../../../utilities/enum';\r\nimport { Brand } from './brand.model';\r\nimport { ShopDocument } from './embedded/shop-document.model';\r\nimport { Parent } from './parent.model';\r\nimport { Address } from './shared/address.model';\r\nimport { StartEndTime, WorkHourSetting } from './shared/work-hour.model';\r\nimport { Tag } from './tag.model';\r\nimport { Zone } from './zone.model';\r\n\r\n\r\n@modelOptions({\r\n\tschemaOptions: { collection: 'shops' },\r\n\toptions: { allowMixed: Severity.ALLOW },\r\n})\r\n@Index(\r\n\t{ name: 1, itemType: 1 },\r\n\t{ unique: true, partialFilterExpression: { deletedAt: null} }\r\n)\r\nexport class Shop extends TimeStamps {\r\n\t@prop({ required: true, unique: true, type: String })\r\n\tpublic slug!: string;\r\n\r\n\t@prop({ required: true, ref: () => Parent })\r\n\tpublic parent: Ref<Parent>;\r\n\r\n\t@prop({ required: true, type: String, enum: ItemType })\r\n\tpublic itemType!: ItemType;\r\n\r\n\t@prop({ required: true, type: String })\r\n\tpublic name!: string;\r\n\r\n\t@prop({ required: true, ref: () => Brand })\r\n\tpublic brand: Ref<Brand>;\r\n\r\n\t@prop({ required: true, type: String })\r\n\tpublic ownerName!: string;\r\n\r\n\t@prop({ required: true, type: String })\r\n\tpublic email!: string;\r\n\r\n\t@prop({ required: true, type: String })\r\n\tpublic phoneNumber!: string;\r\n\r\n\t@prop({ required: true, type: String })\r\n\tpublic userPhoneNumber!: string;\r\n\r\n\t@prop({ type: () => [String], default: [] })\r\n\tpublic additionalPhoneNumbers?: string[];\r\n\r\n\t@prop({ required: true, type: Address })\r\n\tpublic address!: Address;\r\n\r\n\t@prop({ required: true, ref: () => Zone })\r\n\tpublic zone!: Ref<Zone>;\r\n\r\n\t@prop({ type: String })\r\n\tpublic logo?: string;\r\n\r\n\t@prop({ type: String })\r\n\tpublic banner?: string;\r\n\r\n\t@prop({ type: ShopDocument })\r\n\tpublic document?: ShopDocument;\r\n\r\n\t@prop({ required: true, type: Boolean })\r\n\tpublic isBeirutAuthentic!: boolean;\r\n\r\n\t@prop({ required: true, type: Boolean })\r\n\tpublic isVisibleToUser!: boolean;\r\n\r\n\t@prop({ required: true, type: String, enum: Status, default: Status.ACTIVE })\r\n\tpublic status!: Status;\r\n\r\n\t@prop({\r\n\t\ttype: String,\r\n\t\tenum: ShopOnlineStatus,\r\n\t\tdefault: ShopOnlineStatus.OFFLINE,\r\n\t})\r\n\tpublic onlineStatus?: ShopOnlineStatus;\r\n\r\n\t// Setting\r\n\t@prop({ type: Boolean, default: false })\r\n\tpublic allowSpecialInstructions?: boolean;\r\n\r\n\t@prop({ type: Boolean, default: false })\r\n\tpublic isRiderNoteVisible?: boolean;\r\n\r\n\t@prop({ type: String })\r\n\tpublic riderNote?: string;\r\n\r\n\t@prop({ type: Number, default: 1, min: 1, max: 4 })\r\n\tpublic priceRange?: number;\r\n\r\n\t@prop({ type: () => [String], default: [] })\r\n\tpublic dietaries?: string[];\r\n\r\n\t@prop({ ref: () => Tag, default: [] })\r\n\tpublic tags?: Ref<Tag>[];\r\n\r\n\t@prop({ type: Boolean, default: false })\r\n\tpublic isShopDelivery?: boolean;\r\n\r\n\t@prop({ type: Number })\r\n\tpublic deliveryFee?: number;\r\n\r\n\t@prop({ type: Number, default: 0 })\r\n\tpublic minimumOrderAmount?: number;\r\n\r\n\t@prop({ type: Number, default: Infinity })\r\n\tpublic orderCapacity?: number;\r\n\r\n\t@prop({ type: Number, default: 10 })\r\n\tpublic defaultPreparationTime?: number;\r\n\r\n\t@prop({ type: Number, default: null })\r\n\texchangeRate?: number;\r\n\r\n\t@prop({ type: WorkHourSetting })\r\n\tpublic workHourSetting?: WorkHourSetting;\r\n\r\n\t@prop({ type: () => [StartEndTime], default: []})\r\n\tpublic shopActiveTimingsOfCurrentDate?: StartEndTime[];\r\n\r\n\t@prop({ required: false, type: () => Boolean })\r\n\tpublic isFavouriteCategoryVisible?: boolean;\r\n\r\n\t@prop({ required: false, type: () => String })\r\n\tpublic favouriteCategoryTitle?: string;\r\n\r\n\t@prop({ required: false, type: () => Boolean })\r\n\tpublic isBestSellerCategoryVisible?: boolean;\r\n\r\n\t@prop({ required: false, type: () => String })\r\n\tpublic bestSellerCategoryTitle?: string;\r\n\r\n\t@prop({ type: Number, default: 0 })\r\n\tpublic sortingOrder?: number;\r\n}"]}
|
|
@@ -5,11 +5,11 @@ function corsMiddleware(options = {}) {
|
|
|
5
5
|
const config = {
|
|
6
6
|
origin: options.origin || '*',
|
|
7
7
|
methods: options.methods || ['GET, POST, OPTIONS'],
|
|
8
|
-
allowedHeaders: options.allowedHeaders || ['Content-Type', 'Authorization', 'X-Requested-With'],
|
|
9
|
-
exposedHeaders: options.exposedHeaders || ['Content-Range', 'X-Content-Range'],
|
|
10
8
|
credentials: options.credentials || false,
|
|
11
9
|
maxAge: options.maxAge || 86400,
|
|
12
10
|
preflightContinue: options.preflightContinue || false,
|
|
11
|
+
allowedHeaders: options.allowedHeaders || ['Content-Type', 'Authorization', 'X-Requested-With', 'x-refresh-token'],
|
|
12
|
+
exposedHeaders: options.exposedHeaders || ['Content-Range', 'X-Content-Range', 'X-New-Access-Token', 'X-New-Refresh-Token'],
|
|
13
13
|
};
|
|
14
14
|
const methodsString = Array.isArray(config.methods) ? config.methods.join(', ') : config.methods;
|
|
15
15
|
const allowedHeadersString = Array.isArray(config.allowedHeaders)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.js","sourceRoot":"/","sources":["libraries/trpc/middlewares/cors.ts"],"names":[],"mappings":";;AAqBA,wCA6DC;AA7DD,SAAgB,cAAc,CAAC,UAAuB,EAAE;IAEvD,MAAM,MAAM,GAA0B;QACrC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,GAAG;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,oBAAoB,CAAC;QAClD,
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"/","sources":["libraries/trpc/middlewares/cors.ts"],"names":[],"mappings":";;AAqBA,wCA6DC;AA7DD,SAAgB,cAAc,CAAC,UAAuB,EAAE;IAEvD,MAAM,MAAM,GAA0B;QACrC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,GAAG;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,oBAAoB,CAAC;QAClD,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;QAC/B,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,KAAK;QACrD,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,iBAAiB,CAAC;QAClH,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC,eAAe,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,qBAAqB,CAAC;KAC3H,CAAC;IAGF,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO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AAC;gBAC9B,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBACnB,GAAG,CAAC,GAAG,EAAE,CAAC;gBACV,OAAO;YACR,CAAC;YAGD,IAAI,EAAE,CAAC;QACR,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEhB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;YAE/C,IAAI,EAAE,CAAC;QACR,CAAC;IACF,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { IncomingMessage, ServerResponse } from 'http';\r\n\r\n/**\r\n * Interface for CORS middleware options\r\n */\r\ninterface CorsOptions {\r\n\torigin?: string | string[];\r\n\tmethods?: string[];\r\n\tallowedHeaders?: string[];\r\n\texposedHeaders?: string[];\r\n\tcredentials?: boolean;\r\n\tmaxAge?: number;\r\n\tpreflightContinue?: boolean;\r\n}\r\n\r\n/**\r\n * Creates a configurable CORS middleware for tRPC applications\r\n *\r\n * @param options Configuration options for CORS\r\n * @returns A middleware function for handling CORS\r\n */\r\nexport function corsMiddleware(options: CorsOptions = {}) {\r\n\t// Default configuration with sensible values\r\n\tconst config: Required<CorsOptions> = {\r\n\t\torigin: options.origin || '*',\r\n\t\tmethods: options.methods || ['GET, POST, OPTIONS'],\r\n\t\tcredentials: options.credentials || false,\r\n\t\tmaxAge: options.maxAge || 86400, // 24 hours\r\n\t\tpreflightContinue: options.preflightContinue || false,\r\n\t\tallowedHeaders: options.allowedHeaders || ['Content-Type', 'Authorization', 'X-Requested-With', 'x-refresh-token'],\r\n\t\texposedHeaders: options.exposedHeaders || ['Content-Range', 'X-Content-Range', 'X-New-Access-Token', 'X-New-Refresh-Token'],\r\n\t};\r\n\r\n\t// Convert arrays to comma-separated strings for header values\r\n\tconst methodsString = Array.isArray(config.methods) ? config.methods.join(', ') : config.methods;\r\n\tconst allowedHeadersString = Array.isArray(config.allowedHeaders)\r\n\t\t? config.allowedHeaders.join(', ')\r\n\t\t: config.allowedHeaders;\r\n\tconst exposedHeadersString = Array.isArray(config.exposedHeaders)\r\n\t\t? config.exposedHeaders.join(', ')\r\n\t\t: config.exposedHeaders;\r\n\r\n\t// Return the middleware function\r\n\treturn (req: IncomingMessage, res: ServerResponse, next: () => void) => {\r\n\t\ttry {\r\n\t\t\t// Always set the CORS headers\r\n\t\t\tres.setHeader('Access-Control-Allow-Origin', config.origin);\r\n\r\n\t\t\t// Only set other headers if origin is not blocking the request\r\n\t\t\tif (config.origin !== 'none') {\r\n\t\t\t\tres.setHeader('Access-Control-Allow-Methods', methodsString);\r\n\t\t\t\tres.setHeader('Access-Control-Allow-Headers', allowedHeadersString);\r\n\r\n\t\t\t\tif (exposedHeadersString) {\r\n\t\t\t\t\tres.setHeader('Access-Control-Expose-Headers', exposedHeadersString);\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (config.credentials) {\r\n\t\t\t\t\tres.setHeader('Access-Control-Allow-Credentials', 'true');\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (config.maxAge) {\r\n\t\t\t\t\tres.setHeader('Access-Control-Max-Age', config.maxAge.toString());\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Handle OPTIONS preflight requests\r\n\t\t\tif (req.method === 'OPTIONS') {\r\n\t\t\t\tres.writeHead(204); // 204 No Content is more appropriate for preflight\r\n\t\t\t\tres.end();\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\t// Move to the next middleware\r\n\t\t\tnext();\r\n\t\t} catch (error) {\r\n\t\t\t// Handle any errors that might occur\r\n\t\t\tconsole.error('CORS middleware error:', error);\r\n\t\t\t// Call next without the error as it expects no arguments\r\n\t\t\tnext();\r\n\t\t}\r\n\t};\r\n}\r\n"]}
|
|
@@ -21,5 +21,25 @@ export declare class UploadService {
|
|
|
21
21
|
}>>;
|
|
22
22
|
downloadFile(filename: string): Promise<Buffer>;
|
|
23
23
|
deleteFile(filename: string): Promise<void>;
|
|
24
|
+
extractFilenameFromUrl(url: string): string;
|
|
25
|
+
deleteFileByUrl(url: string): Promise<void>;
|
|
24
26
|
downloadImage(url: string): Promise<Buffer>;
|
|
27
|
+
private uploadToGCS;
|
|
28
|
+
uploadProcessedImageToWebp(buffer: Buffer, originalFilename: string, options?: {
|
|
29
|
+
quality?: number;
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
filename: string;
|
|
34
|
+
url: string;
|
|
35
|
+
}>;
|
|
36
|
+
uploadFile(buffer: Buffer, originalFilename: string, options?: {
|
|
37
|
+
quality?: number;
|
|
38
|
+
width?: number;
|
|
39
|
+
height?: number;
|
|
40
|
+
withExtension?: boolean;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
filename: string;
|
|
43
|
+
url: string;
|
|
44
|
+
}>;
|
|
25
45
|
}
|
|
@@ -9,6 +9,7 @@ const sharp_1 = __importDefault(require("sharp"));
|
|
|
9
9
|
const moment_1 = __importDefault(require("moment"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const index_1 = require("../../index");
|
|
12
|
+
const mime_types_1 = __importDefault(require("mime-types"));
|
|
12
13
|
function makeSlug(input) {
|
|
13
14
|
return input
|
|
14
15
|
.toLowerCase()
|
|
@@ -25,13 +26,13 @@ class UploadService {
|
|
|
25
26
|
this.bucket = (0, index_1.getLibraries)().getFirebaseService().superApp.storage().bucket(bucketName);
|
|
26
27
|
this.websiteName = 'lyxa-' + (0, index_1.getLibraries)().getConfigurationService().options.tenet;
|
|
27
28
|
}
|
|
28
|
-
generateFilename(originalFilename) {
|
|
29
|
+
generateFilename(originalFilename, extension) {
|
|
29
30
|
const nameWithoutExt = path_1.default.parse(originalFilename).name;
|
|
30
|
-
const
|
|
31
|
+
const newExtension = extension || path_1.default.extname(originalFilename);
|
|
31
32
|
const timestamp = (0, moment_1.default)().format('DDMMYYHmmss');
|
|
32
33
|
const randomId = Math.floor(Math.random() * 100);
|
|
33
34
|
const baseName = `${makeSlug(nameWithoutExt)}-${this.websiteName}-${timestamp}-${randomId}`;
|
|
34
|
-
return baseName +
|
|
35
|
+
return baseName + newExtension;
|
|
35
36
|
}
|
|
36
37
|
async uploadImage(buffer, originalFilename) {
|
|
37
38
|
const newFilename = this.generateFilename(originalFilename);
|
|
@@ -127,10 +128,99 @@ class UploadService {
|
|
|
127
128
|
}
|
|
128
129
|
await file.delete();
|
|
129
130
|
}
|
|
131
|
+
extractFilenameFromUrl(url) {
|
|
132
|
+
try {
|
|
133
|
+
const urlObj = new URL(url);
|
|
134
|
+
const pathParts = urlObj.pathname.split('/');
|
|
135
|
+
return decodeURIComponent(pathParts[pathParts.length - 1]);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async deleteFileByUrl(url) {
|
|
142
|
+
const filename = this.extractFilenameFromUrl(url);
|
|
143
|
+
const file = this.bucket.file(filename);
|
|
144
|
+
const [exists] = await file.exists();
|
|
145
|
+
if (!exists) {
|
|
146
|
+
throw new Error('File does not exist.');
|
|
147
|
+
}
|
|
148
|
+
await file.delete();
|
|
149
|
+
}
|
|
130
150
|
async downloadImage(url) {
|
|
131
151
|
const response = await axios_1.default.get(url, { responseType: 'arraybuffer' });
|
|
132
152
|
return Buffer.from(response.data, 'binary');
|
|
133
153
|
}
|
|
154
|
+
async uploadToGCS(buffer, filename, contentType) {
|
|
155
|
+
const file = this.bucket.file(filename);
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
const blobStream = file.createWriteStream({
|
|
158
|
+
resumable: false,
|
|
159
|
+
contentType,
|
|
160
|
+
});
|
|
161
|
+
blobStream.on('error', reject);
|
|
162
|
+
blobStream.on('finish', async () => {
|
|
163
|
+
try {
|
|
164
|
+
await file.makePublic();
|
|
165
|
+
const publicUrl = `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;
|
|
166
|
+
resolve({ filename: file.name, url: publicUrl });
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
reject(err);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
blobStream.end(buffer);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
async uploadProcessedImageToWebp(buffer, originalFilename, options) {
|
|
176
|
+
const newFilename = this.generateFilename(originalFilename, '.webp');
|
|
177
|
+
let width = options?.width;
|
|
178
|
+
let height = options?.height;
|
|
179
|
+
const quality = options?.quality ?? 80;
|
|
180
|
+
if (!width || !height) {
|
|
181
|
+
const imageMetadata = await (0, sharp_1.default)(buffer).metadata();
|
|
182
|
+
width = width || imageMetadata.width;
|
|
183
|
+
height = height || imageMetadata.height;
|
|
184
|
+
}
|
|
185
|
+
const processedImage = (0, sharp_1.default)(buffer)
|
|
186
|
+
.resize(width, height, { fit: 'inside' })
|
|
187
|
+
.webp({ quality });
|
|
188
|
+
const file = this.bucket.file(newFilename);
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
const blobStream = file.createWriteStream({
|
|
191
|
+
resumable: false,
|
|
192
|
+
contentType: 'image/webp',
|
|
193
|
+
});
|
|
194
|
+
blobStream.on('error', (err) => {
|
|
195
|
+
reject(err);
|
|
196
|
+
});
|
|
197
|
+
blobStream.on('finish', async () => {
|
|
198
|
+
try {
|
|
199
|
+
await file.makePublic();
|
|
200
|
+
const publicUrl = `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;
|
|
201
|
+
resolve({ filename: file.name, url: publicUrl });
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
reject(err);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
processedImage.pipe(blobStream);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
async uploadFile(buffer, originalFilename, options) {
|
|
211
|
+
const newFilename = this.generateFilename(originalFilename);
|
|
212
|
+
const extension = path_1.default.extname(newFilename).toLowerCase();
|
|
213
|
+
const contentType = mime_types_1.default.lookup(extension) || 'application/octet-stream';
|
|
214
|
+
if (contentType.startsWith('image/')) {
|
|
215
|
+
if (options?.withExtension) {
|
|
216
|
+
return this.uploadImage(buffer, originalFilename);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return this.uploadProcessedImageToWebp(buffer, originalFilename, options);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return this.uploadToGCS(buffer, newFilename, contentType);
|
|
223
|
+
}
|
|
134
224
|
}
|
|
135
225
|
exports.UploadService = UploadService;
|
|
136
226
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/upload/index.ts"],"names":[],"mappings":";;;;;;AACA,kDAA0B;AAC1B,kDAA0C;AAC1C,oDAA4B;AAC5B,gDAAwB;AAIxB,uCAA2C;AAE3C,SAAS,QAAQ,CAAC,KAAa;IAC9B,OAAO,KAAK;SACV,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC3B,CAAC;AAED,MAAa,aAAa;IACjB,MAAM,CAAC;IACE,WAAW,CAAC;IAE7B,YAAY,UAAmB;QAC9B,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,UAAU,GAAG,aAAa,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,IAAA,oBAAY,GAAE,CAAC,kBAAkB,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACxF,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,IAAA,oBAAY,GAAE,CAAC,uBAAuB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACrF,CAAC;IAKO,gBAAgB,CAAC,gBAAwB;QAChD,MAAM,cAAc,GAAG,cAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;QACzD,MAAM,SAAS,GAAG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AM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACzC,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,GAAW;QAC9B,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC,CAAC;QACvE,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;CACD;AA9JD,sCA8JC","sourcesContent":["import { Storage } from '@google-cloud/storage';\r\nimport axios from 'axios';\r\nimport sharp, { FormatEnum } from 'sharp';\r\nimport moment from 'moment';\r\nimport path from 'path';\r\nimport { Service } from 'typedi';\r\nimport { ConfigurationService } from '../configuration';\r\nimport { FirebaseService } from '../firebase';\r\nimport { getLibraries } from '../../index';\r\n\r\nfunction makeSlug(input: string): string {\r\n\treturn input\r\n\t\t.toLowerCase()\r\n\t\t.replace(/[^a-z0-9]+/g, '-')\r\n\t\t.replace(/(^-|-$)/g, '');\r\n}\r\n\r\nexport class UploadService {\r\n\tprivate bucket;\r\n\tprivate readonly websiteName;\r\n\r\n\tconstructor(bucketName?: string) {\r\n\t\tif (!bucketName) {\r\n\t\t\tbucketName = 'lyxa-global';\r\n\t\t}\r\n\r\n\t\tthis.bucket = getLibraries().getFirebaseService().superApp.storage().bucket(bucketName);\r\n\t\tthis.websiteName = 'lyxa-' + getLibraries().getConfigurationService().options.tenet;\r\n\t}\r\n\r\n\t/**\r\n\t * Generates a unique filename using the original filename.\r\n\t */\r\n\tprivate generateFilename(originalFilename: string): string {\r\n\t\tconst nameWithoutExt = path.parse(originalFilename).name;\r\n\t\tconst extension = path.extname(originalFilename);\r\n\t\tconst timestamp = moment().format('DDMMYYHmmss');\r\n\t\tconst randomId = Math.floor(Math.random() * 100);\r\n\t\tconst baseName = `${makeSlug(nameWithoutExt)}-${this.websiteName}-${timestamp}-${randomId}`;\r\n\t\treturn baseName + extension;\r\n\t}\r\n\r\n\t/**\r\n\t * Uploads an image buffer after processing it with Sharp.\r\n\t * An optional destinationPath can be provided (e.g., 'images/product.jpg').\r\n\t */\r\n\tasync uploadImage(buffer: Buffer, originalFilename: string): Promise<{ filename: string; url: string }> {\r\n\t\tconst newFilename = this.generateFilename(originalFilename);\r\n\t\tconst extension = path.extname(newFilename).toLowerCase();\r\n\t\tlet processedImage: sharp.Sharp;\r\n\t\tlet contentType: string;\r\n\t\tif (extension === '.png') {\r\n\t\t\tprocessedImage = sharp(buffer).png({ quality: 80 });\r\n\t\t\tcontentType = 'image/png';\r\n\t\t} else if (extension === '.webp') {\r\n\t\t\tprocessedImage = sharp(buffer).webp({ quality: 80 });\r\n\t\t\tcontentType = 'image/webp';\r\n\t\t} else {\r\n\t\t\tprocessedImage = sharp(buffer).jpeg({ quality: 80 });\r\n\t\t\tcontentType = 'image/jpeg';\r\n\t\t}\r\n\r\n\t\tconst file = this.bucket.file(newFilename);\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst blobStream = file.createWriteStream({\r\n\t\t\t\tresumable: false,\r\n\t\t\t\tcontentType,\r\n\t\t\t});\r\n\r\n\t\t\tblobStream.on('error', (err: Error) => {\r\n\t\t\t\treject(err);\r\n\t\t\t});\r\n\r\n\t\t\tblobStream.on('finish', async () => {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tawait file.makePublic();\r\n\t\t\t\t\tconst publicUrl = `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;\r\n\t\t\t\t\tresolve({ filename: file.name, url: publicUrl });\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\treject(err);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\tprocessedImage.pipe(blobStream);\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Transcodes (resizes) an image buffer into multiple resolutions.\r\n\t * An optional destinationPrefix can be provided to force a specific path or filename base.\r\n\t *\r\n\t * For example, if destinationPrefix is 'images/product', then the original might be\r\n\t * uploaded as 'images/product.jpg' and the resized versions as 'images/product-480.jpg', etc.\r\n\t */\r\n\tasync transcodeImage(\r\n\t\tbuffer: Buffer,\r\n\t\toriginalFilename: string,\r\n\t\tresolutions: number[]\r\n\t): Promise<{\r\n\t\toriginalUrl: string;\r\n\t\tresizedResults: Array<{ resolution: number; url: string }>;\r\n\t}> {\r\n\t\tconst extension = path.extname(originalFilename);\r\n\t\tconst contentType = `image/${extension.replace('.', '') || 'jpeg'}`;\r\n\t\tconst timestamp = moment().format('DDMMYYHmmss');\r\n\t\tconst randomId = Math.floor(Math.random() * 100);\r\n\r\n\t\tconst baseFilename = `${makeSlug(path.parse(originalFilename).name)}-${this.websiteName}-${timestamp}-${randomId}`;\r\n\r\n\t\tconst originalFileName = `${baseFilename}${extension}`;\r\n\t\tconst originalUrl = await this.uploadBuffer(buffer, originalFileName, contentType);\r\n\r\n\t\tconst metadata = await sharp(buffer).metadata();\r\n\t\tconst isLandscape = metadata.width && metadata.height ? metadata.width > metadata.height : true;\r\n\r\n\t\tconst resizedResults = await Promise.all(\r\n\t\t\tresolutions.map(async resolution => {\r\n\t\t\t\tconst resizeOptions = isLandscape ? { width: resolution } : { height: resolution };\r\n\t\t\t\tconst formatKey = (extension.replace('.', '') || 'jpeg') as keyof sharp.FormatEnum;\r\n\t\t\t\tconst resizedBuffer = await sharp(buffer)\r\n\t\t\t\t\t.resize({\r\n\t\t\t\t\t\t...resizeOptions,\r\n\t\t\t\t\t\twithoutEnlargement: true,\r\n\t\t\t\t\t})\r\n\t\t\t\t\t.toFormat(formatKey, { quality: 80 })\r\n\t\t\t\t\t.toBuffer();\r\n\t\t\t\tconst resizedFilename = `${baseFilename}-${resolution}${extension}`;\r\n\t\t\t\tconst resizedUrl = await this.uploadBuffer(resizedBuffer, resizedFilename, contentType);\r\n\t\t\t\treturn { resolution, url: resizedUrl };\r\n\t\t\t})\r\n\t\t);\r\n\r\n\t\treturn { originalUrl, resizedResults };\r\n\t}\r\n\r\n\t/**\r\n\t * Helper function to upload a buffer to a specified filename.\r\n\t */\r\n\tprivate async uploadBuffer(buffer: Buffer, filename: string, contentType: string): Promise<string> {\r\n\t\tconst file = this.bucket.file(filename);\r\n\t\tawait file.save(buffer, {\r\n\t\t\tresumable: false,\r\n\t\t\tcontentType,\r\n\t\t});\r\n\t\tawait file.makePublic();\r\n\t\treturn `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;\r\n\t}\r\n\r\n\tasync getListFiles(): Promise<Array<{ name: string; url: string }>> {\r\n\t\tconst [files] = await this.bucket.getFiles();\r\n\t\treturn files.map(file => ({\r\n\t\t\tname: file.name!,\r\n\t\t\turl: file.metadata.mediaLink!,\r\n\t\t}));\r\n\t}\r\n\r\n\tasync downloadFile(filename: string): Promise<Buffer> {\r\n\t\tconst file = this.bucket.file(filename);\r\n\t\tconst [buffer] = await file.download();\r\n\t\treturn buffer;\r\n\t}\r\n\r\n\tasync deleteFile(filename: string): Promise<void> {\r\n\t\tconst file = this.bucket.file(filename);\r\n\t\tconst [exists] = await file.exists();\r\n\t\tif (!exists) {\r\n\t\t\tthrow new Error('File does not exist.');\r\n\t\t}\r\n\t\tawait file.delete();\r\n\t}\r\n\r\n\tasync downloadImage(url: string): Promise<Buffer> {\r\n\t\tconst response = await axios.get(url, { responseType: 'arraybuffer' });\r\n\t\treturn Buffer.from(response.data, 'binary');\r\n\t}\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/upload/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,kDAA0B;AAC1B,oDAA4B;AAC5B,gDAAwB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AI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,0BAA0B,CAAC;QAGzE,IAAI,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;gBAC5B,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACnD,CAAC;iBAAM,CAAC;gBACP,OAAO,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;YAC3E,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;CACD;AAnSD,sCAmSC","sourcesContent":["import axios from 'axios';\r\nimport sharp from 'sharp';\r\nimport moment from 'moment';\r\nimport path from 'path';\r\nimport { getLibraries } from '../../index';\r\nimport mime from 'mime-types';\r\n\r\nfunction makeSlug(input: string): string {\r\n\treturn input\r\n\t\t.toLowerCase()\r\n\t\t.replace(/[^a-z0-9]+/g, '-')\r\n\t\t.replace(/(^-|-$)/g, '');\r\n}\r\n\r\nexport class UploadService {\r\n\tprivate bucket;\r\n\tprivate readonly websiteName;\r\n\r\n\tconstructor(bucketName?: string) {\r\n\t\tif (!bucketName) {\r\n\t\t\tbucketName = 'lyxa-global';\r\n\t\t}\r\n\r\n\t\tthis.bucket = getLibraries().getFirebaseService().superApp.storage().bucket(bucketName);\r\n\t\tthis.websiteName = 'lyxa-' + getLibraries().getConfigurationService().options.tenet;\r\n\t}\r\n\r\n\t/**\r\n\t * Generates a unique filename using the original filename.\r\n\t */\r\n\tprivate generateFilename(originalFilename: string, extension?: string): string {\r\n\t\tconst nameWithoutExt = path.parse(originalFilename).name;\r\n\t\tconst newExtension = extension || path.extname(originalFilename);\r\n\t\tconst timestamp = moment().format('DDMMYYHmmss');\r\n\t\tconst randomId = Math.floor(Math.random() * 100);\r\n\t\tconst baseName = `${makeSlug(nameWithoutExt)}-${this.websiteName}-${timestamp}-${randomId}`;\r\n\t\treturn baseName + newExtension;\r\n\t}\r\n\r\n\t/**\r\n\t * Uploads an image buffer after processing it with Sharp.\r\n\t * An optional destinationPath can be provided (e.g., 'images/product.jpg').\r\n\t */\r\n\tasync uploadImage(buffer: Buffer, originalFilename: string): Promise<{ filename: string; url: string }> {\r\n\t\tconst newFilename = this.generateFilename(originalFilename);\r\n\t\tconst extension = path.extname(newFilename).toLowerCase();\r\n\t\tlet processedImage: sharp.Sharp;\r\n\t\tlet contentType: string;\r\n\t\tif (extension === '.png') {\r\n\t\t\tprocessedImage = sharp(buffer).png({ quality: 80 });\r\n\t\t\tcontentType = 'image/png';\r\n\t\t} else if (extension === '.webp') {\r\n\t\t\tprocessedImage = sharp(buffer).webp({ quality: 80 });\r\n\t\t\tcontentType = 'image/webp';\r\n\t\t} else {\r\n\t\t\tprocessedImage = sharp(buffer).jpeg({ quality: 80 });\r\n\t\t\tcontentType = 'image/jpeg';\r\n\t\t}\r\n\r\n\t\tconst file = this.bucket.file(newFilename);\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst blobStream = file.createWriteStream({\r\n\t\t\t\tresumable: false,\r\n\t\t\t\tcontentType,\r\n\t\t\t});\r\n\r\n\t\t\tblobStream.on('error', (err: Error) => {\r\n\t\t\t\treject(err);\r\n\t\t\t});\r\n\r\n\t\t\tblobStream.on('finish', async () => {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tawait file.makePublic();\r\n\t\t\t\t\tconst publicUrl = `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;\r\n\t\t\t\t\tresolve({ filename: file.name, url: publicUrl });\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\treject(err);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\tprocessedImage.pipe(blobStream);\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Transcodes (resizes) an image buffer into multiple resolutions.\r\n\t * An optional destinationPrefix can be provided to force a specific path or filename base.\r\n\t *\r\n\t * For example, if destinationPrefix is 'images/product', then the original might be\r\n\t * uploaded as 'images/product.jpg' and the resized versions as 'images/product-480.jpg', etc.\r\n\t */\r\n\tasync transcodeImage(\r\n\t\tbuffer: Buffer,\r\n\t\toriginalFilename: string,\r\n\t\tresolutions: number[]\r\n\t): Promise<{\r\n\t\toriginalUrl: string;\r\n\t\tresizedResults: Array<{ resolution: number; url: string }>;\r\n\t}> {\r\n\t\tconst extension = path.extname(originalFilename);\r\n\t\tconst contentType = `image/${extension.replace('.', '') || 'jpeg'}`;\r\n\t\tconst timestamp = moment().format('DDMMYYHmmss');\r\n\t\tconst randomId = Math.floor(Math.random() * 100);\r\n\r\n\t\tconst baseFilename = `${makeSlug(path.parse(originalFilename).name)}-${this.websiteName}-${timestamp}-${randomId}`;\r\n\r\n\t\tconst originalFileName = `${baseFilename}${extension}`;\r\n\t\tconst originalUrl = await this.uploadBuffer(buffer, originalFileName, contentType);\r\n\r\n\t\tconst metadata = await sharp(buffer).metadata();\r\n\t\tconst isLandscape = metadata.width && metadata.height ? metadata.width > metadata.height : true;\r\n\r\n\t\tconst resizedResults = await Promise.all(\r\n\t\t\tresolutions.map(async resolution => {\r\n\t\t\t\tconst resizeOptions = isLandscape ? { width: resolution } : { height: resolution };\r\n\t\t\t\tconst formatKey = (extension.replace('.', '') || 'jpeg') as keyof sharp.FormatEnum;\r\n\t\t\t\tconst resizedBuffer = await sharp(buffer)\r\n\t\t\t\t\t.resize({\r\n\t\t\t\t\t\t...resizeOptions,\r\n\t\t\t\t\t\twithoutEnlargement: true,\r\n\t\t\t\t\t})\r\n\t\t\t\t\t.toFormat(formatKey, { quality: 80 })\r\n\t\t\t\t\t.toBuffer();\r\n\t\t\t\tconst resizedFilename = `${baseFilename}-${resolution}${extension}`;\r\n\t\t\t\tconst resizedUrl = await this.uploadBuffer(resizedBuffer, resizedFilename, contentType);\r\n\t\t\t\treturn { resolution, url: resizedUrl };\r\n\t\t\t})\r\n\t\t);\r\n\r\n\t\treturn { originalUrl, resizedResults };\r\n\t}\r\n\r\n\t/**\r\n\t * Helper function to upload a buffer to a specified filename.\r\n\t */\r\n\tprivate async uploadBuffer(buffer: Buffer, filename: string, contentType: string): Promise<string> {\r\n\t\tconst file = this.bucket.file(filename);\r\n\t\tawait file.save(buffer, {\r\n\t\t\tresumable: false,\r\n\t\t\tcontentType,\r\n\t\t});\r\n\t\tawait file.makePublic();\r\n\t\treturn `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;\r\n\t}\r\n\r\n\tasync getListFiles(): Promise<Array<{ name: string; url: string }>> {\r\n\t\tconst [files] = await this.bucket.getFiles();\r\n\t\treturn files.map(file => ({\r\n\t\t\tname: file.name!,\r\n\t\t\turl: file.metadata.mediaLink!,\r\n\t\t}));\r\n\t}\r\n\r\n\tasync downloadFile(filename: string): Promise<Buffer> {\r\n\t\tconst file = this.bucket.file(filename);\r\n\t\tconst [buffer] = await file.download();\r\n\t\treturn buffer;\r\n\t}\r\n\r\n\tasync deleteFile(filename: string): Promise<void> {\r\n\t\tconst file = this.bucket.file(filename);\r\n\t\tconst [exists] = await file.exists();\r\n\t\tif (!exists) {\r\n\t\t\tthrow new Error('File does not exist.');\r\n\t\t}\r\n\t\tawait file.delete();\r\n\t}\r\n\r\n\tpublic extractFilenameFromUrl(url: string): string {\r\n\t\ttry {\r\n\t\t\tconst urlObj = new URL(url);\r\n\t\t\tconst pathParts = urlObj.pathname.split('/');\r\n\t\t\treturn decodeURIComponent(pathParts[pathParts.length - 1]);\r\n\t\t} catch (err) {\r\n\t\t\tthrow new Error(`Invalid URL: ${url}`);\r\n\t\t}\r\n\t}\r\n\r\n\tasync deleteFileByUrl(url: string): Promise<void> {\r\n\t\tconst filename = this.extractFilenameFromUrl(url);\r\n\t\tconst file = this.bucket.file(filename);\r\n\t\tconst [exists] = await file.exists();\r\n\t\tif (!exists) {\r\n\t\t\tthrow new Error('File does not exist.');\r\n\t\t}\r\n\t\tawait file.delete();\r\n\t}\r\n\r\n\tasync downloadImage(url: string): Promise<Buffer> {\r\n\t\tconst response = await axios.get(url, { responseType: 'arraybuffer' });\r\n\t\treturn Buffer.from(response.data, 'binary');\r\n\t}\r\n\r\n\t/**\r\n\t * Uploads a buffer to Google Cloud Storage and makes it public\r\n\t */\r\n\tprivate async uploadToGCS(\r\n\t\tbuffer: Buffer,\r\n\t\tfilename: string,\r\n\t\tcontentType: string\r\n\t): Promise<{ filename: string; url: string }> {\r\n\t\tconst file = this.bucket.file(filename);\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\t// Create a write stream to upload the file\r\n\t\t\tconst blobStream = file.createWriteStream({\r\n\t\t\t\tresumable: false,\r\n\t\t\t\tcontentType,\r\n\t\t\t});\r\n\r\n\t\t\tblobStream.on('error', reject);\r\n\r\n\t\t\tblobStream.on('finish', async () => {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t// Make the file publicly accessible\r\n\t\t\t\t\tawait file.makePublic();\r\n\t\t\t\t\tconst publicUrl = `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;\r\n\t\t\t\t\tresolve({ filename: file.name, url: publicUrl });\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\treject(err);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\t// Start uploading the buffer\r\n\t\t\tblobStream.end(buffer);\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Uploads and converts an image to WebP format, resizes if needed, and uploads to GCS\r\n\t */\r\n\tasync uploadProcessedImageToWebp(\r\n\t\tbuffer: Buffer,\r\n\t\toriginalFilename: string,\r\n\t\toptions?: { quality?: number; width?: number; height?: number }\r\n\t): Promise<{ filename: string; url: string }> {\r\n\t\tconst newFilename = this.generateFilename(originalFilename, '.webp');\r\n\r\n\t\tlet width = options?.width;\r\n\t\tlet height = options?.height;\r\n\t\tconst quality = options?.quality ?? 80;\r\n\r\n\t\t// Get original image dimensions if width or height is missing\r\n\t\tif (!width || !height) {\r\n\t\t\tconst imageMetadata = await sharp(buffer).metadata();\r\n\t\t\twidth = width || imageMetadata.width;\r\n\t\t\theight = height || imageMetadata.height;\r\n\t\t}\r\n\r\n\t\t// Convert to WebP and resize\r\n\t\tconst processedImage: sharp.Sharp = sharp(buffer)\r\n\t\t\t.resize(width, height, { fit: 'inside' })\r\n\t\t\t.webp({ quality });\r\n\r\n\t\tconst file = this.bucket.file(newFilename);\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst blobStream = file.createWriteStream({\r\n\t\t\t\tresumable: false,\r\n\t\t\t\tcontentType: 'image/webp',\r\n\t\t\t});\r\n\r\n\t\t\tblobStream.on('error', (err: Error) => {\r\n\t\t\t\treject(err);\r\n\t\t\t});\r\n\r\n\t\t\tblobStream.on('finish', async () => {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tawait file.makePublic();\r\n\t\t\t\t\tconst publicUrl = `https://storage.googleapis.com/${this.bucket.name}/${file.name}`;\r\n\t\t\t\t\tresolve({ filename: file.name, url: publicUrl });\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\treject(err);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t\tprocessedImage.pipe(blobStream);\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Uploads any supported file type to GCS and returns its public URL\r\n\t */\r\n\tasync uploadFile(\r\n\t\tbuffer: Buffer,\r\n\t\toriginalFilename: string,\r\n\t\toptions?: { quality?: number; width?: number; height?: number; withExtension?: boolean }\r\n\t): Promise<{ filename: string; url: string }> {\r\n\t\tconst newFilename = this.generateFilename(originalFilename);\r\n\t\tconst extension = path.extname(newFilename).toLowerCase();\r\n\r\n\t\t// Guess the MIME type using the mime-types library\r\n\t\tconst contentType = mime.lookup(extension) || 'application/octet-stream';\r\n\r\n\t\t// Special image handling (compression)\r\n\t\tif (contentType.startsWith('image/')) {\r\n\t\t\tif (options?.withExtension) {\r\n\t\t\t\treturn this.uploadImage(buffer, originalFilename);\r\n\t\t\t} else {\r\n\t\t\t\treturn this.uploadProcessedImageToWebp(buffer, originalFilename, options);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn this.uploadToGCS(buffer, newFilename, contentType);\r\n\t}\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lyxa.ai/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "The Core system of the Lyxa services.",
|
|
5
5
|
"author": "elie <42282499+Internalizable@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"firebase-admin": "^13.0.1",
|
|
30
30
|
"ioredis": "^5.4.1",
|
|
31
31
|
"jsonwebtoken": "^9.0.2",
|
|
32
|
+
"mime-types": "^3.0.1",
|
|
32
33
|
"moment": "^2.30.1",
|
|
33
34
|
"mongoose": "^8.9.1",
|
|
34
35
|
"nanoid": "^5.1.5",
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
"zod": "^3.24.1"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
47
|
+
"@types/mime-types": "^2.1.4",
|
|
46
48
|
"prettier": "3.5.3"
|
|
47
49
|
}
|
|
48
50
|
}
|