@skyporch/daykeeper-react-native 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/CHANGELOG.md +12 -0
- package/COMPATIBILITY.md +21 -0
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/index.cjs +381 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +682 -0
- package/dist/index.d.ts +682 -0
- package/dist/index.js +353 -0
- package/dist/index.js.map +1 -0
- package/package.json +95 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Add typed customer identity, conversation, message, unread, and seen APIs.
|
|
6
|
+
- Add safe anonymous-thread claiming after sign-in.
|
|
7
|
+
- Support both streaming Fetch responses and React Native's buffered
|
|
8
|
+
`Response.text()` behavior with bounded UTF-8 response validation.
|
|
9
|
+
- Add explicit React Native package exports, rotating tokens, request timeouts,
|
|
10
|
+
and stable customer-safe errors.
|
|
11
|
+
- Preserve reverse-proxy path prefixes and retry exactly once with a forced
|
|
12
|
+
token refresh after an HTTP 401 response.
|
package/COMPATIBILITY.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# React Native compatibility
|
|
2
|
+
|
|
3
|
+
The initial supported target is Expo 57 with React Native 0.86 and Hermes. The
|
|
4
|
+
package declares React Native 0.79 or newer because Metro enables package
|
|
5
|
+
exports by default from that line onward. Releases must be smoke-tested through
|
|
6
|
+
Metro on both iOS and Android before this matrix is expanded.
|
|
7
|
+
|
|
8
|
+
The client depends only on the React Native web-compatible globals `fetch`,
|
|
9
|
+
`Headers`, `URL`, and `AbortController`. It handles both standards-based
|
|
10
|
+
streaming responses and React Native's buffered `Response.text()` response. A
|
|
11
|
+
custom `fetch` implementation must preserve those request and response
|
|
12
|
+
semantics.
|
|
13
|
+
|
|
14
|
+
Version 0.1 is headless and ships no native module. It does not yet provide a
|
|
15
|
+
messenger UI, push-notification registration, attachment selection/upload,
|
|
16
|
+
deep-link routing, persistent offline queues, or background delivery. Consumers
|
|
17
|
+
own those surfaces until they are added here behind reviewed native interfaces.
|
|
18
|
+
|
|
19
|
+
Tokens must be short-lived and customer-scoped. Keep them in memory where
|
|
20
|
+
possible; if persistence is unavoidable, use an OS-backed secret store and
|
|
21
|
+
never AsyncStorage.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SkyPorch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# `@skyporch/daykeeper-react-native`
|
|
2
|
+
|
|
3
|
+
The official headless React Native client for customer-facing Daykeeper support
|
|
4
|
+
experiences. It is generated from the Daykeeper customer API contract and is
|
|
5
|
+
designed for Expo and bare React Native applications on iOS and Android.
|
|
6
|
+
|
|
7
|
+
This package contains no native module and no embedded support UI. It provides
|
|
8
|
+
typed identity, conversation, message, unread, seen, and anonymous-claim APIs.
|
|
9
|
+
Push notifications, attachments, deep links, and native UI can be added here
|
|
10
|
+
without coupling consuming applications to Daykeeper's private platform or to
|
|
11
|
+
Chatwoot.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @skyporch/daykeeper-react-native
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createDaykeeperReactNativeClient } from "@skyporch/daykeeper-react-native";
|
|
23
|
+
|
|
24
|
+
const daykeeper = createDaykeeperReactNativeClient({
|
|
25
|
+
baseUrl: "https://support.example.com/support-api",
|
|
26
|
+
getAccessToken: async ({ forceRefresh }) => {
|
|
27
|
+
// Exchange the signed-in app session for a short-lived, customer-scoped
|
|
28
|
+
// Daykeeper token using your own backend. Bypass any local token cache when
|
|
29
|
+
// forceRefresh is true.
|
|
30
|
+
return getDaykeeperCustomerToken({ forceRefresh });
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const { conversations } = await daykeeper.listConversations();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The token provider runs for every request so the consuming app can rotate
|
|
38
|
+
short-lived credentials. If the gateway returns HTTP 401, the SDK asks the
|
|
39
|
+
provider for one forced refresh and retries exactly once. Keep customer tokens
|
|
40
|
+
in memory where possible. Never place them in URLs, analytics, crash reports,
|
|
41
|
+
or application logs.
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
- `getIdentity()`
|
|
46
|
+
- `listConversations()` and `createConversation()`
|
|
47
|
+
- `listMessages()` and `sendMessage()`
|
|
48
|
+
- `getUnread()` and `markConversationSeen()`
|
|
49
|
+
- `claimAnonymousConversation()`
|
|
50
|
+
|
|
51
|
+
See [`COMPATIBILITY.md`](COMPATIBILITY.md) for the supported runtime contract
|
|
52
|
+
and release certification matrix.
|
|
53
|
+
|
|
54
|
+
## Release status
|
|
55
|
+
|
|
56
|
+
Version `0.1.0` is generated from the customer contract recorded in
|
|
57
|
+
[`openapi/SOURCE.md`](openapi/SOURCE.md). Releases use the protected,
|
|
58
|
+
provenance-producing process in [`RELEASING.md`](RELEASING.md).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
25
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
26
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
27
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
28
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
DaykeeperReactNativeApiError: () => DaykeeperReactNativeApiError,
|
|
34
|
+
DaykeeperReactNativeClient: () => DaykeeperReactNativeClient,
|
|
35
|
+
DaykeeperReactNativeTransportError: () => DaykeeperReactNativeTransportError,
|
|
36
|
+
createDaykeeperReactNativeClient: () => createDaykeeperReactNativeClient
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
|
|
40
|
+
// src/errors.ts
|
|
41
|
+
var DaykeeperReactNativeApiError = class extends Error {
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super(options.code);
|
|
44
|
+
__publicField(this, "status");
|
|
45
|
+
__publicField(this, "code");
|
|
46
|
+
__publicField(this, "retryable");
|
|
47
|
+
this.name = "DaykeeperReactNativeApiError";
|
|
48
|
+
this.status = options.status;
|
|
49
|
+
this.code = options.code;
|
|
50
|
+
this.retryable = options.retryable;
|
|
51
|
+
}
|
|
52
|
+
toJSON() {
|
|
53
|
+
return {
|
|
54
|
+
name: this.name,
|
|
55
|
+
status: this.status,
|
|
56
|
+
code: this.code,
|
|
57
|
+
retryable: this.retryable
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var DaykeeperReactNativeTransportError = class extends Error {
|
|
62
|
+
constructor(options) {
|
|
63
|
+
super(options.message);
|
|
64
|
+
__publicField(this, "code");
|
|
65
|
+
__publicField(this, "retryable");
|
|
66
|
+
this.name = "DaykeeperReactNativeTransportError";
|
|
67
|
+
this.code = options.code;
|
|
68
|
+
this.retryable = options.retryable ?? false;
|
|
69
|
+
}
|
|
70
|
+
toJSON() {
|
|
71
|
+
return {
|
|
72
|
+
name: this.name,
|
|
73
|
+
code: this.code,
|
|
74
|
+
message: this.message,
|
|
75
|
+
retryable: this.retryable
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/client.ts
|
|
81
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
82
|
+
var MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
83
|
+
var MAX_TOKEN_LENGTH = 16384;
|
|
84
|
+
var MAX_MESSAGE_LENGTH = 16e3;
|
|
85
|
+
var _baseUrl, _fetch, _getAccessToken, _timeoutMs, _DaykeeperReactNativeClient_instances, request_fn;
|
|
86
|
+
var DaykeeperReactNativeClient = class {
|
|
87
|
+
constructor(options) {
|
|
88
|
+
__privateAdd(this, _DaykeeperReactNativeClient_instances);
|
|
89
|
+
__privateAdd(this, _baseUrl);
|
|
90
|
+
__privateAdd(this, _fetch);
|
|
91
|
+
__privateAdd(this, _getAccessToken);
|
|
92
|
+
__privateAdd(this, _timeoutMs);
|
|
93
|
+
__privateSet(this, _baseUrl, parseBaseUrl(options.baseUrl));
|
|
94
|
+
__privateSet(this, _fetch, options.fetch ?? globalThis.fetch);
|
|
95
|
+
if (typeof __privateGet(this, _fetch) !== "function") {
|
|
96
|
+
throw configurationError("A Fetch API implementation is required");
|
|
97
|
+
}
|
|
98
|
+
if (typeof options.getAccessToken !== "function") {
|
|
99
|
+
throw configurationError("getAccessToken must be a function");
|
|
100
|
+
}
|
|
101
|
+
__privateSet(this, _getAccessToken, options.getAccessToken);
|
|
102
|
+
__privateSet(this, _timeoutMs, validateTimeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS));
|
|
103
|
+
}
|
|
104
|
+
getIdentity(options) {
|
|
105
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, "/v1/identity", { signal: options?.signal });
|
|
106
|
+
}
|
|
107
|
+
listConversations(options) {
|
|
108
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, "/v1/conversations", { signal: options?.signal });
|
|
109
|
+
}
|
|
110
|
+
createConversation(options) {
|
|
111
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, "/v1/conversations", {
|
|
112
|
+
method: "POST",
|
|
113
|
+
signal: options?.signal
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getUnread(options) {
|
|
117
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, "/v1/unread", { signal: options?.signal });
|
|
118
|
+
}
|
|
119
|
+
markConversationSeen(conversationId, options) {
|
|
120
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, `/v1/conversations/${positiveInteger(conversationId, "conversationId")}/seen`, { method: "POST", signal: options?.signal });
|
|
121
|
+
}
|
|
122
|
+
listMessages(conversationId, options = {}) {
|
|
123
|
+
const id = positiveInteger(conversationId, "conversationId");
|
|
124
|
+
const after = options.after === void 0 ? "" : `?after=${positiveInteger(options.after, "after")}`;
|
|
125
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, `/v1/conversations/${id}/messages${after}`, {
|
|
126
|
+
signal: options.signal
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
sendMessage(conversationId, content, options) {
|
|
130
|
+
const normalizedContent = validateMessage(content);
|
|
131
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, `/v1/conversations/${positiveInteger(conversationId, "conversationId")}/messages`, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
body: { content: normalizedContent },
|
|
134
|
+
signal: options?.signal
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
claimAnonymousConversation(widgetToken, options) {
|
|
138
|
+
if (typeof widgetToken !== "string" || !widgetToken.trim() || widgetToken.length > MAX_TOKEN_LENGTH) {
|
|
139
|
+
throw configurationError("widgetToken is invalid");
|
|
140
|
+
}
|
|
141
|
+
return __privateMethod(this, _DaykeeperReactNativeClient_instances, request_fn).call(this, "/v1/anonymous-conversations/claim", {
|
|
142
|
+
method: "POST",
|
|
143
|
+
body: { widgetToken: widgetToken.trim() },
|
|
144
|
+
signal: options?.signal
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
_baseUrl = new WeakMap();
|
|
149
|
+
_fetch = new WeakMap();
|
|
150
|
+
_getAccessToken = new WeakMap();
|
|
151
|
+
_timeoutMs = new WeakMap();
|
|
152
|
+
_DaykeeperReactNativeClient_instances = new WeakSet();
|
|
153
|
+
request_fn = async function(path, options = {}) {
|
|
154
|
+
const timeoutController = new AbortController();
|
|
155
|
+
let timedOut = false;
|
|
156
|
+
const timeout = setTimeout(() => {
|
|
157
|
+
timedOut = true;
|
|
158
|
+
timeoutController.abort();
|
|
159
|
+
}, __privateGet(this, _timeoutMs));
|
|
160
|
+
const onCallerAbort = () => timeoutController.abort();
|
|
161
|
+
if (options.signal?.aborted) timeoutController.abort();
|
|
162
|
+
else
|
|
163
|
+
options.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
164
|
+
try {
|
|
165
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
166
|
+
const token = validateToken(
|
|
167
|
+
await __privateGet(this, _getAccessToken).call(this, { forceRefresh: attempt === 1 })
|
|
168
|
+
);
|
|
169
|
+
const headers = new Headers({
|
|
170
|
+
accept: "application/json",
|
|
171
|
+
authorization: `Bearer ${token}`
|
|
172
|
+
});
|
|
173
|
+
if (options.body !== void 0) {
|
|
174
|
+
headers.set("content-type", "application/json");
|
|
175
|
+
}
|
|
176
|
+
let response;
|
|
177
|
+
try {
|
|
178
|
+
response = await __privateGet(this, _fetch).call(this, `${__privateGet(this, _baseUrl)}${path}`, {
|
|
179
|
+
method: options.method ?? "GET",
|
|
180
|
+
body: options.body === void 0 ? void 0 : JSON.stringify(options.body),
|
|
181
|
+
headers,
|
|
182
|
+
signal: timeoutController.signal
|
|
183
|
+
});
|
|
184
|
+
} catch {
|
|
185
|
+
if (timedOut) {
|
|
186
|
+
throw new DaykeeperReactNativeTransportError({
|
|
187
|
+
code: "REQUEST_TIMEOUT",
|
|
188
|
+
message: `The Daykeeper request exceeded ${__privateGet(this, _timeoutMs)}ms`,
|
|
189
|
+
retryable: true
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (options.signal?.aborted) {
|
|
193
|
+
throw new DaykeeperReactNativeTransportError({
|
|
194
|
+
code: "REQUEST_ABORTED",
|
|
195
|
+
message: "The Daykeeper request was aborted"
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
throw new DaykeeperReactNativeTransportError({
|
|
199
|
+
code: "NETWORK_ERROR",
|
|
200
|
+
message: "The Daykeeper customer API could not be reached",
|
|
201
|
+
retryable: true
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const payload = await readJson(response);
|
|
205
|
+
if (response.status === 401 && attempt === 0) continue;
|
|
206
|
+
if (!response.ok) {
|
|
207
|
+
const code = isRecord(payload) && typeof payload.error === "string" ? payload.error : "daykeeper_request_failed";
|
|
208
|
+
throw new DaykeeperReactNativeApiError({
|
|
209
|
+
status: response.status,
|
|
210
|
+
code,
|
|
211
|
+
retryable: response.status === 408 || response.status === 429 || response.status >= 500
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (!isRecord(payload)) {
|
|
215
|
+
throw new DaykeeperReactNativeTransportError({
|
|
216
|
+
code: "INVALID_RESPONSE",
|
|
217
|
+
message: "The Daykeeper customer API returned an invalid response",
|
|
218
|
+
retryable: true
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return payload;
|
|
222
|
+
}
|
|
223
|
+
throw new Error("Unreachable Daykeeper request state");
|
|
224
|
+
} finally {
|
|
225
|
+
clearTimeout(timeout);
|
|
226
|
+
options.signal?.removeEventListener("abort", onCallerAbort);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
function createDaykeeperReactNativeClient(options) {
|
|
230
|
+
return new DaykeeperReactNativeClient(options);
|
|
231
|
+
}
|
|
232
|
+
function parseBaseUrl(value) {
|
|
233
|
+
let url;
|
|
234
|
+
try {
|
|
235
|
+
url = new URL(value);
|
|
236
|
+
} catch {
|
|
237
|
+
throw configurationError("baseUrl must be a valid absolute URL");
|
|
238
|
+
}
|
|
239
|
+
const local = ["localhost", "127.0.0.1", "::1"].includes(url.hostname);
|
|
240
|
+
if (url.protocol !== "https:" && !(local && url.protocol === "http:")) {
|
|
241
|
+
throw configurationError(
|
|
242
|
+
"baseUrl must use HTTPS except for loopback development"
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
246
|
+
throw configurationError(
|
|
247
|
+
"baseUrl cannot include credentials, a query, or a fragment"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return url.toString().replace(/\/$/, "");
|
|
251
|
+
}
|
|
252
|
+
function validateTimeout(value) {
|
|
253
|
+
if (!Number.isInteger(value) || value < 1e3 || value > 6e4) {
|
|
254
|
+
throw configurationError(
|
|
255
|
+
"timeoutMs must be an integer from 1000 through 60000"
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
260
|
+
function validateToken(value) {
|
|
261
|
+
if (typeof value !== "string" || !value || value.length > MAX_TOKEN_LENGTH || /[\r\n]/.test(value)) {
|
|
262
|
+
throw configurationError("The customer access token is invalid");
|
|
263
|
+
}
|
|
264
|
+
return value;
|
|
265
|
+
}
|
|
266
|
+
function positiveInteger(value, name) {
|
|
267
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
268
|
+
throw configurationError(`${name} must be a positive integer`);
|
|
269
|
+
}
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
function validateMessage(value) {
|
|
273
|
+
if (typeof value !== "string") {
|
|
274
|
+
throw configurationError("Message content must be a string");
|
|
275
|
+
}
|
|
276
|
+
const normalized = value.trim();
|
|
277
|
+
if (!normalized || normalized.length > MAX_MESSAGE_LENGTH) {
|
|
278
|
+
throw configurationError(
|
|
279
|
+
`Message content must be 1 to ${MAX_MESSAGE_LENGTH} characters`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
return normalized;
|
|
283
|
+
}
|
|
284
|
+
async function readJson(response) {
|
|
285
|
+
const declaredLength = Number(response.headers.get("content-length"));
|
|
286
|
+
if (Number.isFinite(declaredLength) && declaredLength > MAX_RESPONSE_BYTES) {
|
|
287
|
+
throw responseTooLarge();
|
|
288
|
+
}
|
|
289
|
+
const body = response.body;
|
|
290
|
+
if (body && typeof body.getReader === "function" && typeof TextDecoder === "function") {
|
|
291
|
+
return parseJson(await readStream(body));
|
|
292
|
+
}
|
|
293
|
+
let text;
|
|
294
|
+
try {
|
|
295
|
+
text = await response.text();
|
|
296
|
+
} catch {
|
|
297
|
+
throw invalidResponse();
|
|
298
|
+
}
|
|
299
|
+
if (utf8LengthExceeds(text, MAX_RESPONSE_BYTES)) {
|
|
300
|
+
throw responseTooLarge();
|
|
301
|
+
}
|
|
302
|
+
return parseJson(text);
|
|
303
|
+
}
|
|
304
|
+
async function readStream(body) {
|
|
305
|
+
const reader = body.getReader();
|
|
306
|
+
const chunks = [];
|
|
307
|
+
let total = 0;
|
|
308
|
+
try {
|
|
309
|
+
for (; ; ) {
|
|
310
|
+
const { done, value } = await reader.read();
|
|
311
|
+
if (done) break;
|
|
312
|
+
total += value.byteLength;
|
|
313
|
+
if (total > MAX_RESPONSE_BYTES) {
|
|
314
|
+
await reader.cancel();
|
|
315
|
+
throw responseTooLarge();
|
|
316
|
+
}
|
|
317
|
+
chunks.push(value);
|
|
318
|
+
}
|
|
319
|
+
} finally {
|
|
320
|
+
reader.releaseLock();
|
|
321
|
+
}
|
|
322
|
+
const bytes = new Uint8Array(total);
|
|
323
|
+
let offset = 0;
|
|
324
|
+
for (const chunk of chunks) {
|
|
325
|
+
bytes.set(chunk, offset);
|
|
326
|
+
offset += chunk.byteLength;
|
|
327
|
+
}
|
|
328
|
+
return new TextDecoder().decode(bytes);
|
|
329
|
+
}
|
|
330
|
+
function parseJson(text) {
|
|
331
|
+
if (!text) return void 0;
|
|
332
|
+
try {
|
|
333
|
+
return JSON.parse(text);
|
|
334
|
+
} catch {
|
|
335
|
+
throw invalidResponse();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function utf8LengthExceeds(value, maximum) {
|
|
339
|
+
let bytes = 0;
|
|
340
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
341
|
+
const codeUnit = value.charCodeAt(index);
|
|
342
|
+
if (codeUnit < 128) bytes += 1;
|
|
343
|
+
else if (codeUnit < 2048) bytes += 2;
|
|
344
|
+
else if (codeUnit >= 55296 && codeUnit <= 56319 && index + 1 < value.length && value.charCodeAt(index + 1) >= 56320 && value.charCodeAt(index + 1) <= 57343) {
|
|
345
|
+
bytes += 4;
|
|
346
|
+
index += 1;
|
|
347
|
+
} else bytes += 3;
|
|
348
|
+
if (bytes > maximum) return true;
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
function isRecord(value) {
|
|
353
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
354
|
+
}
|
|
355
|
+
function responseTooLarge() {
|
|
356
|
+
return new DaykeeperReactNativeTransportError({
|
|
357
|
+
code: "RESPONSE_TOO_LARGE",
|
|
358
|
+
message: "The Daykeeper response exceeded 1 MiB"
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function invalidResponse() {
|
|
362
|
+
return new DaykeeperReactNativeTransportError({
|
|
363
|
+
code: "INVALID_RESPONSE",
|
|
364
|
+
message: "The Daykeeper customer API returned invalid JSON",
|
|
365
|
+
retryable: true
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
function configurationError(message) {
|
|
369
|
+
return new DaykeeperReactNativeTransportError({
|
|
370
|
+
code: "INVALID_CONFIGURATION",
|
|
371
|
+
message
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
375
|
+
0 && (module.exports = {
|
|
376
|
+
DaykeeperReactNativeApiError,
|
|
377
|
+
DaykeeperReactNativeClient,
|
|
378
|
+
DaykeeperReactNativeTransportError,
|
|
379
|
+
createDaykeeperReactNativeClient
|
|
380
|
+
});
|
|
381
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export {\n createDaykeeperReactNativeClient,\n DaykeeperReactNativeClient,\n} from \"./client.js\";\nexport type {\n DaykeeperReactNativeClientOptions,\n DaykeeperReactNativeRequestOptions,\n DaykeeperReactNativeTokenProvider,\n DaykeeperReactNativeTokenProviderContext,\n} from \"./client.js\";\nexport {\n DaykeeperReactNativeApiError,\n DaykeeperReactNativeTransportError,\n} from \"./errors.js\";\nexport type { DaykeeperReactNativeTransportErrorCode } from \"./errors.js\";\nexport type {\n components as DaykeeperCustomerOpenApiComponents,\n operations as DaykeeperCustomerOpenApiOperations,\n paths as DaykeeperCustomerOpenApiPaths,\n} from \"./generated/schema.js\";\nexport * from \"./types.js\";\n","export type DaykeeperReactNativeTransportErrorCode =\n | \"INVALID_CONFIGURATION\"\n | \"NETWORK_ERROR\"\n | \"REQUEST_ABORTED\"\n | \"REQUEST_TIMEOUT\"\n | \"INVALID_RESPONSE\"\n | \"RESPONSE_TOO_LARGE\";\n\nexport class DaykeeperReactNativeApiError extends Error {\n readonly status: number;\n readonly code: string;\n readonly retryable: boolean;\n\n constructor(options: { status: number; code: string; retryable: boolean }) {\n super(options.code);\n this.name = \"DaykeeperReactNativeApiError\";\n this.status = options.status;\n this.code = options.code;\n this.retryable = options.retryable;\n }\n\n toJSON(): {\n name: string;\n status: number;\n code: string;\n retryable: boolean;\n } {\n return {\n name: this.name,\n status: this.status,\n code: this.code,\n retryable: this.retryable,\n };\n }\n}\n\nexport class DaykeeperReactNativeTransportError extends Error {\n readonly code: DaykeeperReactNativeTransportErrorCode;\n readonly retryable: boolean;\n\n constructor(options: {\n code: DaykeeperReactNativeTransportErrorCode;\n message: string;\n retryable?: boolean;\n }) {\n super(options.message);\n this.name = \"DaykeeperReactNativeTransportError\";\n this.code = options.code;\n this.retryable = options.retryable ?? false;\n }\n\n toJSON(): {\n name: string;\n code: DaykeeperReactNativeTransportErrorCode;\n message: string;\n retryable: boolean;\n } {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n retryable: this.retryable,\n };\n }\n}\n","import {\n DaykeeperReactNativeApiError,\n DaykeeperReactNativeTransportError,\n} from \"./errors.js\";\nimport type {\n DaykeeperClaimConversationResult,\n DaykeeperConversationList,\n DaykeeperConversationResult,\n DaykeeperCustomerIdentity,\n DaykeeperMessageList,\n DaykeeperMessageResult,\n DaykeeperSeenResult,\n DaykeeperUnreadSummary,\n} from \"./types.js\";\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst MAX_RESPONSE_BYTES = 1024 * 1024;\nconst MAX_TOKEN_LENGTH = 16_384;\nconst MAX_MESSAGE_LENGTH = 16_000;\n\nexport interface DaykeeperReactNativeTokenProviderContext {\n /**\n * True only after Daykeeper rejected the first token with HTTP 401. The\n * provider should bypass any token cache and exchange the app session again.\n */\n forceRefresh: boolean;\n}\n\nexport type DaykeeperReactNativeTokenProvider = (\n context: DaykeeperReactNativeTokenProviderContext,\n) => string | Promise<string>;\n\nexport interface DaykeeperReactNativeClientOptions {\n baseUrl: string;\n getAccessToken: DaykeeperReactNativeTokenProvider;\n fetch?: typeof globalThis.fetch;\n timeoutMs?: number;\n}\n\nexport interface DaykeeperReactNativeRequestOptions {\n signal?: AbortSignal;\n}\n\nexport class DaykeeperReactNativeClient {\n readonly #baseUrl: string;\n readonly #fetch: typeof globalThis.fetch;\n readonly #getAccessToken: DaykeeperReactNativeTokenProvider;\n readonly #timeoutMs: number;\n\n constructor(options: DaykeeperReactNativeClientOptions) {\n this.#baseUrl = parseBaseUrl(options.baseUrl);\n this.#fetch = options.fetch ?? globalThis.fetch;\n if (typeof this.#fetch !== \"function\") {\n throw configurationError(\"A Fetch API implementation is required\");\n }\n if (typeof options.getAccessToken !== \"function\") {\n throw configurationError(\"getAccessToken must be a function\");\n }\n this.#getAccessToken = options.getAccessToken;\n this.#timeoutMs = validateTimeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n }\n\n getIdentity(\n options?: DaykeeperReactNativeRequestOptions,\n ): Promise<DaykeeperCustomerIdentity> {\n return this.#request(\"/v1/identity\", { signal: options?.signal });\n }\n\n listConversations(\n options?: DaykeeperReactNativeRequestOptions,\n ): Promise<DaykeeperConversationList> {\n return this.#request(\"/v1/conversations\", { signal: options?.signal });\n }\n\n createConversation(\n options?: DaykeeperReactNativeRequestOptions,\n ): Promise<DaykeeperConversationResult> {\n return this.#request(\"/v1/conversations\", {\n method: \"POST\",\n signal: options?.signal,\n });\n }\n\n getUnread(\n options?: DaykeeperReactNativeRequestOptions,\n ): Promise<DaykeeperUnreadSummary> {\n return this.#request(\"/v1/unread\", { signal: options?.signal });\n }\n\n markConversationSeen(\n conversationId: number,\n options?: DaykeeperReactNativeRequestOptions,\n ): Promise<DaykeeperSeenResult> {\n return this.#request(\n `/v1/conversations/${positiveInteger(conversationId, \"conversationId\")}/seen`,\n { method: \"POST\", signal: options?.signal },\n );\n }\n\n listMessages(\n conversationId: number,\n options: DaykeeperReactNativeRequestOptions & { after?: number } = {},\n ): Promise<DaykeeperMessageList> {\n const id = positiveInteger(conversationId, \"conversationId\");\n const after =\n options.after === undefined\n ? \"\"\n : `?after=${positiveInteger(options.after, \"after\")}`;\n return this.#request(`/v1/conversations/${id}/messages${after}`, {\n signal: options.signal,\n });\n }\n\n sendMessage(\n conversationId: number,\n content: string,\n options?: DaykeeperReactNativeRequestOptions,\n ): Promise<DaykeeperMessageResult> {\n const normalizedContent = validateMessage(content);\n return this.#request(\n `/v1/conversations/${positiveInteger(conversationId, \"conversationId\")}/messages`,\n {\n method: \"POST\",\n body: { content: normalizedContent },\n signal: options?.signal,\n },\n );\n }\n\n claimAnonymousConversation(\n widgetToken: string,\n options?: DaykeeperReactNativeRequestOptions,\n ): Promise<DaykeeperClaimConversationResult> {\n if (\n typeof widgetToken !== \"string\" ||\n !widgetToken.trim() ||\n widgetToken.length > MAX_TOKEN_LENGTH\n ) {\n throw configurationError(\"widgetToken is invalid\");\n }\n return this.#request(\"/v1/anonymous-conversations/claim\", {\n method: \"POST\",\n body: { widgetToken: widgetToken.trim() },\n signal: options?.signal,\n });\n }\n\n async #request<ResponseBody>(\n path: string,\n options: {\n method?: \"GET\" | \"POST\";\n body?: unknown;\n signal?: AbortSignal;\n } = {},\n ): Promise<ResponseBody> {\n const timeoutController = new AbortController();\n let timedOut = false;\n const timeout = setTimeout(() => {\n timedOut = true;\n timeoutController.abort();\n }, this.#timeoutMs);\n const onCallerAbort = () => timeoutController.abort();\n if (options.signal?.aborted) timeoutController.abort();\n else\n options.signal?.addEventListener(\"abort\", onCallerAbort, { once: true });\n\n try {\n for (let attempt = 0; attempt < 2; attempt += 1) {\n const token = validateToken(\n await this.#getAccessToken({ forceRefresh: attempt === 1 }),\n );\n const headers = new Headers({\n accept: \"application/json\",\n authorization: `Bearer ${token}`,\n });\n if (options.body !== undefined) {\n headers.set(\"content-type\", \"application/json\");\n }\n\n let response: Response;\n try {\n response = await this.#fetch(`${this.#baseUrl}${path}`, {\n method: options.method ?? \"GET\",\n body:\n options.body === undefined\n ? undefined\n : JSON.stringify(options.body),\n headers,\n signal: timeoutController.signal,\n });\n } catch {\n if (timedOut) {\n throw new DaykeeperReactNativeTransportError({\n code: \"REQUEST_TIMEOUT\",\n message: `The Daykeeper request exceeded ${this.#timeoutMs}ms`,\n retryable: true,\n });\n }\n if (options.signal?.aborted) {\n throw new DaykeeperReactNativeTransportError({\n code: \"REQUEST_ABORTED\",\n message: \"The Daykeeper request was aborted\",\n });\n }\n throw new DaykeeperReactNativeTransportError({\n code: \"NETWORK_ERROR\",\n message: \"The Daykeeper customer API could not be reached\",\n retryable: true,\n });\n }\n\n const payload = await readJson(response);\n if (response.status === 401 && attempt === 0) continue;\n if (!response.ok) {\n const code =\n isRecord(payload) && typeof payload.error === \"string\"\n ? payload.error\n : \"daykeeper_request_failed\";\n throw new DaykeeperReactNativeApiError({\n status: response.status,\n code,\n retryable:\n response.status === 408 ||\n response.status === 429 ||\n response.status >= 500,\n });\n }\n if (!isRecord(payload)) {\n throw new DaykeeperReactNativeTransportError({\n code: \"INVALID_RESPONSE\",\n message: \"The Daykeeper customer API returned an invalid response\",\n retryable: true,\n });\n }\n return payload as ResponseBody;\n }\n throw new Error(\"Unreachable Daykeeper request state\");\n } finally {\n clearTimeout(timeout);\n options.signal?.removeEventListener(\"abort\", onCallerAbort);\n }\n }\n}\n\nexport function createDaykeeperReactNativeClient(\n options: DaykeeperReactNativeClientOptions,\n): DaykeeperReactNativeClient {\n return new DaykeeperReactNativeClient(options);\n}\n\nfunction parseBaseUrl(value: string): string {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n throw configurationError(\"baseUrl must be a valid absolute URL\");\n }\n const local = [\"localhost\", \"127.0.0.1\", \"::1\"].includes(url.hostname);\n if (url.protocol !== \"https:\" && !(local && url.protocol === \"http:\")) {\n throw configurationError(\n \"baseUrl must use HTTPS except for loopback development\",\n );\n }\n if (url.username || url.password || url.search || url.hash) {\n throw configurationError(\n \"baseUrl cannot include credentials, a query, or a fragment\",\n );\n }\n return url.toString().replace(/\\/$/, \"\");\n}\n\nfunction validateTimeout(value: number): number {\n if (!Number.isInteger(value) || value < 1_000 || value > 60_000) {\n throw configurationError(\n \"timeoutMs must be an integer from 1000 through 60000\",\n );\n }\n return value;\n}\n\nfunction validateToken(value: string): string {\n if (\n typeof value !== \"string\" ||\n !value ||\n value.length > MAX_TOKEN_LENGTH ||\n /[\\r\\n]/.test(value)\n ) {\n throw configurationError(\"The customer access token is invalid\");\n }\n return value;\n}\n\nfunction positiveInteger(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1) {\n throw configurationError(`${name} must be a positive integer`);\n }\n return value;\n}\n\nfunction validateMessage(value: string): string {\n if (typeof value !== \"string\") {\n throw configurationError(\"Message content must be a string\");\n }\n const normalized = value.trim();\n if (!normalized || normalized.length > MAX_MESSAGE_LENGTH) {\n throw configurationError(\n `Message content must be 1 to ${MAX_MESSAGE_LENGTH} characters`,\n );\n }\n return normalized;\n}\n\nasync function readJson(response: Response): Promise<unknown> {\n const declaredLength = Number(response.headers.get(\"content-length\"));\n if (Number.isFinite(declaredLength) && declaredLength > MAX_RESPONSE_BYTES) {\n throw responseTooLarge();\n }\n\n const body = response.body;\n if (\n body &&\n typeof body.getReader === \"function\" &&\n typeof TextDecoder === \"function\"\n ) {\n return parseJson(await readStream(body));\n }\n\n let text: string;\n try {\n text = await response.text();\n } catch {\n throw invalidResponse();\n }\n if (utf8LengthExceeds(text, MAX_RESPONSE_BYTES)) {\n throw responseTooLarge();\n }\n return parseJson(text);\n}\n\nasync function readStream(body: ReadableStream<Uint8Array>): Promise<string> {\n const reader = body.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > MAX_RESPONSE_BYTES) {\n await reader.cancel();\n throw responseTooLarge();\n }\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n const bytes = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return new TextDecoder().decode(bytes);\n}\n\nfunction parseJson(text: string): unknown {\n if (!text) return undefined;\n try {\n return JSON.parse(text) as unknown;\n } catch {\n throw invalidResponse();\n }\n}\n\nfunction utf8LengthExceeds(value: string, maximum: number): boolean {\n let bytes = 0;\n for (let index = 0; index < value.length; index += 1) {\n const codeUnit = value.charCodeAt(index);\n if (codeUnit < 0x80) bytes += 1;\n else if (codeUnit < 0x800) bytes += 2;\n else if (\n codeUnit >= 0xd800 &&\n codeUnit <= 0xdbff &&\n index + 1 < value.length &&\n value.charCodeAt(index + 1) >= 0xdc00 &&\n value.charCodeAt(index + 1) <= 0xdfff\n ) {\n bytes += 4;\n index += 1;\n } else bytes += 3;\n if (bytes > maximum) return true;\n }\n return false;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction responseTooLarge(): DaykeeperReactNativeTransportError {\n return new DaykeeperReactNativeTransportError({\n code: \"RESPONSE_TOO_LARGE\",\n message: \"The Daykeeper response exceeded 1 MiB\",\n });\n}\n\nfunction invalidResponse(): DaykeeperReactNativeTransportError {\n return new DaykeeperReactNativeTransportError({\n code: \"INVALID_RESPONSE\",\n message: \"The Daykeeper customer API returned invalid JSON\",\n retryable: true,\n });\n}\n\nfunction configurationError(\n message: string,\n): DaykeeperReactNativeTransportError {\n return new DaykeeperReactNativeTransportError({\n code: \"INVALID_CONFIGURATION\",\n message,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,IAAM,+BAAN,cAA2C,MAAM;AAAA,EAKtD,YAAY,SAA+D;AACzE,UAAM,QAAQ,IAAI;AALpB,wBAAS;AACT,wBAAS;AACT,wBAAS;AAIP,SAAK,OAAO;AACZ,SAAK,SAAS,QAAQ;AACtB,SAAK,OAAO,QAAQ;AACpB,SAAK,YAAY,QAAQ;AAAA,EAC3B;AAAA,EAEA,SAK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