@goweekdays/core 0.0.11 → 0.0.13

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @goweekdays/core
2
2
 
3
+ ## 0.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - fe5105d: fix promo code listing
8
+
9
+ ## 0.0.12
10
+
11
+ ### Patch Changes
12
+
13
+ - de8f568: Add promo code
14
+
3
15
  ## 0.0.11
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { ObjectId, ClientSession } from 'mongodb';
3
3
  import * as bson from 'bson';
4
4
  import { Request, Response, NextFunction } from 'express';
5
5
  import { paginate } from '@goweekdays/utils';
6
+ import Joi from 'joi';
6
7
 
7
8
  type TVerificationMetadata = {
8
9
  name?: string;
@@ -821,8 +822,19 @@ type TSubscription = {
821
822
  _id?: ObjectId;
822
823
  user?: ObjectId | string;
823
824
  org?: ObjectId | string;
824
- subscriptionId: string;
825
+ customerId: string;
826
+ paymentMethodId: string;
827
+ amount: number;
828
+ description?: string;
829
+ currency: string;
830
+ promoCode?: string;
831
+ type: string;
832
+ seats?: number;
825
833
  status?: string;
834
+ billingCycle: "monthly" | "yearly";
835
+ nextBillingDate?: string;
836
+ lastPaymentStatus?: string;
837
+ failedAttempts?: number;
826
838
  createdAt?: string;
827
839
  updatedAt?: string;
828
840
  deletedAt?: string;
@@ -848,6 +860,16 @@ declare function useSubscriptionRepo(): {
848
860
  pageRange: string;
849
861
  }>;
850
862
  updateStatus: (_id: string | ObjectId, status: string) => Promise<string>;
863
+ getByOrgId: (org: string | ObjectId) => Promise<TSubscription | null>;
864
+ getByAffiliateUserId: (user: string | ObjectId) => Promise<TSubscription | null>;
865
+ getDueSubscriptions: (BATCH_SIZE?: number) => Promise<TSubscription[]>;
866
+ getFailedSubscriptions: (BATCH_SIZE?: number, maxAttempts?: number) => Promise<TSubscription[]>;
867
+ processSuccessfulPayment: (value: Pick<TSubscription, "_id" | "nextBillingDate">, session?: ClientSession) => Promise<string>;
868
+ markSubscriptionAsFailed: ({ _id, failed }?: {
869
+ _id: string | ObjectId;
870
+ failed?: boolean | undefined;
871
+ }, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
872
+ markSubscriptionAsCanceled: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
851
873
  };
852
874
 
853
875
  type TOrg = {
@@ -881,27 +903,54 @@ type TAddress = {
881
903
  declare function MAddress(value: any): TAddress;
882
904
 
883
905
  declare function useSubscriptionService(): {
884
- getByUserId: (id: string) => Promise<TSubscription>;
906
+ getByUserId: (id: string) => Promise<any>;
885
907
  getStatusByUser: (user: string) => Promise<string>;
886
- createAffiliateSubscription: ({ user, amount, payment_method_id, customer_id, }?: {
887
- user?: string | undefined;
888
- amount?: number | undefined;
889
- payment_method_id?: string | undefined;
890
- customer_id?: string | undefined;
908
+ createAffiliateSubscription: (value: {
909
+ user: string;
910
+ amount: number;
911
+ currency: string;
912
+ payment_method_id: string;
913
+ payment_method_number: string;
914
+ payment_method_expiry_month?: string | undefined;
915
+ payment_method_expiry_year?: string | undefined;
916
+ payment_method_cvv?: string | undefined;
917
+ payment_method_cardholder_name?: string | undefined;
918
+ payment_method_channel: string;
919
+ payment_method_type: string;
920
+ customer_id: string;
921
+ billingAddress: TAddress;
891
922
  }) => Promise<string>;
892
923
  createOrgSubscription: (value: {
893
924
  user: string;
894
925
  amount: number;
926
+ currency: string;
895
927
  payment_method_id: string;
928
+ payment_method_number: string;
929
+ payment_method_expiry_month?: string | undefined;
930
+ payment_method_expiry_year?: string | undefined;
931
+ payment_method_cvv?: string | undefined;
932
+ payment_method_cardholder_name?: string | undefined;
933
+ payment_method_channel: string;
934
+ payment_method_type: string;
896
935
  customer_id: string;
897
936
  organization: TOrg;
898
937
  billingAddress: TAddress;
899
- }) => Promise<string>;
938
+ seats: number;
939
+ }) => Promise<{
940
+ message: string;
941
+ data: {
942
+ org: string;
943
+ };
944
+ }>;
945
+ processSubscriptions: (batchSize?: number) => Promise<void>;
946
+ retryFailedPayments: (batchSize?: number) => Promise<void>;
900
947
  };
901
948
 
902
949
  declare function useSubscriptionController(): {
903
950
  add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
904
951
  getByUserId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
952
+ getByOrgId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
953
+ getByAffiliateUserId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
905
954
  getSubscriptions: (req: Request, res: Response, next: NextFunction) => Promise<void>;
906
955
  getSubscriptionStatus: (req: Request, res: Response, next: NextFunction) => Promise<void>;
907
956
  createAffiliateSubscription: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -931,13 +980,14 @@ declare function useXenditService(): {
931
980
  success_return_url?: string | undefined;
932
981
  failure_return_url?: string | undefined;
933
982
  }) => Promise<any>;
934
- initSubscription: ({ customer, currency, amount, paymentMethod, description, interval, }?: {
983
+ initSubscription: ({ customer, currency, amount, paymentMethod, description, interval, seats, }?: {
935
984
  customer?: string | undefined;
936
985
  currency?: string | undefined;
937
986
  amount?: number | undefined;
938
987
  paymentMethod?: string | undefined;
939
988
  description?: string | undefined;
940
989
  interval?: string | undefined;
990
+ seats?: number | undefined;
941
991
  }) => Promise<any>;
942
992
  linkPaymentMethodCard: ({ success_return_url, failure_return_url, card_number, expiry_month, expiry_year, cvv, cardholder_name, currency, }?: {
943
993
  success_return_url?: string | undefined;
@@ -958,6 +1008,16 @@ declare function useXenditService(): {
958
1008
  }) => Promise<any>;
959
1009
  checkSubscriptionStatus: (subscriptionId: string) => Promise<string>;
960
1010
  cancelSubscription: (subscriptionId: string) => Promise<string>;
1011
+ getSubscription: (id: string) => Promise<any>;
1012
+ getSubscriptionCycles: (id: string) => Promise<any>;
1013
+ pay: (value: {
1014
+ amount: number;
1015
+ currency: string;
1016
+ payment_method_id: string;
1017
+ customer_id: string;
1018
+ description?: string;
1019
+ metadata?: Record<string, any>;
1020
+ }) => Promise<any>;
961
1021
  };
962
1022
 
963
1023
  type TPaymentMethod = {
@@ -968,7 +1028,8 @@ type TPaymentMethod = {
968
1028
  description?: string;
969
1029
  type: string;
970
1030
  number: string;
971
- expiry?: string;
1031
+ month_expiry?: string;
1032
+ year_expiry?: string;
972
1033
  cvv?: string;
973
1034
  paymentId: string;
974
1035
  customerId?: string;
@@ -1120,6 +1181,99 @@ declare function useMemberRepo(): {
1120
1181
  updateName: (value: Pick<TMember, "name" | "user">, session?: ClientSession) => Promise<string>;
1121
1182
  };
1122
1183
 
1184
+ declare const schema: Joi.ObjectSchema<any>;
1185
+
1186
+ type TPromoType = "tiered" | "fixed";
1187
+ type TPromoTier = {
1188
+ min: number;
1189
+ max: number;
1190
+ price: number;
1191
+ };
1192
+ type TPromoCode = {
1193
+ _id?: ObjectId;
1194
+ code: string;
1195
+ description?: string;
1196
+ type: TPromoType;
1197
+ tiers?: TPromoTier[];
1198
+ fixed_rate?: number;
1199
+ appliesTo?: string;
1200
+ createdAt?: string;
1201
+ expiresAt?: string;
1202
+ assignedTo?: string | ObjectId;
1203
+ status?: "active" | "expired" | "disabled";
1204
+ };
1205
+ declare function MPromoCode(data: TPromoCode): TPromoCode;
1206
+
1207
+ declare function usePromoCodeRepo(): {
1208
+ createIndex: () => Promise<void>;
1209
+ createUniqueIndex: () => Promise<void>;
1210
+ add: (value: TPromoCode) => Promise<void>;
1211
+ getByCode: (code: string) => Promise<mongodb.WithId<bson.Document> | null>;
1212
+ getPromoCodes: ({ search, page, limit, sort, status, type, }?: {
1213
+ search?: string | undefined;
1214
+ page?: number | undefined;
1215
+ limit?: number | undefined;
1216
+ sort?: {} | undefined;
1217
+ status?: string | undefined;
1218
+ type?: string | undefined;
1219
+ }) => Promise<{
1220
+ items: any[];
1221
+ pages: number;
1222
+ pageRange: string;
1223
+ }>;
1224
+ };
1225
+
1226
+ declare function usePromoCodeController(): {
1227
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1228
+ getByCode: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1229
+ getPromoCodes: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1230
+ };
1231
+
1232
+ type TOrderMetadata = {
1233
+ subscriptionId?: ObjectId | string;
1234
+ cycle?: number;
1235
+ seats?: number;
1236
+ promoCode?: string;
1237
+ };
1238
+ type TOrder = {
1239
+ _id?: ObjectId;
1240
+ payment?: string;
1241
+ user?: ObjectId | string;
1242
+ org?: ObjectId | string;
1243
+ type: string;
1244
+ amount: number;
1245
+ currency: string;
1246
+ description?: string;
1247
+ metadata?: TOrderMetadata;
1248
+ status?: string;
1249
+ createdAt?: string;
1250
+ updatedAt?: string;
1251
+ deletedAt?: string;
1252
+ };
1253
+ declare function MOrder(value: TOrder): TOrder;
1254
+
1255
+ declare function useOrderRepo(): {
1256
+ createIndex: () => void;
1257
+ add: (value: TOrder, session?: ClientSession) => void;
1258
+ getOrders: ({ search, page, limit, sort, status, type, id, }?: {
1259
+ search?: string | undefined;
1260
+ page?: number | undefined;
1261
+ limit?: number | undefined;
1262
+ sort?: {} | undefined;
1263
+ status?: string | undefined;
1264
+ type?: string | undefined;
1265
+ id?: string | undefined;
1266
+ }) => Promise<{
1267
+ items: any[];
1268
+ pages: number;
1269
+ pageRange: string;
1270
+ }>;
1271
+ };
1272
+
1273
+ declare function useOrderController(): {
1274
+ getOrders: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1275
+ };
1276
+
1123
1277
  declare const MONGO_URI: string;
1124
1278
  declare const MONGO_DB: string;
1125
1279
  declare const PORT: number;
@@ -1156,4 +1310,4 @@ declare const PAYPAL_API_URL: string;
1156
1310
  declare const XENDIT_SECRET_KEY: string;
1157
1311
  declare const XENDIT_BASE_URL: string;
1158
1312
 
1159
- 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, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MCapBldgAct, MComment, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MPaymentMethod, MRole, MSubscription, MToken, MUser, MUserRole, MVerification, MWorkflow, 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, TAddress, TAttachment, TCapBldgAct, TCapBldgActAssmtCriteria, TCapBldgActBasicInfo, TCapBldgActInitRevEval, TComment, TEntity, TFile, TMember, TMiniRole, TOrg, TPaymentMethod, TRole, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, TWorkflow, TWorkflowStep, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, isDev, useAddressController, useAddressRepo, useAuthController, useAuthService, useCapBldgActController, useCapBldgActRepo, useCapBldgActService, useCommentController, useCommentRepo, useCommentService, useEntityController, useEntityRepo, useEntityService, useFileController, useFileRepo, useFileService, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useVerificationController, useVerificationRepo, useVerificationService, useWorkflowController, useWorkflowRepo, useWorkflowService, useXenditService };
1313
+ 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, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MCapBldgAct, MComment, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrder, MOrg, MPaymentMethod, MPromoCode, MRole, MSubscription, MToken, MUser, MUserRole, MVerification, MWorkflow, 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, TAddress, TAttachment, TCapBldgAct, TCapBldgActAssmtCriteria, TCapBldgActBasicInfo, TCapBldgActInitRevEval, TComment, TEntity, TFile, TMember, TMiniRole, TOrder, TOrderMetadata, TOrg, TPaymentMethod, TPromoCode, TPromoTier, TRole, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, TWorkflow, TWorkflowStep, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, isDev, schema, useAddressController, useAddressRepo, useAuthController, useAuthService, useCapBldgActController, useCapBldgActRepo, useCapBldgActService, useCommentController, useCommentRepo, useCommentService, useEntityController, useEntityRepo, useEntityService, useFileController, useFileRepo, useFileService, useMemberRepo, useOrderController, useOrderRepo, useOrgController, useOrgRepo, useOrgService, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, usePromoCodeController, usePromoCodeRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useVerificationController, useVerificationRepo, useVerificationService, useWorkflowController, useWorkflowRepo, useWorkflowService, useXenditService };