Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core to version a4d007e7 #122

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions client/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
release_client,
invoke_sync,
} from "@1password/sdk-core";
import { throwError } from "./errors";

/**
* Exposes the SDK core to the host JS SDK.
Expand Down Expand Up @@ -81,17 +82,29 @@ export interface Parameters {
export class SharedCore implements Core {
public invoke_sync(config: InvokeConfig): string {
const serializedConfig = JSON.stringify(config);
return invoke_sync(serializedConfig);
try {
return invoke_sync(serializedConfig);
} catch (e) {
throwError(e as string);
}
}

public async initClient(config: ClientAuthConfig): Promise<string> {
const serializedConfig = JSON.stringify(config);
return init_client(serializedConfig);
try {
return await init_client(serializedConfig);
} catch (e) {
throwError(e as string);
}
}

public async invoke(config: InvokeConfig): Promise<string> {
const serializedConfig = JSON.stringify(config);
return invoke(serializedConfig);
try {
return await invoke(serializedConfig);
} catch (e) {
throwError(e as string);
}
}

public releaseClient(clientId: number): void {
Expand Down
31 changes: 31 additions & 0 deletions client/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Code generated by op-codegen - DO NOT EDIT MANUALLY

export class RateLimitExceededError extends Error {
public message: string;

public constructor(message: string) {
super();
this.message = message;
}
}

export const throwError = (errString: string) => {
interface TypedError {
name: string;
message: string;
}

let err: TypedError;
try {
err = JSON.parse(errString) as TypedError;
} catch (e) {
throw new Error(errString);
}

switch (err.name) {
case "RateLimitExceeded":
throw new RateLimitExceededError(err.message);
default:
throw new Error(err.message);
}
};
30 changes: 14 additions & 16 deletions client/src/items.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Code generated by op-codegen - DO NOT EDIT MANUALLY

import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
import * as types from "./types.js";
import { SdkIterable } from "./iterator.js";
import { Item, ItemCreateParams, ItemOverview } from "./types.js";
import { ItemsSharesApi, ItemsShares } from "./items_shares.js";

/**
Expand All @@ -13,17 +13,17 @@ export interface ItemsApi {
/**
* Create a new item.
*/
create(params: types.ItemCreateParams): Promise<types.Item>;
create(params: ItemCreateParams): Promise<Item>;

/**
* Get an item by vault and item ID
*/
get(vaultId: string, itemId: string): Promise<types.Item>;
get(vaultId: string, itemId: string): Promise<Item>;

/**
* Update an existing item.
*/
put(item: types.Item): Promise<types.Item>;
put(item: Item): Promise<Item>;

/**
* Delete an item.
Expand All @@ -38,7 +38,7 @@ export interface ItemsApi {
/**
* List all items
*/
listAll(vaultId: string): Promise<SdkIterable<types.ItemOverview>>;
listAll(vaultId: string): Promise<SdkIterable<ItemOverview>>;
}

export class Items implements ItemsApi {
Expand All @@ -53,7 +53,7 @@ export class Items implements ItemsApi {
/**
* Create a new item.
*/
public async create(params: types.ItemCreateParams): Promise<types.Item> {
public async create(params: ItemCreateParams): Promise<Item> {
const invocationConfig: InvokeConfig = {
invocation: {
clientId: this.#inner.id,
Expand All @@ -67,13 +67,13 @@ export class Items implements ItemsApi {
};
return JSON.parse(
await this.#inner.core.invoke(invocationConfig),
) as Promise<types.Item>;
) as Promise<Item>;
}

/**
* Get an item by vault and item ID
*/
public async get(vaultId: string, itemId: string): Promise<types.Item> {
public async get(vaultId: string, itemId: string): Promise<Item> {
const invocationConfig: InvokeConfig = {
invocation: {
clientId: this.#inner.id,
Expand All @@ -88,13 +88,13 @@ export class Items implements ItemsApi {
};
return JSON.parse(
await this.#inner.core.invoke(invocationConfig),
) as Promise<types.Item>;
) as Promise<Item>;
}

/**
* Update an existing item.
*/
public async put(item: types.Item): Promise<types.Item> {
public async put(item: Item): Promise<Item> {
const invocationConfig: InvokeConfig = {
invocation: {
clientId: this.#inner.id,
Expand All @@ -108,7 +108,7 @@ export class Items implements ItemsApi {
};
return JSON.parse(
await this.#inner.core.invoke(invocationConfig),
) as Promise<types.Item>;
) as Promise<Item>;
}

/**
Expand Down Expand Up @@ -152,9 +152,7 @@ export class Items implements ItemsApi {
/**
* List all items
*/
public async listAll(
vaultId: string,
): Promise<SdkIterable<types.ItemOverview>> {
public async listAll(vaultId: string): Promise<SdkIterable<ItemOverview>> {
const invocationConfig: InvokeConfig = {
invocation: {
clientId: this.#inner.id,
Expand All @@ -166,10 +164,10 @@ export class Items implements ItemsApi {
},
},
};
return new SdkIterable<types.ItemOverview>(
return new SdkIterable<ItemOverview>(
JSON.parse(
await this.#inner.core.invoke(invocationConfig),
) as types.ItemOverview[],
) as ItemOverview[],
);
}
}
35 changes: 20 additions & 15 deletions client/src/items_shares.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Code generated by op-codegen - DO NOT EDIT MANUALLY

import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
import * as types from "./types.js";
import { SdkIterable } from "./iterator.js";
import {
Item,
ItemShareAccountPolicy,
ItemShareParams,
ValidRecipient,
} from "./types.js";

export interface ItemsSharesApi {
/**
Expand All @@ -11,23 +16,23 @@ export interface ItemsSharesApi {
getAccountPolicy(
vaultId: string,
itemId: string,
): Promise<types.ItemShareAccountPolicy>;
): Promise<ItemShareAccountPolicy>;

/**
* Validate the recipients of an item sharing link.
*/
validateRecipients(
policy: types.ItemShareAccountPolicy,
policy: ItemShareAccountPolicy,
recipients: string[],
): Promise<types.ValidRecipient[]>;
): Promise<ValidRecipient[]>;

/**
* Create a new item sharing link.
*/
create(
item: types.Item,
policy: types.ItemShareAccountPolicy,
params: types.ItemShareParams,
item: Item,
policy: ItemShareAccountPolicy,
params: ItemShareParams,
): Promise<string>;
}

Expand All @@ -44,7 +49,7 @@ export class ItemsShares implements ItemsSharesApi {
public async getAccountPolicy(
vaultId: string,
itemId: string,
): Promise<types.ItemShareAccountPolicy> {
): Promise<ItemShareAccountPolicy> {
const invocationConfig: InvokeConfig = {
invocation: {
clientId: this.#inner.id,
Expand All @@ -59,16 +64,16 @@ export class ItemsShares implements ItemsSharesApi {
};
return JSON.parse(
await this.#inner.core.invoke(invocationConfig),
) as Promise<types.ItemShareAccountPolicy>;
) as Promise<ItemShareAccountPolicy>;
}

/**
* Validate the recipients of an item sharing link.
*/
public async validateRecipients(
policy: types.ItemShareAccountPolicy,
policy: ItemShareAccountPolicy,
recipients: string[],
): Promise<types.ValidRecipient[]> {
): Promise<ValidRecipient[]> {
const invocationConfig: InvokeConfig = {
invocation: {
clientId: this.#inner.id,
Expand All @@ -83,16 +88,16 @@ export class ItemsShares implements ItemsSharesApi {
};
return JSON.parse(
await this.#inner.core.invoke(invocationConfig),
) as Promise<types.ValidRecipient[]>;
) as Promise<ValidRecipient[]>;
}

/**
* Create a new item sharing link.
*/
public async create(
item: types.Item,
policy: types.ItemShareAccountPolicy,
params: types.ItemShareParams,
item: Item,
policy: ItemShareAccountPolicy,
params: ItemShareParams,
): Promise<string> {
const invocationConfig: InvokeConfig = {
invocation: {
Expand Down
1 change: 1 addition & 0 deletions client/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DEFAULT_INTEGRATION_VERSION = "Unknown";
export { Secrets } from "./secrets.js";

export * from "./client.js";
export * from "./errors.js";
export * from "./types.js";

/**
Expand Down
8 changes: 4 additions & 4 deletions client/src/secrets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Code generated by op-codegen - DO NOT EDIT MANUALLY

import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
import * as types from "./types.js";
import { SdkIterable } from "./iterator.js";
import { GeneratePasswordResponse, PasswordRecipe } from "./types.js";

/**
* The Secrets API includes all operations the SDK client can perform on secrets.
Expand Down Expand Up @@ -61,8 +61,8 @@ export class Secrets implements SecretsApi {
}

public static generatePassword(
recipe: types.PasswordRecipe,
): types.GeneratePasswordResponse {
recipe: PasswordRecipe,
): GeneratePasswordResponse {
const sharedCore = new SharedCore();
const invocationConfig: InvokeConfig = {
invocation: {
Expand All @@ -76,6 +76,6 @@ export class Secrets implements SecretsApi {
};
return JSON.parse(
sharedCore.invoke_sync(invocationConfig),
) as types.GeneratePasswordResponse;
) as GeneratePasswordResponse;
}
}
10 changes: 5 additions & 5 deletions client/src/vaults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Code generated by op-codegen - DO NOT EDIT MANUALLY

import { InvokeConfig, InnerClient, SharedCore } from "./core.js";
import * as types from "./types.js";
import { SdkIterable } from "./iterator.js";
import { VaultOverview } from "./types.js";

/**
* The Vaults API holds all the operations the SDK client can perform on 1Password vaults.
Expand All @@ -11,7 +11,7 @@ export interface VaultsApi {
/**
* List all vaults
*/
listAll(): Promise<SdkIterable<types.VaultOverview>>;
listAll(): Promise<SdkIterable<VaultOverview>>;
}

export class Vaults implements VaultsApi {
Expand All @@ -24,7 +24,7 @@ export class Vaults implements VaultsApi {
/**
* List all vaults
*/
public async listAll(): Promise<SdkIterable<types.VaultOverview>> {
public async listAll(): Promise<SdkIterable<VaultOverview>> {
const invocationConfig: InvokeConfig = {
invocation: {
clientId: this.#inner.id,
Expand All @@ -34,10 +34,10 @@ export class Vaults implements VaultsApi {
},
},
};
return new SdkIterable<types.VaultOverview>(
return new SdkIterable<VaultOverview>(
JSON.parse(
await this.#inner.core.invoke(invocationConfig),
) as types.VaultOverview[],
) as VaultOverview[],
);
}
}
23 changes: 8 additions & 15 deletions wasm/nodejs/core.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
/* tslint:disable */
/* eslint-disable */
/**
* Initializes an SDK client with a given configuration.
* @param {string} config
* @returns {Promise<string>}
*/
* Initializes an SDK client with a given configuration.
*/
export function init_client(config: string): Promise<string>;
/**
* Handles all asynchronous invocations to the SDK core received from the SDK.
* @param {string} parameters
* @returns {Promise<string>}
*/
* Handles all asynchronous invocations to the SDK core received from the SDK.
*/
export function invoke(parameters: string): Promise<string>;
/**
* Handles all synchronous invocations to the SDK core received from the SDK.
* @param {string} parameters
* @returns {string}
*/
* Handles all synchronous invocations to the SDK core received from the SDK.
*/
export function invoke_sync(parameters: string): string;
/**
* Drops a client, releasing the memory allocated for it.
* @param {string} client_id
*/
* Drops a client, releasing the memory allocated for it.
*/
export function release_client(client_id: string): void;
Loading
Loading