feat(utils,types,framework,medusa): store endpoints should require publishable key (#9068)

* feat(utils,types,framework,medusa): store endpoints should require publishable key

* chore: fix specs

* chore: fix more specs

* chore: update js-sdk

* chore: fix specs wrt to default SC

* chore: revert custom headers + change error message

* chore: fix specs

* chore: fix new store specs
This commit is contained in:
Riqwan Thamir
2024-09-11 15:08:37 +02:00
committed by GitHub
parent fdd0543011
commit a729fb3fbb
29 changed files with 1037 additions and 464 deletions

View File

@@ -1,5 +1,15 @@
import { IAuthModuleService, IUserModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
import {
ApiKeyDTO,
IApiKeyModuleService,
IAuthModuleService,
IUserModuleService,
MedusaContainer,
} from "@medusajs/types"
import {
ApiKeyType,
ModuleRegistrationName,
PUBLISHABLE_KEY_HEADER,
} from "@medusajs/utils"
import jwt from "jsonwebtoken"
import Scrypt from "scrypt-kdf"
import { getContainer } from "../environment-helpers/use-container"
@@ -61,3 +71,28 @@ export const createAdminUser = async (
return { user, authIdentity }
}
export const generatePublishableKey = async (container?: MedusaContainer) => {
const appContainer = container ?? getContainer()!
const apiKeyModule = appContainer.resolve<IApiKeyModuleService>(
ModuleRegistrationName.API_KEY
)
return await apiKeyModule.createApiKeys({
title: "test publishable key",
type: ApiKeyType.PUBLISHABLE,
created_by: "test",
})
}
export const generateStoreHeaders = ({
publishableKey,
}: {
publishableKey: ApiKeyDTO
}) => {
return {
headers: {
[PUBLISHABLE_KEY_HEADER]: publishableKey.token,
},
}
}