k.google
Google PageSpeed/Lighthouse and Firebase services
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, Page / View server scripts | Valid site Firebase Service Account JSON required (even for Lighthouse root methods) | Generating/parsing Lighthouse reports, verifying Firebase tokens, and managing users |
k.google groups Google-related capabilities: PageSpeed/Lighthouse methods sit directly on k.google, while Firebase Admin capabilities are exposed under k.google.firebase.
Runtime Configuration Prerequisite
Accessing k.google eagerly initializes k.google.firebase by reading the site's Firebase Service Account JSON credential (requiring type: "service_account", project_id, private_key_id, private_key, client_email, and token_uri). If the site has no configured or valid Firebase credential, any access to k.google (including Lighthouse root methods) throws an exception.
Quick Start
k.api.get("lighthouse", () => {
const json = k.google.lHRJson("https://www.kooboo.com", false)
const report = k.google.parseJson(json)
return report.getSummary()
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
lHRJson(absoluteUrl, mobileDevice) | Analyze an absolute URL and return Lighthouse JSON | string |
lHRUrl(absoluteUrl, mobileDevice) | Analyze an absolute URL and return a report URL | string |
lHRUrlFromJson(json) | Convert Lighthouse JSON into an openable report URL | string |
parseJson(json) | Parse Lighthouse JSON into FullLHRObj | FullLHRObj |
saveJson(json) / getJson(id) | Temporarily save Lighthouse JSON and retrieve by ID | Guid / string | null |
shortLhrReportUrl(json) | Save JSON and generate a short report URL | string |
firebase.verifyIdToken(idToken) | Verify a client Firebase ID token and return claims | Record<string, string> |
firebase.createCustomToken(uid) | Issue a Firebase custom token for the given uid | string |
firebase.createUser / updateUser / deleteUser | Create, update, or delete Firebase Auth users | UserRecord / void |
firebase.getUserByEmail / getUserByPhoneNumber | Look up a Firebase user by email or phone number | UserRecord |
firebase.generate*Link | Generate verification, password reset, and sign-in links | string |
PageSpeed / Lighthouse
lHRJson() / lHRUrl()
Generate Lighthouse JSON or an online report URL for an absolute URL.
| Parameter | Type | Required | Description |
|---|---|---|---|
absoluteUrl | string | Yes | Absolute URL to analyze |
mobileDevice | boolean | Yes | Compatibility parameter; the current request does not switch desktop/mobile strategy based on this value |
Returns: lHRJson() returns a Lighthouse JSON string; lHRUrl() returns a /_Admin/LightHouse/index.html?gzip=1#... report URL.
const json = k.google.lHRJson("https://www.kooboo.com", false)
const report = k.google.parseJson(json)
const summary = report.getSummary()
return {
performance: summary.performance,
accessibility: summary.accessibility,
bestpractices: summary.bestpractices,
seo: summary.seo,
pwa: summary.pwa
}If you only need an openable Lighthouse report URL:
const reportUrl = k.google.lHRUrl("https://www.kooboo.com", true)
return { reportUrl }lHRUrlFromJson()
Convert existing Lighthouse JSON into a report URL that can be opened in Kooboo.
| Parameter | Type | Required | Description |
|---|---|---|---|
json | string | Yes | Lighthouse JSON string |
Returns: string.
const json = k.google.lHRJson("https://www.kooboo.com", false)
const reportUrl = k.google.lHRUrlFromJson(json)
return { reportUrl }parseJson() / saveJson() / getJson()
Parse Lighthouse JSON, save it to temporary storage, and retrieve it by ID.
| Method | Parameter | Return | Description |
|---|---|---|---|
parseJson(json) | string | FullLHRObj | Parse Lighthouse JSON |
saveJson(json) | string | Guid | Store JSON in temporary storage and return a Guid ID (use String(id) if a JS string is needed) |
getJson(id) | any | string | null | Read stored JSON by ID; returns null if not found |
Returns: FullLHRObj, temporary report Guid (convert with String(id) if a JS string is needed), or the stored JSON string.
const json = k.google.lHRJson("https://www.kooboo.com", false)
const id = k.google.saveJson(json)
const saved = k.google.getJson(id)
return {
id: String(id),
saved: !!saved,
summary: saved ? k.google.parseJson(saved).getSummary() : null
}shortLhrReportUrl()
Save JSON and generate a short report URL (/_api/LightHouse/ReadReport?id=...).
| Parameter | Type | Required | Description |
|---|---|---|---|
json | string | Yes | Lighthouse JSON string |
Returns: string.
const json = k.google.lHRJson("https://www.kooboo.com", false)
const url = k.google.shortLhrReportUrl(json)
return {
url,
fullUrl: k.site.info.makeAbsUrl(url)
}FullLHRObj and ReportSummary
parseJson(json) returns FullLHRObj:
| Member | Type | Description |
|---|---|---|
lighthouseResult | { categories } | Contains performance, accessibility, bestpractices, seo, and pwa (each with id: string, score: number) |
getSummary() | () => ReportSummary | Multiplies each category score by 100 to produce an integer summary |
ReportSummary properties (note bestpractices is all lowercase):
| Property | Type | Description |
|---|---|---|
performance | number | Performance score (0–100) |
accessibility | number | Accessibility score (0–100) |
bestpractices | number | Best Practices score (0–100) |
seo | number | SEO score (0–100) |
pwa | number | PWA score (0–100) |
Firebase (k.google.firebase)
Requires valid Firebase Admin service account JSON configured in the site settings before calling.
verifyIdToken() / createCustomToken()
Verify a client Firebase ID token or issue a custom token for a user ID.
| Method | Parameter | Return | Description |
|---|---|---|---|
verifyIdToken(idToken) | idToken: string | Record<string, string> | Verify ID token and return its claims map |
createCustomToken(uid) | uid: string | string | Generate a custom token for the given uid |
Returns: verifyIdToken() returns a claims dictionary; createCustomToken() returns the token string.
const claims = k.google.firebase.verifyIdToken(idToken)
const customToken = k.google.firebase.createCustomToken(claims.user_id || claims.sub)
return { claims, customToken }createUser() / updateUser() / deleteUser()
Manage Firebase Auth users.
| Method | Parameter | Return | Description |
|---|---|---|---|
createUser(user) | user: UserRecordArgs | UserRecord | Create a Firebase user |
updateUser(arg) | arg: UserRecordArgs | UserRecord | Update an existing user; uid is required |
deleteUser(uid) | uid: string | void | Delete the user with the given uid |
UserRecordArgs properties:
| Property | Type | Description |
|---|---|---|
uid | string | User UID (required for updateUser; optional for createUser) |
email | string | Email address |
phoneNumber | string | Phone number in E.164 format |
displayName | string | Display name |
emailVerified | boolean | Whether email is verified |
photoUrl | string | Profile photo URL |
disabled | boolean | Whether the account is disabled |
password | string | Password |
Returns: createUser() / updateUser() return UserRecord; deleteUser() returns void.
const user = k.google.firebase.createUser({
email: "alice@example.com",
password: "SecretPassword123!",
displayName: "Alice"
})
const updated = k.google.firebase.updateUser({
uid: user.uid,
emailVerified: true
})
k.google.firebase.deleteUser(updated.uid)getUserByEmail() / getUserByPhoneNumber()
Look up a user by email or phone number.
| Method | Parameter | Return | Description |
|---|---|---|---|
getUserByEmail(email) | email: string | UserRecord | Retrieve user record by email |
getUserByPhoneNumber(phoneNumber) | phoneNumber: string | UserRecord | Retrieve user record by phone number |
Returns: UserRecord.
const byEmail = k.google.firebase.getUserByEmail("alice@example.com")
const byPhone = k.google.firebase.getUserByPhoneNumber("+14155550100")Email Action Link Generation
Generate email verification, password reset, and email sign-in links.
| Method | Parameter | Return | Description |
|---|---|---|---|
generateEmailVerificationLink(email) | email: string | string | Generate email verification link |
generatePasswordResetLink(email) | email: string | string | Generate password reset link |
generatePasswordResetLink(email, settings) | email: string, settings: ActionCodeSettings | string | See the overload note below |
generateSignInWithEmailLink(email, settings) | email: string, settings: ActionCodeSettings | string | Generate email-link sign-in URL |
generatePasswordResetLink 2-Parameter Overload Behavior
In the current runtime, the 2-parameter overload generatePasswordResetLink(email, settings) invokes email-link sign-in generation (equivalent to generateSignInWithEmailLink(email, settings)). Use the 1-parameter generatePasswordResetLink(email) overload to generate a password reset link.
ActionCodeSettings properties:
| Property | Type | Description |
|---|---|---|
url | string | Continue / deep-link URL |
handleCodeInApp | boolean | Whether the action code is handled in-app |
dynamicLinkDomain | string | Firebase Dynamic Links domain |
iosBundleId | string | iOS bundle ID |
androidPackageName | string | Android package name |
androidMinimumVersion | string | Minimum Android app version |
androidInstallApp | boolean | Whether to install the Android app if missing |
Returns: string, the generated email action URL.
const verifyLink = k.google.firebase.generateEmailVerificationLink("alice@example.com")
const resetLink = k.google.firebase.generatePasswordResetLink("alice@example.com")
const signInLink = k.google.firebase.generateSignInWithEmailLink("alice@example.com", {
url: "https://example.com/finish-signin",
handleCodeInApp: true
})UserRecord Properties
| Property | Type | Description |
|---|---|---|
uid | string | Unique user ID |
displayName | string | Display name |
email | string | Email address |
phoneNumber | string | Phone number |
photoUrl | string | Photo URL |
providerId | string | Provider ID |
emailVerified | boolean | Whether email is verified |
disabled | boolean | Whether account is disabled |
providerData | IUserInfo[] | Linked provider entries |
tokensValidAfterTimestamp | Date | Token validity start time |
userMetaData | UserMetadata | Creation and last sign-in metadata |
customClaims | any | Custom claims object |
tenantId | string | Multi-tenant ID |
TypeScript Definitions
Show full TypeScript definitions
interface KGoogle {
firebase: KFirebase;
lHRJson(AbsoluteUrl: string, MobileDevice: boolean): string;
lHRUrl(AbsoluteUrl: string, MobileDevice: boolean): string;
lHRUrlFromJson(json: string): string;
parseJson(json: string): FullLHRObj;
saveJson(json: string): any;
shortLhrReportUrl(json: string): string;
getJson(Id: any): string;
}
interface FullLHRObj {
lighthouseResult: lighthouseResult;
getSummary(): ReportSummary;
}
interface lighthouseResult {
categories: categories;
}
interface categories {
performance: itemResult;
accessibility: itemResult;
bestpractices: itemResult;
seo: itemResult;
pwa: itemResult;
}
interface itemResult {
id: string;
score: number;
}
interface ReportSummary {
performance: number;
accessibility: number;
bestpractices: number;
seo: number;
pwa: number;
}
interface KFirebase {
verifyIdToken(idToken: string): Record<string, string>;
createCustomToken(uid: string): string;
createUser(user: UserRecordArgs): UserRecord;
deleteUser(uid: string): void;
updateUser(arg: UserRecordArgs): UserRecord;
generateEmailVerificationLink(email: string): string;
generatePasswordResetLink(email: string): string;
generatePasswordResetLink(email: string, settings: ActionCodeSettings): string;
getUserByEmail(email: string): UserRecord;
getUserByPhoneNumber(phoneNumber: string): UserRecord;
generateSignInWithEmailLink(email: string, settings: ActionCodeSettings): string;
}
interface UserRecordArgs {
uid?: string;
email?: string;
phoneNumber?: string;
displayName?: string;
emailVerified?: boolean;
photoUrl?: string;
disabled?: boolean;
password?: string;
}
interface IUserInfo {
uid: string;
displayName: string;
email: string;
phoneNumber: string;
photoUrl: string;
providerId: string;
}
interface UserMetadata {
creationTimestamp?: Date;
lastSignInTimestamp?: Date;
lastRefreshTimestamp?: Date;
}
interface UserRecord extends IUserInfo {
uid: string;
displayName: string;
email: string;
phoneNumber: string;
photoUrl: string;
providerId: string;
emailVerified: boolean;
disabled: boolean;
providerData: IUserInfo[];
tokensValidAfterTimestamp: Date;
userMetaData: UserMetadata;
customClaims: any;
tenantId: string;
}
interface ActionCodeSettings {
url: string;
handleCodeInApp?: boolean;
dynamicLinkDomain?: string;
iosBundleId?: string;
androidPackageName?: string;
androidMinimumVersion?: string;
androidInstallApp?: boolean;
}Related Docs
- k.utils.ninjible — Site migration and Lighthouse comparison