Add an OSDK to a bootstrapped repository(向引导初始化的仓库添加 OSDK)¶
This guide explains how to add an OSDK to a repository that was originally bootstrapped without one. It assumes that you bootstrapped your repository from Developer Console in Foundry or locally using the @osdk/create-app CLI. If you have a custom setup, some steps may need to be adjusted.
Required changes¶
Follow the steps below to add an OSDK to your application.
1. Update index.html¶
Add the following meta tag inside the <head> section of your index.html file:
<!DOCTYPE html>
<html>
<head>
<!-- Other head content -->
<meta name="osdk-ontologyRid" content="%VITE_FOUNDRY_ONTOLOGY_RID%" />
<!-- Other head content -->
</head>
<body>
<!-- Body content -->
</body>
</html>
2. Update environment files¶
Add the following environment variable to all environment variable files present in your project. For example: .env.development, .env.production, and .env.code-workspaces:
VITE_FOUNDRY_ONTOLOGY_RID=<ri.ontology.main.ontology.your-ontology-rid>
Replace <ri.ontology.main.ontology.your-ontology-rid> with your OSDK's Ontology RID.
You can find the Ontology RID in Ontology Manager.
3. Update client.ts¶
Read the Ontology RID and initialize the client object:
- import { createPlatformClient, type PlatformClient } from "@osdk/client";
+ import { type Client, createClient } from "@osdk/client";
+ const ontologyRid = getMetaTagContent("osdk-ontologyRid");
- export const client: PlatformClient = createPlatformClient(foundryUrl, auth);
+ export const client: Client = createClient(foundryUrl, ontologyRid, auth);
4. Update package.json¶
Add your OSDK package as a dependency:
{
"dependencies": {
+ "<osdk-package-name>/sdk": "latest"
// Other dependencies
}
}
Replace <osdk-package-name> with your OSDK package name.
You can find the OSDK package name under Developer Console > Overview > Generated SDKs.
5. Update .npmrc¶
:::callout{theme="warning"}
You only need to perform this step if you bootstrapped the repository in a local development environment.
If you bootstrapped the repository in Foundry, skip this step.
:::
Add the registry URL of your OSDK package.
+ <osdk-package-name>:registry=<registry-url>
Replace <osdk-package-name> and <registry-url> with your OSDK package name and registry URL.
- You can find the package name and registry URL under Developer Console > Overview > Generated SDKs.
- Do not include
/sdkin the OSDK package name.
The following is an example .npmrc file:
//hostname.palantirfoundry.com/artifacts/api/:\_authToken=${FOUNDRY_TOKEN}
@osdk-package:registry=https://hostname.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.45660bd6-de33-442e-9f48-a0c02372b906/contents/release/npm
中文翻译¶
向引导初始化的仓库添加 OSDK¶
本指南说明如何向最初未包含 OSDK 的引导初始化仓库中添加 OSDK。前提是您已通过 Foundry 的开发者控制台(Developer Console)或使用 @osdk/create-app CLI 在本地完成了仓库的引导初始化。如果您使用的是自定义设置,部分步骤可能需要调整。
所需更改¶
请按照以下步骤向您的应用程序添加 OSDK。
1. 更新 index.html¶
在 index.html 文件的 <head> 部分中添加以下元标签:
<!DOCTYPE html>
<html>
<head>
<!-- 其他 head 内容 -->
<meta name="osdk-ontologyRid" content="%VITE_FOUNDRY_ONTOLOGY_RID%" />
<!-- 其他 head 内容 -->
</head>
<body>
<!-- 正文内容 -->
</body>
</html>
2. 更新环境变量文件¶
将以下环境变量添加到项目中所有现有的环境变量文件中。例如:.env.development、.env.production 和 .env.code-workspaces:
VITE_FOUNDRY_ONTOLOGY_RID=<ri.ontology.main.ontology.your-ontology-rid>
将 <ri.ontology.main.ontology.your-ontology-rid> 替换为您的 OSDK 的本体论 RID(Ontology RID)。
您可以在本体论管理器(Ontology Manager)中找到本体论 RID。
3. 更新 client.ts¶
读取本体论 RID 并初始化客户端对象:
- import { createPlatformClient, type PlatformClient } from "@osdk/client";
+ import { type Client, createClient } from "@osdk/client";
+ const ontologyRid = getMetaTagContent("osdk-ontologyRid");
- export const client: PlatformClient = createPlatformClient(foundryUrl, auth);
+ export const client: Client = createClient(foundryUrl, ontologyRid, auth);
4. 更新 package.json¶
将您的 OSDK 包添加为依赖项:
{
"dependencies": {
+ "<osdk-package-name>/sdk": "latest"
// 其他依赖项
}
}
将 <osdk-package-name> 替换为您的 OSDK 包名称。
您可以在 开发者控制台(Developer Console) > 概览(Overview) > 生成的 SDK(Generated SDKs) 下找到 OSDK 包名称。
5. 更新 .npmrc¶
:::callout{theme="warning"}
仅当您在本地开发环境中引导初始化仓库时才需要执行此步骤。
如果您在 Foundry 中引导初始化了仓库,请跳过此步骤。
:::
添加您的 OSDK 包的注册表 URL。
+ <osdk-package-name>:registry=<registry-url>
将 <osdk-package-name> 和 <registry-url> 替换为您的 OSDK 包名称和注册表 URL。
- 您可以在 开发者控制台(Developer Console) > 概览(Overview) > 生成的 SDK(Generated SDKs) 下找到包名称和注册表 URL。
- 不要在 OSDK 包名称中包含
/sdk。
以下是一个 .npmrc 文件的示例:
//hostname.palantirfoundry.com/artifacts/api/:\_authToken=${FOUNDRY_TOKEN}
@osdk-package:registry=https://hostname.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.45660bd6-de33-442e-9f48-a0c02372b906/contents/release/npm