@neetru/sdk 1.0.0 → 1.1.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 +32 -1
- package/dist/auth.cjs +177 -1
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +177 -1
- package/dist/auth.mjs.map +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/checkout.cjs +275 -0
- package/dist/checkout.cjs.map +1 -0
- package/dist/checkout.d.cts +1 -0
- package/dist/checkout.d.ts +1 -0
- package/dist/checkout.mjs +272 -0
- package/dist/checkout.mjs.map +1 -0
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/index.cjs +180 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +179 -3
- package/dist/index.mjs.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/react.cjs +158 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +112 -0
- package/dist/react.d.ts +112 -0
- package/dist/react.mjs +134 -0
- package/dist/react.mjs.map +1 -0
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/{types-PKUaFtBY.d.cts → types-BA53dd8S.d.cts} +83 -1
- package/dist/{types-PKUaFtBY.d.ts → types-BA53dd8S.d.ts} +83 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/package.json +18 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { N as NeetruClientConfig, a as NeetruClient } from './types-
|
|
2
|
-
export { A as AuthNamespace, b as AuthStateListener, C as CatalogListOptions, c as CatalogListResponse, d as CreateTicketInput, D as DEFAULT_BASE_URL,
|
|
1
|
+
import { N as NeetruClientConfig, a as NeetruClient } from './types-BA53dd8S.cjs';
|
|
2
|
+
export { A as AuthNamespace, b as AuthStateListener, C as CatalogListOptions, c as CatalogListResponse, d as CheckoutIntentInfo, e as CheckoutIntentStatus, f as CheckoutNamespace, g as CheckoutStartInput, h as CheckoutStartResult, i as CheckoutTenantType, j as CreateTicketInput, D as DEFAULT_BASE_URL, k as DbCollectionRef, l as DbListOptions, m as DbNamespace, n as DbWhereFilter, E as EntitlementCheck, M as MockCheckout, o as NeetruEnv, p as NeetruUser, P as Product, q as ProductPlan, r as ProductStatus, R as ResolvedConfig, S as SignInOptions, s as SupportNamespace, t as SupportSeverity, u as SupportStatus, v as SupportTicket, T as TelemetryEventAck, w as TelemetryEventInput, U as UsageEventInput, x as UsageNamespace, y as UsageQuota, z as createCheckoutNamespace } from './types-BA53dd8S.cjs';
|
|
3
3
|
export { createNeetruClient } from './auth.cjs';
|
|
4
4
|
export { NeetruError, NeetruErrorCode } from './errors.cjs';
|
|
5
5
|
export { DEV_FIXTURE_USER, MockAuth, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.cjs';
|
|
6
6
|
|
|
7
7
|
/** Versão do SDK — exportada explicitamente pra detecção em runtime. */
|
|
8
|
-
declare const VERSION: "1.
|
|
8
|
+
declare const VERSION: "1.1.0";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @deprecated Use `createNeetruClient` em vez de `initNeetru`. Mantido por
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { N as NeetruClientConfig, a as NeetruClient } from './types-
|
|
2
|
-
export { A as AuthNamespace, b as AuthStateListener, C as CatalogListOptions, c as CatalogListResponse, d as CreateTicketInput, D as DEFAULT_BASE_URL,
|
|
1
|
+
import { N as NeetruClientConfig, a as NeetruClient } from './types-BA53dd8S.js';
|
|
2
|
+
export { A as AuthNamespace, b as AuthStateListener, C as CatalogListOptions, c as CatalogListResponse, d as CheckoutIntentInfo, e as CheckoutIntentStatus, f as CheckoutNamespace, g as CheckoutStartInput, h as CheckoutStartResult, i as CheckoutTenantType, j as CreateTicketInput, D as DEFAULT_BASE_URL, k as DbCollectionRef, l as DbListOptions, m as DbNamespace, n as DbWhereFilter, E as EntitlementCheck, M as MockCheckout, o as NeetruEnv, p as NeetruUser, P as Product, q as ProductPlan, r as ProductStatus, R as ResolvedConfig, S as SignInOptions, s as SupportNamespace, t as SupportSeverity, u as SupportStatus, v as SupportTicket, T as TelemetryEventAck, w as TelemetryEventInput, U as UsageEventInput, x as UsageNamespace, y as UsageQuota, z as createCheckoutNamespace } from './types-BA53dd8S.js';
|
|
3
3
|
export { createNeetruClient } from './auth.js';
|
|
4
4
|
export { NeetruError, NeetruErrorCode } from './errors.js';
|
|
5
5
|
export { DEV_FIXTURE_USER, MockAuth, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.js';
|
|
6
6
|
|
|
7
7
|
/** Versão do SDK — exportada explicitamente pra detecção em runtime. */
|
|
8
|
-
declare const VERSION: "1.
|
|
8
|
+
declare const VERSION: "1.1.0";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @deprecated Use `createNeetruClient` em vez de `initNeetru`. Mantido por
|
package/dist/index.mjs
CHANGED
|
@@ -690,6 +690,181 @@ function createDbNamespace(config) {
|
|
|
690
690
|
};
|
|
691
691
|
}
|
|
692
692
|
|
|
693
|
+
// src/checkout.ts
|
|
694
|
+
function parseStartResponse(raw) {
|
|
695
|
+
if (!raw || typeof raw !== "object") {
|
|
696
|
+
throw new NeetruError("invalid_response", "checkout.start response is not an object");
|
|
697
|
+
}
|
|
698
|
+
const r = raw;
|
|
699
|
+
if (typeof r.intentId !== "string" || !r.intentId) {
|
|
700
|
+
throw new NeetruError("invalid_response", "checkout.start response missing intentId");
|
|
701
|
+
}
|
|
702
|
+
if (typeof r.redirectUrl !== "string" || !r.redirectUrl) {
|
|
703
|
+
throw new NeetruError("invalid_response", "checkout.start response missing redirectUrl");
|
|
704
|
+
}
|
|
705
|
+
return {
|
|
706
|
+
intentId: r.intentId,
|
|
707
|
+
redirectUrl: r.redirectUrl,
|
|
708
|
+
status: r.status ?? "pending",
|
|
709
|
+
expiresAt: typeof r.expiresAt === "string" ? r.expiresAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
710
|
+
requiresKyc: r.requiresKyc === true
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
function parseGetResponse(raw) {
|
|
714
|
+
if (!raw || typeof raw !== "object") {
|
|
715
|
+
throw new NeetruError("invalid_response", "checkout.get response is not an object");
|
|
716
|
+
}
|
|
717
|
+
const r = raw;
|
|
718
|
+
const intent = r.intent;
|
|
719
|
+
if (!intent || typeof intent !== "object") {
|
|
720
|
+
throw new NeetruError("invalid_response", "checkout.get response missing intent");
|
|
721
|
+
}
|
|
722
|
+
if (typeof intent.intentId !== "string") {
|
|
723
|
+
throw new NeetruError("invalid_response", "checkout.get response missing intentId");
|
|
724
|
+
}
|
|
725
|
+
return {
|
|
726
|
+
intentId: intent.intentId,
|
|
727
|
+
uid: intent.uid ?? "",
|
|
728
|
+
targetTenantId: intent.targetTenantId ?? "",
|
|
729
|
+
targetTenantType: intent.targetTenantType ?? "pf",
|
|
730
|
+
productId: intent.productId ?? "",
|
|
731
|
+
planId: intent.planId ?? "",
|
|
732
|
+
callbackUrl: intent.callbackUrl ?? "",
|
|
733
|
+
status: intent.status ?? "pending",
|
|
734
|
+
stripeSessionId: intent.stripeSessionId ?? null,
|
|
735
|
+
expiresAt: intent.expiresAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
736
|
+
isStale: r.isStale === true
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function inBrowser() {
|
|
740
|
+
try {
|
|
741
|
+
return typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined" && typeof globalThis.location !== "undefined" && typeof globalThis.location.assign === "function";
|
|
742
|
+
} catch {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function performRedirect(url) {
|
|
747
|
+
try {
|
|
748
|
+
globalThis.location.assign(url);
|
|
749
|
+
} catch {
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
function createHttpCheckoutNamespace(config) {
|
|
753
|
+
return {
|
|
754
|
+
async start(input) {
|
|
755
|
+
if (!input?.productId) {
|
|
756
|
+
throw new NeetruError("validation_failed", "checkout.start: productId is required");
|
|
757
|
+
}
|
|
758
|
+
if (!input?.planId) {
|
|
759
|
+
throw new NeetruError("validation_failed", "checkout.start: planId is required");
|
|
760
|
+
}
|
|
761
|
+
if (!input?.callbackUrl) {
|
|
762
|
+
throw new NeetruError("validation_failed", "checkout.start: callbackUrl is required");
|
|
763
|
+
}
|
|
764
|
+
const body = {
|
|
765
|
+
productId: input.productId,
|
|
766
|
+
planId: input.planId,
|
|
767
|
+
callbackUrl: input.callbackUrl
|
|
768
|
+
};
|
|
769
|
+
if (input.tenantType) body.targetTenantType = input.tenantType;
|
|
770
|
+
if (input.tenantId) body.targetTenantId = input.tenantId;
|
|
771
|
+
const raw = await httpRequest(config, {
|
|
772
|
+
method: "POST",
|
|
773
|
+
path: "/api/v1/checkout/intents",
|
|
774
|
+
body,
|
|
775
|
+
requireAuth: true
|
|
776
|
+
});
|
|
777
|
+
const result = parseStartResponse(raw);
|
|
778
|
+
const shouldRedirect = input.autoRedirect !== false;
|
|
779
|
+
if (shouldRedirect && inBrowser()) {
|
|
780
|
+
performRedirect(result.redirectUrl);
|
|
781
|
+
}
|
|
782
|
+
return result;
|
|
783
|
+
},
|
|
784
|
+
async get(intentId) {
|
|
785
|
+
if (!intentId || typeof intentId !== "string") {
|
|
786
|
+
throw new NeetruError("validation_failed", "checkout.get: intentId is required");
|
|
787
|
+
}
|
|
788
|
+
const raw = await httpRequest(config, {
|
|
789
|
+
method: "GET",
|
|
790
|
+
path: `/api/v1/checkout/intents/${encodeURIComponent(intentId)}`,
|
|
791
|
+
requireAuth: true
|
|
792
|
+
});
|
|
793
|
+
return parseGetResponse(raw);
|
|
794
|
+
},
|
|
795
|
+
async cancel(intentId) {
|
|
796
|
+
if (!intentId || typeof intentId !== "string") {
|
|
797
|
+
throw new NeetruError("validation_failed", "checkout.cancel: intentId is required");
|
|
798
|
+
}
|
|
799
|
+
const raw = await httpRequest(config, {
|
|
800
|
+
method: "DELETE",
|
|
801
|
+
path: `/api/v1/checkout/intents/${encodeURIComponent(intentId)}`,
|
|
802
|
+
requireAuth: true
|
|
803
|
+
});
|
|
804
|
+
return {
|
|
805
|
+
ok: true,
|
|
806
|
+
alreadyCancelled: raw?.alreadyCancelled === true
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
var MockCheckout = class {
|
|
812
|
+
intents = /* @__PURE__ */ new Map();
|
|
813
|
+
async start(input) {
|
|
814
|
+
if (!input?.productId) {
|
|
815
|
+
throw new NeetruError("validation_failed", "checkout.start: productId is required");
|
|
816
|
+
}
|
|
817
|
+
if (!input?.planId) {
|
|
818
|
+
throw new NeetruError("validation_failed", "checkout.start: planId is required");
|
|
819
|
+
}
|
|
820
|
+
if (!input?.callbackUrl) {
|
|
821
|
+
throw new NeetruError("validation_failed", "checkout.start: callbackUrl is required");
|
|
822
|
+
}
|
|
823
|
+
const intentId = `chk_mock_${Math.random().toString(36).slice(2, 10)}`;
|
|
824
|
+
const expiresAt = new Date(Date.now() + 15 * 60 * 1e3).toISOString();
|
|
825
|
+
const redirectUrl = `https://localhost:9003/portal/checkout/${intentId}`;
|
|
826
|
+
this.intents.set(intentId, {
|
|
827
|
+
intentId,
|
|
828
|
+
uid: "dev-fixture-uid",
|
|
829
|
+
targetTenantId: input.tenantId ?? "dev-fixture-uid",
|
|
830
|
+
targetTenantType: input.tenantType ?? "pf",
|
|
831
|
+
productId: input.productId,
|
|
832
|
+
planId: input.planId,
|
|
833
|
+
callbackUrl: input.callbackUrl,
|
|
834
|
+
status: "pending",
|
|
835
|
+
stripeSessionId: null,
|
|
836
|
+
expiresAt
|
|
837
|
+
});
|
|
838
|
+
return {
|
|
839
|
+
intentId,
|
|
840
|
+
redirectUrl,
|
|
841
|
+
status: "pending",
|
|
842
|
+
expiresAt,
|
|
843
|
+
requiresKyc: false
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
async get(intentId) {
|
|
847
|
+
const found = this.intents.get(intentId);
|
|
848
|
+
if (!found) {
|
|
849
|
+
throw new NeetruError("not_found", `Mock intent ${intentId} not found`);
|
|
850
|
+
}
|
|
851
|
+
return { ...found };
|
|
852
|
+
}
|
|
853
|
+
async cancel(intentId) {
|
|
854
|
+
const found = this.intents.get(intentId);
|
|
855
|
+
if (!found) {
|
|
856
|
+
throw new NeetruError("not_found", `Mock intent ${intentId} not found`);
|
|
857
|
+
}
|
|
858
|
+
const alreadyCancelled = found.status === "cancelled";
|
|
859
|
+
this.intents.set(intentId, { ...found, status: "cancelled" });
|
|
860
|
+
return { ok: true, alreadyCancelled };
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
function createCheckoutNamespace(config) {
|
|
864
|
+
if (config.env === "dev") return new MockCheckout();
|
|
865
|
+
return createHttpCheckoutNamespace(config);
|
|
866
|
+
}
|
|
867
|
+
|
|
693
868
|
// src/mocks.ts
|
|
694
869
|
var DEV_FIXTURE_USER = Object.freeze({
|
|
695
870
|
uid: "dev-fixture-uid-0001",
|
|
@@ -1125,18 +1300,19 @@ function createNeetruClient(config = {}) {
|
|
|
1125
1300
|
telemetry: createTelemetryNamespace(resolved),
|
|
1126
1301
|
usage,
|
|
1127
1302
|
support,
|
|
1128
|
-
db
|
|
1303
|
+
db,
|
|
1304
|
+
checkout: createCheckoutNamespace(resolved)
|
|
1129
1305
|
});
|
|
1130
1306
|
return client;
|
|
1131
1307
|
}
|
|
1132
1308
|
|
|
1133
1309
|
// src/index.ts
|
|
1134
|
-
var VERSION = "1.
|
|
1310
|
+
var VERSION = "1.1.0";
|
|
1135
1311
|
function initNeetru(config) {
|
|
1136
1312
|
const { apiUrl, baseUrl, ...rest } = config;
|
|
1137
1313
|
return createNeetruClient({ ...rest, baseUrl: baseUrl ?? apiUrl });
|
|
1138
1314
|
}
|
|
1139
1315
|
|
|
1140
|
-
export { DEFAULT_BASE_URL, DEV_FIXTURE_USER, MockAuth, MockDb, MockEntitlements, MockSupport, MockUsage, NeetruError, VERSION, createNeetruClient, initNeetru };
|
|
1316
|
+
export { DEFAULT_BASE_URL, DEV_FIXTURE_USER, MockAuth, MockCheckout, MockDb, MockEntitlements, MockSupport, MockUsage, NeetruError, VERSION, createCheckoutNamespace, createNeetruClient, initNeetru };
|
|
1141
1317
|
//# sourceMappingURL=index.mjs.map
|
|
1142
1318
|
//# sourceMappingURL=index.mjs.map
|