@hobenakicoffee/libraries 3.2.0 → 3.4.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/package.json +1 -1
- package/src/App.tsx +2 -0
- package/src/nuqs/common.ts +9 -0
- package/src/types/supabase.ts +28 -0
- package/src/utils/get-product-link.test.ts +36 -0
- package/src/utils/get-product-link.ts +10 -0
- package/src/utils/index.ts +1 -0
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import { Button } from "./components/ui/button";
|
|
3
3
|
import { Calendar } from "./components/ui/calendar";
|
|
4
|
+
import { getProductLink } from "./utils/get-product-link";
|
|
4
5
|
|
|
5
6
|
const App = () => {
|
|
6
7
|
const [date, setDate] = useState<Date | undefined>(new Date());
|
|
@@ -20,6 +21,7 @@ const App = () => {
|
|
|
20
21
|
onSelect={setDate}
|
|
21
22
|
selected={date}
|
|
22
23
|
/>
|
|
24
|
+
{getProductLink("leo", "example-product-slug")}
|
|
23
25
|
</div>
|
|
24
26
|
</div>
|
|
25
27
|
);
|
package/src/nuqs/common.ts
CHANGED
|
@@ -10,3 +10,12 @@ export const parseAsDateRange = parseAsJson(
|
|
|
10
10
|
to: z.date().optional(),
|
|
11
11
|
})
|
|
12
12
|
);
|
|
13
|
+
|
|
14
|
+
export const parseAsLastTimeRange = parseAsStringLiteral([
|
|
15
|
+
"last_7_days",
|
|
16
|
+
"last_30_days",
|
|
17
|
+
"last_90_days",
|
|
18
|
+
"last_180_days",
|
|
19
|
+
"last_year",
|
|
20
|
+
]);
|
|
21
|
+
export type LastTimeRange = inferParserType<typeof parseAsLastTimeRange>;
|
package/src/types/supabase.ts
CHANGED
|
@@ -1740,6 +1740,34 @@ export type Database = {
|
|
|
1740
1740
|
spent_total: number;
|
|
1741
1741
|
}[];
|
|
1742
1742
|
};
|
|
1743
|
+
get_transactions_page: {
|
|
1744
|
+
Args: {
|
|
1745
|
+
p_amount_sort?: string;
|
|
1746
|
+
p_cursor_amount?: number;
|
|
1747
|
+
p_cursor_ts?: string;
|
|
1748
|
+
p_date_from?: string;
|
|
1749
|
+
p_date_to?: string;
|
|
1750
|
+
p_limit?: number;
|
|
1751
|
+
p_providers?: string[];
|
|
1752
|
+
p_reference_types?: string[];
|
|
1753
|
+
p_service_types?: string[];
|
|
1754
|
+
p_statuses?: string[];
|
|
1755
|
+
};
|
|
1756
|
+
Returns: {
|
|
1757
|
+
created_at: string;
|
|
1758
|
+
direction: Database["public"]["Enums"]["transaction_direction_enum"];
|
|
1759
|
+
id: string;
|
|
1760
|
+
metadata: Json;
|
|
1761
|
+
net_amount: number;
|
|
1762
|
+
platform_fee: number;
|
|
1763
|
+
provider: Database["public"]["Enums"]["provider_enum"];
|
|
1764
|
+
provider_transaction_id: string;
|
|
1765
|
+
reference_type: Database["public"]["Enums"]["reference_type_enum"];
|
|
1766
|
+
service_type: string;
|
|
1767
|
+
status: Database["public"]["Enums"]["payment_status_enum"];
|
|
1768
|
+
supporter_id: string;
|
|
1769
|
+
}[];
|
|
1770
|
+
};
|
|
1743
1771
|
gift_newsletter_post: {
|
|
1744
1772
|
Args: {
|
|
1745
1773
|
p_expires_at?: string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { getProductLink } from "./get-product-link";
|
|
3
|
+
|
|
4
|
+
describe("getProductLink", () => {
|
|
5
|
+
test("builds product link with default baseUrl", () => {
|
|
6
|
+
const result = getProductLink("johndoe", "my-product");
|
|
7
|
+
expect(result).toBe(
|
|
8
|
+
"https://hobenakicoffee.com/@johndoe/shops/products/my-product"
|
|
9
|
+
);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("builds product link with custom baseUrl", () => {
|
|
13
|
+
const result = getProductLink(
|
|
14
|
+
"johndoe",
|
|
15
|
+
"my-product",
|
|
16
|
+
"https://custom.com"
|
|
17
|
+
);
|
|
18
|
+
expect(result).toBe(
|
|
19
|
+
"https://custom.com/@johndoe/shops/products/my-product"
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("sanitizes username with whitespace", () => {
|
|
24
|
+
const result = getProductLink(" john doe ", "my-product");
|
|
25
|
+
expect(result).toBe(
|
|
26
|
+
"https://hobenakicoffee.com/@johndoe/shops/products/my-product"
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("does not encode slug - passes through as-is", () => {
|
|
31
|
+
const result = getProductLink("johndoe", "my product 123");
|
|
32
|
+
expect(result).toBe(
|
|
33
|
+
"https://hobenakicoffee.com/@johndoe/shops/products/my-product-123"
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getUserPageLink } from "./get-user-page-link";
|
|
2
|
+
|
|
3
|
+
export function getProductLink(
|
|
4
|
+
username: string,
|
|
5
|
+
slug: string,
|
|
6
|
+
baseUrl = "https://hobenakicoffee.com"
|
|
7
|
+
) {
|
|
8
|
+
const sanitizedSlug = slug.trim().replace(/\s+/g, "-");
|
|
9
|
+
return `${getUserPageLink(username, baseUrl)}/shops/products/${sanitizedSlug}`;
|
|
10
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./format-date";
|
|
|
5
5
|
export * from "./format-number";
|
|
6
6
|
export * from "./format-plain-text";
|
|
7
7
|
export * from "./get-newsletter-post-link";
|
|
8
|
+
export * from "./get-product-link";
|
|
8
9
|
export * from "./get-social-handle";
|
|
9
10
|
export * from "./get-social-link";
|
|
10
11
|
export * from "./get-user-name-initials";
|