@dv4resi/dvss-backend-module-offering-im 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +380 -29
- package/dist/index.js +2152 -166
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,6 +7,9 @@ var dvssBackendModuleUtility = require('@dv4resi/dvss-backend-module-utility');
|
|
|
7
7
|
var axios = require('@nestjs/axios');
|
|
8
8
|
var config = require('@nestjs/config');
|
|
9
9
|
var rxjs = require('rxjs');
|
|
10
|
+
var dvssBackendModuleDatastore = require('@dv4resi/dvss-backend-module-datastore');
|
|
11
|
+
var capabilityIntegration_model = require('@dv4resi/dvss-backend-module-datastore/dist/datastore/models/capability-integration.model');
|
|
12
|
+
var models = require('@dv4resi/dvss-backend-module-datastore/dist/datastore/models');
|
|
10
13
|
|
|
11
14
|
var __defProp = Object.defineProperty;
|
|
12
15
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -217,7 +220,7 @@ function _ts_metadata6(k, v) {
|
|
|
217
220
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
218
221
|
}
|
|
219
222
|
__name(_ts_metadata6, "_ts_metadata");
|
|
220
|
-
|
|
223
|
+
exports.IntegrationRequestLoggerService = class _IntegrationRequestLoggerService {
|
|
221
224
|
static {
|
|
222
225
|
__name(this, "IntegrationRequestLoggerService");
|
|
223
226
|
}
|
|
@@ -237,7 +240,7 @@ var IntegrationRequestLoggerService = class _IntegrationRequestLoggerService {
|
|
|
237
240
|
integrationId: logData.integrationId,
|
|
238
241
|
method,
|
|
239
242
|
url,
|
|
240
|
-
headers
|
|
243
|
+
headers,
|
|
241
244
|
requestBody,
|
|
242
245
|
timestamp: logData.timestamp || /* @__PURE__ */ new Date()
|
|
243
246
|
});
|
|
@@ -265,7 +268,7 @@ var IntegrationRequestLoggerService = class _IntegrationRequestLoggerService {
|
|
|
265
268
|
* @param logData - The error log data to be logged
|
|
266
269
|
*/
|
|
267
270
|
logError(logData) {
|
|
268
|
-
const { loggedInUserId, method, url, statusCode, duration, error } = logData;
|
|
271
|
+
const { loggedInUserId, method, url, statusCode, duration, error, responseBody } = logData;
|
|
269
272
|
this.logger.error(loggedInUserId || dvssBackendModuleUtility.SYSTEM_USER_ID, this.logError.name, this.className, `Integration API Error: ${method} ${url} - ${statusCode || "N/A"} (${duration || 0}ms)`, {
|
|
270
273
|
integrationId: logData.integrationId,
|
|
271
274
|
method,
|
|
@@ -273,6 +276,7 @@ var IntegrationRequestLoggerService = class _IntegrationRequestLoggerService {
|
|
|
273
276
|
statusCode,
|
|
274
277
|
duration,
|
|
275
278
|
error,
|
|
279
|
+
responseBody,
|
|
276
280
|
timestamp: logData.timestamp || /* @__PURE__ */ new Date()
|
|
277
281
|
});
|
|
278
282
|
}
|
|
@@ -291,41 +295,14 @@ var IntegrationRequestLoggerService = class _IntegrationRequestLoggerService {
|
|
|
291
295
|
this.logRequest(logData);
|
|
292
296
|
}
|
|
293
297
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Sanitize headers to remove sensitive information
|
|
296
|
-
*
|
|
297
|
-
* @param headers - The headers to sanitize
|
|
298
|
-
* @returns Sanitized headers
|
|
299
|
-
*/
|
|
300
|
-
sanitizeHeaders(headers) {
|
|
301
|
-
if (!headers) {
|
|
302
|
-
return void 0;
|
|
303
|
-
}
|
|
304
|
-
const sanitized = {
|
|
305
|
-
...headers
|
|
306
|
-
};
|
|
307
|
-
const sensitiveKeys = [
|
|
308
|
-
"authorization",
|
|
309
|
-
"api-key",
|
|
310
|
-
"apikey",
|
|
311
|
-
"x-api-key",
|
|
312
|
-
"cookie"
|
|
313
|
-
];
|
|
314
|
-
for (const key of Object.keys(sanitized)) {
|
|
315
|
-
if (sensitiveKeys.includes(key.toLowerCase())) {
|
|
316
|
-
sanitized[key] = "***REDACTED***";
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return sanitized;
|
|
320
|
-
}
|
|
321
298
|
};
|
|
322
|
-
IntegrationRequestLoggerService = _ts_decorate7([
|
|
299
|
+
exports.IntegrationRequestLoggerService = _ts_decorate7([
|
|
323
300
|
common.Injectable(),
|
|
324
301
|
_ts_metadata6("design:type", Function),
|
|
325
302
|
_ts_metadata6("design:paramtypes", [
|
|
326
303
|
typeof dvssBackendModuleUtility.LoggerService === "undefined" ? Object : dvssBackendModuleUtility.LoggerService
|
|
327
304
|
])
|
|
328
|
-
], IntegrationRequestLoggerService);
|
|
305
|
+
], exports.IntegrationRequestLoggerService);
|
|
329
306
|
function _ts_decorate8(decorators, target, key, desc) {
|
|
330
307
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
331
308
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -333,7 +310,7 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
333
310
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
334
311
|
}
|
|
335
312
|
__name(_ts_decorate8, "_ts_decorate");
|
|
336
|
-
|
|
313
|
+
exports.RateLimiterService = class RateLimiterService {
|
|
337
314
|
static {
|
|
338
315
|
__name(this, "RateLimiterService");
|
|
339
316
|
}
|
|
@@ -345,9 +322,9 @@ var RateLimiterService = class {
|
|
|
345
322
|
async validateAndEnforceRateLimit() {
|
|
346
323
|
}
|
|
347
324
|
};
|
|
348
|
-
RateLimiterService = _ts_decorate8([
|
|
325
|
+
exports.RateLimiterService = _ts_decorate8([
|
|
349
326
|
common.Injectable()
|
|
350
|
-
], RateLimiterService);
|
|
327
|
+
], exports.RateLimiterService);
|
|
351
328
|
|
|
352
329
|
// ../../packages/dvss-integration-libs/src/integration-traffic-router/constants/http.constant.ts
|
|
353
330
|
var HTTP_METHOD = /* @__PURE__ */ (function(HTTP_METHOD2) {
|
|
@@ -435,10 +412,15 @@ exports.TrafficGatewayService = class TrafficGatewayService {
|
|
|
435
412
|
requestBody: request.body,
|
|
436
413
|
loggedInUserId,
|
|
437
414
|
timestamp: /* @__PURE__ */ new Date(),
|
|
438
|
-
error: errorDetails.
|
|
415
|
+
error: errorDetails.apiMessage,
|
|
439
416
|
statusCode: errorDetails.statusCode,
|
|
440
|
-
duration
|
|
417
|
+
duration,
|
|
418
|
+
responseBody: errorDetails.responseBody
|
|
441
419
|
});
|
|
420
|
+
const err = error;
|
|
421
|
+
err.apiMessage = errorDetails.message;
|
|
422
|
+
err.statusCode = errorDetails.statusCode;
|
|
423
|
+
err.message = errorDetails.apiMessage;
|
|
442
424
|
throw error;
|
|
443
425
|
}
|
|
444
426
|
}
|
|
@@ -528,17 +510,35 @@ exports.TrafficGatewayService = class TrafficGatewayService {
|
|
|
528
510
|
}
|
|
529
511
|
}
|
|
530
512
|
/**
|
|
531
|
-
* Extract error details from an error object
|
|
513
|
+
* Extract error details from an error object (e.g. Axios error).
|
|
514
|
+
* Provider-agnostic: derives apiMessage from common response shapes so any integration
|
|
515
|
+
* (Trybe, OAuth, REST, etc.) gets a readable reason. Callers can use statusCode and
|
|
516
|
+
* responseBody to map to their own exceptions (e.g. 404 -> RESOURCE_NOT_FOUND).
|
|
517
|
+
*
|
|
518
|
+
* Supported response.data fields (first string wins): message, error_description,
|
|
519
|
+
* error, detail, msg.
|
|
532
520
|
*
|
|
533
521
|
* @private
|
|
534
522
|
* @param error - The error object
|
|
535
|
-
* @returns Extracted error details
|
|
523
|
+
* @returns Extracted error details including apiMessage for logging and callers
|
|
536
524
|
*/
|
|
537
525
|
extractErrorDetails(error) {
|
|
538
526
|
const errorObject = error;
|
|
527
|
+
const responseData = errorObject.response?.data;
|
|
528
|
+
const data = typeof responseData === "object" && responseData !== null ? responseData : void 0;
|
|
529
|
+
const firstString = /* @__PURE__ */ __name((...keys) => {
|
|
530
|
+
for (const k of keys) {
|
|
531
|
+
const v = data?.[k];
|
|
532
|
+
if (typeof v === "string" && v.trim()) return v;
|
|
533
|
+
}
|
|
534
|
+
return void 0;
|
|
535
|
+
}, "firstString");
|
|
536
|
+
const apiMessage = firstString("message", "error_description", "error", "detail", "msg") || errorObject.message || "API error";
|
|
539
537
|
return {
|
|
540
538
|
message: errorObject.message,
|
|
541
|
-
statusCode: errorObject.status || errorObject.response?.status
|
|
539
|
+
statusCode: errorObject.status || errorObject.response?.status,
|
|
540
|
+
responseBody: errorObject.response?.data,
|
|
541
|
+
apiMessage
|
|
542
542
|
};
|
|
543
543
|
}
|
|
544
544
|
};
|
|
@@ -547,8 +547,8 @@ exports.TrafficGatewayService = _ts_decorate9([
|
|
|
547
547
|
_ts_metadata7("design:type", Function),
|
|
548
548
|
_ts_metadata7("design:paramtypes", [
|
|
549
549
|
typeof axios.HttpService === "undefined" ? Object : axios.HttpService,
|
|
550
|
-
typeof IntegrationRequestLoggerService === "undefined" ? Object : IntegrationRequestLoggerService,
|
|
551
|
-
typeof RateLimiterService === "undefined" ? Object : RateLimiterService
|
|
550
|
+
typeof exports.IntegrationRequestLoggerService === "undefined" ? Object : exports.IntegrationRequestLoggerService,
|
|
551
|
+
typeof exports.RateLimiterService === "undefined" ? Object : exports.RateLimiterService
|
|
552
552
|
])
|
|
553
553
|
], exports.TrafficGatewayService);
|
|
554
554
|
|
|
@@ -582,13 +582,13 @@ exports.IntegrationLibsModule = _ts_decorate10([
|
|
|
582
582
|
providers: [
|
|
583
583
|
AppService3,
|
|
584
584
|
exports.TrafficGatewayService,
|
|
585
|
-
IntegrationRequestLoggerService,
|
|
586
|
-
RateLimiterService
|
|
585
|
+
exports.IntegrationRequestLoggerService,
|
|
586
|
+
exports.RateLimiterService
|
|
587
587
|
],
|
|
588
588
|
exports: [
|
|
589
589
|
exports.TrafficGatewayService,
|
|
590
|
-
IntegrationRequestLoggerService,
|
|
591
|
-
RateLimiterService
|
|
590
|
+
exports.IntegrationRequestLoggerService,
|
|
591
|
+
exports.RateLimiterService
|
|
592
592
|
]
|
|
593
593
|
})
|
|
594
594
|
], exports.IntegrationLibsModule);
|
|
@@ -596,13 +596,51 @@ exports.IntegrationLibsModule = _ts_decorate10([
|
|
|
596
596
|
// ../../packages/dvss-integration-libs/src/integration-traffic-router/constants/traffic-router.constant.ts
|
|
597
597
|
var TRAFFIC_ROUTER_CONFIGURATION_STORE_KEY = "traffic-router-configuration-store";
|
|
598
598
|
|
|
599
|
-
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/auth/auth.base.ts
|
|
599
|
+
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/capabilities/auth/auth.base.ts
|
|
600
600
|
var BaseAuth = class {
|
|
601
601
|
static {
|
|
602
602
|
__name(this, "BaseAuth");
|
|
603
603
|
}
|
|
604
604
|
};
|
|
605
605
|
|
|
606
|
+
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/models/credit-management.model.ts
|
|
607
|
+
var CREDIT_TYPE_ENUM = /* @__PURE__ */ (function(CREDIT_TYPE_ENUM2) {
|
|
608
|
+
CREDIT_TYPE_ENUM2["COUPON"] = "COUPON";
|
|
609
|
+
CREDIT_TYPE_ENUM2["AMOUNT"] = "AMOUNT";
|
|
610
|
+
return CREDIT_TYPE_ENUM2;
|
|
611
|
+
})({});
|
|
612
|
+
var CREDIT_STATUS_ENUM = /* @__PURE__ */ (function(CREDIT_STATUS_ENUM2) {
|
|
613
|
+
CREDIT_STATUS_ENUM2["ACTIVE"] = "ACTIVE";
|
|
614
|
+
CREDIT_STATUS_ENUM2["REDEEMED"] = "REDEEMED";
|
|
615
|
+
CREDIT_STATUS_ENUM2["EXPIRED"] = "EXPIRED";
|
|
616
|
+
CREDIT_STATUS_ENUM2["REVOKED"] = "REVOKED";
|
|
617
|
+
return CREDIT_STATUS_ENUM2;
|
|
618
|
+
})({});
|
|
619
|
+
var CREDIT_FILTER_BY_ENUM = /* @__PURE__ */ (function(CREDIT_FILTER_BY_ENUM2) {
|
|
620
|
+
CREDIT_FILTER_BY_ENUM2["TYPE"] = "TYPE";
|
|
621
|
+
CREDIT_FILTER_BY_ENUM2["STATUS"] = "STATUS";
|
|
622
|
+
return CREDIT_FILTER_BY_ENUM2;
|
|
623
|
+
})({});
|
|
624
|
+
|
|
625
|
+
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/models/capability-integration.model.ts
|
|
626
|
+
var INTEGRATION_PROVIDER_ENUM = /* @__PURE__ */ (function(INTEGRATION_PROVIDER_ENUM2) {
|
|
627
|
+
INTEGRATION_PROVIDER_ENUM2["TRYBE"] = "TRYBE";
|
|
628
|
+
return INTEGRATION_PROVIDER_ENUM2;
|
|
629
|
+
})({});
|
|
630
|
+
|
|
631
|
+
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/models/wellness-management.model.ts
|
|
632
|
+
var BOOKABLE_ITEM_TYPE_ENUM = /* @__PURE__ */ (function(BOOKABLE_ITEM_TYPE_ENUM2) {
|
|
633
|
+
BOOKABLE_ITEM_TYPE_ENUM2["APPOINTMENT"] = "APPOINTMENT";
|
|
634
|
+
BOOKABLE_ITEM_TYPE_ENUM2["SESSION"] = "SESSION";
|
|
635
|
+
BOOKABLE_ITEM_TYPE_ENUM2["COURSE"] = "COURSE";
|
|
636
|
+
return BOOKABLE_ITEM_TYPE_ENUM2;
|
|
637
|
+
})({});
|
|
638
|
+
var BOOKABLE_ITEM_STATUS_ENUM = /* @__PURE__ */ (function(BOOKABLE_ITEM_STATUS_ENUM2) {
|
|
639
|
+
BOOKABLE_ITEM_STATUS_ENUM2["ACTIVE"] = "ACTIVE";
|
|
640
|
+
BOOKABLE_ITEM_STATUS_ENUM2["INACTIVE"] = "INACTIVE";
|
|
641
|
+
return BOOKABLE_ITEM_STATUS_ENUM2;
|
|
642
|
+
})({});
|
|
643
|
+
|
|
606
644
|
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/capabilities/wellness/wellness-management.base.ts
|
|
607
645
|
var BaseWellnessManagement = class {
|
|
608
646
|
static {
|
|
@@ -700,79 +738,1582 @@ var BasePaymentUserManagement = class {
|
|
|
700
738
|
__name(this, "BasePaymentUserManagement");
|
|
701
739
|
}
|
|
702
740
|
};
|
|
703
|
-
|
|
704
|
-
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/capabilities/membership/subcapabilities/customer-management.base.ts
|
|
705
|
-
var BaseMembershipCustomerManagement = class {
|
|
741
|
+
|
|
742
|
+
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/capabilities/membership/subcapabilities/customer-management.base.ts
|
|
743
|
+
var BaseMembershipCustomerManagement = class {
|
|
744
|
+
static {
|
|
745
|
+
__name(this, "BaseMembershipCustomerManagement");
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/capabilities/membership/subcapabilities/membership-management.base.ts
|
|
750
|
+
var BaseMembershipManagement = class {
|
|
751
|
+
static {
|
|
752
|
+
__name(this, "BaseMembershipManagement");
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
// ../../packages/dvss-integration-libs/src/integration-operation-skeletons/capabilities/integration-configuration/integration-configuration.base.ts
|
|
757
|
+
var BaseIntegrationConfiguration = class {
|
|
758
|
+
static {
|
|
759
|
+
__name(this, "BaseIntegrationConfiguration");
|
|
760
|
+
}
|
|
761
|
+
integrationConfigurationDao;
|
|
762
|
+
commonValidationDatabaseService;
|
|
763
|
+
constructor(integrationConfigurationDao, commonValidationDatabaseService) {
|
|
764
|
+
this.integrationConfigurationDao = integrationConfigurationDao;
|
|
765
|
+
this.commonValidationDatabaseService = commonValidationDatabaseService;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Validates add-capability-integration input (project, property, parent, capability, provider, configuredFor).
|
|
769
|
+
* Logic copied from project-ms CapabilityIntegrationService.validateAddCapabilityIntegrationInput.
|
|
770
|
+
*/
|
|
771
|
+
async validateAddCapabilityIntegrationInput(input, context) {
|
|
772
|
+
await this.commonValidationDatabaseService.getProject({
|
|
773
|
+
projectId: input.projectId
|
|
774
|
+
});
|
|
775
|
+
if (input.propertyId != null) {
|
|
776
|
+
await this.commonValidationDatabaseService.getProperty({
|
|
777
|
+
propertyId: input.propertyId,
|
|
778
|
+
projectId: input.projectId
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
if (input.parentId != null) {
|
|
782
|
+
const parentIntegration = await this.integrationConfigurationDao.getCapabilityIntegration({
|
|
783
|
+
capabilityIntegrationId: input.parentId
|
|
784
|
+
}, context.loggedInUserId);
|
|
785
|
+
if (!parentIntegration) {
|
|
786
|
+
throw new Error("Parent capability integration not found");
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
const [capability, capabilityProvider] = await Promise.all([
|
|
790
|
+
this.integrationConfigurationDao.getCapability({
|
|
791
|
+
capabilityId: input.capabilityId
|
|
792
|
+
}, context.loggedInUserId),
|
|
793
|
+
this.integrationConfigurationDao.getCapabilityProvider({
|
|
794
|
+
capabilityProviderId: input.capabilityProviderId
|
|
795
|
+
}, context.loggedInUserId)
|
|
796
|
+
]);
|
|
797
|
+
if (!capability) {
|
|
798
|
+
throw new Error("Capability not found");
|
|
799
|
+
}
|
|
800
|
+
if (!capabilityProvider) {
|
|
801
|
+
throw new Error("Capability provider not found");
|
|
802
|
+
}
|
|
803
|
+
if (capability.providerId !== capabilityProvider.id) {
|
|
804
|
+
throw new Error(`Capability provider mismatch: capabilityId=${capability.id}, capabilityProviderId=${capability.providerId}`);
|
|
805
|
+
}
|
|
806
|
+
return {
|
|
807
|
+
capability: {
|
|
808
|
+
id: capability.id,
|
|
809
|
+
type: capability.type,
|
|
810
|
+
category: capability.category,
|
|
811
|
+
providerId: capability.providerId
|
|
812
|
+
},
|
|
813
|
+
capabilityProvider: {
|
|
814
|
+
id: capabilityProvider.id
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Add a capability integration (validate then persist via DAO).
|
|
820
|
+
* Same name as project MS call: addCapabilityIntegration.
|
|
821
|
+
*/
|
|
822
|
+
async addCapabilityIntegration(input, context) {
|
|
823
|
+
const { capability, capabilityProvider } = await this.validateAddCapabilityIntegrationInput(input, context);
|
|
824
|
+
const addCapabilityIntegrationInput = {
|
|
825
|
+
...input,
|
|
826
|
+
providerId: capabilityProvider.id,
|
|
827
|
+
createdBy: context.loggedInUserId,
|
|
828
|
+
type: capability.type,
|
|
829
|
+
category: capability.category,
|
|
830
|
+
availableFor: input.availableFor,
|
|
831
|
+
configuredFor: input.configuredFor
|
|
832
|
+
};
|
|
833
|
+
const result = await this.integrationConfigurationDao.addCapabilityIntegration(addCapabilityIntegrationInput, context.loggedInUserId);
|
|
834
|
+
if (!result || !result.id) {
|
|
835
|
+
throw new Error("Failed to add capability integration");
|
|
836
|
+
}
|
|
837
|
+
return result;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Update a capability integration (add audit then persist via DAO).
|
|
841
|
+
* Same as project MS call: updateCapabilityIntegration.
|
|
842
|
+
* DAO logic copied from project-ms CapabilityIntegrationDao.updateCapabilityIntegration.
|
|
843
|
+
*/
|
|
844
|
+
async updateCapabilityIntegration(id, updateData, context) {
|
|
845
|
+
const updateDataWithAudit = {
|
|
846
|
+
...updateData,
|
|
847
|
+
updatedBy: context.loggedInUserId
|
|
848
|
+
};
|
|
849
|
+
return await this.integrationConfigurationDao.updateCapabilityIntegration({
|
|
850
|
+
id,
|
|
851
|
+
updateData: updateDataWithAudit
|
|
852
|
+
}, context.loggedInUserId);
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// ../../node_modules/drizzle-orm/entity.js
|
|
857
|
+
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
858
|
+
function is(value, type) {
|
|
859
|
+
if (!value || typeof value !== "object") {
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
862
|
+
if (value instanceof type) {
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
|
|
866
|
+
throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
|
|
867
|
+
}
|
|
868
|
+
let cls = value.constructor;
|
|
869
|
+
if (cls) {
|
|
870
|
+
while (cls) {
|
|
871
|
+
if (entityKind in cls && cls[entityKind] === type[entityKind]) {
|
|
872
|
+
return true;
|
|
873
|
+
}
|
|
874
|
+
cls = Object.getPrototypeOf(cls);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
__name(is, "is");
|
|
880
|
+
|
|
881
|
+
// ../../node_modules/drizzle-orm/column.js
|
|
882
|
+
var Column = class Column2 {
|
|
883
|
+
static {
|
|
884
|
+
__name(this, "Column");
|
|
885
|
+
}
|
|
886
|
+
constructor(table, config3) {
|
|
887
|
+
this.table = table;
|
|
888
|
+
this.config = config3;
|
|
889
|
+
this.name = config3.name;
|
|
890
|
+
this.notNull = config3.notNull;
|
|
891
|
+
this.default = config3.default;
|
|
892
|
+
this.defaultFn = config3.defaultFn;
|
|
893
|
+
this.onUpdateFn = config3.onUpdateFn;
|
|
894
|
+
this.hasDefault = config3.hasDefault;
|
|
895
|
+
this.primary = config3.primaryKey;
|
|
896
|
+
this.isUnique = config3.isUnique;
|
|
897
|
+
this.uniqueName = config3.uniqueName;
|
|
898
|
+
this.uniqueType = config3.uniqueType;
|
|
899
|
+
this.dataType = config3.dataType;
|
|
900
|
+
this.columnType = config3.columnType;
|
|
901
|
+
this.generated = config3.generated;
|
|
902
|
+
this.generatedIdentity = config3.generatedIdentity;
|
|
903
|
+
}
|
|
904
|
+
static [entityKind] = "Column";
|
|
905
|
+
name;
|
|
906
|
+
primary;
|
|
907
|
+
notNull;
|
|
908
|
+
default;
|
|
909
|
+
defaultFn;
|
|
910
|
+
onUpdateFn;
|
|
911
|
+
hasDefault;
|
|
912
|
+
isUnique;
|
|
913
|
+
uniqueName;
|
|
914
|
+
uniqueType;
|
|
915
|
+
dataType;
|
|
916
|
+
columnType;
|
|
917
|
+
enumValues = void 0;
|
|
918
|
+
generated = void 0;
|
|
919
|
+
generatedIdentity = void 0;
|
|
920
|
+
config;
|
|
921
|
+
mapFromDriverValue(value) {
|
|
922
|
+
return value;
|
|
923
|
+
}
|
|
924
|
+
mapToDriverValue(value) {
|
|
925
|
+
return value;
|
|
926
|
+
}
|
|
927
|
+
// ** @internal */
|
|
928
|
+
shouldDisableInsert() {
|
|
929
|
+
return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
// ../../node_modules/drizzle-orm/column-builder.js
|
|
934
|
+
var ColumnBuilder = class ColumnBuilder2 {
|
|
935
|
+
static {
|
|
936
|
+
__name(this, "ColumnBuilder");
|
|
937
|
+
}
|
|
938
|
+
static [entityKind] = "ColumnBuilder";
|
|
939
|
+
config;
|
|
940
|
+
constructor(name, dataType, columnType) {
|
|
941
|
+
this.config = {
|
|
942
|
+
name,
|
|
943
|
+
notNull: false,
|
|
944
|
+
default: void 0,
|
|
945
|
+
hasDefault: false,
|
|
946
|
+
primaryKey: false,
|
|
947
|
+
isUnique: false,
|
|
948
|
+
uniqueName: void 0,
|
|
949
|
+
uniqueType: void 0,
|
|
950
|
+
dataType,
|
|
951
|
+
columnType,
|
|
952
|
+
generated: void 0
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
|
|
957
|
+
*
|
|
958
|
+
* @example
|
|
959
|
+
* ```ts
|
|
960
|
+
* const users = pgTable('users', {
|
|
961
|
+
* id: integer('id').$type<UserId>().primaryKey(),
|
|
962
|
+
* details: json('details').$type<UserDetails>().notNull(),
|
|
963
|
+
* });
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
$type() {
|
|
967
|
+
return this;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Adds a `not null` clause to the column definition.
|
|
971
|
+
*
|
|
972
|
+
* Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
|
|
973
|
+
*/
|
|
974
|
+
notNull() {
|
|
975
|
+
this.config.notNull = true;
|
|
976
|
+
return this;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Adds a `default <value>` clause to the column definition.
|
|
980
|
+
*
|
|
981
|
+
* Affects the `insert` model of the table - columns *with* `default` are optional on insert.
|
|
982
|
+
*
|
|
983
|
+
* If you need to set a dynamic default value, use {@link $defaultFn} instead.
|
|
984
|
+
*/
|
|
985
|
+
default(value) {
|
|
986
|
+
this.config.default = value;
|
|
987
|
+
this.config.hasDefault = true;
|
|
988
|
+
return this;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Adds a dynamic default value to the column.
|
|
992
|
+
* The function will be called when the row is inserted, and the returned value will be used as the column value.
|
|
993
|
+
*
|
|
994
|
+
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
995
|
+
*/
|
|
996
|
+
$defaultFn(fn) {
|
|
997
|
+
this.config.defaultFn = fn;
|
|
998
|
+
this.config.hasDefault = true;
|
|
999
|
+
return this;
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Alias for {@link $defaultFn}.
|
|
1003
|
+
*/
|
|
1004
|
+
$default = this.$defaultFn;
|
|
1005
|
+
/**
|
|
1006
|
+
* Adds a dynamic update value to the column.
|
|
1007
|
+
* The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
|
|
1008
|
+
* If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
|
|
1009
|
+
*
|
|
1010
|
+
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
1011
|
+
*/
|
|
1012
|
+
$onUpdateFn(fn) {
|
|
1013
|
+
this.config.onUpdateFn = fn;
|
|
1014
|
+
this.config.hasDefault = true;
|
|
1015
|
+
return this;
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Alias for {@link $onUpdateFn}.
|
|
1019
|
+
*/
|
|
1020
|
+
$onUpdate = this.$onUpdateFn;
|
|
1021
|
+
/**
|
|
1022
|
+
* Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
|
|
1023
|
+
*
|
|
1024
|
+
* In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
|
|
1025
|
+
*/
|
|
1026
|
+
primaryKey() {
|
|
1027
|
+
this.config.primaryKey = true;
|
|
1028
|
+
this.config.notNull = true;
|
|
1029
|
+
return this;
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
// ../../node_modules/drizzle-orm/table.js
|
|
1034
|
+
var TableName = /* @__PURE__ */ Symbol.for("drizzle:Name");
|
|
1035
|
+
var Schema = /* @__PURE__ */ Symbol.for("drizzle:Schema");
|
|
1036
|
+
var Columns = /* @__PURE__ */ Symbol.for("drizzle:Columns");
|
|
1037
|
+
var ExtraConfigColumns = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns");
|
|
1038
|
+
var OriginalName = /* @__PURE__ */ Symbol.for("drizzle:OriginalName");
|
|
1039
|
+
var BaseName = /* @__PURE__ */ Symbol.for("drizzle:BaseName");
|
|
1040
|
+
var IsAlias = /* @__PURE__ */ Symbol.for("drizzle:IsAlias");
|
|
1041
|
+
var ExtraConfigBuilder = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder");
|
|
1042
|
+
var IsDrizzleTable = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
|
|
1043
|
+
var Table = class Table2 {
|
|
1044
|
+
static {
|
|
1045
|
+
__name(this, "Table");
|
|
1046
|
+
}
|
|
1047
|
+
static [entityKind] = "Table";
|
|
1048
|
+
/** @internal */
|
|
1049
|
+
static Symbol = {
|
|
1050
|
+
Name: TableName,
|
|
1051
|
+
Schema,
|
|
1052
|
+
OriginalName,
|
|
1053
|
+
Columns,
|
|
1054
|
+
ExtraConfigColumns,
|
|
1055
|
+
BaseName,
|
|
1056
|
+
IsAlias,
|
|
1057
|
+
ExtraConfigBuilder
|
|
1058
|
+
};
|
|
1059
|
+
/**
|
|
1060
|
+
* @internal
|
|
1061
|
+
* Can be changed if the table is aliased.
|
|
1062
|
+
*/
|
|
1063
|
+
[TableName];
|
|
1064
|
+
/**
|
|
1065
|
+
* @internal
|
|
1066
|
+
* Used to store the original name of the table, before any aliasing.
|
|
1067
|
+
*/
|
|
1068
|
+
[OriginalName];
|
|
1069
|
+
/** @internal */
|
|
1070
|
+
[Schema];
|
|
1071
|
+
/** @internal */
|
|
1072
|
+
[Columns];
|
|
1073
|
+
/** @internal */
|
|
1074
|
+
[ExtraConfigColumns];
|
|
1075
|
+
/**
|
|
1076
|
+
* @internal
|
|
1077
|
+
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
1078
|
+
*/
|
|
1079
|
+
[BaseName];
|
|
1080
|
+
/** @internal */
|
|
1081
|
+
[IsAlias] = false;
|
|
1082
|
+
/** @internal */
|
|
1083
|
+
[IsDrizzleTable] = true;
|
|
1084
|
+
/** @internal */
|
|
1085
|
+
[ExtraConfigBuilder] = void 0;
|
|
1086
|
+
constructor(name, schema2, baseName) {
|
|
1087
|
+
this[TableName] = this[OriginalName] = name;
|
|
1088
|
+
this[Schema] = schema2;
|
|
1089
|
+
this[BaseName] = baseName;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
// ../../node_modules/drizzle-orm/pg-core/table.js
|
|
1094
|
+
var InlineForeignKeys = /* @__PURE__ */ Symbol.for("drizzle:PgInlineForeignKeys");
|
|
1095
|
+
var PgTable = class PgTable2 extends Table {
|
|
1096
|
+
static {
|
|
1097
|
+
__name(this, "PgTable");
|
|
1098
|
+
}
|
|
1099
|
+
static [entityKind] = "PgTable";
|
|
1100
|
+
/** @internal */
|
|
1101
|
+
static Symbol = Object.assign({}, Table.Symbol, {
|
|
1102
|
+
InlineForeignKeys
|
|
1103
|
+
});
|
|
1104
|
+
/**@internal */
|
|
1105
|
+
[InlineForeignKeys] = [];
|
|
1106
|
+
/** @internal */
|
|
1107
|
+
[Table.Symbol.ExtraConfigBuilder] = void 0;
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
// ../../node_modules/drizzle-orm/pg-core/foreign-keys.js
|
|
1111
|
+
var ForeignKeyBuilder = class ForeignKeyBuilder2 {
|
|
1112
|
+
static {
|
|
1113
|
+
__name(this, "ForeignKeyBuilder");
|
|
1114
|
+
}
|
|
1115
|
+
static [entityKind] = "PgForeignKeyBuilder";
|
|
1116
|
+
/** @internal */
|
|
1117
|
+
reference;
|
|
1118
|
+
/** @internal */
|
|
1119
|
+
_onUpdate = "no action";
|
|
1120
|
+
/** @internal */
|
|
1121
|
+
_onDelete = "no action";
|
|
1122
|
+
constructor(config3, actions) {
|
|
1123
|
+
this.reference = () => {
|
|
1124
|
+
const { name, columns, foreignColumns } = config3();
|
|
1125
|
+
return {
|
|
1126
|
+
name,
|
|
1127
|
+
columns,
|
|
1128
|
+
foreignTable: foreignColumns[0].table,
|
|
1129
|
+
foreignColumns
|
|
1130
|
+
};
|
|
1131
|
+
};
|
|
1132
|
+
if (actions) {
|
|
1133
|
+
this._onUpdate = actions.onUpdate;
|
|
1134
|
+
this._onDelete = actions.onDelete;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
onUpdate(action) {
|
|
1138
|
+
this._onUpdate = action === void 0 ? "no action" : action;
|
|
1139
|
+
return this;
|
|
1140
|
+
}
|
|
1141
|
+
onDelete(action) {
|
|
1142
|
+
this._onDelete = action === void 0 ? "no action" : action;
|
|
1143
|
+
return this;
|
|
1144
|
+
}
|
|
1145
|
+
/** @internal */
|
|
1146
|
+
build(table) {
|
|
1147
|
+
return new ForeignKey(table, this);
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
var ForeignKey = class ForeignKey2 {
|
|
1151
|
+
static {
|
|
1152
|
+
__name(this, "ForeignKey");
|
|
1153
|
+
}
|
|
1154
|
+
constructor(table, builder) {
|
|
1155
|
+
this.table = table;
|
|
1156
|
+
this.reference = builder.reference;
|
|
1157
|
+
this.onUpdate = builder._onUpdate;
|
|
1158
|
+
this.onDelete = builder._onDelete;
|
|
1159
|
+
}
|
|
1160
|
+
static [entityKind] = "PgForeignKey";
|
|
1161
|
+
reference;
|
|
1162
|
+
onUpdate;
|
|
1163
|
+
onDelete;
|
|
1164
|
+
getName() {
|
|
1165
|
+
const { name, columns, foreignColumns } = this.reference();
|
|
1166
|
+
const columnNames = columns.map((column) => column.name);
|
|
1167
|
+
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
1168
|
+
const chunks = [
|
|
1169
|
+
this.table[PgTable.Symbol.Name],
|
|
1170
|
+
...columnNames,
|
|
1171
|
+
foreignColumns[0].table[PgTable.Symbol.Name],
|
|
1172
|
+
...foreignColumnNames
|
|
1173
|
+
];
|
|
1174
|
+
return name ?? `${chunks.join("_")}_fk`;
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
// ../../node_modules/drizzle-orm/tracing-utils.js
|
|
1179
|
+
function iife(fn, ...args) {
|
|
1180
|
+
return fn(...args);
|
|
1181
|
+
}
|
|
1182
|
+
__name(iife, "iife");
|
|
1183
|
+
|
|
1184
|
+
// ../../node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
1185
|
+
function uniqueKeyName(table, columns) {
|
|
1186
|
+
return `${table[PgTable.Symbol.Name]}_${columns.join("_")}_unique`;
|
|
1187
|
+
}
|
|
1188
|
+
__name(uniqueKeyName, "uniqueKeyName");
|
|
1189
|
+
var UniqueConstraintBuilder = class UniqueConstraintBuilder2 {
|
|
1190
|
+
static {
|
|
1191
|
+
__name(this, "UniqueConstraintBuilder");
|
|
1192
|
+
}
|
|
1193
|
+
constructor(columns, name) {
|
|
1194
|
+
this.name = name;
|
|
1195
|
+
this.columns = columns;
|
|
1196
|
+
}
|
|
1197
|
+
static [entityKind] = "PgUniqueConstraintBuilder";
|
|
1198
|
+
/** @internal */
|
|
1199
|
+
columns;
|
|
1200
|
+
/** @internal */
|
|
1201
|
+
nullsNotDistinctConfig = false;
|
|
1202
|
+
nullsNotDistinct() {
|
|
1203
|
+
this.nullsNotDistinctConfig = true;
|
|
1204
|
+
return this;
|
|
1205
|
+
}
|
|
1206
|
+
/** @internal */
|
|
1207
|
+
build(table) {
|
|
1208
|
+
return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
(class UniqueOnConstraintBuilder2 {
|
|
1212
|
+
static {
|
|
1213
|
+
__name(this, "UniqueOnConstraintBuilder");
|
|
1214
|
+
}
|
|
1215
|
+
static [entityKind] = "PgUniqueOnConstraintBuilder";
|
|
1216
|
+
/** @internal */
|
|
1217
|
+
name;
|
|
1218
|
+
constructor(name) {
|
|
1219
|
+
this.name = name;
|
|
1220
|
+
}
|
|
1221
|
+
on(...columns) {
|
|
1222
|
+
return new UniqueConstraintBuilder(columns, this.name);
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
var UniqueConstraint = class UniqueConstraint2 {
|
|
1226
|
+
static {
|
|
1227
|
+
__name(this, "UniqueConstraint");
|
|
1228
|
+
}
|
|
1229
|
+
constructor(table, columns, nullsNotDistinct, name) {
|
|
1230
|
+
this.table = table;
|
|
1231
|
+
this.columns = columns;
|
|
1232
|
+
this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
|
|
1233
|
+
this.nullsNotDistinct = nullsNotDistinct;
|
|
1234
|
+
}
|
|
1235
|
+
static [entityKind] = "PgUniqueConstraint";
|
|
1236
|
+
columns;
|
|
1237
|
+
name;
|
|
1238
|
+
nullsNotDistinct = false;
|
|
1239
|
+
getName() {
|
|
1240
|
+
return this.name;
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1244
|
+
// ../../node_modules/drizzle-orm/pg-core/utils/array.js
|
|
1245
|
+
function parsePgArrayValue(arrayString, startFrom, inQuotes) {
|
|
1246
|
+
for (let i = startFrom; i < arrayString.length; i++) {
|
|
1247
|
+
const char = arrayString[i];
|
|
1248
|
+
if (char === "\\") {
|
|
1249
|
+
i++;
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
if (char === '"') {
|
|
1253
|
+
return [
|
|
1254
|
+
arrayString.slice(startFrom, i).replace(/\\/g, ""),
|
|
1255
|
+
i + 1
|
|
1256
|
+
];
|
|
1257
|
+
}
|
|
1258
|
+
if (inQuotes) {
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
if (char === "," || char === "}") {
|
|
1262
|
+
return [
|
|
1263
|
+
arrayString.slice(startFrom, i).replace(/\\/g, ""),
|
|
1264
|
+
i
|
|
1265
|
+
];
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
return [
|
|
1269
|
+
arrayString.slice(startFrom).replace(/\\/g, ""),
|
|
1270
|
+
arrayString.length
|
|
1271
|
+
];
|
|
1272
|
+
}
|
|
1273
|
+
__name(parsePgArrayValue, "parsePgArrayValue");
|
|
1274
|
+
function parsePgNestedArray(arrayString, startFrom = 0) {
|
|
1275
|
+
const result = [];
|
|
1276
|
+
let i = startFrom;
|
|
1277
|
+
let lastCharIsComma = false;
|
|
1278
|
+
while (i < arrayString.length) {
|
|
1279
|
+
const char = arrayString[i];
|
|
1280
|
+
if (char === ",") {
|
|
1281
|
+
if (lastCharIsComma || i === startFrom) {
|
|
1282
|
+
result.push("");
|
|
1283
|
+
}
|
|
1284
|
+
lastCharIsComma = true;
|
|
1285
|
+
i++;
|
|
1286
|
+
continue;
|
|
1287
|
+
}
|
|
1288
|
+
lastCharIsComma = false;
|
|
1289
|
+
if (char === "\\") {
|
|
1290
|
+
i += 2;
|
|
1291
|
+
continue;
|
|
1292
|
+
}
|
|
1293
|
+
if (char === '"') {
|
|
1294
|
+
const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
|
|
1295
|
+
result.push(value2);
|
|
1296
|
+
i = startFrom2;
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
if (char === "}") {
|
|
1300
|
+
return [
|
|
1301
|
+
result,
|
|
1302
|
+
i + 1
|
|
1303
|
+
];
|
|
1304
|
+
}
|
|
1305
|
+
if (char === "{") {
|
|
1306
|
+
const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
|
|
1307
|
+
result.push(value2);
|
|
1308
|
+
i = startFrom2;
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
|
|
1312
|
+
result.push(value);
|
|
1313
|
+
i = newStartFrom;
|
|
1314
|
+
}
|
|
1315
|
+
return [
|
|
1316
|
+
result,
|
|
1317
|
+
i
|
|
1318
|
+
];
|
|
1319
|
+
}
|
|
1320
|
+
__name(parsePgNestedArray, "parsePgNestedArray");
|
|
1321
|
+
function parsePgArray(arrayString) {
|
|
1322
|
+
const [result] = parsePgNestedArray(arrayString, 1);
|
|
1323
|
+
return result;
|
|
1324
|
+
}
|
|
1325
|
+
__name(parsePgArray, "parsePgArray");
|
|
1326
|
+
function makePgArray(array) {
|
|
1327
|
+
return `{${array.map((item) => {
|
|
1328
|
+
if (Array.isArray(item)) {
|
|
1329
|
+
return makePgArray(item);
|
|
1330
|
+
}
|
|
1331
|
+
if (typeof item === "string") {
|
|
1332
|
+
return `"${item.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
1333
|
+
}
|
|
1334
|
+
return `${item}`;
|
|
1335
|
+
}).join(",")}}`;
|
|
1336
|
+
}
|
|
1337
|
+
__name(makePgArray, "makePgArray");
|
|
1338
|
+
|
|
1339
|
+
// ../../node_modules/drizzle-orm/pg-core/columns/common.js
|
|
1340
|
+
var PgColumnBuilder = class PgColumnBuilder2 extends ColumnBuilder {
|
|
1341
|
+
static {
|
|
1342
|
+
__name(this, "PgColumnBuilder");
|
|
1343
|
+
}
|
|
1344
|
+
foreignKeyConfigs = [];
|
|
1345
|
+
static [entityKind] = "PgColumnBuilder";
|
|
1346
|
+
array(size) {
|
|
1347
|
+
return new PgArrayBuilder(this.config.name, this, size);
|
|
1348
|
+
}
|
|
1349
|
+
references(ref, actions = {}) {
|
|
1350
|
+
this.foreignKeyConfigs.push({
|
|
1351
|
+
ref,
|
|
1352
|
+
actions
|
|
1353
|
+
});
|
|
1354
|
+
return this;
|
|
1355
|
+
}
|
|
1356
|
+
unique(name, config3) {
|
|
1357
|
+
this.config.isUnique = true;
|
|
1358
|
+
this.config.uniqueName = name;
|
|
1359
|
+
this.config.uniqueType = config3?.nulls;
|
|
1360
|
+
return this;
|
|
1361
|
+
}
|
|
1362
|
+
generatedAlwaysAs(as) {
|
|
1363
|
+
this.config.generated = {
|
|
1364
|
+
as,
|
|
1365
|
+
type: "always",
|
|
1366
|
+
mode: "stored"
|
|
1367
|
+
};
|
|
1368
|
+
return this;
|
|
1369
|
+
}
|
|
1370
|
+
/** @internal */
|
|
1371
|
+
buildForeignKeys(column, table) {
|
|
1372
|
+
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
1373
|
+
return iife((ref2, actions2) => {
|
|
1374
|
+
const builder = new ForeignKeyBuilder(() => {
|
|
1375
|
+
const foreignColumn = ref2();
|
|
1376
|
+
return {
|
|
1377
|
+
columns: [
|
|
1378
|
+
column
|
|
1379
|
+
],
|
|
1380
|
+
foreignColumns: [
|
|
1381
|
+
foreignColumn
|
|
1382
|
+
]
|
|
1383
|
+
};
|
|
1384
|
+
});
|
|
1385
|
+
if (actions2.onUpdate) {
|
|
1386
|
+
builder.onUpdate(actions2.onUpdate);
|
|
1387
|
+
}
|
|
1388
|
+
if (actions2.onDelete) {
|
|
1389
|
+
builder.onDelete(actions2.onDelete);
|
|
1390
|
+
}
|
|
1391
|
+
return builder.build(table);
|
|
1392
|
+
}, ref, actions);
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
/** @internal */
|
|
1396
|
+
buildExtraConfigColumn(table) {
|
|
1397
|
+
return new ExtraConfigColumn(table, this.config);
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
var PgColumn = class PgColumn2 extends Column {
|
|
1401
|
+
static {
|
|
1402
|
+
__name(this, "PgColumn");
|
|
1403
|
+
}
|
|
1404
|
+
constructor(table, config3) {
|
|
1405
|
+
if (!config3.uniqueName) {
|
|
1406
|
+
config3.uniqueName = uniqueKeyName(table, [
|
|
1407
|
+
config3.name
|
|
1408
|
+
]);
|
|
1409
|
+
}
|
|
1410
|
+
super(table, config3);
|
|
1411
|
+
this.table = table;
|
|
1412
|
+
}
|
|
1413
|
+
static [entityKind] = "PgColumn";
|
|
1414
|
+
};
|
|
1415
|
+
var ExtraConfigColumn = class ExtraConfigColumn2 extends PgColumn {
|
|
1416
|
+
static {
|
|
1417
|
+
__name(this, "ExtraConfigColumn");
|
|
1418
|
+
}
|
|
1419
|
+
static [entityKind] = "ExtraConfigColumn";
|
|
1420
|
+
getSQLType() {
|
|
1421
|
+
return this.getSQLType();
|
|
1422
|
+
}
|
|
1423
|
+
indexConfig = {
|
|
1424
|
+
order: this.config.order ?? "asc",
|
|
1425
|
+
nulls: this.config.nulls ?? "last",
|
|
1426
|
+
opClass: this.config.opClass
|
|
1427
|
+
};
|
|
1428
|
+
defaultConfig = {
|
|
1429
|
+
order: "asc",
|
|
1430
|
+
nulls: "last",
|
|
1431
|
+
opClass: void 0
|
|
1432
|
+
};
|
|
1433
|
+
asc() {
|
|
1434
|
+
this.indexConfig.order = "asc";
|
|
1435
|
+
return this;
|
|
1436
|
+
}
|
|
1437
|
+
desc() {
|
|
1438
|
+
this.indexConfig.order = "desc";
|
|
1439
|
+
return this;
|
|
1440
|
+
}
|
|
1441
|
+
nullsFirst() {
|
|
1442
|
+
this.indexConfig.nulls = "first";
|
|
1443
|
+
return this;
|
|
1444
|
+
}
|
|
1445
|
+
nullsLast() {
|
|
1446
|
+
this.indexConfig.nulls = "last";
|
|
1447
|
+
return this;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* ### PostgreSQL documentation quote
|
|
1451
|
+
*
|
|
1452
|
+
* > An operator class with optional parameters can be specified for each column of an index.
|
|
1453
|
+
* The operator class identifies the operators to be used by the index for that column.
|
|
1454
|
+
* For example, a B-tree index on four-byte integers would use the int4_ops class;
|
|
1455
|
+
* this operator class includes comparison functions for four-byte integers.
|
|
1456
|
+
* In practice the default operator class for the column's data type is usually sufficient.
|
|
1457
|
+
* The main point of having operator classes is that for some data types, there could be more than one meaningful ordering.
|
|
1458
|
+
* For example, we might want to sort a complex-number data type either by absolute value or by real part.
|
|
1459
|
+
* We could do this by defining two operator classes for the data type and then selecting the proper class when creating an index.
|
|
1460
|
+
* More information about operator classes check:
|
|
1461
|
+
*
|
|
1462
|
+
* ### Useful links
|
|
1463
|
+
* https://www.postgresql.org/docs/current/sql-createindex.html
|
|
1464
|
+
*
|
|
1465
|
+
* https://www.postgresql.org/docs/current/indexes-opclass.html
|
|
1466
|
+
*
|
|
1467
|
+
* https://www.postgresql.org/docs/current/xindex.html
|
|
1468
|
+
*
|
|
1469
|
+
* ### Additional types
|
|
1470
|
+
* If you have the `pg_vector` extension installed in your database, you can use the
|
|
1471
|
+
* `vector_l2_ops`, `vector_ip_ops`, `vector_cosine_ops`, `vector_l1_ops`, `bit_hamming_ops`, `bit_jaccard_ops`, `halfvec_l2_ops`, `sparsevec_l2_ops` options, which are predefined types.
|
|
1472
|
+
*
|
|
1473
|
+
* **You can always specify any string you want in the operator class, in case Drizzle doesn't have it natively in its types**
|
|
1474
|
+
*
|
|
1475
|
+
* @param opClass
|
|
1476
|
+
* @returns
|
|
1477
|
+
*/
|
|
1478
|
+
op(opClass) {
|
|
1479
|
+
this.indexConfig.opClass = opClass;
|
|
1480
|
+
return this;
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
(class IndexedColumn2 {
|
|
1484
|
+
static {
|
|
1485
|
+
__name(this, "IndexedColumn");
|
|
1486
|
+
}
|
|
1487
|
+
static [entityKind] = "IndexedColumn";
|
|
1488
|
+
constructor(name, type, indexConfig) {
|
|
1489
|
+
this.name = name;
|
|
1490
|
+
this.type = type;
|
|
1491
|
+
this.indexConfig = indexConfig;
|
|
1492
|
+
}
|
|
1493
|
+
name;
|
|
1494
|
+
type;
|
|
1495
|
+
indexConfig;
|
|
1496
|
+
});
|
|
1497
|
+
var PgArrayBuilder = class PgArrayBuilder2 extends PgColumnBuilder {
|
|
1498
|
+
static {
|
|
1499
|
+
__name(this, "PgArrayBuilder");
|
|
1500
|
+
}
|
|
1501
|
+
static [entityKind] = "PgArrayBuilder";
|
|
1502
|
+
constructor(name, baseBuilder, size) {
|
|
1503
|
+
super(name, "array", "PgArray");
|
|
1504
|
+
this.config.baseBuilder = baseBuilder;
|
|
1505
|
+
this.config.size = size;
|
|
1506
|
+
}
|
|
1507
|
+
/** @internal */
|
|
1508
|
+
build(table) {
|
|
1509
|
+
const baseColumn = this.config.baseBuilder.build(table);
|
|
1510
|
+
return new PgArray(table, this.config, baseColumn);
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
var PgArray = class PgArray2 extends PgColumn {
|
|
1514
|
+
static {
|
|
1515
|
+
__name(this, "PgArray");
|
|
1516
|
+
}
|
|
1517
|
+
constructor(table, config3, baseColumn, range) {
|
|
1518
|
+
super(table, config3);
|
|
1519
|
+
this.baseColumn = baseColumn;
|
|
1520
|
+
this.range = range;
|
|
1521
|
+
this.size = config3.size;
|
|
1522
|
+
}
|
|
1523
|
+
size;
|
|
1524
|
+
static [entityKind] = "PgArray";
|
|
1525
|
+
getSQLType() {
|
|
1526
|
+
return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
|
|
1527
|
+
}
|
|
1528
|
+
mapFromDriverValue(value) {
|
|
1529
|
+
if (typeof value === "string") {
|
|
1530
|
+
value = parsePgArray(value);
|
|
1531
|
+
}
|
|
1532
|
+
return value.map((v) => this.baseColumn.mapFromDriverValue(v));
|
|
1533
|
+
}
|
|
1534
|
+
mapToDriverValue(value, isNestedArray = false) {
|
|
1535
|
+
const a = value.map((v) => v === null ? null : is(this.baseColumn, PgArray2) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v));
|
|
1536
|
+
if (isNestedArray) return a;
|
|
1537
|
+
return makePgArray(a);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
// ../../node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
1542
|
+
var isPgEnumSym = /* @__PURE__ */ Symbol.for("drizzle:isPgEnum");
|
|
1543
|
+
function isPgEnum(obj) {
|
|
1544
|
+
return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
|
|
1545
|
+
}
|
|
1546
|
+
__name(isPgEnum, "isPgEnum");
|
|
1547
|
+
(class PgEnumColumnBuilder2 extends PgColumnBuilder {
|
|
1548
|
+
static {
|
|
1549
|
+
__name(this, "PgEnumColumnBuilder");
|
|
1550
|
+
}
|
|
1551
|
+
static [entityKind] = "PgEnumColumnBuilder";
|
|
1552
|
+
constructor(name, enumInstance) {
|
|
1553
|
+
super(name, "string", "PgEnumColumn");
|
|
1554
|
+
this.config.enum = enumInstance;
|
|
1555
|
+
}
|
|
1556
|
+
/** @internal */
|
|
1557
|
+
build(table) {
|
|
1558
|
+
return new PgEnumColumn(table, this.config);
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
var PgEnumColumn = class PgEnumColumn2 extends PgColumn {
|
|
1562
|
+
static {
|
|
1563
|
+
__name(this, "PgEnumColumn");
|
|
1564
|
+
}
|
|
1565
|
+
static [entityKind] = "PgEnumColumn";
|
|
1566
|
+
enum = this.config.enum;
|
|
1567
|
+
enumValues = this.config.enum.enumValues;
|
|
1568
|
+
constructor(table, config3) {
|
|
1569
|
+
super(table, config3);
|
|
1570
|
+
this.enum = config3.enum;
|
|
1571
|
+
}
|
|
1572
|
+
getSQLType() {
|
|
1573
|
+
return this.enum.enumName;
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1577
|
+
// ../../node_modules/drizzle-orm/subquery.js
|
|
1578
|
+
var Subquery = class Subquery2 {
|
|
1579
|
+
static {
|
|
1580
|
+
__name(this, "Subquery");
|
|
1581
|
+
}
|
|
1582
|
+
static [entityKind] = "Subquery";
|
|
1583
|
+
constructor(sql2, selection, alias, isWith = false) {
|
|
1584
|
+
this._ = {
|
|
1585
|
+
brand: "Subquery",
|
|
1586
|
+
sql: sql2,
|
|
1587
|
+
selectedFields: selection,
|
|
1588
|
+
alias,
|
|
1589
|
+
isWith
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
(class WithSubquery2 extends Subquery {
|
|
1594
|
+
static {
|
|
1595
|
+
__name(this, "WithSubquery");
|
|
1596
|
+
}
|
|
1597
|
+
static [entityKind] = "WithSubquery";
|
|
1598
|
+
});
|
|
1599
|
+
var tracer = {
|
|
1600
|
+
startActiveSpan(name, fn) {
|
|
1601
|
+
{
|
|
1602
|
+
return fn();
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1607
|
+
// ../../node_modules/drizzle-orm/view-common.js
|
|
1608
|
+
var ViewBaseConfig = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig");
|
|
1609
|
+
|
|
1610
|
+
// ../../node_modules/drizzle-orm/sql/sql.js
|
|
1611
|
+
(class FakePrimitiveParam2 {
|
|
1612
|
+
static {
|
|
1613
|
+
__name(this, "FakePrimitiveParam");
|
|
1614
|
+
}
|
|
1615
|
+
static [entityKind] = "FakePrimitiveParam";
|
|
1616
|
+
});
|
|
1617
|
+
function isSQLWrapper(value) {
|
|
1618
|
+
return value !== null && value !== void 0 && typeof value.getSQL === "function";
|
|
1619
|
+
}
|
|
1620
|
+
__name(isSQLWrapper, "isSQLWrapper");
|
|
1621
|
+
function mergeQueries(queries) {
|
|
1622
|
+
const result = {
|
|
1623
|
+
sql: "",
|
|
1624
|
+
params: []
|
|
1625
|
+
};
|
|
1626
|
+
for (const query of queries) {
|
|
1627
|
+
result.sql += query.sql;
|
|
1628
|
+
result.params.push(...query.params);
|
|
1629
|
+
if (query.typings?.length) {
|
|
1630
|
+
if (!result.typings) {
|
|
1631
|
+
result.typings = [];
|
|
1632
|
+
}
|
|
1633
|
+
result.typings.push(...query.typings);
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
return result;
|
|
1637
|
+
}
|
|
1638
|
+
__name(mergeQueries, "mergeQueries");
|
|
1639
|
+
var StringChunk = class StringChunk2 {
|
|
1640
|
+
static {
|
|
1641
|
+
__name(this, "StringChunk");
|
|
1642
|
+
}
|
|
1643
|
+
static [entityKind] = "StringChunk";
|
|
1644
|
+
value;
|
|
1645
|
+
constructor(value) {
|
|
1646
|
+
this.value = Array.isArray(value) ? value : [
|
|
1647
|
+
value
|
|
1648
|
+
];
|
|
1649
|
+
}
|
|
1650
|
+
getSQL() {
|
|
1651
|
+
return new SQL([
|
|
1652
|
+
this
|
|
1653
|
+
]);
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
var SQL = class SQL2 {
|
|
1657
|
+
static {
|
|
1658
|
+
__name(this, "SQL");
|
|
1659
|
+
}
|
|
1660
|
+
constructor(queryChunks) {
|
|
1661
|
+
this.queryChunks = queryChunks;
|
|
1662
|
+
}
|
|
1663
|
+
static [entityKind] = "SQL";
|
|
1664
|
+
/** @internal */
|
|
1665
|
+
decoder = noopDecoder;
|
|
1666
|
+
shouldInlineParams = false;
|
|
1667
|
+
append(query) {
|
|
1668
|
+
this.queryChunks.push(...query.queryChunks);
|
|
1669
|
+
return this;
|
|
1670
|
+
}
|
|
1671
|
+
toQuery(config3) {
|
|
1672
|
+
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
1673
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config3);
|
|
1674
|
+
span?.setAttributes({
|
|
1675
|
+
"drizzle.query.text": query.sql,
|
|
1676
|
+
"drizzle.query.params": JSON.stringify(query.params)
|
|
1677
|
+
});
|
|
1678
|
+
return query;
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
buildQueryFromSourceParams(chunks, _config) {
|
|
1682
|
+
const config3 = Object.assign({}, _config, {
|
|
1683
|
+
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
1684
|
+
paramStartIndex: _config.paramStartIndex || {
|
|
1685
|
+
value: 0
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
const { escapeName, escapeParam, prepareTyping, inlineParams, paramStartIndex } = config3;
|
|
1689
|
+
return mergeQueries(chunks.map((chunk) => {
|
|
1690
|
+
if (is(chunk, StringChunk)) {
|
|
1691
|
+
return {
|
|
1692
|
+
sql: chunk.value.join(""),
|
|
1693
|
+
params: []
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
if (is(chunk, Name)) {
|
|
1697
|
+
return {
|
|
1698
|
+
sql: escapeName(chunk.value),
|
|
1699
|
+
params: []
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
if (chunk === void 0) {
|
|
1703
|
+
return {
|
|
1704
|
+
sql: "",
|
|
1705
|
+
params: []
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
if (Array.isArray(chunk)) {
|
|
1709
|
+
const result = [
|
|
1710
|
+
new StringChunk("(")
|
|
1711
|
+
];
|
|
1712
|
+
for (const [i, p] of chunk.entries()) {
|
|
1713
|
+
result.push(p);
|
|
1714
|
+
if (i < chunk.length - 1) {
|
|
1715
|
+
result.push(new StringChunk(", "));
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
result.push(new StringChunk(")"));
|
|
1719
|
+
return this.buildQueryFromSourceParams(result, config3);
|
|
1720
|
+
}
|
|
1721
|
+
if (is(chunk, SQL2)) {
|
|
1722
|
+
return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
1723
|
+
...config3,
|
|
1724
|
+
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
if (is(chunk, Table)) {
|
|
1728
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
1729
|
+
const tableName = chunk[Table.Symbol.Name];
|
|
1730
|
+
return {
|
|
1731
|
+
sql: schemaName === void 0 ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
1732
|
+
params: []
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
if (is(chunk, Column)) {
|
|
1736
|
+
if (_config.invokeSource === "indexes") {
|
|
1737
|
+
return {
|
|
1738
|
+
sql: escapeName(chunk.name),
|
|
1739
|
+
params: []
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
return {
|
|
1743
|
+
sql: escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(chunk.name),
|
|
1744
|
+
params: []
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
if (is(chunk, View)) {
|
|
1748
|
+
const schemaName = chunk[ViewBaseConfig].schema;
|
|
1749
|
+
const viewName = chunk[ViewBaseConfig].name;
|
|
1750
|
+
return {
|
|
1751
|
+
sql: schemaName === void 0 ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
1752
|
+
params: []
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
if (is(chunk, Param)) {
|
|
1756
|
+
if (is(chunk.value, Placeholder)) {
|
|
1757
|
+
return {
|
|
1758
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
1759
|
+
params: [
|
|
1760
|
+
chunk
|
|
1761
|
+
],
|
|
1762
|
+
typings: [
|
|
1763
|
+
"none"
|
|
1764
|
+
]
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
1768
|
+
if (is(mappedValue, SQL2)) {
|
|
1769
|
+
return this.buildQueryFromSourceParams([
|
|
1770
|
+
mappedValue
|
|
1771
|
+
], config3);
|
|
1772
|
+
}
|
|
1773
|
+
if (inlineParams) {
|
|
1774
|
+
return {
|
|
1775
|
+
sql: this.mapInlineParam(mappedValue, config3),
|
|
1776
|
+
params: []
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
let typings = [
|
|
1780
|
+
"none"
|
|
1781
|
+
];
|
|
1782
|
+
if (prepareTyping) {
|
|
1783
|
+
typings = [
|
|
1784
|
+
prepareTyping(chunk.encoder)
|
|
1785
|
+
];
|
|
1786
|
+
}
|
|
1787
|
+
return {
|
|
1788
|
+
sql: escapeParam(paramStartIndex.value++, mappedValue),
|
|
1789
|
+
params: [
|
|
1790
|
+
mappedValue
|
|
1791
|
+
],
|
|
1792
|
+
typings
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
if (is(chunk, Placeholder)) {
|
|
1796
|
+
return {
|
|
1797
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
1798
|
+
params: [
|
|
1799
|
+
chunk
|
|
1800
|
+
],
|
|
1801
|
+
typings: [
|
|
1802
|
+
"none"
|
|
1803
|
+
]
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
if (is(chunk, SQL2.Aliased) && chunk.fieldAlias !== void 0) {
|
|
1807
|
+
return {
|
|
1808
|
+
sql: escapeName(chunk.fieldAlias),
|
|
1809
|
+
params: []
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1812
|
+
if (is(chunk, Subquery)) {
|
|
1813
|
+
if (chunk._.isWith) {
|
|
1814
|
+
return {
|
|
1815
|
+
sql: escapeName(chunk._.alias),
|
|
1816
|
+
params: []
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
return this.buildQueryFromSourceParams([
|
|
1820
|
+
new StringChunk("("),
|
|
1821
|
+
chunk._.sql,
|
|
1822
|
+
new StringChunk(") "),
|
|
1823
|
+
new Name(chunk._.alias)
|
|
1824
|
+
], config3);
|
|
1825
|
+
}
|
|
1826
|
+
if (isPgEnum(chunk)) {
|
|
1827
|
+
if (chunk.schema) {
|
|
1828
|
+
return {
|
|
1829
|
+
sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName),
|
|
1830
|
+
params: []
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
return {
|
|
1834
|
+
sql: escapeName(chunk.enumName),
|
|
1835
|
+
params: []
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
if (isSQLWrapper(chunk)) {
|
|
1839
|
+
if (chunk.shouldOmitSQLParens?.()) {
|
|
1840
|
+
return this.buildQueryFromSourceParams([
|
|
1841
|
+
chunk.getSQL()
|
|
1842
|
+
], config3);
|
|
1843
|
+
}
|
|
1844
|
+
return this.buildQueryFromSourceParams([
|
|
1845
|
+
new StringChunk("("),
|
|
1846
|
+
chunk.getSQL(),
|
|
1847
|
+
new StringChunk(")")
|
|
1848
|
+
], config3);
|
|
1849
|
+
}
|
|
1850
|
+
if (inlineParams) {
|
|
1851
|
+
return {
|
|
1852
|
+
sql: this.mapInlineParam(chunk, config3),
|
|
1853
|
+
params: []
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
return {
|
|
1857
|
+
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
1858
|
+
params: [
|
|
1859
|
+
chunk
|
|
1860
|
+
],
|
|
1861
|
+
typings: [
|
|
1862
|
+
"none"
|
|
1863
|
+
]
|
|
1864
|
+
};
|
|
1865
|
+
}));
|
|
1866
|
+
}
|
|
1867
|
+
mapInlineParam(chunk, { escapeString }) {
|
|
1868
|
+
if (chunk === null) {
|
|
1869
|
+
return "null";
|
|
1870
|
+
}
|
|
1871
|
+
if (typeof chunk === "number" || typeof chunk === "boolean") {
|
|
1872
|
+
return chunk.toString();
|
|
1873
|
+
}
|
|
1874
|
+
if (typeof chunk === "string") {
|
|
1875
|
+
return escapeString(chunk);
|
|
1876
|
+
}
|
|
1877
|
+
if (typeof chunk === "object") {
|
|
1878
|
+
const mappedValueAsString = chunk.toString();
|
|
1879
|
+
if (mappedValueAsString === "[object Object]") {
|
|
1880
|
+
return escapeString(JSON.stringify(chunk));
|
|
1881
|
+
}
|
|
1882
|
+
return escapeString(mappedValueAsString);
|
|
1883
|
+
}
|
|
1884
|
+
throw new Error("Unexpected param value: " + chunk);
|
|
1885
|
+
}
|
|
1886
|
+
getSQL() {
|
|
1887
|
+
return this;
|
|
1888
|
+
}
|
|
1889
|
+
as(alias) {
|
|
1890
|
+
if (alias === void 0) {
|
|
1891
|
+
return this;
|
|
1892
|
+
}
|
|
1893
|
+
return new SQL2.Aliased(this, alias);
|
|
1894
|
+
}
|
|
1895
|
+
mapWith(decoder) {
|
|
1896
|
+
this.decoder = typeof decoder === "function" ? {
|
|
1897
|
+
mapFromDriverValue: decoder
|
|
1898
|
+
} : decoder;
|
|
1899
|
+
return this;
|
|
1900
|
+
}
|
|
1901
|
+
inlineParams() {
|
|
1902
|
+
this.shouldInlineParams = true;
|
|
1903
|
+
return this;
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* This method is used to conditionally include a part of the query.
|
|
1907
|
+
*
|
|
1908
|
+
* @param condition - Condition to check
|
|
1909
|
+
* @returns itself if the condition is `true`, otherwise `undefined`
|
|
1910
|
+
*/
|
|
1911
|
+
if(condition) {
|
|
1912
|
+
return condition ? this : void 0;
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
var Name = class Name2 {
|
|
1916
|
+
static {
|
|
1917
|
+
__name(this, "Name");
|
|
1918
|
+
}
|
|
1919
|
+
constructor(value) {
|
|
1920
|
+
this.value = value;
|
|
1921
|
+
}
|
|
1922
|
+
static [entityKind] = "Name";
|
|
1923
|
+
brand;
|
|
1924
|
+
getSQL() {
|
|
1925
|
+
return new SQL([
|
|
1926
|
+
this
|
|
1927
|
+
]);
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
function isDriverValueEncoder(value) {
|
|
1931
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
1932
|
+
}
|
|
1933
|
+
__name(isDriverValueEncoder, "isDriverValueEncoder");
|
|
1934
|
+
var noopDecoder = {
|
|
1935
|
+
mapFromDriverValue: /* @__PURE__ */ __name((value) => value, "mapFromDriverValue")
|
|
1936
|
+
};
|
|
1937
|
+
var noopEncoder = {
|
|
1938
|
+
mapToDriverValue: /* @__PURE__ */ __name((value) => value, "mapToDriverValue")
|
|
1939
|
+
};
|
|
1940
|
+
({
|
|
1941
|
+
...noopDecoder,
|
|
1942
|
+
...noopEncoder
|
|
1943
|
+
});
|
|
1944
|
+
var Param = class Param2 {
|
|
1945
|
+
static {
|
|
1946
|
+
__name(this, "Param");
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* @param value - Parameter value
|
|
1950
|
+
* @param encoder - Encoder to convert the value to a driver parameter
|
|
1951
|
+
*/
|
|
1952
|
+
constructor(value, encoder = noopEncoder) {
|
|
1953
|
+
this.value = value;
|
|
1954
|
+
this.encoder = encoder;
|
|
1955
|
+
}
|
|
1956
|
+
static [entityKind] = "Param";
|
|
1957
|
+
brand;
|
|
1958
|
+
getSQL() {
|
|
1959
|
+
return new SQL([
|
|
1960
|
+
this
|
|
1961
|
+
]);
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
function sql(strings, ...params) {
|
|
1965
|
+
const queryChunks = [];
|
|
1966
|
+
if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
|
|
1967
|
+
queryChunks.push(new StringChunk(strings[0]));
|
|
1968
|
+
}
|
|
1969
|
+
for (const [paramIndex, param2] of params.entries()) {
|
|
1970
|
+
queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
1971
|
+
}
|
|
1972
|
+
return new SQL(queryChunks);
|
|
1973
|
+
}
|
|
1974
|
+
__name(sql, "sql");
|
|
1975
|
+
((sql2) => {
|
|
1976
|
+
function empty() {
|
|
1977
|
+
return new SQL([]);
|
|
1978
|
+
}
|
|
1979
|
+
__name(empty, "empty");
|
|
1980
|
+
sql2.empty = empty;
|
|
1981
|
+
function fromList(list) {
|
|
1982
|
+
return new SQL(list);
|
|
1983
|
+
}
|
|
1984
|
+
__name(fromList, "fromList");
|
|
1985
|
+
sql2.fromList = fromList;
|
|
1986
|
+
function raw(str) {
|
|
1987
|
+
return new SQL([
|
|
1988
|
+
new StringChunk(str)
|
|
1989
|
+
]);
|
|
1990
|
+
}
|
|
1991
|
+
__name(raw, "raw");
|
|
1992
|
+
sql2.raw = raw;
|
|
1993
|
+
function join(chunks, separator) {
|
|
1994
|
+
const result = [];
|
|
1995
|
+
for (const [i, chunk] of chunks.entries()) {
|
|
1996
|
+
if (i > 0 && separator !== void 0) {
|
|
1997
|
+
result.push(separator);
|
|
1998
|
+
}
|
|
1999
|
+
result.push(chunk);
|
|
2000
|
+
}
|
|
2001
|
+
return new SQL(result);
|
|
2002
|
+
}
|
|
2003
|
+
__name(join, "join");
|
|
2004
|
+
sql2.join = join;
|
|
2005
|
+
function identifier(value) {
|
|
2006
|
+
return new Name(value);
|
|
2007
|
+
}
|
|
2008
|
+
__name(identifier, "identifier");
|
|
2009
|
+
sql2.identifier = identifier;
|
|
2010
|
+
function placeholder2(name2) {
|
|
2011
|
+
return new Placeholder(name2);
|
|
2012
|
+
}
|
|
2013
|
+
__name(placeholder2, "placeholder2");
|
|
2014
|
+
sql2.placeholder = placeholder2;
|
|
2015
|
+
function param2(value, encoder) {
|
|
2016
|
+
return new Param(value, encoder);
|
|
2017
|
+
}
|
|
2018
|
+
__name(param2, "param2");
|
|
2019
|
+
sql2.param = param2;
|
|
2020
|
+
})(sql || (sql = {}));
|
|
2021
|
+
((SQL22) => {
|
|
2022
|
+
let Aliased = class Aliased2 {
|
|
2023
|
+
static {
|
|
2024
|
+
__name(this, "Aliased");
|
|
2025
|
+
}
|
|
2026
|
+
constructor(sql2, fieldAlias) {
|
|
2027
|
+
this.sql = sql2;
|
|
2028
|
+
this.fieldAlias = fieldAlias;
|
|
2029
|
+
}
|
|
2030
|
+
static [entityKind] = "SQL.Aliased";
|
|
2031
|
+
/** @internal */
|
|
2032
|
+
isSelectionField = false;
|
|
2033
|
+
getSQL() {
|
|
2034
|
+
return this.sql;
|
|
2035
|
+
}
|
|
2036
|
+
/** @internal */
|
|
2037
|
+
clone() {
|
|
2038
|
+
return new Aliased2(this.sql, this.fieldAlias);
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
SQL22.Aliased = Aliased;
|
|
2042
|
+
})(SQL || (SQL = {}));
|
|
2043
|
+
var Placeholder = class Placeholder2 {
|
|
2044
|
+
static {
|
|
2045
|
+
__name(this, "Placeholder");
|
|
2046
|
+
}
|
|
2047
|
+
constructor(name2) {
|
|
2048
|
+
this.name = name2;
|
|
2049
|
+
}
|
|
2050
|
+
static [entityKind] = "Placeholder";
|
|
2051
|
+
getSQL() {
|
|
2052
|
+
return new SQL([
|
|
2053
|
+
this
|
|
2054
|
+
]);
|
|
2055
|
+
}
|
|
2056
|
+
};
|
|
2057
|
+
var View = class View2 {
|
|
2058
|
+
static {
|
|
2059
|
+
__name(this, "View");
|
|
2060
|
+
}
|
|
2061
|
+
static [entityKind] = "View";
|
|
2062
|
+
/** @internal */
|
|
2063
|
+
[ViewBaseConfig];
|
|
2064
|
+
constructor({ name: name2, schema: schema2, selectedFields, query }) {
|
|
2065
|
+
this[ViewBaseConfig] = {
|
|
2066
|
+
name: name2,
|
|
2067
|
+
originalName: name2,
|
|
2068
|
+
schema: schema2,
|
|
2069
|
+
selectedFields,
|
|
2070
|
+
query,
|
|
2071
|
+
isExisting: !query,
|
|
2072
|
+
isAlias: false
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
getSQL() {
|
|
2076
|
+
return new SQL([
|
|
2077
|
+
this
|
|
2078
|
+
]);
|
|
2079
|
+
}
|
|
2080
|
+
};
|
|
2081
|
+
Column.prototype.getSQL = function() {
|
|
2082
|
+
return new SQL([
|
|
2083
|
+
this
|
|
2084
|
+
]);
|
|
2085
|
+
};
|
|
2086
|
+
Table.prototype.getSQL = function() {
|
|
2087
|
+
return new SQL([
|
|
2088
|
+
this
|
|
2089
|
+
]);
|
|
2090
|
+
};
|
|
2091
|
+
Subquery.prototype.getSQL = function() {
|
|
2092
|
+
return new SQL([
|
|
2093
|
+
this
|
|
2094
|
+
]);
|
|
2095
|
+
};
|
|
2096
|
+
|
|
2097
|
+
// ../../node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
2098
|
+
function bindIfParam(value, column) {
|
|
2099
|
+
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
2100
|
+
return new Param(value, column);
|
|
2101
|
+
}
|
|
2102
|
+
return value;
|
|
2103
|
+
}
|
|
2104
|
+
__name(bindIfParam, "bindIfParam");
|
|
2105
|
+
var eq = /* @__PURE__ */ __name((left, right) => {
|
|
2106
|
+
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
2107
|
+
}, "eq");
|
|
2108
|
+
function and(...unfilteredConditions) {
|
|
2109
|
+
const conditions = unfilteredConditions.filter((c) => c !== void 0);
|
|
2110
|
+
if (conditions.length === 0) {
|
|
2111
|
+
return void 0;
|
|
2112
|
+
}
|
|
2113
|
+
if (conditions.length === 1) {
|
|
2114
|
+
return new SQL(conditions);
|
|
2115
|
+
}
|
|
2116
|
+
return new SQL([
|
|
2117
|
+
new StringChunk("("),
|
|
2118
|
+
sql.join(conditions, new StringChunk(" and ")),
|
|
2119
|
+
new StringChunk(")")
|
|
2120
|
+
]);
|
|
2121
|
+
}
|
|
2122
|
+
__name(and, "and");
|
|
2123
|
+
function isNull(value) {
|
|
2124
|
+
return sql`${value} is null`;
|
|
2125
|
+
}
|
|
2126
|
+
__name(isNull, "isNull");
|
|
2127
|
+
|
|
2128
|
+
// ../../packages/dvss-integration-libs/src/integration-common-utils/dao/integration-configuration.dao.ts
|
|
2129
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
2130
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2131
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2132
|
+
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;
|
|
2133
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2134
|
+
}
|
|
2135
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
2136
|
+
function _ts_metadata8(k, v) {
|
|
2137
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2138
|
+
}
|
|
2139
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2140
|
+
function _ts_param(paramIndex, decorator) {
|
|
2141
|
+
return function(target, key) {
|
|
2142
|
+
decorator(target, key, paramIndex);
|
|
2143
|
+
};
|
|
2144
|
+
}
|
|
2145
|
+
__name(_ts_param, "_ts_param");
|
|
2146
|
+
exports.IntegrationConfigurationDao = class IntegrationConfigurationDao {
|
|
2147
|
+
static {
|
|
2148
|
+
__name(this, "IntegrationConfigurationDao");
|
|
2149
|
+
}
|
|
2150
|
+
conn;
|
|
2151
|
+
logger;
|
|
2152
|
+
fileName = "integration-configuration.dao";
|
|
2153
|
+
constructor(conn, logger) {
|
|
2154
|
+
this.conn = conn;
|
|
2155
|
+
this.logger = logger;
|
|
2156
|
+
}
|
|
2157
|
+
async addCapabilityIntegration(input, loggedInUserId) {
|
|
2158
|
+
this.logger.info(loggedInUserId, this.addCapabilityIntegration.name, this.fileName, `CapabilityDaoService -> addCapabilityIntegration called`);
|
|
2159
|
+
try {
|
|
2160
|
+
return this.conn.transaction(async (tx) => {
|
|
2161
|
+
const [integrationResult] = await tx.insert(dvssBackendModuleDatastore.schema.capabilityIntegration).values(input).$returningId();
|
|
2162
|
+
if (!integrationResult.id) {
|
|
2163
|
+
tx.rollback();
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
if (input.configuredFor) {
|
|
2167
|
+
const insertData = {
|
|
2168
|
+
capabilityIntegrationId: integrationResult.id,
|
|
2169
|
+
configuredForId: input.configuredFor.configuredForId,
|
|
2170
|
+
configuredForType: input.configuredFor.configuredForType,
|
|
2171
|
+
status: capabilityIntegration_model.CAPABILITY_INTEGRATION_STATUS_ENUM.ACTIVE,
|
|
2172
|
+
projectId: input.projectId,
|
|
2173
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2174
|
+
createdBy: loggedInUserId
|
|
2175
|
+
};
|
|
2176
|
+
await tx.insert(dvssBackendModuleDatastore.schema.capIntegResourceMapping).values(insertData);
|
|
2177
|
+
}
|
|
2178
|
+
return {
|
|
2179
|
+
id: integrationResult.id
|
|
2180
|
+
};
|
|
2181
|
+
});
|
|
2182
|
+
} catch (error) {
|
|
2183
|
+
this.logger.error(loggedInUserId, this.addCapabilityIntegration.name, this.fileName, "Error in addCapabilityIntegration", error, input);
|
|
2184
|
+
throw error;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
2188
|
+
* Get capability by id (for add-capability-integration validation).
|
|
2189
|
+
* Copied from project-ms CapabilityDaoService.getCapability.
|
|
2190
|
+
*/
|
|
2191
|
+
async getCapability(request, loggedInUserId) {
|
|
2192
|
+
try {
|
|
2193
|
+
this.logger.info(loggedInUserId, this.getCapability.name, this.fileName, "getCapability called", {
|
|
2194
|
+
request
|
|
2195
|
+
});
|
|
2196
|
+
return await this.conn.query.capability.findFirst({
|
|
2197
|
+
where: and(eq(dvssBackendModuleDatastore.schema.capability.id, request.capabilityId), isNull(dvssBackendModuleDatastore.schema.capability.deletedAt))
|
|
2198
|
+
});
|
|
2199
|
+
} catch (error) {
|
|
2200
|
+
this.logger.error(loggedInUserId, this.getCapability.name, this.fileName, "Error on getCapability", error, {
|
|
2201
|
+
request
|
|
2202
|
+
});
|
|
2203
|
+
throw error;
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Get capability provider by id (for add-capability-integration validation).
|
|
2208
|
+
* Copied from project-ms CapabilityProviderDao.getCapabilityProvider.
|
|
2209
|
+
*/
|
|
2210
|
+
async getCapabilityProvider(request, loggedInUserId) {
|
|
2211
|
+
try {
|
|
2212
|
+
this.logger.info(loggedInUserId, this.getCapabilityProvider.name, this.fileName, "getCapabilityProvider called", {
|
|
2213
|
+
request
|
|
2214
|
+
});
|
|
2215
|
+
return await this.conn.query.capabilityProvider.findFirst({
|
|
2216
|
+
where: and(eq(dvssBackendModuleDatastore.schema.capabilityProvider.id, request.capabilityProviderId), isNull(dvssBackendModuleDatastore.schema.capabilityProvider.deletedAt))
|
|
2217
|
+
});
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
this.logger.error(loggedInUserId, this.getCapabilityProvider.name, this.fileName, "Error on getCapabilityProvider", error, {
|
|
2220
|
+
request
|
|
2221
|
+
});
|
|
2222
|
+
throw error;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Updates capability integration in the database.
|
|
2227
|
+
* Copied from project-ms CapabilityIntegrationDao.updateCapabilityIntegration.
|
|
2228
|
+
*
|
|
2229
|
+
* @param input - Object containing the integration ID and update data
|
|
2230
|
+
* @param loggedInUserId - User ID for logging
|
|
2231
|
+
* @returns Promise that resolves to the update operation status
|
|
2232
|
+
*/
|
|
2233
|
+
async updateCapabilityIntegration(input, loggedInUserId) {
|
|
2234
|
+
try {
|
|
2235
|
+
this.logger.info(loggedInUserId, this.updateCapabilityIntegration.name, this.fileName, "Updating capability integration");
|
|
2236
|
+
const response = await this.conn.update(dvssBackendModuleDatastore.schema.capabilityIntegration).set({
|
|
2237
|
+
...input.updateData
|
|
2238
|
+
}).where(eq(dvssBackendModuleDatastore.schema.capabilityIntegration.id, input.id));
|
|
2239
|
+
return {
|
|
2240
|
+
status: response[0].affectedRows > 0
|
|
2241
|
+
};
|
|
2242
|
+
} catch (error) {
|
|
2243
|
+
this.logger.error(loggedInUserId, this.updateCapabilityIntegration.name, this.fileName, "Error updating capability integration", error);
|
|
2244
|
+
throw error;
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
/**
|
|
2248
|
+
* Get capability integration by id (for parent validation when parentId is set).
|
|
2249
|
+
* Copied from project-ms CapabilityIntegrationDao.getCapabilityIntegration.
|
|
2250
|
+
*/
|
|
2251
|
+
async getCapabilityIntegration(input, loggedInUserId) {
|
|
2252
|
+
try {
|
|
2253
|
+
this.logger.info(loggedInUserId, this.getCapabilityIntegration.name, this.fileName, "getCapabilityIntegration called", input);
|
|
2254
|
+
return await this.conn.query.capabilityIntegration.findFirst({
|
|
2255
|
+
where: and(isNull(dvssBackendModuleDatastore.schema.capabilityIntegration.deletedAt), eq(dvssBackendModuleDatastore.schema.capabilityIntegration.id, input.capabilityIntegrationId))
|
|
2256
|
+
});
|
|
2257
|
+
} catch (error) {
|
|
2258
|
+
this.logger.error(loggedInUserId, this.getCapabilityIntegration.name, this.fileName, "Error on getCapabilityIntegration", error, input);
|
|
2259
|
+
throw error;
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
};
|
|
2263
|
+
exports.IntegrationConfigurationDao = _ts_decorate11([
|
|
2264
|
+
common.Injectable(),
|
|
2265
|
+
_ts_param(0, common.Inject(dvssBackendModuleDatastore.appConstants.DB_CONNECTION)),
|
|
2266
|
+
_ts_metadata8("design:type", Function),
|
|
2267
|
+
_ts_metadata8("design:paramtypes", [
|
|
2268
|
+
typeof MySql2Database === "undefined" ? Object : MySql2Database,
|
|
2269
|
+
typeof dvssBackendModuleUtility.LoggerService === "undefined" ? Object : dvssBackendModuleUtility.LoggerService
|
|
2270
|
+
])
|
|
2271
|
+
], exports.IntegrationConfigurationDao);
|
|
2272
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
2273
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2274
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2275
|
+
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;
|
|
2276
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2277
|
+
}
|
|
2278
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
2279
|
+
function _ts_metadata9(k, v) {
|
|
2280
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2281
|
+
}
|
|
2282
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2283
|
+
function _ts_param2(paramIndex, decorator) {
|
|
2284
|
+
return function(target, key) {
|
|
2285
|
+
decorator(target, key, paramIndex);
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
__name(_ts_param2, "_ts_param");
|
|
2289
|
+
exports.IntegrationUserManagementDao = class IntegrationUserManagementDao {
|
|
706
2290
|
static {
|
|
707
|
-
__name(this, "
|
|
2291
|
+
__name(this, "IntegrationUserManagementDao");
|
|
708
2292
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
var BaseMembershipManagement = class {
|
|
713
|
-
static {
|
|
714
|
-
__name(this, "BaseMembershipManagement");
|
|
2293
|
+
conn;
|
|
2294
|
+
constructor(conn) {
|
|
2295
|
+
this.conn = conn;
|
|
715
2296
|
}
|
|
716
2297
|
};
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
CREDIT_STATUS_ENUM2["REDEEMED"] = "REDEEMED";
|
|
727
|
-
CREDIT_STATUS_ENUM2["EXPIRED"] = "EXPIRED";
|
|
728
|
-
CREDIT_STATUS_ENUM2["REVOKED"] = "REVOKED";
|
|
729
|
-
return CREDIT_STATUS_ENUM2;
|
|
730
|
-
})({});
|
|
731
|
-
var CREDIT_FILTER_BY_ENUM = /* @__PURE__ */ (function(CREDIT_FILTER_BY_ENUM2) {
|
|
732
|
-
CREDIT_FILTER_BY_ENUM2["TYPE"] = "TYPE";
|
|
733
|
-
CREDIT_FILTER_BY_ENUM2["STATUS"] = "STATUS";
|
|
734
|
-
return CREDIT_FILTER_BY_ENUM2;
|
|
735
|
-
})({});
|
|
736
|
-
|
|
737
|
-
// ../../packages/dvss-integration-libs/src/integration-common-utils/models/capability-integration.model.ts
|
|
738
|
-
var INTEGRATION_PROVIDER_ENUM = /* @__PURE__ */ (function(INTEGRATION_PROVIDER_ENUM2) {
|
|
739
|
-
INTEGRATION_PROVIDER_ENUM2["TRYBE"] = "TRYBE";
|
|
740
|
-
return INTEGRATION_PROVIDER_ENUM2;
|
|
741
|
-
})({});
|
|
742
|
-
|
|
743
|
-
// ../../packages/dvss-integration-libs/src/integration-common-utils/models/wellness-management.model.ts
|
|
744
|
-
var BOOKABLE_ITEM_TYPE_ENUM = /* @__PURE__ */ (function(BOOKABLE_ITEM_TYPE_ENUM2) {
|
|
745
|
-
BOOKABLE_ITEM_TYPE_ENUM2["APPOINTMENT"] = "APPOINTMENT";
|
|
746
|
-
BOOKABLE_ITEM_TYPE_ENUM2["SESSION"] = "SESSION";
|
|
747
|
-
BOOKABLE_ITEM_TYPE_ENUM2["COURSE"] = "COURSE";
|
|
748
|
-
return BOOKABLE_ITEM_TYPE_ENUM2;
|
|
749
|
-
})({});
|
|
750
|
-
var BOOKABLE_ITEM_STATUS_ENUM = /* @__PURE__ */ (function(BOOKABLE_ITEM_STATUS_ENUM2) {
|
|
751
|
-
BOOKABLE_ITEM_STATUS_ENUM2["ACTIVE"] = "ACTIVE";
|
|
752
|
-
BOOKABLE_ITEM_STATUS_ENUM2["INACTIVE"] = "INACTIVE";
|
|
753
|
-
return BOOKABLE_ITEM_STATUS_ENUM2;
|
|
754
|
-
})({});
|
|
755
|
-
var DAY_OF_WEEK = /* @__PURE__ */ (function(DAY_OF_WEEK2) {
|
|
756
|
-
DAY_OF_WEEK2["MON"] = "MON";
|
|
757
|
-
DAY_OF_WEEK2["TUE"] = "TUE";
|
|
758
|
-
DAY_OF_WEEK2["WED"] = "WED";
|
|
759
|
-
DAY_OF_WEEK2["THU"] = "THU";
|
|
760
|
-
DAY_OF_WEEK2["FRI"] = "FRI";
|
|
761
|
-
DAY_OF_WEEK2["SAT"] = "SAT";
|
|
762
|
-
DAY_OF_WEEK2["SUN"] = "SUN";
|
|
763
|
-
return DAY_OF_WEEK2;
|
|
764
|
-
})({});
|
|
765
|
-
function _ts_decorate11(decorators, target, key, desc) {
|
|
2298
|
+
exports.IntegrationUserManagementDao = _ts_decorate12([
|
|
2299
|
+
common.Injectable(),
|
|
2300
|
+
_ts_param2(0, common.Inject(dvssBackendModuleDatastore.appConstants.DB_CONNECTION)),
|
|
2301
|
+
_ts_metadata9("design:type", Function),
|
|
2302
|
+
_ts_metadata9("design:paramtypes", [
|
|
2303
|
+
typeof MySql2Database === "undefined" ? Object : MySql2Database
|
|
2304
|
+
])
|
|
2305
|
+
], exports.IntegrationUserManagementDao);
|
|
2306
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
766
2307
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
767
2308
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
768
2309
|
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;
|
|
769
2310
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
770
2311
|
}
|
|
771
|
-
__name(
|
|
772
|
-
function
|
|
2312
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
2313
|
+
function _ts_metadata10(k, v) {
|
|
773
2314
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
774
2315
|
}
|
|
775
|
-
__name(
|
|
2316
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
776
2317
|
exports.TrybeCustomerManagement = class _TrybeCustomerManagement {
|
|
777
2318
|
static {
|
|
778
2319
|
__name(this, "TrybeCustomerManagement");
|
|
@@ -788,13 +2329,22 @@ exports.TrybeCustomerManagement = class _TrybeCustomerManagement {
|
|
|
788
2329
|
this.trafficGatewayService = trafficGatewayService;
|
|
789
2330
|
}
|
|
790
2331
|
/**
|
|
791
|
-
*
|
|
792
|
-
* Must be implemented by concrete classes
|
|
2332
|
+
* Create a new customer on Trybe (POST /customers/customers).
|
|
793
2333
|
*
|
|
794
|
-
* @returns Promise resolving
|
|
2334
|
+
* @returns Promise resolving to the created customer
|
|
795
2335
|
*/
|
|
796
|
-
createCustomer() {
|
|
797
|
-
|
|
2336
|
+
async createCustomer(request, integration, loggedInUserId) {
|
|
2337
|
+
this.logger.info(loggedInUserId, this.createCustomer.name, this.fileName, `${_TrybeCustomerManagement.name} -> ${this.createCustomer.name} Called`, {
|
|
2338
|
+
request
|
|
2339
|
+
});
|
|
2340
|
+
const response = await this.trafficGatewayService.executeIntegrationRequest({
|
|
2341
|
+
apiMethod: HTTP_METHOD.POST,
|
|
2342
|
+
url: "/customers/customers",
|
|
2343
|
+
baseUrl: integration.config.platformConfig.baseUrl,
|
|
2344
|
+
headers: integration.headers,
|
|
2345
|
+
body: request
|
|
2346
|
+
}, integration, loggedInUserId);
|
|
2347
|
+
return response.data;
|
|
798
2348
|
}
|
|
799
2349
|
/**
|
|
800
2350
|
* Abstract method to search for wellness customers
|
|
@@ -835,34 +2385,44 @@ exports.TrybeCustomerManagement = class _TrybeCustomerManagement {
|
|
|
835
2385
|
}
|
|
836
2386
|
}
|
|
837
2387
|
/**
|
|
838
|
-
*
|
|
839
|
-
* Must be implemented by concrete classes
|
|
2388
|
+
* Update an existing customer on Trybe (PUT /customers/customers/:id), then fetch and return full customer.
|
|
840
2389
|
*
|
|
841
|
-
* @returns Promise resolving
|
|
2390
|
+
* @returns Promise resolving to the updated customer
|
|
842
2391
|
*/
|
|
843
|
-
updateCustomer() {
|
|
844
|
-
|
|
2392
|
+
async updateCustomer(customerId, request, integration, loggedInUserId) {
|
|
2393
|
+
this.logger.info(loggedInUserId, this.updateCustomer.name, this.fileName, `${_TrybeCustomerManagement.name} -> ${this.updateCustomer.name} Called`, {
|
|
2394
|
+
customerId,
|
|
2395
|
+
request
|
|
2396
|
+
});
|
|
2397
|
+
const response = await this.trafficGatewayService.executeIntegrationRequest({
|
|
2398
|
+
apiMethod: HTTP_METHOD.PUT,
|
|
2399
|
+
url: `/customers/customers/${customerId}`,
|
|
2400
|
+
baseUrl: integration.config.platformConfig.baseUrl,
|
|
2401
|
+
headers: integration.headers,
|
|
2402
|
+
body: request
|
|
2403
|
+
}, integration, loggedInUserId);
|
|
2404
|
+
return response.data;
|
|
845
2405
|
}
|
|
846
2406
|
};
|
|
847
|
-
exports.TrybeCustomerManagement =
|
|
2407
|
+
exports.TrybeCustomerManagement = _ts_decorate13([
|
|
848
2408
|
common.Injectable(),
|
|
849
|
-
|
|
850
|
-
|
|
2409
|
+
_ts_metadata10("design:type", Function),
|
|
2410
|
+
_ts_metadata10("design:paramtypes", [
|
|
851
2411
|
typeof dvssBackendModuleUtility.LoggerService === "undefined" ? Object : dvssBackendModuleUtility.LoggerService,
|
|
852
2412
|
typeof exports.TrafficGatewayService === "undefined" ? Object : exports.TrafficGatewayService
|
|
853
2413
|
])
|
|
854
2414
|
], exports.TrybeCustomerManagement);
|
|
855
|
-
function
|
|
2415
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
856
2416
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
857
2417
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
858
2418
|
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;
|
|
859
2419
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
860
2420
|
}
|
|
861
|
-
__name(
|
|
862
|
-
function
|
|
2421
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
2422
|
+
function _ts_metadata11(k, v) {
|
|
863
2423
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
864
2424
|
}
|
|
865
|
-
__name(
|
|
2425
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
866
2426
|
exports.TrybeAuthService = class _TrybeAuthService {
|
|
867
2427
|
static {
|
|
868
2428
|
__name(this, "TrybeAuthService");
|
|
@@ -911,6 +2471,9 @@ exports.TrybeAuthService = class _TrybeAuthService {
|
|
|
911
2471
|
if (!platformConfig.baseUrl) {
|
|
912
2472
|
throw new Error("Platform configuration is invalid: Base URL not found");
|
|
913
2473
|
}
|
|
2474
|
+
if (!this.isValidUrl(platformConfig.baseUrl)) {
|
|
2475
|
+
throw new Error("Platform configuration is invalid: Base URL is not a valid URL");
|
|
2476
|
+
}
|
|
914
2477
|
} else {
|
|
915
2478
|
throw new Error("Platform configuration is invalid: Platform config is empty");
|
|
916
2479
|
}
|
|
@@ -922,6 +2485,14 @@ exports.TrybeAuthService = class _TrybeAuthService {
|
|
|
922
2485
|
headers
|
|
923
2486
|
};
|
|
924
2487
|
}
|
|
2488
|
+
isValidUrl(urlString) {
|
|
2489
|
+
try {
|
|
2490
|
+
const url = new URL(urlString);
|
|
2491
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
2492
|
+
} catch {
|
|
2493
|
+
return false;
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
925
2496
|
/**
|
|
926
2497
|
* Tests Trybe integration by making a test API call
|
|
927
2498
|
* Uses a test customer lookup to verify credentials are valid
|
|
@@ -956,10 +2527,10 @@ exports.TrybeAuthService = class _TrybeAuthService {
|
|
|
956
2527
|
throw new Error("Method not implemented.");
|
|
957
2528
|
}
|
|
958
2529
|
};
|
|
959
|
-
exports.TrybeAuthService =
|
|
2530
|
+
exports.TrybeAuthService = _ts_decorate14([
|
|
960
2531
|
common.Injectable(),
|
|
961
|
-
|
|
962
|
-
|
|
2532
|
+
_ts_metadata11("design:type", Function),
|
|
2533
|
+
_ts_metadata11("design:paramtypes", [
|
|
963
2534
|
typeof exports.TrybeCustomerManagement === "undefined" ? Object : exports.TrybeCustomerManagement,
|
|
964
2535
|
typeof dvssBackendModuleUtility.LoggerService === "undefined" ? Object : dvssBackendModuleUtility.LoggerService
|
|
965
2536
|
])
|
|
@@ -976,7 +2547,7 @@ __name(mapStatus, "mapStatus");
|
|
|
976
2547
|
function mapTrybeCreditsToSystem(res, integration) {
|
|
977
2548
|
const groups = /* @__PURE__ */ new Map();
|
|
978
2549
|
for (const t of res.data) {
|
|
979
|
-
const key = `${t.coupon_name}|${t.
|
|
2550
|
+
const key = `${t.coupon_name}|${t.expires_at.split("T")[0]}`;
|
|
980
2551
|
const list = groups.get(key) ?? [];
|
|
981
2552
|
list.push(t);
|
|
982
2553
|
groups.set(key, list);
|
|
@@ -1022,17 +2593,17 @@ function mapTrybeCreditsToSystem(res, integration) {
|
|
|
1022
2593
|
__name(mapTrybeCreditsToSystem, "mapTrybeCreditsToSystem");
|
|
1023
2594
|
|
|
1024
2595
|
// ../../packages/dvss-integration-trybe/src/capabilities/credit-management/credit-booking.service.ts
|
|
1025
|
-
function
|
|
2596
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
1026
2597
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1027
2598
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1028
2599
|
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;
|
|
1029
2600
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1030
2601
|
}
|
|
1031
|
-
__name(
|
|
1032
|
-
function
|
|
2602
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
2603
|
+
function _ts_metadata12(k, v) {
|
|
1033
2604
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1034
2605
|
}
|
|
1035
|
-
__name(
|
|
2606
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
1036
2607
|
exports.TrybeCreditBooking = class _TrybeCreditBooking {
|
|
1037
2608
|
static {
|
|
1038
2609
|
__name(this, "TrybeCreditBooking");
|
|
@@ -1090,10 +2661,10 @@ exports.TrybeCreditBooking = class _TrybeCreditBooking {
|
|
|
1090
2661
|
return mapTrybeCreditsToSystem(raw, validatedIntegration);
|
|
1091
2662
|
}
|
|
1092
2663
|
};
|
|
1093
|
-
exports.TrybeCreditBooking =
|
|
2664
|
+
exports.TrybeCreditBooking = _ts_decorate15([
|
|
1094
2665
|
common.Injectable(),
|
|
1095
|
-
|
|
1096
|
-
|
|
2666
|
+
_ts_metadata12("design:type", Function),
|
|
2667
|
+
_ts_metadata12("design:paramtypes", [
|
|
1097
2668
|
typeof dvssBackendModuleUtility.LoggerService === "undefined" ? Object : dvssBackendModuleUtility.LoggerService,
|
|
1098
2669
|
typeof exports.TrafficGatewayService === "undefined" ? Object : exports.TrafficGatewayService,
|
|
1099
2670
|
typeof exports.TrybeAuthService === "undefined" ? Object : exports.TrybeAuthService
|
|
@@ -1160,16 +2731,19 @@ var TRYBE_OFFERING_TYPE_ENUM = /* @__PURE__ */ (function(TRYBE_OFFERING_TYPE_ENU
|
|
|
1160
2731
|
TRYBE_OFFERING_TYPE_ENUM2["COURSE"] = "COURSE";
|
|
1161
2732
|
return TRYBE_OFFERING_TYPE_ENUM2;
|
|
1162
2733
|
})({});
|
|
1163
|
-
|
|
1164
|
-
|
|
2734
|
+
var TRYBE_OFFERING_TYPE_API = {
|
|
2735
|
+
APPOINTMENT: "appointment",
|
|
2736
|
+
SESSION: "session",
|
|
2737
|
+
COURSE: "course"
|
|
2738
|
+
};
|
|
1165
2739
|
var TRYBE_WEEKDAYS_MAPPING = {
|
|
1166
|
-
monday: DAY_OF_WEEK.MON,
|
|
1167
|
-
tuesday: DAY_OF_WEEK.TUE,
|
|
1168
|
-
wednesday: DAY_OF_WEEK.WED,
|
|
1169
|
-
thursday: DAY_OF_WEEK.THU,
|
|
1170
|
-
friday: DAY_OF_WEEK.FRI,
|
|
1171
|
-
saturday: DAY_OF_WEEK.SAT,
|
|
1172
|
-
sunday: DAY_OF_WEEK.SUN
|
|
2740
|
+
monday: models.DAY_OF_WEEK.MON,
|
|
2741
|
+
tuesday: models.DAY_OF_WEEK.TUE,
|
|
2742
|
+
wednesday: models.DAY_OF_WEEK.WED,
|
|
2743
|
+
thursday: models.DAY_OF_WEEK.THU,
|
|
2744
|
+
friday: models.DAY_OF_WEEK.FRI,
|
|
2745
|
+
saturday: models.DAY_OF_WEEK.SAT,
|
|
2746
|
+
sunday: models.DAY_OF_WEEK.SUN
|
|
1173
2747
|
};
|
|
1174
2748
|
function mapTrybeImageToMedia(image) {
|
|
1175
2749
|
if (!image) return void 0;
|
|
@@ -1387,6 +2961,32 @@ function mapTrybeCategoryToBookableItemCategory(category, index) {
|
|
|
1387
2961
|
};
|
|
1388
2962
|
}
|
|
1389
2963
|
__name(mapTrybeCategoryToBookableItemCategory, "mapTrybeCategoryToBookableItemCategory");
|
|
2964
|
+
function mapTrybePractitionerToOfferingResource(practitioner, index) {
|
|
2965
|
+
const media = practitioner.avatar != null && typeof practitioner.avatar === "object" ? {
|
|
2966
|
+
meta: practitioner.avatar
|
|
2967
|
+
} : void 0;
|
|
2968
|
+
return {
|
|
2969
|
+
id: BigInt(index + 1),
|
|
2970
|
+
externalId: practitioner.id,
|
|
2971
|
+
name: practitioner.name,
|
|
2972
|
+
type: models.OFFERING_RESOURCE_TYPE.PEOPLE,
|
|
2973
|
+
status: models.STATUS.ACTIVE,
|
|
2974
|
+
media,
|
|
2975
|
+
updatedAt: practitioner.updated_at ? new Date(practitioner.updated_at) : void 0,
|
|
2976
|
+
meta: {
|
|
2977
|
+
organisationId: practitioner.organisation_id,
|
|
2978
|
+
siteIds: practitioner.site_ids,
|
|
2979
|
+
appointmentRestrictions: practitioner.appointment_restrictions,
|
|
2980
|
+
tagIds: practitioner.tag_ids,
|
|
2981
|
+
tags: practitioner.tags,
|
|
2982
|
+
zones: practitioner.zones,
|
|
2983
|
+
canOfferTags: practitioner.can_offer_tags,
|
|
2984
|
+
createdAt: practitioner.created_at,
|
|
2985
|
+
updatedAt: practitioner.updated_at
|
|
2986
|
+
}
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
__name(mapTrybePractitionerToOfferingResource, "mapTrybePractitionerToOfferingResource");
|
|
1390
2990
|
function mapTrybeAppointmentsToSystemResponse(appointments, totalCount, courseLookup) {
|
|
1391
2991
|
const records = appointments.map((apt, index) => {
|
|
1392
2992
|
const linkedCourses = courseLookup?.get(apt.id) ?? [];
|
|
@@ -1427,6 +3027,14 @@ function mapTrybeCategoriesToSystemResponse(categories, totalCount) {
|
|
|
1427
3027
|
};
|
|
1428
3028
|
}
|
|
1429
3029
|
__name(mapTrybeCategoriesToSystemResponse, "mapTrybeCategoriesToSystemResponse");
|
|
3030
|
+
function mapTrybePractitionersToSystemResponse(practitioners, totalCount) {
|
|
3031
|
+
const records = practitioners.map((practitioner, index) => mapTrybePractitionerToOfferingResource(practitioner, index));
|
|
3032
|
+
return {
|
|
3033
|
+
totalCount,
|
|
3034
|
+
records
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
__name(mapTrybePractitionersToSystemResponse, "mapTrybePractitionersToSystemResponse");
|
|
1430
3038
|
function mapTrybeOfferingTypeToBookableItemType(offeringType) {
|
|
1431
3039
|
switch (offeringType) {
|
|
1432
3040
|
case TRYBE_OFFERING_TYPE_ENUM.APPOINTMENT:
|
|
@@ -1528,17 +3136,17 @@ function mapTrybeAppointmentAvailabilityToSystemResponse(slots) {
|
|
|
1528
3136
|
__name(mapTrybeAppointmentAvailabilityToSystemResponse, "mapTrybeAppointmentAvailabilityToSystemResponse");
|
|
1529
3137
|
|
|
1530
3138
|
// ../../packages/dvss-integration-trybe/src/capabilities/wellness/wellness-management.service.ts
|
|
1531
|
-
function
|
|
3139
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
1532
3140
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1533
3141
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1534
3142
|
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;
|
|
1535
3143
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1536
3144
|
}
|
|
1537
|
-
__name(
|
|
1538
|
-
function
|
|
3145
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
3146
|
+
function _ts_metadata13(k, v) {
|
|
1539
3147
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1540
3148
|
}
|
|
1541
|
-
__name(
|
|
3149
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
1542
3150
|
exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
|
|
1543
3151
|
static {
|
|
1544
3152
|
__name(this, "TrybeWellnessManagement");
|
|
@@ -1552,9 +3160,6 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
|
|
|
1552
3160
|
this.trafficGatewayService = trafficGatewayService;
|
|
1553
3161
|
this.trybeAuthService = trybeAuthService;
|
|
1554
3162
|
}
|
|
1555
|
-
fetchPractitioners() {
|
|
1556
|
-
throw new Error("Method not implemented.");
|
|
1557
|
-
}
|
|
1558
3163
|
fetchWellnessAppointmentSession() {
|
|
1559
3164
|
throw new Error("Method not implemented.");
|
|
1560
3165
|
}
|
|
@@ -1570,6 +3175,265 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
|
|
|
1570
3175
|
confirmWellnessAppointmentSessionOrder() {
|
|
1571
3176
|
throw new Error("Method not implemented.");
|
|
1572
3177
|
}
|
|
3178
|
+
async createOrder(request, integration, loggedInUserId) {
|
|
3179
|
+
let orderId;
|
|
3180
|
+
try {
|
|
3181
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3182
|
+
const siteId = validated.config.integrationConfig.siteId;
|
|
3183
|
+
const res = await this.trafficGatewayService.executeIntegrationRequest({
|
|
3184
|
+
apiMethod: HTTP_METHOD.POST,
|
|
3185
|
+
url: "/shop/orders",
|
|
3186
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3187
|
+
headers: validated.headers,
|
|
3188
|
+
body: {
|
|
3189
|
+
site_id: siteId,
|
|
3190
|
+
status: "new"
|
|
3191
|
+
}
|
|
3192
|
+
}, validated, loggedInUserId);
|
|
3193
|
+
orderId = res.data.id;
|
|
3194
|
+
const items = [];
|
|
3195
|
+
await this.addCustomerToOrder(orderId, request.customerId, integration, loggedInUserId);
|
|
3196
|
+
const order = await this.getOrder(orderId, integration, loggedInUserId);
|
|
3197
|
+
for (const bookableItem of request.bookableItems) {
|
|
3198
|
+
const orderItemResponse = await this.addItemToOrder({
|
|
3199
|
+
orderId,
|
|
3200
|
+
item: {
|
|
3201
|
+
offeringId: bookableItem.externalId,
|
|
3202
|
+
offeringType: bookableItem.type,
|
|
3203
|
+
guestIds: order.guests.map((g) => g.id),
|
|
3204
|
+
practitionerIds: request.offeringResources.map((r) => r.externalId),
|
|
3205
|
+
durationMinutes: request.durationInMinutes,
|
|
3206
|
+
timeIso: request.bookingStartTime.toISOString()
|
|
3207
|
+
}
|
|
3208
|
+
}, integration, loggedInUserId);
|
|
3209
|
+
items.push({
|
|
3210
|
+
externalId: bookableItem.externalId,
|
|
3211
|
+
name: orderItemResponse.name,
|
|
3212
|
+
type: bookableItem.type,
|
|
3213
|
+
totalPrice: (orderItemResponse.netTotal ?? 0) / request.currencyMultiplier
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
if (request.customerCreditId) {
|
|
3217
|
+
await this.addCustomerCreditsToOrder(orderId, request.customerCreditId, integration, loggedInUserId);
|
|
3218
|
+
}
|
|
3219
|
+
await this.submitOrder(orderId, integration, loggedInUserId);
|
|
3220
|
+
this.logger.info(loggedInUserId, this.createOrder.name, this.fileName, "Created Trybe order for offering booking", {
|
|
3221
|
+
orderId
|
|
3222
|
+
});
|
|
3223
|
+
return {
|
|
3224
|
+
externalBookingId: orderId,
|
|
3225
|
+
items,
|
|
3226
|
+
meta: {
|
|
3227
|
+
orderReference: order.meta.orderReference
|
|
3228
|
+
}
|
|
3229
|
+
};
|
|
3230
|
+
} catch (err) {
|
|
3231
|
+
this.logger.error(loggedInUserId, this.createOrder.name, this.fileName, "Error creating Trybe order for offering booking", err);
|
|
3232
|
+
if (orderId) {
|
|
3233
|
+
await this.cancelOrder(orderId, integration, loggedInUserId);
|
|
3234
|
+
}
|
|
3235
|
+
throw err;
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
async addCustomerToOrder(orderId, customerId, integration, loggedInUserId) {
|
|
3239
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3240
|
+
await this.trafficGatewayService.executeIntegrationRequest({
|
|
3241
|
+
apiMethod: HTTP_METHOD.POST,
|
|
3242
|
+
url: `/shop/orders/${orderId}/customer`,
|
|
3243
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3244
|
+
headers: validated.headers,
|
|
3245
|
+
body: {
|
|
3246
|
+
id: customerId,
|
|
3247
|
+
source: "trybe"
|
|
3248
|
+
}
|
|
3249
|
+
}, validated, loggedInUserId);
|
|
3250
|
+
}
|
|
3251
|
+
async getOrder(orderId, integration, loggedInUserId) {
|
|
3252
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3253
|
+
const res = await this.trafficGatewayService.executeIntegrationRequest({
|
|
3254
|
+
apiMethod: HTTP_METHOD.GET,
|
|
3255
|
+
url: `/shop/orders/${orderId}`,
|
|
3256
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3257
|
+
headers: validated.headers
|
|
3258
|
+
}, validated, loggedInUserId);
|
|
3259
|
+
return {
|
|
3260
|
+
orderId: res.data.id,
|
|
3261
|
+
guests: res.data.guests.map((g) => ({
|
|
3262
|
+
id: g.id,
|
|
3263
|
+
name: g.name
|
|
3264
|
+
})),
|
|
3265
|
+
meta: {
|
|
3266
|
+
orderReference: res.data.order_ref
|
|
3267
|
+
},
|
|
3268
|
+
items: res.data.booking_items ?? []
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
mapOfferingTypeToTrybeApi(type) {
|
|
3272
|
+
switch (type) {
|
|
3273
|
+
case BOOKABLE_ITEM_TYPE_ENUM.APPOINTMENT:
|
|
3274
|
+
return TRYBE_OFFERING_TYPE_API.APPOINTMENT;
|
|
3275
|
+
case BOOKABLE_ITEM_TYPE_ENUM.SESSION:
|
|
3276
|
+
return TRYBE_OFFERING_TYPE_API.SESSION;
|
|
3277
|
+
case BOOKABLE_ITEM_TYPE_ENUM.COURSE:
|
|
3278
|
+
return TRYBE_OFFERING_TYPE_API.COURSE;
|
|
3279
|
+
default:
|
|
3280
|
+
throw new Error(`Unsupported offering type: ${type}`);
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
async addItemToOrder(request, integration, loggedInUserId) {
|
|
3284
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3285
|
+
const { orderId, item } = request;
|
|
3286
|
+
const offeringType = this.mapOfferingTypeToTrybeApi(item.offeringType);
|
|
3287
|
+
let body;
|
|
3288
|
+
if (offeringType === TRYBE_OFFERING_TYPE_API.APPOINTMENT) {
|
|
3289
|
+
if (item.durationMinutes == null || !item.timeIso) {
|
|
3290
|
+
throw new Error("durationMinutes and timeIso required for appointment");
|
|
3291
|
+
}
|
|
3292
|
+
body = {
|
|
3293
|
+
offering_type: offeringType,
|
|
3294
|
+
offering_id: item.offeringId,
|
|
3295
|
+
guest_ids: item.guestIds,
|
|
3296
|
+
item_configuration: {
|
|
3297
|
+
duration: item.durationMinutes,
|
|
3298
|
+
skip_availability_checks: false,
|
|
3299
|
+
time: item.timeIso
|
|
3300
|
+
},
|
|
3301
|
+
skip_availability_checks: false
|
|
3302
|
+
};
|
|
3303
|
+
} else if (offeringType === TRYBE_OFFERING_TYPE_API.SESSION) {
|
|
3304
|
+
if (!item.sessionId) {
|
|
3305
|
+
throw new Error("sessionId required for session");
|
|
3306
|
+
}
|
|
3307
|
+
body = {
|
|
3308
|
+
offering_type: offeringType,
|
|
3309
|
+
offering_id: item.offeringId,
|
|
3310
|
+
guest_ids: item.guestIds,
|
|
3311
|
+
item_configuration: {
|
|
3312
|
+
session_id: item.sessionId,
|
|
3313
|
+
skip_availability_checks: false
|
|
3314
|
+
},
|
|
3315
|
+
skip_availability_checks: false
|
|
3316
|
+
};
|
|
3317
|
+
} else {
|
|
3318
|
+
body = {
|
|
3319
|
+
offering_type: offeringType,
|
|
3320
|
+
offering_id: item.offeringId,
|
|
3321
|
+
guest_ids: item.guestIds
|
|
3322
|
+
};
|
|
3323
|
+
}
|
|
3324
|
+
const res = await this.trafficGatewayService.executeIntegrationRequest({
|
|
3325
|
+
apiMethod: HTTP_METHOD.POST,
|
|
3326
|
+
url: `/shop/orders/${orderId}/items`,
|
|
3327
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3328
|
+
headers: validated.headers,
|
|
3329
|
+
body
|
|
3330
|
+
}, validated, loggedInUserId);
|
|
3331
|
+
const d = res.data;
|
|
3332
|
+
return {
|
|
3333
|
+
name: d.booking_summary?.offering?.name ?? d.type_name ?? void 0,
|
|
3334
|
+
netTotal: d.net_total
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
3337
|
+
async addCustomerCreditsToOrder(orderId, customerCreditId, integration, loggedInUserId) {
|
|
3338
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3339
|
+
await this.trafficGatewayService.executeIntegrationRequest({
|
|
3340
|
+
apiMethod: HTTP_METHOD.POST,
|
|
3341
|
+
url: `/shop/orders/${orderId}/customer-credits`,
|
|
3342
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3343
|
+
headers: validated.headers,
|
|
3344
|
+
body: {
|
|
3345
|
+
id: customerCreditId
|
|
3346
|
+
}
|
|
3347
|
+
}, validated, loggedInUserId);
|
|
3348
|
+
}
|
|
3349
|
+
async submitOrder(orderId, integration, loggedInUserId) {
|
|
3350
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3351
|
+
await this.trafficGatewayService.executeIntegrationRequest({
|
|
3352
|
+
apiMethod: HTTP_METHOD.POST,
|
|
3353
|
+
url: `/shop/orders/${orderId}/submit`,
|
|
3354
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3355
|
+
headers: validated.headers
|
|
3356
|
+
}, validated, loggedInUserId);
|
|
3357
|
+
}
|
|
3358
|
+
async cancelOrder(orderId, integration, loggedInUserId) {
|
|
3359
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3360
|
+
await this.trafficGatewayService.executeIntegrationRequest({
|
|
3361
|
+
apiMethod: HTTP_METHOD.POST,
|
|
3362
|
+
url: `/shop/orders/${orderId}/cancel`,
|
|
3363
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3364
|
+
headers: validated.headers
|
|
3365
|
+
}, validated, loggedInUserId);
|
|
3366
|
+
}
|
|
3367
|
+
async updateOrder(request, integration, loggedInUserId) {
|
|
3368
|
+
const order = await this.getOrder(request.orderId, integration, loggedInUserId);
|
|
3369
|
+
const itemId = order.items[0]?.id;
|
|
3370
|
+
if (!itemId) {
|
|
3371
|
+
throw new Error("Item not found in order");
|
|
3372
|
+
}
|
|
3373
|
+
const updateResponse = await this.updateOrderItem(request.orderId, itemId, request, integration, loggedInUserId);
|
|
3374
|
+
return {
|
|
3375
|
+
success: Boolean(updateResponse.data.id),
|
|
3376
|
+
data: updateResponse.data
|
|
3377
|
+
};
|
|
3378
|
+
}
|
|
3379
|
+
async updateOrderItem(orderId, itemId, request, integration, loggedInUserId) {
|
|
3380
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3381
|
+
const offeringType = this.mapOfferingTypeToTrybeApi(request.item.type);
|
|
3382
|
+
let body;
|
|
3383
|
+
if (offeringType === TRYBE_OFFERING_TYPE_API.APPOINTMENT) {
|
|
3384
|
+
if (request.bookingStartTimeLabel == null || request.durationInMinutes == null || request.bookingStartDateLabel == null) {
|
|
3385
|
+
throw new Error("durationInMinutes, bookingStartDateLabel and bookingStartTimeLabel required for appointment");
|
|
3386
|
+
}
|
|
3387
|
+
const timeIso = dvssBackendModuleUtility.convertDateOnlyToTimestamp(request.timezone, request.bookingStartDateLabel, request.bookingStartTimeLabel).toISOString();
|
|
3388
|
+
body = {
|
|
3389
|
+
offering_id: request.item.externalId,
|
|
3390
|
+
item_configuration: {
|
|
3391
|
+
time: timeIso,
|
|
3392
|
+
duration: request.durationInMinutes,
|
|
3393
|
+
skip_availability_checks: false
|
|
3394
|
+
},
|
|
3395
|
+
skip_availability_checks: false
|
|
3396
|
+
};
|
|
3397
|
+
} else if (offeringType === TRYBE_OFFERING_TYPE_API.SESSION) {
|
|
3398
|
+
if (!request.sessionId) {
|
|
3399
|
+
throw new Error("sessionId required for session");
|
|
3400
|
+
}
|
|
3401
|
+
body = {
|
|
3402
|
+
item_configuration: {
|
|
3403
|
+
session_id: request.sessionId,
|
|
3404
|
+
skip_availability_checks: false
|
|
3405
|
+
}
|
|
3406
|
+
};
|
|
3407
|
+
} else {
|
|
3408
|
+
throw new Error("Course is not updatable");
|
|
3409
|
+
}
|
|
3410
|
+
const res = await this.trafficGatewayService.executeIntegrationRequest({
|
|
3411
|
+
apiMethod: HTTP_METHOD.PUT,
|
|
3412
|
+
url: `/shop/orders/${orderId}/items/${itemId}`,
|
|
3413
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3414
|
+
headers: validated.headers,
|
|
3415
|
+
body
|
|
3416
|
+
}, validated, loggedInUserId);
|
|
3417
|
+
return res;
|
|
3418
|
+
}
|
|
3419
|
+
async addPaymentToOrder(request, integration, loggedInUserId) {
|
|
3420
|
+
const validated = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3421
|
+
await this.trafficGatewayService.executeIntegrationRequest({
|
|
3422
|
+
apiMethod: HTTP_METHOD.POST,
|
|
3423
|
+
url: `/shop/orders/${request.orderId}/payments`,
|
|
3424
|
+
baseUrl: validated.config.platformConfig.baseUrl,
|
|
3425
|
+
headers: validated.headers,
|
|
3426
|
+
body: {
|
|
3427
|
+
amount: request.amount,
|
|
3428
|
+
processor: "manual",
|
|
3429
|
+
status: "paid",
|
|
3430
|
+
processor_data: {
|
|
3431
|
+
notes: "",
|
|
3432
|
+
payment_type_id: request.paymentTypeId
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
}, validated, loggedInUserId);
|
|
3436
|
+
}
|
|
1573
3437
|
async fetchAppointments(request, integration, loggedInUserId) {
|
|
1574
3438
|
this.logger.info(loggedInUserId, this.fetchAppointments.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchAppointments.name} Called`, {
|
|
1575
3439
|
request
|
|
@@ -1666,6 +3530,27 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
|
|
|
1666
3530
|
}, validatedIntegration, loggedInUserId));
|
|
1667
3531
|
return mapTrybeCoursesToSystemResponse(records, firstPageResponse.meta.total);
|
|
1668
3532
|
}
|
|
3533
|
+
async fetchPractitioners(request, integration, loggedInUserId) {
|
|
3534
|
+
this.logger.info(loggedInUserId, this.fetchPractitioners.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchPractitioners.name} Called`, {
|
|
3535
|
+
request
|
|
3536
|
+
});
|
|
3537
|
+
const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3538
|
+
const siteId = validatedIntegration.config.integrationConfig.siteId;
|
|
3539
|
+
const apiUrl = `/shop/practitioners/?site_id=${siteId}`;
|
|
3540
|
+
const firstPageResponse = await this.trafficGatewayService.executeIntegrationRequest({
|
|
3541
|
+
apiMethod: HTTP_METHOD.GET,
|
|
3542
|
+
url: apiUrl,
|
|
3543
|
+
baseUrl: validatedIntegration.config.platformConfig.baseUrl,
|
|
3544
|
+
headers: validatedIntegration.headers
|
|
3545
|
+
}, validatedIntegration, loggedInUserId);
|
|
3546
|
+
const records = await fetchAllPages(firstPageResponse, request.shouldFetchAllPractitioners, (page) => this.trafficGatewayService.executeIntegrationRequest({
|
|
3547
|
+
apiMethod: HTTP_METHOD.GET,
|
|
3548
|
+
url: `${apiUrl}&page=${page}`,
|
|
3549
|
+
baseUrl: validatedIntegration.config.platformConfig.baseUrl,
|
|
3550
|
+
headers: validatedIntegration.headers
|
|
3551
|
+
}, validatedIntegration, loggedInUserId));
|
|
3552
|
+
return mapTrybePractitionersToSystemResponse(records, firstPageResponse.meta.total);
|
|
3553
|
+
}
|
|
1669
3554
|
async fetchCategories(request, integration, loggedInUserId) {
|
|
1670
3555
|
this.logger.info(loggedInUserId, this.fetchCategories.name, this.fileName, `${_TrybeWellnessManagement.name} -> ${this.fetchCategories.name} Called`, {
|
|
1671
3556
|
request
|
|
@@ -1755,30 +3640,120 @@ exports.TrybeWellnessManagement = class _TrybeWellnessManagement {
|
|
|
1755
3640
|
return mapTrybeAppointmentAvailabilityToSystemResponse(response.data);
|
|
1756
3641
|
}
|
|
1757
3642
|
};
|
|
1758
|
-
exports.TrybeWellnessManagement =
|
|
3643
|
+
exports.TrybeWellnessManagement = _ts_decorate16([
|
|
1759
3644
|
common.Injectable(),
|
|
1760
|
-
|
|
1761
|
-
|
|
3645
|
+
_ts_metadata13("design:type", Function),
|
|
3646
|
+
_ts_metadata13("design:paramtypes", [
|
|
1762
3647
|
typeof dvssBackendModuleUtility.LoggerService === "undefined" ? Object : dvssBackendModuleUtility.LoggerService,
|
|
1763
3648
|
typeof exports.TrafficGatewayService === "undefined" ? Object : exports.TrafficGatewayService,
|
|
1764
3649
|
typeof exports.TrybeAuthService === "undefined" ? Object : exports.TrybeAuthService
|
|
1765
3650
|
])
|
|
1766
3651
|
], exports.TrybeWellnessManagement);
|
|
1767
3652
|
|
|
3653
|
+
// ../../packages/dvss-integration-trybe/src/capabilities/integration-configuration/integration-configuration.mapper.ts
|
|
3654
|
+
function mapTrybeSiteResponseToSystem(response) {
|
|
3655
|
+
return {
|
|
3656
|
+
customPaymentTypes: response.data?.custom_payment_types?.map((paymentType) => ({
|
|
3657
|
+
id: paymentType.id,
|
|
3658
|
+
name: paymentType.name,
|
|
3659
|
+
kind: paymentType.kind
|
|
3660
|
+
}))
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
__name(mapTrybeSiteResponseToSystem, "mapTrybeSiteResponseToSystem");
|
|
3664
|
+
|
|
3665
|
+
// ../../packages/dvss-integration-trybe/src/capabilities/integration-configuration/integration-configuration.service.ts
|
|
3666
|
+
function _ts_decorate17(decorators, target, key, desc) {
|
|
3667
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3668
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3669
|
+
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;
|
|
3670
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3671
|
+
}
|
|
3672
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
3673
|
+
function _ts_metadata14(k, v) {
|
|
3674
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3675
|
+
}
|
|
3676
|
+
__name(_ts_metadata14, "_ts_metadata");
|
|
3677
|
+
exports.TrybeIntegrationConfigurationService = class TrybeIntegrationConfigurationService extends BaseIntegrationConfiguration {
|
|
3678
|
+
static {
|
|
3679
|
+
__name(this, "TrybeIntegrationConfigurationService");
|
|
3680
|
+
}
|
|
3681
|
+
trybeAuthService;
|
|
3682
|
+
trafficGatewayService;
|
|
3683
|
+
constructor(integrationConfigurationDao, commonValidationDatabaseService, trybeAuthService, trafficGatewayService) {
|
|
3684
|
+
super(integrationConfigurationDao, commonValidationDatabaseService), this.trybeAuthService = trybeAuthService, this.trafficGatewayService = trafficGatewayService;
|
|
3685
|
+
}
|
|
3686
|
+
/**
|
|
3687
|
+
* Add capability integration: validate Trybe config, then configuredFor (offering), then delegate to base.
|
|
3688
|
+
*/
|
|
3689
|
+
async addCapabilityIntegration(input, context) {
|
|
3690
|
+
this.trybeAuthService.validateConfig({
|
|
3691
|
+
config: input.config
|
|
3692
|
+
}, context.loggedInUserId);
|
|
3693
|
+
if (input.configuredFor != null) {
|
|
3694
|
+
await this.validateCapabilityIntegrationConfiguredForInput(input.configuredFor, input.projectId);
|
|
3695
|
+
}
|
|
3696
|
+
return super.addCapabilityIntegration(input, context);
|
|
3697
|
+
}
|
|
3698
|
+
/**
|
|
3699
|
+
* Update capability integration: delegate to base.
|
|
3700
|
+
*/
|
|
3701
|
+
async updateCapabilityIntegration(id, updateData, context) {
|
|
3702
|
+
return super.updateCapabilityIntegration(id, updateData, context);
|
|
3703
|
+
}
|
|
3704
|
+
/**
|
|
3705
|
+
* Validates configuredFor (offering exists and belongs to project). Same as project-ms validateCapabilityIntegrationConfiguredForInput.
|
|
3706
|
+
*/
|
|
3707
|
+
async validateCapabilityIntegrationConfiguredForInput(configuredFor, projectId) {
|
|
3708
|
+
if (configuredFor.configuredForType !== models.CONFIGURED_FOR_TYPE_ENUM.OFFERING) {
|
|
3709
|
+
throw new Error(`configuredForType not supported: ${configuredFor.configuredForType}`);
|
|
3710
|
+
}
|
|
3711
|
+
await this.commonValidationDatabaseService.getOffering({
|
|
3712
|
+
offeringId: configuredFor.configuredForId,
|
|
3713
|
+
projectId
|
|
3714
|
+
});
|
|
3715
|
+
}
|
|
3716
|
+
/**
|
|
3717
|
+
* Trybe 3rd party: GET /shop/sites/{siteId} via executeIntegrationRequest.
|
|
3718
|
+
*/
|
|
3719
|
+
async getSiteDetailedInformation(integration, loggedInUserId) {
|
|
3720
|
+
const validatedIntegration = this.trybeAuthService.validateConfig(integration, loggedInUserId);
|
|
3721
|
+
const siteId = validatedIntegration.config.integrationConfig.siteId;
|
|
3722
|
+
const url = `/shop/sites/${siteId}`;
|
|
3723
|
+
const response = await this.trafficGatewayService.executeIntegrationRequest({
|
|
3724
|
+
apiMethod: HTTP_METHOD.GET,
|
|
3725
|
+
url,
|
|
3726
|
+
baseUrl: validatedIntegration.config.platformConfig.baseUrl,
|
|
3727
|
+
headers: validatedIntegration.headers
|
|
3728
|
+
}, validatedIntegration, loggedInUserId);
|
|
3729
|
+
return mapTrybeSiteResponseToSystem(response);
|
|
3730
|
+
}
|
|
3731
|
+
};
|
|
3732
|
+
exports.TrybeIntegrationConfigurationService = _ts_decorate17([
|
|
3733
|
+
common.Injectable(),
|
|
3734
|
+
_ts_metadata14("design:type", Function),
|
|
3735
|
+
_ts_metadata14("design:paramtypes", [
|
|
3736
|
+
typeof exports.IntegrationConfigurationDao === "undefined" ? Object : exports.IntegrationConfigurationDao,
|
|
3737
|
+
typeof dvssBackendModuleDatastore.CommonValidationDatabaseService === "undefined" ? Object : dvssBackendModuleDatastore.CommonValidationDatabaseService,
|
|
3738
|
+
typeof exports.TrybeAuthService === "undefined" ? Object : exports.TrybeAuthService,
|
|
3739
|
+
typeof exports.TrafficGatewayService === "undefined" ? Object : exports.TrafficGatewayService
|
|
3740
|
+
])
|
|
3741
|
+
], exports.TrybeIntegrationConfigurationService);
|
|
3742
|
+
|
|
1768
3743
|
// ../../packages/dvss-integration-trybe/src/app.module.ts
|
|
1769
|
-
function
|
|
3744
|
+
function _ts_decorate18(decorators, target, key, desc) {
|
|
1770
3745
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1771
3746
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1772
3747
|
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;
|
|
1773
3748
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1774
3749
|
}
|
|
1775
|
-
__name(
|
|
3750
|
+
__name(_ts_decorate18, "_ts_decorate");
|
|
1776
3751
|
exports.IntegrationTrybeModule = class AppModule2 {
|
|
1777
3752
|
static {
|
|
1778
3753
|
__name(this, "AppModule");
|
|
1779
3754
|
}
|
|
1780
3755
|
};
|
|
1781
|
-
exports.IntegrationTrybeModule =
|
|
3756
|
+
exports.IntegrationTrybeModule = _ts_decorate18([
|
|
1782
3757
|
common.Module({
|
|
1783
3758
|
imports: [
|
|
1784
3759
|
// Load environment variables from root .env file
|
|
@@ -1788,7 +3763,8 @@ exports.IntegrationTrybeModule = _ts_decorate15([
|
|
|
1788
3763
|
}),
|
|
1789
3764
|
exports.IntegrationLibsModule,
|
|
1790
3765
|
axios.HttpModule,
|
|
1791
|
-
dvssBackendModuleUtility.LoggerModule
|
|
3766
|
+
dvssBackendModuleUtility.LoggerModule,
|
|
3767
|
+
dvssBackendModuleDatastore.DatastoreModule
|
|
1792
3768
|
],
|
|
1793
3769
|
controllers: [
|
|
1794
3770
|
AppController2
|
|
@@ -1798,31 +3774,40 @@ exports.IntegrationTrybeModule = _ts_decorate15([
|
|
|
1798
3774
|
exports.TrybeAuthService,
|
|
1799
3775
|
exports.TrybeCustomerManagement,
|
|
1800
3776
|
exports.TrybeCreditBooking,
|
|
1801
|
-
exports.TrybeWellnessManagement
|
|
3777
|
+
exports.TrybeWellnessManagement,
|
|
3778
|
+
exports.IntegrationConfigurationDao,
|
|
3779
|
+
exports.IntegrationRequestLoggerService,
|
|
3780
|
+
exports.RateLimiterService,
|
|
3781
|
+
exports.TrafficGatewayService,
|
|
3782
|
+
exports.TrybeCustomerManagement,
|
|
3783
|
+
exports.TrybeAuthService,
|
|
3784
|
+
exports.TrybeIntegrationConfigurationService,
|
|
3785
|
+
dvssBackendModuleDatastore.CommonValidationDatabaseService
|
|
1802
3786
|
],
|
|
1803
3787
|
exports: [
|
|
1804
3788
|
exports.TrybeAuthService,
|
|
1805
3789
|
exports.TrybeCustomerManagement,
|
|
1806
3790
|
exports.TrybeCreditBooking,
|
|
1807
|
-
exports.TrybeWellnessManagement
|
|
3791
|
+
exports.TrybeWellnessManagement,
|
|
3792
|
+
exports.TrybeIntegrationConfigurationService
|
|
1808
3793
|
]
|
|
1809
3794
|
})
|
|
1810
3795
|
], exports.IntegrationTrybeModule);
|
|
1811
3796
|
|
|
1812
3797
|
// src/app.module.ts
|
|
1813
|
-
function
|
|
3798
|
+
function _ts_decorate19(decorators, target, key, desc) {
|
|
1814
3799
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1815
3800
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1816
3801
|
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;
|
|
1817
3802
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1818
3803
|
}
|
|
1819
|
-
__name(
|
|
3804
|
+
__name(_ts_decorate19, "_ts_decorate");
|
|
1820
3805
|
exports.OfferingIntegrationManager = class AppModule3 {
|
|
1821
3806
|
static {
|
|
1822
3807
|
__name(this, "AppModule");
|
|
1823
3808
|
}
|
|
1824
3809
|
};
|
|
1825
|
-
exports.OfferingIntegrationManager =
|
|
3810
|
+
exports.OfferingIntegrationManager = _ts_decorate19([
|
|
1826
3811
|
common.Module({
|
|
1827
3812
|
imports: [
|
|
1828
3813
|
exports.IntegrationTrybeModule,
|
|
@@ -1855,6 +3840,7 @@ exports.BaseAccountingTaxManagement = BaseAccountingTaxManagement;
|
|
|
1855
3840
|
exports.BaseAuth = BaseAuth;
|
|
1856
3841
|
exports.BaseCreditBooking = BaseCreditBooking;
|
|
1857
3842
|
exports.BaseCustomerManagement = BaseCustomerManagement;
|
|
3843
|
+
exports.BaseIntegrationConfiguration = BaseIntegrationConfiguration;
|
|
1858
3844
|
exports.BaseMembershipCustomerManagement = BaseMembershipCustomerManagement;
|
|
1859
3845
|
exports.BaseMembershipManagement = BaseMembershipManagement;
|
|
1860
3846
|
exports.BasePackageManagement = BasePackageManagement;
|
|
@@ -1865,10 +3851,10 @@ exports.BaseWellnessManagement = BaseWellnessManagement;
|
|
|
1865
3851
|
exports.CREDIT_FILTER_BY_ENUM = CREDIT_FILTER_BY_ENUM;
|
|
1866
3852
|
exports.CREDIT_STATUS_ENUM = CREDIT_STATUS_ENUM;
|
|
1867
3853
|
exports.CREDIT_TYPE_ENUM = CREDIT_TYPE_ENUM;
|
|
1868
|
-
exports.DAY_OF_WEEK = DAY_OF_WEEK;
|
|
1869
3854
|
exports.HTTP_METHOD = HTTP_METHOD;
|
|
1870
3855
|
exports.INTEGRATION_PROVIDER_ENUM = INTEGRATION_PROVIDER_ENUM;
|
|
1871
3856
|
exports.TRAFFIC_ROUTER_CONFIGURATION_STORE_KEY = TRAFFIC_ROUTER_CONFIGURATION_STORE_KEY;
|
|
3857
|
+
exports.TRYBE_OFFERING_TYPE_API = TRYBE_OFFERING_TYPE_API;
|
|
1872
3858
|
exports.TRYBE_OFFERING_TYPE_ENUM = TRYBE_OFFERING_TYPE_ENUM;
|
|
1873
3859
|
exports.convertKeysToCamelCase = convertKeysToCamelCase;
|
|
1874
3860
|
exports.extractTimeFromIsoString = extractTimeFromIsoString;
|