How to use the @serverless/utils.set function in @serverless/utils

To help you get started, we’ve selected a few @serverless/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless / components / registry / AwsApiGateway / src / utils.js View on Github external
const defaultResponses = getDefaultResponses(isCorsEnabled)
      updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
      updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
      if (securityDefinition) {
        updatedMethods = set(
          [normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))

    if (enableCorsOnPath) {
      const corsOptionsMethod = getCorsOptionsConfig()
      updatedMethods = set('options', corsOptionsMethod, updatedMethods)
    }

    // set the paths
    paths = set([normalizedPath], updatedMethods, paths)
  }, or(routes, {}))
github serverless / components / src / utils / serialize / utils / serializeObject.js View on Github external
(accum, value, key) => {
      value = resolve(value)
      if (isSerializable(value)) {
        if (isSymbol(key)) {
          const symbolString = getSymbolString(context, key)
          if (symbolString) {
            if (isSerializableReferenceable(value)) {
              return set(['symbols', symbolString], toReference(context, value), accum)
            }
            return set(['symbols', symbolString], serializeValue(context, value), accum)
          }
          // context.log(`unhandled symbol detected ${toString(key)}`)
        } else {
          if (isSerializableReferenceable(value)) {
            return set(['props', key], toReference(context, value), accum)
          }
          return set(['props', key], serializeValue(context, value), accum)
        }
      }
      return accum
    },
    {
github serverless / components / registry / RestApi / src / utils.js View on Github external
const defaultResponses = getDefaultResponses(isCorsEnabled)
      updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
      updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
      if (securityDefinition) {
        updatedMethods = set(
          [normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))

    if (enableCorsOnPath) {
      const corsOptionsMethod = getCorsOptionsConfig()
      updatedMethods = set('options', corsOptionsMethod, updatedMethods)
    }

    // set the paths
    paths = set([normalizedPath], updatedMethods, paths)
  }, or(routes, {}))
github serverless / components / registry / AwsApiGateway / src / utils.js View on Github external
'x-amazon-apigateway-integration': {
      type: 'aws_proxy',
      httpMethod: 'POST',
      credentials: roleArn,
      uri,
      responses: {
        default: {
          statusCode: '200'
        }
      }
    }
  }

  if (useCors) {
    let apiGatewayIntegrationWithCors = { ...apiGatewayIntegration }
    apiGatewayIntegrationWithCors = set(
      ['x-amazon-apigateway-integration', 'responses', 'default', 'responseParameters'],
      {
        'method.response.header.Access-Control-Allow-Headers':
          "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
        'method.response.header.Access-Control-Allow-Methods': "'*'",
        'method.response.header.Access-Control-Allow-Origin': "'*'"
      },
      apiGatewayIntegrationWithCors
    )
    return apiGatewayIntegrationWithCors
  }
  return apiGatewayIntegration
}
github serverless / components / registry / RestApi / src / utils.js View on Github external
function getDefaultResponses(useCors) {
  const defaultResponses = {
    200: {
      description: 'Success'
    }
  }

  if (useCors) {
    let defaultResponsesWithCors = { ...defaultResponses }
    defaultResponsesWithCors = set(
      [200],
      {
        headers: {
          'Access-Control-Allow-Headers': {
            type: 'string'
          },
          'Access-Control-Allow-Methods': {
            type: 'string'
          },
          'Access-Control-Allow-Origin': {
            type: 'string'
          }
        }
      },
      defaultResponsesWithCors
    )
github serverless / components / registry / RestApi / src / utils.js View on Github external
enableCorsOnPath = true
      } else {
        isCorsEnabled = false
      }

      const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
      const securityDefinition = getSecurityDefinition(
        methodObject.authorizer,
        name,
        undefined,
        normalizedPath,
        normalizedMethod
      )
      const defaultResponses = getDefaultResponses(isCorsEnabled)
      updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
      updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
      if (securityDefinition) {
        updatedMethods = set(
          [normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))
github serverless / components / registry / RestApi / src / utils.js View on Github external
isCorsEnabled = false
      }

      const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
      const securityDefinition = getSecurityDefinition(
        methodObject.authorizer,
        name,
        undefined,
        normalizedPath,
        normalizedMethod
      )
      const defaultResponses = getDefaultResponses(isCorsEnabled)
      updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
      updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
      if (securityDefinition) {
        updatedMethods = set(
          [normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))
github serverless / components / registry / RestApi / src / utils.js View on Github external
isCorsEnabled = true
        enableCorsOnPath = true
      } else {
        isCorsEnabled = false
      }

      const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
      const securityDefinition = getSecurityDefinition(
        methodObject.authorizer,
        name,
        undefined,
        normalizedPath,
        normalizedMethod
      )
      const defaultResponses = getDefaultResponses(isCorsEnabled)
      updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
      updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
      if (securityDefinition) {
        updatedMethods = set(
          [normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))
github serverless / components / registry / AwsApiGateway / src / utils.js View on Github external
enableCorsOnPath = true
      } else {
        isCorsEnabled = false
      }

      const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
      const securityDefinition = getSecurityDefinition(
        methodObject.authorizer,
        name,
        undefined,
        normalizedPath,
        normalizedMethod
      )
      const defaultResponses = getDefaultResponses(isCorsEnabled)
      updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
      updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
      if (securityDefinition) {
        updatedMethods = set(
          [normalizedMethod, 'security'],
          [{ [securityDefinition.name]: [] }],
          updatedMethods
        )
        securityDefinitions[securityDefinition.name] = securityDefinition.definition
      }
    }, or(methods, {}))