Skip to content

Commit 00a6773

Browse files
authored
Merge pull request #27 from mym0404/web-share
Web Share, Channel, Social
2 parents 925facd + 34e6ed3 commit 00a6773

File tree

18 files changed

+377
-154
lines changed

18 files changed

+377
-154
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,15 @@ please select the package link from below.
4646

4747
[//]: # (The main package that you interface with is `App` (`@react-native-kakao/app`))
4848

49-
50-
| Name | Android | iOS | Web | Downloads | Status |
51-
|---------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------:|--------|
52-
| [Core](https://rnkakao.dev/docs/intro) | ![common-android](https://img.shields.io/badge/common-2.20.1-green?style=flat-square) | ![common-ios](https://img.shields.io/badge/common-2.22.0-lightblue?style=flat-square) || [![badge](https://img.shields.io/npm/dm/@react-native-kakao/core.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/core) ||
53-
| [Share](https://rnkakao.dev/docs/share/intro) | ![share-android](https://img.shields.io/badge/share-2.20.1-green?style=flat-square) | ![share-ios](https://img.shields.io/badge/share-2.22.0-lightblue?style=flat-square) | 🔥 | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/share.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/share) ||
54-
| [User](https://rnkakao.dev/docs/user/intro) | ![user-android](https://img.shields.io/badge/user-2.20.1-green?style=flat-square) | ![user-ios](https://img.shields.io/badge/user-2.22.0-lightblue?style=flat-square) || [![badge](https://img.shields.io/npm/dm/@react-native-kakao/user.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/user) ||
55-
| [Social](https://rnkakao.dev/docs/social/intro) | ![talk-android](https://img.shields.io/badge/talk-2.20.1-green?style=flat-square) ![friend-android](https://img.shields.io/badge/friend-2.20.1-green?style=flat-square) | ![talk-ios](https://img.shields.io/badge/talk-2.22.0-lightblue?style=flat-square) ![friend-ios](https://img.shields.io/badge/friend-2.22.0-lightblue?style=flat-square) | 🔥 | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/social.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/social) ||
56-
| [Channel](https://rnkakao.dev/docs/channel/intro) | ![talk-android](https://img.shields.io/badge/talk-2.20.1-green?style=flat-square) | ![talk-ios](https://img.shields.io/badge/talk-2.22.0-lightblue?style=flat-square) | 🔥 | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/channel.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/channel) ||
57-
| [Navi](https://rnkakao.dev/docs/navi/intro) | ![navi-android](https://img.shields.io/badge/navi-2.20.1-green?style=flat-square) | ![navi-ios](https://img.shields.io/badge/navi-2.22.0-lightblue?style=flat-square) || [![badge](https://img.shields.io/npm/dm/@react-native-kakao/navi.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/navi) ||
58-
| [Cert](https://rnkakao.dev/docs/cert/intro) | | | | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/cert.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/cert) | 📦 |
59-
| [Map](https://rnkakao.dev/docs/map/intro) | | | | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/map.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/map) | 📦 |
49+
| Name | Android | iOS | Web | Downloads | Status |
50+
|---------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------:|--------|
51+
| [Core](https://rnkakao.dev/docs/intro) | ![common-android](https://img.shields.io/badge/common-2.20.1-green?style=flat-square) | ![common-ios](https://img.shields.io/badge/common-2.22.0-lightblue?style=flat-square) | ![web-sdk](https://img.shields.io/badge/js--sdk-+2.7.1-2460a1?style=flat-square) | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/core.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/core) ||
52+
| [Share](https://rnkakao.dev/docs/share/intro) | ![share-android](https://img.shields.io/badge/share-2.20.1-green?style=flat-square) | ![share-ios](https://img.shields.io/badge/share-2.22.0-lightblue?style=flat-square) | ![web-sdk](https://img.shields.io/badge/js--sdk-+2.7.1-2460a1?style=flat-square) | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/share.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/share) ||
53+
| [User](https://rnkakao.dev/docs/user/intro) | ![user-android](https://img.shields.io/badge/user-2.20.1-green?style=flat-square) | ![user-ios](https://img.shields.io/badge/user-2.22.0-lightblue?style=flat-square) | ![web-sdk](https://img.shields.io/badge/js--sdk-+2.7.1-2460a1?style=flat-square) | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/user.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/user) ||
54+
| [Social](https://rnkakao.dev/docs/social/intro) | ![talk-android](https://img.shields.io/badge/talk-2.20.1-green?style=flat-square) ![friend-android](https://img.shields.io/badge/friend-2.20.1-green?style=flat-square) | ![talk-ios](https://img.shields.io/badge/talk-2.22.0-lightblue?style=flat-square) ![friend-ios](https://img.shields.io/badge/friend-2.22.0-lightblue?style=flat-square) | ![web-sdk](https://img.shields.io/badge/js--sdk-+2.7.1-2460a1?style=flat-square) | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/social.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/social) ||
55+
| [Channel](https://rnkakao.dev/docs/channel/intro) | ![talk-android](https://img.shields.io/badge/talk-2.20.1-green?style=flat-square) | ![talk-ios](https://img.shields.io/badge/talk-2.22.0-lightblue?style=flat-square) | ![web-sdk](https://img.shields.io/badge/js--sdk-+2.7.1-2460a1?style=flat-square) | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/channel.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/channel) ||
56+
| [Navi](https://rnkakao.dev/docs/navi/intro) | ![navi-android](https://img.shields.io/badge/navi-2.20.1-green?style=flat-square) | ![navi-ios](https://img.shields.io/badge/navi-2.22.0-lightblue?style=flat-square) | ![web-sdk](https://img.shields.io/badge/js--sdk-+2.7.1-2460a1?style=flat-square) | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/navi.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/navi) ||
57+
| [Map](https://rnkakao.dev/docs/map/intro) | | | | [![badge](https://img.shields.io/npm/dm/@react-native-kakao/map.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-kakao/map) | 🔥 |
6058

6159
## Documentation
6260

example/src/app/share.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { showMessage } from 'react-native-flash-message';
12
import {
23
type KakaoCommerceTemplate,
34
type KakaoFeedTemplate,
@@ -159,7 +160,7 @@ export default function Page() {
159160
price: '20000',
160161
},
161162
serverCallbackArgs: {},
162-
});
163+
}).catch((e) => showMessage({ type: 'warning', message: e.message }));
163164
}}
164165
/>
165166
<Btn
@@ -170,7 +171,9 @@ export default function Page() {
170171
templateArgs: {
171172
price: '20000',
172173
},
173-
}).then(console.log);
174+
})
175+
.then(console.log)
176+
.catch((e) => showMessage({ type: 'warning', message: e.message }));
174177
}}
175178
/>
176179
<Btn

packages/channel/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "React Native Kakao Channel SDK",
44
"version": "2.1.0",
55
"main": "lib/commonjs/index",
6-
"module": "lib/module/index",
6+
"module": "src/index",
77
"types": "lib/typescript/src/index.d.ts",
88
"react-native": "src/index",
99
"source": "src/index",
@@ -62,7 +62,7 @@
6262
"access": "public"
6363
},
6464
"devDependencies": {
65-
"@react-native-kakao/core": "1.6.1",
65+
"@react-native-kakao/core": "2.1.0",
6666
"@types/invariant": "^2",
6767
"@types/jest": "^29.5.5",
6868
"@types/react": "^18.2.44",
@@ -74,7 +74,7 @@
7474
"typescript": "5.1.6"
7575
},
7676
"peerDependencies": {
77-
"@react-native-kakao/core": "1.6.1",
77+
"@react-native-kakao/core": "2.1.0",
7878
"react": "*",
7979
"react-native": "*"
8080
},

packages/channel/src/index.web.ts

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1+
import { kRunWebAPI } from '@react-native-kakao/core';
2+
import * as querystring from 'querystring';
3+
14
import type { KakaoChannelAPI } from './index';
25

3-
// @ts-ignore
6+
declare const Kakao: {
7+
Channel: {
8+
followChannel: Function;
9+
addChannel: Function;
10+
chat: Function;
11+
};
12+
API: {
13+
request: Function;
14+
};
15+
};
16+
417
const KakaoChannel: KakaoChannelAPI = {
5-
// followChannel: (channelPublicId: string): Promise<boolean> => {},
6-
// addChannel: (channelPublicId: string): Promise<void> => {},
7-
// getAddChannelUrl: (channelPublicId: string): Promise<string> => {},
8-
// openAddChannelUrl: (channelPublicId: string): Promise<string> => {},
9-
// chatChannel: (channelPublicId: string): Promise<void> => {},
10-
// getChatChannelUrl: (channelPublicId: string): Promise<string> => {},
11-
// openChatChannelUrl: (channelPublicId: string): Promise<string> => {},
12-
// channels: (params) => {},
18+
followChannel: (channelPublicId: string): Promise<boolean> =>
19+
kRunWebAPI(async () => {
20+
await Kakao.Channel.followChannel({ channelPublicId });
21+
22+
return true;
23+
}),
24+
addChannel: (channelPublicId: string): Promise<void> =>
25+
kRunWebAPI(() => Kakao.Channel.addChannel({ channelPublicId })),
26+
getAddChannelUrl: (): Promise<string> =>
27+
kRunWebAPI(() => {
28+
throw { message: 'Use addChannel directly in web' };
29+
}),
30+
openAddChannelUrl: (): Promise<string> =>
31+
kRunWebAPI(() => {
32+
throw { message: 'Use addChannel directly in web' };
33+
}),
34+
chatChannel: (channelPublicId: string): Promise<void> =>
35+
kRunWebAPI(() => Kakao.Channel.chat({ channelPublicId })),
36+
getChatChannelUrl: (): Promise<string> =>
37+
kRunWebAPI(() => {
38+
throw { message: 'Use chatChannel directly in web' };
39+
}),
40+
openChatChannelUrl: (): Promise<string> =>
41+
kRunWebAPI(() => {
42+
throw { message: 'Use chatChannel directly in web' };
43+
}),
44+
channels: (params) =>
45+
kRunWebAPI(() =>
46+
Kakao.API.request({
47+
url: `/v1/api/talk/channels${params?.channelPublicIds ? `?${querystring.stringify({ channel_ids: params.channelPublicIds })}` : ''}`,
48+
}),
49+
),
1350
};
1451

1552
export const {

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "React Native Kakao Core SDK",
44
"version": "2.1.0",
55
"main": "lib/commonjs/index",
6-
"module": "lib/module/index",
6+
"module": "src/index",
77
"types": "lib/typescript/src/index.d.ts",
88
"react-native": "src/index",
99
"source": "src/index",

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { KakaoPackageErrorCodes } from './util/kCreateWebError';
66
import { kCreateWebError } from './util/kCreateWebError';
77
import { kFetch, kFetchFormUrlEncoded } from './util/kFetch';
88
import kGlobalStorage from './util/kGlobalStorage';
9+
import { kRunWebAPI } from './util/kRunWebAPI';
910

1011
const LINKING_ERROR =
1112
"The package '@react-native-kakao/core' doesn't seem to be linked. Make sure: \n\n" +
@@ -49,4 +50,4 @@ const KakaoCore = {
4950
export default KakaoCore;
5051
export type KakaoCoreAPI = typeof KakaoCore;
5152
export type { KakaoPackageErrorCodes };
52-
export { kAssert, kCreateWebError, kGlobalStorage, kFetch, kFetchFormUrlEncoded };
53+
export { kAssert, kCreateWebError, kGlobalStorage, kFetch, kFetchFormUrlEncoded, kRunWebAPI };

packages/core/src/index.web.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { kAssert } from './util/kAssert';
22
import { kCreateWebError } from './util/kCreateWebError';
33
import { kFetch, kFetchFormUrlEncoded } from './util/kFetch';
44
import kGlobalStorage from './util/kGlobalStorage';
5+
import { kRunWebAPI } from './util/kRunWebAPI';
56
import type { KakaoCoreAPI } from './index';
67

78
declare const Kakao: {
@@ -17,20 +18,18 @@ const KakaoCore: KakaoCoreAPI = {
1718
kAssert(options?.web?.javascriptKey, '[initializeKakaoSDK] javascriptKey is missing');
1819
kAssert(options?.web?.restApiKey, '[initializeKakaoSDK] restApiKey is missing');
1920

20-
try {
21+
await kRunWebAPI(() => {
2122
kGlobalStorage.javascriptKey = options?.web?.javascriptKey!;
2223
kGlobalStorage.restApiKey = options?.web?.restApiKey!;
2324
if (!Kakao.isInitialized()) {
2425
Kakao.init(options!.web!.javascriptKey);
2526
}
2627

2728
kAssert(Kakao.isInitialized(), 'Kakao.isInitialized returns false');
28-
} catch (e) {
29-
throw e;
30-
}
29+
});
3130
},
3231
};
3332

3433
export const { getKeyHashAndroid, initializeKakaoSDK } = KakaoCore;
3534
export default KakaoCore;
36-
export { kAssert, kCreateWebError, kGlobalStorage, kFetch, kFetchFormUrlEncoded };
35+
export { kAssert, kCreateWebError, kGlobalStorage, kFetch, kFetchFormUrlEncoded, kRunWebAPI };

packages/core/src/util/kCreateWebError.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export type KakaoPackageErrorCodes = 'Package-Unknown' | 'Package-Assertion';
1+
export type KakaoPackageErrorCodes =
2+
| 'Package-Unknown'
3+
| 'Package-Assertion'
4+
| 'Package-Unauthorized'
5+
| (string & {});
26
export function kCreateWebError({
37
code = 'Package-Unknown',
48
message = '',
@@ -22,12 +26,12 @@ export function kCreateWebError({
2226
}) {
2327
throw {
2428
code: code + '',
25-
message: (msg || message) + '',
29+
message: (msg || message || 'unknown') + '',
2630
userInfo: {
2731
isAppsFailed,
2832
isInvalidTokenError,
2933
isClientFailed,
30-
isAuthFailed,
34+
isAuthFailed: isAuthFailed || (code + '').includes('401'),
3135
fatal: true,
3236
isApiFailed,
3337
nativeErrorMessage,

packages/core/src/util/kFetch.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { FetchArgs, ReturnFetchDefaultOptions } from 'return-fetch';
22
import returnFetch from 'return-fetch';
33

4+
import { kCreateWebError } from './kCreateWebError';
5+
46
// Use as a replacer of `RequestInit`
57
type JsonRequestInit = Omit<NonNullable<FetchArgs[1]>, 'body'> & { body?: object };
68

@@ -53,6 +55,14 @@ const returnFetchJson = (args?: ReturnFetchDefaultOptions, formUrlEncoded = fals
5355
},
5456
});
5557

58+
if (response.status === 401) {
59+
throw kCreateWebError({
60+
code: -401 + '',
61+
isAuthFailed: true,
62+
msg: 'this access token does not exist',
63+
});
64+
}
65+
5666
const body = parseJsonSafely(await response.text()) as T;
5767

5868
return {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { kCreateWebError } from './kCreateWebError';
2+
3+
export async function kRunWebAPI<T>(fn: () => Promise<T> | T): Promise<T> {
4+
try {
5+
return await fn();
6+
} catch (e: any) {
7+
throw kCreateWebError(e);
8+
}
9+
}

0 commit comments

Comments
 (0)