sendblue 3.10.1 → 3.11.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 +33 -0
- package/README.md +7 -7
- package/client.d.mts +37 -4
- package/client.d.mts.map +1 -1
- package/client.d.ts +37 -4
- package/client.d.ts.map +1 -1
- package/client.js +33 -0
- package/client.js.map +1 -1
- package/client.mjs +33 -0
- package/client.mjs.map +1 -1
- package/core/streaming.d.mts +33 -0
- package/core/streaming.d.mts.map +1 -0
- package/core/streaming.d.ts +33 -0
- package/core/streaming.d.ts.map +1 -0
- package/core/streaming.js +263 -0
- package/core/streaming.js.map +1 -0
- package/core/streaming.mjs +258 -0
- package/core/streaming.mjs.map +1 -0
- package/internal/decoders/line.d.mts +17 -0
- package/internal/decoders/line.d.mts.map +1 -0
- package/internal/decoders/line.d.ts +17 -0
- package/internal/decoders/line.d.ts.map +1 -0
- package/internal/decoders/line.js +113 -0
- package/internal/decoders/line.js.map +1 -0
- package/internal/decoders/line.mjs +108 -0
- package/internal/decoders/line.mjs.map +1 -0
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +10 -0
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +10 -0
- package/internal/parse.mjs.map +1 -1
- package/internal/request-options.d.mts +2 -0
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +2 -0
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs.map +1 -1
- package/internal/tslib.js +17 -17
- package/package.json +11 -1
- package/resources/auth/auth.d.mts +10 -0
- package/resources/auth/auth.d.mts.map +1 -0
- package/resources/auth/auth.d.ts +10 -0
- package/resources/auth/auth.d.ts.map +1 -0
- package/resources/auth/auth.js +17 -0
- package/resources/auth/auth.js.map +1 -0
- package/resources/auth/auth.mjs +12 -0
- package/resources/auth/auth.mjs.map +1 -0
- package/resources/auth/index.d.mts +3 -0
- package/resources/auth/index.d.mts.map +1 -0
- package/resources/auth/index.d.ts +3 -0
- package/resources/auth/index.d.ts.map +1 -0
- package/resources/auth/index.js +9 -0
- package/resources/auth/index.js.map +1 -0
- package/resources/auth/index.mjs +4 -0
- package/resources/auth/index.mjs.map +1 -0
- package/resources/auth/tokens.d.mts +77 -0
- package/resources/auth/tokens.d.mts.map +1 -0
- package/resources/auth/tokens.d.ts +77 -0
- package/resources/auth/tokens.d.ts.map +1 -0
- package/resources/auth/tokens.js +51 -0
- package/resources/auth/tokens.js.map +1 -0
- package/resources/auth/tokens.mjs +47 -0
- package/resources/auth/tokens.mjs.map +1 -0
- package/resources/auth.d.mts +2 -0
- package/resources/auth.d.mts.map +1 -0
- package/resources/auth.d.ts +2 -0
- package/resources/auth.d.ts.map +1 -0
- package/resources/auth.js +6 -0
- package/resources/auth.js.map +1 -0
- package/resources/auth.mjs +3 -0
- package/resources/auth.mjs.map +1 -0
- package/resources/contacts/contacts.d.mts +8 -0
- package/resources/contacts/contacts.d.mts.map +1 -1
- package/resources/contacts/contacts.d.ts +8 -0
- package/resources/contacts/contacts.d.ts.map +1 -1
- package/resources/contacts/contacts.js.map +1 -1
- package/resources/contacts/contacts.mjs.map +1 -1
- package/resources/events.d.mts +45 -0
- package/resources/events.d.mts.map +1 -0
- package/resources/events.d.ts +45 -0
- package/resources/events.d.ts.map +1 -0
- package/resources/events.js +37 -0
- package/resources/events.js.map +1 -0
- package/resources/events.mjs +33 -0
- package/resources/events.mjs.map +1 -0
- package/resources/groups.d.mts +25 -0
- package/resources/groups.d.mts.map +1 -1
- package/resources/groups.d.ts +25 -0
- package/resources/groups.d.ts.map +1 -1
- package/resources/index.d.mts +8 -2
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +8 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +13 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +6 -0
- package/resources/index.mjs.map +1 -1
- package/resources/lines/call-forwarding.d.mts +3 -0
- package/resources/lines/call-forwarding.d.mts.map +1 -1
- package/resources/lines/call-forwarding.d.ts +3 -0
- package/resources/lines/call-forwarding.d.ts.map +1 -1
- package/resources/lines/call-forwarding.js +3 -0
- package/resources/lines/call-forwarding.js.map +1 -1
- package/resources/lines/call-forwarding.mjs +3 -0
- package/resources/lines/call-forwarding.mjs.map +1 -1
- package/resources/lines/index.d.mts +1 -1
- package/resources/lines/index.d.mts.map +1 -1
- package/resources/lines/index.d.ts +1 -1
- package/resources/lines/index.d.ts.map +1 -1
- package/resources/lines/index.js.map +1 -1
- package/resources/lines/index.mjs.map +1 -1
- package/resources/lines/lines.d.mts +30 -0
- package/resources/lines/lines.d.mts.map +1 -1
- package/resources/lines/lines.d.ts +30 -0
- package/resources/lines/lines.d.ts.map +1 -1
- package/resources/lines/lines.js +15 -0
- package/resources/lines/lines.js.map +1 -1
- package/resources/lines/lines.mjs +15 -0
- package/resources/lines/lines.mjs.map +1 -1
- package/resources/location.d.mts +156 -0
- package/resources/location.d.mts.map +1 -0
- package/resources/location.d.ts +156 -0
- package/resources/location.d.ts.map +1 -0
- package/resources/location.js +57 -0
- package/resources/location.js.map +1 -0
- package/resources/location.mjs +53 -0
- package/resources/location.mjs.map +1 -0
- package/resources/messages.d.mts +507 -9
- package/resources/messages.d.mts.map +1 -1
- package/resources/messages.d.ts +507 -9
- package/resources/messages.d.ts.map +1 -1
- package/resources/messages.js +16 -2
- package/resources/messages.js.map +1 -1
- package/resources/messages.mjs +16 -2
- package/resources/messages.mjs.map +1 -1
- package/resources/request-location.d.mts +54 -0
- package/resources/request-location.d.mts.map +1 -0
- package/resources/request-location.d.ts +54 -0
- package/resources/request-location.d.ts.map +1 -0
- package/resources/request-location.js +30 -0
- package/resources/request-location.js.map +1 -0
- package/resources/request-location.mjs +26 -0
- package/resources/request-location.mjs.map +1 -0
- package/resources/send-carousel.d.mts +67 -0
- package/resources/send-carousel.d.mts.map +1 -1
- package/resources/send-carousel.d.ts +67 -0
- package/resources/send-carousel.d.ts.map +1 -1
- package/resources/v2/groups.d.mts +82 -0
- package/resources/v2/groups.d.mts.map +1 -0
- package/resources/v2/groups.d.ts +82 -0
- package/resources/v2/groups.d.ts.map +1 -0
- package/resources/v2/groups.js +27 -0
- package/resources/v2/groups.js.map +1 -0
- package/resources/v2/groups.mjs +23 -0
- package/resources/v2/groups.mjs.map +1 -0
- package/resources/v2/index.d.mts +1 -0
- package/resources/v2/index.d.mts.map +1 -1
- package/resources/v2/index.d.ts +1 -0
- package/resources/v2/index.d.ts.map +1 -1
- package/resources/v2/index.js +3 -1
- package/resources/v2/index.js.map +1 -1
- package/resources/v2/index.mjs +1 -0
- package/resources/v2/index.mjs.map +1 -1
- package/resources/v2/v2.d.mts +4 -0
- package/resources/v2/v2.d.mts.map +1 -1
- package/resources/v2/v2.d.ts +4 -0
- package/resources/v2/v2.d.ts.map +1 -1
- package/resources/v2/v2.js +4 -0
- package/resources/v2/v2.js.map +1 -1
- package/resources/v2/v2.mjs +4 -0
- package/resources/v2/v2.mjs.map +1 -1
- package/resources/verified-contacts.d.mts +152 -0
- package/resources/verified-contacts.d.mts.map +1 -0
- package/resources/verified-contacts.d.ts +152 -0
- package/resources/verified-contacts.d.ts.map +1 -0
- package/resources/verified-contacts.js +56 -0
- package/resources/verified-contacts.js.map +1 -0
- package/resources/verified-contacts.mjs +52 -0
- package/resources/verified-contacts.mjs.map +1 -0
- package/resources/verify/index.d.mts +3 -0
- package/resources/verify/index.d.mts.map +1 -0
- package/resources/verify/index.d.ts +3 -0
- package/resources/verify/index.d.ts.map +1 -0
- package/resources/verify/index.js +9 -0
- package/resources/verify/index.js.map +1 -0
- package/resources/verify/index.mjs +4 -0
- package/resources/verify/index.mjs.map +1 -0
- package/resources/verify/verifications.d.mts +45 -0
- package/resources/verify/verifications.d.mts.map +1 -0
- package/resources/verify/verifications.d.ts +45 -0
- package/resources/verify/verifications.d.ts.map +1 -0
- package/resources/verify/verifications.js +19 -0
- package/resources/verify/verifications.js.map +1 -0
- package/resources/verify/verifications.mjs +15 -0
- package/resources/verify/verifications.mjs.map +1 -0
- package/resources/verify/verify.d.mts +10 -0
- package/resources/verify/verify.d.mts.map +1 -0
- package/resources/verify/verify.d.ts +10 -0
- package/resources/verify/verify.d.ts.map +1 -0
- package/resources/verify/verify.js +17 -0
- package/resources/verify/verify.js.map +1 -0
- package/resources/verify/verify.mjs +12 -0
- package/resources/verify/verify.mjs.map +1 -0
- package/resources/verify.d.mts +2 -0
- package/resources/verify.d.mts.map +1 -0
- package/resources/verify.d.ts +2 -0
- package/resources/verify.d.ts.map +1 -0
- package/resources/verify.js +6 -0
- package/resources/verify.js.map +1 -0
- package/resources/verify.mjs +3 -0
- package/resources/verify.mjs.map +1 -0
- package/resources/webhooks.d.mts +26 -10
- package/resources/webhooks.d.mts.map +1 -1
- package/resources/webhooks.d.ts +26 -10
- package/resources/webhooks.d.ts.map +1 -1
- package/resources/webhooks.js +13 -2
- package/resources/webhooks.js.map +1 -1
- package/resources/webhooks.mjs +13 -2
- package/resources/webhooks.mjs.map +1 -1
- package/src/client.ts +85 -2
- package/src/core/streaming.ts +319 -0
- package/src/internal/decoders/line.ts +135 -0
- package/src/internal/parse.ts +14 -0
- package/src/internal/request-options.ts +2 -0
- package/src/resources/auth/auth.ts +19 -0
- package/src/resources/auth/index.ts +4 -0
- package/src/resources/auth/tokens.ts +101 -0
- package/src/resources/auth.ts +3 -0
- package/src/resources/contacts/contacts.ts +10 -0
- package/src/resources/events.ts +75 -0
- package/src/resources/groups.ts +28 -0
- package/src/resources/index.ts +26 -1
- package/src/resources/lines/call-forwarding.ts +3 -0
- package/src/resources/lines/index.ts +1 -1
- package/src/resources/lines/lines.ts +44 -0
- package/src/resources/location.ts +237 -0
- package/src/resources/messages.ts +634 -9
- package/src/resources/request-location.ts +72 -0
- package/src/resources/send-carousel.ts +76 -0
- package/src/resources/v2/groups.ts +106 -0
- package/src/resources/v2/index.ts +1 -0
- package/src/resources/v2/v2.ts +6 -0
- package/src/resources/verified-contacts.ts +204 -0
- package/src/resources/verify/index.ts +9 -0
- package/src/resources/verify/verifications.ts +75 -0
- package/src/resources/verify/verify.ts +25 -0
- package/src/resources/verify.ts +3 -0
- package/src/resources/webhooks.ts +27 -10
- package/src/streaming.ts +2 -0
- package/src/version.ts +1 -1
- package/streaming.d.mts +3 -0
- package/streaming.d.mts.map +1 -0
- package/streaming.d.ts +3 -0
- package/streaming.d.ts.map +1 -0
- package/streaming.js +6 -0
- package/streaming.js.map +1 -0
- package/streaming.mjs +3 -0
- package/streaming.mjs.map +1 -0
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,4BAAyB;AAC/C,OAAO,KAAK,WAAW,sBAAmB;AAC1C,OAAO,EAAE,UAAU,EAAE,+BAA4B;AACjD,OAAO,EAAE,cAAc,EAAE,uCAAoC;AAE7D;;GAEG;AACH,qBAAa,QAAS,SAAQ,WAAW;IACvC
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,4BAAyB;AAC/C,OAAO,KAAK,WAAW,sBAAmB;AAC1C,OAAO,EAAE,UAAU,EAAE,+BAA4B;AACjD,OAAO,EAAE,cAAc,EAAE,uCAAoC;AAE7D;;GAEG;AACH,qBAAa,QAAS,SAAQ,WAAW;IACvC;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,qBAAqB,CAAC;IAI9F;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,qBAAqB,CA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BAAmB,GAChD,CAAC;CACH"}
|
package/resources/webhooks.js
CHANGED
|
@@ -9,6 +9,11 @@ const resource_1 = require("../core/resource.js");
|
|
|
9
9
|
class Webhooks extends resource_1.APIResource {
|
|
10
10
|
/**
|
|
11
11
|
* Add new webhooks to the account. Webhooks are appended to existing ones.
|
|
12
|
+
*
|
|
13
|
+
* With a line-scoped temporary bearer token, only receive webhooks can be added.
|
|
14
|
+
* String webhook URLs are automatically scoped to the token's phone numbers;
|
|
15
|
+
* webhook objects must use `sendblue_numbers` within the token's allowed phone
|
|
16
|
+
* numbers.
|
|
12
17
|
*/
|
|
13
18
|
create(body, options) {
|
|
14
19
|
return this._client.post('/api/account/webhooks', { body, ...options });
|
|
@@ -20,13 +25,19 @@ class Webhooks extends resource_1.APIResource {
|
|
|
20
25
|
return this._client.put('/api/account/webhooks', { body, ...options });
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
|
-
* Get
|
|
28
|
+
* Get webhooks configured for the authenticated account.
|
|
29
|
+
*
|
|
30
|
+
* With a line-scoped temporary bearer token, this returns receive webhooks for the
|
|
31
|
+
* token's phone numbers.
|
|
24
32
|
*/
|
|
25
33
|
list(options) {
|
|
26
34
|
return this._client.get('/api/account/webhooks', options);
|
|
27
35
|
}
|
|
28
36
|
/**
|
|
29
|
-
* Delete specific webhooks from the account
|
|
37
|
+
* Delete specific webhooks from the account.
|
|
38
|
+
*
|
|
39
|
+
* With a line-scoped temporary bearer token, this can only remove receive webhooks
|
|
40
|
+
* for the token's phone numbers.
|
|
30
41
|
*/
|
|
31
42
|
delete(body, options) {
|
|
32
43
|
return this._client.delete('/api/account/webhooks', { body, ...options });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kDAA+C;AAK/C;;GAEG;AACH,MAAa,QAAS,SAAQ,sBAAW;IACvC
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kDAA+C;AAK/C;;GAEG;AACH,MAAa,QAAS,SAAQ,sBAAW;IACvC;;;;;;;OAOG;IACH,MAAM,CAAC,IAAyB,EAAE,OAAwB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAyB,EAAE,OAAwB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,OAAwB;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAyB,EAAE,OAAwB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;CACF;AAvCD,4BAuCC"}
|
package/resources/webhooks.mjs
CHANGED
|
@@ -6,6 +6,11 @@ import { APIResource } from "../core/resource.mjs";
|
|
|
6
6
|
export class Webhooks extends APIResource {
|
|
7
7
|
/**
|
|
8
8
|
* Add new webhooks to the account. Webhooks are appended to existing ones.
|
|
9
|
+
*
|
|
10
|
+
* With a line-scoped temporary bearer token, only receive webhooks can be added.
|
|
11
|
+
* String webhook URLs are automatically scoped to the token's phone numbers;
|
|
12
|
+
* webhook objects must use `sendblue_numbers` within the token's allowed phone
|
|
13
|
+
* numbers.
|
|
9
14
|
*/
|
|
10
15
|
create(body, options) {
|
|
11
16
|
return this._client.post('/api/account/webhooks', { body, ...options });
|
|
@@ -17,13 +22,19 @@ export class Webhooks extends APIResource {
|
|
|
17
22
|
return this._client.put('/api/account/webhooks', { body, ...options });
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
|
-
* Get
|
|
25
|
+
* Get webhooks configured for the authenticated account.
|
|
26
|
+
*
|
|
27
|
+
* With a line-scoped temporary bearer token, this returns receive webhooks for the
|
|
28
|
+
* token's phone numbers.
|
|
21
29
|
*/
|
|
22
30
|
list(options) {
|
|
23
31
|
return this._client.get('/api/account/webhooks', options);
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
|
-
* Delete specific webhooks from the account
|
|
34
|
+
* Delete specific webhooks from the account.
|
|
35
|
+
*
|
|
36
|
+
* With a line-scoped temporary bearer token, this can only remove receive webhooks
|
|
37
|
+
* for the token's phone numbers.
|
|
27
38
|
*/
|
|
28
39
|
delete(body, options) {
|
|
29
40
|
return this._client.delete('/api/account/webhooks', { body, ...options });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.mjs","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,WAAW,EAAE,6BAAyB;AAK/C;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,WAAW;IACvC
|
|
1
|
+
{"version":3,"file":"webhooks.mjs","sourceRoot":"","sources":["../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,WAAW,EAAE,6BAAyB;AAK/C;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,WAAW;IACvC;;;;;;;OAOG;IACH,MAAM,CAAC,IAAyB,EAAE,OAAwB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAyB,EAAE,OAAwB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,OAAwB;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAyB,EAAE,OAAwB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;CACF"}
|
package/src/client.ts
CHANGED
|
@@ -17,7 +17,17 @@ import * as Errors from './core/error';
|
|
|
17
17
|
import * as Uploads from './core/uploads';
|
|
18
18
|
import * as API from './resources/index';
|
|
19
19
|
import { APIPromise } from './core/api-promise';
|
|
20
|
+
import { AccountEvent, EventStreamParams, Events } from './resources/events';
|
|
20
21
|
import { GroupModifyParams, GroupModifyResponse, GroupSendMessageParams, Groups } from './resources/groups';
|
|
22
|
+
import {
|
|
23
|
+
Location,
|
|
24
|
+
LocationListParams,
|
|
25
|
+
LocationListResponse,
|
|
26
|
+
LocationRetrieveParams,
|
|
27
|
+
LocationRetrieveResponse,
|
|
28
|
+
LocationWatchParams,
|
|
29
|
+
LocationWatchResponse,
|
|
30
|
+
} from './resources/location';
|
|
21
31
|
import { LookupLookupNumberParams, LookupLookupNumberResponse, Lookups } from './resources/lookups';
|
|
22
32
|
import { MediaObjectUploadParams, MediaObjectUploadResponse, MediaObjects } from './resources/media-objects';
|
|
23
33
|
import {
|
|
@@ -28,14 +38,27 @@ import {
|
|
|
28
38
|
MessageResponse,
|
|
29
39
|
MessageRetrieveResponse,
|
|
30
40
|
MessageSendParams,
|
|
41
|
+
MessageUpdateAppCardParams,
|
|
31
42
|
Messages,
|
|
32
43
|
} from './resources/messages';
|
|
44
|
+
import {
|
|
45
|
+
RequestLocation,
|
|
46
|
+
RequestLocationCreateParams,
|
|
47
|
+
RequestLocationCreateResponse,
|
|
48
|
+
} from './resources/request-location';
|
|
33
49
|
import { SendCarousel, SendCarouselSendParams, SendCarouselSendResponse } from './resources/send-carousel';
|
|
34
50
|
import {
|
|
35
51
|
TypingIndicatorSendParams,
|
|
36
52
|
TypingIndicatorSendResponse,
|
|
37
53
|
TypingIndicators,
|
|
38
54
|
} from './resources/typing-indicators';
|
|
55
|
+
import {
|
|
56
|
+
VerifiedContactCreateParams,
|
|
57
|
+
VerifiedContactCreateResponse,
|
|
58
|
+
VerifiedContactListResponse,
|
|
59
|
+
VerifiedContactRetrieveResponse,
|
|
60
|
+
VerifiedContacts,
|
|
61
|
+
} from './resources/verified-contacts';
|
|
39
62
|
import {
|
|
40
63
|
WebhookConfiguration,
|
|
41
64
|
WebhookCreateParams,
|
|
@@ -47,6 +70,7 @@ import {
|
|
|
47
70
|
WebhookUpdateResponse,
|
|
48
71
|
Webhooks,
|
|
49
72
|
} from './resources/webhooks';
|
|
73
|
+
import { Auth } from './resources/auth/auth';
|
|
50
74
|
import {
|
|
51
75
|
Contact,
|
|
52
76
|
ContactCountResponse,
|
|
@@ -64,8 +88,9 @@ import {
|
|
|
64
88
|
ContactVerifyResponse,
|
|
65
89
|
Contacts,
|
|
66
90
|
} from './resources/contacts/contacts';
|
|
67
|
-
import { Lines } from './resources/lines/lines';
|
|
91
|
+
import { LineGetStateResponse, LineState, Lines } from './resources/lines/lines';
|
|
68
92
|
import { V2 } from './resources/v2/v2';
|
|
93
|
+
import { Verify } from './resources/verify/verify';
|
|
69
94
|
import { type Fetch } from './internal/builtin-types';
|
|
70
95
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
71
96
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
@@ -843,7 +868,28 @@ export class SendblueAPI {
|
|
|
843
868
|
*/
|
|
844
869
|
sendCarousel: API.SendCarousel = new API.SendCarousel(this);
|
|
845
870
|
v2: API.V2 = new API.V2(this);
|
|
871
|
+
/**
|
|
872
|
+
* Sendblue line configuration and health state
|
|
873
|
+
*/
|
|
846
874
|
lines: API.Lines = new API.Lines(this);
|
|
875
|
+
/**
|
|
876
|
+
* Operations for sending and managing messages
|
|
877
|
+
*/
|
|
878
|
+
requestLocation: API.RequestLocation = new API.RequestLocation(this);
|
|
879
|
+
/**
|
|
880
|
+
* Operations for sending and managing messages
|
|
881
|
+
*/
|
|
882
|
+
location: API.Location = new API.Location(this);
|
|
883
|
+
/**
|
|
884
|
+
* Operations for managing verified-contact access to shared iMessage lines
|
|
885
|
+
*/
|
|
886
|
+
verifiedContacts: API.VerifiedContacts = new API.VerifiedContacts(this);
|
|
887
|
+
auth: API.Auth = new API.Auth(this);
|
|
888
|
+
/**
|
|
889
|
+
* Authenticated live account events and recovery contracts
|
|
890
|
+
*/
|
|
891
|
+
events: API.Events = new API.Events(this);
|
|
892
|
+
verify: API.Verify = new API.Verify(this);
|
|
847
893
|
}
|
|
848
894
|
|
|
849
895
|
SendblueAPI.Messages = Messages;
|
|
@@ -856,6 +902,12 @@ SendblueAPI.Webhooks = Webhooks;
|
|
|
856
902
|
SendblueAPI.SendCarousel = SendCarousel;
|
|
857
903
|
SendblueAPI.V2 = V2;
|
|
858
904
|
SendblueAPI.Lines = Lines;
|
|
905
|
+
SendblueAPI.RequestLocation = RequestLocation;
|
|
906
|
+
SendblueAPI.Location = Location;
|
|
907
|
+
SendblueAPI.VerifiedContacts = VerifiedContacts;
|
|
908
|
+
SendblueAPI.Auth = Auth;
|
|
909
|
+
SendblueAPI.Events = Events;
|
|
910
|
+
SendblueAPI.Verify = Verify;
|
|
859
911
|
|
|
860
912
|
export declare namespace SendblueAPI {
|
|
861
913
|
export type RequestOptions = Opts.RequestOptions;
|
|
@@ -869,6 +921,7 @@ export declare namespace SendblueAPI {
|
|
|
869
921
|
type MessageListParams as MessageListParams,
|
|
870
922
|
type MessageGetStatusParams as MessageGetStatusParams,
|
|
871
923
|
type MessageSendParams as MessageSendParams,
|
|
924
|
+
type MessageUpdateAppCardParams as MessageUpdateAppCardParams,
|
|
872
925
|
};
|
|
873
926
|
|
|
874
927
|
export {
|
|
@@ -934,5 +987,35 @@ export declare namespace SendblueAPI {
|
|
|
934
987
|
|
|
935
988
|
export { V2 as V2 };
|
|
936
989
|
|
|
937
|
-
export { Lines as Lines };
|
|
990
|
+
export { Lines as Lines, type LineState as LineState, type LineGetStateResponse as LineGetStateResponse };
|
|
991
|
+
|
|
992
|
+
export {
|
|
993
|
+
RequestLocation as RequestLocation,
|
|
994
|
+
type RequestLocationCreateResponse as RequestLocationCreateResponse,
|
|
995
|
+
type RequestLocationCreateParams as RequestLocationCreateParams,
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
export {
|
|
999
|
+
Location as Location,
|
|
1000
|
+
type LocationRetrieveResponse as LocationRetrieveResponse,
|
|
1001
|
+
type LocationListResponse as LocationListResponse,
|
|
1002
|
+
type LocationWatchResponse as LocationWatchResponse,
|
|
1003
|
+
type LocationRetrieveParams as LocationRetrieveParams,
|
|
1004
|
+
type LocationListParams as LocationListParams,
|
|
1005
|
+
type LocationWatchParams as LocationWatchParams,
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
export {
|
|
1009
|
+
VerifiedContacts as VerifiedContacts,
|
|
1010
|
+
type VerifiedContactCreateResponse as VerifiedContactCreateResponse,
|
|
1011
|
+
type VerifiedContactRetrieveResponse as VerifiedContactRetrieveResponse,
|
|
1012
|
+
type VerifiedContactListResponse as VerifiedContactListResponse,
|
|
1013
|
+
type VerifiedContactCreateParams as VerifiedContactCreateParams,
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
export { Auth as Auth };
|
|
1017
|
+
|
|
1018
|
+
export { Events as Events, type AccountEvent as AccountEvent, type EventStreamParams as EventStreamParams };
|
|
1019
|
+
|
|
1020
|
+
export { Verify as Verify };
|
|
938
1021
|
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { SendblueAPIError } from './error';
|
|
2
|
+
import { type ReadableStream } from '../internal/shim-types';
|
|
3
|
+
import { makeReadableStream } from '../internal/shims';
|
|
4
|
+
import { findDoubleNewlineIndex, LineDecoder } from '../internal/decoders/line';
|
|
5
|
+
import { ReadableStreamToAsyncIterable } from '../internal/shims';
|
|
6
|
+
import { isAbortError } from '../internal/errors';
|
|
7
|
+
import { encodeUTF8 } from '../internal/utils/bytes';
|
|
8
|
+
import { loggerFor } from '../internal/utils/log';
|
|
9
|
+
import type { SendblueAPI } from '../client';
|
|
10
|
+
|
|
11
|
+
type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;
|
|
12
|
+
|
|
13
|
+
export type ServerSentEvent = {
|
|
14
|
+
event: string | null;
|
|
15
|
+
data: string;
|
|
16
|
+
raw: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export class Stream<Item> implements AsyncIterable<Item> {
|
|
20
|
+
controller: AbortController;
|
|
21
|
+
#client: SendblueAPI | undefined;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
private iterator: () => AsyncIterator<Item>,
|
|
25
|
+
controller: AbortController,
|
|
26
|
+
client?: SendblueAPI,
|
|
27
|
+
) {
|
|
28
|
+
this.controller = controller;
|
|
29
|
+
this.#client = client;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static fromSSEResponse<Item>(
|
|
33
|
+
response: Response,
|
|
34
|
+
controller: AbortController,
|
|
35
|
+
client?: SendblueAPI,
|
|
36
|
+
): Stream<Item> {
|
|
37
|
+
let consumed = false;
|
|
38
|
+
const logger = client ? loggerFor(client) : console;
|
|
39
|
+
|
|
40
|
+
async function* iterator(): AsyncIterator<Item, any, undefined> {
|
|
41
|
+
if (consumed) {
|
|
42
|
+
throw new SendblueAPIError(
|
|
43
|
+
'Cannot iterate over a consumed stream, use `.tee()` to split the stream.',
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
consumed = true;
|
|
47
|
+
let done = false;
|
|
48
|
+
try {
|
|
49
|
+
for await (const sse of _iterSSEMessages(response, controller)) {
|
|
50
|
+
try {
|
|
51
|
+
yield JSON.parse(sse.data) as Item;
|
|
52
|
+
} catch (e) {
|
|
53
|
+
logger.error(`Could not parse message into JSON:`, sse.data);
|
|
54
|
+
logger.error(`From chunk:`, sse.raw);
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
done = true;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
61
|
+
if (isAbortError(e)) return;
|
|
62
|
+
throw e;
|
|
63
|
+
} finally {
|
|
64
|
+
// If the user `break`s, abort the ongoing request.
|
|
65
|
+
if (!done) controller.abort();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return new Stream(iterator, controller, client);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generates a Stream from a newline-separated ReadableStream
|
|
74
|
+
* where each item is a JSON value.
|
|
75
|
+
*/
|
|
76
|
+
static fromReadableStream<Item>(
|
|
77
|
+
readableStream: ReadableStream,
|
|
78
|
+
controller: AbortController,
|
|
79
|
+
client?: SendblueAPI,
|
|
80
|
+
): Stream<Item> {
|
|
81
|
+
let consumed = false;
|
|
82
|
+
|
|
83
|
+
async function* iterLines(): AsyncGenerator<string, void, unknown> {
|
|
84
|
+
const lineDecoder = new LineDecoder();
|
|
85
|
+
|
|
86
|
+
const iter = ReadableStreamToAsyncIterable<Bytes>(readableStream);
|
|
87
|
+
for await (const chunk of iter) {
|
|
88
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
89
|
+
yield line;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const line of lineDecoder.flush()) {
|
|
94
|
+
yield line;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function* iterator(): AsyncIterator<Item, any, undefined> {
|
|
99
|
+
if (consumed) {
|
|
100
|
+
throw new SendblueAPIError(
|
|
101
|
+
'Cannot iterate over a consumed stream, use `.tee()` to split the stream.',
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
consumed = true;
|
|
105
|
+
let done = false;
|
|
106
|
+
try {
|
|
107
|
+
for await (const line of iterLines()) {
|
|
108
|
+
if (done) continue;
|
|
109
|
+
if (line) yield JSON.parse(line) as Item;
|
|
110
|
+
}
|
|
111
|
+
done = true;
|
|
112
|
+
} catch (e) {
|
|
113
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
114
|
+
if (isAbortError(e)) return;
|
|
115
|
+
throw e;
|
|
116
|
+
} finally {
|
|
117
|
+
// If the user `break`s, abort the ongoing request.
|
|
118
|
+
if (!done) controller.abort();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return new Stream(iterator, controller, client);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
[Symbol.asyncIterator](): AsyncIterator<Item> {
|
|
126
|
+
return this.iterator();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Splits the stream into two streams which can be
|
|
131
|
+
* independently read from at different speeds.
|
|
132
|
+
*/
|
|
133
|
+
tee(): [Stream<Item>, Stream<Item>] {
|
|
134
|
+
const left: Array<Promise<IteratorResult<Item>>> = [];
|
|
135
|
+
const right: Array<Promise<IteratorResult<Item>>> = [];
|
|
136
|
+
const iterator = this.iterator();
|
|
137
|
+
|
|
138
|
+
const teeIterator = (queue: Array<Promise<IteratorResult<Item>>>): AsyncIterator<Item> => {
|
|
139
|
+
return {
|
|
140
|
+
next: () => {
|
|
141
|
+
if (queue.length === 0) {
|
|
142
|
+
const result = iterator.next();
|
|
143
|
+
left.push(result);
|
|
144
|
+
right.push(result);
|
|
145
|
+
}
|
|
146
|
+
return queue.shift()!;
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return [
|
|
152
|
+
new Stream(() => teeIterator(left), this.controller, this.#client),
|
|
153
|
+
new Stream(() => teeIterator(right), this.controller, this.#client),
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Converts this stream to a newline-separated ReadableStream of
|
|
159
|
+
* JSON stringified values in the stream
|
|
160
|
+
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
|
|
161
|
+
*/
|
|
162
|
+
toReadableStream(): ReadableStream {
|
|
163
|
+
const self = this;
|
|
164
|
+
let iter: AsyncIterator<Item>;
|
|
165
|
+
|
|
166
|
+
return makeReadableStream({
|
|
167
|
+
async start() {
|
|
168
|
+
iter = self[Symbol.asyncIterator]();
|
|
169
|
+
},
|
|
170
|
+
async pull(ctrl: any) {
|
|
171
|
+
try {
|
|
172
|
+
const { value, done } = await iter.next();
|
|
173
|
+
if (done) return ctrl.close();
|
|
174
|
+
|
|
175
|
+
const bytes = encodeUTF8(JSON.stringify(value) + '\n');
|
|
176
|
+
|
|
177
|
+
ctrl.enqueue(bytes);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
ctrl.error(err);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
async cancel() {
|
|
183
|
+
await iter.return?.();
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export async function* _iterSSEMessages(
|
|
190
|
+
response: Response,
|
|
191
|
+
controller: AbortController,
|
|
192
|
+
): AsyncGenerator<ServerSentEvent, void, unknown> {
|
|
193
|
+
if (!response.body) {
|
|
194
|
+
controller.abort();
|
|
195
|
+
if (
|
|
196
|
+
typeof (globalThis as any).navigator !== 'undefined' &&
|
|
197
|
+
(globalThis as any).navigator.product === 'ReactNative'
|
|
198
|
+
) {
|
|
199
|
+
throw new SendblueAPIError(
|
|
200
|
+
`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
throw new SendblueAPIError(`Attempted to iterate over a response with no body`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const sseDecoder = new SSEDecoder();
|
|
207
|
+
const lineDecoder = new LineDecoder();
|
|
208
|
+
|
|
209
|
+
const iter = ReadableStreamToAsyncIterable<Bytes>(response.body);
|
|
210
|
+
for await (const sseChunk of iterSSEChunks(iter)) {
|
|
211
|
+
for (const line of lineDecoder.decode(sseChunk)) {
|
|
212
|
+
const sse = sseDecoder.decode(line);
|
|
213
|
+
if (sse) yield sse;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
for (const line of lineDecoder.flush()) {
|
|
218
|
+
const sse = sseDecoder.decode(line);
|
|
219
|
+
if (sse) yield sse;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Given an async iterable iterator, iterates over it and yields full
|
|
225
|
+
* SSE chunks, i.e. yields when a double new-line is encountered.
|
|
226
|
+
*/
|
|
227
|
+
async function* iterSSEChunks(iterator: AsyncIterableIterator<Bytes>): AsyncGenerator<Uint8Array> {
|
|
228
|
+
let data = new Uint8Array();
|
|
229
|
+
|
|
230
|
+
for await (const chunk of iterator) {
|
|
231
|
+
if (chunk == null) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const binaryChunk =
|
|
236
|
+
chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
|
237
|
+
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
|
238
|
+
: chunk;
|
|
239
|
+
|
|
240
|
+
let newData = new Uint8Array(data.length + binaryChunk.length);
|
|
241
|
+
newData.set(data);
|
|
242
|
+
newData.set(binaryChunk, data.length);
|
|
243
|
+
data = newData;
|
|
244
|
+
|
|
245
|
+
let patternIndex;
|
|
246
|
+
while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {
|
|
247
|
+
yield data.slice(0, patternIndex);
|
|
248
|
+
data = data.slice(patternIndex);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (data.length > 0) {
|
|
253
|
+
yield data;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
class SSEDecoder {
|
|
258
|
+
private data: string[];
|
|
259
|
+
private event: string | null;
|
|
260
|
+
private chunks: string[];
|
|
261
|
+
|
|
262
|
+
constructor() {
|
|
263
|
+
this.event = null;
|
|
264
|
+
this.data = [];
|
|
265
|
+
this.chunks = [];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
decode(line: string) {
|
|
269
|
+
if (line.endsWith('\r')) {
|
|
270
|
+
line = line.substring(0, line.length - 1);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (!line) {
|
|
274
|
+
// empty line and we didn't previously encounter any messages
|
|
275
|
+
if (!this.event && !this.data.length) return null;
|
|
276
|
+
|
|
277
|
+
const sse: ServerSentEvent = {
|
|
278
|
+
event: this.event,
|
|
279
|
+
data: this.data.join('\n'),
|
|
280
|
+
raw: this.chunks,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
this.event = null;
|
|
284
|
+
this.data = [];
|
|
285
|
+
this.chunks = [];
|
|
286
|
+
|
|
287
|
+
return sse;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
this.chunks.push(line);
|
|
291
|
+
|
|
292
|
+
if (line.startsWith(':')) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let [fieldname, _, value] = partition(line, ':');
|
|
297
|
+
|
|
298
|
+
if (value.startsWith(' ')) {
|
|
299
|
+
value = value.substring(1);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (fieldname === 'event') {
|
|
303
|
+
this.event = value;
|
|
304
|
+
} else if (fieldname === 'data') {
|
|
305
|
+
this.data.push(value);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function partition(str: string, delimiter: string): [string, string, string] {
|
|
313
|
+
const index = str.indexOf(delimiter);
|
|
314
|
+
if (index !== -1) {
|
|
315
|
+
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return [str, '', ''];
|
|
319
|
+
}
|