hyperapp-is 0.1.39 → 0.1.41
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/README.md
CHANGED
|
@@ -206,8 +206,9 @@ npm で非公開の関数 (実験用)は、解説に記載します
|
|
|
206
206
|
|
|
207
207
|
**services / google**
|
|
208
208
|
- [getGoogle](#getgoogle)
|
|
209
|
-
- [
|
|
209
|
+
- [getGoogleAuthResult](#getgoogleauthresult)
|
|
210
210
|
- [getAccessToken](#getaccesstoken)
|
|
211
|
+
- [GoogleAuth](#googleauth)
|
|
211
212
|
|
|
212
213
|
## source file / ソースファイル
|
|
213
214
|
|
|
@@ -1601,29 +1602,15 @@ export const getGoogle = async (): Promise<Google>
|
|
|
1601
1602
|
|
|
1602
1603
|
---
|
|
1603
1604
|
|
|
1604
|
-
###
|
|
1605
|
-
|
|
1605
|
+
### getGoogleAuthResult
|
|
1606
|
+
ユーザートークンから、ユーザー情報を取得する
|
|
1606
1607
|
|
|
1607
1608
|
```ts
|
|
1608
|
-
export const
|
|
1609
|
-
```
|
|
1610
|
-
|
|
1611
|
-
```ts
|
|
1612
|
-
export interface GoogleAuthConfig {
|
|
1613
|
-
clientId : string
|
|
1614
|
-
autoSelect?: boolean // default: true
|
|
1615
|
-
uxMode ?: "popup" | "redirect" // default: "popup"
|
|
1616
|
-
}
|
|
1617
|
-
```
|
|
1618
|
-
|
|
1619
|
-
- clientId : アプリケーションのID (https://console.cloud.google.com で作成)
|
|
1620
|
-
- autoSelect?: ユーザーが選択されていた場合、自動でログイン
|
|
1621
|
-
- uxMode ?: ポップアップ、もしくはリダイレクトでログインします
|
|
1622
|
-
|
|
1609
|
+
export const getGoogleAuthResult = (idToken: string): GoogleAuthResult
|
|
1623
1610
|
---
|
|
1624
1611
|
|
|
1625
1612
|
### getAccessToken
|
|
1626
|
-
Googleのaccess token を取得
|
|
1613
|
+
Googleのaccess token を取得
|
|
1627
1614
|
|
|
1628
1615
|
```ts
|
|
1629
1616
|
export const getAccessToken = (config: GetAccessTokenConfig): Promise<string>
|
|
@@ -1640,3 +1627,52 @@ export interface GetAccessTokenConfig {
|
|
|
1640
1627
|
- clientId: アプリケーションのID
|
|
1641
1628
|
- scope : スコープの配列
|
|
1642
1629
|
- prompt ?: ログイン制御 `none` の場合、先にログインしていなければエラーとなります
|
|
1630
|
+
|
|
1631
|
+
---
|
|
1632
|
+
|
|
1633
|
+
### GoogleAuth
|
|
1634
|
+
Google 認証をラップしたクラス
|
|
1635
|
+
|
|
1636
|
+
```ts
|
|
1637
|
+
interface GoogleAuthConfig {
|
|
1638
|
+
clientId : string
|
|
1639
|
+
autoSelect?: boolean // default: true
|
|
1640
|
+
uxMode ?: "popup" | "redirect" // default: "popup"
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
interface GoogleButtonOptions {
|
|
1644
|
+
renderButton?: HTMLElement
|
|
1645
|
+
theme ?: "outline" | "filled_blue" | "filled_black" // default: outline
|
|
1646
|
+
size ?: "large" | "medium" | "small" // default: medium
|
|
1647
|
+
text ?: "signin_with" | "signup_with" | "continue_with" // default: signin_with
|
|
1648
|
+
shape ?: "rectangular" | "pill" | "circle" | "square" // default: rectangular
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
interface GoogleAuthResult {
|
|
1652
|
+
idToken: string
|
|
1653
|
+
user : GoogleUser
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
interface GoogleUser {
|
|
1657
|
+
name : string
|
|
1658
|
+
email : string
|
|
1659
|
+
picture: string
|
|
1660
|
+
sub : string
|
|
1661
|
+
}
|
|
1662
|
+
```
|
|
1663
|
+
|
|
1664
|
+
```ts
|
|
1665
|
+
class GoogleAuth {
|
|
1666
|
+
constructor (config: GoogleAuthConfig, option?: GoogleButtonOptions)
|
|
1667
|
+
async initialize(): Promise<GoogleAuthResult | null>
|
|
1668
|
+
logout (hit: string): void
|
|
1669
|
+
}
|
|
1670
|
+
```
|
|
1671
|
+
|
|
1672
|
+
*MEMO*
|
|
1673
|
+
必ず一度だけ `initialize` を実行します
|
|
1674
|
+
プロンプトがスキップされた場合 `null` が返ります
|
|
1675
|
+
`logout` を実行したあとであれば `initialize` を再実行することが可能です
|
|
1676
|
+
`logout` 前に 2度 `initialize` を実行した場合は、エラーが発生します
|
|
1677
|
+
`logout` の `hit` は `email' か 'sub` を指定する必要があります
|
|
1678
|
+
|
|
@@ -13,4 +13,4 @@ export { Carousel, effect_InitCarousel } from "./animationView/carousel";
|
|
|
13
13
|
export type { ScrollMargin, MatrixState } from "./dom/utils";
|
|
14
14
|
export { getScrollMargin, getMatrixState } from "./dom/utils";
|
|
15
15
|
export type { GoogleAccountsId, GoogleTokenClient, GoogleAccountsOAuth2, GoogleAccounts, Google, GoogleAuthConfig, GoogleUser, GoogleAuthResult, GoogleScope, GetAccessTokenConfig } from "./services/google";
|
|
16
|
-
export { getGoogle, getGoogleAuthResult, getAccessToken,
|
|
16
|
+
export { getGoogle, getGoogleAuthResult, getAccessToken, GoogleAuth } from "./services/google";
|
|
@@ -7,4 +7,4 @@ export { progress_easing } from "./animation/easing";
|
|
|
7
7
|
export { createUnits, createRAFProperties, effect_RAFProperties } from "./animation/properties";
|
|
8
8
|
export { Carousel, effect_InitCarousel } from "./animationView/carousel";
|
|
9
9
|
export { getScrollMargin, getMatrixState } from "./dom/utils";
|
|
10
|
-
export { getGoogle, getGoogleAuthResult, getAccessToken,
|
|
10
|
+
export { getGoogle, getGoogleAuthResult, getAccessToken, GoogleAuth } from "./services/google";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Dispatch, Effect } from "hyperapp";
|
|
2
1
|
export type GoogleScope = "openid" | "email" | "profile" | "https://www.googleapis.com/auth/drive" | "https://www.googleapis.com/auth/drive.readonly" | "https://www.googleapis.com/auth/drive.file" | "https://www.googleapis.com/auth/drive.metadata.readonly" | "https://www.googleapis.com/auth/drive.appdata" | "https://www.googleapis.com/auth/calendar" | "https://www.googleapis.com/auth/calendar.readonly" | "https://www.googleapis.com/auth/calendar.events" | "https://www.googleapis.com/auth/calendar.events.readonly" | "https://www.googleapis.com/auth/gmail.readonly" | "https://www.googleapis.com/auth/gmail.modify" | "https://www.googleapis.com/auth/gmail.send" | "https://www.googleapis.com/auth/gmail.compose" | "https://www.googleapis.com/auth/gmail.labels" | "https://www.googleapis.com/auth/spreadsheets" | "https://www.googleapis.com/auth/spreadsheets.readonly" | "https://www.googleapis.com/auth/documents" | "https://www.googleapis.com/auth/documents.readonly" | "https://www.googleapis.com/auth/presentations" | "https://www.googleapis.com/auth/presentations.readonly" | "https://www.googleapis.com/auth/forms" | "https://www.googleapis.com/auth/forms.responses.readonly" | "https://www.googleapis.com/auth/youtube.readonly" | "https://www.googleapis.com/auth/youtube" | "https://www.googleapis.com/auth/youtube.upload" | "https://www.googleapis.com/auth/youtube.force-ssl" | "https://www.googleapis.com/auth/userinfo.email" | "https://www.googleapis.com/auth/userinfo.profile" | (string & {});
|
|
3
2
|
export interface GoogleAccountsId {
|
|
4
3
|
initialize(config: {
|
|
@@ -75,15 +74,17 @@ export declare const getGoogle: () => Promise<Google>;
|
|
|
75
74
|
*/
|
|
76
75
|
export declare const getGoogleAuthResult: (idToken: string) => GoogleAuthResult;
|
|
77
76
|
export declare const getAccessToken: (config: GetAccessTokenConfig) => Promise<string>;
|
|
78
|
-
|
|
79
|
-
config: GoogleAuthConfig;
|
|
77
|
+
interface GoogleButtonOptions {
|
|
80
78
|
renderButton?: HTMLElement;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
theme?: "outline" | "filled_blue" | "filled_black";
|
|
80
|
+
size?: "large" | "medium" | "small";
|
|
81
|
+
text?: "signin_with" | "signup_with" | "continue_with";
|
|
82
|
+
shape?: "rectangular" | "pill" | "circle" | "square";
|
|
83
|
+
}
|
|
84
|
+
export declare class GoogleAuth {
|
|
85
|
+
#private;
|
|
86
|
+
constructor(config: GoogleAuthConfig, options?: GoogleButtonOptions);
|
|
87
|
+
initialize(): Promise<GoogleAuthResult | null>;
|
|
88
|
+
logout(hint: string): void;
|
|
89
|
+
}
|
|
90
|
+
export {};
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// ========== ========== ========== ========== ==========
|
|
2
2
|
// import
|
|
3
3
|
// ========== ========== ========== ========== ==========
|
|
4
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
8
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
9
|
+
};
|
|
10
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
+
};
|
|
15
|
+
var _GoogleAuth_config, _GoogleAuth_options, _GoogleAuth_google, _GoogleAuth_initialized;
|
|
4
16
|
// ========== ========== ========== ========== ==========
|
|
5
17
|
// procedure
|
|
6
18
|
// ========== ========== ========== ========== ==========
|
|
@@ -99,53 +111,68 @@ export const getAccessToken = async (config) => {
|
|
|
99
111
|
tokenClient.requestAccessToken({ prompt }); // prompt == "none" のときには、事前にログインが必要
|
|
100
112
|
});
|
|
101
113
|
};
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
export class GoogleAuth {
|
|
115
|
+
// constructor
|
|
116
|
+
constructor(config, options) {
|
|
117
|
+
// field
|
|
118
|
+
_GoogleAuth_config.set(this, void 0);
|
|
119
|
+
_GoogleAuth_options.set(this, void 0);
|
|
120
|
+
_GoogleAuth_google.set(this, void 0);
|
|
121
|
+
_GoogleAuth_initialized.set(this, void 0);
|
|
122
|
+
__classPrivateFieldSet(this, _GoogleAuth_config, config, "f");
|
|
123
|
+
__classPrivateFieldSet(this, _GoogleAuth_options, options !== null && options !== void 0 ? options : {}, "f");
|
|
124
|
+
__classPrivateFieldSet(this, _GoogleAuth_initialized, false, "f");
|
|
125
|
+
}
|
|
126
|
+
// method: initialize
|
|
127
|
+
async initialize() {
|
|
128
|
+
var _a, _b, _c, _d, _e;
|
|
129
|
+
if (__classPrivateFieldGet(this, _GoogleAuth_initialized, "f")) {
|
|
130
|
+
throw new Error("Already initialized");
|
|
118
131
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
__classPrivateFieldSet(this, _GoogleAuth_initialized, true, "f");
|
|
133
|
+
__classPrivateFieldSet(this, _GoogleAuth_google, await getGoogle(), "f");
|
|
134
|
+
const client = __classPrivateFieldGet(this, _GoogleAuth_google, "f").accounts.id;
|
|
135
|
+
if ((_a = __classPrivateFieldGet(this, _GoogleAuth_options, "f")) === null || _a === void 0 ? void 0 : _a.renderButton) {
|
|
136
|
+
client.renderButton(__classPrivateFieldGet(this, _GoogleAuth_options, "f").renderButton, {
|
|
137
|
+
theme: (_b = __classPrivateFieldGet(this, _GoogleAuth_options, "f").theme) !== null && _b !== void 0 ? _b : "outline",
|
|
138
|
+
size: (_c = __classPrivateFieldGet(this, _GoogleAuth_options, "f").size) !== null && _c !== void 0 ? _c : "medium",
|
|
139
|
+
text: (_d = __classPrivateFieldGet(this, _GoogleAuth_options, "f").text) !== null && _d !== void 0 ? _d : "signin_with",
|
|
140
|
+
shape: (_e = __classPrivateFieldGet(this, _GoogleAuth_options, "f").shape) !== null && _e !== void 0 ? _e : "rectangular",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return new Promise(resolve => {
|
|
144
|
+
var _a, _b;
|
|
145
|
+
let resolved = false;
|
|
146
|
+
const callback = (response) => {
|
|
147
|
+
if (resolved)
|
|
148
|
+
return;
|
|
149
|
+
resolved = true;
|
|
150
|
+
resolve(getGoogleAuthResult(response.credential));
|
|
151
|
+
};
|
|
152
|
+
client.initialize({
|
|
153
|
+
client_id: __classPrivateFieldGet(this, _GoogleAuth_config, "f").clientId,
|
|
154
|
+
auto_select: (_a = __classPrivateFieldGet(this, _GoogleAuth_config, "f").autoSelect) !== null && _a !== void 0 ? _a : true,
|
|
155
|
+
ux_mode: (_b = __classPrivateFieldGet(this, _GoogleAuth_config, "f").uxMode) !== null && _b !== void 0 ? _b : "popup",
|
|
156
|
+
callback
|
|
157
|
+
});
|
|
158
|
+
client.prompt((notification) => {
|
|
159
|
+
if (!resolved && (notification.isNotDisplayed() ||
|
|
160
|
+
notification.isSkippedMoment())) {
|
|
161
|
+
resolved = true;
|
|
162
|
+
resolve(null);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
138
165
|
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
getGoogle().then(google => {
|
|
146
|
-
const client = google.accounts.id;
|
|
166
|
+
}
|
|
167
|
+
// method: logout
|
|
168
|
+
logout(hint) {
|
|
169
|
+
if (!__classPrivateFieldGet(this, _GoogleAuth_google, "f"))
|
|
170
|
+
return;
|
|
171
|
+
const client = __classPrivateFieldGet(this, _GoogleAuth_google, "f").accounts.id;
|
|
147
172
|
client.disableAutoSelect();
|
|
148
173
|
client.cancel();
|
|
149
174
|
client.revoke(hint, () => { });
|
|
150
|
-
|
|
151
|
-
}
|
|
175
|
+
__classPrivateFieldSet(this, _GoogleAuth_initialized, false, "f");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
_GoogleAuth_config = new WeakMap(), _GoogleAuth_options = new WeakMap(), _GoogleAuth_google = new WeakMap(), _GoogleAuth_initialized = new WeakMap();
|