@greensecurity/javascript-sdk 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/README.md +35 -0
- package/.devcontainer/devcontainer.json +45 -0
- package/FUNCTIONS.md +109 -0
- package/REACT_QUERY.md +318 -0
- package/README.md +561 -0
- package/RUNTIMES.md +48 -0
- package/core.d.ts +10 -0
- package/core.d.ts.map +1 -0
- package/core.js +17 -0
- package/core.js.map +1 -0
- package/docs/sdks/greensecurity/README.md +14 -0
- package/docs/sdks/organizations/README.md +252 -0
- package/docs/sdks/user/README.md +348 -0
- package/docs/sdks/vendors/README.md +219 -0
- package/funcs/organizationsGetFacility.d.ts +17 -0
- package/funcs/organizationsGetFacility.d.ts.map +1 -0
- package/funcs/organizationsGetFacility.js +117 -0
- package/funcs/organizationsGetFacility.js.map +1 -0
- package/funcs/organizationsListOrSearchFacilities.d.ts +28 -0
- package/funcs/organizationsListOrSearchFacilities.d.ts.map +1 -0
- package/funcs/organizationsListOrSearchFacilities.js +131 -0
- package/funcs/organizationsListOrSearchFacilities.js.map +1 -0
- package/funcs/userGetCurrentUser.d.ts +16 -0
- package/funcs/userGetCurrentUser.d.ts.map +1 -0
- package/funcs/userGetCurrentUser.js +101 -0
- package/funcs/userGetCurrentUser.js.map +1 -0
- package/funcs/userGetUserById.d.ts +17 -0
- package/funcs/userGetUserById.d.ts.map +1 -0
- package/funcs/userGetUserById.js +117 -0
- package/funcs/userGetUserById.js.map +1 -0
- package/funcs/userLogsUserIntoTheSystem.d.ts +46 -0
- package/funcs/userLogsUserIntoTheSystem.d.ts.map +1 -0
- package/funcs/userLogsUserIntoTheSystem.js +137 -0
- package/funcs/userLogsUserIntoTheSystem.js.map +1 -0
- package/funcs/vendorsCreateVendorRegistration.d.ts +16 -0
- package/funcs/vendorsCreateVendorRegistration.d.ts.map +1 -0
- package/funcs/vendorsCreateVendorRegistration.js +107 -0
- package/funcs/vendorsCreateVendorRegistration.js.map +1 -0
- package/funcs/vendorsListVendorJobTitles.d.ts +16 -0
- package/funcs/vendorsListVendorJobTitles.d.ts.map +1 -0
- package/funcs/vendorsListVendorJobTitles.js +114 -0
- package/funcs/vendorsListVendorJobTitles.js.map +1 -0
- package/hooks/hooks.d.ts +24 -0
- package/hooks/hooks.d.ts.map +1 -0
- package/hooks/hooks.js +86 -0
- package/hooks/hooks.js.map +1 -0
- package/hooks/index.d.ts +3 -0
- package/hooks/index.d.ts.map +1 -0
- package/hooks/index.js +22 -0
- package/hooks/index.js.map +1 -0
- package/hooks/registration.d.ts +3 -0
- package/hooks/registration.d.ts.map +1 -0
- package/hooks/registration.js +15 -0
- package/hooks/registration.js.map +1 -0
- package/hooks/types.d.ts +78 -0
- package/hooks/types.d.ts.map +1 -0
- package/hooks/types.js +6 -0
- package/hooks/types.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +46 -0
- package/index.js.map +1 -0
- package/jsr.json +27 -0
- package/lib/base64.d.ts +10 -0
- package/lib/base64.d.ts.map +1 -0
- package/lib/base64.js +71 -0
- package/lib/base64.js.map +1 -0
- package/lib/config.d.ts +38 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +46 -0
- package/lib/config.js.map +1 -0
- package/lib/dlv.d.ts +14 -0
- package/lib/dlv.d.ts.map +1 -0
- package/lib/dlv.js +49 -0
- package/lib/dlv.js.map +1 -0
- package/lib/encodings.d.ts +52 -0
- package/lib/encodings.d.ts.map +1 -0
- package/lib/encodings.js +368 -0
- package/lib/encodings.js.map +1 -0
- package/lib/env.d.ts +16 -0
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js +66 -0
- package/lib/env.js.map +1 -0
- package/lib/files.d.ts +8 -0
- package/lib/files.d.ts.map +1 -0
- package/lib/files.js +36 -0
- package/lib/files.js.map +1 -0
- package/lib/http.d.ts +67 -0
- package/lib/http.d.ts.map +1 -0
- package/lib/http.js +217 -0
- package/lib/http.js.map +1 -0
- package/lib/is-plain-object.d.ts +2 -0
- package/lib/is-plain-object.d.ts.map +1 -0
- package/lib/is-plain-object.js +41 -0
- package/lib/is-plain-object.js.map +1 -0
- package/lib/logger.d.ts +6 -0
- package/lib/logger.d.ts.map +1 -0
- package/lib/logger.js +6 -0
- package/lib/logger.js.map +1 -0
- package/lib/matchers.d.ts +64 -0
- package/lib/matchers.d.ts.map +1 -0
- package/lib/matchers.js +204 -0
- package/lib/matchers.js.map +1 -0
- package/lib/primitives.d.ts +23 -0
- package/lib/primitives.d.ts.map +1 -0
- package/lib/primitives.js +104 -0
- package/lib/primitives.js.map +1 -0
- package/lib/retries.d.ts +38 -0
- package/lib/retries.d.ts.map +1 -0
- package/lib/retries.js +153 -0
- package/lib/retries.js.map +1 -0
- package/lib/schemas.d.ts +19 -0
- package/lib/schemas.d.ts.map +1 -0
- package/lib/schemas.js +62 -0
- package/lib/schemas.js.map +1 -0
- package/lib/sdks.d.ts +60 -0
- package/lib/sdks.d.ts.map +1 -0
- package/lib/sdks.js +280 -0
- package/lib/sdks.js.map +1 -0
- package/lib/security.d.ts +82 -0
- package/lib/security.d.ts.map +1 -0
- package/lib/security.js +145 -0
- package/lib/security.js.map +1 -0
- package/lib/url.d.ts +5 -0
- package/lib/url.d.ts.map +1 -0
- package/lib/url.js +25 -0
- package/lib/url.js.map +1 -0
- package/models/components/contact.d.ts +135 -0
- package/models/components/contact.d.ts.map +1 -0
- package/models/components/contact.js +172 -0
- package/models/components/contact.js.map +1 -0
- package/models/components/departmentsummary.d.ts +34 -0
- package/models/components/departmentsummary.d.ts.map +1 -0
- package/models/components/departmentsummary.js +71 -0
- package/models/components/departmentsummary.js.map +1 -0
- package/models/components/desc.d.ts +25 -0
- package/models/components/desc.d.ts.map +1 -0
- package/models/components/desc.js +66 -0
- package/models/components/desc.js.map +1 -0
- package/models/components/expand.d.ts +79 -0
- package/models/components/expand.d.ts.map +1 -0
- package/models/components/expand.js +79 -0
- package/models/components/expand.js.map +1 -0
- package/models/components/facility.d.ts +544 -0
- package/models/components/facility.d.ts.map +1 -0
- package/models/components/facility.js +797 -0
- package/models/components/facility.js.map +1 -0
- package/models/components/facilitysummary.d.ts +34 -0
- package/models/components/facilitysummary.d.ts.map +1 -0
- package/models/components/facilitysummary.js +71 -0
- package/models/components/facilitysummary.js.map +1 -0
- package/models/components/imageset.d.ts +38 -0
- package/models/components/imageset.d.ts.map +1 -0
- package/models/components/imageset.js +75 -0
- package/models/components/imageset.js.map +1 -0
- package/models/components/index.d.ts +20 -0
- package/models/components/index.d.ts.map +1 -0
- package/models/components/index.js +39 -0
- package/models/components/index.js.map +1 -0
- package/models/components/loginemailandpassword.d.ts +45 -0
- package/models/components/loginemailandpassword.d.ts.map +1 -0
- package/models/components/loginemailandpassword.js +82 -0
- package/models/components/loginemailandpassword.js.map +1 -0
- package/models/components/loginrequirementsfromemail.d.ts +40 -0
- package/models/components/loginrequirementsfromemail.d.ts.map +1 -0
- package/models/components/loginrequirementsfromemail.js +80 -0
- package/models/components/loginrequirementsfromemail.js.map +1 -0
- package/models/components/mfarequiredresponse.d.ts +98 -0
- package/models/components/mfarequiredresponse.d.ts.map +1 -0
- package/models/components/mfarequiredresponse.js +126 -0
- package/models/components/mfarequiredresponse.js.map +1 -0
- package/models/components/pager.d.ts +69 -0
- package/models/components/pager.d.ts.map +1 -0
- package/models/components/pager.js +97 -0
- package/models/components/pager.js.map +1 -0
- package/models/components/passwordrequiredresponse.d.ts +62 -0
- package/models/components/passwordrequiredresponse.d.ts.map +1 -0
- package/models/components/passwordrequiredresponse.js +92 -0
- package/models/components/passwordrequiredresponse.js.map +1 -0
- package/models/components/samlloginrequiredresponse.d.ts +73 -0
- package/models/components/samlloginrequiredresponse.d.ts.map +1 -0
- package/models/components/samlloginrequiredresponse.js +106 -0
- package/models/components/samlloginrequiredresponse.js.map +1 -0
- package/models/components/security.d.ts +31 -0
- package/models/components/security.d.ts.map +1 -0
- package/models/components/security.js +80 -0
- package/models/components/security.js.map +1 -0
- package/models/components/status.d.ts +37 -0
- package/models/components/status.d.ts.map +1 -0
- package/models/components/status.js +65 -0
- package/models/components/status.js.map +1 -0
- package/models/components/systemsummary.d.ts +34 -0
- package/models/components/systemsummary.d.ts.map +1 -0
- package/models/components/systemsummary.js +71 -0
- package/models/components/systemsummary.js.map +1 -0
- package/models/components/user.d.ts +265 -0
- package/models/components/user.d.ts.map +1 -0
- package/models/components/user.js +284 -0
- package/models/components/user.js.map +1 -0
- package/models/components/vendorjobtitle.d.ts +41 -0
- package/models/components/vendorjobtitle.d.ts.map +1 -0
- package/models/components/vendorjobtitle.js +71 -0
- package/models/components/vendorjobtitle.js.map +1 -0
- package/models/components/vendortype.d.ts +69 -0
- package/models/components/vendortype.d.ts.map +1 -0
- package/models/components/vendortype.js +135 -0
- package/models/components/vendortype.js.map +1 -0
- package/models/errors/apierror.d.ts +8 -0
- package/models/errors/apierror.d.ts.map +1 -0
- package/models/errors/apierror.js +21 -0
- package/models/errors/apierror.js.map +1 -0
- package/models/errors/apierrorresponse.d.ts +51 -0
- package/models/errors/apierrorresponse.d.ts.map +1 -0
- package/models/errors/apierrorresponse.js +91 -0
- package/models/errors/apierrorresponse.js.map +1 -0
- package/models/errors/httpclienterrors.d.ts +44 -0
- package/models/errors/httpclienterrors.d.ts.map +1 -0
- package/models/errors/httpclienterrors.js +78 -0
- package/models/errors/httpclienterrors.js.map +1 -0
- package/models/errors/index.d.ts +5 -0
- package/models/errors/index.d.ts.map +1 -0
- package/models/errors/index.js +24 -0
- package/models/errors/index.js.map +1 -0
- package/models/errors/sdkvalidationerror.d.ts +20 -0
- package/models/errors/sdkvalidationerror.d.ts.map +1 -0
- package/models/errors/sdkvalidationerror.js +115 -0
- package/models/errors/sdkvalidationerror.js.map +1 -0
- package/models/operations/createvendorregistration.d.ts +115 -0
- package/models/operations/createvendorregistration.d.ts.map +1 -0
- package/models/operations/createvendorregistration.js +143 -0
- package/models/operations/createvendorregistration.js.map +1 -0
- package/models/operations/getfacility.d.ts +32 -0
- package/models/operations/getfacility.d.ts.map +1 -0
- package/models/operations/getfacility.js +69 -0
- package/models/operations/getfacility.js.map +1 -0
- package/models/operations/getuserbyid.d.ts +32 -0
- package/models/operations/getuserbyid.d.ts.map +1 -0
- package/models/operations/getuserbyid.js +69 -0
- package/models/operations/getuserbyid.js.map +1 -0
- package/models/operations/index.d.ts +7 -0
- package/models/operations/index.d.ts.map +1 -0
- package/models/operations/index.js +26 -0
- package/models/operations/index.js.map +1 -0
- package/models/operations/listorsearchfacilities.d.ts +110 -0
- package/models/operations/listorsearchfacilities.d.ts.map +1 -0
- package/models/operations/listorsearchfacilities.js +130 -0
- package/models/operations/listorsearchfacilities.js.map +1 -0
- package/models/operations/listvendorjobtitles.d.ts +86 -0
- package/models/operations/listvendorjobtitles.d.ts.map +1 -0
- package/models/operations/listvendorjobtitles.js +118 -0
- package/models/operations/listvendorjobtitles.js.map +1 -0
- package/models/operations/logsuserintothesystem.d.ts +98 -0
- package/models/operations/logsuserintothesystem.d.ts.map +1 -0
- package/models/operations/logsuserintothesystem.js +164 -0
- package/models/operations/logsuserintothesystem.js.map +1 -0
- package/package.json +41 -0
- package/react-query/_context.d.ts +8 -0
- package/react-query/_context.d.ts.map +1 -0
- package/react-query/_context.js +21 -0
- package/react-query/_context.js.map +1 -0
- package/react-query/_types.d.ts +14 -0
- package/react-query/_types.d.ts.map +1 -0
- package/react-query/_types.js +6 -0
- package/react-query/_types.js.map +1 -0
- package/react-query/index.d.ts +10 -0
- package/react-query/index.d.ts.map +1 -0
- package/react-query/index.js +32 -0
- package/react-query/index.js.map +1 -0
- package/react-query/organizationsGetFacility.d.ts +31 -0
- package/react-query/organizationsGetFacility.d.ts.map +1 -0
- package/react-query/organizationsGetFacility.js +87 -0
- package/react-query/organizationsGetFacility.js.map +1 -0
- package/react-query/organizationsListOrSearchFacilities.d.ts +91 -0
- package/react-query/organizationsListOrSearchFacilities.d.ts.map +1 -0
- package/react-query/organizationsListOrSearchFacilities.js +132 -0
- package/react-query/organizationsListOrSearchFacilities.js.map +1 -0
- package/react-query/userGetCurrentUser.d.ts +29 -0
- package/react-query/userGetCurrentUser.d.ts.map +1 -0
- package/react-query/userGetCurrentUser.js +75 -0
- package/react-query/userGetCurrentUser.js.map +1 -0
- package/react-query/userGetUserById.d.ts +31 -0
- package/react-query/userGetUserById.d.ts.map +1 -0
- package/react-query/userGetUserById.js +87 -0
- package/react-query/userGetUserById.js.map +1 -0
- package/react-query/userLogsUserIntoTheSystem.d.ts +53 -0
- package/react-query/userLogsUserIntoTheSystem.d.ts.map +1 -0
- package/react-query/userLogsUserIntoTheSystem.js +77 -0
- package/react-query/userLogsUserIntoTheSystem.js.map +1 -0
- package/react-query/vendorsCreateVendorRegistration.d.ts +23 -0
- package/react-query/vendorsCreateVendorRegistration.d.ts.map +1 -0
- package/react-query/vendorsCreateVendorRegistration.js +51 -0
- package/react-query/vendorsCreateVendorRegistration.js.map +1 -0
- package/react-query/vendorsListVendorJobTitles.d.ts +53 -0
- package/react-query/vendorsListVendorJobTitles.d.ts.map +1 -0
- package/react-query/vendorsListVendorJobTitles.js +102 -0
- package/react-query/vendorsListVendorJobTitles.js.map +1 -0
- package/sdk/index.d.ts +2 -0
- package/sdk/index.d.ts.map +1 -0
- package/sdk/index.js +21 -0
- package/sdk/index.js.map +1 -0
- package/sdk/organizations.d.ts +33 -0
- package/sdk/organizations.d.ts.map +1 -0
- package/sdk/organizations.js +45 -0
- package/sdk/organizations.js.map +1 -0
- package/sdk/sdk.d.ts +13 -0
- package/sdk/sdk.d.ts.map +1 -0
- package/sdk/sdk.js +23 -0
- package/sdk/sdk.js.map +1 -0
- package/sdk/user.d.ts +57 -0
- package/sdk/user.d.ts.map +1 -0
- package/sdk/user.js +72 -0
- package/sdk/user.js.map +1 -0
- package/sdk/vendors.d.ts +19 -0
- package/sdk/vendors.d.ts.map +1 -0
- package/sdk/vendors.js +32 -0
- package/sdk/vendors.js.map +1 -0
- package/src/core.ts +13 -0
- package/src/funcs/organizationsGetFacility.ts +144 -0
- package/src/funcs/organizationsListOrSearchFacilities.ts +152 -0
- package/src/funcs/userGetCurrentUser.ts +118 -0
- package/src/funcs/userGetUserById.ts +141 -0
- package/src/funcs/userLogsUserIntoTheSystem.ts +161 -0
- package/src/funcs/vendorsCreateVendorRegistration.ts +132 -0
- package/src/funcs/vendorsListVendorJobTitles.ts +141 -0
- package/src/hooks/hooks.ts +132 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/registration.ts +14 -0
- package/src/hooks/types.ts +110 -0
- package/src/index.ts +7 -0
- package/src/lib/base64.ts +37 -0
- package/src/lib/config.ts +76 -0
- package/src/lib/dlv.ts +53 -0
- package/src/lib/encodings.ts +483 -0
- package/src/lib/env.ts +43 -0
- package/src/lib/files.ts +40 -0
- package/src/lib/http.ts +323 -0
- package/src/lib/is-plain-object.ts +43 -0
- package/src/lib/logger.ts +9 -0
- package/src/lib/matchers.ts +322 -0
- package/src/lib/primitives.ts +136 -0
- package/src/lib/retries.ts +218 -0
- package/src/lib/schemas.ts +91 -0
- package/src/lib/sdks.ts +400 -0
- package/src/lib/security.ts +260 -0
- package/src/lib/url.ts +33 -0
- package/src/models/components/contact.ts +268 -0
- package/src/models/components/departmentsummary.ts +73 -0
- package/src/models/components/desc.ts +48 -0
- package/src/models/components/expand.ts +52 -0
- package/src/models/components/facility.ts +1334 -0
- package/src/models/components/facilitysummary.ts +71 -0
- package/src/models/components/imageset.ts +77 -0
- package/src/models/components/index.ts +23 -0
- package/src/models/components/loginemailandpassword.ts +95 -0
- package/src/models/components/loginrequirementsfromemail.ts +88 -0
- package/src/models/components/mfarequiredresponse.ts +160 -0
- package/src/models/components/pager.ts +126 -0
- package/src/models/components/passwordrequiredresponse.ts +105 -0
- package/src/models/components/samlloginrequiredresponse.ts +136 -0
- package/src/models/components/security.ts +75 -0
- package/src/models/components/status.ts +38 -0
- package/src/models/components/systemsummary.ts +69 -0
- package/src/models/components/user.ts +451 -0
- package/src/models/components/vendorjobtitle.ts +76 -0
- package/src/models/components/vendortype.ts +170 -0
- package/src/models/errors/apierror.ts +27 -0
- package/src/models/errors/apierrorresponse.ts +95 -0
- package/src/models/errors/httpclienterrors.ts +62 -0
- package/src/models/errors/index.ts +8 -0
- package/src/models/errors/sdkvalidationerror.ts +97 -0
- package/src/models/operations/createvendorregistration.ts +237 -0
- package/src/models/operations/getfacility.ts +69 -0
- package/src/models/operations/getuserbyid.ts +69 -0
- package/src/models/operations/index.ts +10 -0
- package/src/models/operations/listorsearchfacilities.ts +219 -0
- package/src/models/operations/listvendorjobtitles.ts +179 -0
- package/src/models/operations/logsuserintothesystem.ts +270 -0
- package/src/react-query/_types.ts +91 -0
- package/src/react-query/index.ts +14 -0
- package/src/react-query/organizationsGetFacility.ts +154 -0
- package/src/react-query/organizationsListOrSearchFacilities.ts +241 -0
- package/src/react-query/userGetCurrentUser.ts +124 -0
- package/src/react-query/userGetUserById.ts +152 -0
- package/src/react-query/userLogsUserIntoTheSystem.ts +119 -0
- package/src/react-query/vendorsCreateVendorRegistration.ts +93 -0
- package/src/react-query/vendorsListVendorJobTitles.ts +194 -0
- package/src/sdk/index.ts +5 -0
- package/src/sdk/organizations.ts +59 -0
- package/src/sdk/sdk.ts +25 -0
- package/src/sdk/user.ts +92 -0
- package/src/sdk/vendors.ts +45 -0
- package/src/types/blobs.ts +31 -0
- package/src/types/constdatetime.ts +15 -0
- package/src/types/enums.ts +16 -0
- package/src/types/fp.ts +50 -0
- package/src/types/index.ts +11 -0
- package/src/types/operations.ts +105 -0
- package/src/types/rfcdate.ts +54 -0
- package/src/types/streams.ts +21 -0
- package/tsconfig.json +41 -0
- package/types/blobs.d.ts +4 -0
- package/types/blobs.d.ts.map +1 -0
- package/types/blobs.js +62 -0
- package/types/blobs.js.map +1 -0
- package/types/constdatetime.d.ts +3 -0
- package/types/constdatetime.d.ts.map +1 -0
- package/types/constdatetime.js +46 -0
- package/types/constdatetime.js.map +1 -0
- package/types/enums.d.ts +12 -0
- package/types/enums.d.ts.map +1 -0
- package/types/enums.js +10 -0
- package/types/enums.js.map +1 -0
- package/types/fp.d.ts +31 -0
- package/types/fp.d.ts.map +1 -0
- package/types/fp.js +37 -0
- package/types/fp.js.map +1 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -0
- package/types/index.js +16 -0
- package/types/index.js.map +1 -0
- package/types/operations.d.ts +27 -0
- package/types/operations.d.ts.map +1 -0
- package/types/operations.js +83 -0
- package/types/operations.js.map +1 -0
- package/types/rfcdate.d.ts +21 -0
- package/types/rfcdate.d.ts.map +1 -0
- package/types/rfcdate.js +46 -0
- package/types/rfcdate.js.map +1 -0
- package/types/streams.d.ts +2 -0
- package/types/streams.d.ts.map +1 -0
- package/types/streams.js +18 -0
- package/types/streams.js.map +1 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { GreenSecurityCore } from "../core.js";
|
|
6
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
7
|
+
import * as M from "../lib/matchers.js";
|
|
8
|
+
import { compactMap } from "../lib/primitives.js";
|
|
9
|
+
import { safeParse } from "../lib/schemas.js";
|
|
10
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
11
|
+
import { pathToFunc } from "../lib/url.js";
|
|
12
|
+
import { APIError } from "../models/errors/apierror.js";
|
|
13
|
+
import {
|
|
14
|
+
ConnectionError,
|
|
15
|
+
InvalidRequestError,
|
|
16
|
+
RequestAbortedError,
|
|
17
|
+
RequestTimeoutError,
|
|
18
|
+
UnexpectedClientError,
|
|
19
|
+
} from "../models/errors/httpclienterrors.js";
|
|
20
|
+
import * as errors from "../models/errors/index.js";
|
|
21
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
22
|
+
import * as operations from "../models/operations/index.js";
|
|
23
|
+
import { Result } from "../types/fp.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Logs user into the system
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This endpoint allows a user to authenticate themselves and retrieve a permanent token for access.
|
|
30
|
+
*
|
|
31
|
+
* Permanent tokens should only ever be stored in an encrypted storage because they represent a fully logged in user.
|
|
32
|
+
*
|
|
33
|
+
* Users may log in with `email/password`, `SAML`, `magic link` or `mfa`. The application should handle all of the above as equally valid login methods.
|
|
34
|
+
*
|
|
35
|
+
* The most common way to authenticate a user is to log in with an email and password. If the user provides valid credentials, the server will either respond with a full user object including the token.
|
|
36
|
+
*
|
|
37
|
+
* When the user's account is protected via MFA, the server will send a 6 digit code to the user via their default MFA provider. You should collect that code and resend the email, password and mfa_code together to get a successful authentication.
|
|
38
|
+
*
|
|
39
|
+
* The ideal flow for a login sequence is the following:
|
|
40
|
+
*
|
|
41
|
+
* 1. Present an email address field only and allow the user to submit
|
|
42
|
+
* 2. Send `email` and `return_url` payload to this endpoint
|
|
43
|
+
* 3. Follow the flow based on the response `requires` field
|
|
44
|
+
*
|
|
45
|
+
* Requires: `password`
|
|
46
|
+
*
|
|
47
|
+
* 1. Show a password field for the user to fill out
|
|
48
|
+
* 2. Submit the `email` and `password` to this endpoint
|
|
49
|
+
* 3. If the response is `200`, the login is done. If the response is `201`, then check if `requires: mfa_code` is returned and show MFA flow
|
|
50
|
+
* 4. Submit `email`, `password`, `mfa_code` to this endpoint
|
|
51
|
+
* 5. If the response is `200`, the login is done. Otherwise, show the appropriate error to the user and go back to step 1 or 3 depending on the error.
|
|
52
|
+
*
|
|
53
|
+
* Requires: `saml_login`
|
|
54
|
+
*
|
|
55
|
+
* 1. [Open a browser](https://docs.expo.dev/versions/latest/sdk/webbrowser/#webbrowseropenauthsessionasyncurl-redirecturl-options) to the url returned in `sso_url`
|
|
56
|
+
* 2. User completes sign-in using their configured SAML IdP
|
|
57
|
+
* 3. Site redirects to your selected `return_url`
|
|
58
|
+
* 4. The `user_token` will be appended as a query string parameter to your `return_url` - you must parse this token and store it
|
|
59
|
+
* 5. Fetch the user object from `/users/me` using the token
|
|
60
|
+
*/
|
|
61
|
+
export async function userLogsUserIntoTheSystem(
|
|
62
|
+
client: GreenSecurityCore,
|
|
63
|
+
request: operations.LogsUserIntoTheSystemRequestBody,
|
|
64
|
+
options?: RequestOptions,
|
|
65
|
+
): Promise<
|
|
66
|
+
Result<
|
|
67
|
+
operations.LogsUserIntoTheSystemResponse,
|
|
68
|
+
| errors.ApiErrorResponse
|
|
69
|
+
| APIError
|
|
70
|
+
| SDKValidationError
|
|
71
|
+
| UnexpectedClientError
|
|
72
|
+
| InvalidRequestError
|
|
73
|
+
| RequestAbortedError
|
|
74
|
+
| RequestTimeoutError
|
|
75
|
+
| ConnectionError
|
|
76
|
+
>
|
|
77
|
+
> {
|
|
78
|
+
const parsed = safeParse(
|
|
79
|
+
request,
|
|
80
|
+
(value) =>
|
|
81
|
+
operations.LogsUserIntoTheSystemRequestBody$outboundSchema.parse(value),
|
|
82
|
+
"Input validation failed",
|
|
83
|
+
);
|
|
84
|
+
if (!parsed.ok) {
|
|
85
|
+
return parsed;
|
|
86
|
+
}
|
|
87
|
+
const payload = parsed.value;
|
|
88
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
89
|
+
|
|
90
|
+
const path = pathToFunc("/users/authenticate")();
|
|
91
|
+
|
|
92
|
+
const headers = new Headers(compactMap({
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
Accept: "application/json",
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
const context = {
|
|
98
|
+
baseURL: options?.serverURL ?? "",
|
|
99
|
+
operationID: "logsUserIntoTheSystem",
|
|
100
|
+
oAuth2Scopes: [],
|
|
101
|
+
|
|
102
|
+
resolvedSecurity: null,
|
|
103
|
+
|
|
104
|
+
securitySource: null,
|
|
105
|
+
retryConfig: options?.retries
|
|
106
|
+
|| client._options.retryConfig
|
|
107
|
+
|| { strategy: "none" },
|
|
108
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const requestRes = client._createRequest(context, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
baseURL: options?.serverURL,
|
|
114
|
+
path: path,
|
|
115
|
+
headers: headers,
|
|
116
|
+
body: body,
|
|
117
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
118
|
+
}, options);
|
|
119
|
+
if (!requestRes.ok) {
|
|
120
|
+
return requestRes;
|
|
121
|
+
}
|
|
122
|
+
const req = requestRes.value;
|
|
123
|
+
|
|
124
|
+
const doResult = await client._do(req, {
|
|
125
|
+
context,
|
|
126
|
+
errorCodes: ["400", "401", "404", "4XX", "5XX"],
|
|
127
|
+
retryConfig: context.retryConfig,
|
|
128
|
+
retryCodes: context.retryCodes,
|
|
129
|
+
});
|
|
130
|
+
if (!doResult.ok) {
|
|
131
|
+
return doResult;
|
|
132
|
+
}
|
|
133
|
+
const response = doResult.value;
|
|
134
|
+
|
|
135
|
+
const responseFields = {
|
|
136
|
+
HttpMeta: { Response: response, Request: req },
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const [result] = await M.match<
|
|
140
|
+
operations.LogsUserIntoTheSystemResponse,
|
|
141
|
+
| errors.ApiErrorResponse
|
|
142
|
+
| APIError
|
|
143
|
+
| SDKValidationError
|
|
144
|
+
| UnexpectedClientError
|
|
145
|
+
| InvalidRequestError
|
|
146
|
+
| RequestAbortedError
|
|
147
|
+
| RequestTimeoutError
|
|
148
|
+
| ConnectionError
|
|
149
|
+
>(
|
|
150
|
+
M.json(200, operations.LogsUserIntoTheSystemResponse$inboundSchema),
|
|
151
|
+
M.json(202, operations.LogsUserIntoTheSystemResponse$inboundSchema),
|
|
152
|
+
M.jsonErr([400, 401, 404], errors.ApiErrorResponse$inboundSchema),
|
|
153
|
+
M.fail("4XX"),
|
|
154
|
+
M.fail("5XX"),
|
|
155
|
+
)(response, { extraFields: responseFields });
|
|
156
|
+
if (!result.ok) {
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { GreenSecurityCore } from "../core.js";
|
|
6
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
7
|
+
import * as M from "../lib/matchers.js";
|
|
8
|
+
import { compactMap } from "../lib/primitives.js";
|
|
9
|
+
import { safeParse } from "../lib/schemas.js";
|
|
10
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
11
|
+
import { pathToFunc } from "../lib/url.js";
|
|
12
|
+
import { APIError } from "../models/errors/apierror.js";
|
|
13
|
+
import {
|
|
14
|
+
ConnectionError,
|
|
15
|
+
InvalidRequestError,
|
|
16
|
+
RequestAbortedError,
|
|
17
|
+
RequestTimeoutError,
|
|
18
|
+
UnexpectedClientError,
|
|
19
|
+
} from "../models/errors/httpclienterrors.js";
|
|
20
|
+
import * as errors from "../models/errors/index.js";
|
|
21
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
22
|
+
import * as operations from "../models/operations/index.js";
|
|
23
|
+
import { Result } from "../types/fp.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create vendor registration
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* Create an initial vendor registration. Once successful, the vendor will be able to continue to filling out the rest of their onboarding profile.
|
|
30
|
+
*/
|
|
31
|
+
export async function vendorsCreateVendorRegistration(
|
|
32
|
+
client: GreenSecurityCore,
|
|
33
|
+
request: operations.CreateVendorRegistrationRequestBody,
|
|
34
|
+
options?: RequestOptions,
|
|
35
|
+
): Promise<
|
|
36
|
+
Result<
|
|
37
|
+
operations.CreateVendorRegistrationResponseBody,
|
|
38
|
+
| errors.ApiErrorResponse
|
|
39
|
+
| APIError
|
|
40
|
+
| SDKValidationError
|
|
41
|
+
| UnexpectedClientError
|
|
42
|
+
| InvalidRequestError
|
|
43
|
+
| RequestAbortedError
|
|
44
|
+
| RequestTimeoutError
|
|
45
|
+
| ConnectionError
|
|
46
|
+
>
|
|
47
|
+
> {
|
|
48
|
+
const parsed = safeParse(
|
|
49
|
+
request,
|
|
50
|
+
(value) =>
|
|
51
|
+
operations.CreateVendorRegistrationRequestBody$outboundSchema.parse(
|
|
52
|
+
value,
|
|
53
|
+
),
|
|
54
|
+
"Input validation failed",
|
|
55
|
+
);
|
|
56
|
+
if (!parsed.ok) {
|
|
57
|
+
return parsed;
|
|
58
|
+
}
|
|
59
|
+
const payload = parsed.value;
|
|
60
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
61
|
+
|
|
62
|
+
const path = pathToFunc("/vendors/registration")();
|
|
63
|
+
|
|
64
|
+
const headers = new Headers(compactMap({
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
Accept: "application/json",
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
const context = {
|
|
70
|
+
baseURL: options?.serverURL ?? "",
|
|
71
|
+
operationID: "createVendorRegistration",
|
|
72
|
+
oAuth2Scopes: [],
|
|
73
|
+
|
|
74
|
+
resolvedSecurity: null,
|
|
75
|
+
|
|
76
|
+
securitySource: null,
|
|
77
|
+
retryConfig: options?.retries
|
|
78
|
+
|| client._options.retryConfig
|
|
79
|
+
|| { strategy: "none" },
|
|
80
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const requestRes = client._createRequest(context, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
baseURL: options?.serverURL,
|
|
86
|
+
path: path,
|
|
87
|
+
headers: headers,
|
|
88
|
+
body: body,
|
|
89
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
90
|
+
}, options);
|
|
91
|
+
if (!requestRes.ok) {
|
|
92
|
+
return requestRes;
|
|
93
|
+
}
|
|
94
|
+
const req = requestRes.value;
|
|
95
|
+
|
|
96
|
+
const doResult = await client._do(req, {
|
|
97
|
+
context,
|
|
98
|
+
errorCodes: ["400", "401", "403", "409", "4XX", "5XX"],
|
|
99
|
+
retryConfig: context.retryConfig,
|
|
100
|
+
retryCodes: context.retryCodes,
|
|
101
|
+
});
|
|
102
|
+
if (!doResult.ok) {
|
|
103
|
+
return doResult;
|
|
104
|
+
}
|
|
105
|
+
const response = doResult.value;
|
|
106
|
+
|
|
107
|
+
const responseFields = {
|
|
108
|
+
HttpMeta: { Response: response, Request: req },
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const [result] = await M.match<
|
|
112
|
+
operations.CreateVendorRegistrationResponseBody,
|
|
113
|
+
| errors.ApiErrorResponse
|
|
114
|
+
| APIError
|
|
115
|
+
| SDKValidationError
|
|
116
|
+
| UnexpectedClientError
|
|
117
|
+
| InvalidRequestError
|
|
118
|
+
| RequestAbortedError
|
|
119
|
+
| RequestTimeoutError
|
|
120
|
+
| ConnectionError
|
|
121
|
+
>(
|
|
122
|
+
M.json(201, operations.CreateVendorRegistrationResponseBody$inboundSchema),
|
|
123
|
+
M.jsonErr([400, 401, 403, 409], errors.ApiErrorResponse$inboundSchema),
|
|
124
|
+
M.fail("4XX"),
|
|
125
|
+
M.fail("5XX"),
|
|
126
|
+
)(response, { extraFields: responseFields });
|
|
127
|
+
if (!result.ok) {
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { GreenSecurityCore } from "../core.js";
|
|
6
|
+
import { encodeFormQuery } from "../lib/encodings.js";
|
|
7
|
+
import * as M from "../lib/matchers.js";
|
|
8
|
+
import { compactMap } from "../lib/primitives.js";
|
|
9
|
+
import { safeParse } from "../lib/schemas.js";
|
|
10
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
11
|
+
import { pathToFunc } from "../lib/url.js";
|
|
12
|
+
import { APIError } from "../models/errors/apierror.js";
|
|
13
|
+
import {
|
|
14
|
+
ConnectionError,
|
|
15
|
+
InvalidRequestError,
|
|
16
|
+
RequestAbortedError,
|
|
17
|
+
RequestTimeoutError,
|
|
18
|
+
UnexpectedClientError,
|
|
19
|
+
} from "../models/errors/httpclienterrors.js";
|
|
20
|
+
import * as errors from "../models/errors/index.js";
|
|
21
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
22
|
+
import * as operations from "../models/operations/index.js";
|
|
23
|
+
import { Result } from "../types/fp.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* List vendor job titles
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* List valid job titles for Vendors. This can be used during sign up or in a filter.
|
|
30
|
+
*/
|
|
31
|
+
export async function vendorsListVendorJobTitles(
|
|
32
|
+
client: GreenSecurityCore,
|
|
33
|
+
request: operations.ListVendorJobTitlesRequest,
|
|
34
|
+
options?: RequestOptions,
|
|
35
|
+
): Promise<
|
|
36
|
+
Result<
|
|
37
|
+
operations.ListVendorJobTitlesResponseBody,
|
|
38
|
+
| errors.ApiErrorResponse
|
|
39
|
+
| errors.ApiErrorResponse
|
|
40
|
+
| APIError
|
|
41
|
+
| SDKValidationError
|
|
42
|
+
| UnexpectedClientError
|
|
43
|
+
| InvalidRequestError
|
|
44
|
+
| RequestAbortedError
|
|
45
|
+
| RequestTimeoutError
|
|
46
|
+
| ConnectionError
|
|
47
|
+
>
|
|
48
|
+
> {
|
|
49
|
+
const parsed = safeParse(
|
|
50
|
+
request,
|
|
51
|
+
(value) =>
|
|
52
|
+
operations.ListVendorJobTitlesRequest$outboundSchema.parse(value),
|
|
53
|
+
"Input validation failed",
|
|
54
|
+
);
|
|
55
|
+
if (!parsed.ok) {
|
|
56
|
+
return parsed;
|
|
57
|
+
}
|
|
58
|
+
const payload = parsed.value;
|
|
59
|
+
const body = null;
|
|
60
|
+
|
|
61
|
+
const path = pathToFunc("/vendors/job_titles")();
|
|
62
|
+
|
|
63
|
+
const query = encodeFormQuery({
|
|
64
|
+
"desc": payload.desc,
|
|
65
|
+
"items_per_page": payload.items_per_page,
|
|
66
|
+
"job_like": payload.job_like,
|
|
67
|
+
"page": payload.page,
|
|
68
|
+
"sort": payload.sort,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const headers = new Headers(compactMap({
|
|
72
|
+
Accept: "application/json",
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
const context = {
|
|
76
|
+
baseURL: options?.serverURL ?? "",
|
|
77
|
+
operationID: "listVendorJobTitles",
|
|
78
|
+
oAuth2Scopes: [],
|
|
79
|
+
|
|
80
|
+
resolvedSecurity: null,
|
|
81
|
+
|
|
82
|
+
securitySource: null,
|
|
83
|
+
retryConfig: options?.retries
|
|
84
|
+
|| client._options.retryConfig
|
|
85
|
+
|| { strategy: "none" },
|
|
86
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const requestRes = client._createRequest(context, {
|
|
90
|
+
method: "GET",
|
|
91
|
+
baseURL: options?.serverURL,
|
|
92
|
+
path: path,
|
|
93
|
+
headers: headers,
|
|
94
|
+
query: query,
|
|
95
|
+
body: body,
|
|
96
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
97
|
+
}, options);
|
|
98
|
+
if (!requestRes.ok) {
|
|
99
|
+
return requestRes;
|
|
100
|
+
}
|
|
101
|
+
const req = requestRes.value;
|
|
102
|
+
|
|
103
|
+
const doResult = await client._do(req, {
|
|
104
|
+
context,
|
|
105
|
+
errorCodes: ["403", "4XX", "500", "5XX"],
|
|
106
|
+
retryConfig: context.retryConfig,
|
|
107
|
+
retryCodes: context.retryCodes,
|
|
108
|
+
});
|
|
109
|
+
if (!doResult.ok) {
|
|
110
|
+
return doResult;
|
|
111
|
+
}
|
|
112
|
+
const response = doResult.value;
|
|
113
|
+
|
|
114
|
+
const responseFields = {
|
|
115
|
+
HttpMeta: { Response: response, Request: req },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const [result] = await M.match<
|
|
119
|
+
operations.ListVendorJobTitlesResponseBody,
|
|
120
|
+
| errors.ApiErrorResponse
|
|
121
|
+
| errors.ApiErrorResponse
|
|
122
|
+
| APIError
|
|
123
|
+
| SDKValidationError
|
|
124
|
+
| UnexpectedClientError
|
|
125
|
+
| InvalidRequestError
|
|
126
|
+
| RequestAbortedError
|
|
127
|
+
| RequestTimeoutError
|
|
128
|
+
| ConnectionError
|
|
129
|
+
>(
|
|
130
|
+
M.json(200, operations.ListVendorJobTitlesResponseBody$inboundSchema),
|
|
131
|
+
M.jsonErr(403, errors.ApiErrorResponse$inboundSchema),
|
|
132
|
+
M.jsonErr(500, errors.ApiErrorResponse$inboundSchema),
|
|
133
|
+
M.fail("4XX"),
|
|
134
|
+
M.fail("5XX"),
|
|
135
|
+
)(response, { extraFields: responseFields });
|
|
136
|
+
if (!result.ok) {
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { RequestInput } from "../lib/http.js";
|
|
6
|
+
import {
|
|
7
|
+
AfterErrorContext,
|
|
8
|
+
AfterErrorHook,
|
|
9
|
+
AfterSuccessContext,
|
|
10
|
+
AfterSuccessHook,
|
|
11
|
+
BeforeCreateRequestContext,
|
|
12
|
+
BeforeCreateRequestHook,
|
|
13
|
+
BeforeRequestContext,
|
|
14
|
+
BeforeRequestHook,
|
|
15
|
+
Hook,
|
|
16
|
+
Hooks,
|
|
17
|
+
SDKInitHook,
|
|
18
|
+
SDKInitOptions,
|
|
19
|
+
} from "./types.js";
|
|
20
|
+
|
|
21
|
+
import { initHooks } from "./registration.js";
|
|
22
|
+
|
|
23
|
+
export class SDKHooks implements Hooks {
|
|
24
|
+
sdkInitHooks: SDKInitHook[] = [];
|
|
25
|
+
beforeCreateRequestHooks: BeforeCreateRequestHook[] = [];
|
|
26
|
+
beforeRequestHooks: BeforeRequestHook[] = [];
|
|
27
|
+
afterSuccessHooks: AfterSuccessHook[] = [];
|
|
28
|
+
afterErrorHooks: AfterErrorHook[] = [];
|
|
29
|
+
|
|
30
|
+
constructor() {
|
|
31
|
+
const presetHooks: Array<Hook> = [];
|
|
32
|
+
|
|
33
|
+
for (const hook of presetHooks) {
|
|
34
|
+
if ("sdkInit" in hook) {
|
|
35
|
+
this.registerSDKInitHook(hook);
|
|
36
|
+
}
|
|
37
|
+
if ("beforeCreateRequest" in hook) {
|
|
38
|
+
this.registerBeforeCreateRequestHook(hook);
|
|
39
|
+
}
|
|
40
|
+
if ("beforeRequest" in hook) {
|
|
41
|
+
this.registerBeforeRequestHook(hook);
|
|
42
|
+
}
|
|
43
|
+
if ("afterSuccess" in hook) {
|
|
44
|
+
this.registerAfterSuccessHook(hook);
|
|
45
|
+
}
|
|
46
|
+
if ("afterError" in hook) {
|
|
47
|
+
this.registerAfterErrorHook(hook);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
initHooks(this);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
registerSDKInitHook(hook: SDKInitHook) {
|
|
54
|
+
this.sdkInitHooks.push(hook);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
registerBeforeCreateRequestHook(hook: BeforeCreateRequestHook) {
|
|
58
|
+
this.beforeCreateRequestHooks.push(hook);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
registerBeforeRequestHook(hook: BeforeRequestHook) {
|
|
62
|
+
this.beforeRequestHooks.push(hook);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
registerAfterSuccessHook(hook: AfterSuccessHook) {
|
|
66
|
+
this.afterSuccessHooks.push(hook);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
registerAfterErrorHook(hook: AfterErrorHook) {
|
|
70
|
+
this.afterErrorHooks.push(hook);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
sdkInit(opts: SDKInitOptions): SDKInitOptions {
|
|
74
|
+
return this.sdkInitHooks.reduce((opts, hook) => hook.sdkInit(opts), opts);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
beforeCreateRequest(
|
|
78
|
+
hookCtx: BeforeCreateRequestContext,
|
|
79
|
+
input: RequestInput,
|
|
80
|
+
): RequestInput {
|
|
81
|
+
let inp = input;
|
|
82
|
+
|
|
83
|
+
for (const hook of this.beforeCreateRequestHooks) {
|
|
84
|
+
inp = hook.beforeCreateRequest(hookCtx, inp);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return inp;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async beforeRequest(
|
|
91
|
+
hookCtx: BeforeRequestContext,
|
|
92
|
+
request: Request,
|
|
93
|
+
): Promise<Request> {
|
|
94
|
+
let req = request;
|
|
95
|
+
|
|
96
|
+
for (const hook of this.beforeRequestHooks) {
|
|
97
|
+
req = await hook.beforeRequest(hookCtx, req);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return req;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async afterSuccess(
|
|
104
|
+
hookCtx: AfterSuccessContext,
|
|
105
|
+
response: Response,
|
|
106
|
+
): Promise<Response> {
|
|
107
|
+
let res = response;
|
|
108
|
+
|
|
109
|
+
for (const hook of this.afterSuccessHooks) {
|
|
110
|
+
res = await hook.afterSuccess(hookCtx, res);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async afterError(
|
|
117
|
+
hookCtx: AfterErrorContext,
|
|
118
|
+
response: Response | null,
|
|
119
|
+
error: unknown,
|
|
120
|
+
): Promise<{ response: Response | null; error: unknown }> {
|
|
121
|
+
let res = response;
|
|
122
|
+
let err = error;
|
|
123
|
+
|
|
124
|
+
for (const hook of this.afterErrorHooks) {
|
|
125
|
+
const result = await hook.afterError(hookCtx, res, err);
|
|
126
|
+
res = result.response;
|
|
127
|
+
err = result.error;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { response: res, error: err };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Hooks } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* This file is only ever generated once on the first generation and then is free to be modified.
|
|
5
|
+
* Any hooks you wish to add should be registered in the initHooks function. Feel free to define them
|
|
6
|
+
* in this file or in separate files in the hooks folder.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// @ts-expect-error remove this line when you add your first hook and hooks is used
|
|
10
|
+
export function initHooks(hooks: Hooks) {
|
|
11
|
+
// Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
|
|
12
|
+
// with an instance of a hook that implements that specific Hook interface
|
|
13
|
+
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
|
14
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { HTTPClient, RequestInput } from "../lib/http.js";
|
|
6
|
+
import { RetryConfig } from "../lib/retries.js";
|
|
7
|
+
import { SecurityState } from "../lib/security.js";
|
|
8
|
+
|
|
9
|
+
export type HookContext = {
|
|
10
|
+
baseURL: string | URL;
|
|
11
|
+
operationID: string;
|
|
12
|
+
oAuth2Scopes?: string[];
|
|
13
|
+
securitySource?: any | (() => Promise<any>);
|
|
14
|
+
retryConfig: RetryConfig;
|
|
15
|
+
resolvedSecurity: SecurityState | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Awaitable<T> = T | Promise<T>;
|
|
19
|
+
|
|
20
|
+
export type SDKInitOptions = {
|
|
21
|
+
baseURL: URL | null;
|
|
22
|
+
client: HTTPClient;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type BeforeCreateRequestContext = HookContext & {};
|
|
26
|
+
export type BeforeRequestContext = HookContext & {};
|
|
27
|
+
export type AfterSuccessContext = HookContext & {};
|
|
28
|
+
export type AfterErrorContext = HookContext & {};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* SDKInitHook is called when the SDK is initializing. The
|
|
32
|
+
* hook can return a new baseURL and HTTP client to be used by the SDK.
|
|
33
|
+
*/
|
|
34
|
+
export interface SDKInitHook {
|
|
35
|
+
sdkInit: (opts: SDKInitOptions) => SDKInitOptions;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface BeforeCreateRequestHook {
|
|
39
|
+
/**
|
|
40
|
+
* A hook that is called before the SDK creates a `Request` object. The hook
|
|
41
|
+
* can modify how a request is constructed since certain modifications, like
|
|
42
|
+
* changing the request URL, cannot be done on a request object directly.
|
|
43
|
+
*/
|
|
44
|
+
beforeCreateRequest: (
|
|
45
|
+
hookCtx: BeforeCreateRequestContext,
|
|
46
|
+
input: RequestInput,
|
|
47
|
+
) => RequestInput;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface BeforeRequestHook {
|
|
51
|
+
/**
|
|
52
|
+
* A hook that is called before the SDK sends a request. The hook can
|
|
53
|
+
* introduce instrumentation code such as logging, tracing and metrics or
|
|
54
|
+
* replace the request before it is sent or throw an error to stop the
|
|
55
|
+
* request from being sent.
|
|
56
|
+
*/
|
|
57
|
+
beforeRequest: (
|
|
58
|
+
hookCtx: BeforeRequestContext,
|
|
59
|
+
request: Request,
|
|
60
|
+
) => Awaitable<Request>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface AfterSuccessHook {
|
|
64
|
+
/**
|
|
65
|
+
* A hook that is called after the SDK receives a response. The hook can
|
|
66
|
+
* introduce instrumentation code such as logging, tracing and metrics or
|
|
67
|
+
* modify the response before it is handled or throw an error to stop the
|
|
68
|
+
* response from being handled.
|
|
69
|
+
*/
|
|
70
|
+
afterSuccess: (
|
|
71
|
+
hookCtx: AfterSuccessContext,
|
|
72
|
+
response: Response,
|
|
73
|
+
) => Awaitable<Response>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface AfterErrorHook {
|
|
77
|
+
/**
|
|
78
|
+
* A hook that is called after the SDK encounters an error, or a
|
|
79
|
+
* non-successful response. The hook can introduce instrumentation code such
|
|
80
|
+
* as logging, tracing and metrics or modify the response or error values.
|
|
81
|
+
*/
|
|
82
|
+
afterError: (
|
|
83
|
+
hookCtx: AfterErrorContext,
|
|
84
|
+
response: Response | null,
|
|
85
|
+
error: unknown,
|
|
86
|
+
) => Awaitable<{
|
|
87
|
+
response: Response | null;
|
|
88
|
+
error: unknown;
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface Hooks {
|
|
93
|
+
/** Registers a hook to be used by the SDK for initialization event. */
|
|
94
|
+
registerSDKInitHook(hook: SDKInitHook): void;
|
|
95
|
+
/** Registers a hook to be used by the SDK for to modify `Request` construction. */
|
|
96
|
+
registerBeforeCreateRequestHook(hook: BeforeCreateRequestHook): void;
|
|
97
|
+
/** Registers a hook to be used by the SDK for the before request event. */
|
|
98
|
+
registerBeforeRequestHook(hook: BeforeRequestHook): void;
|
|
99
|
+
/** Registers a hook to be used by the SDK for the after success event. */
|
|
100
|
+
registerAfterSuccessHook(hook: AfterSuccessHook): void;
|
|
101
|
+
/** Registers a hook to be used by the SDK for the after error event. */
|
|
102
|
+
registerAfterErrorHook(hook: AfterErrorHook): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type Hook =
|
|
106
|
+
| SDKInitHook
|
|
107
|
+
| BeforeCreateRequestHook
|
|
108
|
+
| BeforeRequestHook
|
|
109
|
+
| AfterSuccessHook
|
|
110
|
+
| AfterErrorHook;
|