@outbuild/supa-store 0.0.1 → 0.0.3

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/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@outbuild/supa-store",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^18.2.0",
6
- "@angular/core": "^18.2.0"
6
+ "@angular/core": "^18.2.0",
7
+ "@ngrx/signals": "^18.0.2",
8
+ "@supabase/supabase-js": "^2.45.3"
7
9
  },
8
10
  "dependencies": {
9
11
  "tslib": "^2.3.0"
@@ -0,0 +1,6 @@
1
+ import { InjectionToken } from "@angular/core"
2
+
3
+ export const SUPABASE_CREDENTIALS = new InjectionToken<{
4
+ supabaseUrl: string,
5
+ supabaseKey: string
6
+ }>('SUPABASE_CREDENTIALS')
@@ -0,0 +1,11 @@
1
+ import { EnvironmentProviders, makeEnvironmentProviders, ModuleWithProviders, NgModule } from "@angular/core"
2
+ import { SupaStore } from "./supa-store.store"
3
+ import { SUPABASE_CREDENTIALS } from "./common/token/supabase-credentials.token"
4
+
5
+ export function provideSupaStore(supabaseUrl: string, supabaseKey: string): EnvironmentProviders { return makeEnvironmentProviders([
6
+ {
7
+ provide: SUPABASE_CREDENTIALS,
8
+ useValue: { supabaseUrl, supabaseKey }
9
+ },
10
+ SupaStore
11
+ ])}
@@ -0,0 +1,43 @@
1
+ import { inject } from '@angular/core';
2
+ import { patchState, signalStore, signalStoreFeature, withHooks, withMethods, withState } from '@ngrx/signals';
3
+ import { AuthChangeEvent, Session, SupabaseClient, createClient } from '@supabase/supabase-js'
4
+ import { SUPABASE_CREDENTIALS } from './common/token/supabase-credentials.token'
5
+
6
+ export type SupaStoreState = {
7
+ client: SupabaseClient
8
+ session: Session | undefined | null
9
+ authState: AuthChangeEvent | null
10
+ }
11
+
12
+ function withSupaStore() {
13
+
14
+ const { supabaseUrl, supabaseKey } = inject(SUPABASE_CREDENTIALS)
15
+
16
+ return signalStoreFeature(
17
+
18
+ withState<SupaStoreState>({
19
+ client: createClient(supabaseUrl, supabaseKey),
20
+ session: undefined,
21
+ authState: null
22
+ }),
23
+
24
+ withMethods(( store ) => ({
25
+ initSession: async () => {
26
+ const { data: { session }} = await store.client().auth.getSession()
27
+ patchState(store, { session: session as Session })
28
+ }
29
+ })),
30
+
31
+ withHooks({
32
+ onInit(store) {
33
+ store.initSession()
34
+ store.client().auth.onAuthStateChange(res => patchState(store, { authState: res }))
35
+ }
36
+ })
37
+
38
+ )
39
+ }
40
+
41
+ export const SupaStore = signalStore(
42
+ withSupaStore()
43
+ )
package/src/public-api.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  * Public API Surface of ob-supa-store
3
3
  */
4
4
 
5
- export * from './lib/ob-supa-store.service';
6
- export * from './lib/ob-supa-store.component';
5
+ export * from './lib/supa-store.store'
6
+ export * from './lib/supa-store.module'
@@ -1,23 +0,0 @@
1
- import { ComponentFixture, TestBed } from '@angular/core/testing';
2
-
3
- import { ObSupaStoreComponent } from './ob-supa-store.component';
4
-
5
- describe('ObSupaStoreComponent', () => {
6
- let component: ObSupaStoreComponent;
7
- let fixture: ComponentFixture<ObSupaStoreComponent>;
8
-
9
- beforeEach(async () => {
10
- await TestBed.configureTestingModule({
11
- imports: [ObSupaStoreComponent]
12
- })
13
- .compileComponents();
14
-
15
- fixture = TestBed.createComponent(ObSupaStoreComponent);
16
- component = fixture.componentInstance;
17
- fixture.detectChanges();
18
- });
19
-
20
- it('should create', () => {
21
- expect(component).toBeTruthy();
22
- });
23
- });
@@ -1,16 +0,0 @@
1
- import { Component } from '@angular/core';
2
-
3
- @Component({
4
- selector: 'lib-ob-supa-store',
5
- standalone: true,
6
- imports: [],
7
- template: `
8
- <p>
9
- ob-supa-store works!
10
- </p>
11
- `,
12
- styles: ``
13
- })
14
- export class ObSupaStoreComponent {
15
-
16
- }
@@ -1,16 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
-
3
- import { ObSupaStoreService } from './ob-supa-store.service';
4
-
5
- describe('ObSupaStoreService', () => {
6
- let service: ObSupaStoreService;
7
-
8
- beforeEach(() => {
9
- TestBed.configureTestingModule({});
10
- service = TestBed.inject(ObSupaStoreService);
11
- });
12
-
13
- it('should be created', () => {
14
- expect(service).toBeTruthy();
15
- });
16
- });
@@ -1,9 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
-
3
- @Injectable({
4
- providedIn: 'root'
5
- })
6
- export class ObSupaStoreService {
7
-
8
- constructor() { }
9
- }