@react-native-kakao/user 3.1.0-next.0 → 3.1.0-next.1
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/CHANGELOG.md +30 -0
- package/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserModule.kt +289 -128
- package/ios/RNCKakaoUser.mm +58 -6
- package/ios/RNCKakaoUserManager.swift +211 -43
- package/lib/commonjs/index.js +66 -5
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +106 -5
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/spec/NativeKakaoUser.ts +23 -1
- package/lib/module/index.js +61 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +101 -5
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/spec/NativeKakaoUser.ts +23 -1
- package/lib/typescript/src/index.d.ts +58 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/spec/NativeKakaoUser.d.ts +8 -2
- package/lib/typescript/src/spec/NativeKakaoUser.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +157 -4
- package/src/index.web.ts +123 -7
- package/src/spec/NativeKakaoUser.ts +23 -1
package/src/index.web.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { camelCaseObject, filterNonNullishKeys, is } from '@mj-studio/js-util';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
kAssert,
|
|
4
|
+
kCreateWebError,
|
|
5
|
+
kFetch,
|
|
6
|
+
kFetchFormUrlEncoded,
|
|
7
|
+
kGlobalStorage,
|
|
8
|
+
kRunWebAPI,
|
|
9
|
+
} from '@react-native-kakao/core';
|
|
3
10
|
|
|
4
11
|
import {
|
|
5
12
|
type KakaoLoginToken,
|
|
@@ -11,6 +18,7 @@ import {
|
|
|
11
18
|
import { validateShippingAddressOptions } from './validateShippingAddressOptions';
|
|
12
19
|
|
|
13
20
|
declare const Kakao: {
|
|
21
|
+
isInitialized: () => boolean;
|
|
14
22
|
Auth: {
|
|
15
23
|
authorize: Function;
|
|
16
24
|
logout: Function;
|
|
@@ -30,6 +38,21 @@ function isoToUnix(value?: string | number) {
|
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
const KakaoUser: KakaoUserAPI = {
|
|
41
|
+
loginWithKakao: () =>
|
|
42
|
+
kRunWebAPI(() => {
|
|
43
|
+
throw {
|
|
44
|
+
code: 'Package-UnsupportedPlatform',
|
|
45
|
+
message:
|
|
46
|
+
'loginWithKakao is supported on Android and iOS. Use login with web.redirectUri on web.',
|
|
47
|
+
};
|
|
48
|
+
}),
|
|
49
|
+
refreshToken: () =>
|
|
50
|
+
kRunWebAPI(() => {
|
|
51
|
+
throw {
|
|
52
|
+
code: 'Package-UnsupportedPlatform',
|
|
53
|
+
message: 'The Kakao JavaScript SDK does not support refreshToken.',
|
|
54
|
+
};
|
|
55
|
+
}),
|
|
33
56
|
hasToken: () => kRunWebAPI(() => Kakao.Auth.getAccessToken() != null),
|
|
34
57
|
getAccessToken: () =>
|
|
35
58
|
kRunWebAPI(async () => {
|
|
@@ -42,7 +65,62 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
42
65
|
appId: app_id,
|
|
43
66
|
};
|
|
44
67
|
}),
|
|
45
|
-
|
|
68
|
+
issueAccessTokenWithCode: ({ code, codeVerifier, redirectUri, web }) =>
|
|
69
|
+
kRunWebAPI(async () => {
|
|
70
|
+
kAssert(
|
|
71
|
+
is.string(code) && code.length > 0 && is.string(redirectUri) && redirectUri.length > 0,
|
|
72
|
+
'[issueAccessTokenWithCode] code and redirectUri are required on web',
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (typeof Kakao === 'undefined' || !Kakao.isInitialized()) {
|
|
76
|
+
kCreateWebError({
|
|
77
|
+
code: 'Package-SDKNotInitialized',
|
|
78
|
+
message: 'Initialize the Kakao SDK before exchanging an authorization code.',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const token = await KakaoUser.issueAccessTokenWithCodeWeb({
|
|
83
|
+
code,
|
|
84
|
+
codeVerifier,
|
|
85
|
+
redirectUri: redirectUri!,
|
|
86
|
+
clientSecret: web?.clientSecret,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (
|
|
90
|
+
!is.string(token.accessToken) ||
|
|
91
|
+
!token.accessToken ||
|
|
92
|
+
!is.string(token.refreshToken) ||
|
|
93
|
+
!token.refreshToken ||
|
|
94
|
+
!is.string(token.tokenType) ||
|
|
95
|
+
(token.idToken != null && !is.string(token.idToken)) ||
|
|
96
|
+
!Number.isFinite(token.expiresIn) ||
|
|
97
|
+
token.expiresIn < 0 ||
|
|
98
|
+
!Number.isFinite(token.refreshTokenExpiresIn) ||
|
|
99
|
+
token.refreshTokenExpiresIn < 0 ||
|
|
100
|
+
(token.scope != null && !is.string(token.scope))
|
|
101
|
+
) {
|
|
102
|
+
kCreateWebError({
|
|
103
|
+
code: 'Package-APIResponseNotFound',
|
|
104
|
+
message: 'issueAccessTokenWithCode returned invalid token data.',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const issuedAt = Math.floor(Date.now() / 1000);
|
|
109
|
+
KakaoUser.setAccessTokenWeb(token.accessToken);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
accessToken: token.accessToken,
|
|
113
|
+
refreshToken: token.refreshToken,
|
|
114
|
+
tokenType: token.tokenType,
|
|
115
|
+
idToken: token.idToken,
|
|
116
|
+
accessTokenExpiresIn: token.expiresIn,
|
|
117
|
+
refreshTokenExpiresIn: token.refreshTokenExpiresIn,
|
|
118
|
+
accessTokenExpiresAt: issuedAt + token.expiresIn,
|
|
119
|
+
refreshTokenExpiresAt: issuedAt + token.refreshTokenExpiresIn,
|
|
120
|
+
scopes: token.scope?.split(' ').filter(Boolean) ?? [],
|
|
121
|
+
};
|
|
122
|
+
}),
|
|
123
|
+
issueAccessTokenWithCodeWeb: ({ clientSecret, code, codeVerifier, redirectUri }) =>
|
|
46
124
|
kRunWebAPI(async () => {
|
|
47
125
|
const res = await kFetchFormUrlEncoded<{
|
|
48
126
|
token_type: string;
|
|
@@ -59,6 +137,7 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
59
137
|
client_id: kGlobalStorage.restApiKey,
|
|
60
138
|
redirect_uri: redirectUri,
|
|
61
139
|
code,
|
|
140
|
+
code_verifier: codeVerifier,
|
|
62
141
|
client_secret: clientSecret,
|
|
63
142
|
}),
|
|
64
143
|
}).then((r) => r.body);
|
|
@@ -73,10 +152,12 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
73
152
|
kRunWebAPI(() => {
|
|
74
153
|
const { loginHint, nonce, prompt, redirectUri, scope, state, throughTalk, serviceTerms } =
|
|
75
154
|
params?.web ?? {};
|
|
155
|
+
const channelPublicIds = params?.channelPublicIds;
|
|
76
156
|
|
|
77
157
|
return Kakao.Auth.authorize(
|
|
78
158
|
filterNonNullishKeys({
|
|
79
|
-
loginHint,
|
|
159
|
+
loginHint: params?.loginHint ?? loginHint,
|
|
160
|
+
channelPublicId: channelPublicIds?.length ? channelPublicIds.join(',') : undefined,
|
|
80
161
|
nonce: params?.nonce ?? nonce,
|
|
81
162
|
prompt: (
|
|
82
163
|
prompt ??
|
|
@@ -92,6 +173,13 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
92
173
|
}),
|
|
93
174
|
);
|
|
94
175
|
}),
|
|
176
|
+
signup: ({ properties } = {}) =>
|
|
177
|
+
kRunWebAPI(async () => {
|
|
178
|
+
await Kakao.API.request({
|
|
179
|
+
url: '/v1/user/signup',
|
|
180
|
+
data: filterNonNullishKeys({ properties }),
|
|
181
|
+
});
|
|
182
|
+
}),
|
|
95
183
|
logout: () =>
|
|
96
184
|
kRunWebAPI(async () => {
|
|
97
185
|
try {
|
|
@@ -226,15 +314,27 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
226
314
|
throw error;
|
|
227
315
|
}
|
|
228
316
|
}),
|
|
229
|
-
|
|
317
|
+
updateProfile: ({ properties }) =>
|
|
230
318
|
kRunWebAPI(async () => {
|
|
231
|
-
|
|
319
|
+
await Kakao.API.request({ url: '/v1/user/update_profile', data: { properties } });
|
|
320
|
+
}),
|
|
321
|
+
me: ({ secureResource = true } = {}) =>
|
|
322
|
+
kRunWebAPI(async () => {
|
|
323
|
+
const ret = camelCaseObject(
|
|
324
|
+
await Kakao.API.request({ url: '/v2/user/me', data: { secure_resource: secureResource } }),
|
|
325
|
+
) as {
|
|
232
326
|
id: number;
|
|
327
|
+
hasSignedUp?: boolean | null;
|
|
328
|
+
forPartner?: { uuid?: string };
|
|
329
|
+
groupUserToken?: string;
|
|
233
330
|
connectedAt?: string;
|
|
234
331
|
synchedAt?: string;
|
|
235
332
|
kakaoAccount?: Partial<KakaoUserProfile> & {
|
|
236
333
|
profile?: Partial<
|
|
237
|
-
Pick<
|
|
334
|
+
Pick<
|
|
335
|
+
KakaoUserProfile,
|
|
336
|
+
'nickname' | 'profileImageUrl' | 'thumbnailImageUrl' | 'isDefaultImage'
|
|
337
|
+
>
|
|
238
338
|
>;
|
|
239
339
|
};
|
|
240
340
|
properties?: { nickname?: string; profileImage?: string; thumbnailImage?: string };
|
|
@@ -242,9 +342,21 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
242
342
|
const kakaoAccount = ret.kakaoAccount ?? {};
|
|
243
343
|
const properties = ret.properties ?? {};
|
|
244
344
|
const profile = kakaoAccount.profile ?? {};
|
|
345
|
+
const legalGender = kakaoAccount.legalGender;
|
|
245
346
|
|
|
246
347
|
return {
|
|
247
348
|
id: ret.id,
|
|
349
|
+
hasSignedUp: ret.hasSignedUp ?? null,
|
|
350
|
+
uuid: ret.forPartner?.uuid ?? null,
|
|
351
|
+
groupUserToken: ret.groupUserToken ?? null,
|
|
352
|
+
isDefaultImage: profile.isDefaultImage ?? null,
|
|
353
|
+
isLeapMonth: kakaoAccount.isLeapMonth ?? null,
|
|
354
|
+
legalName: kakaoAccount.legalName ?? null,
|
|
355
|
+
legalNameNeedsAgreement: kakaoAccount.legalNameNeedsAgreement ?? null,
|
|
356
|
+
legalBirthDate: kakaoAccount.legalBirthDate ?? null,
|
|
357
|
+
legalBirthDateNeedsAgreement: kakaoAccount.legalBirthDateNeedsAgreement,
|
|
358
|
+
legalGender: legalGender === 'female' || legalGender === 'male' ? legalGender : null,
|
|
359
|
+
legalGenderNeedsAgreement: kakaoAccount.legalGenderNeedsAgreement ?? null,
|
|
248
360
|
email: kakaoAccount.email,
|
|
249
361
|
name: kakaoAccount.name,
|
|
250
362
|
nickname: profile.nickname ?? properties.nickname,
|
|
@@ -270,7 +382,6 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
270
382
|
nameNeedsAgreement: kakaoAccount.nameNeedsAgreement,
|
|
271
383
|
profileImageNeedsAgreement: kakaoAccount.profileImageNeedsAgreement,
|
|
272
384
|
profileNicknameNeedsAgreement: kakaoAccount.profileNicknameNeedsAgreement,
|
|
273
|
-
legalBirthDateNeedsAgreement: kakaoAccount.legalBirthDateNeedsAgreement,
|
|
274
385
|
connectedAt: isoToUnix(ret.connectedAt),
|
|
275
386
|
synchedAt: isoToUnix(ret.synchedAt),
|
|
276
387
|
} as KakaoUserProfile;
|
|
@@ -278,12 +389,17 @@ const KakaoUser: KakaoUserAPI = {
|
|
|
278
389
|
};
|
|
279
390
|
|
|
280
391
|
export const {
|
|
392
|
+
loginWithKakao,
|
|
393
|
+
refreshToken,
|
|
394
|
+
issueAccessTokenWithCode,
|
|
281
395
|
isKakaoTalkLoginAvailable,
|
|
282
396
|
isLogined,
|
|
283
397
|
hasToken,
|
|
284
398
|
login,
|
|
399
|
+
signup,
|
|
285
400
|
logout,
|
|
286
401
|
me,
|
|
402
|
+
updateProfile,
|
|
287
403
|
revokeScopes,
|
|
288
404
|
scopes,
|
|
289
405
|
serviceTerms,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TurboModule } from 'react-native';
|
|
2
2
|
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
4
|
|
|
4
5
|
import type {
|
|
5
6
|
KakaoAccessTokenInfo,
|
|
@@ -19,7 +20,27 @@ export interface Spec extends TurboModule {
|
|
|
19
20
|
useKakaoAccountLogin: boolean,
|
|
20
21
|
scopes?: string[],
|
|
21
22
|
nonce?: string,
|
|
23
|
+
loginHint?: string,
|
|
24
|
+
channelPublicIds?: string[],
|
|
25
|
+
androidRequestCode?: number,
|
|
22
26
|
): Promise<KakaoLoginToken>;
|
|
27
|
+
loginWithKakao(
|
|
28
|
+
uiMode: string,
|
|
29
|
+
orientation: string,
|
|
30
|
+
launchMethod: string,
|
|
31
|
+
prompts: string[],
|
|
32
|
+
loginHint?: string,
|
|
33
|
+
nonce?: string,
|
|
34
|
+
channelPublicIds?: string[],
|
|
35
|
+
serviceTerms?: string[],
|
|
36
|
+
): Promise<KakaoLoginToken>;
|
|
37
|
+
issueAccessTokenWithCode(
|
|
38
|
+
code: string,
|
|
39
|
+
codeVerifier?: string,
|
|
40
|
+
redirectUri?: string,
|
|
41
|
+
): Promise<KakaoLoginToken>;
|
|
42
|
+
refreshToken(token?: UnsafeObject, iosLoggingEnabled?: boolean): Promise<KakaoLoginToken>;
|
|
43
|
+
signup(properties?: UnsafeObject): Promise<void>;
|
|
23
44
|
logout(): Promise<void>;
|
|
24
45
|
unlink(): Promise<void>;
|
|
25
46
|
isLogined(): Promise<boolean>;
|
|
@@ -34,7 +55,8 @@ export interface Spec extends TurboModule {
|
|
|
34
55
|
pageSize?: number,
|
|
35
56
|
): Promise<KakaoShippingAddressResult>;
|
|
36
57
|
selectShippingAddress(): Promise<number>;
|
|
37
|
-
me(): Promise<KakaoUser>;
|
|
58
|
+
me(secureResource?: boolean): Promise<KakaoUser>;
|
|
59
|
+
updateProfile(properties: UnsafeObject): Promise<void>;
|
|
38
60
|
getAccessToken(): Promise<KakaoAccessTokenInfo>;
|
|
39
61
|
}
|
|
40
62
|
|