File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,13 @@ import {
9
9
10
10
type Headers = Record < string , string >
11
11
12
- export const getAuthHeaders = ( options : SeamHttpOptions ) : Headers => {
12
+ export const getAuthHeaders = (
13
+ options : SeamHttpOptions | { publishableKey : string } ,
14
+ ) : Headers => {
15
+ if ( 'publishableKey' in options ) {
16
+ return getAuthHeadersForPublishableKey ( options . publishableKey )
17
+ }
18
+
13
19
if ( isSeamHttpOptionsWithApiKey ( options ) ) {
14
20
return getAuthHeadersForApiKey ( options )
15
21
}
@@ -19,7 +25,7 @@ export const getAuthHeaders = (options: SeamHttpOptions): Headers => {
19
25
}
20
26
21
27
throw new SeamHttpInvalidOptionsError (
22
- 'Must specify an apiKey or clientSessionToken ' ,
28
+ 'Must specify an apiKey, clientSessionToken, or publishableKey ' ,
23
29
)
24
30
}
25
31
@@ -80,6 +86,12 @@ const getAuthHeadersForClientSessionToken = ({
80
86
}
81
87
}
82
88
89
+ const getAuthHeadersForPublishableKey = ( publishableKey : string ) : Headers => {
90
+ return {
91
+ 'seam-publishable-key' : publishableKey ,
92
+ }
93
+ }
94
+
83
95
export class SeamHttpInvalidTokenError extends Error {
84
96
constructor ( message : string ) {
85
97
super ( `SeamHttp received an invalid token: ${ message } ` )
Original file line number Diff line number Diff line change @@ -20,7 +20,11 @@ export interface ClientOptions {
20
20
21
21
type AxiosRetryConfig = Parameters < AxiosRetry > [ 1 ]
22
22
23
- export const createClient = ( options : Required < SeamHttpOptions > ) : Axios => {
23
+ type Options =
24
+ | Required < SeamHttpOptions >
25
+ | ( Required < ClientOptions > & { publishableKey : string } )
26
+
27
+ export const createClient = ( options : Options ) : Axios => {
24
28
if ( isSeamHttpOptionsWithClient ( options ) ) return options . client
25
29
26
30
const client = axios . create ( {
Original file line number Diff line number Diff line change 1
- import { type Client , createClient } from './client.js'
1
+ import { type Client , type ClientOptions , createClient } from './client.js'
2
2
import {
3
3
isSeamHttpOptionsWithApiKey ,
4
4
isSeamHttpOptionsWithClient ,
@@ -70,6 +70,21 @@ export class SeamHttp {
70
70
return new SeamHttp ( opts )
71
71
}
72
72
73
+ static async fromPublishableKey (
74
+ publishableKey : string ,
75
+ userIdentifierKey : string ,
76
+ options : ClientOptions = { } ,
77
+ ) : Promise < SeamHttp > {
78
+ const opts = parseOptions ( options )
79
+ const client = createClient ( { ...opts , publishableKey } )
80
+ const clientSessions = SeamHttpClientSessions . fromClient ( client )
81
+ // TODO: clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey })
82
+ const { token } = await clientSessions . create ( {
83
+ user_identifier_key : userIdentifierKey ,
84
+ } )
85
+ return SeamHttp . fromClientSessionToken ( token , options )
86
+ }
87
+
73
88
get accessCodes ( ) : SeamHttpAccessCodes {
74
89
return SeamHttpAccessCodes . fromClient ( this . client )
75
90
}
You can’t perform that action at this time.
0 commit comments