@_linked/s3 1.0.2

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.
@@ -0,0 +1,20 @@
1
+ # Changesets
2
+
3
+ This package uses [changesets](https://github.com/changesets/changesets) for version management and publishing.
4
+
5
+ ## Adding a changeset
6
+
7
+ When making a change that should trigger a new release, run:
8
+
9
+ ```bash
10
+ npx changeset
11
+ ```
12
+
13
+ This generates a markdown file in `.changeset/` describing the change. Commit it with your PR.
14
+
15
+ On merge to `main`, the publish workflow either:
16
+
17
+ 1. Creates (or updates) a **Release PR** that bumps the version + updates `CHANGELOG.md`, or
18
+ 2. If the Release PR is already merged, publishes the new version to npm.
19
+
20
+ Changes that don't need a release (docs, CI config, tooling) can skip the changeset — the check is a warning, not a block.
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3
+ "changelog": [
4
+ "@changesets/changelog-github",
5
+ { "repo": "linked-cm/s3" }
6
+ ],
7
+ "commit": false,
8
+ "fixed": [],
9
+ "linked": [],
10
+ "access": "public",
11
+ "baseBranch": "main",
12
+ "updateInternalDependencies": "patch",
13
+ "ignore": []
14
+ }
@@ -0,0 +1,44 @@
1
+ name: Changeset Check
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ changeset-check:
10
+ name: Check for changeset
11
+ # Skip the check on the automated Release PR.
12
+ if: ${{ github.head_ref != 'changeset-release/main' }}
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - name: Check for changeset files
21
+ uses: actions/github-script@v7
22
+ with:
23
+ script: |
24
+ const { data: files } = await github.rest.pulls.listFiles({
25
+ owner: context.repo.owner,
26
+ repo: context.repo.repo,
27
+ pull_number: context.issue.number,
28
+ });
29
+
30
+ const hasChangeset = files.some(f =>
31
+ f.filename.startsWith('.changeset/') &&
32
+ f.filename.endsWith('.md') &&
33
+ f.filename !== '.changeset/README.md'
34
+ );
35
+
36
+ if (!hasChangeset) {
37
+ await github.rest.issues.createComment({
38
+ owner: context.repo.owner,
39
+ repo: context.repo.repo,
40
+ issue_number: context.issue.number,
41
+ body: "No changeset found. If this PR should trigger a release, run `npx changeset` and commit the generated file.\n\nIf this change doesn't need a release (docs, CI config, etc.), you can ignore this message."
42
+ });
43
+ core.warning('No changeset file found in this PR.');
44
+ }
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ build-and-test:
10
+ name: Build & Test
11
+ # Skip CI on the automated Release PR created by changesets/action.
12
+ if: ${{ !(github.event.pull_request.base.ref == 'main' && github.head_ref == 'changeset-release/main') }}
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Checkout
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Setup Node.js
19
+ uses: actions/setup-node@v4
20
+ with:
21
+ node-version: 22.16.0
22
+
23
+ - name: Install dependencies
24
+ run: npm ci --legacy-peer-deps
25
+
26
+ - name: Build
27
+ run: npm run build
28
+
29
+ - name: Test
30
+ run: npm test --if-present
@@ -0,0 +1,42 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ concurrency: ${{ github.workflow }}-${{ github.ref }}
9
+
10
+ jobs:
11
+ release:
12
+ name: Publish Release
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: write
16
+ pull-requests: write
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Setup Node.js
22
+ uses: actions/setup-node@v4
23
+ with:
24
+ node-version: 22.16.0
25
+ registry-url: 'https://registry.npmjs.org'
26
+
27
+ - name: Install dependencies
28
+ run: npm ci --legacy-peer-deps
29
+
30
+ - name: Build
31
+ run: npm run build
32
+
33
+ - name: Create release Pull Request or Publish
34
+ uses: changesets/action@v1
35
+ with:
36
+ publish: npx changeset publish
37
+ title: 'chore: release'
38
+ commit: 'chore: release'
39
+ env:
40
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
42
+ NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @\_linked/s3
2
+
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2a8c5d8`](https://github.com/linked-cm/s3/commit/2a8c5d8288f43270eb666a2a4c6ec745791ecb66) - Initial release under the new publishing setup.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # lincd-s3
2
+
3
+ A plug-n-play solution for using an S3 Bucket in LINCD.
4
+
5
+ In place of your usual backend store, you can use the following to get started with S3:
6
+
7
+ ```ts
8
+ // ...
9
+ const {
10
+ LinkedFileStorage,
11
+ } = require('@_linked/core/lib/utils/LinkedFileStorage');
12
+ const { LinkedStorage } = require('@_linked/core/lib/utils/LinkedStorage');
13
+ const { S3QuadStore } = require('lincd-s3/lib/shapes/S3QuadStore');
14
+ const { S3FileStore } = require('lincd-s3/lib/shapes/S3FileStore');
15
+
16
+ // This translates to be the Object name in the bucket. If no object
17
+ // is found with this name, then one will be created - just like how a
18
+ // regular NodeFileStore works!
19
+ const QUADSTORE_NAME = 'foo-bar-data';
20
+ const s3Quads = new S3QuadStore(QUADSTORE_NAME);
21
+
22
+ LinkedStorage.setDefaultStore(s3Quads);
23
+
24
+ // Set up an S3 Filestore
25
+ const FILESTORE_NAME = 'baz-qux-files';
26
+ const s3Files = new S3FileStore(FILESTORE_NAME);
27
+
28
+ LinkedFileStorage.setDefaultStore(s3Files);
29
+ // ...
30
+ ```
31
+
32
+ ## Environment Variables
33
+
34
+ Unless stated otherwise, the following environment variables are required:
35
+
36
+ ```properties
37
+ # Generated using whatever service is hosting your bucket
38
+ AWS_ACCESS_KEY_ID=ABC123XYZ789
39
+ AWS_SECRET_ACCESS_KEY=aBc123Def456xYz789
40
+
41
+ # The endpoint on which your bucket resides. It's important to note that
42
+ # this is the HOST address of your bucket - i.e. it SHOULDN'T contain
43
+ # your bucket name!!
44
+ S3_BUCKET_ENDPOINT=https://my.bucket-provider.com
45
+
46
+ # The name of your buckets
47
+ S3_FILES_BUCKET_NAME=my-file-bucket
48
+ S3_QUADS_BUCKET_NAME=my-data-bucket
49
+
50
+ # OPTIONAL: If using a CDN, you can specify the URL here and it will be used
51
+ S3_CDN_URL=https://my.cdn-provider.com
52
+ ```
53
+
54
+ The S3 client will automagically form the correct URL for your bucket - in this case it would
55
+ be https://my-data-bucket.my.bucket-provider.com or https://my-file-bucket.my.bucket-provider.com
56
+
57
+ ## See also:
58
+
59
+ - [lincd-filebase](https://www.npmjs.com/package/lincd-filebase) - An implementation
60
+ for [filebase](https://filebase.com) IPFS bucket storage
File without changes
@@ -0,0 +1,20 @@
1
+ {
2
+ "@context": {
3
+ "dc": "http://purl.org/dc/elements/1.1/",
4
+ "owl": "http://www.w3.org/2002/07/owl#",
5
+ "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
6
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
7
+ "s3": "http://lincd.org/ont/s3/"
8
+ },
9
+ "@graph": [
10
+ {
11
+ "@id": "s3:ExampleClass",
12
+ "@type": "rdfs:Class",
13
+ "rdfs:comment": "This is an example class. You can remove or rename it",
14
+ "rdfs:isDefinedBy": {
15
+ "@id": "s3:"
16
+ },
17
+ "rdfs:label": "Example Class"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,5 @@
1
+ import './types.js';
2
+ import './ontologies/s3.js';
3
+ import './shapes/S3Bucket.js';
4
+ import './shapes/S3FileStore.js';
5
+ import './utils/accessUrl.js';
@@ -0,0 +1,38 @@
1
+ export declare var loadData: () => Promise<{
2
+ "@context": {
3
+ dc: string;
4
+ owl: string;
5
+ rdf: string;
6
+ rdfs: string;
7
+ s3: string;
8
+ };
9
+ "@graph": {
10
+ "@id": string;
11
+ "@type": string;
12
+ "rdfs:comment": string;
13
+ "rdfs:isDefinedBy": {
14
+ "@id": string;
15
+ };
16
+ "rdfs:label": string;
17
+ }[];
18
+ }>;
19
+ export declare var ns: (term: string) => import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
20
+ export declare var _self: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
21
+ export declare var Bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
22
+ export declare var FileStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
23
+ export declare var FrontendStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
24
+ export declare var QuadStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
25
+ export declare var bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
26
+ export declare var endpoint: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
27
+ export declare var key: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
28
+ export declare var secret: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
29
+ export declare const s3: {
30
+ Bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
31
+ FileStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
32
+ FrontendStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
33
+ QuadStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
34
+ bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
35
+ endpoint: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
36
+ key: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
37
+ secret: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
38
+ };
@@ -0,0 +1,4 @@
1
+ export declare const linkedShape: {
2
+ <T extends typeof import("@_linked/core/shapes/Shape").Shape>(constructor: T): void;
3
+ <T extends typeof import("@_linked/core/shapes/Shape").Shape>(config?: import("@_linked/core/utils/Package").ShapeConfig): (constructor: T) => void;
4
+ }, linkedUtil: (constructor: any) => any, linkedOntology: (allFileExports: any, nameSpace: (term: string) => import("@_linked/core/utils/NodeReference").NodeReferenceValue, suggestedPrefixAndFileName: string, loadDataFunction?: () => Promise<any>, dataSource?: string | string[]) => void, registerPackageExport: (exportedObject: any) => void, packageExports: any, packageName: string;
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@_linked/s3",
3
+ "displayName": "s3",
4
+ "description": "A general purpose Simple Storage Service (S3) package to be extended or used as is",
5
+ "author": {
6
+ "name": "Valentine Wilson",
7
+ "email": "valentine@semantu.com",
8
+ "url": "https://vw.codes"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": ""
13
+ },
14
+ "version": "1.0.2",
15
+ "linkedPackage": true,
16
+ "license": "ISC",
17
+ "scripts": {
18
+ "start": "npm exec linked dev",
19
+ "build": "yarn linked build",
20
+ "prepublishOnly": "yarn linked build production",
21
+ "postpublish": "npm exec linked register"
22
+ },
23
+ "keywords": [
24
+ "lincd",
25
+ "linked data",
26
+ "interoperable",
27
+ "semantic web",
28
+ "web3",
29
+ "s3",
30
+ "simple storage service",
31
+ "cloud storage",
32
+ "aws"
33
+ ],
34
+ "dependencies": {
35
+ "@_linked/core": "^2.2.1",
36
+ "@_linked/server": "~1.0",
37
+ "@_linked/server-utils": "~1.0",
38
+ "@aws-sdk/client-s3": "^3.159.0",
39
+ "@aws-sdk/credential-providers": "^3.159.0",
40
+ "cron": "^3.1.7",
41
+ "mime": "2.6.0"
42
+ },
43
+ "devDependencies": {
44
+ "@_linked/cli": "^1.2",
45
+ "@types/mime": "^3.0.4",
46
+ "tsconfig-to-dual-package": "^1.2.0",
47
+ "typescript": "^5.7.3",
48
+ "typescript-plugin-css-modules": "^5.1.0",
49
+ "@changesets/cli": "^2.29.8",
50
+ "@changesets/changelog-github": "^0.5.2"
51
+ },
52
+ "typesVersions": {
53
+ "*": {
54
+ "*": [
55
+ "lib/esm/*"
56
+ ]
57
+ }
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "type": "commonjs"
63
+ }
@@ -0,0 +1,80 @@
1
+ import { DeleteObjectCommandInput, S3Client } from '@aws-sdk/client-s3';
2
+ import { PutObjectCommandInput, PutObjectCommandOutput } from '@aws-sdk/client-s3/dist-types/commands/PutObjectCommand';
3
+ import { StreamingBlobPayloadInputTypes } from '@smithy/types';
4
+ import { Shape } from '@_linked/core/shapes/Shape';
5
+ export interface S3ClientConfigInput {
6
+ endpoint?: string;
7
+ accessKeyId?: string;
8
+ secretAccessKey?: string;
9
+ region?: string;
10
+ }
11
+ export declare const endpoint: string;
12
+ /**
13
+ * Builds an S3 client from explicit config, falling back to legacy env vars.
14
+ * This enables multiple S3 stores in one process with independent credentials/endpoints.
15
+ */
16
+ export declare const createS3Client: (config?: S3ClientConfigInput) => S3Client;
17
+ /**
18
+ * Legacy singleton exported for backward compatibility. New code should prefer
19
+ * per-instance clients by passing config into S3Bucket/S3FileStore.
20
+ */
21
+ export declare const s3Client: S3Client;
22
+ export declare class S3Bucket extends Shape {
23
+ static targetClass: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
24
+ protected _client: S3Client;
25
+ label: string;
26
+ private ensureKeyPromise;
27
+ constructor(n?: string | {
28
+ id: string;
29
+ }, clientConfig?: S3ClientConfigInput);
30
+ get endpoint(): string;
31
+ /**
32
+ * Delete an object from the bucket.
33
+ * @param key The key of the object to delete
34
+ * @param options Additional options to pass to the DeleteObjectCommand
35
+ * @returns The response from the DeleteObjectCommand
36
+ * @todo Batch delete, see https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html
37
+ */
38
+ deleteObject(key: string, options?: Omit<DeleteObjectCommandInput, 'Key' | 'Bucket'>): Promise<import("@aws-sdk/client-s3").DeleteObjectCommandOutput>;
39
+ copyObject(sourceKey: string, destinationKey: string, options?: Omit<PutObjectCommandInput, 'Key' | 'Bucket'>): Promise<boolean>;
40
+ /**
41
+ * Put an object into the bucket.
42
+ *
43
+ * @param key The key of the object to PUT (i.e. file name)
44
+ * @param value The value of the object to PUT (i.e. file contents)
45
+ * @param options Additional options to pass to the PutObjectCommand
46
+ * @returns The response from the PutObjectCommand
47
+ */
48
+ putObject(key: string, value: StreamingBlobPayloadInputTypes, options?: Omit<PutObjectCommandInput, 'Body' | 'Key' | 'Bucket'>): Promise<PutObjectCommandOutput>;
49
+ /**
50
+ * Get a list of all object keys in the bucket.
51
+ * Important to note that only a maximum 1000 keys will be returned.
52
+ *
53
+ * @param prefix The prefix to search for in the bucket. This can be a folder or the beginning of a file name.
54
+ * @returns A list of all object keys in the bucket
55
+ * @todo Recursive search within directories
56
+ * @todo Implement pagination
57
+ */
58
+ getAllObjectKeys(prefix?: string): Promise<string[]>;
59
+ /**
60
+ * Get the contents of an object in the bucket.
61
+ * @param key The key of the object to get
62
+ * @returns The contents of the object as a string
63
+ */
64
+ getObject(key: string): Promise<string>;
65
+ /**
66
+ * Ensure that the given key exists in the bucket, the file contents
67
+ * will be an empty json object.
68
+ *
69
+ * @param key The key to insert if it does not exist
70
+ * @returns The promise that will resolve when the key exists
71
+ */
72
+ ensureKeyExists(key: string): Promise<string | void>;
73
+ private _ensureKeyExists;
74
+ private keyExists;
75
+ /**
76
+ * Create the bucket if it does not exist.
77
+ * @returns The promise that will resolve when the bucket exists
78
+ */
79
+ createBucket(): Promise<import("@aws-sdk/client-s3").CreateBucketCommandOutput>;
80
+ }
@@ -0,0 +1,59 @@
1
+ import { IFileStore } from '@_linked/core/interfaces/IFileStore';
2
+ import { Shape } from '@_linked/core/shapes/Shape';
3
+ import { type S3ClientConfigInput } from './S3Bucket.js';
4
+ import type { Readable } from 'stream';
5
+ export interface S3FileStoreConfig {
6
+ bucketName?: string;
7
+ accessURL?: string;
8
+ prefix?: string;
9
+ clientConfig?: S3ClientConfigInput;
10
+ }
11
+ export declare class S3FileStore extends Shape implements IFileStore {
12
+ static targetClass: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
13
+ label: string;
14
+ private _bucket;
15
+ private readonly config;
16
+ readonly accessURL: string;
17
+ constructor(n: string | {
18
+ id: string;
19
+ }, config?: S3FileStoreConfig);
20
+ private get bucket();
21
+ private resolveBucketName;
22
+ private resolveAccessURL;
23
+ private get prefix();
24
+ private normalizePath;
25
+ private applyPrefix;
26
+ private stripPrefix;
27
+ /**
28
+ * List all files in the bucket
29
+ * @param recursive Whether to list files recursively or just the top-level files
30
+ * @returns A list of file paths, relative to the endpoint
31
+ * @todo Think about taking an options parameter instead of positional args
32
+ * @todo Take a path parameter to list files in a subdirectory
33
+ */
34
+ listFiles(prefix?: string): Promise<string[]>;
35
+ /**
36
+ * Save a file to the bucket
37
+ * @param filePath The path to save the file to, relative to the endpoint
38
+ * @param fileContent The contents of the file as a buffer
39
+ * @returns The public URL of the file
40
+ */
41
+ saveFile(filePath: string, fileContent: string | Uint8Array | Buffer | Readable, mimeType?: string, preventDuplicate?: boolean): Promise<string>;
42
+ /**
43
+ * Get a file from the bucket
44
+ * @param filePath The path of the file to get, relative to the endpoint
45
+ * @returns The contents of the file as a buffer
46
+ */
47
+ getFile(filePath: string): Promise<Buffer | null>;
48
+ /**
49
+ * Delete a file from the bucket
50
+ * @param filePath The path of the file to delete, relative to the endpoint
51
+ */
52
+ deleteFile(filePath: string): Promise<void>;
53
+ /**
54
+ * Check if a file exists in the bucket
55
+ * @param filePath The path of the file to check, relative to the endpoint
56
+ * @returns Whether the file exists
57
+ */
58
+ fileExists(filePath: string): Promise<boolean>;
59
+ }
@@ -0,0 +1,12 @@
1
+ declare module '*.module.css' {
2
+ const classes: {
3
+ [key: string]: string;
4
+ };
5
+ export default classes;
6
+ }
7
+ declare module '*.module.scss' {
8
+ const classes: {
9
+ [key: string]: string;
10
+ };
11
+ export default classes;
12
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Access URL for user-uploaded files. This intentionally prefers upload-specific
3
+ * env vars, then falls back to legacy shared env vars.
4
+ */
5
+ export declare const getAccessURLUploadsStore: () => string;
6
+ /**
7
+ * Access URL for static web assets (bundles/images/root). This can be independent
8
+ * from uploads and is expected to include the release version when configured by
9
+ * app storage bootstrap (for example ".../4.1.1").
10
+ */
11
+ export declare const getAccessURLStaticStore: () => string;
12
+ /**
13
+ * Backward-compatible alias for existing imports.
14
+ */
15
+ export declare const getAccessURLS3FileStore: () => string;
File without changes
@@ -0,0 +1,20 @@
1
+ {
2
+ "@context": {
3
+ "dc": "http://purl.org/dc/elements/1.1/",
4
+ "owl": "http://www.w3.org/2002/07/owl#",
5
+ "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
6
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
7
+ "s3": "http://lincd.org/ont/s3/"
8
+ },
9
+ "@graph": [
10
+ {
11
+ "@id": "s3:ExampleClass",
12
+ "@type": "rdfs:Class",
13
+ "rdfs:comment": "This is an example class. You can remove or rename it",
14
+ "rdfs:isDefinedBy": {
15
+ "@id": "s3:"
16
+ },
17
+ "rdfs:label": "Example Class"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,5 @@
1
+ import './types.js';
2
+ import './ontologies/s3.js';
3
+ import './shapes/S3Bucket.js';
4
+ import './shapes/S3FileStore.js';
5
+ import './utils/accessUrl.js';
@@ -0,0 +1,38 @@
1
+ export declare var loadData: () => Promise<{
2
+ "@context": {
3
+ dc: string;
4
+ owl: string;
5
+ rdf: string;
6
+ rdfs: string;
7
+ s3: string;
8
+ };
9
+ "@graph": {
10
+ "@id": string;
11
+ "@type": string;
12
+ "rdfs:comment": string;
13
+ "rdfs:isDefinedBy": {
14
+ "@id": string;
15
+ };
16
+ "rdfs:label": string;
17
+ }[];
18
+ }>;
19
+ export declare var ns: (term: string) => import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
20
+ export declare var _self: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
21
+ export declare var Bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
22
+ export declare var FileStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
23
+ export declare var FrontendStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
24
+ export declare var QuadStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
25
+ export declare var bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
26
+ export declare var endpoint: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
27
+ export declare var key: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
28
+ export declare var secret: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
29
+ export declare const s3: {
30
+ Bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
31
+ FileStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
32
+ FrontendStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
33
+ QuadStore: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
34
+ bucket: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
35
+ endpoint: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
36
+ key: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
37
+ secret: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
38
+ };
@@ -0,0 +1,4 @@
1
+ export declare const linkedShape: {
2
+ <T extends typeof import("@_linked/core/shapes/Shape").Shape>(constructor: T): void;
3
+ <T extends typeof import("@_linked/core/shapes/Shape").Shape>(config?: import("@_linked/core/utils/Package").ShapeConfig): (constructor: T) => void;
4
+ }, linkedUtil: (constructor: any) => any, linkedOntology: (allFileExports: any, nameSpace: (term: string) => import("@_linked/core/utils/NodeReference").NodeReferenceValue, suggestedPrefixAndFileName: string, loadDataFunction?: () => Promise<any>, dataSource?: string | string[]) => void, registerPackageExport: (exportedObject: any) => void, packageExports: any, packageName: string;
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@_linked/s3",
3
+ "displayName": "s3",
4
+ "description": "A general purpose Simple Storage Service (S3) package to be extended or used as is",
5
+ "author": {
6
+ "name": "Valentine Wilson",
7
+ "email": "valentine@semantu.com",
8
+ "url": "https://vw.codes"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": ""
13
+ },
14
+ "version": "1.0.2",
15
+ "linkedPackage": true,
16
+ "license": "ISC",
17
+ "scripts": {
18
+ "start": "npm exec linked dev",
19
+ "build": "yarn linked build",
20
+ "prepublishOnly": "yarn linked build production",
21
+ "postpublish": "npm exec linked register"
22
+ },
23
+ "keywords": [
24
+ "lincd",
25
+ "linked data",
26
+ "interoperable",
27
+ "semantic web",
28
+ "web3",
29
+ "s3",
30
+ "simple storage service",
31
+ "cloud storage",
32
+ "aws"
33
+ ],
34
+ "dependencies": {
35
+ "@_linked/core": "^2.2.1",
36
+ "@_linked/server": "~1.0",
37
+ "@_linked/server-utils": "~1.0",
38
+ "@aws-sdk/client-s3": "^3.159.0",
39
+ "@aws-sdk/credential-providers": "^3.159.0",
40
+ "cron": "^3.1.7",
41
+ "mime": "2.6.0"
42
+ },
43
+ "devDependencies": {
44
+ "@_linked/cli": "^1.2",
45
+ "@types/mime": "^3.0.4",
46
+ "tsconfig-to-dual-package": "^1.2.0",
47
+ "typescript": "^5.7.3",
48
+ "typescript-plugin-css-modules": "^5.1.0",
49
+ "@changesets/cli": "^2.29.8",
50
+ "@changesets/changelog-github": "^0.5.2"
51
+ },
52
+ "typesVersions": {
53
+ "*": {
54
+ "*": [
55
+ "lib/esm/*"
56
+ ]
57
+ }
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "type": "module"
63
+ }
@@ -0,0 +1,80 @@
1
+ import { DeleteObjectCommandInput, S3Client } from '@aws-sdk/client-s3';
2
+ import { PutObjectCommandInput, PutObjectCommandOutput } from '@aws-sdk/client-s3/dist-types/commands/PutObjectCommand';
3
+ import { StreamingBlobPayloadInputTypes } from '@smithy/types';
4
+ import { Shape } from '@_linked/core/shapes/Shape';
5
+ export interface S3ClientConfigInput {
6
+ endpoint?: string;
7
+ accessKeyId?: string;
8
+ secretAccessKey?: string;
9
+ region?: string;
10
+ }
11
+ export declare const endpoint: string;
12
+ /**
13
+ * Builds an S3 client from explicit config, falling back to legacy env vars.
14
+ * This enables multiple S3 stores in one process with independent credentials/endpoints.
15
+ */
16
+ export declare const createS3Client: (config?: S3ClientConfigInput) => S3Client;
17
+ /**
18
+ * Legacy singleton exported for backward compatibility. New code should prefer
19
+ * per-instance clients by passing config into S3Bucket/S3FileStore.
20
+ */
21
+ export declare const s3Client: S3Client;
22
+ export declare class S3Bucket extends Shape {
23
+ static targetClass: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
24
+ protected _client: S3Client;
25
+ label: string;
26
+ private ensureKeyPromise;
27
+ constructor(n?: string | {
28
+ id: string;
29
+ }, clientConfig?: S3ClientConfigInput);
30
+ get endpoint(): string;
31
+ /**
32
+ * Delete an object from the bucket.
33
+ * @param key The key of the object to delete
34
+ * @param options Additional options to pass to the DeleteObjectCommand
35
+ * @returns The response from the DeleteObjectCommand
36
+ * @todo Batch delete, see https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html
37
+ */
38
+ deleteObject(key: string, options?: Omit<DeleteObjectCommandInput, 'Key' | 'Bucket'>): Promise<import("@aws-sdk/client-s3").DeleteObjectCommandOutput>;
39
+ copyObject(sourceKey: string, destinationKey: string, options?: Omit<PutObjectCommandInput, 'Key' | 'Bucket'>): Promise<boolean>;
40
+ /**
41
+ * Put an object into the bucket.
42
+ *
43
+ * @param key The key of the object to PUT (i.e. file name)
44
+ * @param value The value of the object to PUT (i.e. file contents)
45
+ * @param options Additional options to pass to the PutObjectCommand
46
+ * @returns The response from the PutObjectCommand
47
+ */
48
+ putObject(key: string, value: StreamingBlobPayloadInputTypes, options?: Omit<PutObjectCommandInput, 'Body' | 'Key' | 'Bucket'>): Promise<PutObjectCommandOutput>;
49
+ /**
50
+ * Get a list of all object keys in the bucket.
51
+ * Important to note that only a maximum 1000 keys will be returned.
52
+ *
53
+ * @param prefix The prefix to search for in the bucket. This can be a folder or the beginning of a file name.
54
+ * @returns A list of all object keys in the bucket
55
+ * @todo Recursive search within directories
56
+ * @todo Implement pagination
57
+ */
58
+ getAllObjectKeys(prefix?: string): Promise<string[]>;
59
+ /**
60
+ * Get the contents of an object in the bucket.
61
+ * @param key The key of the object to get
62
+ * @returns The contents of the object as a string
63
+ */
64
+ getObject(key: string): Promise<string>;
65
+ /**
66
+ * Ensure that the given key exists in the bucket, the file contents
67
+ * will be an empty json object.
68
+ *
69
+ * @param key The key to insert if it does not exist
70
+ * @returns The promise that will resolve when the key exists
71
+ */
72
+ ensureKeyExists(key: string): Promise<string | void>;
73
+ private _ensureKeyExists;
74
+ private keyExists;
75
+ /**
76
+ * Create the bucket if it does not exist.
77
+ * @returns The promise that will resolve when the bucket exists
78
+ */
79
+ createBucket(): Promise<import("@aws-sdk/client-s3").CreateBucketCommandOutput>;
80
+ }
@@ -0,0 +1,59 @@
1
+ import { IFileStore } from '@_linked/core/interfaces/IFileStore';
2
+ import { Shape } from '@_linked/core/shapes/Shape';
3
+ import { type S3ClientConfigInput } from './S3Bucket.js';
4
+ import type { Readable } from 'stream';
5
+ export interface S3FileStoreConfig {
6
+ bucketName?: string;
7
+ accessURL?: string;
8
+ prefix?: string;
9
+ clientConfig?: S3ClientConfigInput;
10
+ }
11
+ export declare class S3FileStore extends Shape implements IFileStore {
12
+ static targetClass: import("@_linked/core/utils/NodeReference.js").NodeReferenceValue;
13
+ label: string;
14
+ private _bucket;
15
+ private readonly config;
16
+ readonly accessURL: string;
17
+ constructor(n: string | {
18
+ id: string;
19
+ }, config?: S3FileStoreConfig);
20
+ private get bucket();
21
+ private resolveBucketName;
22
+ private resolveAccessURL;
23
+ private get prefix();
24
+ private normalizePath;
25
+ private applyPrefix;
26
+ private stripPrefix;
27
+ /**
28
+ * List all files in the bucket
29
+ * @param recursive Whether to list files recursively or just the top-level files
30
+ * @returns A list of file paths, relative to the endpoint
31
+ * @todo Think about taking an options parameter instead of positional args
32
+ * @todo Take a path parameter to list files in a subdirectory
33
+ */
34
+ listFiles(prefix?: string): Promise<string[]>;
35
+ /**
36
+ * Save a file to the bucket
37
+ * @param filePath The path to save the file to, relative to the endpoint
38
+ * @param fileContent The contents of the file as a buffer
39
+ * @returns The public URL of the file
40
+ */
41
+ saveFile(filePath: string, fileContent: string | Uint8Array | Buffer | Readable, mimeType?: string, preventDuplicate?: boolean): Promise<string>;
42
+ /**
43
+ * Get a file from the bucket
44
+ * @param filePath The path of the file to get, relative to the endpoint
45
+ * @returns The contents of the file as a buffer
46
+ */
47
+ getFile(filePath: string): Promise<Buffer | null>;
48
+ /**
49
+ * Delete a file from the bucket
50
+ * @param filePath The path of the file to delete, relative to the endpoint
51
+ */
52
+ deleteFile(filePath: string): Promise<void>;
53
+ /**
54
+ * Check if a file exists in the bucket
55
+ * @param filePath The path of the file to check, relative to the endpoint
56
+ * @returns Whether the file exists
57
+ */
58
+ fileExists(filePath: string): Promise<boolean>;
59
+ }
@@ -0,0 +1,12 @@
1
+ declare module '*.module.css' {
2
+ const classes: {
3
+ [key: string]: string;
4
+ };
5
+ export default classes;
6
+ }
7
+ declare module '*.module.scss' {
8
+ const classes: {
9
+ [key: string]: string;
10
+ };
11
+ export default classes;
12
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Access URL for user-uploaded files. This intentionally prefers upload-specific
3
+ * env vars, then falls back to legacy shared env vars.
4
+ */
5
+ export declare const getAccessURLUploadsStore: () => string;
6
+ /**
7
+ * Access URL for static web assets (bundles/images/root). This can be independent
8
+ * from uploads and is expected to include the release version when configured by
9
+ * app storage bootstrap (for example ".../4.1.1").
10
+ */
11
+ export declare const getAccessURLStaticStore: () => string;
12
+ /**
13
+ * Backward-compatible alias for existing imports.
14
+ */
15
+ export declare const getAccessURLS3FileStore: () => string;
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@_linked/s3",
3
+ "displayName": "s3",
4
+ "description": "A general purpose Simple Storage Service (S3) package to be extended or used as is",
5
+ "author": {
6
+ "name": "Valentine Wilson",
7
+ "email": "valentine@semantu.com",
8
+ "url": "https://vw.codes"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": ""
13
+ },
14
+ "version": "1.0.2",
15
+ "linkedPackage": true,
16
+ "main": "lib/cjs/index.js",
17
+ "types": "dist/s3.d.ts",
18
+ "license": "ISC",
19
+ "scripts": {
20
+ "start": "npm exec linked dev",
21
+ "build": "yarn linked build",
22
+ "prepublishOnly": "yarn linked build production",
23
+ "postpublish": "npm exec linked register"
24
+ },
25
+ "keywords": [
26
+ "lincd",
27
+ "linked data",
28
+ "interoperable",
29
+ "semantic web",
30
+ "web3",
31
+ "s3",
32
+ "simple storage service",
33
+ "cloud storage",
34
+ "aws"
35
+ ],
36
+ "dependencies": {
37
+ "@_linked/core": "^2.2.1",
38
+ "@_linked/server": "~1.0",
39
+ "@_linked/server-utils": "~1.0",
40
+ "@aws-sdk/client-s3": "^3.159.0",
41
+ "@aws-sdk/credential-providers": "^3.159.0",
42
+ "cron": "^3.1.7",
43
+ "mime": "2.6.0"
44
+ },
45
+ "devDependencies": {
46
+ "@_linked/cli": "^1.2",
47
+ "@types/mime": "^3.0.4",
48
+ "tsconfig-to-dual-package": "^1.2.0",
49
+ "typescript": "^5.7.3",
50
+ "typescript-plugin-css-modules": "^5.1.0",
51
+ "@changesets/cli": "^2.29.8",
52
+ "@changesets/changelog-github": "^0.5.2"
53
+ },
54
+ "module": "lib/esm/index.js",
55
+ "exports": {
56
+ ".": {
57
+ "types": "./lib/esm/index.d.ts",
58
+ "import": "./lib/esm/index.js",
59
+ "require": "./lib/cjs/index.js"
60
+ },
61
+ "./*.js": {
62
+ "types": "./lib/esm/*.d.ts",
63
+ "import": "./lib/esm/*.js",
64
+ "require": "./lib/cjs/*.js"
65
+ },
66
+ "./*": {
67
+ "types": "./lib/esm/*.d.ts",
68
+ "import": "./lib/esm/*.js",
69
+ "require": "./lib/cjs/*.js"
70
+ }
71
+ },
72
+ "typesVersions": {
73
+ "*": {
74
+ "*": [
75
+ "lib/esm/*"
76
+ ]
77
+ }
78
+ },
79
+ "publishConfig": {
80
+ "access": "public"
81
+ }
82
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "target": "es6",
6
+ "outDir": "lib/cjs"
7
+ }
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "esnext",
5
+ "target": "es2018",
6
+ "outDir": "lib/esm",
7
+ "moduleResolution": "node"
8
+ }
9
+ }