@aleup/core 0.1.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/LICENSE +202 -0
- package/dist/accept.d.ts +12 -0
- package/dist/accept.d.ts.map +1 -0
- package/dist/accept.js +21 -0
- package/dist/accept.js.map +1 -0
- package/dist/format.d.ts +5 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +20 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mime.d.ts +62 -0
- package/dist/mime.d.ts.map +1 -0
- package/dist/mime.js +157 -0
- package/dist/mime.js.map +1 -0
- package/dist/ports.d.ts +60 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +9 -0
- package/dist/ports.js.map +1 -0
- package/package.json +36 -0
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 [yyyy] [name of copyright owner]
|
|
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/dist/accept.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter a file list down to extensions allowed by `accept` (a comma-separated ".ext" list).
|
|
3
|
+
* Folder pickers (`webkitdirectory`) ignore the `accept` attribute entirely, so callers that let
|
|
4
|
+
* the user select a whole folder must filter client-side before upload — the host's server-side
|
|
5
|
+
* check remains the authoritative gate.
|
|
6
|
+
*
|
|
7
|
+
* Structural on `{ name }` so it works on `File`, directory entries, or provider items alike.
|
|
8
|
+
*/
|
|
9
|
+
export declare function filterFilesByAccept<T extends {
|
|
10
|
+
name: string;
|
|
11
|
+
}>(files: T[], accept: string): T[];
|
|
12
|
+
//# sourceMappingURL=accept.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accept.d.ts","sourceRoot":"","sources":["../src/accept.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,CAU/F"}
|
package/dist/accept.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter a file list down to extensions allowed by `accept` (a comma-separated ".ext" list).
|
|
3
|
+
* Folder pickers (`webkitdirectory`) ignore the `accept` attribute entirely, so callers that let
|
|
4
|
+
* the user select a whole folder must filter client-side before upload — the host's server-side
|
|
5
|
+
* check remains the authoritative gate.
|
|
6
|
+
*
|
|
7
|
+
* Structural on `{ name }` so it works on `File`, directory entries, or provider items alike.
|
|
8
|
+
*/
|
|
9
|
+
export function filterFilesByAccept(files, accept) {
|
|
10
|
+
const exts = accept
|
|
11
|
+
.split(",")
|
|
12
|
+
.map((e) => e.trim().toLowerCase())
|
|
13
|
+
.filter(Boolean);
|
|
14
|
+
if (exts.length === 0)
|
|
15
|
+
return files;
|
|
16
|
+
return files.filter((f) => {
|
|
17
|
+
const name = f.name.toLowerCase();
|
|
18
|
+
return exts.some((ext) => name.endsWith(ext));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=accept.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accept.js","sourceRoot":"","sources":["../src/accept.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAA6B,KAAU,EAAE,MAAc;IACxF,MAAM,IAAI,GAAG,MAAM;SAChB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;SAClC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACpC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACxB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Renderable document formats a viewer routes on. */
|
|
2
|
+
export type DocFormat = "pdf" | "docx" | "md" | "text" | "image" | "google-native" | "other";
|
|
3
|
+
/** Classify by MIME with filename fallback. */
|
|
4
|
+
export declare function detectFormat(mimeType: string, name: string): DocFormat;
|
|
5
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,eAAe,GAAG,OAAO,CAAC;AAE7F,+CAA+C;AAC/C,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAetE"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Classify by MIME with filename fallback. */
|
|
2
|
+
export function detectFormat(mimeType, name) {
|
|
3
|
+
const lower = name.toLowerCase();
|
|
4
|
+
if (mimeType === "application/pdf" || lower.endsWith(".pdf"))
|
|
5
|
+
return "pdf";
|
|
6
|
+
if (mimeType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
|
|
7
|
+
lower.endsWith(".docx") ||
|
|
8
|
+
lower.endsWith(".doc"))
|
|
9
|
+
return "docx";
|
|
10
|
+
if (mimeType === "text/markdown" || lower.endsWith(".md"))
|
|
11
|
+
return "md";
|
|
12
|
+
if (mimeType === "text/plain" || lower.endsWith(".txt"))
|
|
13
|
+
return "text";
|
|
14
|
+
if (mimeType.startsWith("application/vnd.google-apps."))
|
|
15
|
+
return "google-native";
|
|
16
|
+
if (mimeType.startsWith("image/") || /\.(png|jpe?g|gif|webp|svg|bmp)$/i.test(lower))
|
|
17
|
+
return "image";
|
|
18
|
+
return "other";
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAGA,+CAA+C;AAC/C,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,IAAY;IACzD,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,IAAI,QAAQ,KAAK,iBAAiB,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3E,IACE,QAAQ,KAAK,yEAAyE;QACtF,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QAEtB,OAAO,MAAM,CAAC;IAChB,IAAI,QAAQ,KAAK,eAAe,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACvE,IAAI,QAAQ,KAAK,YAAY,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACvE,IAAI,QAAQ,CAAC,UAAU,CAAC,8BAA8B,CAAC;QAAE,OAAO,eAAe,CAAC;IAChF,IAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,kCAAkC,CAAC,IAAI,CAAC,KAAK,CAAC;QACjF,OAAO,OAAO,CAAC;IACjB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
package/dist/mime.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare const DRIVE_FOLDER_MIME = "application/vnd.google-apps.folder";
|
|
2
|
+
/** Non-native binary/text types text can be extracted from (fetched via alt=media). */
|
|
3
|
+
export declare const SUPPORTED_BINARY_MIMES: Set<string>;
|
|
4
|
+
/** Raster image types that are OCR-able for text extraction. */
|
|
5
|
+
export declare const IMAGE_MIMES: Set<string>;
|
|
6
|
+
/** True for native Google editor files (Docs/Sheets/Slides) — these cannot be fetched via alt=media. */
|
|
7
|
+
export declare function isNativeGoogleDoc(mimeType: string): boolean;
|
|
8
|
+
/** A human-readable file type an admin can allow/disallow for import. */
|
|
9
|
+
export interface MimeOption {
|
|
10
|
+
mime: string;
|
|
11
|
+
label: string;
|
|
12
|
+
/** File extensions (with leading dot) for this type — feeds the upload picker's `accept` hint. */
|
|
13
|
+
exts: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The built-in catalog of importable file types, with display labels and extensions — the master
|
|
17
|
+
* list an "allowed file types" admin editor is drawn from. Order is grouped (documents → data →
|
|
18
|
+
* presentations → text → images) to read sensibly in a UI. Hosts can extend it at runtime with
|
|
19
|
+
* custom {mime, ext} entries, so this is the baseline, not the full universe.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_MIME_CATALOG: MimeOption[];
|
|
22
|
+
/** Every mime in the catalog — the default allow-list (everything supported is allowed). */
|
|
23
|
+
export declare const ALL_DEFAULT_MIMES: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Build the upload picker's `accept` string from a set of allowed mimes, drawing extensions from
|
|
26
|
+
* the given catalog (built-in ∪ any host custom types). Only allowed types contribute, so the
|
|
27
|
+
* picker never advertises a type the server-side gate would reject. Order follows the catalog;
|
|
28
|
+
* duplicate extensions are collapsed.
|
|
29
|
+
*/
|
|
30
|
+
export declare function acceptExtensionsFor(allowed: Iterable<string>, catalog?: MimeOption[]): string;
|
|
31
|
+
/** Default `accept` hint for the upload picker: every built-in type's extensions. */
|
|
32
|
+
export declare const DEFAULT_ACCEPT_EXTENSIONS: string;
|
|
33
|
+
/**
|
|
34
|
+
* Whether a file may be imported given an allow-list. Native Google editor files map to their
|
|
35
|
+
* export target (Doc→DOCX, Sheet→XLSX, Slides→PPTX), so allowing the corresponding Office type
|
|
36
|
+
* also allows importing the equivalent Google file.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isMimeAllowed(mimeType: string, allowed: Iterable<string>): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The editable binary format a native Google editor file is exported to, with the matching file
|
|
41
|
+
* extension. Returns null for non-native types (use alt=media instead).
|
|
42
|
+
* Docs → DOCX, Sheets → XLSX, Slides → PPTX.
|
|
43
|
+
* These are round-trippable: Google can convert them back to native on upload AND common parsers
|
|
44
|
+
* can extract text from each. XLSX over CSV matters: a CSV export of a multi-tab sheet only
|
|
45
|
+
* contains the FIRST tab.
|
|
46
|
+
*/
|
|
47
|
+
export declare function nativeGoogleExportTarget(mimeType: string): {
|
|
48
|
+
mime: string;
|
|
49
|
+
ext: string;
|
|
50
|
+
} | null;
|
|
51
|
+
/**
|
|
52
|
+
* Inverse of nativeGoogleExportTarget: the native Google editor type an Office binary converts to
|
|
53
|
+
* when uploaded to Drive with a target mimeType (DOCX → Doc, XLSX → Sheet, PPTX → Slides). Used
|
|
54
|
+
* when opening a stored Office file for editing — Drive converts on upload so it lands as an
|
|
55
|
+
* editable native Google file. Returns null for types Drive can't cleanly convert (e.g. PDF).
|
|
56
|
+
*/
|
|
57
|
+
export declare function nativeGoogleImportTarget(mimeType: string): string | null;
|
|
58
|
+
/** True for files text can be extracted from (after export, for native Google files). */
|
|
59
|
+
export declare function isIndexable(mimeType: string): boolean;
|
|
60
|
+
/** True for items a drive picker should let the user select (folders, or any indexable file). */
|
|
61
|
+
export declare function isPickable(mimeType: string): boolean;
|
|
62
|
+
//# sourceMappingURL=mime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../src/mime.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,iBAAiB,uCAAuC,CAAC;AAKtE,uFAAuF;AACvF,eAAO,MAAM,sBAAsB,aAajC,CAAC;AAEH,gEAAgE;AAChE,eAAO,MAAM,WAAW,aAA0E,CAAC;AAEnG,wGAAwG;AACxG,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,yEAAyE;AACzE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,kGAAkG;IAClG,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,UAAU,EAyB5C,CAAC;AAEF,4FAA4F;AAC5F,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAA4C,CAAC;AAEnF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,EACzB,OAAO,GAAE,UAAU,EAAyB,GAC3C,MAAM,CAQR;AAED,qFAAqF;AACrF,eAAO,MAAM,yBAAyB,EAAE,MAA+C,CAAC;AAExF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,OAAO,CAOlF;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiB/F;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAcxE;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAIrD;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD"}
|
package/dist/mime.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Central MIME registry — a single source of truth for what a document pipeline can ingest.
|
|
2
|
+
//
|
|
3
|
+
// This file is deliberately PURE (zero imports) so it can be bundled into clients (a cloud-drive
|
|
4
|
+
// picker), API routes, and server-side ingest paths alike. Keeping all three in sync prevents the
|
|
5
|
+
// class of bug where "what the picker lets you select" drifts apart from "what the parser can
|
|
6
|
+
// actually extract text from" (a folder would import to zero files silently).
|
|
7
|
+
export const DRIVE_FOLDER_MIME = "application/vnd.google-apps.folder";
|
|
8
|
+
const NATIVE_DOC_PREFIX = "application/vnd.google-apps";
|
|
9
|
+
const DOCX_MIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
10
|
+
/** Non-native binary/text types text can be extracted from (fetched via alt=media). */
|
|
11
|
+
export const SUPPORTED_BINARY_MIMES = new Set([
|
|
12
|
+
"application/pdf",
|
|
13
|
+
"application/msword",
|
|
14
|
+
DOCX_MIME,
|
|
15
|
+
"application/vnd.ms-excel", // legacy .xls
|
|
16
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // .xlsx
|
|
17
|
+
"application/vnd.ms-powerpoint", // legacy .ppt
|
|
18
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation", // .pptx
|
|
19
|
+
"text/plain",
|
|
20
|
+
"text/markdown",
|
|
21
|
+
"text/csv",
|
|
22
|
+
"text/html",
|
|
23
|
+
"application/json",
|
|
24
|
+
]);
|
|
25
|
+
/** Raster image types that are OCR-able for text extraction. */
|
|
26
|
+
export const IMAGE_MIMES = new Set(["image/jpeg", "image/png", "image/gif", "image/webp"]);
|
|
27
|
+
/** True for native Google editor files (Docs/Sheets/Slides) — these cannot be fetched via alt=media. */
|
|
28
|
+
export function isNativeGoogleDoc(mimeType) {
|
|
29
|
+
return mimeType.startsWith(NATIVE_DOC_PREFIX) && mimeType !== DRIVE_FOLDER_MIME;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The built-in catalog of importable file types, with display labels and extensions — the master
|
|
33
|
+
* list an "allowed file types" admin editor is drawn from. Order is grouped (documents → data →
|
|
34
|
+
* presentations → text → images) to read sensibly in a UI. Hosts can extend it at runtime with
|
|
35
|
+
* custom {mime, ext} entries, so this is the baseline, not the full universe.
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_MIME_CATALOG = [
|
|
38
|
+
{ mime: "application/pdf", label: "PDF (.pdf)", exts: [".pdf"] },
|
|
39
|
+
{ mime: DOCX_MIME, label: "Word (.docx)", exts: [".docx"] },
|
|
40
|
+
{ mime: "application/msword", label: "Word 97–2003 (.doc)", exts: [".doc"] },
|
|
41
|
+
{
|
|
42
|
+
mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
43
|
+
label: "Excel (.xlsx)",
|
|
44
|
+
exts: [".xlsx"],
|
|
45
|
+
},
|
|
46
|
+
{ mime: "application/vnd.ms-excel", label: "Excel 97–2003 (.xls)", exts: [".xls"] },
|
|
47
|
+
{
|
|
48
|
+
mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
49
|
+
label: "PowerPoint (.pptx)",
|
|
50
|
+
exts: [".pptx"],
|
|
51
|
+
},
|
|
52
|
+
{ mime: "application/vnd.ms-powerpoint", label: "PowerPoint 97–2003 (.ppt)", exts: [".ppt"] },
|
|
53
|
+
{ mime: "text/plain", label: "Text (.txt)", exts: [".txt"] },
|
|
54
|
+
{ mime: "text/markdown", label: "Markdown (.md)", exts: [".md"] },
|
|
55
|
+
{ mime: "text/csv", label: "CSV (.csv)", exts: [".csv"] },
|
|
56
|
+
{ mime: "text/html", label: "HTML (.html)", exts: [".html"] },
|
|
57
|
+
{ mime: "application/json", label: "JSON (.json)", exts: [".json"] },
|
|
58
|
+
{ mime: "image/jpeg", label: "JPEG image", exts: [".jpg", ".jpeg"] },
|
|
59
|
+
{ mime: "image/png", label: "PNG image", exts: [".png"] },
|
|
60
|
+
{ mime: "image/gif", label: "GIF image", exts: [".gif"] },
|
|
61
|
+
{ mime: "image/webp", label: "WebP image", exts: [".webp"] },
|
|
62
|
+
];
|
|
63
|
+
/** Every mime in the catalog — the default allow-list (everything supported is allowed). */
|
|
64
|
+
export const ALL_DEFAULT_MIMES = DEFAULT_MIME_CATALOG.map((o) => o.mime);
|
|
65
|
+
/**
|
|
66
|
+
* Build the upload picker's `accept` string from a set of allowed mimes, drawing extensions from
|
|
67
|
+
* the given catalog (built-in ∪ any host custom types). Only allowed types contribute, so the
|
|
68
|
+
* picker never advertises a type the server-side gate would reject. Order follows the catalog;
|
|
69
|
+
* duplicate extensions are collapsed.
|
|
70
|
+
*/
|
|
71
|
+
export function acceptExtensionsFor(allowed, catalog = DEFAULT_MIME_CATALOG) {
|
|
72
|
+
const allow = allowed instanceof Set ? allowed : new Set(allowed);
|
|
73
|
+
const out = [];
|
|
74
|
+
for (const o of catalog) {
|
|
75
|
+
if (!allow.has(o.mime))
|
|
76
|
+
continue;
|
|
77
|
+
for (const e of o.exts)
|
|
78
|
+
if (!out.includes(e))
|
|
79
|
+
out.push(e);
|
|
80
|
+
}
|
|
81
|
+
return out.join(",");
|
|
82
|
+
}
|
|
83
|
+
/** Default `accept` hint for the upload picker: every built-in type's extensions. */
|
|
84
|
+
export const DEFAULT_ACCEPT_EXTENSIONS = acceptExtensionsFor(ALL_DEFAULT_MIMES);
|
|
85
|
+
/**
|
|
86
|
+
* Whether a file may be imported given an allow-list. Native Google editor files map to their
|
|
87
|
+
* export target (Doc→DOCX, Sheet→XLSX, Slides→PPTX), so allowing the corresponding Office type
|
|
88
|
+
* also allows importing the equivalent Google file.
|
|
89
|
+
*/
|
|
90
|
+
export function isMimeAllowed(mimeType, allowed) {
|
|
91
|
+
const set = allowed instanceof Set ? allowed : new Set(allowed);
|
|
92
|
+
if (isNativeGoogleDoc(mimeType)) {
|
|
93
|
+
const target = nativeGoogleExportTarget(mimeType);
|
|
94
|
+
return target ? set.has(target.mime) : false;
|
|
95
|
+
}
|
|
96
|
+
return set.has(mimeType);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The editable binary format a native Google editor file is exported to, with the matching file
|
|
100
|
+
* extension. Returns null for non-native types (use alt=media instead).
|
|
101
|
+
* Docs → DOCX, Sheets → XLSX, Slides → PPTX.
|
|
102
|
+
* These are round-trippable: Google can convert them back to native on upload AND common parsers
|
|
103
|
+
* can extract text from each. XLSX over CSV matters: a CSV export of a multi-tab sheet only
|
|
104
|
+
* contains the FIRST tab.
|
|
105
|
+
*/
|
|
106
|
+
export function nativeGoogleExportTarget(mimeType) {
|
|
107
|
+
switch (mimeType) {
|
|
108
|
+
case "application/vnd.google-apps.document":
|
|
109
|
+
return { mime: DOCX_MIME, ext: ".docx" };
|
|
110
|
+
case "application/vnd.google-apps.spreadsheet":
|
|
111
|
+
return {
|
|
112
|
+
mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
113
|
+
ext: ".xlsx",
|
|
114
|
+
};
|
|
115
|
+
case "application/vnd.google-apps.presentation":
|
|
116
|
+
return {
|
|
117
|
+
mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
118
|
+
ext: ".pptx",
|
|
119
|
+
};
|
|
120
|
+
default:
|
|
121
|
+
return null; // Forms, Drawings, Sites, etc. have no clean text export — not indexable.
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Inverse of nativeGoogleExportTarget: the native Google editor type an Office binary converts to
|
|
126
|
+
* when uploaded to Drive with a target mimeType (DOCX → Doc, XLSX → Sheet, PPTX → Slides). Used
|
|
127
|
+
* when opening a stored Office file for editing — Drive converts on upload so it lands as an
|
|
128
|
+
* editable native Google file. Returns null for types Drive can't cleanly convert (e.g. PDF).
|
|
129
|
+
*/
|
|
130
|
+
export function nativeGoogleImportTarget(mimeType) {
|
|
131
|
+
switch (mimeType) {
|
|
132
|
+
case DOCX_MIME:
|
|
133
|
+
case "application/msword":
|
|
134
|
+
return "application/vnd.google-apps.document";
|
|
135
|
+
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
|
|
136
|
+
case "application/vnd.ms-excel":
|
|
137
|
+
return "application/vnd.google-apps.spreadsheet";
|
|
138
|
+
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
139
|
+
case "application/vnd.ms-powerpoint":
|
|
140
|
+
return "application/vnd.google-apps.presentation";
|
|
141
|
+
default:
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** True for files text can be extracted from (after export, for native Google files). */
|
|
146
|
+
export function isIndexable(mimeType) {
|
|
147
|
+
if (mimeType === DRIVE_FOLDER_MIME)
|
|
148
|
+
return false;
|
|
149
|
+
if (isNativeGoogleDoc(mimeType))
|
|
150
|
+
return nativeGoogleExportTarget(mimeType) !== null;
|
|
151
|
+
return SUPPORTED_BINARY_MIMES.has(mimeType) || IMAGE_MIMES.has(mimeType);
|
|
152
|
+
}
|
|
153
|
+
/** True for items a drive picker should let the user select (folders, or any indexable file). */
|
|
154
|
+
export function isPickable(mimeType) {
|
|
155
|
+
return mimeType === DRIVE_FOLDER_MIME || isIndexable(mimeType);
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=mime.js.map
|
package/dist/mime.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../src/mime.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,EAAE;AACF,iGAAiG;AACjG,kGAAkG;AAClG,8FAA8F;AAC9F,8EAA8E;AAE9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,oCAAoC,CAAC;AAEtE,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AACxD,MAAM,SAAS,GAAG,yEAAyE,CAAC;AAE5F,uFAAuF;AACvF,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAS;IACpD,iBAAiB;IACjB,oBAAoB;IACpB,SAAS;IACT,0BAA0B,EAAE,cAAc;IAC1C,mEAAmE,EAAE,QAAQ;IAC7E,+BAA+B,EAAE,cAAc;IAC/C,2EAA2E,EAAE,QAAQ;IACrF,YAAY;IACZ,eAAe;IACf,UAAU;IACV,WAAW;IACX,kBAAkB;CACnB,CAAC,CAAC;AAEH,gEAAgE;AAChE,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAS,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAEnG,wGAAwG;AACxG,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,OAAO,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,QAAQ,KAAK,iBAAiB,CAAC;AAClF,CAAC;AAUD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAiB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AACH,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,IAAI,QAAQ,KAAK,iBAAiB;QAAE,OAAO,KAAK,CAAC;IACjD,IAAI,iBAAiB,CAAC,QAAQ,CAAC;QAAE,OAAO,wBAAwB,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IACpF,OAAO,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC3E,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,OAAO,QAAQ,KAAK,iBAAiB,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/ports.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Where an upload should be sent. */
|
|
2
|
+
export interface UploadTarget {
|
|
3
|
+
/** Absolute or app-relative URL that accepts a multipart POST. */
|
|
4
|
+
endpoint: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
/** Multipart field name for the file body. Default "file". */
|
|
7
|
+
fieldName?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A file that finished uploading (shape intentionally minimal; `response` is transport-specific). */
|
|
10
|
+
export interface UploadedFile {
|
|
11
|
+
id?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
response?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Where finalized bytes go. The host routes this to its own storage policy — e.g. a
|
|
17
|
+
* "drive-as-truth" copy, a signed-token endpoint, or a plain S3 proxy. aleup stays ignorant of why.
|
|
18
|
+
*/
|
|
19
|
+
export interface DestinationPort {
|
|
20
|
+
/** Target for LOCAL browser uploads (typically session-cookie authed). */
|
|
21
|
+
localUploadTarget(): UploadTarget | Promise<UploadTarget>;
|
|
22
|
+
/**
|
|
23
|
+
* Target for REMOTE companion-streamed uploads (typically token authed). Called once per import
|
|
24
|
+
* batch — this is where the host does its token dance.
|
|
25
|
+
*/
|
|
26
|
+
remoteUploadTarget(): Promise<UploadTarget>;
|
|
27
|
+
onFileUploaded?(file: UploadedFile): void;
|
|
28
|
+
}
|
|
29
|
+
/** Client-side gate for what a picker lets the user select. The server stays authoritative. */
|
|
30
|
+
export interface AcceptPolicy {
|
|
31
|
+
/** Comma-separated ".ext" list for `<input accept>`. */
|
|
32
|
+
accept?: string;
|
|
33
|
+
isMimeAllowed?(mime: string): boolean;
|
|
34
|
+
}
|
|
35
|
+
/** Extra multipart fields attached to every upload (e.g. tags). Re-read at upload time. */
|
|
36
|
+
export type MetaSupplier = () => Record<string, string>;
|
|
37
|
+
/** Cloud-drive providers supported for OAuth save-back. */
|
|
38
|
+
export type ConnectProvider = "google-drive" | "onedrive" | "box" | "dropbox";
|
|
39
|
+
export declare const CONNECT_PROVIDERS: readonly ConnectProvider[];
|
|
40
|
+
export interface ProviderTokens {
|
|
41
|
+
accessToken: string;
|
|
42
|
+
refreshToken?: string | null;
|
|
43
|
+
/** Epoch ms. */
|
|
44
|
+
expiresAt?: number | null;
|
|
45
|
+
scope?: string | null;
|
|
46
|
+
}
|
|
47
|
+
/** Persistence for a user's provider tokens — the host owns storage and encryption. */
|
|
48
|
+
export interface TokenStorePort {
|
|
49
|
+
get(userId: string, provider: ConnectProvider): Promise<ProviderTokens | null>;
|
|
50
|
+
put(userId: string, provider: ConnectProvider, tokens: ProviderTokens): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/** OAuth app credentials per provider; return null for providers the host hasn't configured. */
|
|
53
|
+
export type CredentialsPort = (provider: ConnectProvider) => {
|
|
54
|
+
clientId: string;
|
|
55
|
+
clientSecret: string;
|
|
56
|
+
} | null;
|
|
57
|
+
export interface TelemetryPort {
|
|
58
|
+
event(name: string, data?: unknown): void;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.d.ts","s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,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC/E,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvF;AAED,gGAAgG;AAChG,MAAM,MAAM,eAAe,GAAG,CAC5B,QAAQ,EAAE,eAAe,KACtB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC3C"}
|
package/dist/ports.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The ports hosts implement. aleup never persists anything, reads env vars, or calls a backend it
|
|
2
|
+
// wasn't handed an endpoint for — every host concern arrives through one of these interfaces.
|
|
3
|
+
export const CONNECT_PROVIDERS = [
|
|
4
|
+
"google-drive",
|
|
5
|
+
"onedrive",
|
|
6
|
+
"box",
|
|
7
|
+
"dropbox",
|
|
8
|
+
];
|
|
9
|
+
//# sourceMappingURL=ports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../src/ports.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,8FAA8F;AA8C9F,MAAM,CAAC,MAAM,iBAAiB,GAA+B;IAC3D,cAAc;IACd,UAAU;IACV,KAAK;IACL,SAAS;CACV,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aleup/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Ports, MIME registry, and format detection for the aleup document toolkit. Zero dependencies, platform-neutral.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"author": "JD",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/jaideep2/aleup.git",
|
|
30
|
+
"directory": "packages/core"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.build.json",
|
|
34
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
35
|
+
}
|
|
36
|
+
}
|