@goodfellow-cms/github 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,24 @@
1
- import { ConnectDomainOptions, DeployStatus, DnsRecord, FileChange, FileVersion, GitBackend, GitHost, GitUser, HistoryOptions, OwnerAccess, PagesDomains, SetupHost, SiteEditors, SiteUpdates, StorageLike, TokenLink, WriteOptions } from "@goodfellow-cms/core";
1
+ import { ConnectDomainOptions, DeployStatus, DnsRecord, FileChange, FileVersion, GitBackend, GitHost, GitUser, HistoryOptions, OwnerAccess, PagesDomains, RedirectOptions, SetupHost, SignInError, SiteDrafts, SiteEditors, SiteUpdates, StorageLike, TokenLink, WriteOptions } from "@goodfellow-cms/core";
2
+ //#region src/sign-in.d.ts
3
+ /** The sign-in worker Goodfellow runs for every site. Sites can run their own and name it in `github({ signIn })`. */
4
+ export declare const GOODFELLOW_SIGN_IN = "https://sign-in.goodfellow-cms.workers.dev";
5
+ /** The page's address and how to change it. Replaceable in tests. */
6
+ interface BrowserLocation {
7
+ href(): string;
8
+ /** Navigates away, for example to GitHub's sign-in page. */
9
+ assign(url: string): void;
10
+ /** Changes the address without reloading, for example to remove the sign-in's details after coming back. */
11
+ replace(url: string): void;
12
+ }
13
+ //#endregion
2
14
  //#region src/api.d.ts
15
+ /** A token that renews itself, such as one from the sign-in worker. `refresh` asks for a new one even if it hasn't expired. */
16
+ type TokenSource = (options?: {
17
+ refresh?: boolean;
18
+ }) => Promise<string>;
3
19
  interface ApiOptions {
4
20
  apiUrl: string;
5
- token: string;
21
+ token: string | TokenSource;
6
22
  fetch: typeof fetch;
7
23
  }
8
24
  //#endregion
@@ -15,6 +31,17 @@ interface GitHubBackendOptions {
15
31
  onSignOut: () => void;
16
32
  /** Where to create the owner token, which can change editors and GitHub Pages settings. */
17
33
  ownerTokenLink: TokenLink;
34
+ /** Signs in as an owner through the sign-in worker instead of with a token, where it's available. */
35
+ ownerRedirect?: (options?: RedirectOptions) => Promise<void>;
36
+ /**
37
+ * Who commits name as their author. Set when the token is an app's
38
+ * installation token from the sign-in worker, whose commits would otherwise
39
+ * name the app. Commits are then made with Git's data API, which can name them.
40
+ */
41
+ author?: {
42
+ name: string;
43
+ email: string;
44
+ };
18
45
  }
19
46
  /**
20
47
  * The site's files on GitHub. Reads come from the commit `revision()` last
@@ -27,25 +54,47 @@ export declare class GitHubBackend implements GitBackend {
27
54
  readonly editors: SiteEditors;
28
55
  readonly ownerAccess: OwnerAccess;
29
56
  readonly updates: SiteUpdates;
57
+ readonly drafts: SiteDrafts;
58
+ private readonly options;
30
59
  private readonly api;
31
60
  private readonly repo;
32
61
  private readonly branch;
33
62
  private readonly onSignOut;
63
+ private readonly author?;
64
+ private readonly owner;
34
65
  private pinned?;
35
66
  private readonly trees;
67
+ /** Each file's size in bytes at a commit, which GitHub lists with its tree. */
68
+ private readonly treeSizes;
36
69
  private readonly blobs;
37
70
  constructor(options: GitHubBackendOptions);
71
+ /** Drafts on branches of the repository, with pull requests for review. */
72
+ private draftHost;
38
73
  revision(): Promise<string>;
39
74
  /** Path → blob id for every file at a commit. Commits never change, so this is cached. */
40
75
  private tree;
41
76
  private currentTree;
42
77
  read(path: string): Promise<string | undefined>;
43
78
  private readFrom;
79
+ /** Reads many text files in a few GraphQL requests rather than one request each. */
80
+ readFiles(paths: string[]): Promise<Map<string, string>>;
44
81
  readBytes(path: string): Promise<Uint8Array | undefined>;
45
82
  list(dir: string): Promise<string[]>;
46
- write(changes: FileChange[], { message, expectedRevision }: WriteOptions): Promise<{
83
+ fileSizes(dir: string): Promise<Map<string, number>>;
84
+ /** Uses an owner's sign-in through the worker for editors and GitHub Pages settings, until it's forgotten. */
85
+ useOwnerSignIn(token: TokenSource, end: () => void): void;
86
+ /** Remembers why an owner's sign-in through the worker didn't work, which the Editors and Domain screens show. */
87
+ ownerSignInFailed(error: unknown): void;
88
+ write(changes: FileChange[], options: WriteOptions): Promise<{
47
89
  revision: string;
48
90
  }>;
91
+ /**
92
+ * Saves with Git's data API, naming the editor as the commit's author:
93
+ * GitHub refuses to move the branch unless the commit follows on from it, so
94
+ * nothing is overwritten.
95
+ */
96
+ private writeCommit;
97
+ private writeGraphQL;
49
98
  history(path: string, { page, perPage }?: HistoryOptions): Promise<FileVersion[]>;
50
99
  readAt(path: string, revision: string): Promise<string | undefined>;
51
100
  changedPaths(from: string, to: string): Promise<string[]>;
@@ -73,8 +122,17 @@ interface GitHubSetupOptions {
73
122
  apiUrl?: string;
74
123
  /** For GitHub Enterprise. Defaults to `https://github.com`. */
75
124
  webUrl?: string;
125
+ /** The sign-in worker, for "Sign in with GitHub". Defaults to Goodfellow's; `false` for token sign-in only. */
126
+ signIn?: string | false;
76
127
  /** For tests. */
77
128
  fetch?: typeof fetch;
129
+ /** For tests. */
130
+ storage?: {
131
+ local?: StorageLike;
132
+ session?: StorageLike;
133
+ };
134
+ /** For tests. */
135
+ location?: BrowserLocation;
78
136
  }
79
137
  /**
80
138
  * Links to GitHub's token pages with what creating a site needs: creating the
@@ -98,6 +156,12 @@ export interface GitHubOptions {
98
156
  apiUrl?: string;
99
157
  /** For GitHub Enterprise. Defaults to `https://github.com`. */
100
158
  webUrl?: string;
159
+ /**
160
+ * The sign-in worker, which lets editors sign in with GitHub instead of
161
+ * pasting a token. Defaults to Goodfellow's (`GOODFELLOW_SIGN_IN`); give the
162
+ * address of your own copy, or `false` for token sign-in only.
163
+ */
164
+ signIn?: string | false;
101
165
  /** For tests. */
102
166
  fetch?: typeof fetch;
103
167
  /** For tests. */
@@ -105,6 +169,8 @@ export interface GitHubOptions {
105
169
  local?: StorageLike;
106
170
  session?: StorageLike;
107
171
  };
172
+ /** For tests. */
173
+ location?: BrowserLocation;
108
174
  }
109
175
  /**
110
176
  * Links to GitHub's token page with everything filled in except the
@@ -118,4 +184,4 @@ export declare function githubTokenLinks(repo: string, webUrl?: string): {
118
184
  /** Sign-in and storage for a site whose repository is on GitHub. */
119
185
  export declare function github(options: GitHubOptions): GitHost;
120
186
  //#endregion
121
- export type { GitHubSetupOptions };
187
+ export type { BrowserLocation, GitHubSetupOptions };