@endorr/core-sdk 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +76 -0
- package/dist/billing-sync.d.ts +74 -0
- package/dist/billing-sync.d.ts.map +1 -0
- package/dist/billing-sync.js +86 -0
- package/dist/billing-sync.js.map +1 -0
- package/dist/client.d.ts +65 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +46 -0
- package/dist/client.js.map +1 -1
- package/dist/entitlements.d.ts +17 -0
- package/dist/entitlements.d.ts.map +1 -0
- package/dist/entitlements.js +44 -0
- package/dist/entitlements.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +20 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/nextjs.d.ts +16 -1
- package/dist/nextjs.d.ts.map +1 -1
- package/dist/nextjs.js +37 -0
- package/dist/nextjs.js.map +1 -1
- package/dist/react.d.ts +34 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +29 -1
- package/dist/react.js.map +1 -1
- package/dist/types.d.ts +284 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -26
package/dist/errors.js
CHANGED
|
@@ -17,9 +17,24 @@ export class EndorrApiError extends Error {
|
|
|
17
17
|
return this.details?.find((d) => d.path === path)?.message;
|
|
18
18
|
}
|
|
19
19
|
get isUnauthorized() { return this.status === 401; }
|
|
20
|
+
get isPaymentRequired() { return this.status === 402; }
|
|
20
21
|
get isForbidden() { return this.status === 403; }
|
|
21
22
|
get isNotFound() { return this.status === 404; }
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 402 from Core: the organisation may not use the product or feature (`not_entitled`), or cannot
|
|
26
|
+
* afford the action (`insufficient_tokens`). `check` carries what fixes it: `addon`, `upgrade`, `top_up`.
|
|
27
|
+
*/
|
|
28
|
+
export class EndorrEntitlementError extends EndorrApiError {
|
|
29
|
+
check;
|
|
30
|
+
constructor(code, message, check, requestId) {
|
|
31
|
+
super(402, code, message, undefined, requestId);
|
|
32
|
+
this.check = check;
|
|
33
|
+
this.name = 'EndorrEntitlementError';
|
|
34
|
+
}
|
|
35
|
+
get reason() { return this.check.reason; }
|
|
36
|
+
get upgrade() { return this.check.upgrade; }
|
|
37
|
+
}
|
|
23
38
|
/** Error from the OAuth token/authorization endpoints (RFC 6749 §5.2). */
|
|
24
39
|
export class EndorrOAuthError extends Error {
|
|
25
40
|
error;
|
|
@@ -40,6 +55,10 @@ export async function throwForResponse(res) {
|
|
|
40
55
|
}
|
|
41
56
|
catch { /* not json */ }
|
|
42
57
|
const e = body?.error;
|
|
43
|
-
|
|
58
|
+
const requestId = e?.request_id ?? res.headers.get('x-request-id') ?? undefined;
|
|
59
|
+
if (res.status === 402 && (e?.code === 'not_entitled' || e?.code === 'insufficient_tokens') && e.details && typeof e.details === 'object') {
|
|
60
|
+
throw new EndorrEntitlementError(e.code, e.message ?? 'Not included in the current plan.', e.details, requestId);
|
|
61
|
+
}
|
|
62
|
+
throw new EndorrApiError(res.status, e?.code ?? 'http_error', e?.message ?? `Endorr Core answered ${res.status}`, e?.details, requestId);
|
|
44
63
|
}
|
|
45
64
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,+GAA+G;AAC/G,MAAM,OAAO,cAAe,SAAQ,KAAK;IAErB;IACA;IAEA;IACA;IALlB,YACkB,MAAc,EACd,IAAY,EAC5B,OAAe,EACC,OAA8C,EAC9C,SAAkB;QAElC,KAAK,CAAC,OAA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S,CAAC,CAAC;AAC/L,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export { EndorrOAuth, generatePkce, randomState, DEFAULT_SCOPES } from './oauth';
|
|
2
2
|
export type { OAuthConfig, AuthorizationUrlOptions } from './oauth';
|
|
3
3
|
export { EndorrClient } from './client';
|
|
4
|
-
export type { ClientConfig } from './client';
|
|
4
|
+
export type { ClientConfig, AccessQuery } from './client';
|
|
5
|
+
export { hasProduct, hasFeature, describeDenial, assertAllowed, PRODUCT_NAMES, FEATURE_NAMES } from './entitlements';
|
|
5
6
|
export { uploadFile } from './upload';
|
|
7
|
+
export { EndorrBillingSync } from './billing-sync';
|
|
8
|
+
export type { BillingSyncConfig } from './billing-sync';
|
|
6
9
|
export type { UploadOptions } from './upload';
|
|
7
|
-
export { EndorrApiError, EndorrOAuthError } from './errors';
|
|
10
|
+
export { EndorrApiError, EndorrOAuthError, EndorrEntitlementError } from './errors';
|
|
8
11
|
export * from './types';
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACjF,YAAY,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACjF,YAAY,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACrH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACpF,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { EndorrOAuth, generatePkce, randomState, DEFAULT_SCOPES } from './oauth';
|
|
2
2
|
export { EndorrClient } from './client';
|
|
3
|
+
export { hasProduct, hasFeature, describeDenial, assertAllowed, PRODUCT_NAMES, FEATURE_NAMES } from './entitlements';
|
|
3
4
|
export { uploadFile } from './upload';
|
|
4
|
-
export {
|
|
5
|
+
export { EndorrBillingSync } from './billing-sync';
|
|
6
|
+
export { EndorrApiError, EndorrOAuthError, EndorrEntitlementError } from './errors';
|
|
5
7
|
export * from './types';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACrH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACpF,cAAc,SAAS,CAAC"}
|
package/dist/nextjs.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EndorrOAuth, type OAuthConfig } from './oauth';
|
|
2
|
-
import type { IdTokenClaims, TokenSet } from './types';
|
|
2
|
+
import type { AccessCheck, IdTokenClaims, TokenSet } from './types';
|
|
3
|
+
import type { AccessQuery, EndorrClient } from './client';
|
|
3
4
|
/**
|
|
4
5
|
* Next.js (App Router) helpers for the Login with Endorr dance.
|
|
5
6
|
*
|
|
@@ -41,4 +42,18 @@ export declare function endorrLoginHandler(auth: EndorrAuth): {
|
|
|
41
42
|
export declare function endorrCallbackHandler(auth: EndorrAuth, handlers: CallbackHandlers): {
|
|
42
43
|
GET: (req: Request) => Promise<Response>;
|
|
43
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Gate a server action, page or handler: `await requireEntitlement(core, { product: 'printreadysheets' })`.
|
|
47
|
+
* Throws EndorrEntitlementError when denied; `entitlementErrorResponse` turns it into a 402.
|
|
48
|
+
*/
|
|
49
|
+
export declare function requireEntitlement(client: EndorrClient, q: AccessQuery): Promise<AccessCheck>;
|
|
50
|
+
/** 402 JSON carrying the check (reason, usage, upgrade), or null when `err` is not an entitlement error. */
|
|
51
|
+
export declare function entitlementErrorResponse(err: unknown): Response | null;
|
|
52
|
+
/**
|
|
53
|
+
* Route-handler wrapper: runs `handler` only when the organisation may, answers 402 otherwise
|
|
54
|
+
* (also when the handler's own `recordUsage` hits the limit).
|
|
55
|
+
*
|
|
56
|
+
* export const POST = withEntitlement((req) => coreFor(req), { metric: 'filefixer_fixes' }, async (req, access) => { … });
|
|
57
|
+
*/
|
|
58
|
+
export declare function withEntitlement<Ctx = unknown>(clientFor: (req: Request) => EndorrClient | Promise<EndorrClient>, q: AccessQuery, handler: (req: Request, access: AccessCheck, ctx: Ctx) => Promise<Response> | Response): (req: Request, ctx: Ctx) => Promise<Response>;
|
|
44
59
|
//# sourceMappingURL=nextjs.d.ts.map
|
package/dist/nextjs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../src/nextjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6B,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../src/nextjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6B,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG1D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,aAAa,CAAC,EAAE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AAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,IAExE,KAAK,OAAO,EAAE,KAAK,GAAG,KAAG,OAAO,CAAC,QAAQ,CAAC,CAUzD"}
|
package/dist/nextjs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EndorrOAuth, generatePkce, randomState } from './oauth';
|
|
2
|
+
import { EndorrEntitlementError } from './errors';
|
|
2
3
|
const enc = new TextEncoder();
|
|
3
4
|
async function hmac(secret, data) {
|
|
4
5
|
const key = await crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
@@ -89,4 +90,40 @@ export function endorrLoginHandler(auth) {
|
|
|
89
90
|
export function endorrCallbackHandler(auth, handlers) {
|
|
90
91
|
return { GET: (req) => auth.callback(req, handlers) };
|
|
91
92
|
}
|
|
93
|
+
/* ── Entitlements ─────────────────────────────────────────────────────────────── */
|
|
94
|
+
/**
|
|
95
|
+
* Gate a server action, page or handler: `await requireEntitlement(core, { product: 'printreadysheets' })`.
|
|
96
|
+
* Throws EndorrEntitlementError when denied; `entitlementErrorResponse` turns it into a 402.
|
|
97
|
+
*/
|
|
98
|
+
export function requireEntitlement(client, q) {
|
|
99
|
+
return client.billing.require(q);
|
|
100
|
+
}
|
|
101
|
+
/** 402 JSON carrying the check (reason, usage, upgrade), or null when `err` is not an entitlement error. */
|
|
102
|
+
export function entitlementErrorResponse(err) {
|
|
103
|
+
if (!(err instanceof EndorrEntitlementError))
|
|
104
|
+
return null;
|
|
105
|
+
return new Response(JSON.stringify({ error: { code: err.code, message: err.message, details: err.check } }), {
|
|
106
|
+
status: 402, headers: { 'content-type': 'application/json' },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Route-handler wrapper: runs `handler` only when the organisation may, answers 402 otherwise
|
|
111
|
+
* (also when the handler's own `recordUsage` hits the limit).
|
|
112
|
+
*
|
|
113
|
+
* export const POST = withEntitlement((req) => coreFor(req), { metric: 'filefixer_fixes' }, async (req, access) => { … });
|
|
114
|
+
*/
|
|
115
|
+
export function withEntitlement(clientFor, q, handler) {
|
|
116
|
+
return async (req, ctx) => {
|
|
117
|
+
try {
|
|
118
|
+
const access = await (await clientFor(req)).billing.require(q);
|
|
119
|
+
return await handler(req, access, ctx);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
const res = entitlementErrorResponse(err);
|
|
123
|
+
if (res)
|
|
124
|
+
return res;
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
92
129
|
//# sourceMappingURL=nextjs.js.map
|
package/dist/nextjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../src/nextjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAoB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../src/nextjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAoB,MAAM,SAAS,CAAC;AAGnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAuBlD,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC9B,KAAK,UAAU,IAAI,CAAC,MAAc,EAAE,IAAY;IAC9C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACzH,MAAM,GAAG,GAAG,IAAI,UAAU,C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AAC,CAAC,CAAC;AACnC,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,wBAAwB,CAAC,GAAY;IACnD,IAAI,CAAC,CAAC,GAAG,YAAY,sBAAsB,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1D,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE;QAC3G,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAC7D,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAiE,EACjE,CAAc,EACd,OAAsF;IAEtF,OAAO,KAAK,EAAE,GAAY,EAAE,GAAQ,EAAqB,EAAE;QACzD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC/D,OAAO,MAAM,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAC;YACpB,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import { EndorrClient, type ClientConfig } from './client';
|
|
2
|
+
import { EndorrClient, type AccessQuery, type ClientConfig } from './client';
|
|
3
3
|
import { type UploadOptions } from './upload';
|
|
4
|
-
import type { EndorrFile, Me } from './types';
|
|
4
|
+
import type { AccessCheck, EndorrFile, Entitlements, Me, Wallet } from './types';
|
|
5
5
|
export declare function EndorrProvider({ client, config, children }: {
|
|
6
6
|
client?: EndorrClient;
|
|
7
7
|
config?: ClientConfig;
|
|
@@ -21,6 +21,38 @@ export declare function useEndorrMe(): {
|
|
|
21
21
|
loading: boolean;
|
|
22
22
|
refresh: () => Promise<void>;
|
|
23
23
|
};
|
|
24
|
+
/** The organisation's plan, products and limits. Call `refresh` after a checkout or plan change. */
|
|
25
|
+
export declare function useEntitlements(organizationId?: string): {
|
|
26
|
+
data: Entitlements | null;
|
|
27
|
+
error: Error | null;
|
|
28
|
+
loading: boolean;
|
|
29
|
+
refresh: () => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
/** Live access check for a product, feature or action, with what would unlock it (add-on, plan, token pack). */
|
|
32
|
+
export declare function useAccess(q: AccessQuery): {
|
|
33
|
+
data: AccessCheck | null;
|
|
34
|
+
error: Error | null;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
refresh: () => Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
/** The organisation's token wallet. Call `refresh` after a spend or a top-up. */
|
|
39
|
+
export declare function useWallet(organizationId?: string): {
|
|
40
|
+
data: Wallet | null;
|
|
41
|
+
error: Error | null;
|
|
42
|
+
loading: boolean;
|
|
43
|
+
refresh: () => Promise<void>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Renders children only when the organisation may use the product. `fallback` may be a function of
|
|
47
|
+
* the check, to show the right upgrade prompt. UI gating only: the server must still enforce.
|
|
48
|
+
*
|
|
49
|
+
* <Entitled product="printreadysheets" fallback={(c) => <UpgradeCard plan={c.upgrade} />}>…</Entitled>
|
|
50
|
+
*/
|
|
51
|
+
export declare function Entitled({ fallback, loading, children, ...q }: AccessQuery & {
|
|
52
|
+
fallback?: ReactNode | ((check: AccessCheck) => ReactNode);
|
|
53
|
+
loading?: ReactNode;
|
|
54
|
+
children: ReactNode;
|
|
55
|
+
}): import("react").JSX.Element;
|
|
24
56
|
/** Direct-to-storage upload with progress. */
|
|
25
57
|
export declare function useEndorrUpload(): {
|
|
26
58
|
upload: (file: File, opts?: Omit<UploadOptions, "onProgress">) => Promise<EndorrFile | null>;
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AACA,OAAO,EAAgF,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACrH,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AACA,OAAO,EAAgF,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACrH,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AASjF,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,YAAY,CAAC;IAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAGjI;AAED,wBAAgB,SAAS,IAAI,YAAY,CAIxC;AAED,oHAAoH;AACpH,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,OAAO,EAAO;;;;;EAa/F;AAED,wBAAgB,WAAW;;;;;EAE1B;AAED,oGAAoG;AACpG,wBAAgB,eAAe,CAAC,cAAc,CAAC,EAAE,MAAM;;;;;EAEtD;AAED,gHAAgH;AAChH,wBAAgB,SAAS,CAAC,CAAC,EAAE,WAAW;;;;;EAEvC;AAED,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM;;;;;EAEhD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,EAAE,QAAe,EAAE,OAAc,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,EAAE,WAAW,GAAG;IAC1F,QAAQ,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,KAAK,SAAS,CAAC,CAAC;IAC3D,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB,+BAMA;AAED,8CAA8C;AAC9C,wBAAgB,eAAe;mBAKW,IAAI,SAAQ,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,KAAQ,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;;;;EAYxH"}
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { EndorrClient } from './client';
|
|
5
5
|
import { uploadFile } from './upload';
|
|
@@ -47,6 +47,34 @@ export function useEndorrQuery(fn, deps = []) {
|
|
|
47
47
|
export function useEndorrMe() {
|
|
48
48
|
return useEndorrQuery((c) => c.me.get());
|
|
49
49
|
}
|
|
50
|
+
/** The organisation's plan, products and limits. Call `refresh` after a checkout or plan change. */
|
|
51
|
+
export function useEntitlements(organizationId) {
|
|
52
|
+
return useEndorrQuery((c) => c.billing.entitlements(organizationId), [organizationId]);
|
|
53
|
+
}
|
|
54
|
+
/** Live access check for a product, feature or action, with what would unlock it (add-on, plan, token pack). */
|
|
55
|
+
export function useAccess(q) {
|
|
56
|
+
return useEndorrQuery((c) => c.billing.check(q), [q.product, q.feature, q.action, q.quantity, q.organizationId]);
|
|
57
|
+
}
|
|
58
|
+
/** The organisation's token wallet. Call `refresh` after a spend or a top-up. */
|
|
59
|
+
export function useWallet(organizationId) {
|
|
60
|
+
return useEndorrQuery((c) => c.billing.wallet(organizationId), [organizationId]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Renders children only when the organisation may use the product. `fallback` may be a function of
|
|
64
|
+
* the check, to show the right upgrade prompt. UI gating only: the server must still enforce.
|
|
65
|
+
*
|
|
66
|
+
* <Entitled product="printreadysheets" fallback={(c) => <UpgradeCard plan={c.upgrade} />}>…</Entitled>
|
|
67
|
+
*/
|
|
68
|
+
export function Entitled({ fallback = null, loading = null, children, ...q }) {
|
|
69
|
+
const { data, loading: busy } = useAccess(q);
|
|
70
|
+
if (busy && !data)
|
|
71
|
+
return _jsx(_Fragment, { children: loading });
|
|
72
|
+
if (data?.allowed)
|
|
73
|
+
return _jsx(_Fragment, { children: children });
|
|
74
|
+
if (typeof fallback === 'function')
|
|
75
|
+
return _jsx(_Fragment, { children: data ? fallback(data) : null });
|
|
76
|
+
return _jsx(_Fragment, { children: fallback });
|
|
77
|
+
}
|
|
50
78
|
/** Direct-to-storage upload with progress. */
|
|
51
79
|
export function useEndorrUpload() {
|
|
52
80
|
const client = useEndorr();
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACrH,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"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AC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,IAAU,EAAE,OAA0C,EAAE,EAA8B,EAAE;QACxH,YAAY,CAAC,IAAI,CAAC,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC;YACH,OAAO,MAAM,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAC9E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,QAAQ,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAChD,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -184,6 +184,9 @@ export interface StorageUsage {
|
|
|
184
184
|
temporary_bytes: number;
|
|
185
185
|
permanent_bytes: number;
|
|
186
186
|
file_count: number;
|
|
187
|
+
/** The plan's storage quota; permanent files count against it, temporary ones do not. */
|
|
188
|
+
permanent_quota_bytes: number;
|
|
189
|
+
plan: PlanKey;
|
|
187
190
|
}
|
|
188
191
|
export interface TokenSet {
|
|
189
192
|
access_token: string;
|
|
@@ -220,4 +223,285 @@ export interface UserInfo {
|
|
|
220
223
|
role: OrgRole;
|
|
221
224
|
}[];
|
|
222
225
|
}
|
|
226
|
+
export type PlanKey = 'free' | 'studio' | 'studio_plus';
|
|
227
|
+
export type AddonKey = 'printreadysheets';
|
|
228
|
+
export type ProductKey = 'printreadysheets' | 'filefixer' | 'easymockup' | 'pixlpilot' | 'endorrcloud';
|
|
229
|
+
export type FeatureKey = 'sharing' | 'collaboration' | 'filefixer_full' | 'team_workspace' | 'permissions' | 'batch_workflows' | 'priority_processing';
|
|
230
|
+
/** Metered work, priced in tokens by Core. */
|
|
231
|
+
export type TokenAction = 'upscale' | 'repair' | 'vectorize';
|
|
232
|
+
export type SubscriptionStatus = 'incomplete' | 'trialing' | 'active' | 'past_due' | 'canceled' | 'expired';
|
|
233
|
+
/** Decimal string plus ISO currency, e.g. { value: "29.00", currency: "USD" }. */
|
|
234
|
+
export interface Money {
|
|
235
|
+
value: string;
|
|
236
|
+
currency: string;
|
|
237
|
+
}
|
|
238
|
+
export interface EntitlementSet {
|
|
239
|
+
products: ProductKey[];
|
|
240
|
+
features: FeatureKey[];
|
|
241
|
+
seats: number;
|
|
242
|
+
cloud_storage_bytes: number;
|
|
243
|
+
/** Tokens granted every billing period (Studio Free: every calendar month). */
|
|
244
|
+
monthly_tokens: number;
|
|
245
|
+
}
|
|
246
|
+
export interface Plan {
|
|
247
|
+
key: PlanKey;
|
|
248
|
+
name: string;
|
|
249
|
+
description: string;
|
|
250
|
+
amount: Money;
|
|
251
|
+
amount_cents: number;
|
|
252
|
+
interval: string;
|
|
253
|
+
entitlements: EntitlementSet;
|
|
254
|
+
}
|
|
255
|
+
export interface Addon {
|
|
256
|
+
key: AddonKey;
|
|
257
|
+
name: string;
|
|
258
|
+
description: string;
|
|
259
|
+
product: ProductKey;
|
|
260
|
+
amount: Money;
|
|
261
|
+
amount_cents: number;
|
|
262
|
+
interval: string;
|
|
263
|
+
monthly_tokens: number;
|
|
264
|
+
/** Plans that already include it. */
|
|
265
|
+
included_in: PlanKey[];
|
|
266
|
+
}
|
|
267
|
+
export interface TokenPack {
|
|
268
|
+
id: string;
|
|
269
|
+
tokens: number;
|
|
270
|
+
amount: Money;
|
|
271
|
+
amount_cents: number;
|
|
272
|
+
}
|
|
273
|
+
export interface TokenPrice {
|
|
274
|
+
action: TokenAction;
|
|
275
|
+
tokens: number;
|
|
276
|
+
label: string;
|
|
277
|
+
}
|
|
278
|
+
export interface Catalogue {
|
|
279
|
+
plans: Plan[];
|
|
280
|
+
addons: Addon[];
|
|
281
|
+
token_packs: TokenPack[];
|
|
282
|
+
token_actions: TokenPrice[];
|
|
283
|
+
}
|
|
284
|
+
export interface Entitlements extends EntitlementSet {
|
|
285
|
+
organization_id: string;
|
|
286
|
+
/** Studio Free (subscription_id null) unless a paid plan is in place. */
|
|
287
|
+
plan: {
|
|
288
|
+
key: PlanKey;
|
|
289
|
+
name: string;
|
|
290
|
+
subscription_id: string | null;
|
|
291
|
+
};
|
|
292
|
+
addons: {
|
|
293
|
+
key: AddonKey;
|
|
294
|
+
name: string;
|
|
295
|
+
subscription_id: string;
|
|
296
|
+
}[];
|
|
297
|
+
/** Which subscription grants each product. */
|
|
298
|
+
sources: {
|
|
299
|
+
product_key: ProductKey;
|
|
300
|
+
subscription_id: string | null;
|
|
301
|
+
managed_by: string;
|
|
302
|
+
via: 'plan' | 'addon' | 'external';
|
|
303
|
+
}[];
|
|
304
|
+
}
|
|
305
|
+
export type AccessReason = 'included' | 'not_in_plan' | 'addon_required' | 'insufficient_tokens';
|
|
306
|
+
/** Answer to "may this organisation use the product / feature, and afford the action, now?". */
|
|
307
|
+
export interface AccessCheck {
|
|
308
|
+
organization_id: string;
|
|
309
|
+
allowed: boolean;
|
|
310
|
+
reason: AccessReason;
|
|
311
|
+
product: ProductKey | null;
|
|
312
|
+
feature: FeatureKey | null;
|
|
313
|
+
plan: {
|
|
314
|
+
key: PlanKey;
|
|
315
|
+
name: string;
|
|
316
|
+
};
|
|
317
|
+
granted_by: {
|
|
318
|
+
subscription_id: string | null;
|
|
319
|
+
managed_by: string;
|
|
320
|
+
via: 'plan' | 'addon' | 'external';
|
|
321
|
+
} | null;
|
|
322
|
+
tokens: {
|
|
323
|
+
action: TokenAction;
|
|
324
|
+
quantity: number;
|
|
325
|
+
cost: number;
|
|
326
|
+
balance: number;
|
|
327
|
+
} | null;
|
|
328
|
+
/** The cheapest plan that would allow it. */
|
|
329
|
+
upgrade: {
|
|
330
|
+
plan_key: PlanKey;
|
|
331
|
+
plan_name: string;
|
|
332
|
+
amount: Money;
|
|
333
|
+
} | null;
|
|
334
|
+
/** The add-on that would allow it. */
|
|
335
|
+
addon: {
|
|
336
|
+
addon_key: AddonKey;
|
|
337
|
+
addon_name: string;
|
|
338
|
+
amount: Money;
|
|
339
|
+
} | null;
|
|
340
|
+
/** The smallest pack that covers a token shortfall. */
|
|
341
|
+
top_up: {
|
|
342
|
+
pack_id: string;
|
|
343
|
+
tokens: number;
|
|
344
|
+
amount: Money;
|
|
345
|
+
} | null;
|
|
346
|
+
}
|
|
347
|
+
export interface Subscription {
|
|
348
|
+
id: string;
|
|
349
|
+
organization_id: string | null;
|
|
350
|
+
user_id: string | null;
|
|
351
|
+
kind: 'plan' | 'addon' | 'external';
|
|
352
|
+
/** "endorr" for what Core sells; the client id of the product that bills it otherwise. */
|
|
353
|
+
managed_by: string;
|
|
354
|
+
managed_by_name: string;
|
|
355
|
+
external_id: string | null;
|
|
356
|
+
plan_key: string;
|
|
357
|
+
plan_name: string;
|
|
358
|
+
product_key: ProductKey | null;
|
|
359
|
+
pending_plan_key: string | null;
|
|
360
|
+
status: SubscriptionStatus;
|
|
361
|
+
entitled: boolean;
|
|
362
|
+
amount: Money;
|
|
363
|
+
interval: string;
|
|
364
|
+
provider: string;
|
|
365
|
+
current_period_start: string | null;
|
|
366
|
+
current_period_end: string | null;
|
|
367
|
+
trial_ends_at: string | null;
|
|
368
|
+
cancel_at_period_end: boolean;
|
|
369
|
+
canceled_at: string | null;
|
|
370
|
+
ended_at: string | null;
|
|
371
|
+
/** Where to manage a product-billed subscription. */
|
|
372
|
+
manage_url: string | null;
|
|
373
|
+
capabilities: {
|
|
374
|
+
can_cancel: boolean;
|
|
375
|
+
can_resume: boolean;
|
|
376
|
+
can_change_plan: boolean;
|
|
377
|
+
};
|
|
378
|
+
created_at: string;
|
|
379
|
+
updated_at: string;
|
|
380
|
+
}
|
|
381
|
+
export interface TokenBalance {
|
|
382
|
+
balance: number;
|
|
383
|
+
free_balance: number;
|
|
384
|
+
paid_balance: number;
|
|
385
|
+
}
|
|
386
|
+
export interface TokenTransaction {
|
|
387
|
+
id: string;
|
|
388
|
+
type: 'free_grant' | 'plan_grant' | 'purchase' | 'spend' | 'refund' | 'import' | 'adjustment';
|
|
389
|
+
/** Signed: positive credits the wallet. */
|
|
390
|
+
tokens: number;
|
|
391
|
+
free_delta: number;
|
|
392
|
+
paid_delta: number;
|
|
393
|
+
balance_after: number;
|
|
394
|
+
action: TokenAction | null;
|
|
395
|
+
quantity: number | null;
|
|
396
|
+
client_id: string | null;
|
|
397
|
+
reference: string | null;
|
|
398
|
+
description: string;
|
|
399
|
+
refunded_at: string | null;
|
|
400
|
+
created_at: string;
|
|
401
|
+
}
|
|
402
|
+
export interface Wallet extends TokenBalance {
|
|
403
|
+
organization_id: string;
|
|
404
|
+
/** When the free balance is next reset to Studio Free's grant; null when the organisation gets none. */
|
|
405
|
+
free_resets_at: string | null;
|
|
406
|
+
transactions?: TokenTransaction[];
|
|
407
|
+
}
|
|
408
|
+
export interface TokenSpend {
|
|
409
|
+
transaction: TokenTransaction;
|
|
410
|
+
/** True when an idempotency key matched an earlier spend; nothing was spent twice. */
|
|
411
|
+
replayed?: boolean;
|
|
412
|
+
wallet: TokenBalance;
|
|
413
|
+
}
|
|
414
|
+
/** A paid charge of an add-on that unlocks your product (EndorrBillingSync.payments). */
|
|
415
|
+
export interface ProductPayment {
|
|
416
|
+
id: string;
|
|
417
|
+
subscription_id: string;
|
|
418
|
+
organization_id: string | null;
|
|
419
|
+
/** The Endorr user who bought the add-on. */
|
|
420
|
+
user_id: string | null;
|
|
421
|
+
plan_key: string;
|
|
422
|
+
purpose: 'first' | 'renewal' | 'proration';
|
|
423
|
+
amount: Money;
|
|
424
|
+
amount_cents: number;
|
|
425
|
+
provider: string;
|
|
426
|
+
provider_payment_id: string;
|
|
427
|
+
paid_at: string | null;
|
|
428
|
+
}
|
|
429
|
+
export interface ProductPaymentsPage {
|
|
430
|
+
payments: ProductPayment[];
|
|
431
|
+
/** Pass back as `since` for the next page; null when this was the last one. */
|
|
432
|
+
next_since: string | null;
|
|
433
|
+
}
|
|
434
|
+
export interface StorageSummary {
|
|
435
|
+
plan: PlanKey;
|
|
436
|
+
used_bytes: number;
|
|
437
|
+
quota_bytes: number;
|
|
438
|
+
remaining_bytes: number;
|
|
439
|
+
}
|
|
440
|
+
export interface BillingOverview {
|
|
441
|
+
organization_id: string;
|
|
442
|
+
role: OrgRole;
|
|
443
|
+
entitlements: Entitlements;
|
|
444
|
+
subscriptions: Subscription[];
|
|
445
|
+
tokens: Wallet;
|
|
446
|
+
storage: StorageSummary;
|
|
447
|
+
}
|
|
448
|
+
export interface BillingPayment {
|
|
449
|
+
id: string;
|
|
450
|
+
subscription_id: string | null;
|
|
451
|
+
purpose: 'first' | 'renewal' | 'proration' | 'topup';
|
|
452
|
+
status: 'open' | 'pending' | 'authorized' | 'paid' | 'failed' | 'canceled' | 'expired';
|
|
453
|
+
amount: Money;
|
|
454
|
+
plan_key: string | null;
|
|
455
|
+
/** Tokens a top-up credits. */
|
|
456
|
+
tokens: number | null;
|
|
457
|
+
provider: string;
|
|
458
|
+
provider_payment_id: string;
|
|
459
|
+
paid_at: string | null;
|
|
460
|
+
created_at: string;
|
|
461
|
+
}
|
|
462
|
+
export interface CheckoutSession {
|
|
463
|
+
/** Send the browser here; Mollie returns it to your redirect_url with ?subscription_id=. */
|
|
464
|
+
checkout_url: string;
|
|
465
|
+
subscription: Subscription;
|
|
466
|
+
}
|
|
467
|
+
export interface TokenCheckout {
|
|
468
|
+
/** Send the browser here; Mollie returns it to your redirect_url with ?payment_id=. */
|
|
469
|
+
checkout_url: string;
|
|
470
|
+
payment: BillingPayment;
|
|
471
|
+
}
|
|
472
|
+
export interface PlanChange {
|
|
473
|
+
change: 'none' | 'applied' | 'scheduled' | 'schedule_canceled' | 'pending_payment';
|
|
474
|
+
subscription: Subscription;
|
|
475
|
+
prorated_amount: Money | null;
|
|
476
|
+
effective_at: string | null;
|
|
477
|
+
}
|
|
478
|
+
/** What a product reports about a subscription it bills itself (full current state). */
|
|
479
|
+
export interface ExternalSubscriptionInput {
|
|
480
|
+
/** The Endorr user id (`sub`) from Login with Endorr. Preferred. */
|
|
481
|
+
user_id?: string | null;
|
|
482
|
+
organization_id?: string | null;
|
|
483
|
+
/** For customers who have not connected Endorr yet; they claim it once their address is verified. */
|
|
484
|
+
customer_email?: string | null;
|
|
485
|
+
plan_key: string;
|
|
486
|
+
plan_name: string;
|
|
487
|
+
product_key?: ProductKey | null;
|
|
488
|
+
status: SubscriptionStatus;
|
|
489
|
+
provider?: string | null;
|
|
490
|
+
provider_customer_id?: string | null;
|
|
491
|
+
provider_subscription_id?: string | null;
|
|
492
|
+
amount?: Money | null;
|
|
493
|
+
interval?: string | null;
|
|
494
|
+
current_period_start?: string | null;
|
|
495
|
+
current_period_end?: string | null;
|
|
496
|
+
trial_ends_at?: string | null;
|
|
497
|
+
canceled_at?: string | null;
|
|
498
|
+
cancel_at_period_end?: boolean | null;
|
|
499
|
+
manage_url?: string | null;
|
|
500
|
+
metadata?: Record<string, unknown> | null;
|
|
501
|
+
}
|
|
502
|
+
export interface ExternalSubscriptionResult {
|
|
503
|
+
subscription: Subscription;
|
|
504
|
+
/** True while it waits for the owner of customer_email to claim it. */
|
|
505
|
+
claimable: boolean;
|
|
506
|
+
}
|
|
223
507
|
//# sourceMappingURL=types.d.ts.map
|