@lyxa.ai/core 1.2.26 → 1.2.27
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/embedded/order-extra-time.settings.d.ts +13 -0
- package/dist/libraries/mongo/models/embedded/order-extra-time.settings.js +48 -0
- package/dist/libraries/mongo/models/embedded/order-extra-time.settings.js.map +1 -0
- package/dist/libraries/mongo/models/setting.model.d.ts +2 -0
- package/dist/libraries/mongo/models/setting.model.js +6 -0
- package/dist/libraries/mongo/models/setting.model.js.map +1 -1
- package/dist/libraries/osrm/index.d.ts +2 -11
- package/dist/libraries/osrm/index.js +5 -93
- package/dist/libraries/osrm/index.js.map +1 -1
- package/dist/libraries/osrm/osrm-client.d.ts +16 -0
- package/dist/libraries/osrm/osrm-client.js +81 -0
- package/dist/libraries/osrm/osrm-client.js.map +1 -0
- package/dist/libraries/osrm/osrm-service.d.ts +8 -0
- package/dist/libraries/osrm/osrm-service.js +61 -0
- package/dist/libraries/osrm/osrm-service.js.map +1 -0
- package/dist/libraries/osrm/types.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/shared/index.d.ts +1 -0
- package/dist/types/utilities/shared/index.js +1 -0
- package/dist/types/utilities/shared/index.js.map +1 -1
- package/dist/utilities/shared/index.d.ts +1 -0
- package/dist/utilities/shared/index.js +1 -0
- package/dist/utilities/shared/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Ref } from '@typegoose/typegoose';
|
|
2
|
+
import { WeekDay } from '../../../../utilities/enum';
|
|
3
|
+
import { StartEndTime } from '../shared/work-hour.model';
|
|
4
|
+
import { Zone } from '../zone.model';
|
|
5
|
+
export declare class OrderExtraTimeSlot extends StartEndTime {
|
|
6
|
+
extraTimeInSeconds: number;
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class OrderExtraTimeSettings {
|
|
10
|
+
day: WeekDay;
|
|
11
|
+
zone: Ref<Zone>;
|
|
12
|
+
slots: OrderExtraTimeSlot[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OrderExtraTimeSettings = exports.OrderExtraTimeSlot = void 0;
|
|
13
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
14
|
+
const enum_1 = require("../../../../utilities/enum");
|
|
15
|
+
const work_hour_model_1 = require("../shared/work-hour.model");
|
|
16
|
+
const zone_model_1 = require("../zone.model");
|
|
17
|
+
class OrderExtraTimeSlot extends work_hour_model_1.StartEndTime {
|
|
18
|
+
extraTimeInSeconds;
|
|
19
|
+
isActive;
|
|
20
|
+
}
|
|
21
|
+
exports.OrderExtraTimeSlot = OrderExtraTimeSlot;
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, typegoose_1.Prop)({ type: Number, required: true, min: 0 }),
|
|
24
|
+
__metadata("design:type", Number)
|
|
25
|
+
], OrderExtraTimeSlot.prototype, "extraTimeInSeconds", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, typegoose_1.Prop)({ type: Boolean, default: true }),
|
|
28
|
+
__metadata("design:type", Boolean)
|
|
29
|
+
], OrderExtraTimeSlot.prototype, "isActive", void 0);
|
|
30
|
+
class OrderExtraTimeSettings {
|
|
31
|
+
day;
|
|
32
|
+
zone;
|
|
33
|
+
slots;
|
|
34
|
+
}
|
|
35
|
+
exports.OrderExtraTimeSettings = OrderExtraTimeSettings;
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, typegoose_1.Prop)({ type: String, enum: enum_1.WeekDay, required: true }),
|
|
38
|
+
__metadata("design:type", Number)
|
|
39
|
+
], OrderExtraTimeSettings.prototype, "day", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, typegoose_1.Prop)({ ref: () => zone_model_1.Zone, required: true }),
|
|
42
|
+
__metadata("design:type", Object)
|
|
43
|
+
], OrderExtraTimeSettings.prototype, "zone", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typegoose_1.Prop)({ type: [OrderExtraTimeSlot], default: [] }),
|
|
46
|
+
__metadata("design:type", Array)
|
|
47
|
+
], OrderExtraTimeSettings.prototype, "slots", void 0);
|
|
48
|
+
//# sourceMappingURL=order-extra-time.settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-extra-time.settings.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/order-extra-time.settings.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,qDAAqD;AACrD,+DAAyD;AACzD,8CAAqC;AAErC,MAAa,kBAAmB,SAAQ,8BAAY;IAE5C,kBAAkB,CAAU;IAG5B,QAAQ,CAAU;CACzB;AAND,gDAMC;AAJO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;;8DACZ;AAG5B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;oDACd;AAG1B,MAAa,sBAAsB;IAE3B,GAAG,CAAW;IAGd,IAAI,CAAa;IAGjB,KAAK,CAAwB;CACpC;AATD,wDASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mDACjC;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;oDAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;qDACd","sourcesContent":["import { Prop, Ref } from '@typegoose/typegoose';\nimport { WeekDay } from '../../../../utilities/enum';\nimport { StartEndTime } from '../shared/work-hour.model';\nimport { Zone } from '../zone.model';\n\nexport class OrderExtraTimeSlot extends StartEndTime {\n\t@Prop({ type: Number, required: true, min: 0 })\n\tpublic extraTimeInSeconds!: number;\n\n\t@Prop({ type: Boolean, default: true })\n\tpublic isActive: boolean;\n}\n\nexport class OrderExtraTimeSettings {\n\t@Prop({ type: String, enum: WeekDay, required: true })\n\tpublic day!: WeekDay;\n\n\t@Prop({ ref: () => Zone, required: true })\n\tpublic zone!: Ref<Zone>;\n\n\t@Prop({ type: [OrderExtraTimeSlot], default: [] })\n\tpublic slots!: OrderExtraTimeSlot[];\n}\n"]}
|
|
@@ -13,6 +13,7 @@ import { CustomerSupport } from './embedded/customer-support-numbers.model';
|
|
|
13
13
|
import { CustomerSupportBatchesSettings } from './embedded/customer-support-batches.model';
|
|
14
14
|
import { PlusSettings } from './embedded/plus-settings.model';
|
|
15
15
|
import { AgentNotificationSetting } from './embedded/agent-notification-setting.model';
|
|
16
|
+
import { OrderExtraTimeSettings } from './embedded/order-extra-time.settings';
|
|
16
17
|
export declare class Setting extends TimeStamps {
|
|
17
18
|
deliveryCharges: DeliveryCharge[];
|
|
18
19
|
serviceFeeSetting?: ServiceFeeSetting;
|
|
@@ -36,4 +37,5 @@ export declare class Setting extends TimeStamps {
|
|
|
36
37
|
plusSettings?: PlusSettings[];
|
|
37
38
|
agentNotificationSetting?: AgentNotificationSetting;
|
|
38
39
|
cashbackAmount?: number;
|
|
40
|
+
orderExtraTimeSettings?: OrderExtraTimeSettings[];
|
|
39
41
|
}
|
|
@@ -26,6 +26,7 @@ const customer_support_numbers_model_1 = require("./embedded/customer-support-nu
|
|
|
26
26
|
const customer_support_batches_model_1 = require("./embedded/customer-support-batches.model");
|
|
27
27
|
const plus_settings_model_1 = require("./embedded/plus-settings.model");
|
|
28
28
|
const agent_notification_setting_model_1 = require("./embedded/agent-notification-setting.model");
|
|
29
|
+
const order_extra_time_settings_1 = require("./embedded/order-extra-time.settings");
|
|
29
30
|
let Setting = class Setting extends defaultClasses_1.TimeStamps {
|
|
30
31
|
deliveryCharges;
|
|
31
32
|
serviceFeeSetting;
|
|
@@ -49,6 +50,7 @@ let Setting = class Setting extends defaultClasses_1.TimeStamps {
|
|
|
49
50
|
plusSettings;
|
|
50
51
|
agentNotificationSetting;
|
|
51
52
|
cashbackAmount;
|
|
53
|
+
orderExtraTimeSettings;
|
|
52
54
|
};
|
|
53
55
|
exports.Setting = Setting;
|
|
54
56
|
__decorate([
|
|
@@ -139,6 +141,10 @@ __decorate([
|
|
|
139
141
|
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
140
142
|
__metadata("design:type", Number)
|
|
141
143
|
], Setting.prototype, "cashbackAmount", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, typegoose_1.prop)({ type: () => [order_extra_time_settings_1.OrderExtraTimeSettings], default: [] }),
|
|
146
|
+
__metadata("design:type", Array)
|
|
147
|
+
], Setting.prototype, "orderExtraTimeSettings", void 0);
|
|
142
148
|
exports.Setting = Setting = __decorate([
|
|
143
149
|
(0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'settings' } })
|
|
144
150
|
], Setting);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setting.model.js","sourceRoot":"/","sources":["libraries/mongo/models/setting.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA0D;AAC1D,4EAAqE;AACrE,kDAAwD;AACxD,sGAA2F;AAC3F,4FAA0E;AAC1E,4EAAkE;AAClE,8EAAoE;AACpE,0EAAgE;AAChE,wEAA8D;AAC9D,oFAAyE;AACzE,8DAA2D;AAC3D,wEAAsE;AACtE,8FAA4E;AAC5E,8FAA2F;AAC3F,wEAA8D;
|
|
1
|
+
{"version":3,"file":"setting.model.js","sourceRoot":"/","sources":["libraries/mongo/models/setting.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA0D;AAC1D,4EAAqE;AACrE,kDAAwD;AACxD,sGAA2F;AAC3F,4FAA0E;AAC1E,4EAAkE;AAClE,8EAAoE;AACpE,0EAAgE;AAChE,wEAA8D;AAC9D,oFAAyE;AACzE,8DAA2D;AAC3D,wEAAsE;AACtE,8FAA4E;AAC5E,8FAA2F;AAC3F,wEAA8D;AAC9D,kGAAuF;AACvF,oFAA8E;AAGvE,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,2BAAU;IAE/B,eAAe,CAAmB;IAGlC,iBAAiB,CAAqB;IAGtC,aAAa,CAAiB;IAG9B,eAAe,CAAmB;IAGlC,cAAc,CAAkB;IAGhC,YAAY,CAAgB;IAG5B,0BAA0B,CAA8B;IAGxD,eAAe,CAAU;IAGzB,aAAa,CAAU;IAGvB,iBAAiB,CAAY;IAG7B,YAAY,CAA0B;IAGtC,kBAAkB,CAAU;IAG5B,8BAA8B,CAAU;IAGxC,KAAK,CAAY;IAGjB,eAAe,CAAmB;IAGlC,cAAc,CAAmB;IAGjC,mBAAmB,CAAW;IAG9B,eAAe,CAAmB;IAGlC,sBAAsB,CAAoC;IAG1D,YAAY,CAAkB;IAG9B,wBAAwB,CAA4B;IAG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AC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;uDACV;kBApEtC,OAAO;IADnB,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC;GAC/C,OAAO,CAqEnB","sourcesContent":["import { modelOptions, prop } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { PaymentMethod } from '../../../utilities/enum';\nimport { BusinessDevelopmentSetting } from './embedded/business-development-setting.model';\nimport { DeliveryCharge } from './embedded/delivery-charge-setting.model';\nimport { CourierSetting } from './embedded/courier-setting.model';\nimport { CurrencySetting } from './embedded/currency-setting.model';\nimport { PayoutSetting } from './embedded/payout-setting.model';\nimport { RiderSetting } from './embedded/rider-setting.model';\nimport { ServiceFeeSetting } from './embedded/service-fee-setting.model';\nimport { WorkHourSetting } from './shared/work-hour.model';\nimport { RiderBatchesSettings } from './embedded/rider-batches.model';\nimport { CustomerSupport } from './embedded/customer-support-numbers.model';\nimport { CustomerSupportBatchesSettings } from './embedded/customer-support-batches.model';\nimport { PlusSettings } from './embedded/plus-settings.model';\nimport { AgentNotificationSetting } from './embedded/agent-notification-setting.model';\nimport { OrderExtraTimeSettings } from './embedded/order-extra-time.settings';\n\n@modelOptions({ schemaOptions: { collection: 'settings' } })\nexport class Setting extends TimeStamps {\n\t@prop({ type: () => [DeliveryCharge] })\n\tpublic deliveryCharges: DeliveryCharge[];\n\n\t@prop({ type: ServiceFeeSetting })\n\tpublic serviceFeeSetting?: ServiceFeeSetting;\n\n\t@prop({ type: PayoutSetting })\n\tpublic payoutSetting?: PayoutSetting;\n\n\t@prop({ type: WorkHourSetting })\n\tpublic workHourSetting?: WorkHourSetting;\n\n\t@prop({ type: CourierSetting })\n\tpublic courierSetting?: CourierSetting;\n\n\t@prop({ type: RiderSetting })\n\tpublic riderSetting?: RiderSetting;\n\n\t@prop({ type: BusinessDevelopmentSetting })\n\tpublic businessDevelopmentSetting?: BusinessDevelopmentSetting;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic payLimitForUser?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic vatPercentage?: number;\n\n\t@prop({ type: () => [Number], default: [] })\n\tpublic riderSearchRanges?: number[];\n\n\t@prop({ type: () => [RiderBatchesSettings], default: [] })\n\tpublic riderBatches?: RiderBatchesSettings[];\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistance?: number;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistanceInHomeScreen?: number;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic units?: string[];\n\n\t@prop({ type: CurrencySetting })\n\tpublic currencySetting?: CurrencySetting;\n\n\t@prop({ type: () => [String], enum: PaymentMethod, default: [] })\n\tpublic paymentMethods?: PaymentMethod[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isGroupOrderEnabled?: boolean;\n\n\t@prop({ type: CustomerSupport })\n\tpublic customerSupport?: CustomerSupport;\n\n\t@prop({ type: () => [CustomerSupportBatchesSettings], default: [] })\n\tpublic customerSupportBatches?: CustomerSupportBatchesSettings[];\n\n\t@prop({ type: () => [PlusSettings], default: [] })\n\tpublic plusSettings?: PlusSettings[];\n\n\t@prop({ type: AgentNotificationSetting })\n\tpublic agentNotificationSetting?: AgentNotificationSetting;\n\n\t@prop({ type: Number, default: 0 })\n\tcashbackAmount?: number;\n\n\t@prop({ type: () => [OrderExtraTimeSettings], default: [] })\n\torderExtraTimeSettings?: OrderExtraTimeSettings[];\n}\n"]}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import { Coordinate, DistanceResult, OSRMConfig, OSRMOptions } from './types';
|
|
2
1
|
export * from './types';
|
|
3
2
|
export * from './enums';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
private readonly timeout;
|
|
7
|
-
private readonly headers;
|
|
8
|
-
constructor(config?: OSRMConfig);
|
|
9
|
-
getDistance(source: Coordinate, destinations: Coordinate[], options?: OSRMOptions): Promise<DistanceResult[]>;
|
|
10
|
-
private buildUrl;
|
|
11
|
-
private parseResponse;
|
|
12
|
-
private fetch;
|
|
13
|
-
}
|
|
3
|
+
export { OSRMClient } from './osrm-client';
|
|
4
|
+
export { OSRMService } from './osrm-service';
|
|
@@ -10,103 +10,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
-
};
|
|
19
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
15
|
};
|
|
22
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
23
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
24
|
-
};
|
|
25
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.OSRMService = void 0;
|
|
27
|
-
const typedi_1 = require("typedi");
|
|
28
|
-
const enums_1 = require("./enums");
|
|
17
|
+
exports.OSRMService = exports.OSRMClient = void 0;
|
|
29
18
|
__exportStar(require("./types"), exports);
|
|
30
19
|
__exportStar(require("./enums"), exports);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
constructor(config) {
|
|
36
|
-
const envUrls = {
|
|
37
|
-
development: 'https://api-v2-development.lyxa.ai/distance',
|
|
38
|
-
staging: 'https://api-v2-staging.lyxa.ai/distance',
|
|
39
|
-
production: 'https://api-v2.lyxa.ai/distance',
|
|
40
|
-
};
|
|
41
|
-
const env = process.env.NODE_ENV ?? 'development';
|
|
42
|
-
this.baseUrl = config?.baseUrl ?? envUrls[env] ?? envUrls.development;
|
|
43
|
-
this.timeout = config?.timeout ?? 10000;
|
|
44
|
-
this.headers = { Accept: 'application/json', ...config?.headers };
|
|
45
|
-
}
|
|
46
|
-
async getDistance(source, destinations, options) {
|
|
47
|
-
if (!destinations.length)
|
|
48
|
-
return [];
|
|
49
|
-
const profile = options?.profile ?? enums_1.OSRMProfile.BIKE;
|
|
50
|
-
const version = options?.version ?? 'v1';
|
|
51
|
-
const url = this.buildUrl(source, destinations, profile, version);
|
|
52
|
-
const data = await this.fetch(url);
|
|
53
|
-
return this.parseResponse(data, destinations);
|
|
54
|
-
}
|
|
55
|
-
buildUrl(source, destinations, profile, version) {
|
|
56
|
-
const coords = [source, ...destinations].map(([lon, lat]) => `${lon},${lat}`).join(';');
|
|
57
|
-
const indices = destinations.map((_, i) => i + 1).join(';');
|
|
58
|
-
return `${this.baseUrl}/table/${version}/${profile}/${coords}.json?sources=0&destinations=${indices}&annotations=distance,duration`;
|
|
59
|
-
}
|
|
60
|
-
parseResponse(data, destinations) {
|
|
61
|
-
const distances = data.distances?.[0];
|
|
62
|
-
const durations = data.durations?.[0];
|
|
63
|
-
if (!distances || !durations) {
|
|
64
|
-
throw new Error('Invalid OSRM response: missing distance or duration data');
|
|
65
|
-
}
|
|
66
|
-
return destinations.map((point, i) => {
|
|
67
|
-
const meters = distances[i];
|
|
68
|
-
const seconds = durations[i];
|
|
69
|
-
if (meters === null || seconds === null) {
|
|
70
|
-
throw new Error(`No route found for destination ${i + 1} of ${destinations.length}`);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
point,
|
|
74
|
-
distanceKm: +(meters / 1000).toFixed(2),
|
|
75
|
-
durationMin: +(seconds / 60).toFixed(1),
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async fetch(url) {
|
|
80
|
-
const controller = new AbortController();
|
|
81
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
82
|
-
try {
|
|
83
|
-
const response = await fetch(url, {
|
|
84
|
-
signal: controller.signal,
|
|
85
|
-
headers: this.headers,
|
|
86
|
-
});
|
|
87
|
-
if (!response.ok) {
|
|
88
|
-
throw new Error(`OSRM API error: ${response.status} ${response.statusText}`);
|
|
89
|
-
}
|
|
90
|
-
const data = await response.json();
|
|
91
|
-
if (data.code !== enums_1.OSRMCode.OK) {
|
|
92
|
-
throw new Error(`OSRM error: ${data.code}${data.message ? ` - ${data.message}` : ''}`);
|
|
93
|
-
}
|
|
94
|
-
return data;
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
98
|
-
throw new Error(`OSRM request timeout after ${this.timeout}ms`);
|
|
99
|
-
}
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
clearTimeout(timeoutId);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
exports.OSRMService = OSRMService;
|
|
108
|
-
exports.OSRMService = OSRMService = __decorate([
|
|
109
|
-
(0, typedi_1.Service)(),
|
|
110
|
-
__metadata("design:paramtypes", [Object])
|
|
111
|
-
], OSRMService);
|
|
20
|
+
var osrm_client_1 = require("./osrm-client");
|
|
21
|
+
Object.defineProperty(exports, "OSRMClient", { enumerable: true, get: function () { return osrm_client_1.OSRMClient; } });
|
|
22
|
+
var osrm_service_1 = require("./osrm-service");
|
|
23
|
+
Object.defineProperty(exports, "OSRMService", { enumerable: true, get: function () { return osrm_service_1.OSRMService; } });
|
|
112
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/osrm/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/osrm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,0CAAwB;AACxB,0CAAwB;AAGxB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AAGnB,+CAA6C;AAApC,2GAAA,WAAW,OAAA","sourcesContent":["// Export types and enums\nexport * from './types';\nexport * from './enums';\n\n// Export low-level client\nexport { OSRMClient } from './osrm-client';\n\n// Export high-level service\nexport { OSRMService } from './osrm-service';\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OSRMProfile } from './enums';
|
|
2
|
+
import { Coordinate, OSRMConfig, TableResponse } from './types';
|
|
3
|
+
export declare class OSRMClient {
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly timeout;
|
|
6
|
+
private readonly headers;
|
|
7
|
+
constructor(config?: OSRMConfig);
|
|
8
|
+
table(source: Coordinate, destinations: Coordinate[], profile?: OSRMProfile, version?: string): Promise<TableResponse>;
|
|
9
|
+
private buildTableUrl;
|
|
10
|
+
private fetch;
|
|
11
|
+
parseTableResponse(response: TableResponse, destinations: Coordinate[]): Array<{
|
|
12
|
+
point: Coordinate;
|
|
13
|
+
distanceKm: number;
|
|
14
|
+
durationMin: number;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OSRMClient = void 0;
|
|
4
|
+
const enums_1 = require("./enums");
|
|
5
|
+
class OSRMClient {
|
|
6
|
+
baseUrl;
|
|
7
|
+
timeout;
|
|
8
|
+
headers;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
const urls = {
|
|
11
|
+
development: 'https://api-v2-development.lyxa.ai/distance',
|
|
12
|
+
staging: 'https://api-v2-staging.lyxa.ai/distance',
|
|
13
|
+
preprod: 'https://api-v2-preprod.lyxa.ai/distance',
|
|
14
|
+
production: 'https://api-v2.lyxa.ai/distance',
|
|
15
|
+
};
|
|
16
|
+
const env = process.env.NODE_ENV ?? 'development';
|
|
17
|
+
this.baseUrl = config?.baseUrl ?? urls[env] ?? urls.development;
|
|
18
|
+
this.timeout = config?.timeout ?? 10000;
|
|
19
|
+
this.headers = { Accept: 'application/json', ...config?.headers };
|
|
20
|
+
}
|
|
21
|
+
async table(source, destinations, profile = enums_1.OSRMProfile.BIKE, version = 'v1') {
|
|
22
|
+
if (!destinations.length) {
|
|
23
|
+
throw new Error('Destinations array cannot be empty');
|
|
24
|
+
}
|
|
25
|
+
const url = this.buildTableUrl(source, destinations, profile, version);
|
|
26
|
+
return this.fetch(url);
|
|
27
|
+
}
|
|
28
|
+
buildTableUrl(source, destinations, profile, version) {
|
|
29
|
+
const coords = [source, ...destinations].map(([lon, lat]) => `${lon},${lat}`).join(';');
|
|
30
|
+
const indices = destinations.map((_, i) => i + 1).join(';');
|
|
31
|
+
return `${this.baseUrl}/table/${version}/${profile}/${coords}.json?sources=0&destinations=${indices}&annotations=distance,duration`;
|
|
32
|
+
}
|
|
33
|
+
async fetch(url) {
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(url, {
|
|
38
|
+
signal: controller.signal,
|
|
39
|
+
headers: this.headers,
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new Error(`OSRM API error: ${response.status} ${response.statusText}`);
|
|
43
|
+
}
|
|
44
|
+
const data = await response.json();
|
|
45
|
+
if (data.code !== enums_1.OSRMCode.OK) {
|
|
46
|
+
throw new Error(`OSRM error: ${data.code}${data.message ? ` - ${data.message}` : ''}`);
|
|
47
|
+
}
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
52
|
+
throw new Error(`OSRM request timeout after ${this.timeout}ms`);
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
clearTimeout(timeoutId);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
parseTableResponse(response, destinations) {
|
|
61
|
+
const distances = response.distances?.[0];
|
|
62
|
+
const durations = response.durations?.[0];
|
|
63
|
+
if (!distances || !durations) {
|
|
64
|
+
throw new Error('Invalid OSRM response: missing distance or duration data');
|
|
65
|
+
}
|
|
66
|
+
return destinations.map((point, i) => {
|
|
67
|
+
const meters = distances[i];
|
|
68
|
+
const seconds = durations[i];
|
|
69
|
+
if (meters === null || seconds === null) {
|
|
70
|
+
throw new Error(`No route found for destination ${i + 1} of ${destinations.length}`);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
point,
|
|
74
|
+
distanceKm: +(meters / 1000).toFixed(2),
|
|
75
|
+
durationMin: +(seconds / 60).toFixed(1),
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.OSRMClient = OSRMClient;
|
|
81
|
+
//# sourceMappingURL=osrm-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osrm-client.js","sourceRoot":"/","sources":["libraries/osrm/osrm-client.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAOhD,MAAa,UAAU;IACL,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,OAAO,CAAyB;IAEjD,YAAY,MAAmB;QAC9B,MAAM,IAAI,GAAG;YACZ,WAAW,EAAE,6CAA6C;YAC1D,OAAO,EAAE,yCAAyC;YAClD,OAAO,EAAE,yCAAyC;YAClD,UAAU,EAAE,iCAAiC;SACpC,CAAC;QAEX,MAAM,GAAG,GAAI,OAAO,CAAC,GAAG,CAAC,QAA8B,IAAI,aAAa,CAA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AAS,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YACpC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAE7B,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBACzC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,GAAG,CAAC,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;YACtF,CAAC;YAED,OAAO;gBACN,KAAK;gBACL,UAAU,EAAE,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;gBACvC,WAAW,EAAE,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;aACvC,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAlHD,gCAkHC","sourcesContent":["import { OSRMCode, OSRMProfile } from './enums';\nimport { Coordinate, OSRMConfig, TableResponse } from './types';\n\n/**\n * Low-level OSRM HTTP client\n * Handles direct API communication without business logic\n */\nexport class OSRMClient {\n\tprivate readonly baseUrl: string;\n\tprivate readonly timeout: number;\n\tprivate readonly headers: Record<string, string>;\n\n\tconstructor(config?: OSRMConfig) {\n\t\tconst urls = {\n\t\t\tdevelopment: 'https://api-v2-development.lyxa.ai/distance',\n\t\t\tstaging: 'https://api-v2-staging.lyxa.ai/distance',\n\t\t\tpreprod: 'https://api-v2-preprod.lyxa.ai/distance',\n\t\t\tproduction: 'https://api-v2.lyxa.ai/distance',\n\t\t} as const;\n\n\t\tconst env = (process.env.NODE_ENV as keyof typeof urls) ?? 'development';\n\t\tthis.baseUrl = config?.baseUrl ?? urls[env] ?? urls.development;\n\t\tthis.timeout = config?.timeout ?? 10000;\n\t\tthis.headers = { Accept: 'application/json', ...config?.headers };\n\t}\n\n\t/**\n\t * Call OSRM table API to get distances and durations\n\t * @returns Raw OSRM response\n\t */\n\tasync table(\n\t\tsource: Coordinate,\n\t\tdestinations: Coordinate[],\n\t\tprofile: OSRMProfile = OSRMProfile.BIKE,\n\t\tversion: string = 'v1'\n\t): Promise<TableResponse> {\n\t\tif (!destinations.length) {\n\t\t\tthrow new Error('Destinations array cannot be empty');\n\t\t}\n\n\t\tconst url = this.buildTableUrl(source, destinations, profile, version);\n\t\treturn this.fetch(url);\n\t}\n\n\t/**\n\t * Build OSRM table API URL\n\t */\n\tprivate buildTableUrl(\n\t\tsource: Coordinate,\n\t\tdestinations: Coordinate[],\n\t\tprofile: OSRMProfile,\n\t\tversion: string\n\t): string {\n\t\tconst coords = [source, ...destinations].map(([lon, lat]) => `${lon},${lat}`).join(';');\n\t\tconst indices = destinations.map((_, i) => i + 1).join(';');\n\t\treturn `${this.baseUrl}/table/${version}/${profile}/${coords}.json?sources=0&destinations=${indices}&annotations=distance,duration`;\n\t}\n\n\t/**\n\t * HTTP fetch with timeout and error handling\n\t */\n\tprivate async fetch(url: string): Promise<TableResponse> {\n\t\tconst controller = new AbortController();\n\t\tconst timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n\t\ttry {\n\t\t\tconst response = await fetch(url, {\n\t\t\t\tsignal: controller.signal,\n\t\t\t\theaders: this.headers,\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`OSRM API error: ${response.status} ${response.statusText}`);\n\t\t\t}\n\n\t\t\tconst data = await response.json();\n\n\t\t\tif (data.code !== OSRMCode.OK) {\n\t\t\t\tthrow new Error(`OSRM error: ${data.code}${data.message ? ` - ${data.message}` : ''}`);\n\t\t\t}\n\n\t\t\treturn data;\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.name === 'AbortError') {\n\t\t\t\tthrow new Error(`OSRM request timeout after ${this.timeout}ms`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t}\n\n\t/**\n\t * Parse raw OSRM response into structured data\n\t */\n\tpublic parseTableResponse(\n\t\tresponse: TableResponse,\n\t\tdestinations: Coordinate[]\n\t): Array<{ point: Coordinate; distanceKm: number; durationMin: number }> {\n\t\tconst distances = response.distances?.[0];\n\t\tconst durations = response.durations?.[0];\n\n\t\tif (!distances || !durations) {\n\t\t\tthrow new Error('Invalid OSRM response: missing distance or duration data');\n\t\t}\n\n\t\treturn destinations.map((point, i) => {\n\t\t\tconst meters = distances[i];\n\t\t\tconst seconds = durations[i];\n\n\t\t\tif (meters === null || seconds === null) {\n\t\t\t\tthrow new Error(`No route found for destination ${i + 1} of ${destinations.length}`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpoint,\n\t\t\t\tdistanceKm: +(meters / 1000).toFixed(2),\n\t\t\t\tdurationMin: +(seconds / 60).toFixed(1),\n\t\t\t};\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Coordinate, DistanceResult, OSRMConfig, OSRMOptions } from './types';
|
|
2
|
+
export declare class OSRMService {
|
|
3
|
+
private readonly client;
|
|
4
|
+
private readonly DEFAULT_EXTRA_TIME;
|
|
5
|
+
constructor(config?: OSRMConfig);
|
|
6
|
+
getDistance(source: Coordinate, dest: Coordinate | Coordinate[], options?: OSRMOptions): Promise<DistanceResult | DistanceResult[]>;
|
|
7
|
+
private getExtraTime;
|
|
8
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OSRMService = void 0;
|
|
16
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
17
|
+
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
18
|
+
const typedi_1 = require("typedi");
|
|
19
|
+
const index_1 = require("../../index");
|
|
20
|
+
const time_1 = require("../../utilities/time");
|
|
21
|
+
const enums_1 = require("./enums");
|
|
22
|
+
const osrm_client_1 = require("./osrm-client");
|
|
23
|
+
let OSRMService = class OSRMService {
|
|
24
|
+
client;
|
|
25
|
+
DEFAULT_EXTRA_TIME = 10;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.client = new osrm_client_1.OSRMClient(config);
|
|
28
|
+
}
|
|
29
|
+
async getDistance(source, dest, options) {
|
|
30
|
+
const isArray = Array.isArray(dest);
|
|
31
|
+
const destinations = isArray ? dest : [dest];
|
|
32
|
+
if (!destinations.length)
|
|
33
|
+
return [];
|
|
34
|
+
const response = await this.client.table(source, destinations, options?.profile ?? enums_1.OSRMProfile.BIKE, options?.version ?? 'v1');
|
|
35
|
+
const distances = this.client.parseTableResponse(response, destinations);
|
|
36
|
+
const extraTimeSec = await this.getExtraTime();
|
|
37
|
+
const results = distances.map(d => ({
|
|
38
|
+
...d,
|
|
39
|
+
durationMin: +(d.durationMin + extraTimeSec / 60).toFixed(1),
|
|
40
|
+
}));
|
|
41
|
+
return isArray ? results : results[0];
|
|
42
|
+
}
|
|
43
|
+
async getExtraTime() {
|
|
44
|
+
const settings = await (0, index_1.getLibraries)().getCachedSettingsService().getSettings();
|
|
45
|
+
dayjs_1.default.extend(timezone_1.default);
|
|
46
|
+
const now = (0, dayjs_1.default)().tz(time_1.LyxaTimezone);
|
|
47
|
+
const today = now.day();
|
|
48
|
+
const currentTime = now.format('HH:mm');
|
|
49
|
+
const daySetting = settings.orderExtraTimeSettings?.find(s => s.day === today);
|
|
50
|
+
if (!daySetting)
|
|
51
|
+
return this.DEFAULT_EXTRA_TIME;
|
|
52
|
+
const slot = daySetting.slots.find(s => s.isActive && s.start <= currentTime && s.end >= currentTime);
|
|
53
|
+
return slot?.extraTimeInSeconds ?? this.DEFAULT_EXTRA_TIME;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.OSRMService = OSRMService;
|
|
57
|
+
exports.OSRMService = OSRMService = __decorate([
|
|
58
|
+
(0, typedi_1.Service)(),
|
|
59
|
+
__metadata("design:paramtypes", [Object])
|
|
60
|
+
], OSRMService);
|
|
61
|
+
//# sourceMappingURL=osrm-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osrm-service.js","sourceRoot":"/","sources":["libraries/osrm/osrm-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,qEAA6C;AAC7C,mCAAiC;AACjC,uCAA2C;AAE3C,+CAAoD;AAEpD,mCAAsC;AACtC,+CAA2C;AAIpC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACN,MAAM,CAAa;IACnB,kBAAkB,GAAG,EAAE,CAAC;IAEzC,YAAY,MAAmB;QAC9B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,eAAK,GAAE,CAAC,EAAE,CAAC,mBAAY,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,EAAa,CAAC;QACnC,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAExC,MAAM,UAAU,GAAG,QAAQ,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC;QAC/E,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC,kBAAkB,CAAC;QAEhD,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,WAAW,IAAI,CAAC,CAAC,GAAG,IAAI,WAAW,CAAC,CAAC;QACtG,OAAO,IAAI,EAAE,kBAAkB,IAAI,IAAI,CAAC,kBAAkB,CAAC;IAC5D,CAAC;CACD,CAAA;AA/CY,kCAAW;sBAAX,WAAW;IADvB,IAAA,gBAAO,GAAE;;GACG,WAAW,CA+CvB","sourcesContent":["import dayjs from 'dayjs';\nimport timezone from 'dayjs/plugin/timezone';\nimport { Service } from 'typedi';\nimport { getLibraries } from '../../index';\nimport { WeekDay } from '../../utilities/enum';\nimport { LyxaTimezone } from '../../utilities/time';\nimport { Setting } from '../mongo/models';\nimport { OSRMProfile } from './enums';\nimport { OSRMClient } from './osrm-client';\nimport { Coordinate, DistanceResult, OSRMConfig, OSRMOptions } from './types';\n\n@Service()\nexport class OSRMService {\n\tprivate readonly client: OSRMClient;\n\tprivate readonly DEFAULT_EXTRA_TIME = 10;\n\n\tconstructor(config?: OSRMConfig) {\n\t\tthis.client = new OSRMClient(config);\n\t}\n\n\tpublic async getDistance(\n\t\tsource: Coordinate,\n\t\tdest: Coordinate | Coordinate[],\n\t\toptions?: OSRMOptions\n\t): Promise<DistanceResult | DistanceResult[]> {\n\t\tconst isArray = Array.isArray(dest);\n\t\tconst destinations = isArray ? dest : [dest];\n\n\t\tif (!destinations.length) return [];\n\t\tconst response = await this.client.table(\n\t\t\tsource,\n\t\t\tdestinations,\n\t\t\toptions?.profile ?? OSRMProfile.BIKE,\n\t\t\toptions?.version ?? 'v1'\n\t\t);\n\n\t\tconst distances = this.client.parseTableResponse(response, destinations);\n\t\tconst extraTimeSec = await this.getExtraTime();\n\t\tconst results = distances.map(d => ({\n\t\t\t...d,\n\t\t\tdurationMin: +(d.durationMin + extraTimeSec / 60).toFixed(1),\n\t\t}));\n\t\treturn isArray ? results : results[0];\n\t}\n\n\tprivate async getExtraTime(): Promise<number> {\n\t\tconst settings: Setting = await getLibraries().getCachedSettingsService().getSettings();\n\t\tdayjs.extend(timezone);\n\n\t\tconst now = dayjs().tz(LyxaTimezone);\n\t\tconst today = now.day() as WeekDay;\n\t\tconst currentTime = now.format('HH:mm');\n\n\t\tconst daySetting = settings.orderExtraTimeSettings?.find(s => s.day === today);\n\t\tif (!daySetting) return this.DEFAULT_EXTRA_TIME;\n\n\t\tconst slot = daySetting.slots.find(s => s.isActive && s.start <= currentTime && s.end >= currentTime);\n\t\treturn slot?.extraTimeInSeconds ?? this.DEFAULT_EXTRA_TIME;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["libraries/osrm/types.ts"],"names":[],"mappings":"","sourcesContent":["import { OSRMCode, OSRMProfile } from './enums';\n\nexport type Longitude = number;\nexport type Latitude = number;\nexport type Coordinate = readonly [longitude: Longitude, latitude: Latitude];\n\nexport interface OSRMOptions {\n\treadonly profile?: OSRMProfile;\n\treadonly version?: string;\n}\n\nexport interface OSRMConfig
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["libraries/osrm/types.ts"],"names":[],"mappings":"","sourcesContent":["import { OSRMCode, OSRMProfile } from './enums';\n\nexport type Longitude = number;\nexport type Latitude = number;\nexport type Coordinate = readonly [longitude: Longitude, latitude: Latitude];\n\nexport interface OSRMOptions {\n\treadonly profile?: OSRMProfile;\n\treadonly version?: string;\n}\n\nexport interface OSRMConfig {\n\treadonly baseUrl?: string;\n\treadonly timeout?: number;\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\nexport interface TableResponse {\n\treadonly code: OSRMCode;\n\treadonly message?: string;\n\treadonly durations?: ReadonlyArray<ReadonlyArray<number | null>>;\n\treadonly distances?: ReadonlyArray<ReadonlyArray<number | null>>;\n}\n\nexport interface DistanceResult {\n\treadonly point: Coordinate;\n\treadonly distanceKm: number;\n\treadonly durationMin: number;\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./currency"), exports);
|
|
18
18
|
__exportStar(require("./nutritions"), exports);
|
|
19
|
+
__exportStar(require("./common-methods"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B","sourcesContent":["export * from './currency';\nexport * from './nutritions';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,mDAAiC","sourcesContent":["export * from './currency';\nexport * from './nutritions';\nexport * from './common-methods';\n"]}
|
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./currency"), exports);
|
|
18
18
|
__exportStar(require("./nutritions"), exports);
|
|
19
|
+
__exportStar(require("./common-methods"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B","sourcesContent":["export * from './currency';\nexport * from './nutritions';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,mDAAiC","sourcesContent":["export * from './currency';\nexport * from './nutritions';\nexport * from './common-methods';\n"]}
|