Skip to content

Commit

Permalink
fix: fix paywall not decrypt article
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSnow committed Apr 16, 2024
1 parent a59527b commit 66d1db1
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/karbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"changelogen": "0.5.5",
"fs-extra": "11.2.0",
"globby": "14.0.1",
"msw": "^2.2.13",
"nuxt": "3.7.3",
"prettier": "^3.2.5",
"tsup": "8.0.2",
Expand All @@ -157,4 +158,4 @@
"access": "public"
},
"gitHead": "8df1f4d5837a7e2ddbff6cc79f5fec256c34a394"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HttpResponse, graphql } from 'msw'
import { afterAll, expect, it } from 'vitest'
import { setupServer } from 'msw/node'
import isViewable from '../default-is-viewable.mjs'

const server = setupServer(
graphql.query('SubscriberProfile', () => {
return HttpResponse.json({
data: {
subscriberProfile: {
id: '1',
subscribed: true,
},
},
})
}),
)

server.listen()

afterAll(() => {
server.close()
})

it('can check subscribe status', async () => {
await expect(
isViewable({ meta: {} as any, auth: { token: 'token' }, getArticle: (() => {}) as any }),
).resolves.toEqual({
pass: true,
})
})
17 changes: 15 additions & 2 deletions packages/karbon/src/runtime/app/default-is-viewable.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { gql } from '@apollo/client/core/index.js'
import { defineIsViewable } from '@storipress/karbon/helper'
import { createStoripressBaseClient, createTenantURL } from '@storipress/karbon/internal'
import { ApolloClient, ApolloLink, HttpLink, InMemoryCache, Observable, gql } from '@apollo/client/core/index.js'
import { useRuntimeConfig } from '#imports'

const apollo = {
ApolloClient,
ApolloLink,
HttpLink,
InMemoryCache,
Observable,
}

const SubscriberProfileQuery = gql`
query SubscriberProfile {
subscriberProfile {
Expand All @@ -21,9 +29,14 @@ export default defineIsViewable(async ({ meta, auth }) => {
}

const { storipress } = useRuntimeConfig()

const client = createStoripressBaseClient(
() => ({ authorization: `Bearer ${auth.token}` }),
apollo,
() => ({
authorization: `Bearer ${auth.token}`,
}),
createTenantURL(storipress),
{ name: 'subscriber' },
)
let profile

Expand Down
7 changes: 6 additions & 1 deletion packages/karbon/src/test-helpers/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ function notImplemented(name: string) {

export const useAsyncData = notImplemented('useAsyncData')
export const useNuxtApp = notImplemented('useNuxtApp')
export const useRuntimeConfig = notImplemented('useRuntimeConfig')
export const useRuntimeConfig = () => ({
storipress: {
apiHost: 'api.stori.press',
clientId: 'client_id',
},
})
Loading

0 comments on commit 66d1db1

Please sign in to comment.