magic-hour 0.37.0 → 0.39.0
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/dist/client.d.ts +1 -1
- package/dist/client.js +3 -3
- package/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/helpers/generate-type.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/resources/v1/ai-clothes-changer/request-types.js +3 -3
- package/dist/resources/v1/ai-clothes-changer/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-clothes-changer/resource-client.js +4 -4
- package/dist/resources/v1/ai-face-editor/request-types.js +3 -3
- package/dist/resources/v1/ai-face-editor/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-face-editor/resource-client.js +4 -4
- package/dist/resources/v1/ai-gif-generator/request-types.d.ts +5 -0
- package/dist/resources/v1/ai-gif-generator/request-types.js +7 -3
- package/dist/resources/v1/ai-gif-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-gif-generator/resource-client.js +4 -4
- package/dist/resources/v1/ai-headshot-generator/request-types.js +3 -3
- package/dist/resources/v1/ai-headshot-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-headshot-generator/resource-client.js +4 -4
- package/dist/resources/v1/ai-image-editor/request-types.js +3 -3
- package/dist/resources/v1/ai-image-editor/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.js +4 -4
- package/dist/resources/v1/ai-image-generator/request-types.js +3 -3
- package/dist/resources/v1/ai-image-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-image-generator/resource-client.js +4 -4
- package/dist/resources/v1/ai-image-upscaler/request-types.js +3 -3
- package/dist/resources/v1/ai-image-upscaler/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-image-upscaler/resource-client.js +4 -4
- package/dist/resources/v1/ai-meme-generator/request-types.js +3 -3
- package/dist/resources/v1/ai-meme-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-meme-generator/resource-client.js +4 -4
- package/dist/resources/v1/ai-photo-editor/request-types.js +3 -3
- package/dist/resources/v1/ai-photo-editor/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-photo-editor/resource-client.js +4 -4
- package/dist/resources/v1/ai-qr-code-generator/request-types.js +3 -3
- package/dist/resources/v1/ai-qr-code-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-qr-code-generator/resource-client.js +4 -4
- package/dist/resources/v1/ai-talking-photo/request-types.js +3 -3
- package/dist/resources/v1/ai-talking-photo/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-talking-photo/resource-client.js +4 -4
- package/dist/resources/v1/animation/request-types.js +3 -3
- package/dist/resources/v1/animation/resource-client.d.ts +1 -1
- package/dist/resources/v1/animation/resource-client.js +4 -4
- package/dist/resources/v1/auto-subtitle-generator/request-types.js +3 -3
- package/dist/resources/v1/auto-subtitle-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/auto-subtitle-generator/resource-client.js +4 -4
- package/dist/resources/v1/face-detection/request-types.js +5 -5
- package/dist/resources/v1/face-detection/resource-client.d.ts +1 -1
- package/dist/resources/v1/face-detection/resource-client.js +2 -2
- package/dist/resources/v1/face-swap/request-types.js +3 -3
- package/dist/resources/v1/face-swap/resource-client.d.ts +1 -1
- package/dist/resources/v1/face-swap/resource-client.js +4 -4
- package/dist/resources/v1/face-swap-photo/request-types.js +3 -3
- package/dist/resources/v1/face-swap-photo/resource-client.d.ts +1 -1
- package/dist/resources/v1/face-swap-photo/resource-client.js +4 -4
- package/dist/resources/v1/files/resource-client.d.ts +1 -1
- package/dist/resources/v1/files/resource-client.js +3 -3
- package/dist/resources/v1/files/resource-client.test.js +2 -2
- package/dist/resources/v1/files/upload-urls/request-types.js +3 -3
- package/dist/resources/v1/files/upload-urls/resource-client.d.ts +1 -1
- package/dist/resources/v1/files/upload-urls/resource-client.js +2 -2
- package/dist/resources/v1/image-background-remover/request-types.js +3 -3
- package/dist/resources/v1/image-background-remover/resource-client.d.ts +1 -1
- package/dist/resources/v1/image-background-remover/resource-client.js +4 -4
- package/dist/resources/v1/image-projects/request-types.js +5 -5
- package/dist/resources/v1/image-projects/resource-client.d.ts +1 -1
- package/dist/resources/v1/image-projects/resource-client.js +2 -2
- package/dist/resources/v1/image-to-video/request-types.js +3 -3
- package/dist/resources/v1/image-to-video/resource-client.d.ts +1 -1
- package/dist/resources/v1/image-to-video/resource-client.js +4 -4
- package/dist/resources/v1/lip-sync/request-types.js +3 -3
- package/dist/resources/v1/lip-sync/resource-client.d.ts +1 -1
- package/dist/resources/v1/lip-sync/resource-client.js +4 -4
- package/dist/resources/v1/photo-colorizer/request-types.js +3 -3
- package/dist/resources/v1/photo-colorizer/resource-client.d.ts +1 -1
- package/dist/resources/v1/photo-colorizer/resource-client.js +3 -3
- package/dist/resources/v1/resource-client.d.ts +1 -1
- package/dist/resources/v1/resource-client.js +2 -2
- package/dist/resources/v1/text-to-video/request-types.js +3 -3
- package/dist/resources/v1/text-to-video/resource-client.d.ts +1 -1
- package/dist/resources/v1/text-to-video/resource-client.js +4 -4
- package/dist/resources/v1/video-projects/request-types.js +5 -5
- package/dist/resources/v1/video-projects/resource-client.d.ts +1 -1
- package/dist/resources/v1/video-projects/resource-client.js +2 -2
- package/dist/resources/v1/video-to-video/request-types.js +3 -3
- package/dist/resources/v1/video-to-video/resource-client.d.ts +1 -1
- package/dist/resources/v1/video-to-video/resource-client.js +4 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/v1-ai-clothes-changer-create-body-assets.js +3 -3
- package/dist/types/v1-ai-clothes-changer-create-body.js +3 -3
- package/dist/types/v1-ai-clothes-changer-create-response.js +3 -3
- package/dist/types/v1-ai-clothes-changer-create-response400.js +3 -3
- package/dist/types/v1-ai-clothes-changer-create-response401.js +3 -3
- package/dist/types/v1-ai-clothes-changer-create-response404.js +3 -3
- package/dist/types/v1-ai-clothes-changer-create-response422.js +3 -3
- package/dist/types/v1-ai-face-editor-create-body-assets.js +3 -3
- package/dist/types/v1-ai-face-editor-create-body-style.js +3 -3
- package/dist/types/v1-ai-face-editor-create-body.js +3 -3
- package/dist/types/v1-ai-face-editor-create-response.js +3 -3
- package/dist/types/v1-ai-face-editor-create-response400.js +3 -3
- package/dist/types/v1-ai-face-editor-create-response401.js +3 -3
- package/dist/types/v1-ai-face-editor-create-response404.js +3 -3
- package/dist/types/v1-ai-face-editor-create-response422.js +3 -3
- package/dist/types/v1-ai-gif-generator-create-body-output-format-enum.d.ts +4 -0
- package/dist/types/v1-ai-gif-generator-create-body-output-format-enum.js +2 -0
- package/dist/types/v1-ai-gif-generator-create-body-style.js +3 -3
- package/dist/types/v1-ai-gif-generator-create-body.d.ts +5 -0
- package/dist/types/v1-ai-gif-generator-create-body.js +7 -3
- package/dist/types/v1-ai-gif-generator-create-response.js +3 -3
- package/dist/types/v1-ai-gif-generator-create-response400.js +3 -3
- package/dist/types/v1-ai-gif-generator-create-response401.js +3 -3
- package/dist/types/v1-ai-gif-generator-create-response404.js +3 -3
- package/dist/types/v1-ai-gif-generator-create-response422.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-body-assets.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-body-style.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-body.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-response.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-response400.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-response401.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-response404.js +3 -3
- package/dist/types/v1-ai-headshot-generator-create-response422.js +3 -3
- package/dist/types/v1-ai-image-editor-create-body-assets.js +3 -3
- package/dist/types/v1-ai-image-editor-create-body-style.js +3 -3
- package/dist/types/v1-ai-image-editor-create-body.js +3 -3
- package/dist/types/v1-ai-image-editor-create-response.js +3 -3
- package/dist/types/v1-ai-image-editor-create-response400.js +3 -3
- package/dist/types/v1-ai-image-editor-create-response401.js +3 -3
- package/dist/types/v1-ai-image-editor-create-response404.js +3 -3
- package/dist/types/v1-ai-image-editor-create-response422.js +3 -3
- package/dist/types/v1-ai-image-generator-create-body-style.js +3 -3
- package/dist/types/v1-ai-image-generator-create-body.js +3 -3
- package/dist/types/v1-ai-image-generator-create-response.js +3 -3
- package/dist/types/v1-ai-image-generator-create-response400.js +3 -3
- package/dist/types/v1-ai-image-generator-create-response401.js +3 -3
- package/dist/types/v1-ai-image-generator-create-response404.js +3 -3
- package/dist/types/v1-ai-image-generator-create-response422.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-body-assets.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-body-style.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-body.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-response.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-response400.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-response401.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-response404.js +3 -3
- package/dist/types/v1-ai-image-upscaler-create-response422.js +3 -3
- package/dist/types/v1-ai-meme-generator-create-body-style.js +3 -3
- package/dist/types/v1-ai-meme-generator-create-body.js +3 -3
- package/dist/types/v1-ai-meme-generator-create-response.js +3 -3
- package/dist/types/v1-ai-meme-generator-create-response400.js +3 -3
- package/dist/types/v1-ai-meme-generator-create-response401.js +3 -3
- package/dist/types/v1-ai-meme-generator-create-response404.js +3 -3
- package/dist/types/v1-ai-meme-generator-create-response422.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-body-assets.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-body-style.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-body.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-response.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-response400.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-response401.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-response404.js +3 -3
- package/dist/types/v1-ai-photo-editor-create-response422.js +3 -3
- package/dist/types/v1-ai-qr-code-generator-create-body-style.js +3 -3
- package/dist/types/v1-ai-qr-code-generator-create-body.js +3 -3
- package/dist/types/v1-ai-qr-code-generator-create-response.js +3 -3
- package/dist/types/v1-ai-qr-code-generator-create-response400.js +3 -3
- package/dist/types/v1-ai-qr-code-generator-create-response401.js +3 -3
- package/dist/types/v1-ai-qr-code-generator-create-response404.js +3 -3
- package/dist/types/v1-ai-qr-code-generator-create-response422.js +3 -3
- package/dist/types/v1-ai-talking-photo-create-body-assets.js +3 -3
- package/dist/types/v1-ai-talking-photo-create-body-style-generation-mode-enum.d.ts +3 -2
- package/dist/types/v1-ai-talking-photo-create-body-style.d.ts +4 -3
- package/dist/types/v1-ai-talking-photo-create-body-style.js +5 -5
- package/dist/types/v1-ai-talking-photo-create-body.js +3 -3
- package/dist/types/v1-ai-talking-photo-create-response.js +3 -3
- package/dist/types/v1-ai-talking-photo-create-response400.js +3 -3
- package/dist/types/v1-ai-talking-photo-create-response401.js +3 -3
- package/dist/types/v1-ai-talking-photo-create-response404.js +3 -3
- package/dist/types/v1-ai-talking-photo-create-response422.js +3 -3
- package/dist/types/v1-animation-create-body-assets.js +3 -3
- package/dist/types/v1-animation-create-body-style.js +3 -3
- package/dist/types/v1-animation-create-body.js +3 -3
- package/dist/types/v1-animation-create-response.js +3 -3
- package/dist/types/v1-animation-create-response400.js +3 -3
- package/dist/types/v1-animation-create-response401.js +3 -3
- package/dist/types/v1-animation-create-response404.js +3 -3
- package/dist/types/v1-animation-create-response422.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-body-assets.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-body-style-custom-config.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-body-style.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-body.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-response.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-response400.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-response401.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-response404.js +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-response422.js +3 -3
- package/dist/types/v1-face-detection-create-body-assets.js +3 -3
- package/dist/types/v1-face-detection-create-body.js +3 -3
- package/dist/types/v1-face-detection-create-response.js +3 -3
- package/dist/types/v1-face-detection-create-response400.js +3 -3
- package/dist/types/v1-face-detection-create-response401.js +3 -3
- package/dist/types/v1-face-detection-create-response404.js +3 -3
- package/dist/types/v1-face-detection-create-response422.js +3 -3
- package/dist/types/v1-face-detection-get-response-faces-item.js +3 -3
- package/dist/types/v1-face-detection-get-response.js +3 -3
- package/dist/types/v1-face-detection-get-response400.js +3 -3
- package/dist/types/v1-face-detection-get-response401.js +3 -3
- package/dist/types/v1-face-detection-get-response404.js +3 -3
- package/dist/types/v1-face-detection-get-response422.js +3 -3
- package/dist/types/v1-face-swap-create-body-assets-face-mappings-item.js +3 -3
- package/dist/types/v1-face-swap-create-body-assets.js +3 -3
- package/dist/types/v1-face-swap-create-body-style.js +3 -3
- package/dist/types/v1-face-swap-create-body.js +3 -3
- package/dist/types/v1-face-swap-create-response.js +3 -3
- package/dist/types/v1-face-swap-create-response400.js +3 -3
- package/dist/types/v1-face-swap-create-response401.js +3 -3
- package/dist/types/v1-face-swap-create-response404.js +3 -3
- package/dist/types/v1-face-swap-create-response422.js +3 -3
- package/dist/types/v1-face-swap-photo-create-body-assets-face-mappings-item.js +3 -3
- package/dist/types/v1-face-swap-photo-create-body-assets.js +3 -3
- package/dist/types/v1-face-swap-photo-create-body.js +3 -3
- package/dist/types/v1-face-swap-photo-create-response.js +3 -3
- package/dist/types/v1-face-swap-photo-create-response400.js +3 -3
- package/dist/types/v1-face-swap-photo-create-response401.js +3 -3
- package/dist/types/v1-face-swap-photo-create-response404.js +3 -3
- package/dist/types/v1-face-swap-photo-create-response422.js +3 -3
- package/dist/types/v1-files-upload-urls-create-body-items-item.js +3 -3
- package/dist/types/v1-files-upload-urls-create-body.js +3 -3
- package/dist/types/v1-files-upload-urls-create-response-items-item.js +3 -3
- package/dist/types/v1-files-upload-urls-create-response.js +3 -3
- package/dist/types/v1-files-upload-urls-create-response400.js +3 -3
- package/dist/types/v1-files-upload-urls-create-response401.js +3 -3
- package/dist/types/v1-files-upload-urls-create-response404.js +3 -3
- package/dist/types/v1-files-upload-urls-create-response422.js +3 -3
- package/dist/types/v1-image-background-remover-create-body-assets.js +3 -3
- package/dist/types/v1-image-background-remover-create-body.js +3 -3
- package/dist/types/v1-image-background-remover-create-response.js +3 -3
- package/dist/types/v1-image-background-remover-create-response400.js +3 -3
- package/dist/types/v1-image-background-remover-create-response401.js +3 -3
- package/dist/types/v1-image-background-remover-create-response404.js +3 -3
- package/dist/types/v1-image-background-remover-create-response422.js +3 -3
- package/dist/types/v1-image-projects-delete-response400.js +3 -3
- package/dist/types/v1-image-projects-delete-response401.js +3 -3
- package/dist/types/v1-image-projects-delete-response404.js +3 -3
- package/dist/types/v1-image-projects-get-response-downloads-item.js +3 -3
- package/dist/types/v1-image-projects-get-response-error.js +3 -3
- package/dist/types/v1-image-projects-get-response.js +3 -3
- package/dist/types/v1-image-projects-get-response400.js +3 -3
- package/dist/types/v1-image-projects-get-response401.js +3 -3
- package/dist/types/v1-image-projects-get-response404.js +3 -3
- package/dist/types/v1-image-to-video-create-body-assets.js +3 -3
- package/dist/types/v1-image-to-video-create-body-style.js +3 -3
- package/dist/types/v1-image-to-video-create-body.js +3 -3
- package/dist/types/v1-image-to-video-create-response.js +3 -3
- package/dist/types/v1-image-to-video-create-response400.js +3 -3
- package/dist/types/v1-image-to-video-create-response401.js +3 -3
- package/dist/types/v1-image-to-video-create-response404.js +3 -3
- package/dist/types/v1-image-to-video-create-response422.js +3 -3
- package/dist/types/v1-lip-sync-create-body-assets.js +3 -3
- package/dist/types/v1-lip-sync-create-body.js +3 -3
- package/dist/types/v1-lip-sync-create-response.js +3 -3
- package/dist/types/v1-lip-sync-create-response400.js +3 -3
- package/dist/types/v1-lip-sync-create-response401.js +3 -3
- package/dist/types/v1-lip-sync-create-response404.js +3 -3
- package/dist/types/v1-lip-sync-create-response422.js +3 -3
- package/dist/types/v1-photo-colorizer-create-body-assets.js +3 -3
- package/dist/types/v1-photo-colorizer-create-body.js +3 -3
- package/dist/types/v1-photo-colorizer-create-response.js +3 -3
- package/dist/types/v1-photo-colorizer-create-response400.js +3 -3
- package/dist/types/v1-photo-colorizer-create-response401.js +3 -3
- package/dist/types/v1-photo-colorizer-create-response404.js +3 -3
- package/dist/types/v1-photo-colorizer-create-response422.js +3 -3
- package/dist/types/v1-text-to-video-create-body-style.js +3 -3
- package/dist/types/v1-text-to-video-create-body.js +3 -3
- package/dist/types/v1-text-to-video-create-response.js +3 -3
- package/dist/types/v1-text-to-video-create-response400.js +3 -3
- package/dist/types/v1-text-to-video-create-response401.js +3 -3
- package/dist/types/v1-text-to-video-create-response404.js +3 -3
- package/dist/types/v1-text-to-video-create-response422.js +3 -3
- package/dist/types/v1-video-projects-delete-response400.js +3 -3
- package/dist/types/v1-video-projects-delete-response401.js +3 -3
- package/dist/types/v1-video-projects-delete-response404.js +3 -3
- package/dist/types/v1-video-projects-delete-response422.js +3 -3
- package/dist/types/v1-video-projects-get-response-download.js +3 -3
- package/dist/types/v1-video-projects-get-response-downloads-item.js +3 -3
- package/dist/types/v1-video-projects-get-response-error.js +3 -3
- package/dist/types/v1-video-projects-get-response.js +3 -3
- package/dist/types/v1-video-projects-get-response400.js +3 -3
- package/dist/types/v1-video-projects-get-response401.js +3 -3
- package/dist/types/v1-video-projects-get-response404.js +3 -3
- package/dist/types/v1-video-to-video-create-body-assets.js +3 -3
- package/dist/types/v1-video-to-video-create-body-style.js +3 -3
- package/dist/types/v1-video-to-video-create-body.js +3 -3
- package/dist/types/v1-video-to-video-create-response.js +3 -3
- package/dist/types/v1-video-to-video-create-response400.js +3 -3
- package/dist/types/v1-video-to-video-create-response401.js +3 -3
- package/dist/types/v1-video-to-video-create-response404.js +3 -3
- package/dist/types/v1-video-to-video-create-response422.js +3 -3
- package/package.json +7 -14
- package/dist/core/api-error.d.ts +0 -6
- package/dist/core/api-error.js +0 -11
- package/dist/core/api-promise.d.ts +0 -28
- package/dist/core/api-promise.js +0 -252
- package/dist/core/auth.d.ts +0 -76
- package/dist/core/auth.js +0 -232
- package/dist/core/binary-response.d.ts +0 -6
- package/dist/core/binary-response.js +0 -10
- package/dist/core/content-type.d.ts +0 -4
- package/dist/core/content-type.js +0 -12
- package/dist/core/core-client.d.ts +0 -58
- package/dist/core/core-client.js +0 -168
- package/dist/core/form-data.d.ts +0 -26
- package/dist/core/form-data.js +0 -83
- package/dist/core/index.d.ts +0 -9
- package/dist/core/index.js +0 -28
- package/dist/core/query.d.ts +0 -8
- package/dist/core/query.js +0 -77
- package/dist/core/runtime.d.ts +0 -4
- package/dist/core/runtime.js +0 -20
- package/dist/core/zod.d.ts +0 -13
- package/dist/core/zod.js +0 -60
package/dist/core/auth.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { RequestConfig } from "./core-client";
|
|
2
|
-
export interface AuthProvider {
|
|
3
|
-
applyAuth: (cfg: RequestConfig) => Promise<RequestConfig>;
|
|
4
|
-
setValue: (val?: string | undefined) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare class AuthBasic implements AuthProvider {
|
|
7
|
-
username: string | null;
|
|
8
|
-
password: string | null;
|
|
9
|
-
constructor(username?: string, password?: string);
|
|
10
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
11
|
-
setValue(val?: string | undefined): void;
|
|
12
|
-
}
|
|
13
|
-
export declare class AuthBearer implements AuthProvider {
|
|
14
|
-
token: string | null;
|
|
15
|
-
constructor(token?: string);
|
|
16
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
17
|
-
setValue(val?: string | undefined): void;
|
|
18
|
-
}
|
|
19
|
-
export declare class AuthKey implements AuthProvider {
|
|
20
|
-
name: string;
|
|
21
|
-
location: "query" | "header" | "cookie";
|
|
22
|
-
key: string | null;
|
|
23
|
-
constructor(name: string, location: "query" | "header" | "cookie", key?: string);
|
|
24
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
25
|
-
setValue(val?: string | undefined): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* OAuth2 authentication props for a password flow
|
|
29
|
-
*
|
|
30
|
-
* Details:
|
|
31
|
-
* https://datatracker.ietf.org/doc/html/rfc6749#section-4.3
|
|
32
|
-
*/
|
|
33
|
-
export type OAuth2Password = {
|
|
34
|
-
username: string;
|
|
35
|
-
password: string;
|
|
36
|
-
clientId?: string | undefined;
|
|
37
|
-
clientSecret?: string | undefined;
|
|
38
|
-
grantType?: "password" | string | undefined;
|
|
39
|
-
scope?: string[] | undefined;
|
|
40
|
-
tokenUrl?: string | undefined;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* OAuth2 authentication props for a client credentials flow
|
|
44
|
-
*
|
|
45
|
-
* Details:
|
|
46
|
-
* https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
|
|
47
|
-
*/
|
|
48
|
-
export type OAuth2ClientCredentials = {
|
|
49
|
-
clientId: string;
|
|
50
|
-
clientSecret: string;
|
|
51
|
-
grantType?: "client_credentials" | string | undefined;
|
|
52
|
-
scope?: string[] | undefined;
|
|
53
|
-
tokenUrl?: string | undefined;
|
|
54
|
-
};
|
|
55
|
-
export type OAuth2ProviderProps = {
|
|
56
|
-
baseUrl: string;
|
|
57
|
-
defaultTokenUrl: string;
|
|
58
|
-
accessTokenPointer: string;
|
|
59
|
-
expiresInPointer: string;
|
|
60
|
-
credentialsLocation: "request_body" | "basic_authorization_header";
|
|
61
|
-
bodyContent: "form" | "json";
|
|
62
|
-
requestMutator: AuthProvider;
|
|
63
|
-
form?: OAuth2Password | OAuth2ClientCredentials | undefined;
|
|
64
|
-
};
|
|
65
|
-
export declare class OAuth2 implements AuthProvider {
|
|
66
|
-
props: OAuth2ProviderProps;
|
|
67
|
-
accessToken?: string | undefined;
|
|
68
|
-
expiresAt?: Date;
|
|
69
|
-
constructor(props: OAuth2ProviderProps);
|
|
70
|
-
refresh(form: OAuth2Password | OAuth2ClientCredentials): Promise<{
|
|
71
|
-
accessToken: string;
|
|
72
|
-
expiresAt: Date;
|
|
73
|
-
}>;
|
|
74
|
-
applyAuth(cfg: RequestConfig): Promise<RequestConfig>;
|
|
75
|
-
setValue(val?: string | undefined): void;
|
|
76
|
-
}
|
package/dist/core/auth.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.OAuth2 = exports.AuthKey = exports.AuthBearer = exports.AuthBasic = void 0;
|
|
49
|
-
const qs_1 = __importDefault(require("qs"));
|
|
50
|
-
const form_urlencoded_1 = __importDefault(require("form-urlencoded"));
|
|
51
|
-
const js_base64_1 = require("js-base64");
|
|
52
|
-
const jsonpointer = __importStar(require("jsonpointer"));
|
|
53
|
-
const runtime_1 = require("./runtime");
|
|
54
|
-
const api_error_1 = require("./api-error");
|
|
55
|
-
const AUTHORIZATION = "Authorization";
|
|
56
|
-
const COOKIE = "Cookie";
|
|
57
|
-
class AuthBasic {
|
|
58
|
-
constructor(username, password) {
|
|
59
|
-
this.username = username !== null && username !== void 0 ? username : null;
|
|
60
|
-
this.password = password !== null && password !== void 0 ? password : null;
|
|
61
|
-
}
|
|
62
|
-
applyAuth(cfg) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
var _a;
|
|
65
|
-
const headers = (_a = cfg.headers) !== null && _a !== void 0 ? _a : {};
|
|
66
|
-
if (this.username !== null && this.password !== null) {
|
|
67
|
-
const encoded = (0, js_base64_1.toBase64)(`${this.username}:${this.password}`);
|
|
68
|
-
cfg.headers = headers;
|
|
69
|
-
headers[AUTHORIZATION] = `Basic ${encoded}`;
|
|
70
|
-
}
|
|
71
|
-
return cfg;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
setValue(val) {
|
|
75
|
-
this.username = val !== null && val !== void 0 ? val : null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.AuthBasic = AuthBasic;
|
|
79
|
-
class AuthBearer {
|
|
80
|
-
constructor(token) {
|
|
81
|
-
this.token = token !== null && token !== void 0 ? token : null;
|
|
82
|
-
}
|
|
83
|
-
applyAuth(cfg) {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
var _a;
|
|
86
|
-
const headers = (_a = cfg.headers) !== null && _a !== void 0 ? _a : {};
|
|
87
|
-
if (this.token !== null) {
|
|
88
|
-
cfg.headers = headers;
|
|
89
|
-
headers[AUTHORIZATION] = `Bearer ${this.token}`;
|
|
90
|
-
}
|
|
91
|
-
return cfg;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
setValue(val) {
|
|
95
|
-
this.token = val !== null && val !== void 0 ? val : null;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.AuthBearer = AuthBearer;
|
|
99
|
-
class AuthKey {
|
|
100
|
-
constructor(name, location, key) {
|
|
101
|
-
this.name = name;
|
|
102
|
-
this.location = location;
|
|
103
|
-
this.key = key !== null && key !== void 0 ? key : null;
|
|
104
|
-
}
|
|
105
|
-
applyAuth(cfg) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
var _a, _b, _c, _d;
|
|
108
|
-
if (this.key === null) {
|
|
109
|
-
return cfg;
|
|
110
|
-
}
|
|
111
|
-
if (this.location === "query") {
|
|
112
|
-
const query = (_a = cfg.query) !== null && _a !== void 0 ? _a : [];
|
|
113
|
-
cfg.query = query;
|
|
114
|
-
query.push(qs_1.default.stringify({ [this.name]: this.key }));
|
|
115
|
-
}
|
|
116
|
-
else if (this.location === "header") {
|
|
117
|
-
const headers = (_b = cfg.headers) !== null && _b !== void 0 ? _b : {};
|
|
118
|
-
cfg.headers = headers;
|
|
119
|
-
headers[this.name] = this.key;
|
|
120
|
-
}
|
|
121
|
-
else if (this.location === "cookie" && runtime_1.RUNTIME.type === "browser") {
|
|
122
|
-
cfg.withCredentials = true;
|
|
123
|
-
}
|
|
124
|
-
else if (this.location === "cookie") {
|
|
125
|
-
const headers = (_c = cfg.headers) !== null && _c !== void 0 ? _c : {};
|
|
126
|
-
const cookies = (_d = headers[COOKIE]) !== null && _d !== void 0 ? _d : "";
|
|
127
|
-
headers[COOKIE] = `${cookies.length > 0 ? ";" : ""}${this.name}=${this.key}`;
|
|
128
|
-
cfg.headers = headers;
|
|
129
|
-
}
|
|
130
|
-
return cfg;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
setValue(val) {
|
|
134
|
-
this.key = val !== null && val !== void 0 ? val : null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.AuthKey = AuthKey;
|
|
138
|
-
function isOAuth2Password(val) {
|
|
139
|
-
return typeof val.username === "string" && typeof val.password === "string";
|
|
140
|
-
}
|
|
141
|
-
function isOAuth2ClientCredentials(val) {
|
|
142
|
-
return (typeof val.clientId === "string" && typeof val.clientSecret === "string");
|
|
143
|
-
}
|
|
144
|
-
class OAuth2 {
|
|
145
|
-
constructor(props) {
|
|
146
|
-
this.props = props;
|
|
147
|
-
}
|
|
148
|
-
refresh(form) {
|
|
149
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
var _a, _b;
|
|
151
|
-
const { baseUrl, defaultTokenUrl, credentialsLocation, bodyContent, accessTokenPointer, expiresInPointer, } = this.props;
|
|
152
|
-
// build token url
|
|
153
|
-
let tokenUrl = (_a = form === null || form === void 0 ? void 0 : form.tokenUrl) !== null && _a !== void 0 ? _a : defaultTokenUrl;
|
|
154
|
-
if (tokenUrl.startsWith("/")) {
|
|
155
|
-
// relative token url
|
|
156
|
-
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
157
|
-
tokenUrl = `${base}${tokenUrl}`;
|
|
158
|
-
}
|
|
159
|
-
let defaultGrantType = isOAuth2Password(form)
|
|
160
|
-
? "password"
|
|
161
|
-
: "client_credentials";
|
|
162
|
-
const reqHeaders = {};
|
|
163
|
-
const reqData = {
|
|
164
|
-
grant_type: (_b = form.grantType) !== null && _b !== void 0 ? _b : defaultGrantType,
|
|
165
|
-
};
|
|
166
|
-
// Add client credentials
|
|
167
|
-
if (isOAuth2ClientCredentials(form)) {
|
|
168
|
-
if (credentialsLocation === "basic_authorization_header") {
|
|
169
|
-
const encoded = (0, js_base64_1.toBase64)(`${form.clientId}:${form.clientSecret}`);
|
|
170
|
-
reqHeaders[AUTHORIZATION] = `Basic ${encoded}`;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
reqData["client_id"] = form.clientId;
|
|
174
|
-
reqData["client_secret"] = form.clientSecret;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (isOAuth2Password(form)) {
|
|
178
|
-
reqData["username"] = form.username;
|
|
179
|
-
reqData["password"] = form.password;
|
|
180
|
-
}
|
|
181
|
-
if (typeof form.scope !== "undefined") {
|
|
182
|
-
reqData["scope"] = form.scope.join(" ");
|
|
183
|
-
}
|
|
184
|
-
const reqInit = { method: "POST" };
|
|
185
|
-
if (bodyContent === "form") {
|
|
186
|
-
reqInit.body = (0, form_urlencoded_1.default)(reqData);
|
|
187
|
-
reqHeaders["content-type"] = "application/x-www-form-urlencoded";
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
reqInit.body = JSON.stringify(reqData);
|
|
191
|
-
reqHeaders["content-type"] = "application/json";
|
|
192
|
-
}
|
|
193
|
-
reqInit.headers = reqHeaders;
|
|
194
|
-
const fetcherFn = runtime_1.RUNTIME.type === "node" || typeof fetch !== "function"
|
|
195
|
-
? require("node-fetch").default
|
|
196
|
-
: fetch;
|
|
197
|
-
const tokenRes = yield fetcherFn(tokenUrl, reqInit);
|
|
198
|
-
if (!tokenRes.ok) {
|
|
199
|
-
throw new api_error_1.ApiError({
|
|
200
|
-
method: "post",
|
|
201
|
-
path: tokenUrl,
|
|
202
|
-
headers: reqHeaders,
|
|
203
|
-
body: reqData,
|
|
204
|
-
contentType: reqHeaders["content-type"],
|
|
205
|
-
}, tokenRes);
|
|
206
|
-
}
|
|
207
|
-
const tokenResJson = yield tokenRes.json();
|
|
208
|
-
const accessTokenRaw = jsonpointer.get(tokenResJson, accessTokenPointer);
|
|
209
|
-
const accessToken = typeof accessTokenRaw === "string" ? accessTokenRaw : "";
|
|
210
|
-
const expiresInRaw = jsonpointer.get(tokenResJson, expiresInPointer);
|
|
211
|
-
const expiresInSecs = typeof expiresInRaw === "number" ? expiresInRaw : 600;
|
|
212
|
-
const now = new Date();
|
|
213
|
-
const expiresAt = new Date(now.getTime() + expiresInSecs * 1000);
|
|
214
|
-
return { accessToken, expiresAt };
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
applyAuth(cfg) {
|
|
218
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
if (this.props.form && !this.accessToken) {
|
|
220
|
-
const { accessToken, expiresAt } = yield this.refresh(this.props.form);
|
|
221
|
-
this.accessToken = accessToken;
|
|
222
|
-
this.expiresAt = expiresAt;
|
|
223
|
-
}
|
|
224
|
-
this.props.requestMutator.setValue(this.accessToken);
|
|
225
|
-
return yield this.props.requestMutator.applyAuth(cfg);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
setValue(val) {
|
|
229
|
-
throw "an OAuth2 auth provider can not a requestMutator";
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.OAuth2 = OAuth2;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BinaryResponse = void 0;
|
|
4
|
-
class BinaryResponse {
|
|
5
|
-
constructor(content, contentType) {
|
|
6
|
-
this.content = content;
|
|
7
|
-
this.contentType = contentType;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.BinaryResponse = BinaryResponse;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.URL_FORM = exports.MULTIPART_FORM = exports.TEXT_PATTERN = exports.JSON_PATTERN = void 0;
|
|
4
|
-
// use a pattern to match json content type to handle
|
|
5
|
-
// base case of application/json as well as vendor specific
|
|
6
|
-
// headers e.g. application/vnd.github+json
|
|
7
|
-
exports.JSON_PATTERN = /^application\/(.+\+)?json/;
|
|
8
|
-
// use a pattern to match text types to handle base case
|
|
9
|
-
// of text/plain as well as more specific cases e.g. text/html
|
|
10
|
-
exports.TEXT_PATTERN = /^text\/(.+)/;
|
|
11
|
-
exports.MULTIPART_FORM = "multipart/form-data";
|
|
12
|
-
exports.URL_FORM = "application/x-www-form-urlencoded";
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type * as z from "zod";
|
|
2
|
-
import type { Response as NodeResponse } from "node-fetch";
|
|
3
|
-
import type { AuthProvider } from "./auth";
|
|
4
|
-
import { ApiPromise } from "./api-promise";
|
|
5
|
-
import { type QueryStyle } from "./query";
|
|
6
|
-
export interface CoreClientProps {
|
|
7
|
-
baseUrl: string | Record<string, string | undefined>;
|
|
8
|
-
timeout?: number | undefined;
|
|
9
|
-
auths?: Record<string, AuthProvider>;
|
|
10
|
-
}
|
|
11
|
-
export type ApiResponse = Response | NodeResponse;
|
|
12
|
-
export type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
13
|
-
export type RequestConfig = {
|
|
14
|
-
method: HttpMethod;
|
|
15
|
-
path: string;
|
|
16
|
-
serviceName?: string | undefined;
|
|
17
|
-
responseSchema?: z.Schema;
|
|
18
|
-
responseStream?: boolean;
|
|
19
|
-
responseRaw?: boolean;
|
|
20
|
-
auth?: string[];
|
|
21
|
-
query?: string[];
|
|
22
|
-
body?: any;
|
|
23
|
-
bodyEncoding?: {
|
|
24
|
-
style?: Record<string, QueryStyle>;
|
|
25
|
-
explode?: Record<string, boolean>;
|
|
26
|
-
};
|
|
27
|
-
contentType?: string;
|
|
28
|
-
headers?: Record<string, string>;
|
|
29
|
-
opts?: RequestOptions | undefined;
|
|
30
|
-
withCredentials?: boolean;
|
|
31
|
-
};
|
|
32
|
-
export interface RequestOptions {
|
|
33
|
-
timeout?: number;
|
|
34
|
-
additionalHeaders?: Record<string, string>;
|
|
35
|
-
additionalQuery?: Record<string, string>;
|
|
36
|
-
}
|
|
37
|
-
export declare class CoreClient {
|
|
38
|
-
private baseUrl;
|
|
39
|
-
private auths;
|
|
40
|
-
private timeout;
|
|
41
|
-
constructor(props: CoreClientProps);
|
|
42
|
-
private applyAuths;
|
|
43
|
-
buildUrl(path: string, serviceName?: string): string;
|
|
44
|
-
private buildUrlFromCfg;
|
|
45
|
-
private applyHeaders;
|
|
46
|
-
private encodeBodyByContentType;
|
|
47
|
-
private buildRequestInit;
|
|
48
|
-
private request;
|
|
49
|
-
makeRequest<R>(cfg: RequestConfig): ApiPromise<R>;
|
|
50
|
-
}
|
|
51
|
-
export interface ResourceClientOptions {
|
|
52
|
-
lazyLoad?: boolean | undefined;
|
|
53
|
-
}
|
|
54
|
-
export declare class CoreResourceClient {
|
|
55
|
-
protected _client: CoreClient;
|
|
56
|
-
protected _opts: ResourceClientOptions;
|
|
57
|
-
constructor(client: CoreClient, opts: ResourceClientOptions);
|
|
58
|
-
}
|
package/dist/core/core-client.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CoreResourceClient = exports.CoreClient = void 0;
|
|
13
|
-
const runtime_1 = require("./runtime");
|
|
14
|
-
const api_promise_1 = require("./api-promise");
|
|
15
|
-
const api_error_1 = require("./api-error");
|
|
16
|
-
const form_data_1 = require("./form-data");
|
|
17
|
-
const query_1 = require("./query");
|
|
18
|
-
const content_type_1 = require("./content-type");
|
|
19
|
-
const _DEFAULT_SERVICE_NAME = "__default_service__";
|
|
20
|
-
class CoreClient {
|
|
21
|
-
constructor(props) {
|
|
22
|
-
var _a;
|
|
23
|
-
this.baseUrl =
|
|
24
|
-
typeof props.baseUrl === "string"
|
|
25
|
-
? { [_DEFAULT_SERVICE_NAME]: props.baseUrl }
|
|
26
|
-
: props.baseUrl;
|
|
27
|
-
this.auths = (_a = props.auths) !== null && _a !== void 0 ? _a : {};
|
|
28
|
-
this.timeout = props.timeout;
|
|
29
|
-
}
|
|
30
|
-
applyAuths(cfg) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
var _a;
|
|
33
|
-
for (const name of (_a = cfg.auth) !== null && _a !== void 0 ? _a : []) {
|
|
34
|
-
const provider = this.auths[name];
|
|
35
|
-
if (provider) {
|
|
36
|
-
cfg = yield provider.applyAuth(cfg);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return cfg;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
buildUrl(path, serviceName = _DEFAULT_SERVICE_NAME) {
|
|
43
|
-
var _a;
|
|
44
|
-
const baseUrl = (_a = this.baseUrl[serviceName !== null && serviceName !== void 0 ? serviceName : _DEFAULT_SERVICE_NAME]) !== null && _a !== void 0 ? _a : "";
|
|
45
|
-
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
46
|
-
const cleanPath = path.startsWith("/") ? path.slice(1) : path;
|
|
47
|
-
return `${base}/${cleanPath}`;
|
|
48
|
-
}
|
|
49
|
-
buildUrlFromCfg(cfg) {
|
|
50
|
-
var _a, _b, _c;
|
|
51
|
-
let url = this.buildUrl(cfg.path, cfg.serviceName);
|
|
52
|
-
const searchParams = new URLSearchParams(((_a = cfg.query) !== null && _a !== void 0 ? _a : []).join("&"));
|
|
53
|
-
for (const [key, val] of Object.entries((_c = (_b = cfg.opts) === null || _b === void 0 ? void 0 : _b.additionalQuery) !== null && _c !== void 0 ? _c : {})) {
|
|
54
|
-
searchParams.append(key, val);
|
|
55
|
-
}
|
|
56
|
-
if (searchParams.toString().length > 0) {
|
|
57
|
-
url += `?${searchParams.toString()}`;
|
|
58
|
-
}
|
|
59
|
-
return url;
|
|
60
|
-
}
|
|
61
|
-
applyHeaders(cfg, reqInit) {
|
|
62
|
-
var _a, _b, _c;
|
|
63
|
-
const finalHeaders = Object.assign(Object.assign(Object.assign(Object.assign({ "x-sideko-sdk-language": "Javascript", "x-sideko-runtime": runtime_1.RUNTIME.type }, ((_a = reqInit.headers) !== null && _a !== void 0 ? _a : {})), ((_b = cfg.headers) !== null && _b !== void 0 ? _b : {})), (cfg.contentType ? { "content-type": cfg.contentType } : {})), (_c = cfg.opts) === null || _c === void 0 ? void 0 : _c.additionalHeaders);
|
|
64
|
-
reqInit.headers = finalHeaders;
|
|
65
|
-
return reqInit;
|
|
66
|
-
}
|
|
67
|
-
encodeBodyByContentType(cfg, reqInit) {
|
|
68
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
69
|
-
const contentTypeOverride = (_c = (_b = (_a = cfg.opts) === null || _a === void 0 ? void 0 : _a.additionalHeaders) === null || _b === void 0 ? void 0 : _b["content-type"]) !== null && _c !== void 0 ? _c : (_e = (_d = cfg.opts) === null || _d === void 0 ? void 0 : _d.additionalHeaders) === null || _e === void 0 ? void 0 : _e["Content-Type"];
|
|
70
|
-
const contentType = (_f = contentTypeOverride !== null && contentTypeOverride !== void 0 ? contentTypeOverride : cfg.contentType) !== null && _f !== void 0 ? _f : "";
|
|
71
|
-
if (typeof cfg.body === "undefined") {
|
|
72
|
-
return reqInit;
|
|
73
|
-
}
|
|
74
|
-
else if (contentType.match(content_type_1.JSON_PATTERN)) {
|
|
75
|
-
reqInit.body = JSON.stringify(cfg.body);
|
|
76
|
-
}
|
|
77
|
-
else if (contentType.match(content_type_1.TEXT_PATTERN)) {
|
|
78
|
-
reqInit.body = String(cfg.body);
|
|
79
|
-
}
|
|
80
|
-
else if (contentType === content_type_1.MULTIPART_FORM) {
|
|
81
|
-
// encode form
|
|
82
|
-
const form = (0, form_data_1.createForm)(cfg.body);
|
|
83
|
-
const headers = (_g = reqInit.headers) !== null && _g !== void 0 ? _g : {};
|
|
84
|
-
if (runtime_1.RUNTIME.type === "node") {
|
|
85
|
-
// explicitly set boundary
|
|
86
|
-
headers["content-type"] = `${content_type_1.MULTIPART_FORM}; boundary=${form.getBoundary()}`;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// the browser should automatically set the content type
|
|
90
|
-
delete headers["content-type"];
|
|
91
|
-
}
|
|
92
|
-
reqInit.headers = headers;
|
|
93
|
-
reqInit.body = form;
|
|
94
|
-
}
|
|
95
|
-
else if (contentType === content_type_1.URL_FORM) {
|
|
96
|
-
if (typeof cfg.body !== "object") {
|
|
97
|
-
throw new TypeError("x-www-form-urlencoded data must be an object at the top level");
|
|
98
|
-
}
|
|
99
|
-
// encode form data
|
|
100
|
-
const styleMap = (_j = (_h = cfg.bodyEncoding) === null || _h === void 0 ? void 0 : _h.style) !== null && _j !== void 0 ? _j : {};
|
|
101
|
-
const explodeMap = (_l = (_k = cfg.bodyEncoding) === null || _k === void 0 ? void 0 : _k.explode) !== null && _l !== void 0 ? _l : {};
|
|
102
|
-
const formData = Object.entries(cfg.body).map(([name, value]) => {
|
|
103
|
-
var _a, _b;
|
|
104
|
-
const style = (_a = styleMap[name]) !== null && _a !== void 0 ? _a : "form";
|
|
105
|
-
const explode = (_b = explodeMap[name]) !== null && _b !== void 0 ? _b : style === "form";
|
|
106
|
-
return (0, query_1.encodeQueryParam)({ name, value, style, explode });
|
|
107
|
-
});
|
|
108
|
-
reqInit.body = formData.join("&");
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
// we expect body to already be encoded in the correct fashion
|
|
112
|
-
reqInit.body = cfg.body;
|
|
113
|
-
}
|
|
114
|
-
return reqInit;
|
|
115
|
-
}
|
|
116
|
-
buildRequestInit(cfg) {
|
|
117
|
-
let reqInit = { method: cfg.method.toUpperCase() };
|
|
118
|
-
reqInit = this.applyHeaders(cfg, reqInit);
|
|
119
|
-
reqInit = this.encodeBodyByContentType(cfg, reqInit);
|
|
120
|
-
if (cfg.withCredentials) {
|
|
121
|
-
reqInit.credentials = "include";
|
|
122
|
-
}
|
|
123
|
-
return reqInit;
|
|
124
|
-
}
|
|
125
|
-
request(cfg) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
var _a, _b;
|
|
128
|
-
const fetcherFn = runtime_1.RUNTIME.type === "node" || typeof fetch !== "function"
|
|
129
|
-
? require("node-fetch").default
|
|
130
|
-
: fetch;
|
|
131
|
-
cfg = yield this.applyAuths(cfg);
|
|
132
|
-
const reqInit = this.buildRequestInit(cfg);
|
|
133
|
-
const url = this.buildUrlFromCfg(cfg);
|
|
134
|
-
const timeout = (_b = (_a = cfg.opts) === null || _a === void 0 ? void 0 : _a.timeout) !== null && _b !== void 0 ? _b : this.timeout;
|
|
135
|
-
const controller = new AbortController();
|
|
136
|
-
let timeoutId;
|
|
137
|
-
if (typeof timeout !== "undefined") {
|
|
138
|
-
timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
139
|
-
}
|
|
140
|
-
reqInit.signal = controller.signal;
|
|
141
|
-
const response = yield fetcherFn(url, reqInit);
|
|
142
|
-
if (timeoutId) {
|
|
143
|
-
clearTimeout(timeoutId);
|
|
144
|
-
}
|
|
145
|
-
if (!response.ok) {
|
|
146
|
-
throw new api_error_1.ApiError(cfg, response);
|
|
147
|
-
}
|
|
148
|
-
return response;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
makeRequest(cfg) {
|
|
152
|
-
var _a, _b;
|
|
153
|
-
return new api_promise_1.ApiPromise({
|
|
154
|
-
responsePromise: this.request(cfg),
|
|
155
|
-
responseRaw: (_a = cfg.responseRaw) !== null && _a !== void 0 ? _a : false,
|
|
156
|
-
responseStream: (_b = cfg.responseStream) !== null && _b !== void 0 ? _b : false,
|
|
157
|
-
responseSchema: cfg.responseSchema,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
exports.CoreClient = CoreClient;
|
|
162
|
-
class CoreResourceClient {
|
|
163
|
-
constructor(client, opts) {
|
|
164
|
-
this._client = client;
|
|
165
|
-
this._opts = opts;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
exports.CoreResourceClient = CoreResourceClient;
|
package/dist/core/form-data.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ReadStream as NodeReadStream } from "node:fs";
|
|
2
|
-
export type UploadFile = FileLike | NodeReadStream;
|
|
3
|
-
export declare function isUploadFile(val: any): val is UploadFile;
|
|
4
|
-
export declare function isNodeReadStream(val: any): val is NodeReadStream;
|
|
5
|
-
/**
|
|
6
|
-
* Defines common File spec compatible with modern browser File, node-fetch, etc.
|
|
7
|
-
*/
|
|
8
|
-
export interface FileLike extends BlobLike {
|
|
9
|
-
lastModified: number;
|
|
10
|
-
name: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function isFileLike(val: any): val is FileLike;
|
|
13
|
-
/**
|
|
14
|
-
* Defines common Blob spec compatible with modern browser Blob, fetch-blob, etc.
|
|
15
|
-
*/
|
|
16
|
-
export interface BlobLike {
|
|
17
|
-
type: string;
|
|
18
|
-
size: number;
|
|
19
|
-
slice(start?: number, end?: number, type?: string): BlobLike;
|
|
20
|
-
text(): Promise<string>;
|
|
21
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
22
|
-
}
|
|
23
|
-
export declare function isBlobLike(val: any): val is BlobLike;
|
|
24
|
-
export declare function createForm(data: {
|
|
25
|
-
[key: string]: unknown;
|
|
26
|
-
}): any;
|