Skip to content

Commit e0b5d3f

Browse files
committed
feat: make Kakao share strategy asynchronous and update the Kakao SDK URL
1 parent c48a7f1 commit e0b5d3f

5 files changed

Lines changed: 173 additions & 14 deletions

File tree

bun.lock

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-share/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
"node": ">=24.0.0"
7777
},
7878
"dependencies": {
79-
"@types/facebook-js-sdk": "^3.3.12",
80-
"@types/kakao-js-sdk": "^1.39.5"
79+
"@types/facebook-js-sdk": "^3.3.12"
8180
},
8281
"devDependencies": {
8382
"@testing-library/react": "^16.3.1",

packages/react-share/src/hooks/use-headless-share.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { whatsappStrategy } from "@/strategies/whatsapp";
1111
import type { HeadlessShareOptions, ShareData, SharePlatform, ShareStrategy } from "@/types";
1212
import { setupFacebookSDK } from "@/utils/facebook";
1313

14-
const KAKAO_SDK_URL = "https://developers.kakao.com/sdk/js/kakao.js";
14+
const KAKAO_SDK_URL = "https://t1.kakaocdn.net/kakao_js_sdk/2.7.9/kakao.min.js";
1515
const FB_SDK_URL = "https://connect.facebook.net/en_US/sdk.js";
1616

1717
const strategyRegistry = new Map<SharePlatform, ShareStrategy>([

packages/react-share/src/strategies/kakao.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ShareStrategy } from "@/types";
33
import { ensureKakaoInitialized } from "@/utils/kakao";
44

55
export const kakaoStrategy: ShareStrategy = {
6-
share: (data, options) => {
6+
share: async (data, options) => {
77
const kakao = ensureKakaoInitialized(options?.kakao?.jsKey);
88
if (!kakao) {
99
throw new Error("Kakao SDK not initialized");
@@ -12,9 +12,7 @@ export const kakaoStrategy: ShareStrategy = {
1212
const { url, title, description, imageUrl } = data;
1313
const maxLength = options?.textMaxLength ?? 100;
1414

15-
(
16-
kakao as unknown as { Share?: { sendDefault?: (options: unknown) => void } }
17-
).Share?.sendDefault?.({
15+
await kakao.Share?.sendDefault({
1816
buttons: [
1917
{
2018
link: {
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
export {};
2+
3+
declare global {
4+
namespace Kakao {
5+
const VERSION: string;
6+
7+
/**
8+
* @see https://developers.kakao.com/sdk/reference/js/release/Kakao.html#init
9+
*/
10+
function init(appKey: string): void;
11+
12+
/**
13+
* @see https://developers.kakao.com/sdk/reference/js/release/Kakao.html#isInitialized
14+
*/
15+
function isInitialized(): boolean;
16+
17+
/**
18+
* @see https://developers.kakao.com/sdk/reference/js/release/Kakao.html#cleanup
19+
*/
20+
function cleanup(): void;
21+
22+
namespace Auth {
23+
interface AuthorizeSettings {
24+
redirectUri?: string;
25+
state?: string;
26+
scope?: string;
27+
prompt?: string;
28+
nonce?: string;
29+
throughTalk?: boolean;
30+
}
31+
32+
/**
33+
* @see https://developers.kakao.com/docs/latest/ko/kakaologin/js#authorize
34+
*/
35+
function authorize(settings: AuthorizeSettings): void;
36+
37+
/**
38+
* @see https://developers.kakao.com/docs/latest/ko/kakaologin/js#logout
39+
*/
40+
function logout(): Promise<void>;
41+
}
42+
43+
namespace Share {
44+
interface LinkObject {
45+
webUrl?: string;
46+
mobileWebUrl?: string;
47+
androidExecutionParams?: string;
48+
iosExecutionParams?: string;
49+
}
50+
51+
interface ButtonObject {
52+
title: string;
53+
link: LinkObject;
54+
}
55+
56+
interface ContentObject {
57+
title: string;
58+
description?: string;
59+
imageUrl: string;
60+
link: LinkObject;
61+
imageWidth?: number;
62+
imageHeight?: number;
63+
}
64+
65+
interface SocialObject {
66+
likeCount?: number;
67+
commentCount?: number;
68+
sharedCount?: number;
69+
viewCount?: number;
70+
subscriberCount?: number;
71+
}
72+
73+
/**
74+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-share/js-link#default-template-feed
75+
*/
76+
interface DefaultFeedSettings {
77+
objectType: "feed";
78+
content: ContentObject;
79+
social?: SocialObject;
80+
buttons?: ButtonObject[];
81+
}
82+
83+
/**
84+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-share/js-link#default-template-text
85+
*/
86+
interface DefaultTextSettings {
87+
objectType: "text";
88+
text: string;
89+
link: LinkObject;
90+
buttons?: ButtonObject[];
91+
}
92+
93+
/**
94+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-share/js-link#default-template-commerce
95+
*/
96+
interface DefaultCommerceSettings {
97+
objectType: "commerce";
98+
content: ContentObject;
99+
commerce: {
100+
regularPrice: number;
101+
discountPrice?: number;
102+
discountRate?: number;
103+
fixedDiscountPrice?: number;
104+
};
105+
buttons?: ButtonObject[];
106+
}
107+
108+
type DefaultSettings = DefaultFeedSettings | DefaultTextSettings | DefaultCommerceSettings;
109+
110+
interface CustomSettings {
111+
templateId: number;
112+
templateArgs?: Record<string, string>;
113+
installTalk?: boolean;
114+
}
115+
116+
interface ScrapSettings {
117+
requestUrl: string;
118+
templateId?: number;
119+
templateArgs?: Record<string, string>;
120+
}
121+
122+
/**
123+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-share/js-link#send-default
124+
*/
125+
function sendDefault(settings: DefaultSettings): Promise<void>;
126+
127+
/**
128+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-share/js-link#send-custom
129+
*/
130+
function sendCustom(settings: CustomSettings): Promise<void>;
131+
132+
/**
133+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-share/js-link#send-scrap
134+
*/
135+
function sendScrap(settings: ScrapSettings): Promise<void>;
136+
137+
/**
138+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-share/js-link#create-default-button
139+
*/
140+
function createDefaultButton(
141+
settings: DefaultSettings & { container: string | HTMLElement },
142+
): void;
143+
}
144+
145+
namespace Channel {
146+
interface ChannelSettings {
147+
channelPublicId: string;
148+
}
149+
150+
/**
151+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-channel/js#add-channel
152+
*/
153+
function addChannel(settings: ChannelSettings): void;
154+
155+
/**
156+
* @see https://developers.kakao.com/docs/latest/ko/kakaotalk-channel/js#chat
157+
*/
158+
function chat(settings: ChannelSettings): void;
159+
}
160+
}
161+
162+
interface Window {
163+
Kakao: typeof Kakao;
164+
}
165+
}

0 commit comments

Comments
 (0)