@tmlmobilidade/interfaces
Version:
This package provides SDK-style connectors for interacting with databases (e.g., stops, plans, rides, alerts) and external providers (e.g., authentication, storage). It simplifies data access and integration across projects.
598 lines (597 loc) • 23 kB
TypeScript
import { MongoCollectionClass } from '../../common/mongo-collection.js';
import { type CreateUserDto, type UpdateUserDto, type User, type User_UNSAFE } from '@tmlmobilidade/types';
import { type Filter, type FindOptions, type IndexDescription, type WithId } from 'mongodb';
import { z } from 'zod';
interface SafeUserOptions {
includeUnsafeProperties: boolean;
}
declare class UsersClass extends MongoCollectionClass<User_UNSAFE, CreateUserDto, UpdateUserDto> {
private static _instance;
protected createSchema: z.ZodSchema;
protected updateSchema: z.ZodSchema;
private constructor();
static getInstance(): Promise<UsersClass>;
/**
* Finds a user document by its email.
* @param email The email of the user to find.
* @param options.includeUnsafeProperties Whether to include the password hash in the result.
* @returns A promise that resolves to the matching user document or null if not found.
*/
findByEmail(email: string, options: SafeUserOptions & {
includeUnsafeProperties: true;
}): Promise<null | WithId<User_UNSAFE>>;
findByEmail(email: string, options?: SafeUserOptions): Promise<null | WithId<User>>;
/**
* Finds a user document by its ID.
* @param id The ID of the user document to find
* @param includeUnsafeProperties Whether to include the password hash in the result
* @returns A promise that resolves to the matching user document or null if not found
*/
findById(id: string, options: FindOptions & {
includeUnsafeProperties: true;
}): Promise<null | WithId<User_UNSAFE>>;
findById(id: string): Promise<null | WithId<User>>;
/**
* Finds users by their organization code.
* @param code The code of the organization to find users for.
* @param includeUnsafeProperties Whether to include the password hash in the result.
* @returns A promise that resolves to the matching user documents or null if not found.
*/
findByOrganization(id: string): Promise<{
password_hash: any;
permissions: ({
scope: "agencies";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "alerts";
action: "create" | "delete" | "read" | "lock" | "update" | "update_texts" | "update_dates" | "update_publish_status";
resources: {
agency_ids: string[];
reference_types: string[];
};
} | {
scope: "rides";
action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update" | "acceptance_comment_activity";
resources: {
agency_ids: string[];
};
} | {
scope: "sams";
action: "read" | "export";
} | {
scope: "gtfs_validations";
action: "create" | "read" | "lock" | "request_approval" | "update_processing_status";
resources: {
agency_ids: string[];
};
} | {
scope: "home";
action: "read_links" | "read_wiki";
} | {
scope: "organizations";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "performance";
action: "read";
} | {
scope: "plans";
action: "create" | "delete" | "read" | "lock" | "update" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy" | "read_apex_file" | "update_apex_file" | "delete_apex_file" | "send_apex_notification";
resources: {
agency_ids: string[];
};
} | {
scope: "roles";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "stops";
action: "create" | "delete" | "read" | "lock" | "update" | "export" | "edit_coordinates" | "edit_name";
resources: {
municipality_ids: string[];
agency_ids: string[];
};
} | {
scope: "users";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "vehicles";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "fares";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "annotations";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "year_periods";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "holidays";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "events";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "zones";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "typologies";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "lines";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
})[];
session_ids: any;
verification_token_ids: any;
created_at: number & {
__brand: "UnixTimestamp";
};
created_by: string | null;
updated_at: number & {
__brand: "UnixTimestamp";
};
updated_by?: string | undefined;
is_locked: boolean;
email: string;
email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
first_name: string;
last_name: string;
organization_id: string;
phone: string | null;
preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
role_ids: string[];
seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
_id: string;
}[]>;
/**
* Finds a user by their role.
* @param role The role of the user to find.
* @returns A promise that resolves to the matching user document or null if not found.
*/
findByRole(role: string): Promise<{
password_hash: any;
permissions: ({
scope: "agencies";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "alerts";
action: "create" | "delete" | "read" | "lock" | "update" | "update_texts" | "update_dates" | "update_publish_status";
resources: {
agency_ids: string[];
reference_types: string[];
};
} | {
scope: "rides";
action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update" | "acceptance_comment_activity";
resources: {
agency_ids: string[];
};
} | {
scope: "sams";
action: "read" | "export";
} | {
scope: "gtfs_validations";
action: "create" | "read" | "lock" | "request_approval" | "update_processing_status";
resources: {
agency_ids: string[];
};
} | {
scope: "home";
action: "read_links" | "read_wiki";
} | {
scope: "organizations";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "performance";
action: "read";
} | {
scope: "plans";
action: "create" | "delete" | "read" | "lock" | "update" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy" | "read_apex_file" | "update_apex_file" | "delete_apex_file" | "send_apex_notification";
resources: {
agency_ids: string[];
};
} | {
scope: "roles";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "stops";
action: "create" | "delete" | "read" | "lock" | "update" | "export" | "edit_coordinates" | "edit_name";
resources: {
municipality_ids: string[];
agency_ids: string[];
};
} | {
scope: "users";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "vehicles";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "fares";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "annotations";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "year_periods";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "holidays";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "events";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "zones";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "typologies";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "lines";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
})[];
session_ids: any;
verification_token_ids: any;
created_at: number & {
__brand: "UnixTimestamp";
};
created_by: string | null;
updated_at: number & {
__brand: "UnixTimestamp";
};
updated_by?: string | undefined;
is_locked: boolean;
email: string;
email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
first_name: string;
last_name: string;
organization_id: string;
phone: string | null;
preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
role_ids: string[];
seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
_id: string;
}[]>;
/**
* Finds multiple documents matching the filter criteria
* with optional pagination and sorting.
* @param filter (Optional) filter criteria to match documents.
* @param perPage (Optional) number of documents per page for pagination.
* @param page (Optional) page number for pagination.
* @param sort (Optional) sort specification.
* @returns A promise that resolves to an array of matching documents.
*/
findMany(filter?: Filter<User>, options?: FindOptions): Promise<{
password_hash: any;
permissions: ({
scope: "agencies";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "alerts";
action: "create" | "delete" | "read" | "lock" | "update" | "update_texts" | "update_dates" | "update_publish_status";
resources: {
agency_ids: string[];
reference_types: string[];
};
} | {
scope: "rides";
action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update" | "acceptance_comment_activity";
resources: {
agency_ids: string[];
};
} | {
scope: "sams";
action: "read" | "export";
} | {
scope: "gtfs_validations";
action: "create" | "read" | "lock" | "request_approval" | "update_processing_status";
resources: {
agency_ids: string[];
};
} | {
scope: "home";
action: "read_links" | "read_wiki";
} | {
scope: "organizations";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "performance";
action: "read";
} | {
scope: "plans";
action: "create" | "delete" | "read" | "lock" | "update" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy" | "read_apex_file" | "update_apex_file" | "delete_apex_file" | "send_apex_notification";
resources: {
agency_ids: string[];
};
} | {
scope: "roles";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "stops";
action: "create" | "delete" | "read" | "lock" | "update" | "export" | "edit_coordinates" | "edit_name";
resources: {
municipality_ids: string[];
agency_ids: string[];
};
} | {
scope: "users";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "vehicles";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "fares";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "annotations";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "year_periods";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "holidays";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "events";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "zones";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "typologies";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "lines";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
})[];
session_ids: any;
verification_token_ids: any;
created_at: number & {
__brand: "UnixTimestamp";
};
created_by: string | null;
updated_at: number & {
__brand: "UnixTimestamp";
};
updated_by?: string | undefined;
is_locked: boolean;
email: string;
email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
first_name: string;
last_name: string;
organization_id: string;
phone: string | null;
preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
role_ids: string[];
seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
_id: string;
}[]>;
/**
* Finds a single document matching the filter criteria.
* @param filter Filter criteria to match the document.
* @returns A promise that resolves to the matching document or null if not found.
*/
findOne(filter: Filter<User>): Promise<{
password_hash: any;
permissions: ({
scope: "agencies";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "alerts";
action: "create" | "delete" | "read" | "lock" | "update" | "update_texts" | "update_dates" | "update_publish_status";
resources: {
agency_ids: string[];
reference_types: string[];
};
} | {
scope: "rides";
action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update" | "acceptance_comment_activity";
resources: {
agency_ids: string[];
};
} | {
scope: "sams";
action: "read" | "export";
} | {
scope: "gtfs_validations";
action: "create" | "read" | "lock" | "request_approval" | "update_processing_status";
resources: {
agency_ids: string[];
};
} | {
scope: "home";
action: "read_links" | "read_wiki";
} | {
scope: "organizations";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "performance";
action: "read";
} | {
scope: "plans";
action: "create" | "delete" | "read" | "lock" | "update" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy" | "read_apex_file" | "update_apex_file" | "delete_apex_file" | "send_apex_notification";
resources: {
agency_ids: string[];
};
} | {
scope: "roles";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "stops";
action: "create" | "delete" | "read" | "lock" | "update" | "export" | "edit_coordinates" | "edit_name";
resources: {
municipality_ids: string[];
agency_ids: string[];
};
} | {
scope: "users";
action: "create" | "delete" | "read" | "lock" | "update";
} | {
scope: "vehicles";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "fares";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "annotations";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "year_periods";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "holidays";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "events";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
} | {
scope: "zones";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "typologies";
action: "create" | "delete" | "lock" | "update" | "nav";
resources: {
agency_ids: string[];
};
} | {
scope: "lines";
action: "create" | "delete" | "read" | "lock" | "update";
resources: {
agency_ids: string[];
};
})[];
session_ids: any;
verification_token_ids: any;
created_at: number & {
__brand: "UnixTimestamp";
};
created_by: string | null;
updated_at: number & {
__brand: "UnixTimestamp";
};
updated_by?: string | undefined;
is_locked: boolean;
email: string;
email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
first_name: string;
last_name: string;
organization_id: string;
phone: string | null;
preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
role_ids: string[];
seen_last_at: import("@tmlmobilidade/types").UnixTimestamp | null;
_id: string;
}>;
protected getCollectionIndexes(): IndexDescription[];
protected getCollectionName(): string;
protected getEnvName(): string;
private sanitizeUser;
}
/**
* @deprecated This class is deprecated and will be removed in the future.
* Use `@tmlmobilidade/go-interfaces-go-db` instead.
*/
export declare const users: UsersClass;
export {};