Skip to content

Conversation

@Varomir
Copy link
Contributor

@Varomir Varomir commented Feb 4, 2021

Ticket: ZL-796

Description

This PR changes how the JS-SDK handles API versions, to support easy migration from the legacy API Vapid to the new versioned API Rest. Read more about the Rest versioned API in our: Confluence pages.

An optional version can now be passed from the library client-side or default rest/v1.0 will be applied.

The API version can be specified at the time of the request.

Example Requested URL
procore.get({base: '/me'}) https://app.procore.com/rest/v1.0/me
procore.get({base: '/me', version: 'v1.1'}) https://app.procore.com/rest/v1.1/me
procore.get({base: '/me', version: 'vapid'}) https://app.procore.com/vapid/me

lib/client.ts Outdated
return url;
};

private version = (apiVersion: string = 'v1.0'): string => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to process '' (passed empty string from the client code) as default behaviour (v1.0) or we should throw an error in this case? (as now)

lib/client.ts Outdated

private url = (endpoint: Endpoint): string =>
notNil(endpoint) && (endpoint.constructor === String || endpoint instanceof String) ?
`${this.host}${endpoint}` : // TODO: Do we want to allow this. Version will not be handled for this
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably one of the main questions for code review.

My vision: JS-SDK should not support the endpoint instanceof String login anymore

@Varomir
Copy link
Contributor Author

Varomir commented Apr 6, 2021

LGTM

@bpross
Copy link

bpross commented May 26, 2021

@njbbaer @gilmcquillan updated to send the sdk version in the headers. Let me know what you think about the naming.

},
"author": "Procore Tech <insights@procore.com> (http://procore.com)",
"license": "ISC",
"license": "MIT",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nb: Might actually be Procore Development License, see here, but that's a topic for legal I think

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Taking this PR over, so a bit unsure about this change. @Varomir @gilmcquillan any reason that the license here changed?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the rest of our open source libraries use MIT, I think we should use that here as well.

Ruby SDK, MIT: https://github.com/procore/ruby-sdk/blob/master/LICENSE.txt
Blueprinter, MIT: https://github.com/procore/blueprinter/blob/master/MIT-LICENSE
Sift, MIT: https://github.com/procore/sift/blob/master/MIT-LICENSE

I will open up a discussion with legal around what license we should be using.

@Varomir
Copy link
Contributor Author

Varomir commented Jun 3, 2021

@bross I've got a compilation error after yarn & yarn test

TSError: ⨯ Unable to compile TypeScript:
test/authorize.spec.ts:2:27 - error TS2307: Cannot find module '../dist/index' or its corresponding type declarations.

2 import { authorize } from '../dist/index'
                            ~~~~~~~~~~~~~~~
js-sdk % node --version
v10.22.1
js-sdk % npm --version 
6.14.6

@bpross
Copy link

bpross commented Jun 3, 2021

@bross I've got a compilation error after yarn & yarn test

TSError: ⨯ Unable to compile TypeScript:
test/authorize.spec.ts:2:27 - error TS2307: Cannot find module '../dist/index' or its corresponding type declarations.

2 import { authorize } from '../dist/index'
                            ~~~~~~~~~~~~~~~
js-sdk % node --version
v10.22.1
js-sdk % npm --version 
6.14.6

Thanks for pointing this out @Varomir

After some investigation, this appears to be a side effect of importing package.json to get the SDK version. We have two options here: we can either modify the tests to reference the new location dist/lib/* or create a new file that stores the SDK version and read from that. Will discuss in standup.

… use this directory since we are importing the version from package.json and the path is relative, so the compiled structure changes
@bpross bpross merged commit 9f6a4bb into master Jun 11, 2021
@bpross bpross deleted the ZL-796-update-Procore-JS-SDK-to-Rest branch June 11, 2021 16:23
@gilmcquillan gilmcquillan mentioned this pull request Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.