@foxtware/mineral 0.1.14 → 0.1.16
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/.creds.yml.sample +34 -0
- package/AGENTS.md +5 -0
- package/_build_scripts/createNewFunction.js +19 -19
- package/api/_example.js +6 -3
- package/api/_tools/log.js +22 -0
- package/api/algolia/docs.md +7 -0
- package/api/asana/asana.constants.js +7 -0
- package/api/asana/asana.utils.js +37 -0
- package/api/asana/asanaGet.js +150 -0
- package/api/asana/docs.md +5 -0
- package/api/athos/docs.md +9 -0
- package/api/bleckmann/bleckmannAsnsGet.js +3 -1
- package/api/clickup/clickup.constants.js +7 -0
- package/api/clickup/clickup.utils.js +36 -0
- package/api/clickup/clickupGet.js +150 -0
- package/api/clickup/docs.md +6 -0
- package/api/discord/discord.constants.js +7 -0
- package/api/discord/discord.utils.js +36 -0
- package/api/discord/discordGet.js +144 -0
- package/api/discord/docs.md +6 -0
- package/api/etsy/_example.get.js +68 -0
- package/api/etsy/etsy.constants.js +33 -0
- package/api/etsy/etsy.utils.js +208 -0
- package/api/etsy/etsyAccessTokenRefresh.js +106 -0
- package/api/etsy/etsyAccessTokenRequest.js +118 -0
- package/api/etsy/etsyAllListingFilesGet.js +69 -0
- package/api/etsy/etsyAllListingsGetActive.js +88 -0
- package/api/etsy/etsyAuthorizationCodeRequest.js +124 -0
- package/api/etsy/etsyBuyerTaxonomyNodePropertiesGet.js +62 -0
- package/api/etsy/etsyBuyerTaxonomyNodesGet.js +58 -0
- package/api/etsy/etsyDraftListingCreate.js +71 -0
- package/api/etsy/etsyFeaturedListingsByShopGet.js +78 -0
- package/api/etsy/etsyGet.js +150 -0
- package/api/etsy/etsyHolidayPreferencesGet.js +65 -0
- package/api/etsy/etsyHolidayPreferencesUpdate.js +75 -0
- package/api/etsy/etsyListingDelete.js +61 -0
- package/api/etsy/etsyListingFileDelete.js +72 -0
- package/api/etsy/etsyListingFileGet.js +73 -0
- package/api/etsy/etsyListingGet.js +62 -0
- package/api/etsy/etsyListingImageDelete.js +72 -0
- package/api/etsy/etsyListingImageGet.js +66 -0
- package/api/etsy/etsyListingImagesGet.js +62 -0
- package/api/etsy/etsyListingInventoryGet.js +62 -0
- package/api/etsy/etsyListingInventoryUpdate.js +99 -0
- package/api/etsy/etsyListingOfferingGet.js +70 -0
- package/api/etsy/etsyListingPersonalizationDelete.js +68 -0
- package/api/etsy/etsyListingPersonalizationGet.js +62 -0
- package/api/etsy/etsyListingPersonalizationUpdate.js +75 -0
- package/api/etsy/etsyListingProductGet.js +64 -0
- package/api/etsy/etsyListingPropertiesGet.js +69 -0
- package/api/etsy/etsyListingPropertyDelete.js +72 -0
- package/api/etsy/etsyListingPropertyGet.js +66 -0
- package/api/etsy/etsyListingPropertyUpdate.js +79 -0
- package/api/etsy/etsyListingTranslationCreate.js +79 -0
- package/api/etsy/etsyListingTranslationGet.js +73 -0
- package/api/etsy/etsyListingTranslationUpdate.js +79 -0
- package/api/etsy/etsyListingUpdate.js +75 -0
- package/api/etsy/etsyListingVariationImagesGet.js +69 -0
- package/api/etsy/etsyListingVideoDelete.js +72 -0
- package/api/etsy/etsyListingVideoGet.js +66 -0
- package/api/etsy/etsyListingVideosGet.js +62 -0
- package/api/etsy/etsyListingsByListingIdsGet.js +63 -0
- package/api/etsy/etsyListingsByShopReceiptGet.js +82 -0
- package/api/etsy/etsyListingsByShopReturnPolicyGet.js +69 -0
- package/api/etsy/etsyListingsInventoryByListingIdsGet.js +63 -0
- package/api/etsy/etsyListingsShippingByListingIdsGet.js +63 -0
- package/api/etsy/etsyMeGet.js +56 -0
- package/api/etsy/etsyOauthRedirectParse.js +201 -0
- package/api/etsy/etsyPaymentAccountLedgerEntryPaymentsGet.js +65 -0
- package/api/etsy/etsyPaymentsGet.js +65 -0
- package/api/etsy/etsyPing.js +51 -0
- package/api/etsy/etsyReceiptShipmentCreate.js +75 -0
- package/api/etsy/etsyReviewsByListingGet.js +76 -0
- package/api/etsy/etsyReviewsByShopGet.js +80 -0
- package/api/etsy/etsySellerTaxonomyNodePropertiesGet.js +62 -0
- package/api/etsy/etsySellerTaxonomyNodesGet.js +58 -0
- package/api/etsy/etsyShippingCarriersGet.js +63 -0
- package/api/etsy/etsyShopGet.js +65 -0
- package/api/etsy/etsyShopListingsActiveGet.js +82 -0
- package/api/etsy/etsyShopListingsGet.js +87 -0
- package/api/etsy/etsyShopPaymentAccountLedgerEntriesGet.js +80 -0
- package/api/etsy/etsyShopPaymentAccountLedgerEntryGet.js +69 -0
- package/api/etsy/etsyShopPaymentByReceiptIdGet.js +69 -0
- package/api/etsy/etsyShopProductionPartnersGet.js +65 -0
- package/api/etsy/etsyShopReadinessStateDefinitionCreate.js +71 -0
- package/api/etsy/etsyShopReadinessStateDefinitionDelete.js +68 -0
- package/api/etsy/etsyShopReadinessStateDefinitionGet.js +69 -0
- package/api/etsy/etsyShopReadinessStateDefinitionUpdate.js +75 -0
- package/api/etsy/etsyShopReadinessStateDefinitionsGet.js +78 -0
- package/api/etsy/etsyShopReceiptGet.js +67 -0
- package/api/etsy/etsyShopReceiptTransactionGet.js +69 -0
- package/api/etsy/etsyShopReceiptTransactionsByListingGet.js +82 -0
- package/api/etsy/etsyShopReceiptTransactionsByReceiptGet.js +69 -0
- package/api/etsy/etsyShopReceiptTransactionsByShopGet.js +78 -0
- package/api/etsy/etsyShopReceiptUpdate.js +75 -0
- package/api/etsy/etsyShopReceiptsGet.js +70 -0
- package/api/etsy/etsyShopReturnPoliciesConsolidate.js +75 -0
- package/api/etsy/etsyShopReturnPolicyCreate.js +71 -0
- package/api/etsy/etsyShopReturnPolicyDelete.js +68 -0
- package/api/etsy/etsyShopReturnPolicyGet.js +69 -0
- package/api/etsy/etsyShopReturnPolicyUpdate.js +75 -0
- package/api/etsy/etsyShopReturnsPoliciesGet.js +70 -0
- package/api/etsy/etsyShopSectionCreate.js +71 -0
- package/api/etsy/etsyShopSectionDelete.js +68 -0
- package/api/etsy/etsyShopSectionGet.js +69 -0
- package/api/etsy/etsyShopSectionListingsGet.js +86 -0
- package/api/etsy/etsyShopSectionUpdate.js +75 -0
- package/api/etsy/etsyShopSectionsGet.js +65 -0
- package/api/etsy/etsyShopShippingProfileCreate.js +71 -0
- package/api/etsy/etsyShopShippingProfileDelete.js +68 -0
- package/api/etsy/etsyShopShippingProfileDestinationCreate.js +75 -0
- package/api/etsy/etsyShopShippingProfileDestinationDelete.js +72 -0
- package/api/etsy/etsyShopShippingProfileDestinationUpdate.js +79 -0
- package/api/etsy/etsyShopShippingProfileDestinationsByShippingProfileGet.js +82 -0
- package/api/etsy/etsyShopShippingProfileGet.js +69 -0
- package/api/etsy/etsyShopShippingProfileUpdate.js +75 -0
- package/api/etsy/etsyShopShippingProfileUpgradeCreate.js +75 -0
- package/api/etsy/etsyShopShippingProfileUpgradeDelete.js +72 -0
- package/api/etsy/etsyShopShippingProfileUpgradeUpdate.js +79 -0
- package/api/etsy/etsyShopShippingProfileUpgradesGet.js +69 -0
- package/api/etsy/etsyShopShippingProfilesGet.js +65 -0
- package/api/etsy/etsyShopUpdate.js +69 -0
- package/api/etsy/etsyShopsGet.js +70 -0
- package/api/etsy/etsyTokenScopes.js +63 -0
- package/api/etsy/etsyUserAddressDelete.js +61 -0
- package/api/etsy/etsyUserAddressGet.js +62 -0
- package/api/etsy/etsyUserAddressesGet.js +70 -0
- package/api/etsy/etsyUserGet.js +62 -0
- package/api/etsy/etsyUserShopsGet.js +62 -0
- package/api/etsy/etsyVariationImagesUpdate.js +75 -0
- package/api/figma/docs.md +6 -0
- package/api/figma/figma.constants.js +7 -0
- package/api/figma/figma.utils.js +36 -0
- package/api/figma/figmaGet.js +107 -0
- package/api/github/githubReposGet.js +3 -1
- package/api/github/githubUserGet.js +3 -1
- package/api/google/docs.md +7 -0
- package/api/google/google.constants.js +9 -0
- package/api/google/google.utils.js +137 -0
- package/api/google/googlecalendarCalendarsGet.js +54 -0
- package/api/google/googlecalendarEventCreate.js +63 -0
- package/api/google/googlecalendarEventDelete.js +55 -0
- package/api/google/googlecalendarEventGet.js +55 -0
- package/api/google/googlecalendarEventsGet.js +65 -0
- package/api/google/googledriveFileDelete.js +53 -0
- package/api/google/googledriveFileGet.js +57 -0
- package/api/google/googledriveFileUpload.js +127 -0
- package/api/google/googledriveFilesGet.js +72 -0
- package/api/google/googlesheetsSpreadsheetGet.js +57 -0
- package/api/google/googlesheetsSpreadsheetSheetAdd.js +150 -0
- package/api/google/googlesheetsSpreadsheetSheetGetData.js +159 -0
- package/api/google/googlesheetsSpreadsheetTrim.js +239 -0
- package/api/gorgias/docs.md +7 -0
- package/api/logiwa/logiwaAuthGet.js +3 -1
- package/api/logiwa/logiwaInventoriesGet.js +3 -1
- package/api/logiwa/logiwaOrdersGet.js +3 -1
- package/api/logiwa/logiwaProductsGet.js +3 -1
- package/api/logiwa/logiwaReportGetInventorySnapshot.js +3 -1
- package/api/logiwa/logiwaReportGetTotalInventory.js +3 -1
- package/api/logiwa/logiwaWebhooksGet.js +3 -1
- package/api/loop/loopAllowlistItemsGet.js +3 -1
- package/api/loop/loopBlocklistItemsGet.js +3 -1
- package/api/loop/loopDestinationsGet.js +3 -1
- package/api/loop/loopReturnsGet.js +3 -1
- package/api/notion/docs.md +6 -0
- package/api/notion/notion.constants.js +9 -0
- package/api/notion/notion.utils.js +44 -0
- package/api/notion/notionGet.js +146 -0
- package/api/peoplevox/_example.js +4 -1
- package/api/peoplevox/peoplevox.sessions.js +29 -0
- package/api/peoplevox/peoplevox.utils.js +4 -38
- package/api/peoplevox/peoplevoxAuthGet.js +3 -1
- package/api/peoplevox/peoplevoxGetSingle.js +4 -2
- package/api/peoplevox/peoplevoxOrderEdit.js +8 -2
- package/api/peoplevox/peoplevoxOrderGet.js +6 -1
- package/api/peoplevox/peoplevoxReportGet.js +6 -2
- package/api/pipe17/docs.md +8 -0
- package/api/pipe17/pipe17.constants.js +47 -0
- package/api/pipe17/pipe17.utils.js +123 -0
- package/api/pipe17/pipe17ArrivalGet.js +78 -0
- package/api/pipe17/pipe17ArrivalUpdate.js +111 -0
- package/api/pipe17/pipe17ArrivalsGet.js +54 -0
- package/api/pipe17/pipe17FulfillmentGet.js +69 -0
- package/api/pipe17/pipe17FulfillmentsGet.js +54 -0
- package/api/pipe17/pipe17Get.js +151 -0
- package/api/pipe17/pipe17InventoryItemGet.js +57 -0
- package/api/pipe17/pipe17InventoryItemsGet.js +54 -0
- package/api/pipe17/pipe17JobCreate.js +95 -0
- package/api/pipe17/pipe17JobGet.js +70 -0
- package/api/pipe17/pipe17JobResultsGet.js +55 -0
- package/api/pipe17/pipe17LocationGet.js +57 -0
- package/api/pipe17/pipe17LocationsGet.js +54 -0
- package/api/pipe17/pipe17OrderGet.js +71 -0
- package/api/pipe17/pipe17OrdersGet.js +54 -0
- package/api/pipe17/pipe17ProductGet.js +57 -0
- package/api/pipe17/pipe17ProductsGet.js +54 -0
- package/api/pipe17/pipe17PurchaseGet.js +57 -0
- package/api/pipe17/pipe17PurchasesGet.js +54 -0
- package/api/pipe17/pipe17ReceiptGet.js +57 -0
- package/api/pipe17/pipe17ReceiptsGet.js +54 -0
- package/api/pipe17/pipe17ReturnGet.js +57 -0
- package/api/pipe17/pipe17ReturnsGet.js +54 -0
- package/api/printify/_example.get.js +67 -0
- package/api/printify/_example.js +59 -0
- package/api/printify/printify.constants.js +8 -0
- package/api/printify/printify.utils.js +41 -0
- package/api/printify/printifyBlueprintGet.js +60 -0
- package/api/printify/printifyBlueprintPrintProviderVariantsGet.js +77 -0
- package/api/printify/printifyBlueprintPrintProvidersGet.js +60 -0
- package/api/printify/printifyBlueprintsGet.js +38 -0
- package/api/printify/printifyGet.js +154 -0
- package/api/printify/printifyImageUpload.js +74 -0
- package/api/printify/printifyOrderCancel.js +70 -0
- package/api/printify/printifyOrderCreate.js +98 -0
- package/api/printify/printifyOrderGet.js +70 -0
- package/api/printify/printifyOrderSubmit.js +70 -0
- package/api/printify/printifyOrdersGet.js +72 -0
- package/api/printify/printifyProductCreate.js +96 -0
- package/api/printify/printifyProductDelete.js +70 -0
- package/api/printify/printifyProductGet.js +79 -0
- package/api/printify/printifyProductUpdate.js +81 -0
- package/api/printify/printifyProductsGet.js +67 -0
- package/api/printify/printifyShippingGet.js +70 -0
- package/api/printify/printifyShopsGet.js +56 -0
- package/api/printify/printifyWebhookCreate.js +84 -0
- package/api/printify/printifyWebhookDelete.js +70 -0
- package/api/printify/printifyWebhookUpdate.js +81 -0
- package/api/printify/printifyWebhooksGet.js +56 -0
- package/api/salesforce/docs.md +6 -0
- package/api/shopify/_example.create.js +2 -2
- package/api/shopify/_example.get.js +17 -4
- package/api/shopify/_example.getsingle.js +4 -1
- package/api/shopify/_example.js +4 -1
- package/api/shopify/_example.mutation.js +4 -1
- package/api/shopify/shopifyAbandonedCheckoutsGet.js +1 -1
- package/api/shopify/shopifyArticlesGet.js +1 -1
- package/api/shopify/shopifyBlogsGet.js +1 -1
- package/api/shopify/shopifyBulkMutationDo.js +5 -6
- package/api/shopify/shopifyBulkOperationsGet.js +1 -1
- package/api/shopify/shopifyCatalogsGet.js +17 -4
- package/api/shopify/shopifyChannelsGet.js +17 -4
- package/api/shopify/shopifyCheckoutAndAccountsConfigurationsGet.js +17 -4
- package/api/shopify/shopifyCollectionGet.js +4 -1
- package/api/shopify/shopifyCollectionsGet.js +17 -4
- package/api/shopify/shopifyCustomerCreate.js +2 -2
- package/api/shopify/shopifyCustomerGet.js +4 -1
- package/api/shopify/shopifyCustomerMarketingConsentUpdateSms.js +84 -0
- package/api/shopify/shopifyCustomersGet.js +18 -5
- package/api/shopify/shopifyDecodeSessionToken.js +2 -2
- package/api/shopify/shopifyDeliveryCustomizationsGet.js +1 -1
- package/api/shopify/shopifyDeliveryProfilesGet.js +17 -4
- package/api/shopify/shopifyDiscountNodesGet.js +1 -1
- package/api/shopify/shopifyDisputesGet.js +1 -1
- package/api/shopify/shopifyDraftOrdersGet.js +1 -1
- package/api/shopify/shopifyEventsGet.js +1 -1
- package/api/shopify/shopifyFilesGet.js +1 -1
- package/api/shopify/shopifyFulfillmentOrdersGet.js +17 -4
- package/api/shopify/shopifyGet.js +1 -1
- package/api/shopify/shopifyGiftCardCreate.js +4 -1
- package/api/shopify/shopifyGiftCardDeactivate.js +4 -1
- package/api/shopify/shopifyGiftCardsGet.js +17 -4
- package/api/shopify/shopifyInventoryItemsGet.js +17 -4
- package/api/shopify/shopifyLocationsGet.js +1 -1
- package/api/shopify/shopifyMarketingEventsGet.js +1 -1
- package/api/shopify/shopifyMarketsGet.js +1 -1
- package/api/shopify/shopifyMenusGet.js +1 -1
- package/api/shopify/shopifyMetafieldDefinitionCreate.js +111 -0
- package/api/shopify/shopifyMetafieldDefinitionsGet.js +18 -4
- package/api/shopify/shopifyMetafieldsDelete.js +78 -0
- package/api/shopify/shopifyMetaobjectDefinitionsGet.js +1 -1
- package/api/shopify/shopifyMetaobjectsGet.js +1 -1
- package/api/shopify/shopifyMutationDo.js +4 -1
- package/api/shopify/shopifyOrderGet.js +4 -1
- package/api/shopify/shopifyOrdersGet.js +3 -1
- package/api/shopify/shopifyPageDelete.js +4 -1
- package/api/shopify/shopifyPageGet.js +4 -1
- package/api/shopify/shopifyPageUpdate.js +5 -1
- package/api/shopify/shopifyPagesGet.js +1 -1
- package/api/shopify/shopifyPaymentCustomizationsGet.js +1 -1
- package/api/shopify/shopifyProductFeedsGet.js +1 -1
- package/api/shopify/shopifyProductGet.js +110 -0
- package/api/shopify/shopifyProductVariantsGet.js +1 -1
- package/api/shopify/shopifyProductsGet.js +17 -4
- package/api/shopify/shopifyPublicationsGet.js +17 -4
- package/api/shopify/shopifySegmentsGet.js +1 -1
- package/api/shopify/shopifyStoreCreditAccountCredit.js +144 -0
- package/api/shopify/shopifyStoreCreditAccountDebit.js +132 -0
- package/api/shopify/shopifyTagsRemoveBulk.js +77 -0
- package/api/shopify/shopifyThemeDelete.js +4 -1
- package/api/shopify/shopifyThemeDuplicate.js +4 -1
- package/api/shopify/shopifyThemeGet.js +2 -2
- package/api/shopify/shopifyThemesGet.js +3 -1
- package/api/shopify/shopifyUrlRedirectsGet.js +1 -1
- package/api/shopify/shopifyWebhookSubscriptionsGet.js +17 -4
- package/api/snowflake/docs.md +8 -0
- package/api/starshipit/starshipitAddressesGet.js +3 -1
- package/api/starshipit/starshipitOrdersListShipped.js +3 -1
- package/api/starshipit/starshipitProductsGet.js +3 -1
- package/api/stripe/_example.js +4 -1
- package/api/stripe/stripeChargesGet.js +3 -1
- package/api/stripe/stripeRefundsGet.js +3 -1
- package/api/stylearcade/stylearcadeDataGet.js +14 -6
- package/api/stylearcade/stylearcadeMetadataGet.js +3 -1
- package/api/tagalys/docs.md +7 -0
- package/api/telnyx/docs.md +6 -0
- package/api/telnyx/telnyx.constants.js +7 -0
- package/api/telnyx/telnyx.utils.js +37 -0
- package/api/telnyx/telnyxAvailablePhoneNumbersGet.js +59 -0
- package/api/telnyx/telnyxBalanceGet.js +51 -0
- package/api/telnyx/telnyxGet.js +151 -0
- package/api/telnyx/telnyxMessageGet.js +59 -0
- package/api/telnyx/telnyxMessageSend.js +65 -0
- package/api/telnyx/telnyxMessagesGet.js +53 -0
- package/api/telnyx/telnyxMessagingProfileCreate.js +62 -0
- package/api/telnyx/telnyxMessagingProfileGet.js +59 -0
- package/api/telnyx/telnyxMessagingProfileUpdate.js +68 -0
- package/api/telnyx/telnyxMessagingProfilesGet.js +53 -0
- package/api/telnyx/telnyxNumberLookupGet.js +61 -0
- package/api/telnyx/telnyxNumberOrderCreate.js +64 -0
- package/api/telnyx/telnyxPhoneNumberGet.js +59 -0
- package/api/telnyx/telnyxPhoneNumberUpdate.js +68 -0
- package/api/telnyx/telnyxPhoneNumbersGet.js +53 -0
- package/api/telnyx/telnyxWebhookDeliveriesGet.js +58 -0
- package/api/threeclicks/threeclicksCollectionsGet.js +3 -1
- package/api/threeclicks/threeclicksPurchaseOrderCreate.js +4 -1
- package/api/threeclicks/threeclicksPurchaseOrderCreateBulk.js +4 -1
- package/api/threeclicks/threeclicksPurchaseOrderGet.js +4 -1
- package/api/threeclicks/threeclicksPurchaseOrderQuantitiesGet.js +4 -1
- package/api/threeclicks/threeclicksPurchaseOrderQuantityCreate.js +4 -1
- package/api/threeclicks/threeclicksPurchaseOrderQuantityCreateBulk.js +4 -1
- package/api/threeclicks/threeclicksPurchaseOrderUpdate.js +5 -1
- package/api/threeclicks/threeclicksPurchaseOrdersGet.js +3 -1
- package/api/threeclicks/threeclicksShipmentCreate.js +4 -1
- package/api/threeclicks/threeclicksShipmentGet.js +4 -1
- package/api/threeclicks/threeclicksShipmentOrderAdd.js +5 -1
- package/api/threeclicks/threeclicksShipmentOrderQuantityCreate.js +5 -1
- package/api/threeclicks/threeclicksShipmentQuantityUpdate.js +5 -1
- package/api/threeclicks/threeclicksShipmentStatusUpdate.js +5 -1
- package/api/threeclicks/threeclicksShipmentsGet.js +3 -1
- package/api/threeclicks/threeclicksSignatureCalculate.js +4 -4
- package/api/threeclicks/threeclicksStyleCodesGet.js +4 -1
- package/api/threeclicks/threeclicksStyleColourDelete.js +5 -1
- package/api/threeclicks/threeclicksStyleDelete.js +4 -1
- package/api/threeclicks/threeclicksStylesGet.js +3 -1
- package/api/upstash/upstashDel.js +4 -1
- package/api/upstash/upstashExists.js +4 -1
- package/api/upstash/upstashGet.js +4 -1
- package/api/utils.js +86 -6
- package/api/workable/workableJobsGet.js +3 -1
- package/api/yotpo/yotpoCampaignsGet.js +3 -1
- package/api/yotpo/yotpoCustomersRecentGet.js +3 -1
- package/api/yotpo/yotpoRedemptionOptionsGet.js +3 -1
- package/api/yotpo/yotpoVipTiersGet.js +3 -1
- package/hosting/copyCredsToEnv.js +3 -3
- package/hosting/handlerPaths.js +3 -3
- package/package.json +2 -1
- package/server.js +8 -6
- package/server.utils.js +1 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// https://discord.com/developers/docs/resources/user#get-current-user
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, Getter } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { discordClient } = require('../discord/discord.utils');
|
|
6
|
+
const { MAX_PER_PAGE } = require('../discord/discord.constants');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
['url'],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const discordGetPacket = async (
|
|
14
|
+
credsPayload,
|
|
15
|
+
url,
|
|
16
|
+
{
|
|
17
|
+
params,
|
|
18
|
+
perPage = MAX_PER_PAGE,
|
|
19
|
+
} = {},
|
|
20
|
+
) => {
|
|
21
|
+
const {
|
|
22
|
+
limit = Math.min(perPage, MAX_PER_PAGE),
|
|
23
|
+
...restParams
|
|
24
|
+
} = params ?? {};
|
|
25
|
+
|
|
26
|
+
return discordClient.fetch({
|
|
27
|
+
requestPayload: {
|
|
28
|
+
url,
|
|
29
|
+
params: {
|
|
30
|
+
limit,
|
|
31
|
+
...restParams,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
context: {
|
|
35
|
+
credsPayload,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const discordGetPaginator = async (currentParams, response) => {
|
|
41
|
+
const { args, options } = currentParams;
|
|
42
|
+
|
|
43
|
+
if (!response?.ok) {
|
|
44
|
+
return [true];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const items = Array.isArray(response.data) ? response.data : [];
|
|
48
|
+
const { perPage = MAX_PER_PAGE, params = {} } = options;
|
|
49
|
+
const { limit = Math.min(perPage, MAX_PER_PAGE) } = params;
|
|
50
|
+
|
|
51
|
+
if (items.length < limit) {
|
|
52
|
+
return [true];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const lastItem = items[items.length - 1];
|
|
56
|
+
const before = lastItem?.id;
|
|
57
|
+
if (!before) {
|
|
58
|
+
return [true];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return [false, {
|
|
62
|
+
args,
|
|
63
|
+
options: {
|
|
64
|
+
...options,
|
|
65
|
+
params: {
|
|
66
|
+
...params,
|
|
67
|
+
before,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
}];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const discordGet = async (
|
|
74
|
+
returnGetter,
|
|
75
|
+
|
|
76
|
+
credsPayload,
|
|
77
|
+
url,
|
|
78
|
+
{
|
|
79
|
+
params,
|
|
80
|
+
perPage = MAX_PER_PAGE,
|
|
81
|
+
...getterOptions
|
|
82
|
+
} = {},
|
|
83
|
+
) => {
|
|
84
|
+
|
|
85
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
86
|
+
credsPayload,
|
|
87
|
+
url,
|
|
88
|
+
});
|
|
89
|
+
if (rejectResponse) {
|
|
90
|
+
return rejectResponse;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const getter = new Getter(
|
|
94
|
+
{
|
|
95
|
+
args: [credsPayload, url],
|
|
96
|
+
options: {
|
|
97
|
+
params,
|
|
98
|
+
perPage,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
func: discordGetPacket,
|
|
103
|
+
digester: (response) => {
|
|
104
|
+
if (!response?.ok) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return Array.isArray(response.data) ? response.data : [];
|
|
109
|
+
},
|
|
110
|
+
paginator: discordGetPaginator,
|
|
111
|
+
...getterOptions,
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (returnGetter) {
|
|
116
|
+
return getter;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const data = await getter.run({ returnAll: true });
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
ok: true,
|
|
123
|
+
data,
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const funcApiConfig = {
|
|
128
|
+
argsWarden,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
module.exports = {
|
|
132
|
+
discordGet: (...args) => discordGet(false, ...args),
|
|
133
|
+
discordGetter: (...args) => discordGet(true, ...args),
|
|
134
|
+
funcApiConfig,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/*
|
|
138
|
+
curl -X POST "http://localhost:8000/discordGet" \
|
|
139
|
+
-H "Content-Type: application/json" \
|
|
140
|
+
-d '{
|
|
141
|
+
"credsPayload": { "credsPath": "discord" },
|
|
142
|
+
"url": "/users/@me"
|
|
143
|
+
}'
|
|
144
|
+
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Discord
|
|
2
|
+
|
|
3
|
+
- [Developer documentation](https://discord.com/developers/docs/intro)
|
|
4
|
+
- [REST API reference](https://discord.com/developers/docs/reference)
|
|
5
|
+
|
|
6
|
+
REST JSON at `https://discord.com/api/v10` for bots and OAuth applications, with bot requests authenticated via `Authorization: Bot <token>`.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const { ArgsWarden } = require('../utils');
|
|
2
|
+
const { credsValidator } = require('../validators');
|
|
3
|
+
const { etsyGet, etsyGetter } = require('./etsyGet');
|
|
4
|
+
const { resolveShopId } = require('./etsy.utils');
|
|
5
|
+
|
|
6
|
+
const argsWarden = new ArgsWarden([
|
|
7
|
+
['credsPayload', credsValidator],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
const etsyThingsGet = async (
|
|
11
|
+
returnGetter,
|
|
12
|
+
|
|
13
|
+
credsPayload,
|
|
14
|
+
{
|
|
15
|
+
shopId,
|
|
16
|
+
params,
|
|
17
|
+
perPage,
|
|
18
|
+
...getterOptions
|
|
19
|
+
} = {},
|
|
20
|
+
) => {
|
|
21
|
+
|
|
22
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
23
|
+
credsPayload,
|
|
24
|
+
});
|
|
25
|
+
if (rejectResponse) {
|
|
26
|
+
return rejectResponse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const shopIdResponse = await resolveShopId({ shopId, credsPayload });
|
|
30
|
+
if (!shopIdResponse.ok) {
|
|
31
|
+
return shopIdResponse;
|
|
32
|
+
}
|
|
33
|
+
({ data: shopId } = shopIdResponse);
|
|
34
|
+
|
|
35
|
+
const getterArgs = [
|
|
36
|
+
credsPayload,
|
|
37
|
+
`/application/shops/${ shopId }/things`,
|
|
38
|
+
{
|
|
39
|
+
params,
|
|
40
|
+
perPage,
|
|
41
|
+
...getterOptions,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
return returnGetter
|
|
46
|
+
? etsyGetter(...getterArgs)
|
|
47
|
+
: etsyGet(...getterArgs);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const funcApiConfig = {
|
|
51
|
+
argsWarden,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
etsyThingsGet: (...args) => etsyThingsGet(false, ...args),
|
|
56
|
+
etsyThingsGetter: (...args) => etsyThingsGet(true, ...args),
|
|
57
|
+
funcApiConfig,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
curl -X POST "http://localhost:8000/etsyThingsGet" \
|
|
62
|
+
-H "Content-Type: application/json" \
|
|
63
|
+
-d '{
|
|
64
|
+
"credsPayload": {
|
|
65
|
+
"credsPath": "etsy"
|
|
66
|
+
}
|
|
67
|
+
}'
|
|
68
|
+
*/
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const BASE_URL = 'https://api.etsy.com/v3';
|
|
2
|
+
const OAUTH_CONNECT_URL = 'https://www.etsy.com/oauth/connect';
|
|
3
|
+
const MAX_PER_PAGE = 100;
|
|
4
|
+
|
|
5
|
+
const OAUTH_ALL_SCOPES = [
|
|
6
|
+
'address_r',
|
|
7
|
+
'address_w',
|
|
8
|
+
'billing_r',
|
|
9
|
+
'cart_r',
|
|
10
|
+
'cart_w',
|
|
11
|
+
'email_r',
|
|
12
|
+
'favorites_r',
|
|
13
|
+
'favorites_w',
|
|
14
|
+
'feedback_r',
|
|
15
|
+
'listings_d',
|
|
16
|
+
'listings_r',
|
|
17
|
+
'listings_w',
|
|
18
|
+
'profile_r',
|
|
19
|
+
'profile_w',
|
|
20
|
+
'recommend_r',
|
|
21
|
+
'recommend_w',
|
|
22
|
+
'shops_r',
|
|
23
|
+
'shops_w',
|
|
24
|
+
'transactions_r',
|
|
25
|
+
'transactions_w',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
BASE_URL,
|
|
30
|
+
OAUTH_CONNECT_URL,
|
|
31
|
+
MAX_PER_PAGE,
|
|
32
|
+
OAUTH_ALL_SCOPES,
|
|
33
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const { BASE_URL } = require('../etsy/etsy.constants');
|
|
2
|
+
const { resolveCreds, useBaseUrl } = require('../pipelineSteps');
|
|
3
|
+
const { resolveFromCreds, FetchClient, fetchClientCommonSteps } = require('../utils');
|
|
4
|
+
|
|
5
|
+
const etsyAccessTokenExpired = (response) => {
|
|
6
|
+
const details = response?.error?.details;
|
|
7
|
+
|
|
8
|
+
return details?.error === 'invalid_token'
|
|
9
|
+
&& details?.error_description === 'access token is expired';
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const withEtsyAuthTokenRefresh = async (fetchPayload, next) => {
|
|
13
|
+
const { context = {} } = fetchPayload;
|
|
14
|
+
|
|
15
|
+
if (!context.withAccessToken) {
|
|
16
|
+
return next(fetchPayload);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const response = await next(fetchPayload);
|
|
20
|
+
|
|
21
|
+
if (
|
|
22
|
+
response.ok
|
|
23
|
+
|| !etsyAccessTokenExpired(response)
|
|
24
|
+
|| context.etsyRetriedAfterTokenRefresh
|
|
25
|
+
) {
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { etsyAccessTokenRefresh } = require('./etsyAccessTokenRefresh');
|
|
30
|
+
const refreshResponse = await etsyAccessTokenRefresh(context.credsPayload);
|
|
31
|
+
|
|
32
|
+
if (!refreshResponse.ok) {
|
|
33
|
+
return refreshResponse;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { accessToken, refreshToken } = refreshResponse.data;
|
|
37
|
+
|
|
38
|
+
return next({
|
|
39
|
+
...fetchPayload,
|
|
40
|
+
context: {
|
|
41
|
+
...context,
|
|
42
|
+
accessToken,
|
|
43
|
+
refreshToken,
|
|
44
|
+
etsyRetriedAfterTokenRefresh: true,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const useEtsyBaseUrl = async (state) => {
|
|
50
|
+
const { creds } = state.context;
|
|
51
|
+
return useBaseUrl(creds.BASE_URL ?? BASE_URL)(state);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const useEtsyApiKeyHeader = async (state) => {
|
|
55
|
+
const { requestPayload, context } = state;
|
|
56
|
+
const { creds } = context;
|
|
57
|
+
const {
|
|
58
|
+
API_KEY,
|
|
59
|
+
SHARED_SECRET,
|
|
60
|
+
} = creds;
|
|
61
|
+
|
|
62
|
+
if (!API_KEY || !SHARED_SECRET) {
|
|
63
|
+
return {
|
|
64
|
+
breakChain: true,
|
|
65
|
+
response: {
|
|
66
|
+
ok: false,
|
|
67
|
+
error: {
|
|
68
|
+
code: 'INVALID_CREDS',
|
|
69
|
+
message: 'API_KEY and SHARED_SECRET are required.',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
requestPayload: {
|
|
77
|
+
...requestPayload,
|
|
78
|
+
headers: {
|
|
79
|
+
'x-api-key': `${ API_KEY }:${ SHARED_SECRET }`,
|
|
80
|
+
...requestPayload.headers,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const tokensFromCredsIfNotContext = async (state) => {
|
|
87
|
+
const { context } = state;
|
|
88
|
+
const {
|
|
89
|
+
withAccessToken,
|
|
90
|
+
accessToken,
|
|
91
|
+
refreshToken,
|
|
92
|
+
creds,
|
|
93
|
+
} = context;
|
|
94
|
+
|
|
95
|
+
if (!withAccessToken) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const contextPatch = {};
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
ACCESS_TOKEN,
|
|
103
|
+
REFRESH_TOKEN,
|
|
104
|
+
} = creds;
|
|
105
|
+
|
|
106
|
+
if (!accessToken && ACCESS_TOKEN) {
|
|
107
|
+
contextPatch.accessToken = ACCESS_TOKEN;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!refreshToken && REFRESH_TOKEN) {
|
|
111
|
+
contextPatch.refreshToken = REFRESH_TOKEN;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
context: {
|
|
116
|
+
...context,
|
|
117
|
+
...contextPatch,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const useEtsyBearerFromContext = async (state) => {
|
|
123
|
+
const { requestPayload, context } = state;
|
|
124
|
+
const { withAccessToken, accessToken } = context;
|
|
125
|
+
|
|
126
|
+
if (!withAccessToken) {
|
|
127
|
+
return {};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!accessToken) {
|
|
131
|
+
return {
|
|
132
|
+
breakChain: true,
|
|
133
|
+
response: {
|
|
134
|
+
ok: false,
|
|
135
|
+
error: {
|
|
136
|
+
code: 'NO_ACCESS_TOKEN',
|
|
137
|
+
message: 'context.accessToken is required when withAccessToken is true.',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
requestPayload: {
|
|
145
|
+
...requestPayload,
|
|
146
|
+
headers: {
|
|
147
|
+
Authorization: `Bearer ${ accessToken }`,
|
|
148
|
+
...requestPayload.headers,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// TODO: In-memory session map for access/refresh tokens per credsPath.
|
|
155
|
+
const etsyClient = new FetchClient({
|
|
156
|
+
pipeline: [
|
|
157
|
+
resolveCreds,
|
|
158
|
+
tokensFromCredsIfNotContext,
|
|
159
|
+
useEtsyBaseUrl,
|
|
160
|
+
useEtsyApiKeyHeader,
|
|
161
|
+
useEtsyBearerFromContext,
|
|
162
|
+
'fetch',
|
|
163
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
164
|
+
],
|
|
165
|
+
layers: [withEtsyAuthTokenRefresh],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const resolveShopId = async ({ shopId, credsPayload }) => {
|
|
169
|
+
if (shopId) {
|
|
170
|
+
return { ok: true, data: shopId };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const shopIdFromCredsResponse = await resolveFromCreds('SHOP_ID')({ credsPayload });
|
|
174
|
+
if (shopIdFromCredsResponse.ok) {
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
data: shopIdFromCredsResponse.data,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const { etsyMeGet } = require('./etsyMeGet');
|
|
182
|
+
const meGetResponse = await etsyMeGet(credsPayload);
|
|
183
|
+
const { ok: meGetOk, data: meGetData } = meGetResponse;
|
|
184
|
+
if (meGetOk) {
|
|
185
|
+
({ shop_id: shopId } = meGetData);
|
|
186
|
+
|
|
187
|
+
if (shopId) {
|
|
188
|
+
return {
|
|
189
|
+
ok: true,
|
|
190
|
+
data: shopId,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
ok: false,
|
|
197
|
+
error: {
|
|
198
|
+
code: 'NO_SHOP_ID',
|
|
199
|
+
message: 'No shop ID found in creds or me response',
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
module.exports = {
|
|
205
|
+
etsyClient,
|
|
206
|
+
etsyAccessTokenExpired,
|
|
207
|
+
resolveShopId,
|
|
208
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// https://developers.etsy.com/documentation/essentials/authentication#requesting-an-oauth-token
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { credsFromPayload, ArgsWarden } = require('../utils');
|
|
5
|
+
const { etsyClient } = require('./etsy.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const etsyAccessTokenRefresh = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
refreshToken,
|
|
14
|
+
{
|
|
15
|
+
fetchClient = etsyClient,
|
|
16
|
+
} = {},
|
|
17
|
+
) => {
|
|
18
|
+
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
20
|
+
credsPayload,
|
|
21
|
+
});
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const creds = await credsFromPayload(credsPayload);
|
|
27
|
+
const { API_KEY, REFRESH_TOKEN } = creds;
|
|
28
|
+
const token = refreshToken ?? REFRESH_TOKEN;
|
|
29
|
+
|
|
30
|
+
if (!API_KEY || !token) {
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
error: {
|
|
34
|
+
code: 'INVALID_CREDS',
|
|
35
|
+
message: 'API_KEY and REFRESH_TOKEN are required.',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const response = await fetchClient.fetch({
|
|
41
|
+
requestPayload: {
|
|
42
|
+
method: 'post',
|
|
43
|
+
url: '/public/oauth/token',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
46
|
+
},
|
|
47
|
+
body: new URLSearchParams({
|
|
48
|
+
grant_type: 'refresh_token',
|
|
49
|
+
client_id: API_KEY,
|
|
50
|
+
refresh_token: token,
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
context: { credsPayload },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const {
|
|
61
|
+
access_token: accessToken,
|
|
62
|
+
refresh_token: newRefreshToken,
|
|
63
|
+
expires_in: expiresIn,
|
|
64
|
+
token_type: tokenType,
|
|
65
|
+
} = response.data ?? {};
|
|
66
|
+
|
|
67
|
+
if (!accessToken || !newRefreshToken) {
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
error: {
|
|
71
|
+
code: 'TOKEN_RESPONSE_INCOMPLETE',
|
|
72
|
+
message: 'Etsy did not return access_token and refresh_token.',
|
|
73
|
+
details: response.data,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
ok: true,
|
|
80
|
+
data: {
|
|
81
|
+
accessToken,
|
|
82
|
+
refreshToken: newRefreshToken,
|
|
83
|
+
expiresIn,
|
|
84
|
+
tokenType,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const funcApiConfig = {
|
|
90
|
+
argsWarden,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
module.exports = {
|
|
94
|
+
etsyAccessTokenRefresh,
|
|
95
|
+
funcApiConfig,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
curl -X POST "http://localhost:8000/etsyAccessTokenRefresh" \
|
|
100
|
+
-H "Content-Type: application/json" \
|
|
101
|
+
-d '{
|
|
102
|
+
"credsPayload": {
|
|
103
|
+
"credsPath": "etsy"
|
|
104
|
+
}
|
|
105
|
+
}'
|
|
106
|
+
*/
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// https://developers.etsy.com/documentation/essentials/authentication/#step-3-request-an-access-token
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { credsFromPayload, ArgsWarden } = require('../utils');
|
|
5
|
+
const { etsyClient } = require('./etsy.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['code'],
|
|
10
|
+
['redirectUri'],
|
|
11
|
+
['codeVerifier'],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const etsyAccessTokenRequest = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
code,
|
|
17
|
+
redirectUri,
|
|
18
|
+
codeVerifier,
|
|
19
|
+
{
|
|
20
|
+
fetchClient = etsyClient,
|
|
21
|
+
} = {},
|
|
22
|
+
) => {
|
|
23
|
+
|
|
24
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
25
|
+
credsPayload,
|
|
26
|
+
code,
|
|
27
|
+
redirectUri,
|
|
28
|
+
codeVerifier,
|
|
29
|
+
});
|
|
30
|
+
if (rejectResponse) {
|
|
31
|
+
return rejectResponse;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const creds = await credsFromPayload(credsPayload);
|
|
35
|
+
const { API_KEY } = creds;
|
|
36
|
+
|
|
37
|
+
if (!API_KEY) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
error: {
|
|
41
|
+
code: 'INVALID_CREDS',
|
|
42
|
+
message: 'API_KEY is required.',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const response = await fetchClient.fetch({
|
|
48
|
+
requestPayload: {
|
|
49
|
+
method: 'post',
|
|
50
|
+
url: '/public/oauth/token',
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
53
|
+
},
|
|
54
|
+
body: new URLSearchParams({
|
|
55
|
+
grant_type: 'authorization_code',
|
|
56
|
+
client_id: API_KEY,
|
|
57
|
+
redirect_uri: redirectUri,
|
|
58
|
+
code,
|
|
59
|
+
code_verifier: codeVerifier,
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
context: { credsPayload },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
return response;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
access_token: accessToken,
|
|
71
|
+
refresh_token: refreshToken,
|
|
72
|
+
expires_in: expiresIn,
|
|
73
|
+
token_type: tokenType,
|
|
74
|
+
} = response.data ?? {};
|
|
75
|
+
|
|
76
|
+
if (!accessToken || !refreshToken) {
|
|
77
|
+
return {
|
|
78
|
+
ok: false,
|
|
79
|
+
error: {
|
|
80
|
+
code: 'TOKEN_RESPONSE_INCOMPLETE',
|
|
81
|
+
message: 'Etsy did not return access_token and refresh_token.',
|
|
82
|
+
details: response.data,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
ok: true,
|
|
89
|
+
data: {
|
|
90
|
+
accessToken,
|
|
91
|
+
refreshToken,
|
|
92
|
+
expiresIn,
|
|
93
|
+
tokenType,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const funcApiConfig = {
|
|
99
|
+
argsWarden,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
module.exports = {
|
|
103
|
+
etsyAccessTokenRequest,
|
|
104
|
+
funcApiConfig,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/*
|
|
108
|
+
curl -X POST "http://localhost:8000/etsyAccessTokenRequest" \
|
|
109
|
+
-H "Content-Type: application/json" \
|
|
110
|
+
-d '{
|
|
111
|
+
"credsPayload": {
|
|
112
|
+
"credsPath": "etsy"
|
|
113
|
+
},
|
|
114
|
+
"code": "YOUR_CODE",
|
|
115
|
+
"redirectUri": "https://YOUR_NGROK/logEtsyAuthCodeResponse",
|
|
116
|
+
"codeVerifier": "YOUR_CODE_VERIFIER"
|
|
117
|
+
}'
|
|
118
|
+
*/
|