@primitivedotdev/sdk 0.2.3 → 0.3.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.
Files changed (41) hide show
  1. package/README.md +65 -2
  2. package/bin/run.js +5 -0
  3. package/dist/api/generated/client/client.gen.js +235 -0
  4. package/dist/api/generated/client/index.js +6 -0
  5. package/dist/api/generated/client/types.gen.js +2 -0
  6. package/dist/api/generated/client/utils.gen.js +228 -0
  7. package/dist/api/generated/client.gen.js +3 -0
  8. package/dist/api/generated/core/auth.gen.js +14 -0
  9. package/dist/api/generated/core/bodySerializer.gen.js +57 -0
  10. package/dist/api/generated/core/params.gen.js +100 -0
  11. package/dist/api/generated/core/pathSerializer.gen.js +106 -0
  12. package/dist/api/generated/core/queryKeySerializer.gen.js +92 -0
  13. package/dist/api/generated/core/serverSentEvents.gen.js +132 -0
  14. package/dist/api/generated/core/types.gen.js +2 -0
  15. package/dist/api/generated/core/utils.gen.js +87 -0
  16. package/dist/api/generated/index.js +2 -0
  17. package/dist/api/generated/sdk.gen.js +344 -0
  18. package/dist/api/generated/types.gen.js +2 -0
  19. package/dist/api/index.d.ts +1832 -0
  20. package/dist/api/index.js +39 -0
  21. package/dist/chunk-Cl8Af3a2.js +11 -0
  22. package/dist/contract/index.d.ts +3 -3
  23. package/dist/contract/index.js +2 -2
  24. package/dist/{index-BdRIHaXz.d.ts → index-D2OuDGVz.d.ts} +81 -5
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.js +2 -2
  27. package/dist/oclif/api-command.js +154 -0
  28. package/dist/oclif/fish-completion.js +87 -0
  29. package/dist/oclif/index.js +42 -0
  30. package/dist/openapi/index.d.ts +41 -0
  31. package/dist/openapi/index.js +8 -0
  32. package/dist/openapi/openapi.generated.js +2644 -0
  33. package/dist/openapi/operations.generated.js +632 -0
  34. package/dist/parser/index.d.ts +1 -1
  35. package/dist/parser/index.js +40 -25
  36. package/dist/{types-B5IgP-Zx.d.ts → types-C3ms4R0d.d.ts} +4 -0
  37. package/dist/webhook/index.d.ts +3 -3
  38. package/dist/webhook/index.js +2 -2
  39. package/dist/{webhook-Be2vM0F-.js → webhook-uSco6pyX.js} +176 -11
  40. package/oclif.manifest.json +1255 -0
  41. package/package.json +81 -13
@@ -0,0 +1,100 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ const extraPrefixesMap = {
3
+ $body_: 'body',
4
+ $headers_: 'headers',
5
+ $path_: 'path',
6
+ $query_: 'query',
7
+ };
8
+ const extraPrefixes = Object.entries(extraPrefixesMap);
9
+ const buildKeyMap = (fields, map) => {
10
+ if (!map) {
11
+ map = new Map();
12
+ }
13
+ for (const config of fields) {
14
+ if ('in' in config) {
15
+ if (config.key) {
16
+ map.set(config.key, {
17
+ in: config.in,
18
+ map: config.map,
19
+ });
20
+ }
21
+ }
22
+ else if ('key' in config) {
23
+ map.set(config.key, {
24
+ map: config.map,
25
+ });
26
+ }
27
+ else if (config.args) {
28
+ buildKeyMap(config.args, map);
29
+ }
30
+ }
31
+ return map;
32
+ };
33
+ const stripEmptySlots = (params) => {
34
+ for (const [slot, value] of Object.entries(params)) {
35
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
36
+ delete params[slot];
37
+ }
38
+ }
39
+ };
40
+ export const buildClientParams = (args, fields) => {
41
+ const params = {
42
+ body: {},
43
+ headers: {},
44
+ path: {},
45
+ query: {},
46
+ };
47
+ const map = buildKeyMap(fields);
48
+ let config;
49
+ for (const [index, arg] of args.entries()) {
50
+ if (fields[index]) {
51
+ config = fields[index];
52
+ }
53
+ if (!config) {
54
+ continue;
55
+ }
56
+ if ('in' in config) {
57
+ if (config.key) {
58
+ const field = map.get(config.key);
59
+ const name = field.map || config.key;
60
+ if (field.in) {
61
+ params[field.in][name] = arg;
62
+ }
63
+ }
64
+ else {
65
+ params.body = arg;
66
+ }
67
+ }
68
+ else {
69
+ for (const [key, value] of Object.entries(arg ?? {})) {
70
+ const field = map.get(key);
71
+ if (field) {
72
+ if (field.in) {
73
+ const name = field.map || key;
74
+ params[field.in][name] = value;
75
+ }
76
+ else {
77
+ params[field.map] = value;
78
+ }
79
+ }
80
+ else {
81
+ const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
82
+ if (extra) {
83
+ const [prefix, slot] = extra;
84
+ params[slot][key.slice(prefix.length)] = value;
85
+ }
86
+ else if ('allowExtra' in config && config.allowExtra) {
87
+ for (const [slot, allowed] of Object.entries(config.allowExtra)) {
88
+ if (allowed) {
89
+ params[slot][key] = value;
90
+ break;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ stripEmptySlots(params);
99
+ return params;
100
+ };
@@ -0,0 +1,106 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export const separatorArrayExplode = (style) => {
3
+ switch (style) {
4
+ case 'label':
5
+ return '.';
6
+ case 'matrix':
7
+ return ';';
8
+ case 'simple':
9
+ return ',';
10
+ default:
11
+ return '&';
12
+ }
13
+ };
14
+ export const separatorArrayNoExplode = (style) => {
15
+ switch (style) {
16
+ case 'form':
17
+ return ',';
18
+ case 'pipeDelimited':
19
+ return '|';
20
+ case 'spaceDelimited':
21
+ return '%20';
22
+ default:
23
+ return ',';
24
+ }
25
+ };
26
+ export const separatorObjectExplode = (style) => {
27
+ switch (style) {
28
+ case 'label':
29
+ return '.';
30
+ case 'matrix':
31
+ return ';';
32
+ case 'simple':
33
+ return ',';
34
+ default:
35
+ return '&';
36
+ }
37
+ };
38
+ export const serializeArrayParam = ({ allowReserved, explode, name, style, value, }) => {
39
+ if (!explode) {
40
+ const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
41
+ switch (style) {
42
+ case 'label':
43
+ return `.${joinedValues}`;
44
+ case 'matrix':
45
+ return `;${name}=${joinedValues}`;
46
+ case 'simple':
47
+ return joinedValues;
48
+ default:
49
+ return `${name}=${joinedValues}`;
50
+ }
51
+ }
52
+ const separator = separatorArrayExplode(style);
53
+ const joinedValues = value
54
+ .map((v) => {
55
+ if (style === 'label' || style === 'simple') {
56
+ return allowReserved ? v : encodeURIComponent(v);
57
+ }
58
+ return serializePrimitiveParam({
59
+ allowReserved,
60
+ name,
61
+ value: v,
62
+ });
63
+ })
64
+ .join(separator);
65
+ return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
66
+ };
67
+ export const serializePrimitiveParam = ({ allowReserved, name, value, }) => {
68
+ if (value === undefined || value === null) {
69
+ return '';
70
+ }
71
+ if (typeof value === 'object') {
72
+ throw new Error('Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.');
73
+ }
74
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
75
+ };
76
+ export const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly, }) => {
77
+ if (value instanceof Date) {
78
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
79
+ }
80
+ if (style !== 'deepObject' && !explode) {
81
+ let values = [];
82
+ Object.entries(value).forEach(([key, v]) => {
83
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
84
+ });
85
+ const joinedValues = values.join(',');
86
+ switch (style) {
87
+ case 'form':
88
+ return `${name}=${joinedValues}`;
89
+ case 'label':
90
+ return `.${joinedValues}`;
91
+ case 'matrix':
92
+ return `;${name}=${joinedValues}`;
93
+ default:
94
+ return joinedValues;
95
+ }
96
+ }
97
+ const separator = separatorObjectExplode(style);
98
+ const joinedValues = Object.entries(value)
99
+ .map(([key, v]) => serializePrimitiveParam({
100
+ allowReserved,
101
+ name: style === 'deepObject' ? `${name}[${key}]` : key,
102
+ value: v,
103
+ }))
104
+ .join(separator);
105
+ return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
106
+ };
@@ -0,0 +1,92 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ /**
3
+ * Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
4
+ */
5
+ export const queryKeyJsonReplacer = (_key, value) => {
6
+ if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
7
+ return undefined;
8
+ }
9
+ if (typeof value === 'bigint') {
10
+ return value.toString();
11
+ }
12
+ if (value instanceof Date) {
13
+ return value.toISOString();
14
+ }
15
+ return value;
16
+ };
17
+ /**
18
+ * Safely stringifies a value and parses it back into a JsonValue.
19
+ */
20
+ export const stringifyToJsonValue = (input) => {
21
+ try {
22
+ const json = JSON.stringify(input, queryKeyJsonReplacer);
23
+ if (json === undefined) {
24
+ return undefined;
25
+ }
26
+ return JSON.parse(json);
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ };
32
+ /**
33
+ * Detects plain objects (including objects with a null prototype).
34
+ */
35
+ const isPlainObject = (value) => {
36
+ if (value === null || typeof value !== 'object') {
37
+ return false;
38
+ }
39
+ const prototype = Object.getPrototypeOf(value);
40
+ return prototype === Object.prototype || prototype === null;
41
+ };
42
+ /**
43
+ * Turns URLSearchParams into a sorted JSON object for deterministic keys.
44
+ */
45
+ const serializeSearchParams = (params) => {
46
+ const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b));
47
+ const result = {};
48
+ for (const [key, value] of entries) {
49
+ const existing = result[key];
50
+ if (existing === undefined) {
51
+ result[key] = value;
52
+ continue;
53
+ }
54
+ if (Array.isArray(existing)) {
55
+ existing.push(value);
56
+ }
57
+ else {
58
+ result[key] = [existing, value];
59
+ }
60
+ }
61
+ return result;
62
+ };
63
+ /**
64
+ * Normalizes any accepted value into a JSON-friendly shape for query keys.
65
+ */
66
+ export const serializeQueryKeyValue = (value) => {
67
+ if (value === null) {
68
+ return null;
69
+ }
70
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
71
+ return value;
72
+ }
73
+ if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
74
+ return undefined;
75
+ }
76
+ if (typeof value === 'bigint') {
77
+ return value.toString();
78
+ }
79
+ if (value instanceof Date) {
80
+ return value.toISOString();
81
+ }
82
+ if (Array.isArray(value)) {
83
+ return stringifyToJsonValue(value);
84
+ }
85
+ if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) {
86
+ return serializeSearchParams(value);
87
+ }
88
+ if (isPlainObject(value)) {
89
+ return stringifyToJsonValue(value);
90
+ }
91
+ return undefined;
92
+ };
@@ -0,0 +1,132 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
3
+ let lastEventId;
4
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
5
+ const createStream = async function* () {
6
+ let retryDelay = sseDefaultRetryDelay ?? 3000;
7
+ let attempt = 0;
8
+ const signal = options.signal ?? new AbortController().signal;
9
+ while (true) {
10
+ if (signal.aborted)
11
+ break;
12
+ attempt++;
13
+ const headers = options.headers instanceof Headers
14
+ ? options.headers
15
+ : new Headers(options.headers);
16
+ if (lastEventId !== undefined) {
17
+ headers.set('Last-Event-ID', lastEventId);
18
+ }
19
+ try {
20
+ const requestInit = {
21
+ redirect: 'follow',
22
+ ...options,
23
+ body: options.serializedBody,
24
+ headers,
25
+ signal,
26
+ };
27
+ let request = new Request(url, requestInit);
28
+ if (onRequest) {
29
+ request = await onRequest(url, requestInit);
30
+ }
31
+ // fetch must be assigned here, otherwise it would throw the error:
32
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
33
+ const _fetch = options.fetch ?? globalThis.fetch;
34
+ const response = await _fetch(request);
35
+ if (!response.ok)
36
+ throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
37
+ if (!response.body)
38
+ throw new Error('No body in SSE response');
39
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
40
+ let buffer = '';
41
+ const abortHandler = () => {
42
+ try {
43
+ reader.cancel();
44
+ }
45
+ catch {
46
+ // noop
47
+ }
48
+ };
49
+ signal.addEventListener('abort', abortHandler);
50
+ try {
51
+ while (true) {
52
+ const { done, value } = await reader.read();
53
+ if (done)
54
+ break;
55
+ buffer += value;
56
+ buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings
57
+ const chunks = buffer.split('\n\n');
58
+ buffer = chunks.pop() ?? '';
59
+ for (const chunk of chunks) {
60
+ const lines = chunk.split('\n');
61
+ const dataLines = [];
62
+ let eventName;
63
+ for (const line of lines) {
64
+ if (line.startsWith('data:')) {
65
+ dataLines.push(line.replace(/^data:\s*/, ''));
66
+ }
67
+ else if (line.startsWith('event:')) {
68
+ eventName = line.replace(/^event:\s*/, '');
69
+ }
70
+ else if (line.startsWith('id:')) {
71
+ lastEventId = line.replace(/^id:\s*/, '');
72
+ }
73
+ else if (line.startsWith('retry:')) {
74
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10);
75
+ if (!Number.isNaN(parsed)) {
76
+ retryDelay = parsed;
77
+ }
78
+ }
79
+ }
80
+ let data;
81
+ let parsedJson = false;
82
+ if (dataLines.length) {
83
+ const rawData = dataLines.join('\n');
84
+ try {
85
+ data = JSON.parse(rawData);
86
+ parsedJson = true;
87
+ }
88
+ catch {
89
+ data = rawData;
90
+ }
91
+ }
92
+ if (parsedJson) {
93
+ if (responseValidator) {
94
+ await responseValidator(data);
95
+ }
96
+ if (responseTransformer) {
97
+ data = await responseTransformer(data);
98
+ }
99
+ }
100
+ onSseEvent?.({
101
+ data,
102
+ event: eventName,
103
+ id: lastEventId,
104
+ retry: retryDelay,
105
+ });
106
+ if (dataLines.length) {
107
+ yield data;
108
+ }
109
+ }
110
+ }
111
+ }
112
+ finally {
113
+ signal.removeEventListener('abort', abortHandler);
114
+ reader.releaseLock();
115
+ }
116
+ break; // exit loop on normal completion
117
+ }
118
+ catch (error) {
119
+ // connection failed or aborted; retry after delay
120
+ onSseError?.(error);
121
+ if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
122
+ break; // stop after firing error
123
+ }
124
+ // exponential backoff: double retry each attempt, cap at 30s
125
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
126
+ await sleep(backoff);
127
+ }
128
+ }
129
+ };
130
+ const stream = createStream();
131
+ return { stream };
132
+ }
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,87 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from './pathSerializer.gen.js';
3
+ export const PATH_PARAM_RE = /\{[^{}]+\}/g;
4
+ export const defaultPathSerializer = ({ path, url: _url }) => {
5
+ let url = _url;
6
+ const matches = _url.match(PATH_PARAM_RE);
7
+ if (matches) {
8
+ for (const match of matches) {
9
+ let explode = false;
10
+ let name = match.substring(1, match.length - 1);
11
+ let style = 'simple';
12
+ if (name.endsWith('*')) {
13
+ explode = true;
14
+ name = name.substring(0, name.length - 1);
15
+ }
16
+ if (name.startsWith('.')) {
17
+ name = name.substring(1);
18
+ style = 'label';
19
+ }
20
+ else if (name.startsWith(';')) {
21
+ name = name.substring(1);
22
+ style = 'matrix';
23
+ }
24
+ const value = path[name];
25
+ if (value === undefined || value === null) {
26
+ continue;
27
+ }
28
+ if (Array.isArray(value)) {
29
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
30
+ continue;
31
+ }
32
+ if (typeof value === 'object') {
33
+ url = url.replace(match, serializeObjectParam({
34
+ explode,
35
+ name,
36
+ style,
37
+ value: value,
38
+ valueOnly: true,
39
+ }));
40
+ continue;
41
+ }
42
+ if (style === 'matrix') {
43
+ url = url.replace(match, `;${serializePrimitiveParam({
44
+ name,
45
+ value: value,
46
+ })}`);
47
+ continue;
48
+ }
49
+ const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value);
50
+ url = url.replace(match, replaceValue);
51
+ }
52
+ }
53
+ return url;
54
+ };
55
+ export const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => {
56
+ const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
57
+ let url = (baseUrl ?? '') + pathUrl;
58
+ if (path) {
59
+ url = defaultPathSerializer({ path, url });
60
+ }
61
+ let search = query ? querySerializer(query) : '';
62
+ if (search.startsWith('?')) {
63
+ search = search.substring(1);
64
+ }
65
+ if (search) {
66
+ url += `?${search}`;
67
+ }
68
+ return url;
69
+ };
70
+ export function getValidRequestBody(options) {
71
+ const hasBody = options.body !== undefined;
72
+ const isSerializedBody = hasBody && options.bodySerializer;
73
+ if (isSerializedBody) {
74
+ if ('serializedBody' in options) {
75
+ const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== '';
76
+ return hasSerializedBody ? options.serializedBody : null;
77
+ }
78
+ // not all clients implement a serializedBody property (i.e., client-axios)
79
+ return options.body !== '' ? options.body : null;
80
+ }
81
+ // plain/text body
82
+ if (hasBody) {
83
+ return options.body;
84
+ }
85
+ // no body was provided
86
+ return undefined;
87
+ }
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export { addDomain, createEndpoint, createFilter, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, downloadAttachments, downloadRawEmail, getAccount, getEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, replayDelivery, replayEmailWebhooks, rotateWebhookSecret, testEndpoint, updateAccount, updateDomain, updateEndpoint, updateFilter, verifyDomain } from './sdk.gen.js';