@wereform/pkgm-api
v1.0.8
Published
Shared API utilities for BEGENONE and React / React Native apps
Downloads
972
Maintainers
Readme
@wereform/pkg-api
Thin client helpers for the WeReform / BEGENONE backend.
This package wraps common auth, user and channel flows into small, reusable functions so you can call the platform APIs from web, mobile or other Node services without rewriting the same axios logic again and again.
Install
npm install @wereform/pkg-api
# or
yarn add @wereform/pkg-api
# or
pnpm add @wereform/pkg-apiWhat this package gives you
Ready to use axios helpers for:
- Email verification with OTP
- Login and logout
- User signup (with uniqueness check)
- Channel create, delete and fetch
Consistent error logging and rethrow pattern
Works in:
- React / Next
- React Native / Expo
- Node scripts or other backend services
Exports
From @wereform/pkg-api you can import:
import {
emailVerify,
login,
logout,
signup,
createChannel,
deleteChannel,
getChannel,
} from "@wereform/pkg-api";All functions are async and return the raw response.data from the backend.
Environment and endpoints
Each helper expects:
<SERVICE>_API_URL- Example:
AUTH_API_URL,USER_API_URL,CHANNEL_API_URL,VIDEO_API_URL
- Example:
<ACTION>_ENDPOINT- Example:
VERIFY_EMAIL_ENDPOINT,LOGIN_ENDPOINT,CREATE_CHANNEL_ENDPOINT
- Example:
You can:
- Hardcode endpoints into this package, or
- Pass them from the app based on environment
Typical patterns:
const AUTH_API_URL = process.env.AUTH_API_URL;
const USER_API_URL = process.env.USER_API_URL;
const CHANNEL_API_URL = process.env.CHANNEL_API_URL;
const VIDEO_API_URL = process.env.VIDEO_API_URL;
const CLOUDFRONT_URL = process.env.CLOUDFRONT_URL;1. Email verification
Function
emailVerify({
token,
AUTH_API_URL,
email,
VERIFY_EMAIL_ENDPOINT,
}): Promise<any>token6 digit verification codeAUTH_API_URLAuth service base URLemailUser emailVERIFY_EMAIL_ENDPOINTPath for verify email endpoint
Backend expectation
VERIFY_EMAIL_ENDPOINT = "/api/v1/authentication/route-verification/verifyEmail"Example
import { emailVerify } from "@wereform/pkg-api";
await emailVerify({
token: "123456",
email: "[email protected]",
AUTH_API_URL: process.env.AUTH_API_URL!,
VERIFY_EMAIL_ENDPOINT:
"/api/v1/authentication/route-verification/verifyEmail",
});Expected backend payload:
{
"code": "123456",
"email": "[email protected]"
}2. Login
Function
login({
email,
password,
AUTH_API_URL,
LOGIN_ENDPOINT,
}): Promise<any>emailUser emailpasswordUser passwordAUTH_API_URLAuth service base URLLOGIN_ENDPOINTPath for login endpoint
Backend expectation
LOGIN_ENDPOINT = "/api/v1/authentication/route-login/login"Payload shape:
{
"eAddress": {
"email": "[email protected]",
"password": "secret"
}
}Example
import { login } from "@wereform/pkg-api";
const loginRes = await login({
email: "[email protected]",
password: "P@ssw0rd!",
AUTH_API_URL: process.env.AUTH_API_URL!,
LOGIN_ENDPOINT: "/api/v1/authentication/route-login/login",
});
const { user, tokens } = loginRes.data || loginRes;Cookies and sessions are handled on the backend with withCredentials: true.
3. Logout
Function
logout({
AUTH_API_URL,
LOGOUT_ENDPOINT,
}): Promise<any>AUTH_API_URLAuth service base URLLOGOUT_ENDPOINTPath for logout endpoint
Backend expectation
LOGOUT_ENDPOINT = "/api/v1/authentication/route-logout/logout"Example
import { logout } from "@wereform/pkg-api";
await logout({
AUTH_API_URL: process.env.AUTH_API_URL!,
LOGOUT_ENDPOINT: "/api/v1/authentication/route-logout/logout",
});4. Signup
Function
signup({
firstName,
secondName,
email,
password,
passwordConfirm,
username,
USER_API_URL,
USER_CHECK_EXISTENCE_ENDPOINT,
CREATE_USER_ENDPOINT,
}): Promise<any>- Validates
password === passwordConfirmon client - First calls a check existence endpoint
- Then sends final user creation payload
Backend expectations
USER_CHECK_EXISTENCE_ENDPOINT = "/api/v1/users/check-existence"
CREATE_USER_ENDPOINT = "api/v1/users"Example
import { signup } from "@wereform/pkg-api";
const res = await signup({
firstName: "John",
secondName: "Doe",
email: "[email protected]",
password: "P@ssw0rd!",
passwordConfirm: "P@ssw0rd!",
username: "john-doe",
USER_API_URL: process.env.USER_API_URL!,
USER_CHECK_EXISTENCE_ENDPOINT: "/api/v1/users/check-existence",
CREATE_USER_ENDPOINT: "api/v1/users",
});
const createdUser = res.data || res;5. Create channel
Function
createChannel({
NAME,
ABOUT,
CHANNEL_USERNAME,
CHANNEL_API_URL,
CREATE_CHANNEL_ENDPOINT,
}): Promise<any>Backend expectation
CREATE_CHANNEL_ENDPOINT = "/api/v1/channels/channel-routes/"Example
import { createChannel } from "@wereform/pkg-api";
const channel = await createChannel({
NAME: "WeReform HQ",
ABOUT: "Long form breakdowns, wires and experiments",
CHANNEL_USERNAME: "wereform",
CHANNEL_API_URL: process.env.CHANNEL_API_URL!,
CREATE_CHANNEL_ENDPOINT: "/api/v1/channels/channel-routes/",
});6. Delete channel
Function
deleteChannel({
channelId,
CHANNEL_API_URL,
DELETE_CHANNEL_ENDPOINT,
}): Promise<any>Example
import { deleteChannel } from "@wereform/pkg-api";
await deleteChannel({
channelId: "CHANNEL_ID_123",
CHANNEL_API_URL: process.env.CHANNEL_API_URL!,
DELETE_CHANNEL_ENDPOINT: "/api/v1/channels/channel-routes/",
});7. Get channel with videos and wires
Function
getChannel({
channelId,
CHANNEL_API_URL,
VIDEO_API_URL,
CLOUDFRONT_URL,
GET_CHANNEL_ENDPOINT,
}): Promise<any>Example
import { getChannel } from "@wereform/pkg-api";
const channel = await getChannel({
channelId: "CHANNEL_ID_123",
CHANNEL_API_URL: process.env.CHANNEL_API_URL!,
VIDEO_API_URL: process.env.VIDEO_API_URL!,
CLOUDFRONT_URL: process.env.CLOUDFRONT_URL!,
GET_CHANNEL_ENDPOINT: "/api/v1/channels/channel-routes/",
});Error handling pattern
All helpers:
- Log a detailed message to
console.error - Rethrow the original
error
try {
const data = await login({
email,
password,
AUTH_API_URL: process.env.AUTH_API_URL!,
LOGIN_ENDPOINT: "/api/v1/authentication/route-login/login",
});
} catch (err: any) {
const message =
err?.response?.data?.message || err?.message || "Unexpected error";
console.log("AUTH ERROR:", message);
}License
MIT License
Copyright (c) 2025 WeReform / BEGENONE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
