Skip to content

Commit

Permalink
Introduce createPlatformClient (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericanderson authored Jun 7, 2024
1 parent a519655 commit dd6033a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shy-cougars-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/client": patch
---

Adds a createPlatformClient if you only need platform apis
10 changes: 10 additions & 0 deletions examples-extra/basic/cli/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { createPlatformClient } from "@osdk/client";
import type { Client } from "@osdk/client/unstable-do-not-use";
import { createClient } from "@osdk/client/unstable-do-not-use";
import invariant from "tiny-invariant";
Expand All @@ -30,3 +31,12 @@ export const client: Client = createClient(
{ logger },
loggingFetch,
);

/**
* Generally consumers wont need this and will use their createClient() but
* I want to use this to be sure everything works.
*/
export const platformClient = createPlatformClient(
process.env.FOUNDRY_STACK,
async () => process.env.FOUNDRY_USER_TOKEN!,
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { PalantirApiError } from "@osdk/client";
import { Datasets } from "@osdk/internal.foundry";
import { client } from "./client.js";
import { platformClient as client } from "./client.js";
import { logger } from "./logger.js";

export async function runFoundrySdkClientVerificationTest(
Expand Down
44 changes: 44 additions & 0 deletions packages/client/src/createPlatformClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createSharedClientContext } from "@osdk/shared.client.impl";
import { USER_AGENT } from "./util/UserAgent.js";

/**
* Creates a client that can only be used with Platform APIs.
*
* If you already have an OSDK Client (from `createClient`), you do not need to
* create one of these - those clients can be used with Platform APIs as well.
*
* @param baseUrl
* @param tokenProvider
* @param options Currently unused, reserved for future use.
* @param fetchFn
* @returns
*/
export function createPlatformClient(
baseUrl: string,
tokenProvider: () => Promise<string>,
options: undefined = undefined,
fetchFn: typeof globalThis.fetch = fetch,
) {
return createSharedClientContext(
baseUrl,
tokenProvider,
USER_AGENT,
fetchFn,
);
}
1 change: 1 addition & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export { PalantirApiError } from "@osdk/shared.net.errors";

export type { Client } from "./Client.js";
export { createClient } from "./createClient.js";
export { createPlatformClient } from "./createPlatformClient.js";

export { ActionValidationError } from "./actions/ActionValidationError.js";
export type { InterfaceObjectSet, ObjectSet } from "./objectSet/ObjectSet.js";
Expand Down

0 comments on commit dd6033a

Please sign in to comment.