File tree Expand file tree Collapse file tree 3 files changed +32
-30
lines changed Expand file tree Collapse file tree 3 files changed +32
-30
lines changed Original file line number Diff line number Diff line change @@ -128,29 +128,16 @@ app.post("/customer-context", async (c) => {
128
128
) ;
129
129
}
130
130
131
- if ( ! payload . DoitEmployee ) {
132
- // request validation for non-doit employees
133
- const validatePromise = await handleValidateUserRequest ( { } , apiKey ) ;
134
- const result = validatePromise . content [ 0 ] . text ;
135
-
136
- if ( ! result . toLowerCase ( ) . includes ( payload . sub ) ) {
137
- return await renderAuthorizationRejection (
138
- c ,
139
- oauthReqInfo ?. redirectUri || "/"
140
- ) ;
141
- }
142
-
143
- return await handleApprove ( c ) ;
144
- }
131
+ const doitEmployeeContext = payload . DoitEmployee
132
+ ? {
133
+ customerContext : "EE8CtpzYiKp0dVAESVrB" ,
134
+ }
135
+ : { } ;
145
136
146
- // request validation for doit employees
147
137
const validatePromise = await handleValidateUserRequest (
148
- {
149
- customerContext : "EE8CtpzYiKp0dVAESVrB" ,
150
- } ,
138
+ doitEmployeeContext ,
151
139
apiKey
152
140
) ;
153
-
154
141
const result = validatePromise . content [ 0 ] . text ;
155
142
156
143
if ( ! result . toLowerCase ( ) . includes ( payload . sub ) ) {
@@ -160,6 +147,11 @@ app.post("/customer-context", async (c) => {
160
147
) ;
161
148
}
162
149
150
+ if ( ! payload . DoitEmployee ) {
151
+ // request validation for non-doit employees
152
+ return await handleApprove ( c ) ;
153
+ }
154
+
163
155
const content = await renderCustomerContextScreen (
164
156
action ,
165
157
oauthReqInfo ,
Original file line number Diff line number Diff line change @@ -66,13 +66,21 @@ export class ContextStorage extends DurableObject {
66
66
}
67
67
68
68
async saveContext ( customerContext : string ) : Promise < void > {
69
- console . log ( "Saving customer context:" , customerContext , this . ctx . id ) ;
69
+ console . log (
70
+ "Saving customer context:" ,
71
+ customerContext ,
72
+ this . ctx . id . toString ( ) . slice ( - 6 )
73
+ ) ;
70
74
await this . ctx . storage . put ( "customerContext" , customerContext ) ;
71
75
}
72
76
73
77
async loadContext ( ) : Promise < string | null > {
74
78
const context = await this . ctx . storage . get < string > ( "customerContext" ) ;
75
- console . log ( "Loaded customer context:" , context , this . ctx . id ) ;
79
+ console . log (
80
+ "Loaded customer context:" ,
81
+ context ,
82
+ this . ctx . id . toString ( ) . slice ( - 6 )
83
+ ) ;
76
84
return context || null ;
77
85
}
78
86
}
Original file line number Diff line number Diff line change @@ -15,8 +15,6 @@ export const ChangeCustomerArgumentsSchema = z.object({
15
15
// Interfaces
16
16
export interface ChangeCustomerResponse {
17
17
success : boolean ;
18
- previousContext ?: string ;
19
- newContext : string ;
20
18
message : string ;
21
19
}
22
20
@@ -53,24 +51,28 @@ export async function handleChangeCustomerRequest(
53
51
54
52
const previousContext = args . customerContext ;
55
53
56
- // Update the customer context if callback is provided
57
- if ( updateCustomerContext ) {
58
- await updateCustomerContext ( newContext ) ;
59
- }
60
-
61
54
// Verify that the new context is valid
62
55
const newCustomerDomain = await handleValidateUserRequest (
63
56
{ customerContext : newContext } , // Validate doers
64
57
token
65
58
) ;
66
59
60
+ if ( newCustomerDomain . content [ 0 ] . text . toLowerCase ( ) . includes ( "failed" ) ) {
61
+ return createErrorResponse (
62
+ "Customer context is invalid. Please try again with a valid customer id."
63
+ ) ;
64
+ }
65
+
66
+ // Update the customer context if callback is provided
67
+ if ( updateCustomerContext ) {
68
+ await updateCustomerContext ( newContext ) ;
69
+ }
70
+
67
71
const domain = newCustomerDomain . content [ 0 ] . text . split ( "Domain: " ) [ 1 ] ;
68
72
69
73
// Create response
70
74
const response : ChangeCustomerResponse = {
71
75
success : true ,
72
- previousContext,
73
- newContext,
74
76
message : `Customer context successfully changed to '${ domain } '` ,
75
77
} ;
76
78
You can’t perform that action at this time.
0 commit comments