ab-ecosystem-cpass 0.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/README.md +88 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.js +46 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +30 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +30 -0
- package/dist/http.js +62 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/channels.d.ts +10 -0
- package/dist/resources/channels.js +19 -0
- package/dist/resources/channels.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# CRM SDK
|
|
2
|
+
|
|
3
|
+
JavaScript/TypeScript client for the CRM gateway.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install ab-ecosystem-cpass
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { CrmClient } from 'ab-ecosystem-cpass';
|
|
15
|
+
|
|
16
|
+
const crm = new CrmClient({
|
|
17
|
+
gatewayUrl: 'https://api.example.com',
|
|
18
|
+
clientId: 'tpc_xxxxxxxxxxxxxxxx',
|
|
19
|
+
authToken: '<ecosystem bearer token>',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const { data, nextCursor } = await crm.channels.list({ limit: 20 });
|
|
23
|
+
const channel = await crm.channels.get('64ba85075f89cb9bbe30d749');
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Every request carries `authorization: Bearer <authToken>`, `client-id` and `origin`.
|
|
27
|
+
|
|
28
|
+
| Option | Required | Description |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| `gatewayUrl` | yes | Base URL of the gateway. |
|
|
31
|
+
| `clientId` | yes | Sent as the `client-id` header. |
|
|
32
|
+
| `authToken` | yes | String, or a function returning one per request. |
|
|
33
|
+
| `origin` | on Node | Sent as the `origin` header. Browsers set this themselves; on Node the gateway rejects the call without it. |
|
|
34
|
+
| `fetch` | no | Custom fetch implementation. |
|
|
35
|
+
| `timeoutMs` | no | Request timeout, default 30000. |
|
|
36
|
+
|
|
37
|
+
### Node
|
|
38
|
+
|
|
39
|
+
Browsers attach `Origin` automatically and ignore any override, so `origin` only
|
|
40
|
+
needs setting outside the browser:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const crm = new CrmClient({
|
|
44
|
+
gatewayUrl: 'https://api.example.com',
|
|
45
|
+
clientId: 'tpc_xxxxxxxxxxxxxxxx',
|
|
46
|
+
authToken: process.env.CRM_TOKEN!,
|
|
47
|
+
origin: 'https://app.example.com', // must match the token's referer claim
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Refreshing tokens
|
|
52
|
+
|
|
53
|
+
Pass a function to resolve the token per request:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const crm = new CrmClient({
|
|
57
|
+
gatewayUrl: 'https://api.example.com',
|
|
58
|
+
clientId: 'tpc_xxxxxxxxxxxxxxxx',
|
|
59
|
+
authToken: () => auth.getAccessToken(),
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Errors
|
|
64
|
+
|
|
65
|
+
| Error | When |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `CrmConfigError` | Thrown client-side, before any request, when `gatewayUrl`, `clientId` or `authToken` is missing or empty. |
|
|
68
|
+
| `CrmApiError` | The gateway returned a non-2xx status. Carries `status`, `code`, `message` and `details`. |
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { CrmApiError, CrmConfigError } from 'ab-ecosystem-cpass';
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
await crm.channels.list();
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (err instanceof CrmConfigError) console.error('bad SDK setup:', err.message);
|
|
77
|
+
else if (err instanceof CrmApiError) console.error(err.status, err.code, err.message);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API
|
|
82
|
+
|
|
83
|
+
Only the channel module ships in this release.
|
|
84
|
+
|
|
85
|
+
| Method | Endpoint |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `crm.channels.list(query?)` | `GET /v1/channels` |
|
|
88
|
+
| `crm.channels.get(id)` | `GET /v1/channels/:id` |
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrmClient = void 0;
|
|
4
|
+
const http_1 = require("./http");
|
|
5
|
+
const channels_1 = require("./resources/channels");
|
|
6
|
+
// Only the channel module ships in the MVP. The rest stay commented out until
|
|
7
|
+
// their services are live behind the gateway.
|
|
8
|
+
// import { Contacts } from './resources/contacts';
|
|
9
|
+
// import { CustomFields } from './resources/custom-fields';
|
|
10
|
+
// import { Segments } from './resources/segments';
|
|
11
|
+
// import { CrmTriggers } from './resources/crm-triggers';
|
|
12
|
+
// import { ContactImports } from './resources/contact-imports';
|
|
13
|
+
// import { ContactExports } from './resources/contact-exports';
|
|
14
|
+
// import { Webhooks } from './resources/webhooks';
|
|
15
|
+
// import { Campaigns } from './resources/campaigns';
|
|
16
|
+
// import { CampaignReports } from './resources/campaign-reports';
|
|
17
|
+
// import { CampaignReportExports } from './resources/campaign-report-exports';
|
|
18
|
+
class CrmClient {
|
|
19
|
+
channels;
|
|
20
|
+
// readonly contacts: Contacts;
|
|
21
|
+
// readonly customFields: CustomFields;
|
|
22
|
+
// readonly segments: Segments;
|
|
23
|
+
// readonly crmTriggers: CrmTriggers;
|
|
24
|
+
// readonly contactImports: ContactImports;
|
|
25
|
+
// readonly contactExports: ContactExports;
|
|
26
|
+
// readonly webhooks: Webhooks;
|
|
27
|
+
// readonly campaigns: Campaigns;
|
|
28
|
+
// readonly campaignReports: CampaignReports;
|
|
29
|
+
// readonly campaignReportExports: CampaignReportExports;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
const http = new http_1.HttpClient(options);
|
|
32
|
+
this.channels = new channels_1.Channels(http);
|
|
33
|
+
// this.contacts = new Contacts(http);
|
|
34
|
+
// this.customFields = new CustomFields(http);
|
|
35
|
+
// this.segments = new Segments(http);
|
|
36
|
+
// this.crmTriggers = new CrmTriggers(http);
|
|
37
|
+
// this.contactImports = new ContactImports(http);
|
|
38
|
+
// this.contactExports = new ContactExports(http);
|
|
39
|
+
// this.webhooks = new Webhooks(http);
|
|
40
|
+
// this.campaigns = new Campaigns(http);
|
|
41
|
+
// this.campaignReports = new CampaignReports(http);
|
|
42
|
+
// this.campaignReportExports = new CampaignReportExports(http);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.CrmClient = CrmClient;
|
|
46
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,iCAAwD;AACxD,mDAAgD;AAEhD,8EAA8E;AAC9E,8CAA8C;AAC9C,mDAAmD;AACnD,4DAA4D;AAC5D,mDAAmD;AACnD,0DAA0D;AAC1D,gEAAgE;AAChE,gEAAgE;AAChE,mDAAmD;AACnD,qDAAqD;AACrD,kEAAkE;AAClE,+EAA+E;AAE/E,MAAa,SAAS;IACX,QAAQ,CAAW;IAE5B,+BAA+B;IAC/B,uCAAuC;IACvC,+BAA+B;IAC/B,qCAAqC;IACrC,2CAA2C;IAC3C,2CAA2C;IAC3C,+BAA+B;IAC/B,iCAAiC;IACjC,6CAA6C;IAC7C,yDAAyD;IAEzD,YAAY,OAAsB;QAChC,MAAM,IAAI,GAAG,IAAI,iBAAU,CAAC,OAAO,CAAC,CAAC;QAErC,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;QAEnC,sCAAsC;QACtC,8CAA8C;QAC9C,sCAAsC;QACtC,4CAA4C;QAC5C,kDAAkD;QAClD,kDAAkD;QAClD,sCAAsC;QACtC,wCAAwC;QACxC,oDAAoD;QACpD,gEAAgE;IAClE,CAAC;CACF;AA9BD,8BA8BC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Thrown before a request leaves the client, for invalid or missing configuration. */
|
|
2
|
+
export declare class CrmConfigError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
/** Thrown when the gateway responds with a non-2xx status. */
|
|
6
|
+
export declare class CrmApiError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly details?: unknown | undefined;
|
|
10
|
+
constructor(status: number, code: string, message: string, details?: unknown | undefined);
|
|
11
|
+
static fromResponse(response: Response): Promise<CrmApiError>;
|
|
12
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrmApiError = exports.CrmConfigError = void 0;
|
|
4
|
+
/** Thrown before a request leaves the client, for invalid or missing configuration. */
|
|
5
|
+
class CrmConfigError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'CrmConfigError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.CrmConfigError = CrmConfigError;
|
|
12
|
+
/** Thrown when the gateway responds with a non-2xx status. */
|
|
13
|
+
class CrmApiError extends Error {
|
|
14
|
+
status;
|
|
15
|
+
code;
|
|
16
|
+
details;
|
|
17
|
+
constructor(status, code, message, details) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.details = details;
|
|
22
|
+
this.name = 'CrmApiError';
|
|
23
|
+
}
|
|
24
|
+
static async fromResponse(response) {
|
|
25
|
+
const body = (await response.json().catch(() => ({})));
|
|
26
|
+
return new CrmApiError(response.status, body.error?.code ?? 'unknown_error', body.error?.message ?? response.statusText, body.error?.details);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.CrmApiError = CrmApiError;
|
|
30
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,uFAAuF;AACvF,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAED,8DAA8D;AAC9D,MAAa,WAAY,SAAQ,KAAK;IAEzB;IACA;IAEA;IAJX,YACW,MAAc,EACd,IAAY,EACrB,OAAe,EACN,OAAiB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,QAAkB;QAC1C,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAEpD,CAAC;QAEF,OAAO,IAAI,WAAW,CACpB,QAAQ,CAAC,MAAM,EACf,IAAI,CAAC,KAAK,EAAE,IAAI,IAAI,eAAe,EACnC,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,QAAQ,CAAC,UAAU,EAC1C,IAAI,CAAC,KAAK,EAAE,OAAO,CACpB,CAAC;IACJ,CAAC;CACF;AAvBD,kCAuBC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ClientOptions {
|
|
2
|
+
/** Base URL of the CRM gateway, e.g. `https://api.example.com`. */
|
|
3
|
+
gatewayUrl: string;
|
|
4
|
+
/** Ecosystem client id; sent as the `client-id` header on every call. */
|
|
5
|
+
clientId: string;
|
|
6
|
+
/** Ecosystem bearer token, or a function resolving one per request. */
|
|
7
|
+
authToken: string | (() => string | Promise<string>);
|
|
8
|
+
/**
|
|
9
|
+
* Value for the `origin` header. Browsers set this themselves and ignore any
|
|
10
|
+
* override, so it is only needed on Node — where the gateway rejects the call
|
|
11
|
+
* without it. Defaults to the page origin when running in a browser.
|
|
12
|
+
*/
|
|
13
|
+
origin?: string;
|
|
14
|
+
/** Custom fetch implementation; defaults to the global one. */
|
|
15
|
+
fetch?: typeof fetch;
|
|
16
|
+
/** Request timeout in milliseconds. Defaults to 30s. */
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface RequestInitOptions {
|
|
20
|
+
body?: unknown;
|
|
21
|
+
query?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export declare class HttpClient {
|
|
24
|
+
private readonly options;
|
|
25
|
+
private readonly gatewayUrl;
|
|
26
|
+
constructor(options: ClientOptions);
|
|
27
|
+
/** Resolves the bearer token, failing here rather than sending an unauthenticated call. */
|
|
28
|
+
private token;
|
|
29
|
+
request<T>(method: string, path: string, init?: RequestInitOptions): Promise<T>;
|
|
30
|
+
}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const browserOrigin = () => typeof globalThis !== 'undefined' &&
|
|
6
|
+
typeof globalThis.location?.origin === 'string'
|
|
7
|
+
? globalThis.location.origin
|
|
8
|
+
: undefined;
|
|
9
|
+
class HttpClient {
|
|
10
|
+
options;
|
|
11
|
+
gatewayUrl;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
if (!options?.gatewayUrl?.trim())
|
|
15
|
+
throw new errors_1.CrmConfigError('gatewayUrl is required');
|
|
16
|
+
if (!options.clientId?.trim())
|
|
17
|
+
throw new errors_1.CrmConfigError('clientId is required');
|
|
18
|
+
if (typeof options.authToken === 'string' && !options.authToken.trim()) {
|
|
19
|
+
throw new errors_1.CrmConfigError('authToken is required');
|
|
20
|
+
}
|
|
21
|
+
if (options.authToken === undefined || options.authToken === null) {
|
|
22
|
+
throw new errors_1.CrmConfigError('authToken is required');
|
|
23
|
+
}
|
|
24
|
+
this.gatewayUrl = options.gatewayUrl.trim().replace(/\/+$/, '');
|
|
25
|
+
}
|
|
26
|
+
/** Resolves the bearer token, failing here rather than sending an unauthenticated call. */
|
|
27
|
+
async token() {
|
|
28
|
+
const token = typeof this.options.authToken === 'function'
|
|
29
|
+
? await this.options.authToken()
|
|
30
|
+
: this.options.authToken;
|
|
31
|
+
if (typeof token !== 'string' || !token.trim()) {
|
|
32
|
+
throw new errors_1.CrmConfigError('authToken is required');
|
|
33
|
+
}
|
|
34
|
+
return token.trim();
|
|
35
|
+
}
|
|
36
|
+
async request(method, path, init = {}) {
|
|
37
|
+
const token = await this.token();
|
|
38
|
+
const url = new URL(`${this.gatewayUrl}${path}`);
|
|
39
|
+
for (const [key, value] of Object.entries(init.query ?? {})) {
|
|
40
|
+
if (value !== undefined && value !== null)
|
|
41
|
+
url.searchParams.set(key, String(value));
|
|
42
|
+
}
|
|
43
|
+
const origin = this.options.origin ?? browserOrigin();
|
|
44
|
+
const send = this.options.fetch ?? fetch;
|
|
45
|
+
const response = await send(url.toString(), {
|
|
46
|
+
method,
|
|
47
|
+
headers: {
|
|
48
|
+
'content-type': 'application/json',
|
|
49
|
+
authorization: `Bearer ${token}`,
|
|
50
|
+
'client-id': this.options.clientId.trim(),
|
|
51
|
+
...(origin ? { origin } : {}),
|
|
52
|
+
},
|
|
53
|
+
body: init.body === undefined ? undefined : JSON.stringify(init.body),
|
|
54
|
+
signal: AbortSignal.timeout(this.options.timeoutMs ?? 30_000),
|
|
55
|
+
});
|
|
56
|
+
if (!response.ok)
|
|
57
|
+
throw await errors_1.CrmApiError.fromResponse(response);
|
|
58
|
+
return (response.status === 204 ? undefined : await response.json());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.HttpClient = HttpClient;
|
|
62
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
exports.Channels = void 0;
|
|
18
|
+
__exportStar(require("./client"), exports);
|
|
19
|
+
__exportStar(require("./http"), exports);
|
|
20
|
+
__exportStar(require("./errors"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
var channels_1 = require("./resources/channels");
|
|
23
|
+
Object.defineProperty(exports, "Channels", { enumerable: true, get: function () { return channels_1.Channels; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,yCAAuB;AACvB,2CAAyB;AACzB,0CAAwB;AACxB,iDAAgD;AAAvC,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Channel, ChannelResponse, Page, PageQuery } from '../types';
|
|
2
|
+
import type { HttpClient } from '../http';
|
|
3
|
+
export declare class Channels {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
/** `GET /v1/channels` */
|
|
7
|
+
list(query?: Partial<PageQuery>): Promise<Page<Channel>>;
|
|
8
|
+
/** `GET /v1/channels/:id` */
|
|
9
|
+
get(id: string): Promise<ChannelResponse>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Channels = void 0;
|
|
4
|
+
class Channels {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/** `GET /v1/channels` */
|
|
10
|
+
list(query = {}) {
|
|
11
|
+
return this.http.request('GET', '/v1/channels', { query });
|
|
12
|
+
}
|
|
13
|
+
/** `GET /v1/channels/:id` */
|
|
14
|
+
get(id) {
|
|
15
|
+
return this.http.request('GET', `/v1/channels/${encodeURIComponent(id)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Channels = Channels;
|
|
19
|
+
//# sourceMappingURL=channels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channels.js","sourceRoot":"","sources":["../../src/resources/channels.ts"],"names":[],"mappings":";;;AAGA,MAAa,QAAQ;IACU;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,yBAAyB;IACzB,IAAI,CAAC,QAA4B,EAAE;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAgB,KAAK,EAAE,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,6BAA6B;IAC7B,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAkB,KAAK,EAAE,gBAAgB,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7F,CAAC;CAsBF;AAjCD,4BAiCC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response shapes returned by the gateway. Declared here rather than imported
|
|
3
|
+
* from `@crm/contracts` so the published package has no private dependencies.
|
|
4
|
+
*/
|
|
5
|
+
export interface Page<T> {
|
|
6
|
+
data: T[];
|
|
7
|
+
nextCursor: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface PageQuery {
|
|
10
|
+
limit: number;
|
|
11
|
+
cursor?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ChannelMeta {
|
|
14
|
+
category: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
support_template: boolean;
|
|
17
|
+
show_template: boolean;
|
|
18
|
+
bypass_webhook_verification: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ChannelCloud {
|
|
21
|
+
instagram_id: string;
|
|
22
|
+
is_instagram_business_login: boolean;
|
|
23
|
+
waba_id: string;
|
|
24
|
+
business: string;
|
|
25
|
+
phone_number_id: string;
|
|
26
|
+
is_on_biz_app: boolean;
|
|
27
|
+
version: string;
|
|
28
|
+
auto_read_receipt: number;
|
|
29
|
+
upgrade_eligibility: boolean;
|
|
30
|
+
wa_biz_registration: 'pending' | 'completed';
|
|
31
|
+
}
|
|
32
|
+
export interface ChannelWallet {
|
|
33
|
+
free_tier?: number;
|
|
34
|
+
free_usage?: number;
|
|
35
|
+
/** `'NULL'` when the wallet is not visible to the caller. */
|
|
36
|
+
balance: number | 'NULL';
|
|
37
|
+
visible?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface Channel {
|
|
40
|
+
id: string;
|
|
41
|
+
active: boolean;
|
|
42
|
+
ecom?: {
|
|
43
|
+
store_status: boolean;
|
|
44
|
+
store?: string;
|
|
45
|
+
};
|
|
46
|
+
basic_details: {
|
|
47
|
+
name: string;
|
|
48
|
+
color_code: string;
|
|
49
|
+
channel_identity: string;
|
|
50
|
+
};
|
|
51
|
+
meta: ChannelMeta;
|
|
52
|
+
billing: {
|
|
53
|
+
status: boolean;
|
|
54
|
+
currency: string;
|
|
55
|
+
visible: boolean;
|
|
56
|
+
};
|
|
57
|
+
wallet: ChannelWallet;
|
|
58
|
+
campaign_tps: number;
|
|
59
|
+
upgraded_webhook_listener: boolean;
|
|
60
|
+
cloud: ChannelCloud;
|
|
61
|
+
api_only: boolean;
|
|
62
|
+
crm_only: boolean;
|
|
63
|
+
mm_lite_enabled: boolean;
|
|
64
|
+
access_token: string;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
/** `GET /v1/channels/:id` wraps its payload, and returns `{}` when nothing matches. */
|
|
68
|
+
export interface ChannelResponse {
|
|
69
|
+
data: Channel | Record<string, never>;
|
|
70
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Response shapes returned by the gateway. Declared here rather than imported
|
|
4
|
+
* from `@crm/contracts` so the published package has no private dependencies.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ab-ecosystem-cpass",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript/TypeScript SDK for the CPaaS CRM gateway",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"crm",
|
|
18
|
+
"cpaas",
|
|
19
|
+
"sdk",
|
|
20
|
+
"channels"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -b",
|
|
27
|
+
"prepublishOnly": "tsc -b"
|
|
28
|
+
}
|
|
29
|
+
}
|