@proappstore/sdk 0.1.2 → 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/dist/index.d.ts CHANGED
@@ -1,11 +1,20 @@
1
+ import { FreeAppStore } from '@freeappstore/sdk';
1
2
  import { SubscriptionApi } from './subscription.js';
2
3
  import { LicenseApi } from './license.js';
3
4
  import type { ProInitOptions } from './types.js';
5
+ export type { User, Unsubscribe, FasInitOptions, ConnectionState, Room, RoomMessage, RoomPeer, } from '@freeappstore/sdk';
4
6
  export type { ProInitOptions, Subscription, SubscriptionStatus, CheckoutRequest, LicenseInfo, } from './types.js';
5
- export declare class ProAppStore {
7
+ /**
8
+ * Pro SDK instance — includes everything from @freeappstore/sdk (auth, kv,
9
+ * counters, rooms, proxy) plus subscription management and license keys.
10
+ *
11
+ * One import, one instance, all features.
12
+ */
13
+ export declare class ProAppStore extends FreeAppStore {
6
14
  readonly subscription: SubscriptionApi;
7
15
  readonly license: LicenseApi;
8
16
  constructor(opts: ProInitOptions);
9
17
  }
18
+ /** Create a new ProAppStore SDK instance. Includes all free + pro features. */
10
19
  export declare function initPro(opts: ProInitOptions): ProAppStore;
11
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,YAAY,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,qBAAa,WAAW;IACtB,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;gBAEjB,IAAI,EAAE,cAAc;CAOjC;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,WAAW,CAEzD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,YAAY,EACV,IAAI,EACJ,WAAW,EACX,cAAc,EACd,eAAe,EACf,IAAI,EACJ,WAAW,EACX,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;gBAEjB,IAAI,EAAE,cAAc;CAMjC;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,WAAW,CAEzD"}
package/dist/index.js CHANGED
@@ -1,15 +1,23 @@
1
+ import { FreeAppStore } from '@freeappstore/sdk';
1
2
  import { SubscriptionApi } from './subscription.js';
2
3
  import { LicenseApi } from './license.js';
3
- export class ProAppStore {
4
+ /**
5
+ * Pro SDK instance — includes everything from @freeappstore/sdk (auth, kv,
6
+ * counters, rooms, proxy) plus subscription management and license keys.
7
+ *
8
+ * One import, one instance, all features.
9
+ */
10
+ export class ProAppStore extends FreeAppStore {
4
11
  subscription;
5
12
  license;
6
13
  constructor(opts) {
7
- const apiBase = opts.apiBase ?? 'https://api.proappstore.online';
8
- const tokenFn = typeof opts.authToken === 'function' ? opts.authToken : () => opts.authToken;
9
- this.subscription = new SubscriptionApi(opts.appId, apiBase, tokenFn);
10
- this.license = new LicenseApi(opts.appId, apiBase, tokenFn);
14
+ super({ appId: opts.appId, ...(opts.fasApiBase && { apiBase: opts.fasApiBase }) });
15
+ const proApiBase = opts.proApiBase ?? 'https://api.proappstore.online';
16
+ this.subscription = new SubscriptionApi(opts.appId, proApiBase, this.auth);
17
+ this.license = new LicenseApi(opts.appId, proApiBase, this.auth);
11
18
  }
12
19
  }
20
+ /** Create a new ProAppStore SDK instance. Includes all free + pro features. */
13
21
  export function initPro(opts) {
14
22
  return new ProAppStore(opts);
15
23
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAW1C,MAAM,OAAO,WAAW;IACb,YAAY,CAAkB;IAC9B,OAAO,CAAa;IAE7B,YAAY,IAAoB;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,gCAAgC,CAAC;QACjE,MAAM,OAAO,GACX,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAmB,CAAC;QACzF,IAAI,CAAC,YAAY,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;CACF;AAED,MAAM,UAAU,OAAO,CAAC,IAAoB;IAC1C,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAsB1C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAClC,YAAY,CAAkB;IAC9B,OAAO,CAAa;IAE7B,YAAY,IAAoB;QAC9B,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;QACnF,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,gCAAgC,CAAC;QACvE,IAAI,CAAC,YAAY,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3E,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC;CACF;AAED,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,IAAoB;IAC1C,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
package/dist/license.d.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import type { LicenseInfo } from './types.js';
2
+ interface AuthLike {
3
+ token: string | null;
4
+ handleUnauthorized(): void;
5
+ }
2
6
  export declare class LicenseApi {
3
7
  private readonly appId;
4
8
  private readonly apiBase;
5
- private readonly token;
6
- constructor(appId: string, apiBase: string, token: () => string | null);
9
+ private readonly auth;
10
+ constructor(appId: string, apiBase: string, auth: AuthLike);
7
11
  /** Returns the license info for the signed-in user, or null. */
8
12
  current(): Promise<LicenseInfo | null>;
9
- /**
10
- * Validate an arbitrary license key against the server. Useful for cases
11
- * where the key is delivered out-of-band (email, manual entry).
12
- */
13
+ /** Validate an arbitrary license key against the server (no auth required). */
13
14
  validate(key: string): Promise<boolean>;
14
15
  }
16
+ export {};
15
17
  //# sourceMappingURL=license.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAFL,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,MAAM,GAAG,IAAI;IAG7C,gEAAgE;IAC1D,OAAO,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAY5C;;;OAGG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAU9C"}
1
+ {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kBAAkB,IAAI,IAAI,CAAC;CAC5B;AAED,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFJ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,QAAQ;IAGjC,gEAAgE;IAC1D,OAAO,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAa5C,+EAA+E;IACzE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAU9C"}
package/dist/license.js CHANGED
@@ -1,37 +1,38 @@
1
1
  export class LicenseApi {
2
2
  appId;
3
3
  apiBase;
4
- token;
5
- constructor(appId, apiBase, token) {
4
+ auth;
5
+ constructor(appId, apiBase, auth) {
6
6
  this.appId = appId;
7
7
  this.apiBase = apiBase;
8
- this.token = token;
8
+ this.auth = auth;
9
9
  }
10
10
  /** Returns the license info for the signed-in user, or null. */
11
11
  async current() {
12
- const token = this.token();
12
+ const token = this.auth.token;
13
13
  if (!token)
14
14
  return null;
15
- const res = await fetch(new URL(`/v1/apps/${encodeURIComponent(this.appId)}/license`, this.apiBase), { headers: { Authorization: `Bearer ${token}` } });
16
- if (res.status === 404)
15
+ const response = await fetch(new URL(`/v1/apps/${encodeURIComponent(this.appId)}/license`, this.apiBase), { headers: { Authorization: `Bearer ${token}` } });
16
+ if (response.status === 401) {
17
+ this.auth.handleUnauthorized();
17
18
  return null;
18
- if (!res.ok)
19
- throw new Error(`license.current failed: ${res.status}`);
20
- return (await res.json());
19
+ }
20
+ if (response.status === 404)
21
+ return null;
22
+ if (!response.ok)
23
+ throw new Error(`license.current failed: ${response.status}`);
24
+ return (await response.json());
21
25
  }
22
- /**
23
- * Validate an arbitrary license key against the server. Useful for cases
24
- * where the key is delivered out-of-band (email, manual entry).
25
- */
26
+ /** Validate an arbitrary license key against the server (no auth required). */
26
27
  async validate(key) {
27
- const res = await fetch(new URL('/v1/license/validate', this.apiBase), {
28
+ const response = await fetch(new URL('/v1/license/validate', this.apiBase), {
28
29
  method: 'POST',
29
30
  headers: { 'Content-Type': 'application/json' },
30
31
  body: JSON.stringify({ appId: this.appId, key }),
31
32
  });
32
- if (!res.ok)
33
+ if (!response.ok)
33
34
  return false;
34
- const { valid } = (await res.json());
35
+ const { valid } = (await response.json());
35
36
  return valid;
36
37
  }
37
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mapp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AAI,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YAC1E,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;SACjD,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,OAAO,KAAK,CAAC;QAC/B,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAuB,CAAC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -1,18 +1,20 @@
1
1
  import type { CheckoutRequest, Subscription } from './types.js';
2
+ interface AuthLike {
3
+ token: string | null;
4
+ handleUnauthorized(): void;
5
+ }
2
6
  export declare class SubscriptionApi {
3
7
  private readonly appId;
4
8
  private readonly apiBase;
5
- private readonly token;
6
- constructor(appId: string, apiBase: string, token: () => string | null);
9
+ private readonly auth;
10
+ constructor(appId: string, apiBase: string, auth: AuthLike);
7
11
  /** Returns the user's current subscription, or null if they have none. */
8
12
  status(): Promise<Subscription | null>;
9
- /**
10
- * Redirects the user to a Stripe-hosted checkout for the given price.
11
- * Returns nothing — the page navigates away.
12
- */
13
+ /** Redirects to Stripe-hosted checkout. Page navigates away. */
13
14
  openCheckout(req: CheckoutRequest): Promise<void>;
14
- /** Redirects the user to the Stripe customer portal to manage billing. */
15
+ /** Redirects to Stripe customer portal to manage billing. */
15
16
  openPortal(returnUrl: string): Promise<void>;
16
17
  private req;
17
18
  }
19
+ export {};
18
20
  //# sourceMappingURL=subscription.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../src/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhE,q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
- token;
5
- constructor(appId, apiBase, token) {
4
+ auth;
5
+ constructor(appId, apiBase, auth) {
6
6
  this.appId = appId;
7
7
  this.apiBase = apiBase;
8
- this.token = token;
8
+ this.auth = auth;
9
9
  }
10
10
  /** Returns the user's current subscription, or null if they have none. */
11
11
  async status() {
12
- const res = await this.req('GET', '/v1/subscription');
13
- if (res.status === 404)
12
+ const response = await this.req('GET', '/v1/subscription');
13
+ if (response.status === 404)
14
14
  return null;
15
- if (!res.ok)
16
- throw new Error(`subscription.status failed: ${res.status}`);
17
- return (await res.json());
15
+ if (!response.ok)
16
+ throw new Error(`subscription.status failed: ${response.status}`);
17
+ return (await response.json());
18
18
  }
19
- /**
20
- * Redirects the user to a Stripe-hosted checkout for the given price.
21
- * Returns nothing — the page navigates away.
22
- */
19
+ /** Redirects to Stripe-hosted checkout. Page navigates away. */
23
20
  async openCheckout(req) {
24
- const res = await this.req('POST', '/v1/checkout', req);
25
- if (!res.ok)
26
- throw new Error(`subscription.openCheckout failed: ${res.status}`);
27
- const { url } = (await res.json());
28
- window.location.assign(url);
21
+ const response = await this.req('POST', '/v1/checkout', req);
22
+ if (!response.ok)
23
+ throw new Error(`subscription.openCheckout failed: ${response.status}`);
24
+ const { url } = (await response.json());
25
+ if (typeof window !== 'undefined')
26
+ window.location.assign(url);
29
27
  }
30
- /** Redirects the user to the Stripe customer portal to manage billing. */
28
+ /** Redirects to Stripe customer portal to manage billing. */
31
29
  async openPortal(returnUrl) {
32
- const res = await this.req('POST', '/v1/portal', { returnUrl });
33
- if (!res.ok)
34
- throw new Error(`subscription.openPortal failed: ${res.status}`);
35
- const { url } = (await res.json());
36
- window.location.assign(url);
30
+ const response = await this.req('POST', '/v1/portal', { returnUrl });
31
+ if (!response.ok)
32
+ throw new Error(`subscription.openPortal failed: ${response.status}`);
33
+ const { url } = (await response.json());
34
+ if (typeof window !== 'undefined')
35
+ window.location.assign(url);
37
36
  }
38
37
  async req(method, path, body) {
39
- const token = this.token();
38
+ const token = this.auth.token;
40
39
  if (!token)
41
- throw new Error('Not signed in. Pass fas.auth.token to initPro().');
40
+ throw new Error('Not signed in.');
42
41
  const init = {
43
42
  method,
44
43
  headers: {
@@ -48,7 +47,12 @@ export class SubscriptionApi {
48
47
  };
49
48
  if (body !== undefined)
50
49
  init.body = JSON.stringify(body);
51
- return fetch(new URL(path, this.apiBase), init);
50
+ const response = await fetch(new URL(path, this.apiBase), init);
51
+ if (response.status === 401) {
52
+ this.auth.handleUnauthorized();
53
+ throw new Error('Not signed in.');
54
+ }
55
+ return response;
52
56
  }
53
57
  }
54
58
  //# sourceMappingURL=subscription.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../src/subscription.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;IAEP;IACA;IACA;IAHnB,YACmB,KAAa,EACb,OAAe,EACf,KAA0B;QAF1B,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QACf,UAAK,GAAL,KAAK,CAAqB;IAC1C,CAAC;IAEJ,0EAA0E;IAC1E,KAAK,CAAC,MAAM;QACV,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;QACtD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QACpC,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1E,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAiB,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY,CAAC,GAAoB;QACrC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAA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B,CAAC;CACF"}
package/dist/types.d.ts CHANGED
@@ -1,13 +1,9 @@
1
1
  export interface ProInitOptions {
2
2
  appId: string;
3
- /** Defaults to https://api.proappstore.online */
4
- apiBase?: string;
5
- /**
6
- * Bearer token from @freeappstore/sdk. Pro builds on top of free identity —
7
- * the user is the same; pro just adds subscription state. Pass
8
- * `fas.auth.token` here once the free auth flow has signed the user in.
9
- */
10
- authToken: string | (() => string | null);
3
+ /** Defaults to https://api.freeappstore.online (free-tier backend). */
4
+ fasApiBase?: string;
5
+ /** Defaults to https://api.proappstore.online (pro-tier backend). */
6
+ proApiBase?: string;
11
7
  }
12
8
  export type SubscriptionStatus = 'active' | 'past_due' | 'canceled' | 'incomplete';
13
9
  export interface Subscription {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,SAAS,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC;AAEnF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,sDAAsD;IACtD,gBAAgB,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC;AAEnF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,sDAAsD;IACtD,gBAAgB,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proappstore/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Browser SDK for paid apps on proappstore.online — subscriptions, license keys, premium modules.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,6 +18,9 @@
18
18
  "build": "tsc",
19
19
  "typecheck": "tsc --noEmit"
20
20
  },
21
+ "dependencies": {
22
+ "@freeappstore/sdk": "^0.5.0"
23
+ },
21
24
  "devDependencies": {
22
25
  "typescript": "^5.7.0"
23
26
  },