How sandriiy/salesforce-google-drive-library works
Project type and purpose
• This is a Salesforce‐hosted Apex library (unlocked package) that wraps Google Drive REST API v3.
• Its sole purpose is to provide a strongly-typed, builder‐pattern driven interface within Apex to perform Drive operations (upload, download, clone, search, permission management), plus supporting unit tests via HTTP callout mocks.
File structure
• Top-level:
• config/ – Scratch org definition
• google-drive/ – the entire Apex package
• jest.config.js, package.json – local JavaScript testing config (for HTTP mock generation tools)
• sfdx-project.json – Salesforce DX project descriptor
• google-drive/classes:
• auth/GoogleAuthorizationCodeFlow, GoogleCredential – OAuth2 flow, credential storage
• builders/*Builder.cls – Builder pattern classes to construct each REST call
• factories/*Factory.cls – Factory classes to instantiate high-level operations
• entities/*Entity.cls – Domain wrappers for Drive responses (files, drives, permissions)
• interfaces/ – Abstraction of authorizer and file creator for DI and testability
• GoogleDrive.cls – Facade entry point exposing .files(), .drives(), .permissions().
• GoogleDriveHttpMockGenerator.cls – Generates HTTP mocks for unit tests
• GoogleDriveTest.cls – Apex test suite
• Configuration and metadata files (.cls-meta.xml, sfdx, .forceignore, .husky, .prettierrc, etc.)
README for additional insights
• The README confirms:
• Programmatic Apex access to Drive
• Usage examples invoking GoogleDrive.files().upload().execute() style
• Highlights v3 API, custom wrappers (GoogleFileEntity, SearchResult), mock‐based testing
• Deployment via direct metadata or unlocked package
a. Main components
• Salesforce Org
• Apex Runtime
• HTTP Callout Framework
• Named Credential (or Remote Site Settings)
• Apex Library (google-drive package)
• GoogleDrive Facade
• Builder Layer
• Factory Layer
• Entity Layer
• Interface abstractions
• HTTP Mock Generator (test harness)
• External Systems
• Google OAuth 2.0 Authorization Server
• Google Drive REST API v3
b. Relationships & data flows
1. Developer code / client code calls the GoogleDrive facade in Apex.
2. GoogleDrive delegates to Factory to instantiate a specific operation (e.g., FilesBuilder).
3. Builder assembles URL, query params, headers (including OAuth token from Credential).
4. Apex HTTP Callout is issued to Google API endpoint.
5. Google Authorization Server issues/refreshes access tokens.
6. Google Drive API returns JSON payload.
7. Response is parsed into Entity objects.
8. For tests, HTTP Callouts are intercepted by GoogleDriveHttpMockGenerator.
c. Architectural patterns & design principles
• Facade Pattern: GoogleDrive entry point hides internal complexity.
• Builder Pattern: Each request type has its own Builder class to incrementally set parameters.
• Factory Pattern: Factories instantiate Builders preconfigured for specific use cases.
• Dependency Inversion: Interfaces (GoogleAuthorizer, GoogleFileCreator) allow swapping implementations or mocks.
• Layered Architecture: Separation between request construction, authorization, HTTP transport, response mapping, and testing.
• Testability: HTTP Mock Generator and Apex Test classes ensure high coverage without real API calls.
d. Key technologies & frameworks
• Salesforce Apex language & runtime
• Salesforce DX (sfdx-project.json)
• HTTP Callout framework in Apex
• Google OAuth 2.0 / Named Credentials
• Google Drive REST API v3
• Jest (for local mock generation tooling)
• Unlocked Package deployment model