|
@@ -192,11 +192,6 @@ serve(async (req) => {
|
|
|
token_expires_at: new Date(Date.now() + (installation.expires_in * 1000)).toISOString(),
|
|
token_expires_at: new Date(Date.now() + (installation.expires_in * 1000)).toISOString(),
|
|
|
scopes: installation.scopes || [],
|
|
scopes: installation.scopes || [],
|
|
|
phone_number_id: phoneNumberId,
|
|
phone_number_id: phoneNumberId,
|
|
|
- data_access_permissions: {
|
|
|
|
|
- allow_customer_access: true,
|
|
|
|
|
- allow_order_access: true,
|
|
|
|
|
- allow_product_access: true
|
|
|
|
|
- },
|
|
|
|
|
alt_data: {
|
|
alt_data: {
|
|
|
token_type: installation.token_type,
|
|
token_type: installation.token_type,
|
|
|
expires_in: installation.expires_in,
|
|
expires_in: installation.expires_in,
|
|
@@ -494,78 +489,6 @@ serve(async (req) => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // PUT /api/stores/:id/permissions - Update data access permissions for a store
|
|
|
|
|
- if (path.match(/^stores\/[^\/]+\/permissions$/) && req.method === 'PUT') {
|
|
|
|
|
- const storeId = path.split('/')[1]
|
|
|
|
|
- const { data_access_permissions } = await req.json()
|
|
|
|
|
-
|
|
|
|
|
- if (!data_access_permissions || typeof data_access_permissions !== 'object') {
|
|
|
|
|
- return new Response(
|
|
|
|
|
- JSON.stringify({ error: 'data_access_permissions object is required' }),
|
|
|
|
|
- { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Validate permissions structure
|
|
|
|
|
- const validPermissions = ['allow_customer_access', 'allow_order_access', 'allow_product_access']
|
|
|
|
|
- for (const key of Object.keys(data_access_permissions)) {
|
|
|
|
|
- if (!validPermissions.includes(key)) {
|
|
|
|
|
- return new Response(
|
|
|
|
|
- JSON.stringify({ error: `Invalid permission key: ${key}` }),
|
|
|
|
|
- { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- if (typeof data_access_permissions[key] !== 'boolean') {
|
|
|
|
|
- return new Response(
|
|
|
|
|
- JSON.stringify({ error: `Permission ${key} must be a boolean value` }),
|
|
|
|
|
- { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Verify store ownership
|
|
|
|
|
- const { data: store, error: storeError } = await supabase
|
|
|
|
|
- .from('stores')
|
|
|
|
|
- .select('id')
|
|
|
|
|
- .eq('id', storeId)
|
|
|
|
|
- .eq('user_id', user.id)
|
|
|
|
|
- .single()
|
|
|
|
|
-
|
|
|
|
|
- if (storeError || !store) {
|
|
|
|
|
- return new Response(
|
|
|
|
|
- JSON.stringify({ error: 'Store not found or access denied' }),
|
|
|
|
|
- { status: 404, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Update store permissions
|
|
|
|
|
- const { error: updateError } = await supabase
|
|
|
|
|
- .from('stores')
|
|
|
|
|
- .update({
|
|
|
|
|
- data_access_permissions,
|
|
|
|
|
- updated_at: new Date().toISOString()
|
|
|
|
|
- })
|
|
|
|
|
- .eq('id', storeId)
|
|
|
|
|
- .eq('user_id', user.id)
|
|
|
|
|
-
|
|
|
|
|
- if (updateError) {
|
|
|
|
|
- console.error('Error updating data access permissions:', updateError)
|
|
|
|
|
- return new Response(
|
|
|
|
|
- JSON.stringify({ error: 'Failed to update permissions' }),
|
|
|
|
|
- { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return new Response(
|
|
|
|
|
- JSON.stringify({
|
|
|
|
|
- success: true,
|
|
|
|
|
- message: 'Data access permissions updated successfully',
|
|
|
|
|
- permissions: data_access_permissions
|
|
|
|
|
- }),
|
|
|
|
|
- { status: 200, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// PUT /api/stores/:id/access-policies - Update data access policies for a store (GDPR compliance)
|
|
// PUT /api/stores/:id/access-policies - Update data access policies for a store (GDPR compliance)
|
|
|
if (path.match(/^stores\/[^\/]+\/access-policies$/) && req.method === 'PUT') {
|
|
if (path.match(/^stores\/[^\/]+\/access-policies$/) && req.method === 'PUT') {
|
|
|
const storeId = path.split('/')[1]
|
|
const storeId = path.split('/')[1]
|