Skip to content

Commit

Permalink
fix(stripe-utils): update TS typings
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdbd committed Jul 27, 2022
1 parent a4fa9a8 commit 59b57c3
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 63 deletions.
2 changes: 1 addition & 1 deletion docs/stripe-utils/interfaces/DuplicatesConfig.html

Large diffs are not rendered by default.

37 changes: 24 additions & 13 deletions docs/stripe-utils/modules.html

Large diffs are not rendered by default.

42 changes: 41 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@types/pollyjs__persister-fs": "^2.0.1",
"@types/simple-oauth2": "^4.1.1",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.31.0",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"better-sqlite3": "^7.5.3",
Expand Down Expand Up @@ -114,7 +115,7 @@
"stripe": "^9.8.0",
"ts-node": "^10.8.1",
"typedoc": "^0.22.17",
"typescript": "^4.7.3",
"typescript": "^4.7.4",
"wait-port": "^0.2.9",
"yargs": "^17.5.1",
"zx": "^6.2.4"
Expand Down
21 changes: 3 additions & 18 deletions packages/stripe-utils/.ae/stripe-utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
import Stripe from 'stripe';

// Warning: (ae-forgotten-export) The symbol "Config" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "createPriceWithTaxBehavior" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const createPriceWithTaxBehavior: ({ behavior, price, stripe, created_at, created_by }: Config_2) => Promise<Stripe.Response<Stripe.Price>>;

// Warning: (ae-forgotten-export) The symbol "Config" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "customerFromPaymentIntentId" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const customerFromPaymentIntentId: ({ stripe, pi_id }: Config) => Promise<{
Expand All @@ -25,13 +23,10 @@ export const customerFromPaymentIntentId: ({ stripe, pi_id }: Config) => Promise
}>;

// Warning: (ae-forgotten-export) The symbol "EmailIds" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "duplicates" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const duplicates: ({ stripe, threshold, ts_start, ts_stop }: DuplicatesConfig) => Promise<EmailIds>;

// Warning: (ae-missing-release-tag) "DuplicatesConfig" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface DuplicatesConfig {
// (undocumented)
Expand All @@ -50,8 +45,6 @@ export interface DuplicatesConfig {
// @public
export const enabledEventsForWebhookEndpoint: ({ stripe, url }: EnabledEventsForWebhookEndpoint) => Promise<string[]>;

// Warning: (ae-missing-release-tag) "errorFromStripe" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const errorFromStripe: (err: Stripe.StripeError) => {
code: string | undefined;
Expand All @@ -60,21 +53,13 @@ export const errorFromStripe: (err: Stripe.StripeError) => {
status_code: number;
};

// Warning: (ae-missing-release-tag) "isApiKeyLiveMode" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export const isApiKeyLiveMode: (s: string) => boolean;

// Warning: (ae-missing-release-tag) "isApiKeyTestMode" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export const isApiKeyTestMode: (s: string) => boolean;

// Warning: (ae-missing-release-tag) "stripeAccountMode" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export const stripeAccountMode: (api_key: string) => "live" | "test";

// (No @packageDocumentation comment for this package)

```
2 changes: 1 addition & 1 deletion packages/stripe-utils/.ae/tsdoc-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"toolPackages": [
{
"packageName": "@microsoft/api-extractor",
"packageVersion": "7.25.0"
"packageVersion": "7.28.6"
}
]
}
2 changes: 1 addition & 1 deletion packages/stripe-utils/api-docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

| Package | Description |
| --- | --- |
| [@jackdbd/stripe-utils](./stripe-utils.md) | |
| [@jackdbd/stripe-utils](./stripe-utils.md) | Utility functions that might be useful when working with Stripe. |

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Create a new `Stripe.Price` with a defined `tax_behavior`<!-- -->.

In Stripe we can update only `nickname` and `metadata` of a `Price`<!-- -->, so if we need to define `tax_behavior` we have to create a new `Price`<!-- -->. https://stripe.com/docs/billing/subscriptions/products-and-prices\#changing-prices
In Stripe we can update only `nickname` and `metadata` of a `Price`<!-- -->, so if we need to define `tax_behavior` we have to create a new `Price`<!-- -->.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## customerFromPaymentIntentId variable

Extract the Stripe Customer from a Payment Intent Id.
Extracts the Stripe Customer from a Payment Intent Id.

<b>Signature:</b>

Expand Down
13 changes: 7 additions & 6 deletions packages/stripe-utils/api-docs/stripe-utils.duplicatesconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## DuplicatesConfig interface


<b>Signature:</b>

```typescript
Expand All @@ -12,10 +13,10 @@ export interface DuplicatesConfig

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [stripe](./stripe-utils.duplicatesconfig.stripe.md) | Stripe | |
| [threshold?](./stripe-utils.duplicatesconfig.threshold.md) | number | <i>(Optional)</i> |
| [ts\_start](./stripe-utils.duplicatesconfig.ts_start.md) | number | |
| [ts\_stop](./stripe-utils.duplicatesconfig.ts_stop.md) | number | |
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [stripe](./stripe-utils.duplicatesconfig.stripe.md) | | Stripe | |
| [threshold?](./stripe-utils.duplicatesconfig.threshold.md) | | number | <i>(Optional)</i> |
| [ts\_start](./stripe-utils.duplicatesconfig.ts_start.md) | | number | |
| [ts\_stop](./stripe-utils.duplicatesconfig.ts_stop.md) | | number | |

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

## errorFromStripe variable

Convert an error coming from Stripe into an object with a consistent shape.

https://github.com/stripe/stripe-node/blob/4e82ccafda2017654ac264c070e7ebfa0e662fcd/lib/Error.js https://github.com/stripe/stripe-node/wiki/Error-Handling https://stripe.com/docs/error-codes
Converts an error coming from Stripe into an object with a consistent shape.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## isApiKeyLiveMode variable

Checks whether the given string is an API key for a Stripe account in `live` mode.

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## isApiKeyTestMode variable

Checks whether the given string is an API key for a Stripe account in `test` mode.

<b>Signature:</b>

```typescript
Expand Down
16 changes: 9 additions & 7 deletions packages/stripe-utils/api-docs/stripe-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## stripe-utils package

Utility functions that might be useful when working with Stripe.

## Interfaces

| Interface | Description |
Expand All @@ -14,12 +16,12 @@

| Variable | Description |
| --- | --- |
| [createPriceWithTaxBehavior](./stripe-utils.createpricewithtaxbehavior.md) | Create a new <code>Stripe.Price</code> with a defined <code>tax_behavior</code>.<!-- -->In Stripe we can update only <code>nickname</code> and <code>metadata</code> of a <code>Price</code>, so if we need to define <code>tax_behavior</code> we have to create a new <code>Price</code>. https://stripe.com/docs/billing/subscriptions/products-and-prices\#changing-prices |
| [customerFromPaymentIntentId](./stripe-utils.customerfrompaymentintentid.md) | Extract the Stripe Customer from a Payment Intent Id. |
| [createPriceWithTaxBehavior](./stripe-utils.createpricewithtaxbehavior.md) | <p>Create a new <code>Stripe.Price</code> with a defined <code>tax_behavior</code>.</p><p>In Stripe we can update only <code>nickname</code> and <code>metadata</code> of a <code>Price</code>, so if we need to define <code>tax_behavior</code> we have to create a new <code>Price</code>.</p> |
| [customerFromPaymentIntentId](./stripe-utils.customerfrompaymentintentid.md) | Extracts the Stripe Customer from a Payment Intent Id. |
| [duplicates](./stripe-utils.duplicates.md) | Emails that appear more than <code>threshold</code> times in the given Stripe account. The search is restricted to the time range starting from <code>ts_start</code> to <code>ts_stop</code> (both excluded, and both expressed in Unix timestamps in seconds). |
| [enabledEventsForWebhookEndpoint](./stripe-utils.enabledeventsforwebhookendpoint.md) | List of webhook events that the Stripe account <code>stripe</code> is allowed to send to the webhook endpoint <code>url</code>.<!-- -->\*Note\*: you have to configure the events that Stripe sends to a webhook endpoint when you create/update a webhook endpoint in your Stripe account. |
| [errorFromStripe](./stripe-utils.errorfromstripe.md) | Convert an error coming from Stripe into an object with a consistent shape.<!-- -->https://github.com/stripe/stripe-node/blob/4e82ccafda2017654ac264c070e7ebfa0e662fcd/lib/Error.js https://github.com/stripe/stripe-node/wiki/Error-Handling https://stripe.com/docs/error-codes |
| [isApiKeyLiveMode](./stripe-utils.isapikeylivemode.md) | |
| [isApiKeyTestMode](./stripe-utils.isapikeytestmode.md) | |
| [stripeAccountMode](./stripe-utils.stripeaccountmode.md) | |
| [enabledEventsForWebhookEndpoint](./stripe-utils.enabledeventsforwebhookendpoint.md) | <p>List of webhook events that the Stripe account <code>stripe</code> is allowed to send to the webhook endpoint <code>url</code>.</p><p>\*Note\*: you have to configure the events that Stripe sends to a webhook endpoint when you create/update a webhook endpoint in your Stripe account.</p> |
| [errorFromStripe](./stripe-utils.errorfromstripe.md) | Converts an error coming from Stripe into an object with a consistent shape. |
| [isApiKeyLiveMode](./stripe-utils.isapikeylivemode.md) | Checks whether the given string is an API key for a Stripe account in <code>live</code> mode. |
| [isApiKeyTestMode](./stripe-utils.isapikeytestmode.md) | Checks whether the given string is an API key for a Stripe account in <code>test</code> mode. |
| [stripeAccountMode](./stripe-utils.stripeaccountmode.md) | Given a Stripe API key, infers whether the Stripe client was initialized in <code>live</code> mode or <code>test</code> mode. |

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## stripeAccountMode variable

Given a Stripe API key, infers whether the Stripe client was initialized in `live` mode or `test` mode.

<b>Signature:</b>

```typescript
Expand Down
10 changes: 10 additions & 0 deletions packages/stripe-utils/src/checks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/**
* Checks whether the given string is an API key for a Stripe account in `live` mode.
*
* @public
*/
export const isApiKeyLiveMode = (s: string) => {
return s.slice(0, 8) === 'sk_live_'
}

/**
* Checks whether the given string is an API key for a Stripe account in `test` mode.
*
* @public
*/
export const isApiKeyTestMode = (s: string) => {
return s.slice(0, 8) === 'sk_test_'
}
8 changes: 8 additions & 0 deletions packages/stripe-utils/src/customers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import type Stripe from 'stripe'

/**
* @public
*/
export interface EmailIds {
[email: string]: string[]
}

/**
* @public
*/
export interface DuplicatesConfig {
stripe: Stripe
threshold?: number
Expand All @@ -15,6 +21,8 @@ export interface DuplicatesConfig {
* Emails that appear more than `threshold` times in the given Stripe account.
* The search is restricted to the time range starting from `ts_start` to
* `ts_stop` (both excluded, and both expressed in Unix timestamps in seconds).
*
* @public
*/
export const duplicates = async ({
stripe,
Expand Down
10 changes: 6 additions & 4 deletions packages/stripe-utils/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Stripe from 'stripe'

/**
* Convert an error coming from Stripe into an object with a consistent shape.
* Converts an error coming from Stripe into an object with a consistent shape.
*
* https://github.com/stripe/stripe-node/blob/4e82ccafda2017654ac264c070e7ebfa0e662fcd/lib/Error.js
* https://github.com/stripe/stripe-node/wiki/Error-Handling
* https://stripe.com/docs/error-codes
* @public
*
* @see [Error.js - stripe-node](https://github.com/stripe/stripe-node/blob/4e82ccafda2017654ac264c070e7ebfa0e662fcd/lib/Error.js)
* @see [Error Handling - stripe-node Wiki](https://github.com/stripe/stripe-node/wiki/Error-Handling)
* @see [Error codes - Stripe Docs](https://stripe.com/docs/error-codes)
*/
export const errorFromStripe = (err: Stripe.StripeError) => {
const prefix = '[stripe] '
Expand Down
6 changes: 6 additions & 0 deletions packages/stripe-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Utility functions that might be useful when working with Stripe.
*
* @packageDocumentation
*/

export { isApiKeyLiveMode, isApiKeyTestMode } from './checks.js'

export { duplicates } from './customers.js'
Expand Down
4 changes: 3 additions & 1 deletion packages/stripe-utils/src/payment_intents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ interface Config {
}

/**
* Extract the Stripe Customer from a Payment Intent Id.
* Extracts the Stripe Customer from a Payment Intent Id.
*
* @public
*/
export const customerFromPaymentIntentId = async ({
stripe,
Expand Down
Loading

0 comments on commit 59b57c3

Please sign in to comment.