Client for the MyMagti API.
Mocking fetch for tests
Mocking fetch for tests
import { assertEquals } from "@std/assert"; import { fetchToken } from "@hertzg/mymagti-api"; const mockFetch: typeof fetch = async (_url, _init) => new Response( JSON.stringify({ access_token: "A", autoLogin: 0, expires_in: 3600, jti: "id", phoneNo: "5xxxxxxxx", refresh_token: "R", scope: "*", token_type: "bearer", userId: 1, userIdentifier: "u", }), { status: 200, headers: { "content-type": "application/json" } }, ); const res = await fetchToken( { type: "login", username: "u", password: "p" }, { fetch: mockFetch }, ); assertEquals(res.result, "success"); if (res.result === "success") { assertEquals(typeof res.data.access_token, "string"); }
Fetches an OAuth token using the provided request.
Generic error response from OAuth server.
-
error: string
Error code
-
error_description: string
Error description
OAuth token information.
-
access_token: string
Access token for API requests
-
autoLogin: number
Auto-login flag
-
expires_in: number
Token expiration time in seconds
-
jti: string
JWT ID
-
phoneNo: string
Phone number
-
refresh_token: string
Refresh token for getting new access tokens
-
scope: string
Token scope
-
token_type: string
Token type
-
userId: number
User ID
-
userIdentifier: string
User identifier
| { type: "refresh"; refreshToken: string; }
Request type for fetching OAuth tokens.
OAuth helpers for MyMagti API.
Default user agent string for OAuth requests.
OAuth helpers for MyMagti API.
Mocking fetch for tests
Mocking fetch for tests
import { assertEquals } from "@std/assert"; import { fetchToken } from "@hertzg/mymagti-api/oauth"; const mockFetch: typeof fetch = async (_url, _init) => new Response( JSON.stringify({ access_token: "A", autoLogin: 0, expires_in: 3600, jti: "id", phoneNo: "5xxxxxxxx", refresh_token: "R", scope: "*", token_type: "bearer", userId: 1, userIdentifier: "u", }), { status: 200, headers: { "content-type": "application/json" } }, ); const res = await fetchToken( { type: "login", username: "u", password: "p" }, { fetch: mockFetch }, ); assertEquals(res.result, "success"); if (res.result === "success") { assertEquals(typeof res.data.access_token, "string"); }
Fetches an OAuth token using the provided request.
Generic error response from OAuth server.
-
error: string
Error code
-
error_description: string
Error description
OAuth token information.
-
access_token: string
Access token for API requests
-
autoLogin: number
Auto-login flag
-
expires_in: number
Token expiration time in seconds
-
jti: string
JWT ID
-
phoneNo: string
Phone number
-
refresh_token: string
Refresh token for getting new access tokens
-
scope: string
Token scope
-
token_type: string
Token type
-
userId: number
User ID
-
userIdentifier: string
User identifier
| { type: "refresh"; refreshToken: string; }
Request type for fetching OAuth tokens.
OAuth helpers for MyMagti API.
Default user agent string for OAuth requests.