Skip to content

Implement Organizations module and refactor Portal according to latest API version#17

Merged
LauraBeatris merged 17 commits intomainfrom
feature/sdk-622-update-portal-module-according-to
Dec 21, 2022
Merged

Implement Organizations module and refactor Portal according to latest API version#17
LauraBeatris merged 17 commits intomainfrom
feature/sdk-622-update-portal-module-according-to

Conversation

@LauraBeatris
Copy link
Copy Markdown
Contributor

@LauraBeatris LauraBeatris commented Dec 19, 2022

Implement a module for organizations and remove its related functions from the portal module, making it up to date to the latest API version

Closes #16

@linear
Copy link
Copy Markdown

linear Bot commented Dec 19, 2022

@jacobiajohnson
Copy link
Copy Markdown
Contributor

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@LauraBeatris LauraBeatris force-pushed the feature/sdk-622-update-portal-module-according-to branch from fec8d4b to 5f5b39d Compare December 20, 2022 19:51
@LauraBeatris LauraBeatris force-pushed the feature/sdk-622-update-portal-module-according-to branch from 1ddeeb8 to 60f4b13 Compare December 20, 2022 20:41
@LauraBeatris LauraBeatris marked this pull request as ready for review December 20, 2022 20:43
@LauraBeatris LauraBeatris changed the title Implement organizations module Implement Organizations module and refactor Portal according to latest API version Dec 20, 2022
Comment thread test/workos/organizations/organizations_test.exs
Copy link
Copy Markdown
Contributor

@blairworkos blairworkos left a comment

Choose a reason for hiding this comment

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

Awesome! I left a few questions and comments. Let me know if anything doesn't make sense.

Also, not sure if it's in the scope of this PR or we should create a follow up issue - but error handling is also something lacking here, for example, we specifically handle errors from endpoints in the Ruby SDK: https://github.com/workos/workos-ruby/blob/main/lib/workos/organizations.rb#L169

Comment thread lib/workos/organizations/organizations.ex Outdated
Comment thread lib/workos/organizations/organizations.ex
@doc """
Create an organization

### Parameters
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we also support the idempotency key here, like in the Ruby SDK? https://github.com/workos/workos-ruby/blob/main/lib/workos/organizations.rb#L85

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interesting, what's an idempotency key? I didn't find it in the API reference https://workos.com/docs/reference/organization/create

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Strange, I guess we have a separate section on Idempotency: https://workos.com/docs/reference/idempotency

Little blurb:

The WorkOS API supports idempotency which guarantees that performing the same operation multiple times will have the same result as if the operation were performed only once. This is handy in situations where you may need to retry a request due to a failure or prevent accidental duplicate requests from creating more than one resource.

Very helpful for these create requests, so a duplicate org isn't created. You can take it as an optional parameter, and if present, you can send it as a request header.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can also add this as a follow-up

Copy link
Copy Markdown
Contributor Author

@LauraBeatris LauraBeatris Dec 21, 2022

Choose a reason for hiding this comment

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

I think we can add it here already! I think it actually can be already used since we're passing directly the opts argument do the HTTP request, not limiting headers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment thread lib/workos/portal/portal.ex Outdated
- params (map)
- intent (string) The access scope for the generated Admin Portal
link. Valid values are: ["sso"]
link. Valid values are: ["sso"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We support the following values currently:

["sso", "dsync", "audit_logs", "log_streams"]

Is there a preferred way of checking against an enum value in Elixir? For reference, we validate that the intent matches a supported one in Ruby: https://github.com/workos/workos-ruby/blob/main/lib/workos/portal.rb#L58

Copy link
Copy Markdown
Contributor Author

@LauraBeatris LauraBeatris Dec 20, 2022

Choose a reason for hiding this comment

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

We could use the Enum module to verify if the given intent is supported, eg: Enum.member?(["sso", "dsync", "audit_logs", "log_streams"], "sso")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So I ended up defining a module attribute called @generate_link_intents and then using it as a function guard 25a2af9

CleanShot 2022-12-21 at 11 51 24@2x

 def generate_link(%{intent: intent} = _params, _opts)
      when intent not in @generate_link_intents,
      do:
        raise(ArgumentError,
          message:
            "invalid intent, must be one of the following: sso, dsync, audit_logs or log_streams"
        )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment thread test/workos/organizations/organizations_test.exs
Comment thread lib/workos/organizations/organizations.ex Outdated
Copy link
Copy Markdown
Contributor

@blairworkos blairworkos left a comment

Choose a reason for hiding this comment

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

🎉

@LauraBeatris LauraBeatris merged commit b4ebd03 into main Dec 21, 2022
@LauraBeatris LauraBeatris deleted the feature/sdk-622-update-portal-module-according-to branch December 21, 2022 15:14
@blairworkos blairworkos mentioned this pull request Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Refactor portal module and add a Organizations module according to latest API version

3 participants