| 1 | package mapa |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "amadan.net/oficina/notion.git/notion" |
| 7 | ) |
| 8 | |
| 9 | // Mapa reaches the network only through amadan.net/oficina/notion.git, |
| 10 | // only from import_*.go, and only for two things a person asks for: the |
| 11 | // one verify call when a token is saved, and an active run (Notion |
| 12 | // import spec §5, gate I8). The client is built for each and dropped |
| 13 | // after. Mapa never polls Notion. |
| 14 | |
| 15 | // NotionAccess is how the import reaches Notion. Production's dials the |
| 16 | // real API through the module's pinned transports; a test hands in the |
| 17 | // module's fake (UseNotion). |
| 18 | type NotionAccess interface { |
| 19 | Verify(ctx context.Context, token string) (notion.Workspace, error) |
| 20 | Client(token string) (*notion.Client, error) |
| 21 | Files() *notion.Files |
| 22 | } |
| 23 | |
| 24 | // liveNotion is production's: api.notion.com and Notion's file hosts, |
| 25 | // and nothing else. |
| 26 | type liveNotion struct{} |
| 27 | |
| 28 | func (liveNotion) Verify(ctx context.Context, token string) ( |
| 29 | notion.Workspace, error) { |
| 30 | return notion.Verify(ctx, token) |
| 31 | } |
| 32 | |
| 33 | func (liveNotion) Client(token string) (*notion.Client, error) { |
| 34 | return notion.New(token) |
| 35 | } |
| 36 | |
| 37 | func (liveNotion) Files() *notion.Files { return notion.NewFiles() } |
| 38 | |
| 39 | // UseNotion replaces how the import reaches Notion. Tests only: every |
| 40 | // gate runs against the module's fake, and nothing in a test dials |
| 41 | // Notion. |
| 42 | func (built Built) UseNotion(access NotionAccess) { |
| 43 | built.app.notion = access |
| 44 | } |
| 45 | |