@eltjs/source-microsoft-sharepoint 0.0.0-stage → 0.3.10

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 ezzabuzaid
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,215 @@
1
- # Temporary Holding Version
1
+ # @eltjs/source-microsoft-sharepoint
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An ELT source for SharePoint Online sites. It reads the files, the lists and the pages of each site through Microsoft Graph, as one app with an app-only token. [@eltjs/sdk-microsoft-sharepoint](../../../sdks/microsoft/sharepoint/README.md) owns the calls to Graph. This source owns the streams, their schemas and how they sync.
4
+
5
+ The words in this README have one meaning each. See the glossary in [CONTEXT.md](./CONTEXT.md).
6
+
7
+ ```ts
8
+ import { join } from 'node:path';
9
+
10
+ import {
11
+ Connection,
12
+ Copy,
13
+ DocumentText,
14
+ LocalFiles,
15
+ Pipeline,
16
+ } from '@eltjs/elt';
17
+ import {
18
+ ComputedDataset,
19
+ SQLiteCheckpointStore,
20
+ SQLiteColumns,
21
+ SQLiteDestination,
22
+ SQLiteSyncHistory,
23
+ } from '@eltjs/elt-sqlite';
24
+ import { OfficeDocumentParser } from '@eltjs/parser-office/office-document-parser';
25
+ import { SharePointClient } from '@eltjs/sdk-microsoft-sharepoint';
26
+ import { SharePointSource } from '@eltjs/source-microsoft-sharepoint/sharepoint-source';
27
+
28
+ const tenantId = '0b7f3f60-1f2c-4c5e-9d0a-6a1f2e3d4c5b';
29
+ const source = new SharePointSource({
30
+ client: new SharePointClient({
31
+ tenantId,
32
+ clientId: 'c3a1f0e2-5b6d-4e7f-8a9b-0c1d2e3f4a5b',
33
+ clientSecret: 'the client secret of the app',
34
+ clock: globalThis,
35
+ }),
36
+ sites: ['https://contoso.sharepoint.com/sites/Sales'],
37
+ });
38
+ const warehouse = './outputs/warehouse';
39
+ const destination = new SQLiteDestination({
40
+ path: join(warehouse, 'warehouse.sqlite'),
41
+ });
42
+ const files = new LocalFiles({
43
+ directory: join(warehouse, 'sharepoint-files'),
44
+ });
45
+ const parser = new OfficeDocumentParser();
46
+
47
+ // The documents that the parser reads are stored; photos and videos stay in
48
+ // SharePoint.
49
+ const driveItems = destination.table('sharepoint_drive_items', (c) => [
50
+ ...SQLiteColumns.fromSchema(source.driveItems.jsonSchema),
51
+ c
52
+ .text('documentRef')
53
+ .from(source.driveItems.file.accepting(parser).store(files)),
54
+ ]);
55
+ const { streams } = await source.discover();
56
+
57
+ await new Pipeline({
58
+ clock: globalThis,
59
+ history: new SQLiteSyncHistory(),
60
+ connections: [
61
+ new Connection({
62
+ name: 'sharepoint',
63
+ source,
64
+ destination,
65
+ checkpoints: new SQLiteCheckpointStore({
66
+ path: join(warehouse, 'checkpoints.sqlite'),
67
+ }),
68
+ steps: streams.map(
69
+ (stream) =>
70
+ new Copy(
71
+ stream,
72
+ stream === source.driveItems
73
+ ? driveItems
74
+ : destination.table(`sharepoint_${stream.name}`),
75
+ {
76
+ id: `${source.identity}/${stream.name}`,
77
+ syncMode: 'incremental',
78
+ destinationSyncMode: 'append_dedup',
79
+ },
80
+ ),
81
+ ),
82
+ }),
83
+ ],
84
+ derived: [
85
+ new ComputedDataset({
86
+ into: destination,
87
+ name: 'sharepoint_document_text',
88
+ description: 'The text of each stored SharePoint document.',
89
+ from: [driveItems],
90
+ compute: new DocumentText({
91
+ parser: () => parser,
92
+ files: files.directory,
93
+ column: 'documentRef',
94
+ }),
95
+ }),
96
+ ],
97
+ }).run();
98
+ ```
99
+
100
+ ## How to use it
101
+
102
+ 1. Make a `SharePointClient` from the app registration of Microsoft Entra ID: the tenant ID, the client ID and a client secret. The host reads these values, for example from its environment. The source and the SDK read no environment variable.
103
+ 2. Make a `SharePointSource` with the client and the URL of each site. The identity of the source is `sharepoint:<tenantId>`, the tenant of the client.
104
+ 3. Copy each stream with `syncMode: 'incremental'` and `destinationSyncMode: 'append_dedup'`. Each stream deduplicates on its primary key and sends deletions. Give each copy an ID that holds the source identity, such as `sharepoint:<tenantId>/driveItems`, so that two tenants can be in one pipeline.
105
+ 4. To get the text of documents, store the files of `driveItems` with `file.accepting(parser).store(files)`, and derive their text with a `DocumentText` computed dataset (see [elt](../../../elt/README.md#attachment-text)). A file that the parser cannot read gets a row with its error in the dataset, and fails no copy.
106
+
107
+ Each site is a partition of each stream, with a checkpoint of its own. Thus a site that you add starts from the start, and the other sites keep their checkpoints. `siteUrl` is in each record and first in each primary key. It is the URL as the host wrote it.
108
+
109
+ ## Access
110
+
111
+ The app needs the Graph application permission `Sites.Selected`, and an administrator must grant it read access to each site. With `Sites.Selected`, the app cannot list its sites, so the host names them ([SDK ADR 0002](../../../sdks/microsoft/sharepoint/docs/adr/0002-a-sites-selected-app-cannot-list-its-sites-so-callers-name-site-urls.md)).
112
+
113
+ | Error | When | Failure type |
114
+ | ----------------------------- | --------------------------------------------------------------------- | ------------ |
115
+ | `SharePointAccessError` | Graph refused the token (401) or the access to a site (403). | `config` |
116
+ | `SharePointSiteNotFoundError` | No site is at a URL (404). | `config` |
117
+ | Any other error | Graph failed in another way, for example 500 or a refused delta link. | `system` |
118
+
119
+ A site that fails fails only its partition. The other sites load and save their checkpoints.
120
+
121
+ ## Streams
122
+
123
+ | Stream | One record for | Primary key | Sync |
124
+ | ---------------- | -------------------------------------------------------------------------- | ------------------------------- | -------- |
125
+ | `sites` | the site at each URL | `siteUrl`, `siteId` | snapshot |
126
+ | `drives` | each document library | `siteUrl`, `driveId` | snapshot |
127
+ | `driveItems` | each file and folder of each document library, with the file | `siteUrl`, `driveId`, `itemId` | delta |
128
+ | `lists` | each list, hidden lists and document libraries included, with its template | `siteUrl`, `listId` | snapshot |
129
+ | `listColumns` | each column of each list, with its type | `siteUrl`, `listId`, `columnId` | snapshot |
130
+ | `listItems` | each item of each list but the access request lists, with `fields` as JSON | `siteUrl`, `listId`, `itemId` | delta |
131
+ | `accessRequests` | each item of each access request list, with `fields` as JSON | `siteUrl`, `listId`, `itemId` | snapshot |
132
+ | `pages` | each modern page, with the HTML of its text web parts | `siteUrl`, `pageId` | snapshot |
133
+
134
+ - Each timestamp is UTC, in the millisecond form of elt, such as `2026-11-17T09:30:00.000Z`.
135
+ - A value that Graph does not give is `NULL`.
136
+ - `size` and `childCount` are integers. A file of SharePoint is at most 250 GB, far below 2^53.
137
+ - `createdBy` and `lastModifiedBy` are the identitySet of Graph as JSON, for example `{"user":{"id":"…","displayName":"Sam","email":"sam@contoso.com"}}`. `fields` of a list item and `settings` of a column are JSON too. Read a part with `json_extract`.
138
+ - A file of a document library is also an item of the list of the library. `driveItems.listItemId` is the `itemId` of that item in `listItems`, which holds the metadata columns of the library, such as a sector or a year.
139
+ - The root folder of a library has no row in `driveItems`: `drives` describes the library. The `parentId` of an item at the top of a library names the root folder.
140
+
141
+ ## Sync
142
+
143
+ **Delta** streams read through the delta queries of Graph ([ADR 0001](./docs/adr/0001-the-delta-queries-are-the-change-feed-of-drive-items-and-list-items.md)). A collection is a document library for `driveItems`, and a list for `listItems`.
144
+
145
+ - The first read of a site loads each collection, page by page. Each page ends in a checkpoint. A first load that fails continues at the next link that it saved, and does not read its first pages again.
146
+ - Later reads read the changes after the delta link of each collection. An item with the `deleted` facet is a `DELETE`. Each page of changes ends in a checkpoint.
147
+ - A collection that is new on the site starts its own first load. The other collections continue from their links.
148
+ - The site starts over with a `RESET` and loads each item again in these cases:
149
+ - Graph no longer serves a delta link (410).
150
+ - A collection of the checkpoint is gone from the site, for example a removed library. A delta tells no deletion for a collection that is gone.
151
+ - The stream has a field that the checkpoint was read without. A delta gives only the items that changed, so a new field would get values only on those items.
152
+ - A reload commits one time, when it ends. A `RESET` of a partition replaces the rows of the partition at its next commit ([elt ADR 0007](../../../elt/docs/adr/0007-a-stream-that-starts-over-reloads-into-a-hidden-target.md)). Thus readers keep the old rows of the site until the reload ends. A reload that fails starts again on the next run.
153
+
154
+ The checkpoint of a site is `{ fields, links }`: the fields that the reads carried, and for each collection ID `{ delta }`, its delta link, or `{ next }`, the next link of the page that a read got to.
155
+
156
+ **Snapshot** streams list their records in full on each read. An incremental copy compares each read with the snapshot of the last read, writes only the records that changed, and deletes the keys that Graph no longer lists (`ClosedWorld`). A read keeps one record for each primary key. When the pages of a collection give one item two times, for example because it changed during the read, the last one is the record.
157
+
158
+ `accessRequests` is a snapshot stream because Graph refuses the item delta of an access request list ([ADR 0002](./docs/adr/0002-a-list-whose-delta-graph-refuses-is-read-in-full.md)). The source finds these lists by their template, `accessRequest`. `listItems` does not read them.
159
+
160
+ A full refresh reads each stream in full, with no checkpoint and no deletion.
161
+
162
+ ## Files
163
+
164
+ `driveItems` supports file transfer. A copy selects what it takes from a file in its columns (see [elt](../../../elt/README.md#stored-files-and-document-parsing)).
165
+
166
+ - The source downloads a file only when a field of the copy accepts its name: `configuration.fileReads.some((read) => read.accepts(name))`. `file.accepting(new OfficeDocumentParser())` accepts only the names of Office documents and PDF files. Thus no photo or video is downloaded.
167
+ - The download goes to a folder of the run, as `<itemId><extension>`. The extension is `fileExtension(name)` of elt. The source removes the file after the consumer takes its record, and removes the folder when the run ends.
168
+ - A folder, and a file that no field accepts, gives `file: null`. A field of such a record is null.
169
+ - A file that Graph no longer has when the source downloads it (404) gives `file: null`. The delta tells its deletion on the next read.
170
+ - A delta gives a file again when its content or its metadata changes. Each time, the source downloads it again, and `LocalFiles` keeps one copy of the same content.
171
+
172
+ ## Watching
173
+
174
+ `changeSignals` gives one `SiteVersion` of the SDK for each site. Each tells about each selected stream. A watch reads each one every 60 seconds, and one read can take 30 seconds. A read is three requests to Graph: the site, its lists and its pages. Its value changes when the `lastModifiedDateTime` of a list or a page changes, or when a list or a page is added or removed. A document library is a list, so a change to a file changes the value too.
175
+
176
+ Graph sends change notifications (webhooks) only to a public URL, so the source does not use them.
177
+
178
+ ## Limits
179
+
180
+ - The `fields` of a list item and the `settings` of a column pass through JSON numbers. SharePoint keeps Number and Currency columns as doubles, so each value loads exactly; only its text can differ from what Graph sent, such as `1.1` for `1.10`.
181
+ - The snapshot streams read each collection whole: the columns of a list, the pages of a site and the items of an access request list. A read of a site keeps all its records until it ends, to keep one record for each key. SharePoint keeps these collections small. Files and list items go through the delta feeds, one page at a time.
182
+
183
+ - The source reads no versions of files and no permissions of items. `/sites/{id}/permissions` answers 403 to a `Sites.Selected` app.
184
+ - The source reads no text from images or videos. The text of documents is derived data: a `DocumentText` dataset of the host makes it.
185
+ - Graph leaves out the lists that it marks `system`, and the hidden columns of a list and of its items.
186
+ - A reload loads each collection of the site again, and downloads again each file that a field accepts.
187
+ - `pages` asks Graph for the canvas of each page on each read: one request for each page.
188
+ - A delta can give the same item more than once. The last one is the current one, and the copy keeps it.
189
+ - Graph documents that a drive delta can leave out `parentReference.path` and `cTag`. Then `path` and `cTag` are `NULL`.
190
+ - The client takes a client secret, not a certificate.
191
+
192
+ ## Live checks
193
+
194
+ On 2026-11-17, with the app-only token of an app that holds only `Sites.Selected`, granted read on one site of a tenant of SharePoint Online:
195
+
196
+ - The app cannot list sites: `GET /sites?search=*`, `GET /sites/getAllSites` and `GET /sites/root` answer 403. A site that exists and that the app has no grant on answers 403. A site that does not exist answers 404.
197
+ - The granted site had 6 drives, 10 lists, 5,727 files, 314 folders, about 6,450 list items and 4 pages. Its drive deltas gave the 314 folders 682 times: a delta gives a folder again when its children change, and the copy keeps the last one. Its Documents library held about 72 GB, of which about 70 GB were photos and videos (jpg, mp4, mov), and about 714 documents (docx, pdf, pptx, xlsx).
198
+ - The drive delta of each library, and the list items delta of each list but one, end with a delta link.
199
+ - A drive delta gave the root folder of the drive on each of its pages: 31 times over the 31 pages of one drive. The root folder has no `eTag` and no `createdBy`.
200
+ - Graph answered the item delta of the hidden list with the template `accessRequest` with 503 `serviceNotAvailable` on each try, while `GET /sites/{id}/lists/{id}/items` answered 200.
201
+ - Two full reads with no edits between them gave the same values. No value changes from one read to the next.
202
+ - `GET /sites/{id}/pages/{id}/microsoft.graph.sitePage?$expand=canvasLayout` answers 200.
203
+
204
+ Not checked live:
205
+
206
+ - An expired delta link: none was available. Graph documents a 410, and the tests stub it.
207
+ - That the `lastModifiedDateTime` of a list moves when one of its items changes, which `SiteVersion` uses. The app has only a read grant, and no test site is available.
208
+ - A pass of this source over the site. `src/sharepoint-live.test.ts` makes one, and skips unless `SHAREPOINT_TENANT_ID`, `SHAREPOINT_CLIENT_ID` and `SHAREPOINT_CLIENT_SECRET` are set. It downloads only the workbooks of the site.
209
+
210
+ - A second pass 12 hours later (2026-11-18), from the checkpoints of the first, loaded only what the deltas gave: 10 drive items and 10 list items, no deletion. 3 files that people edited had a new `lastModifiedDateTime`; 4 folders had a new `size`, since a file in them changed; 3 documents had a new `eTag` and the same `cTag`, a change of their metadata and not of their content.
211
+
212
+ ## Decisions
213
+
214
+ - [ADR 0001](./docs/adr/0001-the-delta-queries-are-the-change-feed-of-drive-items-and-list-items.md): the delta queries are the change feed of drive items and list items.
215
+ - [ADR 0002](./docs/adr/0002-a-list-whose-delta-graph-refuses-is-read-in-full.md): a list whose delta Graph refuses is read in full.
@@ -0,0 +1,22 @@
1
+ import type { CopyConfiguration, KeyValue, SourceMessage } from '@eltjs/elt';
2
+ import { type DeltaPage } from '@eltjs/sdk-microsoft-sharepoint';
3
+ import type { SharePointRun } from './sharepoint-run.ts';
4
+ import { SharePointStream } from './sharepoint-stream.ts';
5
+ /**
6
+ * A stream read through the delta queries of Graph, one for each collection
7
+ * of the site (ADR 0001). The first read loads every item, page by page, with
8
+ * a checkpoint after each page, so a first load that fails resumes at the
9
+ * next link it saved. Later reads apply the changes after each delta link:
10
+ * an item with the deleted facet is a deletion. When Graph no longer serves
11
+ * a link, when a collection of the state is gone, or when the stream carries
12
+ * a field that the state was read without, the stream starts the site over
13
+ * with a RESET and loads every item again.
14
+ */
15
+ export declare abstract class DeltaStream<Item> extends SharePointStream {
16
+ #private;
17
+ protected abstract collections(siteUrl: string, run: SharePointRun, signal: AbortSignal): Promise<readonly string[]>;
18
+ protected abstract pages(siteUrl: string, collection: string, link: string | undefined, run: SharePointRun, signal: AbortSignal): AsyncIterable<DeltaPage<Item>>;
19
+ protected abstract messages(configuration: CopyConfiguration, siteUrl: string, collection: string, item: Item, run: SharePointRun, signal: AbortSignal): AsyncIterable<SourceMessage>;
20
+ extract(configuration: CopyConfiguration, state: unknown, siteUrl: string, run: SharePointRun, signal: AbortSignal): AsyncGenerator<SourceMessage>;
21
+ protected deletion(configuration: CopyConfiguration, key: Readonly<Record<string, KeyValue>>): Generator<SourceMessage>;
22
+ }
@@ -0,0 +1,115 @@
1
+ import { DeltaExpiredError, } from '@eltjs/sdk-microsoft-sharepoint';
2
+ import { SharePointStream } from './sharepoint-stream.js';
3
+ function link(value) {
4
+ if (typeof value !== 'object' || value === null)
5
+ return undefined;
6
+ if ('delta' in value && typeof value.delta === 'string')
7
+ return { delta: value.delta };
8
+ if ('next' in value && typeof value.next === 'string')
9
+ return { next: value.next };
10
+ return undefined;
11
+ }
12
+ function resumeLink(saved) {
13
+ if (saved === undefined)
14
+ return undefined;
15
+ return 'delta' in saved ? saved.delta : saved.next;
16
+ }
17
+ function parse(state) {
18
+ if (state === null)
19
+ return null;
20
+ const unknown = () => new TypeError(`Unknown SharePoint delta state ${JSON.stringify(state)}`);
21
+ if (typeof state !== 'object' ||
22
+ !('fields' in state) ||
23
+ !Array.isArray(state.fields) ||
24
+ !state.fields.every((field) => typeof field === 'string') ||
25
+ !('links' in state) ||
26
+ typeof state.links !== 'object' ||
27
+ state.links === null)
28
+ throw unknown();
29
+ const links = {};
30
+ for (const [collection, value] of Object.entries(state.links)) {
31
+ const parsed = link(value);
32
+ if (parsed === undefined)
33
+ throw unknown();
34
+ links[collection] = parsed;
35
+ }
36
+ return { fields: state.fields, links };
37
+ }
38
+ /**
39
+ * A stream read through the delta queries of Graph, one for each collection
40
+ * of the site (ADR 0001). The first read loads every item, page by page, with
41
+ * a checkpoint after each page, so a first load that fails resumes at the
42
+ * next link it saved. Later reads apply the changes after each delta link:
43
+ * an item with the deleted facet is a deletion. When Graph no longer serves
44
+ * a link, when a collection of the state is gone, or when the stream carries
45
+ * a field that the state was read without, the stream starts the site over
46
+ * with a RESET and loads every item again.
47
+ */
48
+ export class DeltaStream extends SharePointStream {
49
+ async *extract(configuration, state, siteUrl, run, signal) {
50
+ const collections = await this.collections(siteUrl, run, signal);
51
+ const read = (links) => this.#read(configuration, siteUrl, collections, links, run, signal);
52
+ const saved = configuration.syncMode === 'incremental' ? parse(state) : null;
53
+ if (saved === null) {
54
+ yield* read(new Map());
55
+ return;
56
+ }
57
+ const links = new Map(Object.entries(saved.links));
58
+ if (this.#gained(saved.fields) ||
59
+ links.keys().some((collection) => !collections.includes(collection))) {
60
+ yield* this.#reload(read);
61
+ return;
62
+ }
63
+ try {
64
+ yield* read(links);
65
+ }
66
+ catch (error) {
67
+ if (!(error instanceof DeltaExpiredError))
68
+ throw error;
69
+ yield* this.#reload(read);
70
+ }
71
+ }
72
+ // A DELETE in an incremental read; a full refresh replaces every row, so
73
+ // it deletes nothing.
74
+ *deletion(configuration, key) {
75
+ if (configuration.syncMode === 'incremental')
76
+ yield { type: 'DELETE', stream: this.stream.name, key };
77
+ }
78
+ // A RESET of a partition replaces its rows at the next commit (elt README,
79
+ // "Reset"), so readers see the site fill again page by page, and a reload
80
+ // that fails resumes at the last link it saved. A hidden reload of a
81
+ // partition, as of a whole stream (elt ADR 0007), is backlog #4572.
82
+ async *#reload(read) {
83
+ yield { type: 'RESET', stream: this.stream.name };
84
+ yield* read(new Map());
85
+ }
86
+ async *#read(configuration, siteUrl, collections, from, run, signal) {
87
+ const links = new Map(from);
88
+ const state = () => ({
89
+ type: 'STATE',
90
+ stream: this.stream.name,
91
+ state: { fields: this.#fields, links: Object.fromEntries(links) },
92
+ });
93
+ for (const collection of collections) {
94
+ const start = resumeLink(links.get(collection));
95
+ for await (const page of this.pages(siteUrl, collection, start, run, signal)) {
96
+ for (const item of page.items)
97
+ yield* this.messages(configuration, siteUrl, collection, item, run, signal);
98
+ links.set(collection, 'deltaLink' in page
99
+ ? { delta: page.deltaLink }
100
+ : { next: page.nextLink });
101
+ yield state();
102
+ }
103
+ }
104
+ }
105
+ // The fields a read carries. The state records them, since a delta gives
106
+ // only the items that changed, and a field added later would reach only
107
+ // them: elt keeps a stream's checkpoint and rows through a change of its
108
+ // fields, and leaves filling them in to the source.
109
+ get #fields() {
110
+ return Object.keys(this.stream.jsonSchema.properties ?? {});
111
+ }
112
+ #gained(read) {
113
+ return this.#fields.some((field) => !read.includes(field));
114
+ }
115
+ }
@@ -0,0 +1,59 @@
1
+ import type { RecordDraft } from '@eltjs/elt';
2
+ import type { PresentListItem } from '@eltjs/sdk-microsoft-sharepoint';
3
+ export declare const accessRequestTemplate = "accessRequest";
4
+ export declare const listItemProperties: {
5
+ readonly siteUrl: {
6
+ type: 'string';
7
+ minLength: 1;
8
+ description: string;
9
+ };
10
+ readonly listId: {
11
+ readonly type: 'string';
12
+ readonly minLength: 1;
13
+ readonly description: 'The list of the item: lists.listId.';
14
+ };
15
+ readonly itemId: {
16
+ readonly type: 'string';
17
+ readonly minLength: 1;
18
+ readonly description: "SharePoint's ID of the item in its list, such as 12. In a document library, driveItems.listItemId refers to it.";
19
+ };
20
+ readonly contentType: {
21
+ readonly type: 'string';
22
+ readonly description: 'The name of the content type of the item, such as Item.';
23
+ };
24
+ readonly contentTypeId: {
25
+ readonly type: 'string';
26
+ readonly description: 'The ID of the content type of the item.';
27
+ };
28
+ readonly webUrl: {
29
+ readonly type: 'string';
30
+ readonly description: 'The URL of the item.';
31
+ };
32
+ readonly createdDateTime: {
33
+ readonly type: 'string';
34
+ readonly format: 'date-time';
35
+ readonly description: 'When the item was created, in UTC.';
36
+ };
37
+ readonly lastModifiedDateTime: {
38
+ readonly type: 'string';
39
+ readonly format: 'date-time';
40
+ readonly description: 'When the item last changed, in UTC.';
41
+ };
42
+ readonly createdBy: {
43
+ type: readonly ['string', 'null'];
44
+ description: string;
45
+ };
46
+ readonly lastModifiedBy: {
47
+ type: readonly ['string', 'null'];
48
+ description: string;
49
+ };
50
+ readonly eTag: {
51
+ readonly type: 'string';
52
+ readonly description: 'The version tag of the item, which changes when it changes.';
53
+ };
54
+ readonly fields: {
55
+ readonly type: 'string';
56
+ readonly description: "The value of each column of the item that is not hidden, as JSON, by the name of the column (listColumns.name), as Graph gives it. Read one with json_extract(fields, '$.Title').";
57
+ };
58
+ };
59
+ export declare function listItemRecord(url: string, listId: string, item: PresentListItem): RecordDraft<typeof listItemProperties>;