@knowledgefutures/sdk 0.0.0-stage → 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -2
  3. package/dist/analytics/beacon.d.ts +25 -0
  4. package/dist/analytics/beacon.js +86 -0
  5. package/dist/analytics/binding.d.ts +24 -0
  6. package/dist/analytics/binding.js +46 -0
  7. package/dist/analytics/collector.d.ts +10 -0
  8. package/dist/analytics/collector.js +10 -0
  9. package/dist/analytics/cubes.d.ts +96 -0
  10. package/dist/analytics/cubes.js +213 -0
  11. package/dist/analytics/envelope.d.ts +135 -0
  12. package/dist/analytics/envelope.js +231 -0
  13. package/dist/analytics/errors.d.ts +24 -0
  14. package/dist/analytics/errors.js +20 -0
  15. package/dist/analytics/index.d.ts +38 -0
  16. package/dist/analytics/index.js +98 -0
  17. package/dist/analytics/memory.d.ts +35 -0
  18. package/dist/analytics/memory.js +66 -0
  19. package/dist/analytics/testing.d.ts +6 -0
  20. package/dist/analytics/testing.js +6 -0
  21. package/dist/analytics/types.d.ts +22 -0
  22. package/dist/analytics/types.js +1 -0
  23. package/dist/storage/binding.d.ts +76 -0
  24. package/dist/storage/binding.js +97 -0
  25. package/dist/storage/brokered.d.ts +21 -0
  26. package/dist/storage/brokered.js +94 -0
  27. package/dist/storage/conformance.d.ts +24 -0
  28. package/dist/storage/conformance.js +311 -0
  29. package/dist/storage/errors.d.ts +27 -0
  30. package/dist/storage/errors.js +21 -0
  31. package/dist/storage/index.d.ts +34 -0
  32. package/dist/storage/index.js +77 -0
  33. package/dist/storage/local.d.ts +26 -0
  34. package/dist/storage/local.js +57 -0
  35. package/dist/storage/s3.d.ts +22 -0
  36. package/dist/storage/s3.js +254 -0
  37. package/dist/storage/shared.d.ts +45 -0
  38. package/dist/storage/shared.js +167 -0
  39. package/dist/storage/sigv4.d.ts +50 -0
  40. package/dist/storage/sigv4.js +128 -0
  41. package/dist/storage/testing.d.ts +25 -0
  42. package/dist/storage/testing.js +242 -0
  43. package/dist/storage/types.d.ts +122 -0
  44. package/dist/storage/types.js +13 -0
  45. package/package.json +30 -3
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The storage interface every implementation honours: R2 behind the console,
3
+ * RustFS under `kf dev`, and `memoryStorage` in tests. Project code is written
4
+ * against these types only, and the conformance suite (conformance.ts) holds
5
+ * each implementation to them, so code that passes against one runs the same
6
+ * against the others.
7
+ *
8
+ * The surface is deliberately the subset all of them can honour: no POST
9
+ * policies (R2 has none), no per-object ACLs (R2 has none — public is a
10
+ * separate store), no multipart. Large files go browser → bucket through
11
+ * `signUpload`, never through the project's server.
12
+ */
13
+ /** What `put` accepts. A stream is read to the end before upload; use `signUpload` for large files. */
14
+ export type Body = string | ArrayBuffer | ArrayBufferView | Blob | ReadableStream<Uint8Array>;
15
+ export interface PutOptions {
16
+ contentType?: string;
17
+ /** Sent back verbatim on every read — and, on the public store, what Cloudflare's cache obeys. */
18
+ cacheControl?: string;
19
+ contentDisposition?: string;
20
+ /** Lowercase `[a-z0-9-]` keys. Small: S3 caps all metadata at 2 KB. */
21
+ metadata?: Record<string, string>;
22
+ }
23
+ /** One object as a `list` returns it: only what every backend's listing reports. */
24
+ export interface ListedObject {
25
+ key: string;
26
+ size: number;
27
+ /** Opaque. Stable while the object is unchanged; changes when it is overwritten. */
28
+ etag: string;
29
+ uploaded: Date;
30
+ }
31
+ /** One object as `put` and `head` report it. */
32
+ export interface StoredObject extends ListedObject {
33
+ contentType: string;
34
+ cacheControl?: string;
35
+ contentDisposition?: string;
36
+ metadata: Record<string, string>;
37
+ }
38
+ export interface ObjectBody extends StoredObject {
39
+ body: ReadableStream<Uint8Array>;
40
+ arrayBuffer(): Promise<ArrayBuffer>;
41
+ text(): Promise<string>;
42
+ }
43
+ export interface ListOptions {
44
+ prefix?: string;
45
+ /** From the previous page's `cursor`. Opaque. */
46
+ cursor?: string;
47
+ /** 1–1000. Default 1000. */
48
+ limit?: number;
49
+ }
50
+ export interface ListResult {
51
+ /** In key order (UTF-8 byte order). */
52
+ objects: ListedObject[];
53
+ /** Present when there is another page. */
54
+ cursor?: string;
55
+ }
56
+ export interface SignUploadOptions {
57
+ contentType: string;
58
+ /** The exact byte length. It is signed, so the upload must be exactly this size. */
59
+ size: number;
60
+ /**
61
+ * Seconds. Default 600. Up to 604800 with fixed credentials (`kf dev`, tests);
62
+ * on the console, at most the storage service's credential lifetime (an hour),
63
+ * because a signed URL stops working when the credentials that signed it expire.
64
+ */
65
+ expiresIn?: number;
66
+ cacheControl?: string;
67
+ }
68
+ /** What a browser needs to upload: PUT the file to `url` with exactly these headers. */
69
+ export interface SignedUpload {
70
+ key: string;
71
+ url: string;
72
+ method: 'PUT';
73
+ headers: Record<string, string>;
74
+ expiresAt: Date;
75
+ }
76
+ export interface SignDownloadOptions {
77
+ /** Seconds. Default 300. The same limits as `SignUploadOptions.expiresIn`. */
78
+ expiresIn?: number;
79
+ /** Served as an attachment with this file name. */
80
+ filename?: string;
81
+ }
82
+ /** A file with a name, for `upload`. A `File` is one. */
83
+ export interface Upload {
84
+ body: Body;
85
+ contentType?: string;
86
+ /** Its extension carries over to the generated key. */
87
+ name?: string;
88
+ }
89
+ export interface UploadOptions {
90
+ /** The key is `<prefix>/<uuid><ext>`. */
91
+ prefix?: string;
92
+ cacheControl?: string;
93
+ metadata?: Record<string, string>;
94
+ }
95
+ export interface Store {
96
+ put(key: string, body: Body, options?: PutOptions): Promise<StoredObject>;
97
+ /** null when there is no such object. */
98
+ get(key: string): Promise<ObjectBody | null>;
99
+ /** null when there is no such object. */
100
+ head(key: string): Promise<StoredObject | null>;
101
+ /** Deleting what is not there is success. */
102
+ delete(key: string): Promise<void>;
103
+ list(options?: ListOptions): Promise<ListResult>;
104
+ signUpload(key: string, options: SignUploadOptions): Promise<SignedUpload>;
105
+ signDownload(key: string, options?: SignDownloadOptions): Promise<string>;
106
+ /** A generated key, so nothing is ever overwritten by accident. */
107
+ upload(file: Blob | Upload, options?: UploadOptions): Promise<StoredObject>;
108
+ }
109
+ /**
110
+ * The public store: everything in it is readable by anyone at `url(key)`,
111
+ * through Cloudflare's cache and with no signature. Treat its keys as
112
+ * immutable — an overwrite or delete is seen only after the object's
113
+ * `max-age`, since nothing purges the cache.
114
+ */
115
+ export interface PublicStore extends Store {
116
+ /** Where anyone can GET the object. Synchronous: no network, no signing. */
117
+ url(key: string): string;
118
+ }
119
+ export interface Storage extends Store {
120
+ /** Throws `not_configured` unless the manifest declares `"public": true`. */
121
+ readonly public: PublicStore;
122
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The storage interface every implementation honours: R2 behind the console,
3
+ * RustFS under `kf dev`, and `memoryStorage` in tests. Project code is written
4
+ * against these types only, and the conformance suite (conformance.ts) holds
5
+ * each implementation to them, so code that passes against one runs the same
6
+ * against the others.
7
+ *
8
+ * The surface is deliberately the subset all of them can honour: no POST
9
+ * policies (R2 has none), no per-object ACLs (R2 has none — public is a
10
+ * separate store), no multipart. Large files go browser → bucket through
11
+ * `signUpload`, never through the project's server.
12
+ */
13
+ export {};
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@knowledgefutures/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Zero-config clients for Knowledge Futures platform services, configured by the console.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/knowledgefutures/kf-console.git",
9
+ "directory": "packages/sdk"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "exports": {
17
+ "./storage": {
18
+ "types": "./dist/storage/index.d.ts",
19
+ "default": "./dist/storage/index.js"
20
+ },
21
+ "./storage/testing": {
22
+ "types": "./dist/storage/testing.d.ts",
23
+ "default": "./dist/storage/testing.js"
24
+ }
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc -p tsconfig.build.json",
31
+ "typecheck": "tsc --noEmit -p tsconfig.json"
32
+ }
6
33
  }