@orkow/common 0.0.5

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.
@@ -0,0 +1,12 @@
1
+ export {};
2
+ declare global {
3
+ interface Date {
4
+ addDays(days: number, useThis?: boolean): Date;
5
+ isToday(): boolean;
6
+ clone(): Date;
7
+ isAnotherMonth(date: Date): boolean;
8
+ isWeekend(): boolean;
9
+ isSameDate(date: Date): boolean;
10
+ }
11
+ }
12
+ //# sourceMappingURL=date.extensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.extensions.d.ts","sourceRoot":"","sources":["../src/date.extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA;AAET,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI;QACZ,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;QAC9C,OAAO,IAAI,OAAO,CAAA;QAClB,KAAK,IAAI,IAAI,CAAA;QACb,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAA;QACnC,SAAS,IAAI,OAAO,CAAA;QACpB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAA;KAEhC;CACF"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ Date.prototype.addDays = function (days) {
4
+ if (!days)
5
+ return this;
6
+ this.setDate(this.getDate() + days);
7
+ return this;
8
+ };
9
+ Date.prototype.isToday = function () {
10
+ const today = new Date();
11
+ return this.isSameDate(today);
12
+ };
13
+ Date.prototype.clone = function () {
14
+ return new Date(+this);
15
+ };
16
+ Date.prototype.isAnotherMonth = function (date) {
17
+ return date && this.getMonth() !== date.getMonth();
18
+ };
19
+ Date.prototype.isWeekend = function () {
20
+ return this.getDay() === 0 || this.getDay() === 6;
21
+ };
22
+ Date.prototype.isSameDate = function (date) {
23
+ return (date &&
24
+ this.getFullYear() === date.getFullYear() &&
25
+ this.getMonth() === date.getMonth() &&
26
+ this.getDate() === date.getDate());
27
+ };
@@ -0,0 +1,6 @@
1
+ export type SellPaymentStatusTitle = 'New' | 'Pending' | 'Paid' | 'Refunded' | 'Canceled' | 'Abandoned' | 'Overdue' | 'In Dispute' | 'Awaiting Gateway' | 'Failed Gateway';
2
+ export type SellStatusTitle = 'In process...' | 'Completed' | 'Cancelled' | 'Rejected';
3
+ export type BillingStatusTitle = 'New' | 'Pending' | 'Paid' | 'Refunded' | 'Canceled' | 'Abandoned' | 'Overdue' | 'In Dispute';
4
+ declare const getStatusDescription: (status: string) => "A bill is marked as 'New' when it is first added. A new bill can also be 'Awaiting Gateway', 'Failed Gateway', 'Overdue', and 'In Dispute'. A 'New' bill can move to these statuses: 'Pending', 'Paid', 'Canceled'" | "A bill is marked as 'Pending' when a user selects a manual payment method. The bill will continue to have a 'Pending' status until the payment is recorded by an administrator or an automatic payment method is selected. A 'Pending' bill can move to these statuses: 'Paid', 'Canceled'" | "A bill is marked as 'Paid' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Paid' bill can move to these statuses: 'Refunded', 'Canceled'" | "A bill is marked as 'Refunded' if a partial or full amount of the bill has been refunded to the account. A 'Refunded' bill can move to these statuses: 'Canceled'" | "Any bill can be canceled. If a bill is new or pending, this will stop any further action on the bill. Canceled bills can't be paid and won't become overdue. If a bill has already been paid, canceling the bill will default to issuing a full refund. If you need to retain a handling fee, you can manually edit the refund amount to reflect this. Refunds issued when cancelling a bill will automatically issue credits for any bills paid by credit card. Canceled bills remain canceled; they cannot move to another status or be uncanceled." | "A bill is marked as 'Overdue' if the bill due date has passed and the payment has not been recorded. Email notices can be scheduled to go out based on a bill's due date using the Schedule Overdue Notices." | "If there is a dispute about the bill, it can be marked as In Dispute by a billing administrator. Only unpaid bills can be marked as in dispute. This will prevent the account from receiving overdue notices by email until the dispute has been resolved." | "This status is assigned when an attempt to charge or credit a credit card is not immediately processed. Once the credit card transaction is complete, this status will be removed." | "When a credit card transaction fails, either to charge or to credit money to a credit card, the bill will show a status of 'Failed Gateway'. Credit card transactions can fail for many reasons, and can be retried most of the time." | "If a Pending payment is never completed it becomes Abandoned after a week." | "A shop is marked as 'Request' when it is first added. A 'Request' bill can move to these statuses: 'Waiting for verification'" | "A shop is marked as 'Waiting for verification' if an administrator accepts the request. A 'Waiting for verification' can move to these statuses: 'Verifying in process'" | "A shop is marked as 'Verifying in process' if an administrator accepts the request. A 'Verifying in process' can move to these statuses: 'Actively selling', 'Suspend'" | "A shop is marked as 'Actively selling' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Actively selling' can move to these statuses: 'Suspend', 'Reject'" | "If an administrator suspends; A 'Suspend' can move to these statuses: 'Actively selling', 'Reject'" | "If an administrator refuses; Reject remain reject; they cannot move to another status." | "An enroll is marked as 'Waiting' when it is first added. A 'Waiting' bill can move to these statuses: 'Active', 'Inactive'" | "An enroll or shop is marked as 'Active' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator." | "Marked as 'Inactive' if the due date has passed and the payment has not been recorded. Email notices can be scheduled to go out based on a due date using the Schedule Overdue Notices." | "An sell is marked as 'In process...' when it is first added. A 'In process...' sell can move to these statuses: 'Completed', 'Cancelled'" | "A sell is marked as 'Completed' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Completed' can move to these statuses: 'Cancelled'" | "Any sell can be Cancelled. If a sell is 'In process...', this will stop any further action on the bill. Cancelled sell can't be Completed and won't become rejected. Cancelled sell remain cancelled; they cannot move to another status or be uncancelled" | "A sell is marked 'Rejected' once when the sell is 'Completed'. If a sell has already been paid, rejecting the sell will default to issuing a full refund. Rejected sell can't be 'Completed' and won't become 'Cancelled'. Rejected sell remain rejected; they cannot move to another status." | "";
5
+ export default getStatusDescription;
6
+ //# sourceMappingURL=getStatusDescription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStatusDescription.d.ts","sourceRoot":"","sources":["../src/getStatusDescription.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAC9B,KAAK,GACL,SAAS,GACT,MAAM,GACN,UAAU,GACV,UAAU,GACV,WAAW,GACX,SAAS,GACT,YAAY,GACZ,kBAAkB,GAClB,gBAAgB,CAAA;AACpB,MAAM,MAAM,eAAe,GACvB,eAAe,GACf,WAAW,GACX,WAAW,GACX,UAAU,CAAA;AACd,MAAM,MAAM,kBAAkB,GAC1B,KAAK,GACL,SAAS,GACT,MAAM,GACN,UAAU,GACV,UAAU,GACV,WAAW,GACX,SAAS,GACT,YAAY,CAAA;AAEhB,QAAA,MAAM,oBAAoB,GAAI,QAAQ,MAAM,2pJA0D3C,CAAA;AAED,eAAe,oBAAoB,CAAA"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getStatusDescription = (status) => {
4
+ switch (status) {
5
+ case 'New':
6
+ return "A bill is marked as 'New' when it is first added. A new bill can also be 'Awaiting Gateway', 'Failed Gateway', 'Overdue', and 'In Dispute'. A 'New' bill can move to these statuses: 'Pending', 'Paid', 'Canceled'";
7
+ case 'Pending':
8
+ return "A bill is marked as 'Pending' when a user selects a manual payment method. The bill will continue to have a 'Pending' status until the payment is recorded by an administrator or an automatic payment method is selected. A 'Pending' bill can move to these statuses: 'Paid', 'Canceled'";
9
+ case 'Paid':
10
+ return "A bill is marked as 'Paid' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Paid' bill can move to these statuses: 'Refunded', 'Canceled'";
11
+ case 'Refunded':
12
+ return "A bill is marked as 'Refunded' if a partial or full amount of the bill has been refunded to the account. A 'Refunded' bill can move to these statuses: 'Canceled'";
13
+ case 'Canceled':
14
+ return "Any bill can be canceled. If a bill is new or pending, this will stop any further action on the bill. Canceled bills can't be paid and won't become overdue. If a bill has already been paid, canceling the bill will default to issuing a full refund. If you need to retain a handling fee, you can manually edit the refund amount to reflect this. Refunds issued when cancelling a bill will automatically issue credits for any bills paid by credit card. Canceled bills remain canceled; they cannot move to another status or be uncanceled.";
15
+ case 'Overdue':
16
+ return "A bill is marked as 'Overdue' if the bill due date has passed and the payment has not been recorded. Email notices can be scheduled to go out based on a bill's due date using the Schedule Overdue Notices.";
17
+ case 'In Dispute':
18
+ return 'If there is a dispute about the bill, it can be marked as In Dispute by a billing administrator. Only unpaid bills can be marked as in dispute. This will prevent the account from receiving overdue notices by email until the dispute has been resolved.';
19
+ case 'Awaiting Gateway':
20
+ return 'This status is assigned when an attempt to charge or credit a credit card is not immediately processed. Once the credit card transaction is complete, this status will be removed.';
21
+ case 'Failed Gateway':
22
+ return "When a credit card transaction fails, either to charge or to credit money to a credit card, the bill will show a status of 'Failed Gateway'. Credit card transactions can fail for many reasons, and can be retried most of the time.";
23
+ case 'Abandoned':
24
+ return 'If a Pending payment is never completed it becomes Abandoned after a week.';
25
+ // FOR SHOP
26
+ case 'Request':
27
+ return "A shop is marked as 'Request' when it is first added. A 'Request' bill can move to these statuses: 'Waiting for verification'";
28
+ case 'Waiting for verification':
29
+ return "A shop is marked as 'Waiting for verification' if an administrator accepts the request. A 'Waiting for verification' can move to these statuses: 'Verifying in process'";
30
+ case 'Verifying in process':
31
+ return "A shop is marked as 'Verifying in process' if an administrator accepts the request. A 'Verifying in process' can move to these statuses: 'Actively selling', 'Suspend'";
32
+ case 'Actively selling':
33
+ return "A shop is marked as 'Actively selling' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Actively selling' can move to these statuses: 'Suspend', 'Reject'";
34
+ case 'Suspend':
35
+ return "If an administrator suspends; A 'Suspend' can move to these statuses: 'Actively selling', 'Reject'";
36
+ case 'Reject':
37
+ return 'If an administrator refuses; Reject remain reject; they cannot move to another status.';
38
+ // FOR ENROLL
39
+ case 'Waiting':
40
+ return "An enroll is marked as 'Waiting' when it is first added. A 'Waiting' bill can move to these statuses: 'Active', 'Inactive'";
41
+ case 'Active':
42
+ return "An enroll or shop is marked as 'Active' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator.";
43
+ case 'Inactive':
44
+ return "Marked as 'Inactive' if the due date has passed and the payment has not been recorded. Email notices can be scheduled to go out based on a due date using the Schedule Overdue Notices.";
45
+ // FOR SELL
46
+ case 'In process...':
47
+ return "An sell is marked as 'In process...' when it is first added. A 'In process...' sell can move to these statuses: 'Completed', 'Cancelled'";
48
+ case 'Completed':
49
+ return "A sell is marked as 'Completed' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Completed' can move to these statuses: 'Cancelled'";
50
+ case 'Cancelled':
51
+ return "Any sell can be Cancelled. If a sell is 'In process...', this will stop any further action on the bill. Cancelled sell can't be Completed and won't become rejected. Cancelled sell remain cancelled; they cannot move to another status or be uncancelled";
52
+ case 'Rejected':
53
+ return "A sell is marked 'Rejected' once when the sell is 'Completed'. If a sell has already been paid, rejecting the sell will default to issuing a full refund. Rejected sell can't be 'Completed' and won't become 'Cancelled'. Rejected sell remain rejected; they cannot move to another status.";
54
+ default:
55
+ return '';
56
+ }
57
+ };
58
+ exports.default = getStatusDescription;
59
+ // STATUS_TEXT DESCRIPTION
60
+ // // FOR BILLING AND BILLING PAYMENT
61
+ // New: A bill is marked as 'New' when it is first added. A new bill can also be 'Awaiting Gateway', 'Failed Gateway', 'Overdue', and 'In Dispute'. A 'New' bill can move to these statuses: 'Pending', 'Paid', 'Canceled'
62
+ // Pending: A bill is marked as 'Pending' when a user selects a manual payment method. The bill will continue to have a 'Pending' status until the payment is recorded by an administrator or an automatic payment method is selected. A 'Pending' bill can move to these statuses: 'Paid', 'Canceled'
63
+ // Paid: A bill is marked as 'Paid' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Paid' bill can move to these statuses: 'Refunded', 'Canceled'
64
+ // Refunded: A bill is marked as 'Refunded' if a partial or full amount of the bill has been refunded to the account. A 'Refunded' bill can move to these statuses: 'Canceled'
65
+ // Canceled: Any bill can be canceled. If a bill is new or pending, this will stop any further action on the bill. Canceled bills can't be paid and won't become overdue. If a bill has already been paid, canceling the bill will default to issuing a full refund. If you need to retain a handling fee, you can manually edit the refund amount to reflect this. Refunds issued when cancelling a bill will automatically issue credits for any bills paid by credit card. Canceled bills remain canceled; they cannot move to another status or be uncanceled.
66
+ // Overdue: A bill is marked as 'Overdue' if the bill due date has passed and the payment has not been recorded. Email notices can be scheduled to go out based on a bill's due date using the Schedule Overdue Notices.
67
+ // In Dispute: If there is a dispute about the bill, it can be marked as In Dispute by a billing administrator. Only unpaid bills can be marked as in dispute. This will prevent the account from receiving overdue notices by email until the dispute has been resolved.
68
+ // Awaiting Gateway: This status is assigned when an attempt to charge or credit a credit card is not immediately processed. Once the credit card transaction is complete, this status will be removed.
69
+ // Failed Gateway: When a credit card transaction fails, either to charge or to credit money to a credit card, the bill will show a status of 'Failed Gateway'. Credit card transactions can fail for many reasons, and can be retried most of the time.
70
+ // Abandoned: If a Pending payment is never completed it becomes Abandoned after a week.
71
+ // Important link: https://www.oasis-open.org/khelp/billing/user_help/html/billing_lifecycle.html
72
+ // // FOR SHOP
73
+ // Request: A shop is marked as 'Request' when it is first added. A 'Request' bill can move to these statuses: 'Waiting for verification'
74
+ // Waiting for verification: A shop is marked as 'Waiting for verification' if an administrator accepts the request. A 'Waiting for verification' can move to these statuses: 'Verifying in process'
75
+ // Verifying in process: A shop is marked as 'Verifying in process' if an administrator accepts the request. A 'Verifying in process' can move to these statuses: 'Actively selling', 'Suspend'
76
+ // Actively selling: A shop is marked as 'Actively selling' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Actively selling' can move to these statuses: 'Suspend', 'Reject'
77
+ // Suspend: If an administrator suspends; A 'Suspend' can move to these statuses: 'Actively selling', 'Reject'
78
+ // Reject: If an administrator refuses; Reject remain reject; they cannot move to another status.
79
+ // // FOR ENROLL
80
+ // Waiting: An enroll is marked as 'Waiting' when it is first added. A 'Waiting' bill can move to these statuses: 'Active', 'Inactive'
81
+ // Active: An enroll or shop is marked as 'Active' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator.
82
+ // Inactive: Marked as 'Inactive' if the due date has passed and the payment has not been recorded. Email notices can be scheduled to go out based on a due date using the Schedule Overdue Notices.
83
+ // FOR SELL
84
+ // 'In process...': An sell is marked as 'In process...' when it is first added. A 'In process...' sell can move to these statuses: 'Completed', 'Cancelled'
85
+ // Completed: A sell is marked as 'Completed' once payment is received, either automatically at the successful completion of a credit card transaction or manually by a billing administrator. A 'Completed' can move to these statuses: 'Cancelled'
86
+ // Cancelled: Any sell can be Cancelled. If a sell is 'In process...', this will stop any further action on the bill. Cancelled sell can't be Completed and won't become rejected. Cancelled sell remain cancelled; they cannot move to another status or be uncancelled.
87
+ // Rejected: A sell is marked 'Rejected' once when the sell is 'Completed'. If a sell has already been paid, rejecting the sell will default to issuing a full refund. Rejected sell can't be 'Completed' and won't become 'Cancelled'. Rejected sell remain rejected; they cannot move to another status.
@@ -0,0 +1,7 @@
1
+ export * from './utils/generateToken';
2
+ export * from './utils/getRequestId';
3
+ export * from './utils/getUserId';
4
+ export * from './utils/getUserType';
5
+ export * from './utils/hashPassword';
6
+ export declare const log: (str: any) => void;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AAEpC,eAAO,MAAM,GAAG,GAAI,KAAK,GAAG,SAE3B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.log = void 0;
18
+ __exportStar(require("./utils/generateToken"), exports);
19
+ __exportStar(require("./utils/getRequestId"), exports);
20
+ __exportStar(require("./utils/getUserId"), exports);
21
+ __exportStar(require("./utils/getUserType"), exports);
22
+ __exportStar(require("./utils/hashPassword"), exports);
23
+ const log = (str) => {
24
+ console.log('O logger: ' + str);
25
+ };
26
+ exports.log = log;
@@ -0,0 +1,6 @@
1
+ export type TemplateUserParams = {
2
+ imageUrl: string;
3
+ fullname: string;
4
+ };
5
+ export default function notificationTemplate(user: TemplateUserParams, type: string): string;
6
+ //# sourceMappingURL=notificationTemplate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notificationTemplate.d.ts","sourceRoot":"","sources":["../src/notificationTemplate.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAI,EAAE,kBAAkB,EACxB,IAAI,EAAE,MAAM,UAYb"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = notificationTemplate;
4
+ function notificationTemplate(user, type) {
5
+ const text = getText(type);
6
+ return `<span class="flex-shrink-0 inline-block relative">
7
+ <img class="h-10 w-10 rounded-full" src=${user.imageUrl} alt="" />
8
+ <span class="absolute top-0 right-0 block h-2.5 w-2.5 rounded-full" aria-hidden="true"></span>
9
+ </span>
10
+ <div class="ml-4 truncate">
11
+ <p class="text-sm w-46 sm:w-60.5 font-medium text-gray-900 truncate">${user.fullname}</p>
12
+ <p class="text-sm line-clamp-2 text-gray-500 whitespace-pre-line">${text}</p>
13
+ </div>`;
14
+ }
15
+ function getText(type) {
16
+ switch (type) {
17
+ case 'newBusiness':
18
+ return 'has started a business.';
19
+ case 'updateBusiness':
20
+ return 'has updated the profile information.';
21
+ case 'newBilling':
22
+ return 'A bill has been generated for you.';
23
+ case 'updateBilling':
24
+ return 'Billing status has been updated.';
25
+ case 'newAgent':
26
+ return 'has become an agent.';
27
+ case 'updateAgent':
28
+ return 'has updated the profile information.';
29
+ case 'newUser':
30
+ return 'has become a user.';
31
+ case 'newShop':
32
+ return 'has create a shop.';
33
+ case 'verifying_in_process':
34
+ return 'your shop verifying process undergoing.';
35
+ case 'verified':
36
+ return 'your shop is ready for selling goods.';
37
+ case 'active':
38
+ return 'your shop has been activated.';
39
+ case 'inactive':
40
+ return 'your shop has been deactivated.';
41
+ case 'newEnroll':
42
+ return 'has enrolled.';
43
+ case 'updateEnroll':
44
+ return 'has updated an enroll.';
45
+ case 'newOrder':
46
+ return 'has placed an order.';
47
+ case 'newSell':
48
+ return 'has placed a sell order';
49
+ case 'newPurchase':
50
+ return 'has purchased';
51
+ case 'statusChange':
52
+ return 'status updated.';
53
+ case 'newReview':
54
+ return 'has reviewed on your product.';
55
+ default:
56
+ return 'status updated.';
57
+ }
58
+ }
@@ -0,0 +1,8 @@
1
+ export {};
2
+ declare global {
3
+ interface String {
4
+ toCamelCase(): string;
5
+ toCapitalizeFirst(): string;
6
+ }
7
+ }
8
+ //# sourceMappingURL=string.extensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.extensions.d.ts","sourceRoot":"","sources":["../src/string.extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA;AAET,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,WAAW,IAAI,MAAM,CAAA;QACrB,iBAAiB,IAAI,MAAM,CAAA;KAC5B;CACF"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ String.prototype.toCamelCase = function () {
4
+ return this.replace(/(?:^\w|[A-Z]|-|\b\w)/g, (ltr, idx) => idx === 0 ? ltr.toLowerCase() : ltr.toUpperCase()).replace(/\s+|-/g, '');
5
+ };
6
+ String.prototype.toCapitalizeFirst = function () {
7
+ return this.charAt(0).toUpperCase() + this.slice(1);
8
+ };
@@ -0,0 +1,2 @@
1
+ export declare const generateToken: (userId: string, userType: string) => string;
2
+ //# sourceMappingURL=generateToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../../src/utils/generateToken.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,EAAE,UAAU,MAAM,WAI7D,CAAA"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateToken = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const generateToken = (userId, userType) => {
9
+ return jsonwebtoken_1.default.sign({ userId, userType }, process.env.JWT_SECRET || '', {
10
+ expiresIn: '30 days',
11
+ });
12
+ };
13
+ exports.generateToken = generateToken;
@@ -0,0 +1,2 @@
1
+ export declare const getRequestId: (request: any, requireAuth?: boolean) => string | null;
2
+ //# sourceMappingURL=getRequestId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRequestId.d.ts","sourceRoot":"","sources":["../../src/utils/getRequestId.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,GAAI,SAAS,GAAG,EAAE,qBAAkB,kBAmB5D,CAAA"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRequestId = void 0;
7
+ const graphql_1 = require("graphql");
8
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
+ const getRequestId = (request, requireAuth = true) => {
10
+ const header = request?.headers.get('x-authorization');
11
+ if (header) {
12
+ try {
13
+ const token = header.replace('Bearer ', '');
14
+ const decoded = jsonwebtoken_1.default.verify(token, process.env.SUBGRAPH_ACCESS_TOKEN_SECRET || '');
15
+ // @ts-expect-error -> The user ID will exist in the header
16
+ return decoded.requestId;
17
+ }
18
+ catch (error) {
19
+ throw new graphql_1.GraphQLError('Unable to verify request');
20
+ }
21
+ }
22
+ if (requireAuth)
23
+ throw new graphql_1.GraphQLError('X-Authentication required');
24
+ return null;
25
+ };
26
+ exports.getRequestId = getRequestId;
@@ -0,0 +1,2 @@
1
+ export declare const getUserId: (request: any, requireAuth?: boolean) => string | null;
2
+ //# sourceMappingURL=getUserId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUserId.d.ts","sourceRoot":"","sources":["../../src/utils/getUserId.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,GAAI,SAAS,GAAG,EAAE,qBAAkB,kBAYzD,CAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getUserId = void 0;
7
+ const graphql_1 = require("graphql");
8
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
+ // const header = request.request ? request.request.headers.authorization : request.connection.context.headers?.Authorization ? request.connection.context.headers.Authorization : request.connection.context.Authorization
10
+ const getUserId = (request, requireAuth = true) => {
11
+ const header = request?.headers.get('authorization');
12
+ if (header) {
13
+ const token = header.replace('Bearer ', '');
14
+ const decoded = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET || '');
15
+ // @ts-expect-error -> The user ID will exist in the header
16
+ return decoded.userId;
17
+ }
18
+ if (requireAuth)
19
+ throw new graphql_1.GraphQLError('Authentication required');
20
+ return null;
21
+ };
22
+ exports.getUserId = getUserId;
@@ -0,0 +1,2 @@
1
+ export declare const getUserType: (request: any, requireAuth?: boolean) => string | null;
2
+ //# sourceMappingURL=getUserType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUserType.d.ts","sourceRoot":"","sources":["../../src/utils/getUserType.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW,GAAI,SAAS,GAAG,EAAE,qBAAkB,kBAY3D,CAAA"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getUserType = void 0;
7
+ const graphql_1 = require("graphql");
8
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
+ // const header = request.request ? request.request.headers.authorization : request.connection.context.headers?.Authorization ? request.connection.context.headers.Authorization : request.connection.context.Authorization
10
+ const getUserType = (request, requireAuth = true) => {
11
+ const header = request?.headers.get('authorization');
12
+ if (header) {
13
+ const token = header.replace('Bearer ', '');
14
+ const decoded = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET || '');
15
+ // @ts-expect-error -> The user ID will exist in the header
16
+ return decoded.userType;
17
+ }
18
+ if (requireAuth)
19
+ throw new graphql_1.GraphQLError('Authentication required');
20
+ return null;
21
+ };
22
+ exports.getUserType = getUserType;
@@ -0,0 +1,2 @@
1
+ export declare const hashPassword: (password: string) => Promise<string>;
2
+ //# sourceMappingURL=hashPassword.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashPassword.d.ts","sourceRoot":"","sources":["../../src/utils/hashPassword.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,oBAK5C,CAAA"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.hashPassword = void 0;
7
+ const graphql_1 = require("graphql");
8
+ const bcryptjs_1 = __importDefault(require("bcryptjs"));
9
+ const hashPassword = (password) => {
10
+ if (password.length < 8) {
11
+ throw new graphql_1.GraphQLError('Password must be 8 characters or longer.');
12
+ }
13
+ return bcryptjs_1.default.hash(password, 10);
14
+ };
15
+ exports.hashPassword = hashPassword;
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@orkow/common",
3
+ "version": "0.0.5",
4
+ "description": "Common utils.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "license": "ISC",
8
+ "files": [
9
+ "dist/**"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./date-extensions": "./src/date.extensions.ts",
17
+ "./string-extensions": "./src/string.extensions.ts",
18
+ "./get-status-description": "./src/getStatusDescription.ts",
19
+ "./notification-template": "./src/notificationTemplate.ts"
20
+ },
21
+ "keywords": [],
22
+ "author": "ConCat7 Sky Limited, <ikramhasib007@gmail.com> (https://github.com/ikramhasib007)",
23
+ "scripts": {
24
+ "dev": "tsc -w",
25
+ "clean": "del-cli ./dist/*",
26
+ "build": "pnpm run clean && tsc",
27
+ "lint": "eslint --max-warnings 0",
28
+ "pub": "git add . && git commit -m \"Updates\" && git push origin main && npm version patch && npm run build && npm publish"
29
+ },
30
+ "dependencies": {
31
+ "bcryptjs": "^3.0.3",
32
+ "graphql": "^16.12.0",
33
+ "jsonwebtoken": "^9.0.3"
34
+ },
35
+ "devDependencies": {
36
+ "@repo/eslint-config": "workspace:*",
37
+ "@repo/typescript-config": "workspace:*",
38
+ "@types/jsonwebtoken": "^9.0.10",
39
+ "@types/node": "^24.10.2",
40
+ "del-cli": "^7.0.0",
41
+ "eslint": "^9.39.1",
42
+ "typescript": "~5.9.3"
43
+ },
44
+ "overrides": {
45
+ "eslint": "^9.39.1"
46
+ },
47
+ "volta": {
48
+ "node": "24.11.1",
49
+ "pnpm": "10.25.0"
50
+ }
51
+ }