@mxpicture/gcp-functions-frontend 0.1.20 → 0.1.21

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,7 +1,7 @@
1
1
  import type { MetaItem } from "@mxpicture/zod-meta";
2
2
  import type { ApiKey, DocumentData, WithKey, FunctionName, FunctionPayload, FunctionResult } from "@mxpicture/gcp-functions-common/types";
3
3
  import { IApi } from "@mxpicture/gcp-functions-common/api";
4
- import type { HttpsCallable } from "firebase/functions";
4
+ import { type HttpsCallable } from "firebase/functions";
5
5
  export declare const functionCallable: <DTO extends DocumentData, KEYS extends ApiKey>(name: FunctionName) => Promise<HttpsCallable<FunctionPayload<DTO, KEYS>, Promise<FunctionResult<WithKey<DTO>>>, unknown>>;
6
6
  export declare class FrontendApi<DTO extends DocumentData> extends IApi<DTO> {
7
7
  readonly name: FunctionName;
@@ -1,8 +1,7 @@
1
1
  import { IApi } from "@mxpicture/gcp-functions-common/api";
2
+ import { httpsCallable } from "firebase/functions";
2
3
  import { configFirebase } from "../config/firebase.config.js";
3
- import { loadFirebaseFunctions } from "../loader/firebase.loader.js";
4
4
  export const functionCallable = async (name) => {
5
- const { httpsCallable } = await loadFirebaseFunctions();
6
5
  return httpsCallable((await configFirebase()).functions, name);
7
6
  };
8
7
  export class FrontendApi extends IApi {
@@ -1,5 +1,5 @@
1
1
  import { GoogleAuthProvider, type Auth } from "firebase/auth";
2
- import type { FirebaseApp } from "firebase/app";
2
+ import { type FirebaseApp } from "firebase/app";
3
3
  import { type Functions } from "firebase/functions";
4
4
  import type { FirebaseConfig, FirebaseEmulatorConfig } from "../types/firebase.types.js";
5
5
  export declare const initializeFirebase: (config: FirebaseConfig, emu?: FirebaseEmulatorConfig) => Promise<{
@@ -1,6 +1,6 @@
1
- import { connectAuthEmulator, GoogleAuthProvider, } from "firebase/auth";
2
- import { connectFunctionsEmulator } from "firebase/functions";
3
- import { loadFirebaseApp, loadFirebaseAuth, loadFirebaseFunctions, } from "../loader/firebase.loader.js";
1
+ import { connectAuthEmulator, getAuth, GoogleAuthProvider, } from "firebase/auth";
2
+ import { initializeApp } from "firebase/app";
3
+ import { connectFunctionsEmulator, getFunctions, } from "firebase/functions";
4
4
  let _inst = null;
5
5
  let _config = null;
6
6
  let _emu = null;
@@ -16,9 +16,6 @@ export const configFirebase = async () => {
16
16
  if (!_inst) {
17
17
  if (!_config)
18
18
  throw new Error("Firebase config not provided. Use initializeFirebase at first");
19
- const { getAuth } = await loadFirebaseAuth();
20
- const { getFunctions } = await loadFirebaseFunctions();
21
- const { initializeApp } = await loadFirebaseApp();
22
19
  // Initialize Firebase
23
20
  const app = initializeApp(_config);
24
21
  // Initialize Firebase services
@@ -1,10 +1,9 @@
1
+ import { createUserWithEmailAndPassword, onAuthStateChanged, sendPasswordResetEmail, signInWithEmailAndPassword, signInWithPopup, signOut, } from "firebase/auth";
1
2
  import { configFirebase } from "../../config/firebase.config.js";
2
- import { loadFirebaseAuth } from "../../loader/firebase.loader.js";
3
3
  import { authErrorText } from "../../helper/auth.helper.js";
4
4
  class AuthService {
5
5
  async login(credentials) {
6
6
  try {
7
- const { signInWithEmailAndPassword } = await loadFirebaseAuth();
8
7
  const { user } = await signInWithEmailAndPassword((await configFirebase()).auth, credentials.email, credentials.password);
9
8
  return this.mapFirebaseUserToAuthUser(user);
10
9
  }
@@ -14,7 +13,6 @@ class AuthService {
14
13
  }
15
14
  async loginWithGoogle() {
16
15
  try {
17
- const { signInWithPopup } = await loadFirebaseAuth();
18
16
  const config = await configFirebase();
19
17
  const { user } = await signInWithPopup(config.auth, config.googleProvider);
20
18
  return this.mapFirebaseUserToAuthUser(user);
@@ -25,7 +23,6 @@ class AuthService {
25
23
  }
26
24
  async register(credentials) {
27
25
  try {
28
- const { createUserWithEmailAndPassword } = await loadFirebaseAuth();
29
26
  const { user } = await createUserWithEmailAndPassword((await configFirebase()).auth, credentials.email, credentials.password);
30
27
  // Store additional user data in Firestore
31
28
  // const userService = new UserService()
@@ -38,7 +35,6 @@ class AuthService {
38
35
  }
39
36
  async logout() {
40
37
  try {
41
- const { signOut } = await loadFirebaseAuth();
42
38
  await signOut((await configFirebase()).auth);
43
39
  }
44
40
  catch (error) {
@@ -47,7 +43,6 @@ class AuthService {
47
43
  }
48
44
  async resetPassword(email) {
49
45
  try {
50
- const { sendPasswordResetEmail } = await loadFirebaseAuth();
51
46
  await sendPasswordResetEmail((await configFirebase()).auth, email);
52
47
  }
53
48
  catch (error) {
@@ -55,7 +50,6 @@ class AuthService {
55
50
  }
56
51
  }
57
52
  async onAuthStateChanged(callback) {
58
- const { onAuthStateChanged } = await loadFirebaseAuth();
59
53
  return onAuthStateChanged((await configFirebase()).auth, (user) => {
60
54
  callback(user ? this.mapFirebaseUserToAuthUser(user) : null);
61
55
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxpicture/gcp-functions-frontend",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Utils for google cloud functions, publishing both CommonJS and ESM builds",
5
5
  "type": "module",
6
6
  "author": "MXPicture",