@internxt/sdk 1.9.15 → 1.9.17

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.
@@ -183,6 +183,11 @@ export type CreatedSubscriptionData = {
183
183
  subscriptionId?: string;
184
184
  paymentIntentId?: string;
185
185
  };
186
+ export type CreatedPaymentIntent = {
187
+ clientSecret: string;
188
+ id: string;
189
+ invoiceStatus?: string;
190
+ };
186
191
  export type AvailableProducts = {
187
192
  featuresPerService: {
188
193
  antivirus: boolean;
package/dist/index.d.ts CHANGED
@@ -5,3 +5,5 @@ export * as photos from './photos';
5
5
  export * as Shared from './shared';
6
6
  export * as Workspaces from './workspaces';
7
7
  export * from './meet';
8
+ export * as Payments from './payments';
9
+ export * from './misc';
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Workspaces = exports.Shared = exports.photos = exports.Network = exports.Drive = void 0;
29
+ exports.Payments = exports.Workspaces = exports.Shared = exports.photos = exports.Network = exports.Drive = void 0;
30
30
  __exportStar(require("./auth"), exports);
31
31
  exports.Drive = __importStar(require("./drive"));
32
32
  exports.Network = __importStar(require("./network"));
@@ -34,3 +34,5 @@ exports.photos = __importStar(require("./photos"));
34
34
  exports.Shared = __importStar(require("./shared"));
35
35
  exports.Workspaces = __importStar(require("./workspaces"));
36
36
  __exportStar(require("./meet"), exports);
37
+ exports.Payments = __importStar(require("./payments"));
38
+ __exportStar(require("./misc"), exports);
@@ -0,0 +1 @@
1
+ export * from './location';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./location"), exports);
@@ -0,0 +1,5 @@
1
+ export interface UserLocation {
2
+ ip: string;
3
+ location: string;
4
+ }
5
+ export declare const getUserLocation: (apiUrl: string) => Promise<UserLocation>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getUserLocation = void 0;
40
+ var client_1 = require("../../shared/http/client");
41
+ var getUserLocation = function (apiUrl) { return __awaiter(void 0, void 0, void 0, function () {
42
+ var client;
43
+ return __generator(this, function (_a) {
44
+ client = client_1.HttpClient.create(apiUrl);
45
+ return [2 /*return*/, client.get("".concat(apiUrl), {})];
46
+ });
47
+ }); };
48
+ exports.getUserLocation = getUserLocation;
@@ -0,0 +1,72 @@
1
+ import { CreatedPaymentIntent, CreatedSubscriptionData } from '../drive/payments/types/types';
2
+ import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
3
+ import { CreatePaymentIntentPayload, CreateSubscriptionPayload, GetPriceByIdPayload, PriceWithTax } from './types';
4
+ export declare class Checkout {
5
+ private readonly client;
6
+ private readonly appDetails;
7
+ private readonly apiSecurity;
8
+ static client(apiUrl: ApiUrl, appDetails: AppDetails, apiSecurity: ApiSecurity): Checkout;
9
+ private constructor();
10
+ /**
11
+ * @description Creates a customer or gets the existing one if it already exists
12
+ * @param country - The country of the customer
13
+ * @param postalCode - The postal code of the customer
14
+ * @param companyVatId - The VAT ID of the company (optional)
15
+ * @returns The customer ID and the user token used to create a subscription or payment intent
16
+ */
17
+ getCustomerId({ customerName, postalCode, country, companyVatId, }: {
18
+ customerName: string;
19
+ postalCode: string;
20
+ country: string;
21
+ companyVatId?: string;
22
+ }): Promise<{
23
+ customerId: string;
24
+ token: string;
25
+ }>;
26
+ /**
27
+ * @description Creates a subscription for a given customer
28
+ * @param customerId - The ID of the customer
29
+ * @param priceId - The ID of the price
30
+ * @param token - The token used to authenticate the customer
31
+ * @param currency - The currency of the subscription (optional)
32
+ * @param promoCodeId - The ID of the promo code (optional)
33
+ * @param quantity - The quantity of the subscription (optional)
34
+ * @returns The created subscription data:
35
+ * - `type`: The type of the subscription (setup or payment)
36
+ * - `clientSecret`: The client secret for the subscription to be used with Stripe Elements
37
+ * - `subscriptionId`: The ID of the subscription (optional)
38
+ * - `paymentIntentId`: The ID of the payment intent (optional)
39
+ */
40
+ createSubscription({ customerId, priceId, token, currency, promoCodeId, quantity, }: CreateSubscriptionPayload): Promise<CreatedSubscriptionData>;
41
+ /**
42
+ * @description Creates a payment intent for a given customer
43
+ * @param customerId - The ID of the customer
44
+ * @param priceId - The ID of the price
45
+ * @param token - The token used to authenticate the customer
46
+ * @param currency - The currency of the payment intent (optional)
47
+ * @param promoCodeId - The ID of the promo code (optional)
48
+ * @returns The created invoice data:
49
+ * - `clientSecret`: The client secret for the invoice to be used with Stripe Elements
50
+ * - `id`: The ID of the invoice
51
+ * - `invoiceStatus`: The status of the invoice (only when the status is 'paid')
52
+ */
53
+ createPaymentIntent({ customerId, priceId, token, currency, promoCodeId, }: CreatePaymentIntentPayload): Promise<CreatedPaymentIntent>;
54
+ /**
55
+ * @description Fetch a requested price by its ID and its tax rate
56
+ * @param priceId - The ID of the price
57
+ * @param promoCodeName - The name of the promo code (optional)
58
+ * @param currency - The currency of the price (optional)
59
+ * @returns The price object containing the details of the requested price
60
+ */
61
+ getPriceById({ priceId, promoCodeName, currency, postalCode, country, }: GetPriceByIdPayload): Promise<PriceWithTax>;
62
+ /**
63
+ * Returns the needed headers with authorization header for the module requests
64
+ * @private
65
+ */
66
+ private authHeaders;
67
+ /**
68
+ * Returns the basic needed headers for the module requests
69
+ * @private
70
+ */
71
+ private headers;
72
+ }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.Checkout = void 0;
15
+ var headers_1 = require("../shared/headers");
16
+ var client_1 = require("../shared/http/client");
17
+ var Checkout = /** @class */ (function () {
18
+ function Checkout(apiUrl, appDetails, apiSecurity) {
19
+ this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
20
+ this.appDetails = appDetails;
21
+ this.apiSecurity = apiSecurity;
22
+ }
23
+ Checkout.client = function (apiUrl, appDetails, apiSecurity) {
24
+ return new Checkout(apiUrl, appDetails, apiSecurity);
25
+ };
26
+ /**
27
+ * @description Creates a customer or gets the existing one if it already exists
28
+ * @param country - The country of the customer
29
+ * @param postalCode - The postal code of the customer
30
+ * @param companyVatId - The VAT ID of the company (optional)
31
+ * @returns The customer ID and the user token used to create a subscription or payment intent
32
+ */
33
+ Checkout.prototype.getCustomerId = function (_a) {
34
+ var customerName = _a.customerName, postalCode = _a.postalCode, country = _a.country, companyVatId = _a.companyVatId;
35
+ var query = new URLSearchParams();
36
+ query.set('customerName', customerName);
37
+ query.set('country', country);
38
+ query.set('postalCode', postalCode);
39
+ if (companyVatId !== undefined)
40
+ query.set('companyVatId', companyVatId);
41
+ return this.client.get("/checkout/customer?".concat(query.toString()), this.authHeaders());
42
+ };
43
+ /**
44
+ * @description Creates a subscription for a given customer
45
+ * @param customerId - The ID of the customer
46
+ * @param priceId - The ID of the price
47
+ * @param token - The token used to authenticate the customer
48
+ * @param currency - The currency of the subscription (optional)
49
+ * @param promoCodeId - The ID of the promo code (optional)
50
+ * @param quantity - The quantity of the subscription (optional)
51
+ * @returns The created subscription data:
52
+ * - `type`: The type of the subscription (setup or payment)
53
+ * - `clientSecret`: The client secret for the subscription to be used with Stripe Elements
54
+ * - `subscriptionId`: The ID of the subscription (optional)
55
+ * - `paymentIntentId`: The ID of the payment intent (optional)
56
+ */
57
+ Checkout.prototype.createSubscription = function (_a) {
58
+ var customerId = _a.customerId, priceId = _a.priceId, token = _a.token, currency = _a.currency, promoCodeId = _a.promoCodeId, quantity = _a.quantity;
59
+ return this.client.post('/checkout/subscription', {
60
+ customerId: customerId,
61
+ priceId: priceId,
62
+ token: token,
63
+ currency: currency,
64
+ promoCodeId: promoCodeId,
65
+ quantity: quantity,
66
+ }, this.authHeaders());
67
+ };
68
+ /**
69
+ * @description Creates a payment intent for a given customer
70
+ * @param customerId - The ID of the customer
71
+ * @param priceId - The ID of the price
72
+ * @param token - The token used to authenticate the customer
73
+ * @param currency - The currency of the payment intent (optional)
74
+ * @param promoCodeId - The ID of the promo code (optional)
75
+ * @returns The created invoice data:
76
+ * - `clientSecret`: The client secret for the invoice to be used with Stripe Elements
77
+ * - `id`: The ID of the invoice
78
+ * - `invoiceStatus`: The status of the invoice (only when the status is 'paid')
79
+ */
80
+ Checkout.prototype.createPaymentIntent = function (_a) {
81
+ var customerId = _a.customerId, priceId = _a.priceId, token = _a.token, currency = _a.currency, promoCodeId = _a.promoCodeId;
82
+ return this.client.post('/checkout/payment-intent', {
83
+ customerId: customerId,
84
+ priceId: priceId,
85
+ token: token,
86
+ currency: currency,
87
+ promoCodeId: promoCodeId,
88
+ }, this.authHeaders());
89
+ };
90
+ /**
91
+ * @description Fetch a requested price by its ID and its tax rate
92
+ * @param priceId - The ID of the price
93
+ * @param promoCodeName - The name of the promo code (optional)
94
+ * @param currency - The currency of the price (optional)
95
+ * @returns The price object containing the details of the requested price
96
+ */
97
+ Checkout.prototype.getPriceById = function (_a) {
98
+ var priceId = _a.priceId, promoCodeName = _a.promoCodeName, currency = _a.currency, postalCode = _a.postalCode, country = _a.country;
99
+ var query = new URLSearchParams();
100
+ query.set('priceId', priceId);
101
+ if (promoCodeName !== undefined)
102
+ query.set('promoCodeName', promoCodeName);
103
+ if (currency !== undefined)
104
+ query.set('currency', currency);
105
+ if (postalCode !== undefined)
106
+ query.set('postalCode', postalCode);
107
+ if (country !== undefined)
108
+ query.set('country', country);
109
+ return this.client.get("/checkout/price-by-id?".concat(query.toString()), this.headers());
110
+ };
111
+ /**
112
+ * Returns the needed headers with authorization header for the module requests
113
+ * @private
114
+ */
115
+ Checkout.prototype.authHeaders = function () {
116
+ var additionalHeaders = {};
117
+ if (this.appDetails.desktopHeader) {
118
+ additionalHeaders['x-internxt-desktop-header'] = this.appDetails.desktopHeader;
119
+ }
120
+ return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, this.apiSecurity.token, undefined, additionalHeaders);
121
+ };
122
+ /**
123
+ * Returns the basic needed headers for the module requests
124
+ * @private
125
+ */
126
+ Checkout.prototype.headers = function () {
127
+ var _a;
128
+ var additionalHeaders = __assign({}, ((_a = this.appDetails.customHeaders) !== null && _a !== void 0 ? _a : {}));
129
+ return (0, headers_1.basicHeaders)(this.appDetails.clientName, this.appDetails.clientVersion, additionalHeaders);
130
+ };
131
+ return Checkout;
132
+ }());
133
+ exports.Checkout = Checkout;
@@ -0,0 +1 @@
1
+ export * from './checkout';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./checkout"), exports);
@@ -0,0 +1,45 @@
1
+ import { UserType } from 'src/drive/payments/types/types';
2
+ export interface CreateSubscriptionPayload {
3
+ customerId: string;
4
+ priceId: string;
5
+ token: string;
6
+ currency?: string;
7
+ promoCodeId?: string;
8
+ quantity?: number;
9
+ }
10
+ export interface CreatePaymentIntentPayload {
11
+ customerId: string;
12
+ priceId: string;
13
+ token: string;
14
+ currency?: string;
15
+ promoCodeId?: string;
16
+ }
17
+ export interface GetPriceByIdPayload {
18
+ priceId: string;
19
+ promoCodeName?: string;
20
+ currency?: string;
21
+ postalCode?: string;
22
+ country?: string;
23
+ }
24
+ export type Price = {
25
+ id: string;
26
+ currency: string;
27
+ amount: number;
28
+ bytes: number;
29
+ interval: 'lifetime' | 'year';
30
+ decimalAmount: number;
31
+ type: UserType;
32
+ product: string;
33
+ minimumSeats?: number;
34
+ maximumSeats?: number;
35
+ };
36
+ export type Taxes = {
37
+ tax: number;
38
+ decimalTax: number;
39
+ amountWithTax: number;
40
+ decimalAmountWithTax: number;
41
+ };
42
+ export type PriceWithTax = {
43
+ price: Price;
44
+ taxes: Taxes;
45
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -11,7 +11,7 @@ type InternxtHeaders = {
11
11
  'x-token'?: string;
12
12
  'internxt-resources-token'?: string;
13
13
  };
14
- export declare function basicHeaders(clientName: string, clientVersion: string): InternxtHeaders;
14
+ export declare function basicHeaders(clientName: string, clientVersion: string, customHeaders?: Record<string, string>): InternxtHeaders;
15
15
  export declare function basicHeadersWithPassword(clientName: string, clientVersion: string, password: string): InternxtHeaders;
16
16
  export declare function headersWithToken(clientName: string, clientVersion: string, token: Token, workspaceToken?: Token, customHeaders?: CustomHeaders): InternxtHeaders;
17
17
  export declare function headersWithTokenAndPassword(clientName: string, clientVersion: string, token: Token, workspaceToken: Token | undefined, password: string): InternxtHeaders;
@@ -12,12 +12,8 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.addResourcesTokenToHeaders = exports.headersWithAuthToken = exports.headersWithBasicAuth = exports.headersWithTokenAndPassword = exports.headersWithToken = exports.basicHeadersWithPassword = exports.basicHeaders = void 0;
15
- function basicHeaders(clientName, clientVersion) {
16
- return {
17
- 'content-type': 'application/json; charset=utf-8',
18
- 'internxt-version': clientVersion,
19
- 'internxt-client': clientName,
20
- };
15
+ function basicHeaders(clientName, clientVersion, customHeaders) {
16
+ return __assign({ 'content-type': 'application/json; charset=utf-8', 'internxt-version': clientVersion, 'internxt-client': clientName }, customHeaders);
21
17
  }
22
18
  exports.basicHeaders = basicHeaders;
23
19
  function basicHeadersWithPassword(clientName, clientVersion, password) {
@@ -4,6 +4,7 @@ export type ApiUrl = string;
4
4
  export interface AppDetails {
5
5
  clientName: string;
6
6
  clientVersion: string;
7
+ customHeaders?: Record<string, string>;
7
8
  desktopHeader?: string;
8
9
  }
9
10
  export interface ApiSecurity {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@internxt/sdk",
3
3
  "author": "Internxt <hello@internxt.com>",
4
- "version": "1.9.15",
4
+ "version": "1.9.17",
5
5
  "description": "An sdk for interacting with Internxt's services",
6
6
  "repository": {
7
7
  "type": "git",