mongodb-atlas-api-client 3.17.0 → 3.19.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.
@@ -14,7 +14,7 @@ jobs:
14
14
  fetch-depth: 0 # otherwise, you will failed to push refs to dest repo:
15
15
  - uses: actions/setup-node@v1
16
16
  with:
17
- node-version: 12
17
+ node-version: 16
18
18
  registry-url: https://registry.npmjs.org/
19
19
  - run: npm install
20
20
  - run: npm test
package/README.md CHANGED
@@ -54,6 +54,7 @@ const response = await user.update("someUserName", body, options); // update use
54
54
  Following entities are currently supported
55
55
 
56
56
  - [User](#user)
57
+ - [CloudBackup](#cloudbackup)
57
58
  - [Cluster](#cluster)
58
59
  - [CustomDbRole](#customdbrole)
59
60
  - [ProjectWhitelist](#projectwhitelist)
@@ -128,6 +129,59 @@ Function - Deletes the user name passed.
128
129
 
129
130
  More details - https://docs.atlas.mongodb.com/reference/api/database-users-delete-a-user/
130
131
 
132
+ ### CloudBackup
133
+
134
+ ### cloudBackup.getReplicaSetCloudBackup(clustername, snapshotId, [options]) ⇒ <code>Promise</code>
135
+ Function - Returns the details of the specified snapshotId.
136
+
137
+ **Returns**: <code>Promise</code> - - promise which resolves on success and rejects on error
138
+
139
+ | Param | Type | Default | Description |
140
+ | --- | --- | --- | --- |
141
+ | clustername | <code>String</code> | | name of the cluster for which details needs to be retrieved |
142
+ | snapshotId | <code>String</code> | | Id of the snapshot for which details needs to be retrieved |
143
+ | [options] | <code>Object</code> | <code>{}</code> | Optional object containing extra query strings which will be passed to atlas api. It can also include httpOptions which will be sent to `urllib`. More info can be found here - https://github.com/node-modules/urllib |
144
+
145
+ More details - https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v1/#tag/Cloud-Backups/operation/getReplicaSetBackup
146
+
147
+ ### cloudBackup.getAllReplicaSetCloudBackups(clustername, [options]) ⇒ <code>Promise</code>
148
+ Function - Returns the details of all snapshots of an specified clustername.
149
+
150
+ **Returns**: <code>Promise</code> - - promise which resolves on success and rejects on error
151
+
152
+ | Param | Type | Default | Description |
153
+ | --- | --- | --- | --- |
154
+ | clustername | <code>String</code> | | name of the cluster for which details needs to be retrieved |
155
+ | [options] | <code>Object</code> | <code>{}</code> | Optional object containing extra query strings which will be passed to atlas api. It can also include httpOptions which will be sent to `urllib`. More info can be found here - https://github.com/node-modules/urllib |
156
+
157
+ More details - https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v1/#tag/Cloud-Backups/operation/listReplicaSetBackups
158
+
159
+ ### cloudBackup.getSnapshotRestoreJob(clustername, restoreJobId, [options]) ⇒ <code>Promise</code>
160
+ Function - Returns the details of all snapshots of an specified clustername.
161
+
162
+ **Returns**: <code>Promise</code> - - promise which resolves on success and rejects on error
163
+
164
+ | Param | Type | Default | Description |
165
+ | --- | --- | --- | --- |
166
+ | clustername | <code>String</code> | | name of the cluster for which details needs to be retrieved |
167
+ | restoreJobId | <code>String</code> | | snapshot restore job id for which details needs to be retrieved |
168
+ | [options] | <code>Object</code> | <code>{}</code> | Optional object containing extra query strings which will be passed to atlas api. It can also include httpOptions which will be sent to `urllib`. More info can be found here - https://github.com/node-modules/urllib |
169
+
170
+ More details - https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v1/#tag/Cloud-Backups/operation/getBackupRestoreJob
171
+
172
+ ### cloudBackup.createSnapshotRestoreJob(clustername, body, [options]) ⇒ <code>Promise</code>
173
+ Function - Returns the details of all snapshots of an specified clustername.
174
+
175
+ **Returns**: <code>Promise</code> - - promise which resolves on success and rejects on error
176
+
177
+ | Param | Type | Default | Description |
178
+ | --- | --- | --- | --- |
179
+ | clustername | <code>String</code> | | name of the cluster for which details needs to be retrieved |
180
+ | body | <code>Object</code> | | Body which has details for snapshot restore job which needs to be created |
181
+ | [options] | <code>Object</code> | <code>{}</code> | Optional object containing extra query strings which will be passed to atlas api. It can also include httpOptions which will be sent to `urllib`. More info can be found here - https://github.com/node-modules/urllib |
182
+
183
+ More details - https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v1/#tag/Cloud-Backups/operation/createBackupRestoreJob
184
+
131
185
  ### Cluster
132
186
 
133
187
  ### cluster.get(clustername, [options]) ⇒ <code>Promise</code>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb-atlas-api-client",
3
- "version": "3.17.0",
3
+ "version": "3.19.0",
4
4
  "description": "A mongodb atlas api client for nodejs.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,70 @@
1
+ import {ClusterName, Links, AtlasResultsResponse, AtlasClientOptions, AtlasError} from ".";
2
+
3
+ export interface GetReplicaSetCloudBackup {
4
+ cloudProvider: 'AWS' | 'GCP' | 'AZURE' | 'TENANT';
5
+ copyRegions: string[];
6
+ createdAt: string;
7
+ description?: string;
8
+ expiresAt: string;
9
+ frequencyType: 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly';
10
+ id: string;
11
+ links: Links;
12
+ masterKeyUUID?: string;
13
+ mongodVersion: string;
14
+ policyItems: Array;
15
+ replicaSetName: string;
16
+ snapshotType: 'onDemand' | 'scheduled';
17
+ status: 'queued' | 'inProgress' | 'completed' | 'failed';
18
+ storageSizeBytes: number;
19
+ type: string
20
+ }
21
+
22
+ export type GetAllReplicaSetCloudBackups = AtlasResultsResponse<GetReplicaSetCloudBackup>;
23
+
24
+ export interface SnapshotRestoreJobComponent {
25
+ replicaSetName: string
26
+ }
27
+
28
+ export type SnapshotRestoreJobComponents = SnapshotRestoreJobComponent[]
29
+
30
+ export interface GetSnapshotRestoreJob {
31
+ cancelled?: boolean;
32
+ components?: SnapshotRestoreJobComponents;
33
+ deliveryType: 'automated' | 'download' | 'pointInTime';
34
+ deliveryUrl?: string[];
35
+ desiredTimestamp?: {
36
+ date: string;
37
+ increment: number
38
+ };
39
+ expired?: boolean;
40
+ expiresAt?: string;
41
+ failed?: boolean;
42
+ finishedAt?: string;
43
+ id?: string;
44
+ links?: Links;
45
+ oplogInc?: number;
46
+ oplogTs?: number;
47
+ pointInTimeUTCSeconds?: number;
48
+ snapshotId?: string;
49
+ targetClusterName?: string;
50
+ targetGroupId?: string;
51
+ timestamp?: string
52
+ }
53
+
54
+ export interface SnapshotRestoreJobRequest {
55
+ deliveryType: 'automated' | 'download' | 'pointInTime';
56
+ oplogInc?: number;
57
+ oplogTs?: number;
58
+ pointInTimeUTCSeconds?: number;
59
+ snapshotId?: string;
60
+ targetClusterName?: string;
61
+ targetGroupId?: string
62
+ }
63
+ export type CreateSnapshotRestoreJobResponse = GetSnapshotRestoreJob;
64
+
65
+ export interface CloudBackup {
66
+ getReplicaSetCloudBackup(clustername: ClusterName, snapshotId: string, options?: AtlasClientOptions): Promise<GetReplicaSetCloudBackup | AtlasError>;
67
+ getAllReplicaSetCloudBackups(clustername: ClusterName, options?: AtlasClientOptions): Promise<GetAllReplicaSetCloudBackups | AtlasError>;
68
+ getSnapshotRestoreJob(clustername: ClusterName, restoreJobId: string, options?: AtlasClientOptions): Promise<CreateSnapshotRestoreJobResponse | AtlasError>
69
+ createSnapshotRestoreJob(clustername: ClusterName, body: SnapshotRestoreJobRequest, options?: AtlasClientOptions): Promise<CreateSnapshotRestoreJobResponse | AtlasError>
70
+ }
@@ -0,0 +1,53 @@
1
+ const {getQueryStringFromOptions} = require("./helper");
2
+
3
+ class CloudBackup {
4
+
5
+ constructor(client, baseUrl, projectId) {
6
+ this.client_ = client;
7
+ this.baseUrl_ = baseUrl;
8
+ this.projectId_ = projectId;
9
+ }
10
+
11
+ async getReplicaSetCloudBackup(clustername, snapshotId, options = {}) {
12
+ const queryString = getQueryStringFromOptions(options);
13
+ const httpOptions = options.httpOptions;
14
+ const response = (
15
+ await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}/backup/snapshots/${snapshotId}?${queryString}`, httpOptions)
16
+ );
17
+ return response;
18
+ }
19
+
20
+ async getAllReplicaSetCloudBackups(clustername, options = {}) {
21
+ const queryString = getQueryStringFromOptions(options);
22
+ const httpOptions = options.httpOptions;
23
+ const response = (
24
+ await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}/backup/snapshots?${queryString}`, httpOptions)
25
+ );
26
+ return response;
27
+ }
28
+
29
+ async getSnapshotRestoreJob(clustername, restoreJobId, options = {}) {
30
+ const queryString = getQueryStringFromOptions(options);
31
+ const httpOptions = options.httpOptions;
32
+ const response = (
33
+ await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}/backup/restoreJobs/${restoreJobId}?${queryString}`, httpOptions)
34
+ );
35
+ return response;
36
+ }
37
+
38
+ async createSnapshotRestoreJob(clustername, body, options = {}) {
39
+ const queryString = getQueryStringFromOptions(options);
40
+ const httpOptions = options.httpOptions;
41
+ const response = (
42
+ await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}/backup/restoreJobs?${queryString}`, {
43
+ "method": "POST",
44
+ "data": body,
45
+ "headers": {"Content-Type": "application/json"},
46
+ ...httpOptions
47
+ })
48
+ );
49
+ return response;
50
+ }
51
+ }
52
+
53
+ module.exports = CloudBackup;
package/src/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {Alert} from './alert'
2
2
  import {AtlasUser} from './atlasUser';
3
3
  import {Cluster} from './cluster';
4
+ import {CloudBackup} from './cloudBackup';
4
5
  import {CustomDbRole} from './customDbRole';
5
6
  import {Event} from './event';
6
7
  import {Organization} from './organization';
@@ -15,6 +16,7 @@ import {AtlasSearch} from './atlasSearch';
15
16
  export * from './alert'
16
17
  export * from './atlasUser';
17
18
  export * from './cluster';
19
+ export * from './cloudBackup';
18
20
  export * from './customDbRole';
19
21
  export * from './event';
20
22
  export * from './organization';
@@ -66,6 +68,7 @@ export interface AtlasClient {
66
68
  projectAccesslist: ProjectAccesslist;
67
69
  customDbRole: CustomDbRole;
68
70
  cluster: Cluster;
71
+ cloudBackup: CloudBackup;
69
72
  event: Event;
70
73
  dataLake: DataLake;
71
74
  cloudProviderAccess: CloudProviderAccess;
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const User = require("./user");
2
+ const CloudBackup = require("./cloudBackup");
2
3
  const Cluster = require("./cluster");
3
4
  const CustomDbRole = require("./customDbRole");
4
5
  const ProjectWhitelist = require("./projectWhitelist");
@@ -30,6 +31,7 @@ function getMongodbAtlasApiClient(options) {
30
31
  const client = new HttpClient(urllibClient, options.publicKey, options.privateKey);
31
32
  const user = new User(client, options.baseUrl, options.projectId);
32
33
  const cluster = new Cluster(client, options.baseUrl, options.projectId);
34
+ const cloudBackup = new CloudBackup(client, options.baseUrl, options.projectId);
33
35
  const customDbRole = new CustomDbRole(client, options.baseUrl, options.projectId);
34
36
  const projectWhitelist = new ProjectWhitelist(client, options.baseUrl, options.projectId);
35
37
  const projectAccesslist = new ProjectAccesslist(client, options.baseUrl, options.projectId);
@@ -45,6 +47,7 @@ function getMongodbAtlasApiClient(options) {
45
47
  const functions = {};
46
48
  functions.user = getFunctions(user);
47
49
  functions.cluster = getFunctions(cluster);
50
+ functions.cloudBackup = getFunctions(cloudBackup);
48
51
  functions.customDbRole = getFunctions(customDbRole);
49
52
  functions.projectWhitelist = getFunctions(projectWhitelist);
50
53
  functions.projectAccesslist = getFunctions(projectAccesslist);
@@ -0,0 +1,70 @@
1
+ const {describe, it} = exports.lab = require("@hapi/lab").script();
2
+ const {expect} = require("@hapi/code");
3
+ const nock = require("nock");
4
+ const getClient = require("../src");
5
+
6
+ const baseUrl = "http://dummyBaseUrl";
7
+ const projectId = "dummyProjectId";
8
+
9
+ const client = getClient({
10
+ "publicKey": "dummuyPublicKey",
11
+ "privateKey": "dummyPrivateKey",
12
+ "baseUrl": baseUrl,
13
+ "projectId": projectId
14
+ });
15
+
16
+ describe("Mongo Atlas Api Client - CloudBackup", () => {
17
+
18
+ describe("When cluster is exported from index", () => {
19
+ it("should export cluster functions", async () => {
20
+ expect(client.cloudBackup.getReplicaSetCloudBackup).to.be.function();
21
+ expect(client.cloudBackup.getAllReplicaSetCloudBackups).to.be.function();
22
+ expect(client.cloudBackup.getSnapshotRestoreJob).to.be.function();
23
+ expect(client.cloudBackup.createSnapshotRestoreJob).to.be.function();
24
+ });
25
+ });
26
+
27
+ describe("When getReplicaSetCloudBackup is called with querystring parameters", () => {
28
+ it("should return response", async () => {
29
+ const expectedRequest = nock(baseUrl)
30
+ .get(`/groups/${projectId}/clusters/mycluster/backup/snapshots/mysnapshot?key1=value1&key2=value2`)
31
+ .reply(200, {"replicaSetName": "mycluster"});
32
+ const result = await client.cloudBackup.getReplicaSetCloudBackup("mycluster", "mysnapshot", {"key1": "value1", "key2": "value2"});
33
+ expect(result).to.equal({"replicaSetName": "mycluster"});
34
+ expect(expectedRequest.isDone()).to.be.true();
35
+ });
36
+ });
37
+
38
+ describe("When getAllReplicaSetCloudBackups is called with querystring parameters", () => {
39
+ it("should return response", async () => {
40
+ const expectedRequest = nock(baseUrl)
41
+ .get(`/groups/${projectId}/clusters/mycluster/backup/snapshots?key1=value1&key2=value2`)
42
+ .reply(200, [{"replicaSetName": "mycluster"}]);
43
+ const result = await client.cloudBackup.getAllReplicaSetCloudBackups("mycluster", {"key1": "value1", "key2": "value2"});
44
+ expect(result).to.equal([{"replicaSetName": "mycluster"}]);
45
+ expect(expectedRequest.isDone()).to.be.true();
46
+ });
47
+ });
48
+
49
+ describe("When getSnapshotRestoreJob is called with querystring parameters", () => {
50
+ it("should return response", async () => {
51
+ const expectedRequest = nock(baseUrl)
52
+ .get(`/groups/${projectId}/clusters/mycluster/backup/restoreJobs/myrestorejob?key1=value1&key2=value2`)
53
+ .reply(200, {"id": "myrestorejob"});
54
+ const result = await client.cloudBackup.getSnapshotRestoreJob("mycluster", "myrestorejob", {"key1": "value1", "key2": "value2"});
55
+ expect(result).to.equal({"id": "myrestorejob"});
56
+ expect(expectedRequest.isDone()).to.be.true();
57
+ });
58
+ });
59
+
60
+ describe("When createSnapshotRestoreJob is called with querystring parameters", () => {
61
+ it("should return response", async () => {
62
+ const expectedRequest = nock(baseUrl)
63
+ .post(`/groups/${projectId}/clusters/mycluster/backup/restoreJobs?key1=value1&key2=value2`)
64
+ .reply(200, {"id": "myrestorejob"});
65
+ const result = await client.cloudBackup.createSnapshotRestoreJob("mycluster", {"body": "value"}, {"key1": "value1", "key2": "value2"});
66
+ expect(result).to.equal({"id": "myrestorejob"});
67
+ expect(expectedRequest.isDone()).to.be.true();
68
+ });
69
+ });
70
+ });