@gasboost/auth 0.2.0 → 0.3.0

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
@@ -526,60 +526,6 @@ const pepper =
526
526
  PropertiesService.getScriptProperties().getProperty("AUTH_PEPPER");
527
527
  ```
528
528
 
529
- ## `@gasboost/app` との連携
530
-
531
- `AppsScriptAuth` は、RPC 登録用の handler collection を `auth.handlers` として公開します。
532
-
533
- `@gasboost/app` の `.calls()` にそのまま渡すことで、認証用 RPC を一括登録できます。
534
-
535
- ```ts
536
- import { AppsScript } from "@gasboost/app";
537
- import { AppsScriptAuth } from "@gasboost/auth";
538
-
539
- const auth = new AppsScriptAuth({
540
- repository,
541
- runtime,
542
- session: {
543
- storageType: "cache",
544
- },
545
- emailPassword: {
546
- enabled: true,
547
- pepper: "your-secret-pepper",
548
- },
549
- appsScript: {
550
- enabled: true,
551
- },
552
- });
553
-
554
- const app = new AppsScript().calls(auth.handlers);
555
-
556
- export default app;
557
- ```
558
-
559
- 以下の RPC が登録されます。
560
-
561
- - `signInEmail`
562
- - `signInAppsScript`
563
- - `signUpEmail`
564
- - `signUpAppsScript`
565
- - `getSession`
566
- - `signOut`
567
-
568
- `InferAppsScript` を利用するクライアントでは、これらの RPC がそのまま型推論されます。
569
-
570
- ```ts
571
- client.signInEmail({
572
- email: "user@example.com",
573
- password: "password",
574
- });
575
-
576
- client.getSession("session-id");
577
-
578
- client.signOut("session-id");
579
- ```
580
-
581
- RPC endpoint 名は `@gasboost/auth` 側で管理されるため、利用側で個別に `.call()` を記述したり、endpoint 名を重複定義したりする必要はありません。
582
-
583
529
  ## Testing
584
530
 
585
531
  GAS API を利用するテストでは `gasboost/fake` を使用できます。
@@ -26,28 +26,15 @@ type AppsScriptAuthConfig<TEmailPassword extends EmailPasswordAuthOptions | unde
26
26
  appsScript?: AppsScriptAuthenticationOptions;
27
27
  hooks?: AuthHooks<THookResult>;
28
28
  };
29
- type BaseHandlers<THookResult> = {
30
- signInEmail: AppsScriptAuthSignIn<THookResult>["email"];
31
- signInAppsScript: AppsScriptAuthSignIn<THookResult>["appsScript"];
32
- signUpEmail: AppsScriptAuthSignUp["email"];
33
- signUpAppsScript: AppsScriptAuthSignUp["appsScript"];
34
- getSession: AppsScriptAuthSession["get"];
35
- signOut: AppsScriptAuthSignOut["execute"];
36
- };
37
- type PasswordHandlers = {
38
- forgotPassword: AppsScriptAuthPassword["forgot"];
39
- resetPassword: AppsScriptAuthPassword["reset"];
40
- };
41
- type AppsScriptAuthHandlers<TEmailPassword, THookResult> = TEmailPassword extends {
29
+ type AppsScriptAuthPasswordApi<TEmailPassword> = TEmailPassword extends {
42
30
  passwordReset: unknown;
43
- } ? BaseHandlers<THookResult> & PasswordHandlers : BaseHandlers<THookResult>;
31
+ } ? AppsScriptAuthPassword : undefined;
44
32
  export declare class AppsScriptAuth<TEmailPassword extends EmailPasswordAuthOptions | undefined = undefined, THookResult = undefined> {
45
33
  readonly signIn: AppsScriptAuthSignIn<THookResult>;
46
34
  readonly signUp: AppsScriptAuthSignUp;
47
35
  readonly session: AppsScriptAuthSession;
48
36
  readonly signOut: AppsScriptAuthSignOut;
49
- readonly password: AppsScriptAuthPassword | undefined;
37
+ readonly password: AppsScriptAuthPasswordApi<TEmailPassword>;
50
38
  constructor({ repository, session, runtime, emailPassword, appsScript, hooks, }: AppsScriptAuthConfig<TEmailPassword, THookResult>);
51
- get handlers(): AppsScriptAuthHandlers<TEmailPassword, THookResult>;
52
39
  }
53
40
  export {};
@@ -51,32 +51,12 @@ export class AppsScriptAuth {
51
51
  sessionStorage,
52
52
  });
53
53
  this.signOut = new AppsScriptAuthSignOut(sessionStorage);
54
- if (emailPasswordConfig?.passwordReset) {
55
- this.password = new AppsScriptAuthPassword({
54
+ this.password = (emailPasswordConfig?.passwordReset
55
+ ? new AppsScriptAuthPassword({
56
56
  repository,
57
57
  utilities: runtime.utilities,
58
58
  emailPassword: emailPasswordConfig,
59
- });
60
- }
61
- else {
62
- this.password = undefined;
63
- }
64
- }
65
- get handlers() {
66
- const handlers = {
67
- signInEmail: this.signIn.email,
68
- signInAppsScript: this.signIn.appsScript,
69
- signUpEmail: this.signUp.email,
70
- signUpAppsScript: this.signUp.appsScript,
71
- getSession: this.session.get.bind(this.session),
72
- signOut: this.signOut.execute.bind(this.signOut),
73
- ...(this.password
74
- ? {
75
- forgotPassword: this.password.forgot.bind(this.password),
76
- resetPassword: this.password.reset.bind(this.password),
77
- }
78
- : {}),
79
- };
80
- return handlers;
59
+ })
60
+ : undefined);
81
61
  }
82
62
  }
@@ -58,7 +58,45 @@ export type AuthSchema = {
58
58
  };
59
59
  };
60
60
  };
61
- export declare class AuthSchemaConfig {
62
- readonly schema: AuthSchema;
63
- constructor(options?: AuthSchemaOptions);
61
+ type Section<O, K extends PropertyKey> = K extends keyof O ? O[K] : undefined;
62
+ type Fields<T> = [T] extends [null | undefined] ? undefined : "fields" extends keyof NonNullable<T> ? NonNullable<T>["fields"] : undefined;
63
+ type PropertyOrDefault<T, K extends PropertyKey, Default extends string> = [
64
+ T
65
+ ] extends [null | undefined] ? Default : K extends keyof NonNullable<T> ? Exclude<NonNullable<T>[K], undefined> extends infer Value ? [Value] extends [never] ? Default : Value extends string ? Value : Default : Default : Default;
66
+ type ResolveAuthSchema<O extends AuthSchemaOptions> = {
67
+ dbId: O["dbId"];
68
+ user: {
69
+ modelName: PropertyOrDefault<Section<O, "user">, "modelName", "user">;
70
+ fields: {
71
+ id: PropertyOrDefault<Fields<Section<O, "user">>, "id", "id">;
72
+ name: PropertyOrDefault<Fields<Section<O, "user">>, "name", "name">;
73
+ };
74
+ };
75
+ account: {
76
+ modelName: PropertyOrDefault<Section<O, "account">, "modelName", "account">;
77
+ fields: {
78
+ id: PropertyOrDefault<Fields<Section<O, "account">>, "id", "id">;
79
+ userId: PropertyOrDefault<Fields<Section<O, "account">>, "userId", "userId">;
80
+ provider: PropertyOrDefault<Fields<Section<O, "account">>, "provider", "provider">;
81
+ providerAccountId: PropertyOrDefault<Fields<Section<O, "account">>, "providerAccountId", "providerAccountId">;
82
+ passwordHash: PropertyOrDefault<Fields<Section<O, "account">>, "passwordHash", "passwordHash">;
83
+ };
84
+ };
85
+ passwordReset: {
86
+ modelName: PropertyOrDefault<Section<O, "passwordReset">, "modelName", "passwordReset">;
87
+ fields: {
88
+ id: PropertyOrDefault<Fields<Section<O, "passwordReset">>, "id", "id">;
89
+ accountId: PropertyOrDefault<Fields<Section<O, "passwordReset">>, "accountId", "accountId">;
90
+ tokenHash: PropertyOrDefault<Fields<Section<O, "passwordReset">>, "tokenHash", "tokenHash">;
91
+ expiresAt: PropertyOrDefault<Fields<Section<O, "passwordReset">>, "expiresAt", "expiresAt">;
92
+ enabled: PropertyOrDefault<Fields<Section<O, "passwordReset">>, "enabled", "enabled">;
93
+ };
94
+ };
95
+ };
96
+ export declare class AuthSchemaConfig<const O extends AuthSchemaOptions = {
97
+ dbId: "";
98
+ }> {
99
+ readonly schema: ResolveAuthSchema<O>;
100
+ constructor(options?: O);
64
101
  }
102
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasboost/auth",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Modern authentication for Google Apps Script with email/password, Apps Script authentication, sessions, and password reset.",
5
5
  "keywords": [
6
6
  "google-apps-script",
@@ -39,7 +39,6 @@
39
39
  "access": "public"
40
40
  },
41
41
  "devDependencies": {
42
- "@gasboost/app": "^1.3.0",
43
42
  "@gasboost/fake-core": "^0.1.2",
44
43
  "@gasboost/fake-node": "^0.1.2",
45
44
  "@types/google-apps-script": "^2.0.13"