@updatedev/js
Version:
Update JavaScript SDK
181 lines • 4.31 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var UpdateBilling_exports = {};
__export(UpdateBilling_exports, {
UpdateBillingClient: () => UpdateBillingClient
});
module.exports = __toCommonJS(UpdateBilling_exports);
class UpdateBillingClient {
constructor({
requestClient,
hasSessionToken
}) {
this.requestClient = requestClient;
this.hasSessionToken = hasSessionToken;
}
async getProducts() {
const { data, error } = await this.requestClient.request({
endpoint: "/billing/products",
method: "GET"
});
if (error) {
return {
data: {
products: null
},
error: {
message: error.message
}
};
}
return {
data: {
products: data
},
error: null
};
}
async getSubscriptions() {
if (!this.hasSessionToken) {
console.warn(
"@updatedev/js: billing.getSubscriptions() called without a session token. You need to add `getSessionToken` to createClient()."
);
return {
data: {
subscriptions: null
},
error: {
message: "No session token"
}
};
}
const { data, error } = await this.requestClient.request({
endpoint: "/billing/subscriptions",
method: "GET",
extra: {
includeUser: true
}
});
if (error) {
return {
data: {
subscriptions: null
},
error: {
message: error.message
}
};
}
return {
data: {
subscriptions: data
},
error: null
};
}
async updateSubscription(id, { cancel_at_period_end }) {
if (!this.hasSessionToken) {
console.warn(
"@updatedev/js: billing.updateSubscription() called without a session token. You need to add `getSessionToken` to createClient()."
);
return {
data: {
subscription: null
},
error: {
message: "No session token"
}
};
}
const { data, error } = await this.requestClient.request({
endpoint: "/billing/subscriptions/update",
method: "POST",
body: {
id,
cancel_at_period_end
},
extra: {
includeUser: true
}
});
if (error) {
return {
data: {
subscription: null
},
error: {
message: error.message
}
};
}
return {
data: {
subscription: data
},
error: null
};
}
async createCheckoutSession(id, options) {
if (!this.hasSessionToken) {
console.warn(
"@updatedev/js: billing.createCheckoutSession() called without a session token. You need to add `getSessionToken` to createClient()."
);
return {
data: {
url: null
},
error: {
message: "No session token"
}
};
}
const { data, error } = await this.requestClient.request({
endpoint: "/billing/checkout/create",
method: "POST",
body: {
id,
options
},
extra: {
includeUser: true
}
});
if (error) {
return {
data: {
url: null
},
error: {
message: error.message
}
};
}
return {
data: {
url: data
},
error: null
};
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
UpdateBillingClient
});
//# sourceMappingURL=UpdateBilling.js.map