Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
adb32e8
Add SOS support
pangea-andrest Jan 5, 2024
62b7724
Update packages/pangea-node-sdk/src/response.ts
pangea-andrest Jan 8, 2024
145ce20
import path package
pangea-andrest Jan 9, 2024
e92b042
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Jan 9, 2024
39916a2
Add doc strings for Node SDK
Jan 10, 2024
efd30df
Update doc string
Jan 10, 2024
6ef66aa
add default value in list()
pangea-andrest Jan 11, 2024
6e911d3
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Jan 16, 2024
e9894e4
Update LinkType
pangea-andrest Jan 16, 2024
74bdc95
examples
pangea-andrest Jan 16, 2024
e7f93ca
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Jan 16, 2024
eff56d2
address PR comments
pangea-andrest Jan 16, 2024
58bf169
rename example
pangea-andrest Jan 16, 2024
8540833
update example name
pangea-andrest Jan 17, 2024
4f584f6
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Jan 30, 2024
f1ca199
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Feb 15, 2024
16eb47d
Add `share/link/send` support
pangea-andrest Feb 15, 2024
220a656
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Mar 1, 2024
8db99f9
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Mar 4, 2024
92cb07b
Rename `Store` to `Share`
pangea-andrest Mar 5, 2024
86c09b2
Updates: Improve downloaded file naming
pangea-andrest Mar 5, 2024
6eef763
fixup! Add message, title, notify_email and tags
pangea-andrest Mar 6, 2024
850457f
fixup! keep renaming from store to share
pangea-andrest Mar 6, 2024
cb9c775
fixup! rename share examples folder
pangea-andrest Mar 6, 2024
dc42871
fixup! remove unit_tests stage from gitlab ci. They already run in gi…
pangea-andrest Mar 6, 2024
3d867fb
fixup! lock file
pangea-andrest Mar 6, 2024
55294c4
fixup! disable share examples tests
pangea-andrest Mar 6, 2024
e87273f
fixup! Move FileUploader to its own file to be reused
pangea-andrest Mar 8, 2024
c58f5b3
fixup! Use FileUploader
pangea-andrest Mar 8, 2024
b4601f3
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Mar 13, 2024
fb3f2a4
fixup! Add support to zero bytes files
pangea-andrest Mar 14, 2024
7a87c72
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Mar 14, 2024
089f463
fixup! run prettier
pangea-andrest Mar 14, 2024
70d0551
fixup! update share examples package.json
pangea-andrest Mar 14, 2024
3c4ad13
fixup! yarn.lock
pangea-andrest Mar 14, 2024
900897f
fixup! enable share tests in pipeline
pangea-andrest Mar 14, 2024
698a8df
fixup! use ShareService instead of StoreService
pangea-andrest Mar 14, 2024
4b665b9
fixup! Update to use FileUploader
pangea-andrest Mar 14, 2024
00d5b14
fixup! enable Share tests in pipeline
pangea-andrest Mar 14, 2024
29fce8c
fixup! remove Store references
pangea-andrest Mar 14, 2024
ba48c15
fixup! examples updates
pangea-andrest Mar 14, 2024
5ce1855
fixup! fix share tests
pangea-andrest Mar 14, 2024
68b33ec
fixup! typo
pangea-andrest Mar 18, 2024
c459346
Merge branch 'main' into GEA-2194-sos-service
pangea-andrest Mar 18, 2024
bc77ad8
fixup! increase timeout in share tests
pangea-andrest Mar 19, 2024
8f4355e
pangea-node-sdk: add more Secure Share docs (GEA-11739) (#878)
kenany Mar 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
*.exe
pangea-node-sdk-*.tgz
*.gz
packages/pangea-node-sdk/download/
2 changes: 2 additions & 0 deletions examples/.examples-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ examples-tests:
- "intel"
- "redact"
- "vault"
- "share"
image: node:${NODE_VERSION}
before_script:
- export PANGEA_AUDIT_CONFIG_ID="${PANGEA_AUDIT_CONFIG_ID_1_LVE_AWS}"
Expand All @@ -34,6 +35,7 @@ examples-tests:
- export PANGEA_URL_INTEL_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_USER_INTEL_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_VAULT_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_SHARE_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- pushd packages/pangea-node-sdk
- tar -xf pangea-node-sdk-v*.tgz --strip-components 1 -C .
- popd
Expand Down
2 changes: 1 addition & 1 deletion examples/file_scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Pangea",
"license": "ISC",
"license": "MIT",
"dependencies": {
"pangea-node-sdk": "3.7.0"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/intel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Pangea",
"license": "ISC",
"license": "MIT",
"dependencies": {
"pangea-node-sdk": "3.7.0"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/redact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Pangea",
"license": "ISC",
"license": "MIT",
"dependencies": {
"pangea-node-sdk": "3.7.0"
}
Expand Down
12 changes: 12 additions & 0 deletions examples/share/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Pangea Store Service Example

## Setup

Set up environment variables ([Instructions](https://pangea.cloud/docs/getting-started/integrate/#set-environment-variables)) `PANGEA_SHARE_TOKEN` and `PANGEA_DOMAIN` with your project token configured on Pangea User Console (token should have access to Store service [Instructions](https://pangea.cloud/docs/getting-started/configure-services/#configure-a-pangea-service)) and with your Pangea domain.

## Run example

```
yarn install
node folder_create_n_delete.mjs
```
35 changes: 35 additions & 0 deletions examples/share/folder_create_and_delete.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable no-console */

import { PangeaConfig, ShareService } from "pangea-node-sdk";

// Load Pangea token and domain from environment variables
const token = process.env.PANGEA_SHARE_TOKEN;
const config = new PangeaConfig({ domain: process.env.PANGEA_DOMAIN });

// Create Share client
const client = new ShareService(token, config);

// Create unique folder path
const time = Math.round(Date.now() / 1000);
const folderPath = "/sdk_examples/node/delete/" + time;

(async () => {
try {
console.log("Creating folder...");
const respCreate = await client.folderCreate({
path: folderPath,
});

const id = respCreate.result.object.id;
console.log(`Folder create success. Folder ID: ${id}`);

console.log("Deleting folder...");
const respDelete = await client.delete({
id: id,
});

console.log(`Deleted ${respDelete.result.count} item(s)`);
} catch (e) {
console.log(e);
}
})();
215 changes: 215 additions & 0 deletions examples/share/item_life_cycle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/* eslint-disable no-console */

import {
PangeaConfig,
ShareService,
TransferMethod,
Share,
} from "pangea-node-sdk";
import * as fs from "fs";

// Load Pangea token and domain from environment variables
const token = process.env.PANGEA_SHARE_TOKEN;
const config = new PangeaConfig({ domain: process.env.PANGEA_DOMAIN });

// Create Share client
const client = new ShareService(token, config);

// Create unique folder path
const time = Math.round(Date.now() / 1000);
const folderPath = "/sdk_examples/node/delete/" + time;
const filepath = "./testfile.pdf";

(async () => {
try {
console.log("Creating folder...");
// Create a folder
const respCreate = await client.folderCreate({
path: folderPath,
});
const folderID = respCreate.result.object.id;
console.log(`Create folder success. Folder ID: ${folderID}`);

// # Upload a file with path as unique param
// Read file content as buffer
const data = fs.readFileSync(filepath);

console.log("\nUploading file with path as unique field...");
const path1 = folderPath + "/" + time + "_file_multipart_1";
const respPutPath = await client.put(
{
path: path1,
transfer_method: TransferMethod.MULTIPART,
},
{
file: data,
name: path1,
}
);

console.log(`Upload success. Item ID: ${respPutPath.result.object.id}`);
console.log(`\tParent ID: ${respPutPath.result.object.parent_id}`);
console.log(`\tMetadata: ${respPutPath.result.object.metadata}`);
console.log(`\tTags: ${respPutPath.result.object.tags}`);

console.log("\nUploading file with parent_id and name...");
// Upload a file with parent id and name
const name2 = time + "_file_multipart_2";
const metadata = { field1: "value1", field2: "value2" };
const tags = ["tag1", "tag2"];
const respPutId = await client.put(
{
parent_id: folderID,
name: name2,
transfer_method: TransferMethod.MULTIPART,
metadata: metadata,
tags: tags,
},
{
file: data,
name: path1,
}
);

console.log(`Upload success. Item ID: ${respPutId.result.object.id}`);
console.log(`\tParent ID: ${respPutId.result.object.parent_id}`);
console.log(`\tMetadata: ${respPutId.result.object.metadata}`);
console.log(`\tTags: ${respPutId.result.object.tags}`);

console.log("\nUpdating file with full metadata and tags...");
// Update file with full metadata and tags
const respUpdate = await client.update({
id: respPutPath.result.object.id,
metadata: metadata,
tags: tags,
});

console.log(`Upload success. Item ID: ${respUpdate.result.object.id}`);
console.log(`\tParent ID: ${respUpdate.result.object.parent_id}`);
console.log(`\tMetadata: ${respUpdate.result.object.metadata}`);
console.log(`\tTags: ${respUpdate.result.object.tags}`);

console.log("\nUpdating file with additional metadata and tags...");
// Update file with added metadata and tags
const addMetadata = { field3: "value3" };
const addTags = ["tag3"];

const respUpdateAdd = await client.update({
id: respPutPath.result.object.id,
add_metadata: addMetadata,
add_tags: addTags,
});

console.log(`Upload success. Item ID: ${respUpdateAdd.result.object.id}`);
console.log(`\tParent ID: ${respUpdateAdd.result.object.parent_id}`);
console.log(`\tMetadata: ${respUpdateAdd.result.object.metadata}`);
console.log(`\tTags: ${respUpdateAdd.result.object.tags}`);

console.log("\nGetting archive with multipart transfer method...");
// Get archive
const respGetArchive1 = await client.getArchive({
ids: [folderID],
format: Share.ArchiveFormat.ZIP,
transfer_method: TransferMethod.MULTIPART,
});

// Using multipart as transfer method it should return just 1 file and no dest url
console.log(
`Got ${respGetArchive1.attachedFiles.length} attached file(s).`
);
console.log(`Got URL: ${respGetArchive1.result.dest_url}`);

// Saving attached files
respGetArchive1.attachedFiles.forEach((file) => {
file.save("./");
});

console.log("\nGetting archive with dest-url transfer method...");
const respGetArchive2 = await client.getArchive({
ids: [folderID],
format: Share.ArchiveFormat.TAR,
transfer_method: TransferMethod.DEST_URL,
});

// Using dest-url as transfer method it should return no attahched files but dest url
console.log(
`Got ${respGetArchive2.attachedFiles.length} attached file(s).`
);
console.log(`Got URL: ${respGetArchive2.result.dest_url}`);

console.log("\nDownloading file...");
// Download file
const url = respGetArchive2.result.dest_url ?? "";
let downloadedFile = await client.downloadFile(url);

console.log("\nCreating share link...");
// Create share link
// Create authenticators list to access share link
const authenticators = [
{
auth_type: Share.AuthenticatorType.PASSWORD,
auth_context: "somepassword",
},
];

// Create a link's list, each link should have targets (folder or objects), link_type, etc.
const linkList = [
{
targets: [folderID],
link_type: Share.LinkType.EDITOR,
max_access_count: 3,
authenticators: authenticators,
},
];

// Send share link create request
const respCreateLink = await client.shareLinkCreate({
links: linkList,
});

const links = respCreateLink.result.share_link_objects;
console.log(`Created ${links.length} share links`);

const link = links[0];
console.log(`Link ID: ${link.id}. Link: ${link.link}`);

console.log("\nGetting already created link...");
// Get share link
const linkID = link?.id ?? "";
const respGetLink = await client.shareLinkGet({
id: linkID,
});
console.log(
`Got link ID: ${respGetLink.result.share_link_object.id}. Link: ${respGetLink.result.share_link_object.link}`
);

console.log("\nListing share links...");
// List share link
const respListLink = await client.shareLinkList();
console.log(`Got ${respListLink.result.count} link(s)`);

console.log("\nDeleting link...");
// Delete share link
const respDeleteLink = await client.shareLinkDelete({
ids: [linkID],
});
console.log(
`Deleted ${respDeleteLink.result.share_link_objects.length} link(s)`
);

console.log("\nListing files...");
// List files in folder
// Create a ListFilter and set its possible values
const listFilter = {
folder: folderPath,
};

const respList = await client.list({
filter: listFilter,
});

console.log(`Got ${respList.result.count} item(s)`);
} catch (e) {
console.log(e.toString());
}
})();
14 changes: 14 additions & 0 deletions examples/share/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "share_examples",
"version": "2.0.0",
"description": "Pangea Share example",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Pangea",
"license": "MIT",
"dependencies": {
"pangea-node-sdk": "file:../../packages/pangea-node-sdk"
}
}
Loading