@mapcreator/api 3.3.6 → 5.0.0-alpha.100
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/LICENSE +29 -29
- package/README.md +86 -63
- package/cjs/api/apiCommon.d.ts +7 -0
- package/cjs/api/apiCommon.d.ts.map +1 -0
- package/cjs/api/apiCommon.js +31 -0
- package/cjs/api/apiCommon.js.map +1 -0
- package/cjs/api/choropleth.d.ts +138 -0
- package/cjs/api/choropleth.d.ts.map +1 -0
- package/cjs/api/choropleth.js +41 -0
- package/cjs/api/choropleth.js.map +1 -0
- package/cjs/api/color.d.ts +16 -0
- package/cjs/api/color.d.ts.map +1 -0
- package/cjs/api/color.js +8 -0
- package/cjs/api/color.js.map +1 -0
- package/cjs/api/dimension.d.ts +25 -0
- package/cjs/api/dimension.d.ts.map +1 -0
- package/cjs/api/dimension.js +14 -0
- package/cjs/api/dimension.js.map +1 -0
- package/cjs/api/dimensionSet.d.ts +15 -0
- package/cjs/api/dimensionSet.d.ts.map +1 -0
- package/cjs/api/dimensionSet.js +7 -0
- package/cjs/api/dimensionSet.js.map +1 -0
- package/cjs/api/feature.d.ts +16 -0
- package/cjs/api/feature.d.ts.map +1 -0
- package/cjs/api/feature.js +8 -0
- package/cjs/api/feature.js.map +1 -0
- package/cjs/api/font.d.ts +32 -0
- package/cjs/api/font.d.ts.map +1 -0
- package/cjs/api/font.js +15 -0
- package/cjs/api/font.js.map +1 -0
- package/cjs/api/fontFamily.d.ts +17 -0
- package/cjs/api/fontFamily.d.ts.map +1 -0
- package/cjs/api/fontFamily.js +17 -0
- package/cjs/api/fontFamily.js.map +1 -0
- package/cjs/api/geocode.d.ts +10 -0
- package/cjs/api/geocode.d.ts.map +1 -0
- package/cjs/api/geocode.js +9 -0
- package/cjs/api/geocode.js.map +1 -0
- package/cjs/api/highlight.d.ts +41 -0
- package/cjs/api/highlight.d.ts.map +1 -0
- package/cjs/api/highlight.js +25 -0
- package/cjs/api/highlight.js.map +1 -0
- package/cjs/api/insetMap.d.ts +37 -0
- package/cjs/api/insetMap.d.ts.map +1 -0
- package/cjs/api/insetMap.js +47 -0
- package/cjs/api/insetMap.js.map +1 -0
- package/cjs/api/job.d.ts +42 -0
- package/cjs/api/job.d.ts.map +1 -0
- package/cjs/api/job.js +71 -0
- package/cjs/api/job.js.map +1 -0
- package/cjs/api/jobResult.d.ts +40 -0
- package/cjs/api/jobResult.d.ts.map +1 -0
- package/cjs/api/jobResult.js +35 -0
- package/cjs/api/jobResult.js.map +1 -0
- package/cjs/api/jobRevision.d.ts +76 -0
- package/cjs/api/jobRevision.d.ts.map +1 -0
- package/cjs/api/jobRevision.js +126 -0
- package/cjs/api/jobRevision.js.map +1 -0
- package/cjs/api/jobShare.d.ts +26 -0
- package/cjs/api/jobShare.d.ts.map +1 -0
- package/cjs/api/jobShare.js +9 -0
- package/cjs/api/jobShare.js.map +1 -0
- package/cjs/api/jobType.d.ts +17 -0
- package/cjs/api/jobType.d.ts.map +1 -0
- package/cjs/api/jobType.js +11 -0
- package/cjs/api/jobType.js.map +1 -0
- package/cjs/api/language.d.ts +17 -0
- package/cjs/api/language.d.ts.map +1 -0
- package/cjs/api/language.js +3 -0
- package/cjs/api/language.js.map +1 -0
- package/cjs/api/layer.d.ts +26 -0
- package/cjs/api/layer.d.ts.map +1 -0
- package/cjs/api/layer.js +14 -0
- package/cjs/api/layer.js.map +1 -0
- package/cjs/api/layerFaq.d.ts +27 -0
- package/cjs/api/layerFaq.d.ts.map +1 -0
- package/cjs/api/layerFaq.js +16 -0
- package/cjs/api/layerFaq.js.map +1 -0
- package/cjs/api/layerGroup.d.ts +16 -0
- package/cjs/api/layerGroup.d.ts.map +1 -0
- package/cjs/api/layerGroup.js +36 -0
- package/cjs/api/layerGroup.js.map +1 -0
- package/cjs/api/mapstyleSet.d.ts +32 -0
- package/cjs/api/mapstyleSet.d.ts.map +1 -0
- package/cjs/api/mapstyleSet.js +28 -0
- package/cjs/api/mapstyleSet.js.map +1 -0
- package/cjs/api/message.d.ts +32 -0
- package/cjs/api/message.d.ts.map +1 -0
- package/cjs/api/message.js +37 -0
- package/cjs/api/message.js.map +1 -0
- package/cjs/api/organisation.d.ts +41 -0
- package/cjs/api/organisation.d.ts.map +1 -0
- package/cjs/api/organisation.js +41 -0
- package/cjs/api/organisation.js.map +1 -0
- package/cjs/api/resources.d.ts +65 -0
- package/cjs/api/resources.d.ts.map +1 -0
- package/cjs/api/resources.js +61 -0
- package/cjs/api/resources.js.map +1 -0
- package/cjs/api/svg.d.ts +21 -0
- package/cjs/api/svg.d.ts.map +1 -0
- package/cjs/api/svg.js +15 -0
- package/cjs/api/svg.js.map +1 -0
- package/cjs/api/svgSet.d.ts +22 -0
- package/cjs/api/svgSet.d.ts.map +1 -0
- package/cjs/api/svgSet.js +25 -0
- package/cjs/api/svgSet.js.map +1 -0
- package/cjs/api/user.d.ts +129 -0
- package/cjs/api/user.d.ts.map +1 -0
- package/cjs/api/user.js +145 -0
- package/cjs/api/user.js.map +1 -0
- package/cjs/index.d.ts +28 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +53 -0
- package/cjs/index.js.map +1 -0
- package/cjs/oauth.d.ts +31 -0
- package/cjs/oauth.d.ts.map +1 -0
- package/cjs/oauth.js +76 -0
- package/cjs/oauth.js.map +1 -0
- package/cjs/utils.d.ts +72 -0
- package/cjs/utils.d.ts.map +1 -0
- package/cjs/utils.js +220 -0
- package/cjs/utils.js.map +1 -0
- package/esm/api/apiCommon.d.ts +7 -0
- package/esm/api/apiCommon.d.ts.map +1 -0
- package/esm/api/apiCommon.js +28 -0
- package/esm/api/apiCommon.js.map +1 -0
- package/esm/api/choropleth.d.ts +138 -0
- package/esm/api/choropleth.d.ts.map +1 -0
- package/esm/api/choropleth.js +34 -0
- package/esm/api/choropleth.js.map +1 -0
- package/esm/api/color.d.ts +16 -0
- package/esm/api/color.d.ts.map +1 -0
- package/esm/api/color.js +5 -0
- package/esm/api/color.js.map +1 -0
- package/esm/api/dimension.d.ts +25 -0
- package/esm/api/dimension.d.ts.map +1 -0
- package/esm/api/dimension.js +11 -0
- package/esm/api/dimension.js.map +1 -0
- package/esm/api/dimensionSet.d.ts +15 -0
- package/esm/api/dimensionSet.d.ts.map +1 -0
- package/esm/api/dimensionSet.js +4 -0
- package/esm/api/dimensionSet.js.map +1 -0
- package/esm/api/feature.d.ts +16 -0
- package/esm/api/feature.d.ts.map +1 -0
- package/esm/api/feature.js +5 -0
- package/esm/api/feature.js.map +1 -0
- package/esm/api/font.d.ts +32 -0
- package/esm/api/font.d.ts.map +1 -0
- package/esm/api/font.js +11 -0
- package/esm/api/font.js.map +1 -0
- package/esm/api/fontFamily.d.ts +17 -0
- package/esm/api/fontFamily.d.ts.map +1 -0
- package/esm/api/fontFamily.js +13 -0
- package/esm/api/fontFamily.js.map +1 -0
- package/esm/api/geocode.d.ts +10 -0
- package/esm/api/geocode.d.ts.map +1 -0
- package/esm/api/geocode.js +6 -0
- package/esm/api/geocode.js.map +1 -0
- package/esm/api/highlight.d.ts +41 -0
- package/esm/api/highlight.d.ts.map +1 -0
- package/esm/api/highlight.js +21 -0
- package/esm/api/highlight.js.map +1 -0
- package/esm/api/insetMap.d.ts +37 -0
- package/esm/api/insetMap.d.ts.map +1 -0
- package/esm/api/insetMap.js +42 -0
- package/esm/api/insetMap.js.map +1 -0
- package/esm/api/job.d.ts +42 -0
- package/esm/api/job.d.ts.map +1 -0
- package/esm/api/job.js +59 -0
- package/esm/api/job.js.map +1 -0
- package/esm/api/jobResult.d.ts +40 -0
- package/esm/api/jobResult.d.ts.map +1 -0
- package/esm/api/jobResult.js +30 -0
- package/esm/api/jobResult.js.map +1 -0
- package/esm/api/jobRevision.d.ts +76 -0
- package/esm/api/jobRevision.d.ts.map +1 -0
- package/esm/api/jobRevision.js +114 -0
- package/esm/api/jobRevision.js.map +1 -0
- package/esm/api/jobShare.d.ts +26 -0
- package/esm/api/jobShare.d.ts.map +1 -0
- package/esm/api/jobShare.js +6 -0
- package/esm/api/jobShare.js.map +1 -0
- package/esm/api/jobType.d.ts +17 -0
- package/esm/api/jobType.d.ts.map +1 -0
- package/esm/api/jobType.js +8 -0
- package/esm/api/jobType.js.map +1 -0
- package/esm/api/language.d.ts +17 -0
- package/esm/api/language.d.ts.map +1 -0
- package/esm/api/language.js +2 -0
- package/esm/api/language.js.map +1 -0
- package/esm/api/layer.d.ts +26 -0
- package/esm/api/layer.d.ts.map +1 -0
- package/esm/api/layer.js +11 -0
- package/esm/api/layer.js.map +1 -0
- package/esm/api/layerFaq.d.ts +27 -0
- package/esm/api/layerFaq.d.ts.map +1 -0
- package/esm/api/layerFaq.js +12 -0
- package/esm/api/layerFaq.js.map +1 -0
- package/esm/api/layerGroup.d.ts +16 -0
- package/esm/api/layerGroup.d.ts.map +1 -0
- package/esm/api/layerGroup.js +33 -0
- package/esm/api/layerGroup.js.map +1 -0
- package/esm/api/mapstyleSet.d.ts +32 -0
- package/esm/api/mapstyleSet.d.ts.map +1 -0
- package/esm/api/mapstyleSet.js +24 -0
- package/esm/api/mapstyleSet.js.map +1 -0
- package/esm/api/message.d.ts +32 -0
- package/esm/api/message.d.ts.map +1 -0
- package/esm/api/message.js +32 -0
- package/esm/api/message.js.map +1 -0
- package/esm/api/organisation.d.ts +41 -0
- package/esm/api/organisation.d.ts.map +1 -0
- package/esm/api/organisation.js +35 -0
- package/esm/api/organisation.js.map +1 -0
- package/esm/api/resources.d.ts +65 -0
- package/esm/api/resources.d.ts.map +1 -0
- package/esm/api/resources.js +55 -0
- package/esm/api/resources.js.map +1 -0
- package/esm/api/svg.d.ts +21 -0
- package/esm/api/svg.d.ts.map +1 -0
- package/esm/api/svg.js +11 -0
- package/esm/api/svg.js.map +1 -0
- package/esm/api/svgSet.d.ts +22 -0
- package/esm/api/svgSet.d.ts.map +1 -0
- package/esm/api/svgSet.js +21 -0
- package/esm/api/svgSet.js.map +1 -0
- package/esm/api/user.d.ts +129 -0
- package/esm/api/user.d.ts.map +1 -0
- package/esm/api/user.js +126 -0
- package/esm/api/user.js.map +1 -0
- package/esm/index.d.ts +28 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +28 -0
- package/esm/index.js.map +1 -0
- package/esm/oauth.d.ts +31 -0
- package/esm/oauth.d.ts.map +1 -0
- package/esm/oauth.js +68 -0
- package/esm/oauth.js.map +1 -0
- package/esm/utils.d.ts +72 -0
- package/esm/utils.d.ts.map +1 -0
- package/esm/utils.js +206 -0
- package/esm/utils.js.map +1 -0
- package/package.json +80 -148
- package/src/README.md +126 -0
- package/src/api/apiCommon.ts +70 -0
- package/src/api/choropleth.ts +228 -0
- package/src/api/color.ts +22 -0
- package/src/api/dimension.ts +44 -0
- package/src/api/dimensionSet.ts +20 -0
- package/src/api/feature.ts +22 -0
- package/src/api/font.ts +57 -0
- package/src/api/fontFamily.ts +43 -0
- package/src/api/geocode.ts +17 -0
- package/src/api/highlight.ts +87 -0
- package/src/api/insetMap.ts +95 -0
- package/src/api/job.ts +130 -0
- package/src/api/jobResult.ts +95 -0
- package/src/api/jobRevision.ts +281 -0
- package/src/api/jobShare.ts +35 -0
- package/src/api/jobType.ts +26 -0
- package/src/api/language.ts +19 -0
- package/src/api/layer.ts +38 -0
- package/src/api/layerFaq.ts +53 -0
- package/src/api/layerGroup.ts +69 -0
- package/src/api/mapstyleSet.ts +70 -0
- package/src/api/message.ts +80 -0
- package/src/api/organisation.ts +97 -0
- package/src/api/resources.ts +153 -0
- package/src/api/svg.ts +33 -0
- package/src/api/svgSet.ts +56 -0
- package/src/api/user.ts +327 -0
- package/src/index.ts +44 -0
- package/src/oauth.ts +90 -0
- package/src/utils.ts +342 -0
- package/dist/ImageHandler.d.ts +0 -56
- package/dist/Mapcreator.d.ts +0 -338
- package/dist/PaginatedResourceListing.d.ts +0 -156
- package/dist/RequestParameters.d.ts +0 -241
- package/dist/ResourceLister.d.ts +0 -155
- package/dist/bundle.browser.js +0 -14711
- package/dist/bundle.browser.min.js +0 -3
- package/dist/bundle.browser.min.js.LICENSE.txt +0 -74
- package/dist/bundle.js +0 -12876
- package/dist/bundle.min.js +0 -3
- package/dist/bundle.min.js.LICENSE.txt +0 -44
- package/dist/enums/DeletedState.d.ts +0 -16
- package/dist/enums/Enum.d.ts +0 -40
- package/dist/enums/JobShareVisibility.d.ts +0 -15
- package/dist/enums/ResultStatus.d.ts +0 -17
- package/dist/enums/index.d.ts +0 -5
- package/dist/errors/AbstractError.d.ts +0 -26
- package/dist/errors/ApiError.d.ts +0 -65
- package/dist/errors/GeoError.d.ts +0 -6
- package/dist/errors/NodeError.d.ts +0 -6
- package/dist/errors/OAuthError.d.ts +0 -17
- package/dist/errors/StaticClassError.d.ts +0 -7
- package/dist/errors/ValidationError.d.ts +0 -125
- package/dist/errors/index.d.ts +0 -8
- package/dist/index.d.ts +0 -28
- package/dist/oauth/CookieFlow.d.ts +0 -25
- package/dist/oauth/DummyFlow.d.ts +0 -19
- package/dist/oauth/ImplicitFlow.d.ts +0 -68
- package/dist/oauth/ImplicitFlowPopup.d.ts +0 -25
- package/dist/oauth/OAuth.d.ts +0 -50
- package/dist/oauth/OAuthToken.d.ts +0 -67
- package/dist/oauth/PasswordFlow.d.ts +0 -56
- package/dist/oauth/StateContainer.d.ts +0 -36
- package/dist/proxy/GeoResourceProxy.d.ts +0 -69
- package/dist/proxy/OrganisationProxy.d.ts +0 -62
- package/dist/proxy/OwnedResourceProxy.d.ts +0 -60
- package/dist/proxy/ResourceProxy.d.ts +0 -32
- package/dist/proxy/SimpleResourceProxy.d.ts +0 -76
- package/dist/proxy/index.d.ts +0 -6
- package/dist/resources/Choropleth.d.ts +0 -20
- package/dist/resources/Color.d.ts +0 -9
- package/dist/resources/Contract.d.ts +0 -7
- package/dist/resources/Dimension.d.ts +0 -7
- package/dist/resources/DimensionSet.d.ts +0 -11
- package/dist/resources/Domain.d.ts +0 -7
- package/dist/resources/Faq.d.ts +0 -7
- package/dist/resources/Feature.d.ts +0 -9
- package/dist/resources/Font.d.ts +0 -4
- package/dist/resources/FontFamily.d.ts +0 -11
- package/dist/resources/Highlight.d.ts +0 -4
- package/dist/resources/InsetMap.d.ts +0 -10
- package/dist/resources/Job.d.ts +0 -56
- package/dist/resources/JobResult.d.ts +0 -76
- package/dist/resources/JobRevision.d.ts +0 -64
- package/dist/resources/JobShare.d.ts +0 -15
- package/dist/resources/JobType.d.ts +0 -9
- package/dist/resources/Language.d.ts +0 -4
- package/dist/resources/Layer.d.ts +0 -10
- package/dist/resources/LayerFaq.d.ts +0 -8
- package/dist/resources/LayerGroup.d.ts +0 -14
- package/dist/resources/Mapstyle.d.ts +0 -8
- package/dist/resources/MapstyleSet.d.ts +0 -13
- package/dist/resources/MapstyleSetColor.d.ts +0 -8
- package/dist/resources/Message.d.ts +0 -7
- package/dist/resources/MessageVariant.d.ts +0 -4
- package/dist/resources/Notification.d.ts +0 -4
- package/dist/resources/Organisation.d.ts +0 -99
- package/dist/resources/OrganisationNote.d.ts +0 -17
- package/dist/resources/Permission.d.ts +0 -4
- package/dist/resources/ProductTour.d.ts +0 -10
- package/dist/resources/ProductTourStep.d.ts +0 -7
- package/dist/resources/Role.d.ts +0 -14
- package/dist/resources/Svg.d.ts +0 -4
- package/dist/resources/SvgSet.d.ts +0 -11
- package/dist/resources/Tag.d.ts +0 -9
- package/dist/resources/TagType.d.ts +0 -13
- package/dist/resources/User.d.ts +0 -119
- package/dist/resources/VectorChoropleth.d.ts +0 -4
- package/dist/resources/VectorHighlight.d.ts +0 -4
- package/dist/resources/base/CrudBase.d.ts +0 -66
- package/dist/resources/base/CrudBase.d.ts.map +0 -1
- package/dist/resources/base/CrudSetBase.d.ts +0 -27
- package/dist/resources/base/CrudSetBase.d.ts.map +0 -1
- package/dist/resources/base/CrudSetItemBase.d.ts +0 -19
- package/dist/resources/base/CrudSetItemBase.d.ts.map +0 -1
- package/dist/resources/base/DownloadedResource.d.ts +0 -72
- package/dist/resources/base/DownloadedResource.d.ts.map +0 -1
- package/dist/resources/base/ResourceBase.d.ts +0 -164
- package/dist/resources/base/ResourceBase.d.ts.map +0 -1
- package/dist/resources/index.d.ts +0 -47
- package/dist/storage/CookiesDriver.d.ts +0 -37
- package/dist/storage/DataStoreContract.d.ts +0 -46
- package/dist/storage/DummyDriver.d.ts +0 -15
- package/dist/storage/FileDriver.d.ts +0 -54
- package/dist/storage/LocalStorageDriver.d.ts +0 -13
- package/dist/storage/StorageManager.d.ts +0 -46
- package/dist/traits/HandlesImages.d.ts +0 -15
- package/dist/traits/Injectable.d.ts +0 -60
- package/dist/traits/OwnableResource.d.ts +0 -18
- package/dist/traits/Trait.d.ts +0 -12
- package/dist/utils/Logger.d.ts +0 -55
- package/dist/utils/Singleton.d.ts +0 -9
- package/dist/utils/StaticClass.d.ts +0 -7
- package/dist/utils/Unobservable.d.ts +0 -13
- package/dist/utils/base64.d.ts +0 -12
- package/dist/utils/geo.d.ts +0 -74
- package/dist/utils/hash.d.ts +0 -15
- package/dist/utils/helpers.d.ts +0 -47
- package/dist/utils/node.d.ts +0 -15
- package/dist/utils/reflection.d.ts +0 -43
- package/dist/utils/requests.d.ts +0 -24
- package/dist/utils/uuid.d.ts +0 -19
- package/manual/assets/maps4news.svg +0 -23
- package/manual/building.md +0 -19
- package/manual/css/hide_import.css +0 -3
- package/manual/css/sidebar_fix.css +0 -3
- package/manual/examples.authentication.md +0 -205
- package/manual/examples.md +0 -153
- package/manual/installation.md +0 -33
- package/manual/js/sandbox.js +0 -26
- package/src/ImageHandler.js +0 -134
- package/src/Mapcreator.js +0 -719
- package/src/PaginatedResourceListing.js +0 -300
- package/src/RequestParameters.js +0 -711
- package/src/ResourceLister.js +0 -368
- package/src/enums/DeletedState.js +0 -49
- package/src/enums/Enum.js +0 -130
- package/src/enums/JobShareVisibility.js +0 -43
- package/src/enums/ResultStatus.js +0 -49
- package/src/enums/index.js +0 -36
- package/src/errors/AbstractError.js +0 -70
- package/src/errors/ApiError.js +0 -139
- package/src/errors/GeoError.js +0 -36
- package/src/errors/NodeError.js +0 -36
- package/src/errors/OAuthError.js +0 -71
- package/src/errors/StaticClassError.js +0 -37
- package/src/errors/ValidationError.js +0 -164
- package/src/errors/index.js +0 -39
- package/src/index.js +0 -76
- package/src/oauth/CookieFlow.js +0 -103
- package/src/oauth/DummyFlow.js +0 -63
- package/src/oauth/ImplicitFlow.js +0 -226
- package/src/oauth/ImplicitFlowPopup.js +0 -124
- package/src/oauth/OAuth.js +0 -131
- package/src/oauth/OAuthToken.js +0 -175
- package/src/oauth/PasswordFlow.js +0 -164
- package/src/oauth/StateContainer.js +0 -111
- package/src/proxy/GeoResourceProxy.js +0 -137
- package/src/proxy/OrganisationProxy.js +0 -149
- package/src/proxy/OwnedResourceProxy.js +0 -148
- package/src/proxy/ResourceProxy.js +0 -101
- package/src/proxy/SimpleResourceProxy.js +0 -188
- package/src/proxy/index.js +0 -37
- package/src/resources/Choropleth.js +0 -66
- package/src/resources/Color.js +0 -46
- package/src/resources/Contract.js +0 -42
- package/src/resources/Dimension.js +0 -42
- package/src/resources/DimensionSet.js +0 -56
- package/src/resources/Domain.js +0 -42
- package/src/resources/Faq.js +0 -42
- package/src/resources/Feature.js +0 -47
- package/src/resources/Font.js +0 -43
- package/src/resources/FontFamily.js +0 -55
- package/src/resources/Highlight.js +0 -39
- package/src/resources/InsetMap.js +0 -49
- package/src/resources/Job.js +0 -160
- package/src/resources/JobResult.js +0 -184
- package/src/resources/JobRevision.js +0 -201
- package/src/resources/JobShare.js +0 -61
- package/src/resources/JobType.js +0 -50
- package/src/resources/Language.js +0 -51
- package/src/resources/Layer.js +0 -48
- package/src/resources/LayerFaq.js +0 -47
- package/src/resources/LayerGroup.js +0 -57
- package/src/resources/Mapstyle.js +0 -45
- package/src/resources/MapstyleSet.js +0 -65
- package/src/resources/MapstyleSetColor.js +0 -51
- package/src/resources/Message.js +0 -94
- package/src/resources/MessageVariant.js +0 -37
- package/src/resources/Notification.js +0 -39
- package/src/resources/Organisation.js +0 -233
- package/src/resources/OrganisationNote.js +0 -57
- package/src/resources/Permission.js +0 -39
- package/src/resources/ProductTour.js +0 -53
- package/src/resources/ProductTourStep.js +0 -48
- package/src/resources/Role.js +0 -58
- package/src/resources/Svg.js +0 -39
- package/src/resources/SvgSet.js +0 -55
- package/src/resources/Tag.js +0 -50
- package/src/resources/TagType.js +0 -56
- package/src/resources/User.js +0 -251
- package/src/resources/VectorChoropleth.js +0 -40
- package/src/resources/VectorHighlight.js +0 -40
- package/src/resources/base/CrudBase.js +0 -204
- package/src/resources/base/CrudSetBase.js +0 -83
- package/src/resources/base/CrudSetItemBase.js +0 -82
- package/src/resources/base/DownloadedResource.js +0 -165
- package/src/resources/base/ResourceBase.js +0 -484
- package/src/resources/index.js +0 -81
- package/src/storage/CookiesDriver.js +0 -136
- package/src/storage/DataStoreContract.js +0 -111
- package/src/storage/DummyDriver.js +0 -91
- package/src/storage/FileDriver.js +0 -174
- package/src/storage/LocalStorageDriver.js +0 -108
- package/src/storage/StorageManager.js +0 -109
- package/src/traits/HandlesImages.js +0 -50
- package/src/traits/Injectable.js +0 -221
- package/src/traits/OwnableResource.js +0 -56
- package/src/traits/Trait.js +0 -43
- package/src/utils/Logger.js +0 -137
- package/src/utils/Singleton.js +0 -49
- package/src/utils/StaticClass.js +0 -43
- package/src/utils/Unobservable.js +0 -47
- package/src/utils/base64.js +0 -93
- package/src/utils/geo.js +0 -139
- package/src/utils/hash.js +0 -72
- package/src/utils/helpers.js +0 -178
- package/src/utils/node.js +0 -55
- package/src/utils/reflection.js +0 -170
- package/src/utils/requests.js +0 -120
- package/src/utils/uuid.js +0 -68
package/esm/utils.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { apiHost, authenticate, getAuthorizationHeaders, token } from './oauth.js';
|
|
2
|
+
export const myUser = 'me';
|
|
3
|
+
export const myOrganisations = 'mine';
|
|
4
|
+
export const lastJobRevision = 'last';
|
|
5
|
+
export const defaultListHeader = { 'X-Per-Page': '50' };
|
|
6
|
+
export const deletedNoneParam = getSearchParams({ deleted: 'none' });
|
|
7
|
+
export const keysToRemove = ['created_at', 'deleted_at', 'updated_at'];
|
|
8
|
+
export const staticContext = { keysToRemove: new Set(keysToRemove), keysToAdd: [], revivers: {} };
|
|
9
|
+
// class AuthorizationError extends Error {}
|
|
10
|
+
export class NetworkError extends Error {
|
|
11
|
+
}
|
|
12
|
+
export class HTTPError extends Error {
|
|
13
|
+
constructor(response) {
|
|
14
|
+
super(response.statusText);
|
|
15
|
+
this.statusCode = response.status;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class APIError extends Error {
|
|
19
|
+
constructor(apiError) {
|
|
20
|
+
super(apiError.error.message);
|
|
21
|
+
this.code = apiError.error.type;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function getSearchParams(search) {
|
|
25
|
+
return new URLSearchParams(Object.entries(search).reduce((arr, [key, value]) => {
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
arr.push(...value.map(val => [`${key}[]`, String(val)]));
|
|
28
|
+
}
|
|
29
|
+
else if (value !== null && typeof value === 'object') {
|
|
30
|
+
const params = getSearchParams(value);
|
|
31
|
+
arr.push(...Array.from(params.entries()).map(([subKey, val]) => [
|
|
32
|
+
~subKey.indexOf('[')
|
|
33
|
+
? `${key}[${subKey.slice(0, subKey.indexOf('['))}]${subKey.slice(subKey.indexOf('['))}`
|
|
34
|
+
: `${key}[${subKey}]`,
|
|
35
|
+
val,
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
arr.push([key, String(value)]);
|
|
40
|
+
}
|
|
41
|
+
return arr;
|
|
42
|
+
}, []));
|
|
43
|
+
}
|
|
44
|
+
export class APIMeta extends Error {
|
|
45
|
+
constructor(data, headers, status) {
|
|
46
|
+
super();
|
|
47
|
+
this.data = data;
|
|
48
|
+
this.status = status;
|
|
49
|
+
this.headers = headers;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function request(path, body, extraHeaders, extraOptions) {
|
|
53
|
+
const href = `${apiHost}${path}`;
|
|
54
|
+
const init = getRequestInit(body, extraHeaders, extraOptions);
|
|
55
|
+
const response = await fetch(href, init).catch((error) => {
|
|
56
|
+
var _a;
|
|
57
|
+
throw new NetworkError((_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error);
|
|
58
|
+
});
|
|
59
|
+
if (response.ok) {
|
|
60
|
+
const json = (await response.json().catch(() => ({
|
|
61
|
+
success: false,
|
|
62
|
+
error: { type: 'SyntaxError', message: 'Malformed JSON response' },
|
|
63
|
+
})));
|
|
64
|
+
if (json.success) {
|
|
65
|
+
const { data } = json;
|
|
66
|
+
const withMeta = extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.withMeta;
|
|
67
|
+
const revivers = extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.revivers;
|
|
68
|
+
const keys = revivers ? Object.keys(revivers) : [];
|
|
69
|
+
const context = revivers && keys.length
|
|
70
|
+
? getContext(revivers, keys)
|
|
71
|
+
: staticContext;
|
|
72
|
+
let result;
|
|
73
|
+
if (Array.isArray(data)) {
|
|
74
|
+
let moreData = [];
|
|
75
|
+
const headers = response.headers;
|
|
76
|
+
// @ts-expect-error TS2362, get valid number or 0
|
|
77
|
+
const total = headers.get('X-Paginate-Total') | 0;
|
|
78
|
+
if (!withMeta && ((data.length && total > data.length) || response.status === 206)) {
|
|
79
|
+
// @ts-expect-error TS2362, get valid number or 0
|
|
80
|
+
const offset = `${(headers.get('X-Paginate-Offset') | 0) + data.length}`;
|
|
81
|
+
moreData = await request(path, body, Object.assign(Object.assign({}, extraHeaders), { 'X-Offset': offset }), extraOptions);
|
|
82
|
+
}
|
|
83
|
+
if (data.length) {
|
|
84
|
+
result = (typeof data[0] !== 'string'
|
|
85
|
+
? data.map(processData, context)
|
|
86
|
+
: data).concat(moreData);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
result = moreData;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (data !== undefined) {
|
|
94
|
+
// @ts-expect-error TS2345, TODO: fix type error for the `context` object
|
|
95
|
+
result = (typeof data !== 'string' ? processData.call(context, data) : data);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
result = {};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (withMeta) {
|
|
102
|
+
throw new APIMeta(result, response.headers, response.status);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
throw new APIError(json);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// TODO: parse and process all typical errors
|
|
112
|
+
// eslint-disable-next-line default-case
|
|
113
|
+
switch (response.status) {
|
|
114
|
+
case 401:
|
|
115
|
+
await authenticate();
|
|
116
|
+
break; // NO-OP
|
|
117
|
+
case 403:
|
|
118
|
+
case 404:
|
|
119
|
+
case 406:
|
|
120
|
+
throw new APIError((await response.json().catch(() => ({
|
|
121
|
+
success: false,
|
|
122
|
+
error: { type: 'HttpException', message: response.statusText },
|
|
123
|
+
}))));
|
|
124
|
+
case 429:
|
|
125
|
+
await new Promise((resolve) => { setTimeout(resolve, response.headers.get('X-RateLimit-Reset') * 1000 || 500); });
|
|
126
|
+
return request(path, body, extraHeaders, extraOptions);
|
|
127
|
+
}
|
|
128
|
+
throw new HTTPError(response);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function getRequestInit(body, extraHeaders, extraOptions) {
|
|
132
|
+
var _a;
|
|
133
|
+
let contentType = null;
|
|
134
|
+
if (body !== undefined) {
|
|
135
|
+
switch (true) {
|
|
136
|
+
case typeof body === 'string':
|
|
137
|
+
contentType = { 'Content-Type': 'text/plain' };
|
|
138
|
+
break;
|
|
139
|
+
case body instanceof FormData: // Autofilled with 'multipart/form-data'
|
|
140
|
+
case body instanceof URLSearchParams: // Autofilled with 'application/x-www-form-urlencoded'
|
|
141
|
+
break;
|
|
142
|
+
case body instanceof Blob: // File is instance of Blob too
|
|
143
|
+
contentType = { 'Content-Type': body.type || 'application/octet-stream' };
|
|
144
|
+
break;
|
|
145
|
+
case body instanceof ArrayBuffer:
|
|
146
|
+
case ArrayBuffer.isView(body):
|
|
147
|
+
contentType = { 'Content-Type': 'application/octet-stream' };
|
|
148
|
+
break;
|
|
149
|
+
case body === null && !(extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.sendNull):
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
contentType = { 'Content-Type': 'application/json' };
|
|
153
|
+
body = JSON.stringify(body);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const method = (_a = extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.method) !== null && _a !== void 0 ? _a : (body != null ? 'POST' : 'GET'); // don't touch `!=` please
|
|
157
|
+
const authorization = getAuthorizationHeaders(method);
|
|
158
|
+
const headers = Object.assign(Object.assign(Object.assign({ Accept: 'application/json' }, authorization), contentType), extraHeaders);
|
|
159
|
+
return Object.assign({ body, headers, method }, !token && { credentials: 'include' });
|
|
160
|
+
}
|
|
161
|
+
export function getContext(revivers, keys = Object.keys(revivers)) {
|
|
162
|
+
return {
|
|
163
|
+
keysToRemove: new Set(keys.filter(isUndefined, revivers).concat(keysToRemove)),
|
|
164
|
+
keysToAdd: keys.filter(isReviver, revivers),
|
|
165
|
+
revivers,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export function processData(data) {
|
|
169
|
+
const result = {};
|
|
170
|
+
const keys = Object.keys(data).filter(isPreserved, this.keysToRemove);
|
|
171
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
172
|
+
result[toCamelCase(keys[i])] = data[keys[i]];
|
|
173
|
+
}
|
|
174
|
+
if (this.keysToAdd.length) {
|
|
175
|
+
const keys = this.keysToAdd;
|
|
176
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
177
|
+
result[keys[i]] = this.revivers[keys[i]](data);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
} /* eslint-enable @typescript-eslint/prefer-for-of */
|
|
182
|
+
export function toApiType(body) {
|
|
183
|
+
return Object.fromEntries(Object.entries(body).map(([k, v]) => [toSnakeCase(k), v]));
|
|
184
|
+
}
|
|
185
|
+
export function toAppType(body) {
|
|
186
|
+
return Object.fromEntries(Object.entries(body).map(([k, v]) => [toCamelCase(k), v]));
|
|
187
|
+
}
|
|
188
|
+
export function ensureArray(data) {
|
|
189
|
+
return Array.isArray(data) ? data : [data];
|
|
190
|
+
}
|
|
191
|
+
function toCamelCase(key) {
|
|
192
|
+
return key.replace(/_+(.)/g, (_, c) => c.toUpperCase());
|
|
193
|
+
}
|
|
194
|
+
function toSnakeCase(key) {
|
|
195
|
+
return key.replace(/[A-Z]/g, '_$&').toLowerCase();
|
|
196
|
+
}
|
|
197
|
+
function isUndefined(key) {
|
|
198
|
+
return this[key] === undefined;
|
|
199
|
+
}
|
|
200
|
+
function isReviver(key) {
|
|
201
|
+
return this[key] !== undefined;
|
|
202
|
+
}
|
|
203
|
+
function isPreserved(key) {
|
|
204
|
+
return !this.has(key);
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=utils.js.map
|
package/esm/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AA4BnF,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AAEtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC,EAAE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@mapcreator/api",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Mapcreator JavaScript API",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"source": "./src",
|
|
82
|
-
"destination": "./docs",
|
|
83
|
-
"name": "mapcreator",
|
|
84
|
-
"plugins": [
|
|
85
|
-
{
|
|
86
|
-
"name": "esdoc-standard-plugin",
|
|
87
|
-
"option": {
|
|
88
|
-
"accessor": {
|
|
89
|
-
"access": [
|
|
90
|
-
"public",
|
|
91
|
-
"protected"
|
|
92
|
-
],
|
|
93
|
-
"autoPrivate": true
|
|
94
|
-
},
|
|
95
|
-
"undocumentIdentifier": {
|
|
96
|
-
"enable": true
|
|
97
|
-
},
|
|
98
|
-
"unexportedIdentifier": {
|
|
99
|
-
"enable": false
|
|
100
|
-
},
|
|
101
|
-
"typeInference": {
|
|
102
|
-
"enable": true
|
|
103
|
-
},
|
|
104
|
-
"brand": {
|
|
105
|
-
"title": "Mapcreator Api Wrapper",
|
|
106
|
-
"description": "Mapcreator Api Javascript Wrapper"
|
|
107
|
-
},
|
|
108
|
-
"manual": {
|
|
109
|
-
"asset": "./manual/assets",
|
|
110
|
-
"index": "./README.md",
|
|
111
|
-
"files": [
|
|
112
|
-
"./manual/examples.md",
|
|
113
|
-
"./manual/examples.authentication.md",
|
|
114
|
-
"./manual/building.md",
|
|
115
|
-
"./manual/installation.md"
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
"name": "esdoc-ecmascript-proposal-plugin",
|
|
122
|
-
"option": {
|
|
123
|
-
"all": true
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
"name": "esdoc-inject-script-plugin",
|
|
128
|
-
"option": {
|
|
129
|
-
"enable": true,
|
|
130
|
-
"scripts": [
|
|
131
|
-
"./dist/bundle.browser.js",
|
|
132
|
-
"./manual/js/sandbox.js"
|
|
133
|
-
]
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
"name": "esdoc-inject-style-plugin",
|
|
138
|
-
"option": {
|
|
139
|
-
"enable": true,
|
|
140
|
-
"styles": [
|
|
141
|
-
"./manual/css/sidebar_fix.css",
|
|
142
|
-
"./manual/css/hide_import.css"
|
|
143
|
-
]
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@mapcreator/api",
|
|
3
|
+
"version": "5.0.0-alpha.100",
|
|
4
|
+
"description": "Mapcreator JavaScript API",
|
|
5
|
+
"license": "BSD-3-Clause",
|
|
6
|
+
"main": "./cjs/index.js",
|
|
7
|
+
"types": "./cjs/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./esm/index.d.ts",
|
|
11
|
+
"import": "./esm/index.js",
|
|
12
|
+
"require": "./cjs/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./oauth": {
|
|
15
|
+
"types": "./esm/oauth.d.ts",
|
|
16
|
+
"import": "./esm/oauth.js",
|
|
17
|
+
"require": "./cjs/oauth.js"
|
|
18
|
+
},
|
|
19
|
+
"./oauth.js": {
|
|
20
|
+
"types": "./esm/oauth.d.ts",
|
|
21
|
+
"import": "./esm/oauth.js",
|
|
22
|
+
"require": "./cjs/oauth.js"
|
|
23
|
+
},
|
|
24
|
+
"./utils": {
|
|
25
|
+
"types": "./esm/utils.d.ts",
|
|
26
|
+
"import": "./esm/utils.js",
|
|
27
|
+
"require": "./cjs/utils.js"
|
|
28
|
+
},
|
|
29
|
+
"./utils.js": {
|
|
30
|
+
"types": "./esm/utils.d.ts",
|
|
31
|
+
"import": "./esm/utils.js",
|
|
32
|
+
"require": "./cjs/utils.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json",
|
|
35
|
+
"./*": {
|
|
36
|
+
"types": "./esm/api/*.d.ts",
|
|
37
|
+
"import": "./esm/api/*.js",
|
|
38
|
+
"require": "./cjs/api/*.js"
|
|
39
|
+
},
|
|
40
|
+
"./*.js": {
|
|
41
|
+
"types": "./esm/api/*.d.ts",
|
|
42
|
+
"import": "./esm/api/*.js",
|
|
43
|
+
"require": "./cjs/api/*.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc --outDir esm && tsc -m commonjs --outDir cjs",
|
|
48
|
+
"clean": "npx rimraf esm/ cjs/",
|
|
49
|
+
"lint": "eslint --ext .ts src",
|
|
50
|
+
"prepublishOnly": "npm run lint && npm run clean && npm run build",
|
|
51
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://gitlab.com/mapcreator/api-wrapper.git"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"registry": "https://registry.npmjs.org/"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"cjs",
|
|
62
|
+
"esm",
|
|
63
|
+
"src"
|
|
64
|
+
],
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://gitlab.com/mapcreator/api-wrapper/issues"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://gitlab.com/mapcreator/api-wrapper#readme",
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@types/geojson": "^7946.0.14",
|
|
71
|
+
"type-fest": "^4.10"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@stylistic/eslint-plugin": "~1.5",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "~6.15",
|
|
76
|
+
"@typescript-eslint/parser": "~6.15",
|
|
77
|
+
"eslint": "~8.57",
|
|
78
|
+
"typescript": "~5.8.3"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
### Used type system
|
|
2
|
+
|
|
3
|
+
We use type declarations for both the data coming over the wire and the data used by the application. In general, these types differ only in the presence of additional fields in the data arriving over the network (like `created_at`), and used naming convention. Data over the network uses the so-called snake case.
|
|
4
|
+
|
|
5
|
+
All in all, we can use TypeScript's native mechanisms to convert one type to another and fully define just one type:
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import type { CamelCasedProperties } from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type ApiType =
|
|
11
|
+
| ({
|
|
12
|
+
data: {
|
|
13
|
+
prop: unknown;
|
|
14
|
+
} & ApiCommonData;
|
|
15
|
+
} & Omit<ApiSuccess, 'data'>)
|
|
16
|
+
| ApiError;
|
|
17
|
+
|
|
18
|
+
type AppType = CamelCasedProperties<Omit<Exclude<ApiType, ApiError>['data'], keyof ApiCommonData>>;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
or in reverse order:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import type { SnakeCasedProperties } from 'type-fest';
|
|
25
|
+
|
|
26
|
+
type AppType = {
|
|
27
|
+
prop: unknown;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type ApiType =
|
|
31
|
+
| ({
|
|
32
|
+
data: SnakeCasedProperties<AppType> & ApiCommonData;
|
|
33
|
+
} & Omit<ApiSuccess, 'data'>)
|
|
34
|
+
| ApiError;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
But the decision was made not to do this, since it may be more difficult for the developer to make the conversion in their head than to see it in front of their eyes.
|
|
38
|
+
|
|
39
|
+
### Using a `request()`
|
|
40
|
+
|
|
41
|
+
The function has the following signature:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
async function request<I extends ApiCommon, O extends Record<string, unknown> | string>(
|
|
45
|
+
path: string,
|
|
46
|
+
body?: XMLHttpRequestBodyInit | Record<string | number, unknown> | null,
|
|
47
|
+
extraHeaders?: Record<string, string> | null,
|
|
48
|
+
extraOptions?: ExtraOptions<I, O>,
|
|
49
|
+
): Promise<O | O[]> { /* ... */ }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Let's take it step by step.
|
|
53
|
+
|
|
54
|
+
`I extends ApiCommon` - represents the type of data we receive over the network.
|
|
55
|
+
|
|
56
|
+
`O extends Record<string, unknown> | string` - represents the data type that will be used in the application.
|
|
57
|
+
|
|
58
|
+
Ideally you should describe and convey both types. This will help to check the data types in the arguments passed.
|
|
59
|
+
See current data types for an example.
|
|
60
|
+
|
|
61
|
+
`path: string` - the path to the resource, must include the API version, but must not include the schema or authority.
|
|
62
|
+
Example: `/v1/jobs/12345`
|
|
63
|
+
|
|
64
|
+
`body?: XMLHttpRequestBodyInit | Record<string | number, unknown> | null` - any meaningful body type. In general,
|
|
65
|
+
the presence of an JSON object is assumed (or the absence of one for methods that only request data), but you can
|
|
66
|
+
also pass `Blob`, `FormData`, `URLSearchParams` or just `ArrayBuffer`. The required content type will be added to
|
|
67
|
+
the headers automatically.
|
|
68
|
+
|
|
69
|
+
`extraHeaders?: Record<string, string> | null` - the object with additional headers.
|
|
70
|
+
|
|
71
|
+
`extraOptions?: ExtraOptions<I, O>` - where `ExtraOptions<I, O>` is defined like this:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
interface ExtraOptions<I extends ApiCommon, O extends Record<string, unknown> | string> {
|
|
75
|
+
method?: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
76
|
+
revivers?: O extends Record<string, unknown> ? Revivers<I, O> : never;
|
|
77
|
+
sendNull?: boolean;
|
|
78
|
+
withMeta?: boolean;
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Most fields are self-explanatory.
|
|
83
|
+
|
|
84
|
+
`sendNull` can be used if you really want to pass `null` as body content.
|
|
85
|
+
|
|
86
|
+
`revivers` is used to specify an object that can modify the behavior of the internal handler of data coming over
|
|
87
|
+
the network. Let's take a closer look at this moment.
|
|
88
|
+
|
|
89
|
+
#### Revivers
|
|
90
|
+
|
|
91
|
+
By default, the `request()` function does the following things with data coming over the network:
|
|
92
|
+
|
|
93
|
+
- It removes `created_at`, `updated_at`, `deleted_at` fields from the output objects.
|
|
94
|
+
- It preserves all the remaining fields but converts their names into camelCase.
|
|
95
|
+
|
|
96
|
+
When passing an object with revivers you can a couple of things:
|
|
97
|
+
|
|
98
|
+
- You can list the fields that you want **to exclude** from the result object. To do this, the field must be assigned an
|
|
99
|
+
`undefined` value.
|
|
100
|
+
- You can **add** new fields or **modify** the type of existing ones. To do this, you need to pass a function as a field
|
|
101
|
+
value, which will receive the original object as input.
|
|
102
|
+
|
|
103
|
+
Example:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const jobRevivers: Revivers<ApiJob, Job> = {
|
|
107
|
+
user_id: undefined,
|
|
108
|
+
description: undefined,
|
|
109
|
+
share_token: undefined,
|
|
110
|
+
autosave_preview_path: undefined,
|
|
111
|
+
job_folder_id: undefined,
|
|
112
|
+
|
|
113
|
+
jobTypeId: () => 9,
|
|
114
|
+
createdAt: (data: ApiJobData) => data.created_at as string,
|
|
115
|
+
previewPath: (data: ApiJobData) => data.autosave_preview_path ?? undefined,
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`user_id`, `description`, `share_token`, `autosave_preview_path`, `job_folder_id` fields will be excluded from the
|
|
120
|
+
result object.
|
|
121
|
+
|
|
122
|
+
`jobTypeId` will be always **9**.
|
|
123
|
+
|
|
124
|
+
`createdAt` will be returned (please note that that field is excluded by default)
|
|
125
|
+
|
|
126
|
+
`previewPath` - some actions will be performed with the source data.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type ApiJobData, type Job, jobRevivers } from './job.js';
|
|
2
|
+
import {
|
|
3
|
+
APIMeta,
|
|
4
|
+
type ApiError,
|
|
5
|
+
type ApiSuccess,
|
|
6
|
+
type Revivers,
|
|
7
|
+
defaultListHeader,
|
|
8
|
+
getSearchParams,
|
|
9
|
+
request,
|
|
10
|
+
} from '../utils.js';
|
|
11
|
+
|
|
12
|
+
export interface JobSearchResult {
|
|
13
|
+
pageCount: number;
|
|
14
|
+
data: Job[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function listJobs(
|
|
18
|
+
pathname: string,
|
|
19
|
+
title: string,
|
|
20
|
+
page: number,
|
|
21
|
+
searchOptions?: Record<string, unknown>,
|
|
22
|
+
): Promise<JobSearchResult> {
|
|
23
|
+
const defaultSearchOptions = {
|
|
24
|
+
sort: '-updated',
|
|
25
|
+
only_downloaded: false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const search = { ...defaultSearchOptions, ...searchOptions };
|
|
29
|
+
|
|
30
|
+
const query = getSearchParams({
|
|
31
|
+
only_with_revisions: true,
|
|
32
|
+
search: {
|
|
33
|
+
job_type_id: '9',
|
|
34
|
+
...(title.length > 0 && { title: `~:${title}` }),
|
|
35
|
+
},
|
|
36
|
+
...search,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const path = `${pathname}?${query}`;
|
|
40
|
+
|
|
41
|
+
const headers = {
|
|
42
|
+
...defaultListHeader,
|
|
43
|
+
'X-Page': `${page}`,
|
|
44
|
+
};
|
|
45
|
+
const options = {
|
|
46
|
+
revivers: jobRevivers as Revivers<ApiJobArray, Job>,
|
|
47
|
+
withMeta: true,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type ApiJobArray = {
|
|
51
|
+
data: ApiJobData[];
|
|
52
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
53
|
+
|
|
54
|
+
const result = (await request<ApiJobArray, Job>(path, null, headers, options).catch(
|
|
55
|
+
(error: Error) => {
|
|
56
|
+
if (error instanceof APIMeta) {
|
|
57
|
+
const { data, headers, status } = error as APIMeta<ApiJobArray, Job>;
|
|
58
|
+
|
|
59
|
+
return { data, headers, status };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw error;
|
|
63
|
+
},
|
|
64
|
+
)) as APIMeta<ApiJobArray, Job>;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
data: result.data,
|
|
68
|
+
pageCount: Number(result.headers.get('X-Paginate-Pages')),
|
|
69
|
+
};
|
|
70
|
+
}
|