@krak-stack/auth 0.1.11 → 0.1.13

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.
@@ -1,6 +1,6 @@
1
1
  import { HttpApi, OpenApi } from "effect/unstable/httpapi";
2
2
  import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
3
- import { GetSessionResponse, TooManyRequests, } from "./schema";
3
+ import { GetSessionResponse, TooManyRequests } from "./schema";
4
4
  export const BetterAuthApiGroup = HttpApiGroup.make("betterAuth")
5
5
  .add(HttpApiEndpoint.get("getSession", "/get-session", {
6
6
  success: GetSessionResponse,
package/dist/client.d.ts CHANGED
@@ -1,19 +1,11 @@
1
- import { Context, Effect, Layer, Redacted } from "effect";
1
+ import { Context, Effect, Layer } from "effect";
2
2
  import { HttpClient } from "effect/unstable/http";
3
3
  import { HttpApiClient } from "effect/unstable/httpapi";
4
- declare const AuthClientConfig_base: Context.ServiceClass<AuthClientConfig, "@krak-stack/auth/AuthClientConfig", {
5
- baseUrl: string;
6
- apiKey: Redacted.Redacted<string>;
7
- }> & {
8
- readonly make: Effect.Effect<{
9
- baseUrl: string;
10
- apiKey: Redacted.Redacted<string>;
11
- }, import("effect/Config").ConfigError, never>;
4
+ import { AuthClientConfig, type ClientConfig } from "./config";
5
+ export type AuthClientLayerOptions = Partial<ClientConfig> & {
6
+ readonly headers?: Record<string, string>;
12
7
  };
13
- export declare class AuthClientConfig extends AuthClientConfig_base {
14
- static readonly layer: Layer.Layer<AuthClientConfig, import("effect/Config").ConfigError, never>;
15
- }
16
- declare const AuthClient_base: Context.ServiceClass<AuthClient, "@krak-stack/auth/AuthClient", {
8
+ declare const AuthApiClients_base: Context.ServiceClass<AuthApiClients, "@krak-stack/auth/AuthApiClients", {
17
9
  server: {
18
10
  listOrganizations: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
19
11
  readonly query: {
@@ -516,7 +508,509 @@ declare const AuthClient_base: Context.ServiceClass<AuthClient, "@krak-stack/aut
516
508
  } | null, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./better-auth").TooManyRequests | import("effect/unstable/httpapi/HttpApiError").BadRequest | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").Forbidden | import("effect/unstable/httpapi/HttpApiError").NotFound | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
517
509
  }, never, AuthClientConfig | HttpClient.HttpClient>;
518
510
  };
511
+ export declare class AuthApiClients extends AuthApiClients_base {
512
+ static readonly layer: (options?: AuthClientLayerOptions) => Layer.Layer<AuthApiClients, import("effect/Config").ConfigError, never>;
513
+ }
514
+ declare const AuthClient_base: Context.ServiceClass<AuthClient, "@krak-stack/auth/AuthClient", {
515
+ getSession: () => Effect.Effect<{
516
+ readonly session: {
517
+ readonly id: string;
518
+ readonly expiresAt: Date;
519
+ readonly token: string;
520
+ readonly createdAt: Date;
521
+ readonly updatedAt: Date;
522
+ readonly userId: string;
523
+ readonly ipAddress?: string | null | undefined;
524
+ readonly userAgent?: string | null | undefined;
525
+ readonly impersonatedBy?: string | null | undefined;
526
+ readonly activeOrganizationId?: string | null | undefined;
527
+ };
528
+ readonly user: {
529
+ readonly id: string;
530
+ readonly name: string;
531
+ readonly email: string;
532
+ readonly emailVerified: boolean;
533
+ readonly image: string | null;
534
+ readonly role: string | null;
535
+ readonly banned: boolean | null;
536
+ readonly createdAt: Date;
537
+ readonly updatedAt: Date;
538
+ };
539
+ } | null, unknown, never>;
540
+ server: {
541
+ listOrganizations: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
542
+ readonly query: {
543
+ readonly ids?: string | undefined;
544
+ readonly userId?: string | undefined;
545
+ };
546
+ readonly responseMode?: Mode;
547
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
548
+ readonly data: readonly {
549
+ readonly id: string;
550
+ readonly name: string;
551
+ readonly slug: string;
552
+ readonly logo: string | null;
553
+ readonly metadata: {
554
+ readonly translations: readonly {
555
+ readonly locale: "en" | "fr";
556
+ readonly name: string;
557
+ readonly logo: string | null;
558
+ readonly contactEmail: string | null;
559
+ readonly location: string | null;
560
+ }[];
561
+ } | null;
562
+ readonly createdAt: Date;
563
+ }[];
564
+ readonly missingIds: readonly string[];
565
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").BadRequest | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
566
+ getOrganization: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
567
+ readonly params: {
568
+ readonly id: string;
569
+ };
570
+ readonly responseMode?: Mode;
571
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
572
+ readonly id: string;
573
+ readonly name: string;
574
+ readonly slug: string;
575
+ readonly logo: string | null;
576
+ readonly metadata: {
577
+ readonly translations: readonly {
578
+ readonly locale: "en" | "fr";
579
+ readonly name: string;
580
+ readonly logo: string | null;
581
+ readonly contactEmail: string | null;
582
+ readonly location: string | null;
583
+ }[];
584
+ } | null;
585
+ readonly createdAt: Date;
586
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").NotFound | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
587
+ getActiveMember: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
588
+ readonly params: {
589
+ readonly organizationId: string;
590
+ readonly userId: string;
591
+ };
592
+ readonly responseMode?: Mode;
593
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
594
+ readonly id: string;
595
+ readonly organizationId: string;
596
+ readonly userId: string;
597
+ readonly role: string;
598
+ readonly createdAt: Date;
599
+ readonly user: {
600
+ readonly id: string;
601
+ readonly name: string;
602
+ readonly email: string;
603
+ readonly emailVerified: boolean;
604
+ readonly image: string | null;
605
+ readonly role: string | null;
606
+ readonly banned: boolean | null;
607
+ readonly createdAt: Date;
608
+ readonly updatedAt: Date;
609
+ };
610
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").NotFound | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
611
+ listOrganizationMembers: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
612
+ readonly params: {
613
+ readonly organizationId: string;
614
+ };
615
+ readonly responseMode?: Mode;
616
+ }) => Effect.Effect<HttpApiClient.Client.Response<readonly {
617
+ readonly id: string;
618
+ readonly organizationId: string;
619
+ readonly userId: string;
620
+ readonly role: string;
621
+ readonly createdAt: Date;
622
+ readonly user: {
623
+ readonly id: string;
624
+ readonly name: string;
625
+ readonly email: string;
626
+ readonly emailVerified: boolean;
627
+ readonly image: string | null;
628
+ readonly role: string | null;
629
+ readonly banned: boolean | null;
630
+ readonly createdAt: Date;
631
+ readonly updatedAt: Date;
632
+ };
633
+ }[], Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
634
+ listUsersByIds: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
635
+ readonly query: {
636
+ readonly ids: string;
637
+ };
638
+ readonly responseMode?: Mode;
639
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
640
+ readonly data: readonly {
641
+ readonly id: string;
642
+ readonly name: string;
643
+ readonly email: string;
644
+ readonly emailVerified: boolean;
645
+ readonly image: string | null;
646
+ readonly role: string | null;
647
+ readonly banned: boolean | null;
648
+ readonly createdAt: Date;
649
+ readonly updatedAt: Date;
650
+ }[];
651
+ readonly missingIds: readonly string[];
652
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
653
+ getUser: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
654
+ readonly params: {
655
+ readonly id: string;
656
+ };
657
+ readonly responseMode?: Mode;
658
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
659
+ readonly id: string;
660
+ readonly name: string;
661
+ readonly email: string;
662
+ readonly emailVerified: boolean;
663
+ readonly image: string | null;
664
+ readonly role: string | null;
665
+ readonly banned: boolean | null;
666
+ readonly createdAt: Date;
667
+ readonly updatedAt: Date;
668
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").NotFound | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
669
+ getUserActiveOrganization: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
670
+ readonly params: {
671
+ readonly userId: string;
672
+ };
673
+ readonly responseMode?: Mode;
674
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
675
+ readonly id: string | null;
676
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
677
+ };
678
+ extra: {
679
+ readonly setPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
680
+ readonly payload: {
681
+ readonly newPassword: string;
682
+ };
683
+ readonly responseMode?: Mode;
684
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
685
+ readonly ok: boolean;
686
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
687
+ readonly verifyPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
688
+ readonly payload: {
689
+ readonly password: string;
690
+ };
691
+ readonly responseMode?: Mode;
692
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
693
+ readonly ok: boolean;
694
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
695
+ readonly createApiKey: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
696
+ readonly payload: {
697
+ readonly configId: "user" | "organization" | "service";
698
+ readonly name?: string | undefined;
699
+ readonly organizationId?: string | undefined;
700
+ readonly permissions?: {
701
+ readonly [x: string]: readonly string[];
702
+ } | undefined;
703
+ };
704
+ readonly responseMode?: Mode;
705
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
706
+ readonly id: string;
707
+ readonly key: string;
708
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
709
+ readonly verifyApiKey: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
710
+ readonly payload: {
711
+ readonly key: string;
712
+ readonly configId?: "user" | "organization" | "service" | undefined;
713
+ readonly permissions?: {
714
+ readonly [x: string]: readonly string[];
715
+ } | undefined;
716
+ };
717
+ readonly responseMode?: Mode;
718
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
719
+ readonly valid: boolean;
720
+ readonly error: {
721
+ readonly message: string;
722
+ readonly code: string;
723
+ } | null;
724
+ readonly key: {
725
+ readonly id: string;
726
+ readonly configId: string;
727
+ readonly name: string | null;
728
+ readonly start: string | null;
729
+ readonly prefix: string | null;
730
+ readonly referenceId: string;
731
+ readonly enabled: boolean | null;
732
+ readonly expiresAt: Date | null;
733
+ readonly createdAt: Date;
734
+ readonly updatedAt: Date;
735
+ readonly permissions: {
736
+ readonly [x: string]: readonly string[];
737
+ } | null;
738
+ readonly metadata: unknown;
739
+ } | null;
740
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
741
+ readonly presignUserImageUpload: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
742
+ readonly payload: {
743
+ readonly fileName: string;
744
+ readonly contentType: string;
745
+ };
746
+ readonly responseMode?: Mode;
747
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
748
+ readonly uploadUrl: string;
749
+ readonly url: string;
750
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
751
+ readonly presign: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
752
+ readonly payload: {
753
+ readonly fileName: string;
754
+ readonly contentType: string;
755
+ };
756
+ readonly responseMode?: Mode;
757
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
758
+ readonly uploadUrl: string;
759
+ readonly url: string;
760
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").BadRequest | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").Forbidden | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
761
+ };
762
+ }> & {
763
+ readonly make: (headers?: Record<string, string>) => Effect.Effect<{
764
+ getSession: () => Effect.Effect<{
765
+ readonly session: {
766
+ readonly id: string;
767
+ readonly expiresAt: Date;
768
+ readonly token: string;
769
+ readonly createdAt: Date;
770
+ readonly updatedAt: Date;
771
+ readonly userId: string;
772
+ readonly ipAddress?: string | null | undefined;
773
+ readonly userAgent?: string | null | undefined;
774
+ readonly impersonatedBy?: string | null | undefined;
775
+ readonly activeOrganizationId?: string | null | undefined;
776
+ };
777
+ readonly user: {
778
+ readonly id: string;
779
+ readonly name: string;
780
+ readonly email: string;
781
+ readonly emailVerified: boolean;
782
+ readonly image: string | null;
783
+ readonly role: string | null;
784
+ readonly banned: boolean | null;
785
+ readonly createdAt: Date;
786
+ readonly updatedAt: Date;
787
+ };
788
+ } | null, unknown, never>;
789
+ server: {
790
+ listOrganizations: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
791
+ readonly query: {
792
+ readonly ids?: string | undefined;
793
+ readonly userId?: string | undefined;
794
+ };
795
+ readonly responseMode?: Mode;
796
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
797
+ readonly data: readonly {
798
+ readonly id: string;
799
+ readonly name: string;
800
+ readonly slug: string;
801
+ readonly logo: string | null;
802
+ readonly metadata: {
803
+ readonly translations: readonly {
804
+ readonly locale: "en" | "fr";
805
+ readonly name: string;
806
+ readonly logo: string | null;
807
+ readonly contactEmail: string | null;
808
+ readonly location: string | null;
809
+ }[];
810
+ } | null;
811
+ readonly createdAt: Date;
812
+ }[];
813
+ readonly missingIds: readonly string[];
814
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").BadRequest | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
815
+ getOrganization: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
816
+ readonly params: {
817
+ readonly id: string;
818
+ };
819
+ readonly responseMode?: Mode;
820
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
821
+ readonly id: string;
822
+ readonly name: string;
823
+ readonly slug: string;
824
+ readonly logo: string | null;
825
+ readonly metadata: {
826
+ readonly translations: readonly {
827
+ readonly locale: "en" | "fr";
828
+ readonly name: string;
829
+ readonly logo: string | null;
830
+ readonly contactEmail: string | null;
831
+ readonly location: string | null;
832
+ }[];
833
+ } | null;
834
+ readonly createdAt: Date;
835
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").NotFound | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
836
+ getActiveMember: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
837
+ readonly params: {
838
+ readonly organizationId: string;
839
+ readonly userId: string;
840
+ };
841
+ readonly responseMode?: Mode;
842
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
843
+ readonly id: string;
844
+ readonly organizationId: string;
845
+ readonly userId: string;
846
+ readonly role: string;
847
+ readonly createdAt: Date;
848
+ readonly user: {
849
+ readonly id: string;
850
+ readonly name: string;
851
+ readonly email: string;
852
+ readonly emailVerified: boolean;
853
+ readonly image: string | null;
854
+ readonly role: string | null;
855
+ readonly banned: boolean | null;
856
+ readonly createdAt: Date;
857
+ readonly updatedAt: Date;
858
+ };
859
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").NotFound | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
860
+ listOrganizationMembers: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
861
+ readonly params: {
862
+ readonly organizationId: string;
863
+ };
864
+ readonly responseMode?: Mode;
865
+ }) => Effect.Effect<HttpApiClient.Client.Response<readonly {
866
+ readonly id: string;
867
+ readonly organizationId: string;
868
+ readonly userId: string;
869
+ readonly role: string;
870
+ readonly createdAt: Date;
871
+ readonly user: {
872
+ readonly id: string;
873
+ readonly name: string;
874
+ readonly email: string;
875
+ readonly emailVerified: boolean;
876
+ readonly image: string | null;
877
+ readonly role: string | null;
878
+ readonly banned: boolean | null;
879
+ readonly createdAt: Date;
880
+ readonly updatedAt: Date;
881
+ };
882
+ }[], Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
883
+ listUsersByIds: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
884
+ readonly query: {
885
+ readonly ids: string;
886
+ };
887
+ readonly responseMode?: Mode;
888
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
889
+ readonly data: readonly {
890
+ readonly id: string;
891
+ readonly name: string;
892
+ readonly email: string;
893
+ readonly emailVerified: boolean;
894
+ readonly image: string | null;
895
+ readonly role: string | null;
896
+ readonly banned: boolean | null;
897
+ readonly createdAt: Date;
898
+ readonly updatedAt: Date;
899
+ }[];
900
+ readonly missingIds: readonly string[];
901
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
902
+ getUser: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
903
+ readonly params: {
904
+ readonly id: string;
905
+ };
906
+ readonly responseMode?: Mode;
907
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
908
+ readonly id: string;
909
+ readonly name: string;
910
+ readonly email: string;
911
+ readonly emailVerified: boolean;
912
+ readonly image: string | null;
913
+ readonly role: string | null;
914
+ readonly banned: boolean | null;
915
+ readonly createdAt: Date;
916
+ readonly updatedAt: Date;
917
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").NotFound | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
918
+ getUserActiveOrganization: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
919
+ readonly params: {
920
+ readonly userId: string;
921
+ };
922
+ readonly responseMode?: Mode;
923
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
924
+ readonly id: string | null;
925
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
926
+ };
927
+ extra: {
928
+ readonly setPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
929
+ readonly payload: {
930
+ readonly newPassword: string;
931
+ };
932
+ readonly responseMode?: Mode;
933
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
934
+ readonly ok: boolean;
935
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
936
+ readonly verifyPassword: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
937
+ readonly payload: {
938
+ readonly password: string;
939
+ };
940
+ readonly responseMode?: Mode;
941
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
942
+ readonly ok: boolean;
943
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
944
+ readonly createApiKey: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
945
+ readonly payload: {
946
+ readonly configId: "user" | "organization" | "service";
947
+ readonly name?: string | undefined;
948
+ readonly organizationId?: string | undefined;
949
+ readonly permissions?: {
950
+ readonly [x: string]: readonly string[];
951
+ } | undefined;
952
+ };
953
+ readonly responseMode?: Mode;
954
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
955
+ readonly id: string;
956
+ readonly key: string;
957
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
958
+ readonly verifyApiKey: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
959
+ readonly payload: {
960
+ readonly key: string;
961
+ readonly configId?: "user" | "organization" | "service" | undefined;
962
+ readonly permissions?: {
963
+ readonly [x: string]: readonly string[];
964
+ } | undefined;
965
+ };
966
+ readonly responseMode?: Mode;
967
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
968
+ readonly valid: boolean;
969
+ readonly error: {
970
+ readonly message: string;
971
+ readonly code: string;
972
+ } | null;
973
+ readonly key: {
974
+ readonly id: string;
975
+ readonly configId: string;
976
+ readonly name: string | null;
977
+ readonly start: string | null;
978
+ readonly prefix: string | null;
979
+ readonly referenceId: string;
980
+ readonly enabled: boolean | null;
981
+ readonly expiresAt: Date | null;
982
+ readonly createdAt: Date;
983
+ readonly updatedAt: Date;
984
+ readonly permissions: {
985
+ readonly [x: string]: readonly string[];
986
+ } | null;
987
+ readonly metadata: unknown;
988
+ } | null;
989
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
990
+ readonly presignUserImageUpload: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
991
+ readonly payload: {
992
+ readonly fileName: string;
993
+ readonly contentType: string;
994
+ };
995
+ readonly responseMode?: Mode;
996
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
997
+ readonly uploadUrl: string;
998
+ readonly url: string;
999
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").InternalServerError | import("./extra").ExtraBadRequest), [Mode] extends ["response-only"] ? never : never>;
1000
+ readonly presign: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
1001
+ readonly payload: {
1002
+ readonly fileName: string;
1003
+ readonly contentType: string;
1004
+ };
1005
+ readonly responseMode?: Mode;
1006
+ }) => Effect.Effect<HttpApiClient.Client.Response<{
1007
+ readonly uploadUrl: string;
1008
+ readonly url: string;
1009
+ }, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("effect/Schema").SchemaError | import("effect/unstable/httpapi/HttpApiError").BadRequest | import("effect/unstable/httpapi/HttpApiError").Unauthorized | import("effect/unstable/httpapi/HttpApiError").Forbidden | import("effect/unstable/httpapi/HttpApiError").InternalServerError), [Mode] extends ["response-only"] ? never : never>;
1010
+ };
1011
+ }, never, AuthApiClients>;
1012
+ };
519
1013
  export declare class AuthClient extends AuthClient_base {
520
- static readonly layer: (headers?: Record<string, string>) => Layer.Layer<AuthClient, import("effect/Config").ConfigError, never>;
1014
+ static readonly layer: (options?: AuthClientLayerOptions) => Layer.Layer<AuthClient, import("effect/Config").ConfigError, never>;
521
1015
  }
522
1016
  export {};
package/dist/client.js CHANGED
@@ -1,16 +1,13 @@
1
- import { Context, Effect, Layer, Redacted } from "effect";
1
+ import { Cache, Duration, Context, Effect, Layer, Redacted, Exit, } from "effect";
2
2
  import { FetchHttpClient, HttpClient, HttpClientRequest, } from "effect/unstable/http";
3
3
  import { HttpApiClient } from "effect/unstable/httpapi";
4
4
  import { BetterAuthApi } from "./better-auth/api";
5
- import { readClientConfig } from "./config";
5
+ import { AuthClientConfig } from "./config";
6
6
  import { ExtraApi } from "./extra/api";
7
7
  import { ServerApi } from "./server/api";
8
8
  const forwardedAuthHeaderNames = [
9
9
  "accept-language",
10
- "baggage",
11
10
  "cookie",
12
- "traceparent",
13
- "tracestate",
14
11
  "user-agent",
15
12
  ];
16
13
  const forwardedAuthHeaders = (headers) => {
@@ -26,10 +23,12 @@ const authHttpClientLayer = (headers) => Layer.effect(HttpClient.HttpClient, Eff
26
23
  const http = yield* HttpClient.HttpClient;
27
24
  return HttpClient.mapRequest(http, (request) => HttpClientRequest.setHeaders(request, forwardedAuthHeaders(headers)));
28
25
  })).pipe(Layer.provide(FetchHttpClient.layer));
29
- export class AuthClientConfig extends Context.Service()("@krak-stack/auth/AuthClientConfig", { make: readClientConfig }) {
30
- static layer = Layer.effect(this, this.make);
31
- }
32
- export class AuthClient extends Context.Service()("@krak-stack/auth/AuthClient", {
26
+ const getSessionCacheKey = (headers) => JSON.stringify(forwardedAuthHeaders(headers));
27
+ const clientConfigOptions = ({ baseUrl, apiKey }) => ({
28
+ ...(baseUrl ? { baseUrl } : {}),
29
+ ...(apiKey ? { apiKey } : {}),
30
+ });
31
+ export class AuthApiClients extends Context.Service()("@krak-stack/auth/AuthApiClients", {
33
32
  make: Effect.gen(function* () {
34
33
  const config = yield* AuthClientConfig;
35
34
  const http = yield* HttpClient.HttpClient;
@@ -64,5 +63,31 @@ export class AuthClient extends Context.Service()("@krak-stack/auth/AuthClient",
64
63
  };
65
64
  }),
66
65
  }) {
67
- static layer = (headers = {}) => Layer.effect(this, this.make).pipe(Layer.provide(AuthClientConfig.layer), Layer.provide(authHttpClientLayer(headers)));
66
+ static layer = (options = {}) => {
67
+ const headers = options.headers ?? {};
68
+ return Layer.effect(this, this.make).pipe(Layer.provide(AuthClientConfig.layer(clientConfigOptions(options))), Layer.provide(authHttpClientLayer(headers)));
69
+ };
70
+ }
71
+ const sessionCache = Effect.runSync(Cache.makeWith(() => Effect.gen(function* () {
72
+ const auth = yield* AuthApiClients;
73
+ return yield* auth.getSession();
74
+ }), {
75
+ capacity: 500,
76
+ timeToLive: (exit) => Exit.isSuccess(exit) ? Duration.seconds(2) : Duration.zero,
77
+ requireServicesAt: "lookup",
78
+ }));
79
+ export class AuthClient extends Context.Service()("@krak-stack/auth/AuthClient", {
80
+ make: (headers = {}) => Effect.gen(function* () {
81
+ const clients = yield* AuthApiClients;
82
+ const sessionCacheKey = getSessionCacheKey(headers);
83
+ return {
84
+ ...clients,
85
+ getSession: () => Cache.get(sessionCache, sessionCacheKey).pipe(Effect.provideService(AuthApiClients, clients)),
86
+ };
87
+ }),
88
+ }) {
89
+ static layer = (options = {}) => {
90
+ const headers = options.headers ?? {};
91
+ return Layer.effect(this, this.make(headers)).pipe(Layer.provide(AuthClientConfig.layer(clientConfigOptions(options))), Layer.provide(AuthApiClients.layer(options)));
92
+ };
68
93
  }
package/dist/config.d.ts CHANGED
@@ -1,11 +1,20 @@
1
- import { Config, Effect, Redacted } from "effect";
1
+ import { Config, Context, Effect, Layer, Redacted } from "effect";
2
2
  export declare const normalizeBaseUrl: (value: string) => string;
3
3
  export declare const defaultBaseUrl: () => string;
4
- export declare const readClientConfig: Effect.Effect<{
5
- baseUrl: string;
6
- apiKey: Redacted.Redacted<string>;
7
- }, Config.ConfigError, never>;
8
4
  export type ClientConfig = {
9
5
  readonly baseUrl: string;
10
6
  readonly apiKey: Redacted.Redacted;
11
7
  };
8
+ declare const AuthClientConfig_base: Context.ServiceClass<AuthClientConfig, "@krak-stack/auth/AuthClientConfig", {
9
+ baseUrl: string;
10
+ apiKey: Redacted.Redacted<string>;
11
+ }> & {
12
+ readonly make: (options?: Partial<ClientConfig>) => Effect.Effect<{
13
+ baseUrl: string;
14
+ apiKey: Redacted.Redacted<string>;
15
+ }, Config.ConfigError, never>;
16
+ };
17
+ export declare class AuthClientConfig extends AuthClientConfig_base {
18
+ static readonly layer: (options?: Partial<ClientConfig>) => Layer.Layer<AuthClientConfig, Config.ConfigError, never>;
19
+ }
20
+ export {};
package/dist/config.js CHANGED
@@ -1,14 +1,19 @@
1
- import { Config, Effect, Redacted } from "effect";
1
+ import { Config, Context, Effect, Layer, Redacted } from "effect";
2
2
  export const normalizeBaseUrl = (value) => value.replace(/\/$/, "");
3
3
  export const defaultBaseUrl = () => {
4
4
  const env = globalThis.process?.env;
5
5
  return normalizeBaseUrl(env?.VITE_KRAKSTACK_AUTH_URL ?? "http://localhost:3000");
6
6
  };
7
- export const readClientConfig = Effect.gen(function* () {
8
- const baseUrl = yield* Config.string("VITE_KRAKSTACK_AUTH_URL");
9
- const apiKey = yield* Config.redacted("KRAKSTACK_AUTH_SERVICE_API_KEY");
10
- return {
11
- baseUrl: normalizeBaseUrl(baseUrl),
12
- apiKey,
13
- };
14
- });
7
+ export class AuthClientConfig extends Context.Service()("@krak-stack/auth/AuthClientConfig", {
8
+ make: (options = {}) => Effect.gen(function* () {
9
+ const baseUrl = options.baseUrl ?? (yield* Config.string("VITE_KRAKSTACK_AUTH_URL"));
10
+ const apiKey = options.apiKey ??
11
+ (yield* Config.redacted("KRAKSTACK_AUTH_SERVICE_API_KEY"));
12
+ return {
13
+ baseUrl: normalizeBaseUrl(baseUrl),
14
+ apiKey,
15
+ };
16
+ }),
17
+ }) {
18
+ static layer = (options = {}) => Layer.effect(this, this.make(options));
19
+ }
@@ -54,7 +54,8 @@ declare const ExtraApiClient_base: AtomHttpApi.AtomHttpApiClient<ExtraApiClient,
54
54
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").BadRequest | typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false>>;
55
55
  export declare class ExtraApiClient extends ExtraApiClient_base {
56
56
  }
57
- export { AuthClient, AuthClientConfig } from "../client";
57
+ export { AuthClient } from "../client";
58
+ export { AuthClientConfig } from "../config";
58
59
  export { ExtraApi, ExtraApiGroup } from "./api";
59
60
  export * from "./schema";
60
61
  export type { Organization, OrganizationMetadata } from "../schema";
@@ -8,6 +8,7 @@ export class ExtraApiClient extends AtomHttpApi.Service()("ExtraApiClient", {
8
8
  httpClient: FetchHttpClient.layer,
9
9
  }) {
10
10
  }
11
- export { AuthClient, AuthClientConfig } from "../client";
11
+ export { AuthClient } from "../client";
12
+ export { AuthClientConfig } from "../config";
12
13
  export { ExtraApi, ExtraApiGroup } from "./api";
13
14
  export * from "./schema";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./schema";
2
- export { AuthClient, AuthClientConfig } from "./client";
2
+ export { AuthApiClients, AuthClient, type AuthClientLayerOptions, } from "./client";
3
+ export { AuthClientConfig } from "./config";
3
4
  export { OrganizationSwitcher, UserButton, type AuthUiClient, } from "./components";
4
5
  export * as BetterAuth from "./better-auth";
5
6
  export * as Extra from "./extra";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./schema";
2
- export { AuthClient, AuthClientConfig } from "./client";
2
+ export { AuthApiClients, AuthClient, } from "./client";
3
+ export { AuthClientConfig } from "./config";
3
4
  export { OrganizationSwitcher, UserButton, } from "./components";
4
5
  export * as BetterAuth from "./better-auth";
5
6
  export * as Extra from "./extra";
@@ -1,4 +1,5 @@
1
- export { AuthClient, AuthClientConfig } from "../client";
1
+ export { AuthClient } from "../client";
2
+ export { AuthClientConfig } from "../config";
2
3
  export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
3
4
  export type { ServerActiveOrganization, ServerMembersResponse, ServerOrganizationsResponse, ServerUsersResponse, } from "./schema";
4
5
  export type { Member, Organization, OrganizationMetadata, User, } from "../schema";
@@ -1,2 +1,3 @@
1
- export { AuthClient, AuthClientConfig } from "../client";
1
+ export { AuthClient } from "../client";
2
+ export { AuthClientConfig } from "../config";
2
3
  export { ServerApi, ServerOrganizationsApiGroup, ServerUsersApiGroup, } from "./api";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [