hyperapp-is 0.1.37 → 0.1.38

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.
@@ -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, googleAuth, getAccessToken } from "./services/google";
16
+ export { getGoogle, getGoogleAuthResult, getAccessToken, effect_googleAuth, googleLogout } 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, googleAuth, getAccessToken } from "./services/google";
10
+ export { getGoogle, getGoogleAuthResult, getAccessToken, effect_googleAuth, googleLogout } from "./services/google";
@@ -1,3 +1,5 @@
1
+ import type { Dispatch, Effect } from "hyperapp";
2
+ 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 & {});
1
3
  export interface GoogleAccountsId {
2
4
  initialize(config: {
3
5
  client_id: string;
@@ -16,6 +18,8 @@ export interface GoogleAccountsId {
16
18
  text?: "signin_with" | "signup_with" | "continue_with";
17
19
  shape?: "rectangular" | "pill" | "circle" | "square";
18
20
  }): void;
21
+ revoke(hint: string, // email or sub
22
+ callback: () => void): void;
19
23
  }
20
24
  export interface GoogleTokenClient {
21
25
  requestAccessToken(options?: {
@@ -39,7 +43,6 @@ export interface GoogleAccounts {
39
43
  export interface Google {
40
44
  accounts: GoogleAccounts;
41
45
  }
42
- export declare const getGoogle: () => Promise<Google>;
43
46
  export interface GoogleAuthConfig {
44
47
  clientId: string;
45
48
  autoSelect?: boolean;
@@ -55,12 +58,33 @@ export interface GoogleAuthResult {
55
58
  idToken: string;
56
59
  user: GoogleUser;
57
60
  }
58
- export declare const getGoogleAuthResult: (idToken: string) => GoogleAuthResult;
59
- export declare const googleAuth: (config: GoogleAuthConfig) => Promise<GoogleAuthResult | null>;
60
- 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 & {});
61
61
  export interface GetAccessTokenConfig {
62
62
  clientId: string;
63
63
  scope: GoogleScope[];
64
64
  prompt?: "none" | "select_account" | "consent";
65
65
  }
66
+ /**
67
+ * Google 変数を取得する
68
+ */
69
+ export declare const getGoogle: () => Promise<Google>;
70
+ /**
71
+ * idToken から ユーザー情報を取得
72
+ *
73
+ * @param {string} idToken - ユーザートークン
74
+ * @returns {GoogleAuthResult}
75
+ */
76
+ export declare const getGoogleAuthResult: (idToken: string) => GoogleAuthResult;
66
77
  export declare const getAccessToken: (config: GetAccessTokenConfig) => Promise<string>;
78
+ export declare const effect_googleAuth: <S>(props: {
79
+ state: S;
80
+ config: GoogleAuthConfig;
81
+ renderButton?: HTMLElement;
82
+ renderOptions?: {
83
+ theme?: "outline" | "filled_blue" | "filled_black";
84
+ size?: "large" | "medium" | "small";
85
+ text?: "signin_with" | "signup_with" | "continue_with";
86
+ shape?: "rectangular" | "pill" | "circle" | "square";
87
+ };
88
+ onLoad: (state: S, res: GoogleAuthResult) => S | [S, Effect<S>];
89
+ }) => (dispatch: Dispatch<S>) => Promise<void>;
90
+ export declare const googleLogout: (hint: string) => void;
@@ -1,12 +1,17 @@
1
- // ---------- ---------- ----------
2
- // interface GoogleAccountsId
3
- // ---------- ---------- ----------
4
- // ---------- ---------- ----------
1
+ // ========== ========== ========== ========== ==========
2
+ // import
3
+ // ========== ========== ========== ========== ==========
4
+ // ========== ========== ========== ========== ==========
5
+ // procedure
6
+ // ========== ========== ========== ========== ==========
7
+ // ---------- ---------- ---------- ---------- ----------
5
8
  // getGoogle
6
- // ---------- ---------- ----------
9
+ // ---------- ---------- ---------- ---------- ----------
7
10
  // 2重読み込み防止用の変数
8
11
  let googlePromise = null;
9
- // google 変数を取得する
12
+ /**
13
+ * Google 変数を取得する
14
+ */
10
15
  export const getGoogle = async () => {
11
16
  if (window.google)
12
17
  return window.google;
@@ -37,6 +42,12 @@ export const getGoogle = async () => {
37
42
  // ---------- ---------- ---------- ---------- ----------
38
43
  // getGoogleAuthResult
39
44
  // ---------- ---------- ---------- ---------- ----------
45
+ /**
46
+ * idToken から ユーザー情報を取得
47
+ *
48
+ * @param {string} idToken - ユーザートークン
49
+ * @returns {GoogleAuthResult}
50
+ */
40
51
  export const getGoogleAuthResult = (idToken) => {
41
52
  const base64 = idToken.split(".")[1]
42
53
  .replace(/-/g, "+")
@@ -58,43 +69,6 @@ export const getGoogleAuthResult = (idToken) => {
58
69
  };
59
70
  };
60
71
  // ---------- ---------- ---------- ---------- ----------
61
- // googleAuth
62
- // ---------- ---------- ---------- ---------- ----------
63
- export const googleAuth = async (config) => {
64
- var _a, _b;
65
- // get google
66
- const google = await getGoogle();
67
- // variable
68
- const autoSelect = (_a = config.autoSelect) !== null && _a !== void 0 ? _a : true;
69
- const uxMode = (_b = config.uxMode) !== null && _b !== void 0 ? _b : "popup";
70
- // result
71
- return new Promise((resolve, reject) => {
72
- // get client
73
- const client = google.accounts.id;
74
- // initialize
75
- client.initialize({
76
- client_id: config.clientId,
77
- auto_select: autoSelect,
78
- ux_mode: uxMode,
79
- callback: (response) => {
80
- try {
81
- const idToken = response.credential;
82
- resolve(getGoogleAuthResult(idToken));
83
- }
84
- catch (error) {
85
- reject(error);
86
- }
87
- }
88
- }); // end initialize
89
- // show prompt
90
- client.prompt((notification) => {
91
- if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
92
- resolve(null);
93
- }
94
- });
95
- }); // end result
96
- };
97
- // ---------- ---------- ---------- ---------- ----------
98
72
  // getAccessToken
99
73
  // ---------- ---------- ---------- ---------- ----------
100
74
  export const getAccessToken = async (config) => {
@@ -125,3 +99,53 @@ export const getAccessToken = async (config) => {
125
99
  tokenClient.requestAccessToken({ prompt }); // prompt == "none" のときには、事前にログインが必要
126
100
  });
127
101
  };
102
+ // ========== ========== ========== ========== ==========
103
+ // effect
104
+ // ========== ========== ========== ========== ==========
105
+ // ---------- ---------- ---------- ---------- ----------
106
+ // effect_googleAuth
107
+ // ---------- ---------- ---------- ---------- ----------
108
+ export const effect_googleAuth = function (props) {
109
+ // variable
110
+ const { state, config, renderButton, renderOptions, onLoad } = props;
111
+ // result
112
+ return async (dispatch) => {
113
+ // get google api
114
+ const google = await getGoogle();
115
+ // set renderButton
116
+ if (renderButton) {
117
+ google.accounts.id.renderButton(renderButton, renderOptions);
118
+ }
119
+ // get client
120
+ const client = google.accounts.id;
121
+ // initialize
122
+ client.initialize({
123
+ client_id: config.clientId,
124
+ auto_select: config.autoSelect,
125
+ ux_mode: config.uxMode,
126
+ callback: (response) => {
127
+ dispatch((state) => onLoad(state, getGoogleAuthResult(response.credential)));
128
+ }
129
+ });
130
+ // show prompt
131
+ client.prompt((notification) => {
132
+ if (notification.isNotDisplayed()) {
133
+ console.log("Google prompt not displayed");
134
+ }
135
+ if (notification.isSkippedMoment()) {
136
+ console.log("Google prompt skipped");
137
+ }
138
+ });
139
+ }; // end result
140
+ };
141
+ // ---------- ---------- ---------- ---------- ----------
142
+ // googleLogout
143
+ // ---------- ---------- ---------- ---------- ----------
144
+ export const googleLogout = (hint) => {
145
+ getGoogle().then(google => {
146
+ const client = google.accounts.id;
147
+ client.disableAutoSelect();
148
+ client.cancel();
149
+ client.revoke(hint, () => { });
150
+ });
151
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperapp-is",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "UI foundation library for Hyperapp by is4416",
5
5
  "license": "MIT",
6
6
  "type": "module",