diff --git a/examples/global-catalog.v1.test.js b/examples/global-catalog.v1.test.js new file mode 100644 index 00000000..784a3324 --- /dev/null +++ b/examples/global-catalog.v1.test.js @@ -0,0 +1,568 @@ +/** +* @jest-environment node +*/ +/** + * (C) Copyright IBM Corp. 2021. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +const GlobalCatalogV1 = require('../dist/global-catalog/v1'); +const { readExternalSources, streamToPromise } = require('ibm-cloud-sdk-core'); +const authHelper = require('../test/resources/auth-helper.js'); +const { CreateCatalogEntryConstants, UpdateCatalogEntryConstants } = require('../dist/global-catalog/v1'); +const { v4: uuidv4 } = require('uuid'); + +// +// This file provides an example of how to use the Global Catalog service. +// +// GLOBAL_CATALOG_URL= +// GLOBAL_CATALOG_AUTH_TYPE=iam +// GLOBAL_CATALOG_APIKEY= +// GLOBAL_CATALOG_AUTH_URL= +// + +// Location of our config file. +const configFile = 'global_catalog.env'; + +const describe = authHelper.prepareTests(configFile); +const timeout = 60000; + +// Save original console.log and console.warn +const originalLog = console.log; +const originalWarn = console.warn; + +// Mocks for console.log and console.warn +const consoleLogMock = jest.spyOn(console, 'log'); +const consoleWarnMock = jest.spyOn(console, 'warn'); + +describe('GlobalCatalogV1', () => { + jest.setTimeout(timeout); + + // begin-common + + const globalCatalogService = GlobalCatalogV1.newInstance({}); + + // end-common + + const config = readExternalSources(GlobalCatalogV1.DEFAULT_SERVICE_NAME); + + // Global variables to hold values shared between testcases. + let catalogEntryId; + + + test('createCatalogEntry request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-create_catalog_entry + const overviewModelEN = { + display_name: 'Example Web Starter', + description: 'Use the Example service in your applications', + long_description: 'This is a starter that helps you use the Example service within your applications.', + }; + const overviewUIModel = { + en: overviewModelEN, + }; + const imageModel = { + image: 'https://somehost.com/examplewebstarter/cachedIcon/large/0', + small_image: 'https://somehost.com/examplewebstarter/cachedIcon/small/0', + medium_image: 'https://somehost.com/examplewebstarter/cachedIcon/medium/0', + feature_image: 'https://somehost.com/examplewebstarter/cachedIcon/large/0', + }; + const providerModel = { + email: 'info@examplestarter.com', + name: 'Example Starter Co., Inc.', + contact: 'Example Starter Developer Relations', + support_email: 'support@examplestarter.com', + phone: '800-555-1234', + }; + const metadataModel = { + version: '1.0.0', + }; + + catalogEntryId = uuidv4(); + + const params = { + name: 'exampleWebStarter123', + kind: CreateCatalogEntryConstants.Kind.TEMPLATE, + overviewUi: overviewUIModel, + images: imageModel, + disabled: false, + tags: ['example-tag-1', 'example-tag-2'], + provider: providerModel, + id: catalogEntryId, + active: true, + metadata: metadataModel, + }; + + globalCatalogService.createCatalogEntry(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-create_catalog_entry + }); + test('getCatalogEntry request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-get_catalog_entry + + const params = { + id: catalogEntryId, + complete: true, + }; + + globalCatalogService.getCatalogEntry(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_catalog_entry + }); + test('updateCatalogEntry request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-update_catalog_entry + const overviewModelEN = { + display_name: 'Example Web Starter V2', + description: 'Use the Example V2 service in your applications', + long_description: 'This is a starter that helps you use the Example V2 service within your applications.', + }; + const overviewUIModel = { + en: overviewModelEN, + }; + const imageModel = { + image: 'https://somehost.com/examplewebstarter/cachedIcon/large/0', + small_image: 'https://somehost.com/examplewebstarter/cachedIcon/small/0', + medium_image: 'https://somehost.com/examplewebstarter/cachedIcon/medium/0', + feature_image: 'https://somehost.com/examplewebstarter/cachedIcon/large/0', + }; + const providerModel = { + email: 'info@examplestarter.com', + name: 'Example Starter Co., Inc.', + contact: 'Example Starter Developer Relations', + support_email: 'support@examplestarter.com', + phone: '800-555-1234', + }; + const metadataModel = { + version: '2.0.0', + }; + + const params = { + id: catalogEntryId, + name: 'exampleWebStarter123', + kind: UpdateCatalogEntryConstants.Kind.TEMPLATE, + overviewUi: overviewUIModel, + images: imageModel, + disabled: false, + tags: ['example-tag-1', 'example-tag-2', 'new-example-tag-3'], + provider: providerModel, + active: true, + metadata: metadataModel, + }; + + globalCatalogService.updateCatalogEntry(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-update_catalog_entry + }); + test('listCatalogEntries request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + // begin-list_catalog_entries + const params = { + offset: 0, + limit: 10, + q: 'kind:template tag:example-tag-1', + complete: true, + }; + globalCatalogService.listCatalogEntries(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-list_catalog_entries + }); + test('getChildObjects request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-get_child_objects + + const params = { + id: catalogEntryId, + kind: '*', + offset: 0, + limit: 10, + complete: true, + }; + + globalCatalogService.getChildObjects(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_child_objects + }); + test('restoreCatalogEntry request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-restore_catalog_entry + + const params = { + id: catalogEntryId, + }; + + globalCatalogService.restoreCatalogEntry(params) + .then(res => { + console.log(JSON.stringify(res, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-restore_catalog_entry + }); + test('getVisibility request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-get_visibility + + const params = { + id: catalogEntryId, + }; + + globalCatalogService.getVisibility(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_visibility + }); + test('updateVisibility request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-update_visibility + + const params = { + id: catalogEntryId, + extendable: false, + }; + + globalCatalogService.updateVisibility(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.log('updateVisibility() returned the following error: ' + err); + }); + + // end-update_visibility + }); + test('getPricing request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-get_pricing + + const params = { + id: catalogEntryId, + }; + + globalCatalogService.getPricing(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_pricing + }); + test('getAuditLogs request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-get_audit_logs + + const params = { + id: catalogEntryId, + offset: 0, + limit: 10, + }; + + globalCatalogService.getAuditLogs(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_audit_logs + }); + test('uploadArtifact request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-upload_artifact + const params = { + objectId: catalogEntryId, + artifactId: 'artifact.txt', + artifact: Buffer.from('This is an example artifact associated with a catalog entry.', 'utf8'), + contentType: 'text/plain', + }; + + globalCatalogService.uploadArtifact(params) + .then(res => { + console.log(JSON.stringify(res, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-upload_artifact + }); + test('getArtifact request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + let responseContentType = null; + + // begin-get_artifact + + const params = { + objectId: catalogEntryId, + artifactId: 'artifact.txt', + }; + + globalCatalogService.getArtifact(params) + .then(res => { + responseContentType = res.headers['content-type']; + return streamToPromise(res.result); + }) + .then(contents => { + console.log(`Artifact content type: ${responseContentType}\nArtifact contents: ${contents}`); + }) + .catch(err => { + console.warn(err) + }); + + // end-get_artifact + }); + test('listArtifacts request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-list_artifacts + + const params = { + objectId: catalogEntryId, + }; + + globalCatalogService.listArtifacts(params) + .then(res => { + console.log(JSON.stringify(res.result, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-list_artifacts + }); + test('deleteArtifact request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-delete_artifact + + const params = { + objectId: catalogEntryId, + artifactId: 'artifact.txt', + }; + + globalCatalogService.deleteArtifact(params) + .then(res => { + console.log(JSON.stringify(res, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-delete_artifact + }); + test('deleteCatalogEntry request example', done => { + + consoleLogMock.mockImplementation(output => { + originalLog(output); + done(); + }); + consoleWarnMock.mockImplementation(output => { + done(output); + }); + + expect(catalogEntryId).not.toBeNull(); + + // begin-delete_catalog_entry + + const params = { + id: catalogEntryId, + }; + + globalCatalogService.deleteCatalogEntry(params) + .then(res => { + console.log(JSON.stringify(res, null, 2)); + }) + .catch(err => { + console.warn(err) + }); + + // end-delete_catalog_entry + }); +}); diff --git a/global-catalog/v1.ts b/global-catalog/v1.ts index 467864bb..371e34ec 100644 --- a/global-catalog/v1.ts +++ b/global-catalog/v1.ts @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-629bbb97-20201207-171303 + * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-4c92c221-20210211-060810 */ @@ -121,8 +121,15 @@ class GlobalCatalogV1 extends BaseService { * returned are of the language preferred by your browser through the Accept-Langauge header, which allows an override * of the header. Languages are specified in standard form, such as `en-us`. To include all languages use a wildcard * (*). - * @param {string} [params.complete] - Returns all available fields for all languages. Use the value `?complete=true` + * @param {boolean} [params.catalog] - Checks to see if a catalog's object is visible, or if it's filtered by service, + * plan, deployment, or region. Use the value `?catalog=true`. If a `200` code is returned, the object is visible. If + * a `403` code is returned, the object is not visible for the user. + * @param {boolean} [params.complete] - Returns all available fields for all languages. Use the value `?complete=true` * as shortcut for ?include=*&languages=*. + * @param {number} [params.offset] - Useful for pagination, specifies index (origin 0) of first item to return in + * response. + * @param {number} [params.limit] - Useful for pagination, specifies the maximum number of items to return in the + * response. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -136,7 +143,10 @@ class GlobalCatalogV1 extends BaseService { 'sort-by': _params.sortBy, 'descending': _params.descending, 'languages': _params.languages, - 'complete': _params.complete + 'catalog': _params.catalog, + 'complete': _params.complete, + '_offset': _params.offset, + '_limit': _params.limit }; const sdkHeaders = getSdkHeaders(GlobalCatalogV1.DEFAULT_SERVICE_NAME, 'v1', 'listCatalogEntries'); @@ -255,7 +265,7 @@ class GlobalCatalogV1 extends BaseService { * returned are of the language preferred by your browser through the Accept-Langauge header, which allows an override * of the header. Languages are specified in standard form, such as `en-us`. To include all languages use a wildcard * (*). - * @param {string} [params.complete] - Returns all available fields for all languages. Use the value `?complete=true` + * @param {boolean} [params.complete] - Returns all available fields for all languages. Use the value `?complete=true` * as shortcut for ?include=*&languages=*. * @param {number} [params.depth] - Return the children down to the requested depth. Use * to include the entire * children tree. If there are more children than the maximum permitted an error will be returned. Be judicious with @@ -467,7 +477,11 @@ class GlobalCatalogV1 extends BaseService { * returned are of the language preferred by your browser through the Accept-Langauge header. This allows an override * of the header. Languages are specified in standard form, such as `en-us`. To include all languages use the wildcard * (*). - * @param {string} [params.complete] - Use the value `?complete=true` as shortcut for ?include=*&languages=*. + * @param {boolean} [params.complete] - Use the value `?complete=true` as shortcut for ?include=*&languages=*. + * @param {number} [params.offset] - Useful for pagination, specifies index (origin 0) of first item to return in + * response. + * @param {number} [params.limit] - Useful for pagination, specifies the maximum number of items to return in the + * response. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -487,7 +501,9 @@ class GlobalCatalogV1 extends BaseService { 'sort-by': _params.sortBy, 'descending': _params.descending, 'languages': _params.languages, - 'complete': _params.complete + 'complete': _params.complete, + '_offset': _params.offset, + '_limit': _params.limit }; const path = { @@ -1072,10 +1088,19 @@ namespace GlobalCatalogV1 { * are specified in standard form, such as `en-us`. To include all languages use a wildcard (*). */ languages?: string; + /** Checks to see if a catalog's object is visible, or if it's filtered by service, plan, deployment, or region. + * Use the value `?catalog=true`. If a `200` code is returned, the object is visible. If a `403` code is returned, + * the object is not visible for the user. + */ + catalog?: boolean; /** Returns all available fields for all languages. Use the value `?complete=true` as shortcut for * ?include=*&languages=*. */ - complete?: string; + complete?: boolean; + /** Useful for pagination, specifies index (origin 0) of first item to return in response. */ + offset?: number; + /** Useful for pagination, specifies the maximum number of items to return in the response. */ + limit?: number; headers?: OutgoingHttpHeaders; } @@ -1152,7 +1177,7 @@ namespace GlobalCatalogV1 { /** Returns all available fields for all languages. Use the value `?complete=true` as shortcut for * ?include=*&languages=*. */ - complete?: string; + complete?: boolean; /** Return the children down to the requested depth. Use * to include the entire children tree. If there are * more children than the maximum permitted an error will be returned. Be judicious with this as it can cause a * large number of database accesses and can result in a large amount of data returned. @@ -1267,7 +1292,11 @@ namespace GlobalCatalogV1 { */ languages?: string; /** Use the value `?complete=true` as shortcut for ?include=*&languages=*. */ - complete?: string; + complete?: boolean; + /** Useful for pagination, specifies index (origin 0) of first item to return in response. */ + offset?: number; + /** Useful for pagination, specifies the maximum number of items to return in the response. */ + limit?: number; headers?: OutgoingHttpHeaders; } diff --git a/package-lock.json b/package-lock.json index 624d4df5..1cf7786e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "ibm-platform-services", - "version": "0.17.8", + "version": "0.17.9", "license": "Apache-2.0", "dependencies": { "@types/node": "^12.0.8", @@ -684,7 +684,6 @@ "jest-resolve": "^26.6.2", "jest-util": "^26.6.2", "jest-worker": "^26.6.2", - "node-notifier": "^8.0.0", "slash": "^3.0.0", "source-map": "^0.6.0", "string-length": "^4.0.1", @@ -4324,7 +4323,6 @@ "minimist": "^1.2.5", "neo-async": "^2.6.0", "source-map": "^0.6.1", - "uglify-js": "^3.1.4", "wordwrap": "^1.0.0" }, "bin": { @@ -5523,7 +5521,6 @@ "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", - "fsevents": "^2.1.2", "graceful-fs": "^4.2.4", "jest-regex-util": "^26.0.0", "jest-serializer": "^26.6.2", @@ -8027,7 +8024,6 @@ "inBundle": true, "license": "MIT", "dependencies": { - "colors": "^1.1.2", "object-assign": "^4.1.0", "string-width": "^2.1.1" }, @@ -11309,7 +11305,6 @@ "license": "ISC", "dependencies": { "debuglog": "^1.0.1", - "graceful-fs": "^4.1.2", "read-package-json": "^2.0.0", "readdir-scoped-modules": "^1.0.0", "semver": "2 || 3 || 4 || 5", @@ -11329,7 +11324,6 @@ "license": "ISC", "dependencies": { "glob": "^7.1.1", - "graceful-fs": "^4.1.2", "json-parse-better-errors": "^1.0.1", "normalize-package-data": "^2.0.0", "npm-normalize-package-bin": "^1.0.0" @@ -11798,13 +11792,9 @@ "dependencies": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", - "bcrypt-pbkdf": "^1.0.0", "dashdash": "^1.12.0", - "ecc-jsbn": "~0.1.1", "getpass": "^0.1.1", - "jsbn": "~0.1.0", - "safer-buffer": "^2.0.2", - "tweetnacl": "~0.14.0" + "safer-buffer": "^2.0.2" }, "bin": { "sshpk-conv": "bin/sshpk-conv", diff --git a/test/unit/global-catalog.v1.test.js b/test/unit/global-catalog.v1.test.js index b766c121..7033b2bf 100644 --- a/test/unit/global-catalog.v1.test.js +++ b/test/unit/global-catalog.v1.test.js @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,7 +110,10 @@ describe('GlobalCatalogV1', () => { const sortBy = 'testString'; const descending = 'testString'; const languages = 'testString'; - const complete = 'testString'; + const catalog = true; + const complete = true; + const offset = 38; + const limit = 200; const params = { account: account, include: include, @@ -118,7 +121,10 @@ describe('GlobalCatalogV1', () => { sortBy: sortBy, descending: descending, languages: languages, + catalog: catalog, complete: complete, + offset: offset, + limit: limit, }; const listCatalogEntriesResult = globalCatalogService.listCatalogEntries(params); @@ -141,7 +147,10 @@ describe('GlobalCatalogV1', () => { expect(options.qs['sort-by']).toEqual(sortBy); expect(options.qs['descending']).toEqual(descending); expect(options.qs['languages']).toEqual(languages); + expect(options.qs['catalog']).toEqual(catalog); expect(options.qs['complete']).toEqual(complete); + expect(options.qs['_offset']).toEqual(offset); + expect(options.qs['_limit']).toEqual(limit); }); test('should prioritize user-given headers', () => { @@ -308,7 +317,7 @@ describe('GlobalCatalogV1', () => { primary_offering_id: 'testString', accessible_during_provision: true, side_by_side_index: 38, - end_of_service_time: '2019-01-01T12:00:00', + end_of_service_time: '2019-01-01T12:00:00.000Z', hidden: true, hide_lite_metering: true, no_upgrade_next_step: true, @@ -532,7 +541,7 @@ describe('GlobalCatalogV1', () => { const account = 'testString'; const include = 'testString'; const languages = 'testString'; - const complete = 'testString'; + const complete = true; const depth = 38; const params = { id: id, @@ -749,7 +758,7 @@ describe('GlobalCatalogV1', () => { primary_offering_id: 'testString', accessible_during_provision: true, side_by_side_index: 38, - end_of_service_time: '2019-01-01T12:00:00', + end_of_service_time: '2019-01-01T12:00:00.000Z', hidden: true, hide_lite_metering: true, no_upgrade_next_step: true, @@ -1054,7 +1063,9 @@ describe('GlobalCatalogV1', () => { const sortBy = 'testString'; const descending = 'testString'; const languages = 'testString'; - const complete = 'testString'; + const complete = true; + const offset = 38; + const limit = 200; const params = { id: id, kind: kind, @@ -1065,6 +1076,8 @@ describe('GlobalCatalogV1', () => { descending: descending, languages: languages, complete: complete, + offset: offset, + limit: limit, }; const getChildObjectsResult = globalCatalogService.getChildObjects(params); @@ -1088,6 +1101,8 @@ describe('GlobalCatalogV1', () => { expect(options.qs['descending']).toEqual(descending); expect(options.qs['languages']).toEqual(languages); expect(options.qs['complete']).toEqual(complete); + expect(options.qs['_offset']).toEqual(offset); + expect(options.qs['_limit']).toEqual(limit); expect(options.path['id']).toEqual(id); expect(options.path['kind']).toEqual(kind); });