@hobenakicoffee/libraries 0.0.12 → 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/README.md +65 -24
- package/package.json +1 -1
- package/src/constants/payment.test.ts +74 -3
- package/src/constants/payment.ts +26 -0
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# @hobenakicoffee/libraries
|
|
2
2
|
|
|
3
|
-
Framework-agnostic shared
|
|
3
|
+
Framework-agnostic shared constants and utilities for “হবে নাকি Coffee?” projects.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
Install the package from npm:
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npm install @hobenakicoffee/libraries
|
|
@@ -16,12 +14,43 @@ yarn add @hobenakicoffee/libraries
|
|
|
16
14
|
bun add @hobenakicoffee/libraries
|
|
17
15
|
```
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
This package exposes three entry points:
|
|
20
|
+
|
|
21
|
+
- `@hobenakicoffee/libraries` (re-exports constants)
|
|
22
|
+
- `@hobenakicoffee/libraries/constants`
|
|
23
|
+
- `@hobenakicoffee/libraries/utils`
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
20
26
|
|
|
21
27
|
```ts
|
|
22
|
-
import {
|
|
28
|
+
import { PaymentStatuses, ServiceTypes } from "@hobenakicoffee/libraries";
|
|
29
|
+
|
|
30
|
+
import { SupporterPlatforms } from "@hobenakicoffee/libraries/constants";
|
|
31
|
+
|
|
32
|
+
import {
|
|
33
|
+
formatAmount,
|
|
34
|
+
formatDate,
|
|
35
|
+
getUserPageLink,
|
|
36
|
+
} from "@hobenakicoffee/libraries/utils";
|
|
23
37
|
```
|
|
24
38
|
|
|
39
|
+
## API at a glance
|
|
40
|
+
|
|
41
|
+
### Constants and types
|
|
42
|
+
|
|
43
|
+
| Entrypoint | Runtime exports | Type exports |
|
|
44
|
+
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
|
45
|
+
| `@hobenakicoffee/libraries` | Re-exports all constants from `@hobenakicoffee/libraries/constants` | Re-exports all types from `@hobenakicoffee/libraries/constants` |
|
|
46
|
+
| `@hobenakicoffee/libraries/constants` | `Visibility`, `productInfo`, `companyInfo`, `PaymentTypes`, `PaymentStatuses`, `PaymentProviders`, `PaymentDirections`, `SupporterPlatforms`, `ServiceTypes` | `Visibility`, `PaymentType`, `PaymentStatus`, `PaymentProvider`, `PaymentDirection`, `SupporterPlatform`, `ServiceType` |
|
|
47
|
+
|
|
48
|
+
### Utilities
|
|
49
|
+
|
|
50
|
+
| Entrypoint | Function exports |
|
|
51
|
+
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `@hobenakicoffee/libraries/utils` | `formatAmount`, `formatSignedAmount`, `formatDate`, `formatToPlainText`, `formatMetadataKey`, `getSocialUrl`, `getUserPageLink`, `openInNewWindow`, `shareToFacebook`, `shareToInstagram`, `shareToLinkedIn`, `shareToX`, `printQrSvg` |
|
|
53
|
+
|
|
25
54
|
## Local development
|
|
26
55
|
|
|
27
56
|
Install dependencies:
|
|
@@ -30,27 +59,26 @@ Install dependencies:
|
|
|
30
59
|
bun install
|
|
31
60
|
```
|
|
32
61
|
|
|
33
|
-
|
|
62
|
+
Available scripts:
|
|
34
63
|
|
|
35
64
|
```bash
|
|
65
|
+
# Build the library
|
|
66
|
+
bun run build
|
|
67
|
+
|
|
36
68
|
# Run in watch mode during development
|
|
37
69
|
bun run dev
|
|
38
70
|
|
|
39
|
-
# Run type checking
|
|
40
|
-
bun run typecheck
|
|
41
|
-
|
|
42
71
|
# Run tests
|
|
43
72
|
bun run test
|
|
44
73
|
|
|
45
74
|
# Run tests in watch mode
|
|
46
75
|
bun run test:watch
|
|
47
|
-
```
|
|
48
76
|
|
|
49
|
-
|
|
77
|
+
# Run type checking
|
|
78
|
+
bun run typecheck
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
bun run build
|
|
80
|
+
# Alias for typecheck
|
|
81
|
+
bun run lint
|
|
54
82
|
|
|
55
83
|
# Clean build artifacts
|
|
56
84
|
bun run clean
|
|
@@ -58,10 +86,28 @@ bun run clean
|
|
|
58
86
|
|
|
59
87
|
## Project structure
|
|
60
88
|
|
|
61
|
-
```
|
|
89
|
+
```text
|
|
62
90
|
src/
|
|
63
|
-
index.ts
|
|
64
|
-
constants/
|
|
91
|
+
index.ts
|
|
92
|
+
constants/
|
|
93
|
+
common.ts
|
|
94
|
+
legal.ts
|
|
95
|
+
payment.ts
|
|
96
|
+
platforms.ts
|
|
97
|
+
services.ts
|
|
98
|
+
index.ts
|
|
99
|
+
utils/
|
|
100
|
+
format-amount.ts
|
|
101
|
+
format-date.ts
|
|
102
|
+
format-plain-text.ts
|
|
103
|
+
get-social-handle.ts
|
|
104
|
+
get-user-page-link.ts
|
|
105
|
+
open-to-new-window.ts
|
|
106
|
+
post-to-facebook.ts
|
|
107
|
+
post-to-instagram.ts
|
|
108
|
+
post-to-linkedin.ts
|
|
109
|
+
post-to-x.ts
|
|
110
|
+
qr-svg-utils.ts
|
|
65
111
|
index.ts
|
|
66
112
|
```
|
|
67
113
|
|
|
@@ -70,15 +116,10 @@ src/
|
|
|
70
116
|
Publishing is automated on push to the `main` branch via GitHub Actions. Ensure:
|
|
71
117
|
|
|
72
118
|
- `package.json` version is updated.
|
|
73
|
-
- `NPM_TOKEN` secret is
|
|
119
|
+
- `NPM_TOKEN` secret is configured with publish permissions.
|
|
74
120
|
|
|
75
121
|
For local publish (if needed):
|
|
76
122
|
|
|
77
123
|
```bash
|
|
78
124
|
npm publish --access public
|
|
79
125
|
```
|
|
80
|
-
|
|
81
|
-
## Notes
|
|
82
|
-
|
|
83
|
-
- This project uses Bun for development and builds.
|
|
84
|
-
- To generate supabase types, follow https://supabase.com/docs/guides/api/rest/generating-types
|
package/package.json
CHANGED
|
@@ -4,12 +4,16 @@ import {
|
|
|
4
4
|
PaymentStatuses,
|
|
5
5
|
PaymentTypes,
|
|
6
6
|
PaymentDirections,
|
|
7
|
+
PayoutProviders,
|
|
8
|
+
WithdrawalStatuses,
|
|
7
9
|
} from "./payment";
|
|
8
10
|
import type {
|
|
9
11
|
PaymentProvider,
|
|
10
12
|
PaymentStatus,
|
|
11
13
|
PaymentType,
|
|
12
14
|
PaymentDirection,
|
|
15
|
+
PayoutProvider,
|
|
16
|
+
WithdrawalStatus,
|
|
13
17
|
} from "./payment";
|
|
14
18
|
|
|
15
19
|
describe("PaymentStatuses", () => {
|
|
@@ -64,7 +68,15 @@ describe("PaymentStatuses", () => {
|
|
|
64
68
|
|
|
65
69
|
describe("PaymentTypes", () => {
|
|
66
70
|
test("should contain all expected keys", () => {
|
|
67
|
-
const expectedKeys = [
|
|
71
|
+
const expectedKeys = [
|
|
72
|
+
"SUBSCRIPTION",
|
|
73
|
+
"ONE_TIME",
|
|
74
|
+
"PAYOUT",
|
|
75
|
+
"WITHDRAW_LOCK",
|
|
76
|
+
"WITHDRAW_RELEASE",
|
|
77
|
+
"WITHDRAW_COMPLETE",
|
|
78
|
+
"MANUAL_ADJUSTMENT",
|
|
79
|
+
];
|
|
68
80
|
expect(Object.keys(PaymentTypes)).toEqual(expectedKeys);
|
|
69
81
|
});
|
|
70
82
|
|
|
@@ -72,6 +84,10 @@ describe("PaymentTypes", () => {
|
|
|
72
84
|
expect(PaymentTypes.SUBSCRIPTION).toBe("subscription");
|
|
73
85
|
expect(PaymentTypes.ONE_TIME).toBe("one-time");
|
|
74
86
|
expect(PaymentTypes.PAYOUT).toBe("payout");
|
|
87
|
+
expect(PaymentTypes.WITHDRAW_LOCK).toBe("withdraw_lock");
|
|
88
|
+
expect(PaymentTypes.WITHDRAW_RELEASE).toBe("withdraw_release");
|
|
89
|
+
expect(PaymentTypes.WITHDRAW_COMPLETE).toBe("withdraw_complete");
|
|
90
|
+
expect(PaymentTypes.MANUAL_ADJUSTMENT).toBe("manual_adjustment");
|
|
75
91
|
});
|
|
76
92
|
|
|
77
93
|
test("should be read-only at compile time", () => {
|
|
@@ -86,8 +102,8 @@ describe("PaymentTypes", () => {
|
|
|
86
102
|
expect(validType).toBe("subscription");
|
|
87
103
|
});
|
|
88
104
|
|
|
89
|
-
test("should have
|
|
90
|
-
expect(Object.keys(PaymentTypes).length).toBe(
|
|
105
|
+
test("should have 7 payment types", () => {
|
|
106
|
+
expect(Object.keys(PaymentTypes).length).toBe(7);
|
|
91
107
|
});
|
|
92
108
|
|
|
93
109
|
test("all values should be lowercase or kebab-case strings", () => {
|
|
@@ -99,6 +115,61 @@ describe("PaymentTypes", () => {
|
|
|
99
115
|
});
|
|
100
116
|
});
|
|
101
117
|
|
|
118
|
+
describe("PayoutProviders", () => {
|
|
119
|
+
test("should contain all expected provider keys", () => {
|
|
120
|
+
const expectedKeys = ["BKASH", "NAGAD", "ROCKET", "BANK"];
|
|
121
|
+
expect(Object.keys(PayoutProviders)).toEqual(expectedKeys);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("should have correct values for each provider", () => {
|
|
125
|
+
expect(PayoutProviders.BKASH).toBe("bkash");
|
|
126
|
+
expect(PayoutProviders.NAGAD).toBe("nagad");
|
|
127
|
+
expect(PayoutProviders.ROCKET).toBe("rocket");
|
|
128
|
+
expect(PayoutProviders.BANK).toBe("bank");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("PayoutProvider type should accept valid provider values", () => {
|
|
132
|
+
const validProvider: PayoutProvider = "bkash";
|
|
133
|
+
expect(validProvider).toBe("bkash");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("should have 4 payout providers", () => {
|
|
137
|
+
expect(Object.keys(PayoutProviders).length).toBe(4);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("WithdrawalStatuses", () => {
|
|
142
|
+
test("should contain all expected status keys", () => {
|
|
143
|
+
const expectedKeys = [
|
|
144
|
+
"REQUESTED",
|
|
145
|
+
"APPROVED",
|
|
146
|
+
"PROCESSING",
|
|
147
|
+
"PAID",
|
|
148
|
+
"REJECTED",
|
|
149
|
+
"FAILED",
|
|
150
|
+
];
|
|
151
|
+
expect(Object.keys(WithdrawalStatuses)).toEqual(expectedKeys);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("should have correct values for each status", () => {
|
|
155
|
+
expect(WithdrawalStatuses.REQUESTED).toBe("requested");
|
|
156
|
+
expect(WithdrawalStatuses.APPROVED).toBe("approved");
|
|
157
|
+
expect(WithdrawalStatuses.PROCESSING).toBe("processing");
|
|
158
|
+
expect(WithdrawalStatuses.PAID).toBe("paid");
|
|
159
|
+
expect(WithdrawalStatuses.REJECTED).toBe("rejected");
|
|
160
|
+
expect(WithdrawalStatuses.FAILED).toBe("failed");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("WithdrawalStatus type should accept valid status values", () => {
|
|
164
|
+
const validStatus: WithdrawalStatus = "processing";
|
|
165
|
+
expect(validStatus).toBe("processing");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("should have 6 withdrawal statuses", () => {
|
|
169
|
+
expect(Object.keys(WithdrawalStatuses).length).toBe(6);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
102
173
|
describe("PaymentProviders", () => {
|
|
103
174
|
test("should contain all expected provider keys", () => {
|
|
104
175
|
const expectedKeys = [
|
package/src/constants/payment.ts
CHANGED
|
@@ -2,6 +2,10 @@ export const PaymentTypes = {
|
|
|
2
2
|
SUBSCRIPTION: "subscription",
|
|
3
3
|
ONE_TIME: "one-time",
|
|
4
4
|
PAYOUT: "payout",
|
|
5
|
+
WITHDRAW_LOCK: "withdraw_lock",
|
|
6
|
+
WITHDRAW_RELEASE: "withdraw_release",
|
|
7
|
+
WITHDRAW_COMPLETE: "withdraw_complete",
|
|
8
|
+
MANUAL_ADJUSTMENT: "manual_adjustment",
|
|
5
9
|
} as const;
|
|
6
10
|
|
|
7
11
|
export type PaymentType = (typeof PaymentTypes)[keyof typeof PaymentTypes];
|
|
@@ -43,3 +47,25 @@ export const PaymentDirections = {
|
|
|
43
47
|
|
|
44
48
|
export type PaymentDirection =
|
|
45
49
|
(typeof PaymentDirections)[keyof typeof PaymentDirections];
|
|
50
|
+
|
|
51
|
+
export const PayoutProviders = {
|
|
52
|
+
BKASH: "bkash",
|
|
53
|
+
NAGAD: "nagad",
|
|
54
|
+
ROCKET: "rocket",
|
|
55
|
+
BANK: "bank",
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
export type PayoutProvider =
|
|
59
|
+
(typeof PayoutProviders)[keyof typeof PayoutProviders];
|
|
60
|
+
|
|
61
|
+
export const WithdrawalStatuses = {
|
|
62
|
+
REQUESTED: "requested",
|
|
63
|
+
APPROVED: "approved",
|
|
64
|
+
PROCESSING: "processing",
|
|
65
|
+
PAID: "paid",
|
|
66
|
+
REJECTED: "rejected",
|
|
67
|
+
FAILED: "failed",
|
|
68
|
+
} as const;
|
|
69
|
+
|
|
70
|
+
export type WithdrawalStatus =
|
|
71
|
+
(typeof WithdrawalStatuses)[keyof typeof WithdrawalStatuses];
|