3vot-salesforce-proxy 中文文档教程

发布于 10年前 浏览 32 项目主页 更新于 3年前

Deploy

3vot-salesforce-proxy

WHY

Salesforce 使用 OAUTH 2.0 用于身份验证,不提供直接从 Web 应用程序连接的 CORS。

更重要的是,Salesforce REST API 并不是为前端友好而设计的。 大多数模型和 AJAX 模块都不起作用。 Salesforce 应用程序开发人员最终不使用模型并直接与 Salesforce REST API 通信。 这种方法需要 APEX 和 Salesforce 的知识,使应用程序开发变得更加昂贵并且破坏了 M*VC。

What

用 NodeJS 编写的生产代理服务器,具有将标准传统 REST 转换为 Salesforce Rest API 的集群。 它使在 Javascript 中使用 Salesforce Data 变得容易。

开发人员可以简单地创建对象 Account.create({ Name: "Acme" }) - 查询 Account.query("select id, name from account") - 更新和删除'account.save()' - 'account.delete()'。

通过这种方式,前端开发人员可以构建 Salesforce 应用程序,从而降低成本并将开发速度提高 3 倍以上。

服务器包括基于 oauth2 或密码的登录,处理会话刷新并且它是无状态的,因此它可以立即扩展到无限大。

How

只需使用 Heroku 按钮即可让您的代理服务器立即运行! Deploy

从 NPM 部署通过使用文件 app.js 或 bin/www 作为节点启动脚本。

在您自己的服务器中使用 routes/login 和 routes/api 中的路由,确保您使用的是 cookie-session NPM 模块

More

This Server is part of ClayForSalesforce.com< /a> ,一个在浏览器和移动设备中为 Salesforce 开发现代前端应用程序作为 Visualforce/静态资源的平台。

Salesforce 有一个特殊的 Rest 特质,因为它为更新和删除返回 null,它们混合 Id 和 id 字段并返回包装在另一个对象中的 Rest 结果。 如果您解决了这个问题,它应该适用于大多数 Ajax 模型。

ClayforSalesforce 有一个名为 Clay Model 的多功能模型,可以与名为 clay-model-salesforce-api 的 Salesforce APi 适配器结合使用,这使得一切都开箱即用,并且作为一个附加功能,仅在更新时发送修改的字段,这非常棒在处理 CRUD 和 FLS 安全上下文中的更新时。

该软件包由 3VOT Corporation 提供支持。

Install

$ npm install 3vot-salesforce-proxy

Setup

安装可以通过使用 Heroku 按钮稍微加速 > APP_NAME,然后是 heroku cloneheroku config:pull

  1. 为本地主机 (localhost:5000) 和生产环境创建一个 Salesforce Connect 应用程序(使用您的服务器 url 或 xxxx.herokuapp。 com )

  2. 设置以下 ENV 变量文件 .env 和 .denv SALESFORCECLIENTID、SALESFORCECLIENTSECRET、SALESFORCEREDIRECTURL、NODE_ENV、ORIGINS

检查此要点以获得快速格式:https://gist。 github.com/rodriguezartav/b5ed90528075777d2edd

Getting Started

启动服务器 生产 foreman start - 自动加载 .env 生产 ./bin/ww - 加载 .env 开发 ./bin/w - 加载 .denv

将浏览器指向 http://localhost:5000/login ,检查 /session 和 /whoami

Using from an App

首先你必须登录,将浏览器指向 /login路由确保提供和 appurl 查询字符串变量。 这是登录后代理将重定向到的 URL。 您还可以将该值硬编码为名为 SALESFORCEFINAL_URL 的 ENV-VARIABLE

现在使用 OBJECT/ID url 的

Get 请求进行常规 HTTP REST API 调用 GET、POST、PUT、DEL 与 ?query=select… querystring 被视为 SOQL查询,添加 autoFetch 和 maxFetch 查询字符串参数来控制返回多少条记录。 即:http://localhost:5000/Account?query="select id, name from Account&autoFetch=true&maxFetch=10000"

也可以使用 Apex Rest 路由 [GET,POST,PUT,DEL,PATCH] apex/方法,其中方法是 APEX 测试方法名称。 当 [POST,PUT,DEL,PATCH] 时,可以在 http 正文中提供参数,对于 GET 请求,包括带有方法名称的查询字符串。 apex/method?param1=true

Rules

登录后代理将根据以下规则重定向:

  1. appurl: It will use the appurl query string provided to the login route. /login?app_url=myapp.com/start
  2. SALESFORCEFINALURL: ENV variable that points to a final route, use it when you only have one app.
  3. /login/whoami: By default, the proxy will redirect to the whoami route, the browser will end up here so it's not good to use the default other than when testing for development.

如果您在开发中运行代理,还有 /session 路由。 会输出Salesforce Security Token,这个对测试有效,方便获取token。 它不会在生产中可用,因为您将 ENV 变量 NODE_ENV 设置为“生产”

Using the Proxy

代理基于并使用 jsforce,因此请跟进 JSFORCE 文档,研究此 repo 中提供的测试或请求我们的支持。

该代理旨在开箱即用地使用 Javascript 模型,特别是使用 clay-model-salesforce-api 的粘土模型。

使用粘土模型时,在 Salesforce 内部部署的 Visualforce Remoting 或使用 API 和此代理外部​​部署的应用程序无需修改代码。

有关使用代理的更多信息可以在 Github 的 3VOT Profile 中的 clay-model 和 clay-model-salesforce-api 存储库中找到。

CORS

在环境变量 ORIGINS=*.DOMAIN.com 上设置允许的域,其他域以 ',' 分隔

Clustering

此 API 代理服务器启用了集群,我们还使用分叉来确保任何未处理的异常都不会停止服务器,只是工人,而主人刚刚启动了一个新工人。

Using in another server

为了在您的服务器中使用此代理,只需使用登录名和 api 路由即可。 登录路由并不是真正必需的,只要在会话中定义了 salesforce 属性即可。 就像 salesforce 返回它一样存储 saleforce 属性。

Testing

首先创建并填写在开发上运行的文件 .denv。 确保创建指向 http://localhost:5000/login/callback 的 Salesforce Connected App,并在 .denv 文件中设置客户端 ID 和密码。

使用 Tape,运行 tape ./test

Support

3VOT Saleforce Proxy 由 3VOT Corporation 支持,它是 Clay Plataform @ 3vot.com 的核心组件,

谢谢

Deploy

3vot-salesforce-proxy

WHY

Salesforce uses OAUTH 2.0 for authentication and does not provide CORS to connect directly from Web Apps.

More importantly the Salesforce REST API is not designed to be frontend friendly. Most Models and AJAX modules won't work. Salesforce App Developers end up not using models and communicating with Salesforce REST API directly. This approach requires knowledge of APEX and Salesforce, makes App Development much more expensive and breaks M*VC.

What

A Production Proxy Server written in NodeJS with clustering that translates standard traditional REST to Salesforce Rest API. It makes it easy work with Salesforce Data in Javascript.

Developers can simply create object Account.create({ Name: "Acme" }) - query Account.query("select id, name from account") - update and delete 'account.save()' - 'account.delete()'.

This way frontend developers can build Salesforce Apps, reducing costs and improving development speed in several by 3X+.

The server includes Login based in oauth2 or password, handles session refresh and it's stateless, so it can be scaled instantly up to infinity.

How

Simply use the Heroku Button to get your Proxy Server Running now! Deploy

Deploy from NPM by using the file app.js as or bin/www as node start script.

Use the routes in routes/login and routes/api in your own server, making sure you are using the cookie-session NPM module

More

This Server is part of ClayForSalesforce.com , a platform to develop Modern Frontend Apps for Salesforce as Visualforce/Static Resources, in the Browser and in Mobile Devices.

Salesforce has a particular Rest idiosyncrasy in that it returns null for updates and deletes, they mix Id and id fields and return the Rest results wrapped in another object. It should work with most Ajax Models if you cater for this issues.

ClayforSalesforce has a versatile model called Clay Model that can be used in conjuntion with the Salesforce APi Adapter called clay-model-salesforce-api which makes everything works out of the box and as an additional featurea only sends modified fields on update, which is great while dealing with update in context of CRUD and FLS Security.

This package is supported by 3VOT Corporation.

Install

$ npm install 3vot-salesforce-proxy

Setup

Setup can be somewhat accelerated by using the Heroku button > APP_NAME, then heroku clone and heroku config:pull

  1. Create a Salesforce Connect App for localhost (localhost:5000) and one for production ( using your server url or xxxx.herokuapp.com )

  2. Setup the following ENV Variables file .env and .denv SALESFORCECLIENTID, SALESFORCECLIENTSECRET, SALESFORCEREDIRECTURL, NODE_ENV, ORIGINS

Check this gist for a quick format: https://gist.github.com/rodriguezartav/b5ed90528075777d2edd

Getting Started

Start the server Production foreman start - auto loads .env Production ./bin/ww - loads .env Development ./bin/w - loads .denv

Point your browser to http://localhost:5000/login , check out /session and /whoami

Using from an App

First you must login, point your browser to the /login route make sure to supply and appurl query string variable. This is the URL where the Proxy will redirect after login. You can also hardcode this value as ENV-VARIABLE called SALESFORCEFINAL_URL

Now make regular HTTP REST API Calls GET,POST,PUT,DEL using OBJECT/ID url's

Get requests with a ?query=select… querystring are treated as SOQL Queries, add autoFetch and maxFetch query string params to control how many records to return. ie: http://localhost:5000/Account?query="select id, name from Account&autoFetch=true&maxFetch=10000"

Also available is the Apex Rest route [GET,POST,PUT,DEL,PATCH] apex/method where method is the APEX TEST method name. Params can be supplied in http body when [POST,PUT,DEL,PATCH], for GET request include querystring with the method name. apex/method?param1=true

Rules

After login the proxy will redirect depending on the following rules:

  1. appurl: It will use the appurl query string provided to the login route. /login?app_url=myapp.com/start
  2. SALESFORCEFINALURL: ENV variable that points to a final route, use it when you only have one app.
  3. /login/whoami: By default, the proxy will redirect to the whoami route, the browser will end up here so it's not good to use the default other than when testing for development.

If you are running the proxy in development, there is also the /session route. Which will output Salesforce Security Token, this is valid for testing and easily obtaining tokens. It will not be available in production becase you'll set the ENV Variable NODE_ENV to 'production'

Using the Proxy

The Proxy is based and uses jsforce, so follow up on JSFORCE documentation, study the tests provide in this repo or request support from us.

The proxy is designed to work out of the box with Javascript Models, specially clay-model using clay-model-salesforce-api.

When using clay-model, apps without code modification between Visualforce Remoting deployed inside Salesforce or deployed Externally using the API and this Proxy.

More information about using the proxy can be found in clay-model and clay-model-salesforce-api repositories in 3VOT Profile in Github.

CORS

Set the allowed domains on the enviroment variable ORIGINS=*.DOMAIN.com , other domains separated by ','

Clustering

This API Proxy server is enabled with clustering, we also use forking to make sure any unhandled exception won't stop the server, just the worker while the master just spins up a new worker.

Using in another server

In order to use this proxy in your server, simple use the login and api route. The login route is not really necessary, as long as the salesforce property is defined in the session. The saleforce property is stored just like salesforce returns it.

Testing

First create and fill in the file .denv that runs on development. Make sure to create a Salesforce Connected App that points to http://localhost:5000/login/callback and set the Client Id and Secret on .denv file.

Using Tape, run tape ./test

Support

3VOT Saleforce Proxy is supported by 3VOT Corporation and it's a core component of the Clay Plataform @ 3vot.com

Thank You

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文