@goweekdays/core 2.4.2 → 2.5.0
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +141 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -398,7 +398,10 @@ declare function useOrgRepo(): {
|
|
|
398
398
|
declare function useOrgService(): {
|
|
399
399
|
add: (value: TOrg & {
|
|
400
400
|
seats: number;
|
|
401
|
-
}) => Promise<
|
|
401
|
+
}) => Promise<{
|
|
402
|
+
org: string;
|
|
403
|
+
paypalOrderLink: any;
|
|
404
|
+
}>;
|
|
402
405
|
};
|
|
403
406
|
|
|
404
407
|
declare function useOrgController(): {
|
|
@@ -627,6 +630,7 @@ declare function useGitHubService(): {
|
|
|
627
630
|
declare function useUtilController(): {
|
|
628
631
|
healthCheck: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
629
632
|
setGitHubVariables: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
633
|
+
paypalWebhook: (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>>>;
|
|
630
634
|
};
|
|
631
635
|
|
|
632
636
|
declare const transactionSchema: Joi.ObjectSchema<any>;
|
|
@@ -1026,8 +1030,10 @@ declare const SPACES_BUCKET: string;
|
|
|
1026
1030
|
declare const PAYPAL_CLIENT_ID: string;
|
|
1027
1031
|
declare const PAYPAL_CLIENT_SECRET: string;
|
|
1028
1032
|
declare const PAYPAL_API_URL: string;
|
|
1033
|
+
declare const PAYPAL_WEBHOOK_ID: string;
|
|
1029
1034
|
declare const XENDIT_SECRET_KEY: string;
|
|
1030
1035
|
declare const XENDIT_BASE_URL: string;
|
|
1031
1036
|
declare const DOMAIN: string;
|
|
1037
|
+
declare const APP_ORG: string;
|
|
1032
1038
|
|
|
1033
|
-
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, modelApp, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscription, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
|
1039
|
+
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, APP_ORG, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, modelApp, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscription, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
ACCESS_TOKEN_SECRET: () => ACCESS_TOKEN_SECRET,
|
|
35
35
|
APP_ACCOUNT: () => APP_ACCOUNT,
|
|
36
36
|
APP_MAIN: () => APP_MAIN,
|
|
37
|
+
APP_ORG: () => APP_ORG,
|
|
37
38
|
DEFAULT_USER_EMAIL: () => DEFAULT_USER_EMAIL,
|
|
38
39
|
DEFAULT_USER_FIRST_NAME: () => DEFAULT_USER_FIRST_NAME,
|
|
39
40
|
DEFAULT_USER_LAST_NAME: () => DEFAULT_USER_LAST_NAME,
|
|
@@ -52,6 +53,7 @@ __export(src_exports, {
|
|
|
52
53
|
PAYPAL_API_URL: () => PAYPAL_API_URL,
|
|
53
54
|
PAYPAL_CLIENT_ID: () => PAYPAL_CLIENT_ID,
|
|
54
55
|
PAYPAL_CLIENT_SECRET: () => PAYPAL_CLIENT_SECRET,
|
|
56
|
+
PAYPAL_WEBHOOK_ID: () => PAYPAL_WEBHOOK_ID,
|
|
55
57
|
PORT: () => PORT,
|
|
56
58
|
REDIS_HOST: () => REDIS_HOST,
|
|
57
59
|
REDIS_PASSWORD: () => REDIS_PASSWORD,
|
|
@@ -1028,9 +1030,11 @@ var SPACES_BUCKET = process.env.SPACES_BUCKET;
|
|
|
1028
1030
|
var PAYPAL_CLIENT_ID = process.env.PAYPAL_CLIENT_ID ?? "";
|
|
1029
1031
|
var PAYPAL_CLIENT_SECRET = process.env.PAYPAL_CLIENT_SECRET ?? "";
|
|
1030
1032
|
var PAYPAL_API_URL = process.env.PAYPAL_API_URL ?? "https://api-m.sandbox.paypal.com";
|
|
1033
|
+
var PAYPAL_WEBHOOK_ID = process.env.PAYPAL_WEBHOOK_ID ?? "";
|
|
1031
1034
|
var XENDIT_SECRET_KEY = process.env.XENDIT_SECRET_KEY ?? "";
|
|
1032
1035
|
var XENDIT_BASE_URL = process.env.XENDIT_BASE_URL ?? "https://api.xendit.co";
|
|
1033
1036
|
var DOMAIN = process.env.DOMAIN || "localhost";
|
|
1037
|
+
var APP_ORG = process.env.APP_ORG || "http://localhost/organizations/create";
|
|
1034
1038
|
|
|
1035
1039
|
// src/resources/user/user.service.ts
|
|
1036
1040
|
var import_utils38 = require("@goweekdays/utils");
|
|
@@ -3555,6 +3559,11 @@ function useAppService() {
|
|
|
3555
3559
|
code: "ride",
|
|
3556
3560
|
name: "Ride",
|
|
3557
3561
|
description: "Transportation and ride services."
|
|
3562
|
+
},
|
|
3563
|
+
{
|
|
3564
|
+
code: "job",
|
|
3565
|
+
name: "jobs",
|
|
3566
|
+
description: "Job listings and recruitment services."
|
|
3558
3567
|
}
|
|
3559
3568
|
];
|
|
3560
3569
|
const session = import_utils17.useAtlas.getClient()?.startSession();
|
|
@@ -6350,6 +6359,112 @@ function usePlanController() {
|
|
|
6350
6359
|
};
|
|
6351
6360
|
}
|
|
6352
6361
|
|
|
6362
|
+
// src/resources/utils/paypal.service.ts
|
|
6363
|
+
var import_paypal_server_sdk = require("@paypal/paypal-server-sdk");
|
|
6364
|
+
function usePaypalService() {
|
|
6365
|
+
const paypalClient = new import_paypal_server_sdk.Client({
|
|
6366
|
+
clientCredentialsAuthCredentials: {
|
|
6367
|
+
oAuthClientId: PAYPAL_CLIENT_ID,
|
|
6368
|
+
oAuthClientSecret: PAYPAL_CLIENT_SECRET
|
|
6369
|
+
},
|
|
6370
|
+
timeout: 0,
|
|
6371
|
+
environment: isDev ? import_paypal_server_sdk.Environment.Sandbox : import_paypal_server_sdk.Environment.Production
|
|
6372
|
+
});
|
|
6373
|
+
function addOrder({
|
|
6374
|
+
amount = 0,
|
|
6375
|
+
currency = "PHP",
|
|
6376
|
+
customId = "",
|
|
6377
|
+
returnUrl = "",
|
|
6378
|
+
cancelUrl = "",
|
|
6379
|
+
action = "pay"
|
|
6380
|
+
} = {}) {
|
|
6381
|
+
return new import_paypal_server_sdk.OrdersController(paypalClient).createOrder({
|
|
6382
|
+
body: {
|
|
6383
|
+
intent: import_paypal_server_sdk.CheckoutPaymentIntent.Capture,
|
|
6384
|
+
purchaseUnits: [
|
|
6385
|
+
{
|
|
6386
|
+
amount: {
|
|
6387
|
+
currencyCode: currency,
|
|
6388
|
+
value: amount.toFixed(2)
|
|
6389
|
+
},
|
|
6390
|
+
customId
|
|
6391
|
+
}
|
|
6392
|
+
],
|
|
6393
|
+
applicationContext: {
|
|
6394
|
+
returnUrl,
|
|
6395
|
+
cancelUrl,
|
|
6396
|
+
userAction: action === "pay" ? import_paypal_server_sdk.OrderApplicationContextUserAction.PayNow : action === "continue" ? import_paypal_server_sdk.OrderApplicationContextUserAction.Continue : void 0
|
|
6397
|
+
}
|
|
6398
|
+
},
|
|
6399
|
+
prefer: "return=minimal"
|
|
6400
|
+
});
|
|
6401
|
+
}
|
|
6402
|
+
function captureOrder(id) {
|
|
6403
|
+
return new import_paypal_server_sdk.OrdersController(paypalClient).captureOrder({ id });
|
|
6404
|
+
}
|
|
6405
|
+
async function verifyWebhook(headers, body, webhookId = PAYPAL_WEBHOOK_ID) {
|
|
6406
|
+
const authAlgo = headers["paypal-auth-algo"];
|
|
6407
|
+
const certUrl = headers["paypal-cert-url"];
|
|
6408
|
+
const transmissionId = headers["paypal-transmission-id"];
|
|
6409
|
+
const transmissionSig = headers["paypal-transmission-sig"];
|
|
6410
|
+
const transmissionTime = headers["paypal-transmission-time"];
|
|
6411
|
+
if (!authAlgo || !certUrl || !transmissionId || !transmissionSig || !transmissionTime) {
|
|
6412
|
+
return {
|
|
6413
|
+
verified: false,
|
|
6414
|
+
verificationStatus: "FAILURE"
|
|
6415
|
+
};
|
|
6416
|
+
}
|
|
6417
|
+
const auth = Buffer.from(
|
|
6418
|
+
`${PAYPAL_CLIENT_ID}:${PAYPAL_CLIENT_SECRET}`
|
|
6419
|
+
).toString("base64");
|
|
6420
|
+
const tokenResponse = await fetch(`${PAYPAL_API_URL}/v1/oauth2/token`, {
|
|
6421
|
+
method: "POST",
|
|
6422
|
+
headers: {
|
|
6423
|
+
Authorization: `Basic ${auth}`,
|
|
6424
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
6425
|
+
},
|
|
6426
|
+
body: "grant_type=client_credentials"
|
|
6427
|
+
});
|
|
6428
|
+
if (!tokenResponse.ok) {
|
|
6429
|
+
throw new Error("Failed to obtain PayPal access token");
|
|
6430
|
+
}
|
|
6431
|
+
const tokenData = await tokenResponse.json();
|
|
6432
|
+
const accessToken = tokenData.access_token;
|
|
6433
|
+
const verifyResponse = await fetch(
|
|
6434
|
+
`${PAYPAL_API_URL}/v1/notifications/verify-webhook-signature`,
|
|
6435
|
+
{
|
|
6436
|
+
method: "POST",
|
|
6437
|
+
headers: {
|
|
6438
|
+
Authorization: `Bearer ${accessToken}`,
|
|
6439
|
+
"Content-Type": "application/json"
|
|
6440
|
+
},
|
|
6441
|
+
body: JSON.stringify({
|
|
6442
|
+
auth_algo: authAlgo,
|
|
6443
|
+
cert_url: certUrl,
|
|
6444
|
+
transmission_id: transmissionId,
|
|
6445
|
+
transmission_sig: transmissionSig,
|
|
6446
|
+
transmission_time: transmissionTime,
|
|
6447
|
+
webhook_id: webhookId,
|
|
6448
|
+
webhook_event: body
|
|
6449
|
+
})
|
|
6450
|
+
}
|
|
6451
|
+
);
|
|
6452
|
+
if (!verifyResponse.ok) {
|
|
6453
|
+
throw new Error("Failed to verify PayPal webhook signature");
|
|
6454
|
+
}
|
|
6455
|
+
const verifyData = await verifyResponse.json();
|
|
6456
|
+
return {
|
|
6457
|
+
verified: verifyData.verification_status === "SUCCESS",
|
|
6458
|
+
verificationStatus: verifyData.verification_status
|
|
6459
|
+
};
|
|
6460
|
+
}
|
|
6461
|
+
return {
|
|
6462
|
+
addOrder,
|
|
6463
|
+
captureOrder,
|
|
6464
|
+
verifyWebhook
|
|
6465
|
+
};
|
|
6466
|
+
}
|
|
6467
|
+
|
|
6353
6468
|
// src/resources/organization/organization.service.ts
|
|
6354
6469
|
function useOrgService() {
|
|
6355
6470
|
const { add: addOrg } = useOrgRepo();
|
|
@@ -6360,6 +6475,7 @@ function useOrgService() {
|
|
|
6360
6475
|
const { getDefault } = usePlanRepo();
|
|
6361
6476
|
const { add: addSubscription } = useSubscriptionRepo();
|
|
6362
6477
|
const { add: addSubscriptionTransaction } = useSubscriptionTransactionRepo();
|
|
6478
|
+
const { addOrder: addPaypalOrder } = usePaypalService();
|
|
6363
6479
|
async function add(value) {
|
|
6364
6480
|
const { error } = schemaOrgAdd.validate(value);
|
|
6365
6481
|
if (error) {
|
|
@@ -6454,8 +6570,22 @@ function useOrgService() {
|
|
|
6454
6570
|
},
|
|
6455
6571
|
session
|
|
6456
6572
|
);
|
|
6573
|
+
const order = await addPaypalOrder({
|
|
6574
|
+
amount,
|
|
6575
|
+
currency: plan.currency,
|
|
6576
|
+
customId: subscriptionId,
|
|
6577
|
+
returnUrl: `${APP_ORG}/organizations/success`,
|
|
6578
|
+
cancelUrl: `${APP_ORG}/organizations/cancel`,
|
|
6579
|
+
action: "pay"
|
|
6580
|
+
});
|
|
6457
6581
|
await session?.commitTransaction();
|
|
6458
|
-
|
|
6582
|
+
const paypalOrderLink = JSON.parse(order.body.toString()).links.find(
|
|
6583
|
+
(link) => link.rel === "approve"
|
|
6584
|
+
);
|
|
6585
|
+
return {
|
|
6586
|
+
org: String(org),
|
|
6587
|
+
paypalOrderLink: paypalOrderLink ? paypalOrderLink.href : ""
|
|
6588
|
+
};
|
|
6459
6589
|
} catch (error2) {
|
|
6460
6590
|
await session?.abortTransaction();
|
|
6461
6591
|
throw error2;
|
|
@@ -6488,10 +6618,10 @@ function useOrgController() {
|
|
|
6488
6618
|
return;
|
|
6489
6619
|
}
|
|
6490
6620
|
try {
|
|
6491
|
-
const
|
|
6621
|
+
const data = await _add(value);
|
|
6492
6622
|
res.json({
|
|
6493
6623
|
message: "Organization created successfully.",
|
|
6494
|
-
data
|
|
6624
|
+
data
|
|
6495
6625
|
});
|
|
6496
6626
|
return;
|
|
6497
6627
|
} catch (error2) {
|
|
@@ -9709,9 +9839,14 @@ function useUtilController() {
|
|
|
9709
9839
|
}
|
|
9710
9840
|
}
|
|
9711
9841
|
}
|
|
9842
|
+
async function paypalWebhook(req, res, next) {
|
|
9843
|
+
console.log(req.body);
|
|
9844
|
+
return res.status(200).send("OK");
|
|
9845
|
+
}
|
|
9712
9846
|
return {
|
|
9713
9847
|
healthCheck,
|
|
9714
|
-
setGitHubVariables
|
|
9848
|
+
setGitHubVariables,
|
|
9849
|
+
paypalWebhook
|
|
9715
9850
|
};
|
|
9716
9851
|
}
|
|
9717
9852
|
|
|
@@ -9974,6 +10109,7 @@ function useVerificationController() {
|
|
|
9974
10109
|
ACCESS_TOKEN_SECRET,
|
|
9975
10110
|
APP_ACCOUNT,
|
|
9976
10111
|
APP_MAIN,
|
|
10112
|
+
APP_ORG,
|
|
9977
10113
|
DEFAULT_USER_EMAIL,
|
|
9978
10114
|
DEFAULT_USER_FIRST_NAME,
|
|
9979
10115
|
DEFAULT_USER_LAST_NAME,
|
|
@@ -9992,6 +10128,7 @@ function useVerificationController() {
|
|
|
9992
10128
|
PAYPAL_API_URL,
|
|
9993
10129
|
PAYPAL_CLIENT_ID,
|
|
9994
10130
|
PAYPAL_CLIENT_SECRET,
|
|
10131
|
+
PAYPAL_WEBHOOK_ID,
|
|
9995
10132
|
PORT,
|
|
9996
10133
|
REDIS_HOST,
|
|
9997
10134
|
REDIS_PASSWORD,
|