smswire 0.0.0-stage → 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/http.ts","../src/resources/messages.ts","../src/resources/otp.ts","../src/resources/campaigns.ts","../src/resources/groups.ts","../src/resources/schedules.ts","../src/webhooks.ts","../src/client.ts"],"sourcesContent":["import { SMSWire } from './client';\n\nexport { SMSWire, VERSION, type ClientOptions } from './client';\nexport { SMSWireError, SMSWireSignatureError } from './errors';\nexport { verifyWebhook, SIGNATURE_HEADER, type VerifyOptions } from './webhooks';\nexport type { SendOptions } from './resources/messages';\nexport type * from './types';\nexport default SMSWire;\n","/** A request that failed: the API's answer (status, code, message) or a network problem (status null). */\nexport class SMSWireError extends Error {\n override readonly name: string = 'SMSWireError';\n\n constructor(\n /** HTTP status, or null when no answer arrived. */\n readonly status: number | null,\n /** Stable machine code, e.g. `invalid_request`, `rate_limited`, `network_error`, `timeout`. */\n readonly code: string,\n message: string,\n /** Seconds until trying again makes sense (from Retry-After), when the API said. */\n readonly retryAfter: number | null = null,\n options?: { cause?: unknown },\n ) {\n super(message, options);\n }\n}\n\n/** A webhook whose signature is missing, wrong or too old. Answer it with 400. */\nexport class SMSWireSignatureError extends Error {\n override readonly name = 'SMSWireSignatureError';\n}\n","import { SMSWireError } from './errors';\n\nexport interface HttpOptions {\n apiKey: string;\n baseUrl: string;\n maxRetries: number;\n maxRetryWait: number;\n timeout: number;\n fetch: typeof fetch;\n userAgent: string;\n}\n\nexport interface Request {\n method: 'GET' | 'POST' | 'PATCH' | 'DELETE';\n path: string;\n query?: Record<string, unknown>;\n body?: unknown;\n headers?: Record<string, string>;\n /** Safe to repeat after a 5xx or a dropped connection (GET, PATCH, DELETE, or a POST with an Idempotency-Key). */\n idempotent: boolean;\n}\n\nconst sleep = (seconds: number) => new Promise((r) => setTimeout(r, seconds * 1000));\n\n/** Seconds from a Retry-After header (seconds or an HTTP date). */\nfunction retryAfter(header: string | null): number | null {\n if (!header) return null;\n const n = Number(header);\n if (Number.isFinite(n)) return Math.max(0, n);\n const at = Date.parse(header);\n return Number.isNaN(at) ? null : Math.max(0, (at - Date.now()) / 1000);\n}\n\n/** Exponential backoff from 0.5 s, capped at 8 s, with up to 25% jitter. */\nconst backoff = (attempt: number) => Math.min(8, 0.5 * 2 ** attempt) * (1 + Math.random() * 0.25);\n\n/** The SDK's error for a non-2xx answer. */\nexport async function errorFrom(res: Response): Promise<SMSWireError> {\n const text = await res.text().catch(() => '');\n let code = 'http_error';\n let message = `HTTP ${res.status}`;\n try {\n const body = JSON.parse(text) as { error?: unknown; message?: unknown };\n if (typeof body.error === 'string' && typeof body.message === 'string') {\n code = body.error;\n message = body.message;\n }\n } catch {\n // Not JSON (a proxy's error page): keep the generic code.\n }\n return new SMSWireError(res.status, code, message, retryAfter(res.headers.get('retry-after')));\n}\n\n/** Whether to try [err] again on attempt [attempt] (0-based), and after how long. */\nexport function retryDelay(err: SMSWireError, req: Pick<Request, 'idempotent'>, attempt: number, opts: Pick<HttpOptions, 'maxRetries' | 'maxRetryWait'>): number | null {\n if (attempt >= opts.maxRetries) return null;\n const retryable = err.status === 429 || (req.idempotent && (err.status === null || err.status >= 500));\n if (!retryable) return null;\n if (err.retryAfter !== null) return err.retryAfter <= opts.maxRetryWait ? err.retryAfter : null;\n return backoff(attempt);\n}\n\nexport async function send<T>(opts: HttpOptions, req: Request): Promise<T> {\n const url = new URL(opts.baseUrl.replace(/\\/+$/, '') + req.path);\n for (const [k, v] of Object.entries(req.query ?? {})) {\n if (v !== undefined && v !== null) url.searchParams.set(k, String(v));\n }\n const headers: Record<string, string> = {\n Authorization: `Bearer ${opts.apiKey}`,\n Accept: 'application/json',\n 'User-Agent': opts.userAgent,\n ...req.headers,\n };\n if (req.body !== undefined) headers['Content-Type'] = 'application/json';\n const body = req.body === undefined ? undefined : JSON.stringify(req.body);\n\n for (let attempt = 0; ; attempt++) {\n let res: Response | undefined;\n let err: SMSWireError;\n try {\n res = await opts.fetch(url, { method: req.method, headers, body, signal: AbortSignal.timeout(opts.timeout) });\n } catch (e) {\n const timedOut = e instanceof Error && e.name === 'TimeoutError';\n err = new SMSWireError(\n null,\n timedOut ? 'timeout' : 'network_error',\n timedOut ? `No answer within ${opts.timeout} ms` : `Could not reach ${url.origin}: ${(e as Error).message}`,\n null,\n { cause: e },\n );\n }\n if (res?.ok) {\n const text = await res.text();\n return (text ? JSON.parse(text) : undefined) as T;\n }\n if (res) err = await errorFrom(res);\n const wait = retryDelay(err!, req, attempt, opts);\n if (wait === null) throw err!;\n await sleep(wait);\n }\n}\n","import type { Request } from '../http';\nimport type { BulkResult, ListMessagesParams, Message, MessagePage, SendBulkParams, SendMessageParams } from '../types';\n\nexport type Call = <T>(req: Request) => Promise<T>;\n\nexport interface SendOptions {\n /**\n * Repeating a send with the same key returns the first message instead of sending again.\n * Defaults to a fresh random key, so the SDK's own retries never send twice; pass your own\n * (an order id, say) to make your retries safe too.\n */\n idempotencyKey?: string;\n}\n\nexport class Messages {\n constructor(\n private readonly call: Call,\n private readonly base: string,\n ) {}\n\n /** Queues one SMS for the project's phone. */\n send(params: SendMessageParams, options: SendOptions = {}): Promise<Message> {\n return this.call({\n method: 'POST',\n path: this.base,\n body: params,\n headers: { 'Idempotency-Key': options.idempotencyKey ?? crypto.randomUUID() },\n idempotent: true,\n });\n }\n\n /** Queues a batch. Invalid or opted-out items come back in `rejected`; the rest go out as one batch. */\n sendBulk(params: SendBulkParams): Promise<BulkResult> {\n return this.call({ method: 'POST', path: `${this.base}/bulk`, body: params, idempotent: false });\n }\n\n get(id: string): Promise<Message> {\n return this.call({ method: 'GET', path: `${this.base}/${encodeURIComponent(id)}`, idempotent: true });\n }\n\n /** Stops a message that hasn't reached a phone yet. */\n cancel(id: string): Promise<Message> {\n return this.call({ method: 'DELETE', path: `${this.base}/${encodeURIComponent(id)}`, idempotent: true });\n }\n\n /** One page, newest first. Pass `next_cursor` back as `cursor` for the next. */\n list(params: ListMessagesParams = {}): Promise<MessagePage> {\n return this.call({ method: 'GET', path: this.base, query: params, idempotent: true });\n }\n\n /** Every matching message, newest first, fetching pages as you go. */\n async *listAll(params: Omit<ListMessagesParams, 'cursor'> = {}): AsyncGenerator<Message> {\n let cursor: string | null | undefined;\n do {\n const page = await this.list({ ...params, cursor: cursor ?? undefined });\n yield* page.data;\n cursor = page.next_cursor;\n } while (cursor);\n }\n}\n","import type { Otp, OtpVerification, SendOtpParams, VerifyOtpParams } from '../types';\nimport type { Call } from './messages';\n\nexport class OneTimeCodes {\n constructor(\n private readonly call: Call,\n private readonly base: string,\n ) {}\n\n /** Texts a fresh code to `to`. Keep the returned `id` for verify(). */\n send(params: SendOtpParams): Promise<Otp> {\n return this.call({ method: 'POST', path: this.base, body: params, idempotent: false });\n }\n\n /** Checks what the user typed. `valid` is false with a `reason` when it's wrong, expired or used. */\n verify(params: VerifyOtpParams): Promise<OtpVerification> {\n return this.call({ method: 'POST', path: `${this.base}/verify`, body: params, idempotent: false });\n }\n}\n","import type {\n Campaign,\n CampaignList,\n CampaignPreview,\n CampaignResults,\n CampaignSendResult,\n CreateCampaignParams,\n UpdateCampaignParams,\n} from '../types';\nimport type { Call } from './messages';\n\n/**\n * Campaigns: a send with a name, an audience, who to leave out and when. A campaign is made as a\n * draft and nothing goes out until `send`, so an audience can be built up over several calls and\n * checked with `preview` first. Each run is an ordinary batch.\n */\nexport class Campaigns {\n constructor(\n private readonly call: Call,\n private readonly base: string,\n ) {}\n\n /**\n * Makes a draft. Marketing needs `consent: true` -- that the recipients agreed to hear from\n * you -- and `stop_footer` ends every marketing message with your opt-out line. With `cron` it\n * repeats instead of sending once.\n */\n create(params: CreateCampaignParams): Promise<Campaign> {\n return this.call({ method: 'POST', path: this.base, body: params, idempotent: false });\n }\n\n list(): Promise<CampaignList> {\n return this.call({ method: 'GET', path: this.base, idempotent: true });\n }\n\n get(id: string): Promise<Campaign> {\n return this.call({ method: 'GET', path: this.one(id), idempotent: true });\n }\n\n /** Absent fields stay as they are, and the change reaches the runs still to come. */\n update(id: string, params: UpdateCampaignParams): Promise<Campaign> {\n return this.call({ method: 'PATCH', path: this.one(id), body: params, idempotent: true });\n }\n\n /** The campaign goes; its runs stay in the message log. */\n async delete(id: string): Promise<void> {\n await this.call({ method: 'DELETE', path: this.one(id), idempotent: true });\n }\n\n /** Who it would reach right now: groups read, duplicates dropped, exclusions applied. */\n preview(id: string): Promise<CampaignPreview> {\n return this.call({ method: 'GET', path: `${this.one(id)}/preview`, idempotent: true });\n }\n\n /** How it did: delivery, SMS parts, replies and the opt-outs it cost. */\n results(id: string): Promise<CampaignResults> {\n return this.call({ method: 'GET', path: `${this.one(id)}/results`, idempotent: true });\n }\n\n /** Starts it: `queued` with a batch, or `scheduled` when it waits for its time or its cron. */\n send(id: string): Promise<CampaignSendResult> {\n return this.call({ method: 'POST', path: `${this.one(id)}/send`, idempotent: false });\n }\n\n /** Holds every run still going, or lets them carry on. */\n control(id: string, status: 'running' | 'paused'): Promise<Campaign> {\n return this.call({ method: 'POST', path: `${this.one(id)}/control`, body: { status }, idempotent: true });\n }\n\n /** Stops it for good: what is still on the server is cancelled and refunded. */\n cancel(id: string): Promise<Campaign> {\n return this.call({ method: 'POST', path: `${this.one(id)}/cancel`, idempotent: true });\n }\n\n private one(id: string) {\n return `${this.base}/${encodeURIComponent(id)}`;\n }\n}\n","import type { AddMembersResult, CreateGroupParams, Group, GroupList, GroupMember, GroupMemberInput, GroupMemberPage, ListMembersParams, UpdateGroupParams } from '../types';\nimport type { Call } from './messages';\n\n/** The workspace's contact groups: every project's key sees the same ones. */\nexport class Groups {\n constructor(\n private readonly call: Call,\n private readonly base: string,\n ) {}\n\n /** With `keywords`, someone who texts one of them (the whole text) to a workspace phone joins. */\n create(params: CreateGroupParams): Promise<Group> {\n return this.call({ method: 'POST', path: this.base, body: params, idempotent: false });\n }\n\n list(): Promise<GroupList> {\n return this.call({ method: 'GET', path: this.base, idempotent: true });\n }\n\n get(id: string): Promise<Group> {\n return this.call({ method: 'GET', path: this.one(id), idempotent: true });\n }\n\n /** Absent fields stay as they are; `keywords: []` turns joining by text off. */\n update(id: string, params: UpdateGroupParams): Promise<Group> {\n return this.call({ method: 'PATCH', path: this.one(id), body: params, idempotent: true });\n }\n\n /** The group goes; its contacts stay. */\n async delete(id: string): Promise<void> {\n await this.call({ method: 'DELETE', path: this.one(id), idempotent: true });\n }\n\n /** One page of members, alphabetically; pass `next_cursor` back as `cursor` for the next. */\n listMembers(id: string, params: ListMembersParams = {}): Promise<GroupMemberPage> {\n return this.call({ method: 'GET', path: `${this.one(id)}/members`, query: params, idempotent: true });\n }\n\n /** Every member, fetching pages as you iterate. */\n async *listAllMembers(id: string, params: Omit<ListMembersParams, 'cursor'> = {}): AsyncGenerator<GroupMember> {\n let cursor: string | undefined;\n do {\n const page = await this.listMembers(id, { ...params, cursor });\n yield* page.data;\n cursor = page.next_cursor ?? undefined;\n } while (cursor);\n }\n\n /** Adds people by number; new numbers become contacts (a given name replaces theirs, fields merge). */\n addMembers(id: string, members: GroupMemberInput[]): Promise<AddMembersResult> {\n return this.call({ method: 'POST', path: `${this.one(id)}/members`, body: { members }, idempotent: true });\n }\n\n /** Takes the number out of the group; the contact stays. */\n async removeMember(id: string, phone: string): Promise<void> {\n await this.call({ method: 'DELETE', path: `${this.one(id)}/members/${encodeURIComponent(phone)}`, idempotent: true });\n }\n\n private one(id: string) {\n return `${this.base}/${encodeURIComponent(id)}`;\n }\n}\n","import type { CreateScheduleParams, Schedule, SchedulePage, UpdateScheduleParams } from '../types';\nimport type { Call } from './messages';\n\nexport class Schedules {\n constructor(\n private readonly call: Call,\n private readonly base: string,\n ) {}\n\n /** A message (or batch) sent again and again on a cron schedule. */\n create(params: CreateScheduleParams): Promise<Schedule> {\n return this.call({ method: 'POST', path: this.base, body: params, idempotent: false });\n }\n\n list(): Promise<SchedulePage> {\n return this.call({ method: 'GET', path: this.base, idempotent: true });\n }\n\n /** One schedule, with its recent runs. */\n get(id: string): Promise<Schedule> {\n return this.call({ method: 'GET', path: `${this.base}/${encodeURIComponent(id)}`, idempotent: true });\n }\n\n /** Absent fields stay as they are; recipients can't change. */\n update(id: string, params: UpdateScheduleParams): Promise<Schedule> {\n return this.call({ method: 'PATCH', path: `${this.base}/${encodeURIComponent(id)}`, body: params, idempotent: true });\n }\n\n async delete(id: string): Promise<void> {\n await this.call({ method: 'DELETE', path: `${this.base}/${encodeURIComponent(id)}`, idempotent: true });\n }\n}\n","import { SMSWireSignatureError } from './errors';\nimport type { WebhookEvent } from './types';\n\nexport interface VerifyOptions {\n /** Oldest (and furthest in the future) signature accepted, in seconds. Default 300. */\n tolerance?: number;\n /** The current time in unix seconds; for tests. */\n now?: number;\n}\n\n/** The header the signature arrives in. */\nexport const SIGNATURE_HEADER = 'X-SMSWire-Signature';\n\nconst encoder = new TextEncoder();\n\nfunction bytes(body: string | Uint8Array | ArrayBuffer): Uint8Array {\n if (typeof body === 'string') return encoder.encode(body);\n return body instanceof Uint8Array ? body : new Uint8Array(body);\n}\n\n/** `t=<unix>,v1=<hex>[,v1=<hex>…]`, in any order; null when it isn't one. */\nfunction parse(header: string): { t: number; signatures: string[] } | null {\n let t: number | null = null;\n const signatures: string[] = [];\n for (const part of header.split(',')) {\n const i = part.indexOf('=');\n if (i < 0) continue;\n const key = part.slice(0, i).trim();\n const value = part.slice(i + 1).trim();\n if (key === 't' && /^\\d+$/.test(value)) t = Number(value);\n else if (key === 'v1' && /^[0-9a-f]{64}$/i.test(value)) signatures.push(value.toLowerCase());\n }\n return t === null || !signatures.length ? null : { t, signatures };\n}\n\nasync function hmacHex(secret: string, message: Uint8Array<ArrayBuffer>): Promise<string> {\n const key = await crypto.subtle.importKey('raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);\n const mac = new Uint8Array(await crypto.subtle.sign('HMAC', key, message));\n return Array.from(mac, (b) => b.toString(16).padStart(2, '0')).join('');\n}\n\n/** Compares two equal-length strings without stopping at the first difference. */\nfunction constantTimeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);\n return diff === 0;\n}\n\n/**\n * Checks a webhook's X-SMSWire-Signature against the **raw** request body (not re-serialised JSON)\n * and returns the parsed event. Throws SMSWireSignatureError when the signature is missing,\n * wrong, or more than `tolerance` seconds off.\n */\nexport async function verifyWebhook(\n rawBody: string | Uint8Array | ArrayBuffer,\n signature: string | null | undefined,\n secret: string,\n options: VerifyOptions = {},\n): Promise<WebhookEvent> {\n if (!secret) throw new SMSWireSignatureError('No webhook signing secret given');\n const parsed = parse(signature ?? '');\n if (!parsed) throw new SMSWireSignatureError(`Missing or malformed ${SIGNATURE_HEADER} header`);\n const now = options.now ?? Math.floor(Date.now() / 1000);\n if (Math.abs(now - parsed.t) > (options.tolerance ?? 300)) {\n throw new SMSWireSignatureError('Signature timestamp is outside the tolerance');\n }\n const body = bytes(rawBody);\n const prefix = encoder.encode(`${parsed.t}.`);\n const signed = new Uint8Array(prefix.length + body.length);\n signed.set(prefix);\n signed.set(body, prefix.length);\n const expected = await hmacHex(secret, signed);\n if (!parsed.signatures.some((s) => constantTimeEqual(s, expected))) {\n throw new SMSWireSignatureError('Signature does not match');\n }\n return JSON.parse(new TextDecoder().decode(body)) as WebhookEvent;\n}\n","import { send, type HttpOptions, type Request } from './http';\nimport { Messages } from './resources/messages';\nimport { OneTimeCodes } from './resources/otp';\nimport { Campaigns } from './resources/campaigns';\nimport { Groups } from './resources/groups';\nimport { Schedules } from './resources/schedules';\nimport type { WebhookEvent } from './types';\nimport { verifyWebhook, type VerifyOptions } from './webhooks';\n\nexport const VERSION = '0.2.0';\n\nexport interface ClientOptions {\n /** The project's API key (`smswire_live_…`). Defaults to SMSWIRE_KEY. */\n apiKey?: string;\n /** The project's slug, the part after /p/ in its endpoint. Defaults to SMSWIRE_PROJECT. */\n project?: string;\n /** Defaults to SMSWIRE_URL, then https://api.smswire.app. */\n baseUrl?: string;\n /** Signing secret (`whsec_…`) for webhooks.verify(). Defaults to SMSWIRE_WEBHOOK_SECRET. */\n webhookSecret?: string;\n /** Retries after a 429, a 5xx or a network error (see the README for which calls). Default 2. */\n maxRetries?: number;\n /** Longest Retry-After worth waiting for, in seconds; longer ones throw at once. Default 60. */\n maxRetryWait?: number;\n /** Per-attempt timeout in milliseconds. Default 30 000. */\n timeout?: number;\n /** A fetch implementation, for runtimes or tests that need their own. */\n fetch?: typeof fetch;\n}\n\nconst env = (name: string): string | undefined =>\n typeof process === 'undefined' ? undefined : process.env?.[name] || undefined;\n\nexport class SMSWire {\n readonly messages: Messages;\n readonly otp: OneTimeCodes;\n readonly schedules: Schedules;\n readonly groups: Groups;\n readonly campaigns: Campaigns;\n readonly webhooks: { verify(rawBody: string | Uint8Array | ArrayBuffer, signature: string | null | undefined, options?: VerifyOptions): Promise<WebhookEvent> };\n\n constructor(options: ClientOptions = {}) {\n const apiKey = options.apiKey ?? env('SMSWIRE_KEY');\n const project = options.project ?? env('SMSWIRE_PROJECT');\n if (!apiKey) throw new Error('SMSWire: pass apiKey or set SMSWIRE_KEY');\n if (!project) throw new Error('SMSWire: pass project or set SMSWIRE_PROJECT');\n\n const http: HttpOptions = {\n apiKey,\n baseUrl: options.baseUrl ?? env('SMSWIRE_URL') ?? 'https://api.smswire.app',\n maxRetries: options.maxRetries ?? 2,\n maxRetryWait: options.maxRetryWait ?? 60,\n timeout: options.timeout ?? 30_000,\n fetch: options.fetch ?? globalThis.fetch.bind(globalThis),\n userAgent: `smswire-node/${VERSION}`,\n };\n const call = <T>(req: Request) => send<T>(http, req);\n const p = `/v1/p/${encodeURIComponent(project)}`;\n this.messages = new Messages(call, `${p}/messages`);\n this.otp = new OneTimeCodes(call, `${p}/otp`);\n this.schedules = new Schedules(call, `${p}/schedules`);\n this.groups = new Groups(call, `${p}/groups`);\n this.campaigns = new Campaigns(call, `${p}/campaigns`);\n\n const secret = options.webhookSecret ?? env('SMSWIRE_WEBHOOK_SECRET');\n this.webhooks = {\n verify: (rawBody, signature, opts) => {\n if (!secret) throw new Error('SMSWire: pass webhookSecret or set SMSWIRE_WEBHOOK_SECRET');\n return verifyWebhook(rawBody, signature, secret, opts);\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,IAAM,eAAN,cAA2B,MAAM;AAAA,EAGtC,YAEW,QAEA,MACT,SAESA,cAA4B,MACrC,SACA;AACA,UAAM,SAAS,OAAO;AARb;AAEA;AAGA,sBAAAA;AAAA,EAIX;AAAA,EATW;AAAA,EAEA;AAAA,EAGA;AAAA,EATO,OAAe;AAcnC;AAGO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAC7B,OAAO;AAC3B;;;ACCA,IAAM,QAAQ,CAAC,YAAoB,IAAI,QAAQ,CAAC,MAAM,WAAW,GAAG,UAAU,GAAI,CAAC;AAGnF,SAAS,WAAW,QAAsC;AACxD,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,IAAI,OAAO,MAAM;AACvB,MAAI,OAAO,SAAS,CAAC,EAAG,QAAO,KAAK,IAAI,GAAG,CAAC;AAC5C,QAAM,KAAK,KAAK,MAAM,MAAM;AAC5B,SAAO,OAAO,MAAM,EAAE,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,GAAI;AACvE;AAGA,IAAM,UAAU,CAAC,YAAoB,KAAK,IAAI,GAAG,MAAM,KAAK,OAAO,KAAK,IAAI,KAAK,OAAO,IAAI;AAG5F,eAAsB,UAAU,KAAsC;AACpE,QAAM,OAAO,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,EAAE;AAC5C,MAAI,OAAO;AACX,MAAI,UAAU,QAAQ,IAAI,MAAM;AAChC,MAAI;AACF,UAAM,OAAO,KAAK,MAAM,IAA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