@biteasy/javascript-sdk 1.0.1 → 1.0.3

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.
@@ -0,0 +1,19 @@
1
+ import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
2
+ export interface PathSerializer {
3
+ path: Record<string, unknown>;
4
+ url: string;
5
+ }
6
+ export declare const PATH_PARAM_RE: RegExp;
7
+ export declare const defaultPathSerializer: ({ path, url: _url }: PathSerializer) => string;
8
+ export declare const getUrl: ({ baseUrl, path, query, querySerializer, url: _url, }: {
9
+ baseUrl?: string;
10
+ path?: Record<string, unknown>;
11
+ query?: Record<string, unknown>;
12
+ querySerializer: QuerySerializer;
13
+ url: string;
14
+ }) => string;
15
+ export declare function getValidRequestBody(options: {
16
+ body?: unknown;
17
+ bodySerializer?: BodySerializer | null;
18
+ serializedBody?: unknown;
19
+ }): unknown;
@@ -0,0 +1,2 @@
1
+ export { type Options, v1Claim, v1Defer, v1DeferPreflight } from "./sdk.gen";
2
+ export type { ClientOptions, V1ClaimData, V1ClaimResponse, V1ClaimResponses, V1DeferData, V1DeferPreflightData, V1DeferPreflightResponse, V1DeferPreflightResponses, V1DeferResponse, V1DeferResponses, } from "./types.gen";
@@ -0,0 +1,59 @@
1
+ import type { Client, Options as Options2, TDataShape } from './client';
2
+ import type { V1ClaimData, V1ClaimResponses, V1DeferData, V1DeferPreflightData, V1DeferPreflightResponses, V1DeferResponses } from './types.gen';
3
+ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & {
4
+ /**
5
+ * You can provide a client instance returned by `createClient()` instead of
6
+ * individual options. This might be also useful if you want to implement a
7
+ * custom client.
8
+ */
9
+ client?: Client;
10
+ /**
11
+ * You can pass arbitrary values through the `meta` object. This can be
12
+ * used to access values that aren't defined as part of the SDK function.
13
+ */
14
+ meta?: Record<string, unknown>;
15
+ };
16
+ /**
17
+ * Claim referral intent
18
+ *
19
+ * Claim a referral intent
20
+ *
21
+ * Use this endpoint to attribute an app installation to a referral partner.
22
+ *
23
+ * Attribution can happen in one of two ways, depending on the request:
24
+ *
25
+ * 1. Explicit claim (recommended)
26
+ *
27
+ * If a `claimCode` is provided, the referral intent is claimed deterministically using that code.
28
+ * This is the preferred and most reliable attribution method.
29
+ *
30
+ * 2. Time-window auto-claim (best-effort)
31
+ *
32
+ * If no `claimCode` is provided, the request opts into time-window auto-claiming.
33
+ *
34
+ * In this mode, BitEasy will attempt to attribute the installation to exactly one recent referral intent created shortly before install.
35
+ * If no eligible intent exists — or if attribution would be ambiguous — no attribution is made.
36
+ */
37
+ export declare const v1Claim: <ThrowOnError extends boolean = false>(options: Options<V1ClaimData, ThrowOnError>) => import("./client").RequestResult<V1ClaimResponses, unknown, ThrowOnError, "fields">;
38
+ /**
39
+ * Issue referral claim code
40
+ *
41
+ * Issues a short-lived referral claim code that can be shown to a user before they install the app.
42
+ *
43
+ * This is the explicit attribution entry point: the user copies or scans the code and later pastes it in-app to complete attribution.
44
+ *
45
+ * Platform attribution (iOS / Android) is recorded separately via the `/defer` endpoint.
46
+ *
47
+ */
48
+ export declare const v1DeferPreflight: <ThrowOnError extends boolean = false>(options: Options<V1DeferPreflightData, ThrowOnError>) => import("./client").RequestResult<V1DeferPreflightResponses, unknown, ThrowOnError, "fields">;
49
+ /**
50
+ * Defer referral intent
51
+ *
52
+ * Register a referral intent.
53
+ *
54
+ * The intent is identified by a claim code, which is a unique identifier for the intent. Another option is to use a time based identifier.
55
+ *
56
+ * The intent is claimed by the user who is making the request.
57
+ *
58
+ */
59
+ export declare const v1Defer: <ThrowOnError extends boolean = false>(options: Options<V1DeferData, ThrowOnError>) => import("./client").RequestResult<V1DeferResponses, unknown, ThrowOnError, "fields">;
@@ -0,0 +1,78 @@
1
+ export type ClientOptions = {
2
+ baseUrl: `${string}://${string}/api/v1` | (string & {});
3
+ };
4
+ export type V1ClaimData = {
5
+ body: {
6
+ appId: string;
7
+ installId: string;
8
+ platform: 'ios' | 'android';
9
+ claimCode?: string;
10
+ };
11
+ path?: never;
12
+ query?: never;
13
+ url: '/v1/claim';
14
+ };
15
+ export type V1ClaimResponses = {
16
+ /**
17
+ * OK
18
+ */
19
+ 200: {
20
+ referrer: string | null;
21
+ path: string | null;
22
+ paywall: {
23
+ id?: string;
24
+ offerCode: {
25
+ code: string;
26
+ expiresAt: string;
27
+ platform: 'ios' | 'android';
28
+ subscriptionDuration: 'monthly' | 'yearly';
29
+ };
30
+ partner: string;
31
+ source: 'partner';
32
+ } | null;
33
+ status: 'claimed' | 'already_claimed' | 'not_found' | 'invalid_code' | 'limit_exceeded';
34
+ };
35
+ };
36
+ export type V1ClaimResponse = V1ClaimResponses[keyof V1ClaimResponses];
37
+ export type V1DeferPreflightData = {
38
+ body: {
39
+ appId: string;
40
+ referrer: string;
41
+ };
42
+ path?: never;
43
+ query?: never;
44
+ url: '/v1/defer-preflight';
45
+ };
46
+ export type V1DeferPreflightResponses = {
47
+ /**
48
+ * OK
49
+ */
50
+ 200: {
51
+ success: boolean;
52
+ claimCode: string;
53
+ expiresAt: string;
54
+ };
55
+ };
56
+ export type V1DeferPreflightResponse = V1DeferPreflightResponses[keyof V1DeferPreflightResponses];
57
+ export type V1DeferData = {
58
+ body: {
59
+ appId: string;
60
+ referrer: string;
61
+ platform: 'ios' | 'android';
62
+ path?: string;
63
+ claimCode?: string;
64
+ };
65
+ path?: never;
66
+ query?: never;
67
+ url: '/v1/defer';
68
+ };
69
+ export type V1DeferResponses = {
70
+ /**
71
+ * OK
72
+ */
73
+ 200: {
74
+ success: boolean;
75
+ expiresAt?: string;
76
+ };
77
+ };
78
+ export type V1DeferResponse = V1DeferResponses[keyof V1DeferResponses];
@@ -0,0 +1,84 @@
1
+ import * as z from 'zod';
2
+ export declare const zV1ClaimData: z.ZodObject<{
3
+ body: z.ZodObject<{
4
+ appId: z.ZodUUID;
5
+ installId: z.ZodString;
6
+ platform: z.ZodEnum<{
7
+ ios: "ios";
8
+ android: "android";
9
+ }>;
10
+ claimCode: z.ZodOptional<z.ZodString>;
11
+ }, z.core.$strip>;
12
+ path: z.ZodOptional<z.ZodNever>;
13
+ query: z.ZodOptional<z.ZodNever>;
14
+ }, z.core.$strip>;
15
+ /**
16
+ * OK
17
+ */
18
+ export declare const zV1ClaimResponse: z.ZodObject<{
19
+ referrer: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
20
+ path: z.ZodUnion<readonly [z.ZodString, z.ZodNull]>;
21
+ paywall: z.ZodUnion<readonly [z.ZodObject<{
22
+ id: z.ZodDefault<z.ZodOptional<z.ZodString>>;
23
+ offerCode: z.ZodObject<{
24
+ code: z.ZodString;
25
+ expiresAt: z.ZodString;
26
+ platform: z.ZodEnum<{
27
+ ios: "ios";
28
+ android: "android";
29
+ }>;
30
+ subscriptionDuration: z.ZodEnum<{
31
+ monthly: "monthly";
32
+ yearly: "yearly";
33
+ }>;
34
+ }, z.core.$strip>;
35
+ partner: z.ZodString;
36
+ source: z.ZodEnum<{
37
+ partner: "partner";
38
+ }>;
39
+ }, z.core.$strip>, z.ZodNull]>;
40
+ status: z.ZodEnum<{
41
+ claimed: "claimed";
42
+ already_claimed: "already_claimed";
43
+ not_found: "not_found";
44
+ invalid_code: "invalid_code";
45
+ limit_exceeded: "limit_exceeded";
46
+ }>;
47
+ }, z.core.$strip>;
48
+ export declare const zV1DeferPreflightData: z.ZodObject<{
49
+ body: z.ZodObject<{
50
+ appId: z.ZodUUID;
51
+ referrer: z.ZodString;
52
+ }, z.core.$strip>;
53
+ path: z.ZodOptional<z.ZodNever>;
54
+ query: z.ZodOptional<z.ZodNever>;
55
+ }, z.core.$strip>;
56
+ /**
57
+ * OK
58
+ */
59
+ export declare const zV1DeferPreflightResponse: z.ZodObject<{
60
+ success: z.ZodBoolean;
61
+ claimCode: z.ZodString;
62
+ expiresAt: z.ZodISODateTime;
63
+ }, z.core.$strip>;
64
+ export declare const zV1DeferData: z.ZodObject<{
65
+ body: z.ZodObject<{
66
+ appId: z.ZodUUID;
67
+ referrer: z.ZodString;
68
+ platform: z.ZodEnum<{
69
+ ios: "ios";
70
+ android: "android";
71
+ }>;
72
+ path: z.ZodOptional<z.ZodString>;
73
+ claimCode: z.ZodOptional<z.ZodString>;
74
+ }, z.core.$strip>;
75
+ path: z.ZodOptional<z.ZodNever>;
76
+ query: z.ZodOptional<z.ZodNever>;
77
+ }, z.core.$strip>;
78
+ /**
79
+ * OK
80
+ */
81
+ export declare const zV1DeferResponse: z.ZodObject<{
82
+ success: z.ZodBoolean;
83
+ expiresAt: z.ZodOptional<z.ZodISODateTime>;
84
+ }, z.core.$strip>;
package/dist/index.d.ts CHANGED
@@ -1,27 +1,65 @@
1
- import { ClaimRequestSchema, ClaimResponseSchema, DeferInputSchema, DeferOutputSchema, DeferPreflightInputSchema, DeferPreflightOutputSchema } from "@biteasy/contracts";
2
- export { ClaimRequestSchema, ClaimResponseSchema, DeferInputSchema, DeferOutputSchema, DeferPreflightInputSchema, DeferPreflightOutputSchema, };
3
- import { z } from "zod";
1
+ import type { V1ClaimResponse, V1DeferPreflightResponse, V1DeferResponse } from "./gen/types.gen";
2
+ export type { V1ClaimResponse, V1DeferPreflightResponse, V1DeferResponse };
3
+ export type BitEasyClient = {
4
+ appId: string;
5
+ version: string;
6
+ };
4
7
  export type BitEasyClientConfig = {
5
8
  appId: string;
6
- baseUrl?: string;
9
+ /** @default "1" */
7
10
  version?: string;
11
+ /** @default "https://api.biteasy.com/api" */
12
+ baseUrl?: string;
13
+ /** Custom fetch implementation for environments where globalThis.fetch is unavailable. */
8
14
  fetch?: typeof fetch;
9
15
  };
10
- export type BitEasyClient = {
11
- appId: string;
12
- apiBaseUrl: string;
13
- fetch: typeof fetch;
14
- };
15
- export declare function createBitEasyClient(config: BitEasyClientConfig): BitEasyClient;
16
- export declare function deferPreflight(client: BitEasyClient, params: Omit<DeferPreflightInput, "appId">): Promise<DeferPreflightOutput>;
17
- export declare function defer(client: BitEasyClient, params: Omit<DeferInput, "appId">): Promise<DeferOutput>;
18
- export declare function claimAttribution(client: BitEasyClient, params: Omit<ClaimAttributionInput, "appId">): Promise<ClaimResponse>;
19
- export type DeferPreflightInput = z.infer<typeof DeferPreflightInputSchema>;
20
- export type DeferPreflightOutput = z.infer<typeof DeferPreflightOutputSchema>;
21
- export type DeferPreflightParams = Omit<DeferPreflightInput, "appId">;
22
- export type DeferInput = z.infer<typeof DeferInputSchema>;
23
- export type DeferOutput = z.infer<typeof DeferOutputSchema>;
24
- export type DeferParams = Omit<DeferInput, "appId">;
25
- export type ClaimAttributionInput = z.infer<typeof ClaimRequestSchema>;
26
- export type ClaimResponse = z.infer<typeof ClaimResponseSchema>;
27
- export type ClaimAttributionParams = Omit<ClaimAttributionInput, "appId">;
16
+ /**
17
+ * Create a BitEasy client instance.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createClient, claim } from "@biteasy/javascript-sdk";
22
+ *
23
+ * const client = createClient({ appId: "your-app-id" });
24
+ * const result = await claim(client, { installId: "...", platform: "ios" });
25
+ * ```
26
+ */
27
+ export declare function createClient(config: BitEasyClientConfig): BitEasyClient;
28
+ /**
29
+ * Claim a referral intent.
30
+ *
31
+ * Use this to attribute an app installation to a referral partner.
32
+ * If a `claimCode` is provided, attribution is deterministic.
33
+ * Otherwise, time-window auto-claiming is attempted.
34
+ *
35
+ * @throws On non-2xx responses.
36
+ */
37
+ export declare function claimAttribution(client: BitEasyClient, params: {
38
+ installId: string;
39
+ platform: "ios" | "android";
40
+ claimCode?: string;
41
+ }): Promise<V1ClaimResponse>;
42
+ /**
43
+ * Issue a short-lived referral claim code.
44
+ *
45
+ * The code can be shown to a user before they install the app.
46
+ * Platform attribution is recorded separately via {@link defer}.
47
+ *
48
+ * @throws On non-2xx responses.
49
+ */
50
+ export declare function deferPreflight(client: BitEasyClient, params: {
51
+ referrer: string;
52
+ }): Promise<V1DeferPreflightResponse>;
53
+ /**
54
+ * Register a referral intent.
55
+ *
56
+ * The intent is identified by a claim code or via time-based attribution.
57
+ *
58
+ * @throws On non-2xx responses.
59
+ */
60
+ export declare function defer(client: BitEasyClient, params: {
61
+ referrer: string;
62
+ platform: "ios" | "android";
63
+ path?: string;
64
+ claimCode?: string;
65
+ }): Promise<V1DeferResponse>;