Skip to content

Commit

Permalink
Expose type (#62)
Browse files Browse the repository at this point in the history
* Export SDKError and ClientConfig

* Upgrade scripts and samples to jsr

* Remove dependency on std/media_types
  • Loading branch information
tomas-zijdemans-vipps authored Sep 14, 2024
1 parent 8c3676c commit 55eb070
Show file tree
Hide file tree
Showing 33 changed files with 200 additions and 162 deletions.
11 changes: 11 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"imports": {
"@deno/dnt": "jsr:@deno/dnt@^0.41.3",
"@hey-api/openapi-ts": "npm:@hey-api/openapi-ts",
"@lambdalisue/systemopen": "jsr:@lambdalisue/systemopen@^1.0.0",
"@std/cli": "jsr:@std/cli@^1.0.6",
"@std/dotenv": "jsr:@std/dotenv@^0.225.2",
"@std/fmt": "jsr:@std/fmt@^1.0.2",
"@std/semver": "jsr:@std/semver@^1.0.3"
}
}
2 changes: 1 addition & 1 deletion sample_code/checkout_sample.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "https://deno.land/std@0.224.0/dotenv/load.ts";
import "@std/dotenv/load";
import { Client, InitiatePaymentSessionRequest } from "../src/mod.ts";

// First, get your API keys from https://portal.vipps.no/
Expand Down
6 changes: 3 additions & 3 deletions sample_code/epayment_sample.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { open } from "https://deno.land/x/open@v0.0.6/index.ts";
import "https://deno.land/std@0.224.0/dotenv/load.ts";
import { systemopen } from "@lambdalisue/systemopen";
import "@std/dotenv/load";
import { Client, CreatePaymentRequest } from "../src/mod.ts";

// First, get your API keys from https://portal.vipps.no/
Expand Down Expand Up @@ -57,7 +57,7 @@ console.log("📋 Payment reference:", reference);

// Open the payment redirect URL in the browser
if (payment.data.redirectUrl) {
await open(payment.data.redirectUrl);
await systemopen(payment.data.redirectUrl);
} else {
console.error("😟 Error: Redirect URL is undefined 😟");
}
2 changes: 1 addition & 1 deletion sample_code/webhook_sample.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "https://deno.land/std@0.224.0/dotenv/load.ts";
import "@std/dotenv/load";
import { Client } from "../src/mod.ts";

// First, get your API keys from https://portal.vipps.no/
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_npm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { build, emptyDir } from "jsr:@deno/dnt";
import { build, emptyDir } from "@deno/dnt";

/**
* This script builds the SDK for NPM.
Expand Down
20 changes: 10 additions & 10 deletions scripts/generate_types.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import { createClient } from "npm:@hey-api/openapi-ts";
import { createClient } from "@hey-api/openapi-ts";
import { run } from "./run.ts";

// Access Token API
await createClient({
input:
"https://developer.vippsmobilepay.com/redocusaurus/access-token-swagger-id.yaml",
output: "src/apis/generated_types/access_token",
output: "src/generated_types/access_token",
services: false,
exportCore: false,
schemas: false,
});

await run(`rm -rf src/apis/generated_types/access_token/index.ts`);
await run(`rm -rf src/generated_types/access_token/index.ts`);

// Checkout API
await createClient({
input:
"https://developer.vippsmobilepay.com/redocusaurus/checkout-swagger-id.yaml",
output: "src/apis/generated_types/checkout",
output: "src/generated_types/checkout",
services: false,
exportCore: false,
schemas: false,
});

await run(`rm -rf src/apis/generated_types/checkout/index.ts`);
await run(`rm -rf src/generated_types/checkout/index.ts`);

// ePayment API
await createClient({
input:
"https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml",
output: "src/apis/generated_types/epayment",
output: "src/generated_types/epayment",
services: false,
exportCore: false,
schemas: false,
});

await run(`rm -rf src/apis/generated_types/epayment/index.ts`);
await run(`rm -rf src/generated_types/epayment/index.ts`);

// Webhooks API
await createClient({
input:
"https://developer.vippsmobilepay.com/redocusaurus/webhooks-swagger-id.yaml",
output: "src/apis/generated_types/webhooks",
output: "src/generated_types/webhooks",
services: false,
exportCore: false,
schemas: false,
});

await run(`rm -rf src/apis/generated_types/webhooks/index.ts`);
await run(`rm -rf src/generated_types/webhooks/index.ts`);

// Auto-format the code
await run(`deno fmt`);
await run(`deno fmt --quiet`, "Auto-formatting the code...");
4 changes: 2 additions & 2 deletions scripts/publish_latest_tag_to_npm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bold, gray, green, white } from "jsr:@std/fmt/colors";
import { greaterThan, parse } from "jsr:@std/semver";
import { bold, gray, green, white } from "@std/fmt/colors";
import { greaterThan, parse } from "@std/semver";
import { run } from "./run.ts";

const PACKAGE_NAME = `@vippsmobilepay/sdk`;
Expand Down
2 changes: 1 addition & 1 deletion scripts/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Spinner } from "jsr:@std/cli";
import { Spinner } from "@std/cli/unstable-spinner";

type CommandResult = {
ok: true;
Expand Down
2 changes: 1 addition & 1 deletion src/api_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { authRequestFactory } from "./apis/auth.ts";
import { checkoutRequestFactory } from "./apis/checkout.ts";
import { ePaymentRequestFactory } from "./apis/epayment.ts";
import { webhooksRequestFactory } from "./apis/webhooks.ts";
import type { ApiProxy, BaseClient, RequestFactory } from "./types.ts";
import type { ApiProxy, BaseClient, RequestFactory } from "./types_internal.ts";

export type SDKClient = {
auth: ReturnType<typeof proxifyFactory<typeof authRequestFactory>>;
Expand Down
4 changes: 2 additions & 2 deletions src/apis/auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RequestData } from "../types.ts";
import type { RequestData } from "../types_internal.ts";
import type {
AccessTokenError,
AuthorizationTokenResponse,
} from "./external_types.ts";
} from "../types_external.ts";

/**
* Factory for creating authentication-related request data.
Expand Down
4 changes: 2 additions & 2 deletions src/apis/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { uuid } from "../deps.ts";
import type { RequestData } from "../types.ts";
import type { RequestData } from "../types_internal.ts";
import type {
CheckoutProblemDetails,
InitiatePaymentSessionRequest,
InitiateSessionResponse,
InitiateSubscriptionSessionRequest,
SessionResponse,
} from "./external_types.ts";
} from "../types_external.ts";

/**
* Factory object for creating checkout request data.
Expand Down
4 changes: 2 additions & 2 deletions src/apis/epayment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uuid } from "../deps.ts";
import type { RequestData } from "../types.ts";
import type { RequestData } from "../types_internal.ts";
import type {
CancelPaymentResponse,
CaptureModificationRequest,
Expand All @@ -13,7 +13,7 @@ import type {
Problem,
RefundModificationRequest,
RefundPaymentResponse,
} from "./external_types.ts";
} from "../types_external.ts";

/**
* Factory object for creating ePayment API requests.
Expand Down
4 changes: 2 additions & 2 deletions src/apis/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { RequestData } from "../types.ts";
import type { RequestData } from "../types_internal.ts";
import type {
ProblemDetails,
QueryResponse,
RegisterRequest,
RegisterResponse,
} from "./external_types.ts";
} from "../types_external.ts";

/**
* Factory object for creating webhooks requests.
Expand Down
4 changes: 2 additions & 2 deletions src/base_client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
BaseClient,
ClientConfig,
ClientResponse,
RequestData,
} from "./types.ts";
} from "./types_internal.ts";
import type { ClientConfig } from "./types_external.ts";
import { buildRequest } from "./base_client_helper.ts";
import { parseError } from "./errors.ts";
import { validateRequestData } from "./validate.ts";
Expand Down
5 changes: 2 additions & 3 deletions src/base_client_helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { filterKeys } from "./deps.ts";
import type {
ClientConfig,
DefaultHeaders,
OmitHeaders,
RequestData,
} from "./types.ts";

} from "./types_internal.ts";
import type { ClientConfig } from "./types_external.ts";
import { uuid } from "./deps.ts";

/**
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RetryError } from "./deps.ts";
import type { SDKError } from "./types.ts";
import type { SDKError } from "./types_external.ts";

/**
* Parses the error and returns an object with error details.
Expand Down
2 changes: 1 addition & 1 deletion src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
isSuccessfulStatus,
parseResponseToJson,
} from "./fetch_helper.ts";
import type { ClientResponse } from "./types.ts";
import type { ClientResponse } from "./types_internal.ts";

/**
* Executes a fetch request with optional retry logic.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ClientConfig } from "./types.ts";
import { baseClient } from "./base_client.ts";
import { proxifyClient, type SDKClient } from "./api_proxy.ts";
import type { ClientConfig } from "./types_external.ts";

// Export all API types, for convenience.
export type * from "./apis/external_types.ts";
export type * from "./types_external.ts";

/**
* Creates a new SDK client.
Expand Down
111 changes: 0 additions & 111 deletions src/types.ts

This file was deleted.

Loading

0 comments on commit 55eb070

Please sign in to comment.