@eluvio/elv-client-js 4.2.24 → 4.2.27

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,13 @@
1
+ {
2
+ "dev": {
3
+ "contentSpaceId": "ispc3ANoVSzNA3P6t7abLR69ho5YPPZU",
4
+ "networkId": 955210,
5
+ "networkName": "dev",
6
+ "fabricVersion": 3,
7
+ "fabricURIs": ["http://127.0.0.1:8008"],
8
+ "ethereumURIs": ["https://host-76-74-28-234.contentfabric.io/eth/"],
9
+ "fileServiceURIs": ["http://127.0.0.1:8008"],
10
+ "authServiceURIs": [],
11
+ "searchURIs": []
12
+ }
13
+ }
@@ -16,17 +16,36 @@ const StorageEndpointModel = SealedModel({
16
16
  });
17
17
 
18
18
  const CloudCredentialsModel = SealedModel({
19
- access_key_id: NonBlankString,
20
- secret_access_key: NonBlankString
21
- });
19
+ access_key_id: [NonBlankString],
20
+ secret_access_key: [NonBlankString],
21
+ signed_url: [NonBlankString]
22
+ }).assert(
23
+ function hasOneAuthenticationMethod(credentials) {
24
+ const hasAccessKey = Boolean(credentials.access_key_id);
25
+ const hasSecret = Boolean(credentials.secret_access_key);
26
+ const hasSignedUrl = Boolean(credentials.signed_url);
27
+
28
+ return hasSignedUrl
29
+ ? !hasAccessKey && !hasSecret
30
+ : hasAccessKey && hasSecret;
31
+ },
32
+ "cloud_credentials must contain either signed_url or both access_key_id and secret_access_key"
33
+ );
22
34
 
23
35
  const RemoteAccessModel = ObjectModel({
24
36
  protocol: "s3",
25
37
  platform: "aws",
26
- path: NonBlankString,
27
- storage_endpoint: StorageEndpointModel,
38
+ path: [NonBlankString],
39
+ storage_endpoint: [StorageEndpointModel],
28
40
  cloud_credentials: CloudCredentialsModel
29
- });
41
+ }).assert(
42
+ function hasLocationForAccessKeyCredentials(remoteAccess) {
43
+ if(remoteAccess.cloud_credentials.signed_url) return true;
44
+
45
+ return Boolean(remoteAccess.path && remoteAccess.storage_endpoint);
46
+ },
47
+ "path and storage_endpoint are required when using access key credentials"
48
+ );
30
49
 
31
50
  const CredentialModel = ObjectModel({
32
51
  path_matchers: TypedArrayNonEmpty(NonBlankString),
@@ -43,4 +62,4 @@ module.exports = {
43
62
  CheckedCredentialSet,
44
63
  CredentialModel,
45
64
  CredentialSetModel,
46
- };
65
+ };
@@ -0,0 +1,96 @@
1
+ const {expect} = require("chai");
2
+
3
+ const {ElvClient} = require("../../../../../src/ElvClient");
4
+ const Client = require("../../../../lib/concerns/Client");
5
+
6
+ const logger = {
7
+ error: () => {},
8
+ log: () => {}
9
+ };
10
+
11
+ const context = ({args={}, env={}} = {}) => ({
12
+ args: {
13
+ ethContractTimeout: 10,
14
+ ...args
15
+ },
16
+ concerns: {Logger: logger},
17
+ env: {
18
+ PRIVATE_KEY: "private-key",
19
+ ...env
20
+ }
21
+ });
22
+
23
+ const fakeClient = () => {
24
+ const nodeSelections = [];
25
+
26
+ return {
27
+ GenerateWallet: () => ({AddAccount: () => ({})}),
28
+ SetNodes: nodes => nodeSelections.push(nodes),
29
+ SetSigner: async () => {},
30
+ ToggleLogging: () => {},
31
+ nodeSelections
32
+ };
33
+ };
34
+
35
+ describe("Client concern", () => {
36
+ let originalFromConfigurationUrl;
37
+ let originalFromNetworkName;
38
+
39
+ beforeEach(() => {
40
+ originalFromConfigurationUrl = ElvClient.FromConfigurationUrl;
41
+ originalFromNetworkName = ElvClient.FromNetworkName;
42
+ });
43
+
44
+ afterEach(() => {
45
+ ElvClient.FromConfigurationUrl = originalFromConfigurationUrl;
46
+ ElvClient.FromNetworkName = originalFromNetworkName;
47
+ });
48
+
49
+ it("uses the main network by default", async () => {
50
+ let initArgs;
51
+ ElvClient.FromNetworkName = async args => {
52
+ initArgs = args;
53
+ return fakeClient();
54
+ };
55
+
56
+ await Client.New(context()).get();
57
+
58
+ expect(initArgs.networkName).to.equal("main");
59
+ });
60
+
61
+ it("uses a supplied config URL instead of the default network", async () => {
62
+ let initArgs;
63
+ ElvClient.FromConfigurationUrl = async args => {
64
+ initArgs = args;
65
+ return fakeClient();
66
+ };
67
+
68
+ await Client.New(context({args: {configUrl: "https://example.com/config"}})).get();
69
+
70
+ expect(initArgs.configUrl).to.equal("https://example.com/config");
71
+ });
72
+
73
+ it("uses an explicitly selected built-in network", async () => {
74
+ let initArgs;
75
+ ElvClient.FromNetworkName = async args => {
76
+ initArgs = args;
77
+ return fakeClient();
78
+ };
79
+
80
+ await Client.New(context({args: {network: "demo"}})).get();
81
+
82
+ expect(initArgs.networkName).to.equal("demo");
83
+ });
84
+
85
+ it("pins fabric and file-service requests to the supplied node", async () => {
86
+ const client = fakeClient();
87
+ ElvClient.FromNetworkName = async () => client;
88
+
89
+ await Client.New(context({args: {node: "fabric.example.com"}})).get();
90
+
91
+ expect(client.nodeSelections).to.deep.equal([{
92
+ fabricURIs: ["https://fabric.example.com"],
93
+ fileServiceURIs: ["https://fabric.example.com"]
94
+ }]);
95
+ });
96
+ });