Skip to content

Commit

Permalink
Add general swagger/openApi SDK (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
easingthemes committed Mar 2, 2020
1 parent b9c4504 commit 443f9a9
Show file tree
Hide file tree
Showing 23 changed files with 18,652 additions and 201 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
dist/
src/methods4docs.js
1,092 changes: 1,043 additions & 49 deletions README.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions docs/readme_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const sdk = require('@adobe/aio-lib-customer-profile')

async function sdkTest() {
//initialize sdk
const client = await sdk.init('<tenant>', 'x-api-key', '<valid auth token>')
const client = await sdk.init('<tenant>', '<iMSOrgId>', 'x-api-key', '<valid auth token>', '[sandbox]')
}
```

Expand All @@ -43,12 +43,14 @@ const sdk = require('@adobe/aio-lib-customer-profile')

async function sdkTest() {
// initialize sdk
const client = await sdk.init('<tenant>', 'x-api-key', '<valid auth token>')
const client = await sdk.init('<tenant>', '<iMSOrgId>', 'x-api-key', '<valid auth token>', '[sandbox]')

// call methods
try {
// get profiles by custom filters
const result = await client.getSomething({})
const result = await client.getSegmentRoute({
segmentId: 'abc123'
})
console.log(result)

} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions e2e/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CUSTOMER_PROFILE_API_TENANT_ID=
CUSTOMER_PROFILE_API_IMS_ORG_ID=
CUSTOMER_PROFILE_API_API_KEY=
CUSTOMER_PROFILE_API_ACCESS_TOKEN=
7 changes: 4 additions & 3 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
## Requirements

To run the e2e test you'll need these env variables set:
1. `CustomerProfileAPI_TENANT_ID`
2. `CustomerProfileAPI_API_KEY`
3. `CustomerProfileAPI_ACCESS_TOKEN`
1. `CUSTOMER_PROFILE_API_TENANT_ID`
3. `CUSTOMER_PROFILE_API_IMS_ORG_ID`
4. `CUSTOMER_PROFILE_API_API_KEY`
5. `CUSTOMER_PROFILE_API_ACCESS_TOKEN`

## Run

Expand Down
32 changes: 21 additions & 11 deletions e2e/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,55 @@ require('dotenv').config({ path: path.join(__dirname, '.env') })

let sdkClient = {}
const tenantId = process.env.CUSTOMER_PROFILE_API_TENANT_ID
const iMSOrgId = process.env.CUSTOMER_PROFILE_API_IMS_ORG_ID
const apiKey = process.env.CUSTOMER_PROFILE_API_API_KEY
const accessToken = process.env.CUSTOMER_PROFILE_ACCESS_TOKEN

beforeAll(async () => {
sdkClient = await sdk.init(tenantId, apiKey, accessToken)
sdkClient = await sdk.init(tenantId, iMSOrgId, apiKey, accessToken)
})

test('sdk init test', async () => {
expect(sdkClient.tenantId).toBe(tenantId)
expect(sdkClient.iMSOrgId).toBe(iMSOrgId)
expect(sdkClient.apiKey).toBe(apiKey)
expect(sdkClient.accessToken).toBe(accessToken)
})

const requiredParam = {
'schema.name': '_xdm.context.profile'
}

test('test bad access token', async () => {
const _sdkClient = await sdk.init(tenantId, apiKey, 'bad_access_token')
const promise = _sdkClient.getSomething()
const _sdkClient = await sdk.init(tenantId, iMSOrgId, apiKey, 'bad_access_token')
const promise = _sdkClient.getAccessEntities(requiredParam)

// just match the error message
return expect(promise).rejects.toThrow('401')
})

test('test bad api key', async () => {
const _sdkClient = await sdk.init(tenantId, 'bad_api_key', accessToken)
const promise = _sdkClient.getSomething()
const _sdkClient = await sdk.init(tenantId, iMSOrgId, 'bad_api_key', accessToken)
const promise = _sdkClient.getAccessEntities(requiredParam)

// just match the error message
return expect(promise).rejects.toThrow('403')
return expect(promise).rejects.toThrow('401')
})

test('test bad tenant id', async () => {
const _sdkClient = await sdk.init('bad_tenant_id', apiKey, accessToken)
const promise = _sdkClient.getSomething()
const _sdkClient = await sdk.init('bad_tenant_id', iMSOrgId, apiKey, accessToken)
const promise = _sdkClient.getAccessEntities(requiredParam)

// just match the error message
return expect(promise).rejects.toThrow('500')
return expect(promise).rejects.toThrow('401')
})

test('test getSomething API', async () => {
test('test getAccessEntities API', async () => {
// check success response
const res = await sdkClient.getSomething({ limit: 5, page: 0 })
const res = await sdkClient.getAccessEntities({
entityId: '1',
'schema.name': '_xdm.context.profile',
entityIdNS: '1'
})
expect(res.ok).toBeTruthy()
})
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"dependencies": {
"@adobe/aio-lib-core-errors": "^3.0.0",
"@adobe/aio-lib-core-logging": "1.1.0",
"cross-fetch": "^3.0.4",
"swagger-client": "^3.9.0"
"change-case": "^4.1.1",
"swagger-client": "^3.9.0",
"uuid": "^7.0.0"
},
"deprecated": false,
"description": "Adobe I/O Lib",
"description": "Adobe I/O Customer Profile Lib",
"devDependencies": {
"@adobe/eslint-config-aio-lib-config": "^1.1.0",
"@types/node-fetch": "^2.5.4",
Expand All @@ -32,8 +33,11 @@
"jest-plugin-fs": "^2.9.0",
"jsdoc": "^3.6.3",
"jsdoc-to-markdown": "^5.0.0",
"node-fetch": "^2.6.0",
"openapi-schema-validator": "^3.0.3",
"stdout-stderr": "^0.1.9",
"swagger-parser": "^8.0.4",
"swagger2openapi": "^5.3.3",
"tsd-jsdoc": "^2.4.0"
},
"homepage": "https://github.com/@adobe/aio-lib-customer-profile",
Expand All @@ -43,13 +47,15 @@
"repository": "https://github.com/@adobe/aio-lib-customer-profile",
"scripts": {
"e2e": "jest --config e2e/jest.config.js",
"generate-docs": "npm run typings && npm run jsdoc",
"generate-docs": "npm run generate-methods4docs && npm run typings && npm run jsdoc",
"jsdoc": "jsdoc2md -t ./docs/readme_template.md src/**/*.js > README.md",
"lint": "eslint src test",
"test": "npm run validate && npm run lint && npm run unit-tests",
"typings": "jsdoc -t node_modules/tsd-jsdoc/dist -r src/*.js -d .",
"unit-tests": "jest --config test/jest.config.js --maxWorkers=2",
"validate": "node bin/validate_spec.js spec/api.json"
"validate": "node bin/validate_spec.js spec/api.json",
"generate-api": "node ./tools/getApiFile.js",
"generate-methods4docs": "node ./tools/apiDocs.js"
},
"version": "0.0.1"
"version": "1.0.0"
}

0 comments on commit 443f9a9

Please sign in to comment.