Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap Open api generated output into client #6

Merged
merged 15 commits into from
Nov 2, 2021
Merged
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ logs
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

#Asana Client
/openapitools.json
51 changes: 40 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
# asana-sdk

> asana-sdk: revelry and awe are afoot

## Test

```bash
yarn test
# or
yarn test.watch
This was created to have the proper types for the asana api. The official [node-asana](https://github.com/Asana/node-asana) sdk is generated with their open-api spec but doesn't includes types and there seems to be some inconsistencies with @types/asana. Found [an issue](https://github.com/Asana/node-asana/issues/244) that suggested using the [open-api generator](https://github.com/OpenAPITools/openapi-generator-cli) with asana's open-api spec and which is used to generate the /src/lib/asanaClient folder.

All of the generated api classes are added to exported **Asana** class with the below having changes to not have to destrucutre the data key returned from both axios and Asana:

- PortfolioMemberships
- Portfolios
- ProjectMemberships
- Projects
- TeamMemberships
- Teams
- Users

### Install Package

```
yarn add @pliancy/asana-sdk
```

# Test Coverage

```bash
yarn test.cov
# then
yarn cov.view

### PAT Auth

```
import { Asana } from '@pliancy/asana-sdk'

const asana = new Asana({accessToken: '12345'}, 'workspaceGid', 'ownerGid')
```



##### Dev Environment Setup:

The below command will create the generated /src/lib/asanaClient folder

```
yarn dev
```







7 changes: 7 additions & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "5.3.0"
}
}
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
}
},
"dependencies": {
"axios": "0.24.0",
"tslib": "2.3.1"
},
"description": "Wrapper around the Asana node SDK",
"devDependencies": {
"@digitalroute/cz-conventional-changelog-for-jira": "6.6.0",
santese marked this conversation as resolved.
Show resolved Hide resolved
"@openapitools/openapi-generator-cli": "2.4.13",
"@pliancy/eslint-config-ts": "0.0.5",
"@pliancy/semantic-release-config-npm": "2.1.0",
"@types/got": "9.6.12",
santese marked this conversation as resolved.
Show resolved Hide resolved
"@types/jest": "27.0.2",
"@types/jest": "26.0.24",
"@types/node": "16.11.6",
"commitizen": "4.2.4",
"cpy-cli": "3.1.1",
Expand All @@ -38,23 +39,26 @@
"homepage": "https://github.com/pliancy/asana-sdk",
"keywords": [],
"license": "MIT",
"main": "src/index.ts",
santese marked this conversation as resolved.
Show resolved Hide resolved
"main": "index.js",
"name": "@pliancy/asana-sdk",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/pliancy/asana-sdk"
},
"scripts": {
"build": "run-s -l clean test tsc copy",
santese marked this conversation as resolved.
Show resolved Hide resolved
"build": "run-s -l clean openapi:generate test tsc copy",
"build:check": "tsc --noEmit",
"clean": "rimraf coverage dist tmp",
"clean": "rimraf coverage dist tmp src/lib/asanaClient",
"copy": "pinst --disable && cpy package.json dist && cpy README.md dist && pinst --enable",
"dev": "run-s -l clean openapi:generate",
"lint": "eslint \"src/**/*.ts\" --fix",
"postinstall": "husky install",
"qa": "run-s -l lint test clean build:check",
"qa": "run-s -l lint clean openapi:generate test build:check",
"semantic-release": "semantic-release",
"test": "jest",
"tsc": "tsc -p tsconfig.build.json"
"tsc": "tsc -p tsconfig.build.json",
"openapi:generate": "openapi-generator-cli generate -p apiPackage=api -p modelPackage=types -p withSeparateModelsAndApi=true -p modelPropertyNaming=original -p supportsES6=true -i https://raw.githubusercontent.com/Asana/developer-docs/master/defs/asana_oas.yaml -g typescript-axios -o \"src/lib/asanaClient\" --skip-validate-spec"
},
"version": "0.0.0",
"volta": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Asana } from './lib/asana'
export * from './lib/asanaClient/types'
2 changes: 1 addition & 1 deletion src/lib/asana.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Asana } from './asana'

santese marked this conversation as resolved.
Show resolved Hide resolved
describe('Asana', () => {
it('creates an instance', () => {
expect(new Asana()).toBeTruthy()
expect(new Asana({}, 'a', 'a')).toBeTruthy()
})
})
152 changes: 149 additions & 3 deletions src/lib/asana.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,152 @@
import {
AttachmentsApi,
AuditLogAPIApi,
BatchAPIApi,
Configuration,
ConfigurationParameters,
CustomFieldsApi,
CustomFieldSettingsApi,
EventsApi,
GoalsApi,
JobsApi,
OrganizationExportsApi,
ProjectStatusesApi,
SectionsApi,
StoriesApi,
TagsApi,
TasksApi,
TimePeriodsApi,
TypeaheadApi,
UserTaskListsApi,
WebhooksApi,
WorkspaceMembershipsApi,
WorkspacesApi,
} from './asanaClient'
import { PortfolioMemberships } from './portfolioMemberships/portfolioMemberships'
import { Portfolios } from './portfolios/portfolios'
import { ProjectMemberships } from './projectMemberships/projectMemberships'
import { Projects } from './projects/projects'
import { TeamMemberships } from './teamMemberships/teamMemberships'
import { Teams } from './teams/teams'
import { Users } from './users/users'

export class Asana {
constructor() {
// eslint-disable-next-line no-console
console.log('Welcome to the Pliancy Asana SDK!')
readonly attachments: AttachmentsApi

readonly auditLog: AuditLogAPIApi

readonly batch: BatchAPIApi

readonly customFieldSettings: CustomFieldSettingsApi

readonly customFields: CustomFieldsApi

readonly events: EventsApi

readonly goals: GoalsApi

readonly jobs: JobsApi

readonly organizationExports: OrganizationExportsApi

readonly projectStatuse: ProjectStatusesApi

readonly sections: SectionsApi

readonly stories: StoriesApi

readonly tags: TagsApi

readonly tasks: TasksApi

readonly timePeriods: TimePeriodsApi

readonly typeahead: TypeaheadApi

readonly userTaskLists: UserTaskListsApi

readonly webhook: WebhooksApi

readonly workspaceMemberships: WorkspaceMembershipsApi

readonly workspaces: WorkspacesApi

// Updated Classes - Updated / destrcutured to return the data property directly from the Asana Api
readonly portfolios: Portfolios

readonly portfolioMemberships: PortfolioMemberships

readonly projects: Projects

readonly projectMemberships: ProjectMemberships

readonly teams: Teams

readonly teamMemberships: TeamMemberships

readonly users: Users

constructor(
private readonly configuration: ConfigurationParameters,
private readonly workspaceGid: string,
private readonly ownerGid: string,
) {
const config = new Configuration(this.configuration)

this.attachments = new AttachmentsApi(config)

this.auditLog = new AuditLogAPIApi(config)

this.batch = new BatchAPIApi(config)

this.customFieldSettings = new CustomFieldSettingsApi(config)

this.customFields = new CustomFieldsApi(config)

this.events = new EventsApi(config)

this.goals = new GoalsApi(config)

this.jobs = new JobsApi(config)

this.organizationExports = new OrganizationExportsApi(config)

this.projectStatuse = new ProjectStatusesApi(config)

this.sections = new SectionsApi(config)

this.stories = new StoriesApi(config)

this.tags = new TagsApi(config)

this.tasks = new TasksApi(config)

this.timePeriods = new TimePeriodsApi(config)

this.typeahead = new TypeaheadApi(config)

this.userTaskLists = new UserTaskListsApi(config)

this.webhook = new WebhooksApi(config)

this.workspaceMemberships = new WorkspaceMembershipsApi(config)

this.workspaces = new WorkspacesApi(config)

// Updated Classes

this.portfolios = new Portfolios(config, this.workspaceGid, this.ownerGid)

this.portfolioMemberships = new PortfolioMemberships(config, this.workspaceGid)

this.projects = new Projects(config, this.workspaceGid)

this.projectMemberships = new ProjectMemberships(config)

this.teams = new Teams(config, this.workspaceGid)

this.teamMemberships = new TeamMemberships(config, this.workspaceGid)

this.users = new Users(config, this.workspaceGid)
}
}
4 changes: 4 additions & 0 deletions src/lib/asanaClient/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
1 change: 1 addition & 0 deletions src/lib/asanaClient/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
23 changes: 23 additions & 0 deletions src/lib/asanaClient/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Loading