botcast-sdk 1.0.7 → 1.0.8
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/README.md +3 -1
- package/dist/admin.cjs +40 -3
- package/dist/admin.d.ts +18 -1
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js +40 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,10 +62,12 @@ const { instance } = await admin.createInstance({
|
|
|
62
62
|
platform: "whatsapp",
|
|
63
63
|
type: "paid",
|
|
64
64
|
plan_months: 12,
|
|
65
|
+
expires_at: "2027-12-31T23:59:59.000Z", // Optional exact expiration date
|
|
65
66
|
});
|
|
66
67
|
|
|
67
|
-
// Renew subscription
|
|
68
|
+
// Renew subscription (by months or exact date)
|
|
68
69
|
await admin.renewInstance(instance.id, { months: 12 });
|
|
70
|
+
// or: await admin.setExpiration(instance.id, "2028-06-30T23:59:59.000Z");
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
---
|
package/dist/admin.cjs
CHANGED
|
@@ -65,6 +65,12 @@ class BotcastAdminClient {
|
|
|
65
65
|
* Admins are zero-payment, so instances are provisioned as active paid instances.
|
|
66
66
|
*/
|
|
67
67
|
async createInstance(options) {
|
|
68
|
+
const rawExp = options.expires_at || options.expiresAt;
|
|
69
|
+
const expires_at = rawExp
|
|
70
|
+
? rawExp instanceof Date
|
|
71
|
+
? rawExp.toISOString()
|
|
72
|
+
: new Date(rawExp).toISOString()
|
|
73
|
+
: undefined;
|
|
68
74
|
return this.request('/api/instances', {
|
|
69
75
|
method: 'POST',
|
|
70
76
|
body: JSON.stringify({
|
|
@@ -75,29 +81,60 @@ class BotcastAdminClient {
|
|
|
75
81
|
allowed_numbers: options.allowed_numbers || [],
|
|
76
82
|
webhook_url: options.webhook_url || '',
|
|
77
83
|
target_user_id: options.target_user_id,
|
|
84
|
+
expires_at,
|
|
78
85
|
}),
|
|
79
86
|
});
|
|
80
87
|
}
|
|
81
88
|
/**
|
|
82
89
|
* Programmatically renews an instance's subscription without payment transactions.
|
|
90
|
+
* Supports either extending by months or setting an exact expiration date.
|
|
83
91
|
*/
|
|
84
92
|
async renewInstance(instanceId, options) {
|
|
93
|
+
const rawExp = options?.expires_at || options?.expiresAt;
|
|
94
|
+
const expires_at = rawExp
|
|
95
|
+
? rawExp instanceof Date
|
|
96
|
+
? rawExp.toISOString()
|
|
97
|
+
: new Date(rawExp).toISOString()
|
|
98
|
+
: undefined;
|
|
85
99
|
return this.request(`/api/instances/${instanceId}/renew`, {
|
|
86
100
|
method: 'POST',
|
|
87
101
|
body: JSON.stringify({
|
|
88
|
-
months: options?.months || options?.plan_months || 12,
|
|
102
|
+
months: options?.months || options?.plan_months || (expires_at ? undefined : 12),
|
|
103
|
+
expires_at,
|
|
89
104
|
}),
|
|
90
105
|
});
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
93
|
-
* Updates instance configuration (name, webhook URL, allowed recipient numbers).
|
|
108
|
+
* Updates instance configuration (name, webhook URL, allowed recipient numbers, expiration date).
|
|
94
109
|
*/
|
|
95
110
|
async updateInstance(instanceId, updates) {
|
|
111
|
+
const rawExp = updates.expires_at !== undefined ? updates.expires_at : updates.expiresAt;
|
|
112
|
+
let expires_at = undefined;
|
|
113
|
+
if (rawExp !== undefined) {
|
|
114
|
+
if (rawExp === null) {
|
|
115
|
+
expires_at = null;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
expires_at = rawExp instanceof Date ? rawExp.toISOString() : new Date(rawExp).toISOString();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
96
121
|
return this.request(`/api/instances/${instanceId}`, {
|
|
97
122
|
method: 'PUT',
|
|
98
|
-
body: JSON.stringify(
|
|
123
|
+
body: JSON.stringify({
|
|
124
|
+
...updates,
|
|
125
|
+
expires_at,
|
|
126
|
+
}),
|
|
99
127
|
});
|
|
100
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Directly sets or clears the exact expiration date for an instance.
|
|
131
|
+
*
|
|
132
|
+
* @param instanceId Target instance ID (e.g. `ins_paid_...`)
|
|
133
|
+
* @param expiresAt Date instance, ISO string (e.g. `2027-01-01T00:00:00.000Z`), or `null` to remove expiry.
|
|
134
|
+
*/
|
|
135
|
+
async setExpiration(instanceId, expiresAt) {
|
|
136
|
+
return this.updateInstance(instanceId, { expires_at: expiresAt });
|
|
137
|
+
}
|
|
101
138
|
/**
|
|
102
139
|
* Regenerates secret instance token for an instance.
|
|
103
140
|
*/
|
package/dist/admin.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface CreateAdminInstanceOptions {
|
|
|
12
12
|
allowed_numbers?: string[];
|
|
13
13
|
webhook_url?: string;
|
|
14
14
|
target_user_id?: number;
|
|
15
|
+
expires_at?: string | Date;
|
|
16
|
+
expiresAt?: string | Date;
|
|
15
17
|
}
|
|
16
18
|
export interface AdminInstanceRecord {
|
|
17
19
|
id: string;
|
|
@@ -59,26 +61,41 @@ export declare class BotcastAdminClient {
|
|
|
59
61
|
}>;
|
|
60
62
|
/**
|
|
61
63
|
* Programmatically renews an instance's subscription without payment transactions.
|
|
64
|
+
* Supports either extending by months or setting an exact expiration date.
|
|
62
65
|
*/
|
|
63
66
|
renewInstance(instanceId: string, options?: {
|
|
64
67
|
months?: number;
|
|
65
68
|
plan_months?: number;
|
|
69
|
+
expires_at?: string | Date;
|
|
70
|
+
expiresAt?: string | Date;
|
|
66
71
|
}): Promise<{
|
|
67
72
|
success: boolean;
|
|
68
73
|
message: string;
|
|
69
74
|
instance: AdminInstanceRecord;
|
|
70
75
|
}>;
|
|
71
76
|
/**
|
|
72
|
-
* Updates instance configuration (name, webhook URL, allowed recipient numbers).
|
|
77
|
+
* Updates instance configuration (name, webhook URL, allowed recipient numbers, expiration date).
|
|
73
78
|
*/
|
|
74
79
|
updateInstance(instanceId: string, updates: {
|
|
75
80
|
name?: string;
|
|
76
81
|
webhook_url?: string;
|
|
77
82
|
allowed_numbers?: string[];
|
|
83
|
+
expires_at?: string | Date | null;
|
|
84
|
+
expiresAt?: string | Date | null;
|
|
78
85
|
}): Promise<{
|
|
79
86
|
message: string;
|
|
80
87
|
instance: AdminInstanceRecord;
|
|
81
88
|
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Directly sets or clears the exact expiration date for an instance.
|
|
91
|
+
*
|
|
92
|
+
* @param instanceId Target instance ID (e.g. `ins_paid_...`)
|
|
93
|
+
* @param expiresAt Date instance, ISO string (e.g. `2027-01-01T00:00:00.000Z`), or `null` to remove expiry.
|
|
94
|
+
*/
|
|
95
|
+
setExpiration(instanceId: string, expiresAt: string | Date | null): Promise<{
|
|
96
|
+
message: string;
|
|
97
|
+
instance: AdminInstanceRecord;
|
|
98
|
+
}>;
|
|
82
99
|
/**
|
|
83
100
|
* Regenerates secret instance token for an instance.
|
|
84
101
|
*/
|
package/dist/admin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/admin.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IACnC,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/admin.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBA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CAAA;KAAE,CAAC;IAoB9D;;;;;OAKG;IACU,aAAa,CACxB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAC9B,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,mBAAmB,CAAA;KAAE,CAAC;IAI9D;;OAEG;IACU,uBAAuB,CAClC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IAMvD;;OAEG;IACU,cAAc,CACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAKpD"}
|
package/dist/admin.js
CHANGED
|
@@ -62,6 +62,12 @@ export class BotcastAdminClient {
|
|
|
62
62
|
* Admins are zero-payment, so instances are provisioned as active paid instances.
|
|
63
63
|
*/
|
|
64
64
|
async createInstance(options) {
|
|
65
|
+
const rawExp = options.expires_at || options.expiresAt;
|
|
66
|
+
const expires_at = rawExp
|
|
67
|
+
? rawExp instanceof Date
|
|
68
|
+
? rawExp.toISOString()
|
|
69
|
+
: new Date(rawExp).toISOString()
|
|
70
|
+
: undefined;
|
|
65
71
|
return this.request('/api/instances', {
|
|
66
72
|
method: 'POST',
|
|
67
73
|
body: JSON.stringify({
|
|
@@ -72,29 +78,60 @@ export class BotcastAdminClient {
|
|
|
72
78
|
allowed_numbers: options.allowed_numbers || [],
|
|
73
79
|
webhook_url: options.webhook_url || '',
|
|
74
80
|
target_user_id: options.target_user_id,
|
|
81
|
+
expires_at,
|
|
75
82
|
}),
|
|
76
83
|
});
|
|
77
84
|
}
|
|
78
85
|
/**
|
|
79
86
|
* Programmatically renews an instance's subscription without payment transactions.
|
|
87
|
+
* Supports either extending by months or setting an exact expiration date.
|
|
80
88
|
*/
|
|
81
89
|
async renewInstance(instanceId, options) {
|
|
90
|
+
const rawExp = options?.expires_at || options?.expiresAt;
|
|
91
|
+
const expires_at = rawExp
|
|
92
|
+
? rawExp instanceof Date
|
|
93
|
+
? rawExp.toISOString()
|
|
94
|
+
: new Date(rawExp).toISOString()
|
|
95
|
+
: undefined;
|
|
82
96
|
return this.request(`/api/instances/${instanceId}/renew`, {
|
|
83
97
|
method: 'POST',
|
|
84
98
|
body: JSON.stringify({
|
|
85
|
-
months: options?.months || options?.plan_months || 12,
|
|
99
|
+
months: options?.months || options?.plan_months || (expires_at ? undefined : 12),
|
|
100
|
+
expires_at,
|
|
86
101
|
}),
|
|
87
102
|
});
|
|
88
103
|
}
|
|
89
104
|
/**
|
|
90
|
-
* Updates instance configuration (name, webhook URL, allowed recipient numbers).
|
|
105
|
+
* Updates instance configuration (name, webhook URL, allowed recipient numbers, expiration date).
|
|
91
106
|
*/
|
|
92
107
|
async updateInstance(instanceId, updates) {
|
|
108
|
+
const rawExp = updates.expires_at !== undefined ? updates.expires_at : updates.expiresAt;
|
|
109
|
+
let expires_at = undefined;
|
|
110
|
+
if (rawExp !== undefined) {
|
|
111
|
+
if (rawExp === null) {
|
|
112
|
+
expires_at = null;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
expires_at = rawExp instanceof Date ? rawExp.toISOString() : new Date(rawExp).toISOString();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
93
118
|
return this.request(`/api/instances/${instanceId}`, {
|
|
94
119
|
method: 'PUT',
|
|
95
|
-
body: JSON.stringify(
|
|
120
|
+
body: JSON.stringify({
|
|
121
|
+
...updates,
|
|
122
|
+
expires_at,
|
|
123
|
+
}),
|
|
96
124
|
});
|
|
97
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Directly sets or clears the exact expiration date for an instance.
|
|
128
|
+
*
|
|
129
|
+
* @param instanceId Target instance ID (e.g. `ins_paid_...`)
|
|
130
|
+
* @param expiresAt Date instance, ISO string (e.g. `2027-01-01T00:00:00.000Z`), or `null` to remove expiry.
|
|
131
|
+
*/
|
|
132
|
+
async setExpiration(instanceId, expiresAt) {
|
|
133
|
+
return this.updateInstance(instanceId, { expires_at: expiresAt });
|
|
134
|
+
}
|
|
98
135
|
/**
|
|
99
136
|
* Regenerates secret instance token for an instance.
|
|
100
137
|
*/
|
package/package.json
CHANGED