Skip to content

Commit 1e486f8

Browse files
authored
chore: integrate docgen (#327)
* init docgen * better types for docgen * generate docgen
1 parent dece438 commit 1e486f8

File tree

4 files changed

+247
-16
lines changed

4 files changed

+247
-16
lines changed

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,112 @@ const config: CapacitorConfig = {
226226
export default config;
227227
```
228228

229+
## API
230+
231+
<docgen-index>
232+
233+
* [`initialize(...)`](#initialize)
234+
* [`signIn()`](#signin)
235+
* [`refresh()`](#refresh)
236+
* [`signOut()`](#signout)
237+
* [Interfaces](#interfaces)
238+
239+
</docgen-index>
240+
<docgen-api>
241+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
242+
243+
### initialize(...)
244+
245+
```typescript
246+
initialize(options?: InitOptions) => void
247+
```
248+
249+
Initializes the GoogleAuthPlugin, loading the gapi library and setting up the plugin.
250+
251+
| Param | Type | Description |
252+
| ------------- | --------------------------------------------------- | ---------------------------------- |
253+
| **`options`** | <code><a href="#initoptions">InitOptions</a></code> | - Optional initialization options. |
254+
255+
**Since:** 3.1.0
256+
257+
--------------------
258+
259+
260+
### signIn()
261+
262+
```typescript
263+
signIn() => Promise<User>
264+
```
265+
266+
Initiates the sign-in process and returns a Promise that resolves with the user information.
267+
268+
**Returns:** <code>Promise&lt;<a href="#user">User</a>&gt;</code>
269+
270+
--------------------
271+
272+
273+
### refresh()
274+
275+
```typescript
276+
refresh() => Promise<Authentication>
277+
```
278+
279+
Refreshes the authentication token and returns a Promise that resolves with the updated authentication details.
280+
281+
**Returns:** <code>Promise&lt;<a href="#authentication">Authentication</a>&gt;</code>
282+
283+
--------------------
284+
285+
286+
### signOut()
287+
288+
```typescript
289+
signOut() => Promise<any>
290+
```
291+
292+
Signs out the user and returns a Promise.
293+
294+
**Returns:** <code>Promise&lt;any&gt;</code>
295+
296+
--------------------
297+
298+
299+
### Interfaces
300+
301+
302+
#### InitOptions
303+
304+
| Prop | Type | Description | Default | Since |
305+
| ------------------------ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ----- |
306+
| **`clientId`** | <code>string</code> | The app's client ID, found and created in the Google Developers Console. Common for Android or iOS. The default is defined in the configuration. | | 3.1.0 |
307+
| **`scopes`** | <code>string[]</code> | Specifies the scopes required for accessing Google APIs The default is defined in the configuration. | | |
308+
| **`grantOfflineAccess`** | <code>boolean</code> | Set if your application needs to refresh access tokens when the user is not present at the browser. In response use `serverAuthCode` key | <code>false</code> | 3.1.0 |
309+
310+
311+
#### User
312+
313+
| Prop | Type | Description |
314+
| -------------------- | --------------------------------------------------------- | ------------------------------------------------------------------- |
315+
| **`id`** | <code>string</code> | The unique identifier for the user. |
316+
| **`email`** | <code>string</code> | The email address associated with the user. |
317+
| **`name`** | <code>string</code> | The user's full name. |
318+
| **`familyName`** | <code>string</code> | The family name (last name) of the user. |
319+
| **`givenName`** | <code>string</code> | The given name (first name) of the user. |
320+
| **`imageUrl`** | <code>string</code> | The URL of the user's profile picture. |
321+
| **`serverAuthCode`** | <code>string</code> | The server authentication code. |
322+
| **`authentication`** | <code><a href="#authentication">Authentication</a></code> | The authentication details including access, refresh and ID tokens. |
323+
324+
325+
#### Authentication
326+
327+
| Prop | Type | Description |
328+
| ------------------ | ------------------- | ------------------------------------------------ |
329+
| **`accessToken`** | <code>string</code> | The access token obtained during authentication. |
330+
| **`idToken`** | <code>string</code> | The ID token obtained during authentication. |
331+
| **`refreshToken`** | <code>string</code> | The refresh token. |
332+
333+
</docgen-api>
334+
229335
## Migration guide
230336

231337
#### Migrate from 3.2.x to 3.3.x

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
"watch": "tsc --watch",
1111
"prepublishOnly": "npm run build",
1212
"prepare": "tsc",
13-
"test": "echo \"no test specified\""
13+
"test": "echo \"no test specified\"",
14+
"docgen": "docgen --api GoogleAuthPlugin --output-readme README.md"
1415
},
1516
"author": "CodetrixStudio",
1617
"license": "MIT",
1718
"devDependencies": {
1819
"@capacitor/android": "^5.0.4",
1920
"@capacitor/cli": "^5.0.4",
2021
"@capacitor/core": "^5.0.4",
22+
"@capacitor/docgen": "^0.2.1",
2123
"@capacitor/ios": "^5.0.4",
2224
"@ionic/prettier-config": "^2.0.0",
2325
"@types/gapi": "0.0.42",
@@ -64,4 +66,4 @@
6466
"url": "https://github.com/CodetrixStudio/CapacitorGoogleAuth/issues"
6567
},
6668
"prettier": "@ionic/prettier-config"
67-
}
69+
}

src/definitions.ts

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,68 @@ declare module '@capacitor/cli' {
77
}
88

99
export interface User {
10+
/**
11+
* The unique identifier for the user.
12+
*/
1013
id: string;
14+
15+
/**
16+
* The email address associated with the user.
17+
*/
1118
email: string;
19+
1220
/**
13-
* @deprecated use `name` instead
21+
* The user's full name.
1422
*/
15-
displayName: string
1623
name: string;
24+
25+
/**
26+
* The family name (last name) of the user.
27+
*/
1728
familyName: string;
29+
30+
/**
31+
* The given name (first name) of the user.
32+
*/
1833
givenName: string;
34+
35+
/**
36+
* The URL of the user's profile picture.
37+
*/
1938
imageUrl: string;
2039

40+
/**
41+
* The server authentication code.
42+
*/
2143
serverAuthCode: string;
44+
45+
/**
46+
* The authentication details including access, refresh and ID tokens.
47+
*/
2248
authentication: Authentication;
2349
}
2450

2551
export interface Authentication {
52+
/**
53+
* The access token obtained during authentication.
54+
*/
2655
accessToken: string;
56+
57+
/**
58+
* The ID token obtained during authentication.
59+
*/
2760
idToken: string;
2861

2962
/**
30-
* refreshToken only for iOS and Android
63+
* The refresh token.
64+
* @warning This property is applicable only for mobile platforms (iOS and Android).
3165
*/
3266
refreshToken?: string;
3367
}
3468

3569
export interface GoogleAuthPluginOptions {
3670
/**
37-
* The app's client ID, found and created in the Google Developers Console.
71+
* The default app's client ID, found and created in the Google Developers Console.
3872
* common for Android or iOS
3973
* @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
4074
* @since 3.1.0
@@ -54,10 +88,10 @@ export interface GoogleAuthPluginOptions {
5488
androidClientId?: string;
5589

5690
/**
57-
* Scopes that you might need to request to access Google APIs
91+
* Specifies the default scopes required for accessing Google APIs.
5892
* @example ["profile", "email"]
59-
* @default []
60-
* @see @link https://developers.google.com/identity/protocols/oauth2/scopes
93+
* @default ["email", "profile", "openid"]
94+
* @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)
6195
*/
6296
scopes?: string[];
6397

@@ -75,25 +109,54 @@ export interface GoogleAuthPluginOptions {
75109
forceCodeForRefreshToken?: boolean;
76110
}
77111

78-
export interface InitOptions extends Pick<GoogleAuthPluginOptions, 'scopes' | 'clientId'> {
112+
export interface InitOptions {
113+
/**
114+
* The app's client ID, found and created in the Google Developers Console.
115+
* Common for Android or iOS.
116+
* The default is defined in the configuration.
117+
* @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
118+
* @since 3.1.0
119+
*/
120+
clientId?: string;
121+
122+
/**
123+
* Specifies the scopes required for accessing Google APIs
124+
* The default is defined in the configuration.
125+
* @example ["profile", "email"]
126+
* @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)
127+
*/
128+
scopes?: string[];
129+
79130
/**
80131
* Set if your application needs to refresh access tokens when the user is not present at the browser.
81132
* In response use `serverAuthCode` key
82133
*
83134
* @default false
84135
* @since 3.1.0
85136
* */
86-
grantOfflineAccess: boolean;
137+
grantOfflineAccess?: boolean;
87138
}
88139

89140
export interface GoogleAuthPlugin {
141+
/**
142+
* Initializes the GoogleAuthPlugin, loading the gapi library and setting up the plugin.
143+
* @param options - Optional initialization options.
144+
* @since 3.1.0
145+
*/
146+
initialize(options?: InitOptions): void;
147+
148+
/**
149+
* Initiates the sign-in process and returns a Promise that resolves with the user information.
150+
*/
90151
signIn(): Promise<User>;
152+
153+
/**
154+
* Refreshes the authentication token and returns a Promise that resolves with the updated authentication details.
155+
*/
91156
refresh(): Promise<Authentication>;
92-
signOut(): Promise<any>;
93157

94158
/**
95-
* Init hook for load gapi and init plugin
96-
* @since 3.1.0
97-
* */
98-
initialize(options?: Partial<InitOptions>): void;
159+
* Signs out the user and returns a Promise.
160+
*/
161+
signOut(): Promise<any>;
99162
}

0 commit comments

Comments
 (0)